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 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 | #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 | } |
|
|
96 | |
95 | return can_detect_enemy (npc, npc->enemy, rv) ? npc->enemy : NULL; |
97 | return can_detect_enemy (npc, npc->enemy, rv) ? npc->enemy : NULL; |
96 | } |
98 | } |
97 | |
99 | |
98 | /* Returns the nearest living creature (monster or generator). |
100 | /* Returns the nearest living creature (monster or generator). |
99 | * Modified to deal with tiled maps properly. |
101 | * Modified to deal with tiled maps properly. |
… | |
… | |
143 | } |
145 | } |
144 | |
146 | |
145 | return 0; |
147 | return 0; |
146 | } |
148 | } |
147 | |
149 | |
148 | |
|
|
149 | /* Tries to find an enmy for npc. We pass the range vector since |
150 | /* Tries to find an enemy for npc. We pass the range vector since |
150 | * our caller will find the information useful. |
151 | * our caller will find the information useful. |
151 | * Currently, only move_monster calls this function. |
152 | * Currently, only move_monster calls this function. |
152 | * Fix function so that we always make calls to get_rangevector |
153 | * Fix function so that we always make calls to get_rangevector |
153 | * if we have a valid target - function as not doing so in |
154 | * if we have a valid target - function as not doing so in |
154 | * many cases. |
155 | * many cases. |
155 | */ |
156 | */ |
156 | |
|
|
157 | object * |
157 | object * |
158 | find_enemy (object *npc, rv_vector * rv) |
158 | find_enemy (object *npc, rv_vector * rv) |
159 | { |
159 | { |
160 | object *attacker, *tmp = NULL; |
160 | object *attacker, *tmp = NULL; |
161 | |
161 | |
… | |
… | |
167 | { |
167 | { |
168 | tmp = find_nearest_living_creature (npc); |
168 | tmp = find_nearest_living_creature (npc); |
169 | |
169 | |
170 | if (tmp) |
170 | if (tmp) |
171 | get_rangevector (npc, tmp, rv, 0); |
171 | get_rangevector (npc, tmp, rv, 0); |
|
|
172 | |
172 | return tmp; |
173 | return tmp; |
173 | } |
174 | } |
174 | |
175 | |
175 | /* Here is the main enemy selection. |
176 | /* Here is the main enemy selection. |
176 | * We want this: if there is an enemy, attack him until its not possible or |
177 | * We want this: if there is an enemy, attack him until its not possible or |
… | |
… | |
229 | /* Sees if this monster should wake up. |
230 | /* Sees if this monster should wake up. |
230 | * Currently, this is only called from move_monster, and |
231 | * Currently, this is only called from move_monster, and |
231 | * if enemy is set, then so should be rv. |
232 | * if enemy is set, then so should be rv. |
232 | * returns 1 if the monster should wake up, 0 otherwise. |
233 | * returns 1 if the monster should wake up, 0 otherwise. |
233 | */ |
234 | */ |
234 | |
|
|
235 | int |
235 | int |
236 | check_wakeup (object *op, object *enemy, rv_vector * rv) |
236 | check_wakeup (object *op, object *enemy, rv_vector * rv) |
237 | { |
237 | { |
238 | int radius = op->stats.Wis > MIN_MON_RADIUS ? op->stats.Wis : MIN_MON_RADIUS; |
238 | int radius = op->stats.Wis > MIN_MON_RADIUS ? op->stats.Wis : MIN_MON_RADIUS; |
239 | |
239 | |
… | |
… | |
287 | } |
287 | } |
288 | |
288 | |
289 | /* |
289 | /* |
290 | * Move-monster returns 1 if the object has been freed, otherwise 0. |
290 | * Move-monster returns 1 if the object has been freed, otherwise 0. |
291 | */ |
291 | */ |
292 | |
|
|
293 | int |
292 | int |
294 | move_monster (object *op) |
293 | move_monster (object *op) |
295 | { |
294 | { |
296 | int dir, diff, pre_att_dir; /* elmex: pre_att_dir remembers the direction before attack movement */ |
295 | int dir, diff, pre_att_dir; /* elmex: pre_att_dir remembers the direction before attack movement */ |
297 | object *owner, *enemy, *part, *oph = op; |
296 | object *owner, *enemy, *part, *oph = op; |
… | |
… | |
446 | } /* stand still */ |
445 | } /* stand still */ |
447 | return 0; |
446 | return 0; |
448 | } /* no enemy */ |
447 | } /* no enemy */ |
449 | |
448 | |
450 | /* We have an enemy. Block immediately below is for pets */ |
449 | /* 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)) |
450 | if ((op->attack_movement & HI4) == PETMOVE |
|
|
451 | && (owner = op->owner) != NULL |
|
|
452 | && !on_same_map (op, owner) |
|
|
453 | && !owner->flag [FLAG_REMOVED]) |
452 | return follow_owner (op, owner); |
454 | return follow_owner (op, owner); |
453 | |
455 | |
454 | /* doppleganger code to change monster facing to that of the nearest |
456 | /* doppleganger code to change monster facing to that of the nearest |
455 | * player. Hmm. The code is here, but no monster in the current |
457 | * player. Hmm. The code is here, but no monster in the current |
456 | * arch set uses it. |
458 | * arch set uses it. |
… | |
… | |
475 | if (!QUERY_FLAG (op, FLAG_SCARED)) |
477 | if (!QUERY_FLAG (op, FLAG_SCARED)) |
476 | { |
478 | { |
477 | rv_vector rv1; |
479 | rv_vector rv1; |
478 | |
480 | |
479 | /* now we test every part of an object .... this is a real ugly piece of code */ |
481 | /* 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) |
482 | for (part = op; part; part = part->more) |
481 | { |
483 | { |
482 | get_rangevector (part, enemy, &rv1, 0x1); |
484 | get_rangevector (part, enemy, &rv1, 0x1); |
483 | dir = rv1.direction; |
485 | dir = rv1.direction; |
484 | |
486 | |
485 | /* hm, not sure about this part - in original was a scared flag here too |
487 | /* 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 |
488 | * but that we test above... so can be old code here |
487 | */ |
489 | */ |
488 | if (QUERY_FLAG (op, FLAG_RUN_AWAY)) |
490 | if (QUERY_FLAG (op, FLAG_RUN_AWAY)) |
489 | dir = absdir (dir + 4); |
491 | dir = absdir (dir + 4); |
|
|
492 | |
490 | if (QUERY_FLAG (op, FLAG_CONFUSED)) |
493 | if (QUERY_FLAG (op, FLAG_CONFUSED)) |
491 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
494 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
492 | |
495 | |
493 | if (QUERY_FLAG (op, FLAG_CAST_SPELL) && !(rndm (3))) |
496 | if (QUERY_FLAG (op, FLAG_CAST_SPELL) && !(rndm (3))) |
494 | { |
|
|
495 | if (monster_cast_spell (op, part, enemy, dir, &rv1)) |
497 | if (monster_cast_spell (op, part, enemy, dir, &rv1)) |
496 | return 0; |
498 | return 0; |
497 | } |
|
|
498 | |
499 | |
499 | if (QUERY_FLAG (op, FLAG_READY_SCROLL) && !(rndm (3))) |
500 | if (QUERY_FLAG (op, FLAG_READY_SCROLL) && !(rndm (3))) |
500 | { |
|
|
501 | if (monster_use_scroll (op, part, enemy, dir, &rv1)) |
501 | if (monster_use_scroll (op, part, enemy, dir, &rv1)) |
502 | return 0; |
502 | return 0; |
503 | } |
|
|
504 | |
503 | |
505 | if (QUERY_FLAG (op, FLAG_READY_RANGE) && !(rndm (3))) |
504 | if (QUERY_FLAG (op, FLAG_READY_RANGE) && !(rndm (3))) |
506 | { |
|
|
507 | if (monster_use_range (op, part, enemy, dir)) |
505 | if (monster_use_range (op, part, enemy, dir)) |
508 | return 0; |
506 | return 0; |
509 | } |
507 | |
510 | if (QUERY_FLAG (op, FLAG_READY_SKILL) && !(rndm (3))) |
508 | if (QUERY_FLAG (op, FLAG_READY_SKILL) && !(rndm (3))) |
511 | { |
|
|
512 | if (monster_use_skill (op, rv.part, enemy, rv.direction)) |
509 | if (monster_use_skill (op, rv.part, enemy, rv.direction)) |
513 | return 0; |
510 | return 0; |
514 | } |
511 | |
515 | if (QUERY_FLAG (op, FLAG_READY_BOW) && !(rndm (2))) |
512 | if (QUERY_FLAG (op, FLAG_READY_BOW) && !(rndm (2))) |
516 | { |
|
|
517 | if (monster_use_bow (op, part, enemy, dir)) |
513 | if (monster_use_bow (op, part, enemy, dir)) |
518 | return 0; |
514 | return 0; |
519 | } |
|
|
520 | } /* for processing of all parts */ |
515 | } /* for processing of all parts */ |
521 | } /* If not scared */ |
516 | } /* If not scared */ |
522 | |
517 | |
523 | |
518 | |
524 | part = rv.part; |
519 | part = rv.part; |
… | |
… | |
896 | * The skills we are treating here are all but those. -b.t. |
891 | * The skills we are treating here are all but those. -b.t. |
897 | * |
892 | * |
898 | * At the moment this is only useful for throwing, perhaps for |
893 | * 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 |
894 | * stealing. TODO: This should be more integrated in the game. -MT, 25.11.01 |
900 | */ |
895 | */ |
901 | |
|
|
902 | int |
896 | int |
903 | monster_use_skill (object *head, object *part, object *pl, int dir) |
897 | monster_use_skill (object *head, object *part, object *pl, int dir) |
904 | { |
898 | { |
905 | object *skill, *owner; |
899 | object *skill, *owner; |
906 | |
900 | |
… | |
… | |
912 | int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y); |
906 | int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y); |
913 | |
907 | |
914 | if (dirdiff (dir, dir2) < 1) |
908 | if (dirdiff (dir, dir2) < 1) |
915 | return 0; /* Might hit owner with skill -thrown rocks for example ? */ |
909 | return 0; /* Might hit owner with skill -thrown rocks for example ? */ |
916 | } |
910 | } |
|
|
911 | |
917 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
912 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
918 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
913 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
919 | |
914 | |
920 | /* skill selection - monster will use the next unused skill. |
915 | /* skill selection - monster will use the next unused skill. |
921 | * well...the following scenario will allow the monster to |
916 | * well...the following scenario will allow the monster to |
922 | * toggle between 2 skills. One day it would be nice to make |
917 | * toggle between 2 skills. One day it would be nice to make |
923 | * more skills available to monsters. |
918 | * more skills available to monsters. |
924 | */ |
919 | */ |
925 | |
|
|
926 | for (skill = head->inv; skill != NULL; skill = skill->below) |
920 | for (skill = head->inv; skill; skill = skill->below) |
927 | if (skill->type == SKILL && skill != head->chosen_skill) |
921 | if (skill->type == SKILL && skill != head->chosen_skill) |
928 | { |
922 | { |
929 | head->chosen_skill = skill; |
923 | head->chosen_skill = skill; |
930 | break; |
924 | break; |
931 | } |
925 | } |
… | |
… | |
934 | { |
928 | { |
935 | LOG (llevDebug, "Error: Monster %s (%d) has FLAG_READY_SKILL without skill.\n", &head->name, head->count); |
929 | LOG (llevDebug, "Error: Monster %s (%d) has FLAG_READY_SKILL without skill.\n", &head->name, head->count); |
936 | CLEAR_FLAG (head, FLAG_READY_SKILL); |
930 | CLEAR_FLAG (head, FLAG_READY_SKILL); |
937 | return 0; |
931 | return 0; |
938 | } |
932 | } |
|
|
933 | |
939 | /* use skill */ |
934 | /* use skill */ |
940 | return do_skill (head, part, head->chosen_skill, dir, NULL); |
935 | return do_skill (head, part, head->chosen_skill, dir, NULL); |
941 | } |
936 | } |
942 | |
937 | |
943 | /* Monster will use a ranged spell attack. */ |
938 | /* Monster will use a ranged spell attack. */ |
944 | |
|
|
945 | int |
939 | int |
946 | monster_use_range (object *head, object *part, object *pl, int dir) |
940 | monster_use_range (object *head, object *part, object *pl, int dir) |
947 | { |
941 | { |
948 | object *wand, *owner; |
942 | object *wand, *owner; |
949 | int at_least_one = 0; |
943 | int at_least_one = 0; |
… | |
… | |
956 | int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y); |
950 | int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y); |
957 | |
951 | |
958 | if (dirdiff (dir, dir2) < 2) |
952 | if (dirdiff (dir, dir2) < 2) |
959 | return 0; /* Might hit owner with spell */ |
953 | return 0; /* Might hit owner with spell */ |
960 | } |
954 | } |
|
|
955 | |
961 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
956 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
962 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
957 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
963 | |
958 | |
964 | for (wand = head->inv; wand != NULL; wand = wand->below) |
959 | for (wand = head->inv; wand; wand = wand->below) |
965 | { |
960 | { |
966 | if (wand->type == WAND) |
961 | if (wand->type == WAND) |
967 | { |
962 | { |
968 | /* Found a wand, let's see if it has charges left */ |
963 | /* Found a wand, let's see if it has charges left */ |
969 | at_least_one = 1; |
964 | at_least_one = 1; |
… | |
… | |
975 | if (!(--wand->stats.food)) |
970 | if (!(--wand->stats.food)) |
976 | { |
971 | { |
977 | if (wand->arch) |
972 | if (wand->arch) |
978 | { |
973 | { |
979 | CLEAR_FLAG (wand, FLAG_ANIMATE); |
974 | CLEAR_FLAG (wand, FLAG_ANIMATE); |
980 | wand->face = wand->arch->clone.face; |
975 | wand->face = wand->arch->face; |
981 | wand->set_speed (0); |
976 | wand->set_speed (0); |
982 | } |
977 | } |
983 | } |
978 | } |
984 | /* Success */ |
979 | /* Success */ |
985 | return 1; |
980 | return 1; |
… | |
… | |
1004 | } |
999 | } |
1005 | |
1000 | |
1006 | if (at_least_one) |
1001 | if (at_least_one) |
1007 | return 0; |
1002 | return 0; |
1008 | |
1003 | |
1009 | LOG (llevError, "Error: Monster %s (%d) HAS_READY_RANG() without wand/horn/rod.\n", &head->name, head->count); |
1004 | 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); |
1005 | CLEAR_FLAG (head, FLAG_READY_RANGE); |
1011 | return 0; |
1006 | return 0; |
1012 | } |
1007 | } |
1013 | |
1008 | |
1014 | int |
1009 | int |
… | |
… | |
1016 | { |
1011 | { |
1017 | object *owner; |
1012 | object *owner; |
1018 | |
1013 | |
1019 | if (!(dir = path_to_player (part, pl, 0))) |
1014 | if (!(dir = path_to_player (part, pl, 0))) |
1020 | return 0; |
1015 | return 0; |
|
|
1016 | |
1021 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
1017 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
1022 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
1018 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
1023 | |
1019 | |
1024 | if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL) |
1020 | if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL) |
1025 | { |
1021 | { |
… | |
… | |
1033 | return fire_bow (head, part, NULL, dir, 0, part->x, part->y); |
1029 | return fire_bow (head, part, NULL, dir, 0, part->x, part->y); |
1034 | |
1030 | |
1035 | } |
1031 | } |
1036 | |
1032 | |
1037 | /* Checks if putting on 'item' will make 'who' do more |
1033 | /* Checks if putting on 'item' will make 'who' do more |
1038 | * damage. This is a very simplistic check - also checking things |
1034 | * damage. This is a very simplistic check - also checking things |
1039 | * like speed and ac are also relevant. |
1035 | * like speed and ac are also relevant. |
1040 | * |
1036 | * |
1041 | * return true if item is a better object. |
1037 | * return true if item is a better object. |
1042 | */ |
1038 | */ |
1043 | |
|
|
1044 | int |
1039 | int |
1045 | check_good_weapon (object *who, object *item) |
1040 | check_good_weapon (object *who, object *item) |
1046 | { |
1041 | { |
1047 | object *other_weap; |
1042 | object *other_weap; |
1048 | int val = 0, i; |
1043 | int val = 0, i; |
1049 | |
1044 | |
1050 | for (other_weap = who->inv; other_weap != NULL; other_weap = other_weap->below) |
1045 | 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)) |
1046 | if (other_weap->type == item->type && QUERY_FLAG (other_weap, FLAG_APPLIED)) |
1052 | break; |
1047 | break; |
1053 | |
1048 | |
1054 | if (other_weap == NULL) /* No other weapons */ |
1049 | if (!other_weap) /* No other weapons */ |
1055 | return 1; |
1050 | return 1; |
1056 | |
1051 | |
1057 | /* Rather than go through and apply the new one, and see if it is |
1052 | /* Rather than go through and apply the new one, and see if it is |
1058 | * better, just do some simple checks |
1053 | * better, just do some simple checks |
1059 | * Put some multipliers for things that hvae several effects, |
1054 | * Put some multipliers for things that hvae several effects, |
… | |
… | |
1064 | val += (item->magic - other_weap->magic) * 3; |
1059 | val += (item->magic - other_weap->magic) * 3; |
1065 | /* Monsters don't really get benefits from things like regen rates |
1060 | /* Monsters don't really get benefits from things like regen rates |
1066 | * from items. But the bonus for their stats are very important. |
1061 | * from items. But the bonus for their stats are very important. |
1067 | */ |
1062 | */ |
1068 | for (i = 0; i < NUM_STATS; i++) |
1063 | for (i = 0; i < NUM_STATS; i++) |
1069 | val += (get_attr_value (&item->stats, i) - get_attr_value (&other_weap->stats, i)) * 2; |
1064 | val += item->stats.stat (i) - other_weap->stats.stat (i) * 2; |
1070 | |
1065 | |
1071 | if (val > 0) |
1066 | if (val > 0) |
1072 | return 1; |
1067 | return 1; |
1073 | else |
1068 | else |
1074 | return 0; |
1069 | return 0; |
1075 | |
|
|
1076 | } |
1070 | } |
1077 | |
1071 | |
1078 | int |
1072 | int |
1079 | check_good_armour (object *who, object *item) |
1073 | check_good_armour (object *who, object *item) |
1080 | { |
1074 | { |
1081 | object *other_armour; |
1075 | object *other_armour; |
1082 | int val = 0, i; |
1076 | int val = 0, i; |
1083 | |
1077 | |
1084 | for (other_armour = who->inv; other_armour != NULL; other_armour = other_armour->below) |
1078 | 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)) |
1079 | if (other_armour->type == item->type && QUERY_FLAG (other_armour, FLAG_APPLIED)) |
1086 | break; |
1080 | break; |
1087 | |
1081 | |
1088 | if (other_armour == NULL) /* No other armour, use the new */ |
1082 | if (other_armour == NULL) /* No other armour, use the new */ |
1089 | return 1; |
1083 | return 1; |
… | |
… | |
1111 | |
1105 | |
1112 | if (val > 0) |
1106 | if (val > 0) |
1113 | return 1; |
1107 | return 1; |
1114 | else |
1108 | else |
1115 | return 0; |
1109 | return 0; |
1116 | |
|
|
1117 | } |
1110 | } |
1118 | |
1111 | |
1119 | /* |
1112 | /* |
1120 | * monster_check_pickup(): checks for items that monster can pick up. |
1113 | * monster_check_pickup(): checks for items that monster can pick up. |
1121 | * |
1114 | * |
… | |
… | |
1129 | * This function was seen be continueing looping at one point (tmp->below |
1122 | * 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 |
1123 | * 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 |
1124 | * after we pick everything up, since that function may call others which |
1132 | * affect stacking on this space. |
1125 | * affect stacking on this space. |
1133 | */ |
1126 | */ |
1134 | |
|
|
1135 | void |
1127 | void |
1136 | monster_check_pickup (object *monster) |
1128 | monster_check_pickup (object *monster) |
1137 | { |
1129 | { |
1138 | object *tmp, *next; |
1130 | object *tmp, *next; |
1139 | |
1131 | |
… | |
… | |
1158 | * monster_can_pick(): If the monster is interested in picking up |
1150 | * monster_can_pick(): If the monster is interested in picking up |
1159 | * the item, then return 0. Otherwise 0. |
1151 | * the item, then return 0. Otherwise 0. |
1160 | * Instead of pick_up, flags for "greed", etc, should be used. |
1152 | * Instead of pick_up, flags for "greed", etc, should be used. |
1161 | * I've already utilized flags for bows, wands, rings, etc, etc. -Frank. |
1153 | * I've already utilized flags for bows, wands, rings, etc, etc. -Frank. |
1162 | */ |
1154 | */ |
1163 | |
|
|
1164 | int |
1155 | int |
1165 | monster_can_pick (object *monster, object *item) |
1156 | monster_can_pick (object *monster, object *item) |
1166 | { |
1157 | { |
1167 | int flag = 0; |
1158 | int flag = 0; |
1168 | int i; |
1159 | int i; |
… | |
… | |
1214 | case ROD: |
1205 | case ROD: |
1215 | flag = QUERY_FLAG (monster, FLAG_USE_RANGE); |
1206 | flag = QUERY_FLAG (monster, FLAG_USE_RANGE); |
1216 | break; |
1207 | break; |
1217 | |
1208 | |
1218 | case SPELLBOOK: |
1209 | case SPELLBOOK: |
1219 | flag = (monster->arch != NULL && QUERY_FLAG ((&monster->arch->clone), FLAG_CAST_SPELL)); |
1210 | flag = monster->arch && QUERY_FLAG (monster->arch, FLAG_CAST_SPELL); |
1220 | break; |
1211 | break; |
1221 | |
1212 | |
1222 | case SCROLL: |
1213 | case SCROLL: |
1223 | flag = QUERY_FLAG (monster, FLAG_USE_SCROLL); |
1214 | flag = QUERY_FLAG (monster, FLAG_USE_SCROLL); |
1224 | break; |
1215 | break; |
… | |
… | |
1226 | case BOW: |
1217 | case BOW: |
1227 | case ARROW: |
1218 | case ARROW: |
1228 | flag = QUERY_FLAG (monster, FLAG_USE_BOW); |
1219 | flag = QUERY_FLAG (monster, FLAG_USE_BOW); |
1229 | break; |
1220 | break; |
1230 | } |
1221 | } |
|
|
1222 | |
1231 | /* Simplistic check - if the monster has a location to equip it, he will |
1223 | /* 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 |
1224 | * pick it up. Note that this doesn't handle cases where an item may |
1233 | * use several locations. |
1225 | * use several locations. |
1234 | */ |
1226 | */ |
1235 | for (i = 0; i < NUM_BODY_LOCATIONS; i++) |
1227 | for (i = 0; i < NUM_BODY_LOCATIONS; i++) |
1236 | { |
1228 | { |
1237 | if (monster->body_info[i] && item->body_info[i]) |
1229 | if (monster->slot[i].info && item->slot[i].info) |
1238 | { |
1230 | { |
1239 | flag = 1; |
1231 | flag = 1; |
1240 | break; |
1232 | break; |
1241 | } |
1233 | } |
1242 | } |
1234 | } |
… | |
… | |
1250 | * monster_apply_below(): |
1242 | * monster_apply_below(): |
1251 | * Vick's (vick@bern.docs.uu.se) @921107 -> If a monster who's |
1243 | * Vick's (vick@bern.docs.uu.se) @921107 -> If a monster who's |
1252 | * eager to apply things, encounters something apply-able, |
1244 | * eager to apply things, encounters something apply-able, |
1253 | * then make him apply it |
1245 | * then make him apply it |
1254 | */ |
1246 | */ |
1255 | |
|
|
1256 | void |
1247 | void |
1257 | monster_apply_below (object *monster) |
1248 | monster_apply_below (object *monster) |
1258 | { |
1249 | { |
1259 | object *tmp, *next; |
1250 | object *tmp, *next; |
1260 | |
1251 | |
… | |
… | |
1287 | * a pointer to that object is returned, so it can be dropped. |
1278 | * a pointer to that object is returned, so it can be dropped. |
1288 | * (so that other monsters can pick it up and use it) |
1279 | * (so that other monsters can pick it up and use it) |
1289 | * Note that as things are now, monsters never drop something - |
1280 | * Note that as things are now, monsters never drop something - |
1290 | * they can pick up all that they can use. |
1281 | * they can pick up all that they can use. |
1291 | */ |
1282 | */ |
1292 | |
|
|
1293 | /* Sept 96, fixed this so skills will be readied -b.t.*/ |
1283 | /* Sept 96, fixed this so skills will be readied -b.t.*/ |
1294 | |
|
|
1295 | void |
1284 | void |
1296 | monster_check_apply (object *mon, object *item) |
1285 | monster_check_apply (object *mon, object *item) |
1297 | { |
1286 | { |
1298 | |
|
|
1299 | int flag = 0; |
1287 | int flag = 0; |
1300 | |
1288 | |
1301 | if (item->type == SPELLBOOK && mon->arch != NULL && (QUERY_FLAG ((&mon->arch->clone), FLAG_CAST_SPELL))) |
1289 | if (item->type == SPELLBOOK && mon->arch && (QUERY_FLAG (mon->arch, FLAG_CAST_SPELL))) |
1302 | { |
1290 | { |
1303 | SET_FLAG (mon, FLAG_CAST_SPELL); |
1291 | SET_FLAG (mon, FLAG_CAST_SPELL); |
1304 | return; |
1292 | return; |
1305 | } |
1293 | } |
1306 | |
1294 | |
… | |
… | |
1315 | if (QUERY_FLAG (mon, FLAG_USE_BOW) && item->type == ARROW) |
1303 | if (QUERY_FLAG (mon, FLAG_USE_BOW) && item->type == ARROW) |
1316 | { |
1304 | { |
1317 | /* Check for the right kind of bow */ |
1305 | /* Check for the right kind of bow */ |
1318 | object *bow; |
1306 | object *bow; |
1319 | |
1307 | |
1320 | for (bow = mon->inv; bow != NULL; bow = bow->below) |
1308 | for (bow = mon->inv; bow; bow = bow->below) |
1321 | if (bow->type == BOW && bow->race == item->race) |
1309 | if (bow->type == BOW && bow->race == item->race) |
1322 | { |
1310 | { |
1323 | SET_FLAG (mon, FLAG_READY_BOW); |
1311 | SET_FLAG (mon, FLAG_READY_BOW); |
1324 | LOG (llevMonster, "Found correct bow for arrows.\n"); |
1312 | LOG (llevMonster, "Found correct bow for arrows.\n"); |
1325 | return; /* nothing more to do for arrows */ |
1313 | return; /* nothing more to do for arrows */ |
… | |
… | |
1377 | */ |
1365 | */ |
1378 | SET_FLAG (mon, FLAG_READY_SKILL); |
1366 | SET_FLAG (mon, FLAG_READY_SKILL); |
1379 | return; |
1367 | return; |
1380 | } |
1368 | } |
1381 | |
1369 | |
1382 | |
|
|
1383 | /* if we don't match one of the above types, return now. |
1370 | /* 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, |
1371 | * can_apply_object will say that we can apply things like flesh, |
1385 | * bolts, and whatever else, because it only checks against the |
1372 | * bolts, and whatever else, because it only checks against the |
1386 | * body_info locations. |
1373 | * body_info locations. |
1387 | */ |
1374 | */ |
… | |
… | |
1398 | /* should only be applying this item, not unapplying it. |
1385 | /* should only be applying this item, not unapplying it. |
1399 | * also, ignore status of curse so they can take off old armour. |
1386 | * also, ignore status of curse so they can take off old armour. |
1400 | * monsters have some advantages after all. |
1387 | * monsters have some advantages after all. |
1401 | */ |
1388 | */ |
1402 | manual_apply (mon, item, AP_APPLY | AP_IGNORE_CURSE); |
1389 | manual_apply (mon, item, AP_APPLY | AP_IGNORE_CURSE); |
1403 | |
|
|
1404 | return; |
|
|
1405 | } |
1390 | } |
1406 | |
1391 | |
1407 | void |
1392 | void |
1408 | npc_call_help (object *op) |
1393 | npc_call_help (object *op) |
1409 | { |
1394 | { |
… | |
… | |
1427 | if (QUERY_FLAG (npc, FLAG_ALIVE) && QUERY_FLAG (npc, FLAG_UNAGGRESSIVE)) |
1412 | if (QUERY_FLAG (npc, FLAG_ALIVE) && QUERY_FLAG (npc, FLAG_UNAGGRESSIVE)) |
1428 | npc->enemy = op->enemy; |
1413 | npc->enemy = op->enemy; |
1429 | } |
1414 | } |
1430 | } |
1415 | } |
1431 | |
1416 | |
1432 | |
|
|
1433 | int |
1417 | int |
1434 | dist_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1418 | dist_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1435 | { |
1419 | { |
1436 | |
|
|
1437 | if (can_hit (part, enemy, rv)) |
1420 | if (can_hit (part, enemy, rv)) |
1438 | return dir; |
1421 | return dir; |
1439 | if (rv->distance < 10) |
1422 | if (rv->distance < 10) |
1440 | return absdir (dir + 4); |
1423 | return absdir (dir + 4); |
1441 | else if (rv->distance > 18) |
1424 | else if (rv->distance > 18) |
1442 | return dir; |
1425 | return dir; |
|
|
1426 | |
1443 | return 0; |
1427 | return 0; |
1444 | } |
1428 | } |
1445 | |
1429 | |
1446 | int |
1430 | int |
1447 | run_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1431 | run_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1448 | { |
1432 | { |
1449 | |
|
|
1450 | if ((can_hit (part, enemy, rv) && ob->move_status < 20) || ob->move_status < 20) |
1433 | if ((can_hit (part, enemy, rv) && ob->move_status < 20) || ob->move_status < 20) |
1451 | { |
1434 | { |
1452 | ob->move_status++; |
1435 | ob->move_status++; |
1453 | return (dir); |
1436 | return (dir); |
1454 | } |
1437 | } |
1455 | else if (ob->move_status > 20) |
1438 | else if (ob->move_status > 20) |
1456 | ob->move_status = 0; |
1439 | ob->move_status = 0; |
|
|
1440 | |
1457 | return absdir (dir + 4); |
1441 | return absdir (dir + 4); |
1458 | } |
1442 | } |
1459 | |
1443 | |
1460 | int |
1444 | int |
1461 | hitrun_att (int dir, object *ob, object *enemy) |
1445 | hitrun_att (int dir, object *ob, object *enemy) |
… | |
… | |
1464 | return dir; |
1448 | return dir; |
1465 | else if (ob->move_status < 50) |
1449 | else if (ob->move_status < 50) |
1466 | return absdir (dir + 4); |
1450 | return absdir (dir + 4); |
1467 | else |
1451 | else |
1468 | ob->move_status = 0; |
1452 | ob->move_status = 0; |
|
|
1453 | |
1469 | return absdir (dir + 4); |
1454 | return absdir (dir + 4); |
1470 | } |
1455 | } |
1471 | |
1456 | |
1472 | int |
1457 | int |
1473 | wait_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1458 | wait_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
… | |
… | |
1482 | return 0; |
1467 | return 0; |
1483 | else if (ob->move_status < 10) |
1468 | else if (ob->move_status < 10) |
1484 | return dir; |
1469 | return dir; |
1485 | else if (ob->move_status < 15) |
1470 | else if (ob->move_status < 15) |
1486 | return absdir (dir + 4); |
1471 | return absdir (dir + 4); |
|
|
1472 | |
1487 | ob->move_status = 0; |
1473 | ob->move_status = 0; |
1488 | return 0; |
1474 | return 0; |
1489 | } |
1475 | } |
1490 | |
1476 | |
1491 | int |
1477 | int |
… | |
… | |
1499 | * at least one map has this set, and whatever the map contains, the |
1485 | * 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 |
1486 | * server should try to be resilant enough to avoid the problem |
1501 | */ |
1487 | */ |
1502 | if (ob->stats.maxhp && (ob->stats.hp * 100) / ob->stats.maxhp < ob->run_away) |
1488 | if (ob->stats.maxhp && (ob->stats.hp * 100) / ob->stats.maxhp < ob->run_away) |
1503 | return absdir (dir + 4); |
1489 | return absdir (dir + 4); |
|
|
1490 | |
1504 | return dist_att (dir, ob, enemy, part, rv); |
1491 | return dist_att (dir, ob, enemy, part, rv); |
1505 | } |
1492 | } |
1506 | |
1493 | |
1507 | int |
1494 | int |
1508 | wait_att2 (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1495 | wait_att2 (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1509 | { |
1496 | { |
1510 | if (rv->distance < 9) |
1497 | if (rv->distance < 9) |
1511 | return absdir (dir + 4); |
1498 | return absdir (dir + 4); |
|
|
1499 | |
1512 | return 0; |
1500 | return 0; |
1513 | } |
1501 | } |
1514 | |
1502 | |
1515 | void |
1503 | void |
1516 | circ1_move (object *ob) |
1504 | circ1_move (object *ob) |
1517 | { |
1505 | { |
1518 | static int circle[12] = { 3, 3, 4, 5, 5, 6, 7, 7, 8, 1, 1, 2 }; |
1506 | static int circle[12] = { 3, 3, 4, 5, 5, 6, 7, 7, 8, 1, 1, 2 }; |
|
|
1507 | |
1519 | if (++ob->move_status > 11) |
1508 | if (++ob->move_status > 11) |
1520 | ob->move_status = 0; |
1509 | ob->move_status = 0; |
|
|
1510 | |
1521 | if (!(move_object (ob, circle[ob->move_status]))) |
1511 | if (!(move_object (ob, circle[ob->move_status]))) |
1522 | (void) move_object (ob, rndm (8) + 1); |
1512 | move_object (ob, rndm (8) + 1); |
1523 | } |
1513 | } |
1524 | |
1514 | |
1525 | void |
1515 | void |
1526 | circ2_move (object *ob) |
1516 | circ2_move (object *ob) |
1527 | { |
1517 | { |
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 }; |
1518 | static int circle[20] = { 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8, 1, 1, 1, 2, 2 }; |
|
|
1519 | |
1529 | if (++ob->move_status > 19) |
1520 | if (++ob->move_status > 19) |
1530 | ob->move_status = 0; |
1521 | ob->move_status = 0; |
|
|
1522 | |
1531 | if (!(move_object (ob, circle[ob->move_status]))) |
1523 | if (!(move_object (ob, circle[ob->move_status]))) |
1532 | (void) move_object (ob, rndm (8) + 1); |
1524 | move_object (ob, rndm (8) + 1); |
1533 | } |
1525 | } |
1534 | |
1526 | |
1535 | void |
1527 | void |
1536 | pace_movev (object *ob) |
1528 | pace_movev (object *ob) |
1537 | { |
1529 | { |
1538 | if (ob->move_status++ > 6) |
1530 | if (ob->move_status++ > 6) |
1539 | ob->move_status = 0; |
1531 | ob->move_status = 0; |
|
|
1532 | |
1540 | if (ob->move_status < 4) |
1533 | if (ob->move_status < 4) |
1541 | (void) move_object (ob, 5); |
1534 | move_object (ob, 5); |
1542 | else |
1535 | else |
1543 | (void) move_object (ob, 1); |
1536 | move_object (ob, 1); |
1544 | } |
1537 | } |
1545 | |
1538 | |
1546 | void |
1539 | void |
1547 | pace_moveh (object *ob) |
1540 | pace_moveh (object *ob) |
1548 | { |
1541 | { |
1549 | if (ob->move_status++ > 6) |
1542 | if (ob->move_status++ > 6) |
1550 | ob->move_status = 0; |
1543 | ob->move_status = 0; |
|
|
1544 | |
1551 | if (ob->move_status < 4) |
1545 | if (ob->move_status < 4) |
1552 | (void) move_object (ob, 3); |
1546 | move_object (ob, 3); |
1553 | else |
1547 | else |
1554 | (void) move_object (ob, 7); |
1548 | move_object (ob, 7); |
1555 | } |
1549 | } |
1556 | |
1550 | |
1557 | void |
1551 | void |
1558 | pace2_movev (object *ob) |
1552 | pace2_movev (object *ob) |
1559 | { |
1553 | { |
1560 | if (ob->move_status++ > 16) |
1554 | if (ob->move_status++ > 16) |
1561 | ob->move_status = 0; |
1555 | ob->move_status = 0; |
|
|
1556 | |
1562 | if (ob->move_status < 6) |
1557 | if (ob->move_status < 6) |
1563 | (void) move_object (ob, 5); |
1558 | move_object (ob, 5); |
1564 | else if (ob->move_status < 8) |
1559 | else if (ob->move_status < 8) |
1565 | return; |
1560 | return; |
1566 | else if (ob->move_status < 13) |
1561 | else if (ob->move_status < 13) |
1567 | (void) move_object (ob, 1); |
1562 | move_object (ob, 1); |
1568 | else |
1563 | else |
1569 | return; |
1564 | return; |
1570 | } |
1565 | } |
1571 | |
1566 | |
1572 | void |
1567 | void |
1573 | pace2_moveh (object *ob) |
1568 | pace2_moveh (object *ob) |
1574 | { |
1569 | { |
1575 | if (ob->move_status++ > 16) |
1570 | if (ob->move_status++ > 16) |
1576 | ob->move_status = 0; |
1571 | ob->move_status = 0; |
|
|
1572 | |
1577 | if (ob->move_status < 6) |
1573 | if (ob->move_status < 6) |
1578 | (void) move_object (ob, 3); |
1574 | move_object (ob, 3); |
1579 | else if (ob->move_status < 8) |
1575 | else if (ob->move_status < 8) |
1580 | return; |
1576 | return; |
1581 | else if (ob->move_status < 13) |
1577 | else if (ob->move_status < 13) |
1582 | (void) move_object (ob, 7); |
1578 | move_object (ob, 7); |
1583 | else |
1579 | else |
1584 | return; |
1580 | return; |
1585 | } |
1581 | } |
1586 | |
1582 | |
1587 | void |
1583 | void |
… | |
… | |
1630 | * monsters to throw things like chairs and other pieces of |
1626 | * monsters to throw things like chairs and other pieces of |
1631 | * furniture, even if they are not good throwable objects. |
1627 | * furniture, even if they are not good throwable objects. |
1632 | * Probably better to have the monster throw a throwable object |
1628 | * Probably better to have the monster throw a throwable object |
1633 | * first, then throw any non equipped weapon. |
1629 | * first, then throw any non equipped weapon. |
1634 | */ |
1630 | */ |
1635 | |
|
|
1636 | object * |
1631 | object * |
1637 | find_mon_throw_ob (object *op) |
1632 | find_mon_throw_ob (object *op) |
1638 | { |
1633 | { |
1639 | object *tmp = NULL; |
1634 | object *tmp = NULL; |
1640 | |
1635 | |
… | |
… | |
1671 | * properly. I also so odd code in place that checked for x distance |
1666 | * properly. I also so odd code in place that checked for x distance |
1672 | * OR y distance being within some range - that seemed wrong - both should |
1667 | * OR y distance being within some range - that seemed wrong - both should |
1673 | * be within the valid range. MSW 2001-08-05 |
1668 | * be within the valid range. MSW 2001-08-05 |
1674 | * Returns 0 if enemy can not be detected, 1 if it is detected |
1669 | * Returns 0 if enemy can not be detected, 1 if it is detected |
1675 | */ |
1670 | */ |
1676 | |
|
|
1677 | int |
1671 | int |
1678 | can_detect_enemy (object *op, object *enemy, rv_vector * rv) |
1672 | can_detect_enemy (object *op, object *enemy, rv_vector * rv) |
1679 | { |
1673 | { |
1680 | int radius = MIN_MON_RADIUS, hide_discovery; |
1674 | int radius = MIN_MON_RADIUS, hide_discovery; |
1681 | |
1675 | |
… | |
… | |
1712 | /* use this for invis also */ |
1706 | /* use this for invis also */ |
1713 | hide_discovery = op->stats.Int / 5; |
1707 | hide_discovery = op->stats.Int / 5; |
1714 | |
1708 | |
1715 | /* Determine Detection radii */ |
1709 | /* Determine Detection radii */ |
1716 | if (!enemy->hide) /* to detect non-hidden (eg dark/invis enemy) */ |
1710 | if (!enemy->hide) /* to detect non-hidden (eg dark/invis enemy) */ |
1717 | radius = (op->stats.Wis / 5) + 1 > MIN_MON_RADIUS ? (op->stats.Wis / 5) + 1 : MIN_MON_RADIUS; |
1711 | radius = max (MIN_MON_RADIUS, op->stats.Wis / 5 + 1); |
1718 | else |
1712 | else |
1719 | { /* a level/INT/Dex adjustment for hiding */ |
1713 | { /* a level/INT/Dex adjustment for hiding */ |
1720 | object *sk_hide; |
|
|
1721 | int bonus = (op->level / 2) + (op->stats.Int / 5); |
1714 | int bonus = op->level / 2 + op->stats.Int / 5; |
1722 | |
1715 | |
1723 | if (enemy->type == PLAYER) |
1716 | if (enemy->type == PLAYER) |
1724 | { |
1717 | { |
1725 | if ((sk_hide = find_skill_by_number (enemy, SK_HIDING))) |
1718 | if (object *sk_hide = find_skill_by_number (enemy, SK_HIDING)) |
1726 | bonus -= sk_hide->level; |
1719 | bonus -= sk_hide->level; |
1727 | else |
1720 | else |
1728 | { |
1721 | { |
1729 | LOG (llevError, "can_detect_enemy() got hidden player w/o hiding skill!\n"); |
1722 | LOG (llevError, "can_detect_enemy() got hidden player w/o hiding skill!\n"); |
1730 | make_visible (enemy); |
1723 | make_visible (enemy); |
… | |
… | |
1739 | } /* else creature has modifiers for hiding */ |
1732 | } /* else creature has modifiers for hiding */ |
1740 | |
1733 | |
1741 | /* Radii stealth adjustment. Only if you are stealthy |
1734 | /* Radii stealth adjustment. Only if you are stealthy |
1742 | * will you be able to sneak up closer to creatures */ |
1735 | * will you be able to sneak up closer to creatures */ |
1743 | if (QUERY_FLAG (enemy, FLAG_STEALTH)) |
1736 | if (QUERY_FLAG (enemy, FLAG_STEALTH)) |
1744 | radius = radius / 2, hide_discovery = hide_discovery / 3; |
1737 | { |
|
|
1738 | radius /= 2; |
|
|
1739 | hide_discovery /= 3; |
|
|
1740 | } |
1745 | |
1741 | |
1746 | /* Radii adjustment for enemy standing in the dark */ |
1742 | /* Radii adjustment for enemy standing in the dark */ |
1747 | if (op->map->darkness > 0 && !stand_in_light (enemy)) |
1743 | if (op->map->darkness > 0 && !stand_in_light (enemy)) |
1748 | { |
1744 | { |
1749 | /* on dark maps body heat can help indicate location with infravision |
1745 | /* on dark maps body heat can help indicate location with infravision |
… | |
… | |
1767 | * may have for their map - in that way, creatures at the edge will |
1763 | * may have for their map - in that way, creatures at the edge will |
1768 | * do something. Note that the distance field in the |
1764 | * do something. Note that the distance field in the |
1769 | * vector is real distance, so in theory this should be 18 to |
1765 | * vector is real distance, so in theory this should be 18 to |
1770 | * find that. |
1766 | * find that. |
1771 | */ |
1767 | */ |
1772 | if (radius > 13) |
1768 | // note that the above reasoning was utter bullshit even at the time it was written |
1773 | radius = 13; |
1769 | // we use 25, lets see if we have the cpu time for it |
|
|
1770 | radius = min (25, radius); |
1774 | |
1771 | |
1775 | /* Enemy in range! Now test for detection */ |
1772 | /* Enemy in range! Now test for detection */ |
1776 | if ((int) rv->distance <= radius) |
1773 | if (rv->distance <= radius) |
1777 | { |
1774 | { |
1778 | /* ah, we are within range, detected? take cases */ |
1775 | /* ah, we are within range, detected? take cases */ |
1779 | if (!enemy->invisible) /* enemy in dark squares... are seen! */ |
1776 | if (!enemy->invisible) /* enemy in dark squares... are seen! */ |
1780 | return 1; |
1777 | return 1; |
1781 | |
1778 | |
1782 | /* hidden or low-quality invisible */ |
1779 | /* hidden or low-quality invisible */ |
1783 | if (enemy->hide && (rv->distance <= 1) && (rndm (100) <= hide_discovery)) |
1780 | if (enemy->hide && rv->distance <= 1 && rndm (100) <= hide_discovery) |
1784 | { |
1781 | { |
1785 | make_visible (enemy); |
1782 | make_visible (enemy); |
|
|
1783 | |
1786 | /* inform players of new status */ |
1784 | /* inform players of new status */ |
1787 | if (enemy->type == PLAYER && player_can_view (enemy, op)) |
1785 | if (enemy->type == PLAYER && player_can_view (enemy, op)) |
1788 | new_draw_info_format (NDI_UNIQUE, 0, enemy, "You are discovered by %s!", &op->name); |
1786 | new_draw_info_format (NDI_UNIQUE, 0, enemy, "You are discovered by %s!", &op->name); |
|
|
1787 | |
1789 | return 1; /* detected enemy */ |
1788 | return 1; /* detected enemy */ |
1790 | } |
1789 | } |
1791 | else if (enemy->invisible) |
1790 | else if (enemy->invisible) |
1792 | { |
1791 | { |
1793 | /* Change this around - instead of negating the invisible, just |
1792 | /* Change this around - instead of negating the invisible, just |
1794 | * return true so that the mosnter that managed to detect you can |
1793 | * return true so that the monster that managed to detect you can |
1795 | * do something to you. Decreasing the duration of invisible |
1794 | * do something to you. Decreasing the duration of invisible |
1796 | * doesn't make a lot of sense IMO, as a bunch of stupid creatures |
1795 | * doesn't make a lot of sense IMO, as a bunch of stupid creatures |
1797 | * can then basically negate the spell. The spell isn't negated - |
1796 | * can then basically negate the spell. The spell isn't negated - |
1798 | * they just know where you are! |
1797 | * they just know where you are! |
1799 | */ |
1798 | */ |
1800 | if ((rndm (50)) <= hide_discovery) |
1799 | if (rndm (50) <= hide_discovery) |
1801 | { |
1800 | { |
1802 | if (enemy->type == PLAYER) |
1801 | if (enemy->type == PLAYER) |
1803 | { |
|
|
1804 | new_draw_info_format (NDI_UNIQUE, 0, enemy, "You see %s noticing your position.", query_name (op)); |
1802 | new_draw_info_format (NDI_UNIQUE, 0, enemy, "You see %s noticing your position.", query_name (op)); |
1805 | } |
1803 | |
1806 | return 1; |
1804 | return 1; |
1807 | } |
1805 | } |
1808 | } |
1806 | } |
1809 | } /* within range */ |
1807 | } /* within range */ |
1810 | |
1808 | |
… | |
… | |
1815 | /* determine if op stands in a lighted square. This is not a very |
1813 | /* 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 |
1814 | * intellegent algorithm. For one thing, we ignore los here, SO it |
1817 | * is possible for a bright light to illuminate a player on the |
1815 | * is possible for a bright light to illuminate a player on the |
1818 | * other side of a wall (!). |
1816 | * other side of a wall (!). |
1819 | */ |
1817 | */ |
1820 | |
|
|
1821 | int |
1818 | int |
1822 | stand_in_light (object *op) |
1819 | stand_in_light (object *op) |
1823 | { |
1820 | { |
1824 | sint16 nx, ny; |
|
|
1825 | maptile *m; |
|
|
1826 | |
|
|
1827 | |
|
|
1828 | if (!op) |
1821 | if (!op) |
1829 | return 0; |
1822 | return 0; |
|
|
1823 | |
1830 | if (op->glow_radius > 0) |
1824 | if (op->glow_radius > 0) |
1831 | return 1; |
1825 | return 1; |
1832 | |
1826 | |
1833 | if (op->map) |
1827 | if (op->map) |
1834 | { |
1828 | { |
1835 | int x, y, x1, y1; |
|
|
1836 | |
|
|
1837 | |
|
|
1838 | |
|
|
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 (int x = op->x - MAX_LIGHT_RADII; x <= op->x + MAX_LIGHT_RADII; x++) |
1843 | { |
1833 | { |
1844 | for (y = op->y - MAX_LIGHT_RADII; y <= op->y + MAX_LIGHT_RADII; y++) |
1834 | for (int y = op->y - MAX_LIGHT_RADII; y <= op->y + MAX_LIGHT_RADII; y++) |
1845 | { |
1835 | { |
1846 | m = op->map; |
1836 | maptile *m = op->map; |
1847 | nx = x; |
1837 | sint16 nx = x; |
1848 | ny = y; |
1838 | sint16 ny = y; |
1849 | |
1839 | |
1850 | if (get_map_flags (m, &m, nx, ny, &nx, &ny) & P_OUT_OF_MAP) |
1840 | if (xy_normalise (m, nx, ny)) |
1851 | continue; |
1841 | if (idistance (x - op->x, y - op->y) < m->at (nx, ny).light) |
1852 | |
|
|
1853 | x1 = abs (x - op->x) * abs (x - op->x); |
|
|
1854 | y1 = abs (y - op->y) * abs (y - op->y); |
|
|
1855 | if (isqrt (x1 + y1) < GET_MAP_LIGHT (m, nx, ny)) |
|
|
1856 | return 1; |
1842 | return 1; |
1857 | } |
1843 | } |
1858 | } |
1844 | } |
1859 | } |
1845 | } |
|
|
1846 | |
1860 | return 0; |
1847 | return 0; |
1861 | } |
1848 | } |
1862 | |
|
|
1863 | |
1849 | |
1864 | /* assuming no walls/barriers, lets check to see if its *possible* |
1850 | /* assuming no walls/barriers, lets check to see if its *possible* |
1865 | * to see an enemy. Note, "detection" is different from "seeing". |
1851 | * to see an enemy. Note, "detection" is different from "seeing". |
1866 | * See can_detect_enemy() for more details. -b.t. |
1852 | * See can_detect_enemy() for more details. -b.t. |
1867 | * return 0 if can't be seen, 1 if can be |
1853 | * return 0 if can't be seen, 1 if can be |
1868 | */ |
1854 | */ |
1869 | |
|
|
1870 | int |
1855 | int |
1871 | can_see_enemy (object *op, object *enemy) |
1856 | can_see_enemy (object *op, object *enemy) |
1872 | { |
1857 | { |
1873 | object *looker = op->head ? op->head : op; |
1858 | object *looker = op->head ? op->head : op; |
1874 | |
1859 | |
… | |
… | |
1895 | if (enemy->hide) |
1880 | if (enemy->hide) |
1896 | { |
1881 | { |
1897 | make_visible (enemy); |
1882 | make_visible (enemy); |
1898 | new_draw_info (NDI_UNIQUE, 0, enemy, "Your light reveals your hiding spot!"); |
1883 | new_draw_info (NDI_UNIQUE, 0, enemy, "Your light reveals your hiding spot!"); |
1899 | } |
1884 | } |
|
|
1885 | |
1900 | return 1; |
1886 | return 1; |
1901 | } |
1887 | } |
1902 | else if (enemy->hide) |
1888 | else if (enemy->hide) |
1903 | return 0; |
1889 | return 0; |
1904 | |
1890 | |
1905 | /* Invisible enemy. Break apart the check for invis undead/invis looker |
1891 | /* Invisible enemy. Break apart the check for invis undead/invis looker |
1906 | * into more simple checks - the QUERY_FLAG doesn't return 1/0 values, |
1892 | * into more simple checks - the QUERY_FLAG doesn't return 1/0 values, |
1907 | * and making it a conditional makes the code pretty ugly. |
1893 | * and making it a conditional makes the code pretty ugly. |
1908 | */ |
1894 | */ |
1909 | if (!QUERY_FLAG (looker, FLAG_SEE_INVISIBLE)) |
1895 | if (!QUERY_FLAG (looker, FLAG_SEE_INVISIBLE)) |
1910 | { |
|
|
1911 | if (makes_invisible_to (enemy, looker)) |
1896 | if (makes_invisible_to (enemy, looker)) |
1912 | return 0; |
1897 | return 0; |
1913 | } |
|
|
1914 | } |
1898 | } |
1915 | else if (looker->type == PLAYER) /* for players, a (possible) shortcut */ |
1899 | else if (looker->type == PLAYER) /* for players, a (possible) shortcut */ |
1916 | if (player_can_view (looker, enemy)) |
1900 | if (player_can_view (looker, enemy)) |
1917 | return 1; |
1901 | return 1; |
1918 | |
1902 | |
… | |
… | |
1929 | && (!QUERY_FLAG (looker, FLAG_SEE_IN_DARK) || !is_true_undead (looker) || !QUERY_FLAG (looker, FLAG_XRAYS))) |
1913 | && (!QUERY_FLAG (looker, FLAG_SEE_IN_DARK) || !is_true_undead (looker) || !QUERY_FLAG (looker, FLAG_XRAYS))) |
1930 | return 0; |
1914 | return 0; |
1931 | |
1915 | |
1932 | return 1; |
1916 | return 1; |
1933 | } |
1917 | } |
|
|
1918 | |