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

Comparing deliantra/server/server/monster.C (file contents):
Revision 1.24 by root, Thu Jan 18 21:27:19 2007 UTC vs.
Revision 1.36 by root, Sun Jul 1 05:00:20 2007 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game for X-windows 2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT 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 * Crossfire TRT 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 <crossfire@schmorp.de>
23 */ 22 */
24 23
25#include <global.h> 24#include <global.h>
26#include <sproto.h> 25#include <sproto.h>
27#include <spells.h> 26#include <spells.h>
85 * target enemy - this code below makes sure the enemy is something 84 * target enemy - this code below makes sure the enemy is something
86 * that should be attacked. My guess is that the arrow hits 85 * that should be attacked. My guess is that the arrow hits
87 * the creature/owner, and so the creature then takes that 86 * the creature/owner, and so the creature then takes that
88 * as the enemy to attack. 87 * as the enemy to attack.
89 */ 88 */
90 else if (!QUERY_FLAG (npc->enemy, FLAG_MONSTER) && 89 else if (!QUERY_FLAG (npc->enemy, FLAG_MONSTER)
91 !QUERY_FLAG (npc->enemy, FLAG_GENERATOR) && npc->enemy->type != PLAYER && npc->enemy->type != GOLEM) 90 && !QUERY_FLAG (npc->enemy, FLAG_GENERATOR)
91 && npc->enemy->type != PLAYER
92 && npc->enemy->type != GOLEM)
92 npc->enemy = NULL; 93 npc->enemy = NULL;
93 94
94 } 95 }
95 return can_detect_enemy (npc, npc->enemy, rv) ? npc->enemy : NULL; 96 return can_detect_enemy (npc, npc->enemy, rv) ? npc->enemy : NULL;
96} 97}
143 } 144 }
144 145
145 return 0; 146 return 0;
146} 147}
147 148
148
149/* Tries to find an enmy for npc. We pass the range vector since 149/* Tries to find an enemy for npc. We pass the range vector since
150 * our caller will find the information useful. 150 * our caller will find the information useful.
151 * Currently, only move_monster calls this function. 151 * Currently, only move_monster calls this function.
152 * Fix function so that we always make calls to get_rangevector 152 * Fix function so that we always make calls to get_rangevector
153 * if we have a valid target - function as not doing so in 153 * if we have a valid target - function as not doing so in
154 * many cases. 154 * many cases.
155 */ 155 */
156
157object * 156object *
158find_enemy (object *npc, rv_vector * rv) 157find_enemy (object *npc, rv_vector * rv)
159{ 158{
160 object *attacker, *tmp = NULL; 159 object *attacker, *tmp = NULL;
161 160
229/* Sees if this monster should wake up. 228/* Sees if this monster should wake up.
230 * Currently, this is only called from move_monster, and 229 * Currently, this is only called from move_monster, and
231 * if enemy is set, then so should be rv. 230 * if enemy is set, then so should be rv.
232 * returns 1 if the monster should wake up, 0 otherwise. 231 * returns 1 if the monster should wake up, 0 otherwise.
233 */ 232 */
234
235int 233int
236check_wakeup (object *op, object *enemy, rv_vector * rv) 234check_wakeup (object *op, object *enemy, rv_vector * rv)
237{ 235{
238 int radius = op->stats.Wis > MIN_MON_RADIUS ? op->stats.Wis : MIN_MON_RADIUS; 236 int radius = op->stats.Wis > MIN_MON_RADIUS ? op->stats.Wis : MIN_MON_RADIUS;
239 237
287} 285}
288 286
289/* 287/*
290 * Move-monster returns 1 if the object has been freed, otherwise 0. 288 * Move-monster returns 1 if the object has been freed, otherwise 0.
291 */ 289 */
292
293int 290int
294move_monster (object *op) 291move_monster (object *op)
295{ 292{
296 int dir, diff, pre_att_dir; /* elmex: pre_att_dir remembers the direction before attack movement */ 293 int dir, diff, pre_att_dir; /* elmex: pre_att_dir remembers the direction before attack movement */
297 object *owner, *enemy, *part, *oph = op; 294 object *owner, *enemy, *part, *oph = op;
446 } /* stand still */ 443 } /* stand still */
447 return 0; 444 return 0;
448 } /* no enemy */ 445 } /* no enemy */
449 446
450 /* We have an enemy. Block immediately below is for pets */ 447 /* We have an enemy. Block immediately below is for pets */
451 if ((op->attack_movement & HI4) == PETMOVE && (owner = op->owner) != NULL && !on_same_map (op, owner)) 448 if ((op->attack_movement & HI4) == PETMOVE
449 && (owner = op->owner) != NULL
450 && !on_same_map (op, owner)
451 && !owner->flag [FLAG_REMOVED])
452 return follow_owner (op, owner); 452 return follow_owner (op, owner);
453 453
454 /* doppleganger code to change monster facing to that of the nearest 454 /* doppleganger code to change monster facing to that of the nearest
455 * player. Hmm. The code is here, but no monster in the current 455 * player. Hmm. The code is here, but no monster in the current
456 * arch set uses it. 456 * arch set uses it.
475 if (!QUERY_FLAG (op, FLAG_SCARED)) 475 if (!QUERY_FLAG (op, FLAG_SCARED))
476 { 476 {
477 rv_vector rv1; 477 rv_vector rv1;
478 478
479 /* now we test every part of an object .... this is a real ugly piece of code */ 479 /* now we test every part of an object .... this is a real ugly piece of code */
480 for (part = op; part != NULL; part = part->more) 480 for (part = op; part; part = part->more)
481 { 481 {
482 get_rangevector (part, enemy, &rv1, 0x1); 482 get_rangevector (part, enemy, &rv1, 0x1);
483 dir = rv1.direction; 483 dir = rv1.direction;
484 484
485 /* hm, not sure about this part - in original was a scared flag here too 485 /* hm, not sure about this part - in original was a scared flag here too
486 * but that we test above... so can be old code here 486 * but that we test above... so can be old code here
487 */ 487 */
488 if (QUERY_FLAG (op, FLAG_RUN_AWAY)) 488 if (QUERY_FLAG (op, FLAG_RUN_AWAY))
489 dir = absdir (dir + 4); 489 dir = absdir (dir + 4);
490
490 if (QUERY_FLAG (op, FLAG_CONFUSED)) 491 if (QUERY_FLAG (op, FLAG_CONFUSED))
491 dir = absdir (dir + rndm (3) + rndm (3) - 2); 492 dir = absdir (dir + rndm (3) + rndm (3) - 2);
492 493
493 if (QUERY_FLAG (op, FLAG_CAST_SPELL) && !(rndm (3))) 494 if (QUERY_FLAG (op, FLAG_CAST_SPELL) && !(rndm (3)))
494 {
495 if (monster_cast_spell (op, part, enemy, dir, &rv1)) 495 if (monster_cast_spell (op, part, enemy, dir, &rv1))
496 return 0; 496 return 0;
497 }
498 497
499 if (QUERY_FLAG (op, FLAG_READY_SCROLL) && !(rndm (3))) 498 if (QUERY_FLAG (op, FLAG_READY_SCROLL) && !(rndm (3)))
500 {
501 if (monster_use_scroll (op, part, enemy, dir, &rv1)) 499 if (monster_use_scroll (op, part, enemy, dir, &rv1))
502 return 0; 500 return 0;
503 }
504 501
505 if (QUERY_FLAG (op, FLAG_READY_RANGE) && !(rndm (3))) 502 if (QUERY_FLAG (op, FLAG_READY_RANGE) && !(rndm (3)))
506 {
507 if (monster_use_range (op, part, enemy, dir)) 503 if (monster_use_range (op, part, enemy, dir))
508 return 0; 504 return 0;
509 } 505
510 if (QUERY_FLAG (op, FLAG_READY_SKILL) && !(rndm (3))) 506 if (QUERY_FLAG (op, FLAG_READY_SKILL) && !(rndm (3)))
511 {
512 if (monster_use_skill (op, rv.part, enemy, rv.direction)) 507 if (monster_use_skill (op, rv.part, enemy, rv.direction))
513 return 0; 508 return 0;
514 } 509
515 if (QUERY_FLAG (op, FLAG_READY_BOW) && !(rndm (2))) 510 if (QUERY_FLAG (op, FLAG_READY_BOW) && !(rndm (2)))
516 {
517 if (monster_use_bow (op, part, enemy, dir)) 511 if (monster_use_bow (op, part, enemy, dir))
518 return 0; 512 return 0;
519 }
520 } /* for processing of all parts */ 513 } /* for processing of all parts */
521 } /* If not scared */ 514 } /* If not scared */
522 515
523 516
524 part = rv.part; 517 part = rv.part;
896 * The skills we are treating here are all but those. -b.t. 889 * The skills we are treating here are all but those. -b.t.
897 * 890 *
898 * At the moment this is only useful for throwing, perhaps for 891 * At the moment this is only useful for throwing, perhaps for
899 * stealing. TODO: This should be more integrated in the game. -MT, 25.11.01 892 * stealing. TODO: This should be more integrated in the game. -MT, 25.11.01
900 */ 893 */
901
902int 894int
903monster_use_skill (object *head, object *part, object *pl, int dir) 895monster_use_skill (object *head, object *part, object *pl, int dir)
904{ 896{
905 object *skill, *owner; 897 object *skill, *owner;
906 898
912 int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y); 904 int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y);
913 905
914 if (dirdiff (dir, dir2) < 1) 906 if (dirdiff (dir, dir2) < 1)
915 return 0; /* Might hit owner with skill -thrown rocks for example ? */ 907 return 0; /* Might hit owner with skill -thrown rocks for example ? */
916 } 908 }
909
917 if (QUERY_FLAG (head, FLAG_CONFUSED)) 910 if (QUERY_FLAG (head, FLAG_CONFUSED))
918 dir = absdir (dir + rndm (3) + rndm (3) - 2); 911 dir = absdir (dir + rndm (3) + rndm (3) - 2);
919 912
920 /* skill selection - monster will use the next unused skill. 913 /* skill selection - monster will use the next unused skill.
921 * well...the following scenario will allow the monster to 914 * well...the following scenario will allow the monster to
922 * toggle between 2 skills. One day it would be nice to make 915 * toggle between 2 skills. One day it would be nice to make
923 * more skills available to monsters. 916 * more skills available to monsters.
924 */ 917 */
925
926 for (skill = head->inv; skill != NULL; skill = skill->below) 918 for (skill = head->inv; skill; skill = skill->below)
927 if (skill->type == SKILL && skill != head->chosen_skill) 919 if (skill->type == SKILL && skill != head->chosen_skill)
928 { 920 {
929 head->chosen_skill = skill; 921 head->chosen_skill = skill;
930 break; 922 break;
931 } 923 }
934 { 926 {
935 LOG (llevDebug, "Error: Monster %s (%d) has FLAG_READY_SKILL without skill.\n", &head->name, head->count); 927 LOG (llevDebug, "Error: Monster %s (%d) has FLAG_READY_SKILL without skill.\n", &head->name, head->count);
936 CLEAR_FLAG (head, FLAG_READY_SKILL); 928 CLEAR_FLAG (head, FLAG_READY_SKILL);
937 return 0; 929 return 0;
938 } 930 }
931
939 /* use skill */ 932 /* use skill */
940 return do_skill (head, part, head->chosen_skill, dir, NULL); 933 return do_skill (head, part, head->chosen_skill, dir, NULL);
941} 934}
942 935
943/* Monster will use a ranged spell attack. */ 936/* Monster will use a ranged spell attack. */
944
945int 937int
946monster_use_range (object *head, object *part, object *pl, int dir) 938monster_use_range (object *head, object *part, object *pl, int dir)
947{ 939{
948 object *wand, *owner; 940 object *wand, *owner;
949 int at_least_one = 0; 941 int at_least_one = 0;
956 int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y); 948 int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y);
957 949
958 if (dirdiff (dir, dir2) < 2) 950 if (dirdiff (dir, dir2) < 2)
959 return 0; /* Might hit owner with spell */ 951 return 0; /* Might hit owner with spell */
960 } 952 }
953
961 if (QUERY_FLAG (head, FLAG_CONFUSED)) 954 if (QUERY_FLAG (head, FLAG_CONFUSED))
962 dir = absdir (dir + rndm (3) + rndm (3) - 2); 955 dir = absdir (dir + rndm (3) + rndm (3) - 2);
963 956
964 for (wand = head->inv; wand != NULL; wand = wand->below) 957 for (wand = head->inv; wand; wand = wand->below)
965 { 958 {
966 if (wand->type == WAND) 959 if (wand->type == WAND)
967 { 960 {
968 /* Found a wand, let's see if it has charges left */ 961 /* Found a wand, let's see if it has charges left */
969 at_least_one = 1; 962 at_least_one = 1;
975 if (!(--wand->stats.food)) 968 if (!(--wand->stats.food))
976 { 969 {
977 if (wand->arch) 970 if (wand->arch)
978 { 971 {
979 CLEAR_FLAG (wand, FLAG_ANIMATE); 972 CLEAR_FLAG (wand, FLAG_ANIMATE);
980 wand->face = wand->arch->clone.face; 973 wand->face = wand->arch->face;
981 wand->set_speed (0); 974 wand->set_speed (0);
982 } 975 }
983 } 976 }
984 /* Success */ 977 /* Success */
985 return 1; 978 return 1;
1004 } 997 }
1005 998
1006 if (at_least_one) 999 if (at_least_one)
1007 return 0; 1000 return 0;
1008 1001
1009 LOG (llevError, "Error: Monster %s (%d) HAS_READY_RANG() without wand/horn/rod.\n", &head->name, head->count); 1002 LOG (llevError, "Error: Monster %s (%d) HAS_READY_RANGE() without wand/horn/rod.\n", &head->name, head->count);
1010 CLEAR_FLAG (head, FLAG_READY_RANGE); 1003 CLEAR_FLAG (head, FLAG_READY_RANGE);
1011 return 0; 1004 return 0;
1012} 1005}
1013 1006
1014int 1007int
1016{ 1009{
1017 object *owner; 1010 object *owner;
1018 1011
1019 if (!(dir = path_to_player (part, pl, 0))) 1012 if (!(dir = path_to_player (part, pl, 0)))
1020 return 0; 1013 return 0;
1014
1021 if (QUERY_FLAG (head, FLAG_CONFUSED)) 1015 if (QUERY_FLAG (head, FLAG_CONFUSED))
1022 dir = absdir (dir + rndm (3) + rndm (3) - 2); 1016 dir = absdir (dir + rndm (3) + rndm (3) - 2);
1023 1017
1024 if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL) 1018 if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL)
1025 { 1019 {
1033 return fire_bow (head, part, NULL, dir, 0, part->x, part->y); 1027 return fire_bow (head, part, NULL, dir, 0, part->x, part->y);
1034 1028
1035} 1029}
1036 1030
1037/* Checks if putting on 'item' will make 'who' do more 1031/* Checks if putting on 'item' will make 'who' do more
1038 * damage. This is a very simplistic check - also checking things 1032 * damage. This is a very simplistic check - also checking things
1039 * like speed and ac are also relevant. 1033 * like speed and ac are also relevant.
1040 * 1034 *
1041 * return true if item is a better object. 1035 * return true if item is a better object.
1042 */ 1036 */
1043
1044int 1037int
1045check_good_weapon (object *who, object *item) 1038check_good_weapon (object *who, object *item)
1046{ 1039{
1047 object *other_weap; 1040 object *other_weap;
1048 int val = 0, i; 1041 int val = 0, i;
1049 1042
1050 for (other_weap = who->inv; other_weap != NULL; other_weap = other_weap->below) 1043 for (other_weap = who->inv; other_weap; other_weap = other_weap->below)
1051 if (other_weap->type == item->type && QUERY_FLAG (other_weap, FLAG_APPLIED)) 1044 if (other_weap->type == item->type && QUERY_FLAG (other_weap, FLAG_APPLIED))
1052 break; 1045 break;
1053 1046
1054 if (other_weap == NULL) /* No other weapons */ 1047 if (!other_weap) /* No other weapons */
1055 return 1; 1048 return 1;
1056 1049
1057 /* Rather than go through and apply the new one, and see if it is 1050 /* Rather than go through and apply the new one, and see if it is
1058 * better, just do some simple checks 1051 * better, just do some simple checks
1059 * Put some multipliers for things that hvae several effects, 1052 * Put some multipliers for things that hvae several effects,
1064 val += (item->magic - other_weap->magic) * 3; 1057 val += (item->magic - other_weap->magic) * 3;
1065 /* Monsters don't really get benefits from things like regen rates 1058 /* Monsters don't really get benefits from things like regen rates
1066 * from items. But the bonus for their stats are very important. 1059 * from items. But the bonus for their stats are very important.
1067 */ 1060 */
1068 for (i = 0; i < NUM_STATS; i++) 1061 for (i = 0; i < NUM_STATS; i++)
1069 val += (get_attr_value (&item->stats, i) - get_attr_value (&other_weap->stats, i)) * 2; 1062 val += item->stats.stat (i) - other_weap->stats.stat (i) * 2;
1070 1063
1071 if (val > 0) 1064 if (val > 0)
1072 return 1; 1065 return 1;
1073 else 1066 else
1074 return 0; 1067 return 0;
1075
1076} 1068}
1077 1069
1078int 1070int
1079check_good_armour (object *who, object *item) 1071check_good_armour (object *who, object *item)
1080{ 1072{
1081 object *other_armour; 1073 object *other_armour;
1082 int val = 0, i; 1074 int val = 0, i;
1083 1075
1084 for (other_armour = who->inv; other_armour != NULL; other_armour = other_armour->below) 1076 for (other_armour = who->inv; other_armour; other_armour = other_armour->below)
1085 if (other_armour->type == item->type && QUERY_FLAG (other_armour, FLAG_APPLIED)) 1077 if (other_armour->type == item->type && QUERY_FLAG (other_armour, FLAG_APPLIED))
1086 break; 1078 break;
1087 1079
1088 if (other_armour == NULL) /* No other armour, use the new */ 1080 if (other_armour == NULL) /* No other armour, use the new */
1089 return 1; 1081 return 1;
1111 1103
1112 if (val > 0) 1104 if (val > 0)
1113 return 1; 1105 return 1;
1114 else 1106 else
1115 return 0; 1107 return 0;
1116
1117} 1108}
1118 1109
1119/* 1110/*
1120 * monster_check_pickup(): checks for items that monster can pick up. 1111 * monster_check_pickup(): checks for items that monster can pick up.
1121 * 1112 *
1129 * This function was seen be continueing looping at one point (tmp->below 1120 * This function was seen be continueing looping at one point (tmp->below
1130 * became a recursive loop. It may be better to call monster_check_apply 1121 * became a recursive loop. It may be better to call monster_check_apply
1131 * after we pick everything up, since that function may call others which 1122 * after we pick everything up, since that function may call others which
1132 * affect stacking on this space. 1123 * affect stacking on this space.
1133 */ 1124 */
1134
1135void 1125void
1136monster_check_pickup (object *monster) 1126monster_check_pickup (object *monster)
1137{ 1127{
1138 object *tmp, *next; 1128 object *tmp, *next;
1139 1129
1158 * monster_can_pick(): If the monster is interested in picking up 1148 * monster_can_pick(): If the monster is interested in picking up
1159 * the item, then return 0. Otherwise 0. 1149 * the item, then return 0. Otherwise 0.
1160 * Instead of pick_up, flags for "greed", etc, should be used. 1150 * Instead of pick_up, flags for "greed", etc, should be used.
1161 * I've already utilized flags for bows, wands, rings, etc, etc. -Frank. 1151 * I've already utilized flags for bows, wands, rings, etc, etc. -Frank.
1162 */ 1152 */
1163
1164int 1153int
1165monster_can_pick (object *monster, object *item) 1154monster_can_pick (object *monster, object *item)
1166{ 1155{
1167 int flag = 0; 1156 int flag = 0;
1168 int i; 1157 int i;
1214 case ROD: 1203 case ROD:
1215 flag = QUERY_FLAG (monster, FLAG_USE_RANGE); 1204 flag = QUERY_FLAG (monster, FLAG_USE_RANGE);
1216 break; 1205 break;
1217 1206
1218 case SPELLBOOK: 1207 case SPELLBOOK:
1219 flag = (monster->arch != NULL && QUERY_FLAG ((&monster->arch->clone), FLAG_CAST_SPELL)); 1208 flag = monster->arch && QUERY_FLAG (monster->arch, FLAG_CAST_SPELL);
1220 break; 1209 break;
1221 1210
1222 case SCROLL: 1211 case SCROLL:
1223 flag = QUERY_FLAG (monster, FLAG_USE_SCROLL); 1212 flag = QUERY_FLAG (monster, FLAG_USE_SCROLL);
1224 break; 1213 break;
1226 case BOW: 1215 case BOW:
1227 case ARROW: 1216 case ARROW:
1228 flag = QUERY_FLAG (monster, FLAG_USE_BOW); 1217 flag = QUERY_FLAG (monster, FLAG_USE_BOW);
1229 break; 1218 break;
1230 } 1219 }
1220
1231 /* Simplistic check - if the monster has a location to equip it, he will 1221 /* Simplistic check - if the monster has a location to equip it, he will
1232 * pick it up. Note that this doesn't handle cases where an item may 1222 * pick it up. Note that this doesn't handle cases where an item may
1233 * use several locations. 1223 * use several locations.
1234 */ 1224 */
1235 for (i = 0; i < NUM_BODY_LOCATIONS; i++) 1225 for (i = 0; i < NUM_BODY_LOCATIONS; i++)
1236 { 1226 {
1237 if (monster->body_info[i] && item->body_info[i]) 1227 if (monster->slot[i].info && item->slot[i].info)
1238 { 1228 {
1239 flag = 1; 1229 flag = 1;
1240 break; 1230 break;
1241 } 1231 }
1242 } 1232 }
1250 * monster_apply_below(): 1240 * monster_apply_below():
1251 * Vick's (vick@bern.docs.uu.se) @921107 -> If a monster who's 1241 * Vick's (vick@bern.docs.uu.se) @921107 -> If a monster who's
1252 * eager to apply things, encounters something apply-able, 1242 * eager to apply things, encounters something apply-able,
1253 * then make him apply it 1243 * then make him apply it
1254 */ 1244 */
1255
1256void 1245void
1257monster_apply_below (object *monster) 1246monster_apply_below (object *monster)
1258{ 1247{
1259 object *tmp, *next; 1248 object *tmp, *next;
1260 1249
1287 * a pointer to that object is returned, so it can be dropped. 1276 * a pointer to that object is returned, so it can be dropped.
1288 * (so that other monsters can pick it up and use it) 1277 * (so that other monsters can pick it up and use it)
1289 * Note that as things are now, monsters never drop something - 1278 * Note that as things are now, monsters never drop something -
1290 * they can pick up all that they can use. 1279 * they can pick up all that they can use.
1291 */ 1280 */
1292
1293/* Sept 96, fixed this so skills will be readied -b.t.*/ 1281/* Sept 96, fixed this so skills will be readied -b.t.*/
1294
1295void 1282void
1296monster_check_apply (object *mon, object *item) 1283monster_check_apply (object *mon, object *item)
1297{ 1284{
1298
1299 int flag = 0; 1285 int flag = 0;
1300 1286
1301 if (item->type == SPELLBOOK && mon->arch != NULL && (QUERY_FLAG ((&mon->arch->clone), FLAG_CAST_SPELL))) 1287 if (item->type == SPELLBOOK && mon->arch && (QUERY_FLAG (mon->arch, FLAG_CAST_SPELL)))
1302 { 1288 {
1303 SET_FLAG (mon, FLAG_CAST_SPELL); 1289 SET_FLAG (mon, FLAG_CAST_SPELL);
1304 return; 1290 return;
1305 } 1291 }
1306 1292
1315 if (QUERY_FLAG (mon, FLAG_USE_BOW) && item->type == ARROW) 1301 if (QUERY_FLAG (mon, FLAG_USE_BOW) && item->type == ARROW)
1316 { 1302 {
1317 /* Check for the right kind of bow */ 1303 /* Check for the right kind of bow */
1318 object *bow; 1304 object *bow;
1319 1305
1320 for (bow = mon->inv; bow != NULL; bow = bow->below) 1306 for (bow = mon->inv; bow; bow = bow->below)
1321 if (bow->type == BOW && bow->race == item->race) 1307 if (bow->type == BOW && bow->race == item->race)
1322 { 1308 {
1323 SET_FLAG (mon, FLAG_READY_BOW); 1309 SET_FLAG (mon, FLAG_READY_BOW);
1324 LOG (llevMonster, "Found correct bow for arrows.\n"); 1310 LOG (llevMonster, "Found correct bow for arrows.\n");
1325 return; /* nothing more to do for arrows */ 1311 return; /* nothing more to do for arrows */
1377 */ 1363 */
1378 SET_FLAG (mon, FLAG_READY_SKILL); 1364 SET_FLAG (mon, FLAG_READY_SKILL);
1379 return; 1365 return;
1380 } 1366 }
1381 1367
1382
1383 /* if we don't match one of the above types, return now. 1368 /* if we don't match one of the above types, return now.
1384 * can_apply_object will say that we can apply things like flesh, 1369 * can_apply_object will say that we can apply things like flesh,
1385 * bolts, and whatever else, because it only checks against the 1370 * bolts, and whatever else, because it only checks against the
1386 * body_info locations. 1371 * body_info locations.
1387 */ 1372 */
1398 /* should only be applying this item, not unapplying it. 1383 /* should only be applying this item, not unapplying it.
1399 * also, ignore status of curse so they can take off old armour. 1384 * also, ignore status of curse so they can take off old armour.
1400 * monsters have some advantages after all. 1385 * monsters have some advantages after all.
1401 */ 1386 */
1402 manual_apply (mon, item, AP_APPLY | AP_IGNORE_CURSE); 1387 manual_apply (mon, item, AP_APPLY | AP_IGNORE_CURSE);
1403
1404 return;
1405} 1388}
1406 1389
1407void 1390void
1408npc_call_help (object *op) 1391npc_call_help (object *op)
1409{ 1392{
1427 if (QUERY_FLAG (npc, FLAG_ALIVE) && QUERY_FLAG (npc, FLAG_UNAGGRESSIVE)) 1410 if (QUERY_FLAG (npc, FLAG_ALIVE) && QUERY_FLAG (npc, FLAG_UNAGGRESSIVE))
1428 npc->enemy = op->enemy; 1411 npc->enemy = op->enemy;
1429 } 1412 }
1430} 1413}
1431 1414
1432
1433int 1415int
1434dist_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) 1416dist_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv)
1435{ 1417{
1436
1437 if (can_hit (part, enemy, rv)) 1418 if (can_hit (part, enemy, rv))
1438 return dir; 1419 return dir;
1439 if (rv->distance < 10) 1420 if (rv->distance < 10)
1440 return absdir (dir + 4); 1421 return absdir (dir + 4);
1441 else if (rv->distance > 18) 1422 else if (rv->distance > 18)
1442 return dir; 1423 return dir;
1424
1443 return 0; 1425 return 0;
1444} 1426}
1445 1427
1446int 1428int
1447run_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) 1429run_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv)
1448{ 1430{
1449
1450 if ((can_hit (part, enemy, rv) && ob->move_status < 20) || ob->move_status < 20) 1431 if ((can_hit (part, enemy, rv) && ob->move_status < 20) || ob->move_status < 20)
1451 { 1432 {
1452 ob->move_status++; 1433 ob->move_status++;
1453 return (dir); 1434 return (dir);
1454 } 1435 }
1455 else if (ob->move_status > 20) 1436 else if (ob->move_status > 20)
1456 ob->move_status = 0; 1437 ob->move_status = 0;
1438
1457 return absdir (dir + 4); 1439 return absdir (dir + 4);
1458} 1440}
1459 1441
1460int 1442int
1461hitrun_att (int dir, object *ob, object *enemy) 1443hitrun_att (int dir, object *ob, object *enemy)
1464 return dir; 1446 return dir;
1465 else if (ob->move_status < 50) 1447 else if (ob->move_status < 50)
1466 return absdir (dir + 4); 1448 return absdir (dir + 4);
1467 else 1449 else
1468 ob->move_status = 0; 1450 ob->move_status = 0;
1451
1469 return absdir (dir + 4); 1452 return absdir (dir + 4);
1470} 1453}
1471 1454
1472int 1455int
1473wait_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) 1456wait_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv)
1482 return 0; 1465 return 0;
1483 else if (ob->move_status < 10) 1466 else if (ob->move_status < 10)
1484 return dir; 1467 return dir;
1485 else if (ob->move_status < 15) 1468 else if (ob->move_status < 15)
1486 return absdir (dir + 4); 1469 return absdir (dir + 4);
1470
1487 ob->move_status = 0; 1471 ob->move_status = 0;
1488 return 0; 1472 return 0;
1489} 1473}
1490 1474
1491int 1475int
1499 * at least one map has this set, and whatever the map contains, the 1483 * at least one map has this set, and whatever the map contains, the
1500 * server should try to be resilant enough to avoid the problem 1484 * server should try to be resilant enough to avoid the problem
1501 */ 1485 */
1502 if (ob->stats.maxhp && (ob->stats.hp * 100) / ob->stats.maxhp < ob->run_away) 1486 if (ob->stats.maxhp && (ob->stats.hp * 100) / ob->stats.maxhp < ob->run_away)
1503 return absdir (dir + 4); 1487 return absdir (dir + 4);
1488
1504 return dist_att (dir, ob, enemy, part, rv); 1489 return dist_att (dir, ob, enemy, part, rv);
1505} 1490}
1506 1491
1507int 1492int
1508wait_att2 (int dir, object *ob, object *enemy, object *part, rv_vector * rv) 1493wait_att2 (int dir, object *ob, object *enemy, object *part, rv_vector * rv)
1509{ 1494{
1510 if (rv->distance < 9) 1495 if (rv->distance < 9)
1511 return absdir (dir + 4); 1496 return absdir (dir + 4);
1497
1512 return 0; 1498 return 0;
1513} 1499}
1514 1500
1515void 1501void
1516circ1_move (object *ob) 1502circ1_move (object *ob)
1517{ 1503{
1518 static int circle[12] = { 3, 3, 4, 5, 5, 6, 7, 7, 8, 1, 1, 2 }; 1504 static int circle[12] = { 3, 3, 4, 5, 5, 6, 7, 7, 8, 1, 1, 2 };
1505
1519 if (++ob->move_status > 11) 1506 if (++ob->move_status > 11)
1520 ob->move_status = 0; 1507 ob->move_status = 0;
1508
1521 if (!(move_object (ob, circle[ob->move_status]))) 1509 if (!(move_object (ob, circle[ob->move_status])))
1522 (void) move_object (ob, rndm (8) + 1); 1510 move_object (ob, rndm (8) + 1);
1523} 1511}
1524 1512
1525void 1513void
1526circ2_move (object *ob) 1514circ2_move (object *ob)
1527{ 1515{
1528 static int circle[20] = { 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8, 1, 1, 1, 2, 2 }; 1516 static int circle[20] = { 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8, 1, 1, 1, 2, 2 };
1517
1529 if (++ob->move_status > 19) 1518 if (++ob->move_status > 19)
1530 ob->move_status = 0; 1519 ob->move_status = 0;
1520
1531 if (!(move_object (ob, circle[ob->move_status]))) 1521 if (!(move_object (ob, circle[ob->move_status])))
1532 (void) move_object (ob, rndm (8) + 1); 1522 move_object (ob, rndm (8) + 1);
1533} 1523}
1534 1524
1535void 1525void
1536pace_movev (object *ob) 1526pace_movev (object *ob)
1537{ 1527{
1538 if (ob->move_status++ > 6) 1528 if (ob->move_status++ > 6)
1539 ob->move_status = 0; 1529 ob->move_status = 0;
1530
1540 if (ob->move_status < 4) 1531 if (ob->move_status < 4)
1541 (void) move_object (ob, 5); 1532 move_object (ob, 5);
1542 else 1533 else
1543 (void) move_object (ob, 1); 1534 move_object (ob, 1);
1544} 1535}
1545 1536
1546void 1537void
1547pace_moveh (object *ob) 1538pace_moveh (object *ob)
1548{ 1539{
1549 if (ob->move_status++ > 6) 1540 if (ob->move_status++ > 6)
1550 ob->move_status = 0; 1541 ob->move_status = 0;
1542
1551 if (ob->move_status < 4) 1543 if (ob->move_status < 4)
1552 (void) move_object (ob, 3); 1544 move_object (ob, 3);
1553 else 1545 else
1554 (void) move_object (ob, 7); 1546 move_object (ob, 7);
1555} 1547}
1556 1548
1557void 1549void
1558pace2_movev (object *ob) 1550pace2_movev (object *ob)
1559{ 1551{
1560 if (ob->move_status++ > 16) 1552 if (ob->move_status++ > 16)
1561 ob->move_status = 0; 1553 ob->move_status = 0;
1554
1562 if (ob->move_status < 6) 1555 if (ob->move_status < 6)
1563 (void) move_object (ob, 5); 1556 move_object (ob, 5);
1564 else if (ob->move_status < 8) 1557 else if (ob->move_status < 8)
1565 return; 1558 return;
1566 else if (ob->move_status < 13) 1559 else if (ob->move_status < 13)
1567 (void) move_object (ob, 1); 1560 move_object (ob, 1);
1568 else 1561 else
1569 return; 1562 return;
1570} 1563}
1571 1564
1572void 1565void
1573pace2_moveh (object *ob) 1566pace2_moveh (object *ob)
1574{ 1567{
1575 if (ob->move_status++ > 16) 1568 if (ob->move_status++ > 16)
1576 ob->move_status = 0; 1569 ob->move_status = 0;
1570
1577 if (ob->move_status < 6) 1571 if (ob->move_status < 6)
1578 (void) move_object (ob, 3); 1572 move_object (ob, 3);
1579 else if (ob->move_status < 8) 1573 else if (ob->move_status < 8)
1580 return; 1574 return;
1581 else if (ob->move_status < 13) 1575 else if (ob->move_status < 13)
1582 (void) move_object (ob, 7); 1576 move_object (ob, 7);
1583 else 1577 else
1584 return; 1578 return;
1585} 1579}
1586 1580
1587void 1581void
1630 * monsters to throw things like chairs and other pieces of 1624 * monsters to throw things like chairs and other pieces of
1631 * furniture, even if they are not good throwable objects. 1625 * furniture, even if they are not good throwable objects.
1632 * Probably better to have the monster throw a throwable object 1626 * Probably better to have the monster throw a throwable object
1633 * first, then throw any non equipped weapon. 1627 * first, then throw any non equipped weapon.
1634 */ 1628 */
1635
1636object * 1629object *
1637find_mon_throw_ob (object *op) 1630find_mon_throw_ob (object *op)
1638{ 1631{
1639 object *tmp = NULL; 1632 object *tmp = NULL;
1640 1633
1815/* determine if op stands in a lighted square. This is not a very 1808/* determine if op stands in a lighted square. This is not a very
1816 * intellegent algorithm. For one thing, we ignore los here, SO it 1809 * intellegent algorithm. For one thing, we ignore los here, SO it
1817 * is possible for a bright light to illuminate a player on the 1810 * is possible for a bright light to illuminate a player on the
1818 * other side of a wall (!). 1811 * other side of a wall (!).
1819 */ 1812 */
1820
1821int 1813int
1822stand_in_light (object *op) 1814stand_in_light (object *op)
1823{ 1815{
1824 sint16 nx, ny; 1816 sint16 nx, ny;
1825 maptile *m; 1817 maptile *m;
1826 1818
1827
1828 if (!op) 1819 if (!op)
1829 return 0; 1820 return 0;
1821
1830 if (op->glow_radius > 0) 1822 if (op->glow_radius > 0)
1831 return 1; 1823 return 1;
1832 1824
1833 if (op->map) 1825 if (op->map)
1834 { 1826 {
1835 int x, y, x1, y1; 1827 int x, y, x1, y1;
1836
1837
1838 1828
1839 /* Check the spaces with the max light radius to see if any of them 1829 /* Check the spaces with the max light radius to see if any of them
1840 * have lights, and if any of them light the player enough, then return 1. 1830 * have lights, and if any of them light the player enough, then return 1.
1841 */ 1831 */
1842 for (x = op->x - MAX_LIGHT_RADII; x <= op->x + MAX_LIGHT_RADII; x++) 1832 for (x = op->x - MAX_LIGHT_RADII; x <= op->x + MAX_LIGHT_RADII; x++)
1855 if (isqrt (x1 + y1) < GET_MAP_LIGHT (m, nx, ny)) 1845 if (isqrt (x1 + y1) < GET_MAP_LIGHT (m, nx, ny))
1856 return 1; 1846 return 1;
1857 } 1847 }
1858 } 1848 }
1859 } 1849 }
1850
1860 return 0; 1851 return 0;
1861} 1852}
1862
1863 1853
1864/* assuming no walls/barriers, lets check to see if its *possible* 1854/* assuming no walls/barriers, lets check to see if its *possible*
1865 * to see an enemy. Note, "detection" is different from "seeing". 1855 * to see an enemy. Note, "detection" is different from "seeing".
1866 * See can_detect_enemy() for more details. -b.t. 1856 * See can_detect_enemy() for more details. -b.t.
1867 * return 0 if can't be seen, 1 if can be 1857 * return 0 if can't be seen, 1 if can be
1868 */ 1858 */
1869
1870int 1859int
1871can_see_enemy (object *op, object *enemy) 1860can_see_enemy (object *op, object *enemy)
1872{ 1861{
1873 object *looker = op->head ? op->head : op; 1862 object *looker = op->head ? op->head : op;
1874 1863

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines