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.28 by elmex, Mon Apr 16 11:50:45 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 CLEAR_FLAG (pet, FLAG_FRIENDLY);
55 remove_friendly_object (pet);
56 pet->attack_movement &= ~PETMOVE;
57 return owner;
58 }
59 } 49 {
60 else
61 {
62 /* else the owner is no longer around, so the 50 /* the owner is no longer around, so the
63 * pet no longer needs to be friendly. 51 * pet no longer needs to be friendly.
64 */ 52 */
65 CLEAR_FLAG (pet, FLAG_FRIENDLY);
66 remove_friendly_object (pet); 53 remove_friendly_object (pet);
67 pet->attack_movement &= ~PETMOVE; 54 pet->attack_movement &= ~PETMOVE;
68 return 0; 55 return 0;
69 } 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;
66 }
67
70 /* 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 */
71 //if (!on_same_map (pet, owner)) 69 //if (!on_same_map (pet, owner))
72 // return 0; 70 // return 0;
73 71
74 /* See if the pet has an existing enemy. If so, don't start a new one */ 72 /* See if the pet has an existing enemy. If so, don't start a new one */
107 105
108 /* Since the pet has no existing enemy, look for anything nasty 106 /* Since the pet has no existing enemy, look for anything nasty
109 * around the owner that it should go and attack. (if the owner is 107 * around the owner that it should go and attack. (if the owner is
110 * still on a map) 108 * still on a map)
111 */ 109 */
110 // owners sometimes are not on a map but in the inventory of somehting else
112 if (!owner->flag [FLAG_REMOVED]) 111 if (!owner->flag [FLAG_REMOVED] && owner->map)
113 { 112 {
114 tmp3 = 0; 113 tmp3 = 0;
115 114
116 for (i = 0; i < SIZEOFFREE; i++) 115 for (i = 0; i < SIZEOFFREE; i++)
117 { 116 {
249void 248void
250terminate_all_pets (object *owner) 249terminate_all_pets (object *owner)
251{ 250{
252 objectlink *obl, *next; 251 objectlink *obl, *next;
253 252
254 for (obl = first_friendly_object; obl != NULL; obl = next) 253 for (obl = first_friendly_object; obl; obl = next)
255 { 254 {
256 object *ob = obl->ob; 255 object *ob = obl->ob;
257
258 next = obl->next; 256 next = obl->next;
257
259 if (ob->owner == owner) 258 if (ob->owner == owner)
260 {
261 if (!QUERY_FLAG (ob, FLAG_REMOVED))
262 ob->remove ();
263 remove_friendly_object (ob);
264 ob->destroy (); 259 ob->drop_and_destroy ();
265 }
266 } 260 }
267} 261}
268 262
269/* 263/*
270 * Unfortunately, sometimes, the owner of a pet is in the 264 * Unfortunately, sometimes, the owner of a pet is in the
298int 292int
299follow_owner (object *ob, object *owner) 293follow_owner (object *ob, object *owner)
300{ 294{
301 if (owner->flag [FLAG_REMOVED]) 295 if (owner->flag [FLAG_REMOVED])
302 return 0; // do nothing if the owner is removed 296 return 0; // do nothing if the owner is removed
303 else if (owner->map->in_memory != MAP_IN_MEMORY) 297 else if (!owner->map || owner->map->in_memory != MAP_ACTIVE)
304 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);
305 else 299 else
306 { 300 {
307 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);
308 302
309 if (dir >= 0) 303 if (dir >= 0)
315 309
316 return 0; 310 return 0;
317 } 311 }
318 } 312 }
319 313
320 ob->destroy (); 314 ob->drop_and_destroy ();
315
321 return 1; 316 return 1;
322} 317}
323 318
324void 319void
325pet_move (object *ob) 320pet_move (object *ob)
330 maptile *m; 325 maptile *m;
331 326
332 /* Check to see if player pulled out */ 327 /* Check to see if player pulled out */
333 if ((owner = ob->owner) == NULL) 328 if ((owner = ob->owner) == NULL)
334 { 329 {
335 ob->remove (); /* Will be freed when returning */
336 remove_friendly_object (ob);
337 ob->destroy (); 330 ob->drop_and_destroy ();
338 LOG (llevMonster, "Pet: no owner, leaving.\n"); 331 LOG (llevMonster, "Pet: no owner, leaving.\n");
339 return; 332 return;
340 } 333 }
341 334
342 /* 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
444 * is_golem is to note that this is a golem spell. 437 * is_golem is to note that this is a golem spell.
445 */ 438 */
446object * 439object *
447fix_summon_pet (archetype *at, object *op, int dir, int is_golem) 440fix_summon_pet (archetype *at, object *op, int dir, int is_golem)
448{ 441{
449 archetype *atmp;
450 object *tmp = NULL, *prev = NULL, *head = NULL; 442 object *tmp = NULL, *prev = NULL, *head = NULL;
451 443
452 for (atmp = at; atmp; atmp = atmp->more) 444 for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more)
453 { 445 {
454 tmp = arch_to_object (atmp); 446 tmp = arch_to_object (atmp);
455 447
456 if (atmp == at) 448 if (atmp == at)
457 { 449 {
458 if (!is_golem) 450 if (!is_golem)
459 SET_FLAG (tmp, FLAG_MONSTER); 451 SET_FLAG (tmp, FLAG_MONSTER);
460 452
461 tmp->set_owner (op); 453 tmp->set_owner (op);
454
462 if (op->type == PLAYER) 455 if (op->type == PLAYER)
463 { 456 {
464 tmp->stats.exp = 0; 457 tmp->stats.exp = 0;
465 add_friendly_object (tmp); 458 add_friendly_object (tmp);
466 if (is_golem) 459 if (is_golem)
494 } 487 }
495 488
496 if (!head) 489 if (!head)
497 head = tmp; 490 head = tmp;
498 491
499 tmp->x = op->x + freearr_x[dir] + tmp->arch->clone.x; 492 tmp->x = op->x + freearr_x[dir] + tmp->arch->x;
500 tmp->y = op->y + freearr_y[dir] + tmp->arch->clone.y; 493 tmp->y = op->y + freearr_y[dir] + tmp->arch->y;
501 tmp->map = op->map; 494 tmp->map = op->map;
502 495
503 if (tmp->invisible) 496 if (tmp->invisible)
504 tmp->invisible = 0; 497 tmp->invisible = 0;
505 498
537 object *tmp; 530 object *tmp;
538 531
539 if (QUERY_FLAG (op, FLAG_MONSTER)) 532 if (QUERY_FLAG (op, FLAG_MONSTER))
540 return; /* Has already been moved */ 533 return; /* Has already been moved */
541 534
542 if (op->owner == NULL) 535 if (!op->owner)
543 { 536 {
544 LOG (llevDebug, "Golem without owner destructed.\n"); 537 LOG (llevDebug, "Golem without owner destructed.\n");
545 op->remove ();
546 op->destroy (); 538 op->drop_and_destroy ();
547 return; 539 return;
548 } 540 }
549 541
550 /* 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
551 * when the golem expires than these hard coded entries. 543 * when the golem expires than these hard coded entries.
555 if (--op->stats.hp < 0) 547 if (--op->stats.hp < 0)
556 { 548 {
557 if (op->msg) 549 if (op->msg)
558 new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg); 550 new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg);
559 551
560 op->owner->contr->ranges[range_golem] = 0;
561 remove_friendly_object (op);
562 op->remove ();
563 op->destroy (); 552 op->drop_and_destroy ();
564 return; 553 return;
565 } 554 }
566 555
567 /* Do golem attacks/movement for single & multisq golems. 556 /* Do golem attacks/movement for single & multisq golems.
568 * 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
586 mflags = get_map_flags (m, &m, x, y, &x, &y); 575 mflags = get_map_flags (m, &m, x, y, &x, &y);
587 576
588 if (mflags & P_OUT_OF_MAP) 577 if (mflags & P_OUT_OF_MAP)
589 continue; 578 continue;
590 579
591 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)
592 if (QUERY_FLAG (victim, FLAG_ALIVE)) 581 if (QUERY_FLAG (victim, FLAG_ALIVE))
593 break; 582 break;
594 583
595 /* 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
596 * 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
599 * but since we are not trying to dereferance that pointer, 588 * but since we are not trying to dereferance that pointer,
600 * that isn't a problem. 589 * that isn't a problem.
601 */ 590 */
602 if (victim && victim != op && victim->head != op) 591 if (victim && victim != op && victim->head != op)
603 { 592 {
604
605 /* for golems with race fields, we don't attack 593 /* for golems with race fields, we don't attack
606 * aligned races 594 * aligned races
607 */ 595 */
608 596
609 if (victim->race && op->race && strstr (op->race, victim->race)) 597 if (victim->race && op->race && op->race.contains (victim->race))
610 { 598 {
611 if (op->owner) 599 if (op->owner)
612 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);
613 } 601 }
614 else if (victim == op->owner) 602 else if (victim == op->owner)
637control_golem (object *op, int dir) 625control_golem (object *op, int dir)
638{ 626{
639 op->direction = dir; 627 op->direction = dir;
640} 628}
641 629
642/* summon golem: summons a monster for 'op'. caster is the object 630/* summon golem: summons a monster for 'op'. caster is the object
643 * casting the spell, dir is the direction to place the monster, 631 * casting the spell, dir is the direction to place the monster,
644 * 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
645 * 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
646 * adjust some values in the monster. 634 * adjust some values in the monster.
647 */ 635 */
653 char buf[MAX_BUF]; 641 char buf[MAX_BUF];
654 642
655 /* Because there can be different golem spells, player may want to 643 /* Because there can be different golem spells, player may want to
656 * 'lose' their old golem. 644 * 'lose' their old golem.
657 */ 645 */
658 if (op->type == PLAYER && op->contr->ranges[range_golem]) 646 if (op->type == PLAYER && op->contr->golem)
659 { 647 {
660 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.");
661 op->contr->ranges[range_golem]->remove ();
662 op->contr->ranges[range_golem]->destroy (); 649 op->contr->golem->drop_and_destroy ();
663 op->contr->ranges[range_golem] = 0; 650 op->contr->golem = 0;
664 } 651 }
665 652
666 if (spob->other_arch) 653 if (spob->other_arch)
667 at = spob->other_arch; 654 at = spob->other_arch;
668 else if (spob->race) 655 else if (spob->race)
688 LOG (llevError, "Spell %s lacks other_arch\n", &spob->name); 675 LOG (llevError, "Spell %s lacks other_arch\n", &spob->name);
689 return 0; 676 return 0;
690 } 677 }
691 678
692 if (!dir) 679 if (!dir)
693 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);
694 681
695 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]))
696 { 683 {
697 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.");
698 return 0; 685 return 0;
699 } 686 }
700 687
707 } 694 }
708 695
709 if (op->type == PLAYER) 696 if (op->type == PLAYER)
710 { 697 {
711 tmp->type = GOLEM; 698 tmp->type = GOLEM;
712 tmp->set_owner (op); 699 op->contr->golem = tmp;
700 /* give the player control of the golem */
713 set_spell_skill (op, caster, spob, tmp); 701 set_spell_skill (op, caster, spob, tmp);
714 op->contr->ranges[range_golem] = tmp;
715 /* give the player control of the golem */
716 op->contr->shoottype = range_golem;
717 }
718 else
719 {
720 if (QUERY_FLAG (op, FLAG_FRIENDLY))
721 {
722 object *owner = op->owner;
723
724 if (owner)
725 { /* For now, we transfer ownership */
726 tmp->set_owner (owner);
727 tmp->attack_movement = PETMOVE;
728 add_friendly_object (tmp);
729 }
730 }
731
732 SET_FLAG (tmp, FLAG_MONSTER);
733 } 702 }
734 703
735 /* make the speed positive. */ 704 /* make the speed positive. */
736 tmp->speed = FABS (tmp->speed); 705 tmp->speed = fabs (tmp->speed);
737 706
738 /* This sets the level dependencies on dam and hp for monsters */ 707 /* This sets the level dependencies on dam and hp for monsters */
739 /* players can't cope with too strong summonings. */ 708 /* players can't cope with too strong summonings. */
740 /* but monsters can. reserve these for players. */ 709 /* but monsters can. reserve these for players. */
741 if (op->type == PLAYER) 710 if (op->type == PLAYER)
746 tmp->stats.dam += SP_level_dam_adjust (caster, spob); 715 tmp->stats.dam += SP_level_dam_adjust (caster, spob);
747 else 716 else
748 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);
749 718
750 tmp->speed += .02 * SP_level_range_adjust (caster, spob); 719 tmp->speed += .02 * SP_level_range_adjust (caster, spob);
751 tmp->speed = MIN (tmp->speed, 1.0); 720 tmp->speed = min (tmp->speed, 1.0);
752 721
753 if (spob->attacktype) 722 if (spob->attacktype)
754 tmp->attacktype = spob->attacktype; 723 tmp->attacktype = spob->attacktype;
755 } 724 }
756 725
760 729
761 /* make experience increase in proportion to the strength. 730 /* make experience increase in proportion to the strength.
762 * 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
763 * often the sp doubles and use that as the ratio. 732 * often the sp doubles and use that as the ratio.
764 */ 733 */
765 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);
766 tmp->speed_left = 0; 735 tmp->speed_left = 0;
767 tmp->direction = dir; 736 tmp->direction = dir;
768 737
769 /* Holy spell - some additional tailoring */ 738 /* Holy spell - some additional tailoring */
770 if (god) 739 if (god)
786 if (!(tmp->attacktype & AT_PHYSICAL)) 755 if (!(tmp->attacktype & AT_PHYSICAL))
787 tmp->attacktype |= AT_PHYSICAL; 756 tmp->attacktype |= AT_PHYSICAL;
788 } 757 }
789 758
790 insert_ob_in_map (tmp, tmp->map, op, 0); 759 insert_ob_in_map (tmp, tmp->map, op, 0);
760
791 return 1; 761 return 1;
792} 762}
793 763
794 764
795/*************************************************************************** 765/***************************************************************************
801/* 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
802 * god) find acceptable. This checks level, races allowed by god, etc 772 * god) find acceptable. This checks level, races allowed by god, etc
803 * to determine what is acceptable. 773 * to determine what is acceptable.
804 * This returns NULL if no match was found. 774 * This returns NULL if no match was found.
805 */ 775 */
806
807object * 776object *
808choose_cult_monster (object *pl, object *god, int summon_level) 777choose_cult_monster (object *pl, object *god, int summon_level)
809{ 778{
810 char buf[MAX_BUF]; 779 char buf[MAX_BUF];
811 const char *race; 780 const char *race;
866 * a valid entry, assuming nothing is available and quit. 835 * a valid entry, assuming nothing is available and quit.
867 */ 836 */
868 if (!mon_nr) 837 if (!mon_nr)
869 return NULL; 838 return NULL;
870 839
871 mon_nr = rndm (0, mon_nr - 1); 840 mon_nr = rndm (mon_nr - 1);
872 for (tobl = list->member; tobl; tobl = tobl->next) 841 for (tobl = list->member; tobl; tobl = tobl->next)
873 { 842 {
874 otmp = tobl->ob; 843 otmp = tobl->ob;
875 if (!otmp || !QUERY_FLAG (otmp, FLAG_MONSTER)) 844 if (!otmp || !QUERY_FLAG (otmp, FLAG_MONSTER))
876 continue; 845 continue;
846
877 if (otmp->level <= summon_level && !mon_nr--) 847 if (otmp->level <= summon_level && !mon_nr--)
878 return otmp; 848 return otmp;
879 } 849 }
850
880 /* This should not happen */ 851 /* This should not happen */
881 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");
882 return NULL; 853 return NULL;
883} 854}
884 855
891 862
892 if (spell_ob->other_arch) 863 if (spell_ob->other_arch)
893 summon_arch = spell_ob->other_arch; 864 summon_arch = spell_ob->other_arch;
894 else if (spell_ob->randomitems) 865 else if (spell_ob->randomitems)
895 { 866 {
896 int level = caster_level (caster, spell_ob); 867 int level = casting_level (caster, spell_ob);
897 treasure *tr, *lasttr = NULL; 868 treasure *tr, *lasttr = NULL;
898 869
899 shstr_cmp sparam (stringarg); 870 shstr_cmp sparam (stringarg);
900 871
901 /* In old code, this was a very convoluted for statement, 872 /* In old code, this was a very convoluted for statement,
910 if (level < tr->magic) 881 if (level < tr->magic)
911 break; 882 break;
912 883
913 lasttr = tr; 884 lasttr = tr;
914 885
915 if (tr->item->name == sparam) 886 if (tr->item->archname == sparam)
916 break; 887 break;
917 } 888 }
918 889
919 if (!lasttr) 890 if (!lasttr)
920 { 891 {
943 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);
944 return 0; 915 return 0;
945 } 916 }
946 917
947 /* the summon level */ 918 /* the summon level */
948 summon_level = caster_level (caster, spell_ob); 919 summon_level = casting_level (caster, spell_ob);
949 if (summon_level == 0) 920 if (summon_level == 0)
950 summon_level = 1; 921 summon_level = 1;
951 922
952 tries = 0; 923 tries = 0;
953 do 924 do
962 ndir = dir; 933 ndir = dir;
963 934
964 if (!ndir) 935 if (!ndir)
965 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);
966 937
967 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]))
968 { 939 {
969 ndir = -1; 940 ndir = -1;
970 if (++tries == 5) 941 if (++tries == 5)
971 { 942 {
972 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.");
995 return 0; 966 return 0;
996 } 967 }
997 968
998 for (i = 1; i <= nrof; i++) 969 for (i = 1; i <= nrof; i++)
999 { 970 {
1000 archetype *atmp;
1001 object *prev = NULL, *head = NULL, *tmp; 971 object *prev = NULL, *head = NULL, *tmp;
1002 972
1003 if (dir) 973 if (dir)
1004 { 974 {
1005 ndir = dir; 975 ndir = dir;
1006 dir = absdir (dir + 1); 976 dir = absdir (dir + 1);
1007 } 977 }
1008 else 978 else
1009 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);
1010 980
1011 if (ndir > 0) 981 if (ndir > 0)
1012 { 982 {
1013 x = freearr_x[ndir]; 983 x = freearr_x[ndir];
1014 y = freearr_y[ndir]; 984 y = freearr_y[ndir];
1015 } 985 }
1016 986
1017 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))
1018 { 988 {
1019 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.");
1020 if (nrof > 1) 990 if (nrof > 1)
1021 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.");
1022 992
1023 return nrof > 1; 993 return nrof > 1;
1024 } 994 }
1025 995
1026 for (atmp = summon_arch; atmp != NULL; atmp = atmp->more) 996 for (archetype *atmp = summon_arch; atmp != NULL; atmp = (archetype *)atmp->more)
1027 { 997 {
1028 tmp = arch_to_object (atmp); 998 tmp = arch_to_object (atmp);
1029 if (atmp == summon_arch) 999 if (atmp == summon_arch)
1030 { 1000 {
1031 if (QUERY_FLAG (tmp, FLAG_MONSTER)) 1001 if (QUERY_FLAG (tmp, FLAG_MONSTER))
1064 tmp->head = head; 1034 tmp->head = head;
1065 prev->more = tmp; 1035 prev->more = tmp;
1066 } 1036 }
1067 1037
1068 prev = tmp; 1038 prev = tmp;
1069 tmp->x = op->x + x + tmp->arch->clone.x; 1039 tmp->x = op->x + x + tmp->arch->x;
1070 tmp->y = op->y + y + tmp->arch->clone.y; 1040 tmp->y = op->y + y + tmp->arch->y;
1071 tmp->map = op->map; 1041 tmp->map = op->map;
1072 } 1042 }
1073 1043
1074 head->direction = freedir[ndir]; 1044 head->direction = freedir[ndir];
1075 head->stats.exp = 0; 1045 head->stats.exp = 0;
1083 SET_FLAG (tmp, FLAG_DESTROY_ON_DEATH); 1053 SET_FLAG (tmp, FLAG_DESTROY_ON_DEATH);
1084 } 1054 }
1085 } /* for i < nrof */ 1055 } /* for i < nrof */
1086 1056
1087 return 1; 1057 return 1;
1088}
1089
1090/* recursively look through the owner property of objects until the real owner
1091is found */
1092object *
1093get_real_owner (object *ob)
1094{
1095 object *realowner = ob;
1096
1097 if (realowner == NULL)
1098 return NULL;
1099
1100 while (realowner->owner != NULL)
1101 {
1102 realowner = realowner->owner;
1103 }
1104 return realowner;
1105} 1058}
1106 1059
1107/* 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
1108overruled by the arena petmode */ 1061overruled by the arena petmode */
1109int 1062int
1115 if ((target == NULL) || (pet == NULL) || (owner == NULL)) 1068 if ((target == NULL) || (pet == NULL) || (owner == NULL))
1116 return 0; 1069 return 0;
1117 1070
1118 /* 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
1119 pets */ 1072 pets */
1120 rowner = get_real_owner (owner); 1073 rowner = owner->outer_owner ();
1121 if (target->type != PLAYER) 1074 towner = target->is_player () ? 0 : target->outer_owner ();
1122 {
1123 towner = get_real_owner (target);
1124 }
1125 else
1126 {
1127 towner = 0;
1128 }
1129 1075
1130 /* if the pet has now owner, exit with error */ 1076 /* if the pet has now owner, exit with error */
1131 if (rowner == NULL) 1077 if (!rowner)
1132 { 1078 {
1133 LOG (llevError, "Pet has no owner.\n"); 1079 LOG (llevError, "Pet has no owner.\n");
1134 return 0; 1080 return 0;
1135 } 1081 }
1136 1082
1137 /* 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
1138 */ 1084 */
1139 if ((towner == NULL) && (target->type != PLAYER)) 1085 if (!towner && !target->is_player ())
1140 { 1086 {
1141 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");
1142 return 0; 1088 return 0;
1143 } 1089 }
1144 1090
1145 /* make sure that the owner is a player */ 1091 /* make sure that the owner is a player */
1146 if (rowner->type != PLAYER) 1092 if (!rowner->is_player ())
1147 return 0; 1093 return 0;
1148 1094
1149 /* abort if the petmode is not arena */ 1095 /* abort if the petmode is not arena */
1150 if (rowner->contr->petmode != pet_arena) 1096 if (rowner->contr->petmode != pet_arena)
1151 return 0; 1097 return 0;
1153 /* 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 */
1154 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)))
1155 return 0; 1101 return 0;
1156 1102
1157 /* 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 */
1158 if ((target->type != PLAYER) && (rowner == towner)) 1104 if (!target->is_player () && rowner == towner)
1159 return 0; 1105 return 0;
1160 1106
1161 /* 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
1162 parties */ 1108 parties */
1163 if (target->type != PLAYER) 1109 if (!target->is_player ())
1164 { 1110 {
1165 /* 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
1166 it's not in the same party */ 1112 it's not in the same party */
1167 if ((towner->type == PLAYER) && (rowner->contr->party != NULL)) 1113 if (towner->is_player () && rowner->contr->party)
1168 {
1169 if (rowner->contr->party == towner->contr->party) 1114 if (rowner->contr->party == towner->contr->party)
1170 return 0; 1115 return 0;
1171 }
1172 } 1116 }
1173 else 1117 else
1174 { 1118 {
1175 /* 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
1176 in the same party */ 1120 in the same party */
1177 if (rowner->contr->party != NULL) 1121 if (rowner->contr->party)
1178 {
1179 if (rowner->contr->party == target->contr->party) 1122 if (rowner->contr->party == target->contr->party)
1180 return 0; 1123 return 0;
1181 }
1182 } 1124 }
1183 1125
1184 return 1; 1126 return 1;
1185} 1127}
1128

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines