1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
3 | |
3 | * |
4 | Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
5 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | |
7 | * |
8 | This program is free software; you can redistribute it and/or modify |
8 | * Crossfire TRT is free software; you can redistribute it and/or modify it |
9 | it under the terms of the GNU General Public License as published by |
9 | * under the terms of the GNU General Public License as published by the Free |
10 | the Free Software Foundation; either version 2 of the License, or |
10 | * Software Foundation; either version 2 of the License, or (at your option) |
11 | (at your option) any later version. |
11 | * 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, but |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
16 | GNU General Public License for more details. |
16 | * 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 along |
19 | along with this program; if not, write to the Free Software |
19 | * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
21 | |
21 | * |
22 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | #include <global.h> |
25 | #include <global.h> |
26 | #include <sproto.h> |
26 | #include <sproto.h> |
27 | #include <spells.h> |
27 | #include <spells.h> |
28 | #include <skills.h> |
28 | #include <skills.h> |
… | |
… | |
85 | * target enemy - this code below makes sure the enemy is something |
85 | * target enemy - this code below makes sure the enemy is something |
86 | * that should be attacked. My guess is that the arrow hits |
86 | * that should be attacked. My guess is that the arrow hits |
87 | * the creature/owner, and so the creature then takes that |
87 | * the creature/owner, and so the creature then takes that |
88 | * as the enemy to attack. |
88 | * as the enemy to attack. |
89 | */ |
89 | */ |
90 | else if (!QUERY_FLAG (npc->enemy, FLAG_MONSTER) && |
90 | else if (!QUERY_FLAG (npc->enemy, FLAG_MONSTER) |
91 | !QUERY_FLAG (npc->enemy, FLAG_GENERATOR) && npc->enemy->type != PLAYER && npc->enemy->type != GOLEM) |
91 | && !QUERY_FLAG (npc->enemy, FLAG_GENERATOR) |
|
|
92 | && npc->enemy->type != PLAYER |
|
|
93 | && npc->enemy->type != GOLEM) |
92 | npc->enemy = NULL; |
94 | npc->enemy = NULL; |
93 | |
95 | |
94 | } |
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 | } |
… | |
… | |
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 | |
… | |
… | |
229 | /* Sees if this monster should wake up. |
229 | /* Sees if this monster should wake up. |
230 | * Currently, this is only called from move_monster, and |
230 | * Currently, this is only called from move_monster, and |
231 | * if enemy is set, then so should be rv. |
231 | * if enemy is set, then so should be rv. |
232 | * returns 1 if the monster should wake up, 0 otherwise. |
232 | * returns 1 if the monster should wake up, 0 otherwise. |
233 | */ |
233 | */ |
234 | |
|
|
235 | int |
234 | int |
236 | check_wakeup (object *op, object *enemy, rv_vector * rv) |
235 | check_wakeup (object *op, object *enemy, rv_vector * rv) |
237 | { |
236 | { |
238 | int radius = op->stats.Wis > MIN_MON_RADIUS ? op->stats.Wis : MIN_MON_RADIUS; |
237 | int radius = op->stats.Wis > MIN_MON_RADIUS ? op->stats.Wis : MIN_MON_RADIUS; |
239 | |
238 | |
… | |
… | |
278 | int i; |
277 | int i; |
279 | |
278 | |
280 | /* Give up to 15 chances for a monster to move randomly */ |
279 | /* Give up to 15 chances for a monster to move randomly */ |
281 | for (i = 0; i < 15; i++) |
280 | for (i = 0; i < 15; i++) |
282 | { |
281 | { |
283 | if (move_object (op, RANDOM () % 8 + 1)) |
282 | if (move_object (op, rndm (8) + 1)) |
284 | return 1; |
283 | return 1; |
285 | } |
284 | } |
286 | return 0; |
285 | return 0; |
287 | } |
286 | } |
288 | |
287 | |
289 | /* |
288 | /* |
290 | * Move-monster returns 1 if the object has been freed, otherwise 0. |
289 | * Move-monster returns 1 if the object has been freed, otherwise 0. |
291 | */ |
290 | */ |
292 | |
|
|
293 | int |
291 | int |
294 | move_monster (object *op) |
292 | move_monster (object *op) |
295 | { |
293 | { |
296 | int dir, diff, pre_att_dir; /* elmex: pre_att_dir remembers the direction before attack movement */ |
294 | int dir, diff, pre_att_dir; /* elmex: pre_att_dir remembers the direction before attack movement */ |
297 | object *owner, *enemy, *part, *oph = op; |
295 | object *owner, *enemy, *part, *oph = op; |
… | |
… | |
357 | } |
355 | } |
358 | |
356 | |
359 | /* this should probably get modified by many more values. |
357 | /* this should probably get modified by many more values. |
360 | * (eg, creatures resistance to fear, level, etc. ) |
358 | * (eg, creatures resistance to fear, level, etc. ) |
361 | */ |
359 | */ |
362 | if (QUERY_FLAG (op, FLAG_SCARED) && !(RANDOM () % 20)) |
360 | if (QUERY_FLAG (op, FLAG_SCARED) && !(rndm (20))) |
363 | { |
361 | { |
364 | CLEAR_FLAG (op, FLAG_SCARED); /* Time to regain some "guts"... */ |
362 | CLEAR_FLAG (op, FLAG_SCARED); /* Time to regain some "guts"... */ |
365 | } |
363 | } |
366 | |
364 | |
367 | if (INVOKE_OBJECT (MONSTER_MOVE, op, ARG_OBJECT (op->enemy))) |
365 | if (INVOKE_OBJECT (MONSTER_MOVE, op, ARG_OBJECT (op->enemy))) |
… | |
… | |
446 | } /* stand still */ |
444 | } /* stand still */ |
447 | return 0; |
445 | return 0; |
448 | } /* no enemy */ |
446 | } /* no enemy */ |
449 | |
447 | |
450 | /* We have an enemy. Block immediately below is for pets */ |
448 | /* 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)) |
449 | if ((op->attack_movement & HI4) == PETMOVE |
|
|
450 | && (owner = op->owner) != NULL |
|
|
451 | && !on_same_map (op, owner) |
|
|
452 | && !owner->flag [FLAG_REMOVED]) |
452 | return follow_owner (op, owner); |
453 | return follow_owner (op, owner); |
453 | |
454 | |
454 | /* doppleganger code to change monster facing to that of the nearest |
455 | /* doppleganger code to change monster facing to that of the nearest |
455 | * player. Hmm. The code is here, but no monster in the current |
456 | * player. Hmm. The code is here, but no monster in the current |
456 | * arch set uses it. |
457 | * arch set uses it. |
… | |
… | |
475 | if (!QUERY_FLAG (op, FLAG_SCARED)) |
476 | if (!QUERY_FLAG (op, FLAG_SCARED)) |
476 | { |
477 | { |
477 | rv_vector rv1; |
478 | rv_vector rv1; |
478 | |
479 | |
479 | /* now we test every part of an object .... this is a real ugly piece of code */ |
480 | /* 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) |
481 | for (part = op; part; part = part->more) |
481 | { |
482 | { |
482 | get_rangevector (part, enemy, &rv1, 0x1); |
483 | get_rangevector (part, enemy, &rv1, 0x1); |
483 | dir = rv1.direction; |
484 | dir = rv1.direction; |
484 | |
485 | |
485 | /* hm, not sure about this part - in original was a scared flag here too |
486 | /* 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 |
487 | * but that we test above... so can be old code here |
487 | */ |
488 | */ |
488 | if (QUERY_FLAG (op, FLAG_RUN_AWAY)) |
489 | if (QUERY_FLAG (op, FLAG_RUN_AWAY)) |
489 | dir = absdir (dir + 4); |
490 | dir = absdir (dir + 4); |
|
|
491 | |
490 | if (QUERY_FLAG (op, FLAG_CONFUSED)) |
492 | if (QUERY_FLAG (op, FLAG_CONFUSED)) |
491 | dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); |
493 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
492 | |
494 | |
493 | if (QUERY_FLAG (op, FLAG_CAST_SPELL) && !(RANDOM () % 3)) |
495 | if (QUERY_FLAG (op, FLAG_CAST_SPELL) && !(rndm (3))) |
494 | { |
|
|
495 | if (monster_cast_spell (op, part, enemy, dir, &rv1)) |
496 | if (monster_cast_spell (op, part, enemy, dir, &rv1)) |
496 | return 0; |
497 | return 0; |
497 | } |
|
|
498 | |
498 | |
499 | if (QUERY_FLAG (op, FLAG_READY_SCROLL) && !(RANDOM () % 3)) |
499 | if (QUERY_FLAG (op, FLAG_READY_SCROLL) && !(rndm (3))) |
500 | { |
|
|
501 | if (monster_use_scroll (op, part, enemy, dir, &rv1)) |
500 | if (monster_use_scroll (op, part, enemy, dir, &rv1)) |
502 | return 0; |
501 | return 0; |
503 | } |
|
|
504 | |
502 | |
505 | if (QUERY_FLAG (op, FLAG_READY_RANGE) && !(RANDOM () % 3)) |
503 | if (QUERY_FLAG (op, FLAG_READY_RANGE) && !(rndm (3))) |
506 | { |
|
|
507 | if (monster_use_range (op, part, enemy, dir)) |
504 | if (monster_use_range (op, part, enemy, dir)) |
508 | return 0; |
505 | return 0; |
509 | } |
506 | |
510 | if (QUERY_FLAG (op, FLAG_READY_SKILL) && !(RANDOM () % 3)) |
507 | if (QUERY_FLAG (op, FLAG_READY_SKILL) && !(rndm (3))) |
511 | { |
|
|
512 | if (monster_use_skill (op, rv.part, enemy, rv.direction)) |
508 | if (monster_use_skill (op, rv.part, enemy, rv.direction)) |
513 | return 0; |
509 | return 0; |
514 | } |
510 | |
515 | if (QUERY_FLAG (op, FLAG_READY_BOW) && !(RANDOM () % 2)) |
511 | if (QUERY_FLAG (op, FLAG_READY_BOW) && !(rndm (2))) |
516 | { |
|
|
517 | if (monster_use_bow (op, part, enemy, dir)) |
512 | if (monster_use_bow (op, part, enemy, dir)) |
518 | return 0; |
513 | return 0; |
519 | } |
|
|
520 | } /* for processing of all parts */ |
514 | } /* for processing of all parts */ |
521 | } /* If not scared */ |
515 | } /* If not scared */ |
522 | |
516 | |
523 | |
517 | |
524 | part = rv.part; |
518 | part = rv.part; |
… | |
… | |
526 | |
520 | |
527 | if (QUERY_FLAG (op, FLAG_SCARED) || QUERY_FLAG (op, FLAG_RUN_AWAY)) |
521 | if (QUERY_FLAG (op, FLAG_SCARED) || QUERY_FLAG (op, FLAG_RUN_AWAY)) |
528 | dir = absdir (dir + 4); |
522 | dir = absdir (dir + 4); |
529 | |
523 | |
530 | if (QUERY_FLAG (op, FLAG_CONFUSED)) |
524 | if (QUERY_FLAG (op, FLAG_CONFUSED)) |
531 | dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); |
525 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
532 | |
526 | |
533 | pre_att_dir = dir; /* remember the original direction */ |
527 | pre_att_dir = dir; /* remember the original direction */ |
534 | |
528 | |
535 | if ((op->attack_movement & LO4) && !QUERY_FLAG (op, FLAG_SCARED)) |
529 | if ((op->attack_movement & LO4) && !QUERY_FLAG (op, FLAG_SCARED)) |
536 | { |
530 | { |
… | |
… | |
668 | can_hit (object *ob1, object *ob2, rv_vector * rv) |
662 | can_hit (object *ob1, object *ob2, rv_vector * rv) |
669 | { |
663 | { |
670 | object *more; |
664 | object *more; |
671 | rv_vector rv1; |
665 | rv_vector rv1; |
672 | |
666 | |
673 | if (QUERY_FLAG (ob1, FLAG_CONFUSED) && !(RANDOM () % 3)) |
667 | if (QUERY_FLAG (ob1, FLAG_CONFUSED) && !(rndm (3))) |
674 | return 0; |
668 | return 0; |
675 | |
669 | |
676 | if (abs (rv->distance_x) < 2 && abs (rv->distance_y) < 2) |
670 | if (abs (rv->distance_x) < 2 && abs (rv->distance_y) < 2) |
677 | return 1; |
671 | return 1; |
678 | |
672 | |
… | |
… | |
787 | return 0; /* Might hit owner with spell */ |
781 | return 0; /* Might hit owner with spell */ |
788 | } |
782 | } |
789 | } |
783 | } |
790 | |
784 | |
791 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
785 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
792 | dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); |
786 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
793 | |
787 | |
794 | /* If the monster hasn't already chosen a spell, choose one |
788 | /* If the monster hasn't already chosen a spell, choose one |
795 | * I'm not sure if it really make sense to pre-select spells (events |
789 | * I'm not sure if it really make sense to pre-select spells (events |
796 | * could be different by the time the monster goes again). |
790 | * could be different by the time the monster goes again). |
797 | */ |
791 | */ |
… | |
… | |
864 | return 0; /* Might hit owner with spell */ |
858 | return 0; /* Might hit owner with spell */ |
865 | } |
859 | } |
866 | } |
860 | } |
867 | |
861 | |
868 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
862 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
869 | dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); |
863 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
870 | |
864 | |
871 | for (scroll = head->inv; scroll; scroll = scroll->below) |
865 | for (scroll = head->inv; scroll; scroll = scroll->below) |
872 | if (scroll->type == SCROLL && monster_should_cast_spell (head, scroll->inv)) |
866 | if (scroll->type == SCROLL && monster_should_cast_spell (head, scroll->inv)) |
873 | break; |
867 | break; |
874 | |
868 | |
… | |
… | |
896 | * The skills we are treating here are all but those. -b.t. |
890 | * The skills we are treating here are all but those. -b.t. |
897 | * |
891 | * |
898 | * At the moment this is only useful for throwing, perhaps for |
892 | * 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 |
893 | * stealing. TODO: This should be more integrated in the game. -MT, 25.11.01 |
900 | */ |
894 | */ |
901 | |
|
|
902 | int |
895 | int |
903 | monster_use_skill (object *head, object *part, object *pl, int dir) |
896 | monster_use_skill (object *head, object *part, object *pl, int dir) |
904 | { |
897 | { |
905 | object *skill, *owner; |
898 | object *skill, *owner; |
906 | |
899 | |
… | |
… | |
912 | int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y); |
905 | int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y); |
913 | |
906 | |
914 | if (dirdiff (dir, dir2) < 1) |
907 | if (dirdiff (dir, dir2) < 1) |
915 | return 0; /* Might hit owner with skill -thrown rocks for example ? */ |
908 | return 0; /* Might hit owner with skill -thrown rocks for example ? */ |
916 | } |
909 | } |
|
|
910 | |
917 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
911 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
918 | dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); |
912 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
919 | |
913 | |
920 | /* skill selection - monster will use the next unused skill. |
914 | /* skill selection - monster will use the next unused skill. |
921 | * well...the following scenario will allow the monster to |
915 | * well...the following scenario will allow the monster to |
922 | * toggle between 2 skills. One day it would be nice to make |
916 | * toggle between 2 skills. One day it would be nice to make |
923 | * more skills available to monsters. |
917 | * more skills available to monsters. |
924 | */ |
918 | */ |
925 | |
|
|
926 | for (skill = head->inv; skill != NULL; skill = skill->below) |
919 | for (skill = head->inv; skill; skill = skill->below) |
927 | if (skill->type == SKILL && skill != head->chosen_skill) |
920 | if (skill->type == SKILL && skill != head->chosen_skill) |
928 | { |
921 | { |
929 | head->chosen_skill = skill; |
922 | head->chosen_skill = skill; |
930 | break; |
923 | break; |
931 | } |
924 | } |
… | |
… | |
934 | { |
927 | { |
935 | LOG (llevDebug, "Error: Monster %s (%d) has FLAG_READY_SKILL without skill.\n", &head->name, head->count); |
928 | LOG (llevDebug, "Error: Monster %s (%d) has FLAG_READY_SKILL without skill.\n", &head->name, head->count); |
936 | CLEAR_FLAG (head, FLAG_READY_SKILL); |
929 | CLEAR_FLAG (head, FLAG_READY_SKILL); |
937 | return 0; |
930 | return 0; |
938 | } |
931 | } |
|
|
932 | |
939 | /* use skill */ |
933 | /* use skill */ |
940 | return do_skill (head, part, head->chosen_skill, dir, NULL); |
934 | return do_skill (head, part, head->chosen_skill, dir, NULL); |
941 | } |
935 | } |
942 | |
936 | |
943 | /* Monster will use a ranged spell attack. */ |
937 | /* Monster will use a ranged spell attack. */ |
944 | |
|
|
945 | int |
938 | int |
946 | monster_use_range (object *head, object *part, object *pl, int dir) |
939 | monster_use_range (object *head, object *part, object *pl, int dir) |
947 | { |
940 | { |
948 | object *wand, *owner; |
941 | object *wand, *owner; |
949 | int at_least_one = 0; |
942 | int at_least_one = 0; |
… | |
… | |
956 | int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y); |
949 | int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y); |
957 | |
950 | |
958 | if (dirdiff (dir, dir2) < 2) |
951 | if (dirdiff (dir, dir2) < 2) |
959 | return 0; /* Might hit owner with spell */ |
952 | return 0; /* Might hit owner with spell */ |
960 | } |
953 | } |
|
|
954 | |
961 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
955 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
962 | dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); |
956 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
963 | |
957 | |
964 | for (wand = head->inv; wand != NULL; wand = wand->below) |
958 | for (wand = head->inv; wand; wand = wand->below) |
965 | { |
959 | { |
966 | if (wand->type == WAND) |
960 | if (wand->type == WAND) |
967 | { |
961 | { |
968 | /* Found a wand, let's see if it has charges left */ |
962 | /* Found a wand, let's see if it has charges left */ |
969 | at_least_one = 1; |
963 | at_least_one = 1; |
… | |
… | |
975 | if (!(--wand->stats.food)) |
969 | if (!(--wand->stats.food)) |
976 | { |
970 | { |
977 | if (wand->arch) |
971 | if (wand->arch) |
978 | { |
972 | { |
979 | CLEAR_FLAG (wand, FLAG_ANIMATE); |
973 | CLEAR_FLAG (wand, FLAG_ANIMATE); |
980 | wand->face = wand->arch->clone.face; |
974 | wand->face = wand->arch->face; |
981 | wand->set_speed (0); |
975 | wand->set_speed (0); |
982 | } |
976 | } |
983 | } |
977 | } |
984 | /* Success */ |
978 | /* Success */ |
985 | return 1; |
979 | return 1; |
… | |
… | |
1004 | } |
998 | } |
1005 | |
999 | |
1006 | if (at_least_one) |
1000 | if (at_least_one) |
1007 | return 0; |
1001 | return 0; |
1008 | |
1002 | |
1009 | LOG (llevError, "Error: Monster %s (%d) HAS_READY_RANG() without wand/horn/rod.\n", &head->name, head->count); |
1003 | 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); |
1004 | CLEAR_FLAG (head, FLAG_READY_RANGE); |
1011 | return 0; |
1005 | return 0; |
1012 | } |
1006 | } |
1013 | |
1007 | |
1014 | int |
1008 | int |
… | |
… | |
1016 | { |
1010 | { |
1017 | object *owner; |
1011 | object *owner; |
1018 | |
1012 | |
1019 | if (!(dir = path_to_player (part, pl, 0))) |
1013 | if (!(dir = path_to_player (part, pl, 0))) |
1020 | return 0; |
1014 | return 0; |
|
|
1015 | |
1021 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
1016 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
1022 | dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); |
1017 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
1023 | |
1018 | |
1024 | if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL) |
1019 | if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL) |
1025 | { |
1020 | { |
1026 | int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y); |
1021 | int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y); |
1027 | |
1022 | |
… | |
… | |
1033 | return fire_bow (head, part, NULL, dir, 0, part->x, part->y); |
1028 | return fire_bow (head, part, NULL, dir, 0, part->x, part->y); |
1034 | |
1029 | |
1035 | } |
1030 | } |
1036 | |
1031 | |
1037 | /* Checks if putting on 'item' will make 'who' do more |
1032 | /* Checks if putting on 'item' will make 'who' do more |
1038 | * damage. This is a very simplistic check - also checking things |
1033 | * damage. This is a very simplistic check - also checking things |
1039 | * like speed and ac are also relevant. |
1034 | * like speed and ac are also relevant. |
1040 | * |
1035 | * |
1041 | * return true if item is a better object. |
1036 | * return true if item is a better object. |
1042 | */ |
1037 | */ |
1043 | |
|
|
1044 | int |
1038 | int |
1045 | check_good_weapon (object *who, object *item) |
1039 | check_good_weapon (object *who, object *item) |
1046 | { |
1040 | { |
1047 | object *other_weap; |
1041 | object *other_weap; |
1048 | int val = 0, i; |
1042 | int val = 0, i; |
1049 | |
1043 | |
1050 | for (other_weap = who->inv; other_weap != NULL; other_weap = other_weap->below) |
1044 | 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)) |
1045 | if (other_weap->type == item->type && QUERY_FLAG (other_weap, FLAG_APPLIED)) |
1052 | break; |
1046 | break; |
1053 | |
1047 | |
1054 | if (other_weap == NULL) /* No other weapons */ |
1048 | if (!other_weap) /* No other weapons */ |
1055 | return 1; |
1049 | return 1; |
1056 | |
1050 | |
1057 | /* Rather than go through and apply the new one, and see if it is |
1051 | /* Rather than go through and apply the new one, and see if it is |
1058 | * better, just do some simple checks |
1052 | * better, just do some simple checks |
1059 | * Put some multipliers for things that hvae several effects, |
1053 | * Put some multipliers for things that hvae several effects, |
… | |
… | |
1064 | val += (item->magic - other_weap->magic) * 3; |
1058 | val += (item->magic - other_weap->magic) * 3; |
1065 | /* Monsters don't really get benefits from things like regen rates |
1059 | /* Monsters don't really get benefits from things like regen rates |
1066 | * from items. But the bonus for their stats are very important. |
1060 | * from items. But the bonus for their stats are very important. |
1067 | */ |
1061 | */ |
1068 | for (i = 0; i < NUM_STATS; i++) |
1062 | for (i = 0; i < NUM_STATS; i++) |
1069 | val += (get_attr_value (&item->stats, i) - get_attr_value (&other_weap->stats, i)) * 2; |
1063 | val += item->stats.stat (i) - other_weap->stats.stat (i) * 2; |
1070 | |
1064 | |
1071 | if (val > 0) |
1065 | if (val > 0) |
1072 | return 1; |
1066 | return 1; |
1073 | else |
1067 | else |
1074 | return 0; |
1068 | return 0; |
1075 | |
|
|
1076 | } |
1069 | } |
1077 | |
1070 | |
1078 | int |
1071 | int |
1079 | check_good_armour (object *who, object *item) |
1072 | check_good_armour (object *who, object *item) |
1080 | { |
1073 | { |
1081 | object *other_armour; |
1074 | object *other_armour; |
1082 | int val = 0, i; |
1075 | int val = 0, i; |
1083 | |
1076 | |
1084 | for (other_armour = who->inv; other_armour != NULL; other_armour = other_armour->below) |
1077 | 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)) |
1078 | if (other_armour->type == item->type && QUERY_FLAG (other_armour, FLAG_APPLIED)) |
1086 | break; |
1079 | break; |
1087 | |
1080 | |
1088 | if (other_armour == NULL) /* No other armour, use the new */ |
1081 | if (other_armour == NULL) /* No other armour, use the new */ |
1089 | return 1; |
1082 | return 1; |
… | |
… | |
1111 | |
1104 | |
1112 | if (val > 0) |
1105 | if (val > 0) |
1113 | return 1; |
1106 | return 1; |
1114 | else |
1107 | else |
1115 | return 0; |
1108 | return 0; |
1116 | |
|
|
1117 | } |
1109 | } |
1118 | |
1110 | |
1119 | /* |
1111 | /* |
1120 | * monster_check_pickup(): checks for items that monster can pick up. |
1112 | * monster_check_pickup(): checks for items that monster can pick up. |
1121 | * |
1113 | * |
… | |
… | |
1129 | * This function was seen be continueing looping at one point (tmp->below |
1121 | * 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 |
1122 | * 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 |
1123 | * after we pick everything up, since that function may call others which |
1132 | * affect stacking on this space. |
1124 | * affect stacking on this space. |
1133 | */ |
1125 | */ |
1134 | |
|
|
1135 | void |
1126 | void |
1136 | monster_check_pickup (object *monster) |
1127 | monster_check_pickup (object *monster) |
1137 | { |
1128 | { |
1138 | object *tmp, *next; |
1129 | object *tmp, *next; |
1139 | |
1130 | |
… | |
… | |
1158 | * monster_can_pick(): If the monster is interested in picking up |
1149 | * monster_can_pick(): If the monster is interested in picking up |
1159 | * the item, then return 0. Otherwise 0. |
1150 | * the item, then return 0. Otherwise 0. |
1160 | * Instead of pick_up, flags for "greed", etc, should be used. |
1151 | * Instead of pick_up, flags for "greed", etc, should be used. |
1161 | * I've already utilized flags for bows, wands, rings, etc, etc. -Frank. |
1152 | * I've already utilized flags for bows, wands, rings, etc, etc. -Frank. |
1162 | */ |
1153 | */ |
1163 | |
|
|
1164 | int |
1154 | int |
1165 | monster_can_pick (object *monster, object *item) |
1155 | monster_can_pick (object *monster, object *item) |
1166 | { |
1156 | { |
1167 | int flag = 0; |
1157 | int flag = 0; |
1168 | int i; |
1158 | int i; |
… | |
… | |
1214 | case ROD: |
1204 | case ROD: |
1215 | flag = QUERY_FLAG (monster, FLAG_USE_RANGE); |
1205 | flag = QUERY_FLAG (monster, FLAG_USE_RANGE); |
1216 | break; |
1206 | break; |
1217 | |
1207 | |
1218 | case SPELLBOOK: |
1208 | case SPELLBOOK: |
1219 | flag = (monster->arch != NULL && QUERY_FLAG ((&monster->arch->clone), FLAG_CAST_SPELL)); |
1209 | flag = monster->arch && QUERY_FLAG (monster->arch, FLAG_CAST_SPELL); |
1220 | break; |
1210 | break; |
1221 | |
1211 | |
1222 | case SCROLL: |
1212 | case SCROLL: |
1223 | flag = QUERY_FLAG (monster, FLAG_USE_SCROLL); |
1213 | flag = QUERY_FLAG (monster, FLAG_USE_SCROLL); |
1224 | break; |
1214 | break; |
… | |
… | |
1226 | case BOW: |
1216 | case BOW: |
1227 | case ARROW: |
1217 | case ARROW: |
1228 | flag = QUERY_FLAG (monster, FLAG_USE_BOW); |
1218 | flag = QUERY_FLAG (monster, FLAG_USE_BOW); |
1229 | break; |
1219 | break; |
1230 | } |
1220 | } |
|
|
1221 | |
1231 | /* Simplistic check - if the monster has a location to equip it, he will |
1222 | /* 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 |
1223 | * pick it up. Note that this doesn't handle cases where an item may |
1233 | * use several locations. |
1224 | * use several locations. |
1234 | */ |
1225 | */ |
1235 | for (i = 0; i < NUM_BODY_LOCATIONS; i++) |
1226 | for (i = 0; i < NUM_BODY_LOCATIONS; i++) |
1236 | { |
1227 | { |
1237 | if (monster->body_info[i] && item->body_info[i]) |
1228 | if (monster->slot[i].info && item->slot[i].info) |
1238 | { |
1229 | { |
1239 | flag = 1; |
1230 | flag = 1; |
1240 | break; |
1231 | break; |
1241 | } |
1232 | } |
1242 | } |
1233 | } |
… | |
… | |
1250 | * monster_apply_below(): |
1241 | * monster_apply_below(): |
1251 | * Vick's (vick@bern.docs.uu.se) @921107 -> If a monster who's |
1242 | * Vick's (vick@bern.docs.uu.se) @921107 -> If a monster who's |
1252 | * eager to apply things, encounters something apply-able, |
1243 | * eager to apply things, encounters something apply-able, |
1253 | * then make him apply it |
1244 | * then make him apply it |
1254 | */ |
1245 | */ |
1255 | |
|
|
1256 | void |
1246 | void |
1257 | monster_apply_below (object *monster) |
1247 | monster_apply_below (object *monster) |
1258 | { |
1248 | { |
1259 | object *tmp, *next; |
1249 | object *tmp, *next; |
1260 | |
1250 | |
… | |
… | |
1287 | * a pointer to that object is returned, so it can be dropped. |
1277 | * a pointer to that object is returned, so it can be dropped. |
1288 | * (so that other monsters can pick it up and use it) |
1278 | * (so that other monsters can pick it up and use it) |
1289 | * Note that as things are now, monsters never drop something - |
1279 | * Note that as things are now, monsters never drop something - |
1290 | * they can pick up all that they can use. |
1280 | * they can pick up all that they can use. |
1291 | */ |
1281 | */ |
1292 | |
|
|
1293 | /* Sept 96, fixed this so skills will be readied -b.t.*/ |
1282 | /* Sept 96, fixed this so skills will be readied -b.t.*/ |
1294 | |
|
|
1295 | void |
1283 | void |
1296 | monster_check_apply (object *mon, object *item) |
1284 | monster_check_apply (object *mon, object *item) |
1297 | { |
1285 | { |
1298 | |
|
|
1299 | int flag = 0; |
1286 | int flag = 0; |
1300 | |
1287 | |
1301 | if (item->type == SPELLBOOK && mon->arch != NULL && (QUERY_FLAG ((&mon->arch->clone), FLAG_CAST_SPELL))) |
1288 | if (item->type == SPELLBOOK && mon->arch && (QUERY_FLAG (mon->arch, FLAG_CAST_SPELL))) |
1302 | { |
1289 | { |
1303 | SET_FLAG (mon, FLAG_CAST_SPELL); |
1290 | SET_FLAG (mon, FLAG_CAST_SPELL); |
1304 | return; |
1291 | return; |
1305 | } |
1292 | } |
1306 | |
1293 | |
… | |
… | |
1315 | if (QUERY_FLAG (mon, FLAG_USE_BOW) && item->type == ARROW) |
1302 | if (QUERY_FLAG (mon, FLAG_USE_BOW) && item->type == ARROW) |
1316 | { |
1303 | { |
1317 | /* Check for the right kind of bow */ |
1304 | /* Check for the right kind of bow */ |
1318 | object *bow; |
1305 | object *bow; |
1319 | |
1306 | |
1320 | for (bow = mon->inv; bow != NULL; bow = bow->below) |
1307 | for (bow = mon->inv; bow; bow = bow->below) |
1321 | if (bow->type == BOW && bow->race == item->race) |
1308 | if (bow->type == BOW && bow->race == item->race) |
1322 | { |
1309 | { |
1323 | SET_FLAG (mon, FLAG_READY_BOW); |
1310 | SET_FLAG (mon, FLAG_READY_BOW); |
1324 | LOG (llevMonster, "Found correct bow for arrows.\n"); |
1311 | LOG (llevMonster, "Found correct bow for arrows.\n"); |
1325 | return; /* nothing more to do for arrows */ |
1312 | return; /* nothing more to do for arrows */ |
… | |
… | |
1377 | */ |
1364 | */ |
1378 | SET_FLAG (mon, FLAG_READY_SKILL); |
1365 | SET_FLAG (mon, FLAG_READY_SKILL); |
1379 | return; |
1366 | return; |
1380 | } |
1367 | } |
1381 | |
1368 | |
1382 | |
|
|
1383 | /* if we don't match one of the above types, return now. |
1369 | /* 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, |
1370 | * can_apply_object will say that we can apply things like flesh, |
1385 | * bolts, and whatever else, because it only checks against the |
1371 | * bolts, and whatever else, because it only checks against the |
1386 | * body_info locations. |
1372 | * body_info locations. |
1387 | */ |
1373 | */ |
… | |
… | |
1398 | /* should only be applying this item, not unapplying it. |
1384 | /* should only be applying this item, not unapplying it. |
1399 | * also, ignore status of curse so they can take off old armour. |
1385 | * also, ignore status of curse so they can take off old armour. |
1400 | * monsters have some advantages after all. |
1386 | * monsters have some advantages after all. |
1401 | */ |
1387 | */ |
1402 | manual_apply (mon, item, AP_APPLY | AP_IGNORE_CURSE); |
1388 | manual_apply (mon, item, AP_APPLY | AP_IGNORE_CURSE); |
1403 | |
|
|
1404 | return; |
|
|
1405 | } |
1389 | } |
1406 | |
1390 | |
1407 | void |
1391 | void |
1408 | npc_call_help (object *op) |
1392 | npc_call_help (object *op) |
1409 | { |
1393 | { |
… | |
… | |
1427 | if (QUERY_FLAG (npc, FLAG_ALIVE) && QUERY_FLAG (npc, FLAG_UNAGGRESSIVE)) |
1411 | if (QUERY_FLAG (npc, FLAG_ALIVE) && QUERY_FLAG (npc, FLAG_UNAGGRESSIVE)) |
1428 | npc->enemy = op->enemy; |
1412 | npc->enemy = op->enemy; |
1429 | } |
1413 | } |
1430 | } |
1414 | } |
1431 | |
1415 | |
1432 | |
|
|
1433 | int |
1416 | int |
1434 | dist_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1417 | dist_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1435 | { |
1418 | { |
1436 | |
|
|
1437 | if (can_hit (part, enemy, rv)) |
1419 | if (can_hit (part, enemy, rv)) |
1438 | return dir; |
1420 | return dir; |
1439 | if (rv->distance < 10) |
1421 | if (rv->distance < 10) |
1440 | return absdir (dir + 4); |
1422 | return absdir (dir + 4); |
1441 | else if (rv->distance > 18) |
1423 | else if (rv->distance > 18) |
1442 | return dir; |
1424 | return dir; |
|
|
1425 | |
1443 | return 0; |
1426 | return 0; |
1444 | } |
1427 | } |
1445 | |
1428 | |
1446 | int |
1429 | int |
1447 | run_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1430 | run_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1448 | { |
1431 | { |
1449 | |
|
|
1450 | if ((can_hit (part, enemy, rv) && ob->move_status < 20) || ob->move_status < 20) |
1432 | if ((can_hit (part, enemy, rv) && ob->move_status < 20) || ob->move_status < 20) |
1451 | { |
1433 | { |
1452 | ob->move_status++; |
1434 | ob->move_status++; |
1453 | return (dir); |
1435 | return (dir); |
1454 | } |
1436 | } |
1455 | else if (ob->move_status > 20) |
1437 | else if (ob->move_status > 20) |
1456 | ob->move_status = 0; |
1438 | ob->move_status = 0; |
|
|
1439 | |
1457 | return absdir (dir + 4); |
1440 | return absdir (dir + 4); |
1458 | } |
1441 | } |
1459 | |
1442 | |
1460 | int |
1443 | int |
1461 | hitrun_att (int dir, object *ob, object *enemy) |
1444 | hitrun_att (int dir, object *ob, object *enemy) |
… | |
… | |
1464 | return dir; |
1447 | return dir; |
1465 | else if (ob->move_status < 50) |
1448 | else if (ob->move_status < 50) |
1466 | return absdir (dir + 4); |
1449 | return absdir (dir + 4); |
1467 | else |
1450 | else |
1468 | ob->move_status = 0; |
1451 | ob->move_status = 0; |
|
|
1452 | |
1469 | return absdir (dir + 4); |
1453 | return absdir (dir + 4); |
1470 | } |
1454 | } |
1471 | |
1455 | |
1472 | int |
1456 | int |
1473 | wait_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1457 | wait_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
… | |
… | |
1482 | return 0; |
1466 | return 0; |
1483 | else if (ob->move_status < 10) |
1467 | else if (ob->move_status < 10) |
1484 | return dir; |
1468 | return dir; |
1485 | else if (ob->move_status < 15) |
1469 | else if (ob->move_status < 15) |
1486 | return absdir (dir + 4); |
1470 | return absdir (dir + 4); |
|
|
1471 | |
1487 | ob->move_status = 0; |
1472 | ob->move_status = 0; |
1488 | return 0; |
1473 | return 0; |
1489 | } |
1474 | } |
1490 | |
1475 | |
1491 | int |
1476 | int |
… | |
… | |
1499 | * at least one map has this set, and whatever the map contains, the |
1484 | * 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 |
1485 | * server should try to be resilant enough to avoid the problem |
1501 | */ |
1486 | */ |
1502 | if (ob->stats.maxhp && (ob->stats.hp * 100) / ob->stats.maxhp < ob->run_away) |
1487 | if (ob->stats.maxhp && (ob->stats.hp * 100) / ob->stats.maxhp < ob->run_away) |
1503 | return absdir (dir + 4); |
1488 | return absdir (dir + 4); |
|
|
1489 | |
1504 | return dist_att (dir, ob, enemy, part, rv); |
1490 | return dist_att (dir, ob, enemy, part, rv); |
1505 | } |
1491 | } |
1506 | |
1492 | |
1507 | int |
1493 | int |
1508 | wait_att2 (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1494 | wait_att2 (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1509 | { |
1495 | { |
1510 | if (rv->distance < 9) |
1496 | if (rv->distance < 9) |
1511 | return absdir (dir + 4); |
1497 | return absdir (dir + 4); |
|
|
1498 | |
1512 | return 0; |
1499 | return 0; |
1513 | } |
1500 | } |
1514 | |
1501 | |
1515 | void |
1502 | void |
1516 | circ1_move (object *ob) |
1503 | circ1_move (object *ob) |
1517 | { |
1504 | { |
1518 | static int circle[12] = { 3, 3, 4, 5, 5, 6, 7, 7, 8, 1, 1, 2 }; |
1505 | static int circle[12] = { 3, 3, 4, 5, 5, 6, 7, 7, 8, 1, 1, 2 }; |
|
|
1506 | |
1519 | if (++ob->move_status > 11) |
1507 | if (++ob->move_status > 11) |
1520 | ob->move_status = 0; |
1508 | ob->move_status = 0; |
|
|
1509 | |
1521 | if (!(move_object (ob, circle[ob->move_status]))) |
1510 | if (!(move_object (ob, circle[ob->move_status]))) |
1522 | (void) move_object (ob, RANDOM () % 8 + 1); |
1511 | move_object (ob, rndm (8) + 1); |
1523 | } |
1512 | } |
1524 | |
1513 | |
1525 | void |
1514 | void |
1526 | circ2_move (object *ob) |
1515 | circ2_move (object *ob) |
1527 | { |
1516 | { |
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 }; |
1517 | 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 | |
1529 | if (++ob->move_status > 19) |
1519 | if (++ob->move_status > 19) |
1530 | ob->move_status = 0; |
1520 | ob->move_status = 0; |
|
|
1521 | |
1531 | if (!(move_object (ob, circle[ob->move_status]))) |
1522 | if (!(move_object (ob, circle[ob->move_status]))) |
1532 | (void) move_object (ob, RANDOM () % 8 + 1); |
1523 | move_object (ob, rndm (8) + 1); |
1533 | } |
1524 | } |
1534 | |
1525 | |
1535 | void |
1526 | void |
1536 | pace_movev (object *ob) |
1527 | pace_movev (object *ob) |
1537 | { |
1528 | { |
1538 | if (ob->move_status++ > 6) |
1529 | if (ob->move_status++ > 6) |
1539 | ob->move_status = 0; |
1530 | ob->move_status = 0; |
|
|
1531 | |
1540 | if (ob->move_status < 4) |
1532 | if (ob->move_status < 4) |
1541 | (void) move_object (ob, 5); |
1533 | move_object (ob, 5); |
1542 | else |
1534 | else |
1543 | (void) move_object (ob, 1); |
1535 | move_object (ob, 1); |
1544 | } |
1536 | } |
1545 | |
1537 | |
1546 | void |
1538 | void |
1547 | pace_moveh (object *ob) |
1539 | pace_moveh (object *ob) |
1548 | { |
1540 | { |
1549 | if (ob->move_status++ > 6) |
1541 | if (ob->move_status++ > 6) |
1550 | ob->move_status = 0; |
1542 | ob->move_status = 0; |
|
|
1543 | |
1551 | if (ob->move_status < 4) |
1544 | if (ob->move_status < 4) |
1552 | (void) move_object (ob, 3); |
1545 | move_object (ob, 3); |
1553 | else |
1546 | else |
1554 | (void) move_object (ob, 7); |
1547 | move_object (ob, 7); |
1555 | } |
1548 | } |
1556 | |
1549 | |
1557 | void |
1550 | void |
1558 | pace2_movev (object *ob) |
1551 | pace2_movev (object *ob) |
1559 | { |
1552 | { |
1560 | if (ob->move_status++ > 16) |
1553 | if (ob->move_status++ > 16) |
1561 | ob->move_status = 0; |
1554 | ob->move_status = 0; |
|
|
1555 | |
1562 | if (ob->move_status < 6) |
1556 | if (ob->move_status < 6) |
1563 | (void) move_object (ob, 5); |
1557 | move_object (ob, 5); |
1564 | else if (ob->move_status < 8) |
1558 | else if (ob->move_status < 8) |
1565 | return; |
1559 | return; |
1566 | else if (ob->move_status < 13) |
1560 | else if (ob->move_status < 13) |
1567 | (void) move_object (ob, 1); |
1561 | move_object (ob, 1); |
1568 | else |
1562 | else |
1569 | return; |
1563 | return; |
1570 | } |
1564 | } |
1571 | |
1565 | |
1572 | void |
1566 | void |
1573 | pace2_moveh (object *ob) |
1567 | pace2_moveh (object *ob) |
1574 | { |
1568 | { |
1575 | if (ob->move_status++ > 16) |
1569 | if (ob->move_status++ > 16) |
1576 | ob->move_status = 0; |
1570 | ob->move_status = 0; |
|
|
1571 | |
1577 | if (ob->move_status < 6) |
1572 | if (ob->move_status < 6) |
1578 | (void) move_object (ob, 3); |
1573 | move_object (ob, 3); |
1579 | else if (ob->move_status < 8) |
1574 | else if (ob->move_status < 8) |
1580 | return; |
1575 | return; |
1581 | else if (ob->move_status < 13) |
1576 | else if (ob->move_status < 13) |
1582 | (void) move_object (ob, 7); |
1577 | move_object (ob, 7); |
1583 | else |
1578 | else |
1584 | return; |
1579 | return; |
1585 | } |
1580 | } |
1586 | |
1581 | |
1587 | void |
1582 | void |
1588 | rand_move (object *ob) |
1583 | rand_move (object *ob) |
1589 | { |
1584 | { |
1590 | int i; |
1585 | int i; |
1591 | |
1586 | |
1592 | if (ob->move_status < 1 || ob->move_status > 8 || !(move_object (ob, ob->move_status || !(RANDOM () % 9)))) |
1587 | if (ob->move_status < 1 || ob->move_status > 8 || !(move_object (ob, ob->move_status || !(rndm (9))))) |
1593 | for (i = 0; i < 5; i++) |
1588 | for (i = 0; i < 5; i++) |
1594 | if (move_object (ob, ob->move_status = RANDOM () % 8 + 1)) |
1589 | if (move_object (ob, ob->move_status = rndm (8) + 1)) |
1595 | return; |
1590 | return; |
1596 | } |
1591 | } |
1597 | |
1592 | |
1598 | void |
1593 | void |
1599 | check_earthwalls (object *op, maptile *m, int x, int y) |
1594 | check_earthwalls (object *op, maptile *m, int x, int y) |
… | |
… | |
1630 | * monsters to throw things like chairs and other pieces of |
1625 | * monsters to throw things like chairs and other pieces of |
1631 | * furniture, even if they are not good throwable objects. |
1626 | * furniture, even if they are not good throwable objects. |
1632 | * Probably better to have the monster throw a throwable object |
1627 | * Probably better to have the monster throw a throwable object |
1633 | * first, then throw any non equipped weapon. |
1628 | * first, then throw any non equipped weapon. |
1634 | */ |
1629 | */ |
1635 | |
|
|
1636 | object * |
1630 | object * |
1637 | find_mon_throw_ob (object *op) |
1631 | find_mon_throw_ob (object *op) |
1638 | { |
1632 | { |
1639 | object *tmp = NULL; |
1633 | object *tmp = NULL; |
1640 | |
1634 | |
… | |
… | |
1644 | tmp = op; |
1638 | tmp = op; |
1645 | |
1639 | |
1646 | /* New throw code: look through the inventory. Grap the first legal is_thrown |
1640 | /* New throw code: look through the inventory. Grap the first legal is_thrown |
1647 | * marked item and throw it to the enemy. |
1641 | * marked item and throw it to the enemy. |
1648 | */ |
1642 | */ |
1649 | |
|
|
1650 | for (tmp = op->inv; tmp; tmp = tmp->below) |
1643 | for (tmp = op->inv; tmp; tmp = tmp->below) |
1651 | { |
1644 | { |
1652 | |
|
|
1653 | /* Can't throw invisible objects or items that are applied */ |
1645 | /* Can't throw invisible objects or items that are applied */ |
1654 | if (tmp->invisible || QUERY_FLAG (tmp, FLAG_APPLIED)) |
1646 | if (tmp->invisible || QUERY_FLAG (tmp, FLAG_APPLIED)) |
1655 | continue; |
1647 | continue; |
1656 | |
1648 | |
1657 | if (QUERY_FLAG (tmp, FLAG_IS_THROWN)) |
1649 | if (QUERY_FLAG (tmp, FLAG_IS_THROWN)) |
… | |
… | |
1780 | /* ah, we are within range, detected? take cases */ |
1772 | /* ah, we are within range, detected? take cases */ |
1781 | if (!enemy->invisible) /* enemy in dark squares... are seen! */ |
1773 | if (!enemy->invisible) /* enemy in dark squares... are seen! */ |
1782 | return 1; |
1774 | return 1; |
1783 | |
1775 | |
1784 | /* hidden or low-quality invisible */ |
1776 | /* hidden or low-quality invisible */ |
1785 | if (enemy->hide && (rv->distance <= 1) && (RANDOM () % 100 <= hide_discovery)) |
1777 | if (enemy->hide && (rv->distance <= 1) && (rndm (100) <= hide_discovery)) |
1786 | { |
1778 | { |
1787 | make_visible (enemy); |
1779 | make_visible (enemy); |
1788 | /* inform players of new status */ |
1780 | /* inform players of new status */ |
1789 | if (enemy->type == PLAYER && player_can_view (enemy, op)) |
1781 | if (enemy->type == PLAYER && player_can_view (enemy, op)) |
1790 | new_draw_info_format (NDI_UNIQUE, 0, enemy, "You are discovered by %s!", &op->name); |
1782 | new_draw_info_format (NDI_UNIQUE, 0, enemy, "You are discovered by %s!", &op->name); |
… | |
… | |
1797 | * do something to you. Decreasing the duration of invisible |
1789 | * do something to you. Decreasing the duration of invisible |
1798 | * doesn't make a lot of sense IMO, as a bunch of stupid creatures |
1790 | * doesn't make a lot of sense IMO, as a bunch of stupid creatures |
1799 | * can then basically negate the spell. The spell isn't negated - |
1791 | * can then basically negate the spell. The spell isn't negated - |
1800 | * they just know where you are! |
1792 | * they just know where you are! |
1801 | */ |
1793 | */ |
1802 | if ((RANDOM () % 50) <= hide_discovery) |
1794 | if ((rndm (50)) <= hide_discovery) |
1803 | { |
1795 | { |
1804 | if (enemy->type == PLAYER) |
1796 | if (enemy->type == PLAYER) |
1805 | { |
1797 | { |
1806 | new_draw_info_format (NDI_UNIQUE, 0, enemy, "You see %s noticing your position.", query_name (op)); |
1798 | new_draw_info_format (NDI_UNIQUE, 0, enemy, "You see %s noticing your position.", query_name (op)); |
1807 | } |
1799 | } |
… | |
… | |
1817 | /* determine if op stands in a lighted square. This is not a very |
1809 | /* determine if op stands in a lighted square. This is not a very |
1818 | * intellegent algorithm. For one thing, we ignore los here, SO it |
1810 | * intellegent algorithm. For one thing, we ignore los here, SO it |
1819 | * is possible for a bright light to illuminate a player on the |
1811 | * is possible for a bright light to illuminate a player on the |
1820 | * other side of a wall (!). |
1812 | * other side of a wall (!). |
1821 | */ |
1813 | */ |
1822 | |
|
|
1823 | int |
1814 | int |
1824 | stand_in_light (object *op) |
1815 | stand_in_light (object *op) |
1825 | { |
1816 | { |
1826 | sint16 nx, ny; |
1817 | sint16 nx, ny; |
1827 | maptile *m; |
1818 | maptile *m; |
1828 | |
1819 | |
1829 | |
|
|
1830 | if (!op) |
1820 | if (!op) |
1831 | return 0; |
1821 | return 0; |
|
|
1822 | |
1832 | if (op->glow_radius > 0) |
1823 | if (op->glow_radius > 0) |
1833 | return 1; |
1824 | return 1; |
1834 | |
1825 | |
1835 | if (op->map) |
1826 | if (op->map) |
1836 | { |
1827 | { |
1837 | int x, y, x1, y1; |
1828 | int x, y, x1, y1; |
1838 | |
|
|
1839 | |
|
|
1840 | |
1829 | |
1841 | /* Check the spaces with the max light radius to see if any of them |
1830 | /* Check the spaces with the max light radius to see if any of them |
1842 | * have lights, and if any of them light the player enough, then return 1. |
1831 | * have lights, and if any of them light the player enough, then return 1. |
1843 | */ |
1832 | */ |
1844 | for (x = op->x - MAX_LIGHT_RADII; x <= op->x + MAX_LIGHT_RADII; x++) |
1833 | for (x = op->x - MAX_LIGHT_RADII; x <= op->x + MAX_LIGHT_RADII; x++) |
… | |
… | |
1857 | if (isqrt (x1 + y1) < GET_MAP_LIGHT (m, nx, ny)) |
1846 | if (isqrt (x1 + y1) < GET_MAP_LIGHT (m, nx, ny)) |
1858 | return 1; |
1847 | return 1; |
1859 | } |
1848 | } |
1860 | } |
1849 | } |
1861 | } |
1850 | } |
|
|
1851 | |
1862 | return 0; |
1852 | return 0; |
1863 | } |
1853 | } |
1864 | |
|
|
1865 | |
1854 | |
1866 | /* assuming no walls/barriers, lets check to see if its *possible* |
1855 | /* assuming no walls/barriers, lets check to see if its *possible* |
1867 | * to see an enemy. Note, "detection" is different from "seeing". |
1856 | * to see an enemy. Note, "detection" is different from "seeing". |
1868 | * See can_detect_enemy() for more details. -b.t. |
1857 | * See can_detect_enemy() for more details. -b.t. |
1869 | * return 0 if can't be seen, 1 if can be |
1858 | * return 0 if can't be seen, 1 if can be |
1870 | */ |
1859 | */ |
1871 | |
|
|
1872 | int |
1860 | int |
1873 | can_see_enemy (object *op, object *enemy) |
1861 | can_see_enemy (object *op, object *enemy) |
1874 | { |
1862 | { |
1875 | object *looker = op->head ? op->head : op; |
1863 | object *looker = op->head ? op->head : op; |
1876 | |
1864 | |