# Source:NetHack 3.6.1/src/trap.c
Below is the full text to trap.c from the source code of NetHack 3.6.1. To link to a particular line, write [[Source:NetHack 3.6.1/src/trap.c#line123]], for example.

Contents

1 Top of file
2 burnarmor
3 erode_obj
4 grease_protect
5 maketrap
6 fall_through
7 animate_statue
8 activate_statue_trap
9 keep_saddle_with_steedcorpse
10 mu_maybe_destroy_web
11 dotrap
12 trapnote
13 steedintrap
14 blow_up_landmine
15 launch_drop_spot
16 launch_in_progress
17 force_launch_placement
18 launch_obj
19 seetrap
20 feeltrap
21 mkroll_launch
22 isclearpath
23 mintrap
24 instapetrify
25 minstapetrify
26 selftouch
27 mselftouch
28 float_up
29 fill_pit
30 float_down
31 climb_pit
32 dofiretrap
33 domagictrap
34 fire_damage
35 fire_damage_chain
36 lava_damage
37 acid_damage
38 water_damage
39 water_damage_chain
40 emergency_disrobe
41 drown
42 drain_en
43 dountrap
44 untrap_prob
45 cnv_trap_obj
46 move_into_trap
47 try_disarm
48 reward_untrap
49 disarm_holdingtrap
50 disarm_landmine
51 disarm_squeaky_board
52 disarm_shooting_trap
53 try_lift
54 help_monster_out
55 untrap
56 openholdingtrap
57 closeholdingtrap
58 openfallingtrap
59 chest_trap
60 t_at
61 deltrap
62 conjoined_pits
63 clear_conjoined_pits
64 adj_nonconjoined_pit
65 uteetering_at_seen_pit
66 delfloortrap
67 b_trapped
68 thitm
69 unconscious
70 lava_effects
71 sink_into_lava
72 sokoban_guilt
73 maybe_finish_sokoban

Top of file
&nbsp;/* NetHack 3.6	trap.c	$NHDT-Date: 1524312044 2018/04/21 12:00:44 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.290 $ */
&nbsp;/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
&nbsp;/*-Copyright (c) Robert Patrick Rankin, 2013. */
&nbsp;/* NetHack may be freely redistributed.  See license for details. */

The NetHack General Public License applies to screenshots, source code and other content from NetHack.
This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

&nbsp;
&nbsp;#include "hack.h"
&nbsp;
&nbsp;extern const char *const destroy_strings[][3]; /* from zap.c */
&nbsp;
&nbsp;STATIC_DCL void FDECL(dofiretrap, (struct obj *));
&nbsp;STATIC_DCL void NDECL(domagictrap);
&nbsp;STATIC_DCL boolean FDECL(emergency_disrobe, (boolean *));
&nbsp;STATIC_DCL int FDECL(untrap_prob, (struct trap *));
&nbsp;STATIC_DCL void FDECL(move_into_trap, (struct trap *));
&nbsp;STATIC_DCL int FDECL(try_disarm, (struct trap *, BOOLEAN_P));
&nbsp;STATIC_DCL void FDECL(reward_untrap, (struct trap *, struct monst *));
&nbsp;STATIC_DCL int FDECL(disarm_holdingtrap, (struct trap *));
&nbsp;STATIC_DCL int FDECL(disarm_landmine, (struct trap *));
&nbsp;STATIC_DCL int FDECL(disarm_squeaky_board, (struct trap *));
&nbsp;STATIC_DCL int FDECL(disarm_shooting_trap, (struct trap *, int));
&nbsp;STATIC_DCL int FDECL(try_lift, (struct monst *, struct trap *, int,
&nbsp;                                BOOLEAN_P));
&nbsp;STATIC_DCL int FDECL(help_monster_out, (struct monst *, struct trap *));
&nbsp;STATIC_DCL boolean FDECL(thitm, (int, struct monst *, struct obj *, int,
&nbsp;                                 BOOLEAN_P));
&nbsp;STATIC_DCL void FDECL(launch_drop_spot, (struct obj *, XCHAR_P, XCHAR_P));
&nbsp;STATIC_DCL int FDECL(mkroll_launch, (struct trap *, XCHAR_P, XCHAR_P,
&nbsp;                                     SHORT_P, long));
&nbsp;STATIC_DCL boolean FDECL(isclearpath, (coord *, int, SCHAR_P, SCHAR_P));
&nbsp;STATIC_DCL char *FDECL(trapnote, (struct trap *, BOOLEAN_P));
&nbsp;#if 0
&nbsp;STATIC_DCL void FDECL(join_adjacent_pits, (struct trap *));
&nbsp;#endif
&nbsp;STATIC_DCL void FDECL(clear_conjoined_pits, (struct trap *));
&nbsp;STATIC_DCL boolean FDECL(adj_nonconjoined_pit, (struct trap *));
&nbsp;
&nbsp;STATIC_DCL int FDECL(steedintrap, (struct trap *, struct obj *));
&nbsp;STATIC_DCL boolean FDECL(keep_saddle_with_steedcorpse, (unsigned,
&nbsp;                                                        struct obj *,
&nbsp;                                                        struct obj *));
&nbsp;STATIC_DCL void NDECL(maybe_finish_sokoban);
&nbsp;
&nbsp;/* mintrap() should take a flags argument, but for time being we use this */
&nbsp;STATIC_VAR int force_mintrap = 0;
&nbsp;
&nbsp;STATIC_VAR const char *const a_your[2] = { "a", "your" };
&nbsp;STATIC_VAR const char *const A_Your[2] = { "A", "Your" };
&nbsp;STATIC_VAR const char tower_of_flame[] = "tower of flame";
&nbsp;STATIC_VAR const char *const A_gush_of_water_hits = "A gush of water hits";
&nbsp;STATIC_VAR const char *const blindgas[6] = { "humid",   "odorless",
&nbsp;                                             "pungent", "chilling",
&nbsp;                                             "acrid",   "biting" };
&nbsp;
burnarmor
&nbsp;/* called when you're hit by fire (dofiretrap,buzz,zapyourself,explode);
&nbsp;   returns TRUE if hit on torso */
&nbsp;boolean
&nbsp;burnarmor(victim)
&nbsp;struct monst *victim;
&nbsp;{
&nbsp;    struct obj *item;
&nbsp;    char buf[BUFSZ];
&nbsp;    int mat_idx, oldspe;
&nbsp;    boolean hitting_u;
&nbsp;
&nbsp;    if (!victim)
&nbsp;        return 0;
&nbsp;    hitting_u = (victim == &amp;youmonst);
&nbsp;
&nbsp;    /* burning damage may dry wet towel */
&nbsp;    item = hitting_u ? carrying(TOWEL) : m_carrying(victim, TOWEL);
&nbsp;    while (item) {
&nbsp;        if (is_wet_towel(item)) {
&nbsp;            oldspe = item-&gt;spe;
&nbsp;            dry_a_towel(item, rn2(oldspe + 1), TRUE);
&nbsp;            if (item-&gt;spe != oldspe)
&nbsp;                break; /* stop once one towel has been affected */
&nbsp;        }
&nbsp;        item = item-&gt;nobj;
&nbsp;    }
&nbsp;
&nbsp;#define burn_dmg(obj, descr) erode_obj(obj, descr, ERODE_BURN, EF_GREASE)
&nbsp;    while (1) {
&nbsp;        switch (rn2(5)) {
&nbsp;        case 0:
&nbsp;            item = hitting_u ? uarmh : which_armor(victim, W_ARMH);
&nbsp;            if (item) {
&nbsp;                mat_idx = objects[item-&gt;otyp].oc_material;
&nbsp;                Sprintf(buf, "%s %s", materialnm[mat_idx],
&nbsp;                        helm_simple_name(item));
&nbsp;            }
&nbsp;            if (!burn_dmg(item, item ? buf : "helmet"))
&nbsp;                continue;
&nbsp;            break;
&nbsp;        case 1:
&nbsp;            item = hitting_u ? uarmc : which_armor(victim, W_ARMC);
&nbsp;            if (item) {
&nbsp;                (void) burn_dmg(item, cloak_simple_name(item));
&nbsp;                return TRUE;
&nbsp;            }
&nbsp;            item = hitting_u ? uarm : which_armor(victim, W_ARM);
&nbsp;            if (item) {
&nbsp;                (void) burn_dmg(item, xname(item));
&nbsp;                return TRUE;
&nbsp;            }
&nbsp;            item = hitting_u ? uarmu : which_armor(victim, W_ARMU);
&nbsp;            if (item)
&nbsp;                (void) burn_dmg(item, "shirt");
&nbsp;            return TRUE;
&nbsp;        case 2:
&nbsp;            item = hitting_u ? uarms : which_armor(victim, W_ARMS);
&nbsp;            if (!burn_dmg(item, "wooden shield"))
&nbsp;                continue;
&nbsp;            break;
&nbsp;        case 3:
&nbsp;            item = hitting_u ? uarmg : which_armor(victim, W_ARMG);
&nbsp;            if (!burn_dmg(item, "gloves"))
&nbsp;                continue;
&nbsp;            break;
&nbsp;        case 4:
&nbsp;            item = hitting_u ? uarmf : which_armor(victim, W_ARMF);
&nbsp;            if (!burn_dmg(item, "boots"))
&nbsp;                continue;
&nbsp;            break;
&nbsp;        }
&nbsp;        break; /* Out of while loop */
&nbsp;    }
&nbsp;#undef burn_dmg
&nbsp;
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
erode_obj
&nbsp;/* Generic erode-item function.
&nbsp; * "ostr", if non-null, is an alternate string to print instead of the
&nbsp; *   object's name.
&nbsp; * "type" is an ERODE_* value for the erosion type
&nbsp; * "flags" is an or-ed list of EF_* flags
&nbsp; *
&nbsp; * Returns an erosion return value (ER_*)
&nbsp; */
&nbsp;int
&nbsp;erode_obj(otmp, ostr, type, ef_flags)
&nbsp;register struct obj *otmp;
&nbsp;const char *ostr;
&nbsp;int type;
&nbsp;int ef_flags;
&nbsp;{
&nbsp;    static NEARDATA const char
&nbsp;        *const action[] = { "smoulder", "rust", "rot", "corrode" },
&nbsp;        *const msg[] = { "burnt", "rusted", "rotten", "corroded" },
&nbsp;        *const bythe[] = { "heat", "oxidation", "decay", "corrosion" };
&nbsp;    boolean vulnerable = FALSE, is_primary = TRUE,
&nbsp;            check_grease = (ef_flags &amp; EF_GREASE) ? TRUE : FALSE,
&nbsp;            print = (ef_flags &amp; EF_VERBOSE) ? TRUE : FALSE,
&nbsp;            uvictim, vismon, visobj;
&nbsp;    int erosion, cost_type;
&nbsp;    struct monst *victim;
&nbsp;
&nbsp;    if (!otmp)
&nbsp;        return ER_NOTHING;
&nbsp;
&nbsp;    victim = carried(otmp) ? &amp;youmonst : mcarried(otmp) ? otmp-&gt;ocarry : NULL;
&nbsp;    uvictim = (victim == &amp;youmonst);
&nbsp;    vismon = victim &amp;&amp; (victim != &amp;youmonst) &amp;&amp; canseemon(victim);
&nbsp;    /* Is bhitpos correct here? Ugh. */
&nbsp;    visobj = !victim &amp;&amp; cansee(bhitpos.x, bhitpos.y);
&nbsp;
&nbsp;    switch (type) {
&nbsp;    case ERODE_BURN:
&nbsp;        vulnerable = is_flammable(otmp);
&nbsp;        check_grease = FALSE;
&nbsp;        cost_type = COST_BURN;
&nbsp;        break;
&nbsp;    case ERODE_RUST:
&nbsp;        vulnerable = is_rustprone(otmp);
&nbsp;        cost_type = COST_RUST;
&nbsp;        break;
&nbsp;    case ERODE_ROT:
&nbsp;        vulnerable = is_rottable(otmp);
&nbsp;        check_grease = FALSE;
&nbsp;        is_primary = FALSE;
&nbsp;        cost_type = COST_ROT;
&nbsp;        break;
&nbsp;    case ERODE_CORRODE:
&nbsp;        vulnerable = is_corrodeable(otmp);
&nbsp;        is_primary = FALSE;
&nbsp;        cost_type = COST_CORRODE;
&nbsp;        break;
&nbsp;    default:
&nbsp;        impossible("Invalid erosion type in erode_obj");
&nbsp;        return ER_NOTHING;
&nbsp;    }
&nbsp;    erosion = is_primary ? otmp-&gt;oeroded : otmp-&gt;oeroded2;
&nbsp;
&nbsp;    if (!ostr)
&nbsp;        ostr = cxname(otmp);
&nbsp;    /* 'visobj' messages insert "the"; probably ought to switch to the() */
&nbsp;    if (visobj &amp;&amp; !(uvictim || vismon) &amp;&amp; !strncmpi(ostr, "the ", 4))
&nbsp;        ostr += 4;
&nbsp;
&nbsp;    if (check_grease &amp;&amp; otmp-&gt;greased) {
&nbsp;        grease_protect(otmp, ostr, victim);
&nbsp;        return ER_GREASED;
&nbsp;    } else if (!erosion_matters(otmp)) {
&nbsp;        return ER_NOTHING;
&nbsp;    } else if (!vulnerable || (otmp-&gt;oerodeproof &amp;&amp; otmp-&gt;rknown)) {
&nbsp;        if (flags.verbose &amp;&amp; print &amp;&amp; (uvictim || vismon))
&nbsp;            pline("%s %s %s not affected by %s.",
&nbsp;                  uvictim ? "Your" : s_suffix(Monnam(victim)),
&nbsp;                  ostr, vtense(ostr, "are"), bythe[type]);
&nbsp;        return ER_NOTHING;
&nbsp;    } else if (otmp-&gt;oerodeproof || (otmp-&gt;blessed &amp;&amp; !rnl(4))) {
&nbsp;        if (flags.verbose &amp;&amp; (print || otmp-&gt;oerodeproof)
&nbsp;            &amp;&amp; (uvictim || vismon || visobj))
&nbsp;            pline("Somehow, %s %s %s not affected by the %s.",
&nbsp;                  uvictim ? "your"
&nbsp;                          : !vismon ? "the" /* visobj */
&nbsp;                                    : s_suffix(mon_nam(victim)),
&nbsp;                  ostr, vtense(ostr, "are"), bythe[type]);
&nbsp;        /* We assume here that if the object is protected because it
&nbsp;         * is blessed, it still shows some minor signs of wear, and
&nbsp;         * the hero can distinguish this from an object that is
&nbsp;         * actually proof against damage.
&nbsp;         */
&nbsp;        if (otmp-&gt;oerodeproof) {
&nbsp;            otmp-&gt;rknown = TRUE;
&nbsp;            if (victim == &amp;youmonst)
&nbsp;                update_inventory();
&nbsp;        }
&nbsp;
&nbsp;        return ER_NOTHING;
&nbsp;    } else if (erosion &lt; MAX_ERODE) {
&nbsp;        const char *adverb = (erosion + 1 == MAX_ERODE)
&nbsp;                                 ? " completely"
&nbsp;                                 : erosion ? " further" : "";
&nbsp;
&nbsp;        if (uvictim || vismon || visobj)
&nbsp;            pline("%s %s %s%s!",
&nbsp;                  uvictim ? "Your"
&nbsp;                          : !vismon ? "The" /* visobj */
&nbsp;                                    : s_suffix(Monnam(victim)),
&nbsp;                  ostr, vtense(ostr, action[type]), adverb);
&nbsp;
&nbsp;        if (ef_flags &amp; EF_PAY)
&nbsp;            costly_alteration(otmp, cost_type);
&nbsp;
&nbsp;        if (is_primary)
&nbsp;            otmp-&gt;oeroded++;
&nbsp;        else
&nbsp;            otmp-&gt;oeroded2++;
&nbsp;
&nbsp;        if (victim == &amp;youmonst)
&nbsp;            update_inventory();
&nbsp;
&nbsp;        return ER_DAMAGED;
&nbsp;    } else if (ef_flags &amp; EF_DESTROY) {
&nbsp;        if (uvictim || vismon || visobj)
&nbsp;            pline("%s %s %s away!",
&nbsp;                  uvictim ? "Your"
&nbsp;                          : !vismon ? "The" /* visobj */
&nbsp;                                    : s_suffix(Monnam(victim)),
&nbsp;                  ostr, vtense(ostr, action[type]));
&nbsp;
&nbsp;        if (ef_flags &amp; EF_PAY)
&nbsp;            costly_alteration(otmp, cost_type);
&nbsp;
&nbsp;        setnotworn(otmp);
&nbsp;        delobj(otmp);
&nbsp;        return ER_DESTROYED;
&nbsp;    } else {
&nbsp;        if (flags.verbose &amp;&amp; print) {
&nbsp;            if (uvictim)
&nbsp;                Your("%s %s completely %s.",
&nbsp;                     ostr, vtense(ostr, Blind ? "feel" : "look"), msg[type]);
&nbsp;            else if (vismon || visobj)
&nbsp;                pline("%s %s %s completely %s.",
&nbsp;                      !vismon ? "The" : s_suffix(Monnam(victim)),
&nbsp;                      ostr, vtense(ostr, "look"), msg[type]);
&nbsp;        }
&nbsp;        return ER_NOTHING;
&nbsp;    }
&nbsp;}
&nbsp;
grease_protect
&nbsp;/* Protect an item from erosion with grease. Returns TRUE if the grease
&nbsp; * wears off.
&nbsp; */
&nbsp;boolean
&nbsp;grease_protect(otmp, ostr, victim)
&nbsp;register struct obj *otmp;
&nbsp;const char *ostr;
&nbsp;struct monst *victim;
&nbsp;{
&nbsp;    static const char txt[] = "protected by the layer of grease!";
&nbsp;    boolean vismon = victim &amp;&amp; (victim != &amp;youmonst) &amp;&amp; canseemon(victim);
&nbsp;
&nbsp;    if (ostr) {
&nbsp;        if (victim == &amp;youmonst)
&nbsp;            Your("%s %s %s", ostr, vtense(ostr, "are"), txt);
&nbsp;        else if (vismon)
&nbsp;            pline("%s's %s %s %s", Monnam(victim),
&nbsp;                  ostr, vtense(ostr, "are"), txt);
&nbsp;    } else if (victim == &amp;youmonst || vismon) {
&nbsp;        pline("%s %s", Yobjnam2(otmp, "are"), txt);
&nbsp;    }
&nbsp;    if (!rn2(2)) {
&nbsp;        otmp-&gt;greased = 0;
&nbsp;        if (carried(otmp)) {
&nbsp;            pline_The("grease dissolves.");
&nbsp;            update_inventory();
&nbsp;        }
&nbsp;        return TRUE;
&nbsp;    }
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
maketrap
&nbsp;struct trap *
&nbsp;maketrap(x, y, typ)
&nbsp;int x, y, typ;
&nbsp;{
&nbsp;    static union vlaunchinfo zero_vl;
&nbsp;    boolean oldplace;
&nbsp;    struct trap *ttmp;
&nbsp;    struct rm *lev = &amp;levl[x][y];
&nbsp;
&nbsp;    if ((ttmp = t_at(x, y)) != 0) {
&nbsp;        if (ttmp-&gt;ttyp == MAGIC_PORTAL || ttmp-&gt;ttyp == VIBRATING_SQUARE)
&nbsp;            return (struct trap *) 0;
&nbsp;        oldplace = TRUE;
&nbsp;        if (u.utrap &amp;&amp; x == u.ux &amp;&amp; y == u.uy
&nbsp;            &amp;&amp; ((u.utraptype == TT_BEARTRAP &amp;&amp; typ != BEAR_TRAP)
&nbsp;                || (u.utraptype == TT_WEB &amp;&amp; typ != WEB)
&nbsp;                || (u.utraptype == TT_PIT &amp;&amp; typ != PIT
&nbsp;                    &amp;&amp; typ != SPIKED_PIT)))
&nbsp;            u.utrap = 0;
&nbsp;        /* old 

<tx,ty> remain valid */
&nbsp;    } else if (IS_FURNITURE(lev-&gt;typ)
&nbsp;               &amp;&amp; (!IS_GRAVE(lev-&gt;typ) || (typ != PIT &amp;&amp; typ != HOLE))) {
&nbsp;        /* no trap on top of furniture (caller usually screens the
&nbsp;           location to inhibit this, but wizard mode wishing doesn't) */
&nbsp;        return (struct trap *) 0;
&nbsp;    } else {
&nbsp;        oldplace = FALSE;
&nbsp;        ttmp = newtrap();
&nbsp;        (void) memset((genericptr_t)ttmp, 0, sizeof(struct trap));
&nbsp;        ttmp-&gt;ntrap = 0;
&nbsp;        ttmp-&gt;tx = x;
&nbsp;        ttmp-&gt;ty = y;
&nbsp;    }
&nbsp;    /* [re-]initialize all fields except ntrap (handled below) and <tx,ty> */
&nbsp;    ttmp-&gt;vl = zero_vl;
&nbsp;    ttmp-&gt;launch.x = ttmp-&gt;launch.y = -1; /* force error if used before set */
&nbsp;    ttmp-&gt;dst.dnum = ttmp-&gt;dst.dlevel = -1;
&nbsp;    ttmp-&gt;madeby_u = 0;
&nbsp;    ttmp-&gt;once = 0;
&nbsp;    ttmp-&gt;tseen = (typ == HOLE); /* hide non-holes */
&nbsp;    ttmp-&gt;ttyp = typ;
&nbsp;
&nbsp;    switch (typ) {
&nbsp;    case SQKY_BOARD: {
&nbsp;        int tavail[12], tpick[12], tcnt = 0, k;
&nbsp;        struct trap *t;
&nbsp;
&nbsp;        for (k = 0; k &lt; 12; ++k)
&nbsp;            tavail[k] = tpick[k] = 0;
&nbsp;        for (t = ftrap; t; t = t-&gt;ntrap)
&nbsp;            if (t-&gt;ttyp == SQKY_BOARD &amp;&amp; t != ttmp)
&nbsp;                tavail[t-&gt;tnote] = 1;
&nbsp;        /* now populate tpick[] with the available indices */
&nbsp;        for (k = 0; k &lt; 12; ++k)
&nbsp;            if (tavail[k] == 0)
&nbsp;                tpick[tcnt++] = k;
&nbsp;        /* choose an unused note; if all are in use, pick a random one */
&nbsp;        ttmp-&gt;tnote = (short) ((tcnt &gt; 0) ? tpick[rn2(tcnt)] : rn2(12));
&nbsp;        break;
&nbsp;    }
&nbsp;    case STATUE_TRAP: { /* create a "living" statue */
&nbsp;        struct monst *mtmp;
&nbsp;        struct obj *otmp, *statue;
&nbsp;        struct permonst *mptr;
&nbsp;        int trycount = 10;
&nbsp;
&nbsp;        do { /* avoid ultimately hostile co-aligned unicorn */
&nbsp;            mptr = &amp;mons[rndmonnum()];
&nbsp;        } while (--trycount &gt; 0 &amp;&amp; is_unicorn(mptr)
&nbsp;                 &amp;&amp; sgn(u.ualign.type) == sgn(mptr-&gt;maligntyp));
&nbsp;        statue = mkcorpstat(STATUE, (struct monst *) 0, mptr, x, y,
&nbsp;                            CORPSTAT_NONE);
&nbsp;        mtmp = makemon(&amp;mons[statue-&gt;corpsenm], 0, 0, MM_NOCOUNTBIRTH);
&nbsp;        if (!mtmp)
&nbsp;            break; /* should never happen */
&nbsp;        while (mtmp-&gt;minvent) {
&nbsp;            otmp = mtmp-&gt;minvent;
&nbsp;            otmp-&gt;owornmask = 0;
&nbsp;            obj_extract_self(otmp);
&nbsp;            (void) add_to_container(statue, otmp);
&nbsp;        }
&nbsp;        statue-&gt;owt = weight(statue);
&nbsp;        mongone(mtmp);
&nbsp;        break;
&nbsp;    }
&nbsp;    case ROLLING_BOULDER_TRAP: /* boulder will roll towards trigger */
&nbsp;        (void) mkroll_launch(ttmp, x, y, BOULDER, 1L);
&nbsp;        break;
&nbsp;    case PIT:
&nbsp;    case SPIKED_PIT:
&nbsp;        ttmp-&gt;conjoined = 0;
&nbsp;        /*FALLTHRU*/
&nbsp;    case HOLE:
&nbsp;    case TRAPDOOR:
&nbsp;        if (*in_rooms(x, y, SHOPBASE)
&nbsp;            &amp;&amp; (typ == HOLE || typ == TRAPDOOR
&nbsp;                || IS_DOOR(lev-&gt;typ) || IS_WALL(lev-&gt;typ)))
&nbsp;            add_damage(x, y, /* schedule repair */
&nbsp;                       ((IS_DOOR(lev-&gt;typ) || IS_WALL(lev-&gt;typ))
&nbsp;                        &amp;&amp; !context.mon_moving)
&nbsp;                           ? SHOP_HOLE_COST
&nbsp;                           : 0L);
&nbsp;        lev-&gt;doormask = 0;     /* subsumes altarmask, icedpool... */
&nbsp;        if (IS_ROOM(lev-&gt;typ)) /* &amp;&amp; !IS_AIR(lev-&gt;typ) */
&nbsp;            lev-&gt;typ = ROOM;
&nbsp;        /*
&nbsp;         * some cases which can happen when digging
&nbsp;         * down while phazing thru solid areas
&nbsp;         */
&nbsp;        else if (lev-&gt;typ == STONE || lev-&gt;typ == SCORR)
&nbsp;            lev-&gt;typ = CORR;
&nbsp;        else if (IS_WALL(lev-&gt;typ) || lev-&gt;typ == SDOOR)
&nbsp;            lev-&gt;typ = level.flags.is_maze_lev
&nbsp;                           ? ROOM
&nbsp;                           : level.flags.is_cavernous_lev ? CORR : DOOR;
&nbsp;
&nbsp;        unearth_objs(x, y);
&nbsp;        break;
&nbsp;    }
&nbsp;
&nbsp;    if (!oldplace) {
&nbsp;        ttmp-&gt;ntrap = ftrap;
&nbsp;        ftrap = ttmp;
&nbsp;    } else {
&nbsp;        /* oldplace;
&nbsp;           it shouldn't be possible to override a sokoban pit or hole
&nbsp;           with some other trap, but we'll check just to be safe */
&nbsp;        if (Sokoban)
&nbsp;            maybe_finish_sokoban();
&nbsp;    }
&nbsp;    return ttmp;
&nbsp;}
&nbsp;
fall_through
&nbsp;void
&nbsp;fall_through(td)
&nbsp;boolean td; /* td == TRUE : trap door or hole */
&nbsp;{
&nbsp;    d_level dtmp;
&nbsp;    char msgbuf[BUFSZ];
&nbsp;    const char *dont_fall = 0;
&nbsp;    int newlevel, bottom;
&nbsp;
&nbsp;    /* we'll fall even while levitating in Sokoban; otherwise, if we
&nbsp;       won't fall and won't be told that we aren't falling, give up now */
&nbsp;    if (Blind &amp;&amp; Levitation &amp;&amp; !Sokoban)
&nbsp;        return;
&nbsp;
&nbsp;    bottom = dunlevs_in_dungeon(&amp;u.uz);
&nbsp;    /* when in the upper half of the quest, don't fall past the
&nbsp;       middle "quest locate" level if hero hasn't been there yet */
&nbsp;    if (In_quest(&amp;u.uz)) {
&nbsp;        int qlocate_depth = qlocate_level.dlevel;
&nbsp;
&nbsp;        /* deepest reached &lt; qlocate implies current &lt; qlocate */
&nbsp;        if (dunlev_reached(&amp;u.uz) &lt; qlocate_depth)
&nbsp;            bottom = qlocate_depth; /* early cut-off */
&nbsp;    }
&nbsp;    newlevel = dunlev(&amp;u.uz); /* current level */
&nbsp;    do {
&nbsp;        newlevel++;
&nbsp;    } while (!rn2(4) &amp;&amp; newlevel &lt; bottom);
&nbsp;
&nbsp;    if (td) {
&nbsp;        struct trap *t = t_at(u.ux, u.uy);
&nbsp;
&nbsp;        feeltrap(t);
&nbsp;        if (!Sokoban) {
&nbsp;            if (t-&gt;ttyp == TRAPDOOR)
&nbsp;                pline("A trap door opens up under you!");
&nbsp;            else
&nbsp;                pline("There's a gaping hole under you!");
&nbsp;        }
&nbsp;    } else
&nbsp;        pline_The("%s opens up under you!", surface(u.ux, u.uy));
&nbsp;
&nbsp;    if (Sokoban &amp;&amp; Can_fall_thru(&amp;u.uz))
&nbsp;        ; /* KMH -- You can't escape the Sokoban level traps */
&nbsp;    else if (Levitation || u.ustuck
&nbsp;             || (!Can_fall_thru(&amp;u.uz) &amp;&amp; !levl[u.ux][u.uy].candig) || Flying
&nbsp;             || is_clinger(youmonst.data)
&nbsp;             || (Inhell &amp;&amp; !u.uevent.invoked &amp;&amp; newlevel == bottom)) {
&nbsp;        dont_fall = "don't fall in.";
&nbsp;    } else if (youmonst.data-&gt;msize &gt;= MZ_HUGE) {
&nbsp;        dont_fall = "don't fit through.";
&nbsp;    } else if (!next_to_u()) {
&nbsp;        dont_fall = "are jerked back by your pet!";
&nbsp;    }
&nbsp;    if (dont_fall) {
&nbsp;        You1(dont_fall);
&nbsp;        /* hero didn't fall through, but any objects here might */
&nbsp;        impact_drop((struct obj *) 0, u.ux, u.uy, 0);
&nbsp;        if (!td) {
&nbsp;            display_nhwindow(WIN_MESSAGE, FALSE);
&nbsp;            pline_The("opening under you closes up.");
&nbsp;        }
&nbsp;        return;
&nbsp;    }
&nbsp;
&nbsp;    if (*u.ushops)
&nbsp;        shopdig(1);
&nbsp;    if (Is_stronghold(&amp;u.uz)) {
&nbsp;        find_hell(&amp;dtmp);
&nbsp;    } else {
&nbsp;        int dist = newlevel - dunlev(&amp;u.uz);
&nbsp;        dtmp.dnum = u.uz.dnum;
&nbsp;        dtmp.dlevel = newlevel;
&nbsp;        if (dist &gt; 1)
&nbsp;            You("fall down a %s%sshaft!", dist &gt; 3 ? "very " : "",
&nbsp;                dist &gt; 2 ? "deep " : "");
&nbsp;    }
&nbsp;    if (!td)
&nbsp;        Sprintf(msgbuf, "The hole in the %s above you closes up.",
&nbsp;                ceiling(u.ux, u.uy));
&nbsp;
&nbsp;    schedule_goto(&amp;dtmp, FALSE, TRUE, 0, (char *) 0,
&nbsp;                  !td ? msgbuf : (char *) 0);
&nbsp;}
&nbsp;
animate_statue
&nbsp;/*
&nbsp; * Animate the given statue.  May have been via shatter attempt, trap,
&nbsp; * or stone to flesh spell.  Return a monster if successfully animated.
&nbsp; * If the monster is animated, the object is deleted.  If fail_reason
&nbsp; * is non-null, then fill in the reason for failure (or success).
&nbsp; *
&nbsp; * The cause of animation is:
&nbsp; *
&nbsp; *      ANIMATE_NORMAL  - hero "finds" the monster
&nbsp; *      ANIMATE_SHATTER - hero tries to destroy the statue
&nbsp; *      ANIMATE_SPELL   - stone to flesh spell hits the statue
&nbsp; *
&nbsp; * Perhaps x, y is not needed if we can use get_obj_location() to find
&nbsp; * the statue's location... ???
&nbsp; *
&nbsp; * Sequencing matters:
&nbsp; *      create monster; if it fails, give up with statue intact;
&nbsp; *      give "statue comes to life" message;
&nbsp; *      if statue belongs to shop, have shk give "you owe" message;
&nbsp; *      transfer statue contents to monster (after stolen_value());
&nbsp; *      delete statue.
&nbsp; *      [This ordering means that if the statue ends up wearing a cloak of
&nbsp; *       invisibility or a mummy wrapping, the visibility checks might be
&nbsp; *       wrong, but to avoid that we'd have to clone the statue contents
&nbsp; *       first in order to give them to the monster before checking their
&nbsp; *       shop status--it's not worth the hassle.]
&nbsp; */
&nbsp;struct monst *
&nbsp;animate_statue(statue, x, y, cause, fail_reason)
&nbsp;struct obj *statue;
&nbsp;xchar x, y;
&nbsp;int cause;
&nbsp;int *fail_reason;
&nbsp;{
&nbsp;    int mnum = statue-&gt;corpsenm;
&nbsp;    struct permonst *mptr = &amp;mons[mnum];
&nbsp;    struct monst *mon = 0, *shkp;
&nbsp;    struct obj *item;
&nbsp;    coord cc;
&nbsp;    boolean historic = (Role_if(PM_ARCHEOLOGIST)
&nbsp;                        &amp;&amp; (statue-&gt;spe &amp; STATUE_HISTORIC) != 0),
&nbsp;            golem_xform = FALSE, use_saved_traits;
&nbsp;    const char *comes_to_life;
&nbsp;    char statuename[BUFSZ], tmpbuf[BUFSZ];
&nbsp;    static const char historic_statue_is_gone[] =
&nbsp;        "that the historic statue is now gone";
&nbsp;
&nbsp;    if (cant_revive(&amp;mnum, TRUE, statue)) {
&nbsp;        /* mnum has changed; we won't be animating this statue as itself */
&nbsp;        if (mnum != PM_DOPPELGANGER)
&nbsp;            mptr = &amp;mons[mnum];
&nbsp;        use_saved_traits = FALSE;
&nbsp;    } else if (is_golem(mptr) &amp;&amp; cause == ANIMATE_SPELL) {
&nbsp;        /* statue of any golem hit by stone-to-flesh becomes flesh golem */
&nbsp;        golem_xform = (mptr != &amp;mons[PM_FLESH_GOLEM]);
&nbsp;        mnum = PM_FLESH_GOLEM;
&nbsp;        mptr = &amp;mons[PM_FLESH_GOLEM];
&nbsp;        use_saved_traits = (has_omonst(statue) &amp;&amp; !golem_xform);
&nbsp;    } else {
&nbsp;        use_saved_traits = has_omonst(statue);
&nbsp;    }
&nbsp;
&nbsp;    if (use_saved_traits) {
&nbsp;        /* restore a petrified monster */
&nbsp;        cc.x = x, cc.y = y;
&nbsp;        mon = montraits(statue, &amp;cc);
&nbsp;        if (mon &amp;&amp; mon-&gt;mtame &amp;&amp; !mon-&gt;isminion)
&nbsp;            wary_dog(mon, TRUE);
&nbsp;    } else {
&nbsp;        /* statues of unique monsters from bones or wishing end
&nbsp;           up here (cant_revive() sets mnum to be doppelganger;
&nbsp;           mptr reflects the original form for use by newcham()) */
&nbsp;        if ((mnum == PM_DOPPELGANGER &amp;&amp; mptr != &amp;mons[PM_DOPPELGANGER])
&nbsp;            /* block quest guards from other roles */
&nbsp;            || (mptr-&gt;msound == MS_GUARDIAN
&nbsp;                &amp;&amp; quest_info(MS_GUARDIAN) != mnum)) {
&nbsp;            mon = makemon(&amp;mons[PM_DOPPELGANGER], x, y,
&nbsp;                          NO_MINVENT | MM_NOCOUNTBIRTH | MM_ADJACENTOK);
&nbsp;            /* if hero has protection from shape changers, cham field will
&nbsp;               be NON_PM; otherwise, set form to match the statue */
&nbsp;            if (mon &amp;&amp; mon-&gt;cham &gt;= LOW_PM)
&nbsp;                (void) newcham(mon, mptr, FALSE, FALSE);
&nbsp;        } else
&nbsp;            mon = makemon(mptr, x, y, (cause == ANIMATE_SPELL)
&nbsp;                                          ? (NO_MINVENT | MM_ADJACENTOK)
&nbsp;                                          : NO_MINVENT);
&nbsp;    }
&nbsp;
&nbsp;    if (!mon) {
&nbsp;        if (fail_reason)
&nbsp;            *fail_reason = unique_corpstat(&amp;mons[statue-&gt;corpsenm])
&nbsp;                               ? AS_MON_IS_UNIQUE
&nbsp;                               : AS_NO_MON;
&nbsp;        return (struct monst *) 0;
&nbsp;    }
&nbsp;
&nbsp;    /* a non-montraits() statue might specify gender */
&nbsp;    if (statue-&gt;spe &amp; STATUE_MALE)
&nbsp;        mon-&gt;female = FALSE;
&nbsp;    else if (statue-&gt;spe &amp; STATUE_FEMALE)
&nbsp;        mon-&gt;female = TRUE;
&nbsp;    /* if statue has been named, give same name to the monster */
&nbsp;    if (has_oname(statue) &amp;&amp; !unique_corpstat(mon-&gt;data))
&nbsp;        mon = christen_monst(mon, ONAME(statue));
&nbsp;    /* mimic statue becomes seen mimic; other hiders won't be hidden */
&nbsp;    if (mon-&gt;m_ap_type)
&nbsp;        seemimic(mon);
&nbsp;    else
&nbsp;        mon-&gt;mundetected = FALSE;
&nbsp;    mon-&gt;msleeping = 0;
&nbsp;    if (cause == ANIMATE_NORMAL || cause == ANIMATE_SHATTER) {
&nbsp;        /* trap always releases hostile monster */
&nbsp;        mon-&gt;mtame = 0; /* (might be petrified pet tossed onto trap) */
&nbsp;        mon-&gt;mpeaceful = 0;
&nbsp;        set_malign(mon);
&nbsp;    }
&nbsp;
&nbsp;    comes_to_life = !canspotmon(mon)
&nbsp;                        ? "disappears"
&nbsp;                        : golem_xform
&nbsp;                              ? "turns into flesh"
&nbsp;                              : (nonliving(mon-&gt;data) || is_vampshifter(mon))
&nbsp;                                    ? "moves"
&nbsp;                                    : "comes to life";
&nbsp;    if ((x == u.ux &amp;&amp; y == u.uy) || cause == ANIMATE_SPELL) {
&nbsp;        /* "the|your|Manlobbi's statue [of a wombat]" */
&nbsp;        shkp = shop_keeper(*in_rooms(mon-&gt;mx, mon-&gt;my, SHOPBASE));
&nbsp;        Sprintf(statuename, "%s%s", shk_your(tmpbuf, statue),
&nbsp;                (cause == ANIMATE_SPELL
&nbsp;                 /* avoid "of a shopkeeper" if it's Manlobbi himself
&nbsp;                    (if carried, it can't be unpaid--hence won't be
&nbsp;                    described as "Manlobbi's statue"--because there
&nbsp;                    wasn't any living shk when statue was picked up) */
&nbsp;                 &amp;&amp; (mon != shkp || carried(statue)))
&nbsp;                   ? xname(statue)
&nbsp;                   : "statue");
&nbsp;        pline("%s %s!", upstart(statuename), comes_to_life);
&nbsp;    } else if (Hallucination) { /* They don't know it's a statue */
&nbsp;        pline_The("%s suddenly seems more animated.", rndmonnam((char *) 0));
&nbsp;    } else if (cause == ANIMATE_SHATTER) {
&nbsp;        if (cansee(x, y))
&nbsp;            Sprintf(statuename, "%s%s", shk_your(tmpbuf, statue),
&nbsp;                    xname(statue));
&nbsp;        else
&nbsp;            Strcpy(statuename, "a statue");
&nbsp;        pline("Instead of shattering, %s suddenly %s!", statuename,
&nbsp;              comes_to_life);
&nbsp;    } else { /* cause == ANIMATE_NORMAL */
&nbsp;        You("find %s posing as a statue.",
&nbsp;            canspotmon(mon) ? a_monnam(mon) : something);
&nbsp;        if (!canspotmon(mon) &amp;&amp; Blind)
&nbsp;            map_invisible(x, y);
&nbsp;        stop_occupation();
&nbsp;    }
&nbsp;
&nbsp;    /* if this isn't caused by a monster using a wand of striking,
&nbsp;       there might be consequences for the hero */
&nbsp;    if (!context.mon_moving) {
&nbsp;        /* if statue is owned by a shop, hero will have to pay for it;
&nbsp;           stolen_value gives a message (about debt or use of credit)
&nbsp;           which refers to "it" so needs to follow a message describing
&nbsp;           the object ("the statue comes to life" one above) */
&nbsp;        if (cause != ANIMATE_NORMAL &amp;&amp; costly_spot(x, y)
&nbsp;            &amp;&amp; (carried(statue) ? statue-&gt;unpaid : !statue-&gt;no_charge)
&nbsp;            &amp;&amp; (shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) != 0
&nbsp;            /* avoid charging for Manlobbi's statue of Manlobbi
&nbsp;               if stone-to-flesh is used on petrified shopkeep */
&nbsp;            &amp;&amp; mon != shkp)
&nbsp;            (void) stolen_value(statue, x, y, (boolean) shkp-&gt;mpeaceful,
&nbsp;                                FALSE);
&nbsp;
&nbsp;        if (historic) {
&nbsp;            You_feel("guilty %s.", historic_statue_is_gone);
&nbsp;            adjalign(-1);
&nbsp;        }
&nbsp;    } else {
&nbsp;        if (historic &amp;&amp; cansee(x, y))
&nbsp;            You_feel("regret %s.", historic_statue_is_gone);
&nbsp;        /* no alignment penalty */
&nbsp;    }
&nbsp;
&nbsp;    /* transfer any statue contents to monster's inventory */
&nbsp;    while ((item = statue-&gt;cobj) != 0) {
&nbsp;        obj_extract_self(item);
&nbsp;        (void) mpickobj(mon, item);
&nbsp;    }
&nbsp;    m_dowear(mon, TRUE);
&nbsp;    /* in case statue is wielded and hero zaps stone-to-flesh at self */
&nbsp;    if (statue-&gt;owornmask)
&nbsp;        remove_worn_item(statue, TRUE);
&nbsp;    /* statue no longer exists */
&nbsp;    delobj(statue);
&nbsp;
&nbsp;    /* avoid hiding under nothing */
&nbsp;    if (x == u.ux &amp;&amp; y == u.uy &amp;&amp; Upolyd &amp;&amp; hides_under(youmonst.data)
&nbsp;        &amp;&amp; !OBJ_AT(x, y))
&nbsp;        u.uundetected = 0;
&nbsp;
&nbsp;    if (fail_reason)
&nbsp;        *fail_reason = AS_OK;
&nbsp;    return mon;
&nbsp;}
&nbsp;
activate_statue_trap
&nbsp;/*
&nbsp; * You've either stepped onto a statue trap's location or you've triggered a
&nbsp; * statue trap by searching next to it or by trying to break it with a wand
&nbsp; * or pick-axe.
&nbsp; */
&nbsp;struct monst *
&nbsp;activate_statue_trap(trap, x, y, shatter)
&nbsp;struct trap *trap;
&nbsp;xchar x, y;
&nbsp;boolean shatter;
&nbsp;{
&nbsp;    struct monst *mtmp = (struct monst *) 0;
&nbsp;    struct obj *otmp = sobj_at(STATUE, x, y);
&nbsp;    int fail_reason;
&nbsp;
&nbsp;    /*
&nbsp;     * Try to animate the first valid statue.  Stop the loop when we
&nbsp;     * actually create something or the failure cause is not because
&nbsp;     * the mon was unique.
&nbsp;     */
&nbsp;    deltrap(trap);
&nbsp;    while (otmp) {
&nbsp;        mtmp = animate_statue(otmp, x, y,
&nbsp;                              shatter ? ANIMATE_SHATTER : ANIMATE_NORMAL,
&nbsp;                              &amp;fail_reason);
&nbsp;        if (mtmp || fail_reason != AS_MON_IS_UNIQUE)
&nbsp;            break;
&nbsp;
&nbsp;        otmp = nxtobj(otmp, STATUE, TRUE);
&nbsp;    }
&nbsp;
&nbsp;    feel_newsym(x, y);
&nbsp;    return mtmp;
&nbsp;}
&nbsp;
keep_saddle_with_steedcorpse
&nbsp;STATIC_OVL boolean
&nbsp;keep_saddle_with_steedcorpse(steed_mid, objchn, saddle)
&nbsp;unsigned steed_mid;
&nbsp;struct obj *objchn, *saddle;
&nbsp;{
&nbsp;    if (!saddle)
&nbsp;        return FALSE;
&nbsp;    while (objchn) {
&nbsp;        if (objchn-&gt;otyp == CORPSE &amp;&amp; has_omonst(objchn)) {
&nbsp;            struct monst *mtmp = OMONST(objchn);
&nbsp;
&nbsp;            if (mtmp-&gt;m_id == steed_mid) {
&nbsp;                /* move saddle */
&nbsp;                xchar x, y;
&nbsp;                if (get_obj_location(objchn, &amp;x, &amp;y, 0)) {
&nbsp;                    obj_extract_self(saddle);
&nbsp;                    place_object(saddle, x, y);
&nbsp;                    stackobj(saddle);
&nbsp;                }
&nbsp;                return TRUE;
&nbsp;            }
&nbsp;        }
&nbsp;        if (Has_contents(objchn)
&nbsp;            &amp;&amp; keep_saddle_with_steedcorpse(steed_mid, objchn-&gt;cobj, saddle))
&nbsp;            return TRUE;
&nbsp;        objchn = objchn-&gt;nobj;
&nbsp;    }
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
mu_maybe_destroy_web
&nbsp;/* monster or you go through and possibly destroy a web.
&nbsp;   return TRUE if could go through. */
&nbsp;boolean
&nbsp;mu_maybe_destroy_web(mtmp, domsg, trap)
&nbsp;struct monst *mtmp;
&nbsp;boolean domsg;
&nbsp;struct trap *trap;
&nbsp;{
&nbsp;    boolean isyou = (mtmp == &amp;youmonst);
&nbsp;    struct permonst *mptr = mtmp-&gt;data;
&nbsp;    if (amorphous(mptr) || is_whirly(mptr) || flaming(mptr)
&nbsp;        || unsolid(mptr) || mptr == &amp;mons[PM_GELATINOUS_CUBE]) {
&nbsp;        xchar x = trap-&gt;tx;
&nbsp;        xchar y = trap-&gt;ty;
&nbsp;        if (flaming(mptr) || acidic(mptr)) {
&nbsp;            if (domsg) {
&nbsp;                if (isyou)
&nbsp;                    You("%s %s spider web!",
&nbsp;                        (flaming(mptr)) ? "burn" : "dissolve",
&nbsp;                        a_your[trap-&gt;madeby_u]);
&nbsp;                else
&nbsp;                    pline("%s %s %s spider web!", Monnam(mtmp),
&nbsp;                          (flaming(mptr)) ? "burns" : "dissolves",
&nbsp;                          a_your[trap-&gt;madeby_u]);
&nbsp;            }
&nbsp;            deltrap(trap);
&nbsp;            newsym(x, y);
&nbsp;            return TRUE;
&nbsp;        }
&nbsp;        if (domsg) {
&nbsp;            if (isyou)
&nbsp;                You("flow through %s spider web.", a_your[trap-&gt;madeby_u]);
&nbsp;            else {
&nbsp;                pline("%s flows through %s spider web.", Monnam(mtmp),
&nbsp;                      a_your[trap-&gt;madeby_u]);
&nbsp;                seetrap(trap);
&nbsp;            }
&nbsp;        }
&nbsp;        return TRUE;
&nbsp;    }
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
dotrap
&nbsp;void
&nbsp;dotrap(trap, trflags)
&nbsp;register struct trap *trap;
&nbsp;unsigned trflags;
&nbsp;{
&nbsp;    register int ttype = trap-&gt;ttyp;
&nbsp;    struct obj *otmp;
&nbsp;    boolean already_seen = trap-&gt;tseen,
&nbsp;            forcetrap = (trflags &amp; FORCETRAP) != 0,
&nbsp;            webmsgok = (trflags &amp; NOWEBMSG) == 0,
&nbsp;            forcebungle = (trflags &amp; FORCEBUNGLE) != 0,
&nbsp;            plunged = (trflags &amp; TOOKPLUNGE) != 0,
&nbsp;            viasitting = (trflags &amp; VIASITTING) != 0,
&nbsp;            conj_pit = conjoined_pits(trap, t_at(u.ux0, u.uy0), TRUE),
&nbsp;            adj_pit = adj_nonconjoined_pit(trap);
&nbsp;    int oldumort;
&nbsp;    int steed_article = ARTICLE_THE;
&nbsp;
&nbsp;    nomul(0);
&nbsp;
&nbsp;    /* KMH -- You can't escape the Sokoban level traps */
&nbsp;    if (Sokoban &amp;&amp; (ttype == PIT || ttype == SPIKED_PIT
&nbsp;                    || ttype == HOLE || ttype == TRAPDOOR)) {
&nbsp;        /* The "air currents" message is still appropriate -- even when
&nbsp;         * the hero isn't flying or levitating -- because it conveys the
&nbsp;         * reason why the player cannot escape the trap with a dexterity
&nbsp;         * check, clinging to the ceiling, etc.
&nbsp;         */
&nbsp;        pline("Air currents pull you down into %s %s!",
&nbsp;              a_your[trap-&gt;madeby_u],
&nbsp;              defsyms[trap_to_defsym(ttype)].explanation);
&nbsp;        /* then proceed to normal trap effect */
&nbsp;    } else if (already_seen &amp;&amp; !forcetrap) {
&nbsp;        if ((Levitation || (Flying &amp;&amp; !plunged))
&nbsp;            &amp;&amp; (ttype == PIT || ttype == SPIKED_PIT || ttype == HOLE
&nbsp;                || ttype == BEAR_TRAP)) {
&nbsp;            You("%s over %s %s.", Levitation ? "float" : "fly",
&nbsp;                a_your[trap-&gt;madeby_u],
&nbsp;                defsyms[trap_to_defsym(ttype)].explanation);
&nbsp;            return;
&nbsp;        }
&nbsp;        if (!Fumbling &amp;&amp; ttype != MAGIC_PORTAL &amp;&amp; ttype != VIBRATING_SQUARE
&nbsp;            &amp;&amp; ttype != ANTI_MAGIC &amp;&amp; !forcebungle &amp;&amp; !plunged
&nbsp;            &amp;&amp; !conj_pit &amp;&amp; !adj_pit
&nbsp;            &amp;&amp; (!rn2(5) || ((ttype == PIT || ttype == SPIKED_PIT)
&nbsp;                            &amp;&amp; is_clinger(youmonst.data)))) {
&nbsp;                You("escape %s %s.", (ttype == ARROW_TRAP &amp;&amp; !trap-&gt;madeby_u)
&nbsp;                                     ? "an"
&nbsp;                                     : a_your[trap-&gt;madeby_u],
&nbsp;                defsyms[trap_to_defsym(ttype)].explanation);
&nbsp;            return;
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    if (u.usteed) {
&nbsp;        u.usteed-&gt;mtrapseen |= (1 &lt;&lt; (ttype - 1));
&nbsp;        /* suppress article in various steed messages when using its
&nbsp;           name (which won't occur when hallucinating) */
&nbsp;        if (has_mname(u.usteed) &amp;&amp; !Hallucination)
&nbsp;            steed_article = ARTICLE_NONE;
&nbsp;    }
&nbsp;
&nbsp;    switch (ttype) {
&nbsp;    case ARROW_TRAP:
&nbsp;        if (trap-&gt;once &amp;&amp; trap-&gt;tseen &amp;&amp; !rn2(15)) {
&nbsp;            You_hear("a loud click!");
&nbsp;            deltrap(trap);
&nbsp;            newsym(u.ux, u.uy);
&nbsp;            break;
&nbsp;        }
&nbsp;        trap-&gt;once = 1;
&nbsp;        seetrap(trap);
&nbsp;        pline("An arrow shoots out at you!");
&nbsp;        otmp = mksobj(ARROW, TRUE, FALSE);
&nbsp;        otmp-&gt;quan = 1L;
&nbsp;        otmp-&gt;owt = weight(otmp);
&nbsp;        otmp-&gt;opoisoned = 0;
&nbsp;        if (u.usteed &amp;&amp; !rn2(2) &amp;&amp; steedintrap(trap, otmp)) { /* nothing */
&nbsp;            ;
&nbsp;        } else if (thitu(8, dmgval(otmp, &amp;youmonst), &amp;otmp, "arrow")) {
&nbsp;            if (otmp)
&nbsp;                obfree(otmp, (struct obj *) 0);
&nbsp;        } else {
&nbsp;            place_object(otmp, u.ux, u.uy);
&nbsp;            if (!Blind)
&nbsp;                otmp-&gt;dknown = 1;
&nbsp;            stackobj(otmp);
&nbsp;            newsym(u.ux, u.uy);
&nbsp;        }
&nbsp;        break;
&nbsp;
&nbsp;    case DART_TRAP:
&nbsp;        if (trap-&gt;once &amp;&amp; trap-&gt;tseen &amp;&amp; !rn2(15)) {
&nbsp;            You_hear("a soft click.");
&nbsp;            deltrap(trap);
&nbsp;            newsym(u.ux, u.uy);
&nbsp;            break;
&nbsp;        }
&nbsp;        trap-&gt;once = 1;
&nbsp;        seetrap(trap);
&nbsp;        pline("A little dart shoots out at you!");
&nbsp;        otmp = mksobj(DART, TRUE, FALSE);
&nbsp;        otmp-&gt;quan = 1L;
&nbsp;        otmp-&gt;owt = weight(otmp);
&nbsp;        if (!rn2(6))
&nbsp;            otmp-&gt;opoisoned = 1;
&nbsp;        oldumort = u.umortality;
&nbsp;        if (u.usteed &amp;&amp; !rn2(2) &amp;&amp; steedintrap(trap, otmp)) { /* nothing */
&nbsp;            ;
&nbsp;        } else if (thitu(7, dmgval(otmp, &amp;youmonst), &amp;otmp, "little dart")) {
&nbsp;            if (otmp) {
&nbsp;                if (otmp-&gt;opoisoned)
&nbsp;                    poisoned("dart", A_CON, "little dart",
&nbsp;                             /* if damage triggered life-saving,
&nbsp;                                poison is limited to attrib loss */
&nbsp;                             (u.umortality &gt; oldumort) ? 0 : 10, TRUE);
&nbsp;                obfree(otmp, (struct obj *) 0);
&nbsp;            }
&nbsp;        } else {
&nbsp;            place_object(otmp, u.ux, u.uy);
&nbsp;            if (!Blind)
&nbsp;                otmp-&gt;dknown = 1;
&nbsp;            stackobj(otmp);
&nbsp;            newsym(u.ux, u.uy);
&nbsp;        }
&nbsp;        break;
&nbsp;
&nbsp;    case ROCKTRAP:
&nbsp;        if (trap-&gt;once &amp;&amp; trap-&gt;tseen &amp;&amp; !rn2(15)) {
&nbsp;            pline("A trap door in %s opens, but nothing falls out!",
&nbsp;                  the(ceiling(u.ux, u.uy)));
&nbsp;            deltrap(trap);
&nbsp;            newsym(u.ux, u.uy);
&nbsp;        } else {
&nbsp;            int dmg = d(2, 6); /* should be std ROCK dmg? */
&nbsp;
&nbsp;            trap-&gt;once = 1;
&nbsp;            feeltrap(trap);
&nbsp;            otmp = mksobj_at(ROCK, u.ux, u.uy, TRUE, FALSE);
&nbsp;            otmp-&gt;quan = 1L;
&nbsp;            otmp-&gt;owt = weight(otmp);
&nbsp;
&nbsp;            pline("A trap door in %s opens and %s falls on your %s!",
&nbsp;                  the(ceiling(u.ux, u.uy)), an(xname(otmp)), body_part(HEAD));
&nbsp;
&nbsp;            if (uarmh) {
&nbsp;                if (is_metallic(uarmh)) {
&nbsp;                    pline("Fortunately, you are wearing a hard helmet.");
&nbsp;                    dmg = 2;
&nbsp;                } else if (flags.verbose) {
&nbsp;                    pline("%s does not protect you.", Yname2(uarmh));
&nbsp;                }
&nbsp;            }
&nbsp;
&nbsp;            if (!Blind)
&nbsp;                otmp-&gt;dknown = 1;
&nbsp;            stackobj(otmp);
&nbsp;            newsym(u.ux, u.uy); /* map the rock */
&nbsp;
&nbsp;            losehp(Maybe_Half_Phys(dmg), "falling rock", KILLED_BY_AN);
&nbsp;            exercise(A_STR, FALSE);
&nbsp;        }
&nbsp;        break;
&nbsp;
&nbsp;    case SQKY_BOARD: /* stepped on a squeaky board */
&nbsp;        if ((Levitation || Flying) &amp;&amp; !forcetrap) {
&nbsp;            if (!Blind) {
&nbsp;                seetrap(trap);
&nbsp;                if (Hallucination)
&nbsp;                    You("notice a crease in the linoleum.");
&nbsp;                else
&nbsp;                    You("notice a loose board below you.");
&nbsp;            }
&nbsp;        } else {
&nbsp;            seetrap(trap);
&nbsp;            pline("A board beneath you %s%s%s.",
&nbsp;                  Deaf ? "vibrates" : "squeaks ",
&nbsp;                  Deaf ? "" : trapnote(trap, 0), Deaf ? "" : " loudly");
&nbsp;            wake_nearby();
&nbsp;        }
&nbsp;        break;
&nbsp;
&nbsp;    case BEAR_TRAP: {
&nbsp;        int dmg = d(2, 4);
&nbsp;
&nbsp;        if ((Levitation || Flying) &amp;&amp; !forcetrap)
&nbsp;            break;
&nbsp;        feeltrap(trap);
&nbsp;        if (amorphous(youmonst.data) || is_whirly(youmonst.data)
&nbsp;            || unsolid(youmonst.data)) {
&nbsp;            pline("%s bear trap closes harmlessly through you.",
&nbsp;                  A_Your[trap-&gt;madeby_u]);
&nbsp;            break;
&nbsp;        }
&nbsp;        if (!u.usteed &amp;&amp; youmonst.data-&gt;msize &lt;= MZ_SMALL) {
&nbsp;            pline("%s bear trap closes harmlessly over you.",
&nbsp;                  A_Your[trap-&gt;madeby_u]);
&nbsp;            break;
&nbsp;        }
&nbsp;        u.utrap = rn1(4, 4);
&nbsp;        u.utraptype = TT_BEARTRAP;
&nbsp;        if (u.usteed) {
&nbsp;            pline("%s bear trap closes on %s %s!", A_Your[trap-&gt;madeby_u],
&nbsp;                  s_suffix(mon_nam(u.usteed)), mbodypart(u.usteed, FOOT));
&nbsp;            if (thitm(0, u.usteed, (struct obj *) 0, dmg, FALSE))
&nbsp;                u.utrap = 0; /* steed died, hero not trapped */
&nbsp;        } else {
&nbsp;            pline("%s bear trap closes on your %s!", A_Your[trap-&gt;madeby_u],
&nbsp;                  body_part(FOOT));
&nbsp;            set_wounded_legs(rn2(2) ? RIGHT_SIDE : LEFT_SIDE, rn1(10, 10));
&nbsp;            if (u.umonnum == PM_OWLBEAR || u.umonnum == PM_BUGBEAR)
&nbsp;                You("howl in anger!");
&nbsp;            losehp(Maybe_Half_Phys(dmg), "bear trap", KILLED_BY_AN);
&nbsp;        }
&nbsp;        exercise(A_DEX, FALSE);
&nbsp;        break;
&nbsp;    }
&nbsp;
&nbsp;    case SLP_GAS_TRAP:
&nbsp;        seetrap(trap);
&nbsp;        if (Sleep_resistance || breathless(youmonst.data)) {
&nbsp;            You("are enveloped in a cloud of gas!");
&nbsp;        } else {
&nbsp;            pline("A cloud of gas puts you to sleep!");
&nbsp;            fall_asleep(-rnd(25), TRUE);
&nbsp;        }
&nbsp;        (void) steedintrap(trap, (struct obj *) 0);
&nbsp;        break;
&nbsp;
&nbsp;    case RUST_TRAP:
&nbsp;        seetrap(trap);
&nbsp;
&nbsp;        /* Unlike monsters, traps cannot aim their rust attacks at
&nbsp;         * you, so instead of looping through and taking either the
&nbsp;         * first rustable one or the body, we take whatever we get,
&nbsp;         * even if it is not rustable.
&nbsp;         */
&nbsp;        switch (rn2(5)) {
&nbsp;        case 0:
&nbsp;            pline("%s you on the %s!", A_gush_of_water_hits, body_part(HEAD));
&nbsp;            (void) water_damage(uarmh, helm_simple_name(uarmh), TRUE);
&nbsp;            break;
&nbsp;        case 1:
&nbsp;            pline("%s your left %s!", A_gush_of_water_hits, body_part(ARM));
&nbsp;            if (water_damage(uarms, "shield", TRUE) != ER_NOTHING)
&nbsp;                break;
&nbsp;            if (u.twoweap || (uwep &amp;&amp; bimanual(uwep)))
&nbsp;                (void) water_damage(u.twoweap ? uswapwep : uwep, 0, TRUE);
&nbsp;        glovecheck:
&nbsp;            (void) water_damage(uarmg, "gauntlets", TRUE);
&nbsp;            /* Not "metal gauntlets" since it gets called
&nbsp;             * even if it's leather for the message
&nbsp;             */
&nbsp;            break;
&nbsp;        case 2:
&nbsp;            pline("%s your right %s!", A_gush_of_water_hits, body_part(ARM));
&nbsp;            (void) water_damage(uwep, 0, TRUE);
&nbsp;            goto glovecheck;
&nbsp;        default:
&nbsp;            pline("%s you!", A_gush_of_water_hits);
&nbsp;            for (otmp = invent; otmp; otmp = otmp-&gt;nobj)
&nbsp;                if (otmp-&gt;lamplit &amp;&amp; otmp != uwep
&nbsp;                    &amp;&amp; (otmp != uswapwep || !u.twoweap))
&nbsp;                    (void) snuff_lit(otmp);
&nbsp;            if (uarmc)
&nbsp;                (void) water_damage(uarmc, cloak_simple_name(uarmc), TRUE);
&nbsp;            else if (uarm)
&nbsp;                (void) water_damage(uarm, suit_simple_name(uarm), TRUE);
&nbsp;            else if (uarmu)
&nbsp;                (void) water_damage(uarmu, "shirt", TRUE);
&nbsp;        }
&nbsp;        update_inventory();
&nbsp;
&nbsp;        if (u.umonnum == PM_IRON_GOLEM) {
&nbsp;            int dam = u.mhmax;
&nbsp;
&nbsp;            You("are covered with rust!");
&nbsp;            losehp(Maybe_Half_Phys(dam), "rusting away", KILLED_BY);
&nbsp;        } else if (u.umonnum == PM_GREMLIN &amp;&amp; rn2(3)) {
&nbsp;            (void) split_mon(&amp;youmonst, (struct monst *) 0);
&nbsp;        }
&nbsp;
&nbsp;        break;
&nbsp;
&nbsp;    case FIRE_TRAP:
&nbsp;        seetrap(trap);
&nbsp;        dofiretrap((struct obj *) 0);
&nbsp;        break;
&nbsp;
&nbsp;    case PIT:
&nbsp;    case SPIKED_PIT:
&nbsp;        /* KMH -- You can't escape the Sokoban level traps */
&nbsp;        if (!Sokoban &amp;&amp; (Levitation || (Flying &amp;&amp; !plunged)))
&nbsp;            break;
&nbsp;        feeltrap(trap);
&nbsp;        if (!Sokoban &amp;&amp; is_clinger(youmonst.data) &amp;&amp; !plunged) {
&nbsp;            if (trap-&gt;tseen) {
&nbsp;                You_see("%s %spit below you.", a_your[trap-&gt;madeby_u],
&nbsp;                        ttype == SPIKED_PIT ? "spiked " : "");
&nbsp;            } else {
&nbsp;                pline("%s pit %sopens up under you!", A_Your[trap-&gt;madeby_u],
&nbsp;                      ttype == SPIKED_PIT ? "full of spikes " : "");
&nbsp;                You("don't fall in!");
&nbsp;            }
&nbsp;            break;
&nbsp;        }
&nbsp;        if (!Sokoban) {
&nbsp;            char verbbuf[BUFSZ];
&nbsp;
&nbsp;            if (u.usteed) {
&nbsp;                if ((trflags &amp; RECURSIVETRAP) != 0)
&nbsp;                    Sprintf(verbbuf, "and %s fall",
&nbsp;                            x_monnam(u.usteed, steed_article, (char *) 0,
&nbsp;                                     SUPPRESS_SADDLE, FALSE));
&nbsp;                else
&nbsp;                    Sprintf(verbbuf, "lead %s",
&nbsp;                            x_monnam(u.usteed, steed_article, "poor",
&nbsp;                                     SUPPRESS_SADDLE, FALSE));
&nbsp;            } else if (conj_pit) {
&nbsp;                You("move into an adjacent pit.");
&nbsp;            } else if (adj_pit) {
&nbsp;                You("stumble over debris%s.",
&nbsp;                    !rn2(5) ? " between the pits" : "");
&nbsp;            } else {
&nbsp;                Strcpy(verbbuf,
&nbsp;                       !plunged ? "fall" : (Flying ? "dive" : "plunge"));
&nbsp;                You("%s into %s pit!", verbbuf, a_your[trap-&gt;madeby_u]);
&nbsp;            }
&nbsp;        }
&nbsp;        /* wumpus reference */
&nbsp;        if (Role_if(PM_RANGER) &amp;&amp; !trap-&gt;madeby_u &amp;&amp; !trap-&gt;once
&nbsp;            &amp;&amp; In_quest(&amp;u.uz) &amp;&amp; Is_qlocate(&amp;u.uz)) {
&nbsp;            pline("Fortunately it has a bottom after all...");
&nbsp;            trap-&gt;once = 1;
&nbsp;        } else if (u.umonnum == PM_PIT_VIPER || u.umonnum == PM_PIT_FIEND) {
&nbsp;            pline("How pitiful.  Isn't that the pits?");
&nbsp;        }
&nbsp;        if (ttype == SPIKED_PIT) {
&nbsp;            const char *predicament = "on a set of sharp iron spikes";
&nbsp;
&nbsp;            if (u.usteed) {
&nbsp;                pline("%s %s %s!",
&nbsp;                      upstart(x_monnam(u.usteed, steed_article, "poor",
&nbsp;                                       SUPPRESS_SADDLE, FALSE)),
&nbsp;                      conj_pit ? "steps" : "lands", predicament);
&nbsp;            } else
&nbsp;                You("%s %s!", conj_pit ? "step" : "land", predicament);
&nbsp;        }
&nbsp;        u.utrap = rn1(6, 2);
&nbsp;        u.utraptype = TT_PIT;
&nbsp;        if (!steedintrap(trap, (struct obj *) 0)) {
&nbsp;            if (ttype == SPIKED_PIT) {
&nbsp;                oldumort = u.umortality;
&nbsp;                losehp(Maybe_Half_Phys(rnd(conj_pit ? 4 : adj_pit ? 6 : 10)),
&nbsp;                       plunged
&nbsp;                           ? "deliberately plunged into a pit of iron spikes"
&nbsp;                           : conj_pit ? "stepped into a pit of iron spikes"
&nbsp;                           : adj_pit ? "stumbled into a pit of iron spikes"
&nbsp;                                     : "fell into a pit of iron spikes",
&nbsp;                       NO_KILLER_PREFIX);
&nbsp;                if (!rn2(6))
&nbsp;                    poisoned("spikes", A_STR,
&nbsp;                             (conj_pit || adj_pit) ? "stepping on poison spikes"
&nbsp;                                     : "fall onto poison spikes",
&nbsp;                             /* if damage triggered life-saving,
&nbsp;                                poison is limited to attrib loss */
&nbsp;                             (u.umortality &gt; oldumort) ? 0 : 8, FALSE);
&nbsp;            } else {
&nbsp;                /* plunging flyers take spike damage but not pit damage */
&nbsp;                if (!conj_pit
&nbsp;                    &amp;&amp; !(plunged &amp;&amp; (Flying || is_clinger(youmonst.data))))
&nbsp;                    losehp(Maybe_Half_Phys(rnd(adj_pit ? 3 : 6)),
&nbsp;                           plunged ? "deliberately plunged into a pit"
&nbsp;                                   : "fell into a pit",
&nbsp;                           NO_KILLER_PREFIX);
&nbsp;            }
&nbsp;            if (Punished &amp;&amp; !carried(uball)) {
&nbsp;                unplacebc();
&nbsp;                ballfall();
&nbsp;                placebc();
&nbsp;            }
&nbsp;            if (!conj_pit)
&nbsp;                selftouch("Falling, you");
&nbsp;            vision_full_recalc = 1; /* vision limits change */
&nbsp;            exercise(A_STR, FALSE);
&nbsp;            exercise(A_DEX, FALSE);
&nbsp;        }
&nbsp;        break;
&nbsp;
&nbsp;    case HOLE:
&nbsp;    case TRAPDOOR:
&nbsp;        if (!Can_fall_thru(&amp;u.uz)) {
&nbsp;            seetrap(trap); /* normally done in fall_through */
&nbsp;            impossible("dotrap: %ss cannot exist on this level.",
&nbsp;                       defsyms[trap_to_defsym(ttype)].explanation);
&nbsp;            break; /* don't activate it after all */
&nbsp;        }
&nbsp;        fall_through(TRUE);
&nbsp;        break;
&nbsp;
&nbsp;    case TELEP_TRAP:
&nbsp;        seetrap(trap);
&nbsp;        tele_trap(trap);
&nbsp;        break;
&nbsp;
&nbsp;    case LEVEL_TELEP:
&nbsp;        seetrap(trap);
&nbsp;        level_tele_trap(trap, trflags);
&nbsp;        break;
&nbsp;
&nbsp;    case WEB: /* Our luckless player has stumbled into a web. */
&nbsp;        feeltrap(trap);
&nbsp;        if (mu_maybe_destroy_web(&amp;youmonst, webmsgok, trap))
&nbsp;            break;
&nbsp;        if (webmaker(youmonst.data)) {
&nbsp;            if (webmsgok)
&nbsp;                pline(trap-&gt;madeby_u ? "You take a walk on your web."
&nbsp;                                     : "There is a spider web here.");
&nbsp;            break;
&nbsp;        }
&nbsp;        if (webmsgok) {
&nbsp;            char verbbuf[BUFSZ];
&nbsp;
&nbsp;            if (forcetrap || viasitting) {
&nbsp;                Strcpy(verbbuf, "are caught by");
&nbsp;            } else if (u.usteed) {
&nbsp;                Sprintf(verbbuf, "lead %s into",
&nbsp;                        x_monnam(u.usteed, steed_article, "poor",
&nbsp;                                 SUPPRESS_SADDLE, FALSE));
&nbsp;            } else {
&nbsp;                Sprintf(verbbuf, "%s into",
&nbsp;                        Levitation ? (const char *) "float"
&nbsp;                                   : locomotion(youmonst.data, "stumble"));
&nbsp;            }
&nbsp;            You("%s %s spider web!", verbbuf, a_your[trap-&gt;madeby_u]);
&nbsp;        }
&nbsp;        u.utraptype = TT_WEB;
&nbsp;
&nbsp;        /* Time stuck in the web depends on your/steed strength. */
&nbsp;        {
&nbsp;            register int str = ACURR(A_STR);
&nbsp;
&nbsp;            /* If mounted, the steed gets trapped.  Use mintrap
&nbsp;             * to do all the work.  If mtrapped is set as a result,
&nbsp;             * unset it and set utrap instead.  In the case of a
&nbsp;             * strongmonst and mintrap said it's trapped, use a
&nbsp;             * short but non-zero trap time.  Otherwise, monsters
&nbsp;             * have no specific strength, so use player strength.
&nbsp;             * This gets skipped for webmsgok, which implies that
&nbsp;             * the steed isn't a factor.
&nbsp;             */
&nbsp;            if (u.usteed &amp;&amp; webmsgok) {
&nbsp;                /* mtmp location might not be up to date */
&nbsp;                u.usteed-&gt;mx = u.ux;
&nbsp;                u.usteed-&gt;my = u.uy;
&nbsp;
&nbsp;                /* mintrap currently does not return 2(died) for webs */
&nbsp;                if (mintrap(u.usteed)) {
&nbsp;                    u.usteed-&gt;mtrapped = 0;
&nbsp;                    if (strongmonst(u.usteed-&gt;data))
&nbsp;                        str = 17;
&nbsp;                } else {
&nbsp;                    break;
&nbsp;                }
&nbsp;
&nbsp;                webmsgok = FALSE; /* mintrap printed the messages */
&nbsp;            }
&nbsp;            if (str &lt;= 3)
&nbsp;                u.utrap = rn1(6, 6);
&nbsp;            else if (str &lt; 6)
&nbsp;                u.utrap = rn1(6, 4);
&nbsp;            else if (str &lt; 9)
&nbsp;                u.utrap = rn1(4, 4);
&nbsp;            else if (str &lt; 12)
&nbsp;                u.utrap = rn1(4, 2);
&nbsp;            else if (str &lt; 15)
&nbsp;                u.utrap = rn1(2, 2);
&nbsp;            else if (str &lt; 18)
&nbsp;                u.utrap = rnd(2);
&nbsp;            else if (str &lt; 69)
&nbsp;                u.utrap = 1;
&nbsp;            else {
&nbsp;                u.utrap = 0;
&nbsp;                if (webmsgok)
&nbsp;                    You("tear through %s web!", a_your[trap-&gt;madeby_u]);
&nbsp;                deltrap(trap);
&nbsp;                newsym(u.ux, u.uy); /* get rid of trap symbol */
&nbsp;            }
&nbsp;        }
&nbsp;        break;
&nbsp;
&nbsp;    case STATUE_TRAP:
&nbsp;        (void) activate_statue_trap(trap, u.ux, u.uy, FALSE);
&nbsp;        break;
&nbsp;
&nbsp;    case MAGIC_TRAP: /* A magic trap. */
&nbsp;        seetrap(trap);
&nbsp;        if (!rn2(30)) {
&nbsp;            deltrap(trap);
&nbsp;            newsym(u.ux, u.uy); /* update position */
&nbsp;            You("are caught in a magical explosion!");
&nbsp;            losehp(rnd(10), "magical explosion", KILLED_BY_AN);
&nbsp;            Your("body absorbs some of the magical energy!");
&nbsp;            u.uen = (u.uenmax += 2);
&nbsp;            break;
&nbsp;        } else {
&nbsp;            domagictrap();
&nbsp;        }
&nbsp;        (void) steedintrap(trap, (struct obj *) 0);
&nbsp;        break;
&nbsp;
&nbsp;    case ANTI_MAGIC:
&nbsp;        seetrap(trap);
&nbsp;        /* hero without magic resistance loses spell energy,
&nbsp;           hero with magic resistance takes damage instead;
&nbsp;           possibly non-intuitive but useful for play balance */
&nbsp;        if (!Antimagic) {
&nbsp;            drain_en(rnd(u.ulevel) + 1);
&nbsp;        } else {
&nbsp;            int dmgval2 = rnd(4), hp = Upolyd ? u.mh : u.uhp;
&nbsp;
&nbsp;            /* Half_XXX_damage has opposite its usual effect (approx)
&nbsp;               but isn't cumulative if hero has more than one */
&nbsp;            if (Half_physical_damage || Half_spell_damage)
&nbsp;                dmgval2 += rnd(4);
&nbsp;            /* give Magicbane wielder dose of own medicine */
&nbsp;            if (uwep &amp;&amp; uwep-&gt;oartifact == ART_MAGICBANE)
&nbsp;                dmgval2 += rnd(4);
&nbsp;            /* having an artifact--other than own quest one--which
&nbsp;               confers magic resistance simply by being carried
&nbsp;               also increases the effect */
&nbsp;            for (otmp = invent; otmp; otmp = otmp-&gt;nobj)
&nbsp;                if (otmp-&gt;oartifact &amp;&amp; !is_quest_artifact(otmp)
&nbsp;                    &amp;&amp; defends_when_carried(AD_MAGM, otmp))
&nbsp;                    break;
&nbsp;            if (otmp)
&nbsp;                dmgval2 += rnd(4);
&nbsp;            if (Passes_walls)
&nbsp;                dmgval2 = (dmgval2 + 3) / 4;
&nbsp;
&nbsp;            You_feel((dmgval2 &gt;= hp) ? "unbearably torpid!"
&nbsp;                                     : (dmgval2 &gt;= hp / 4) ? "very lethargic."
&nbsp;                                                           : "sluggish.");
&nbsp;            /* opposite of magical explosion */
&nbsp;            losehp(dmgval2, "anti-magic implosion", KILLED_BY_AN);
&nbsp;        }
&nbsp;        break;
&nbsp;
&nbsp;    case POLY_TRAP: {
&nbsp;        char verbbuf[BUFSZ];
&nbsp;
&nbsp;        seetrap(trap);
&nbsp;        if (viasitting)
&nbsp;            Strcpy(verbbuf, "trigger"); /* follows "You sit down." */
&nbsp;        else if (u.usteed)
&nbsp;            Sprintf(verbbuf, "lead %s onto",
&nbsp;                    x_monnam(u.usteed, steed_article, (char *) 0,
&nbsp;                             SUPPRESS_SADDLE, FALSE));
&nbsp;        else
&nbsp;            Sprintf(verbbuf, "%s onto",
&nbsp;                    Levitation ? (const char *) "float"
&nbsp;                               : locomotion(youmonst.data, "step"));
&nbsp;        You("%s a polymorph trap!", verbbuf);
&nbsp;        if (Antimagic || Unchanging) {
&nbsp;            shieldeff(u.ux, u.uy);
&nbsp;            You_feel("momentarily different.");
&nbsp;            /* Trap did nothing; don't remove it --KAA */
&nbsp;        } else {
&nbsp;            (void) steedintrap(trap, (struct obj *) 0);
&nbsp;            deltrap(trap);      /* delete trap before polymorph */
&nbsp;            newsym(u.ux, u.uy); /* get rid of trap symbol */
&nbsp;            You_feel("a change coming over you.");
&nbsp;            polyself(0);
&nbsp;        }
&nbsp;        break;
&nbsp;    }
&nbsp;    case LANDMINE: {
&nbsp;        unsigned steed_mid = 0;
&nbsp;        struct obj *saddle = 0;
&nbsp;
&nbsp;        if ((Levitation || Flying) &amp;&amp; !forcetrap) {
&nbsp;            if (!already_seen &amp;&amp; rn2(3))
&nbsp;                break;
&nbsp;            feeltrap(trap);
&nbsp;            pline("%s %s in a pile of soil below you.",
&nbsp;                  already_seen ? "There is" : "You discover",
&nbsp;                  trap-&gt;madeby_u ? "the trigger of your mine" : "a trigger");
&nbsp;            if (already_seen &amp;&amp; rn2(3))
&nbsp;                break;
&nbsp;            pline("KAABLAMM!!!  %s %s%s off!",
&nbsp;                  forcebungle ? "Your inept attempt sets"
&nbsp;                              : "The air currents set",
&nbsp;                  already_seen ? a_your[trap-&gt;madeby_u] : "",
&nbsp;                  already_seen ? " land mine" : "it");
&nbsp;        } else {
&nbsp;            /* prevent landmine from killing steed, throwing you to
&nbsp;             * the ground, and you being affected again by the same
&nbsp;             * mine because it hasn't been deleted yet
&nbsp;             */
&nbsp;            static boolean recursive_mine = FALSE;
&nbsp;
&nbsp;            if (recursive_mine)
&nbsp;                break;
&nbsp;            feeltrap(trap);
&nbsp;            pline("KAABLAMM!!!  You triggered %s land mine!",
&nbsp;                  a_your[trap-&gt;madeby_u]);
&nbsp;            if (u.usteed)
&nbsp;                steed_mid = u.usteed-&gt;m_id;
&nbsp;            recursive_mine = TRUE;
&nbsp;            (void) steedintrap(trap, (struct obj *) 0);
&nbsp;            recursive_mine = FALSE;
&nbsp;            saddle = sobj_at(SADDLE, u.ux, u.uy);
&nbsp;            set_wounded_legs(LEFT_SIDE, rn1(35, 41));
&nbsp;            set_wounded_legs(RIGHT_SIDE, rn1(35, 41));
&nbsp;            exercise(A_DEX, FALSE);
&nbsp;        }
&nbsp;        blow_up_landmine(trap);
&nbsp;        if (steed_mid &amp;&amp; saddle &amp;&amp; !u.usteed)
&nbsp;            (void) keep_saddle_with_steedcorpse(steed_mid, fobj, saddle);
&nbsp;        newsym(u.ux, u.uy); /* update trap symbol */
&nbsp;        losehp(Maybe_Half_Phys(rnd(16)), "land mine", KILLED_BY_AN);
&nbsp;        /* fall recursively into the pit... */
&nbsp;        if ((trap = t_at(u.ux, u.uy)) != 0)
&nbsp;            dotrap(trap, RECURSIVETRAP);
&nbsp;        fill_pit(u.ux, u.uy);
&nbsp;        break;
&nbsp;    }
&nbsp;
&nbsp;    case ROLLING_BOULDER_TRAP: {
&nbsp;        int style = ROLL | (trap-&gt;tseen ? LAUNCH_KNOWN : 0);
&nbsp;
&nbsp;        feeltrap(trap);
&nbsp;        pline("Click! You trigger a rolling boulder trap!");
&nbsp;        if (!launch_obj(BOULDER, trap-&gt;launch.x, trap-&gt;launch.y,
&nbsp;                        trap-&gt;launch2.x, trap-&gt;launch2.y, style)) {
&nbsp;            deltrap(trap);
&nbsp;            newsym(u.ux, u.uy); /* get rid of trap symbol */
&nbsp;            pline("Fortunately for you, no boulder was released.");
&nbsp;        }
&nbsp;        break;
&nbsp;    }
&nbsp;
&nbsp;    case MAGIC_PORTAL:
&nbsp;        feeltrap(trap);
&nbsp;        domagicportal(trap);
&nbsp;        break;
&nbsp;
&nbsp;    case VIBRATING_SQUARE:
&nbsp;        feeltrap(trap);
&nbsp;        /* messages handled elsewhere; the trap symbol is merely to mark the
&nbsp;         * square for future reference */
&nbsp;        break;
&nbsp;
&nbsp;    default:
&nbsp;        feeltrap(trap);
&nbsp;        impossible("You hit a trap of type %u", trap-&gt;ttyp);
&nbsp;    }
&nbsp;}
&nbsp;
trapnote
&nbsp;STATIC_OVL char *
&nbsp;trapnote(trap, noprefix)
&nbsp;struct trap *trap;
&nbsp;boolean noprefix;
&nbsp;{
&nbsp;    static char tnbuf[12];
&nbsp;    const char *tn,
&nbsp;        *tnnames[12] = { "C note",  "D flat", "D note",  "E flat",
&nbsp;                         "E note",  "F note", "F sharp", "G note",
&nbsp;                         "G sharp", "A note", "B flat",  "B note" };
&nbsp;
&nbsp;    tnbuf[0] = '\0';
&nbsp;    tn = tnnames[trap-&gt;tnote];
&nbsp;    if (!noprefix)
&nbsp;        Sprintf(tnbuf, "%s ",
&nbsp;                (*tn == 'A' || *tn == 'E' || *tn == 'F') ? "an" : "a");
&nbsp;    Sprintf(eos(tnbuf), "%s", tn);
&nbsp;    return tnbuf;
&nbsp;}
&nbsp;
steedintrap
&nbsp;STATIC_OVL int
&nbsp;steedintrap(trap, otmp)
&nbsp;struct trap *trap;
&nbsp;struct obj *otmp;
&nbsp;{
&nbsp;    struct monst *steed = u.usteed;
&nbsp;    int tt;
&nbsp;    boolean trapkilled, steedhit;
&nbsp;
&nbsp;    if (!steed || !trap)
&nbsp;        return 0;
&nbsp;    tt = trap-&gt;ttyp;
&nbsp;    steed-&gt;mx = u.ux;
&nbsp;    steed-&gt;my = u.uy;
&nbsp;    trapkilled = steedhit = FALSE;
&nbsp;
&nbsp;    switch (tt) {
&nbsp;    case ARROW_TRAP:
&nbsp;        if (!otmp) {
&nbsp;            impossible("steed hit by non-existant arrow?");
&nbsp;            return 0;
&nbsp;        }
&nbsp;        trapkilled = thitm(8, steed, otmp, 0, FALSE);
&nbsp;        steedhit = TRUE;
&nbsp;        break;
&nbsp;    case DART_TRAP:
&nbsp;        if (!otmp) {
&nbsp;            impossible("steed hit by non-existant dart?");
&nbsp;            return 0;
&nbsp;        }
&nbsp;        trapkilled = thitm(7, steed, otmp, 0, FALSE);
&nbsp;        steedhit = TRUE;
&nbsp;        break;
&nbsp;    case SLP_GAS_TRAP:
&nbsp;        if (!resists_sleep(steed) &amp;&amp; !breathless(steed-&gt;data)
&nbsp;            &amp;&amp; !steed-&gt;msleeping &amp;&amp; steed-&gt;mcanmove) {
&nbsp;            if (sleep_monst(steed, rnd(25), -1))
&nbsp;                /* no in_sight check here; you can feel it even if blind */
&nbsp;                pline("%s suddenly falls asleep!", Monnam(steed));
&nbsp;        }
&nbsp;        steedhit = TRUE;
&nbsp;        break;
&nbsp;    case LANDMINE:
&nbsp;        trapkilled = thitm(0, steed, (struct obj *) 0, rnd(16), FALSE);
&nbsp;        steedhit = TRUE;
&nbsp;        break;
&nbsp;    case PIT:
&nbsp;    case SPIKED_PIT:
&nbsp;        trapkilled = (steed-&gt;mhp &lt;= 0
&nbsp;                      || thitm(0, steed, (struct obj *) 0,
&nbsp;                               rnd((tt == PIT) ? 6 : 10), FALSE));
&nbsp;        steedhit = TRUE;
&nbsp;        break;
&nbsp;    case POLY_TRAP:
&nbsp;        if (!resists_magm(steed) &amp;&amp; !resist(steed, WAND_CLASS, 0, NOTELL)) {
&nbsp;            (void) newcham(steed, (struct permonst *) 0, FALSE, FALSE);
&nbsp;            if (!can_saddle(steed) || !can_ride(steed))
&nbsp;                dismount_steed(DISMOUNT_POLY);
&nbsp;            else
&nbsp;                You("have to adjust yourself in the saddle on %s.",
&nbsp;                    x_monnam(steed, ARTICLE_A, (char *) 0, SUPPRESS_SADDLE,
&nbsp;                             FALSE));
&nbsp;        }
&nbsp;        steedhit = TRUE;
&nbsp;        break;
&nbsp;    default:
&nbsp;        break;
&nbsp;    }
&nbsp;
&nbsp;    if (trapkilled) {
&nbsp;        dismount_steed(DISMOUNT_POLY);
&nbsp;        return 2;
&nbsp;    }
&nbsp;    return steedhit ? 1 : 0;
&nbsp;}
&nbsp;
blow_up_landmine
&nbsp;/* some actions common to both player and monsters for triggered landmine */
&nbsp;void
&nbsp;blow_up_landmine(trap)
&nbsp;struct trap *trap;
&nbsp;{
&nbsp;    int x = trap-&gt;tx, y = trap-&gt;ty, dbx, dby;
&nbsp;    struct rm *lev = &amp;levl[x][y];
&nbsp;
&nbsp;    (void) scatter(x, y, 4,
&nbsp;                   MAY_DESTROY | MAY_HIT | MAY_FRACTURE | VIS_EFFECTS,
&nbsp;                   (struct obj *) 0);
&nbsp;    del_engr_at(x, y);
&nbsp;    wake_nearto(x, y, 400);
&nbsp;    if (IS_DOOR(lev-&gt;typ))
&nbsp;        lev-&gt;doormask = D_BROKEN;
&nbsp;    /* destroy drawbridge if present */
&nbsp;    if (lev-&gt;typ == DRAWBRIDGE_DOWN || is_drawbridge_wall(x, y) &gt;= 0) {
&nbsp;        dbx = x, dby = y;
&nbsp;        /* if under the portcullis, the bridge is adjacent */
&nbsp;        if (find_drawbridge(&amp;dbx, &amp;dby))
&nbsp;            destroy_drawbridge(dbx, dby);
&nbsp;        trap = t_at(x, y); /* expected to be null after destruction */
&nbsp;    }
&nbsp;    /* convert landmine into pit */
&nbsp;    if (trap) {
&nbsp;        if (Is_waterlevel(&amp;u.uz) || Is_airlevel(&amp;u.uz)) {
&nbsp;            /* no pits here */
&nbsp;            deltrap(trap);
&nbsp;        } else {
&nbsp;            trap-&gt;ttyp = PIT;       /* explosion creates a pit */
&nbsp;            trap-&gt;madeby_u = FALSE; /* resulting pit isn't yours */
&nbsp;            seetrap(trap);          /* and it isn't concealed */
&nbsp;        }
&nbsp;    }
&nbsp;}
&nbsp;
&nbsp;/*
&nbsp; * The following are used to track launched objects to
&nbsp; * prevent them from vanishing if you are killed. They
&nbsp; * will reappear at the launchplace in bones files.
&nbsp; */
&nbsp;static struct {
&nbsp;    struct obj *obj;
&nbsp;    xchar x, y;
&nbsp;} launchplace;
&nbsp;
launch_drop_spot
&nbsp;static void
&nbsp;launch_drop_spot(obj, x, y)
&nbsp;struct obj *obj;
&nbsp;xchar x, y;
&nbsp;{
&nbsp;    if (!obj) {
&nbsp;        launchplace.obj = (struct obj *) 0;
&nbsp;        launchplace.x = 0;
&nbsp;        launchplace.y = 0;
&nbsp;    } else {
&nbsp;        launchplace.obj = obj;
&nbsp;        launchplace.x = x;
&nbsp;        launchplace.y = y;
&nbsp;    }
&nbsp;}
&nbsp;
launch_in_progress
&nbsp;boolean
&nbsp;launch_in_progress()
&nbsp;{
&nbsp;    if (launchplace.obj)
&nbsp;        return TRUE;
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
force_launch_placement
&nbsp;void
&nbsp;force_launch_placement()
&nbsp;{
&nbsp;    if (launchplace.obj) {
&nbsp;        launchplace.obj-&gt;otrapped = 0;
&nbsp;        place_object(launchplace.obj, launchplace.x, launchplace.y);
&nbsp;    }
&nbsp;}
&nbsp;
launch_obj
&nbsp;/*
&nbsp; * Move obj from (x1,y1) to (x2,y2)
&nbsp; *
&nbsp; * Return 0 if no object was launched.
&nbsp; *        1 if an object was launched and placed somewhere.
&nbsp; *        2 if an object was launched, but used up.
&nbsp; */
&nbsp;int
&nbsp;launch_obj(otyp, x1, y1, x2, y2, style)
&nbsp;short otyp;
&nbsp;register int x1, y1, x2, y2;
&nbsp;int style;
&nbsp;{
&nbsp;    register struct monst *mtmp;
&nbsp;    register struct obj *otmp, *otmp2;
&nbsp;    register int dx, dy;
&nbsp;    struct obj *singleobj;
&nbsp;    boolean used_up = FALSE;
&nbsp;    boolean otherside = FALSE;
&nbsp;    int dist;
&nbsp;    int tmp;
&nbsp;    int delaycnt = 0;
&nbsp;
&nbsp;    otmp = sobj_at(otyp, x1, y1);
&nbsp;    /* Try the other side too, for rolling boulder traps */
&nbsp;    if (!otmp &amp;&amp; otyp == BOULDER) {
&nbsp;        otherside = TRUE;
&nbsp;        otmp = sobj_at(otyp, x2, y2);
&nbsp;    }
&nbsp;    if (!otmp)
&nbsp;        return 0;
&nbsp;    if (otherside) { /* swap 'em */
&nbsp;        int tx, ty;
&nbsp;
&nbsp;        tx = x1;
&nbsp;        ty = y1;
&nbsp;        x1 = x2;
&nbsp;        y1 = y2;
&nbsp;        x2 = tx;
&nbsp;        y2 = ty;
&nbsp;    }
&nbsp;
&nbsp;    if (otmp-&gt;quan == 1L) {
&nbsp;        obj_extract_self(otmp);
&nbsp;        singleobj = otmp;
&nbsp;        otmp = (struct obj *) 0;
&nbsp;    } else {
&nbsp;        singleobj = splitobj(otmp, 1L);
&nbsp;        obj_extract_self(singleobj);
&nbsp;    }
&nbsp;    newsym(x1, y1);
&nbsp;    /* in case you're using a pick-axe to chop the boulder that's being
&nbsp;       launched (perhaps a monster triggered it), destroy context so that
&nbsp;       next dig attempt never thinks you're resuming previous effort */
&nbsp;    if ((otyp == BOULDER || otyp == STATUE)
&nbsp;        &amp;&amp; singleobj-&gt;ox == context.digging.pos.x
&nbsp;        &amp;&amp; singleobj-&gt;oy == context.digging.pos.y)
&nbsp;        (void) memset((genericptr_t) &amp;context.digging, 0,
&nbsp;                      sizeof(struct dig_info));
&nbsp;
&nbsp;    dist = distmin(x1, y1, x2, y2);
&nbsp;    bhitpos.x = x1;
&nbsp;    bhitpos.y = y1;
&nbsp;    dx = sgn(x2 - x1);
&nbsp;    dy = sgn(y2 - y1);
&nbsp;    switch (style) {
&nbsp;    case ROLL | LAUNCH_UNSEEN:
&nbsp;        if (otyp == BOULDER) {
&nbsp;            You_hear(Hallucination ? "someone bowling."
&nbsp;                                   : "rumbling in the distance.");
&nbsp;        }
&nbsp;        style &amp;= ~LAUNCH_UNSEEN;
&nbsp;        goto roll;
&nbsp;    case ROLL | LAUNCH_KNOWN:
&nbsp;        /* use otrapped as a flag to ohitmon */
&nbsp;        singleobj-&gt;otrapped = 1;
&nbsp;        style &amp;= ~LAUNCH_KNOWN;
&nbsp;    /* fall through */
&nbsp;    roll:
&nbsp;    case ROLL:
&nbsp;        delaycnt = 2;
&nbsp;    /* fall through */
&nbsp;    default:
&nbsp;        if (!delaycnt)
&nbsp;            delaycnt = 1;
&nbsp;        if (!cansee(bhitpos.x, bhitpos.y))
&nbsp;            curs_on_u();
&nbsp;        tmp_at(DISP_FLASH, obj_to_glyph(singleobj));
&nbsp;        tmp_at(bhitpos.x, bhitpos.y);
&nbsp;    }
&nbsp;    /* Mark a spot to place object in bones files to prevent
&nbsp;     * loss of object. Use the starting spot to ensure that
&nbsp;     * a rolling boulder will still launch, which it wouldn't
&nbsp;     * do if left midstream. Unfortunately we can't use the
&nbsp;     * target resting spot, because there are some things/situations
&nbsp;     * that would prevent it from ever getting there (bars), and we
&nbsp;     * can't tell that yet.
&nbsp;     */
&nbsp;    launch_drop_spot(singleobj, bhitpos.x, bhitpos.y);
&nbsp;
&nbsp;    /* Set the object in motion */
&nbsp;    while (dist-- &gt; 0 &amp;&amp; !used_up) {
&nbsp;        struct trap *t;
&nbsp;        tmp_at(bhitpos.x, bhitpos.y);
&nbsp;        tmp = delaycnt;
&nbsp;
&nbsp;        /* dstage@u.washington.edu -- Delay only if hero sees it */
&nbsp;        if (cansee(bhitpos.x, bhitpos.y))
&nbsp;            while (tmp-- &gt; 0)
&nbsp;                delay_output();
&nbsp;
&nbsp;        bhitpos.x += dx;
&nbsp;        bhitpos.y += dy;
&nbsp;        t = t_at(bhitpos.x, bhitpos.y);
&nbsp;
&nbsp;        if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) {
&nbsp;            if (otyp == BOULDER &amp;&amp; throws_rocks(mtmp-&gt;data)) {
&nbsp;                if (rn2(3)) {
&nbsp;                    if (cansee(bhitpos.x, bhitpos.y))
&nbsp;                        pline("%s snatches the boulder.", Monnam(mtmp));
&nbsp;                    singleobj-&gt;otrapped = 0;
&nbsp;                    (void) mpickobj(mtmp, singleobj);
&nbsp;                    used_up = TRUE;
&nbsp;                    launch_drop_spot((struct obj *) 0, 0, 0);
&nbsp;                    break;
&nbsp;                }
&nbsp;            }
&nbsp;            if (ohitmon(mtmp, singleobj, (style == ROLL) ? -1 : dist,
&nbsp;                        FALSE)) {
&nbsp;                used_up = TRUE;
&nbsp;                launch_drop_spot((struct obj *) 0, 0, 0);
&nbsp;                break;
&nbsp;            }
&nbsp;        } else if (bhitpos.x == u.ux &amp;&amp; bhitpos.y == u.uy) {
&nbsp;            if (multi)
&nbsp;                nomul(0);
&nbsp;            if (thitu(9 + singleobj-&gt;spe, dmgval(singleobj, &amp;youmonst),
&nbsp;                      &amp;singleobj, (char *) 0))
&nbsp;                stop_occupation();
&nbsp;        }
&nbsp;        if (style == ROLL) {
&nbsp;            if (down_gate(bhitpos.x, bhitpos.y) != -1) {
&nbsp;                if (ship_object(singleobj, bhitpos.x, bhitpos.y, FALSE)) {
&nbsp;                    used_up = TRUE;
&nbsp;                    launch_drop_spot((struct obj *) 0, 0, 0);
&nbsp;                    break;
&nbsp;                }
&nbsp;            }
&nbsp;            if (t &amp;&amp; otyp == BOULDER) {
&nbsp;                switch (t-&gt;ttyp) {
&nbsp;                case LANDMINE:
&nbsp;                    if (rn2(10) &gt; 2) {
&nbsp;                        pline(
&nbsp;                            "KAABLAMM!!!%s",
&nbsp;                            cansee(bhitpos.x, bhitpos.y)
&nbsp;                                ? " The rolling boulder triggers a land mine."
&nbsp;                                : "");
&nbsp;                        deltrap(t);
&nbsp;                        del_engr_at(bhitpos.x, bhitpos.y);
&nbsp;                        place_object(singleobj, bhitpos.x, bhitpos.y);
&nbsp;                        singleobj-&gt;otrapped = 0;
&nbsp;                        fracture_rock(singleobj);
&nbsp;                        (void) scatter(bhitpos.x, bhitpos.y, 4,
&nbsp;                                       MAY_DESTROY | MAY_HIT | MAY_FRACTURE
&nbsp;                                           | VIS_EFFECTS,
&nbsp;                                       (struct obj *) 0);
&nbsp;                        if (cansee(bhitpos.x, bhitpos.y))
&nbsp;                            newsym(bhitpos.x, bhitpos.y);
&nbsp;                        used_up = TRUE;
&nbsp;                        launch_drop_spot((struct obj *) 0, 0, 0);
&nbsp;                    }
&nbsp;                    break;
&nbsp;                case LEVEL_TELEP:
&nbsp;                case TELEP_TRAP:
&nbsp;                    if (cansee(bhitpos.x, bhitpos.y))
&nbsp;                        pline("Suddenly the rolling boulder disappears!");
&nbsp;                    else
&nbsp;                        You_hear("a rumbling stop abruptly.");
&nbsp;                    singleobj-&gt;otrapped = 0;
&nbsp;                    if (t-&gt;ttyp == TELEP_TRAP)
&nbsp;                        (void) rloco(singleobj);
&nbsp;                    else {
&nbsp;                        int newlev = random_teleport_level();
&nbsp;                        d_level dest;
&nbsp;
&nbsp;                        if (newlev == depth(&amp;u.uz) || In_endgame(&amp;u.uz))
&nbsp;                            continue;
&nbsp;                        add_to_migration(singleobj);
&nbsp;                        get_level(&amp;dest, newlev);
&nbsp;                        singleobj-&gt;ox = dest.dnum;
&nbsp;                        singleobj-&gt;oy = dest.dlevel;
&nbsp;                        singleobj-&gt;owornmask = (long) MIGR_RANDOM;
&nbsp;                    }
&nbsp;                    seetrap(t);
&nbsp;                    used_up = TRUE;
&nbsp;                    launch_drop_spot((struct obj *) 0, 0, 0);
&nbsp;                    break;
&nbsp;                case PIT:
&nbsp;                case SPIKED_PIT:
&nbsp;                case HOLE:
&nbsp;                case TRAPDOOR:
&nbsp;                    /* the boulder won't be used up if there is a
&nbsp;                       monster in the trap; stop rolling anyway */
&nbsp;                    x2 = bhitpos.x, y2 = bhitpos.y; /* stops here */
&nbsp;                    if (flooreffects(singleobj, x2, y2, "fall")) {
&nbsp;                        used_up = TRUE;
&nbsp;                        launch_drop_spot((struct obj *) 0, 0, 0);
&nbsp;                    }
&nbsp;                    dist = -1; /* stop rolling immediately */
&nbsp;                    break;
&nbsp;                }
&nbsp;                if (used_up || dist == -1)
&nbsp;                    break;
&nbsp;            }
&nbsp;            if (flooreffects(singleobj, bhitpos.x, bhitpos.y, "fall")) {
&nbsp;                used_up = TRUE;
&nbsp;                launch_drop_spot((struct obj *) 0, 0, 0);
&nbsp;                break;
&nbsp;            }
&nbsp;            if (otyp == BOULDER
&nbsp;                &amp;&amp; (otmp2 = sobj_at(BOULDER, bhitpos.x, bhitpos.y)) != 0) {
&nbsp;                const char *bmsg = " as one boulder sets another in motion";
&nbsp;
&nbsp;                if (!isok(bhitpos.x + dx, bhitpos.y + dy) || !dist
&nbsp;                    || IS_ROCK(levl[bhitpos.x + dx][bhitpos.y + dy].typ))
&nbsp;                    bmsg = " as one boulder hits another";
&nbsp;
&nbsp;                You_hear("a loud crash%s!",
&nbsp;                         cansee(bhitpos.x, bhitpos.y) ? bmsg : "");
&nbsp;                obj_extract_self(otmp2);
&nbsp;                /* pass off the otrapped flag to the next boulder */
&nbsp;                otmp2-&gt;otrapped = singleobj-&gt;otrapped;
&nbsp;                singleobj-&gt;otrapped = 0;
&nbsp;                place_object(singleobj, bhitpos.x, bhitpos.y);
&nbsp;                singleobj = otmp2;
&nbsp;                otmp2 = (struct obj *) 0;
&nbsp;                wake_nearto(bhitpos.x, bhitpos.y, 10 * 10);
&nbsp;            }
&nbsp;        }
&nbsp;        if (otyp == BOULDER &amp;&amp; closed_door(bhitpos.x, bhitpos.y)) {
&nbsp;            if (cansee(bhitpos.x, bhitpos.y))
&nbsp;                pline_The("boulder crashes through a door.");
&nbsp;            levl[bhitpos.x][bhitpos.y].doormask = D_BROKEN;
&nbsp;            if (dist)
&nbsp;                unblock_point(bhitpos.x, bhitpos.y);
&nbsp;        }
&nbsp;
&nbsp;        /* if about to hit iron bars, do so now */
&nbsp;        if (dist &gt; 0 &amp;&amp; isok(bhitpos.x + dx, bhitpos.y + dy)
&nbsp;            &amp;&amp; levl[bhitpos.x + dx][bhitpos.y + dy].typ == IRONBARS) {
&nbsp;            x2 = bhitpos.x, y2 = bhitpos.y; /* object stops here */
&nbsp;            if (hits_bars(&amp;singleobj,
&nbsp;                          x2, y2, x2+dx, y2+dy,
&nbsp;                          !rn2(20), 0)) {
&nbsp;                if (!singleobj) {
&nbsp;                    used_up = TRUE;
&nbsp;                    launch_drop_spot((struct obj *) 0, 0, 0);
&nbsp;                }
&nbsp;                break;
&nbsp;            }
&nbsp;        }
&nbsp;    }
&nbsp;    tmp_at(DISP_END, 0);
&nbsp;    launch_drop_spot((struct obj *) 0, 0, 0);
&nbsp;    if (!used_up) {
&nbsp;        singleobj-&gt;otrapped = 0;
&nbsp;        place_object(singleobj, x2, y2);
&nbsp;        newsym(x2, y2);
&nbsp;        return 1;
&nbsp;    } else
&nbsp;        return 2;
&nbsp;}
&nbsp;
seetrap
&nbsp;void
&nbsp;seetrap(trap)
&nbsp;struct trap *trap;
&nbsp;{
&nbsp;    if (!trap-&gt;tseen) {
&nbsp;        trap-&gt;tseen = 1;
&nbsp;        newsym(trap-&gt;tx, trap-&gt;ty);
&nbsp;    }
&nbsp;}
&nbsp;
feeltrap
&nbsp;/* like seetrap() but overrides vision */
&nbsp;void
&nbsp;feeltrap(trap)
&nbsp;struct trap *trap;
&nbsp;{
&nbsp;    trap-&gt;tseen = 1;
&nbsp;    map_trap(trap, 1);
&nbsp;    /* in case it's beneath something, redisplay the something */
&nbsp;    newsym(trap-&gt;tx, trap-&gt;ty);
&nbsp;}
&nbsp;
mkroll_launch
&nbsp;STATIC_OVL int
&nbsp;mkroll_launch(ttmp, x, y, otyp, ocount)
&nbsp;struct trap *ttmp;
&nbsp;xchar x, y;
&nbsp;short otyp;
&nbsp;long ocount;
&nbsp;{
&nbsp;    struct obj *otmp;
&nbsp;    register int tmp;
&nbsp;    schar dx, dy;
&nbsp;    int distance;
&nbsp;    coord cc;
&nbsp;    coord bcc;
&nbsp;    int trycount = 0;
&nbsp;    boolean success = FALSE;
&nbsp;    int mindist = 4;
&nbsp;
&nbsp;    if (ttmp-&gt;ttyp == ROLLING_BOULDER_TRAP)
&nbsp;        mindist = 2;
&nbsp;    distance = rn1(5, 4); /* 4..8 away */
&nbsp;    tmp = rn2(8);         /* randomly pick a direction to try first */
&nbsp;    while (distance &gt;= mindist) {
&nbsp;        dx = xdir[tmp];
&nbsp;        dy = ydir[tmp];
&nbsp;        cc.x = x;
&nbsp;        cc.y = y;
&nbsp;        /* Prevent boulder from being placed on water */
&nbsp;        if (ttmp-&gt;ttyp == ROLLING_BOULDER_TRAP
&nbsp;            &amp;&amp; is_pool_or_lava(x + distance * dx, y + distance * dy))
&nbsp;            success = FALSE;
&nbsp;        else
&nbsp;            success = isclearpath(&amp;cc, distance, dx, dy);
&nbsp;        if (ttmp-&gt;ttyp == ROLLING_BOULDER_TRAP) {
&nbsp;            boolean success_otherway;
&nbsp;
&nbsp;            bcc.x = x;
&nbsp;            bcc.y = y;
&nbsp;            success_otherway = isclearpath(&amp;bcc, distance, -(dx), -(dy));
&nbsp;            if (!success_otherway)
&nbsp;                success = FALSE;
&nbsp;        }
&nbsp;        if (success)
&nbsp;            break;
&nbsp;        if (++tmp &gt; 7)
&nbsp;            tmp = 0;
&nbsp;        if ((++trycount % 8) == 0)
&nbsp;            --distance;
&nbsp;    }
&nbsp;    if (!success) {
&nbsp;        /* create the trap without any ammo, launch pt at trap location */
&nbsp;        cc.x = bcc.x = x;
&nbsp;        cc.y = bcc.y = y;
&nbsp;    } else {
&nbsp;        otmp = mksobj(otyp, TRUE, FALSE);
&nbsp;        otmp-&gt;quan = ocount;
&nbsp;        otmp-&gt;owt = weight(otmp);
&nbsp;        place_object(otmp, cc.x, cc.y);
&nbsp;        stackobj(otmp);
&nbsp;    }
&nbsp;    ttmp-&gt;launch.x = cc.x;
&nbsp;    ttmp-&gt;launch.y = cc.y;
&nbsp;    if (ttmp-&gt;ttyp == ROLLING_BOULDER_TRAP) {
&nbsp;        ttmp-&gt;launch2.x = bcc.x;
&nbsp;        ttmp-&gt;launch2.y = bcc.y;
&nbsp;    } else
&nbsp;        ttmp-&gt;launch_otyp = otyp;
&nbsp;    newsym(ttmp-&gt;launch.x, ttmp-&gt;launch.y);
&nbsp;    return 1;
&nbsp;}
&nbsp;
isclearpath
&nbsp;STATIC_OVL boolean
&nbsp;isclearpath(cc, distance, dx, dy)
&nbsp;coord *cc;
&nbsp;int distance;
&nbsp;schar dx, dy;
&nbsp;{
&nbsp;    uchar typ;
&nbsp;    xchar x, y;
&nbsp;
&nbsp;    x = cc-&gt;x;
&nbsp;    y = cc-&gt;y;
&nbsp;    while (distance-- &gt; 0) {
&nbsp;        x += dx;
&nbsp;        y += dy;
&nbsp;        typ = levl[x][y].typ;
&nbsp;        if (!isok(x, y) || !ZAP_POS(typ) || closed_door(x, y))
&nbsp;            return FALSE;
&nbsp;    }
&nbsp;    cc-&gt;x = x;
&nbsp;    cc-&gt;y = y;
&nbsp;    return TRUE;
&nbsp;}
&nbsp;
mintrap
&nbsp;int
&nbsp;mintrap(mtmp)
&nbsp;register struct monst *mtmp;
&nbsp;{
&nbsp;    register struct trap *trap = t_at(mtmp-&gt;mx, mtmp-&gt;my);
&nbsp;    boolean trapkilled = FALSE;
&nbsp;    struct permonst *mptr = mtmp-&gt;data;
&nbsp;    struct obj *otmp;
&nbsp;
&nbsp;    if (!trap) {
&nbsp;        mtmp-&gt;mtrapped = 0;      /* perhaps teleported? */
&nbsp;    } else if (mtmp-&gt;mtrapped) { /* is currently in the trap */
&nbsp;        if (!trap-&gt;tseen &amp;&amp; cansee(mtmp-&gt;mx, mtmp-&gt;my) &amp;&amp; canseemon(mtmp)
&nbsp;            &amp;&amp; (trap-&gt;ttyp == SPIKED_PIT || trap-&gt;ttyp == BEAR_TRAP
&nbsp;                || trap-&gt;ttyp == HOLE || trap-&gt;ttyp == PIT
&nbsp;                || trap-&gt;ttyp == WEB)) {
&nbsp;            /* If you come upon an obviously trapped monster, then
&nbsp;             * you must be able to see the trap it's in too.
&nbsp;             */
&nbsp;            seetrap(trap);
&nbsp;        }
&nbsp;
&nbsp;        if (!rn2(40)) {
&nbsp;            if (sobj_at(BOULDER, mtmp-&gt;mx, mtmp-&gt;my)
&nbsp;                &amp;&amp; (trap-&gt;ttyp == PIT || trap-&gt;ttyp == SPIKED_PIT)) {
&nbsp;                if (!rn2(2)) {
&nbsp;                    mtmp-&gt;mtrapped = 0;
&nbsp;                    if (canseemon(mtmp))
&nbsp;                        pline("%s pulls free...", Monnam(mtmp));
&nbsp;                    fill_pit(mtmp-&gt;mx, mtmp-&gt;my);
&nbsp;                }
&nbsp;            } else {
&nbsp;                mtmp-&gt;mtrapped = 0;
&nbsp;            }
&nbsp;        } else if (metallivorous(mptr)) {
&nbsp;            if (trap-&gt;ttyp == BEAR_TRAP) {
&nbsp;                if (canseemon(mtmp))
&nbsp;                    pline("%s eats a bear trap!", Monnam(mtmp));
&nbsp;                deltrap(trap);
&nbsp;                mtmp-&gt;meating = 5;
&nbsp;                mtmp-&gt;mtrapped = 0;
&nbsp;            } else if (trap-&gt;ttyp == SPIKED_PIT) {
&nbsp;                if (canseemon(mtmp))
&nbsp;                    pline("%s munches on some spikes!", Monnam(mtmp));
&nbsp;                trap-&gt;ttyp = PIT;
&nbsp;                mtmp-&gt;meating = 5;
&nbsp;            }
&nbsp;        }
&nbsp;    } else {
&nbsp;        register int tt = trap-&gt;ttyp;
&nbsp;        boolean in_sight, tear_web, see_it,
&nbsp;            inescapable = force_mintrap || ((tt == HOLE || tt == PIT)
&nbsp;                                            &amp;&amp; Sokoban &amp;&amp; !trap-&gt;madeby_u);
&nbsp;        const char *fallverb;
&nbsp;
&nbsp;        /* true when called from dotrap, inescapable is not an option */
&nbsp;        if (mtmp == u.usteed)
&nbsp;            inescapable = TRUE;
&nbsp;        if (!inescapable &amp;&amp; ((mtmp-&gt;mtrapseen &amp; (1 &lt;&lt; (tt - 1))) != 0
&nbsp;                             || (tt == HOLE &amp;&amp; !mindless(mptr)))) {
&nbsp;            /* it has been in such a trap - perhaps it escapes */
&nbsp;            if (rn2(4))
&nbsp;                return 0;
&nbsp;        } else {
&nbsp;            mtmp-&gt;mtrapseen |= (1 &lt;&lt; (tt - 1));
&nbsp;        }
&nbsp;        /* Monster is aggravated by being trapped by you.
&nbsp;           Recognizing who made the trap isn't completely
&nbsp;           unreasonable; everybody has their own style. */
&nbsp;        if (trap-&gt;madeby_u &amp;&amp; rnl(5))
&nbsp;            setmangry(mtmp, TRUE);
&nbsp;
&nbsp;        in_sight = canseemon(mtmp);
&nbsp;        see_it = cansee(mtmp-&gt;mx, mtmp-&gt;my);
&nbsp;        /* assume hero can tell what's going on for the steed */
&nbsp;        if (mtmp == u.usteed)
&nbsp;            in_sight = TRUE;
&nbsp;        switch (tt) {
&nbsp;        case ARROW_TRAP:
&nbsp;            if (trap-&gt;once &amp;&amp; trap-&gt;tseen &amp;&amp; !rn2(15)) {
&nbsp;                if (in_sight &amp;&amp; see_it)
&nbsp;                    pline("%s triggers a trap but nothing happens.",
&nbsp;                          Monnam(mtmp));
&nbsp;                deltrap(trap);
&nbsp;                newsym(mtmp-&gt;mx, mtmp-&gt;my);
&nbsp;                break;
&nbsp;            }
&nbsp;            trap-&gt;once = 1;
&nbsp;            otmp = mksobj(ARROW, TRUE, FALSE);
&nbsp;            otmp-&gt;quan = 1L;
&nbsp;            otmp-&gt;owt = weight(otmp);
&nbsp;            otmp-&gt;opoisoned = 0;
&nbsp;            if (in_sight)
&nbsp;                seetrap(trap);
&nbsp;            if (thitm(8, mtmp, otmp, 0, FALSE))
&nbsp;                trapkilled = TRUE;
&nbsp;            break;
&nbsp;        case DART_TRAP:
&nbsp;            if (trap-&gt;once &amp;&amp; trap-&gt;tseen &amp;&amp; !rn2(15)) {
&nbsp;                if (in_sight &amp;&amp; see_it)
&nbsp;                    pline("%s triggers a trap but nothing happens.",
&nbsp;                          Monnam(mtmp));
&nbsp;                deltrap(trap);
&nbsp;                newsym(mtmp-&gt;mx, mtmp-&gt;my);
&nbsp;                break;
&nbsp;            }
&nbsp;            trap-&gt;once = 1;
&nbsp;            otmp = mksobj(DART, TRUE, FALSE);
&nbsp;            otmp-&gt;quan = 1L;
&nbsp;            otmp-&gt;owt = weight(otmp);
&nbsp;            if (!rn2(6))
&nbsp;                otmp-&gt;opoisoned = 1;
&nbsp;            if (in_sight)
&nbsp;                seetrap(trap);
&nbsp;            if (thitm(7, mtmp, otmp, 0, FALSE))
&nbsp;                trapkilled = TRUE;
&nbsp;            break;
&nbsp;        case ROCKTRAP:
&nbsp;            if (trap-&gt;once &amp;&amp; trap-&gt;tseen &amp;&amp; !rn2(15)) {
&nbsp;                if (in_sight &amp;&amp; see_it)
&nbsp;                    pline(
&nbsp;                        "A trap door above %s opens, but nothing falls out!",
&nbsp;                        mon_nam(mtmp));
&nbsp;                deltrap(trap);
&nbsp;                newsym(mtmp-&gt;mx, mtmp-&gt;my);
&nbsp;                break;
&nbsp;            }
&nbsp;            trap-&gt;once = 1;
&nbsp;            otmp = mksobj(ROCK, TRUE, FALSE);
&nbsp;            otmp-&gt;quan = 1L;
&nbsp;            otmp-&gt;owt = weight(otmp);
&nbsp;            if (in_sight)
&nbsp;                seetrap(trap);
&nbsp;            if (thitm(0, mtmp, otmp, d(2, 6), FALSE))
&nbsp;                trapkilled = TRUE;
&nbsp;            break;
&nbsp;        case SQKY_BOARD:
&nbsp;            if (is_flyer(mptr))
&nbsp;                break;
&nbsp;            /* stepped on a squeaky board */
&nbsp;            if (in_sight) {
&nbsp;                if (!Deaf) {
&nbsp;                    pline("A board beneath %s squeaks %s loudly.",
&nbsp;                          mon_nam(mtmp), trapnote(trap, 0));
&nbsp;                    seetrap(trap);
&nbsp;                } else {
&nbsp;                    pline("%s stops momentarily and appears to cringe.",
&nbsp;                          Monnam(mtmp));
&nbsp;                }
&nbsp;            } else {
&nbsp;                /* same near/far threshold as mzapmsg() */
&nbsp;                int range = couldsee(mtmp-&gt;mx, mtmp-&gt;my) /* 9 or 5 */
&nbsp;                               ? (BOLT_LIM + 1) : (BOLT_LIM - 3);
&nbsp;
&nbsp;                You_hear("a %s squeak %s.", trapnote(trap, 1),
&nbsp;                         (distu(mtmp-&gt;mx, mtmp-&gt;my) &lt;= range * range)
&nbsp;                            ? "nearby" : "in the distance");
&nbsp;            }
&nbsp;            /* wake up nearby monsters */
&nbsp;            wake_nearto(mtmp-&gt;mx, mtmp-&gt;my, 40);
&nbsp;            break;
&nbsp;        case BEAR_TRAP:
&nbsp;            if (mptr-&gt;msize &gt; MZ_SMALL &amp;&amp; !amorphous(mptr) &amp;&amp; !is_flyer(mptr)
&nbsp;                &amp;&amp; !is_whirly(mptr) &amp;&amp; !unsolid(mptr)) {
&nbsp;                mtmp-&gt;mtrapped = 1;
&nbsp;                if (in_sight) {
&nbsp;                    pline("%s is caught in %s bear trap!", Monnam(mtmp),
&nbsp;                          a_your[trap-&gt;madeby_u]);
&nbsp;                    seetrap(trap);
&nbsp;                } else {
&nbsp;                    if (mptr == &amp;mons[PM_OWLBEAR]
&nbsp;                        || mptr == &amp;mons[PM_BUGBEAR])
&nbsp;                        You_hear("the roaring of an angry bear!");
&nbsp;                }
&nbsp;            } else if (force_mintrap) {
&nbsp;                if (in_sight) {
&nbsp;                    pline("%s evades %s bear trap!", Monnam(mtmp),
&nbsp;                          a_your[trap-&gt;madeby_u]);
&nbsp;                    seetrap(trap);
&nbsp;                }
&nbsp;            }
&nbsp;            if (mtmp-&gt;mtrapped)
&nbsp;                trapkilled = thitm(0, mtmp, (struct obj *) 0, d(2, 4), FALSE);
&nbsp;            break;
&nbsp;        case SLP_GAS_TRAP:
&nbsp;            if (!resists_sleep(mtmp) &amp;&amp; !breathless(mptr) &amp;&amp; !mtmp-&gt;msleeping
&nbsp;                &amp;&amp; mtmp-&gt;mcanmove) {
&nbsp;                if (sleep_monst(mtmp, rnd(25), -1) &amp;&amp; in_sight) {
&nbsp;                    pline("%s suddenly falls asleep!", Monnam(mtmp));
&nbsp;                    seetrap(trap);
&nbsp;                }
&nbsp;            }
&nbsp;            break;
&nbsp;        case RUST_TRAP: {
&nbsp;            struct obj *target;
&nbsp;
&nbsp;            if (in_sight)
&nbsp;                seetrap(trap);
&nbsp;            switch (rn2(5)) {
&nbsp;            case 0:
&nbsp;                if (in_sight)
&nbsp;                    pline("%s %s on the %s!", A_gush_of_water_hits,
&nbsp;                          mon_nam(mtmp), mbodypart(mtmp, HEAD));
&nbsp;                target = which_armor(mtmp, W_ARMH);
&nbsp;                (void) water_damage(target, helm_simple_name(target), TRUE);
&nbsp;                break;
&nbsp;            case 1:
&nbsp;                if (in_sight)
&nbsp;                    pline("%s %s's left %s!", A_gush_of_water_hits,
&nbsp;                          mon_nam(mtmp), mbodypart(mtmp, ARM));
&nbsp;                target = which_armor(mtmp, W_ARMS);
&nbsp;                if (water_damage(target, "shield", TRUE) != ER_NOTHING)
&nbsp;                    break;
&nbsp;                target = MON_WEP(mtmp);
&nbsp;                if (target &amp;&amp; bimanual(target))
&nbsp;                    (void) water_damage(target, 0, TRUE);
&nbsp;            glovecheck:
&nbsp;                target = which_armor(mtmp, W_ARMG);
&nbsp;                (void) water_damage(target, "gauntlets", TRUE);
&nbsp;                break;
&nbsp;            case 2:
&nbsp;                if (in_sight)
&nbsp;                    pline("%s %s's right %s!", A_gush_of_water_hits,
&nbsp;                          mon_nam(mtmp), mbodypart(mtmp, ARM));
&nbsp;                (void) water_damage(MON_WEP(mtmp), 0, TRUE);
&nbsp;                goto glovecheck;
&nbsp;            default:
&nbsp;                if (in_sight)
&nbsp;                    pline("%s %s!", A_gush_of_water_hits, mon_nam(mtmp));
&nbsp;                for (otmp = mtmp-&gt;minvent; otmp; otmp = otmp-&gt;nobj)
&nbsp;                    if (otmp-&gt;lamplit
&nbsp;                        &amp;&amp; (otmp-&gt;owornmask &amp; (W_WEP | W_SWAPWEP)) == 0)
&nbsp;                        (void) snuff_lit(otmp);
&nbsp;                if ((target = which_armor(mtmp, W_ARMC)) != 0)
&nbsp;                    (void) water_damage(target, cloak_simple_name(target),
&nbsp;                                        TRUE);
&nbsp;                else if ((target = which_armor(mtmp, W_ARM)) != 0)
&nbsp;                    (void) water_damage(target, suit_simple_name(target),
&nbsp;                                        TRUE);
&nbsp;                else if ((target = which_armor(mtmp, W_ARMU)) != 0)
&nbsp;                    (void) water_damage(target, "shirt", TRUE);
&nbsp;            }
&nbsp;
&nbsp;            if (mptr == &amp;mons[PM_IRON_GOLEM]) {
&nbsp;                if (in_sight)
&nbsp;                    pline("%s falls to pieces!", Monnam(mtmp));
&nbsp;                else if (mtmp-&gt;mtame)
&nbsp;                    pline("May %s rust in peace.", mon_nam(mtmp));
&nbsp;                mondied(mtmp);
&nbsp;                if (mtmp-&gt;mhp &lt;= 0)
&nbsp;                    trapkilled = TRUE;
&nbsp;            } else if (mptr == &amp;mons[PM_GREMLIN] &amp;&amp; rn2(3)) {
&nbsp;                (void) split_mon(mtmp, (struct monst *) 0);
&nbsp;            }
&nbsp;            break;
&nbsp;        } /* RUST_TRAP */
&nbsp;        case FIRE_TRAP:
&nbsp;        mfiretrap:
&nbsp;            if (in_sight)
&nbsp;                pline("A %s erupts from the %s under %s!", tower_of_flame,
&nbsp;                      surface(mtmp-&gt;mx, mtmp-&gt;my), mon_nam(mtmp));
&nbsp;            else if (see_it) /* evidently `mtmp' is invisible */
&nbsp;                You_see("a %s erupt from the %s!", tower_of_flame,
&nbsp;                        surface(mtmp-&gt;mx, mtmp-&gt;my));
&nbsp;
&nbsp;            if (resists_fire(mtmp)) {
&nbsp;                if (in_sight) {
&nbsp;                    shieldeff(mtmp-&gt;mx, mtmp-&gt;my);
&nbsp;                    pline("%s is uninjured.", Monnam(mtmp));
&nbsp;                }
&nbsp;            } else {
&nbsp;                int num = d(2, 4), alt;
&nbsp;                boolean immolate = FALSE;
&nbsp;
&nbsp;                /* paper burns very fast, assume straw is tightly
&nbsp;                 * packed and burns a bit slower */
&nbsp;                switch (monsndx(mptr)) {
&nbsp;                case PM_PAPER_GOLEM:
&nbsp;                    immolate = TRUE;
&nbsp;                    alt = mtmp-&gt;mhpmax;
&nbsp;                    break;
&nbsp;                case PM_STRAW_GOLEM:
&nbsp;                    alt = mtmp-&gt;mhpmax / 2;
&nbsp;                    break;
&nbsp;                case PM_WOOD_GOLEM:
&nbsp;                    alt = mtmp-&gt;mhpmax / 4;
&nbsp;                    break;
&nbsp;                case PM_LEATHER_GOLEM:
&nbsp;                    alt = mtmp-&gt;mhpmax / 8;
&nbsp;                    break;
&nbsp;                default:
&nbsp;                    alt = 0;
&nbsp;                    break;
&nbsp;                }
&nbsp;                if (alt &gt; num)
&nbsp;                    num = alt;
&nbsp;
&nbsp;                if (thitm(0, mtmp, (struct obj *) 0, num, immolate))
&nbsp;                    trapkilled = TRUE;
&nbsp;                else
&nbsp;                    /* we know mhp is at least `num' below mhpmax,
&nbsp;                       so no (mhp &gt; mhpmax) check is needed here */
&nbsp;                    mtmp-&gt;mhpmax -= rn2(num + 1);
&nbsp;            }
&nbsp;            if (burnarmor(mtmp) || rn2(3)) {
&nbsp;                (void) destroy_mitem(mtmp, SCROLL_CLASS, AD_FIRE);
&nbsp;                (void) destroy_mitem(mtmp, SPBOOK_CLASS, AD_FIRE);
&nbsp;                (void) destroy_mitem(mtmp, POTION_CLASS, AD_FIRE);
&nbsp;            }
&nbsp;            if (burn_floor_objects(mtmp-&gt;mx, mtmp-&gt;my, see_it, FALSE)
&nbsp;                &amp;&amp; !see_it &amp;&amp; distu(mtmp-&gt;mx, mtmp-&gt;my) &lt;= 3 * 3)
&nbsp;                You("smell smoke.");
&nbsp;            if (is_ice(mtmp-&gt;mx, mtmp-&gt;my))
&nbsp;                melt_ice(mtmp-&gt;mx, mtmp-&gt;my, (char *) 0);
&nbsp;            if (see_it)
&nbsp;                seetrap(trap);
&nbsp;            break;
&nbsp;        case PIT:
&nbsp;        case SPIKED_PIT:
&nbsp;            fallverb = "falls";
&nbsp;            if (is_flyer(mptr) || is_floater(mptr)
&nbsp;                || (mtmp-&gt;wormno &amp;&amp; count_wsegs(mtmp) &gt; 5)
&nbsp;                || is_clinger(mptr)) {
&nbsp;                if (force_mintrap &amp;&amp; !Sokoban) {
&nbsp;                    /* openfallingtrap; not inescapable here */
&nbsp;                    if (in_sight) {
&nbsp;                        seetrap(trap);
&nbsp;                        pline("%s doesn't fall into the pit.", Monnam(mtmp));
&nbsp;                    }
&nbsp;                    break; /* inescapable = FALSE; */
&nbsp;                }
&nbsp;                if (!inescapable)
&nbsp;                    break;               /* avoids trap */
&nbsp;                fallverb = "is dragged"; /* sokoban pit */
&nbsp;            }
&nbsp;            if (!passes_walls(mptr))
&nbsp;                mtmp-&gt;mtrapped = 1;
&nbsp;            if (in_sight) {
&nbsp;                pline("%s %s into %s pit!", Monnam(mtmp), fallverb,
&nbsp;                      a_your[trap-&gt;madeby_u]);
&nbsp;                if (mptr == &amp;mons[PM_PIT_VIPER]
&nbsp;                    || mptr == &amp;mons[PM_PIT_FIEND])
&nbsp;                    pline("How pitiful.  Isn't that the pits?");
&nbsp;                seetrap(trap);
&nbsp;            }
&nbsp;            mselftouch(mtmp, "Falling, ", FALSE);
&nbsp;            if (mtmp-&gt;mhp &lt;= 0 || thitm(0, mtmp, (struct obj *) 0,
&nbsp;                                        rnd((tt == PIT) ? 6 : 10), FALSE))
&nbsp;                trapkilled = TRUE;
&nbsp;            break;
&nbsp;        case HOLE:
&nbsp;        case TRAPDOOR:
&nbsp;            if (!Can_fall_thru(&amp;u.uz)) {
&nbsp;                impossible("mintrap: %ss cannot exist on this level.",
&nbsp;                           defsyms[trap_to_defsym(tt)].explanation);
&nbsp;                break; /* don't activate it after all */
&nbsp;            }
&nbsp;            if (is_flyer(mptr) || is_floater(mptr) || mptr == &amp;mons[PM_WUMPUS]
&nbsp;                || (mtmp-&gt;wormno &amp;&amp; count_wsegs(mtmp) &gt; 5)
&nbsp;                || mptr-&gt;msize &gt;= MZ_HUGE) {
&nbsp;                if (force_mintrap &amp;&amp; !Sokoban) {
&nbsp;                    /* openfallingtrap; not inescapable here */
&nbsp;                    if (in_sight) {
&nbsp;                        seetrap(trap);
&nbsp;                        if (tt == TRAPDOOR)
&nbsp;                            pline(
&nbsp;                            "A trap door opens, but %s doesn't fall through.",
&nbsp;                                  mon_nam(mtmp));
&nbsp;                        else /* (tt == HOLE) */
&nbsp;                            pline("%s doesn't fall through the hole.",
&nbsp;                                  Monnam(mtmp));
&nbsp;                    }
&nbsp;                    break; /* inescapable = FALSE; */
&nbsp;                }
&nbsp;                if (inescapable) { /* sokoban hole */
&nbsp;                    if (in_sight) {
&nbsp;                        pline("%s seems to be yanked down!", Monnam(mtmp));
&nbsp;                        /* suppress message in mlevel_tele_trap() */
&nbsp;                        in_sight = FALSE;
&nbsp;                        seetrap(trap);
&nbsp;                    }
&nbsp;                } else
&nbsp;                    break;
&nbsp;            }
&nbsp;            /*FALLTHRU*/
&nbsp;        case LEVEL_TELEP:
&nbsp;        case MAGIC_PORTAL: {
&nbsp;            int mlev_res;
&nbsp;
&nbsp;            mlev_res = mlevel_tele_trap(mtmp, trap, inescapable, in_sight);
&nbsp;            if (mlev_res)
&nbsp;                return mlev_res;
&nbsp;            break;
&nbsp;        }
&nbsp;        case TELEP_TRAP:
&nbsp;            mtele_trap(mtmp, trap, in_sight);
&nbsp;            break;
&nbsp;        case WEB:
&nbsp;            /* Monster in a web. */
&nbsp;            if (webmaker(mptr))
&nbsp;                break;
&nbsp;            if (mu_maybe_destroy_web(mtmp, in_sight, trap))
&nbsp;                break;
&nbsp;            tear_web = FALSE;
&nbsp;            switch (monsndx(mptr)) {
&nbsp;            case PM_OWLBEAR: /* Eric Backus */
&nbsp;            case PM_BUGBEAR:
&nbsp;                if (!in_sight) {
&nbsp;                    You_hear("the roaring of a confused bear!");
&nbsp;                    mtmp-&gt;mtrapped = 1;
&nbsp;                    break;
&nbsp;                }
&nbsp;                /*FALLTHRU*/
&nbsp;            default:
&nbsp;                if (mptr-&gt;mlet == S_GIANT
&nbsp;                    /* exclude baby dragons and relatively short worms */
&nbsp;                    || (mptr-&gt;mlet == S_DRAGON &amp;&amp; extra_nasty(mptr))
&nbsp;                    || (mtmp-&gt;wormno &amp;&amp; count_wsegs(mtmp) &gt; 5)) {
&nbsp;                    tear_web = TRUE;
&nbsp;                } else if (in_sight) {
&nbsp;                    pline("%s is caught in %s spider web.", Monnam(mtmp),
&nbsp;                          a_your[trap-&gt;madeby_u]);
&nbsp;                    seetrap(trap);
&nbsp;                }
&nbsp;                mtmp-&gt;mtrapped = tear_web ? 0 : 1;
&nbsp;                break;
&nbsp;            /* this list is fairly arbitrary; it deliberately
&nbsp;               excludes wumpus &amp; giant/ettin zombies/mummies */
&nbsp;            case PM_TITANOTHERE:
&nbsp;            case PM_BALUCHITHERIUM:
&nbsp;            case PM_PURPLE_WORM:
&nbsp;            case PM_JABBERWOCK:
&nbsp;            case PM_IRON_GOLEM:
&nbsp;            case PM_BALROG:
&nbsp;            case PM_KRAKEN:
&nbsp;            case PM_MASTODON:
&nbsp;            case PM_ORION:
&nbsp;            case PM_NORN:
&nbsp;            case PM_CYCLOPS:
&nbsp;            case PM_LORD_SURTUR:
&nbsp;                tear_web = TRUE;
&nbsp;                break;
&nbsp;            }
&nbsp;            if (tear_web) {
&nbsp;                if (in_sight)
&nbsp;                    pline("%s tears through %s spider web!", Monnam(mtmp),
&nbsp;                          a_your[trap-&gt;madeby_u]);
&nbsp;                deltrap(trap);
&nbsp;                newsym(mtmp-&gt;mx, mtmp-&gt;my);
&nbsp;            } else if (force_mintrap &amp;&amp; !mtmp-&gt;mtrapped) {
&nbsp;                if (in_sight) {
&nbsp;                    pline("%s avoids %s spider web!", Monnam(mtmp),
&nbsp;                          a_your[trap-&gt;madeby_u]);
&nbsp;                    seetrap(trap);
&nbsp;                }
&nbsp;            }
&nbsp;            break;
&nbsp;        case STATUE_TRAP:
&nbsp;            break;
&nbsp;        case MAGIC_TRAP:
&nbsp;            /* A magic trap.  Monsters usually immune. */
&nbsp;            if (!rn2(21))
&nbsp;                goto mfiretrap;
&nbsp;            break;
&nbsp;        case ANTI_MAGIC:
&nbsp;            /* similar to hero's case, more or less */
&nbsp;            if (!resists_magm(mtmp)) { /* lose spell energy */
&nbsp;                if (!mtmp-&gt;mcan &amp;&amp; (attacktype(mptr, AT_MAGC)
&nbsp;                                    || attacktype(mptr, AT_BREA))) {
&nbsp;                    mtmp-&gt;mspec_used += d(2, 2);
&nbsp;                    if (in_sight) {
&nbsp;                        seetrap(trap);
&nbsp;                        pline("%s seems lethargic.", Monnam(mtmp));
&nbsp;                    }
&nbsp;                }
&nbsp;            } else { /* take some damage */
&nbsp;                int dmgval2 = rnd(4);
&nbsp;
&nbsp;                if ((otmp = MON_WEP(mtmp)) != 0
&nbsp;                    &amp;&amp; otmp-&gt;oartifact == ART_MAGICBANE)
&nbsp;                    dmgval2 += rnd(4);
&nbsp;                for (otmp = mtmp-&gt;minvent; otmp; otmp = otmp-&gt;nobj)
&nbsp;                    if (otmp-&gt;oartifact
&nbsp;                        &amp;&amp; defends_when_carried(AD_MAGM, otmp))
&nbsp;                        break;
&nbsp;                if (otmp)
&nbsp;                    dmgval2 += rnd(4);
&nbsp;                if (passes_walls(mptr))
&nbsp;                    dmgval2 = (dmgval2 + 3) / 4;
&nbsp;
&nbsp;                if (in_sight)
&nbsp;                    seetrap(trap);
&nbsp;                mtmp-&gt;mhp -= dmgval2;
&nbsp;                if (mtmp-&gt;mhp &lt;= 0)
&nbsp;                    monkilled(mtmp,
&nbsp;                              in_sight
&nbsp;                                  ? "compression from an anti-magic field"
&nbsp;                                  : (const char *) 0,
&nbsp;                              -AD_MAGM);
&nbsp;                if (mtmp-&gt;mhp &lt;= 0)
&nbsp;                    trapkilled = TRUE;
&nbsp;                if (see_it)
&nbsp;                    newsym(trap-&gt;tx, trap-&gt;ty);
&nbsp;            }
&nbsp;            break;
&nbsp;        case LANDMINE:
&nbsp;            if (rn2(3))
&nbsp;                break; /* monsters usually don't set it off */
&nbsp;            if (is_flyer(mptr)) {
&nbsp;                boolean already_seen = trap-&gt;tseen;
&nbsp;
&nbsp;                if (in_sight &amp;&amp; !already_seen) {
&nbsp;                    pline("A trigger appears in a pile of soil below %s.",
&nbsp;                          mon_nam(mtmp));
&nbsp;                    seetrap(trap);
&nbsp;                }
&nbsp;                if (rn2(3))
&nbsp;                    break;
&nbsp;                if (in_sight) {
&nbsp;                    newsym(mtmp-&gt;mx, mtmp-&gt;my);
&nbsp;                    pline_The("air currents set %s off!",
&nbsp;                              already_seen ? "a land mine" : "it");
&nbsp;                }
&nbsp;            } else if (in_sight) {
&nbsp;                newsym(mtmp-&gt;mx, mtmp-&gt;my);
&nbsp;                pline("%s%s triggers %s land mine!",
&nbsp;                      !Deaf ? "KAABLAMM!!!  " : "", Monnam(mtmp),
&nbsp;                      a_your[trap-&gt;madeby_u]);
&nbsp;            }
&nbsp;            if (!in_sight &amp;&amp; !Deaf)
&nbsp;                pline("Kaablamm!  You hear an explosion in the distance!");
&nbsp;            blow_up_landmine(trap);
&nbsp;            /* explosion might have destroyed a drawbridge; don't
&nbsp;               dish out more damage if monster is already dead */
&nbsp;            if (mtmp-&gt;mhp &lt;= 0
&nbsp;                || thitm(0, mtmp, (struct obj *) 0, rnd(16), FALSE)) {
&nbsp;                trapkilled = TRUE;
&nbsp;            } else {
&nbsp;                /* monsters recursively fall into new pit */
&nbsp;                if (mintrap(mtmp) == 2)
&nbsp;                    trapkilled = TRUE;
&nbsp;            }
&nbsp;            /* a boulder may fill the new pit, crushing monster */
&nbsp;            fill_pit(trap-&gt;tx, trap-&gt;ty);
&nbsp;            if (mtmp-&gt;mhp &lt;= 0)
&nbsp;                trapkilled = TRUE;
&nbsp;            if (unconscious()) {
&nbsp;                multi = -1;
&nbsp;                nomovemsg = "The explosion awakens you!";
&nbsp;            }
&nbsp;            break;
&nbsp;        case POLY_TRAP:
&nbsp;            if (resists_magm(mtmp)) {
&nbsp;                shieldeff(mtmp-&gt;mx, mtmp-&gt;my);
&nbsp;            } else if (!resist(mtmp, WAND_CLASS, 0, NOTELL)) {
&nbsp;                if (newcham(mtmp, (struct permonst *) 0, FALSE, FALSE))
&nbsp;                    /* we're done with mptr but keep it up to date */
&nbsp;                    mptr = mtmp-&gt;data;
&nbsp;                if (in_sight)
&nbsp;                    seetrap(trap);
&nbsp;            }
&nbsp;            break;
&nbsp;        case ROLLING_BOULDER_TRAP:
&nbsp;            if (!is_flyer(mptr)) {
&nbsp;                int style = ROLL | (in_sight ? 0 : LAUNCH_UNSEEN);
&nbsp;
&nbsp;                newsym(mtmp-&gt;mx, mtmp-&gt;my);
&nbsp;                if (in_sight)
&nbsp;                    pline("Click! %s triggers %s.", Monnam(mtmp),
&nbsp;                          trap-&gt;tseen ? "a rolling boulder trap" : something);
&nbsp;                if (launch_obj(BOULDER, trap-&gt;launch.x, trap-&gt;launch.y,
&nbsp;                               trap-&gt;launch2.x, trap-&gt;launch2.y, style)) {
&nbsp;                    if (in_sight)
&nbsp;                        trap-&gt;tseen = TRUE;
&nbsp;                    if (mtmp-&gt;mhp &lt;= 0)
&nbsp;                        trapkilled = TRUE;
&nbsp;                } else {
&nbsp;                    deltrap(trap);
&nbsp;                    newsym(mtmp-&gt;mx, mtmp-&gt;my);
&nbsp;                }
&nbsp;            }
&nbsp;            break;
&nbsp;        case VIBRATING_SQUARE:
&nbsp;            if (see_it &amp;&amp; !Blind) {
&nbsp;                if (in_sight)
&nbsp;                    pline("You see a strange vibration beneath %s %s.",
&nbsp;                          s_suffix(mon_nam(mtmp)),
&nbsp;                          makeplural(mbodypart(mtmp, FOOT)));
&nbsp;                else
&nbsp;                    pline("You see the ground vibrate in the distance.");
&nbsp;                seetrap(trap);
&nbsp;            }
&nbsp;            break;
&nbsp;        default:
&nbsp;            impossible("Some monster encountered a strange trap of type %d.",
&nbsp;                       tt);
&nbsp;        }
&nbsp;    }
&nbsp;    if (trapkilled)
&nbsp;        return 2;
&nbsp;    return mtmp-&gt;mtrapped;
&nbsp;}
&nbsp;
instapetrify
&nbsp;/* Combine cockatrice checks into single functions to avoid repeating code. */
&nbsp;void
&nbsp;instapetrify(str)
&nbsp;const char *str;
&nbsp;{
&nbsp;    if (Stone_resistance)
&nbsp;        return;
&nbsp;    if (poly_when_stoned(youmonst.data) &amp;&amp; polymon(PM_STONE_GOLEM))
&nbsp;        return;
&nbsp;    You("turn to stone...");
&nbsp;    killer.format = KILLED_BY;
&nbsp;    if (str != killer.name)
&nbsp;        Strcpy(killer.name, str ? str : "");
&nbsp;    done(STONING);
&nbsp;}
&nbsp;
minstapetrify
&nbsp;void
&nbsp;minstapetrify(mon, byplayer)
&nbsp;struct monst *mon;
&nbsp;boolean byplayer;
&nbsp;{
&nbsp;    if (resists_ston(mon))
&nbsp;        return;
&nbsp;    if (poly_when_stoned(mon-&gt;data)) {
&nbsp;        mon_to_stone(mon);
&nbsp;        return;
&nbsp;    }
&nbsp;    if (!vamp_stone(mon))
&nbsp;        return;
&nbsp;
&nbsp;    /* give a "<mon> is slowing down" message and also remove
&nbsp;       intrinsic speed (comparable to similar effect on the hero) */
&nbsp;    mon_adjust_speed(mon, -3, (struct obj *) 0);
&nbsp;
&nbsp;    if (cansee(mon-&gt;mx, mon-&gt;my))
&nbsp;        pline("%s turns to stone.", Monnam(mon));
&nbsp;    if (byplayer) {
&nbsp;        stoned = TRUE;
&nbsp;        xkilled(mon, XKILL_NOMSG);
&nbsp;    } else
&nbsp;        monstone(mon);
&nbsp;}
&nbsp;
selftouch
&nbsp;void
&nbsp;selftouch(arg)
&nbsp;const char *arg;
&nbsp;{
&nbsp;    char kbuf[BUFSZ];
&nbsp;
&nbsp;    if (uwep &amp;&amp; uwep-&gt;otyp == CORPSE &amp;&amp; touch_petrifies(&amp;mons[uwep-&gt;corpsenm])
&nbsp;        &amp;&amp; !Stone_resistance) {
&nbsp;        pline("%s touch the %s corpse.", arg, mons[uwep-&gt;corpsenm].mname);
&nbsp;        Sprintf(kbuf, "%s corpse", an(mons[uwep-&gt;corpsenm].mname));
&nbsp;        instapetrify(kbuf);
&nbsp;        /* life-saved; unwield the corpse if we can't handle it */
&nbsp;        if (!uarmg &amp;&amp; !Stone_resistance)
&nbsp;            uwepgone();
&nbsp;    }
&nbsp;    /* Or your secondary weapon, if wielded [hypothetical; we don't
&nbsp;       allow two-weapon combat when either weapon is a corpse] */
&nbsp;    if (u.twoweap &amp;&amp; uswapwep &amp;&amp; uswapwep-&gt;otyp == CORPSE
&nbsp;        &amp;&amp; touch_petrifies(&amp;mons[uswapwep-&gt;corpsenm]) &amp;&amp; !Stone_resistance) {
&nbsp;        pline("%s touch the %s corpse.", arg, mons[uswapwep-&gt;corpsenm].mname);
&nbsp;        Sprintf(kbuf, "%s corpse", an(mons[uswapwep-&gt;corpsenm].mname));
&nbsp;        instapetrify(kbuf);
&nbsp;        /* life-saved; unwield the corpse */
&nbsp;        if (!uarmg &amp;&amp; !Stone_resistance)
&nbsp;            uswapwepgone();
&nbsp;    }
&nbsp;}
&nbsp;
mselftouch
&nbsp;void
&nbsp;mselftouch(mon, arg, byplayer)
&nbsp;struct monst *mon;
&nbsp;const char *arg;
&nbsp;boolean byplayer;
&nbsp;{
&nbsp;    struct obj *mwep = MON_WEP(mon);
&nbsp;
&nbsp;    if (mwep &amp;&amp; mwep-&gt;otyp == CORPSE &amp;&amp; touch_petrifies(&amp;mons[mwep-&gt;corpsenm])
&nbsp;        &amp;&amp; !resists_ston(mon)) {
&nbsp;        if (cansee(mon-&gt;mx, mon-&gt;my)) {
&nbsp;            pline("%s%s touches %s.", arg ? arg : "",
&nbsp;                  arg ? mon_nam(mon) : Monnam(mon),
&nbsp;                  corpse_xname(mwep, (const char *) 0, CXN_PFX_THE));
&nbsp;        }
&nbsp;        minstapetrify(mon, byplayer);
&nbsp;        /* if life-saved, might not be able to continue wielding */
&nbsp;        if (mon-&gt;mhp &gt; 0 &amp;&amp; !which_armor(mon, W_ARMG) &amp;&amp; !resists_ston(mon))
&nbsp;            mwepgone(mon);
&nbsp;    }
&nbsp;}
&nbsp;
float_up
&nbsp;/* start levitating */
&nbsp;void
&nbsp;float_up()
&nbsp;{
&nbsp;    context.botl = TRUE;
&nbsp;    if (u.utrap) {
&nbsp;        if (u.utraptype == TT_PIT) {
&nbsp;            u.utrap = 0;
&nbsp;            You("float up, out of the pit!");
&nbsp;            vision_full_recalc = 1; /* vision limits change */
&nbsp;            fill_pit(u.ux, u.uy);
&nbsp;        } else if (u.utraptype == TT_INFLOOR) {
&nbsp;            Your("body pulls upward, but your %s are still stuck.",
&nbsp;                 makeplural(body_part(LEG)));
&nbsp;        } else {
&nbsp;            You("float up, only your %s is still stuck.", body_part(LEG));
&nbsp;        }
&nbsp;#if 0
&nbsp;    } else if (Is_waterlevel(&amp;u.uz)) {
&nbsp;        pline("It feels as though you've lost some weight.");
&nbsp;#endif
&nbsp;    } else if (u.uinwater) {
&nbsp;        spoteffects(TRUE);
&nbsp;    } else if (u.uswallow) {
&nbsp;        You(is_animal(u.ustuck-&gt;data) ? "float away from the %s."
&nbsp;                                      : "spiral up into %s.",
&nbsp;            is_animal(u.ustuck-&gt;data) ? surface(u.ux, u.uy)
&nbsp;                                      : mon_nam(u.ustuck));
&nbsp;    } else if (Hallucination) {
&nbsp;        pline("Up, up, and awaaaay!  You're walking on air!");
&nbsp;    } else if (Is_airlevel(&amp;u.uz)) {
&nbsp;        You("gain control over your movements.");
&nbsp;    } else {
&nbsp;        You("start to float in the air!");
&nbsp;    }
&nbsp;    if (u.usteed &amp;&amp; !is_floater(u.usteed-&gt;data)
&nbsp;        &amp;&amp; !is_flyer(u.usteed-&gt;data)) {
&nbsp;        if (Lev_at_will) {
&nbsp;            pline("%s magically floats up!", Monnam(u.usteed));
&nbsp;        } else {
&nbsp;            You("cannot stay on %s.", mon_nam(u.usteed));
&nbsp;            dismount_steed(DISMOUNT_GENERIC);
&nbsp;        }
&nbsp;    }
&nbsp;    if (Flying)
&nbsp;        You("are no longer able to control your flight.");
&nbsp;    BFlying |= I_SPECIAL;
&nbsp;    /* levitation gives maximum carrying capacity, so encumbrance
&nbsp;       state might be reduced */
&nbsp;    (void) encumber_msg();
&nbsp;    return;
&nbsp;}
&nbsp;
fill_pit
&nbsp;void
&nbsp;fill_pit(x, y)
&nbsp;int x, y;
&nbsp;{
&nbsp;    struct obj *otmp;
&nbsp;    struct trap *t;
&nbsp;
&nbsp;    if ((t = t_at(x, y)) &amp;&amp; ((t-&gt;ttyp == PIT) || (t-&gt;ttyp == SPIKED_PIT))
&nbsp;        &amp;&amp; (otmp = sobj_at(BOULDER, x, y))) {
&nbsp;        obj_extract_self(otmp);
&nbsp;        (void) flooreffects(otmp, x, y, "settle");
&nbsp;    }
&nbsp;}
&nbsp;
float_down
&nbsp;/* stop levitating */
&nbsp;int
&nbsp;float_down(hmask, emask)
&nbsp;long hmask, emask; /* might cancel timeout */
&nbsp;{
&nbsp;    register struct trap *trap = (struct trap *) 0;
&nbsp;    d_level current_dungeon_level;
&nbsp;    boolean no_msg = FALSE;
&nbsp;
&nbsp;    HLevitation &amp;= ~hmask;
&nbsp;    ELevitation &amp;= ~emask;
&nbsp;    if (Levitation)
&nbsp;        return 0; /* maybe another ring/potion/boots */
&nbsp;    if (BLevitation) {
&nbsp;        /* Levitation is blocked, so hero is not actually floating
&nbsp;           hence shouldn't have float_down effects and feedback */
&nbsp;        float_vs_flight(); /* before nomul() rather than after */
&nbsp;        return 0;
&nbsp;    }
&nbsp;    context.botl = TRUE;
&nbsp;    nomul(0); /* stop running or resting */
&nbsp;    if (BFlying) {
&nbsp;        /* controlled flight no longer overridden by levitation */
&nbsp;        BFlying &amp;= ~I_SPECIAL;
&nbsp;        if (Flying) {
&nbsp;            You("have stopped levitating and are now flying.");
&nbsp;            (void) encumber_msg(); /* carrying capacity might have changed */
&nbsp;            return 1;
&nbsp;        }
&nbsp;    }
&nbsp;    if (u.uswallow) {
&nbsp;        You("float down, but you are still %s.",
&nbsp;            is_animal(u.ustuck-&gt;data) ? "swallowed" : "engulfed");
&nbsp;        (void) encumber_msg();
&nbsp;        return 1;
&nbsp;    }
&nbsp;
&nbsp;    if (Punished &amp;&amp; !carried(uball)
&nbsp;        &amp;&amp; (is_pool(uball-&gt;ox, uball-&gt;oy)
&nbsp;            || ((trap = t_at(uball-&gt;ox, uball-&gt;oy))
&nbsp;                &amp;&amp; ((trap-&gt;ttyp == PIT) || (trap-&gt;ttyp == SPIKED_PIT)
&nbsp;                    || (trap-&gt;ttyp == TRAPDOOR) || (trap-&gt;ttyp == HOLE))))) {
&nbsp;        u.ux0 = u.ux;
&nbsp;        u.uy0 = u.uy;
&nbsp;        u.ux = uball-&gt;ox;
&nbsp;        u.uy = uball-&gt;oy;
&nbsp;        movobj(uchain, uball-&gt;ox, uball-&gt;oy);
&nbsp;        newsym(u.ux0, u.uy0);
&nbsp;        vision_full_recalc = 1; /* in case the hero moved. */
&nbsp;    }
&nbsp;    /* check for falling into pool - added by GAN 10/20/86 */
&nbsp;    if (!Flying) {
&nbsp;        if (!u.uswallow &amp;&amp; u.ustuck) {
&nbsp;            if (sticks(youmonst.data))
&nbsp;                You("aren't able to maintain your hold on %s.",
&nbsp;                    mon_nam(u.ustuck));
&nbsp;            else
&nbsp;                pline("Startled, %s can no longer hold you!",
&nbsp;                      mon_nam(u.ustuck));
&nbsp;            u.ustuck = 0;
&nbsp;        }
&nbsp;        /* kludge alert:
&nbsp;         * drown() and lava_effects() print various messages almost
&nbsp;         * every time they're called which conflict with the "fall
&nbsp;         * into" message below.  Thus, we want to avoid printing
&nbsp;         * confusing, duplicate or out-of-order messages.
&nbsp;         * Use knowledge of the two routines as a hack -- this
&nbsp;         * should really be handled differently -dlc
&nbsp;         */
&nbsp;        if (is_pool(u.ux, u.uy) &amp;&amp; !Wwalking &amp;&amp; !Swimming &amp;&amp; !u.uinwater)
&nbsp;            no_msg = drown();
&nbsp;
&nbsp;        if (is_lava(u.ux, u.uy)) {
&nbsp;            (void) lava_effects();
&nbsp;            no_msg = TRUE;
&nbsp;        }
&nbsp;    }
&nbsp;    if (!trap) {
&nbsp;        trap = t_at(u.ux, u.uy);
&nbsp;        if (Is_airlevel(&amp;u.uz)) {
&nbsp;            You("begin to tumble in place.");
&nbsp;        } else if (Is_waterlevel(&amp;u.uz) &amp;&amp; !no_msg) {
&nbsp;            You_feel("heavier.");
&nbsp;        /* u.uinwater msgs already in spoteffects()/drown() */
&nbsp;        } else if (!u.uinwater &amp;&amp; !no_msg) {
&nbsp;            if (!(emask &amp; W_SADDLE)) {
&nbsp;                if (Sokoban &amp;&amp; trap) {
&nbsp;                    /* Justification elsewhere for Sokoban traps is based
&nbsp;                     * on air currents.  This is consistent with that.
&nbsp;                     * The unexpected additional force of the air currents
&nbsp;                     * once levitation ceases knocks you off your feet.
&nbsp;                     */
&nbsp;                    if (Hallucination)
&nbsp;                        pline("Bummer!  You've crashed.");
&nbsp;                    else
&nbsp;                        You("fall over.");
&nbsp;                    losehp(rnd(2), "dangerous winds", KILLED_BY);
&nbsp;                    if (u.usteed)
&nbsp;                        dismount_steed(DISMOUNT_FELL);
&nbsp;                    selftouch("As you fall, you");
&nbsp;                } else if (u.usteed &amp;&amp; (is_floater(u.usteed-&gt;data)
&nbsp;                                        || is_flyer(u.usteed-&gt;data))) {
&nbsp;                    You("settle more firmly in the saddle.");
&nbsp;                } else if (Hallucination) {
&nbsp;                    pline("Bummer!  You've %s.",
&nbsp;                          is_pool(u.ux, u.uy)
&nbsp;                             ? "splashed down"
&nbsp;                             : "hit the ground");
&nbsp;                } else {
&nbsp;                    You("float gently to the %s.", surface(u.ux, u.uy));
&nbsp;                }
&nbsp;            }
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    /* levitation gives maximum carrying capacity, so having it end
&nbsp;       potentially triggers greater encumbrance; do this after
&nbsp;       'come down' messages, before trap activation or autopickup */
&nbsp;    (void) encumber_msg();
&nbsp;
&nbsp;    /* can't rely on u.uz0 for detecting trap door-induced level change;
&nbsp;       it gets changed to reflect the new level before we can check it */
&nbsp;    assign_level(&amp;current_dungeon_level, &amp;u.uz);
&nbsp;    if (trap) {
&nbsp;        switch (trap-&gt;ttyp) {
&nbsp;        case STATUE_TRAP:
&nbsp;            break;
&nbsp;        case HOLE:
&nbsp;        case TRAPDOOR:
&nbsp;            if (!Can_fall_thru(&amp;u.uz) || u.ustuck)
&nbsp;                break;
&nbsp;            /*FALLTHRU*/
&nbsp;        default:
&nbsp;            if (!u.utrap) /* not already in the trap */
&nbsp;                dotrap(trap, 0);
&nbsp;        }
&nbsp;    }
&nbsp;    if (!Is_airlevel(&amp;u.uz) &amp;&amp; !Is_waterlevel(&amp;u.uz) &amp;&amp; !u.uswallow
&nbsp;        /* falling through trap door calls goto_level,
&nbsp;           and goto_level does its own pickup() call */
&nbsp;        &amp;&amp; on_level(&amp;u.uz, &amp;current_dungeon_level))
&nbsp;        (void) pickup(1);
&nbsp;    return 1;
&nbsp;}
&nbsp;
climb_pit
&nbsp;/* shared code for climbing out of a pit */
&nbsp;void
&nbsp;climb_pit()
&nbsp;{
&nbsp;    if (!u.utrap || u.utraptype != TT_PIT)
&nbsp;        return;
&nbsp;
&nbsp;    if (Passes_walls) {
&nbsp;        /* marked as trapped so they can pick things up */
&nbsp;        You("ascend from the pit.");
&nbsp;        u.utrap = 0;
&nbsp;        fill_pit(u.ux, u.uy);
&nbsp;        vision_full_recalc = 1; /* vision limits change */
&nbsp;    } else if (!rn2(2) &amp;&amp; sobj_at(BOULDER, u.ux, u.uy)) {
&nbsp;        Your("%s gets stuck in a crevice.", body_part(LEG));
&nbsp;        display_nhwindow(WIN_MESSAGE, FALSE);
&nbsp;        clear_nhwindow(WIN_MESSAGE);
&nbsp;        You("free your %s.", body_part(LEG));
&nbsp;    } else if ((Flying || is_clinger(youmonst.data)) &amp;&amp; !Sokoban) {
&nbsp;        /* eg fell in pit, then poly'd to a flying monster;
&nbsp;           or used '&gt;' to deliberately enter it */
&nbsp;        You("%s from the pit.", Flying ? "fly" : "climb");
&nbsp;        u.utrap = 0;
&nbsp;        fill_pit(u.ux, u.uy);
&nbsp;        vision_full_recalc = 1; /* vision limits change */
&nbsp;    } else if (!(--u.utrap)) {
&nbsp;        You("%s to the edge of the pit.",
&nbsp;            (Sokoban &amp;&amp; Levitation)
&nbsp;                ? "struggle against the air currents and float"
&nbsp;                : u.usteed ? "ride" : "crawl");
&nbsp;        fill_pit(u.ux, u.uy);
&nbsp;        vision_full_recalc = 1; /* vision limits change */
&nbsp;    } else if (u.dz || flags.verbose) {
&nbsp;        if (u.usteed)
&nbsp;            Norep("%s is still in a pit.", upstart(y_monnam(u.usteed)));
&nbsp;        else
&nbsp;            Norep((Hallucination &amp;&amp; !rn2(5))
&nbsp;                      ? "You've fallen, and you can't get up."
&nbsp;                      : "You are still in a pit.");
&nbsp;    }
&nbsp;}
&nbsp;
dofiretrap
&nbsp;STATIC_OVL void
&nbsp;dofiretrap(box)
&nbsp;struct obj *box; /* null for floor trap */
&nbsp;{
&nbsp;    boolean see_it = !Blind;
&nbsp;    int num, alt;
&nbsp;
&nbsp;    /* Bug: for box case, the equivalent of burn_floor_objects() ought
&nbsp;     * to be done upon its contents.
&nbsp;     */
&nbsp;
&nbsp;    if ((box &amp;&amp; !carried(box)) ? is_pool(box-&gt;ox, box-&gt;oy) : Underwater) {
&nbsp;        pline("A cascade of steamy bubbles erupts from %s!",
&nbsp;              the(box ? xname(box) : surface(u.ux, u.uy)));
&nbsp;        if (Fire_resistance)
&nbsp;            You("are uninjured.");
&nbsp;        else
&nbsp;            losehp(rnd(3), "boiling water", KILLED_BY);
&nbsp;        return;
&nbsp;    }
&nbsp;    pline("A %s %s from %s!", tower_of_flame, box ? "bursts" : "erupts",
&nbsp;          the(box ? xname(box) : surface(u.ux, u.uy)));
&nbsp;    if (Fire_resistance) {
&nbsp;        shieldeff(u.ux, u.uy);
&nbsp;        num = rn2(2);
&nbsp;    } else if (Upolyd) {
&nbsp;        num = d(2, 4);
&nbsp;        switch (u.umonnum) {
&nbsp;        case PM_PAPER_GOLEM:
&nbsp;            alt = u.mhmax;
&nbsp;            break;
&nbsp;        case PM_STRAW_GOLEM:
&nbsp;            alt = u.mhmax / 2;
&nbsp;            break;
&nbsp;        case PM_WOOD_GOLEM:
&nbsp;            alt = u.mhmax / 4;
&nbsp;            break;
&nbsp;        case PM_LEATHER_GOLEM:
&nbsp;            alt = u.mhmax / 8;
&nbsp;            break;
&nbsp;        default:
&nbsp;            alt = 0;
&nbsp;            break;
&nbsp;        }
&nbsp;        if (alt &gt; num)
&nbsp;            num = alt;
&nbsp;        if (u.mhmax &gt; mons[u.umonnum].mlevel)
&nbsp;            u.mhmax -= rn2(min(u.mhmax, num + 1)), context.botl = 1;
&nbsp;    } else {
&nbsp;        num = d(2, 4);
&nbsp;        if (u.uhpmax &gt; u.ulevel)
&nbsp;            u.uhpmax -= rn2(min(u.uhpmax, num + 1)), context.botl = 1;
&nbsp;    }
&nbsp;    if (!num)
&nbsp;        You("are uninjured.");
&nbsp;    else
&nbsp;        losehp(num, tower_of_flame, KILLED_BY_AN); /* fire damage */
&nbsp;    burn_away_slime();
&nbsp;
&nbsp;    if (burnarmor(&amp;youmonst) || rn2(3)) {
&nbsp;        destroy_item(SCROLL_CLASS, AD_FIRE);
&nbsp;        destroy_item(SPBOOK_CLASS, AD_FIRE);
&nbsp;        destroy_item(POTION_CLASS, AD_FIRE);
&nbsp;    }
&nbsp;    if (!box &amp;&amp; burn_floor_objects(u.ux, u.uy, see_it, TRUE) &amp;&amp; !see_it)
&nbsp;        You("smell paper burning.");
&nbsp;    if (is_ice(u.ux, u.uy))
&nbsp;        melt_ice(u.ux, u.uy, (char *) 0);
&nbsp;}
&nbsp;
domagictrap
&nbsp;STATIC_OVL void
&nbsp;domagictrap()
&nbsp;{
&nbsp;    register int fate = rnd(20);
&nbsp;
&nbsp;    /* What happened to the poor sucker? */
&nbsp;
&nbsp;    if (fate &lt; 10) {
&nbsp;        /* Most of the time, it creates some monsters. */
&nbsp;        register int cnt = rnd(4);
&nbsp;
&nbsp;        /* blindness effects */
&nbsp;        if (!resists_blnd(&amp;youmonst)) {
&nbsp;            You("are momentarily blinded by a flash of light!");
&nbsp;            make_blinded((long) rn1(5, 10), FALSE);
&nbsp;            if (!Blind)
&nbsp;                Your1(vision_clears);
&nbsp;        } else if (!Blind) {
&nbsp;            You_see("a flash of light!");
&nbsp;        }
&nbsp;
&nbsp;        /* deafness effects */
&nbsp;        if (!Deaf) {
&nbsp;            You_hear("a deafening roar!");
&nbsp;            incr_itimeout(&amp;HDeaf, rn1(20, 30));
&nbsp;            context.botl = TRUE;
&nbsp;        } else {
&nbsp;            /* magic vibrations still hit you */
&nbsp;            You_feel("rankled.");
&nbsp;            incr_itimeout(&amp;HDeaf, rn1(5, 15));
&nbsp;            context.botl = TRUE;
&nbsp;        }
&nbsp;        while (cnt--)
&nbsp;            (void) makemon((struct permonst *) 0, u.ux, u.uy, NO_MM_FLAGS);
&nbsp;    } else
&nbsp;        switch (fate) {
&nbsp;        case 10:
&nbsp;        case 11:
&nbsp;            /* sometimes nothing happens */
&nbsp;            break;
&nbsp;        case 12: /* a flash of fire */
&nbsp;            dofiretrap((struct obj *) 0);
&nbsp;            break;
&nbsp;
&nbsp;        /* odd feelings */
&nbsp;        case 13:
&nbsp;            pline("A shiver runs up and down your %s!", body_part(SPINE));
&nbsp;            break;
&nbsp;        case 14:
&nbsp;            You_hear(Hallucination ? "the moon howling at you."
&nbsp;                                   : "distant howling.");
&nbsp;            break;
&nbsp;        case 15:
&nbsp;            if (on_level(&amp;u.uz, &amp;qstart_level))
&nbsp;                You_feel(
&nbsp;                    "%slike the prodigal son.",
&nbsp;                    (flags.female || (Upolyd &amp;&amp; is_neuter(youmonst.data)))
&nbsp;                        ? "oddly "
&nbsp;                        : "");
&nbsp;            else
&nbsp;                You("suddenly yearn for %s.",
&nbsp;                    Hallucination
&nbsp;                        ? "Cleveland"
&nbsp;                        : (In_quest(&amp;u.uz) || at_dgn_entrance("The Quest"))
&nbsp;                              ? "your nearby homeland"
&nbsp;                              : "your distant homeland");
&nbsp;            break;
&nbsp;        case 16:
&nbsp;            Your("pack shakes violently!");
&nbsp;            break;
&nbsp;        case 17:
&nbsp;            You(Hallucination ? "smell hamburgers." : "smell charred flesh.");
&nbsp;            break;
&nbsp;        case 18:
&nbsp;            You_feel("tired.");
&nbsp;            break;
&nbsp;
&nbsp;        /* very occasionally something nice happens. */
&nbsp;        case 19: { /* tame nearby monsters */
&nbsp;            int i, j;
&nbsp;            struct monst *mtmp;
&nbsp;
&nbsp;            (void) adjattrib(A_CHA, 1, FALSE);
&nbsp;            for (i = -1; i &lt;= 1; i++)
&nbsp;                for (j = -1; j &lt;= 1; j++) {
&nbsp;                    if (!isok(u.ux + i, u.uy + j))
&nbsp;                        continue;
&nbsp;                    mtmp = m_at(u.ux + i, u.uy + j);
&nbsp;                    if (mtmp)
&nbsp;                        (void) tamedog(mtmp, (struct obj *) 0);
&nbsp;                }
&nbsp;            break;
&nbsp;        }
&nbsp;        case 20: { /* uncurse stuff */
&nbsp;            struct obj pseudo;
&nbsp;            long save_conf = HConfusion;
&nbsp;
&nbsp;            pseudo = zeroobj; /* neither cursed nor blessed,
&nbsp;                                 and zero out oextra */
&nbsp;            pseudo.otyp = SCR_REMOVE_CURSE;
&nbsp;            HConfusion = 0L;
&nbsp;            (void) seffects(&amp;pseudo);
&nbsp;            HConfusion = save_conf;
&nbsp;            break;
&nbsp;        }
&nbsp;        default:
&nbsp;            break;
&nbsp;        }
&nbsp;}
&nbsp;
fire_damage
&nbsp;/* Set an item on fire.
&nbsp; *   "force" means not to roll a luck-based protection check for the
&nbsp; *     item.
&nbsp; *   "x" and "y" are the coordinates to dump the contents of a
&nbsp; *     container, if it burns up.
&nbsp; *
&nbsp; * Return whether the object was destroyed.
&nbsp; */
&nbsp;boolean
&nbsp;fire_damage(obj, force, x, y)
&nbsp;struct obj *obj;
&nbsp;boolean force;
&nbsp;xchar x, y;
&nbsp;{
&nbsp;    int chance;
&nbsp;    struct obj *otmp, *ncobj;
&nbsp;    int in_sight = !Blind &amp;&amp; couldsee(x, y); /* Don't care if it's lit */
&nbsp;    int dindx;
&nbsp;
&nbsp;    /* object might light in a controlled manner */
&nbsp;    if (catch_lit(obj))
&nbsp;        return FALSE;
&nbsp;
&nbsp;    if (Is_container(obj)) {
&nbsp;        switch (obj-&gt;otyp) {
&nbsp;        case ICE_BOX:
&nbsp;            return FALSE; /* Immune */
&nbsp;        case CHEST:
&nbsp;            chance = 40;
&nbsp;            break;
&nbsp;        case LARGE_BOX:
&nbsp;            chance = 30;
&nbsp;            break;
&nbsp;        default:
&nbsp;            chance = 20;
&nbsp;            break;
&nbsp;        }
&nbsp;        if ((!force &amp;&amp; (Luck + 5) &gt; rn2(chance))
&nbsp;            || (is_flammable(obj) &amp;&amp; obj-&gt;oerodeproof))
&nbsp;            return FALSE;
&nbsp;        /* Container is burnt up - dump contents out */
&nbsp;        if (in_sight)
&nbsp;            pline("%s catches fire and burns.", Yname2(obj));
&nbsp;        if (Has_contents(obj)) {
&nbsp;            if (in_sight)
&nbsp;                pline("Its contents fall out.");
&nbsp;            for (otmp = obj-&gt;cobj; otmp; otmp = ncobj) {
&nbsp;                ncobj = otmp-&gt;nobj;
&nbsp;                obj_extract_self(otmp);
&nbsp;                if (!flooreffects(otmp, x, y, ""))
&nbsp;                    place_object(otmp, x, y);
&nbsp;            }
&nbsp;        }
&nbsp;        setnotworn(obj);
&nbsp;        delobj(obj);
&nbsp;        return TRUE;
&nbsp;    } else if (!force &amp;&amp; (Luck + 5) &gt; rn2(20)) {
&nbsp;        /*  chance per item of sustaining damage:
&nbsp;          *     max luck (Luck==13):    10%
&nbsp;          *     avg luck (Luck==0):     75%
&nbsp;          *     awful luck (Luck&lt;-4):  100%
&nbsp;          */
&nbsp;        return FALSE;
&nbsp;    } else if (obj-&gt;oclass == SCROLL_CLASS || obj-&gt;oclass == SPBOOK_CLASS) {
&nbsp;        if (obj-&gt;otyp == SCR_FIRE || obj-&gt;otyp == SPE_FIREBALL)
&nbsp;            return FALSE;
&nbsp;        if (obj-&gt;otyp == SPE_BOOK_OF_THE_DEAD) {
&nbsp;            if (in_sight)
&nbsp;                pline("Smoke rises from %s.", the(xname(obj)));
&nbsp;            return FALSE;
&nbsp;        }
&nbsp;        dindx = (obj-&gt;oclass == SCROLL_CLASS) ? 3 : 4;
&nbsp;        if (in_sight)
&nbsp;            pline("%s %s.", Yname2(obj),
&nbsp;                  destroy_strings[dindx][(obj-&gt;quan &gt; 1L)]);
&nbsp;        setnotworn(obj);
&nbsp;        delobj(obj);
&nbsp;        return TRUE;
&nbsp;    } else if (obj-&gt;oclass == POTION_CLASS) {
&nbsp;        dindx = (obj-&gt;otyp != POT_OIL) ? 1 : 2;
&nbsp;        if (in_sight)
&nbsp;            pline("%s %s.", Yname2(obj),
&nbsp;                  destroy_strings[dindx][(obj-&gt;quan &gt; 1L)]);
&nbsp;        setnotworn(obj);
&nbsp;        delobj(obj);
&nbsp;        return TRUE;
&nbsp;    } else if (erode_obj(obj, (char *) 0, ERODE_BURN, EF_DESTROY)
&nbsp;               == ER_DESTROYED) {
&nbsp;        return TRUE;
&nbsp;    }
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
fire_damage_chain
&nbsp;/*
&nbsp; * Apply fire_damage() to an entire chain.
&nbsp; *
&nbsp; * Return number of objects destroyed. --ALI
&nbsp; */
&nbsp;int
&nbsp;fire_damage_chain(chain, force, here, x, y)
&nbsp;struct obj *chain;
&nbsp;boolean force, here;
&nbsp;xchar x, y;
&nbsp;{
&nbsp;    struct obj *obj, *nobj;
&nbsp;    int num = 0;
&nbsp;
&nbsp;    for (obj = chain; obj; obj = nobj) {
&nbsp;        nobj = here ? obj-&gt;nexthere : obj-&gt;nobj;
&nbsp;        if (fire_damage(obj, force, x, y))
&nbsp;            ++num;
&nbsp;    }
&nbsp;
&nbsp;    if (num &amp;&amp; (Blind &amp;&amp; !couldsee(x, y)))
&nbsp;        You("smell smoke.");
&nbsp;    return num;
&nbsp;}
&nbsp;
lava_damage
&nbsp;/* obj has been thrown or dropped into lava; damage is worse than mere fire */
&nbsp;boolean
&nbsp;lava_damage(obj, x, y)
&nbsp;struct obj *obj;
&nbsp;xchar x, y;
&nbsp;{
&nbsp;    int otyp = obj-&gt;otyp, ocls = obj-&gt;oclass;
&nbsp;
&nbsp;    /* the Amulet, invocation items, and Rider corpses are never destroyed
&nbsp;       (let Book of the Dead fall through to fire_damage() to get feedback) */
&nbsp;    if (obj_resists(obj, 0, 0) &amp;&amp; otyp != SPE_BOOK_OF_THE_DEAD)
&nbsp;        return FALSE;
&nbsp;    /* destroy liquid (venom), wax, veggy, flesh, paper (except for scrolls
&nbsp;       and books--let fire damage deal with them), cloth, leather, wood, bone
&nbsp;       unless it's inherently or explicitly fireproof or contains something;
&nbsp;       note: potions are glass so fall through to fire_damage() and boil */
&nbsp;    if (objects[otyp].oc_material &lt; DRAGON_HIDE
&nbsp;        &amp;&amp; ocls != SCROLL_CLASS &amp;&amp; ocls != SPBOOK_CLASS
&nbsp;        &amp;&amp; objects[otyp].oc_oprop != FIRE_RES
&nbsp;        &amp;&amp; otyp != WAN_FIRE &amp;&amp; otyp != FIRE_HORN
&nbsp;        /* assumes oerodeproof isn't overloaded for some other purpose on
&nbsp;           non-eroding items */
&nbsp;        &amp;&amp; !obj-&gt;oerodeproof
&nbsp;        /* fire_damage() knows how to deal with containers and contents */
&nbsp;        &amp;&amp; !Has_contents(obj)) {
&nbsp;        if (cansee(x, y)) {
&nbsp;            /* this feedback is pretty clunky and can become very verbose
&nbsp;               when former contents of a burned container get here via
&nbsp;               flooreffects() */
&nbsp;            if (obj == thrownobj || obj == kickedobj)
&nbsp;                pline("%s %s up!", is_plural(obj) ? "They" : "It",
&nbsp;                      otense(obj, "burn"));
&nbsp;            else
&nbsp;                You_see("%s hit lava and burn up!", doname(obj));
&nbsp;        }
&nbsp;        if (carried(obj)) { /* shouldn't happen */
&nbsp;            remove_worn_item(obj, TRUE);
&nbsp;            useupall(obj);
&nbsp;        } else
&nbsp;            delobj(obj);
&nbsp;        return TRUE;
&nbsp;    }
&nbsp;    return fire_damage(obj, TRUE, x, y);
&nbsp;}
&nbsp;
acid_damage
&nbsp;void
&nbsp;acid_damage(obj)
&nbsp;struct obj *obj;
&nbsp;{
&nbsp;    /* Scrolls but not spellbooks can be erased by acid. */
&nbsp;    struct monst *victim;
&nbsp;    boolean vismon;
&nbsp;
&nbsp;    if (!obj)
&nbsp;        return;
&nbsp;
&nbsp;    victim = carried(obj) ? &amp;youmonst : mcarried(obj) ? obj-&gt;ocarry : NULL;
&nbsp;    vismon = victim &amp;&amp; (victim != &amp;youmonst) &amp;&amp; canseemon(victim);
&nbsp;
&nbsp;    if (obj-&gt;greased) {
&nbsp;        grease_protect(obj, (char *) 0, victim);
&nbsp;    } else if (obj-&gt;oclass == SCROLL_CLASS &amp;&amp; obj-&gt;otyp != SCR_BLANK_PAPER) {
&nbsp;        if (obj-&gt;otyp != SCR_BLANK_PAPER
&nbsp;#ifdef MAIL
&nbsp;            &amp;&amp; obj-&gt;otyp != SCR_MAIL
&nbsp;#endif
&nbsp;            ) {
&nbsp;            if (!Blind) {
&nbsp;                if (victim == &amp;youmonst)
&nbsp;                    pline("Your %s.", aobjnam(obj, "fade"));
&nbsp;                else if (vismon)
&nbsp;                    pline("%s %s.", s_suffix(Monnam(victim)),
&nbsp;                          aobjnam(obj, "fade"));
&nbsp;            }
&nbsp;        }
&nbsp;        obj-&gt;otyp = SCR_BLANK_PAPER;
&nbsp;        obj-&gt;spe = 0;
&nbsp;        obj-&gt;dknown = 0;
&nbsp;    } else
&nbsp;        erode_obj(obj, (char *) 0, ERODE_CORRODE, EF_GREASE | EF_VERBOSE);
&nbsp;}
&nbsp;
&nbsp;/* context for water_damage(), managed by water_damage_chain();
&nbsp;   when more than one stack of potions of acid explode while processing
&nbsp;   a chain of objects, use alternate phrasing after the first message */
&nbsp;static struct h2o_ctx {
&nbsp;    int dkn_boom, unk_boom; /* track dknown, !dknown separately */
&nbsp;    boolean ctx_valid;
&nbsp;} acid_ctx = { 0, 0, FALSE };
&nbsp;
water_damage
&nbsp;/* Get an object wet and damage it appropriately.
&nbsp; *   "ostr", if present, is used instead of the object name in some
&nbsp; *     messages.
&nbsp; *   "force" means not to roll luck to protect some objects.
&nbsp; * Returns an erosion return value (ER_*)
&nbsp; */
&nbsp;int
&nbsp;water_damage(obj, ostr, force)
&nbsp;struct obj *obj;
&nbsp;const char *ostr;
&nbsp;boolean force;
&nbsp;{
&nbsp;    if (!obj)
&nbsp;        return ER_NOTHING;
&nbsp;
&nbsp;    if (snuff_lit(obj))
&nbsp;        return ER_DAMAGED;
&nbsp;
&nbsp;    if (!ostr)
&nbsp;        ostr = cxname(obj);
&nbsp;
&nbsp;    if (obj-&gt;otyp == CAN_OF_GREASE &amp;&amp; obj-&gt;spe &gt; 0) {
&nbsp;        return ER_NOTHING;
&nbsp;    } else if (obj-&gt;otyp == TOWEL &amp;&amp; obj-&gt;spe &lt; 7) {
&nbsp;        wet_a_towel(obj, rnd(7), TRUE);
&nbsp;        return ER_NOTHING;
&nbsp;    } else if (obj-&gt;greased) {
&nbsp;        if (!rn2(2))
&nbsp;            obj-&gt;greased = 0;
&nbsp;        if (carried(obj))
&nbsp;            update_inventory();
&nbsp;        return ER_GREASED;
&nbsp;    } else if (Is_container(obj) &amp;&amp; !Is_box(obj)
&nbsp;               &amp;&amp; (obj-&gt;otyp != OILSKIN_SACK || (obj-&gt;cursed &amp;&amp; !rn2(3)))) {
&nbsp;        if (carried(obj))
&nbsp;            pline("Water gets into your %s!", ostr);
&nbsp;
&nbsp;        water_damage_chain(obj-&gt;cobj, FALSE);
&nbsp;        return ER_DAMAGED; /* contents were damaged */
&nbsp;    } else if (obj-&gt;otyp == OILSKIN_SACK) {
&nbsp;        if (carried(obj))
&nbsp;            pline("Some water slides right off your %s.", ostr);
&nbsp;        makeknown(OILSKIN_SACK);
&nbsp;        /* not actually damaged, but because we /didn't/ get the "water
&nbsp;           gets into!" message, the player now has more information and
&nbsp;           thus we need to waste any potion they may have used (also,
&nbsp;           flavourwise the water is now on the floor) */
&nbsp;        return ER_DAMAGED;
&nbsp;    } else if (!force &amp;&amp; (Luck + 5) &gt; rn2(20)) {
&nbsp;        /*  chance per item of sustaining damage:
&nbsp;            *   max luck:               10%
&nbsp;            *   avg luck (Luck==0):     75%
&nbsp;            *   awful luck (Luck&lt;-4):  100%
&nbsp;            */
&nbsp;        return ER_NOTHING;
&nbsp;    } else if (obj-&gt;oclass == SCROLL_CLASS) {
&nbsp;        if (obj-&gt;otyp == SCR_BLANK_PAPER
&nbsp;#ifdef MAIL
&nbsp;            || obj-&gt;otyp == SCR_MAIL
&nbsp;#endif
&nbsp;           ) return 0;
&nbsp;        if (carried(obj))
&nbsp;            pline("Your %s %s.", ostr, vtense(ostr, "fade"));
&nbsp;
&nbsp;        obj-&gt;otyp = SCR_BLANK_PAPER;
&nbsp;        obj-&gt;dknown = 0;
&nbsp;        obj-&gt;spe = 0;
&nbsp;        if (carried(obj))
&nbsp;            update_inventory();
&nbsp;        return ER_DAMAGED;
&nbsp;    } else if (obj-&gt;oclass == SPBOOK_CLASS) {
&nbsp;        if (obj-&gt;otyp == SPE_BOOK_OF_THE_DEAD) {
&nbsp;            pline("Steam rises from %s.", the(xname(obj)));
&nbsp;            return 0;
&nbsp;        } else if (obj-&gt;otyp == SPE_BLANK_PAPER) {
&nbsp;            return 0;
&nbsp;        }
&nbsp;        if (carried(obj))
&nbsp;            pline("Your %s %s.", ostr, vtense(ostr, "fade"));
&nbsp;
&nbsp;        if (obj-&gt;otyp == SPE_NOVEL) {
&nbsp;            obj-&gt;novelidx = 0;
&nbsp;            free_oname(obj);
&nbsp;        }
&nbsp;
&nbsp;        obj-&gt;otyp = SPE_BLANK_PAPER;
&nbsp;        obj-&gt;dknown = 0;
&nbsp;        if (carried(obj))
&nbsp;            update_inventory();
&nbsp;        return ER_DAMAGED;
&nbsp;    } else if (obj-&gt;oclass == POTION_CLASS) {
&nbsp;        if (obj-&gt;otyp == POT_ACID) {
&nbsp;            char *bufp;
&nbsp;            boolean one = (obj-&gt;quan == 1L), update = carried(obj),
&nbsp;                    exploded = FALSE;
&nbsp;
&nbsp;            if (Blind &amp;&amp; !carried(obj))
&nbsp;                obj-&gt;dknown = 0;
&nbsp;            if (acid_ctx.ctx_valid)
&nbsp;                exploded = ((obj-&gt;dknown ? acid_ctx.dkn_boom
&nbsp;                                         : acid_ctx.unk_boom) &gt; 0);
&nbsp;            /* First message is
&nbsp;             * "a [potion|<color> potion|potion of acid] explodes"
&nbsp;             * depending on obj-&gt;dknown (potion has been seen) and
&nbsp;             * objects[POT_ACID].oc_name_known (fully discovered),
&nbsp;             * or "some {plural version} explode" when relevant.
&nbsp;             * Second and subsequent messages for same chain and
&nbsp;             * matching dknown status are
&nbsp;             * "another [potion|<color> &amp;c] explodes" or plural
&nbsp;             * variant.
&nbsp;             */
&nbsp;            bufp = simpleonames(obj);
&nbsp;            pline("%s %s %s!", /* "A potion explodes!" */
&nbsp;                  !exploded ? (one ? "A" : "Some")
&nbsp;                            : (one ? "Another" : "More"),
&nbsp;                  bufp, vtense(bufp, "explode"));
&nbsp;            if (acid_ctx.ctx_valid) {
&nbsp;                if (obj-&gt;dknown)
&nbsp;                    acid_ctx.dkn_boom++;
&nbsp;                else
&nbsp;                    acid_ctx.unk_boom++;
&nbsp;            }
&nbsp;            setnotworn(obj);
&nbsp;            delobj(obj);
&nbsp;            if (update)
&nbsp;                update_inventory();
&nbsp;            return ER_DESTROYED;
&nbsp;        } else if (obj-&gt;odiluted) {
&nbsp;            if (carried(obj))
&nbsp;                pline("Your %s %s further.", ostr, vtense(ostr, "dilute"));
&nbsp;
&nbsp;            obj-&gt;otyp = POT_WATER;
&nbsp;            obj-&gt;dknown = 0;
&nbsp;            obj-&gt;blessed = obj-&gt;cursed = 0;
&nbsp;            obj-&gt;odiluted = 0;
&nbsp;            if (carried(obj))
&nbsp;                update_inventory();
&nbsp;            return ER_DAMAGED;
&nbsp;        } else if (obj-&gt;otyp != POT_WATER) {
&nbsp;            if (carried(obj))
&nbsp;                pline("Your %s %s.", ostr, vtense(ostr, "dilute"));
&nbsp;
&nbsp;            obj-&gt;odiluted++;
&nbsp;            if (carried(obj))
&nbsp;                update_inventory();
&nbsp;            return ER_DAMAGED;
&nbsp;        }
&nbsp;    } else {
&nbsp;        return erode_obj(obj, ostr, ERODE_RUST, EF_NONE);
&nbsp;    }
&nbsp;    return ER_NOTHING;
&nbsp;}
&nbsp;
water_damage_chain
&nbsp;void
&nbsp;water_damage_chain(obj, here)
&nbsp;struct obj *obj;
&nbsp;boolean here;
&nbsp;{
&nbsp;    struct obj *otmp;
&nbsp;
&nbsp;    /* initialize acid context: so far, neither seen (dknown) potions of
&nbsp;       acid nor unseen have exploded during this water damage sequence */
&nbsp;    acid_ctx.dkn_boom = acid_ctx.unk_boom = 0;
&nbsp;    acid_ctx.ctx_valid = TRUE;
&nbsp;
&nbsp;    for (; obj; obj = otmp) {
&nbsp;        otmp = here ? obj-&gt;nexthere : obj-&gt;nobj;
&nbsp;        water_damage(obj, (char *) 0, FALSE);
&nbsp;    }
&nbsp;
&nbsp;    /* reset acid context */
&nbsp;    acid_ctx.dkn_boom = acid_ctx.unk_boom = 0;
&nbsp;    acid_ctx.ctx_valid = FALSE;
&nbsp;}
&nbsp;
emergency_disrobe
&nbsp;/*
&nbsp; * This function is potentially expensive - rolling
&nbsp; * inventory list multiple times.  Luckily it's seldom needed.
&nbsp; * Returns TRUE if disrobing made player unencumbered enough to
&nbsp; * crawl out of the current predicament.
&nbsp; */
&nbsp;STATIC_OVL boolean
&nbsp;emergency_disrobe(lostsome)
&nbsp;boolean *lostsome;
&nbsp;{
&nbsp;    int invc = inv_cnt(TRUE);
&nbsp;
&nbsp;    while (near_capacity() &gt; (Punished ? UNENCUMBERED : SLT_ENCUMBER)) {
&nbsp;        register struct obj *obj, *otmp = (struct obj *) 0;
&nbsp;        register int i;
&nbsp;
&nbsp;        /* Pick a random object */
&nbsp;        if (invc &gt; 0) {
&nbsp;            i = rn2(invc);
&nbsp;            for (obj = invent; obj; obj = obj-&gt;nobj) {
&nbsp;                /*
&nbsp;                 * Undroppables are: body armor, boots, gloves,
&nbsp;                 * amulets, and rings because of the time and effort
&nbsp;                 * in removing them + loadstone and other cursed stuff
&nbsp;                 * for obvious reasons.
&nbsp;                 */
&nbsp;                if (!((obj-&gt;otyp == LOADSTONE &amp;&amp; obj-&gt;cursed) || obj == uamul
&nbsp;                      || obj == uleft || obj == uright || obj == ublindf
&nbsp;                      || obj == uarm || obj == uarmc || obj == uarmg
&nbsp;                      || obj == uarmf || obj == uarmu
&nbsp;                      || (obj-&gt;cursed &amp;&amp; (obj == uarmh || obj == uarms))
&nbsp;                      || welded(obj)))
&nbsp;                    otmp = obj;
&nbsp;                /* reached the mark and found some stuff to drop? */
&nbsp;                if (--i &lt; 0 &amp;&amp; otmp)
&nbsp;                    break;
&nbsp;
&nbsp;                /* else continue */
&nbsp;            }
&nbsp;        }
&nbsp;        if (!otmp)
&nbsp;            return FALSE; /* nothing to drop! */
&nbsp;        if (otmp-&gt;owornmask)
&nbsp;            remove_worn_item(otmp, FALSE);
&nbsp;        *lostsome = TRUE;
&nbsp;        dropx(otmp);
&nbsp;        invc--;
&nbsp;    }
&nbsp;    return TRUE;
&nbsp;}
&nbsp;
&nbsp;
drown
&nbsp;/*  return TRUE iff player relocated */
&nbsp;boolean
&nbsp;drown()
&nbsp;{
&nbsp;    const char *pool_of_water;
&nbsp;    boolean inpool_ok = FALSE, crawl_ok;
&nbsp;    int i, x, y;
&nbsp;
&nbsp;    /* happily wading in the same contiguous pool */
&nbsp;    if (u.uinwater &amp;&amp; is_pool(u.ux - u.dx, u.uy - u.dy)
&nbsp;        &amp;&amp; (Swimming || Amphibious)) {
&nbsp;        /* water effects on objects every now and then */
&nbsp;        if (!rn2(5))
&nbsp;            inpool_ok = TRUE;
&nbsp;        else
&nbsp;            return FALSE;
&nbsp;    }
&nbsp;
&nbsp;    if (!u.uinwater) {
&nbsp;        You("%s into the %s%c", Is_waterlevel(&amp;u.uz) ? "plunge" : "fall",
&nbsp;            hliquid("water"),
&nbsp;            Amphibious || Swimming ? '.' : '!');
&nbsp;        if (!Swimming &amp;&amp; !Is_waterlevel(&amp;u.uz))
&nbsp;            You("sink like %s.", Hallucination ? "the Titanic" : "a rock");
&nbsp;    }
&nbsp;
&nbsp;    water_damage_chain(invent, FALSE);
&nbsp;
&nbsp;    if (u.umonnum == PM_GREMLIN &amp;&amp; rn2(3))
&nbsp;        (void) split_mon(&amp;youmonst, (struct monst *) 0);
&nbsp;    else if (u.umonnum == PM_IRON_GOLEM) {
&nbsp;        You("rust!");
&nbsp;        i = Maybe_Half_Phys(d(2, 6));
&nbsp;        if (u.mhmax &gt; i)
&nbsp;            u.mhmax -= i;
&nbsp;        losehp(i, "rusting away", KILLED_BY);
&nbsp;    }
&nbsp;    if (inpool_ok)
&nbsp;        return FALSE;
&nbsp;
&nbsp;    if ((i = number_leashed()) &gt; 0) {
&nbsp;        pline_The("leash%s slip%s loose.", (i &gt; 1) ? "es" : "",
&nbsp;                  (i &gt; 1) ? "" : "s");
&nbsp;        unleash_all();
&nbsp;    }
&nbsp;
&nbsp;    if (Amphibious || Swimming) {
&nbsp;        if (Amphibious) {
&nbsp;            if (flags.verbose)
&nbsp;                pline("But you aren't drowning.");
&nbsp;            if (!Is_waterlevel(&amp;u.uz)) {
&nbsp;                if (Hallucination)
&nbsp;                    Your("keel hits the bottom.");
&nbsp;                else
&nbsp;                    You("touch bottom.");
&nbsp;            }
&nbsp;        }
&nbsp;        if (Punished) {
&nbsp;            unplacebc();
&nbsp;            placebc();
&nbsp;        }
&nbsp;        vision_recalc(2); /* unsee old position */
&nbsp;        u.uinwater = 1;
&nbsp;        under_water(1);
&nbsp;        vision_full_recalc = 1;
&nbsp;        return FALSE;
&nbsp;    }
&nbsp;    if ((Teleportation || can_teleport(youmonst.data)) &amp;&amp; !Unaware
&nbsp;        &amp;&amp; (Teleport_control || rn2(3) &lt; Luck + 2)) {
&nbsp;        You("attempt a teleport spell."); /* utcsri!carroll */
&nbsp;        if (!level.flags.noteleport) {
&nbsp;            (void) dotele();
&nbsp;            if (!is_pool(u.ux, u.uy))
&nbsp;                return TRUE;
&nbsp;        } else
&nbsp;            pline_The("attempted teleport spell fails.");
&nbsp;    }
&nbsp;    if (u.usteed) {
&nbsp;        dismount_steed(DISMOUNT_GENERIC);
&nbsp;        if (!is_pool(u.ux, u.uy))
&nbsp;            return TRUE;
&nbsp;    }
&nbsp;    crawl_ok = FALSE;
&nbsp;    x = y = 0; /* lint suppression */
&nbsp;    /* if sleeping, wake up now so that we don't crawl out of water
&nbsp;       while still asleep; we can't do that the same way that waking
&nbsp;       due to combat is handled; note unmul() clears u.usleep */
&nbsp;    if (u.usleep)
&nbsp;        unmul("Suddenly you wake up!");
&nbsp;    /* being doused will revive from fainting */
&nbsp;    if (is_fainted())
&nbsp;        reset_faint();
&nbsp;    /* can't crawl if unable to move (crawl_ok flag stays false) */
&nbsp;    if (multi &lt; 0 || (Upolyd &amp;&amp; !youmonst.data-&gt;mmove))
&nbsp;        goto crawl;
&nbsp;    /* look around for a place to crawl to */
&nbsp;    for (i = 0; i &lt; 100; i++) {
&nbsp;        x = rn1(3, u.ux - 1);
&nbsp;        y = rn1(3, u.uy - 1);
&nbsp;        if (crawl_destination(x, y)) {
&nbsp;            crawl_ok = TRUE;
&nbsp;            goto crawl;
&nbsp;        }
&nbsp;    }
&nbsp;    /* one more scan */
&nbsp;    for (x = u.ux - 1; x &lt;= u.ux + 1; x++)
&nbsp;        for (y = u.uy - 1; y &lt;= u.uy + 1; y++)
&nbsp;            if (crawl_destination(x, y)) {
&nbsp;                crawl_ok = TRUE;
&nbsp;                goto crawl;
&nbsp;            }
&nbsp;crawl:
&nbsp;    if (crawl_ok) {
&nbsp;        boolean lost = FALSE;
&nbsp;        /* time to do some strip-tease... */
&nbsp;        boolean succ = Is_waterlevel(&amp;u.uz) ? TRUE : emergency_disrobe(&amp;lost);
&nbsp;
&nbsp;        You("try to crawl out of the %s.", hliquid("water"));
&nbsp;        if (lost)
&nbsp;            You("dump some of your gear to lose weight...");
&nbsp;        if (succ) {
&nbsp;            pline("Pheew!  That was close.");
&nbsp;            teleds(x, y, TRUE);
&nbsp;            return TRUE;
&nbsp;        }
&nbsp;        /* still too much weight */
&nbsp;        pline("But in vain.");
&nbsp;    }
&nbsp;    u.uinwater = 1;
&nbsp;    You("drown.");
&nbsp;    for (i = 0; i &lt; 5; i++) { /* arbitrary number of loops */
&nbsp;        /* killer format and name are reconstructed every iteration
&nbsp;           because lifesaving resets them */
&nbsp;        pool_of_water = waterbody_name(u.ux, u.uy);
&nbsp;        killer.format = KILLED_BY_AN;
&nbsp;        /* avoid "drowned in [a] water" */
&nbsp;        if (!strcmp(pool_of_water, "water"))
&nbsp;            pool_of_water = "deep water", killer.format = KILLED_BY;
&nbsp;        Strcpy(killer.name, pool_of_water);
&nbsp;        done(DROWNING);
&nbsp;        /* oops, we're still alive.  better get out of the water. */
&nbsp;        if (safe_teleds(TRUE))
&nbsp;            break; /* successful life-save */
&nbsp;        /* nowhere safe to land; repeat drowning loop... */
&nbsp;        pline("You're still drowning.");
&nbsp;    }
&nbsp;    if (u.uinwater) {
&nbsp;        u.uinwater = 0;
&nbsp;        You("find yourself back %s.",
&nbsp;            Is_waterlevel(&amp;u.uz) ? "in an air bubble" : "on land");
&nbsp;    }
&nbsp;    return TRUE;
&nbsp;}
&nbsp;
drain_en
&nbsp;void
&nbsp;drain_en(n)
&nbsp;int n;
&nbsp;{
&nbsp;    if (!u.uenmax) {
&nbsp;        /* energy is completely gone */
&nbsp;        You_feel("momentarily lethargic.");
&nbsp;    } else {
&nbsp;        /* throttle further loss a bit when there's not much left to lose */
&nbsp;        if (n &gt; u.uenmax || n &gt; u.ulevel)
&nbsp;            n = rnd(n);
&nbsp;
&nbsp;        You_feel("your magical energy drain away%c", (n &gt; u.uen) ? '!' : '.');
&nbsp;        u.uen -= n;
&nbsp;        if (u.uen &lt; 0) {
&nbsp;            u.uenmax -= rnd(-u.uen);
&nbsp;            if (u.uenmax &lt; 0)
&nbsp;                u.uenmax = 0;
&nbsp;            u.uen = 0;
&nbsp;        }
&nbsp;        context.botl = 1;
&nbsp;    }
&nbsp;}
&nbsp;
dountrap
&nbsp;/* disarm a trap */
&nbsp;int
&nbsp;dountrap()
&nbsp;{
&nbsp;    if (near_capacity() &gt;= HVY_ENCUMBER) {
&nbsp;        pline("You're too strained to do that.");
&nbsp;        return 0;
&nbsp;    }
&nbsp;    if ((nohands(youmonst.data) &amp;&amp; !webmaker(youmonst.data))
&nbsp;        || !youmonst.data-&gt;mmove) {
&nbsp;        pline("And just how do you expect to do that?");
&nbsp;        return 0;
&nbsp;    } else if (u.ustuck &amp;&amp; sticks(youmonst.data)) {
&nbsp;        pline("You'll have to let go of %s first.", mon_nam(u.ustuck));
&nbsp;        return 0;
&nbsp;    }
&nbsp;    if (u.ustuck || (welded(uwep) &amp;&amp; bimanual(uwep))) {
&nbsp;        Your("%s seem to be too busy for that.", makeplural(body_part(HAND)));
&nbsp;        return 0;
&nbsp;    }
&nbsp;    return untrap(FALSE);
&nbsp;}
&nbsp;
untrap_prob
&nbsp;/* Probability of disabling a trap.  Helge Hafting */
&nbsp;STATIC_OVL int
&nbsp;untrap_prob(ttmp)
&nbsp;struct trap *ttmp;
&nbsp;{
&nbsp;    int chance = 3;
&nbsp;
&nbsp;    /* Only spiders know how to deal with webs reliably */
&nbsp;    if (ttmp-&gt;ttyp == WEB &amp;&amp; !webmaker(youmonst.data))
&nbsp;        chance = 30;
&nbsp;    if (Confusion || Hallucination)
&nbsp;        chance++;
&nbsp;    if (Blind)
&nbsp;        chance++;
&nbsp;    if (Stunned)
&nbsp;        chance += 2;
&nbsp;    if (Fumbling)
&nbsp;        chance *= 2;
&nbsp;    /* Your own traps are better known than others. */
&nbsp;    if (ttmp &amp;&amp; ttmp-&gt;madeby_u)
&nbsp;        chance--;
&nbsp;    if (Role_if(PM_ROGUE)) {
&nbsp;        if (rn2(2 * MAXULEV) &lt; u.ulevel)
&nbsp;            chance--;
&nbsp;        if (u.uhave.questart &amp;&amp; chance &gt; 1)
&nbsp;            chance--;
&nbsp;    } else if (Role_if(PM_RANGER) &amp;&amp; chance &gt; 1)
&nbsp;        chance--;
&nbsp;    return rn2(chance);
&nbsp;}
&nbsp;
cnv_trap_obj
&nbsp;/* Replace trap with object(s).  Helge Hafting */
&nbsp;void
&nbsp;cnv_trap_obj(otyp, cnt, ttmp, bury_it)
&nbsp;int otyp;
&nbsp;int cnt;
&nbsp;struct trap *ttmp;
&nbsp;boolean bury_it;
&nbsp;{
&nbsp;    struct obj *otmp = mksobj(otyp, TRUE, FALSE);
&nbsp;
&nbsp;    otmp-&gt;quan = cnt;
&nbsp;    otmp-&gt;owt = weight(otmp);
&nbsp;    /* Only dart traps are capable of being poisonous */
&nbsp;    if (otyp != DART)
&nbsp;        otmp-&gt;opoisoned = 0;
&nbsp;    place_object(otmp, ttmp-&gt;tx, ttmp-&gt;ty);
&nbsp;    if (bury_it) {
&nbsp;        /* magical digging first disarms this trap, then will unearth it */
&nbsp;        (void) bury_an_obj(otmp, (boolean *) 0);
&nbsp;    } else {
&nbsp;        /* Sell your own traps only... */
&nbsp;        if (ttmp-&gt;madeby_u)
&nbsp;            sellobj(otmp, ttmp-&gt;tx, ttmp-&gt;ty);
&nbsp;        stackobj(otmp);
&nbsp;    }
&nbsp;    newsym(ttmp-&gt;tx, ttmp-&gt;ty);
&nbsp;    if (u.utrap &amp;&amp; ttmp-&gt;tx == u.ux &amp;&amp; ttmp-&gt;ty == u.uy)
&nbsp;        u.utrap = 0;
&nbsp;    deltrap(ttmp);
&nbsp;}
&nbsp;
move_into_trap
&nbsp;/* while attempting to disarm an adjacent trap, we've fallen into it */
&nbsp;STATIC_OVL void
&nbsp;move_into_trap(ttmp)
&nbsp;struct trap *ttmp;
&nbsp;{
&nbsp;    int bc = 0;
&nbsp;    xchar x = ttmp-&gt;tx, y = ttmp-&gt;ty, bx, by, cx, cy;
&nbsp;    boolean unused;
&nbsp;
&nbsp;    bx = by = cx = cy = 0; /* lint suppression */
&nbsp;    /* we know there's no monster in the way, and we're not trapped */
&nbsp;    if (!Punished
&nbsp;        || drag_ball(x, y, &amp;bc, &amp;bx, &amp;by, &amp;cx, &amp;cy, &amp;unused, TRUE)) {
&nbsp;        u.ux0 = u.ux, u.uy0 = u.uy;
&nbsp;        u.ux = x, u.uy = y;
&nbsp;        u.umoved = TRUE;
&nbsp;        newsym(u.ux0, u.uy0);
&nbsp;        vision_recalc(1);
&nbsp;        check_leash(u.ux0, u.uy0);
&nbsp;        if (Punished)
&nbsp;            move_bc(0, bc, bx, by, cx, cy);
&nbsp;        /* marking the trap unseen forces dotrap() to treat it like a new
&nbsp;           discovery and prevents pickup() -&gt; look_here() -&gt; check_here()
&nbsp;           from giving a redundant "there is a <trap> here" message when
&nbsp;           there are objects covering this trap */
&nbsp;        ttmp-&gt;tseen = 0; /* hack for check_here() */
&nbsp;        /* trigger the trap */
&nbsp;        spoteffects(TRUE); /* pickup() + dotrap() */
&nbsp;        exercise(A_WIS, FALSE);
&nbsp;    }
&nbsp;}
&nbsp;
try_disarm
&nbsp;/* 0: doesn't even try
&nbsp; * 1: tries and fails
&nbsp; * 2: succeeds
&nbsp; */
&nbsp;STATIC_OVL int
&nbsp;try_disarm(ttmp, force_failure)
&nbsp;struct trap *ttmp;
&nbsp;boolean force_failure;
&nbsp;{
&nbsp;    struct monst *mtmp = m_at(ttmp-&gt;tx, ttmp-&gt;ty);
&nbsp;    int ttype = ttmp-&gt;ttyp;
&nbsp;    boolean under_u = (!u.dx &amp;&amp; !u.dy);
&nbsp;    boolean holdingtrap = (ttype == BEAR_TRAP || ttype == WEB);
&nbsp;
&nbsp;    /* Test for monster first, monsters are displayed instead of trap. */
&nbsp;    if (mtmp &amp;&amp; (!mtmp-&gt;mtrapped || !holdingtrap)) {
&nbsp;        pline("%s is in the way.", Monnam(mtmp));
&nbsp;        return 0;
&nbsp;    }
&nbsp;    /* We might be forced to move onto the trap's location. */
&nbsp;    if (sobj_at(BOULDER, ttmp-&gt;tx, ttmp-&gt;ty) &amp;&amp; !Passes_walls &amp;&amp; !under_u) {
&nbsp;        There("is a boulder in your way.");
&nbsp;        return 0;
&nbsp;    }
&nbsp;    /* duplicate tight-space checks from test_move */
&nbsp;    if (u.dx &amp;&amp; u.dy &amp;&amp; bad_rock(youmonst.data, u.ux, ttmp-&gt;ty)
&nbsp;        &amp;&amp; bad_rock(youmonst.data, ttmp-&gt;tx, u.uy)) {
&nbsp;        if ((invent &amp;&amp; (inv_weight() + weight_cap() &gt; 600))
&nbsp;            || bigmonst(youmonst.data)) {
&nbsp;            /* don't allow untrap if they can't get thru to it */
&nbsp;            You("are unable to reach the %s!",
&nbsp;                defsyms[trap_to_defsym(ttype)].explanation);
&nbsp;            return 0;
&nbsp;        }
&nbsp;    }
&nbsp;    /* untrappable traps are located on the ground. */
&nbsp;    if (!can_reach_floor(TRUE)) {
&nbsp;        if (u.usteed &amp;&amp; P_SKILL(P_RIDING) &lt; P_BASIC)
&nbsp;            rider_cant_reach();
&nbsp;        else
&nbsp;            You("are unable to reach the %s!",
&nbsp;                defsyms[trap_to_defsym(ttype)].explanation);
&nbsp;        return 0;
&nbsp;    }
&nbsp;
&nbsp;    /* Will our hero succeed? */
&nbsp;    if (force_failure || untrap_prob(ttmp)) {
&nbsp;        if (rnl(5)) {
&nbsp;            pline("Whoops...");
&nbsp;            if (mtmp) { /* must be a trap that holds monsters */
&nbsp;                if (ttype == BEAR_TRAP) {
&nbsp;                    if (mtmp-&gt;mtame)
&nbsp;                        abuse_dog(mtmp);
&nbsp;                    mtmp-&gt;mhp -= rnd(4);
&nbsp;                    if (mtmp-&gt;mhp &lt;= 0)
&nbsp;                        killed(mtmp);
&nbsp;                } else if (ttype == WEB) {
&nbsp;                    if (!webmaker(youmonst.data)) {
&nbsp;                        struct trap *ttmp2 = maketrap(u.ux, u.uy, WEB);
&nbsp;
&nbsp;                        if (ttmp2) {
&nbsp;                            pline_The(
&nbsp;                                "webbing sticks to you. You're caught too!");
&nbsp;                            dotrap(ttmp2, NOWEBMSG);
&nbsp;                            if (u.usteed &amp;&amp; u.utrap) {
&nbsp;                                /* you, not steed, are trapped */
&nbsp;                                dismount_steed(DISMOUNT_FELL);
&nbsp;                            }
&nbsp;                        }
&nbsp;                    } else
&nbsp;                        pline("%s remains entangled.", Monnam(mtmp));
&nbsp;                }
&nbsp;            } else if (under_u) {
&nbsp;                dotrap(ttmp, 0);
&nbsp;            } else {
&nbsp;                move_into_trap(ttmp);
&nbsp;            }
&nbsp;        } else {
&nbsp;            pline("%s %s is difficult to %s.",
&nbsp;                  ttmp-&gt;madeby_u ? "Your" : under_u ? "This" : "That",
&nbsp;                  defsyms[trap_to_defsym(ttype)].explanation,
&nbsp;                  (ttype == WEB) ? "remove" : "disarm");
&nbsp;        }
&nbsp;        return 1;
&nbsp;    }
&nbsp;    return 2;
&nbsp;}
&nbsp;
reward_untrap
&nbsp;STATIC_OVL void
&nbsp;reward_untrap(ttmp, mtmp)
&nbsp;struct trap *ttmp;
&nbsp;struct monst *mtmp;
&nbsp;{
&nbsp;    if (!ttmp-&gt;madeby_u) {
&nbsp;        if (rnl(10) &lt; 8 &amp;&amp; !mtmp-&gt;mpeaceful &amp;&amp; !mtmp-&gt;msleeping
&nbsp;            &amp;&amp; !mtmp-&gt;mfrozen &amp;&amp; !mindless(mtmp-&gt;data)
&nbsp;            &amp;&amp; mtmp-&gt;data-&gt;mlet != S_HUMAN) {
&nbsp;            mtmp-&gt;mpeaceful = 1;
&nbsp;            set_malign(mtmp); /* reset alignment */
&nbsp;            pline("%s is grateful.", Monnam(mtmp));
&nbsp;        }
&nbsp;        /* Helping someone out of a trap is a nice thing to do,
&nbsp;         * A lawful may be rewarded, but not too often.  */
&nbsp;        if (!rn2(3) &amp;&amp; !rnl(8) &amp;&amp; u.ualign.type == A_LAWFUL) {
&nbsp;            adjalign(1);
&nbsp;            You_feel("that you did the right thing.");
&nbsp;        }
&nbsp;    }
&nbsp;}
&nbsp;
disarm_holdingtrap
&nbsp;STATIC_OVL int
&nbsp;disarm_holdingtrap(ttmp) /* Helge Hafting */
&nbsp;struct trap *ttmp;
&nbsp;{
&nbsp;    struct monst *mtmp;
&nbsp;    int fails = try_disarm(ttmp, FALSE);
&nbsp;
&nbsp;    if (fails &lt; 2)
&nbsp;        return fails;
&nbsp;
&nbsp;    /* ok, disarm it. */
&nbsp;
&nbsp;    /* untrap the monster, if any.
&nbsp;       There's no need for a cockatrice test, only the trap is touched */
&nbsp;    if ((mtmp = m_at(ttmp-&gt;tx, ttmp-&gt;ty)) != 0) {
&nbsp;        mtmp-&gt;mtrapped = 0;
&nbsp;        You("remove %s %s from %s.", the_your[ttmp-&gt;madeby_u],
&nbsp;            (ttmp-&gt;ttyp == BEAR_TRAP) ? "bear trap" : "webbing",
&nbsp;            mon_nam(mtmp));
&nbsp;        reward_untrap(ttmp, mtmp);
&nbsp;    } else {
&nbsp;        if (ttmp-&gt;ttyp == BEAR_TRAP) {
&nbsp;            You("disarm %s bear trap.", the_your[ttmp-&gt;madeby_u]);
&nbsp;            cnv_trap_obj(BEARTRAP, 1, ttmp, FALSE);
&nbsp;        } else /* if (ttmp-&gt;ttyp == WEB) */ {
&nbsp;            You("succeed in removing %s web.", the_your[ttmp-&gt;madeby_u]);
&nbsp;            deltrap(ttmp);
&nbsp;        }
&nbsp;    }
&nbsp;    newsym(u.ux + u.dx, u.uy + u.dy);
&nbsp;    return 1;
&nbsp;}
&nbsp;
disarm_landmine
&nbsp;STATIC_OVL int
&nbsp;disarm_landmine(ttmp) /* Helge Hafting */
&nbsp;struct trap *ttmp;
&nbsp;{
&nbsp;    int fails = try_disarm(ttmp, FALSE);
&nbsp;
&nbsp;    if (fails &lt; 2)
&nbsp;        return fails;
&nbsp;    You("disarm %s land mine.", the_your[ttmp-&gt;madeby_u]);
&nbsp;    cnv_trap_obj(LAND_MINE, 1, ttmp, FALSE);
&nbsp;    return 1;
&nbsp;}
&nbsp;
&nbsp;/* getobj will filter down to cans of grease and known potions of oil */
&nbsp;static NEARDATA const char oil[] = { ALL_CLASSES, TOOL_CLASS, POTION_CLASS,
&nbsp;                                     0 };
&nbsp;
disarm_squeaky_board
&nbsp;/* it may not make much sense to use grease on floor boards, but so what? */
&nbsp;STATIC_OVL int
&nbsp;disarm_squeaky_board(ttmp)
&nbsp;struct trap *ttmp;
&nbsp;{
&nbsp;    struct obj *obj;
&nbsp;    boolean bad_tool;
&nbsp;    int fails;
&nbsp;
&nbsp;    obj = getobj(oil, "untrap with");
&nbsp;    if (!obj)
&nbsp;        return 0;
&nbsp;
&nbsp;    bad_tool = (obj-&gt;cursed
&nbsp;                || ((obj-&gt;otyp != POT_OIL || obj-&gt;lamplit)
&nbsp;                    &amp;&amp; (obj-&gt;otyp != CAN_OF_GREASE || !obj-&gt;spe)));
&nbsp;    fails = try_disarm(ttmp, bad_tool);
&nbsp;    if (fails &lt; 2)
&nbsp;        return fails;
&nbsp;
&nbsp;    /* successfully used oil or grease to fix squeaky board */
&nbsp;    if (obj-&gt;otyp == CAN_OF_GREASE) {
&nbsp;        consume_obj_charge(obj, TRUE);
&nbsp;    } else {
&nbsp;        useup(obj); /* oil */
&nbsp;        makeknown(POT_OIL);
&nbsp;    }
&nbsp;    You("repair the squeaky board."); /* no madeby_u */
&nbsp;    deltrap(ttmp);
&nbsp;    newsym(u.ux + u.dx, u.uy + u.dy);
&nbsp;    more_experienced(1, 5);
&nbsp;    newexplevel();
&nbsp;    return 1;
&nbsp;}
&nbsp;
disarm_shooting_trap
&nbsp;/* removes traps that shoot arrows, darts, etc. */
&nbsp;STATIC_OVL int
&nbsp;disarm_shooting_trap(ttmp, otyp)
&nbsp;struct trap *ttmp;
&nbsp;int otyp;
&nbsp;{
&nbsp;    int fails = try_disarm(ttmp, FALSE);
&nbsp;
&nbsp;    if (fails &lt; 2)
&nbsp;        return fails;
&nbsp;    You("disarm %s trap.", the_your[ttmp-&gt;madeby_u]);
&nbsp;    cnv_trap_obj(otyp, 50 - rnl(50), ttmp, FALSE);
&nbsp;    return 1;
&nbsp;}
&nbsp;
try_lift
&nbsp;/* Is the weight too heavy?
&nbsp; * Formula as in near_capacity() &amp; check_capacity() */
&nbsp;STATIC_OVL int
&nbsp;try_lift(mtmp, ttmp, wt, stuff)
&nbsp;struct monst *mtmp;
&nbsp;struct trap *ttmp;
&nbsp;int wt;
&nbsp;boolean stuff;
&nbsp;{
&nbsp;    int wc = weight_cap();
&nbsp;
&nbsp;    if (((wt * 2) / wc) &gt;= HVY_ENCUMBER) {
&nbsp;        pline("%s is %s for you to lift.", Monnam(mtmp),
&nbsp;              stuff ? "carrying too much" : "too heavy");
&nbsp;        if (!ttmp-&gt;madeby_u &amp;&amp; !mtmp-&gt;mpeaceful &amp;&amp; mtmp-&gt;mcanmove
&nbsp;            &amp;&amp; !mindless(mtmp-&gt;data) &amp;&amp; mtmp-&gt;data-&gt;mlet != S_HUMAN
&nbsp;            &amp;&amp; rnl(10) &lt; 3) {
&nbsp;            mtmp-&gt;mpeaceful = 1;
&nbsp;            set_malign(mtmp); /* reset alignment */
&nbsp;            pline("%s thinks it was nice of you to try.", Monnam(mtmp));
&nbsp;        }
&nbsp;        return 0;
&nbsp;    }
&nbsp;    return 1;
&nbsp;}
&nbsp;
help_monster_out
&nbsp;/* Help trapped monster (out of a (spiked) pit) */
&nbsp;STATIC_OVL int
&nbsp;help_monster_out(mtmp, ttmp)
&nbsp;struct monst *mtmp;
&nbsp;struct trap *ttmp;
&nbsp;{
&nbsp;    int wt;
&nbsp;    struct obj *otmp;
&nbsp;    boolean uprob;
&nbsp;
&nbsp;    /*
&nbsp;     * This works when levitating too -- consistent with the ability
&nbsp;     * to hit monsters while levitating.
&nbsp;     *
&nbsp;     * Should perhaps check that our hero has arms/hands at the
&nbsp;     * moment.  Helping can also be done by engulfing...
&nbsp;     *
&nbsp;     * Test the monster first - monsters are displayed before traps.
&nbsp;     */
&nbsp;    if (!mtmp-&gt;mtrapped) {
&nbsp;        pline("%s isn't trapped.", Monnam(mtmp));
&nbsp;        return 0;
&nbsp;    }
&nbsp;    /* Do you have the necessary capacity to lift anything? */
&nbsp;    if (check_capacity((char *) 0))
&nbsp;        return 1;
&nbsp;
&nbsp;    /* Will our hero succeed? */
&nbsp;    if ((uprob = untrap_prob(ttmp)) &amp;&amp; !mtmp-&gt;msleeping &amp;&amp; mtmp-&gt;mcanmove) {
&nbsp;        You("try to reach out your %s, but %s backs away skeptically.",
&nbsp;            makeplural(body_part(ARM)), mon_nam(mtmp));
&nbsp;        return 1;
&nbsp;    }
&nbsp;
&nbsp;    /* is it a cockatrice?... */
&nbsp;    if (touch_petrifies(mtmp-&gt;data) &amp;&amp; !uarmg &amp;&amp; !Stone_resistance) {
&nbsp;        You("grab the trapped %s using your bare %s.", mtmp-&gt;data-&gt;mname,
&nbsp;            makeplural(body_part(HAND)));
&nbsp;
&nbsp;        if (poly_when_stoned(youmonst.data) &amp;&amp; polymon(PM_STONE_GOLEM)) {
&nbsp;            display_nhwindow(WIN_MESSAGE, FALSE);
&nbsp;        } else {
&nbsp;            char kbuf[BUFSZ];
&nbsp;
&nbsp;            Sprintf(kbuf, "trying to help %s out of a pit",
&nbsp;                    an(mtmp-&gt;data-&gt;mname));
&nbsp;            instapetrify(kbuf);
&nbsp;            return 1;
&nbsp;        }
&nbsp;    }
&nbsp;    /* need to do cockatrice check first if sleeping or paralyzed */
&nbsp;    if (uprob) {
&nbsp;        You("try to grab %s, but cannot get a firm grasp.", mon_nam(mtmp));
&nbsp;        if (mtmp-&gt;msleeping) {
&nbsp;            mtmp-&gt;msleeping = 0;
&nbsp;            pline("%s awakens.", Monnam(mtmp));
&nbsp;        }
&nbsp;        return 1;
&nbsp;    }
&nbsp;
&nbsp;    You("reach out your %s and grab %s.", makeplural(body_part(ARM)),
&nbsp;        mon_nam(mtmp));
&nbsp;
&nbsp;    if (mtmp-&gt;msleeping) {
&nbsp;        mtmp-&gt;msleeping = 0;
&nbsp;        pline("%s awakens.", Monnam(mtmp));
&nbsp;    } else if (mtmp-&gt;mfrozen &amp;&amp; !rn2(mtmp-&gt;mfrozen)) {
&nbsp;        /* After such manhandling, perhaps the effect wears off */
&nbsp;        mtmp-&gt;mcanmove = 1;
&nbsp;        mtmp-&gt;mfrozen = 0;
&nbsp;        pline("%s stirs.", Monnam(mtmp));
&nbsp;    }
&nbsp;
&nbsp;    /* is the monster too heavy? */
&nbsp;    wt = inv_weight() + mtmp-&gt;data-&gt;cwt;
&nbsp;    if (!try_lift(mtmp, ttmp, wt, FALSE))
&nbsp;        return 1;
&nbsp;
&nbsp;    /* is the monster with inventory too heavy? */
&nbsp;    for (otmp = mtmp-&gt;minvent; otmp; otmp = otmp-&gt;nobj)
&nbsp;        wt += otmp-&gt;owt;
&nbsp;    if (!try_lift(mtmp, ttmp, wt, TRUE))
&nbsp;        return 1;
&nbsp;
&nbsp;    You("pull %s out of the pit.", mon_nam(mtmp));
&nbsp;    mtmp-&gt;mtrapped = 0;
&nbsp;    fill_pit(mtmp-&gt;mx, mtmp-&gt;my);
&nbsp;    reward_untrap(ttmp, mtmp);
&nbsp;    return 1;
&nbsp;}
&nbsp;
untrap
&nbsp;int
&nbsp;untrap(force)
&nbsp;boolean force;
&nbsp;{
&nbsp;    register struct obj *otmp;
&nbsp;    register int x, y;
&nbsp;    int ch;
&nbsp;    struct trap *ttmp;
&nbsp;    struct monst *mtmp;
&nbsp;    const char *trapdescr;
&nbsp;    boolean here, useplural, deal_with_floor_trap,
&nbsp;            confused = (Confusion || Hallucination),
&nbsp;            trap_skipped = FALSE;
&nbsp;    int boxcnt = 0;
&nbsp;    char the_trap[BUFSZ], qbuf[QBUFSZ];
&nbsp;
&nbsp;    if (!getdir((char *) 0))
&nbsp;        return 0;
&nbsp;    x = u.ux + u.dx;
&nbsp;    y = u.uy + u.dy;
&nbsp;    if (!isok(x, y)) {
&nbsp;        pline_The("perils lurking there are beyond your grasp.");
&nbsp;        return 0;
&nbsp;    }
&nbsp;    /* 'force' is true for #invoke; make it be true for #untrap if
&nbsp;       carrying MKoT */
&nbsp;    if (!force &amp;&amp; has_magic_key(&amp;youmonst))
&nbsp;        force = TRUE;
&nbsp;
&nbsp;    ttmp = t_at(x, y);
&nbsp;    if (ttmp &amp;&amp; !ttmp-&gt;tseen)
&nbsp;        ttmp = 0;
&nbsp;    trapdescr = ttmp ? defsyms[trap_to_defsym(ttmp-&gt;ttyp)].explanation : 0;
&nbsp;    here = (x == u.ux &amp;&amp; y == u.uy); /* !u.dx &amp;&amp; !u.dy */
&nbsp;
&nbsp;    if (here) /* are there are one or more containers here? */
&nbsp;        for (otmp = level.objects[x][y]; otmp; otmp = otmp-&gt;nexthere)
&nbsp;            if (Is_box(otmp)) {
&nbsp;                if (++boxcnt &gt; 1)
&nbsp;                    break;
&nbsp;            }
&nbsp;
&nbsp;    deal_with_floor_trap = can_reach_floor(FALSE);
&nbsp;    if (!deal_with_floor_trap) {
&nbsp;        *the_trap = '\0';
&nbsp;        if (ttmp)
&nbsp;            Strcat(the_trap, an(trapdescr));
&nbsp;        if (ttmp &amp;&amp; boxcnt)
&nbsp;            Strcat(the_trap, " and ");
&nbsp;        if (boxcnt)
&nbsp;            Strcat(the_trap, (boxcnt == 1) ? "a container" : "containers");
&nbsp;        useplural = ((ttmp &amp;&amp; boxcnt &gt; 0) || boxcnt &gt; 1);
&nbsp;        /* note: boxcnt and useplural will always be 0 for !here case */
&nbsp;        if (ttmp || boxcnt)
&nbsp;            There("%s %s %s but you can't reach %s%s.",
&nbsp;                  useplural ? "are" : "is", the_trap, here ? "here" : "there",
&nbsp;                  useplural ? "them" : "it",
&nbsp;                  u.usteed ? " while mounted" : "");
&nbsp;        trap_skipped = (ttmp != 0);
&nbsp;    } else { /* deal_with_floor_trap */
&nbsp;
&nbsp;        if (ttmp) {
&nbsp;            Strcpy(the_trap, the(trapdescr));
&nbsp;            if (boxcnt) {
&nbsp;                if (ttmp-&gt;ttyp == PIT || ttmp-&gt;ttyp == SPIKED_PIT) {
&nbsp;                    You_cant("do much about %s%s.", the_trap,
&nbsp;                             u.utrap ? " that you're stuck in"
&nbsp;                                     : " while standing on the edge of it");
&nbsp;                    trap_skipped = TRUE;
&nbsp;                    deal_with_floor_trap = FALSE;
&nbsp;                } else {
&nbsp;                    Sprintf(
&nbsp;                        qbuf, "There %s and %s here. %s %s?",
&nbsp;                        (boxcnt == 1) ? "is a container" : "are containers",
&nbsp;                        an(trapdescr),
&nbsp;                        (ttmp-&gt;ttyp == WEB) ? "Remove" : "Disarm", the_trap);
&nbsp;                    switch (ynq(qbuf)) {
&nbsp;                    case 'q':
&nbsp;                        return 0;
&nbsp;                    case 'n':
&nbsp;                        trap_skipped = TRUE;
&nbsp;                        deal_with_floor_trap = FALSE;
&nbsp;                        break;
&nbsp;                    }
&nbsp;                }
&nbsp;            }
&nbsp;            if (deal_with_floor_trap) {
&nbsp;                if (u.utrap) {
&nbsp;                    You("cannot deal with %s while trapped%s!", the_trap,
&nbsp;                        (x == u.ux &amp;&amp; y == u.uy) ? " in it" : "");
&nbsp;                    return 1;
&nbsp;                }
&nbsp;                if ((mtmp = m_at(x, y)) != 0
&nbsp;                    &amp;&amp; (mtmp-&gt;m_ap_type == M_AP_FURNITURE
&nbsp;                        || mtmp-&gt;m_ap_type == M_AP_OBJECT)) {
&nbsp;                    stumble_onto_mimic(mtmp);
&nbsp;                    return 1;
&nbsp;                }
&nbsp;                switch (ttmp-&gt;ttyp) {
&nbsp;                case BEAR_TRAP:
&nbsp;                case WEB:
&nbsp;                    return disarm_holdingtrap(ttmp);
&nbsp;                case LANDMINE:
&nbsp;                    return disarm_landmine(ttmp);
&nbsp;                case SQKY_BOARD:
&nbsp;                    return disarm_squeaky_board(ttmp);
&nbsp;                case DART_TRAP:
&nbsp;                    return disarm_shooting_trap(ttmp, DART);
&nbsp;                case ARROW_TRAP:
&nbsp;                    return disarm_shooting_trap(ttmp, ARROW);
&nbsp;                case PIT:
&nbsp;                case SPIKED_PIT:
&nbsp;                    if (here) {
&nbsp;                        You("are already on the edge of the pit.");
&nbsp;                        return 0;
&nbsp;                    }
&nbsp;                    if (!mtmp) {
&nbsp;                        pline("Try filling the pit instead.");
&nbsp;                        return 0;
&nbsp;                    }
&nbsp;                    return help_monster_out(mtmp, ttmp);
&nbsp;                default:
&nbsp;                    You("cannot disable %s trap.", !here ? "that" : "this");
&nbsp;                    return 0;
&nbsp;                }
&nbsp;            }
&nbsp;        } /* end if */
&nbsp;
&nbsp;        if (boxcnt) {
&nbsp;            for (otmp = level.objects[x][y]; otmp; otmp = otmp-&gt;nexthere)
&nbsp;                if (Is_box(otmp)) {
&nbsp;                    (void) safe_qbuf(qbuf, "There is ",
&nbsp;                                     " here.  Check it for traps?", otmp,
&nbsp;                                     doname, ansimpleoname, "a box");
&nbsp;                    switch (ynq(qbuf)) {
&nbsp;                    case 'q':
&nbsp;                        return 0;
&nbsp;                    case 'n':
&nbsp;                        continue;
&nbsp;                    }
&nbsp;
&nbsp;                    if ((otmp-&gt;otrapped
&nbsp;                         &amp;&amp; (force || (!confused
&nbsp;                                       &amp;&amp; rn2(MAXULEV + 1 - u.ulevel) &lt; 10)))
&nbsp;                        || (!force &amp;&amp; confused &amp;&amp; !rn2(3))) {
&nbsp;                        You("find a trap on %s!", the(xname(otmp)));
&nbsp;                        if (!confused)
&nbsp;                            exercise(A_WIS, TRUE);
&nbsp;
&nbsp;                        switch (ynq("Disarm it?")) {
&nbsp;                        case 'q':
&nbsp;                            return 1;
&nbsp;                        case 'n':
&nbsp;                            trap_skipped = TRUE;
&nbsp;                            continue;
&nbsp;                        }
&nbsp;
&nbsp;                        if (otmp-&gt;otrapped) {
&nbsp;                            exercise(A_DEX, TRUE);
&nbsp;                            ch = ACURR(A_DEX) + u.ulevel;
&nbsp;                            if (Role_if(PM_ROGUE))
&nbsp;                                ch *= 2;
&nbsp;                            if (!force &amp;&amp; (confused || Fumbling
&nbsp;                                           || rnd(75 + level_difficulty() / 2)
&nbsp;                                                  &gt; ch)) {
&nbsp;                                (void) chest_trap(otmp, FINGER, TRUE);
&nbsp;                            } else {
&nbsp;                                You("disarm it!");
&nbsp;                                otmp-&gt;otrapped = 0;
&nbsp;                            }
&nbsp;                        } else
&nbsp;                            pline("That %s was not trapped.", xname(otmp));
&nbsp;                        return 1;
&nbsp;                    } else {
&nbsp;                        You("find no traps on %s.", the(xname(otmp)));
&nbsp;                        return 1;
&nbsp;                    }
&nbsp;                }
&nbsp;
&nbsp;            You(trap_skipped ? "find no other traps here."
&nbsp;                             : "know of no traps here.");
&nbsp;            return 0;
&nbsp;        }
&nbsp;
&nbsp;        if (stumble_on_door_mimic(x, y))
&nbsp;            return 1;
&nbsp;
&nbsp;    } /* deal_with_floor_trap */
&nbsp;    /* doors can be manipulated even while levitating/unskilled riding */
&nbsp;
&nbsp;    if (!IS_DOOR(levl[x][y].typ)) {
&nbsp;        if (!trap_skipped)
&nbsp;            You("know of no traps there.");
&nbsp;        return 0;
&nbsp;    }
&nbsp;
&nbsp;    switch (levl[x][y].doormask) {
&nbsp;    case D_NODOOR:
&nbsp;        You("%s no door there.", Blind ? "feel" : "see");
&nbsp;        return 0;
&nbsp;    case D_ISOPEN:
&nbsp;        pline("This door is safely open.");
&nbsp;        return 0;
&nbsp;    case D_BROKEN:
&nbsp;        pline("This door is broken.");
&nbsp;        return 0;
&nbsp;    }
&nbsp;
&nbsp;    if (((levl[x][y].doormask &amp; D_TRAPPED) != 0
&nbsp;         &amp;&amp; (force || (!confused &amp;&amp; rn2(MAXULEV - u.ulevel + 11) &lt; 10)))
&nbsp;        || (!force &amp;&amp; confused &amp;&amp; !rn2(3))) {
&nbsp;        You("find a trap on the door!");
&nbsp;        exercise(A_WIS, TRUE);
&nbsp;        if (ynq("Disarm it?") != 'y')
&nbsp;            return 1;
&nbsp;        if (levl[x][y].doormask &amp; D_TRAPPED) {
&nbsp;            ch = 15 + (Role_if(PM_ROGUE) ? u.ulevel * 3 : u.ulevel);
&nbsp;            exercise(A_DEX, TRUE);
&nbsp;            if (!force &amp;&amp; (confused || Fumbling
&nbsp;                           || rnd(75 + level_difficulty() / 2) &gt; ch)) {
&nbsp;                You("set it off!");
&nbsp;                b_trapped("door", FINGER);
&nbsp;                levl[x][y].doormask = D_NODOOR;
&nbsp;                unblock_point(x, y);
&nbsp;                newsym(x, y);
&nbsp;                /* (probably ought to charge for this damage...) */
&nbsp;                if (*in_rooms(x, y, SHOPBASE))
&nbsp;                    add_damage(x, y, 0L);
&nbsp;            } else {
&nbsp;                You("disarm it!");
&nbsp;                levl[x][y].doormask &amp;= ~D_TRAPPED;
&nbsp;            }
&nbsp;        } else
&nbsp;            pline("This door was not trapped.");
&nbsp;        return 1;
&nbsp;    } else {
&nbsp;        You("find no traps on the door.");
&nbsp;        return 1;
&nbsp;    }
&nbsp;}
&nbsp;
openholdingtrap
&nbsp;/* for magic unlocking; returns true if targetted monster (which might
&nbsp;   be hero) gets untrapped; the trap remains intact */
&nbsp;boolean
&nbsp;openholdingtrap(mon, noticed)
&nbsp;struct monst *mon;
&nbsp;boolean *noticed; /* set to true iff hero notices the effect; */
&nbsp;{                 /* otherwise left with its previous value intact */
&nbsp;    struct trap *t;
&nbsp;    char buf[BUFSZ];
&nbsp;    const char *trapdescr, *which;
&nbsp;    boolean ishero = (mon == &amp;youmonst);
&nbsp;
&nbsp;    if (!mon)
&nbsp;        return FALSE;
&nbsp;    if (mon == u.usteed)
&nbsp;        ishero = TRUE;
&nbsp;    t = t_at(ishero ? u.ux : mon-&gt;mx, ishero ? u.uy : mon-&gt;my);
&nbsp;    /* if no trap here or it's not a holding trap, we're done */
&nbsp;    if (!t || (t-&gt;ttyp != BEAR_TRAP &amp;&amp; t-&gt;ttyp != WEB))
&nbsp;        return FALSE;
&nbsp;
&nbsp;    trapdescr = defsyms[trap_to_defsym(t-&gt;ttyp)].explanation;
&nbsp;    which = t-&gt;tseen ? the_your[t-&gt;madeby_u]
&nbsp;                     : index(vowels, *trapdescr) ? "an" : "a";
&nbsp;
&nbsp;    if (ishero) {
&nbsp;        if (!u.utrap)
&nbsp;            return FALSE;
&nbsp;        u.utrap = 0; /* released regardless of type */
&nbsp;        *noticed = TRUE;
&nbsp;        /* give message only if trap was the expected type */
&nbsp;        if (u.utraptype == TT_BEARTRAP || u.utraptype == TT_WEB) {
&nbsp;            if (u.usteed)
&nbsp;                Sprintf(buf, "%s is", noit_Monnam(u.usteed));
&nbsp;            else
&nbsp;                Strcpy(buf, "You are");
&nbsp;            pline("%s released from %s %s.", buf, which, trapdescr);
&nbsp;        }
&nbsp;    } else {
&nbsp;        if (!mon-&gt;mtrapped)
&nbsp;            return FALSE;
&nbsp;        mon-&gt;mtrapped = 0;
&nbsp;        if (canspotmon(mon)) {
&nbsp;            *noticed = TRUE;
&nbsp;            pline("%s is released from %s %s.", Monnam(mon), which,
&nbsp;                  trapdescr);
&nbsp;        } else if (cansee(t-&gt;tx, t-&gt;ty) &amp;&amp; t-&gt;tseen) {
&nbsp;            *noticed = TRUE;
&nbsp;            if (t-&gt;ttyp == WEB)
&nbsp;                pline("%s is released from %s %s.", Something, which,
&nbsp;                      trapdescr);
&nbsp;            else /* BEAR_TRAP */
&nbsp;                pline("%s %s opens.", upstart(strcpy(buf, which)), trapdescr);
&nbsp;        }
&nbsp;        /* might pacify monster if adjacent */
&nbsp;        if (rn2(2) &amp;&amp; distu(mon-&gt;mx, mon-&gt;my) &lt;= 2)
&nbsp;            reward_untrap(t, mon);
&nbsp;    }
&nbsp;    return TRUE;
&nbsp;}
&nbsp;
closeholdingtrap
&nbsp;/* for magic locking; returns true if targetted monster (which might
&nbsp;   be hero) gets hit by a trap (might avoid actually becoming trapped) */
&nbsp;boolean
&nbsp;closeholdingtrap(mon, noticed)
&nbsp;struct monst *mon;
&nbsp;boolean *noticed; /* set to true iff hero notices the effect; */
&nbsp;{                 /* otherwise left with its previous value intact */
&nbsp;    struct trap *t;
&nbsp;    unsigned dotrapflags;
&nbsp;    boolean ishero = (mon == &amp;youmonst), result;
&nbsp;
&nbsp;    if (!mon)
&nbsp;        return FALSE;
&nbsp;    if (mon == u.usteed)
&nbsp;        ishero = TRUE;
&nbsp;    t = t_at(ishero ? u.ux : mon-&gt;mx, ishero ? u.uy : mon-&gt;my);
&nbsp;    /* if no trap here or it's not a holding trap, we're done */
&nbsp;    if (!t || (t-&gt;ttyp != BEAR_TRAP &amp;&amp; t-&gt;ttyp != WEB))
&nbsp;        return FALSE;
&nbsp;
&nbsp;    if (ishero) {
&nbsp;        if (u.utrap)
&nbsp;            return FALSE; /* already trapped */
&nbsp;        *noticed = TRUE;
&nbsp;        dotrapflags = FORCETRAP;
&nbsp;        /* dotrap calls mintrap when mounted hero encounters a web */
&nbsp;        if (u.usteed)
&nbsp;            dotrapflags |= NOWEBMSG;
&nbsp;        ++force_mintrap;
&nbsp;        dotrap(t, dotrapflags);
&nbsp;        --force_mintrap;
&nbsp;        result = (u.utrap != 0);
&nbsp;    } else {
&nbsp;        if (mon-&gt;mtrapped)
&nbsp;            return FALSE; /* already trapped */
&nbsp;        /* you notice it if you see the trap close/tremble/whatever
&nbsp;           or if you sense the monster who becomes trapped */
&nbsp;        *noticed = cansee(t-&gt;tx, t-&gt;ty) || canspotmon(mon);
&nbsp;        ++force_mintrap;
&nbsp;        result = (mintrap(mon) != 0);
&nbsp;        --force_mintrap;
&nbsp;    }
&nbsp;    return result;
&nbsp;}
&nbsp;
openfallingtrap
&nbsp;/* for magic unlocking; returns true if targetted monster (which might
&nbsp;   be hero) gets hit by a trap (target might avoid its effect) */
&nbsp;boolean
&nbsp;openfallingtrap(mon, trapdoor_only, noticed)
&nbsp;struct monst *mon;
&nbsp;boolean trapdoor_only;
&nbsp;boolean *noticed; /* set to true iff hero notices the effect; */
&nbsp;{                 /* otherwise left with its previous value intact */
&nbsp;    struct trap *t;
&nbsp;    boolean ishero = (mon == &amp;youmonst), result;
&nbsp;
&nbsp;    if (!mon)
&nbsp;        return FALSE;
&nbsp;    if (mon == u.usteed)
&nbsp;        ishero = TRUE;
&nbsp;    t = t_at(ishero ? u.ux : mon-&gt;mx, ishero ? u.uy : mon-&gt;my);
&nbsp;    /* if no trap here or it's not a falling trap, we're done
&nbsp;       (note: falling rock traps have a trapdoor in the ceiling) */
&nbsp;    if (!t || ((t-&gt;ttyp != TRAPDOOR &amp;&amp; t-&gt;ttyp != ROCKTRAP)
&nbsp;               &amp;&amp; (trapdoor_only || (t-&gt;ttyp != HOLE &amp;&amp; t-&gt;ttyp != PIT
&nbsp;                                     &amp;&amp; t-&gt;ttyp != SPIKED_PIT))))
&nbsp;        return FALSE;
&nbsp;
&nbsp;    if (ishero) {
&nbsp;        if (u.utrap)
&nbsp;            return FALSE; /* already trapped */
&nbsp;        *noticed = TRUE;
&nbsp;        dotrap(t, FORCETRAP);
&nbsp;        result = (u.utrap != 0);
&nbsp;    } else {
&nbsp;        if (mon-&gt;mtrapped)
&nbsp;            return FALSE; /* already trapped */
&nbsp;        /* you notice it if you see the trap close/tremble/whatever
&nbsp;           or if you sense the monster who becomes trapped */
&nbsp;        *noticed = cansee(t-&gt;tx, t-&gt;ty) || canspotmon(mon);
&nbsp;        /* monster will be angered; mintrap doesn't handle that */
&nbsp;        wakeup(mon, TRUE);
&nbsp;        ++force_mintrap;
&nbsp;        result = (mintrap(mon) != 0);
&nbsp;        --force_mintrap;
&nbsp;        /* mon might now be on the migrating monsters list */
&nbsp;    }
&nbsp;    return result;
&nbsp;}
&nbsp;
chest_trap
&nbsp;/* only called when the player is doing something to the chest directly */
&nbsp;boolean
&nbsp;chest_trap(obj, bodypart, disarm)
&nbsp;register struct obj *obj;
&nbsp;register int bodypart;
&nbsp;boolean disarm;
&nbsp;{
&nbsp;    register struct obj *otmp = obj, *otmp2;
&nbsp;    char buf[80];
&nbsp;    const char *msg;
&nbsp;    coord cc;
&nbsp;
&nbsp;    if (get_obj_location(obj, &amp;cc.x, &amp;cc.y, 0)) /* might be carried */
&nbsp;        obj-&gt;ox = cc.x, obj-&gt;oy = cc.y;
&nbsp;
&nbsp;    otmp-&gt;otrapped = 0; /* trap is one-shot; clear flag first in case
&nbsp;                           chest kills you and ends up in bones file */
&nbsp;    You(disarm ? "set it off!" : "trigger a trap!");
&nbsp;    display_nhwindow(WIN_MESSAGE, FALSE);
&nbsp;    if (Luck &gt; -13 &amp;&amp; rn2(13 + Luck) &gt; 7) { /* saved by luck */
&nbsp;        /* trap went off, but good luck prevents damage */
&nbsp;        switch (rn2(13)) {
&nbsp;        case 12:
&nbsp;        case 11:
&nbsp;            msg = "explosive charge is a dud";
&nbsp;            break;
&nbsp;        case 10:
&nbsp;        case 9:
&nbsp;            msg = "electric charge is grounded";
&nbsp;            break;
&nbsp;        case 8:
&nbsp;        case 7:
&nbsp;            msg = "flame fizzles out";
&nbsp;            break;
&nbsp;        case 6:
&nbsp;        case 5:
&nbsp;        case 4:
&nbsp;            msg = "poisoned needle misses";
&nbsp;            break;
&nbsp;        case 3:
&nbsp;        case 2:
&nbsp;        case 1:
&nbsp;        case 0:
&nbsp;            msg = "gas cloud blows away";
&nbsp;            break;
&nbsp;        default:
&nbsp;            impossible("chest disarm bug");
&nbsp;            msg = (char *) 0;
&nbsp;            break;
&nbsp;        }
&nbsp;        if (msg)
&nbsp;            pline("But luckily the %s!", msg);
&nbsp;    } else {
&nbsp;        switch (rn2(20) ? ((Luck &gt;= 13) ? 0 : rn2(13 - Luck)) : rn2(26)) {
&nbsp;        case 25:
&nbsp;        case 24:
&nbsp;        case 23:
&nbsp;        case 22:
&nbsp;        case 21: {
&nbsp;            struct monst *shkp = 0;
&nbsp;            long loss = 0L;
&nbsp;            boolean costly, insider;
&nbsp;            register xchar ox = obj-&gt;ox, oy = obj-&gt;oy;
&nbsp;
&nbsp;            /* the obj location need not be that of player */
&nbsp;            costly = (costly_spot(ox, oy)
&nbsp;                      &amp;&amp; (shkp = shop_keeper(*in_rooms(ox, oy, SHOPBASE)))
&nbsp;                             != (struct monst *) 0);
&nbsp;            insider = (*u.ushops &amp;&amp; inside_shop(u.ux, u.uy)
&nbsp;                       &amp;&amp; *in_rooms(ox, oy, SHOPBASE) == *u.ushops);
&nbsp;
&nbsp;            pline("%s!", Tobjnam(obj, "explode"));
&nbsp;            Sprintf(buf, "exploding %s", xname(obj));
&nbsp;
&nbsp;            if (costly)
&nbsp;                loss += stolen_value(obj, ox, oy, (boolean) shkp-&gt;mpeaceful,
&nbsp;                                     TRUE);
&nbsp;            delete_contents(obj);
&nbsp;            /* unpunish() in advance if either ball or chain (or both)
&nbsp;               is going to be destroyed */
&nbsp;            if (Punished &amp;&amp; ((uchain-&gt;ox == u.ux &amp;&amp; uchain-&gt;oy == u.uy)
&nbsp;                             || (uball-&gt;where == OBJ_FLOOR
&nbsp;                                 &amp;&amp; uball-&gt;ox == u.ux &amp;&amp; uball-&gt;oy == u.uy)))
&nbsp;                unpunish();
&nbsp;
&nbsp;            for (otmp = level.objects[u.ux][u.uy]; otmp; otmp = otmp2) {
&nbsp;                otmp2 = otmp-&gt;nexthere;
&nbsp;                if (costly)
&nbsp;                    loss += stolen_value(otmp, otmp-&gt;ox, otmp-&gt;oy,
&nbsp;                                         (boolean) shkp-&gt;mpeaceful, TRUE);
&nbsp;                delobj(otmp);
&nbsp;            }
&nbsp;            wake_nearby();
&nbsp;            losehp(Maybe_Half_Phys(d(6, 6)), buf, KILLED_BY_AN);
&nbsp;            exercise(A_STR, FALSE);
&nbsp;            if (costly &amp;&amp; loss) {
&nbsp;                if (insider)
&nbsp;                    You("owe %ld %s for objects destroyed.", loss,
&nbsp;                        currency(loss));
&nbsp;                else {
&nbsp;                    You("caused %ld %s worth of damage!", loss,
&nbsp;                        currency(loss));
&nbsp;                    make_angry_shk(shkp, ox, oy);
&nbsp;                }
&nbsp;            }
&nbsp;            return TRUE;
&nbsp;        } /* case 21 */
&nbsp;        case 20:
&nbsp;        case 19:
&nbsp;        case 18:
&nbsp;        case 17:
&nbsp;            pline("A cloud of noxious gas billows from %s.", the(xname(obj)));
&nbsp;            poisoned("gas cloud", A_STR, "cloud of poison gas", 15, FALSE);
&nbsp;            exercise(A_CON, FALSE);
&nbsp;            break;
&nbsp;        case 16:
&nbsp;        case 15:
&nbsp;        case 14:
&nbsp;        case 13:
&nbsp;            You_feel("a needle prick your %s.", body_part(bodypart));
&nbsp;            poisoned("needle", A_CON, "poisoned needle", 10, FALSE);
&nbsp;            exercise(A_CON, FALSE);
&nbsp;            break;
&nbsp;        case 12:
&nbsp;        case 11:
&nbsp;        case 10:
&nbsp;        case 9:
&nbsp;            dofiretrap(obj);
&nbsp;            break;
&nbsp;        case 8:
&nbsp;        case 7:
&nbsp;        case 6: {
&nbsp;            int dmg;
&nbsp;
&nbsp;            You("are jolted by a surge of electricity!");
&nbsp;            if (Shock_resistance) {
&nbsp;                shieldeff(u.ux, u.uy);
&nbsp;                You("don't seem to be affected.");
&nbsp;                dmg = 0;
&nbsp;            } else
&nbsp;                dmg = d(4, 4);
&nbsp;            destroy_item(RING_CLASS, AD_ELEC);
&nbsp;            destroy_item(WAND_CLASS, AD_ELEC);
&nbsp;            if (dmg)
&nbsp;                losehp(dmg, "electric shock", KILLED_BY_AN);
&nbsp;            break;
&nbsp;        } /* case 6 */
&nbsp;        case 5:
&nbsp;        case 4:
&nbsp;        case 3:
&nbsp;            if (!Free_action) {
&nbsp;                pline("Suddenly you are frozen in place!");
&nbsp;                nomul(-d(5, 6));
&nbsp;                multi_reason = "frozen by a trap";
&nbsp;                exercise(A_DEX, FALSE);
&nbsp;                nomovemsg = You_can_move_again;
&nbsp;            } else
&nbsp;                You("momentarily stiffen.");
&nbsp;            break;
&nbsp;        case 2:
&nbsp;        case 1:
&nbsp;        case 0:
&nbsp;            pline("A cloud of %s gas billows from %s.",
&nbsp;                  Blind ? blindgas[rn2(SIZE(blindgas))] : rndcolor(),
&nbsp;                  the(xname(obj)));
&nbsp;            if (!Stunned) {
&nbsp;                if (Hallucination)
&nbsp;                    pline("What a groovy feeling!");
&nbsp;                else
&nbsp;                    You("%s%s...", stagger(youmonst.data, "stagger"),
&nbsp;                        Halluc_resistance ? ""
&nbsp;                                          : Blind ? " and get dizzy"
&nbsp;                                                  : " and your vision blurs");
&nbsp;            }
&nbsp;            make_stunned((HStun &amp; TIMEOUT) + (long) rn1(7, 16), FALSE);
&nbsp;            (void) make_hallucinated(
&nbsp;                (HHallucination &amp; TIMEOUT) + (long) rn1(5, 16), FALSE, 0L);
&nbsp;            break;
&nbsp;        default:
&nbsp;            impossible("bad chest trap");
&nbsp;            break;
&nbsp;        }
&nbsp;        bot(); /* to get immediate botl re-display */
&nbsp;    }
&nbsp;
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
t_at
&nbsp;struct trap *
&nbsp;t_at(x, y)
&nbsp;register int x, y;
&nbsp;{
&nbsp;    register struct trap *trap = ftrap;
&nbsp;
&nbsp;    while (trap) {
&nbsp;        if (trap-&gt;tx == x &amp;&amp; trap-&gt;ty == y)
&nbsp;            return trap;
&nbsp;        trap = trap-&gt;ntrap;
&nbsp;    }
&nbsp;    return (struct trap *) 0;
&nbsp;}
&nbsp;
deltrap
&nbsp;void
&nbsp;deltrap(trap)
&nbsp;register struct trap *trap;
&nbsp;{
&nbsp;    register struct trap *ttmp;
&nbsp;
&nbsp;    clear_conjoined_pits(trap);
&nbsp;    if (trap == ftrap) {
&nbsp;        ftrap = ftrap-&gt;ntrap;
&nbsp;    } else {
&nbsp;        for (ttmp = ftrap; ttmp; ttmp = ttmp-&gt;ntrap)
&nbsp;            if (ttmp-&gt;ntrap == trap)
&nbsp;                break;
&nbsp;        if (!ttmp)
&nbsp;            panic("deltrap: no preceding trap!");
&nbsp;        ttmp-&gt;ntrap = trap-&gt;ntrap;
&nbsp;    }
&nbsp;    if (Sokoban &amp;&amp; (trap-&gt;ttyp == PIT || trap-&gt;ttyp == HOLE))
&nbsp;        maybe_finish_sokoban();
&nbsp;    dealloc_trap(trap);
&nbsp;}
&nbsp;
conjoined_pits
&nbsp;boolean
&nbsp;conjoined_pits(trap2, trap1, u_entering_trap2)
&nbsp;struct trap *trap2, *trap1;
&nbsp;boolean u_entering_trap2;
&nbsp;{
&nbsp;    int dx, dy, diridx, adjidx;
&nbsp;
&nbsp;    if (!trap1 || !trap2)
&nbsp;        return FALSE;
&nbsp;    if (!isok(trap2-&gt;tx, trap2-&gt;ty) || !isok(trap1-&gt;tx, trap1-&gt;ty)
&nbsp;        || !(trap2-&gt;ttyp == PIT || trap2-&gt;ttyp == SPIKED_PIT)
&nbsp;        || !(trap1-&gt;ttyp == PIT || trap1-&gt;ttyp == SPIKED_PIT)
&nbsp;        || (u_entering_trap2 &amp;&amp; !(u.utrap &amp;&amp; u.utraptype == TT_PIT)))
&nbsp;        return FALSE;
&nbsp;    dx = sgn(trap2-&gt;tx - trap1-&gt;tx);
&nbsp;    dy = sgn(trap2-&gt;ty - trap1-&gt;ty);
&nbsp;    for (diridx = 0; diridx &lt; 8; diridx++)
&nbsp;        if (xdir[diridx] == dx &amp;&amp; ydir[diridx] == dy)
&nbsp;            break;
&nbsp;    /* diridx is valid if &lt; 8 */
&nbsp;    if (diridx &lt; 8) {
&nbsp;        adjidx = (diridx + 4) % 8;
&nbsp;        if ((trap1-&gt;conjoined &amp; (1 &lt;&lt; diridx))
&nbsp;            &amp;&amp; (trap2-&gt;conjoined &amp; (1 &lt;&lt; adjidx)))
&nbsp;            return TRUE;
&nbsp;    }
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
clear_conjoined_pits
&nbsp;void
&nbsp;clear_conjoined_pits(trap)
&nbsp;struct trap *trap;
&nbsp;{
&nbsp;    int diridx, adjidx, x, y;
&nbsp;    struct trap *t;
&nbsp;
&nbsp;    if (trap &amp;&amp; (trap-&gt;ttyp == PIT || trap-&gt;ttyp == SPIKED_PIT)) {
&nbsp;        for (diridx = 0; diridx &lt; 8; ++diridx) {
&nbsp;            if (trap-&gt;conjoined &amp; (1 &lt;&lt; diridx)) {
&nbsp;                x = trap-&gt;tx + xdir[diridx];
&nbsp;                y = trap-&gt;ty + ydir[diridx];
&nbsp;                if (isok(x, y)
&nbsp;                    &amp;&amp; (t = t_at(x, y)) != 0
&nbsp;                    &amp;&amp; (t-&gt;ttyp == PIT || t-&gt;ttyp == SPIKED_PIT)) {
&nbsp;                    adjidx = (diridx + 4) % 8;
&nbsp;                    t-&gt;conjoined &amp;= ~(1 &lt;&lt; adjidx);
&nbsp;                }
&nbsp;                trap-&gt;conjoined &amp;= ~(1 &lt;&lt; diridx);
&nbsp;            }
&nbsp;        }
&nbsp;    }
&nbsp;}
&nbsp;
adj_nonconjoined_pit
&nbsp;boolean
&nbsp;adj_nonconjoined_pit(adjtrap)
&nbsp;struct trap *adjtrap;
&nbsp;{
&nbsp;    struct trap *trap_with_u = t_at(u.ux0, u.uy0);
&nbsp;
&nbsp;    if (trap_with_u &amp;&amp; adjtrap &amp;&amp; u.utrap &amp;&amp; u.utraptype == TT_PIT &amp;&amp;
&nbsp;        (trap_with_u-&gt;ttyp == PIT || trap_with_u-&gt;ttyp == SPIKED_PIT) &amp;&amp;
&nbsp;        (adjtrap-&gt;ttyp == PIT || adjtrap-&gt;ttyp == SPIKED_PIT)) {
&nbsp;        int idx;
&nbsp;        for (idx = 0; idx &lt; 8; idx++) {
&nbsp;            if (xdir[idx] == u.dx &amp;&amp; ydir[idx] == u.dy)
&nbsp;                return TRUE;
&nbsp;        }
&nbsp;    }
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
&nbsp;#if 0
&nbsp;/*
&nbsp; * Mark all neighboring pits as conjoined pits.
&nbsp; * (currently not called from anywhere)
&nbsp; */
&nbsp;STATIC_OVL void
&nbsp;join_adjacent_pits(trap)
&nbsp;struct trap *trap;
&nbsp;{
&nbsp;    struct trap *t;
&nbsp;    int diridx, x, y;
&nbsp;
&nbsp;    if (!trap)
&nbsp;        return;
&nbsp;    for (diridx = 0; diridx &lt; 8; ++diridx) {
&nbsp;        x = trap-&gt;tx + xdir[diridx];
&nbsp;        y = trap-&gt;ty + ydir[diridx];
&nbsp;        if (isok(x, y)) {
&nbsp;            if ((t = t_at(x, y)) != 0
&nbsp;                &amp;&amp; (t-&gt;ttyp == PIT || t-&gt;ttyp == SPIKED_PIT)) {
&nbsp;                trap-&gt;conjoined |= (1 &lt;&lt; diridx);
&nbsp;                join_adjacent_pits(t);
&nbsp;            } else
&nbsp;                trap-&gt;conjoined &amp;= ~(1 &lt;&lt; diridx);
&nbsp;        }
&nbsp;    }
&nbsp;}
&nbsp;#endif /*0*/
&nbsp;
uteetering_at_seen_pit
&nbsp;/*
&nbsp; * Returns TRUE if you escaped a pit and are standing on the precipice.
&nbsp; */
&nbsp;boolean
&nbsp;uteetering_at_seen_pit(trap)
&nbsp;struct trap *trap;
&nbsp;{
&nbsp;    if (trap &amp;&amp; trap-&gt;tseen &amp;&amp; (!u.utrap || u.utraptype != TT_PIT)
&nbsp;        &amp;&amp; (trap-&gt;ttyp == PIT || trap-&gt;ttyp == SPIKED_PIT))
&nbsp;        return TRUE;
&nbsp;    else
&nbsp;        return FALSE;
&nbsp;}
&nbsp;
delfloortrap
&nbsp;/* Destroy a trap that emanates from the floor. */
&nbsp;boolean
&nbsp;delfloortrap(ttmp)
&nbsp;register struct trap *ttmp;
&nbsp;{
&nbsp;    /* some of these are arbitrary -dlc */
&nbsp;    if (ttmp &amp;&amp; ((ttmp-&gt;ttyp == SQKY_BOARD) || (ttmp-&gt;ttyp == BEAR_TRAP)
&nbsp;                 || (ttmp-&gt;ttyp == LANDMINE) || (ttmp-&gt;ttyp == FIRE_TRAP)
&nbsp;                 || (ttmp-&gt;ttyp == PIT) || (ttmp-&gt;ttyp == SPIKED_PIT)
&nbsp;                 || (ttmp-&gt;ttyp == HOLE) || (ttmp-&gt;ttyp == TRAPDOOR)
&nbsp;                 || (ttmp-&gt;ttyp == TELEP_TRAP) || (ttmp-&gt;ttyp == LEVEL_TELEP)
&nbsp;                 || (ttmp-&gt;ttyp == WEB) || (ttmp-&gt;ttyp == MAGIC_TRAP)
&nbsp;                 || (ttmp-&gt;ttyp == ANTI_MAGIC))) {
&nbsp;        register struct monst *mtmp;
&nbsp;
&nbsp;        if (ttmp-&gt;tx == u.ux &amp;&amp; ttmp-&gt;ty == u.uy) {
&nbsp;            u.utrap = 0;
&nbsp;            u.utraptype = 0;
&nbsp;        } else if ((mtmp = m_at(ttmp-&gt;tx, ttmp-&gt;ty)) != 0) {
&nbsp;            mtmp-&gt;mtrapped = 0;
&nbsp;        }
&nbsp;        deltrap(ttmp);
&nbsp;        return TRUE;
&nbsp;    }
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
b_trapped
&nbsp;/* used for doors (also tins).  can be used for anything else that opens. */
&nbsp;void
&nbsp;b_trapped(item, bodypart)
&nbsp;const char *item;
&nbsp;int bodypart;
&nbsp;{
&nbsp;    int lvl = level_difficulty(),
&nbsp;        dmg = rnd(5 + (lvl &lt; 5 ? lvl : 2 + lvl / 2));
&nbsp;
&nbsp;    pline("KABOOM!!  %s was booby-trapped!", The(item));
&nbsp;    wake_nearby();
&nbsp;    losehp(Maybe_Half_Phys(dmg), "explosion", KILLED_BY_AN);
&nbsp;    exercise(A_STR, FALSE);
&nbsp;    if (bodypart)
&nbsp;        exercise(A_CON, FALSE);
&nbsp;    make_stunned((HStun &amp; TIMEOUT) + (long) dmg, TRUE);
&nbsp;}
&nbsp;
thitm
&nbsp;/* Monster is hit by trap. */
&nbsp;/* Note: doesn't work if both obj and d_override are null */
&nbsp;STATIC_OVL boolean
&nbsp;thitm(tlev, mon, obj, d_override, nocorpse)
&nbsp;int tlev;
&nbsp;struct monst *mon;
&nbsp;struct obj *obj;
&nbsp;int d_override;
&nbsp;boolean nocorpse;
&nbsp;{
&nbsp;    int strike;
&nbsp;    boolean trapkilled = FALSE;
&nbsp;
&nbsp;    if (d_override)
&nbsp;        strike = 1;
&nbsp;    else if (obj)
&nbsp;        strike = (find_mac(mon) + tlev + obj-&gt;spe &lt;= rnd(20));
&nbsp;    else
&nbsp;        strike = (find_mac(mon) + tlev &lt;= rnd(20));
&nbsp;
&nbsp;    /* Actually more accurate than thitu, which doesn't take
&nbsp;     * obj-&gt;spe into account.
&nbsp;     */
&nbsp;    if (!strike) {
&nbsp;        if (obj &amp;&amp; cansee(mon-&gt;mx, mon-&gt;my))
&nbsp;            pline("%s is almost hit by %s!", Monnam(mon), doname(obj));
&nbsp;    } else {
&nbsp;        int dam = 1;
&nbsp;
&nbsp;        if (obj &amp;&amp; cansee(mon-&gt;mx, mon-&gt;my))
&nbsp;            pline("%s is hit by %s!", Monnam(mon), doname(obj));
&nbsp;        if (d_override)
&nbsp;            dam = d_override;
&nbsp;        else if (obj) {
&nbsp;            dam = dmgval(obj, mon);
&nbsp;            if (dam &lt; 1)
&nbsp;                dam = 1;
&nbsp;        }
&nbsp;        mon-&gt;mhp -= dam;
&nbsp;        if (mon-&gt;mhp &lt;= 0) {
&nbsp;            int xx = mon-&gt;mx, yy = mon-&gt;my;
&nbsp;
&nbsp;            monkilled(mon, "", nocorpse ? -AD_RBRE : AD_PHYS);
&nbsp;            if (mon-&gt;mhp &lt;= 0) {
&nbsp;                newsym(xx, yy);
&nbsp;                trapkilled = TRUE;
&nbsp;            }
&nbsp;        }
&nbsp;    }
&nbsp;    if (obj &amp;&amp; (!strike || d_override)) {
&nbsp;        place_object(obj, mon-&gt;mx, mon-&gt;my);
&nbsp;        stackobj(obj);
&nbsp;    } else if (obj)
&nbsp;        dealloc_obj(obj);
&nbsp;
&nbsp;    return trapkilled;
&nbsp;}
&nbsp;
unconscious
&nbsp;boolean
&nbsp;unconscious()
&nbsp;{
&nbsp;    if (multi &gt;= 0)
&nbsp;        return FALSE;
&nbsp;
&nbsp;    return (boolean) (u.usleep
&nbsp;                      || (nomovemsg
&nbsp;                          &amp;&amp; (!strncmp(nomovemsg, "You awake", 9)
&nbsp;                              || !strncmp(nomovemsg, "You regain con", 14)
&nbsp;                              || !strncmp(nomovemsg, "You are consci", 14))));
&nbsp;}
&nbsp;
&nbsp;static const char lava_killer[] = "molten lava";
&nbsp;
lava_effects
&nbsp;boolean
&nbsp;lava_effects()
&nbsp;{
&nbsp;    register struct obj *obj, *obj2;
&nbsp;    int dmg = d(6, 6); /* only applicable for water walking */
&nbsp;    boolean usurvive, boil_away;
&nbsp;
&nbsp;    burn_away_slime();
&nbsp;    if (likes_lava(youmonst.data))
&nbsp;        return FALSE;
&nbsp;
&nbsp;    usurvive = Fire_resistance || (Wwalking &amp;&amp; dmg &lt; u.uhp);
&nbsp;    /*
&nbsp;     * A timely interrupt might manage to salvage your life
&nbsp;     * but not your gear.  For scrolls and potions this
&nbsp;     * will destroy whole stacks, where fire resistant hero
&nbsp;     * survivor only loses partial stacks via destroy_item().
&nbsp;     *
&nbsp;     * Flag items to be destroyed before any messages so
&nbsp;     * that player causing hangup at --More-- won't get an
&nbsp;     * emergency save file created before item destruction.
&nbsp;     */
&nbsp;    if (!usurvive)
&nbsp;        for (obj = invent; obj; obj = obj-&gt;nobj)
&nbsp;            if ((is_organic(obj) || obj-&gt;oclass == POTION_CLASS)
&nbsp;                &amp;&amp; !obj-&gt;oerodeproof
&nbsp;                &amp;&amp; objects[obj-&gt;otyp].oc_oprop != FIRE_RES
&nbsp;                &amp;&amp; obj-&gt;otyp != SCR_FIRE &amp;&amp; obj-&gt;otyp != SPE_FIREBALL
&nbsp;                &amp;&amp; !obj_resists(obj, 0, 0)) /* for invocation items */
&nbsp;                obj-&gt;in_use = 1;
&nbsp;
&nbsp;    /* Check whether we should burn away boots *first* so we know whether to
&nbsp;     * make the player sink into the lava. Assumption: water walking only
&nbsp;     * comes from boots.
&nbsp;     */
&nbsp;    if (uarmf &amp;&amp; is_organic(uarmf) &amp;&amp; !uarmf-&gt;oerodeproof) {
&nbsp;        obj = uarmf;
&nbsp;        pline("%s into flame!", Yobjnam2(obj, "burst"));
&nbsp;        iflags.in_lava_effects++; /* (see above) */
&nbsp;        (void) Boots_off();
&nbsp;        useup(obj);
&nbsp;        iflags.in_lava_effects--;
&nbsp;    }
&nbsp;
&nbsp;    if (!Fire_resistance) {
&nbsp;        if (Wwalking) {
&nbsp;            pline_The("%s here burns you!", hliquid("lava"));
&nbsp;            if (usurvive) {
&nbsp;                losehp(dmg, lava_killer, KILLED_BY); /* lava damage */
&nbsp;                goto burn_stuff;
&nbsp;            }
&nbsp;        } else
&nbsp;            You("fall into the %s!", hliquid("lava"));
&nbsp;
&nbsp;        usurvive = Lifesaved || discover;
&nbsp;        if (wizard)
&nbsp;            usurvive = TRUE;
&nbsp;
&nbsp;        /* prevent remove_worn_item() -&gt; Boots_off(WATER_WALKING_BOOTS) -&gt;
&nbsp;           spoteffects() -&gt; lava_effects() recursion which would
&nbsp;           successfully delete (via useupall) the no-longer-worn boots;
&nbsp;           once recursive call returned, we would try to delete them again
&nbsp;           here in the outer call (and access stale memory, probably panic) */
&nbsp;        iflags.in_lava_effects++;
&nbsp;
&nbsp;        for (obj = invent; obj; obj = obj2) {
&nbsp;            obj2 = obj-&gt;nobj;
&nbsp;            /* above, we set in_use for objects which are to be destroyed */
&nbsp;            if (obj-&gt;otyp == SPE_BOOK_OF_THE_DEAD &amp;&amp; !Blind) {
&nbsp;                if (usurvive)
&nbsp;                    pline("%s glows a strange %s, but remains intact.",
&nbsp;                          The(xname(obj)), hcolor("dark red"));
&nbsp;            } else if (obj-&gt;in_use) {
&nbsp;                if (obj-&gt;owornmask) {
&nbsp;                    if (usurvive)
&nbsp;                        pline("%s into flame!", Yobjnam2(obj, "burst"));
&nbsp;                    remove_worn_item(obj, TRUE);
&nbsp;                }
&nbsp;                useupall(obj);
&nbsp;            }
&nbsp;        }
&nbsp;
&nbsp;        iflags.in_lava_effects--;
&nbsp;
&nbsp;        /* s/he died... */
&nbsp;        boil_away = (u.umonnum == PM_WATER_ELEMENTAL
&nbsp;                     || u.umonnum == PM_STEAM_VORTEX
&nbsp;                     || u.umonnum == PM_FOG_CLOUD);
&nbsp;        for (;;) {
&nbsp;            u.uhp = -1;
&nbsp;            /* killer format and name are reconstructed every iteration
&nbsp;               because lifesaving resets them */
&nbsp;            killer.format = KILLED_BY;
&nbsp;            Strcpy(killer.name, lava_killer);
&nbsp;            You("%s...", boil_away ? "boil away" : "burn to a crisp");
&nbsp;            done(BURNING);
&nbsp;            if (safe_teleds(TRUE))
&nbsp;                break; /* successful life-save */
&nbsp;            /* nowhere safe to land; repeat burning loop */
&nbsp;            pline("You're still burning.");
&nbsp;        }
&nbsp;        You("find yourself back on solid %s.", surface(u.ux, u.uy));
&nbsp;        return TRUE;
&nbsp;    } else if (!Wwalking &amp;&amp; (!u.utrap || u.utraptype != TT_LAVA)) {
&nbsp;        boil_away = !Fire_resistance;
&nbsp;        /* if not fire resistant, sink_into_lava() will quickly be fatal;
&nbsp;           hero needs to escape immediately */
&nbsp;        u.utrap = rn1(4, 4) + ((boil_away ? 2 : rn1(4, 12)) &lt;&lt; 8);
&nbsp;        u.utraptype = TT_LAVA;
&nbsp;        You("sink into the %s%s!", hliquid("lava"),
&nbsp;            !boil_away
&nbsp;            ? ", but it only burns slightly"
&nbsp;            : " and are about to be immolated");
&nbsp;        if (u.uhp &gt; 1)
&nbsp;            losehp(!boil_away ? 1 : (u.uhp / 2), lava_killer,
&nbsp;                   KILLED_BY); /* lava damage */
&nbsp;    }
&nbsp;
&nbsp;burn_stuff:
&nbsp;    destroy_item(SCROLL_CLASS, AD_FIRE);
&nbsp;    destroy_item(SPBOOK_CLASS, AD_FIRE);
&nbsp;    destroy_item(POTION_CLASS, AD_FIRE);
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
sink_into_lava
&nbsp;/* called each turn when trapped in lava */
&nbsp;void
&nbsp;sink_into_lava()
&nbsp;{
&nbsp;    static const char sink_deeper[] = "You sink deeper into the lava.";
&nbsp;
&nbsp;    if (!u.utrap || u.utraptype != TT_LAVA) {
&nbsp;        ; /* do nothing; this shouldn't happen */
&nbsp;    } else if (!is_lava(u.ux, u.uy)) {
&nbsp;        u.utrap = 0; /* this shouldn't happen either */
&nbsp;    } else if (!u.uinvulnerable) {
&nbsp;        /* ordinarily we'd have to be fire resistant to survive long
&nbsp;           enough to become stuck in lava, but it can happen without
&nbsp;           resistance if water walking boots allow survival and then
&nbsp;           get burned up; u.utrap time will be quite short in that case */
&nbsp;        if (!Fire_resistance)
&nbsp;            u.uhp = (u.uhp + 2) / 3;
&nbsp;
&nbsp;        u.utrap -= (1 &lt;&lt; 8);
&nbsp;        if (u.utrap &lt; (1 &lt;&lt; 8)) {
&nbsp;            killer.format = KILLED_BY;
&nbsp;            Strcpy(killer.name, "molten lava");
&nbsp;            You("sink below the surface and die.");
&nbsp;            burn_away_slime(); /* add insult to injury? */
&nbsp;            done(DISSOLVED);
&nbsp;            /* can only get here via life-saving; try to get away from lava */
&nbsp;            u.utrap = 0;
&nbsp;            (void) safe_teleds(TRUE);
&nbsp;        } else if (!u.umoved) {
&nbsp;            /* can't fully turn into slime while in lava, but might not
&nbsp;               have it be burned away until you've come awfully close */
&nbsp;            if (Slimed &amp;&amp; rnd(10 - 1) &gt;= (int) (Slimed &amp; TIMEOUT)) {
&nbsp;                pline(sink_deeper);
&nbsp;                burn_away_slime();
&nbsp;            } else {
&nbsp;                Norep(sink_deeper);
&nbsp;            }
&nbsp;            u.utrap += rnd(4);
&nbsp;        }
&nbsp;    }
&nbsp;}
&nbsp;
sokoban_guilt
&nbsp;/* called when something has been done (breaking a boulder, for instance)
&nbsp;   which entails a luck penalty if performed on a sokoban level */
&nbsp;void
&nbsp;sokoban_guilt()
&nbsp;{
&nbsp;    if (Sokoban) {
&nbsp;        change_luck(-1);
&nbsp;        /* TODO: issue some feedback so that player can learn that whatever
&nbsp;           he/she just did is a naughty thing to do in sokoban and should
&nbsp;           probably be avoided in future....
&nbsp;           Caveat: doing this might introduce message sequencing issues,
&nbsp;           depending upon feedback during the various actions which trigger
&nbsp;           Sokoban luck penalties. */
&nbsp;    }
&nbsp;}
&nbsp;
maybe_finish_sokoban
&nbsp;/* called when a trap has been deleted or had its ttyp replaced */
&nbsp;STATIC_OVL void
&nbsp;maybe_finish_sokoban()
&nbsp;{
&nbsp;    struct trap *t;
&nbsp;
&nbsp;    if (Sokoban &amp;&amp; !in_mklev) {
&nbsp;        /* scan all remaining traps, ignoring any created by the hero;
&nbsp;           if this level has no more pits or holes, the current sokoban
&nbsp;           puzzle has been solved */
&nbsp;        for (t = ftrap; t; t = t-&gt;ntrap) {
&nbsp;            if (t-&gt;madeby_u)
&nbsp;                continue;
&nbsp;            if (t-&gt;ttyp == PIT || t-&gt;ttyp == HOLE)
&nbsp;                break;
&nbsp;        }
&nbsp;        if (!t) {
&nbsp;            /* we've passed the last trap without finding a pit or hole;
&nbsp;               clear the sokoban_rules flag so that luck penalties for
&nbsp;               things like breaking boulders or jumping will no longer
&nbsp;               be given, and restrictions on diagonal moves are lifted */
&nbsp;            Sokoban = 0; /* clear level.flags.sokoban_rules */
&nbsp;            /* TODO: give some feedback about solving the sokoban puzzle
&nbsp;               (perhaps say "congratulations" in Japanese?) */
&nbsp;        }
&nbsp;    }
&nbsp;}
&nbsp;
&nbsp;/*trap.c*/

</trap></color></color></mon></tx,ty></tx,ty>