ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/spell_attack.C
(Generate patch)

Comparing deliantra/server/server/spell_attack.C (file contents):
Revision 1.11 by root, Mon Sep 11 20:26:41 2006 UTC vs.
Revision 1.17 by root, Tue Dec 12 21:39:57 2006 UTC

1
2/*
3 * static char *rcsid_spell_attack_c =
4 * "$Id: spell_attack.C,v 1.11 2006/09/11 20:26:41 root Exp $";
5 */
6
7
8/* 1/*
9 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
10 3
11 Copyright (C) 2002-2003 Mark Wedel & Crossfire Development Team 4 Copyright (C) 2002-2003 Mark Wedel & Crossfire Development Team
12 Copyright (C) 1992 Frank Tore Johansen 5 Copyright (C) 1992 Frank Tore Johansen
23 16
24 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 20
28 The authors can be reached via e-mail at crossfire-devel@real-time.com 21 The authors can be reached via e-mail at <crossfire@schmorp.de>
29*/ 22*/
30 23
31/* This file contains all the spell attack code. Grouping this code 24/* This file contains all the spell attack code. Grouping this code
32 * together should hopefully make it easier to find the relevent bits 25 * together should hopefully make it easier to find the relevent bits
33 * of code 26 * of code
124void 117void
125forklightning (object *op, object *tmp) 118forklightning (object *op, object *tmp)
126{ 119{
127 int new_dir = 1; /* direction or -1 for left, +1 for right 0 if no new bolt */ 120 int new_dir = 1; /* direction or -1 for left, +1 for right 0 if no new bolt */
128 int t_dir; /* stores temporary dir calculation */ 121 int t_dir; /* stores temporary dir calculation */
129 mapstruct *m; 122 maptile *m;
130 sint16 sx, sy; 123 sint16 sx, sy;
131 object *new_bolt; 124 object *new_bolt;
132 125
133 /* pick a fork direction. tmp->stats.Con is the left bias 126 /* pick a fork direction. tmp->stats.Con is the left bias
134 * i.e., the chance in 100 of forking LEFT 127 * i.e., the chance in 100 of forking LEFT
147 140
148 if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (m, sx, sy))) 141 if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (m, sx, sy)))
149 return; 142 return;
150 143
151 /* OK, we made a fork */ 144 /* OK, we made a fork */
152 new_bolt = get_object (); 145 new_bolt = object::create ();
153 copy_object (tmp, new_bolt); 146 tmp->copy_to (new_bolt);
154 147
155 /* reduce chances of subsequent forking */ 148 /* reduce chances of subsequent forking */
156 new_bolt->stats.Dex -= 10; 149 new_bolt->stats.Dex -= 10;
157 tmp->stats.Dex -= 10; /* less forks from main bolt too */ 150 tmp->stats.Dex -= 10; /* less forks from main bolt too */
158 new_bolt->stats.Con += 25 * new_dir; /* adjust the left bias */ 151 new_bolt->stats.Con += 25 * new_dir; /* adjust the left bias */
177move_bolt (object *op) 170move_bolt (object *op)
178{ 171{
179 object *tmp; 172 object *tmp;
180 int mflags; 173 int mflags;
181 sint16 x, y; 174 sint16 x, y;
182 mapstruct *m; 175 maptile *m;
183 176
184 if (--(op->duration) < 0) 177 if (--(op->duration) < 0)
185 { 178 {
186 remove_ob (op); 179 op->destroy ();
187 free_object (op);
188 return; 180 return;
189 } 181 }
190 182
191 hit_map (op, 0, op->attacktype, 1); 183 hit_map (op, 0, op->attacktype, 1);
192 184
257 update_turn_face (op); /* A bolt *must* be IS_TURNABLE */ 249 update_turn_face (op); /* A bolt *must* be IS_TURNABLE */
258 return; 250 return;
259 } 251 }
260 else 252 else
261 { /* Create a copy of this object and put it ahead */ 253 { /* Create a copy of this object and put it ahead */
262 tmp = get_object (); 254 tmp = object::create ();
263 copy_object (op, tmp); 255 op->copy_to (tmp);
264 tmp->speed_left = -0.1; 256 tmp->speed_left = -0.1;
265 tmp->x += DIRX (tmp), tmp->y += DIRY (tmp); 257 tmp->x += DIRX (tmp), tmp->y += DIRY (tmp);
266 tmp = insert_ob_in_map (tmp, op->map, op, 0); 258 tmp = insert_ob_in_map (tmp, op->map, op, 0);
267 /* To make up for the decrease at the top of the function */ 259 /* To make up for the decrease at the top of the function */
268 tmp->duration++; 260 tmp->duration++;
327 tmp->map = op->map; 319 tmp->map = op->map;
328 320
329 mflags = get_map_flags (tmp->map, &tmp->map, tmp->x, tmp->y, &tmp->x, &tmp->y); 321 mflags = get_map_flags (tmp->map, &tmp->map, tmp->x, tmp->y, &tmp->x, &tmp->y);
330 if (mflags & P_OUT_OF_MAP) 322 if (mflags & P_OUT_OF_MAP)
331 { 323 {
332 free_object (tmp); 324 tmp->destroy ();
333 return 0; 325 return 0;
334 } 326 }
327
335 if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (tmp->map, tmp->x, tmp->y))) 328 if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (tmp->map, tmp->x, tmp->y)))
336 { 329 {
337 if (!QUERY_FLAG (tmp, FLAG_REFLECTING)) 330 if (!QUERY_FLAG (tmp, FLAG_REFLECTING))
338 { 331 {
339 free_object (tmp); 332 tmp->destroy ();
340 return 0; 333 return 0;
341 } 334 }
335
342 tmp->x = op->x; 336 tmp->x = op->x;
343 tmp->y = op->y; 337 tmp->y = op->y;
344 tmp->direction = absdir (tmp->direction + 4); 338 tmp->direction = absdir (tmp->direction + 4);
345 tmp->map = op->map; 339 tmp->map = op->map;
346 } 340 }
341
347 if ((tmp = insert_ob_in_map (tmp, tmp->map, op, 0)) != NULL) 342 if ((tmp = insert_ob_in_map (tmp, tmp->map, op, 0)) != NULL)
348 move_bolt (tmp); 343 move_bolt (tmp);
344
349 return 1; 345 return 1;
350} 346}
351 347
352 348
353 349
363 */ 359 */
364void 360void
365explosion (object *op) 361explosion (object *op)
366{ 362{
367 object *tmp; 363 object *tmp;
368 mapstruct *m = op->map; 364 maptile *m = op->map;
369 int i; 365 int i;
370 366
371 if (--(op->duration) < 0) 367 if (--(op->duration) < 0)
372 { 368 {
373 remove_ob (op); 369 op->destroy ();
374 free_object (op);
375 return; 370 return;
376 } 371 }
372
377 hit_map (op, 0, op->attacktype, 0); 373 hit_map (op, 0, op->attacktype, 0);
378 374
379 if (op->range > 0) 375 if (op->range > 0)
380 { 376 {
381 for (i = 1; i < 9; i++) 377 for (i = 1; i < 9; i++)
387 /* ok_to_put_more already does things like checks for walls, 383 /* ok_to_put_more already does things like checks for walls,
388 * out of map, etc. 384 * out of map, etc.
389 */ 385 */
390 if (ok_to_put_more (op->map, dx, dy, op, op->attacktype)) 386 if (ok_to_put_more (op->map, dx, dy, op, op->attacktype))
391 { 387 {
392 tmp = get_object (); 388 tmp = object::create ();
393 copy_object (op, tmp); 389 op->copy_to (tmp);
394 tmp->state = 0; 390 tmp->state = 0;
395 tmp->speed_left = -0.21; 391 tmp->speed_left = -0.21;
396 tmp->range--; 392 tmp->range--;
397 tmp->value = 0; 393 tmp->value = 0;
398 tmp->x = dx; 394 tmp->x = dx;
409 * explode. 405 * explode.
410 */ 406 */
411void 407void
412explode_bullet (object *op) 408explode_bullet (object *op)
413{ 409{
414 tag_t op_tag = op->count;
415 object *tmp, *owner; 410 object *tmp, *owner;
416 411
417 if (op->other_arch == NULL) 412 if (op->other_arch == NULL)
418 { 413 {
419 LOG (llevError, "BUG: explode_bullet(): op without other_arch\n"); 414 LOG (llevError, "BUG: explode_bullet(): op without other_arch\n");
420 remove_ob (op); 415 op->destroy ();
421 free_object (op);
422 return; 416 return;
423 } 417 }
424 418
425 if (op->env) 419 if (op->env)
426 { 420 {
428 422
429 env = object_get_env_recursive (op); 423 env = object_get_env_recursive (op);
430 if (env->map == NULL || out_of_map (env->map, env->x, env->y)) 424 if (env->map == NULL || out_of_map (env->map, env->x, env->y))
431 { 425 {
432 LOG (llevError, "BUG: explode_bullet(): env out of map\n"); 426 LOG (llevError, "BUG: explode_bullet(): env out of map\n");
433 remove_ob (op); 427 op->destroy ();
434 free_object (op);
435 return; 428 return;
436 } 429 }
430
437 remove_ob (op); 431 op->remove ();
438 op->x = env->x; 432 op->x = env->x;
439 op->y = env->y; 433 op->y = env->y;
440 insert_ob_in_map (op, env->map, op, INS_NO_MERGE | INS_NO_WALK_ON); 434 insert_ob_in_map (op, env->map, op, INS_NO_MERGE | INS_NO_WALK_ON);
441 } 435 }
442 else if (out_of_map (op->map, op->x, op->y)) 436 else if (out_of_map (op->map, op->x, op->y))
443 { 437 {
444 LOG (llevError, "BUG: explode_bullet(): op out of map\n"); 438 LOG (llevError, "BUG: explode_bullet(): op out of map\n");
445 remove_ob (op); 439 op->destroy ();
446 free_object (op);
447 return; 440 return;
448 } 441 }
449 442
450 // elmex Tue Aug 15 17:46:51 CEST 2006: Prevent explosions of any kind on safe maps 443 // elmex Tue Aug 15 17:46:51 CEST 2006: Prevent explosions of any kind on safe maps
451 // NOTE: If this breaks something important: remove this. I can't think of anything 444 // NOTE: If this breaks something important: remove this. I can't think of anything
452 // bad at the moment that might happen from this. 445 // bad at the moment that might happen from this.
453 if (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_SAFE) 446 if (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_SAFE)
454 { 447 {
455 remove_ob (op); 448 op->destroy ();
456 free_object (op);
457 return; 449 return;
458 } 450 }
459 451
460 if (op->attacktype) 452 if (op->attacktype)
461 { 453 {
462 hit_map (op, 0, op->attacktype, 1); 454 hit_map (op, 0, op->attacktype, 1);
463 if (was_destroyed (op, op_tag)) 455 if (op->destroyed ())
464 return; 456 return;
465 } 457 }
466 458
467 /* other_arch contains what this explodes into */ 459 /* other_arch contains what this explodes into */
468 tmp = arch_to_object (op->other_arch); 460 tmp = arch_to_object (op->other_arch);
472 464
473 owner = get_owner (op); 465 owner = get_owner (op);
474 466
475 if ((tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER) && owner && !tailor_god_spell (tmp, owner)) 467 if ((tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER) && owner && !tailor_god_spell (tmp, owner))
476 { 468 {
477 remove_ob (op); 469 op->destroy ();
478 free_object (op);
479 return; 470 return;
480 } 471 }
481 472
482 tmp->x = op->x; 473 tmp->x = op->x;
483 tmp->y = op->y; 474 tmp->y = op->y;
511 /* Prevent recursion */ 502 /* Prevent recursion */
512 op->move_on = 0; 503 op->move_on = 0;
513 504
514 insert_ob_in_map (tmp, op->map, op, 0); 505 insert_ob_in_map (tmp, op->map, op, 0);
515 /* remove the firebullet */ 506 /* remove the firebullet */
516 if (!was_destroyed (op, op_tag)) 507 if (!op->destroyed ())
517 { 508 {
518 remove_ob (op); 509 op->destroy ();
519 free_object (op);
520 } 510 }
521} 511}
522 512
523 513
524 514
527 */ 517 */
528 518
529void 519void
530check_bullet (object *op) 520check_bullet (object *op)
531{ 521{
532 tag_t op_tag = op->count, tmp_tag;
533 object *tmp; 522 object *tmp;
534 int dam, mflags; 523 int dam, mflags;
535 mapstruct *m; 524 maptile *m;
536 sint16 sx, sy; 525 sint16 sx, sy;
537 526
538 mflags = get_map_flags (op->map, &m, op->x, op->y, &sx, &sy); 527 mflags = get_map_flags (op->map, &m, op->x, op->y, &sx, &sy);
539 528
540 if (!(mflags & P_IS_ALIVE) && !OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, sx, sy))) 529 if (!(mflags & P_IS_ALIVE) && !OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, sx, sy)))
553 542
554 for (tmp = get_map_ob (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) 543 for (tmp = get_map_ob (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above)
555 { 544 {
556 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 545 if (QUERY_FLAG (tmp, FLAG_ALIVE))
557 { 546 {
558 tmp_tag = tmp->count;
559 dam = hit_player (tmp, op->stats.dam, op, op->attacktype, 1); 547 dam = hit_player (tmp, op->stats.dam, op, op->attacktype, 1);
560 if (was_destroyed (op, op_tag) || !was_destroyed (tmp, tmp_tag) || (op->stats.dam -= dam) < 0) 548 if (op->destroyed () || !tmp->destroyed () || (op->stats.dam -= dam) < 0)
561 { 549 {
562 if (!QUERY_FLAG (op, FLAG_REMOVED)) 550 if (!QUERY_FLAG (op, FLAG_REMOVED))
563 { 551 {
564 remove_ob (op); 552 op->destroy ();
565 free_object (op);
566 return; 553 return;
567 } 554 }
568 } 555 }
569 } 556 }
570 } 557 }
580void 567void
581move_bullet (object *op) 568move_bullet (object *op)
582{ 569{
583 sint16 new_x, new_y; 570 sint16 new_x, new_y;
584 int mflags; 571 int mflags;
585 mapstruct *m; 572 maptile *m;
586 573
587#if 0 574#if 0
588 /* We need a better general purpose way to do this */ 575 /* We need a better general purpose way to do this */
589 576
590 /* peterm: added to make comet leave a trail of burnouts 577 /* peterm: added to make comet leave a trail of burnouts
591 it's an unadulterated hack, but the effect is cool. */ 578 it's an unadulterated hack, but the effect is cool. */
592 if (op->stats.sp == SP_METEOR) 579 if (op->stats.sp == SP_METEOR)
593 { 580 {
594 replace_insert_ob_in_map ("fire_trail", op); 581 replace_insert_ob_in_map ("fire_trail", op);
595 if (was_destroyed (op, op_tag)) 582 if (op->destroyed ())
596 return; 583 return;
597 } /* end addition. */ 584 } /* end addition. */
598#endif 585#endif
599 586
600 /* Reached the end of its life - remove it */ 587 /* Reached the end of its life - remove it */
601 if (--op->range <= 0) 588 if (--op->range <= 0)
602 { 589 {
603 if (op->other_arch) 590 if (op->other_arch)
604 {
605 explode_bullet (op); 591 explode_bullet (op);
606 }
607 else 592 else
608 { 593 op->destroy ();
609 remove_ob (op); 594
610 free_object (op);
611 }
612 return; 595 return;
613 } 596 }
614 597
615 new_x = op->x + DIRX (op); 598 new_x = op->x + DIRX (op);
616 new_y = op->y + DIRY (op); 599 new_y = op->y + DIRY (op);
617 m = op->map; 600 m = op->map;
618 mflags = get_map_flags (m, &m, new_x, new_y, &new_x, &new_y); 601 mflags = get_map_flags (m, &m, new_x, new_y, &new_x, &new_y);
619 602
620 if (mflags & P_OUT_OF_MAP) 603 if (mflags & P_OUT_OF_MAP)
621 { 604 {
622 remove_ob (op); 605 op->destroy ();
623 free_object (op);
624 return; 606 return;
625 } 607 }
626 608
627 if (!op->direction || OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, new_x, new_y))) 609 if (!op->direction || OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, new_x, new_y)))
628 { 610 {
629 if (op->other_arch) 611 if (op->other_arch)
630 {
631 explode_bullet (op); 612 explode_bullet (op);
632 }
633 else 613 else
634 { 614 op->destroy ();
635 remove_ob (op); 615
636 free_object (op);
637 }
638 return; 616 return;
639 } 617 }
640 618
641 remove_ob (op); 619 op->remove ();
642 op->x = new_x; 620 op->x = new_x;
643 op->y = new_y; 621 op->y = new_y;
644 if ((op = insert_ob_in_map (op, m, op, 0)) == NULL) 622 if ((op = insert_ob_in_map (op, m, op, 0)) == NULL)
645 return; 623 return;
646 624
705 tmp->map = op->map; 683 tmp->map = op->map;
706 684
707 mflags = get_map_flags (tmp->map, &tmp->map, tmp->x, tmp->y, &tmp->x, &tmp->y); 685 mflags = get_map_flags (tmp->map, &tmp->map, tmp->x, tmp->y, &tmp->x, &tmp->y);
708 if (mflags & P_OUT_OF_MAP) 686 if (mflags & P_OUT_OF_MAP)
709 { 687 {
710 free_object (tmp); 688 tmp->destroy ();
711 return 0; 689 return 0;
712 } 690 }
691
713 if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (tmp->map, tmp->x, tmp->y))) 692 if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (tmp->map, tmp->x, tmp->y)))
714 { 693 {
715 if (!QUERY_FLAG (tmp, FLAG_REFLECTING)) 694 if (!QUERY_FLAG (tmp, FLAG_REFLECTING))
716 { 695 {
717 free_object (tmp); 696 tmp->destroy ();
718 return 0; 697 return 0;
719 } 698 }
699
720 tmp->x = op->x; 700 tmp->x = op->x;
721 tmp->y = op->y; 701 tmp->y = op->y;
722 tmp->direction = absdir (tmp->direction + 4); 702 tmp->direction = absdir (tmp->direction + 4);
723 tmp->map = op->map; 703 tmp->map = op->map;
724 } 704 }
705
725 if ((tmp = insert_ob_in_map (tmp, tmp->map, op, 0)) != NULL) 706 if ((tmp = insert_ob_in_map (tmp, tmp->map, op, 0)) != NULL)
726 {
727 check_bullet (tmp); 707 check_bullet (tmp);
728 } 708
729 return 1; 709 return 1;
730} 710}
731 711
732 712
733 713
763 743
764void 744void
765move_cone (object *op) 745move_cone (object *op)
766{ 746{
767 int i; 747 int i;
768 tag_t tag;
769 748
770 /* if no map then hit_map will crash so just ignore object */ 749 /* if no map then hit_map will crash so just ignore object */
771 if (!op->map) 750 if (!op->map)
772 { 751 {
773 LOG (llevError, "Tried to move_cone object %s without a map.\n", op->name ? &op->name : "unknown"); 752 LOG (llevError, "Tried to move_cone object %s without a map.\n", op->name ? &op->name : "unknown");
788 * when their cone dies when they die. 767 * when their cone dies when they die.
789 */ 768 */
790 /* If no owner left, the spell dies out. */ 769 /* If no owner left, the spell dies out. */
791 if (get_owner (op) == NULL) 770 if (get_owner (op) == NULL)
792 { 771 {
793 remove_ob (op); 772 op->destroy ();
794 free_object (op);
795 return; 773 return;
796 } 774 }
797#endif 775#endif
798 776
799 tag = op->count;
800 hit_map (op, 0, op->attacktype, 0); 777 hit_map (op, 0, op->attacktype, 0);
801 778
802 /* Check to see if we should push anything. 779 /* Check to see if we should push anything.
803 * Spell objects with weight push whatever they encounter to some 780 * Spell objects with weight push whatever they encounter to some
804 * degree. 781 * degree.
805 */ 782 */
806 if (op->weight) 783 if (op->weight)
807 check_spell_knockback (op); 784 check_spell_knockback (op);
808 785
809 if (was_destroyed (op, tag)) 786 if (op->destroyed ())
810 return; 787 return;
811 788
812 if ((op->duration--) < 0) 789 if ((op->duration--) < 0)
813 { 790 {
814 remove_ob (op); 791 op->destroy ();
815 free_object (op);
816 return; 792 return;
817 } 793 }
818 /* Object has hit maximum range, so don't have it move 794 /* Object has hit maximum range, so don't have it move
819 * any further. When the duration above expires, 795 * any further. When the duration above expires,
820 * then the object will get removed. 796 * then the object will get removed.
829 { 805 {
830 sint16 x = op->x + freearr_x[absdir (op->stats.sp + i)], y = op->y + freearr_y[absdir (op->stats.sp + i)]; 806 sint16 x = op->x + freearr_x[absdir (op->stats.sp + i)], y = op->y + freearr_y[absdir (op->stats.sp + i)];
831 807
832 if (ok_to_put_more (op->map, x, y, op, op->attacktype)) 808 if (ok_to_put_more (op->map, x, y, op, op->attacktype))
833 { 809 {
834 object *tmp = get_object (); 810 object *tmp = object::create ();
835 811
836 copy_object (op, tmp); 812 op->copy_to (tmp);
837 tmp->x = x; 813 tmp->x = x;
838 tmp->y = y; 814 tmp->y = y;
839 815
840 tmp->duration = op->duration + 1; 816 tmp->duration = op->duration + 1;
841 817
859int 835int
860cast_cone (object *op, object *caster, int dir, object *spell) 836cast_cone (object *op, object *caster, int dir, object *spell)
861{ 837{
862 object *tmp; 838 object *tmp;
863 int i, success = 0, range_min = -1, range_max = 1; 839 int i, success = 0, range_min = -1, range_max = 1;
864 mapstruct *m; 840 maptile *m;
865 sint16 sx, sy; 841 sint16 sx, sy;
866 MoveType movetype; 842 MoveType movetype;
867 843
868 if (!spell->other_arch) 844 if (!spell->other_arch)
869 return 0; 845 return 0;
1024 return; 1000 return;
1025 1001
1026 if (env->type == PLAYER) 1002 if (env->type == PLAYER)
1027 esrv_del_item (env->contr, op->count); 1003 esrv_del_item (env->contr, op->count);
1028 1004
1029 remove_ob (op); 1005 op->remove ();
1030 op->x = env->x; 1006 op->x = env->x;
1031 op->y = env->y; 1007 op->y = env->y;
1032 if ((op = insert_ob_in_map (op, env->map, op, 0)) == NULL) 1008 if ((op = insert_ob_in_map (op, env->map, op, 0)) == NULL)
1033 return; 1009 return;
1034 } 1010 }
1036 // elmex Tue Aug 15 17:46:51 CEST 2006: Prevent bomb from exploding 1012 // elmex Tue Aug 15 17:46:51 CEST 2006: Prevent bomb from exploding
1037 // on a safe map. I don't like this special casing, but it seems to be neccessary 1013 // on a safe map. I don't like this special casing, but it seems to be neccessary
1038 // as bombs can be carried. 1014 // as bombs can be carried.
1039 if (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_SAFE) 1015 if (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_SAFE)
1040 { 1016 {
1041 remove_ob (op); 1017 op->destroy ();
1042 free_object (op);
1043 return; 1018 return;
1044 } 1019 }
1045 1020
1046 /* This copies a lot of the code from the fire bullet, 1021 /* This copies a lot of the code from the fire bullet,
1047 * but using the cast_bullet isn't really feasible, 1022 * but using the cast_bullet isn't really feasible,
1048 * so just set up the appropriate values. 1023 * so just set up the appropriate values.
1049 */ 1024 */
1050 at = find_archetype (SPLINT); 1025 at = archetype::find (SPLINT);
1051 if (at) 1026 if (at)
1052 { 1027 {
1053 for (i = 1; i < 9; i++) 1028 for (i = 1; i < 9; i++)
1054 { 1029 {
1055 if (out_of_map (op->map, op->x + freearr_x[i], op->y + freearr_x[i])) 1030 if (out_of_map (op->map, op->x + freearr_x[i], op->y + freearr_x[i]))
1082{ 1057{
1083 1058
1084 object *tmp; 1059 object *tmp;
1085 int mflags; 1060 int mflags;
1086 sint16 dx = op->x + freearr_x[dir], dy = op->y + freearr_y[dir]; 1061 sint16 dx = op->x + freearr_x[dir], dy = op->y + freearr_y[dir];
1087 mapstruct *m; 1062 maptile *m;
1088 1063
1089 mflags = get_map_flags (op->map, &m, dx, dy, &dx, &dy); 1064 mflags = get_map_flags (op->map, &m, dx, dy, &dx, &dy);
1090 if ((mflags & P_OUT_OF_MAP) || (GET_MAP_MOVE_BLOCK (m, dx, dy) & MOVE_WALK)) 1065 if ((mflags & P_OUT_OF_MAP) || (GET_MAP_MOVE_BLOCK (m, dx, dy) & MOVE_WALK))
1091 { 1066 {
1092 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); 1067 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way.");
1128get_pointed_target (object *op, int dir, int range, int type) 1103get_pointed_target (object *op, int dir, int range, int type)
1129{ 1104{
1130 object *target; 1105 object *target;
1131 sint16 x, y; 1106 sint16 x, y;
1132 int dist, mflags; 1107 int dist, mflags;
1133 mapstruct *mp; 1108 maptile *mp;
1134 1109
1135 if (dir == 0) 1110 if (dir == 0)
1136 return NULL; 1111 return NULL;
1137 1112
1138 for (dist = 1; dist < range; dist++) 1113 for (dist = 1; dist < range; dist++)
1241 } 1216 }
1242 else 1217 else
1243 { 1218 {
1244 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s looks stronger!", query_name (target)); 1219 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s looks stronger!", query_name (target));
1245 target->stats.hp = target->stats.maxhp * 2; 1220 target->stats.hp = target->stats.maxhp * 2;
1246 free_object (effect); 1221 effect->destroy ();
1247 return 0; 1222 return 0;
1248 } 1223 }
1249 } 1224 }
1250 } 1225 }
1251 else 1226 else
1278move_missile (object *op) 1253move_missile (object *op)
1279{ 1254{
1280 int i, mflags; 1255 int i, mflags;
1281 object *owner; 1256 object *owner;
1282 sint16 new_x, new_y; 1257 sint16 new_x, new_y;
1283 mapstruct *m; 1258 maptile *m;
1284 1259
1285 if (op->range-- <= 0) 1260 if (op->range-- <= 0)
1286 { 1261 {
1287 remove_ob (op); 1262 op->destroy ();
1288 free_object (op);
1289 return; 1263 return;
1290 } 1264 }
1291 1265
1292 owner = get_owner (op); 1266 owner = get_owner (op);
1293#if 0 1267#if 0
1294 /* It'd make things nastier if this wasn't here - spells cast by 1268 /* It'd make things nastier if this wasn't here - spells cast by
1295 * monster that are then killed would continue to survive 1269 * monster that are then killed would continue to survive
1296 */ 1270 */
1297 if (owner == NULL) 1271 if (owner == NULL)
1298 { 1272 {
1299 remove_ob (op); 1273 op->destroy ();
1300 free_object (op);
1301 return; 1274 return;
1302 } 1275 }
1303#endif 1276#endif
1304 1277
1305 new_x = op->x + DIRX (op); 1278 new_x = op->x + DIRX (op);
1307 1280
1308 mflags = get_map_flags (op->map, &m, new_x, new_y, &new_x, &new_y); 1281 mflags = get_map_flags (op->map, &m, new_x, new_y, &new_x, &new_y);
1309 1282
1310 if (!(mflags & P_OUT_OF_MAP) && ((mflags & P_IS_ALIVE) || OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, new_x, new_y)))) 1283 if (!(mflags & P_OUT_OF_MAP) && ((mflags & P_IS_ALIVE) || OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, new_x, new_y))))
1311 { 1284 {
1312 tag_t tag = op->count;
1313
1314 hit_map (op, op->direction, AT_MAGIC, 1); 1285 hit_map (op, op->direction, AT_MAGIC, 1);
1315 /* Basically, missile only hits one thing then goes away. 1286 /* Basically, missile only hits one thing then goes away.
1316 * we need to remove it if someone hasn't already done so. 1287 * we need to remove it if someone hasn't already done so.
1317 */ 1288 */
1318 if (!was_destroyed (op, tag)) 1289 if (!op->destroyed ())
1319 { 1290 op->destroy ();
1320 remove_ob (op); 1291
1321 free_object (op);
1322 }
1323 return; 1292 return;
1324 } 1293 }
1325 1294
1326 remove_ob (op); 1295 op->remove ();
1296
1327 if (!op->direction || (mflags & P_OUT_OF_MAP)) 1297 if (!op->direction || (mflags & P_OUT_OF_MAP))
1328 { 1298 {
1329 free_object (op); 1299 op->destroy ();
1330 return; 1300 return;
1331 } 1301 }
1302
1332 op->x = new_x; 1303 op->x = new_x;
1333 op->y = new_y; 1304 op->y = new_y;
1334 op->map = m; 1305 op->map = m;
1335 i = spell_find_dir (op->map, op->x, op->y, get_owner (op)); 1306 i = spell_find_dir (op->map, op->x, op->y, get_owner (op));
1336 if (i > 0 && i != op->direction) 1307 if (i > 0 && i != op->direction)
1337 { 1308 {
1338 op->direction = i; 1309 op->direction = i;
1339 SET_ANIMATION (op, op->direction); 1310 SET_ANIMATION (op, op->direction);
1340 } 1311 }
1312
1341 insert_ob_in_map (op, op->map, op, 0); 1313 insert_ob_in_map (op, op->map, op, 0);
1342} 1314}
1343 1315
1344/**************************************************************************** 1316/****************************************************************************
1345 * Destruction 1317 * Destruction
1391int 1363int
1392cast_destruction (object *op, object *caster, object *spell_ob) 1364cast_destruction (object *op, object *caster, object *spell_ob)
1393{ 1365{
1394 int i, j, range, mflags, friendly = 0, dam, dur; 1366 int i, j, range, mflags, friendly = 0, dam, dur;
1395 sint16 sx, sy; 1367 sint16 sx, sy;
1396 mapstruct *m; 1368 maptile *m;
1397 object *tmp; 1369 object *tmp;
1398 const char *skill; 1370 const char *skill;
1399 1371
1400 range = spell_ob->range + SP_level_range_adjust (caster, spell_ob); 1372 range = spell_ob->range + SP_level_range_adjust (caster, spell_ob);
1401 dam = spell_ob->stats.dam + SP_level_dam_adjust (caster, spell_ob); 1373 dam = spell_ob->stats.dam + SP_level_dam_adjust (caster, spell_ob);
1583mood_change (object *op, object *caster, object *spell) 1555mood_change (object *op, object *caster, object *spell)
1584{ 1556{
1585 object *tmp, *god, *head; 1557 object *tmp, *god, *head;
1586 int done_one, range, mflags, level, at, best_at; 1558 int done_one, range, mflags, level, at, best_at;
1587 sint16 x, y, nx, ny; 1559 sint16 x, y, nx, ny;
1588 mapstruct *m; 1560 maptile *m;
1589 const char *race; 1561 const char *race;
1590 1562
1591 /* We precompute some values here so that we don't have to keep 1563 /* We precompute some values here so that we don't have to keep
1592 * doing it over and over again. 1564 * doing it over and over again.
1593 */ 1565 */
1757move_ball_spell (object *op) 1729move_ball_spell (object *op)
1758{ 1730{
1759 int i, j, dam_save, dir, mflags; 1731 int i, j, dam_save, dir, mflags;
1760 sint16 nx, ny, hx, hy; 1732 sint16 nx, ny, hx, hy;
1761 object *owner; 1733 object *owner;
1762 mapstruct *m; 1734 maptile *m;
1763 1735
1764 owner = get_owner (op); 1736 owner = get_owner (op);
1765 1737
1766 /* the following logic makes sure that the ball doesn't move into a wall, 1738 /* the following logic makes sure that the ball doesn't move into a wall,
1767 * and makes sure that it will move along a wall to try and get at it's 1739 * and makes sure that it will move along a wall to try and get at it's
1798 nx = op->x; 1770 nx = op->x;
1799 ny = op->y; 1771 ny = op->y;
1800 m = op->map; 1772 m = op->map;
1801 } 1773 }
1802 1774
1803 remove_ob (op); 1775 op->remove ();
1804 op->y = ny; 1776 op->y = ny;
1805 op->x = nx; 1777 op->x = nx;
1806 insert_ob_in_map (op, m, op, 0); 1778 insert_ob_in_map (op, m, op, 0);
1807 1779
1808 dam_save = op->stats.dam; /* save the original dam: we do halfdam on 1780 dam_save = op->stats.dam; /* save the original dam: we do halfdam on
1879#if 0 1851#if 0
1880 static int cardinal_adjust[9] = { -3, -2, -1, 0, 0, 0, 1, 2, 3 }; 1852 static int cardinal_adjust[9] = { -3, -2, -1, 0, 0, 0, 1, 2, 3 };
1881 static int diagonal_adjust[10] = { -3, -2, -2, -1, 0, 0, 1, 2, 2, 3 }; 1853 static int diagonal_adjust[10] = { -3, -2, -2, -1, 0, 0, 1, 2, 2, 3 };
1882 sint16 target_x, target_y, origin_x, origin_y; 1854 sint16 target_x, target_y, origin_x, origin_y;
1883 int adjustdir; 1855 int adjustdir;
1884 mapstruct *m; 1856 maptile *m;
1885#endif 1857#endif
1886 int basedir; 1858 int basedir;
1887 object *owner; 1859 object *owner;
1888 1860
1889 owner = get_owner (op); 1861 owner = get_owner (op);
1890 if (op->duration == 0 || owner == NULL) 1862 if (op->duration == 0 || owner == NULL)
1891 { 1863 {
1892 remove_ob (op); 1864 op->destroy ();
1893 free_object (op);
1894 return; 1865 return;
1895 } 1866 }
1867
1896 op->duration--; 1868 op->duration--;
1897 1869
1898 basedir = op->direction; 1870 basedir = op->direction;
1899 if (basedir == 0) 1871 if (basedir == 0)
1900 { 1872 {
2032cast_light (object *op, object *caster, object *spell, int dir) 2004cast_light (object *op, object *caster, object *spell, int dir)
2033{ 2005{
2034 object *target = NULL, *tmp = NULL; 2006 object *target = NULL, *tmp = NULL;
2035 sint16 x, y; 2007 sint16 x, y;
2036 int dam, mflags; 2008 int dam, mflags;
2037 mapstruct *m; 2009 maptile *m;
2038 2010
2039 dam = spell->stats.dam + SP_level_dam_adjust (caster, spell); 2011 dam = spell->stats.dam + SP_level_dam_adjust (caster, spell);
2040 2012
2041 if (!dir) 2013 if (!dir)
2042 { 2014 {
2110cast_cause_disease (object *op, object *caster, object *spell, int dir) 2082cast_cause_disease (object *op, object *caster, object *spell, int dir)
2111{ 2083{
2112 sint16 x, y; 2084 sint16 x, y;
2113 int i, mflags, range, dam_mod, dur_mod; 2085 int i, mflags, range, dam_mod, dur_mod;
2114 object *walk; 2086 object *walk;
2115 mapstruct *m; 2087 maptile *m;
2116 2088
2117 x = op->x; 2089 x = op->x;
2118 y = op->y; 2090 y = op->y;
2119 2091
2120 /* If casting from a scroll, no direction will be available, so refer to the 2092 /* If casting from a scroll, no direction will be available, so refer to the
2212 { 2184 {
2213 object *flash; /* visual effect for inflicting disease */ 2185 object *flash; /* visual effect for inflicting disease */
2214 2186
2215 new_draw_info_format (NDI_UNIQUE, 0, op, "You inflict %s on %s!", &disease->name, &walk->name); 2187 new_draw_info_format (NDI_UNIQUE, 0, op, "You inflict %s on %s!", &disease->name, &walk->name);
2216 2188
2217 free_object (disease); /* don't need this one anymore */ 2189 disease->destroy (); /* don't need this one anymore */
2218 flash = get_archetype (ARCH_DETECT_MAGIC); 2190 flash = get_archetype (ARCH_DETECT_MAGIC);
2219 flash->x = x; 2191 flash->x = x;
2220 flash->y = y; 2192 flash->y = y;
2221 flash->map = walk->map; 2193 flash->map = walk->map;
2222 insert_ob_in_map (flash, walk->map, op, 0); 2194 insert_ob_in_map (flash, walk->map, op, 0);
2223 return 1; 2195 return 1;
2224 } 2196 }
2225 free_object (disease); 2197
2198 disease->destroy ();
2226 } 2199 }
2227 } /* if living creature */ 2200 } /* if living creature */
2228 } /* for range of spaces */ 2201 } /* for range of spaces */
2229 new_draw_info (NDI_UNIQUE, 0, op, "No one caught anything!"); 2202 new_draw_info (NDI_UNIQUE, 0, op, "No one caught anything!");
2230 return 1; 2203 return 1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines