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.31 by root, Sun May 6 04:49:37 2007 UTC vs.
Revision 1.50 by root, Thu Jan 1 15:43:35 2009 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game for X-windows 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version. 11 * (at your 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 GNU General Public License
19 * along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * 20 *
22 * The authors can be reached via e-mail at <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 22 */
24 23
25#include <global.h> 24#include <global.h>
26#include <sproto.h> 25#include <sproto.h>
27 26
32 * this is now tilemap aware. 31 * this is now tilemap aware.
33 */ 32 */
34object * 33object *
35get_pet_enemy (object *pet, rv_vector * rv) 34get_pet_enemy (object *pet, rv_vector * rv)
36{ 35{
37 object *owner, *tmp, *attacker, *tmp3; 36 object *tmp, *attacker, *tmp3;
38 int i; 37 int i;
39 sint16 x, y; 38 sint16 x, y;
40 maptile *nm; 39 maptile *nm;
41 int search_arr[SIZEOFFREE]; 40 int search_arr[SIZEOFFREE];
42 int mflags; 41 int mflags;
43 42
44 attacker = pet->attacked_by; /*pointer to attacking enemy */ 43 attacker = pet->attacked_by; /*pointer to attacking enemy */
45 pet->attacked_by = NULL; /*clear this, since we are dealing with it */ 44 pet->attacked_by = NULL; /*clear this, since we are dealing with it */
46 45
47 if (owner = pet->owner) 46 object *owner = pet->owner;
48 { 47
49 /* If the owner has turned on the pet, make the pet 48 if (!owner)
50 * unfriendly.
51 */
52 if (check_enemy (owner, rv) == pet)
53 {
54 remove_friendly_object (pet);
55 pet->attack_movement &= ~PETMOVE;
56 return owner;
57 }
58 } 49 {
59 else
60 {
61 /* else the owner is no longer around, so the 50 /* the owner is no longer around, so the
62 * pet no longer needs to be friendly. 51 * pet no longer needs to be friendly.
63 */ 52 */
64 remove_friendly_object (pet); 53 remove_friendly_object (pet);
65 pet->attack_movement &= ~PETMOVE; 54 pet->attack_movement &= ~PETMOVE;
66 return 0; 55 return 0;
56 }
57
58 /* If the owner has turned on the pet, make the pet
59 * unfriendly.
60 */
61 if (check_enemy (owner, rv) == pet)
62 {
63 remove_friendly_object (pet);
64 pet->attack_movement &= ~PETMOVE;
65 return owner;
67 } 66 }
68 67
69 /* If they are not on the same map, the pet won't be agressive */ 68 /* If they are not on the same map, the pet won't be agressive */
70 //if (!on_same_map (pet, owner)) 69 //if (!on_same_map (pet, owner))
71 // return 0; 70 // return 0;
255 { 254 {
256 object *ob = obl->ob; 255 object *ob = obl->ob;
257 next = obl->next; 256 next = obl->next;
258 257
259 if (ob->owner == owner) 258 if (ob->owner == owner)
260 ob->destroy (); 259 ob->drop_and_destroy ();
261 } 260 }
262} 261}
263 262
264/* 263/*
265 * Unfortunately, sometimes, the owner of a pet is in the 264 * Unfortunately, sometimes, the owner of a pet is in the
293int 292int
294follow_owner (object *ob, object *owner) 293follow_owner (object *ob, object *owner)
295{ 294{
296 if (owner->flag [FLAG_REMOVED]) 295 if (owner->flag [FLAG_REMOVED])
297 return 0; // do nothing if the owner is removed 296 return 0; // do nothing if the owner is removed
298 else if (owner->map->in_memory != MAP_IN_MEMORY) 297 else if (!owner->map || owner->map->in_memory != MAP_ACTIVE)
299 LOG (llevError, "Owner of the pet not on a map in memory!?\n"); 298 LOG (llevError, "owner '%s' of the pet '%s' not on a map in memory!?\n", &owner->name, &ob->name);
300 else 299 else
301 { 300 {
302 int dir = find_free_spot (ob, owner->map, owner->x, owner->y, 1, SIZEOFFREE); 301 int dir = find_free_spot (ob, owner->map, owner->x, owner->y, 1, SIZEOFFREE);
303 302
304 if (dir >= 0) 303 if (dir >= 0)
310 309
311 return 0; 310 return 0;
312 } 311 }
313 } 312 }
314 313
315 ob->destroy (); 314 ob->drop_and_destroy ();
315
316 return 1; 316 return 1;
317} 317}
318 318
319void 319void
320pet_move (object *ob) 320pet_move (object *ob)
325 maptile *m; 325 maptile *m;
326 326
327 /* Check to see if player pulled out */ 327 /* Check to see if player pulled out */
328 if ((owner = ob->owner) == NULL) 328 if ((owner = ob->owner) == NULL)
329 { 329 {
330 ob->destroy (); 330 ob->drop_and_destroy ();
331 LOG (llevMonster, "Pet: no owner, leaving.\n"); 331 LOG (llevMonster, "Pet: no owner, leaving.\n");
332 return; 332 return;
333 } 333 }
334 334
335 /* move monster into the owners map if not in the same map 335 /* move monster into the owners map if not in the same map
437 * is_golem is to note that this is a golem spell. 437 * is_golem is to note that this is a golem spell.
438 */ 438 */
439object * 439object *
440fix_summon_pet (archetype *at, object *op, int dir, int is_golem) 440fix_summon_pet (archetype *at, object *op, int dir, int is_golem)
441{ 441{
442 archetype *atmp;
443 object *tmp = NULL, *prev = NULL, *head = NULL; 442 object *tmp = NULL, *prev = NULL, *head = NULL;
444 443
445 for (atmp = at; atmp; atmp = atmp->more) 444 for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more)
446 { 445 {
447 tmp = arch_to_object (atmp); 446 tmp = arch_to_object (atmp);
448 447
449 if (atmp == at) 448 if (atmp == at)
450 { 449 {
451 if (!is_golem) 450 if (!is_golem)
452 SET_FLAG (tmp, FLAG_MONSTER); 451 SET_FLAG (tmp, FLAG_MONSTER);
453 452
454 tmp->set_owner (op); 453 tmp->set_owner (op);
454
455 if (op->type == PLAYER) 455 if (op->type == PLAYER)
456 { 456 {
457 tmp->stats.exp = 0; 457 tmp->stats.exp = 0;
458 add_friendly_object (tmp); 458 add_friendly_object (tmp);
459 if (is_golem) 459 if (is_golem)
487 } 487 }
488 488
489 if (!head) 489 if (!head)
490 head = tmp; 490 head = tmp;
491 491
492 tmp->x = op->x + freearr_x[dir] + tmp->arch->clone.x; 492 tmp->x = op->x + freearr_x[dir] + tmp->arch->x;
493 tmp->y = op->y + freearr_y[dir] + tmp->arch->clone.y; 493 tmp->y = op->y + freearr_y[dir] + tmp->arch->y;
494 tmp->map = op->map; 494 tmp->map = op->map;
495 495
496 if (tmp->invisible) 496 if (tmp->invisible)
497 tmp->invisible = 0; 497 tmp->invisible = 0;
498 498
533 return; /* Has already been moved */ 533 return; /* Has already been moved */
534 534
535 if (!op->owner) 535 if (!op->owner)
536 { 536 {
537 LOG (llevDebug, "Golem without owner destructed.\n"); 537 LOG (llevDebug, "Golem without owner destructed.\n");
538 op->remove ();
539 op->destroy (); 538 op->drop_and_destroy ();
540 return; 539 return;
541 } 540 }
542 541
543 /* It would be nice to have a cleaner way of what message to print 542 /* It would be nice to have a cleaner way of what message to print
544 * when the golem expires than these hard coded entries. 543 * when the golem expires than these hard coded entries.
548 if (--op->stats.hp < 0) 547 if (--op->stats.hp < 0)
549 { 548 {
550 if (op->msg) 549 if (op->msg)
551 new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg); 550 new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg);
552 551
553 op->destroy (); 552 op->drop_and_destroy ();
554 return; 553 return;
555 } 554 }
556 555
557 /* Do golem attacks/movement for single & multisq golems. 556 /* Do golem attacks/movement for single & multisq golems.
558 * Assuming here that op is the 'head' object. Pass only op to 557 * Assuming here that op is the 'head' object. Pass only op to
576 mflags = get_map_flags (m, &m, x, y, &x, &y); 575 mflags = get_map_flags (m, &m, x, y, &x, &y);
577 576
578 if (mflags & P_OUT_OF_MAP) 577 if (mflags & P_OUT_OF_MAP)
579 continue; 578 continue;
580 579
581 for (victim = GET_MAP_OB (op->map, x, y); victim; victim = victim->above) 580 for (victim = GET_MAP_OB (m, x, y); victim; victim = victim->above)
582 if (QUERY_FLAG (victim, FLAG_ALIVE)) 581 if (QUERY_FLAG (victim, FLAG_ALIVE))
583 break; 582 break;
584 583
585 /* We used to call will_hit_self to make sure we don't 584 /* We used to call will_hit_self to make sure we don't
586 * hit ourselves, but that didn't work, and I don't really 585 * hit ourselves, but that didn't work, and I don't really
593 { 592 {
594 /* for golems with race fields, we don't attack 593 /* for golems with race fields, we don't attack
595 * aligned races 594 * aligned races
596 */ 595 */
597 596
598 if (victim->race && op->race && strstr (op->race, victim->race)) 597 if (victim->race && op->race && op->race.contains (victim->race))
599 { 598 {
600 if (op->owner) 599 if (op->owner)
601 new_draw_info_format (NDI_UNIQUE, 0, op->owner, "%s avoids damaging %s.", &op->name, &victim->name); 600 new_draw_info_format (NDI_UNIQUE, 0, op->owner, "%s avoids damaging %s.", &op->name, &victim->name);
602 } 601 }
603 else if (victim == op->owner) 602 else if (victim == op->owner)
626control_golem (object *op, int dir) 625control_golem (object *op, int dir)
627{ 626{
628 op->direction = dir; 627 op->direction = dir;
629} 628}
630 629
631/* summon golem: summons a monster for 'op'. caster is the object 630/* summon golem: summons a monster for 'op'. caster is the object
632 * casting the spell, dir is the direction to place the monster, 631 * casting the spell, dir is the direction to place the monster,
633 * at is the archetype of the monster, and spob is the spell 632 * at is the archetype of the monster, and spob is the spell
634 * object. At this stage, all spob is really used for is to 633 * object. At this stage, all spob is really used for is to
635 * adjust some values in the monster. 634 * adjust some values in the monster.
636 */ 635 */
645 * 'lose' their old golem. 644 * 'lose' their old golem.
646 */ 645 */
647 if (op->type == PLAYER && op->contr->golem) 646 if (op->type == PLAYER && op->contr->golem)
648 { 647 {
649 new_draw_info (NDI_UNIQUE, 0, op, "You dismiss your existing golem."); 648 new_draw_info (NDI_UNIQUE, 0, op, "You dismiss your existing golem.");
650 op->contr->golem->remove ();
651 op->contr->golem->destroy (); 649 op->contr->golem->drop_and_destroy ();
652 op->contr->golem = 0; 650 op->contr->golem = 0;
653 } 651 }
654 652
655 if (spob->other_arch) 653 if (spob->other_arch)
656 at = spob->other_arch; 654 at = spob->other_arch;
677 LOG (llevError, "Spell %s lacks other_arch\n", &spob->name); 675 LOG (llevError, "Spell %s lacks other_arch\n", &spob->name);
678 return 0; 676 return 0;
679 } 677 }
680 678
681 if (!dir) 679 if (!dir)
682 dir = find_free_spot (&at->clone, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1); 680 dir = find_free_spot (at, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1);
683 681
684 if (dir < 0 || ob_blocked (&at->clone, op->map, op->x + freearr_x[dir], op->y + freearr_y[dir])) 682 if (dir < 0 || at->blocked (op->map, op->x + freearr_x[dir], op->y + freearr_y[dir]))
685 { 683 {
686 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); 684 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way.");
687 return 0; 685 return 0;
688 } 686 }
689 687
696 } 694 }
697 695
698 if (op->type == PLAYER) 696 if (op->type == PLAYER)
699 { 697 {
700 tmp->type = GOLEM; 698 tmp->type = GOLEM;
701 tmp->set_owner (op);
702 op->contr->golem = tmp; 699 op->contr->golem = tmp;
703 /* give the player control of the golem */ 700 /* give the player control of the golem */
704 set_spell_skill (op, caster, spob, tmp); 701 set_spell_skill (op, caster, spob, tmp);
705 } 702 }
706 else
707 {
708 if (QUERY_FLAG (op, FLAG_FRIENDLY))
709 {
710 object *owner = op->owner;
711
712 if (owner)
713 { /* For now, we transfer ownership */
714 tmp->set_owner (owner);
715 tmp->attack_movement = PETMOVE;
716 add_friendly_object (tmp);
717 }
718 }
719
720 SET_FLAG (tmp, FLAG_MONSTER);
721 }
722 703
723 /* make the speed positive. */ 704 /* make the speed positive. */
724 tmp->speed = FABS (tmp->speed); 705 tmp->speed = fabs (tmp->speed);
725 706
726 /* This sets the level dependencies on dam and hp for monsters */ 707 /* This sets the level dependencies on dam and hp for monsters */
727 /* players can't cope with too strong summonings. */ 708 /* players can't cope with too strong summonings. */
728 /* but monsters can. reserve these for players. */ 709 /* but monsters can. reserve these for players. */
729 if (op->type == PLAYER) 710 if (op->type == PLAYER)
734 tmp->stats.dam += SP_level_dam_adjust (caster, spob); 715 tmp->stats.dam += SP_level_dam_adjust (caster, spob);
735 else 716 else
736 tmp->stats.dam = spob->stats.dam + SP_level_dam_adjust (caster, spob); 717 tmp->stats.dam = spob->stats.dam + SP_level_dam_adjust (caster, spob);
737 718
738 tmp->speed += .02 * SP_level_range_adjust (caster, spob); 719 tmp->speed += .02 * SP_level_range_adjust (caster, spob);
739 tmp->speed = MIN (tmp->speed, 1.0); 720 tmp->speed = min (tmp->speed, 1.0);
740 721
741 if (spob->attacktype) 722 if (spob->attacktype)
742 tmp->attacktype = spob->attacktype; 723 tmp->attacktype = spob->attacktype;
743 } 724 }
744 725
748 729
749 /* make experience increase in proportion to the strength. 730 /* make experience increase in proportion to the strength.
750 * this is a bit simplistic - we are basically just looking at how 731 * this is a bit simplistic - we are basically just looking at how
751 * often the sp doubles and use that as the ratio. 732 * often the sp doubles and use that as the ratio.
752 */ 733 */
753 tmp->stats.exp *= 1 + (MAX (spob->stats.maxgrace, spob->stats.sp) / caster_level (caster, spob)); 734 tmp->stats.exp *= 1 + max (spob->stats.maxgrace, spob->stats.sp) / casting_level (caster, spob);
754 tmp->speed_left = 0; 735 tmp->speed_left = 0;
755 tmp->direction = dir; 736 tmp->direction = dir;
756 737
757 /* Holy spell - some additional tailoring */ 738 /* Holy spell - some additional tailoring */
758 if (god) 739 if (god)
774 if (!(tmp->attacktype & AT_PHYSICAL)) 755 if (!(tmp->attacktype & AT_PHYSICAL))
775 tmp->attacktype |= AT_PHYSICAL; 756 tmp->attacktype |= AT_PHYSICAL;
776 } 757 }
777 758
778 insert_ob_in_map (tmp, tmp->map, op, 0); 759 insert_ob_in_map (tmp, tmp->map, op, 0);
760
779 return 1; 761 return 1;
780} 762}
781 763
782 764
783/*************************************************************************** 765/***************************************************************************
789/* Returns a monster (chosen at random) that this particular player (and his 771/* Returns a monster (chosen at random) that this particular player (and his
790 * god) find acceptable. This checks level, races allowed by god, etc 772 * god) find acceptable. This checks level, races allowed by god, etc
791 * to determine what is acceptable. 773 * to determine what is acceptable.
792 * This returns NULL if no match was found. 774 * This returns NULL if no match was found.
793 */ 775 */
794
795object * 776object *
796choose_cult_monster (object *pl, object *god, int summon_level) 777choose_cult_monster (object *pl, object *god, int summon_level)
797{ 778{
798 char buf[MAX_BUF]; 779 char buf[MAX_BUF];
799 const char *race; 780 const char *race;
854 * a valid entry, assuming nothing is available and quit. 835 * a valid entry, assuming nothing is available and quit.
855 */ 836 */
856 if (!mon_nr) 837 if (!mon_nr)
857 return NULL; 838 return NULL;
858 839
859 mon_nr = rndm (0, mon_nr - 1); 840 mon_nr = rndm (mon_nr - 1);
860 for (tobl = list->member; tobl; tobl = tobl->next) 841 for (tobl = list->member; tobl; tobl = tobl->next)
861 { 842 {
862 otmp = tobl->ob; 843 otmp = tobl->ob;
863 if (!otmp || !QUERY_FLAG (otmp, FLAG_MONSTER)) 844 if (!otmp || !QUERY_FLAG (otmp, FLAG_MONSTER))
864 continue; 845 continue;
846
865 if (otmp->level <= summon_level && !mon_nr--) 847 if (otmp->level <= summon_level && !mon_nr--)
866 return otmp; 848 return otmp;
867 } 849 }
850
868 /* This should not happen */ 851 /* This should not happen */
869 LOG (llevDebug, "choose_cult_monster() mon_nr was set, but did not find a monster\n"); 852 LOG (llevDebug, "choose_cult_monster() mon_nr was set, but did not find a monster\n");
870 return NULL; 853 return NULL;
871} 854}
872 855
879 862
880 if (spell_ob->other_arch) 863 if (spell_ob->other_arch)
881 summon_arch = spell_ob->other_arch; 864 summon_arch = spell_ob->other_arch;
882 else if (spell_ob->randomitems) 865 else if (spell_ob->randomitems)
883 { 866 {
884 int level = caster_level (caster, spell_ob); 867 int level = casting_level (caster, spell_ob);
885 treasure *tr, *lasttr = NULL; 868 treasure *tr, *lasttr = NULL;
886 869
887 shstr_cmp sparam (stringarg); 870 shstr_cmp sparam (stringarg);
888 871
889 /* In old code, this was a very convoluted for statement, 872 /* In old code, this was a very convoluted for statement,
898 if (level < tr->magic) 881 if (level < tr->magic)
899 break; 882 break;
900 883
901 lasttr = tr; 884 lasttr = tr;
902 885
903 if (tr->item->name == sparam) 886 if (tr->item->archname == sparam)
904 break; 887 break;
905 } 888 }
906 889
907 if (!lasttr) 890 if (!lasttr)
908 { 891 {
931 new_draw_info_format (NDI_UNIQUE, 0, op, "%s has no creatures that you may summon!", &god->name); 914 new_draw_info_format (NDI_UNIQUE, 0, op, "%s has no creatures that you may summon!", &god->name);
932 return 0; 915 return 0;
933 } 916 }
934 917
935 /* the summon level */ 918 /* the summon level */
936 summon_level = caster_level (caster, spell_ob); 919 summon_level = casting_level (caster, spell_ob);
937 if (summon_level == 0) 920 if (summon_level == 0)
938 summon_level = 1; 921 summon_level = 1;
939 922
940 tries = 0; 923 tries = 0;
941 do 924 do
950 ndir = dir; 933 ndir = dir;
951 934
952 if (!ndir) 935 if (!ndir)
953 ndir = find_free_spot (mon, op->map, op->x, op->y, 1, SIZEOFFREE); 936 ndir = find_free_spot (mon, op->map, op->x, op->y, 1, SIZEOFFREE);
954 937
955 if (ndir < 0 || ob_blocked (mon, op->map, op->x + freearr_x[ndir], op->y + freearr_y[ndir])) 938 if (ndir < 0 || mon->blocked (op->map, op->x + freearr_x[ndir], op->y + freearr_y[ndir]))
956 { 939 {
957 ndir = -1; 940 ndir = -1;
958 if (++tries == 5) 941 if (++tries == 5)
959 { 942 {
960 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); 943 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way.");
983 return 0; 966 return 0;
984 } 967 }
985 968
986 for (i = 1; i <= nrof; i++) 969 for (i = 1; i <= nrof; i++)
987 { 970 {
988 archetype *atmp;
989 object *prev = NULL, *head = NULL, *tmp; 971 object *prev = NULL, *head = NULL, *tmp;
990 972
991 if (dir) 973 if (dir)
992 { 974 {
993 ndir = dir; 975 ndir = dir;
994 dir = absdir (dir + 1); 976 dir = absdir (dir + 1);
995 } 977 }
996 else 978 else
997 ndir = find_free_spot (&summon_arch->clone, op->map, op->x, op->y, 1, SIZEOFFREE); 979 ndir = find_free_spot (summon_arch, op->map, op->x, op->y, 1, SIZEOFFREE);
998 980
999 if (ndir > 0) 981 if (ndir > 0)
1000 { 982 {
1001 x = freearr_x[ndir]; 983 x = freearr_x[ndir];
1002 y = freearr_y[ndir]; 984 y = freearr_y[ndir];
1003 } 985 }
1004 986
1005 if (ndir < 0 || ob_blocked (&summon_arch->clone, op->map, op->x + x, op->y + y)) 987 if (ndir < 0 || summon_arch->blocked (op->map, op->x + x, op->y + y))
1006 { 988 {
1007 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); 989 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way.");
1008 if (nrof > 1) 990 if (nrof > 1)
1009 new_draw_info (NDI_UNIQUE, 0, op, "No more pets for this casting."); 991 new_draw_info (NDI_UNIQUE, 0, op, "No more pets for this casting.");
1010 992
1011 return nrof > 1; 993 return nrof > 1;
1012 } 994 }
1013 995
1014 for (atmp = summon_arch; atmp != NULL; atmp = atmp->more) 996 for (archetype *atmp = summon_arch; atmp != NULL; atmp = (archetype *)atmp->more)
1015 { 997 {
1016 tmp = arch_to_object (atmp); 998 tmp = arch_to_object (atmp);
1017 if (atmp == summon_arch) 999 if (atmp == summon_arch)
1018 { 1000 {
1019 if (QUERY_FLAG (tmp, FLAG_MONSTER)) 1001 if (QUERY_FLAG (tmp, FLAG_MONSTER))
1052 tmp->head = head; 1034 tmp->head = head;
1053 prev->more = tmp; 1035 prev->more = tmp;
1054 } 1036 }
1055 1037
1056 prev = tmp; 1038 prev = tmp;
1057 tmp->x = op->x + x + tmp->arch->clone.x; 1039 tmp->x = op->x + x + tmp->arch->x;
1058 tmp->y = op->y + y + tmp->arch->clone.y; 1040 tmp->y = op->y + y + tmp->arch->y;
1059 tmp->map = op->map; 1041 tmp->map = op->map;
1060 } 1042 }
1061 1043
1062 head->direction = freedir[ndir]; 1044 head->direction = freedir[ndir];
1063 head->stats.exp = 0; 1045 head->stats.exp = 0;
1071 SET_FLAG (tmp, FLAG_DESTROY_ON_DEATH); 1053 SET_FLAG (tmp, FLAG_DESTROY_ON_DEATH);
1072 } 1054 }
1073 } /* for i < nrof */ 1055 } /* for i < nrof */
1074 1056
1075 return 1; 1057 return 1;
1076}
1077
1078/* recursively look through the owner property of objects until the real owner
1079is found */
1080object *
1081get_real_owner (object *ob)
1082{
1083 object *realowner = ob;
1084
1085 if (realowner == NULL)
1086 return NULL;
1087
1088 while (realowner->owner != NULL)
1089 {
1090 realowner = realowner->owner;
1091 }
1092 return realowner;
1093} 1058}
1094 1059
1095/* determines if checks so pets don't attack players or other pets should be 1060/* determines if checks so pets don't attack players or other pets should be
1096overruled by the arena petmode */ 1061overruled by the arena petmode */
1097int 1062int
1103 if ((target == NULL) || (pet == NULL) || (owner == NULL)) 1068 if ((target == NULL) || (pet == NULL) || (owner == NULL))
1104 return 0; 1069 return 0;
1105 1070
1106 /* get the owners of itself and the target, this is to deal with pets of 1071 /* get the owners of itself and the target, this is to deal with pets of
1107 pets */ 1072 pets */
1108 rowner = get_real_owner (owner); 1073 rowner = owner->outer_owner ();
1109 towner = target->type == PLAYER ? 0 : get_real_owner (target); 1074 towner = target->is_player () ? 0 : target->outer_owner ();
1110 1075
1111 /* if the pet has now owner, exit with error */ 1076 /* if the pet has now owner, exit with error */
1112 if (!rowner) 1077 if (!rowner)
1113 { 1078 {
1114 LOG (llevError, "Pet has no owner.\n"); 1079 LOG (llevError, "Pet has no owner.\n");
1115 return 0; 1080 return 0;
1116 } 1081 }
1117 1082
1118 /* if the target is not a player, and has no owner, we shouldn't be here 1083 /* if the target is not a player, and has no owner, we shouldn't be here
1119 */ 1084 */
1120 if ((towner == NULL) && (target->type != PLAYER)) 1085 if (!towner && !target->is_player ())
1121 { 1086 {
1122 LOG (llevError, "Target is not a player but has no owner. We should not be here.\n"); 1087 LOG (llevError, "Target is not a player but has no owner. We should not be here.\n");
1123 return 0; 1088 return 0;
1124 } 1089 }
1125 1090
1126 /* make sure that the owner is a player */ 1091 /* make sure that the owner is a player */
1127 if (rowner->type != PLAYER) 1092 if (!rowner->is_player ())
1128 return 0; 1093 return 0;
1129 1094
1130 /* abort if the petmode is not arena */ 1095 /* abort if the petmode is not arena */
1131 if (rowner->contr->petmode != pet_arena) 1096 if (rowner->contr->petmode != pet_arena)
1132 return 0; 1097 return 0;
1134 /* abort if the pet, it's owner, or the target is not on battleground */ 1099 /* abort if the pet, it's owner, or the target is not on battleground */
1135 if (!(op_on_battleground (pet, NULL, NULL) && op_on_battleground (owner, NULL, NULL) && op_on_battleground (target, NULL, NULL))) 1100 if (!(op_on_battleground (pet, NULL, NULL) && op_on_battleground (owner, NULL, NULL) && op_on_battleground (target, NULL, NULL)))
1136 return 0; 1101 return 0;
1137 1102
1138 /* if the target is a monster, make sure it's owner is not the same */ 1103 /* if the target is a monster, make sure it's owner is not the same */
1139 if ((target->type != PLAYER) && (rowner == towner)) 1104 if (!target->is_player () && rowner == towner)
1140 return 0; 1105 return 0;
1141 1106
1142 /* check if the target is a player which affects how it will handle 1107 /* check if the target is a player which affects how it will handle
1143 parties */ 1108 parties */
1144 if (target->type != PLAYER) 1109 if (!target->is_player ())
1145 { 1110 {
1146 /* if the target is owned by a player make sure than make sure 1111 /* if the target is owned by a player make sure than make sure
1147 it's not in the same party */ 1112 it's not in the same party */
1148 if ((towner->type == PLAYER) && (rowner->contr->party != NULL)) 1113 if (towner->is_player () && rowner->contr->party)
1149 {
1150 if (rowner->contr->party == towner->contr->party) 1114 if (rowner->contr->party == towner->contr->party)
1151 return 0; 1115 return 0;
1152 }
1153 } 1116 }
1154 else 1117 else
1155 { 1118 {
1156 /* if the target is a player make sure than make sure it's not 1119 /* if the target is a player make sure than make sure it's not
1157 in the same party */ 1120 in the same party */
1158 if (rowner->contr->party != NULL) 1121 if (rowner->contr->party)
1159 {
1160 if (rowner->contr->party == target->contr->party) 1122 if (rowner->contr->party == target->contr->party)
1161 return 0; 1123 return 0;
1162 }
1163 } 1124 }
1164 1125
1165 return 1; 1126 return 1;
1166} 1127}
1128

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines