1 | /* |
1 | /* |
2 | * CrossFire, A Multiplayer game for X-windows |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with this program; if not, write to the Free Software |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
|
21 | * |
20 | * |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
22 | */ |
24 | |
23 | |
25 | #include <global.h> |
24 | #include <global.h> |
26 | #include <sproto.h> |
25 | #include <sproto.h> |
27 | #include <spells.h> |
26 | #include <spells.h> |
… | |
… | |
92 | && npc->enemy->type != PLAYER |
91 | && npc->enemy->type != PLAYER |
93 | && npc->enemy->type != GOLEM) |
92 | && npc->enemy->type != GOLEM) |
94 | npc->enemy = NULL; |
93 | npc->enemy = NULL; |
95 | |
94 | |
96 | } |
95 | } |
|
|
96 | |
97 | return can_detect_enemy (npc, npc->enemy, rv) ? npc->enemy : NULL; |
97 | return can_detect_enemy (npc, npc->enemy, rv) ? npc->enemy : NULL; |
98 | } |
98 | } |
99 | |
99 | |
100 | /* Returns the nearest living creature (monster or generator). |
100 | /* Returns the nearest living creature (monster or generator). |
101 | * Modified to deal with tiled maps properly. |
101 | * Modified to deal with tiled maps properly. |
… | |
… | |
145 | } |
145 | } |
146 | |
146 | |
147 | return 0; |
147 | return 0; |
148 | } |
148 | } |
149 | |
149 | |
150 | |
|
|
151 | /* 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 |
152 | * our caller will find the information useful. |
151 | * our caller will find the information useful. |
153 | * Currently, only move_monster calls this function. |
152 | * Currently, only move_monster calls this function. |
154 | * Fix function so that we always make calls to get_rangevector |
153 | * Fix function so that we always make calls to get_rangevector |
155 | * 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 |
156 | * many cases. |
155 | * many cases. |
157 | */ |
156 | */ |
158 | |
|
|
159 | object * |
157 | object * |
160 | find_enemy (object *npc, rv_vector * rv) |
158 | find_enemy (object *npc, rv_vector * rv) |
161 | { |
159 | { |
162 | object *attacker, *tmp = NULL; |
160 | object *attacker, *tmp = NULL; |
163 | |
161 | |
… | |
… | |
169 | { |
167 | { |
170 | tmp = find_nearest_living_creature (npc); |
168 | tmp = find_nearest_living_creature (npc); |
171 | |
169 | |
172 | if (tmp) |
170 | if (tmp) |
173 | get_rangevector (npc, tmp, rv, 0); |
171 | get_rangevector (npc, tmp, rv, 0); |
|
|
172 | |
174 | return tmp; |
173 | return tmp; |
175 | } |
174 | } |
176 | |
175 | |
177 | /* Here is the main enemy selection. |
176 | /* Here is the main enemy selection. |
178 | * 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 |
… | |
… | |
231 | /* Sees if this monster should wake up. |
230 | /* Sees if this monster should wake up. |
232 | * Currently, this is only called from move_monster, and |
231 | * Currently, this is only called from move_monster, and |
233 | * if enemy is set, then so should be rv. |
232 | * if enemy is set, then so should be rv. |
234 | * returns 1 if the monster should wake up, 0 otherwise. |
233 | * returns 1 if the monster should wake up, 0 otherwise. |
235 | */ |
234 | */ |
236 | |
|
|
237 | int |
235 | int |
238 | check_wakeup (object *op, object *enemy, rv_vector * rv) |
236 | check_wakeup (object *op, object *enemy, rv_vector * rv) |
239 | { |
237 | { |
240 | 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; |
241 | |
239 | |
… | |
… | |
289 | } |
287 | } |
290 | |
288 | |
291 | /* |
289 | /* |
292 | * 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. |
293 | */ |
291 | */ |
294 | |
|
|
295 | int |
292 | int |
296 | move_monster (object *op) |
293 | move_monster (object *op) |
297 | { |
294 | { |
298 | 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 */ |
299 | object *owner, *enemy, *part, *oph = op; |
296 | object *owner, *enemy, *part, *oph = op; |
… | |
… | |
375 | if (!check_wakeup (op, enemy, &rv)) |
372 | if (!check_wakeup (op, enemy, &rv)) |
376 | return 0; |
373 | return 0; |
377 | } |
374 | } |
378 | |
375 | |
379 | /* check if monster pops out of hidden spot */ |
376 | /* check if monster pops out of hidden spot */ |
380 | if (op->hide) |
377 | if (op->flag [FLAG_HIDDEN]) |
381 | do_hidden_move (op); |
378 | do_hidden_move (op); |
382 | |
379 | |
383 | if (op->pick_up) |
380 | if (op->pick_up) |
384 | monster_check_pickup (op); |
381 | monster_check_pickup (op); |
385 | |
382 | |
… | |
… | |
389 | /* If we don't have an enemy, do special movement or the like */ |
386 | /* If we don't have an enemy, do special movement or the like */ |
390 | if (!enemy) |
387 | if (!enemy) |
391 | { |
388 | { |
392 | if (QUERY_FLAG (op, FLAG_ONLY_ATTACK)) |
389 | if (QUERY_FLAG (op, FLAG_ONLY_ATTACK)) |
393 | { |
390 | { |
394 | op->destroy (); |
391 | op->drop_and_destroy (); |
395 | return 1; |
392 | return 1; |
396 | } |
393 | } |
397 | |
394 | |
398 | /* Probably really a bug for a creature to have both |
395 | /* Probably really a bug for a creature to have both |
399 | * stand still and a movement type set. |
396 | * stand still and a movement type set. |
… | |
… | |
480 | if (!QUERY_FLAG (op, FLAG_SCARED)) |
477 | if (!QUERY_FLAG (op, FLAG_SCARED)) |
481 | { |
478 | { |
482 | rv_vector rv1; |
479 | rv_vector rv1; |
483 | |
480 | |
484 | /* 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 */ |
485 | for (part = op; part != NULL; part = part->more) |
482 | for (part = op; part; part = part->more) |
486 | { |
483 | { |
487 | get_rangevector (part, enemy, &rv1, 0x1); |
484 | get_rangevector (part, enemy, &rv1, 0x1); |
488 | dir = rv1.direction; |
485 | dir = rv1.direction; |
489 | |
486 | |
490 | /* 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 |
491 | * but that we test above... so can be old code here |
488 | * but that we test above... so can be old code here |
492 | */ |
489 | */ |
493 | if (QUERY_FLAG (op, FLAG_RUN_AWAY)) |
490 | if (QUERY_FLAG (op, FLAG_RUN_AWAY)) |
494 | dir = absdir (dir + 4); |
491 | dir = absdir (dir + 4); |
|
|
492 | |
495 | if (QUERY_FLAG (op, FLAG_CONFUSED)) |
493 | if (QUERY_FLAG (op, FLAG_CONFUSED)) |
496 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
494 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
497 | |
495 | |
498 | if (QUERY_FLAG (op, FLAG_CAST_SPELL) && !(rndm (3))) |
496 | if (QUERY_FLAG (op, FLAG_CAST_SPELL) && !(rndm (3))) |
499 | { |
|
|
500 | if (monster_cast_spell (op, part, enemy, dir, &rv1)) |
497 | if (monster_cast_spell (op, part, enemy, dir, &rv1)) |
501 | return 0; |
498 | return 0; |
502 | } |
|
|
503 | |
499 | |
504 | if (QUERY_FLAG (op, FLAG_READY_SCROLL) && !(rndm (3))) |
500 | if (QUERY_FLAG (op, FLAG_READY_SCROLL) && !(rndm (3))) |
505 | { |
|
|
506 | if (monster_use_scroll (op, part, enemy, dir, &rv1)) |
501 | if (monster_use_scroll (op, part, enemy, dir, &rv1)) |
507 | return 0; |
502 | return 0; |
508 | } |
|
|
509 | |
503 | |
510 | if (QUERY_FLAG (op, FLAG_READY_RANGE) && !(rndm (3))) |
504 | if (QUERY_FLAG (op, FLAG_READY_RANGE) && !(rndm (3))) |
511 | { |
|
|
512 | if (monster_use_range (op, part, enemy, dir)) |
505 | if (monster_use_range (op, part, enemy, dir)) |
513 | return 0; |
506 | return 0; |
514 | } |
507 | |
515 | if (QUERY_FLAG (op, FLAG_READY_SKILL) && !(rndm (3))) |
508 | if (QUERY_FLAG (op, FLAG_READY_SKILL) && !(rndm (3))) |
516 | { |
|
|
517 | if (monster_use_skill (op, rv.part, enemy, rv.direction)) |
509 | if (monster_use_skill (op, rv.part, enemy, rv.direction)) |
518 | return 0; |
510 | return 0; |
519 | } |
511 | |
520 | if (QUERY_FLAG (op, FLAG_READY_BOW) && !(rndm (2))) |
512 | if (QUERY_FLAG (op, FLAG_READY_BOW) && !(rndm (2))) |
521 | { |
|
|
522 | if (monster_use_bow (op, part, enemy, dir)) |
513 | if (monster_use_bow (op, part, enemy, dir)) |
523 | return 0; |
514 | return 0; |
524 | } |
|
|
525 | } /* for processing of all parts */ |
515 | } /* for processing of all parts */ |
526 | } /* If not scared */ |
516 | } /* If not scared */ |
527 | |
517 | |
528 | |
518 | |
529 | part = rv.part; |
519 | part = rv.part; |
… | |
… | |
660 | if (QUERY_FLAG (part, FLAG_FREED)) /* Might be freed by ghost-attack or hit-back */ |
650 | if (QUERY_FLAG (part, FLAG_FREED)) /* Might be freed by ghost-attack or hit-back */ |
661 | return 1; |
651 | return 1; |
662 | |
652 | |
663 | if (QUERY_FLAG (op, FLAG_ONLY_ATTACK)) |
653 | if (QUERY_FLAG (op, FLAG_ONLY_ATTACK)) |
664 | { |
654 | { |
665 | op->remove (); |
|
|
666 | op->destroy (); |
655 | op->drop_and_destroy (); |
667 | return 1; |
656 | return 1; |
668 | } |
657 | } |
|
|
658 | |
669 | return 0; |
659 | return 0; |
670 | } |
660 | } |
671 | |
661 | |
672 | int |
662 | int |
673 | can_hit (object *ob1, object *ob2, rv_vector * rv) |
663 | can_hit (object *ob1, object *ob2, rv_vector * rv) |
… | |
… | |
901 | * 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. |
902 | * |
892 | * |
903 | * At the moment this is only useful for throwing, perhaps for |
893 | * At the moment this is only useful for throwing, perhaps for |
904 | * 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 |
905 | */ |
895 | */ |
906 | |
|
|
907 | int |
896 | int |
908 | monster_use_skill (object *head, object *part, object *pl, int dir) |
897 | monster_use_skill (object *head, object *part, object *pl, int dir) |
909 | { |
898 | { |
910 | object *skill, *owner; |
899 | object *skill, *owner; |
911 | |
900 | |
… | |
… | |
917 | 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); |
918 | |
907 | |
919 | if (dirdiff (dir, dir2) < 1) |
908 | if (dirdiff (dir, dir2) < 1) |
920 | return 0; /* Might hit owner with skill -thrown rocks for example ? */ |
909 | return 0; /* Might hit owner with skill -thrown rocks for example ? */ |
921 | } |
910 | } |
|
|
911 | |
922 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
912 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
923 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
913 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
924 | |
914 | |
925 | /* skill selection - monster will use the next unused skill. |
915 | /* skill selection - monster will use the next unused skill. |
926 | * well...the following scenario will allow the monster to |
916 | * well...the following scenario will allow the monster to |
927 | * 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 |
928 | * more skills available to monsters. |
918 | * more skills available to monsters. |
929 | */ |
919 | */ |
930 | |
|
|
931 | for (skill = head->inv; skill != NULL; skill = skill->below) |
920 | for (skill = head->inv; skill; skill = skill->below) |
932 | if (skill->type == SKILL && skill != head->chosen_skill) |
921 | if (skill->type == SKILL && skill != head->chosen_skill) |
933 | { |
922 | { |
934 | head->chosen_skill = skill; |
923 | head->chosen_skill = skill; |
935 | break; |
924 | break; |
936 | } |
925 | } |
… | |
… | |
939 | { |
928 | { |
940 | 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); |
941 | CLEAR_FLAG (head, FLAG_READY_SKILL); |
930 | CLEAR_FLAG (head, FLAG_READY_SKILL); |
942 | return 0; |
931 | return 0; |
943 | } |
932 | } |
|
|
933 | |
944 | /* use skill */ |
934 | /* use skill */ |
945 | return do_skill (head, part, head->chosen_skill, dir, NULL); |
935 | return do_skill (head, part, head->chosen_skill, dir, NULL); |
946 | } |
936 | } |
947 | |
937 | |
948 | /* Monster will use a ranged spell attack. */ |
938 | /* Monster will use a ranged spell attack. */ |
949 | |
|
|
950 | int |
939 | int |
951 | monster_use_range (object *head, object *part, object *pl, int dir) |
940 | monster_use_range (object *head, object *part, object *pl, int dir) |
952 | { |
941 | { |
953 | object *wand, *owner; |
942 | object *wand, *owner; |
954 | int at_least_one = 0; |
943 | int at_least_one = 0; |
… | |
… | |
961 | 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); |
962 | |
951 | |
963 | if (dirdiff (dir, dir2) < 2) |
952 | if (dirdiff (dir, dir2) < 2) |
964 | return 0; /* Might hit owner with spell */ |
953 | return 0; /* Might hit owner with spell */ |
965 | } |
954 | } |
|
|
955 | |
966 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
956 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
967 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
957 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
968 | |
958 | |
969 | for (wand = head->inv; wand != NULL; wand = wand->below) |
959 | for (wand = head->inv; wand; wand = wand->below) |
970 | { |
960 | { |
971 | if (wand->type == WAND) |
961 | if (wand->type == WAND) |
972 | { |
962 | { |
973 | /* Found a wand, let's see if it has charges left */ |
963 | /* Found a wand, let's see if it has charges left */ |
974 | at_least_one = 1; |
964 | at_least_one = 1; |
… | |
… | |
980 | if (!(--wand->stats.food)) |
970 | if (!(--wand->stats.food)) |
981 | { |
971 | { |
982 | if (wand->arch) |
972 | if (wand->arch) |
983 | { |
973 | { |
984 | CLEAR_FLAG (wand, FLAG_ANIMATE); |
974 | CLEAR_FLAG (wand, FLAG_ANIMATE); |
985 | wand->face = wand->arch->clone.face; |
975 | wand->face = wand->arch->face; |
986 | wand->set_speed (0); |
976 | wand->set_speed (0); |
987 | } |
977 | } |
988 | } |
978 | } |
989 | /* Success */ |
979 | /* Success */ |
990 | return 1; |
980 | return 1; |
… | |
… | |
1009 | } |
999 | } |
1010 | |
1000 | |
1011 | if (at_least_one) |
1001 | if (at_least_one) |
1012 | return 0; |
1002 | return 0; |
1013 | |
1003 | |
1014 | 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); |
1015 | CLEAR_FLAG (head, FLAG_READY_RANGE); |
1005 | CLEAR_FLAG (head, FLAG_READY_RANGE); |
1016 | return 0; |
1006 | return 0; |
1017 | } |
1007 | } |
1018 | |
1008 | |
1019 | int |
1009 | int |
… | |
… | |
1021 | { |
1011 | { |
1022 | object *owner; |
1012 | object *owner; |
1023 | |
1013 | |
1024 | if (!(dir = path_to_player (part, pl, 0))) |
1014 | if (!(dir = path_to_player (part, pl, 0))) |
1025 | return 0; |
1015 | return 0; |
|
|
1016 | |
1026 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
1017 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
1027 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
1018 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
1028 | |
1019 | |
1029 | if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL) |
1020 | if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL) |
1030 | { |
1021 | { |
… | |
… | |
1038 | 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); |
1039 | |
1030 | |
1040 | } |
1031 | } |
1041 | |
1032 | |
1042 | /* Checks if putting on 'item' will make 'who' do more |
1033 | /* Checks if putting on 'item' will make 'who' do more |
1043 | * damage. This is a very simplistic check - also checking things |
1034 | * damage. This is a very simplistic check - also checking things |
1044 | * like speed and ac are also relevant. |
1035 | * like speed and ac are also relevant. |
1045 | * |
1036 | * |
1046 | * return true if item is a better object. |
1037 | * return true if item is a better object. |
1047 | */ |
1038 | */ |
1048 | |
|
|
1049 | int |
1039 | int |
1050 | check_good_weapon (object *who, object *item) |
1040 | check_good_weapon (object *who, object *item) |
1051 | { |
1041 | { |
1052 | object *other_weap; |
1042 | object *other_weap; |
1053 | int val = 0, i; |
1043 | int val = 0, i; |
1054 | |
1044 | |
1055 | 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) |
1056 | 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)) |
1057 | break; |
1047 | break; |
1058 | |
1048 | |
1059 | if (other_weap == NULL) /* No other weapons */ |
1049 | if (!other_weap) /* No other weapons */ |
1060 | return 1; |
1050 | return 1; |
1061 | |
1051 | |
1062 | /* 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 |
1063 | * better, just do some simple checks |
1053 | * better, just do some simple checks |
1064 | * Put some multipliers for things that hvae several effects, |
1054 | * Put some multipliers for things that hvae several effects, |
… | |
… | |
1069 | val += (item->magic - other_weap->magic) * 3; |
1059 | val += (item->magic - other_weap->magic) * 3; |
1070 | /* Monsters don't really get benefits from things like regen rates |
1060 | /* Monsters don't really get benefits from things like regen rates |
1071 | * from items. But the bonus for their stats are very important. |
1061 | * from items. But the bonus for their stats are very important. |
1072 | */ |
1062 | */ |
1073 | for (i = 0; i < NUM_STATS; i++) |
1063 | for (i = 0; i < NUM_STATS; i++) |
1074 | 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; |
1075 | |
1065 | |
1076 | if (val > 0) |
1066 | if (val > 0) |
1077 | return 1; |
1067 | return 1; |
1078 | else |
1068 | else |
1079 | return 0; |
1069 | return 0; |
1080 | |
|
|
1081 | } |
1070 | } |
1082 | |
1071 | |
1083 | int |
1072 | int |
1084 | check_good_armour (object *who, object *item) |
1073 | check_good_armour (object *who, object *item) |
1085 | { |
1074 | { |
1086 | object *other_armour; |
1075 | object *other_armour; |
1087 | int val = 0, i; |
1076 | int val = 0, i; |
1088 | |
1077 | |
1089 | 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) |
1090 | 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)) |
1091 | break; |
1080 | break; |
1092 | |
1081 | |
1093 | if (other_armour == NULL) /* No other armour, use the new */ |
1082 | if (other_armour == NULL) /* No other armour, use the new */ |
1094 | return 1; |
1083 | return 1; |
… | |
… | |
1116 | |
1105 | |
1117 | if (val > 0) |
1106 | if (val > 0) |
1118 | return 1; |
1107 | return 1; |
1119 | else |
1108 | else |
1120 | return 0; |
1109 | return 0; |
1121 | |
|
|
1122 | } |
1110 | } |
1123 | |
1111 | |
1124 | /* |
1112 | /* |
1125 | * monster_check_pickup(): checks for items that monster can pick up. |
1113 | * monster_check_pickup(): checks for items that monster can pick up. |
1126 | * |
1114 | * |
… | |
… | |
1134 | * 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 |
1135 | * 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 |
1136 | * 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 |
1137 | * affect stacking on this space. |
1125 | * affect stacking on this space. |
1138 | */ |
1126 | */ |
1139 | |
|
|
1140 | void |
1127 | void |
1141 | monster_check_pickup (object *monster) |
1128 | monster_check_pickup (object *monster) |
1142 | { |
1129 | { |
1143 | object *tmp, *next; |
1130 | object *tmp, *next; |
1144 | |
1131 | |
… | |
… | |
1163 | * monster_can_pick(): If the monster is interested in picking up |
1150 | * monster_can_pick(): If the monster is interested in picking up |
1164 | * the item, then return 0. Otherwise 0. |
1151 | * the item, then return 0. Otherwise 0. |
1165 | * Instead of pick_up, flags for "greed", etc, should be used. |
1152 | * Instead of pick_up, flags for "greed", etc, should be used. |
1166 | * 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. |
1167 | */ |
1154 | */ |
1168 | |
|
|
1169 | int |
1155 | int |
1170 | monster_can_pick (object *monster, object *item) |
1156 | monster_can_pick (object *monster, object *item) |
1171 | { |
1157 | { |
1172 | int flag = 0; |
1158 | int flag = 0; |
1173 | int i; |
1159 | int i; |
… | |
… | |
1219 | case ROD: |
1205 | case ROD: |
1220 | flag = QUERY_FLAG (monster, FLAG_USE_RANGE); |
1206 | flag = QUERY_FLAG (monster, FLAG_USE_RANGE); |
1221 | break; |
1207 | break; |
1222 | |
1208 | |
1223 | case SPELLBOOK: |
1209 | case SPELLBOOK: |
1224 | flag = (monster->arch != NULL && QUERY_FLAG ((&monster->arch->clone), FLAG_CAST_SPELL)); |
1210 | flag = monster->arch && QUERY_FLAG (monster->arch, FLAG_CAST_SPELL); |
1225 | break; |
1211 | break; |
1226 | |
1212 | |
1227 | case SCROLL: |
1213 | case SCROLL: |
1228 | flag = QUERY_FLAG (monster, FLAG_USE_SCROLL); |
1214 | flag = QUERY_FLAG (monster, FLAG_USE_SCROLL); |
1229 | break; |
1215 | break; |
… | |
… | |
1231 | case BOW: |
1217 | case BOW: |
1232 | case ARROW: |
1218 | case ARROW: |
1233 | flag = QUERY_FLAG (monster, FLAG_USE_BOW); |
1219 | flag = QUERY_FLAG (monster, FLAG_USE_BOW); |
1234 | break; |
1220 | break; |
1235 | } |
1221 | } |
|
|
1222 | |
1236 | /* 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 |
1237 | * 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 |
1238 | * use several locations. |
1225 | * use several locations. |
1239 | */ |
1226 | */ |
1240 | for (i = 0; i < NUM_BODY_LOCATIONS; i++) |
1227 | for (i = 0; i < NUM_BODY_LOCATIONS; i++) |
1241 | { |
1228 | { |
1242 | if (monster->body_info[i] && item->body_info[i]) |
1229 | if (monster->slot[i].info && item->slot[i].info) |
1243 | { |
1230 | { |
1244 | flag = 1; |
1231 | flag = 1; |
1245 | break; |
1232 | break; |
1246 | } |
1233 | } |
1247 | } |
1234 | } |
… | |
… | |
1255 | * monster_apply_below(): |
1242 | * monster_apply_below(): |
1256 | * 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 |
1257 | * eager to apply things, encounters something apply-able, |
1244 | * eager to apply things, encounters something apply-able, |
1258 | * then make him apply it |
1245 | * then make him apply it |
1259 | */ |
1246 | */ |
1260 | |
|
|
1261 | void |
1247 | void |
1262 | monster_apply_below (object *monster) |
1248 | monster_apply_below (object *monster) |
1263 | { |
1249 | { |
1264 | object *tmp, *next; |
1250 | object *tmp, *next; |
1265 | |
1251 | |
… | |
… | |
1292 | * 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. |
1293 | * (so that other monsters can pick it up and use it) |
1279 | * (so that other monsters can pick it up and use it) |
1294 | * Note that as things are now, monsters never drop something - |
1280 | * Note that as things are now, monsters never drop something - |
1295 | * they can pick up all that they can use. |
1281 | * they can pick up all that they can use. |
1296 | */ |
1282 | */ |
1297 | |
|
|
1298 | /* Sept 96, fixed this so skills will be readied -b.t.*/ |
1283 | /* Sept 96, fixed this so skills will be readied -b.t.*/ |
1299 | |
|
|
1300 | void |
1284 | void |
1301 | monster_check_apply (object *mon, object *item) |
1285 | monster_check_apply (object *mon, object *item) |
1302 | { |
1286 | { |
1303 | |
|
|
1304 | int flag = 0; |
1287 | int flag = 0; |
1305 | |
1288 | |
1306 | 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))) |
1307 | { |
1290 | { |
1308 | SET_FLAG (mon, FLAG_CAST_SPELL); |
1291 | SET_FLAG (mon, FLAG_CAST_SPELL); |
1309 | return; |
1292 | return; |
1310 | } |
1293 | } |
1311 | |
1294 | |
… | |
… | |
1320 | if (QUERY_FLAG (mon, FLAG_USE_BOW) && item->type == ARROW) |
1303 | if (QUERY_FLAG (mon, FLAG_USE_BOW) && item->type == ARROW) |
1321 | { |
1304 | { |
1322 | /* Check for the right kind of bow */ |
1305 | /* Check for the right kind of bow */ |
1323 | object *bow; |
1306 | object *bow; |
1324 | |
1307 | |
1325 | for (bow = mon->inv; bow != NULL; bow = bow->below) |
1308 | for (bow = mon->inv; bow; bow = bow->below) |
1326 | if (bow->type == BOW && bow->race == item->race) |
1309 | if (bow->type == BOW && bow->race == item->race) |
1327 | { |
1310 | { |
1328 | SET_FLAG (mon, FLAG_READY_BOW); |
1311 | SET_FLAG (mon, FLAG_READY_BOW); |
1329 | LOG (llevMonster, "Found correct bow for arrows.\n"); |
1312 | LOG (llevMonster, "Found correct bow for arrows.\n"); |
1330 | return; /* nothing more to do for arrows */ |
1313 | return; /* nothing more to do for arrows */ |
… | |
… | |
1382 | */ |
1365 | */ |
1383 | SET_FLAG (mon, FLAG_READY_SKILL); |
1366 | SET_FLAG (mon, FLAG_READY_SKILL); |
1384 | return; |
1367 | return; |
1385 | } |
1368 | } |
1386 | |
1369 | |
1387 | |
|
|
1388 | /* 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. |
1389 | * 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, |
1390 | * bolts, and whatever else, because it only checks against the |
1372 | * bolts, and whatever else, because it only checks against the |
1391 | * body_info locations. |
1373 | * body_info locations. |
1392 | */ |
1374 | */ |
… | |
… | |
1403 | /* should only be applying this item, not unapplying it. |
1385 | /* should only be applying this item, not unapplying it. |
1404 | * 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. |
1405 | * monsters have some advantages after all. |
1387 | * monsters have some advantages after all. |
1406 | */ |
1388 | */ |
1407 | manual_apply (mon, item, AP_APPLY | AP_IGNORE_CURSE); |
1389 | manual_apply (mon, item, AP_APPLY | AP_IGNORE_CURSE); |
1408 | |
|
|
1409 | return; |
|
|
1410 | } |
1390 | } |
1411 | |
1391 | |
1412 | void |
1392 | void |
1413 | npc_call_help (object *op) |
1393 | npc_call_help (object *op) |
1414 | { |
1394 | { |
… | |
… | |
1432 | if (QUERY_FLAG (npc, FLAG_ALIVE) && QUERY_FLAG (npc, FLAG_UNAGGRESSIVE)) |
1412 | if (QUERY_FLAG (npc, FLAG_ALIVE) && QUERY_FLAG (npc, FLAG_UNAGGRESSIVE)) |
1433 | npc->enemy = op->enemy; |
1413 | npc->enemy = op->enemy; |
1434 | } |
1414 | } |
1435 | } |
1415 | } |
1436 | |
1416 | |
1437 | |
|
|
1438 | int |
1417 | int |
1439 | 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) |
1440 | { |
1419 | { |
1441 | |
|
|
1442 | if (can_hit (part, enemy, rv)) |
1420 | if (can_hit (part, enemy, rv)) |
1443 | return dir; |
1421 | return dir; |
1444 | if (rv->distance < 10) |
1422 | if (rv->distance < 10) |
1445 | return absdir (dir + 4); |
1423 | return absdir (dir + 4); |
1446 | else if (rv->distance > 18) |
1424 | else if (rv->distance > 18) |
1447 | return dir; |
1425 | return dir; |
|
|
1426 | |
1448 | return 0; |
1427 | return 0; |
1449 | } |
1428 | } |
1450 | |
1429 | |
1451 | int |
1430 | int |
1452 | 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) |
1453 | { |
1432 | { |
1454 | |
|
|
1455 | 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) |
1456 | { |
1434 | { |
1457 | ob->move_status++; |
1435 | ob->move_status++; |
1458 | return (dir); |
1436 | return (dir); |
1459 | } |
1437 | } |
1460 | else if (ob->move_status > 20) |
1438 | else if (ob->move_status > 20) |
1461 | ob->move_status = 0; |
1439 | ob->move_status = 0; |
|
|
1440 | |
1462 | return absdir (dir + 4); |
1441 | return absdir (dir + 4); |
1463 | } |
1442 | } |
1464 | |
1443 | |
1465 | int |
1444 | int |
1466 | hitrun_att (int dir, object *ob, object *enemy) |
1445 | hitrun_att (int dir, object *ob, object *enemy) |
… | |
… | |
1469 | return dir; |
1448 | return dir; |
1470 | else if (ob->move_status < 50) |
1449 | else if (ob->move_status < 50) |
1471 | return absdir (dir + 4); |
1450 | return absdir (dir + 4); |
1472 | else |
1451 | else |
1473 | ob->move_status = 0; |
1452 | ob->move_status = 0; |
|
|
1453 | |
1474 | return absdir (dir + 4); |
1454 | return absdir (dir + 4); |
1475 | } |
1455 | } |
1476 | |
1456 | |
1477 | int |
1457 | int |
1478 | 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) |
… | |
… | |
1487 | return 0; |
1467 | return 0; |
1488 | else if (ob->move_status < 10) |
1468 | else if (ob->move_status < 10) |
1489 | return dir; |
1469 | return dir; |
1490 | else if (ob->move_status < 15) |
1470 | else if (ob->move_status < 15) |
1491 | return absdir (dir + 4); |
1471 | return absdir (dir + 4); |
|
|
1472 | |
1492 | ob->move_status = 0; |
1473 | ob->move_status = 0; |
1493 | return 0; |
1474 | return 0; |
1494 | } |
1475 | } |
1495 | |
1476 | |
1496 | int |
1477 | int |
… | |
… | |
1504 | * 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 |
1505 | * server should try to be resilant enough to avoid the problem |
1486 | * server should try to be resilant enough to avoid the problem |
1506 | */ |
1487 | */ |
1507 | 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) |
1508 | return absdir (dir + 4); |
1489 | return absdir (dir + 4); |
|
|
1490 | |
1509 | return dist_att (dir, ob, enemy, part, rv); |
1491 | return dist_att (dir, ob, enemy, part, rv); |
1510 | } |
1492 | } |
1511 | |
1493 | |
1512 | int |
1494 | int |
1513 | 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) |
1514 | { |
1496 | { |
1515 | if (rv->distance < 9) |
1497 | if (rv->distance < 9) |
1516 | return absdir (dir + 4); |
1498 | return absdir (dir + 4); |
|
|
1499 | |
1517 | return 0; |
1500 | return 0; |
1518 | } |
1501 | } |
1519 | |
1502 | |
1520 | void |
1503 | void |
1521 | circ1_move (object *ob) |
1504 | circ1_move (object *ob) |
1522 | { |
1505 | { |
1523 | 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 | |
1524 | if (++ob->move_status > 11) |
1508 | if (++ob->move_status > 11) |
1525 | ob->move_status = 0; |
1509 | ob->move_status = 0; |
|
|
1510 | |
1526 | if (!(move_object (ob, circle[ob->move_status]))) |
1511 | if (!(move_object (ob, circle[ob->move_status]))) |
1527 | (void) move_object (ob, rndm (8) + 1); |
1512 | move_object (ob, rndm (8) + 1); |
1528 | } |
1513 | } |
1529 | |
1514 | |
1530 | void |
1515 | void |
1531 | circ2_move (object *ob) |
1516 | circ2_move (object *ob) |
1532 | { |
1517 | { |
1533 | 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 | |
1534 | if (++ob->move_status > 19) |
1520 | if (++ob->move_status > 19) |
1535 | ob->move_status = 0; |
1521 | ob->move_status = 0; |
|
|
1522 | |
1536 | if (!(move_object (ob, circle[ob->move_status]))) |
1523 | if (!(move_object (ob, circle[ob->move_status]))) |
1537 | (void) move_object (ob, rndm (8) + 1); |
1524 | move_object (ob, rndm (8) + 1); |
1538 | } |
1525 | } |
1539 | |
1526 | |
1540 | void |
1527 | void |
1541 | pace_movev (object *ob) |
1528 | pace_movev (object *ob) |
1542 | { |
1529 | { |
1543 | if (ob->move_status++ > 6) |
1530 | if (ob->move_status++ > 6) |
1544 | ob->move_status = 0; |
1531 | ob->move_status = 0; |
|
|
1532 | |
1545 | if (ob->move_status < 4) |
1533 | if (ob->move_status < 4) |
1546 | (void) move_object (ob, 5); |
1534 | move_object (ob, 5); |
1547 | else |
1535 | else |
1548 | (void) move_object (ob, 1); |
1536 | move_object (ob, 1); |
1549 | } |
1537 | } |
1550 | |
1538 | |
1551 | void |
1539 | void |
1552 | pace_moveh (object *ob) |
1540 | pace_moveh (object *ob) |
1553 | { |
1541 | { |
1554 | if (ob->move_status++ > 6) |
1542 | if (ob->move_status++ > 6) |
1555 | ob->move_status = 0; |
1543 | ob->move_status = 0; |
|
|
1544 | |
1556 | if (ob->move_status < 4) |
1545 | if (ob->move_status < 4) |
1557 | (void) move_object (ob, 3); |
1546 | move_object (ob, 3); |
1558 | else |
1547 | else |
1559 | (void) move_object (ob, 7); |
1548 | move_object (ob, 7); |
1560 | } |
1549 | } |
1561 | |
1550 | |
1562 | void |
1551 | void |
1563 | pace2_movev (object *ob) |
1552 | pace2_movev (object *ob) |
1564 | { |
1553 | { |
1565 | if (ob->move_status++ > 16) |
1554 | if (ob->move_status++ > 16) |
1566 | ob->move_status = 0; |
1555 | ob->move_status = 0; |
|
|
1556 | |
1567 | if (ob->move_status < 6) |
1557 | if (ob->move_status < 6) |
1568 | (void) move_object (ob, 5); |
1558 | move_object (ob, 5); |
1569 | else if (ob->move_status < 8) |
1559 | else if (ob->move_status < 8) |
1570 | return; |
1560 | return; |
1571 | else if (ob->move_status < 13) |
1561 | else if (ob->move_status < 13) |
1572 | (void) move_object (ob, 1); |
1562 | move_object (ob, 1); |
1573 | else |
1563 | else |
1574 | return; |
1564 | return; |
1575 | } |
1565 | } |
1576 | |
1566 | |
1577 | void |
1567 | void |
1578 | pace2_moveh (object *ob) |
1568 | pace2_moveh (object *ob) |
1579 | { |
1569 | { |
1580 | if (ob->move_status++ > 16) |
1570 | if (ob->move_status++ > 16) |
1581 | ob->move_status = 0; |
1571 | ob->move_status = 0; |
|
|
1572 | |
1582 | if (ob->move_status < 6) |
1573 | if (ob->move_status < 6) |
1583 | (void) move_object (ob, 3); |
1574 | move_object (ob, 3); |
1584 | else if (ob->move_status < 8) |
1575 | else if (ob->move_status < 8) |
1585 | return; |
1576 | return; |
1586 | else if (ob->move_status < 13) |
1577 | else if (ob->move_status < 13) |
1587 | (void) move_object (ob, 7); |
1578 | move_object (ob, 7); |
1588 | else |
1579 | else |
1589 | return; |
1580 | return; |
1590 | } |
1581 | } |
1591 | |
1582 | |
1592 | void |
1583 | void |
… | |
… | |
1635 | * monsters to throw things like chairs and other pieces of |
1626 | * monsters to throw things like chairs and other pieces of |
1636 | * furniture, even if they are not good throwable objects. |
1627 | * furniture, even if they are not good throwable objects. |
1637 | * Probably better to have the monster throw a throwable object |
1628 | * Probably better to have the monster throw a throwable object |
1638 | * first, then throw any non equipped weapon. |
1629 | * first, then throw any non equipped weapon. |
1639 | */ |
1630 | */ |
1640 | |
|
|
1641 | object * |
1631 | object * |
1642 | find_mon_throw_ob (object *op) |
1632 | find_mon_throw_ob (object *op) |
1643 | { |
1633 | { |
1644 | object *tmp = NULL; |
1634 | object *tmp = NULL; |
1645 | |
1635 | |
… | |
… | |
1676 | * 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 |
1677 | * 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 |
1678 | * be within the valid range. MSW 2001-08-05 |
1668 | * be within the valid range. MSW 2001-08-05 |
1679 | * 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 |
1680 | */ |
1670 | */ |
1681 | |
|
|
1682 | int |
1671 | int |
1683 | can_detect_enemy (object *op, object *enemy, rv_vector * rv) |
1672 | can_detect_enemy (object *op, object *enemy, rv_vector * rv) |
1684 | { |
1673 | { |
1685 | int radius = MIN_MON_RADIUS, hide_discovery; |
1674 | int radius = MIN_MON_RADIUS, hide_discovery; |
1686 | |
1675 | |
… | |
… | |
1716 | |
1705 | |
1717 | /* use this for invis also */ |
1706 | /* use this for invis also */ |
1718 | hide_discovery = op->stats.Int / 5; |
1707 | hide_discovery = op->stats.Int / 5; |
1719 | |
1708 | |
1720 | /* Determine Detection radii */ |
1709 | /* Determine Detection radii */ |
1721 | if (!enemy->hide) /* to detect non-hidden (eg dark/invis enemy) */ |
1710 | if (!enemy->flag [FLAG_HIDDEN]) /* to detect non-hidden (eg dark/invis enemy) */ |
1722 | 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); |
1723 | else |
1712 | else |
1724 | { /* a level/INT/Dex adjustment for hiding */ |
1713 | { /* a level/INT/Dex adjustment for hiding */ |
1725 | object *sk_hide; |
|
|
1726 | int bonus = (op->level / 2) + (op->stats.Int / 5); |
1714 | int bonus = op->level / 2 + op->stats.Int / 5; |
1727 | |
1715 | |
1728 | if (enemy->type == PLAYER) |
1716 | if (enemy->type == PLAYER) |
1729 | { |
1717 | { |
1730 | if ((sk_hide = find_skill_by_number (enemy, SK_HIDING))) |
1718 | if (object *sk_hide = find_skill_by_number (enemy, SK_HIDING)) |
1731 | bonus -= sk_hide->level; |
1719 | bonus -= sk_hide->level; |
1732 | else |
1720 | else |
1733 | { |
1721 | { |
1734 | 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"); |
1735 | make_visible (enemy); |
1723 | make_visible (enemy); |
… | |
… | |
1744 | } /* else creature has modifiers for hiding */ |
1732 | } /* else creature has modifiers for hiding */ |
1745 | |
1733 | |
1746 | /* Radii stealth adjustment. Only if you are stealthy |
1734 | /* Radii stealth adjustment. Only if you are stealthy |
1747 | * will you be able to sneak up closer to creatures */ |
1735 | * will you be able to sneak up closer to creatures */ |
1748 | if (QUERY_FLAG (enemy, FLAG_STEALTH)) |
1736 | if (QUERY_FLAG (enemy, FLAG_STEALTH)) |
1749 | radius = radius / 2, hide_discovery = hide_discovery / 3; |
1737 | { |
|
|
1738 | radius /= 2; |
|
|
1739 | hide_discovery /= 3; |
|
|
1740 | } |
1750 | |
1741 | |
1751 | /* Radii adjustment for enemy standing in the dark */ |
1742 | /* Radii adjustment for enemy standing in the dark */ |
1752 | if (op->map->darkness > 0 && !stand_in_light (enemy)) |
1743 | if (op->map->darkness > 0 && !stand_in_light (enemy)) |
1753 | { |
1744 | { |
1754 | /* on dark maps body heat can help indicate location with infravision |
1745 | /* on dark maps body heat can help indicate location with infravision |
… | |
… | |
1772 | * 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 |
1773 | * do something. Note that the distance field in the |
1764 | * do something. Note that the distance field in the |
1774 | * 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 |
1775 | * find that. |
1766 | * find that. |
1776 | */ |
1767 | */ |
1777 | if (radius > 13) |
1768 | // note that the above reasoning was utter bullshit even at the time it was written |
1778 | radius = 13; |
1769 | // we use 25, lets see if we have the cpu time for it |
|
|
1770 | radius = min (25, radius); |
1779 | |
1771 | |
1780 | /* Enemy in range! Now test for detection */ |
1772 | /* Enemy in range! Now test for detection */ |
1781 | if ((int) rv->distance <= radius) |
1773 | if (rv->distance <= radius) |
1782 | { |
1774 | { |
1783 | /* ah, we are within range, detected? take cases */ |
1775 | /* ah, we are within range, detected? take cases */ |
1784 | if (!enemy->invisible) /* enemy in dark squares... are seen! */ |
1776 | if (!enemy->invisible) /* enemy in dark squares... are seen! */ |
1785 | return 1; |
1777 | return 1; |
1786 | |
1778 | |
1787 | /* hidden or low-quality invisible */ |
1779 | /* hidden or low-quality invisible */ |
1788 | if (enemy->hide && (rv->distance <= 1) && (rndm (100) <= hide_discovery)) |
1780 | if (enemy->flag [FLAG_HIDDEN] && rv->distance <= 1 && rndm (100) <= hide_discovery) |
1789 | { |
1781 | { |
1790 | make_visible (enemy); |
1782 | make_visible (enemy); |
|
|
1783 | |
1791 | /* inform players of new status */ |
1784 | /* inform players of new status */ |
1792 | if (enemy->type == PLAYER && player_can_view (enemy, op)) |
1785 | if (enemy->type == PLAYER && player_can_view (enemy, op)) |
1793 | 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 | |
1794 | return 1; /* detected enemy */ |
1788 | return 1; /* detected enemy */ |
1795 | } |
1789 | } |
1796 | else if (enemy->invisible) |
1790 | else if (enemy->invisible) |
1797 | { |
1791 | { |
1798 | /* Change this around - instead of negating the invisible, just |
1792 | /* Change this around - instead of negating the invisible, just |
1799 | * 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 |
1800 | * do something to you. Decreasing the duration of invisible |
1794 | * do something to you. Decreasing the duration of invisible |
1801 | * 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 |
1802 | * can then basically negate the spell. The spell isn't negated - |
1796 | * can then basically negate the spell. The spell isn't negated - |
1803 | * they just know where you are! |
1797 | * they just know where you are! |
1804 | */ |
1798 | */ |
1805 | if ((rndm (50)) <= hide_discovery) |
1799 | if (rndm (50) <= hide_discovery) |
1806 | { |
1800 | { |
1807 | if (enemy->type == PLAYER) |
1801 | if (enemy->type == PLAYER) |
1808 | { |
|
|
1809 | 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)); |
1810 | } |
1803 | |
1811 | return 1; |
1804 | return 1; |
1812 | } |
1805 | } |
1813 | } |
1806 | } |
1814 | } /* within range */ |
1807 | } /* within range */ |
1815 | |
1808 | |
… | |
… | |
1820 | /* 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 |
1821 | * intellegent algorithm. For one thing, we ignore los here, SO it |
1814 | * intellegent algorithm. For one thing, we ignore los here, SO it |
1822 | * 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 |
1823 | * other side of a wall (!). |
1816 | * other side of a wall (!). |
1824 | */ |
1817 | */ |
1825 | |
|
|
1826 | int |
1818 | int |
1827 | stand_in_light (object *op) |
1819 | stand_in_light (object *op) |
1828 | { |
1820 | { |
1829 | sint16 nx, ny; |
|
|
1830 | maptile *m; |
|
|
1831 | |
|
|
1832 | |
|
|
1833 | if (!op) |
1821 | if (!op) |
1834 | return 0; |
1822 | return 0; |
|
|
1823 | |
1835 | if (op->glow_radius > 0) |
1824 | if (op->glow_radius > 0) |
1836 | return 1; |
1825 | return 1; |
1837 | |
1826 | |
1838 | if (op->map) |
1827 | if (op->map) |
1839 | { |
1828 | { |
1840 | int x, y, x1, y1; |
|
|
1841 | |
|
|
1842 | |
|
|
1843 | |
|
|
1844 | /* 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 |
1845 | * 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. |
1846 | */ |
1831 | */ |
1847 | 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++) |
1848 | { |
1833 | { |
1849 | 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++) |
1850 | { |
1835 | { |
1851 | m = op->map; |
1836 | maptile *m = op->map; |
1852 | nx = x; |
1837 | sint16 nx = x; |
1853 | ny = y; |
1838 | sint16 ny = y; |
1854 | |
1839 | |
1855 | if (get_map_flags (m, &m, nx, ny, &nx, &ny) & P_OUT_OF_MAP) |
1840 | if (xy_normalise (m, nx, ny)) |
1856 | continue; |
1841 | if (idistance (x - op->x, y - op->y) < m->at (nx, ny).light) |
1857 | |
|
|
1858 | x1 = abs (x - op->x) * abs (x - op->x); |
|
|
1859 | y1 = abs (y - op->y) * abs (y - op->y); |
|
|
1860 | if (isqrt (x1 + y1) < GET_MAP_LIGHT (m, nx, ny)) |
|
|
1861 | return 1; |
1842 | return 1; |
1862 | } |
1843 | } |
1863 | } |
1844 | } |
1864 | } |
1845 | } |
|
|
1846 | |
1865 | return 0; |
1847 | return 0; |
1866 | } |
1848 | } |
1867 | |
|
|
1868 | |
1849 | |
1869 | /* assuming no walls/barriers, lets check to see if its *possible* |
1850 | /* assuming no walls/barriers, lets check to see if its *possible* |
1870 | * to see an enemy. Note, "detection" is different from "seeing". |
1851 | * to see an enemy. Note, "detection" is different from "seeing". |
1871 | * See can_detect_enemy() for more details. -b.t. |
1852 | * See can_detect_enemy() for more details. -b.t. |
1872 | * return 0 if can't be seen, 1 if can be |
1853 | * return 0 if can't be seen, 1 if can be |
1873 | */ |
1854 | */ |
1874 | |
|
|
1875 | int |
1855 | int |
1876 | can_see_enemy (object *op, object *enemy) |
1856 | can_see_enemy (object *op, object *enemy) |
1877 | { |
1857 | { |
1878 | object *looker = op->head ? op->head : op; |
1858 | object *looker = op->head ? op->head : op; |
1879 | |
1859 | |
… | |
… | |
1895 | * However,if you carry any source of light, then the hidden |
1875 | * However,if you carry any source of light, then the hidden |
1896 | * creature is seeable (and stupid) */ |
1876 | * creature is seeable (and stupid) */ |
1897 | |
1877 | |
1898 | if (has_carried_lights (enemy)) |
1878 | if (has_carried_lights (enemy)) |
1899 | { |
1879 | { |
1900 | if (enemy->hide) |
1880 | if (enemy->flag [FLAG_HIDDEN]) |
1901 | { |
1881 | { |
1902 | make_visible (enemy); |
1882 | make_visible (enemy); |
1903 | 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!"); |
1904 | } |
1884 | } |
|
|
1885 | |
1905 | return 1; |
1886 | return 1; |
1906 | } |
1887 | } |
1907 | else if (enemy->hide) |
1888 | else if (enemy->flag [FLAG_HIDDEN]) |
1908 | return 0; |
1889 | return 0; |
1909 | |
1890 | |
1910 | /* Invisible enemy. Break apart the check for invis undead/invis looker |
1891 | /* Invisible enemy. Break apart the check for invis undead/invis looker |
1911 | * 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, |
1912 | * and making it a conditional makes the code pretty ugly. |
1893 | * and making it a conditional makes the code pretty ugly. |
1913 | */ |
1894 | */ |
1914 | if (!QUERY_FLAG (looker, FLAG_SEE_INVISIBLE)) |
1895 | if (!QUERY_FLAG (looker, FLAG_SEE_INVISIBLE)) |
1915 | { |
|
|
1916 | if (makes_invisible_to (enemy, looker)) |
1896 | if (makes_invisible_to (enemy, looker)) |
1917 | return 0; |
1897 | return 0; |
1918 | } |
|
|
1919 | } |
1898 | } |
1920 | else if (looker->type == PLAYER) /* for players, a (possible) shortcut */ |
1899 | else if (looker->type == PLAYER) /* for players, a (possible) shortcut */ |
1921 | if (player_can_view (looker, enemy)) |
1900 | if (player_can_view (looker, enemy)) |
1922 | return 1; |
1901 | return 1; |
1923 | |
1902 | |
… | |
… | |
1934 | && (!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))) |
1935 | return 0; |
1914 | return 0; |
1936 | |
1915 | |
1937 | return 1; |
1916 | return 1; |
1938 | } |
1917 | } |
|
|
1918 | |