* for PR#259 - paranoid_confirm:trap * * Will a monster suffer any adverse effects from a certain trap? * Note: does NOT mean "will a monster trigger a trap in the first place", * though if it won't that does imply that they'll not suffer adverse effects. * For example, an elf is considered immune to sleeping gas traps even though * they'll set the trap off. * Return value: * TRAP_NOT_IMM
| 2780 | * be warned of this trap, while monsters implicitly know they're immune. |
| 2781 | */ |
| 2782 | int |
| 2783 | immune_to_trap(struct monst *mon, unsigned ttype) |
| 2784 | { |
| 2785 | struct permonst *pm; |
| 2786 | struct obj *obj; |
| 2787 | boolean is_you; |
| 2788 | |
| 2789 | if (!mon) { |
| 2790 | impossible("immune_to_trap: null monster"); |
| 2791 | return TRAP_NOT_IMMUNE; |
| 2792 | } |
| 2793 | pm = mon->data; |
| 2794 | is_you = (mon == &gy.youmonst); |
| 2795 | |
| 2796 | switch (ttype) { |
| 2797 | case ARROW_TRAP: |
| 2798 | case DART_TRAP: |
| 2799 | case ROCKTRAP: |
| 2800 | /* can hit anything; even noncorporeal monsters might get a blessed |
| 2801 | projectile */ |
| 2802 | return TRAP_NOT_IMMUNE; |
| 2803 | case BEAR_TRAP: |
| 2804 | if (pm->msize <= MZ_SMALL |
| 2805 | || amorphous(pm) || is_whirly(pm) || unsolid(pm)) |
| 2806 | return TRAP_CLEARLY_IMMUNE; |
| 2807 | FALLTHROUGH; |
| 2808 | /*FALLTHRU*/ |
| 2809 | case SQKY_BOARD: |
| 2810 | case LANDMINE: |
| 2811 | case ROLLING_BOULDER_TRAP: |
| 2812 | case HOLE: |
| 2813 | case TRAPDOOR: |
| 2814 | case PIT: |
| 2815 | case SPIKED_PIT: |
| 2816 | /* ground-based traps, which can be evaded by levitation, flying, or |
| 2817 | hanging to the ceiling */ |
| 2818 | if (Sokoban && (is_pit(ttype) || is_hole(ttype))) |
| 2819 | return TRAP_NOT_IMMUNE; |
| 2820 | if (In_sokoban(&u.uz) && ttype == ROLLING_BOULDER_TRAP) |
| 2821 | return TRAP_CLEARLY_IMMUNE; /* not dangerous in Sokoban */ |
| 2822 | if (is_floater(pm) || is_flyer(pm) |
| 2823 | || (is_clinger(pm) && has_ceiling(&u.uz))) |
| 2824 | return TRAP_CLEARLY_IMMUNE; |
| 2825 | else if (is_you && (Levitation || Flying)) |
| 2826 | return TRAP_CLEARLY_IMMUNE; |
| 2827 | return TRAP_NOT_IMMUNE; |
| 2828 | case SLP_GAS_TRAP: |
| 2829 | if (breathless(pm)) |
| 2830 | return TRAP_CLEARLY_IMMUNE; |
| 2831 | else if (!is_you && resists_sleep(mon)) |
| 2832 | return TRAP_CLEARLY_IMMUNE; |
| 2833 | else if (is_you && Sleep_resistance) |
| 2834 | return TRAP_HIDDEN_IMMUNE; |
| 2835 | return TRAP_NOT_IMMUNE; |
| 2836 | case LEVEL_TELEP: |
| 2837 | case TELEP_TRAP: |
| 2838 | /* consider unintended teleporting to be an adverse effect; if in |
| 2839 | the endgame or carrying the Amulet, the teleport trap won't work |
no test coverage detected