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

Comparing deliantra/server/server/pets.C (file contents):
Revision 1.38 by root, Sun Jul 1 05:00:20 2007 UTC vs.
Revision 1.58 by root, Sun Nov 29 09:41:28 2009 UTC

1/* 1/*
2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Crossfire TRT is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
20 * 21 *
21 * The authors can be reached via e-mail to <crossfire@schmorp.de> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 23 */
23 24
24#include <global.h> 25#include <global.h>
25#include <sproto.h> 26#include <sproto.h>
26 27
31 * this is now tilemap aware. 32 * this is now tilemap aware.
32 */ 33 */
33object * 34object *
34get_pet_enemy (object *pet, rv_vector * rv) 35get_pet_enemy (object *pet, rv_vector * rv)
35{ 36{
36 object *owner, *tmp, *attacker, *tmp3; 37 object *tmp, *attacker, *tmp3;
37 int i; 38 int i;
38 sint16 x, y; 39 sint16 x, y;
39 maptile *nm; 40 maptile *nm;
40 int search_arr[SIZEOFFREE]; 41 int search_arr[SIZEOFFREE];
41 int mflags; 42 int mflags;
42 43
43 attacker = pet->attacked_by; /*pointer to attacking enemy */ 44 attacker = pet->attacked_by; /*pointer to attacking enemy */
44 pet->attacked_by = NULL; /*clear this, since we are dealing with it */ 45 pet->attacked_by = NULL; /*clear this, since we are dealing with it */
45 46
46 if (owner = pet->owner) 47 object *owner = pet->owner;
47 { 48
48 /* If the owner has turned on the pet, make the pet 49 if (!owner)
49 * unfriendly.
50 */
51 if (check_enemy (owner, rv) == pet)
52 {
53 remove_friendly_object (pet);
54 pet->attack_movement &= ~PETMOVE;
55 return owner;
56 }
57 } 50 {
58 else
59 {
60 /* else the owner is no longer around, so the 51 /* the owner is no longer around, so the
61 * pet no longer needs to be friendly. 52 * pet no longer needs to be friendly.
62 */ 53 */
63 remove_friendly_object (pet); 54 remove_friendly_object (pet);
64 pet->attack_movement &= ~PETMOVE; 55 pet->attack_movement &= ~PETMOVE;
65 return 0; 56 return 0;
57 }
58
59 /* If the owner has turned on the pet, make the pet
60 * unfriendly.
61 */
62 if (check_enemy (owner, rv) == pet)
63 {
64 remove_friendly_object (pet);
65 pet->attack_movement &= ~PETMOVE;
66 return owner;
66 } 67 }
67 68
68 /* If they are not on the same map, the pet won't be agressive */ 69 /* If they are not on the same map, the pet won't be agressive */
69 //if (!on_same_map (pet, owner)) 70 //if (!on_same_map (pet, owner))
70 // return 0; 71 // return 0;
254 { 255 {
255 object *ob = obl->ob; 256 object *ob = obl->ob;
256 next = obl->next; 257 next = obl->next;
257 258
258 if (ob->owner == owner) 259 if (ob->owner == owner)
259 ob->destroy (); 260 ob->drop_and_destroy ();
260 } 261 }
261} 262}
262 263
263/* 264/*
264 * Unfortunately, sometimes, the owner of a pet is in the 265 * Unfortunately, sometimes, the owner of a pet is in the
292int 293int
293follow_owner (object *ob, object *owner) 294follow_owner (object *ob, object *owner)
294{ 295{
295 if (owner->flag [FLAG_REMOVED]) 296 if (owner->flag [FLAG_REMOVED])
296 return 0; // do nothing if the owner is removed 297 return 0; // do nothing if the owner is removed
297 else if (!owner->map || owner->map->in_memory != MAP_IN_MEMORY) 298 else if (!owner->map || owner->map->in_memory != MAP_ACTIVE)
298 LOG (llevError, "owner '%s' of the pet '%s' not on a map in memory!?\n", &owner->name, &ob->name); 299 LOG (llevError, "owner '%s' of the pet '%s' not on a map in memory!?\n", &owner->name, &ob->name);
299 else 300 else
300 { 301 {
301 int dir = find_free_spot (ob, owner->map, owner->x, owner->y, 1, SIZEOFFREE); 302 int dir = find_free_spot (ob, owner->map, owner->x, owner->y, 1, SIZEOFFREE);
302 303
309 310
310 return 0; 311 return 0;
311 } 312 }
312 } 313 }
313 314
314 ob->destroy (); 315 ob->drop_and_destroy ();
316
315 return 1; 317 return 1;
316} 318}
317 319
318void 320void
319pet_move (object *ob) 321pet_move (object *ob)
324 maptile *m; 326 maptile *m;
325 327
326 /* Check to see if player pulled out */ 328 /* Check to see if player pulled out */
327 if ((owner = ob->owner) == NULL) 329 if ((owner = ob->owner) == NULL)
328 { 330 {
329 ob->destroy (); 331 ob->drop_and_destroy ();
330 LOG (llevMonster, "Pet: no owner, leaving.\n"); 332 LOG (llevMonster, "Pet: no owner, leaving.\n");
331 return; 333 return;
332 } 334 }
333 335
334 /* move monster into the owners map if not in the same map 336 /* move monster into the owners map if not in the same map
337 if (!on_same_map (ob, owner) && !owner->flag [FLAG_REMOVED]) 339 if (!on_same_map (ob, owner) && !owner->flag [FLAG_REMOVED])
338 { 340 {
339 follow_owner (ob, owner); 341 follow_owner (ob, owner);
340 return; 342 return;
341 } 343 }
344
342 /* Calculate Direction */ 345 /* Calculate Direction */
343 if (owner->type == PLAYER && owner->contr->petmode == pet_sad) 346 if (owner->type == PLAYER && owner->contr->petmode == pet_sad)
344 { 347 {
345 /* in S&D mode, if we have no enemy, run randomly about. */ 348 /* in S&D mode, if we have no enemy, run randomly about. */
346 for (i = 0; i < 15; i++) 349 for (i = 0; i < 15; i++)
362 struct rv_vector rv; 365 struct rv_vector rv;
363 366
364 get_rangevector (ob, ob->owner, &rv, 0); 367 get_rangevector (ob, ob->owner, &rv, 0);
365 dir = rv.direction; 368 dir = rv.direction;
366 } 369 }
370
367 ob->direction = dir; 371 ob->direction = dir;
368 372
369 /* move_ob returns 0 if the object couldn't move. If that is the 373 /* move_ob returns 0 if the object couldn't move. If that is the
370 * case, lets do some other work. 374 * case, lets do some other work.
371 */ 375 */
388 for (ob2 = GET_MAP_OB (m, dx, dy); ob2 != NULL; ob2 = ob2->above) 392 for (ob2 = GET_MAP_OB (m, dx, dy); ob2 != NULL; ob2 = ob2->above)
389 { 393 {
390 object *new_ob; 394 object *new_ob;
391 395
392 new_ob = ob2->head ? ob2->head : ob2; 396 new_ob = ob2->head ? ob2->head : ob2;
397
393 if (new_ob == ob) 398 if (new_ob == ob)
394 break; 399 break;
400
395 if (new_ob == ob->owner) 401 if (new_ob == ob->owner)
396 return; 402 return;
403
397 if (new_ob->owner == ob->owner) 404 if (new_ob->owner == ob->owner)
398 break; 405 break;
399 406
400 /* Hmm. Did we try to move into an enemy monster? If so, 407 /* Hmm. Did we try to move into an enemy monster? If so,
401 * make it our enemy. 408 * make it our enemy.
416 } 423 }
417 } 424 }
418 } 425 }
419 /* Try a different course */ 426 /* Try a different course */
420 dir = absdir (dir + 4 - (rndm (5)) - (rndm (5))); 427 dir = absdir (dir + 4 - (rndm (5)) - (rndm (5)));
421 (void) move_ob (ob, dir, ob); 428 move_ob (ob, dir, ob);
422 } 429 }
423 return;
424} 430}
425 431
426/**************************************************************************** 432/****************************************************************************
427 * 433 *
428 * GOLEM SPELL CODE 434 * GOLEM SPELL CODE
433 * proper for map insertion. 439 * proper for map insertion.
434 * at is the archetype, op is the caster of the spell, dir is the 440 * at is the archetype, op is the caster of the spell, dir is the
435 * direction the monster should be placed in. 441 * direction the monster should be placed in.
436 * is_golem is to note that this is a golem spell. 442 * is_golem is to note that this is a golem spell.
437 */ 443 */
438object * 444static object *
439fix_summon_pet (archetype *at, object *op, int dir, int is_golem) 445fix_summon_pet (archetype *at, object *op, int dir, int is_golem)
440{ 446{
441 object *tmp = NULL, *prev = NULL, *head = NULL; 447 object *tmp = NULL, *prev = NULL, *head = NULL;
442 448
443 for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more) 449 for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more)
532 return; /* Has already been moved */ 538 return; /* Has already been moved */
533 539
534 if (!op->owner) 540 if (!op->owner)
535 { 541 {
536 LOG (llevDebug, "Golem without owner destructed.\n"); 542 LOG (llevDebug, "Golem without owner destructed.\n");
537 op->remove ();
538 op->destroy (); 543 op->drop_and_destroy ();
539 return; 544 return;
540 } 545 }
541 546
542 /* It would be nice to have a cleaner way of what message to print 547 /* It would be nice to have a cleaner way of what message to print
543 * when the golem expires than these hard coded entries. 548 * when the golem expires than these hard coded entries.
547 if (--op->stats.hp < 0) 552 if (--op->stats.hp < 0)
548 { 553 {
549 if (op->msg) 554 if (op->msg)
550 new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg); 555 new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg);
551 556
552 op->destroy (); 557 op->drop_and_destroy ();
553 return; 558 return;
554 } 559 }
555 560
556 /* Do golem attacks/movement for single & multisq golems. 561 /* Do golem attacks/movement for single & multisq golems.
557 * Assuming here that op is the 'head' object. Pass only op to 562 * Assuming here that op is the 'head' object. Pass only op to
575 mflags = get_map_flags (m, &m, x, y, &x, &y); 580 mflags = get_map_flags (m, &m, x, y, &x, &y);
576 581
577 if (mflags & P_OUT_OF_MAP) 582 if (mflags & P_OUT_OF_MAP)
578 continue; 583 continue;
579 584
580 for (victim = GET_MAP_OB (op->map, x, y); victim; victim = victim->above) 585 for (victim = GET_MAP_OB (m, x, y); victim; victim = victim->above)
581 if (QUERY_FLAG (victim, FLAG_ALIVE)) 586 if (QUERY_FLAG (victim, FLAG_ALIVE))
582 break; 587 break;
583 588
584 /* We used to call will_hit_self to make sure we don't 589 /* We used to call will_hit_self to make sure we don't
585 * hit ourselves, but that didn't work, and I don't really 590 * hit ourselves, but that didn't work, and I don't really
592 { 597 {
593 /* for golems with race fields, we don't attack 598 /* for golems with race fields, we don't attack
594 * aligned races 599 * aligned races
595 */ 600 */
596 601
597 if (victim->race && op->race && strstr (op->race, victim->race)) 602 if (victim->race && op->race && op->race.contains (victim->race))
598 { 603 {
599 if (op->owner) 604 if (op->owner)
600 new_draw_info_format (NDI_UNIQUE, 0, op->owner, "%s avoids damaging %s.", &op->name, &victim->name); 605 new_draw_info_format (NDI_UNIQUE, 0, op->owner, "%s avoids damaging %s.", &op->name, &victim->name);
601 } 606 }
602 else if (victim == op->owner) 607 else if (victim == op->owner)
625control_golem (object *op, int dir) 630control_golem (object *op, int dir)
626{ 631{
627 op->direction = dir; 632 op->direction = dir;
628} 633}
629 634
630/* summon golem: summons a monster for 'op'. caster is the object 635/* summon golem: summons a monster for 'op'. caster is the object
631 * casting the spell, dir is the direction to place the monster, 636 * casting the spell, dir is the direction to place the monster,
632 * at is the archetype of the monster, and spob is the spell 637 * at is the archetype of the monster, and spob is the spell
633 * object. At this stage, all spob is really used for is to 638 * object. At this stage, all spob is really used for is to
634 * adjust some values in the monster. 639 * adjust some values in the monster.
635 */ 640 */
636int 641int
637summon_golem (object *op, object *caster, int dir, object *spob) 642summon_golem (object *op, object *caster, int dir, object *spob)
638{ 643{
639 object *tmp, *god = NULL; 644 object *tmp, *god = NULL;
640 archetype *at; 645 archetype *at;
641 char buf[MAX_BUF];
642 646
643 /* Because there can be different golem spells, player may want to 647 /* Because there can be different golem spells, player may want to
644 * 'lose' their old golem. 648 * 'lose' their old golem.
645 */ 649 */
646 if (op->type == PLAYER && op->contr->golem) 650 if (op->type == PLAYER && op->contr->golem)
647 { 651 {
648 new_draw_info (NDI_UNIQUE, 0, op, "You dismiss your existing golem."); 652 new_draw_info (NDI_UNIQUE, 0, op, "You dismiss your existing golem.");
649 op->contr->golem->remove ();
650 op->contr->golem->destroy (); 653 op->contr->golem->drop_and_destroy ();
651 op->contr->golem = 0; 654 op->contr->golem = 0;
652 } 655 }
653 656
654 if (spob->other_arch) 657 if (spob->other_arch)
655 at = spob->other_arch; 658 at = spob->other_arch;
678 } 681 }
679 682
680 if (!dir) 683 if (!dir)
681 dir = find_free_spot (at, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1); 684 dir = find_free_spot (at, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1);
682 685
683 if (dir < 0 || ob_blocked (at, op->map, op->x + freearr_x[dir], op->y + freearr_y[dir])) 686 if (dir < 0 || at->blocked (op->map, op->x + freearr_x[dir], op->y + freearr_y[dir]))
684 { 687 {
685 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); 688 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way.");
686 return 0; 689 return 0;
687 } 690 }
688 691
695 } 698 }
696 699
697 if (op->type == PLAYER) 700 if (op->type == PLAYER)
698 { 701 {
699 tmp->type = GOLEM; 702 tmp->type = GOLEM;
700 tmp->set_owner (op);
701 op->contr->golem = tmp; 703 op->contr->golem = tmp;
702 /* give the player control of the golem */ 704 /* give the player control of the golem */
703 set_spell_skill (op, caster, spob, tmp); 705 set_spell_skill (op, caster, spob, tmp);
704 } 706 }
705 else
706 {
707 if (QUERY_FLAG (op, FLAG_FRIENDLY))
708 {
709 object *owner = op->owner;
710 707
711 if (owner)
712 { /* For now, we transfer ownership */
713 tmp->set_owner (owner);
714 tmp->attack_movement = PETMOVE;
715 add_friendly_object (tmp);
716 }
717 }
718
719 SET_FLAG (tmp, FLAG_MONSTER);
720 }
721
722 /* make the speed positive. */
723 tmp->speed = FABS (tmp->speed);
724
725 /* This sets the level dependencies on dam and hp for monsters */ 708 /* This sets the level dependencies on dam and hp for monsters */
726 /* players can't cope with too strong summonings. */ 709 /* players can't cope with too strong summonings. */
727 /* but monsters can. reserve these for players. */ 710 /* but monsters can. reserve these for players. */
728 if (op->type == PLAYER) 711 if (op->type == PLAYER)
729 { 712 {
730 tmp->stats.hp += spob->duration + SP_level_duration_adjust (caster, spob); 713 tmp->stats.hp += spob->duration + SP_level_duration_adjust (caster, spob);
733 tmp->stats.dam += SP_level_dam_adjust (caster, spob); 716 tmp->stats.dam += SP_level_dam_adjust (caster, spob);
734 else 717 else
735 tmp->stats.dam = spob->stats.dam + SP_level_dam_adjust (caster, spob); 718 tmp->stats.dam = spob->stats.dam + SP_level_dam_adjust (caster, spob);
736 719
737 tmp->speed += .02 * SP_level_range_adjust (caster, spob); 720 tmp->speed += .02 * SP_level_range_adjust (caster, spob);
738 tmp->speed = MIN (tmp->speed, 1.0); 721 tmp->speed = min (tmp->speed, 1.0);
739 722
740 if (spob->attacktype) 723 if (spob->attacktype)
741 tmp->attacktype = spob->attacktype; 724 tmp->attacktype = spob->attacktype;
742 } 725 }
743 726
747 730
748 /* make experience increase in proportion to the strength. 731 /* make experience increase in proportion to the strength.
749 * this is a bit simplistic - we are basically just looking at how 732 * this is a bit simplistic - we are basically just looking at how
750 * often the sp doubles and use that as the ratio. 733 * often the sp doubles and use that as the ratio.
751 */ 734 */
752 tmp->stats.exp *= 1 + (MAX (spob->stats.maxgrace, spob->stats.sp) / caster_level (caster, spob)); 735 tmp->stats.exp *= 1 + max (spob->stats.maxgrace, spob->stats.sp) / casting_level (caster, spob);
753 tmp->speed_left = 0; 736 tmp->speed_left = 0;
754 tmp->direction = dir; 737 tmp->direction = dir;
755 738
756 /* Holy spell - some additional tailoring */ 739 /* Holy spell - some additional tailoring */
757 if (god) 740 if (god)
758 { 741 {
759 object *tmp2;
760
761 sprintf (buf, "%s of %s", &spob->name, &god->name); 742 char *buf = format ("%s of %s", &spob->name, &god->name);
762 buf[0] = toupper (buf[0]); 743 buf[0] = toupper (buf[0]);
763 744
764 for (tmp2 = tmp; tmp2; tmp2 = tmp2->more) 745 for (object *tmp2 = tmp; tmp2; tmp2 = tmp2->more)
765 tmp2->name = buf; 746 tmp2->name = buf;
766 747
767 tmp->attacktype |= god->attacktype; 748 tmp->attacktype |= god->attacktype;
768 memcpy (tmp->resist, god->resist, sizeof (tmp->resist)); 749 memcpy (tmp->resist, god->resist, sizeof (tmp->resist));
769 tmp->race = god->race; 750 tmp->race = god->race;
773 if (!(tmp->attacktype & AT_PHYSICAL)) 754 if (!(tmp->attacktype & AT_PHYSICAL))
774 tmp->attacktype |= AT_PHYSICAL; 755 tmp->attacktype |= AT_PHYSICAL;
775 } 756 }
776 757
777 insert_ob_in_map (tmp, tmp->map, op, 0); 758 insert_ob_in_map (tmp, tmp->map, op, 0);
759
778 return 1; 760 return 1;
779} 761}
780 762
781 763
782/*************************************************************************** 764/***************************************************************************
788/* Returns a monster (chosen at random) that this particular player (and his 770/* Returns a monster (chosen at random) that this particular player (and his
789 * god) find acceptable. This checks level, races allowed by god, etc 771 * god) find acceptable. This checks level, races allowed by god, etc
790 * to determine what is acceptable. 772 * to determine what is acceptable.
791 * This returns NULL if no match was found. 773 * This returns NULL if no match was found.
792 */ 774 */
793 775static object *
794object *
795choose_cult_monster (object *pl, object *god, int summon_level) 776choose_cult_monster (object *pl, object *god, int summon_level)
796{ 777{
797 char buf[MAX_BUF]; 778 char buf[MAX_BUF];
798 const char *race; 779 const char *race;
799 int racenr, mon_nr, i; 780 int racenr, mon_nr, i;
853 * a valid entry, assuming nothing is available and quit. 834 * a valid entry, assuming nothing is available and quit.
854 */ 835 */
855 if (!mon_nr) 836 if (!mon_nr)
856 return NULL; 837 return NULL;
857 838
858 mon_nr = rndm (0, mon_nr - 1); 839 mon_nr = rndm (mon_nr - 1);
859 for (tobl = list->member; tobl; tobl = tobl->next) 840 for (tobl = list->member; tobl; tobl = tobl->next)
860 { 841 {
861 otmp = tobl->ob; 842 otmp = tobl->ob;
862 if (!otmp || !QUERY_FLAG (otmp, FLAG_MONSTER)) 843 if (!otmp || !QUERY_FLAG (otmp, FLAG_MONSTER))
863 continue; 844 continue;
845
864 if (otmp->level <= summon_level && !mon_nr--) 846 if (otmp->level <= summon_level && !mon_nr--)
865 return otmp; 847 return otmp;
866 } 848 }
849
867 /* This should not happen */ 850 /* This should not happen */
868 LOG (llevDebug, "choose_cult_monster() mon_nr was set, but did not find a monster\n"); 851 LOG (llevDebug, "choose_cult_monster() mon_nr was set, but did not find a monster\n");
869 return NULL; 852 return NULL;
870} 853}
871 854
872int 855int
873summon_object (object *op, object *caster, object *spell_ob, int dir, const char *stringarg) 856summon_object (object *op, object *caster, object *spell_ob, int dir, const char *stringarg)
874{ 857{
875 sint16 x, y, nrof = 1, i; 858 int nrof = 1;
876 archetype *summon_arch; 859 archetype *summon_arch;
877 int ndir; 860 int ndir;
878 861
879 if (spell_ob->other_arch) 862 if (spell_ob->other_arch)
880 summon_arch = spell_ob->other_arch; 863 summon_arch = spell_ob->other_arch;
881 else if (spell_ob->randomitems) 864 else if (spell_ob->randomitems)
882 { 865 {
883 int level = caster_level (caster, spell_ob); 866 int level = casting_level (caster, spell_ob);
884 treasure *tr, *lasttr = NULL; 867 treasure *tr, *lasttr = NULL;
885 868
886 shstr_cmp sparam (stringarg); 869 shstr_cmp sparam (stringarg);
887 870
888 /* In old code, this was a very convoluted for statement, 871 /* In old code, this was a very convoluted for statement,
911 } 894 }
912 895
913 summon_arch = lasttr->item; 896 summon_arch = lasttr->item;
914 nrof = lasttr->nrof; 897 nrof = lasttr->nrof;
915 } 898 }
916 else if (spell_ob->race && !strcmp (spell_ob->race, "GODCULTMON")) 899 else if (spell_ob->race == shstr_GODCULTMON)
917 { 900 {
918 object *god = find_god (determine_god (op)), *mon, *owner; 901 object *god = find_god (determine_god (op)), *mon, *owner;
919 int summon_level, tries; 902 int summon_level, tries;
920 903
921 if (!god && ((owner = op->owner) != NULL)) 904 if (!god && ((owner = op->owner) != NULL))
930 new_draw_info_format (NDI_UNIQUE, 0, op, "%s has no creatures that you may summon!", &god->name); 913 new_draw_info_format (NDI_UNIQUE, 0, op, "%s has no creatures that you may summon!", &god->name);
931 return 0; 914 return 0;
932 } 915 }
933 916
934 /* the summon level */ 917 /* the summon level */
935 summon_level = caster_level (caster, spell_ob); 918 summon_level = casting_level (caster, spell_ob);
936 if (summon_level == 0) 919 if (summon_level == 0)
937 summon_level = 1; 920 summon_level = 1;
938 921
939 tries = 0; 922 tries = 0;
940 do 923 do
949 ndir = dir; 932 ndir = dir;
950 933
951 if (!ndir) 934 if (!ndir)
952 ndir = find_free_spot (mon, op->map, op->x, op->y, 1, SIZEOFFREE); 935 ndir = find_free_spot (mon, op->map, op->x, op->y, 1, SIZEOFFREE);
953 936
954 if (ndir < 0 || ob_blocked (mon, op->map, op->x + freearr_x[ndir], op->y + freearr_y[ndir])) 937 if (ndir < 0 || mon->blocked (op->map, op->x + freearr_x[ndir], op->y + freearr_y[ndir]))
955 { 938 {
956 ndir = -1; 939 ndir = -1;
957 if (++tries == 5) 940 if (++tries == 5)
958 { 941 {
959 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); 942 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way.");
980 { 963 {
981 new_draw_info (NDI_UNIQUE, 0, op, "There is no monsters available for summoning."); 964 new_draw_info (NDI_UNIQUE, 0, op, "There is no monsters available for summoning.");
982 return 0; 965 return 0;
983 } 966 }
984 967
985 for (i = 1; i <= nrof; i++) 968 for (int i = 1; i <= nrof; i++)
986 { 969 {
987 object *prev = NULL, *head = NULL, *tmp; 970 object *prev = NULL, *head = NULL, *tmp;
988 971
989 if (dir) 972 if (dir)
990 { 973 {
992 dir = absdir (dir + 1); 975 dir = absdir (dir + 1);
993 } 976 }
994 else 977 else
995 ndir = find_free_spot (summon_arch, op->map, op->x, op->y, 1, SIZEOFFREE); 978 ndir = find_free_spot (summon_arch, op->map, op->x, op->y, 1, SIZEOFFREE);
996 979
997 if (ndir > 0)
998 {
999 x = freearr_x[ndir]; 980 sint16 x = freearr_x [ndir];
1000 y = freearr_y[ndir]; 981 sint16 y = freearr_y [ndir];
1001 }
1002 982
1003 if (ndir < 0 || ob_blocked (summon_arch, op->map, op->x + x, op->y + y)) 983 if (ndir < 0 || summon_arch->blocked (op->map, op->x + x, op->y + y))
1004 { 984 {
1005 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); 985 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way.");
1006 if (nrof > 1) 986 if (nrof > 1)
1007 new_draw_info (NDI_UNIQUE, 0, op, "No more pets for this casting."); 987 new_draw_info (NDI_UNIQUE, 0, op, "No more pets for this casting.");
1008 988
1009 return nrof > 1; 989 return nrof > 1;
1010 } 990 }
1011 991
1012 for (archetype *atmp = summon_arch; atmp != NULL; atmp = (archetype *)atmp->more) 992 for (archetype *atmp = summon_arch; atmp; atmp = (archetype *)atmp->more)
1013 { 993 {
1014 tmp = arch_to_object (atmp); 994 tmp = arch_to_object (atmp);
1015 if (atmp == summon_arch) 995 if (atmp == summon_arch)
1016 { 996 {
1017 if (QUERY_FLAG (tmp, FLAG_MONSTER)) 997 if (QUERY_FLAG (tmp, FLAG_MONSTER))
1071 } /* for i < nrof */ 1051 } /* for i < nrof */
1072 1052
1073 return 1; 1053 return 1;
1074} 1054}
1075 1055
1076/* recursively look through the owner property of objects until the real owner
1077is found */
1078object *
1079get_real_owner (object *ob)
1080{
1081 object *realowner = ob;
1082
1083 if (realowner == NULL)
1084 return NULL;
1085
1086 while (realowner->owner != NULL)
1087 {
1088 realowner = realowner->owner;
1089 }
1090 return realowner;
1091}
1092
1093/* determines if checks so pets don't attack players or other pets should be 1056/* determines if checks so pets don't attack players or other pets should be
1094overruled by the arena petmode */ 1057overruled by the arena petmode */
1095int 1058int
1096should_arena_attack (object *pet, object *owner, object *target) 1059should_arena_attack (object *pet, object *owner, object *target)
1097{ 1060{
1101 if ((target == NULL) || (pet == NULL) || (owner == NULL)) 1064 if ((target == NULL) || (pet == NULL) || (owner == NULL))
1102 return 0; 1065 return 0;
1103 1066
1104 /* get the owners of itself and the target, this is to deal with pets of 1067 /* get the owners of itself and the target, this is to deal with pets of
1105 pets */ 1068 pets */
1106 rowner = get_real_owner (owner); 1069 rowner = owner->outer_owner ();
1107 towner = target->type == PLAYER ? 0 : get_real_owner (target); 1070 towner = target->is_player () ? 0 : target->outer_owner ();
1108 1071
1109 /* if the pet has now owner, exit with error */ 1072 /* if the pet has now owner, exit with error */
1110 if (!rowner) 1073 if (!rowner)
1111 { 1074 {
1112 LOG (llevError, "Pet has no owner.\n"); 1075 LOG (llevError, "Pet has no owner.\n");
1113 return 0; 1076 return 0;
1114 } 1077 }
1115 1078
1116 /* if the target is not a player, and has no owner, we shouldn't be here 1079 /* if the target is not a player, and has no owner, we shouldn't be here
1117 */ 1080 */
1118 if ((towner == NULL) && (target->type != PLAYER)) 1081 if (!towner && !target->is_player ())
1119 { 1082 {
1120 LOG (llevError, "Target is not a player but has no owner. We should not be here.\n"); 1083 LOG (llevError, "Target is not a player but has no owner. We should not be here.\n");
1121 return 0; 1084 return 0;
1122 } 1085 }
1123 1086
1124 /* make sure that the owner is a player */ 1087 /* make sure that the owner is a player */
1125 if (rowner->type != PLAYER) 1088 if (!rowner->is_player ())
1126 return 0; 1089 return 0;
1127 1090
1128 /* abort if the petmode is not arena */ 1091 /* abort if the petmode is not arena */
1129 if (rowner->contr->petmode != pet_arena) 1092 if (rowner->contr->petmode != pet_arena)
1130 return 0; 1093 return 0;
1132 /* abort if the pet, it's owner, or the target is not on battleground */ 1095 /* abort if the pet, it's owner, or the target is not on battleground */
1133 if (!(op_on_battleground (pet, NULL, NULL) && op_on_battleground (owner, NULL, NULL) && op_on_battleground (target, NULL, NULL))) 1096 if (!(op_on_battleground (pet, NULL, NULL) && op_on_battleground (owner, NULL, NULL) && op_on_battleground (target, NULL, NULL)))
1134 return 0; 1097 return 0;
1135 1098
1136 /* if the target is a monster, make sure it's owner is not the same */ 1099 /* if the target is a monster, make sure it's owner is not the same */
1137 if ((target->type != PLAYER) && (rowner == towner)) 1100 if (!target->is_player () && rowner == towner)
1138 return 0; 1101 return 0;
1139 1102
1140 /* check if the target is a player which affects how it will handle 1103 /* check if the target is a player which affects how it will handle
1141 parties */ 1104 parties */
1142 if (target->type != PLAYER) 1105 if (!target->is_player ())
1143 { 1106 {
1144 /* if the target is owned by a player make sure than make sure 1107 /* if the target is owned by a player make sure than make sure
1145 it's not in the same party */ 1108 it's not in the same party */
1146 if ((towner->type == PLAYER) && (rowner->contr->party != NULL)) 1109 if (towner->is_player () && rowner->contr->party)
1147 {
1148 if (rowner->contr->party == towner->contr->party) 1110 if (rowner->contr->party == towner->contr->party)
1149 return 0; 1111 return 0;
1150 }
1151 } 1112 }
1152 else 1113 else
1153 { 1114 {
1154 /* if the target is a player make sure than make sure it's not 1115 /* if the target is a player make sure than make sure it's not
1155 in the same party */ 1116 in the same party */
1156 if (rowner->contr->party != NULL) 1117 if (rowner->contr->party)
1157 {
1158 if (rowner->contr->party == target->contr->party) 1118 if (rowner->contr->party == target->contr->party)
1159 return 0; 1119 return 0;
1160 }
1161 } 1120 }
1162 1121
1163 return 1; 1122 return 1;
1164} 1123}
1124

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines