1 | /* |
1 | /* |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Crossfire TRT is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
… | |
… | |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * |
20 | * |
21 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
22 | */ |
23 | |
23 | |
24 | #include <global.h> |
24 | #include <global.h> |
25 | #include <sproto.h> |
25 | #include <sproto.h> |
26 | #include <spells.h> |
26 | #include <spells.h> |
… | |
… | |
197 | /* we check our old enemy. */ |
197 | /* we check our old enemy. */ |
198 | if (!(tmp = check_enemy (npc, rv))) |
198 | if (!(tmp = check_enemy (npc, rv))) |
199 | { |
199 | { |
200 | if (attacker) /* if we have an attacker, check him */ |
200 | if (attacker) /* if we have an attacker, check him */ |
201 | { |
201 | { |
202 | /* TODO: thats not finished */ |
202 | /* TODO: that's not finished */ |
203 | /* we don't want a fight evil vs evil or good against non evil */ |
203 | /* we don't want a fight evil vs evil or good against non evil */ |
204 | |
204 | |
205 | if (QUERY_FLAG (npc, FLAG_NEUTRAL) || QUERY_FLAG (attacker, FLAG_NEUTRAL) || /* neutral */ |
205 | if (QUERY_FLAG (npc, FLAG_NEUTRAL) || QUERY_FLAG (attacker, FLAG_NEUTRAL) || /* neutral */ |
206 | (QUERY_FLAG (npc, FLAG_FRIENDLY) && QUERY_FLAG (attacker, FLAG_FRIENDLY)) || |
206 | (QUERY_FLAG (npc, FLAG_FRIENDLY) && QUERY_FLAG (attacker, FLAG_FRIENDLY)) || |
207 | (!QUERY_FLAG (npc, FLAG_FRIENDLY) && (!QUERY_FLAG (attacker, FLAG_FRIENDLY) && attacker->type != PLAYER))) |
207 | (!QUERY_FLAG (npc, FLAG_FRIENDLY) && (!QUERY_FLAG (attacker, FLAG_FRIENDLY) && attacker->type != PLAYER))) |
208 | CLEAR_FLAG (npc, FLAG_SLEEP); /* skip it, but lets wakeup */ |
208 | CLEAR_FLAG (npc, FLAG_SLEEP); /* skip it, but lets wakeup */ |
209 | else if (on_same_map (npc, attacker)) /* thats the only thing we must know... */ |
209 | else if (on_same_map (npc, attacker)) /* that's the only thing we must know... */ |
210 | { |
210 | { |
211 | CLEAR_FLAG (npc, FLAG_SLEEP); /* well, NOW we really should wake up! */ |
211 | CLEAR_FLAG (npc, FLAG_SLEEP); /* well, NOW we really should wake up! */ |
212 | npc->enemy = attacker; |
212 | npc->enemy = attacker; |
213 | return attacker; /* yes, we face our attacker! */ |
213 | return attacker; /* yes, we face our attacker! */ |
214 | } |
214 | } |
… | |
… | |
231 | * Currently, this is only called from move_monster, and |
231 | * Currently, this is only called from move_monster, and |
232 | * if enemy is set, then so should be rv. |
232 | * if enemy is set, then so should be rv. |
233 | * returns 1 if the monster should wake up, 0 otherwise. |
233 | * returns 1 if the monster should wake up, 0 otherwise. |
234 | */ |
234 | */ |
235 | int |
235 | int |
236 | check_wakeup (object *op, object *enemy, rv_vector * rv) |
236 | check_wakeup (object *op, object *enemy, rv_vector *rv) |
237 | { |
237 | { |
238 | int radius = op->stats.Wis > MIN_MON_RADIUS ? op->stats.Wis : MIN_MON_RADIUS; |
|
|
239 | |
|
|
240 | /* Trim work - if no enemy, no need to do anything below */ |
238 | /* Trim work - if no enemy, no need to do anything below */ |
241 | if (!enemy) |
239 | if (!enemy) |
242 | return 0; |
240 | return 0; |
243 | |
241 | |
|
|
242 | int radius = max (op->stats.Wis, MIN_MON_RADIUS); |
|
|
243 | |
|
|
244 | if (op->flag [FLAG_BLIND]) |
244 | /* blinded monsters can only find nearby objects to attack */ |
245 | /* blinded monsters can only find nearby objects to attack */ |
245 | if (QUERY_FLAG (op, FLAG_BLIND)) |
|
|
246 | radius = MIN_MON_RADIUS; |
246 | radius = MIN_MON_RADIUS; |
247 | |
247 | else if (op->map |
|
|
248 | && !enemy->invisible |
|
|
249 | && !stand_in_light (enemy) |
|
|
250 | && (!op->flag[FLAG_SEE_IN_DARK] || !op->flag [FLAG_SEE_INVISIBLE])) |
248 | /* This covers the situation where the monster is in the dark |
251 | /* This covers the situation where the monster is in the dark |
249 | * and has an enemy. If the enemy has no carried light (or isnt |
252 | * and has an enemy. If the enemy has no carried light (or isnt |
250 | * glowing!) then the monster has trouble finding the enemy. |
253 | * glowing!) then the monster has trouble finding the enemy. |
251 | * Remember we already checked to see if the monster can see in |
254 | * Remember we already checked to see if the monster can see in |
252 | * the dark. */ |
255 | * the dark. */ |
253 | |
256 | radius = min (radius, MIN_MON_RADIUS + MAX_DARKNESS - op->map->darklevel ()); |
254 | else if (op->map && op->map->darkness > 0 && enemy && !enemy->invisible && |
257 | else if (!op->flag [FLAG_SLEEP]) |
255 | !stand_in_light (enemy) && (!QUERY_FLAG (op, FLAG_SEE_IN_DARK) || !QUERY_FLAG (op, FLAG_SEE_INVISIBLE))) |
|
|
256 | { |
|
|
257 | int dark = radius / (op->map->darkness); |
|
|
258 | |
|
|
259 | radius = (dark > MIN_MON_RADIUS) ? (dark + 1) : MIN_MON_RADIUS; |
|
|
260 | } |
|
|
261 | else if (!QUERY_FLAG (op, FLAG_SLEEP)) |
|
|
262 | return 1; |
258 | return 1; |
|
|
259 | |
|
|
260 | if (enemy->flag [FLAG_STEALTH]) |
|
|
261 | radius = radius / 2 + 1; |
263 | |
262 | |
264 | /* enemy should already be on this map, so don't really need to check |
263 | /* enemy should already be on this map, so don't really need to check |
265 | * for that. |
264 | * for that. |
266 | */ |
265 | */ |
267 | if (rv->distance < (unsigned int) (QUERY_FLAG (enemy, FLAG_STEALTH) ? (radius / 2) + 1 : radius)) |
266 | if (rv->distance <= radius) |
268 | { |
267 | { |
269 | CLEAR_FLAG (op, FLAG_SLEEP); |
268 | CLEAR_FLAG (op, FLAG_SLEEP); |
270 | return 1; |
269 | return 1; |
271 | } |
270 | } |
|
|
271 | |
272 | return 0; |
272 | return 0; |
273 | } |
273 | } |
274 | |
274 | |
275 | int |
275 | int |
276 | move_randomly (object *op) |
276 | move_randomly (object *op) |
277 | { |
277 | { |
278 | int i; |
|
|
279 | |
|
|
280 | /* Give up to 15 chances for a monster to move randomly */ |
278 | /* Give up to 15 chances for a monster to move randomly */ |
281 | for (i = 0; i < 15; i++) |
279 | for (int i = 0; i < 15; i++) |
282 | { |
|
|
283 | if (move_object (op, rndm (8) + 1)) |
280 | if (move_object (op, rndm (8) + 1)) |
284 | return 1; |
281 | return 1; |
285 | } |
282 | |
286 | return 0; |
283 | return 0; |
287 | } |
284 | } |
288 | |
285 | |
289 | /* |
286 | /* |
290 | * Move-monster returns 1 if the object has been freed, otherwise 0. |
287 | * Move-monster returns 1 if the object has been freed, otherwise 0. |
… | |
… | |
313 | enemy->attacked_by = op; /* our ptr */ |
310 | enemy->attacked_by = op; /* our ptr */ |
314 | |
311 | |
315 | /* generate hp, if applicable */ |
312 | /* generate hp, if applicable */ |
316 | if (op->stats.Con > 0 && op->stats.hp < op->stats.maxhp) |
313 | if (op->stats.Con > 0 && op->stats.hp < op->stats.maxhp) |
317 | { |
314 | { |
318 | |
|
|
319 | /* last heal is in funny units. Dividing by speed puts |
315 | /* last heal is in funny units. Dividing by speed puts |
320 | * the regeneration rate on a basis of time instead of |
316 | * the regeneration rate on a basis of time instead of |
321 | * #moves the monster makes. The scaling by 8 is |
317 | * #moves the monster makes. The scaling by 8 is |
322 | * to capture 8th's of a hp fraction regens |
318 | * to capture 8th's of a hp fraction regens |
323 | * |
319 | * |
… | |
… | |
338 | } |
334 | } |
339 | |
335 | |
340 | /* generate sp, if applicable */ |
336 | /* generate sp, if applicable */ |
341 | if (op->stats.Pow > 0 && op->stats.sp < op->stats.maxsp) |
337 | if (op->stats.Pow > 0 && op->stats.sp < op->stats.maxsp) |
342 | { |
338 | { |
343 | |
|
|
344 | /* last_sp is in funny units. Dividing by speed puts |
339 | /* last_sp is in funny units. Dividing by speed puts |
345 | * the regeneration rate on a basis of time instead of |
340 | * the regeneration rate on a basis of time instead of |
346 | * #moves the monster makes. The scaling by 8 is |
341 | * #moves the monster makes. The scaling by 8 is |
347 | * to capture 8th's of a sp fraction regens |
342 | * to capture 8th's of a sp fraction regens |
348 | * |
343 | * |
… | |
… | |
357 | |
352 | |
358 | /* this should probably get modified by many more values. |
353 | /* this should probably get modified by many more values. |
359 | * (eg, creatures resistance to fear, level, etc. ) |
354 | * (eg, creatures resistance to fear, level, etc. ) |
360 | */ |
355 | */ |
361 | if (QUERY_FLAG (op, FLAG_SCARED) && !(rndm (20))) |
356 | if (QUERY_FLAG (op, FLAG_SCARED) && !(rndm (20))) |
362 | { |
|
|
363 | CLEAR_FLAG (op, FLAG_SCARED); /* Time to regain some "guts"... */ |
357 | CLEAR_FLAG (op, FLAG_SCARED); /* Time to regain some "guts"... */ |
364 | } |
|
|
365 | |
358 | |
366 | if (INVOKE_OBJECT (MONSTER_MOVE, op, ARG_OBJECT (op->enemy))) |
359 | if (INVOKE_OBJECT (MONSTER_MOVE, op, ARG_OBJECT (op->enemy))) |
367 | return QUERY_FLAG (op, FLAG_FREED); |
360 | return QUERY_FLAG (op, FLAG_FREED); |
368 | |
361 | |
369 | if (QUERY_FLAG (op, FLAG_SLEEP) || QUERY_FLAG (op, FLAG_BLIND) || |
362 | if (QUERY_FLAG (op, FLAG_SLEEP) || QUERY_FLAG (op, FLAG_BLIND) || |
370 | ((op->map->darkness > 0) && !QUERY_FLAG (op, FLAG_SEE_IN_DARK) && !QUERY_FLAG (op, FLAG_SEE_INVISIBLE))) |
363 | ((op->map->darklevel () > 0) && !QUERY_FLAG (op, FLAG_SEE_IN_DARK) && !QUERY_FLAG (op, FLAG_SEE_INVISIBLE))) |
371 | { |
|
|
372 | if (!check_wakeup (op, enemy, &rv)) |
364 | if (!check_wakeup (op, enemy, &rv)) |
373 | return 0; |
365 | return 0; |
374 | } |
|
|
375 | |
366 | |
376 | /* check if monster pops out of hidden spot */ |
367 | /* check if monster pops out of hidden spot */ |
377 | if (op->hide) |
368 | if (op->flag [FLAG_HIDDEN]) |
378 | do_hidden_move (op); |
369 | do_hidden_move (op); |
379 | |
370 | |
380 | if (op->pick_up) |
371 | if (op->pick_up) |
381 | monster_check_pickup (op); |
372 | monster_check_pickup (op); |
382 | |
373 | |
… | |
… | |
386 | /* If we don't have an enemy, do special movement or the like */ |
377 | /* If we don't have an enemy, do special movement or the like */ |
387 | if (!enemy) |
378 | if (!enemy) |
388 | { |
379 | { |
389 | if (QUERY_FLAG (op, FLAG_ONLY_ATTACK)) |
380 | if (QUERY_FLAG (op, FLAG_ONLY_ATTACK)) |
390 | { |
381 | { |
391 | op->destroy (); |
382 | op->drop_and_destroy (); |
392 | return 1; |
383 | return 1; |
393 | } |
384 | } |
394 | |
385 | |
395 | /* Probably really a bug for a creature to have both |
386 | /* Probably really a bug for a creature to have both |
396 | * stand still and a movement type set. |
387 | * stand still and a movement type set. |
… | |
… | |
399 | { |
390 | { |
400 | if (op->attack_movement & HI4) |
391 | if (op->attack_movement & HI4) |
401 | { |
392 | { |
402 | switch (op->attack_movement & HI4) |
393 | switch (op->attack_movement & HI4) |
403 | { |
394 | { |
404 | case (PETMOVE): |
395 | case (PETMOVE): |
405 | pet_move (op); |
396 | pet_move (op); |
406 | break; |
397 | break; |
407 | |
398 | |
408 | case (CIRCLE1): |
399 | case (CIRCLE1): |
409 | circ1_move (op); |
400 | circ1_move (op); |
410 | break; |
401 | break; |
411 | |
402 | |
412 | case (CIRCLE2): |
403 | case (CIRCLE2): |
413 | circ2_move (op); |
404 | circ2_move (op); |
414 | break; |
405 | break; |
415 | |
406 | |
416 | case (PACEV): |
407 | case (PACEV): |
417 | pace_movev (op); |
408 | pace_movev (op); |
418 | break; |
409 | break; |
419 | |
410 | |
420 | case (PACEH): |
411 | case (PACEH): |
421 | pace_moveh (op); |
412 | pace_moveh (op); |
422 | break; |
413 | break; |
423 | |
414 | |
424 | case (PACEV2): |
415 | case (PACEV2): |
425 | pace2_movev (op); |
416 | pace2_movev (op); |
426 | break; |
417 | break; |
427 | |
418 | |
428 | case (PACEH2): |
419 | case (PACEH2): |
429 | pace2_moveh (op); |
420 | pace2_moveh (op); |
430 | break; |
421 | break; |
431 | |
422 | |
432 | case (RANDO): |
423 | case (RANDO): |
433 | rand_move (op); |
424 | rand_move (op); |
434 | break; |
425 | break; |
435 | |
426 | |
436 | case (RANDO2): |
427 | case (RANDO2): |
437 | move_randomly (op); |
428 | move_randomly (op); |
438 | break; |
429 | break; |
439 | } |
430 | } |
|
|
431 | |
440 | return 0; |
432 | return 0; |
441 | } |
433 | } |
442 | else if (QUERY_FLAG (op, FLAG_RANDOM_MOVE)) |
434 | else if (QUERY_FLAG (op, FLAG_RANDOM_MOVE)) |
443 | (void) move_randomly (op); |
435 | move_randomly (op); |
444 | |
|
|
445 | } /* stand still */ |
436 | } /* stand still */ |
|
|
437 | |
446 | return 0; |
438 | return 0; |
447 | } /* no enemy */ |
439 | } /* no enemy */ |
448 | |
440 | |
449 | /* We have an enemy. Block immediately below is for pets */ |
441 | /* We have an enemy. Block immediately below is for pets */ |
450 | if ((op->attack_movement & HI4) == PETMOVE |
442 | if ((op->attack_movement & HI4) == PETMOVE |
… | |
… | |
452 | && !on_same_map (op, owner) |
444 | && !on_same_map (op, owner) |
453 | && !owner->flag [FLAG_REMOVED]) |
445 | && !owner->flag [FLAG_REMOVED]) |
454 | return follow_owner (op, owner); |
446 | return follow_owner (op, owner); |
455 | |
447 | |
456 | /* doppleganger code to change monster facing to that of the nearest |
448 | /* doppleganger code to change monster facing to that of the nearest |
457 | * player. Hmm. The code is here, but no monster in the current |
449 | * player. Hmm. The code is here, but no monster in the current |
458 | * arch set uses it. |
450 | * arch set uses it. |
459 | */ |
451 | */ |
460 | if ((op->race != NULL) && strcmp (op->race, "doppleganger") == 0) |
452 | if (op->race && strcmp (op->race, "doppleganger") == 0) |
461 | { |
453 | { |
462 | op->face = enemy->face; |
454 | op->face = enemy->face; |
463 | op->name = enemy->name; |
455 | op->name = enemy->name; |
464 | } |
456 | } |
465 | |
457 | |
… | |
… | |
529 | |
521 | |
530 | if ((op->attack_movement & LO4) && !QUERY_FLAG (op, FLAG_SCARED)) |
522 | if ((op->attack_movement & LO4) && !QUERY_FLAG (op, FLAG_SCARED)) |
531 | { |
523 | { |
532 | switch (op->attack_movement & LO4) |
524 | switch (op->attack_movement & LO4) |
533 | { |
525 | { |
534 | case DISTATT: |
526 | case DISTATT: |
535 | dir = dist_att (dir, op, enemy, part, &rv); |
527 | dir = dist_att (dir, op, enemy, part, &rv); |
536 | break; |
528 | break; |
537 | |
529 | |
538 | case RUNATT: |
530 | case RUNATT: |
539 | dir = run_att (dir, op, enemy, part, &rv); |
531 | dir = run_att (dir, op, enemy, part, &rv); |
540 | break; |
532 | break; |
541 | |
533 | |
542 | case HITRUN: |
534 | case HITRUN: |
543 | dir = hitrun_att (dir, op, enemy); |
535 | dir = hitrun_att (dir, op, enemy); |
544 | break; |
536 | break; |
545 | |
537 | |
546 | case WAITATT: |
538 | case WAITATT: |
547 | dir = wait_att (dir, op, enemy, part, &rv); |
539 | dir = wait_att (dir, op, enemy, part, &rv); |
548 | break; |
540 | break; |
549 | |
541 | |
550 | case RUSH: /* default - monster normally moves towards player */ |
542 | case RUSH: /* default - monster normally moves towards player */ |
551 | case ALLRUN: |
543 | case ALLRUN: |
552 | break; |
544 | break; |
553 | |
545 | |
554 | case DISTHIT: |
546 | case DISTHIT: |
555 | dir = disthit_att (dir, op, enemy, part, &rv); |
547 | dir = disthit_att (dir, op, enemy, part, &rv); |
556 | break; |
548 | break; |
557 | |
549 | |
558 | case WAIT2: |
550 | case WAIT2: |
559 | dir = wait_att2 (dir, op, enemy, part, &rv); |
551 | dir = wait_att2 (dir, op, enemy, part, &rv); |
560 | break; |
552 | break; |
561 | |
553 | |
562 | default: |
554 | default: |
563 | LOG (llevDebug, "Illegal low mon-move: %d\n", op->attack_movement & LO4); |
555 | LOG (llevDebug, "Illegal low mon-move: %d\n", op->attack_movement & LO4); |
564 | } |
556 | } |
565 | } |
557 | } |
566 | |
558 | |
567 | if (!dir) |
559 | if (!dir) |
568 | return 0; |
560 | return 0; |
… | |
… | |
578 | return 0; |
570 | return 0; |
579 | } |
571 | } |
580 | |
572 | |
581 | if (QUERY_FLAG (op, FLAG_SCARED) || !can_hit (part, enemy, &rv) || QUERY_FLAG (op, FLAG_RUN_AWAY)) |
573 | if (QUERY_FLAG (op, FLAG_SCARED) || !can_hit (part, enemy, &rv) || QUERY_FLAG (op, FLAG_RUN_AWAY)) |
582 | { |
574 | { |
583 | |
|
|
584 | /* Try move around corners if !close */ |
575 | /* Try move around corners if !close */ |
585 | int maxdiff = (QUERY_FLAG (op, FLAG_ONLY_ATTACK) || RANDOM () & 1) ? 1 : 2; |
576 | int maxdiff = (QUERY_FLAG (op, FLAG_ONLY_ATTACK) || rndm (2)) ? 1 : 2; |
586 | |
577 | |
587 | for (diff = 1; diff <= maxdiff; diff++) |
578 | for (diff = 1; diff <= maxdiff; diff++) |
588 | { |
579 | { |
589 | /* try different detours */ |
580 | /* try different detours */ |
590 | int m = 1 - (RANDOM () & 2); /* Try left or right first? */ |
581 | int m = 1 - rndm (2) * 2; /* Try left or right first? */ |
591 | |
582 | |
592 | if (move_object (op, absdir (dir + diff * m)) || move_object (op, absdir (dir - diff * m))) |
583 | if (move_object (op, absdir (dir + diff * m)) || move_object (op, absdir (dir - diff * m))) |
593 | return 0; |
584 | return 0; |
594 | } |
585 | } |
595 | } |
586 | } |
… | |
… | |
622 | { |
613 | { |
623 | object *nearest_player = get_nearest_player (op); |
614 | object *nearest_player = get_nearest_player (op); |
624 | |
615 | |
625 | if (nearest_player && nearest_player != enemy && !can_hit (part, enemy, &rv)) |
616 | if (nearest_player && nearest_player != enemy && !can_hit (part, enemy, &rv)) |
626 | { |
617 | { |
627 | op->enemy = NULL; |
618 | op->enemy = 0; |
628 | enemy = nearest_player; |
619 | enemy = nearest_player; |
629 | } |
620 | } |
630 | } |
621 | } |
631 | |
622 | |
632 | if (!QUERY_FLAG (op, FLAG_SCARED) && can_hit (part, enemy, &rv)) |
623 | if (!QUERY_FLAG (op, FLAG_SCARED) && can_hit (part, enemy, &rv)) |
… | |
… | |
638 | * still be pretty nasty. |
629 | * still be pretty nasty. |
639 | */ |
630 | */ |
640 | if (QUERY_FLAG (op, FLAG_RUN_AWAY)) |
631 | if (QUERY_FLAG (op, FLAG_RUN_AWAY)) |
641 | { |
632 | { |
642 | part->stats.wc += 10; |
633 | part->stats.wc += 10; |
643 | (void) skill_attack (enemy, part, 0, NULL, NULL); |
634 | skill_attack (enemy, part, 0, NULL, NULL); |
644 | part->stats.wc -= 10; |
635 | part->stats.wc -= 10; |
645 | } |
636 | } |
646 | else |
637 | else |
647 | (void) skill_attack (enemy, part, 0, NULL, NULL); |
638 | skill_attack (enemy, part, 0, NULL, NULL); |
648 | } /* if monster is in attack range */ |
639 | } /* if monster is in attack range */ |
649 | |
640 | |
650 | if (QUERY_FLAG (part, FLAG_FREED)) /* Might be freed by ghost-attack or hit-back */ |
641 | if (QUERY_FLAG (part, FLAG_FREED)) /* Might be freed by ghost-attack or hit-back */ |
651 | return 1; |
642 | return 1; |
652 | |
643 | |
653 | if (QUERY_FLAG (op, FLAG_ONLY_ATTACK)) |
644 | if (QUERY_FLAG (op, FLAG_ONLY_ATTACK)) |
654 | { |
645 | { |
655 | op->remove (); |
|
|
656 | op->destroy (); |
646 | op->drop_and_destroy (); |
657 | return 1; |
647 | return 1; |
658 | } |
648 | } |
|
|
649 | |
659 | return 0; |
650 | return 0; |
660 | } |
651 | } |
661 | |
652 | |
662 | int |
653 | int |
663 | can_hit (object *ob1, object *ob2, rv_vector * rv) |
654 | can_hit (object *ob1, object *ob2, rv_vector * rv) |
… | |
… | |
678 | { |
669 | { |
679 | get_rangevector (ob1, more, &rv1, 0); |
670 | get_rangevector (ob1, more, &rv1, 0); |
680 | if (abs (rv1.distance_x) < 2 && abs (rv1.distance_y) < 2) |
671 | if (abs (rv1.distance_x) < 2 && abs (rv1.distance_y) < 2) |
681 | return 1; |
672 | return 1; |
682 | } |
673 | } |
|
|
674 | |
683 | return 0; |
675 | return 0; |
684 | |
|
|
685 | } |
676 | } |
686 | |
677 | |
687 | /* Returns 1 is monster should cast spell sp at an enemy |
678 | /* Returns 1 is monster should cast spell sp at an enemy |
688 | * Returns 0 if the monster should not cast this spell. |
679 | * Returns 0 if the monster should not cast this spell. |
689 | * |
680 | * |
… | |
… | |
707 | spell_ob->subtype == SP_EXPLOSION || spell_ob->subtype == SP_CONE || |
698 | spell_ob->subtype == SP_EXPLOSION || spell_ob->subtype == SP_CONE || |
708 | spell_ob->subtype == SP_BOMB || spell_ob->subtype == SP_SMITE || |
699 | spell_ob->subtype == SP_BOMB || spell_ob->subtype == SP_SMITE || |
709 | spell_ob->subtype == SP_MAGIC_MISSILE || spell_ob->subtype == SP_SUMMON_GOLEM || |
700 | spell_ob->subtype == SP_MAGIC_MISSILE || spell_ob->subtype == SP_SUMMON_GOLEM || |
710 | spell_ob->subtype == SP_MAGIC_WALL || spell_ob->subtype == SP_SUMMON_MONSTER || |
701 | spell_ob->subtype == SP_MAGIC_WALL || spell_ob->subtype == SP_SUMMON_MONSTER || |
711 | spell_ob->subtype == SP_MOVING_BALL || spell_ob->subtype == SP_SWARM || spell_ob->subtype == SP_INVISIBLE) |
702 | spell_ob->subtype == SP_MOVING_BALL || spell_ob->subtype == SP_SWARM || spell_ob->subtype == SP_INVISIBLE) |
712 | |
|
|
713 | return 1; |
703 | return 1; |
714 | |
704 | |
715 | return 0; |
705 | return 0; |
716 | } |
706 | } |
717 | |
|
|
718 | |
707 | |
719 | #define MAX_KNOWN_SPELLS 20 |
708 | #define MAX_KNOWN_SPELLS 20 |
720 | |
709 | |
721 | /* Returns a randomly selected spell. This logic is still |
710 | /* Returns a randomly selected spell. This logic is still |
722 | * less than ideal. This code also only seems to deal with |
711 | * less than ideal. This code also only seems to deal with |
… | |
… | |
725 | */ |
714 | */ |
726 | object * |
715 | object * |
727 | monster_choose_random_spell (object *monster) |
716 | monster_choose_random_spell (object *monster) |
728 | { |
717 | { |
729 | object *altern[MAX_KNOWN_SPELLS]; |
718 | object *altern[MAX_KNOWN_SPELLS]; |
730 | object *tmp; |
|
|
731 | int i = 0; |
719 | int i = 0; |
732 | |
720 | |
733 | for (tmp = monster->inv; tmp != NULL; tmp = tmp->below) |
721 | for (object *tmp = monster->inv; tmp; tmp = tmp->below) |
734 | if (tmp->type == SPELLBOOK || tmp->type == SPELL) |
722 | if (tmp->type == SPELLBOOK || tmp->type == SPELL) |
735 | { |
723 | { |
736 | /* Check and see if it's actually a useful spell. |
724 | /* Check and see if it's actually a useful spell. |
737 | * If its a spellbook, the spell is actually the inventory item. |
725 | * If its a spellbook, the spell is actually the inventory item. |
738 | * if it is a spell, then it is just the object itself. |
726 | * if it is a spell, then it is just the object itself. |
739 | */ |
727 | */ |
740 | if (monster_should_cast_spell (monster, (tmp->type == SPELLBOOK) ? tmp->inv : tmp)) |
728 | if (monster_should_cast_spell (monster, (tmp->type == SPELLBOOK) ? tmp->inv : tmp)) |
741 | { |
729 | { |
742 | altern[i++] = tmp; |
730 | altern [i++] = tmp; |
|
|
731 | |
743 | if (i == MAX_KNOWN_SPELLS) |
732 | if (i == MAX_KNOWN_SPELLS) |
744 | break; |
733 | break; |
745 | } |
734 | } |
746 | } |
735 | } |
747 | if (!i) |
736 | |
748 | return NULL; |
737 | return i ? altern [rndm (i)] : 0; |
749 | return altern[RANDOM () % i]; |
|
|
750 | } |
738 | } |
751 | |
739 | |
752 | /* This checks to see if the monster should cast a spell/ability. |
740 | /* This checks to see if the monster should cast a spell/ability. |
753 | * it returns true if the monster casts a spell, 0 if he doesn't. |
741 | * it returns true if the monster casts a spell, 0 if he doesn't. |
754 | * head is the head of the monster. |
742 | * head is the head of the monster. |
755 | * part is the part of the monster we are checking against. |
743 | * part is the part of the monster we are checking against. |
756 | * pl is the target. |
744 | * pl is the target. |
757 | * dir is the direction to case. |
745 | * dir is the direction to case. |
758 | * rv is the vector which describes where the enemy is. |
746 | * rv is the vector which describes where the enemy is. |
759 | */ |
747 | */ |
760 | |
|
|
761 | int |
748 | int |
762 | monster_cast_spell (object *head, object *part, object *pl, int dir, rv_vector * rv) |
749 | monster_cast_spell (object *head, object *part, object *pl, int dir, rv_vector * rv) |
763 | { |
750 | { |
764 | object *spell_item; |
751 | object *spell_item; |
765 | object *owner; |
752 | object *owner; |
… | |
… | |
776 | |
763 | |
777 | if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL) |
764 | if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL) |
778 | { |
765 | { |
779 | get_rangevector (head, owner, &rv1, 0x1); |
766 | get_rangevector (head, owner, &rv1, 0x1); |
780 | if (dirdiff (dir, rv1.direction) < 2) |
767 | if (dirdiff (dir, rv1.direction) < 2) |
781 | { |
|
|
782 | return 0; /* Might hit owner with spell */ |
768 | return 0; /* Might hit owner with spell */ |
783 | } |
|
|
784 | } |
769 | } |
785 | |
770 | |
786 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
771 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
787 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
772 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
788 | |
773 | |
… | |
… | |
796 | { |
781 | { |
797 | LOG (llevMonster, "Turned off spells in %s\n", &head->name); |
782 | LOG (llevMonster, "Turned off spells in %s\n", &head->name); |
798 | CLEAR_FLAG (head, FLAG_CAST_SPELL); /* Will be turned on when picking up book */ |
783 | CLEAR_FLAG (head, FLAG_CAST_SPELL); /* Will be turned on when picking up book */ |
799 | return 0; |
784 | return 0; |
800 | } |
785 | } |
|
|
786 | |
801 | if (spell_item->type == SPELLBOOK) |
787 | if (spell_item->type == SPELLBOOK) |
802 | { |
788 | { |
803 | if (!spell_item->inv) |
789 | if (!spell_item->inv) |
804 | { |
790 | { |
805 | LOG (llevError, "spellbook %s does not contain a spell?\n", &spell_item->name); |
791 | LOG (llevError, "spellbook %s does not contain a spell?\n", &spell_item->name); |
806 | return 0; |
792 | return 0; |
807 | } |
793 | } |
|
|
794 | |
808 | spell_item = spell_item->inv; |
795 | spell_item = spell_item->inv; |
809 | } |
796 | } |
810 | } |
797 | } |
811 | else |
798 | else |
812 | spell_item = head->spellitem; |
799 | spell_item = head->spellitem; |
… | |
… | |
831 | /* set this to null, so next time monster will choose something different */ |
818 | /* set this to null, so next time monster will choose something different */ |
832 | head->spellitem = NULL; |
819 | head->spellitem = NULL; |
833 | |
820 | |
834 | return cast_spell (part, part, dir, spell_item, NULL); |
821 | return cast_spell (part, part, dir, spell_item, NULL); |
835 | } |
822 | } |
836 | |
|
|
837 | |
823 | |
838 | int |
824 | int |
839 | monster_use_scroll (object *head, object *part, object *pl, int dir, rv_vector * rv) |
825 | monster_use_scroll (object *head, object *part, object *pl, int dir, rv_vector * rv) |
840 | { |
826 | { |
841 | object *scroll; |
827 | object *scroll; |
… | |
… | |
1233 | } |
1219 | } |
1234 | } |
1220 | } |
1235 | |
1221 | |
1236 | if (((!(monster->pick_up & 32)) && flag) || ((monster->pick_up & 32) && (!flag))) |
1222 | if (((!(monster->pick_up & 32)) && flag) || ((monster->pick_up & 32) && (!flag))) |
1237 | return 1; |
1223 | return 1; |
|
|
1224 | |
1238 | return 0; |
1225 | return 0; |
1239 | } |
1226 | } |
1240 | |
1227 | |
1241 | /* |
1228 | /* |
1242 | * monster_apply_below(): |
1229 | * monster_apply_below(): |
… | |
… | |
1417 | int |
1404 | int |
1418 | dist_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1405 | dist_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1419 | { |
1406 | { |
1420 | if (can_hit (part, enemy, rv)) |
1407 | if (can_hit (part, enemy, rv)) |
1421 | return dir; |
1408 | return dir; |
|
|
1409 | |
1422 | if (rv->distance < 10) |
1410 | if (rv->distance < 10) |
1423 | return absdir (dir + 4); |
1411 | return absdir (dir + 4); |
1424 | else if (rv->distance > 18) |
1412 | else if (rv->distance > 18) |
1425 | return dir; |
1413 | return dir; |
1426 | |
1414 | |
… | |
… | |
1581 | } |
1569 | } |
1582 | |
1570 | |
1583 | void |
1571 | void |
1584 | rand_move (object *ob) |
1572 | rand_move (object *ob) |
1585 | { |
1573 | { |
1586 | int i; |
|
|
1587 | |
|
|
1588 | if (ob->move_status < 1 || ob->move_status > 8 || !(move_object (ob, ob->move_status || !(rndm (9))))) |
1574 | if (ob->move_status < 1 || ob->move_status > 8 || !(move_object (ob, ob->move_status || !(rndm (9))))) |
1589 | for (i = 0; i < 5; i++) |
1575 | for (int i = 0; i < 5; i++) |
1590 | if (move_object (ob, ob->move_status = rndm (8) + 1)) |
1576 | if (move_object (ob, ob->move_status = rndm (8) + 1)) |
1591 | return; |
1577 | return; |
1592 | } |
1578 | } |
1593 | |
1579 | |
1594 | void |
1580 | void |
1595 | check_earthwalls (object *op, maptile *m, int x, int y) |
1581 | check_earthwalls (object *op, maptile *m, int x, int y) |
1596 | { |
1582 | { |
1597 | object *tmp; |
|
|
1598 | |
|
|
1599 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) |
1583 | for (object *tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) |
1600 | { |
|
|
1601 | if (tmp->type == EARTHWALL) |
1584 | if (tmp->type == EARTHWALL) |
1602 | { |
1585 | { |
1603 | hit_player (tmp, op->stats.dam, op, AT_PHYSICAL, 1); |
1586 | hit_player (tmp, op->stats.dam, op, AT_PHYSICAL, 1); |
1604 | return; |
1587 | return; |
1605 | } |
1588 | } |
1606 | } |
|
|
1607 | } |
1589 | } |
1608 | |
1590 | |
1609 | void |
1591 | void |
1610 | check_doors (object *op, maptile *m, int x, int y) |
1592 | check_doors (object *op, maptile *m, int x, int y) |
1611 | { |
1593 | { |
1612 | object *tmp; |
|
|
1613 | |
|
|
1614 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) |
1594 | for (object *tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) |
1615 | { |
|
|
1616 | if (tmp->type == DOOR) |
1595 | if (tmp->type == DOOR) |
1617 | { |
1596 | { |
1618 | hit_player (tmp, 1000, op, AT_PHYSICAL, 1); |
1597 | hit_player (tmp, 1000, op, AT_PHYSICAL, 1); |
1619 | return; |
1598 | return; |
1620 | } |
1599 | } |
1621 | } |
|
|
1622 | } |
1600 | } |
1623 | |
1601 | |
1624 | /* find_mon_throw_ob() - modeled on find_throw_ob |
1602 | /* find_mon_throw_ob() - modeled on find_throw_ob |
1625 | * This is probably overly simplistic as it is now - We want |
1603 | * This is probably overly simplistic as it is now - We want |
1626 | * monsters to throw things like chairs and other pieces of |
1604 | * monsters to throw things like chairs and other pieces of |
… | |
… | |
1682 | return 0; |
1660 | return 0; |
1683 | |
1661 | |
1684 | get_rangevector (op, enemy, rv, 0); |
1662 | get_rangevector (op, enemy, rv, 0); |
1685 | |
1663 | |
1686 | /* Monsters always ignore the DM */ |
1664 | /* Monsters always ignore the DM */ |
1687 | if ((op->type != PLAYER) && QUERY_FLAG (enemy, FLAG_WIZ)) |
1665 | if (op->type != PLAYER && QUERY_FLAG (enemy, FLAG_WIZ)) |
1688 | return 0; |
1666 | return 0; |
1689 | |
1667 | |
1690 | /* simple check. Should probably put some range checks in here. */ |
1668 | /* simple check. Should probably put some range checks in here. */ |
1691 | if (can_see_enemy (op, enemy)) |
1669 | if (can_see_enemy (op, enemy)) |
1692 | return 1; |
1670 | return 1; |
… | |
… | |
1705 | |
1683 | |
1706 | /* use this for invis also */ |
1684 | /* use this for invis also */ |
1707 | hide_discovery = op->stats.Int / 5; |
1685 | hide_discovery = op->stats.Int / 5; |
1708 | |
1686 | |
1709 | /* Determine Detection radii */ |
1687 | /* Determine Detection radii */ |
1710 | if (!enemy->hide) /* to detect non-hidden (eg dark/invis enemy) */ |
1688 | if (!enemy->flag [FLAG_HIDDEN]) /* to detect non-hidden (eg dark/invis enemy) */ |
1711 | radius = max (MIN_MON_RADIUS, op->stats.Wis / 5 + 1); |
1689 | radius = max (MIN_MON_RADIUS, op->stats.Wis / 5 + 1); |
1712 | else |
1690 | else |
1713 | { /* a level/INT/Dex adjustment for hiding */ |
1691 | { /* a level/INT/Dex adjustment for hiding */ |
1714 | int bonus = op->level / 2 + op->stats.Int / 5; |
1692 | int bonus = op->level / 2 + op->stats.Int / 5; |
1715 | |
1693 | |
1716 | if (enemy->type == PLAYER) |
1694 | if (enemy->is_player ()) |
1717 | { |
1695 | { |
1718 | if (object *sk_hide = find_skill_by_number (enemy, SK_HIDING)) |
1696 | if (object *sk_hide = find_skill_by_number (enemy, SK_HIDING)) |
1719 | bonus -= sk_hide->level; |
1697 | bonus -= sk_hide->level; |
1720 | else |
1698 | else |
1721 | { |
1699 | { |
… | |
… | |
1738 | radius /= 2; |
1716 | radius /= 2; |
1739 | hide_discovery /= 3; |
1717 | hide_discovery /= 3; |
1740 | } |
1718 | } |
1741 | |
1719 | |
1742 | /* Radii adjustment for enemy standing in the dark */ |
1720 | /* Radii adjustment for enemy standing in the dark */ |
1743 | if (op->map->darkness > 0 && !stand_in_light (enemy)) |
1721 | if (op->map->darklevel () > 0 && !stand_in_light (enemy)) |
1744 | { |
1722 | { |
1745 | /* on dark maps body heat can help indicate location with infravision |
1723 | /* on dark maps body heat can help indicate location with infravision |
1746 | * undead don't have body heat, so no benefit detecting them. |
1724 | * undead don't have body heat, so no benefit detecting them. |
1747 | */ |
1725 | */ |
1748 | if (QUERY_FLAG (op, FLAG_SEE_IN_DARK) && !is_true_undead (enemy)) |
1726 | if (QUERY_FLAG (op, FLAG_SEE_IN_DARK) && !is_true_undead (enemy)) |
1749 | radius += op->map->darkness / 2; |
1727 | radius += op->map->darklevel () / 2; |
1750 | else |
1728 | else |
1751 | radius -= op->map->darkness / 2; |
1729 | radius -= op->map->darklevel () / 2; |
1752 | |
1730 | |
1753 | /* op next to a monster (and not in complete darkness) |
1731 | /* op next to a monster (and not in complete darkness) |
1754 | * the monster should have a chance to see you. |
1732 | * the monster should have a chance to see you. |
1755 | */ |
1733 | */ |
1756 | if (radius < MIN_MON_RADIUS && op->map->darkness < 5 && rv->distance <= 1) |
1734 | if (radius < MIN_MON_RADIUS && op->map->darklevel () < 5 && rv->distance <= 1) |
1757 | radius = MIN_MON_RADIUS; |
1735 | radius = MIN_MON_RADIUS; |
1758 | } /* if on dark map */ |
1736 | } /* if on dark map */ |
1759 | |
1737 | |
1760 | /* Lets not worry about monsters that have incredible detection |
1738 | /* Lets not worry about monsters that have incredible detection |
1761 | * radii, we only need to worry here about things the player can |
1739 | * radii, we only need to worry here about things the player can |
… | |
… | |
1775 | /* ah, we are within range, detected? take cases */ |
1753 | /* ah, we are within range, detected? take cases */ |
1776 | if (!enemy->invisible) /* enemy in dark squares... are seen! */ |
1754 | if (!enemy->invisible) /* enemy in dark squares... are seen! */ |
1777 | return 1; |
1755 | return 1; |
1778 | |
1756 | |
1779 | /* hidden or low-quality invisible */ |
1757 | /* hidden or low-quality invisible */ |
1780 | if (enemy->hide && rv->distance <= 1 && rndm (100) <= hide_discovery) |
1758 | if (enemy->flag [FLAG_HIDDEN] && rv->distance <= 1 && rndm (100) <= hide_discovery) |
1781 | { |
1759 | { |
1782 | make_visible (enemy); |
1760 | make_visible (enemy); |
1783 | |
1761 | |
1784 | /* inform players of new status */ |
1762 | /* inform players of new status */ |
1785 | if (enemy->type == PLAYER && player_can_view (enemy, op)) |
1763 | if (enemy->type == PLAYER && player_can_view (enemy, op)) |
… | |
… | |
1816 | * other side of a wall (!). |
1794 | * other side of a wall (!). |
1817 | */ |
1795 | */ |
1818 | int |
1796 | int |
1819 | stand_in_light (object *op) |
1797 | stand_in_light (object *op) |
1820 | { |
1798 | { |
1821 | if (!op) |
1799 | if (op) |
1822 | return 0; |
1800 | { |
1823 | |
|
|
1824 | if (op->glow_radius > 0) |
1801 | if (op->glow_radius > 0) |
1825 | return 1; |
1802 | return 1; |
1826 | |
1803 | |
1827 | if (op->map) |
1804 | if (op->map) |
1828 | { |
1805 | unordered_mapwalk (op, -MAX_LIGHT_RADIUS, -MAX_LIGHT_RADIUS, MAX_LIGHT_RADIUS, MAX_LIGHT_RADIUS) |
|
|
1806 | { |
1829 | /* Check the spaces with the max light radius to see if any of them |
1807 | /* Check the spaces with the max light radius to see if any of them |
1830 | * have lights, and if any of them light the player enough, then return 1. |
1808 | * have lights, and if any of them light the player enough, then return 1. |
1831 | */ |
|
|
1832 | for (int x = op->x - MAX_LIGHT_RADII; x <= op->x + MAX_LIGHT_RADII; x++) |
|
|
1833 | { |
|
|
1834 | for (int y = op->y - MAX_LIGHT_RADII; y <= op->y + MAX_LIGHT_RADII; y++) |
|
|
1835 | { |
1809 | */ |
1836 | maptile *m = op->map; |
1810 | int light = m->at (nx, ny).light; |
1837 | sint16 nx = x; |
|
|
1838 | sint16 ny = y; |
|
|
1839 | |
1811 | |
1840 | if (xy_normalise (m, nx, ny)) |
1812 | if (expect_false (light > 0) && idistance (dx, dy) <= light) |
1841 | if (idistance (x - op->x, y - op->y) < m->at (nx, ny).light) |
|
|
1842 | return 1; |
1813 | return 1; |
1843 | } |
1814 | } |
1844 | } |
|
|
1845 | } |
1815 | } |
1846 | |
1816 | |
1847 | return 0; |
1817 | return 0; |
1848 | } |
1818 | } |
1849 | |
1819 | |
… | |
… | |
1875 | * However,if you carry any source of light, then the hidden |
1845 | * However,if you carry any source of light, then the hidden |
1876 | * creature is seeable (and stupid) */ |
1846 | * creature is seeable (and stupid) */ |
1877 | |
1847 | |
1878 | if (has_carried_lights (enemy)) |
1848 | if (has_carried_lights (enemy)) |
1879 | { |
1849 | { |
1880 | if (enemy->hide) |
1850 | if (enemy->flag [FLAG_HIDDEN]) |
1881 | { |
1851 | { |
1882 | make_visible (enemy); |
1852 | make_visible (enemy); |
1883 | new_draw_info (NDI_UNIQUE, 0, enemy, "Your light reveals your hiding spot!"); |
1853 | new_draw_info (NDI_UNIQUE, 0, enemy, "Your light reveals your hiding spot!"); |
1884 | } |
1854 | } |
|
|
1855 | |
1885 | return 1; |
1856 | return 1; |
1886 | } |
1857 | } |
1887 | else if (enemy->hide) |
1858 | else if (enemy->flag [FLAG_HIDDEN]) |
1888 | return 0; |
1859 | return 0; |
1889 | |
1860 | |
1890 | /* Invisible enemy. Break apart the check for invis undead/invis looker |
1861 | /* Invisible enemy. Break apart the check for invis undead/invis looker |
1891 | * into more simple checks - the QUERY_FLAG doesn't return 1/0 values, |
1862 | * into more simple checks - the QUERY_FLAG doesn't return 1/0 values, |
1892 | * and making it a conditional makes the code pretty ugly. |
1863 | * and making it a conditional makes the code pretty ugly. |
1893 | */ |
1864 | */ |
1894 | if (!QUERY_FLAG (looker, FLAG_SEE_INVISIBLE)) |
1865 | if (!QUERY_FLAG (looker, FLAG_SEE_INVISIBLE)) |
1895 | { |
|
|
1896 | if (makes_invisible_to (enemy, looker)) |
1866 | if (makes_invisible_to (enemy, looker)) |
1897 | return 0; |
1867 | return 0; |
1898 | } |
|
|
1899 | } |
1868 | } |
1900 | else if (looker->type == PLAYER) /* for players, a (possible) shortcut */ |
1869 | else if (looker->is_player ()) /* for players, a (possible) shortcut */ |
1901 | if (player_can_view (looker, enemy)) |
1870 | if (player_can_view (looker, enemy)) |
1902 | return 1; |
1871 | return 1; |
1903 | |
1872 | |
1904 | /* ENEMY IN DARK MAP. Without infravision, the enemy is not seen |
1873 | /* ENEMY IN DARK MAP. Without infravision, the enemy is not seen |
1905 | * unless they carry a light or stand in light. Darkness doesnt |
1874 | * unless they carry a light or stand in light. Darkness doesnt |
… | |
… | |
1908 | * we care about the enemy maps status, not the looker. |
1877 | * we care about the enemy maps status, not the looker. |
1909 | * only relevant for tiled maps, but it is possible that the |
1878 | * only relevant for tiled maps, but it is possible that the |
1910 | * enemy is on a bright map and the looker on a dark - in that |
1879 | * enemy is on a bright map and the looker on a dark - in that |
1911 | * case, the looker can still see the enemy |
1880 | * case, the looker can still see the enemy |
1912 | */ |
1881 | */ |
1913 | if (enemy->map->darkness > 0 && !stand_in_light (enemy) |
1882 | if (enemy->map->darklevel () > 0 |
|
|
1883 | && !stand_in_light (enemy) |
1914 | && (!QUERY_FLAG (looker, FLAG_SEE_IN_DARK) || !is_true_undead (looker) || !QUERY_FLAG (looker, FLAG_XRAYS))) |
1884 | && (!QUERY_FLAG (looker, FLAG_SEE_IN_DARK) || !is_true_undead (looker) || !QUERY_FLAG (looker, FLAG_XRAYS))) |
1915 | return 0; |
1885 | return 0; |
1916 | |
1886 | |
1917 | return 1; |
1887 | return 1; |
1918 | } |
1888 | } |
|
|
1889 | |