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.45 by root, Tue May 6 16:55:26 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 ob->destroy (); 259 ob->drop_and_destroy ();
260 } 260 }
261} 261}
262 262
263/* 263/*
264 * Unfortunately, sometimes, the owner of a pet is in the 264 * Unfortunately, sometimes, the owner of a pet is in the
309 309
310 return 0; 310 return 0;
311 } 311 }
312 } 312 }
313 313
314 ob->destroy (); 314 ob->drop_and_destroy ();
315
315 return 1; 316 return 1;
316} 317}
317 318
318void 319void
319pet_move (object *ob) 320pet_move (object *ob)
324 maptile *m; 325 maptile *m;
325 326
326 /* Check to see if player pulled out */ 327 /* Check to see if player pulled out */
327 if ((owner = ob->owner) == NULL) 328 if ((owner = ob->owner) == NULL)
328 { 329 {
329 ob->destroy (); 330 ob->drop_and_destroy ();
330 LOG (llevMonster, "Pet: no owner, leaving.\n"); 331 LOG (llevMonster, "Pet: no owner, leaving.\n");
331 return; 332 return;
332 } 333 }
333 334
334 /* 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
532 return; /* Has already been moved */ 533 return; /* Has already been moved */
533 534
534 if (!op->owner) 535 if (!op->owner)
535 { 536 {
536 LOG (llevDebug, "Golem without owner destructed.\n"); 537 LOG (llevDebug, "Golem without owner destructed.\n");
537 op->remove ();
538 op->destroy (); 538 op->drop_and_destroy ();
539 return; 539 return;
540 } 540 }
541 541
542 /* 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
543 * when the golem expires than these hard coded entries. 543 * when the golem expires than these hard coded entries.
547 if (--op->stats.hp < 0) 547 if (--op->stats.hp < 0)
548 { 548 {
549 if (op->msg) 549 if (op->msg)
550 new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg); 550 new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg);
551 551
552 op->destroy (); 552 op->drop_and_destroy ();
553 return; 553 return;
554 } 554 }
555 555
556 /* Do golem attacks/movement for single & multisq golems. 556 /* Do golem attacks/movement for single & multisq golems.
557 * 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
625control_golem (object *op, int dir) 625control_golem (object *op, int dir)
626{ 626{
627 op->direction = dir; 627 op->direction = dir;
628} 628}
629 629
630/* summon golem: summons a monster for 'op'. caster is the object 630/* summon golem: summons a monster for 'op'. caster is the object
631 * casting the spell, dir is the direction to place the monster, 631 * casting the spell, dir is the direction to place the monster,
632 * 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
633 * 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
634 * adjust some values in the monster. 634 * adjust some values in the monster.
635 */ 635 */
644 * 'lose' their old golem. 644 * 'lose' their old golem.
645 */ 645 */
646 if (op->type == PLAYER && op->contr->golem) 646 if (op->type == PLAYER && op->contr->golem)
647 { 647 {
648 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.");
649 op->contr->golem->remove ();
650 op->contr->golem->destroy (); 649 op->contr->golem->drop_and_destroy ();
651 op->contr->golem = 0; 650 op->contr->golem = 0;
652 } 651 }
653 652
654 if (spob->other_arch) 653 if (spob->other_arch)
655 at = spob->other_arch; 654 at = spob->other_arch;
701 /* give the player control of the golem */ 700 /* give the player control of the golem */
702 set_spell_skill (op, caster, spob, tmp); 701 set_spell_skill (op, caster, spob, tmp);
703 } 702 }
704 703
705 /* make the speed positive. */ 704 /* make the speed positive. */
706 tmp->speed = FABS (tmp->speed); 705 tmp->speed = fabs (tmp->speed);
707 706
708 /* This sets the level dependencies on dam and hp for monsters */ 707 /* This sets the level dependencies on dam and hp for monsters */
709 /* players can't cope with too strong summonings. */ 708 /* players can't cope with too strong summonings. */
710 /* but monsters can. reserve these for players. */ 709 /* but monsters can. reserve these for players. */
711 if (op->type == PLAYER) 710 if (op->type == PLAYER)
716 tmp->stats.dam += SP_level_dam_adjust (caster, spob); 715 tmp->stats.dam += SP_level_dam_adjust (caster, spob);
717 else 716 else
718 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);
719 718
720 tmp->speed += .02 * SP_level_range_adjust (caster, spob); 719 tmp->speed += .02 * SP_level_range_adjust (caster, spob);
721 tmp->speed = MIN (tmp->speed, 1.0); 720 tmp->speed = min (tmp->speed, 1.0);
722 721
723 if (spob->attacktype) 722 if (spob->attacktype)
724 tmp->attacktype = spob->attacktype; 723 tmp->attacktype = spob->attacktype;
725 } 724 }
726 725
730 729
731 /* make experience increase in proportion to the strength. 730 /* make experience increase in proportion to the strength.
732 * 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
733 * often the sp doubles and use that as the ratio. 732 * often the sp doubles and use that as the ratio.
734 */ 733 */
735 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);
736 tmp->speed_left = 0; 735 tmp->speed_left = 0;
737 tmp->direction = dir; 736 tmp->direction = dir;
738 737
739 /* Holy spell - some additional tailoring */ 738 /* Holy spell - some additional tailoring */
740 if (god) 739 if (god)
756 if (!(tmp->attacktype & AT_PHYSICAL)) 755 if (!(tmp->attacktype & AT_PHYSICAL))
757 tmp->attacktype |= AT_PHYSICAL; 756 tmp->attacktype |= AT_PHYSICAL;
758 } 757 }
759 758
760 insert_ob_in_map (tmp, tmp->map, op, 0); 759 insert_ob_in_map (tmp, tmp->map, op, 0);
760
761 return 1; 761 return 1;
762} 762}
763 763
764 764
765/*************************************************************************** 765/***************************************************************************
771/* 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
772 * god) find acceptable. This checks level, races allowed by god, etc 772 * god) find acceptable. This checks level, races allowed by god, etc
773 * to determine what is acceptable. 773 * to determine what is acceptable.
774 * This returns NULL if no match was found. 774 * This returns NULL if no match was found.
775 */ 775 */
776
777object * 776object *
778choose_cult_monster (object *pl, object *god, int summon_level) 777choose_cult_monster (object *pl, object *god, int summon_level)
779{ 778{
780 char buf[MAX_BUF]; 779 char buf[MAX_BUF];
781 const char *race; 780 const char *race;
836 * a valid entry, assuming nothing is available and quit. 835 * a valid entry, assuming nothing is available and quit.
837 */ 836 */
838 if (!mon_nr) 837 if (!mon_nr)
839 return NULL; 838 return NULL;
840 839
841 mon_nr = rndm (0, mon_nr - 1); 840 mon_nr = rndm (mon_nr - 1);
842 for (tobl = list->member; tobl; tobl = tobl->next) 841 for (tobl = list->member; tobl; tobl = tobl->next)
843 { 842 {
844 otmp = tobl->ob; 843 otmp = tobl->ob;
845 if (!otmp || !QUERY_FLAG (otmp, FLAG_MONSTER)) 844 if (!otmp || !QUERY_FLAG (otmp, FLAG_MONSTER))
846 continue; 845 continue;
846
847 if (otmp->level <= summon_level && !mon_nr--) 847 if (otmp->level <= summon_level && !mon_nr--)
848 return otmp; 848 return otmp;
849 } 849 }
850
850 /* This should not happen */ 851 /* This should not happen */
851 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");
852 return NULL; 853 return NULL;
853} 854}
854 855
861 862
862 if (spell_ob->other_arch) 863 if (spell_ob->other_arch)
863 summon_arch = spell_ob->other_arch; 864 summon_arch = spell_ob->other_arch;
864 else if (spell_ob->randomitems) 865 else if (spell_ob->randomitems)
865 { 866 {
866 int level = caster_level (caster, spell_ob); 867 int level = casting_level (caster, spell_ob);
867 treasure *tr, *lasttr = NULL; 868 treasure *tr, *lasttr = NULL;
868 869
869 shstr_cmp sparam (stringarg); 870 shstr_cmp sparam (stringarg);
870 871
871 /* In old code, this was a very convoluted for statement, 872 /* In old code, this was a very convoluted for statement,
913 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);
914 return 0; 915 return 0;
915 } 916 }
916 917
917 /* the summon level */ 918 /* the summon level */
918 summon_level = caster_level (caster, spell_ob); 919 summon_level = casting_level (caster, spell_ob);
919 if (summon_level == 0) 920 if (summon_level == 0)
920 summon_level = 1; 921 summon_level = 1;
921 922
922 tries = 0; 923 tries = 0;
923 do 924 do
1054 } /* for i < nrof */ 1055 } /* for i < nrof */
1055 1056
1056 return 1; 1057 return 1;
1057} 1058}
1058 1059
1059/* recursively look through the owner property of objects until the real owner
1060is found */
1061object *
1062get_real_owner (object *ob)
1063{
1064 object *realowner = ob;
1065
1066 if (realowner == NULL)
1067 return NULL;
1068
1069 while (realowner->owner != NULL)
1070 {
1071 realowner = realowner->owner;
1072 }
1073 return realowner;
1074}
1075
1076/* 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
1077overruled by the arena petmode */ 1061overruled by the arena petmode */
1078int 1062int
1079should_arena_attack (object *pet, object *owner, object *target) 1063should_arena_attack (object *pet, object *owner, object *target)
1080{ 1064{
1084 if ((target == NULL) || (pet == NULL) || (owner == NULL)) 1068 if ((target == NULL) || (pet == NULL) || (owner == NULL))
1085 return 0; 1069 return 0;
1086 1070
1087 /* 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
1088 pets */ 1072 pets */
1089 rowner = get_real_owner (owner); 1073 rowner = owner->outer_owner ();
1090 towner = target->type == PLAYER ? 0 : get_real_owner (target); 1074 towner = target->is_player () ? 0 : target->outer_owner ();
1091 1075
1092 /* if the pet has now owner, exit with error */ 1076 /* if the pet has now owner, exit with error */
1093 if (!rowner) 1077 if (!rowner)
1094 { 1078 {
1095 LOG (llevError, "Pet has no owner.\n"); 1079 LOG (llevError, "Pet has no owner.\n");
1096 return 0; 1080 return 0;
1097 } 1081 }
1098 1082
1099 /* 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
1100 */ 1084 */
1101 if ((towner == NULL) && (target->type != PLAYER)) 1085 if (!towner && !target->is_player ())
1102 { 1086 {
1103 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");
1104 return 0; 1088 return 0;
1105 } 1089 }
1106 1090
1107 /* make sure that the owner is a player */ 1091 /* make sure that the owner is a player */
1108 if (rowner->type != PLAYER) 1092 if (!rowner->is_player ())
1109 return 0; 1093 return 0;
1110 1094
1111 /* abort if the petmode is not arena */ 1095 /* abort if the petmode is not arena */
1112 if (rowner->contr->petmode != pet_arena) 1096 if (rowner->contr->petmode != pet_arena)
1113 return 0; 1097 return 0;
1115 /* 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 */
1116 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)))
1117 return 0; 1101 return 0;
1118 1102
1119 /* 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 */
1120 if ((target->type != PLAYER) && (rowner == towner)) 1104 if (!target->is_player () && rowner == towner)
1121 return 0; 1105 return 0;
1122 1106
1123 /* 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
1124 parties */ 1108 parties */
1125 if (target->type != PLAYER) 1109 if (!target->is_player ())
1126 { 1110 {
1127 /* 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
1128 it's not in the same party */ 1112 it's not in the same party */
1129 if ((towner->type == PLAYER) && (rowner->contr->party != NULL)) 1113 if (towner->is_player () && rowner->contr->party)
1130 {
1131 if (rowner->contr->party == towner->contr->party) 1114 if (rowner->contr->party == towner->contr->party)
1132 return 0; 1115 return 0;
1133 }
1134 } 1116 }
1135 else 1117 else
1136 { 1118 {
1137 /* 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
1138 in the same party */ 1120 in the same party */
1139 if (rowner->contr->party != NULL) 1121 if (rowner->contr->party)
1140 {
1141 if (rowner->contr->party == target->contr->party) 1122 if (rowner->contr->party == target->contr->party)
1142 return 0; 1123 return 0;
1143 }
1144 } 1124 }
1145 1125
1146 return 1; 1126 return 1;
1147} 1127}
1128

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines