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 (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | |
7 | * |
7 | This program is free software; you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify |
8 | 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 |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | (at your option) any later version. |
11 | * (at your option) any later version. |
11 | |
12 | * |
12 | 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, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
16 | |
17 | * |
17 | 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 |
18 | along with this program; if not, write to the Free Software |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * |
20 | |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
|
|
22 | */ |
22 | */ |
23 | |
23 | |
24 | #include <global.h> |
24 | #include <global.h> |
25 | #ifndef __CEXTRACT__ |
|
|
26 | # include <sproto.h> |
25 | #include <sproto.h> |
27 | # include <spells.h> |
26 | #include <spells.h> |
28 | # include <skills.h> |
27 | #include <skills.h> |
29 | #endif |
|
|
30 | |
|
|
31 | |
28 | |
32 | #define MIN_MON_RADIUS 3 /* minimum monster detection radius */ |
29 | #define MIN_MON_RADIUS 3 /* minimum monster detection radius */ |
33 | |
|
|
34 | |
30 | |
35 | /* checks npc->enemy and returns that enemy if still valid, |
31 | /* checks npc->enemy and returns that enemy if still valid, |
36 | * NULL otherwise. |
32 | * NULL otherwise. |
37 | * this is map tile aware. |
33 | * this is map tile aware. |
38 | * If this returns an enemy, the range vector rv should also be |
34 | * If this returns an enemy, the range vector rv should also be |
… | |
… | |
88 | * target enemy - this code below makes sure the enemy is something |
84 | * target enemy - this code below makes sure the enemy is something |
89 | * that should be attacked. My guess is that the arrow hits |
85 | * that should be attacked. My guess is that the arrow hits |
90 | * the creature/owner, and so the creature then takes that |
86 | * the creature/owner, and so the creature then takes that |
91 | * as the enemy to attack. |
87 | * as the enemy to attack. |
92 | */ |
88 | */ |
93 | else if (!QUERY_FLAG (npc->enemy, FLAG_MONSTER) && |
89 | else if (!QUERY_FLAG (npc->enemy, FLAG_MONSTER) |
94 | !QUERY_FLAG (npc->enemy, FLAG_GENERATOR) && npc->enemy->type != PLAYER && npc->enemy->type != GOLEM) |
90 | && !QUERY_FLAG (npc->enemy, FLAG_GENERATOR) |
|
|
91 | && npc->enemy->type != PLAYER |
|
|
92 | && npc->enemy->type != GOLEM) |
95 | npc->enemy = NULL; |
93 | npc->enemy = NULL; |
96 | |
94 | |
97 | } |
95 | } |
|
|
96 | |
98 | return can_detect_enemy (npc, npc->enemy, rv) ? npc->enemy : NULL; |
97 | return can_detect_enemy (npc, npc->enemy, rv) ? npc->enemy : NULL; |
99 | } |
98 | } |
100 | |
99 | |
101 | /* Returns the nearest living creature (monster or generator). |
100 | /* Returns the nearest living creature (monster or generator). |
102 | * Modified to deal with tiled maps properly. |
101 | * Modified to deal with tiled maps properly. |
… | |
… | |
116 | find_nearest_living_creature (object *npc) |
115 | find_nearest_living_creature (object *npc) |
117 | { |
116 | { |
118 | int i, mflags; |
117 | int i, mflags; |
119 | sint16 nx, ny; |
118 | sint16 nx, ny; |
120 | maptile *m; |
119 | maptile *m; |
121 | object *tmp; |
|
|
122 | int search_arr[SIZEOFFREE]; |
120 | int search_arr[SIZEOFFREE]; |
123 | |
121 | |
124 | get_search_arr (search_arr); |
122 | get_search_arr (search_arr); |
|
|
123 | |
125 | for (i = 0; i < SIZEOFFREE; i++) |
124 | for (i = 0; i < SIZEOFFREE; i++) |
126 | { |
125 | { |
127 | /* modified to implement smart searching using search_arr |
126 | /* modified to implement smart searching using search_arr |
128 | * guidance array to determine direction of search order |
127 | * guidance array to determine direction of search order |
129 | */ |
128 | */ |
130 | nx = npc->x + freearr_x[search_arr[i]]; |
129 | nx = npc->x + freearr_x[search_arr[i]]; |
131 | ny = npc->y + freearr_y[search_arr[i]]; |
130 | ny = npc->y + freearr_y[search_arr[i]]; |
132 | m = npc->map; |
131 | m = npc->map; |
133 | |
132 | |
134 | mflags = get_map_flags (m, &m, nx, ny, &nx, &ny); |
133 | mflags = get_map_flags (m, &m, nx, ny, &nx, &ny); |
|
|
134 | |
135 | if (mflags & P_OUT_OF_MAP) |
135 | if (mflags & P_OUT_OF_MAP) |
136 | continue; |
136 | continue; |
137 | |
137 | |
138 | if (mflags & P_IS_ALIVE) |
138 | if (mflags & P_IS_ALIVE) |
139 | { |
139 | { |
140 | tmp = get_map_ob (m, nx, ny); |
140 | for (object *tmp = m->at (nx, ny).top; tmp; tmp = tmp->below) |
141 | while (tmp != NULL && !QUERY_FLAG (tmp, FLAG_MONSTER) && !QUERY_FLAG (tmp, FLAG_GENERATOR) && tmp->type != PLAYER) |
141 | if (tmp->flag [FLAG_MONSTER] || tmp->flag [FLAG_GENERATOR] || tmp->type == PLAYER) |
142 | tmp = tmp->above; |
|
|
143 | |
|
|
144 | if (!tmp) |
|
|
145 | { |
|
|
146 | LOG (llevDebug, "find_nearest_living_creature: map %s (%d,%d) has is_alive set but did not find a monster?\n", |
|
|
147 | m->path, nx, ny); |
|
|
148 | } |
|
|
149 | else |
|
|
150 | { |
|
|
151 | if (can_see_monsterP (m, nx, ny, i)) |
142 | if (can_see_monsterP (m, nx, ny, i)) |
152 | return tmp; |
143 | return tmp; |
153 | } |
144 | } |
154 | } /* is something living on this space */ |
|
|
155 | } |
145 | } |
156 | return NULL; /* nothing found */ |
|
|
157 | } |
|
|
158 | |
146 | |
|
|
147 | return 0; |
|
|
148 | } |
159 | |
149 | |
160 | /* 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 |
161 | * our caller will find the information useful. |
151 | * our caller will find the information useful. |
162 | * Currently, only move_monster calls this function. |
152 | * Currently, only move_monster calls this function. |
163 | * Fix function so that we always make calls to get_rangevector |
153 | * Fix function so that we always make calls to get_rangevector |
164 | * 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 |
165 | * many cases. |
155 | * many cases. |
166 | */ |
156 | */ |
167 | |
|
|
168 | object * |
157 | object * |
169 | find_enemy (object *npc, rv_vector * rv) |
158 | find_enemy (object *npc, rv_vector * rv) |
170 | { |
159 | { |
171 | object *attacker, *tmp = NULL; |
160 | object *attacker, *tmp = NULL; |
172 | |
161 | |
… | |
… | |
178 | { |
167 | { |
179 | tmp = find_nearest_living_creature (npc); |
168 | tmp = find_nearest_living_creature (npc); |
180 | |
169 | |
181 | if (tmp) |
170 | if (tmp) |
182 | get_rangevector (npc, tmp, rv, 0); |
171 | get_rangevector (npc, tmp, rv, 0); |
|
|
172 | |
183 | return tmp; |
173 | return tmp; |
184 | } |
174 | } |
185 | |
175 | |
186 | /* Here is the main enemy selection. |
176 | /* Here is the main enemy selection. |
187 | * 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 |
… | |
… | |
240 | /* Sees if this monster should wake up. |
230 | /* Sees if this monster should wake up. |
241 | * Currently, this is only called from move_monster, and |
231 | * Currently, this is only called from move_monster, and |
242 | * if enemy is set, then so should be rv. |
232 | * if enemy is set, then so should be rv. |
243 | * returns 1 if the monster should wake up, 0 otherwise. |
233 | * returns 1 if the monster should wake up, 0 otherwise. |
244 | */ |
234 | */ |
245 | |
|
|
246 | int |
235 | int |
247 | check_wakeup (object *op, object *enemy, rv_vector * rv) |
236 | check_wakeup (object *op, object *enemy, rv_vector * rv) |
248 | { |
237 | { |
249 | 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; |
250 | |
239 | |
… | |
… | |
289 | int i; |
278 | int i; |
290 | |
279 | |
291 | /* Give up to 15 chances for a monster to move randomly */ |
280 | /* Give up to 15 chances for a monster to move randomly */ |
292 | for (i = 0; i < 15; i++) |
281 | for (i = 0; i < 15; i++) |
293 | { |
282 | { |
294 | if (move_object (op, RANDOM () % 8 + 1)) |
283 | if (move_object (op, rndm (8) + 1)) |
295 | return 1; |
284 | return 1; |
296 | } |
285 | } |
297 | return 0; |
286 | return 0; |
298 | } |
287 | } |
299 | |
288 | |
300 | /* |
289 | /* |
301 | * 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. |
302 | */ |
291 | */ |
303 | |
|
|
304 | int |
292 | int |
305 | move_monster (object *op) |
293 | move_monster (object *op) |
306 | { |
294 | { |
307 | 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 */ |
308 | object *owner, *enemy, *part, *oph = op; |
296 | object *owner, *enemy, *part, *oph = op; |
… | |
… | |
368 | } |
356 | } |
369 | |
357 | |
370 | /* this should probably get modified by many more values. |
358 | /* this should probably get modified by many more values. |
371 | * (eg, creatures resistance to fear, level, etc. ) |
359 | * (eg, creatures resistance to fear, level, etc. ) |
372 | */ |
360 | */ |
373 | if (QUERY_FLAG (op, FLAG_SCARED) && !(RANDOM () % 20)) |
361 | if (QUERY_FLAG (op, FLAG_SCARED) && !(rndm (20))) |
374 | { |
362 | { |
375 | CLEAR_FLAG (op, FLAG_SCARED); /* Time to regain some "guts"... */ |
363 | CLEAR_FLAG (op, FLAG_SCARED); /* Time to regain some "guts"... */ |
376 | } |
364 | } |
377 | |
365 | |
378 | if (INVOKE_OBJECT (MONSTER_MOVE, op, ARG_OBJECT (op->enemy))) |
366 | if (INVOKE_OBJECT (MONSTER_MOVE, op, ARG_OBJECT (op->enemy))) |
… | |
… | |
384 | if (!check_wakeup (op, enemy, &rv)) |
372 | if (!check_wakeup (op, enemy, &rv)) |
385 | return 0; |
373 | return 0; |
386 | } |
374 | } |
387 | |
375 | |
388 | /* check if monster pops out of hidden spot */ |
376 | /* check if monster pops out of hidden spot */ |
389 | if (op->hide) |
377 | if (op->flag [FLAG_HIDDEN]) |
390 | do_hidden_move (op); |
378 | do_hidden_move (op); |
391 | |
379 | |
392 | if (op->pick_up) |
380 | if (op->pick_up) |
393 | monster_check_pickup (op); |
381 | monster_check_pickup (op); |
394 | |
382 | |
… | |
… | |
398 | /* 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 */ |
399 | if (!enemy) |
387 | if (!enemy) |
400 | { |
388 | { |
401 | if (QUERY_FLAG (op, FLAG_ONLY_ATTACK)) |
389 | if (QUERY_FLAG (op, FLAG_ONLY_ATTACK)) |
402 | { |
390 | { |
403 | op->destroy (); |
391 | op->drop_and_destroy (); |
404 | return 1; |
392 | return 1; |
405 | } |
393 | } |
406 | |
394 | |
407 | /* Probably really a bug for a creature to have both |
395 | /* Probably really a bug for a creature to have both |
408 | * stand still and a movement type set. |
396 | * stand still and a movement type set. |
… | |
… | |
457 | } /* stand still */ |
445 | } /* stand still */ |
458 | return 0; |
446 | return 0; |
459 | } /* no enemy */ |
447 | } /* no enemy */ |
460 | |
448 | |
461 | /* We have an enemy. Block immediately below is for pets */ |
449 | /* We have an enemy. Block immediately below is for pets */ |
462 | if ((op->attack_movement & HI4) == PETMOVE && (owner = get_owner (op)) != NULL && !on_same_map (op, owner)) |
450 | if ((op->attack_movement & HI4) == PETMOVE |
|
|
451 | && (owner = op->owner) != NULL |
|
|
452 | && !on_same_map (op, owner) |
|
|
453 | && !owner->flag [FLAG_REMOVED]) |
463 | return follow_owner (op, owner); |
454 | return follow_owner (op, owner); |
464 | |
455 | |
465 | /* doppleganger code to change monster facing to that of the nearest |
456 | /* doppleganger code to change monster facing to that of the nearest |
466 | * player. Hmm. The code is here, but no monster in the current |
457 | * player. Hmm. The code is here, but no monster in the current |
467 | * arch set uses it. |
458 | * arch set uses it. |
… | |
… | |
486 | if (!QUERY_FLAG (op, FLAG_SCARED)) |
477 | if (!QUERY_FLAG (op, FLAG_SCARED)) |
487 | { |
478 | { |
488 | rv_vector rv1; |
479 | rv_vector rv1; |
489 | |
480 | |
490 | /* 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 */ |
491 | for (part = op; part != NULL; part = part->more) |
482 | for (part = op; part; part = part->more) |
492 | { |
483 | { |
493 | get_rangevector (part, enemy, &rv1, 0x1); |
484 | get_rangevector (part, enemy, &rv1, 0x1); |
494 | dir = rv1.direction; |
485 | dir = rv1.direction; |
495 | |
486 | |
496 | /* 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 |
497 | * but that we test above... so can be old code here |
488 | * but that we test above... so can be old code here |
498 | */ |
489 | */ |
499 | if (QUERY_FLAG (op, FLAG_RUN_AWAY)) |
490 | if (QUERY_FLAG (op, FLAG_RUN_AWAY)) |
500 | dir = absdir (dir + 4); |
491 | dir = absdir (dir + 4); |
|
|
492 | |
501 | if (QUERY_FLAG (op, FLAG_CONFUSED)) |
493 | if (QUERY_FLAG (op, FLAG_CONFUSED)) |
502 | dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); |
494 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
503 | |
495 | |
504 | if (QUERY_FLAG (op, FLAG_CAST_SPELL) && !(RANDOM () % 3)) |
496 | if (QUERY_FLAG (op, FLAG_CAST_SPELL) && !(rndm (3))) |
505 | { |
|
|
506 | if (monster_cast_spell (op, part, enemy, dir, &rv1)) |
497 | if (monster_cast_spell (op, part, enemy, dir, &rv1)) |
507 | return 0; |
498 | return 0; |
508 | } |
|
|
509 | |
499 | |
510 | if (QUERY_FLAG (op, FLAG_READY_SCROLL) && !(RANDOM () % 3)) |
500 | if (QUERY_FLAG (op, FLAG_READY_SCROLL) && !(rndm (3))) |
511 | { |
|
|
512 | if (monster_use_scroll (op, part, enemy, dir, &rv1)) |
501 | if (monster_use_scroll (op, part, enemy, dir, &rv1)) |
513 | return 0; |
502 | return 0; |
514 | } |
|
|
515 | |
503 | |
516 | if (QUERY_FLAG (op, FLAG_READY_RANGE) && !(RANDOM () % 3)) |
504 | if (QUERY_FLAG (op, FLAG_READY_RANGE) && !(rndm (3))) |
517 | { |
|
|
518 | if (monster_use_range (op, part, enemy, dir)) |
505 | if (monster_use_range (op, part, enemy, dir)) |
519 | return 0; |
506 | return 0; |
520 | } |
507 | |
521 | if (QUERY_FLAG (op, FLAG_READY_SKILL) && !(RANDOM () % 3)) |
508 | if (QUERY_FLAG (op, FLAG_READY_SKILL) && !(rndm (3))) |
522 | { |
|
|
523 | if (monster_use_skill (op, rv.part, enemy, rv.direction)) |
509 | if (monster_use_skill (op, rv.part, enemy, rv.direction)) |
524 | return 0; |
510 | return 0; |
525 | } |
511 | |
526 | if (QUERY_FLAG (op, FLAG_READY_BOW) && !(RANDOM () % 2)) |
512 | if (QUERY_FLAG (op, FLAG_READY_BOW) && !(rndm (2))) |
527 | { |
|
|
528 | if (monster_use_bow (op, part, enemy, dir)) |
513 | if (monster_use_bow (op, part, enemy, dir)) |
529 | return 0; |
514 | return 0; |
530 | } |
|
|
531 | } /* for processing of all parts */ |
515 | } /* for processing of all parts */ |
532 | } /* If not scared */ |
516 | } /* If not scared */ |
533 | |
517 | |
534 | |
518 | |
535 | part = rv.part; |
519 | part = rv.part; |
… | |
… | |
537 | |
521 | |
538 | if (QUERY_FLAG (op, FLAG_SCARED) || QUERY_FLAG (op, FLAG_RUN_AWAY)) |
522 | if (QUERY_FLAG (op, FLAG_SCARED) || QUERY_FLAG (op, FLAG_RUN_AWAY)) |
539 | dir = absdir (dir + 4); |
523 | dir = absdir (dir + 4); |
540 | |
524 | |
541 | if (QUERY_FLAG (op, FLAG_CONFUSED)) |
525 | if (QUERY_FLAG (op, FLAG_CONFUSED)) |
542 | dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); |
526 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
543 | |
527 | |
544 | pre_att_dir = dir; /* remember the original direction */ |
528 | pre_att_dir = dir; /* remember the original direction */ |
545 | |
529 | |
546 | if ((op->attack_movement & LO4) && !QUERY_FLAG (op, FLAG_SCARED)) |
530 | if ((op->attack_movement & LO4) && !QUERY_FLAG (op, FLAG_SCARED)) |
547 | { |
531 | { |
… | |
… | |
666 | 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 */ |
667 | return 1; |
651 | return 1; |
668 | |
652 | |
669 | if (QUERY_FLAG (op, FLAG_ONLY_ATTACK)) |
653 | if (QUERY_FLAG (op, FLAG_ONLY_ATTACK)) |
670 | { |
654 | { |
671 | op->remove (); |
|
|
672 | op->destroy (); |
655 | op->drop_and_destroy (); |
673 | return 1; |
656 | return 1; |
674 | } |
657 | } |
|
|
658 | |
675 | return 0; |
659 | return 0; |
676 | } |
660 | } |
677 | |
661 | |
678 | int |
662 | int |
679 | can_hit (object *ob1, object *ob2, rv_vector * rv) |
663 | can_hit (object *ob1, object *ob2, rv_vector * rv) |
680 | { |
664 | { |
681 | object *more; |
665 | object *more; |
682 | rv_vector rv1; |
666 | rv_vector rv1; |
683 | |
667 | |
684 | if (QUERY_FLAG (ob1, FLAG_CONFUSED) && !(RANDOM () % 3)) |
668 | if (QUERY_FLAG (ob1, FLAG_CONFUSED) && !(rndm (3))) |
685 | return 0; |
669 | return 0; |
686 | |
670 | |
687 | if (abs (rv->distance_x) < 2 && abs (rv->distance_y) < 2) |
671 | if (abs (rv->distance_x) < 2 && abs (rv->distance_y) < 2) |
688 | return 1; |
672 | return 1; |
689 | |
673 | |
… | |
… | |
788 | * other monsters) |
772 | * other monsters) |
789 | */ |
773 | */ |
790 | if (!(dir = path_to_player (part, pl, 0))) |
774 | if (!(dir = path_to_player (part, pl, 0))) |
791 | return 0; |
775 | return 0; |
792 | |
776 | |
793 | if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = get_owner (head)) != NULL) |
777 | if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL) |
794 | { |
778 | { |
795 | get_rangevector (head, owner, &rv1, 0x1); |
779 | get_rangevector (head, owner, &rv1, 0x1); |
796 | if (dirdiff (dir, rv1.direction) < 2) |
780 | if (dirdiff (dir, rv1.direction) < 2) |
797 | { |
781 | { |
798 | return 0; /* Might hit owner with spell */ |
782 | return 0; /* Might hit owner with spell */ |
799 | } |
783 | } |
800 | } |
784 | } |
801 | |
785 | |
802 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
786 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
803 | dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); |
787 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
804 | |
788 | |
805 | /* If the monster hasn't already chosen a spell, choose one |
789 | /* If the monster hasn't already chosen a spell, choose one |
806 | * I'm not sure if it really make sense to pre-select spells (events |
790 | * I'm not sure if it really make sense to pre-select spells (events |
807 | * could be different by the time the monster goes again). |
791 | * could be different by the time the monster goes again). |
808 | */ |
792 | */ |
… | |
… | |
865 | * other monsters) |
849 | * other monsters) |
866 | */ |
850 | */ |
867 | if (!(dir = path_to_player (part, pl, 0))) |
851 | if (!(dir = path_to_player (part, pl, 0))) |
868 | return 0; |
852 | return 0; |
869 | |
853 | |
870 | if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = get_owner (head)) != NULL) |
854 | if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL) |
871 | { |
855 | { |
872 | get_rangevector (head, owner, &rv1, 0x1); |
856 | get_rangevector (head, owner, &rv1, 0x1); |
873 | if (dirdiff (dir, rv1.direction) < 2) |
857 | if (dirdiff (dir, rv1.direction) < 2) |
874 | { |
858 | { |
875 | return 0; /* Might hit owner with spell */ |
859 | return 0; /* Might hit owner with spell */ |
876 | } |
860 | } |
877 | } |
861 | } |
878 | |
862 | |
879 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
863 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
880 | dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); |
864 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
881 | |
865 | |
882 | for (scroll = head->inv; scroll; scroll = scroll->below) |
866 | for (scroll = head->inv; scroll; scroll = scroll->below) |
883 | if (scroll->type == SCROLL && monster_should_cast_spell (head, scroll->inv)) |
867 | if (scroll->type == SCROLL && monster_should_cast_spell (head, scroll->inv)) |
884 | break; |
868 | break; |
885 | |
869 | |
… | |
… | |
907 | * 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. |
908 | * |
892 | * |
909 | * At the moment this is only useful for throwing, perhaps for |
893 | * At the moment this is only useful for throwing, perhaps for |
910 | * 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 |
911 | */ |
895 | */ |
912 | |
|
|
913 | int |
896 | int |
914 | monster_use_skill (object *head, object *part, object *pl, int dir) |
897 | monster_use_skill (object *head, object *part, object *pl, int dir) |
915 | { |
898 | { |
916 | object *skill, *owner; |
899 | object *skill, *owner; |
917 | |
900 | |
918 | if (!(dir = path_to_player (part, pl, 0))) |
901 | if (!(dir = path_to_player (part, pl, 0))) |
919 | return 0; |
902 | return 0; |
920 | |
903 | |
921 | if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = get_owner (head)) != NULL) |
904 | if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL) |
922 | { |
905 | { |
923 | 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); |
924 | |
907 | |
925 | if (dirdiff (dir, dir2) < 1) |
908 | if (dirdiff (dir, dir2) < 1) |
926 | return 0; /* Might hit owner with skill -thrown rocks for example ? */ |
909 | return 0; /* Might hit owner with skill -thrown rocks for example ? */ |
927 | } |
910 | } |
|
|
911 | |
928 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
912 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
929 | dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); |
913 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
930 | |
914 | |
931 | /* skill selection - monster will use the next unused skill. |
915 | /* skill selection - monster will use the next unused skill. |
932 | * well...the following scenario will allow the monster to |
916 | * well...the following scenario will allow the monster to |
933 | * 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 |
934 | * more skills available to monsters. |
918 | * more skills available to monsters. |
935 | */ |
919 | */ |
936 | |
|
|
937 | for (skill = head->inv; skill != NULL; skill = skill->below) |
920 | for (skill = head->inv; skill; skill = skill->below) |
938 | if (skill->type == SKILL && skill != head->chosen_skill) |
921 | if (skill->type == SKILL && skill != head->chosen_skill) |
939 | { |
922 | { |
940 | head->chosen_skill = skill; |
923 | head->chosen_skill = skill; |
941 | break; |
924 | break; |
942 | } |
925 | } |
… | |
… | |
945 | { |
928 | { |
946 | 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); |
947 | CLEAR_FLAG (head, FLAG_READY_SKILL); |
930 | CLEAR_FLAG (head, FLAG_READY_SKILL); |
948 | return 0; |
931 | return 0; |
949 | } |
932 | } |
|
|
933 | |
950 | /* use skill */ |
934 | /* use skill */ |
951 | return do_skill (head, part, head->chosen_skill, dir, NULL); |
935 | return do_skill (head, part, head->chosen_skill, dir, NULL); |
952 | } |
936 | } |
953 | |
937 | |
954 | /* Monster will use a ranged spell attack. */ |
938 | /* Monster will use a ranged spell attack. */ |
955 | |
|
|
956 | int |
939 | int |
957 | monster_use_range (object *head, object *part, object *pl, int dir) |
940 | monster_use_range (object *head, object *part, object *pl, int dir) |
958 | { |
941 | { |
959 | object *wand, *owner; |
942 | object *wand, *owner; |
960 | int at_least_one = 0; |
943 | int at_least_one = 0; |
961 | |
944 | |
962 | if (!(dir = path_to_player (part, pl, 0))) |
945 | if (!(dir = path_to_player (part, pl, 0))) |
963 | return 0; |
946 | return 0; |
964 | |
947 | |
965 | if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = get_owner (head)) != NULL) |
948 | if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL) |
966 | { |
949 | { |
967 | 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); |
968 | |
951 | |
969 | if (dirdiff (dir, dir2) < 2) |
952 | if (dirdiff (dir, dir2) < 2) |
970 | return 0; /* Might hit owner with spell */ |
953 | return 0; /* Might hit owner with spell */ |
971 | } |
954 | } |
|
|
955 | |
972 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
956 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
973 | dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); |
957 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
974 | |
958 | |
975 | for (wand = head->inv; wand != NULL; wand = wand->below) |
959 | for (wand = head->inv; wand; wand = wand->below) |
976 | { |
960 | { |
977 | if (wand->type == WAND) |
961 | if (wand->type == WAND) |
978 | { |
962 | { |
979 | /* Found a wand, let's see if it has charges left */ |
963 | /* Found a wand, let's see if it has charges left */ |
980 | at_least_one = 1; |
964 | at_least_one = 1; |
… | |
… | |
986 | if (!(--wand->stats.food)) |
970 | if (!(--wand->stats.food)) |
987 | { |
971 | { |
988 | if (wand->arch) |
972 | if (wand->arch) |
989 | { |
973 | { |
990 | CLEAR_FLAG (wand, FLAG_ANIMATE); |
974 | CLEAR_FLAG (wand, FLAG_ANIMATE); |
991 | wand->face = wand->arch->clone.face; |
975 | wand->face = wand->arch->face; |
992 | wand->speed = 0; |
976 | wand->set_speed (0); |
993 | update_ob_speed (wand); |
|
|
994 | } |
977 | } |
995 | } |
978 | } |
996 | /* Success */ |
979 | /* Success */ |
997 | return 1; |
980 | return 1; |
998 | } |
981 | } |
… | |
… | |
1016 | } |
999 | } |
1017 | |
1000 | |
1018 | if (at_least_one) |
1001 | if (at_least_one) |
1019 | return 0; |
1002 | return 0; |
1020 | |
1003 | |
1021 | 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); |
1022 | CLEAR_FLAG (head, FLAG_READY_RANGE); |
1005 | CLEAR_FLAG (head, FLAG_READY_RANGE); |
1023 | return 0; |
1006 | return 0; |
1024 | } |
1007 | } |
1025 | |
1008 | |
1026 | int |
1009 | int |
… | |
… | |
1028 | { |
1011 | { |
1029 | object *owner; |
1012 | object *owner; |
1030 | |
1013 | |
1031 | if (!(dir = path_to_player (part, pl, 0))) |
1014 | if (!(dir = path_to_player (part, pl, 0))) |
1032 | return 0; |
1015 | return 0; |
|
|
1016 | |
1033 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
1017 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
1034 | dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); |
1018 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
1035 | |
1019 | |
1036 | if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = get_owner (head)) != NULL) |
1020 | if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL) |
1037 | { |
1021 | { |
1038 | int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y); |
1022 | int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y); |
1039 | |
1023 | |
1040 | if (dirdiff (dir, dir2) < 1) |
1024 | if (dirdiff (dir, dir2) < 1) |
1041 | return 0; /* Might hit owner with arrow */ |
1025 | return 0; /* Might hit owner with arrow */ |
… | |
… | |
1045 | 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); |
1046 | |
1030 | |
1047 | } |
1031 | } |
1048 | |
1032 | |
1049 | /* Checks if putting on 'item' will make 'who' do more |
1033 | /* Checks if putting on 'item' will make 'who' do more |
1050 | * damage. This is a very simplistic check - also checking things |
1034 | * damage. This is a very simplistic check - also checking things |
1051 | * like speed and ac are also relevant. |
1035 | * like speed and ac are also relevant. |
1052 | * |
1036 | * |
1053 | * return true if item is a better object. |
1037 | * return true if item is a better object. |
1054 | */ |
1038 | */ |
1055 | |
|
|
1056 | int |
1039 | int |
1057 | check_good_weapon (object *who, object *item) |
1040 | check_good_weapon (object *who, object *item) |
1058 | { |
1041 | { |
1059 | object *other_weap; |
1042 | object *other_weap; |
1060 | int val = 0, i; |
1043 | int val = 0, i; |
1061 | |
1044 | |
1062 | 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) |
1063 | 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)) |
1064 | break; |
1047 | break; |
1065 | |
1048 | |
1066 | if (other_weap == NULL) /* No other weapons */ |
1049 | if (!other_weap) /* No other weapons */ |
1067 | return 1; |
1050 | return 1; |
1068 | |
1051 | |
1069 | /* 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 |
1070 | * better, just do some simple checks |
1053 | * better, just do some simple checks |
1071 | * Put some multipliers for things that hvae several effects, |
1054 | * Put some multipliers for things that hvae several effects, |
… | |
… | |
1076 | val += (item->magic - other_weap->magic) * 3; |
1059 | val += (item->magic - other_weap->magic) * 3; |
1077 | /* Monsters don't really get benefits from things like regen rates |
1060 | /* Monsters don't really get benefits from things like regen rates |
1078 | * from items. But the bonus for their stats are very important. |
1061 | * from items. But the bonus for their stats are very important. |
1079 | */ |
1062 | */ |
1080 | for (i = 0; i < NUM_STATS; i++) |
1063 | for (i = 0; i < NUM_STATS; i++) |
1081 | 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; |
1082 | |
1065 | |
1083 | if (val > 0) |
1066 | if (val > 0) |
1084 | return 1; |
1067 | return 1; |
1085 | else |
1068 | else |
1086 | return 0; |
1069 | return 0; |
1087 | |
|
|
1088 | } |
1070 | } |
1089 | |
1071 | |
1090 | int |
1072 | int |
1091 | check_good_armour (object *who, object *item) |
1073 | check_good_armour (object *who, object *item) |
1092 | { |
1074 | { |
1093 | object *other_armour; |
1075 | object *other_armour; |
1094 | int val = 0, i; |
1076 | int val = 0, i; |
1095 | |
1077 | |
1096 | 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) |
1097 | 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)) |
1098 | break; |
1080 | break; |
1099 | |
1081 | |
1100 | if (other_armour == NULL) /* No other armour, use the new */ |
1082 | if (other_armour == NULL) /* No other armour, use the new */ |
1101 | return 1; |
1083 | return 1; |
… | |
… | |
1123 | |
1105 | |
1124 | if (val > 0) |
1106 | if (val > 0) |
1125 | return 1; |
1107 | return 1; |
1126 | else |
1108 | else |
1127 | return 0; |
1109 | return 0; |
1128 | |
|
|
1129 | } |
1110 | } |
1130 | |
1111 | |
1131 | /* |
1112 | /* |
1132 | * monster_check_pickup(): checks for items that monster can pick up. |
1113 | * monster_check_pickup(): checks for items that monster can pick up. |
1133 | * |
1114 | * |
… | |
… | |
1141 | * 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 |
1142 | * 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 |
1143 | * 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 |
1144 | * affect stacking on this space. |
1125 | * affect stacking on this space. |
1145 | */ |
1126 | */ |
1146 | |
|
|
1147 | void |
1127 | void |
1148 | monster_check_pickup (object *monster) |
1128 | monster_check_pickup (object *monster) |
1149 | { |
1129 | { |
1150 | object *tmp, *next; |
1130 | object *tmp, *next; |
1151 | |
1131 | |
… | |
… | |
1170 | * monster_can_pick(): If the monster is interested in picking up |
1150 | * monster_can_pick(): If the monster is interested in picking up |
1171 | * the item, then return 0. Otherwise 0. |
1151 | * the item, then return 0. Otherwise 0. |
1172 | * Instead of pick_up, flags for "greed", etc, should be used. |
1152 | * Instead of pick_up, flags for "greed", etc, should be used. |
1173 | * 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. |
1174 | */ |
1154 | */ |
1175 | |
|
|
1176 | int |
1155 | int |
1177 | monster_can_pick (object *monster, object *item) |
1156 | monster_can_pick (object *monster, object *item) |
1178 | { |
1157 | { |
1179 | int flag = 0; |
1158 | int flag = 0; |
1180 | int i; |
1159 | int i; |
… | |
… | |
1226 | case ROD: |
1205 | case ROD: |
1227 | flag = QUERY_FLAG (monster, FLAG_USE_RANGE); |
1206 | flag = QUERY_FLAG (monster, FLAG_USE_RANGE); |
1228 | break; |
1207 | break; |
1229 | |
1208 | |
1230 | case SPELLBOOK: |
1209 | case SPELLBOOK: |
1231 | flag = (monster->arch != NULL && QUERY_FLAG ((&monster->arch->clone), FLAG_CAST_SPELL)); |
1210 | flag = monster->arch && QUERY_FLAG (monster->arch, FLAG_CAST_SPELL); |
1232 | break; |
1211 | break; |
1233 | |
1212 | |
1234 | case SCROLL: |
1213 | case SCROLL: |
1235 | flag = QUERY_FLAG (monster, FLAG_USE_SCROLL); |
1214 | flag = QUERY_FLAG (monster, FLAG_USE_SCROLL); |
1236 | break; |
1215 | break; |
… | |
… | |
1238 | case BOW: |
1217 | case BOW: |
1239 | case ARROW: |
1218 | case ARROW: |
1240 | flag = QUERY_FLAG (monster, FLAG_USE_BOW); |
1219 | flag = QUERY_FLAG (monster, FLAG_USE_BOW); |
1241 | break; |
1220 | break; |
1242 | } |
1221 | } |
|
|
1222 | |
1243 | /* 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 |
1244 | * 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 |
1245 | * use several locations. |
1225 | * use several locations. |
1246 | */ |
1226 | */ |
1247 | for (i = 0; i < NUM_BODY_LOCATIONS; i++) |
1227 | for (i = 0; i < NUM_BODY_LOCATIONS; i++) |
1248 | { |
1228 | { |
1249 | if (monster->body_info[i] && item->body_info[i]) |
1229 | if (monster->slot[i].info && item->slot[i].info) |
1250 | { |
1230 | { |
1251 | flag = 1; |
1231 | flag = 1; |
1252 | break; |
1232 | break; |
1253 | } |
1233 | } |
1254 | } |
1234 | } |
… | |
… | |
1262 | * monster_apply_below(): |
1242 | * monster_apply_below(): |
1263 | * 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 |
1264 | * eager to apply things, encounters something apply-able, |
1244 | * eager to apply things, encounters something apply-able, |
1265 | * then make him apply it |
1245 | * then make him apply it |
1266 | */ |
1246 | */ |
1267 | |
|
|
1268 | void |
1247 | void |
1269 | monster_apply_below (object *monster) |
1248 | monster_apply_below (object *monster) |
1270 | { |
1249 | { |
1271 | object *tmp, *next; |
1250 | object *tmp, *next; |
1272 | |
1251 | |
… | |
… | |
1299 | * 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. |
1300 | * (so that other monsters can pick it up and use it) |
1279 | * (so that other monsters can pick it up and use it) |
1301 | * Note that as things are now, monsters never drop something - |
1280 | * Note that as things are now, monsters never drop something - |
1302 | * they can pick up all that they can use. |
1281 | * they can pick up all that they can use. |
1303 | */ |
1282 | */ |
1304 | |
|
|
1305 | /* Sept 96, fixed this so skills will be readied -b.t.*/ |
1283 | /* Sept 96, fixed this so skills will be readied -b.t.*/ |
1306 | |
|
|
1307 | void |
1284 | void |
1308 | monster_check_apply (object *mon, object *item) |
1285 | monster_check_apply (object *mon, object *item) |
1309 | { |
1286 | { |
1310 | |
|
|
1311 | int flag = 0; |
1287 | int flag = 0; |
1312 | |
1288 | |
1313 | 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))) |
1314 | { |
1290 | { |
1315 | SET_FLAG (mon, FLAG_CAST_SPELL); |
1291 | SET_FLAG (mon, FLAG_CAST_SPELL); |
1316 | return; |
1292 | return; |
1317 | } |
1293 | } |
1318 | |
1294 | |
… | |
… | |
1327 | if (QUERY_FLAG (mon, FLAG_USE_BOW) && item->type == ARROW) |
1303 | if (QUERY_FLAG (mon, FLAG_USE_BOW) && item->type == ARROW) |
1328 | { |
1304 | { |
1329 | /* Check for the right kind of bow */ |
1305 | /* Check for the right kind of bow */ |
1330 | object *bow; |
1306 | object *bow; |
1331 | |
1307 | |
1332 | for (bow = mon->inv; bow != NULL; bow = bow->below) |
1308 | for (bow = mon->inv; bow; bow = bow->below) |
1333 | if (bow->type == BOW && bow->race == item->race) |
1309 | if (bow->type == BOW && bow->race == item->race) |
1334 | { |
1310 | { |
1335 | SET_FLAG (mon, FLAG_READY_BOW); |
1311 | SET_FLAG (mon, FLAG_READY_BOW); |
1336 | LOG (llevMonster, "Found correct bow for arrows.\n"); |
1312 | LOG (llevMonster, "Found correct bow for arrows.\n"); |
1337 | return; /* nothing more to do for arrows */ |
1313 | return; /* nothing more to do for arrows */ |
… | |
… | |
1352 | /* Don't use it right now */ |
1328 | /* Don't use it right now */ |
1353 | return; |
1329 | return; |
1354 | } |
1330 | } |
1355 | else if (item->type == WEAPON) |
1331 | else if (item->type == WEAPON) |
1356 | flag = check_good_weapon (mon, item); |
1332 | flag = check_good_weapon (mon, item); |
1357 | else if (IS_ARMOR (item)) |
1333 | else if (item->is_armor ()) |
1358 | flag = check_good_armour (mon, item); |
1334 | flag = check_good_armour (mon, item); |
1359 | /* Should do something more, like make sure this is a better item */ |
1335 | /* Should do something more, like make sure this is a better item */ |
1360 | else if (item->type == RING) |
1336 | else if (item->type == RING) |
1361 | flag = 1; |
1337 | flag = 1; |
1362 | else if (item->type == WAND || item->type == ROD || item->type == HORN) |
1338 | else if (item->type == WAND || item->type == ROD || item->type == HORN) |
… | |
… | |
1389 | */ |
1365 | */ |
1390 | SET_FLAG (mon, FLAG_READY_SKILL); |
1366 | SET_FLAG (mon, FLAG_READY_SKILL); |
1391 | return; |
1367 | return; |
1392 | } |
1368 | } |
1393 | |
1369 | |
1394 | |
|
|
1395 | /* 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. |
1396 | * 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, |
1397 | * bolts, and whatever else, because it only checks against the |
1372 | * bolts, and whatever else, because it only checks against the |
1398 | * body_info locations. |
1373 | * body_info locations. |
1399 | */ |
1374 | */ |
… | |
… | |
1410 | /* should only be applying this item, not unapplying it. |
1385 | /* should only be applying this item, not unapplying it. |
1411 | * 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. |
1412 | * monsters have some advantages after all. |
1387 | * monsters have some advantages after all. |
1413 | */ |
1388 | */ |
1414 | manual_apply (mon, item, AP_APPLY | AP_IGNORE_CURSE); |
1389 | manual_apply (mon, item, AP_APPLY | AP_IGNORE_CURSE); |
1415 | |
|
|
1416 | return; |
|
|
1417 | } |
1390 | } |
1418 | |
1391 | |
1419 | void |
1392 | void |
1420 | npc_call_help (object *op) |
1393 | npc_call_help (object *op) |
1421 | { |
1394 | { |
… | |
… | |
1433 | mflags = get_map_flags (m, &m, sx, sy, &sx, &sy); |
1406 | mflags = get_map_flags (m, &m, sx, sy, &sx, &sy); |
1434 | /* If nothing alive on this space, no need to search the space. */ |
1407 | /* If nothing alive on this space, no need to search the space. */ |
1435 | if ((mflags & P_OUT_OF_MAP) || !(mflags & P_IS_ALIVE)) |
1408 | if ((mflags & P_OUT_OF_MAP) || !(mflags & P_IS_ALIVE)) |
1436 | continue; |
1409 | continue; |
1437 | |
1410 | |
1438 | for (npc = get_map_ob (m, sx, sy); npc != NULL; npc = npc->above) |
1411 | for (npc = GET_MAP_OB (m, sx, sy); npc != NULL; npc = npc->above) |
1439 | if (QUERY_FLAG (npc, FLAG_ALIVE) && QUERY_FLAG (npc, FLAG_UNAGGRESSIVE)) |
1412 | if (QUERY_FLAG (npc, FLAG_ALIVE) && QUERY_FLAG (npc, FLAG_UNAGGRESSIVE)) |
1440 | npc->enemy = op->enemy; |
1413 | npc->enemy = op->enemy; |
1441 | } |
1414 | } |
1442 | } |
1415 | } |
1443 | |
1416 | |
1444 | |
|
|
1445 | int |
1417 | int |
1446 | 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) |
1447 | { |
1419 | { |
1448 | |
|
|
1449 | if (can_hit (part, enemy, rv)) |
1420 | if (can_hit (part, enemy, rv)) |
1450 | return dir; |
1421 | return dir; |
1451 | if (rv->distance < 10) |
1422 | if (rv->distance < 10) |
1452 | return absdir (dir + 4); |
1423 | return absdir (dir + 4); |
1453 | else if (rv->distance > 18) |
1424 | else if (rv->distance > 18) |
1454 | return dir; |
1425 | return dir; |
|
|
1426 | |
1455 | return 0; |
1427 | return 0; |
1456 | } |
1428 | } |
1457 | |
1429 | |
1458 | int |
1430 | int |
1459 | 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) |
1460 | { |
1432 | { |
1461 | |
|
|
1462 | 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) |
1463 | { |
1434 | { |
1464 | ob->move_status++; |
1435 | ob->move_status++; |
1465 | return (dir); |
1436 | return (dir); |
1466 | } |
1437 | } |
1467 | else if (ob->move_status > 20) |
1438 | else if (ob->move_status > 20) |
1468 | ob->move_status = 0; |
1439 | ob->move_status = 0; |
|
|
1440 | |
1469 | return absdir (dir + 4); |
1441 | return absdir (dir + 4); |
1470 | } |
1442 | } |
1471 | |
1443 | |
1472 | int |
1444 | int |
1473 | hitrun_att (int dir, object *ob, object *enemy) |
1445 | hitrun_att (int dir, object *ob, object *enemy) |
… | |
… | |
1476 | return dir; |
1448 | return dir; |
1477 | else if (ob->move_status < 50) |
1449 | else if (ob->move_status < 50) |
1478 | return absdir (dir + 4); |
1450 | return absdir (dir + 4); |
1479 | else |
1451 | else |
1480 | ob->move_status = 0; |
1452 | ob->move_status = 0; |
|
|
1453 | |
1481 | return absdir (dir + 4); |
1454 | return absdir (dir + 4); |
1482 | } |
1455 | } |
1483 | |
1456 | |
1484 | int |
1457 | int |
1485 | 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) |
… | |
… | |
1494 | return 0; |
1467 | return 0; |
1495 | else if (ob->move_status < 10) |
1468 | else if (ob->move_status < 10) |
1496 | return dir; |
1469 | return dir; |
1497 | else if (ob->move_status < 15) |
1470 | else if (ob->move_status < 15) |
1498 | return absdir (dir + 4); |
1471 | return absdir (dir + 4); |
|
|
1472 | |
1499 | ob->move_status = 0; |
1473 | ob->move_status = 0; |
1500 | return 0; |
1474 | return 0; |
1501 | } |
1475 | } |
1502 | |
1476 | |
1503 | int |
1477 | int |
… | |
… | |
1511 | * 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 |
1512 | * server should try to be resilant enough to avoid the problem |
1486 | * server should try to be resilant enough to avoid the problem |
1513 | */ |
1487 | */ |
1514 | 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) |
1515 | return absdir (dir + 4); |
1489 | return absdir (dir + 4); |
|
|
1490 | |
1516 | return dist_att (dir, ob, enemy, part, rv); |
1491 | return dist_att (dir, ob, enemy, part, rv); |
1517 | } |
1492 | } |
1518 | |
1493 | |
1519 | int |
1494 | int |
1520 | 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) |
1521 | { |
1496 | { |
1522 | if (rv->distance < 9) |
1497 | if (rv->distance < 9) |
1523 | return absdir (dir + 4); |
1498 | return absdir (dir + 4); |
|
|
1499 | |
1524 | return 0; |
1500 | return 0; |
1525 | } |
1501 | } |
1526 | |
1502 | |
1527 | void |
1503 | void |
1528 | circ1_move (object *ob) |
1504 | circ1_move (object *ob) |
1529 | { |
1505 | { |
1530 | 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 | |
1531 | if (++ob->move_status > 11) |
1508 | if (++ob->move_status > 11) |
1532 | ob->move_status = 0; |
1509 | ob->move_status = 0; |
|
|
1510 | |
1533 | if (!(move_object (ob, circle[ob->move_status]))) |
1511 | if (!(move_object (ob, circle[ob->move_status]))) |
1534 | (void) move_object (ob, RANDOM () % 8 + 1); |
1512 | move_object (ob, rndm (8) + 1); |
1535 | } |
1513 | } |
1536 | |
1514 | |
1537 | void |
1515 | void |
1538 | circ2_move (object *ob) |
1516 | circ2_move (object *ob) |
1539 | { |
1517 | { |
1540 | 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 | |
1541 | if (++ob->move_status > 19) |
1520 | if (++ob->move_status > 19) |
1542 | ob->move_status = 0; |
1521 | ob->move_status = 0; |
|
|
1522 | |
1543 | if (!(move_object (ob, circle[ob->move_status]))) |
1523 | if (!(move_object (ob, circle[ob->move_status]))) |
1544 | (void) move_object (ob, RANDOM () % 8 + 1); |
1524 | move_object (ob, rndm (8) + 1); |
1545 | } |
1525 | } |
1546 | |
1526 | |
1547 | void |
1527 | void |
1548 | pace_movev (object *ob) |
1528 | pace_movev (object *ob) |
1549 | { |
1529 | { |
1550 | if (ob->move_status++ > 6) |
1530 | if (ob->move_status++ > 6) |
1551 | ob->move_status = 0; |
1531 | ob->move_status = 0; |
|
|
1532 | |
1552 | if (ob->move_status < 4) |
1533 | if (ob->move_status < 4) |
1553 | (void) move_object (ob, 5); |
1534 | move_object (ob, 5); |
1554 | else |
1535 | else |
1555 | (void) move_object (ob, 1); |
1536 | move_object (ob, 1); |
1556 | } |
1537 | } |
1557 | |
1538 | |
1558 | void |
1539 | void |
1559 | pace_moveh (object *ob) |
1540 | pace_moveh (object *ob) |
1560 | { |
1541 | { |
1561 | if (ob->move_status++ > 6) |
1542 | if (ob->move_status++ > 6) |
1562 | ob->move_status = 0; |
1543 | ob->move_status = 0; |
|
|
1544 | |
1563 | if (ob->move_status < 4) |
1545 | if (ob->move_status < 4) |
1564 | (void) move_object (ob, 3); |
1546 | move_object (ob, 3); |
1565 | else |
1547 | else |
1566 | (void) move_object (ob, 7); |
1548 | move_object (ob, 7); |
1567 | } |
1549 | } |
1568 | |
1550 | |
1569 | void |
1551 | void |
1570 | pace2_movev (object *ob) |
1552 | pace2_movev (object *ob) |
1571 | { |
1553 | { |
1572 | if (ob->move_status++ > 16) |
1554 | if (ob->move_status++ > 16) |
1573 | ob->move_status = 0; |
1555 | ob->move_status = 0; |
|
|
1556 | |
1574 | if (ob->move_status < 6) |
1557 | if (ob->move_status < 6) |
1575 | (void) move_object (ob, 5); |
1558 | move_object (ob, 5); |
1576 | else if (ob->move_status < 8) |
1559 | else if (ob->move_status < 8) |
1577 | return; |
1560 | return; |
1578 | else if (ob->move_status < 13) |
1561 | else if (ob->move_status < 13) |
1579 | (void) move_object (ob, 1); |
1562 | move_object (ob, 1); |
1580 | else |
1563 | else |
1581 | return; |
1564 | return; |
1582 | } |
1565 | } |
1583 | |
1566 | |
1584 | void |
1567 | void |
1585 | pace2_moveh (object *ob) |
1568 | pace2_moveh (object *ob) |
1586 | { |
1569 | { |
1587 | if (ob->move_status++ > 16) |
1570 | if (ob->move_status++ > 16) |
1588 | ob->move_status = 0; |
1571 | ob->move_status = 0; |
|
|
1572 | |
1589 | if (ob->move_status < 6) |
1573 | if (ob->move_status < 6) |
1590 | (void) move_object (ob, 3); |
1574 | move_object (ob, 3); |
1591 | else if (ob->move_status < 8) |
1575 | else if (ob->move_status < 8) |
1592 | return; |
1576 | return; |
1593 | else if (ob->move_status < 13) |
1577 | else if (ob->move_status < 13) |
1594 | (void) move_object (ob, 7); |
1578 | move_object (ob, 7); |
1595 | else |
1579 | else |
1596 | return; |
1580 | return; |
1597 | } |
1581 | } |
1598 | |
1582 | |
1599 | void |
1583 | void |
1600 | rand_move (object *ob) |
1584 | rand_move (object *ob) |
1601 | { |
1585 | { |
1602 | int i; |
1586 | int i; |
1603 | |
1587 | |
1604 | if (ob->move_status < 1 || ob->move_status > 8 || !(move_object (ob, ob->move_status || !(RANDOM () % 9)))) |
1588 | if (ob->move_status < 1 || ob->move_status > 8 || !(move_object (ob, ob->move_status || !(rndm (9))))) |
1605 | for (i = 0; i < 5; i++) |
1589 | for (i = 0; i < 5; i++) |
1606 | if (move_object (ob, ob->move_status = RANDOM () % 8 + 1)) |
1590 | if (move_object (ob, ob->move_status = rndm (8) + 1)) |
1607 | return; |
1591 | return; |
1608 | } |
1592 | } |
1609 | |
1593 | |
1610 | void |
1594 | void |
1611 | check_earthwalls (object *op, maptile *m, int x, int y) |
1595 | check_earthwalls (object *op, maptile *m, int x, int y) |
1612 | { |
1596 | { |
1613 | object *tmp; |
1597 | object *tmp; |
1614 | |
1598 | |
1615 | for (tmp = get_map_ob (m, x, y); tmp != NULL; tmp = tmp->above) |
1599 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) |
1616 | { |
1600 | { |
1617 | if (tmp->type == EARTHWALL) |
1601 | if (tmp->type == EARTHWALL) |
1618 | { |
1602 | { |
1619 | hit_player (tmp, op->stats.dam, op, AT_PHYSICAL, 1); |
1603 | hit_player (tmp, op->stats.dam, op, AT_PHYSICAL, 1); |
1620 | return; |
1604 | return; |
… | |
… | |
1625 | void |
1609 | void |
1626 | check_doors (object *op, maptile *m, int x, int y) |
1610 | check_doors (object *op, maptile *m, int x, int y) |
1627 | { |
1611 | { |
1628 | object *tmp; |
1612 | object *tmp; |
1629 | |
1613 | |
1630 | for (tmp = get_map_ob (m, x, y); tmp != NULL; tmp = tmp->above) |
1614 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) |
1631 | { |
1615 | { |
1632 | if (tmp->type == DOOR) |
1616 | if (tmp->type == DOOR) |
1633 | { |
1617 | { |
1634 | hit_player (tmp, 1000, op, AT_PHYSICAL, 1); |
1618 | hit_player (tmp, 1000, op, AT_PHYSICAL, 1); |
1635 | return; |
1619 | return; |
… | |
… | |
1642 | * monsters to throw things like chairs and other pieces of |
1626 | * monsters to throw things like chairs and other pieces of |
1643 | * furniture, even if they are not good throwable objects. |
1627 | * furniture, even if they are not good throwable objects. |
1644 | * Probably better to have the monster throw a throwable object |
1628 | * Probably better to have the monster throw a throwable object |
1645 | * first, then throw any non equipped weapon. |
1629 | * first, then throw any non equipped weapon. |
1646 | */ |
1630 | */ |
1647 | |
|
|
1648 | object * |
1631 | object * |
1649 | find_mon_throw_ob (object *op) |
1632 | find_mon_throw_ob (object *op) |
1650 | { |
1633 | { |
1651 | object *tmp = NULL; |
1634 | object *tmp = NULL; |
1652 | |
1635 | |
… | |
… | |
1656 | tmp = op; |
1639 | tmp = op; |
1657 | |
1640 | |
1658 | /* New throw code: look through the inventory. Grap the first legal is_thrown |
1641 | /* New throw code: look through the inventory. Grap the first legal is_thrown |
1659 | * marked item and throw it to the enemy. |
1642 | * marked item and throw it to the enemy. |
1660 | */ |
1643 | */ |
1661 | |
|
|
1662 | for (tmp = op->inv; tmp; tmp = tmp->below) |
1644 | for (tmp = op->inv; tmp; tmp = tmp->below) |
1663 | { |
1645 | { |
1664 | |
|
|
1665 | /* Can't throw invisible objects or items that are applied */ |
1646 | /* Can't throw invisible objects or items that are applied */ |
1666 | if (tmp->invisible || QUERY_FLAG (tmp, FLAG_APPLIED)) |
1647 | if (tmp->invisible || QUERY_FLAG (tmp, FLAG_APPLIED)) |
1667 | continue; |
1648 | continue; |
1668 | |
1649 | |
1669 | if (QUERY_FLAG (tmp, FLAG_IS_THROWN)) |
1650 | if (QUERY_FLAG (tmp, FLAG_IS_THROWN)) |
… | |
… | |
1685 | * 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 |
1686 | * 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 |
1687 | * be within the valid range. MSW 2001-08-05 |
1668 | * be within the valid range. MSW 2001-08-05 |
1688 | * 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 |
1689 | */ |
1670 | */ |
1690 | |
|
|
1691 | int |
1671 | int |
1692 | can_detect_enemy (object *op, object *enemy, rv_vector * rv) |
1672 | can_detect_enemy (object *op, object *enemy, rv_vector * rv) |
1693 | { |
1673 | { |
1694 | int radius = MIN_MON_RADIUS, hide_discovery; |
1674 | int radius = MIN_MON_RADIUS, hide_discovery; |
1695 | |
1675 | |
… | |
… | |
1725 | |
1705 | |
1726 | /* use this for invis also */ |
1706 | /* use this for invis also */ |
1727 | hide_discovery = op->stats.Int / 5; |
1707 | hide_discovery = op->stats.Int / 5; |
1728 | |
1708 | |
1729 | /* Determine Detection radii */ |
1709 | /* Determine Detection radii */ |
1730 | 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) */ |
1731 | 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); |
1732 | else |
1712 | else |
1733 | { /* a level/INT/Dex adjustment for hiding */ |
1713 | { /* a level/INT/Dex adjustment for hiding */ |
1734 | object *sk_hide; |
|
|
1735 | int bonus = (op->level / 2) + (op->stats.Int / 5); |
1714 | int bonus = op->level / 2 + op->stats.Int / 5; |
1736 | |
1715 | |
1737 | if (enemy->type == PLAYER) |
1716 | if (enemy->type == PLAYER) |
1738 | { |
1717 | { |
1739 | if ((sk_hide = find_skill_by_number (enemy, SK_HIDING))) |
1718 | if (object *sk_hide = find_skill_by_number (enemy, SK_HIDING)) |
1740 | bonus -= sk_hide->level; |
1719 | bonus -= sk_hide->level; |
1741 | else |
1720 | else |
1742 | { |
1721 | { |
1743 | 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"); |
1744 | make_visible (enemy); |
1723 | make_visible (enemy); |
… | |
… | |
1753 | } /* else creature has modifiers for hiding */ |
1732 | } /* else creature has modifiers for hiding */ |
1754 | |
1733 | |
1755 | /* Radii stealth adjustment. Only if you are stealthy |
1734 | /* Radii stealth adjustment. Only if you are stealthy |
1756 | * will you be able to sneak up closer to creatures */ |
1735 | * will you be able to sneak up closer to creatures */ |
1757 | if (QUERY_FLAG (enemy, FLAG_STEALTH)) |
1736 | if (QUERY_FLAG (enemy, FLAG_STEALTH)) |
1758 | radius = radius / 2, hide_discovery = hide_discovery / 3; |
1737 | { |
|
|
1738 | radius /= 2; |
|
|
1739 | hide_discovery /= 3; |
|
|
1740 | } |
1759 | |
1741 | |
1760 | /* Radii adjustment for enemy standing in the dark */ |
1742 | /* Radii adjustment for enemy standing in the dark */ |
1761 | if (op->map->darkness > 0 && !stand_in_light (enemy)) |
1743 | if (op->map->darkness > 0 && !stand_in_light (enemy)) |
1762 | { |
1744 | { |
1763 | /* on dark maps body heat can help indicate location with infravision |
1745 | /* on dark maps body heat can help indicate location with infravision |
… | |
… | |
1781 | * 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 |
1782 | * do something. Note that the distance field in the |
1764 | * do something. Note that the distance field in the |
1783 | * 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 |
1784 | * find that. |
1766 | * find that. |
1785 | */ |
1767 | */ |
1786 | if (radius > 13) |
1768 | // note that the above reasoning was utter bullshit even at the time it was written |
1787 | radius = 13; |
1769 | // we use 25, lets see if we have the cpu time for it |
|
|
1770 | radius = min (25, radius); |
1788 | |
1771 | |
1789 | /* Enemy in range! Now test for detection */ |
1772 | /* Enemy in range! Now test for detection */ |
1790 | if ((int) rv->distance <= radius) |
1773 | if (rv->distance <= radius) |
1791 | { |
1774 | { |
1792 | /* ah, we are within range, detected? take cases */ |
1775 | /* ah, we are within range, detected? take cases */ |
1793 | if (!enemy->invisible) /* enemy in dark squares... are seen! */ |
1776 | if (!enemy->invisible) /* enemy in dark squares... are seen! */ |
1794 | return 1; |
1777 | return 1; |
1795 | |
1778 | |
1796 | /* hidden or low-quality invisible */ |
1779 | /* hidden or low-quality invisible */ |
1797 | if (enemy->hide && (rv->distance <= 1) && (RANDOM () % 100 <= hide_discovery)) |
1780 | if (enemy->flag [FLAG_HIDDEN] && rv->distance <= 1 && rndm (100) <= hide_discovery) |
1798 | { |
1781 | { |
1799 | make_visible (enemy); |
1782 | make_visible (enemy); |
|
|
1783 | |
1800 | /* inform players of new status */ |
1784 | /* inform players of new status */ |
1801 | if (enemy->type == PLAYER && player_can_view (enemy, op)) |
1785 | if (enemy->type == PLAYER && player_can_view (enemy, op)) |
1802 | 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 | |
1803 | return 1; /* detected enemy */ |
1788 | return 1; /* detected enemy */ |
1804 | } |
1789 | } |
1805 | else if (enemy->invisible) |
1790 | else if (enemy->invisible) |
1806 | { |
1791 | { |
1807 | /* Change this around - instead of negating the invisible, just |
1792 | /* Change this around - instead of negating the invisible, just |
1808 | * 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 |
1809 | * do something to you. Decreasing the duration of invisible |
1794 | * do something to you. Decreasing the duration of invisible |
1810 | * 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 |
1811 | * can then basically negate the spell. The spell isn't negated - |
1796 | * can then basically negate the spell. The spell isn't negated - |
1812 | * they just know where you are! |
1797 | * they just know where you are! |
1813 | */ |
1798 | */ |
1814 | if ((RANDOM () % 50) <= hide_discovery) |
1799 | if (rndm (50) <= hide_discovery) |
1815 | { |
1800 | { |
1816 | if (enemy->type == PLAYER) |
1801 | if (enemy->type == PLAYER) |
1817 | { |
|
|
1818 | 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)); |
1819 | } |
1803 | |
1820 | return 1; |
1804 | return 1; |
1821 | } |
1805 | } |
1822 | } |
1806 | } |
1823 | } /* within range */ |
1807 | } /* within range */ |
1824 | |
1808 | |
… | |
… | |
1829 | /* 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 |
1830 | * intellegent algorithm. For one thing, we ignore los here, SO it |
1814 | * intellegent algorithm. For one thing, we ignore los here, SO it |
1831 | * 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 |
1832 | * other side of a wall (!). |
1816 | * other side of a wall (!). |
1833 | */ |
1817 | */ |
1834 | |
|
|
1835 | int |
1818 | int |
1836 | stand_in_light (object *op) |
1819 | stand_in_light (object *op) |
1837 | { |
1820 | { |
1838 | sint16 nx, ny; |
|
|
1839 | maptile *m; |
|
|
1840 | |
|
|
1841 | |
|
|
1842 | if (!op) |
1821 | if (!op) |
1843 | return 0; |
1822 | return 0; |
|
|
1823 | |
1844 | if (op->glow_radius > 0) |
1824 | if (op->glow_radius > 0) |
1845 | return 1; |
1825 | return 1; |
1846 | |
1826 | |
1847 | if (op->map) |
1827 | if (op->map) |
1848 | { |
1828 | { |
1849 | int x, y, x1, y1; |
|
|
1850 | |
|
|
1851 | |
|
|
1852 | |
|
|
1853 | /* 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 |
1854 | * 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. |
1855 | */ |
1831 | */ |
1856 | 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++) |
1857 | { |
1833 | { |
1858 | 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++) |
1859 | { |
1835 | { |
1860 | m = op->map; |
1836 | maptile *m = op->map; |
1861 | nx = x; |
1837 | sint16 nx = x; |
1862 | ny = y; |
1838 | sint16 ny = y; |
1863 | |
1839 | |
1864 | if (get_map_flags (m, &m, nx, ny, &nx, &ny) & P_OUT_OF_MAP) |
1840 | if (xy_normalise (m, nx, ny)) |
1865 | continue; |
1841 | if (idistance (x - op->x, y - op->y) < m->at (nx, ny).light) |
1866 | |
|
|
1867 | x1 = abs (x - op->x) * abs (x - op->x); |
|
|
1868 | y1 = abs (y - op->y) * abs (y - op->y); |
|
|
1869 | if (isqrt (x1 + y1) < GET_MAP_LIGHT (m, nx, ny)) |
|
|
1870 | return 1; |
1842 | return 1; |
1871 | } |
1843 | } |
1872 | } |
1844 | } |
1873 | } |
1845 | } |
|
|
1846 | |
1874 | return 0; |
1847 | return 0; |
1875 | } |
1848 | } |
1876 | |
|
|
1877 | |
1849 | |
1878 | /* assuming no walls/barriers, lets check to see if its *possible* |
1850 | /* assuming no walls/barriers, lets check to see if its *possible* |
1879 | * to see an enemy. Note, "detection" is different from "seeing". |
1851 | * to see an enemy. Note, "detection" is different from "seeing". |
1880 | * See can_detect_enemy() for more details. -b.t. |
1852 | * See can_detect_enemy() for more details. -b.t. |
1881 | * return 0 if can't be seen, 1 if can be |
1853 | * return 0 if can't be seen, 1 if can be |
1882 | */ |
1854 | */ |
1883 | |
|
|
1884 | int |
1855 | int |
1885 | can_see_enemy (object *op, object *enemy) |
1856 | can_see_enemy (object *op, object *enemy) |
1886 | { |
1857 | { |
1887 | object *looker = op->head ? op->head : op; |
1858 | object *looker = op->head ? op->head : op; |
1888 | |
1859 | |
… | |
… | |
1904 | * However,if you carry any source of light, then the hidden |
1875 | * However,if you carry any source of light, then the hidden |
1905 | * creature is seeable (and stupid) */ |
1876 | * creature is seeable (and stupid) */ |
1906 | |
1877 | |
1907 | if (has_carried_lights (enemy)) |
1878 | if (has_carried_lights (enemy)) |
1908 | { |
1879 | { |
1909 | if (enemy->hide) |
1880 | if (enemy->flag [FLAG_HIDDEN]) |
1910 | { |
1881 | { |
1911 | make_visible (enemy); |
1882 | make_visible (enemy); |
1912 | 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!"); |
1913 | } |
1884 | } |
|
|
1885 | |
1914 | return 1; |
1886 | return 1; |
1915 | } |
1887 | } |
1916 | else if (enemy->hide) |
1888 | else if (enemy->flag [FLAG_HIDDEN]) |
1917 | return 0; |
1889 | return 0; |
1918 | |
1890 | |
1919 | /* Invisible enemy. Break apart the check for invis undead/invis looker |
1891 | /* Invisible enemy. Break apart the check for invis undead/invis looker |
1920 | * 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, |
1921 | * and making it a conditional makes the code pretty ugly. |
1893 | * and making it a conditional makes the code pretty ugly. |
1922 | */ |
1894 | */ |
1923 | if (!QUERY_FLAG (looker, FLAG_SEE_INVISIBLE)) |
1895 | if (!QUERY_FLAG (looker, FLAG_SEE_INVISIBLE)) |
1924 | { |
|
|
1925 | if (makes_invisible_to (enemy, looker)) |
1896 | if (makes_invisible_to (enemy, looker)) |
1926 | return 0; |
1897 | return 0; |
1927 | } |
|
|
1928 | } |
1898 | } |
1929 | else if (looker->type == PLAYER) /* for players, a (possible) shortcut */ |
1899 | else if (looker->type == PLAYER) /* for players, a (possible) shortcut */ |
1930 | if (player_can_view (looker, enemy)) |
1900 | if (player_can_view (looker, enemy)) |
1931 | return 1; |
1901 | return 1; |
1932 | |
1902 | |
… | |
… | |
1943 | && (!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))) |
1944 | return 0; |
1914 | return 0; |
1945 | |
1915 | |
1946 | return 1; |
1916 | return 1; |
1947 | } |
1917 | } |
|
|
1918 | |