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.47 by root, Mon Sep 29 10:20:49 2008 UTC vs.
Revision 1.49 by root, Mon Dec 29 07:43:36 2008 UTC

254 { 254 {
255 object *ob = obl->ob; 255 object *ob = obl->ob;
256 next = obl->next; 256 next = obl->next;
257 257
258 if (ob->owner == owner) 258 if (ob->owner == owner)
259 {
260 op->destroy_inv (true); // be explicit about dropping
261 ob->destroy (true); 259 ob->drop_and_destroy ();
262 }
263 } 260 }
264} 261}
265 262
266/* 263/*
267 * Unfortunately, sometimes, the owner of a pet is in the 264 * Unfortunately, sometimes, the owner of a pet is in the
312 309
313 return 0; 310 return 0;
314 } 311 }
315 } 312 }
316 313
317 ob->destroy_inv (true); // be explicit about dropping 314 ob->drop_and_destroy ();
318 ob->destroy (true);
319 315
320 return 1; 316 return 1;
321} 317}
322 318
323void 319void
329 maptile *m; 325 maptile *m;
330 326
331 /* Check to see if player pulled out */ 327 /* Check to see if player pulled out */
332 if ((owner = ob->owner) == NULL) 328 if ((owner = ob->owner) == NULL)
333 { 329 {
334 op->destroy_inv (true); // be explicit about dropping
335 ob->destroy (true); 330 ob->drop_and_destroy ();
336 LOG (llevMonster, "Pet: no owner, leaving.\n"); 331 LOG (llevMonster, "Pet: no owner, leaving.\n");
337 return; 332 return;
338 } 333 }
339 334
340 /* 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
538 return; /* Has already been moved */ 533 return; /* Has already been moved */
539 534
540 if (!op->owner) 535 if (!op->owner)
541 { 536 {
542 LOG (llevDebug, "Golem without owner destructed.\n"); 537 LOG (llevDebug, "Golem without owner destructed.\n");
543 op->destroy_inv (true); // be explicit about dropping
544 op->destroy (true); 538 op->drop_and_destroy ();
545 return; 539 return;
546 } 540 }
547 541
548 /* 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
549 * when the golem expires than these hard coded entries. 543 * when the golem expires than these hard coded entries.
553 if (--op->stats.hp < 0) 547 if (--op->stats.hp < 0)
554 { 548 {
555 if (op->msg) 549 if (op->msg)
556 new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg); 550 new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg);
557 551
558 op->destroy_inv (true); // be explicit about dropping
559 op->destroy (true); 552 op->drop_and_destroy ();
560 return; 553 return;
561 } 554 }
562 555
563 /* Do golem attacks/movement for single & multisq golems. 556 /* Do golem attacks/movement for single & multisq golems.
564 * 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
632control_golem (object *op, int dir) 625control_golem (object *op, int dir)
633{ 626{
634 op->direction = dir; 627 op->direction = dir;
635} 628}
636 629
637/* summon golem: summons a monster for 'op'. caster is the object 630/* summon golem: summons a monster for 'op'. caster is the object
638 * casting the spell, dir is the direction to place the monster, 631 * casting the spell, dir is the direction to place the monster,
639 * 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
640 * 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
641 * adjust some values in the monster. 634 * adjust some values in the monster.
642 */ 635 */
651 * 'lose' their old golem. 644 * 'lose' their old golem.
652 */ 645 */
653 if (op->type == PLAYER && op->contr->golem) 646 if (op->type == PLAYER && op->contr->golem)
654 { 647 {
655 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.");
656 op->contr->holem->destroy_inv (true); // be explicit about dropping
657 op->contr->golem->destroy (true); 649 op->contr->golem->drop_and_destroy ();
658 op->contr->golem = 0; 650 op->contr->golem = 0;
659 } 651 }
660 652
661 if (spob->other_arch) 653 if (spob->other_arch)
662 at = spob->other_arch; 654 at = spob->other_arch;
763 if (!(tmp->attacktype & AT_PHYSICAL)) 755 if (!(tmp->attacktype & AT_PHYSICAL))
764 tmp->attacktype |= AT_PHYSICAL; 756 tmp->attacktype |= AT_PHYSICAL;
765 } 757 }
766 758
767 insert_ob_in_map (tmp, tmp->map, op, 0); 759 insert_ob_in_map (tmp, tmp->map, op, 0);
760
768 return 1; 761 return 1;
769} 762}
770 763
771 764
772/*************************************************************************** 765/***************************************************************************
778/* 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
779 * god) find acceptable. This checks level, races allowed by god, etc 772 * god) find acceptable. This checks level, races allowed by god, etc
780 * to determine what is acceptable. 773 * to determine what is acceptable.
781 * This returns NULL if no match was found. 774 * This returns NULL if no match was found.
782 */ 775 */
783
784object * 776object *
785choose_cult_monster (object *pl, object *god, int summon_level) 777choose_cult_monster (object *pl, object *god, int summon_level)
786{ 778{
787 char buf[MAX_BUF]; 779 char buf[MAX_BUF];
788 const char *race; 780 const char *race;
843 * a valid entry, assuming nothing is available and quit. 835 * a valid entry, assuming nothing is available and quit.
844 */ 836 */
845 if (!mon_nr) 837 if (!mon_nr)
846 return NULL; 838 return NULL;
847 839
848 mon_nr = rndm (0, mon_nr - 1); 840 mon_nr = rndm (mon_nr - 1);
849 for (tobl = list->member; tobl; tobl = tobl->next) 841 for (tobl = list->member; tobl; tobl = tobl->next)
850 { 842 {
851 otmp = tobl->ob; 843 otmp = tobl->ob;
852 if (!otmp || !QUERY_FLAG (otmp, FLAG_MONSTER)) 844 if (!otmp || !QUERY_FLAG (otmp, FLAG_MONSTER))
853 continue; 845 continue;
846
854 if (otmp->level <= summon_level && !mon_nr--) 847 if (otmp->level <= summon_level && !mon_nr--)
855 return otmp; 848 return otmp;
856 } 849 }
850
857 /* This should not happen */ 851 /* This should not happen */
858 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");
859 return NULL; 853 return NULL;
860} 854}
861 855
1061 } /* for i < nrof */ 1055 } /* for i < nrof */
1062 1056
1063 return 1; 1057 return 1;
1064} 1058}
1065 1059
1066/* recursively look through the owner property of objects until the real owner
1067is found */
1068object *
1069get_real_owner (object *ob)
1070{
1071 object *realowner = ob;
1072
1073 if (realowner == NULL)
1074 return NULL;
1075
1076 while (realowner->owner != NULL)
1077 {
1078 realowner = realowner->owner;
1079 }
1080 return realowner;
1081}
1082
1083/* 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
1084overruled by the arena petmode */ 1061overruled by the arena petmode */
1085int 1062int
1086should_arena_attack (object *pet, object *owner, object *target) 1063should_arena_attack (object *pet, object *owner, object *target)
1087{ 1064{
1091 if ((target == NULL) || (pet == NULL) || (owner == NULL)) 1068 if ((target == NULL) || (pet == NULL) || (owner == NULL))
1092 return 0; 1069 return 0;
1093 1070
1094 /* 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
1095 pets */ 1072 pets */
1096 rowner = get_real_owner (owner); 1073 rowner = owner->outer_owner ();
1097 towner = target->type == PLAYER ? 0 : get_real_owner (target); 1074 towner = target->is_player () ? 0 : target->outer_owner ();
1098 1075
1099 /* if the pet has now owner, exit with error */ 1076 /* if the pet has now owner, exit with error */
1100 if (!rowner) 1077 if (!rowner)
1101 { 1078 {
1102 LOG (llevError, "Pet has no owner.\n"); 1079 LOG (llevError, "Pet has no owner.\n");
1103 return 0; 1080 return 0;
1104 } 1081 }
1105 1082
1106 /* 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
1107 */ 1084 */
1108 if ((towner == NULL) && (target->type != PLAYER)) 1085 if (!towner && !target->is_player ())
1109 { 1086 {
1110 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");
1111 return 0; 1088 return 0;
1112 } 1089 }
1113 1090
1114 /* make sure that the owner is a player */ 1091 /* make sure that the owner is a player */
1115 if (rowner->type != PLAYER) 1092 if (!rowner->is_player ())
1116 return 0; 1093 return 0;
1117 1094
1118 /* abort if the petmode is not arena */ 1095 /* abort if the petmode is not arena */
1119 if (rowner->contr->petmode != pet_arena) 1096 if (rowner->contr->petmode != pet_arena)
1120 return 0; 1097 return 0;
1122 /* 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 */
1123 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)))
1124 return 0; 1101 return 0;
1125 1102
1126 /* 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 */
1127 if ((target->type != PLAYER) && (rowner == towner)) 1104 if (!target->is_player () && rowner == towner)
1128 return 0; 1105 return 0;
1129 1106
1130 /* 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
1131 parties */ 1108 parties */
1132 if (target->type != PLAYER) 1109 if (!target->is_player ())
1133 { 1110 {
1134 /* 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
1135 it's not in the same party */ 1112 it's not in the same party */
1136 if ((towner->type == PLAYER) && (rowner->contr->party != NULL)) 1113 if (towner->is_player () && rowner->contr->party)
1137 {
1138 if (rowner->contr->party == towner->contr->party) 1114 if (rowner->contr->party == towner->contr->party)
1139 return 0; 1115 return 0;
1140 }
1141 } 1116 }
1142 else 1117 else
1143 { 1118 {
1144 /* 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
1145 in the same party */ 1120 in the same party */
1146 if (rowner->contr->party != NULL) 1121 if (rowner->contr->party)
1147 {
1148 if (rowner->contr->party == target->contr->party) 1122 if (rowner->contr->party == target->contr->party)
1149 return 0; 1123 return 0;
1150 }
1151 } 1124 }
1152 1125
1153 return 1; 1126 return 1;
1154} 1127}
1128

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines