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

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.

Contents

1 Top of file
2 dodrop
3 boulder_hits_pool
4 flooreffects
5 doaltarobj
6 trycall
7 polymorph_sink
8 teleport_sink
9 dosinkring
10 canletgo
11 drop
12 dropx
13 dropy
14 dropz
15 obj_no_longer_held
16 doddrop
17 menu_drop
18 dodown
19 doup
20 currentlevel_rewrite
21 save_currentstate
22 goto_level
23 final_level
24 schedule_goto
25 deferred_goto
26 revive_corpse
27 revive_mon
28 donull
29 wipeoff
30 dowipe
31 set_wounded_legs
32 heal_legs

Top of file
&nbsp;/* NetHack 3.6	do.c	$NHDT-Date: 1446975464 2015/11/08 09:37:44 $  $NHDT-Branch: master $:$NHDT-Revision: 1.149 $ */
&nbsp;/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
&nbsp;/* NetHack may be freely redistributed.  See license for details. */
&nbsp;
&nbsp;/* Contains code for 'd', 'D' (drop), '&gt;', '&lt;' (up, down) */
&nbsp;
&nbsp;#include "hack.h"
&nbsp;#include "lev.h"
&nbsp;
&nbsp;STATIC_DCL void FDECL(trycall, (struct obj *));
&nbsp;STATIC_DCL void NDECL(polymorph_sink);
&nbsp;STATIC_DCL boolean NDECL(teleport_sink);
&nbsp;STATIC_DCL void FDECL(dosinkring, (struct obj *));
&nbsp;STATIC_PTR int FDECL(drop, (struct obj *));
&nbsp;STATIC_PTR int NDECL(wipeoff);
&nbsp;STATIC_DCL int FDECL(menu_drop, (int));
&nbsp;STATIC_DCL int NDECL(currentlevel_rewrite);
&nbsp;STATIC_DCL void NDECL(final_level);
&nbsp;/* static boolean FDECL(badspot, (XCHAR_P,XCHAR_P)); */
&nbsp;
&nbsp;extern int n_dgns; /* number of dungeons, from dungeon.c */
&nbsp;
&nbsp;static NEARDATA const char drop_types[] = { ALLOW_COUNT, COIN_CLASS,
&nbsp;                                            ALL_CLASSES, 0 };
&nbsp;
dodrop
&nbsp;/* 'd' command: drop one inventory item */
&nbsp;int
&nbsp;dodrop()
&nbsp;{
&nbsp;    int result, i = (invent) ? 0 : (SIZE(drop_types) - 1);
&nbsp;
&nbsp;    if (*u.ushops)
&nbsp;        sellobj_state(SELL_DELIBERATE);
&nbsp;    result = drop(getobj(&amp;drop_types[i], "drop"));
&nbsp;    if (*u.ushops)
&nbsp;        sellobj_state(SELL_NORMAL);
&nbsp;    reset_occupations();
&nbsp;
&nbsp;    return result;
&nbsp;}
&nbsp;
boulder_hits_pool
&nbsp;/* Called when a boulder is dropped, thrown, or pushed.  If it ends up
&nbsp; * in a pool, it either fills the pool up or sinks away.  In either case,
&nbsp; * it's gone for good...  If the destination is not a pool, returns FALSE.
&nbsp; */
&nbsp;boolean
&nbsp;boulder_hits_pool(otmp, rx, ry, pushing)
&nbsp;struct obj *otmp;
&nbsp;register int rx, ry;
&nbsp;boolean pushing;
&nbsp;{
&nbsp;    if (!otmp || otmp-&gt;otyp != BOULDER) {
&nbsp;        impossible("Not a boulder?");
&nbsp;    } else if (!Is_waterlevel(&amp;u.uz) &amp;&amp; is_pool_or_lava(rx, ry)) {
&nbsp;        boolean lava = is_lava(rx, ry), fills_up;
&nbsp;        const char *what = waterbody_name(rx, ry);
&nbsp;        schar ltyp = levl[rx][ry].typ;
&nbsp;        int chance = rn2(10); /* water: 90%; lava: 10% */
&nbsp;        fills_up = lava ? chance == 0 : chance != 0;
&nbsp;
&nbsp;        if (fills_up) {
&nbsp;            struct trap *ttmp = t_at(rx, ry);
&nbsp;
&nbsp;            if (ltyp == DRAWBRIDGE_UP) {
&nbsp;                levl[rx][ry].drawbridgemask &amp;= ~DB_UNDER; /* clear lava */
&nbsp;                levl[rx][ry].drawbridgemask |= DB_FLOOR;
&nbsp;            } else
&nbsp;                levl[rx][ry].typ = ROOM;
&nbsp;
&nbsp;            if (ttmp)
&nbsp;                (void) delfloortrap(ttmp);
&nbsp;            bury_objs(rx, ry);
&nbsp;
&nbsp;            newsym(rx, ry);
&nbsp;            if (pushing) {
&nbsp;                char whobuf[BUFSZ];
&nbsp;
&nbsp;                Strcpy(whobuf, "you");
&nbsp;                if (u.usteed)
&nbsp;                    Strcpy(whobuf, y_monnam(u.usteed));
&nbsp;                pline("%s %s %s into the %s.", upstart(whobuf),
&nbsp;                      vtense(whobuf, "push"), the(xname(otmp)), what);
&nbsp;                if (flags.verbose &amp;&amp; !Blind)
&nbsp;                    pline("Now you can cross it!");
&nbsp;                /* no splashing in this case */
&nbsp;            }
&nbsp;        }
&nbsp;        if (!fills_up || !pushing) { /* splashing occurs */
&nbsp;            if (!u.uinwater) {
&nbsp;                if (pushing ? !Blind : cansee(rx, ry)) {
&nbsp;                    There("is a large splash as %s %s the %s.",
&nbsp;                          the(xname(otmp)), fills_up ? "fills" : "falls into",
&nbsp;                          what);
&nbsp;                } else if (!Deaf)
&nbsp;                    You_hear("a%s splash.", lava ? " sizzling" : "");
&nbsp;                wake_nearto(rx, ry, 40);
&nbsp;            }
&nbsp;
&nbsp;            if (fills_up &amp;&amp; u.uinwater &amp;&amp; distu(rx, ry) == 0) {
&nbsp;                u.uinwater = 0;
&nbsp;                docrt();
&nbsp;                vision_full_recalc = 1;
&nbsp;                You("find yourself on dry land again!");
&nbsp;            } else if (lava &amp;&amp; distu(rx, ry) &lt;= 2) {
&nbsp;                int dmg;
&nbsp;                You("are hit by molten lava%c", Fire_resistance ? '.' : '!');
&nbsp;                burn_away_slime();
&nbsp;                dmg = d((Fire_resistance ? 1 : 3), 6);
&nbsp;                losehp(Maybe_Half_Phys(dmg), /* lava damage */
&nbsp;                       "molten lava", KILLED_BY);
&nbsp;            } else if (!fills_up &amp;&amp; flags.verbose
&nbsp;                       &amp;&amp; (pushing ? !Blind : cansee(rx, ry)))
&nbsp;                pline("It sinks without a trace!");
&nbsp;        }
&nbsp;
&nbsp;        /* boulder is now gone */
&nbsp;        if (pushing)
&nbsp;            delobj(otmp);
&nbsp;        else
&nbsp;            obfree(otmp, (struct obj *) 0);
&nbsp;        return TRUE;
&nbsp;    }
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
flooreffects
&nbsp;/* Used for objects which sometimes do special things when dropped; must be
&nbsp; * called with the object not in any chain.  Returns TRUE if the object goes
&nbsp; * away.
&nbsp; */
&nbsp;boolean
&nbsp;flooreffects(obj, x, y, verb)
&nbsp;struct obj *obj;
&nbsp;int x, y;
&nbsp;const char *verb;
&nbsp;{
&nbsp;    struct trap *t;
&nbsp;    struct monst *mtmp;
&nbsp;    struct obj *otmp;
&nbsp;
&nbsp;    if (obj-&gt;where != OBJ_FREE)
&nbsp;        panic("flooreffects: obj not free");
&nbsp;
&nbsp;    /* make sure things like water_damage() have no pointers to follow */
&nbsp;    obj-&gt;nobj = obj-&gt;nexthere = (struct obj *) 0;
&nbsp;
&nbsp;    if (obj-&gt;otyp == BOULDER &amp;&amp; boulder_hits_pool(obj, x, y, FALSE)) {
&nbsp;        return TRUE;
&nbsp;    } else if (obj-&gt;otyp == BOULDER &amp;&amp; (t = t_at(x, y)) != 0
&nbsp;             &amp;&amp; (t-&gt;ttyp == PIT || t-&gt;ttyp == SPIKED_PIT
&nbsp;                 || t-&gt;ttyp == TRAPDOOR || t-&gt;ttyp == HOLE)) {
&nbsp;        if (((mtmp = m_at(x, y)) &amp;&amp; mtmp-&gt;mtrapped)
&nbsp;            || (u.utrap &amp;&amp; u.ux == x &amp;&amp; u.uy == y)) {
&nbsp;            if (*verb)
&nbsp;                pline_The("boulder %s into the pit%s.",
&nbsp;                          vtense((const char *) 0, verb),
&nbsp;                          (mtmp) ? "" : " with you");
&nbsp;            if (mtmp) {
&nbsp;                if (!passes_walls(mtmp-&gt;data) &amp;&amp; !throws_rocks(mtmp-&gt;data)) {
&nbsp;                    if (hmon(mtmp, obj, TRUE) &amp;&amp; !is_whirly(mtmp-&gt;data))
&nbsp;                        return FALSE; /* still alive */
&nbsp;                }
&nbsp;                mtmp-&gt;mtrapped = 0;
&nbsp;            } else {
&nbsp;                if (!Passes_walls &amp;&amp; !throws_rocks(youmonst.data)) {
&nbsp;                    losehp(Maybe_Half_Phys(rnd(15)),
&nbsp;                           "squished under a boulder", NO_KILLER_PREFIX);
&nbsp;                    return FALSE; /* player remains trapped */
&nbsp;                } else
&nbsp;                    u.utrap = 0;
&nbsp;            }
&nbsp;        }
&nbsp;        if (*verb) {
&nbsp;            if (Blind &amp;&amp; (x == u.ux) &amp;&amp; (y == u.uy)) {
&nbsp;                You_hear("a CRASH! beneath you.");
&nbsp;            } else if (!Blind &amp;&amp; cansee(x, y)) {
&nbsp;                pline_The("boulder %s%s.", t-&gt;tseen ? "" : "triggers and ",
&nbsp;                          t-&gt;ttyp == TRAPDOOR
&nbsp;                              ? "plugs a trap door"
&nbsp;                              : t-&gt;ttyp == HOLE ? "plugs a hole"
&nbsp;                                                : "fills a pit");
&nbsp;            } else {
&nbsp;                You_hear("a boulder %s.", verb);
&nbsp;            }
&nbsp;        }
&nbsp;        deltrap(t);
&nbsp;        useupf(obj, 1L);
&nbsp;        bury_objs(x, y);
&nbsp;        newsym(x, y);
&nbsp;        return TRUE;
&nbsp;    } else if (is_lava(x, y)) {
&nbsp;        return fire_damage(obj, FALSE, x, y);
&nbsp;    } else if (is_pool(x, y)) {
&nbsp;        /* Reasonably bulky objects (arbitrary) splash when dropped.
&nbsp;         * If you're floating above the water even small things make
&nbsp;         * noise.  Stuff dropped near fountains always misses */
&nbsp;        if ((Blind || (Levitation || Flying)) &amp;&amp; !Deaf
&nbsp;            &amp;&amp; ((x == u.ux) &amp;&amp; (y == u.uy))) {
&nbsp;            if (!Underwater) {
&nbsp;                if (weight(obj) &gt; 9) {
&nbsp;                    pline("Splash!");
&nbsp;                } else if (Levitation || Flying) {
&nbsp;                    pline("Plop!");
&nbsp;                }
&nbsp;            }
&nbsp;            map_background(x, y, 0);
&nbsp;            newsym(x, y);
&nbsp;        }
&nbsp;        return water_damage(obj, NULL, FALSE) == ER_DESTROYED;
&nbsp;    } else if (u.ux == x &amp;&amp; u.uy == y &amp;&amp; (t = t_at(x, y)) != 0
&nbsp;               &amp;&amp; uteetering_at_seen_pit(t)) {
&nbsp;        if (Blind &amp;&amp; !Deaf)
&nbsp;            You_hear("%s tumble downwards.", the(xname(obj)));
&nbsp;        else
&nbsp;            pline("%s %s into %s pit.", The(xname(obj)),
&nbsp;                  otense(obj, "tumble"), the_your[t-&gt;madeby_u]);
&nbsp;    } else if (obj-&gt;globby) {
&nbsp;        /* Globby things like puddings might stick together */
&nbsp;        while (obj
&nbsp;               &amp;&amp; (otmp = obj_nexto_xy(obj-&gt;otyp, x, y, obj-&gt;o_id))
&nbsp;                      != (struct obj *) 0) {
&nbsp;            pudding_merge_message(obj, otmp);
&nbsp;            /* intentionally not getting the melded object; obj_meld may set
&nbsp;             * obj to null. */
&nbsp;            (void) obj_meld(&amp;obj, &amp;otmp);
&nbsp;        }
&nbsp;        return (boolean) (obj == NULL);
&nbsp;    }
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
doaltarobj
&nbsp;/* obj is an object dropped on an altar */
&nbsp;void
&nbsp;doaltarobj(obj)
&nbsp;register struct obj *obj;
&nbsp;{
&nbsp;    if (Blind)
&nbsp;        return;
&nbsp;
&nbsp;    if (obj-&gt;oclass != COIN_CLASS) {
&nbsp;        /* KMH, conduct */
&nbsp;        u.uconduct.gnostic++;
&nbsp;    } else {
&nbsp;        /* coins don't have bless/curse status */
&nbsp;        obj-&gt;blessed = obj-&gt;cursed = 0;
&nbsp;    }
&nbsp;
&nbsp;    if (obj-&gt;blessed || obj-&gt;cursed) {
&nbsp;        There("is %s flash as %s %s the altar.",
&nbsp;              an(hcolor(obj-&gt;blessed ? NH_AMBER : NH_BLACK)), doname(obj),
&nbsp;              otense(obj, "hit"));
&nbsp;        if (!Hallucination)
&nbsp;            obj-&gt;bknown = 1;
&nbsp;    } else {
&nbsp;        pline("%s %s on the altar.", Doname2(obj), otense(obj, "land"));
&nbsp;        if (obj-&gt;oclass != COIN_CLASS)
&nbsp;            obj-&gt;bknown = 1;
&nbsp;    }
&nbsp;}
&nbsp;
trycall
&nbsp;STATIC_OVL void
&nbsp;trycall(obj)
&nbsp;register struct obj *obj;
&nbsp;{
&nbsp;    if (!objects[obj-&gt;otyp].oc_name_known &amp;&amp; !objects[obj-&gt;otyp].oc_uname)
&nbsp;        docall(obj);
&nbsp;}
&nbsp;
polymorph_sink
&nbsp;/* Transforms the sink at the player's position into
&nbsp;   a fountain, throne, altar or grave. */
&nbsp;STATIC_DCL void
&nbsp;polymorph_sink()
&nbsp;{
&nbsp;    if (levl[u.ux][u.uy].typ != SINK)
&nbsp;        return;
&nbsp;
&nbsp;    level.flags.nsinks--;
&nbsp;    levl[u.ux][u.uy].doormask = 0;
&nbsp;    switch (rn2(4)) {
&nbsp;    default:
&nbsp;    case 0:
&nbsp;        levl[u.ux][u.uy].typ = FOUNTAIN;
&nbsp;        level.flags.nfountains++;
&nbsp;        break;
&nbsp;    case 1:
&nbsp;        levl[u.ux][u.uy].typ = THRONE;
&nbsp;        break;
&nbsp;    case 2:
&nbsp;        levl[u.ux][u.uy].typ = ALTAR;
&nbsp;        levl[u.ux][u.uy].altarmask = Align2amask(rn2((int) A_LAWFUL + 2) - 1);
&nbsp;        break;
&nbsp;    case 3:
&nbsp;        levl[u.ux][u.uy].typ = ROOM;
&nbsp;        make_grave(u.ux, u.uy, (char *) 0);
&nbsp;        break;
&nbsp;    }
&nbsp;    pline_The("sink transforms into %s!", (levl[u.ux][u.uy].typ == THRONE)
&nbsp;                                              ? "a throne"
&nbsp;                                              : an(surface(u.ux, u.uy)));
&nbsp;    newsym(u.ux, u.uy);
&nbsp;}
&nbsp;
teleport_sink
&nbsp;/* Teleports the sink at the player's position;
&nbsp;   return True if sink teleported. */
&nbsp;STATIC_DCL boolean
&nbsp;teleport_sink()
&nbsp;{
&nbsp;    int cx, cy;
&nbsp;    int cnt = 0;
&nbsp;    struct trap *trp;
&nbsp;    struct engr *eng;
&nbsp;
&nbsp;    do {
&nbsp;        cx = rnd(COLNO - 1);
&nbsp;        cy = rn2(ROWNO);
&nbsp;        trp = t_at(cx, cy);
&nbsp;        eng = engr_at(cx, cy);
&nbsp;    } while ((levl[cx][cy].typ != ROOM || trp || eng || cansee(cx, cy))
&nbsp;             &amp;&amp; cnt++ &lt; 200);
&nbsp;
&nbsp;    if (levl[cx][cy].typ == ROOM &amp;&amp; !trp &amp;&amp; !eng) {
&nbsp;        /* create sink at new position */
&nbsp;        levl[cx][cy].typ = SINK;
&nbsp;        levl[cx][cy].looted = levl[u.ux][u.uy].looted;
&nbsp;        newsym(cx, cy);
&nbsp;        /* remove old sink */
&nbsp;        levl[u.ux][u.uy].typ = ROOM;
&nbsp;        levl[u.ux][u.uy].looted = 0;
&nbsp;        newsym(u.ux, u.uy);
&nbsp;        return TRUE;
&nbsp;    }
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
dosinkring
&nbsp;/* obj is a ring being dropped over a kitchen sink */
&nbsp;STATIC_OVL void
&nbsp;dosinkring(obj)
&nbsp;register struct obj *obj;
&nbsp;{
&nbsp;    struct obj *otmp, *otmp2;
&nbsp;    boolean ideed = TRUE;
&nbsp;    boolean nosink = FALSE;
&nbsp;
&nbsp;    You("drop %s down the drain.", doname(obj));
&nbsp;    obj-&gt;in_use = TRUE;  /* block free identification via interrupt */
&nbsp;    switch (obj-&gt;otyp) { /* effects that can be noticed without eyes */
&nbsp;    case RIN_SEARCHING:
&nbsp;        You("thought %s got lost in the sink, but there it is!", yname(obj));
&nbsp;        goto giveback;
&nbsp;    case RIN_SLOW_DIGESTION:
&nbsp;        pline_The("ring is regurgitated!");
&nbsp;    giveback:
&nbsp;        obj-&gt;in_use = FALSE;
&nbsp;        dropx(obj);
&nbsp;        trycall(obj);
&nbsp;        return;
&nbsp;    case RIN_LEVITATION:
&nbsp;        pline_The("sink quivers upward for a moment.");
&nbsp;        break;
&nbsp;    case RIN_POISON_RESISTANCE:
&nbsp;        You("smell rotten %s.", makeplural(fruitname(FALSE)));
&nbsp;        break;
&nbsp;    case RIN_AGGRAVATE_MONSTER:
&nbsp;        pline("Several %s buzz angrily around the sink.",
&nbsp;              Hallucination ? makeplural(rndmonnam(NULL)) : "flies");
&nbsp;        break;
&nbsp;    case RIN_SHOCK_RESISTANCE:
&nbsp;        pline("Static electricity surrounds the sink.");
&nbsp;        break;
&nbsp;    case RIN_CONFLICT:
&nbsp;        You_hear("loud noises coming from the drain.");
&nbsp;        break;
&nbsp;    case RIN_SUSTAIN_ABILITY: /* KMH */
&nbsp;        pline_The("water flow seems fixed.");
&nbsp;        break;
&nbsp;    case RIN_GAIN_STRENGTH:
&nbsp;        pline_The("water flow seems %ser now.",
&nbsp;                  (obj-&gt;spe &lt; 0) ? "weak" : "strong");
&nbsp;        break;
&nbsp;    case RIN_GAIN_CONSTITUTION:
&nbsp;        pline_The("water flow seems %ser now.",
&nbsp;                  (obj-&gt;spe &lt; 0) ? "less" : "great");
&nbsp;        break;
&nbsp;    case RIN_INCREASE_ACCURACY: /* KMH */
&nbsp;        pline_The("water flow %s the drain.",
&nbsp;                  (obj-&gt;spe &lt; 0) ? "misses" : "hits");
&nbsp;        break;
&nbsp;    case RIN_INCREASE_DAMAGE:
&nbsp;        pline_The("water's force seems %ser now.",
&nbsp;                  (obj-&gt;spe &lt; 0) ? "small" : "great");
&nbsp;        break;
&nbsp;    case RIN_HUNGER:
&nbsp;        ideed = FALSE;
&nbsp;        for (otmp = level.objects[u.ux][u.uy]; otmp; otmp = otmp2) {
&nbsp;            otmp2 = otmp-&gt;nexthere;
&nbsp;            if (otmp != uball &amp;&amp; otmp != uchain
&nbsp;                &amp;&amp; !obj_resists(otmp, 1, 99)) {
&nbsp;                if (!Blind) {
&nbsp;                    pline("Suddenly, %s %s from the sink!", doname(otmp),
&nbsp;                          otense(otmp, "vanish"));
&nbsp;                    ideed = TRUE;
&nbsp;                }
&nbsp;                delobj(otmp);
&nbsp;            }
&nbsp;        }
&nbsp;        break;
&nbsp;    case MEAT_RING:
&nbsp;        /* Not the same as aggravate monster; besides, it's obvious. */
&nbsp;        pline("Several flies buzz around the sink.");
&nbsp;        break;
&nbsp;    default:
&nbsp;        ideed = FALSE;
&nbsp;        break;
&nbsp;    }
&nbsp;    if (!Blind &amp;&amp; !ideed &amp;&amp; obj-&gt;otyp != RIN_HUNGER) {
&nbsp;        ideed = TRUE;
&nbsp;        switch (obj-&gt;otyp) { /* effects that need eyes */
&nbsp;        case RIN_ADORNMENT:
&nbsp;            pline_The("faucets flash brightly for a moment.");
&nbsp;            break;
&nbsp;        case RIN_REGENERATION:
&nbsp;            pline_The("sink looks as good as new.");
&nbsp;            break;
&nbsp;        case RIN_INVISIBILITY:
&nbsp;            You("don't see anything happen to the sink.");
&nbsp;            break;
&nbsp;        case RIN_FREE_ACTION:
&nbsp;            You_see("the ring slide right down the drain!");
&nbsp;            break;
&nbsp;        case RIN_SEE_INVISIBLE:
&nbsp;            You_see("some %s in the sink.",
&nbsp;                    Hallucination ? "oxygen molecules" : "air");
&nbsp;            break;
&nbsp;        case RIN_STEALTH:
&nbsp;            pline_The("sink seems to blend into the floor for a moment.");
&nbsp;            break;
&nbsp;        case RIN_FIRE_RESISTANCE:
&nbsp;            pline_The("hot water faucet flashes brightly for a moment.");
&nbsp;            break;
&nbsp;        case RIN_COLD_RESISTANCE:
&nbsp;            pline_The("cold water faucet flashes brightly for a moment.");
&nbsp;            break;
&nbsp;        case RIN_PROTECTION_FROM_SHAPE_CHAN:
&nbsp;            pline_The("sink looks nothing like a fountain.");
&nbsp;            break;
&nbsp;        case RIN_PROTECTION:
&nbsp;            pline_The("sink glows %s for a moment.",
&nbsp;                      hcolor((obj-&gt;spe &lt; 0) ? NH_BLACK : NH_SILVER));
&nbsp;            break;
&nbsp;        case RIN_WARNING:
&nbsp;            pline_The("sink glows %s for a moment.", hcolor(NH_WHITE));
&nbsp;            break;
&nbsp;        case RIN_TELEPORTATION:
&nbsp;            nosink = teleport_sink();
&nbsp;            pline_The("sink %svanishes.", nosink ? "" : "momentarily ");
&nbsp;            break;
&nbsp;        case RIN_TELEPORT_CONTROL:
&nbsp;            pline_The("sink looks like it is being beamed aboard somewhere.");
&nbsp;            break;
&nbsp;        case RIN_POLYMORPH:
&nbsp;            polymorph_sink();
&nbsp;            nosink = TRUE;
&nbsp;            break;
&nbsp;        case RIN_POLYMORPH_CONTROL:
&nbsp;            pline_The(
&nbsp;                "sink momentarily looks like a regularly erupting geyser.");
&nbsp;            break;
&nbsp;        }
&nbsp;    }
&nbsp;    if (ideed)
&nbsp;        trycall(obj);
&nbsp;    else if (!nosink)
&nbsp;        You_hear("the ring bouncing down the drainpipe.");
&nbsp;
&nbsp;    if (!rn2(20) &amp;&amp; !nosink) {
&nbsp;        pline_The("sink backs up, leaving %s.", doname(obj));
&nbsp;        obj-&gt;in_use = FALSE;
&nbsp;        dropx(obj);
&nbsp;    } else
&nbsp;        useup(obj);
&nbsp;}
&nbsp;
canletgo
&nbsp;/* some common tests when trying to drop or throw items */
&nbsp;boolean
&nbsp;canletgo(obj, word)
&nbsp;struct obj *obj;
&nbsp;const char *word;
&nbsp;{
&nbsp;    if (obj-&gt;owornmask &amp; (W_ARMOR | W_ACCESSORY)) {
&nbsp;        if (*word)
&nbsp;            Norep("You cannot %s %s you are wearing.", word, something);
&nbsp;        return FALSE;
&nbsp;    }
&nbsp;    if (obj-&gt;otyp == LOADSTONE &amp;&amp; obj-&gt;cursed) {
&nbsp;        /* getobj() kludge sets corpsenm to user's specified count
&nbsp;           when refusing to split a stack of cursed loadstones */
&nbsp;        if (*word) {
&nbsp;            /* getobj() ignores a count for throwing since that is
&nbsp;               implicitly forced to be 1; replicate its kludge... */
&nbsp;            if (!strcmp(word, "throw") &amp;&amp; obj-&gt;quan &gt; 1L)
&nbsp;                obj-&gt;corpsenm = 1;
&nbsp;            pline("For some reason, you cannot %s%s the stone%s!", word,
&nbsp;                  obj-&gt;corpsenm ? " any of" : "", plur(obj-&gt;quan));
&nbsp;        }
&nbsp;        obj-&gt;corpsenm = 0; /* reset */
&nbsp;        obj-&gt;bknown = 1;
&nbsp;        return FALSE;
&nbsp;    }
&nbsp;    if (obj-&gt;otyp == LEASH &amp;&amp; obj-&gt;leashmon != 0) {
&nbsp;        if (*word)
&nbsp;            pline_The("leash is tied around your %s.", body_part(HAND));
&nbsp;        return FALSE;
&nbsp;    }
&nbsp;    if (obj-&gt;owornmask &amp; W_SADDLE) {
&nbsp;        if (*word)
&nbsp;            You("cannot %s %s you are sitting on.", word, something);
&nbsp;        return FALSE;
&nbsp;    }
&nbsp;    return TRUE;
&nbsp;}
&nbsp;
drop
&nbsp;STATIC_PTR int
&nbsp;drop(obj)
&nbsp;register struct obj *obj;
&nbsp;{
&nbsp;    if (!obj)
&nbsp;        return 0;
&nbsp;    if (!canletgo(obj, "drop"))
&nbsp;        return 0;
&nbsp;    if (obj == uwep) {
&nbsp;        if (welded(uwep)) {
&nbsp;            weldmsg(obj);
&nbsp;            return 0;
&nbsp;        }
&nbsp;        setuwep((struct obj *) 0);
&nbsp;    }
&nbsp;    if (obj == uquiver) {
&nbsp;        setuqwep((struct obj *) 0);
&nbsp;    }
&nbsp;    if (obj == uswapwep) {
&nbsp;        setuswapwep((struct obj *) 0);
&nbsp;    }
&nbsp;
&nbsp;    if (u.uswallow) {
&nbsp;        /* barrier between you and the floor */
&nbsp;        if (flags.verbose) {
&nbsp;            char buf[BUFSZ];
&nbsp;
&nbsp;            /* doname can call s_suffix, reusing its buffer */
&nbsp;            Strcpy(buf, s_suffix(mon_nam(u.ustuck)));
&nbsp;            You("drop %s into %s %s.", doname(obj), buf,
&nbsp;                mbodypart(u.ustuck, STOMACH));
&nbsp;        }
&nbsp;    } else {
&nbsp;        if ((obj-&gt;oclass == RING_CLASS || obj-&gt;otyp == MEAT_RING)
&nbsp;            &amp;&amp; IS_SINK(levl[u.ux][u.uy].typ)) {
&nbsp;            dosinkring(obj);
&nbsp;            return 1;
&nbsp;        }
&nbsp;        if (!can_reach_floor(TRUE)) {
&nbsp;            /* we might be levitating due to #invoke Heart of Ahriman;
&nbsp;               if so, levitation would end during call to freeinv()
&nbsp;               and we want hitfloor() to happen before float_down() */
&nbsp;            boolean levhack = finesse_ahriman(obj);
&nbsp;
&nbsp;            if (levhack)
&nbsp;                ELevitation = W_ART; /* other than W_ARTI */
&nbsp;            if (flags.verbose)
&nbsp;                You("drop %s.", doname(obj));
&nbsp;            /* Ensure update when we drop gold objects */
&nbsp;            if (obj-&gt;oclass == COIN_CLASS)
&nbsp;                context.botl = 1;
&nbsp;            freeinv(obj);
&nbsp;            hitfloor(obj);
&nbsp;            if (levhack)
&nbsp;                float_down(I_SPECIAL | TIMEOUT, W_ARTI | W_ART);
&nbsp;            return 1;
&nbsp;        }
&nbsp;        if (!IS_ALTAR(levl[u.ux][u.uy].typ) &amp;&amp; flags.verbose)
&nbsp;            You("drop %s.", doname(obj));
&nbsp;    }
&nbsp;    dropx(obj);
&nbsp;    return 1;
&nbsp;}
&nbsp;
dropx
&nbsp;/* dropx - take dropped item out of inventory;
&nbsp;   called in several places - may produce output
&nbsp;   (eg ship_object() and dropy() -&gt; sellobj() both produce output) */
&nbsp;void
&nbsp;dropx(obj)
&nbsp;register struct obj *obj;
&nbsp;{
&nbsp;    /* Ensure update when we drop gold objects */
&nbsp;    if (obj-&gt;oclass == COIN_CLASS)
&nbsp;        context.botl = 1;
&nbsp;    freeinv(obj);
&nbsp;    if (!u.uswallow) {
&nbsp;        if (ship_object(obj, u.ux, u.uy, FALSE))
&nbsp;            return;
&nbsp;        if (IS_ALTAR(levl[u.ux][u.uy].typ))
&nbsp;            doaltarobj(obj); /* set bknown */
&nbsp;    }
&nbsp;    dropy(obj);
&nbsp;}
&nbsp;
dropy
&nbsp;/* dropy - put dropped object at destination; called from lots of places */
&nbsp;void
&nbsp;dropy(obj)
&nbsp;struct obj *obj;
&nbsp;{
&nbsp;    dropz(obj, FALSE);
&nbsp;}
&nbsp;
dropz
&nbsp;/* dropz - really put dropped object at its destination... */
&nbsp;void
&nbsp;dropz(obj, with_impact)
&nbsp;struct obj *obj;
&nbsp;boolean with_impact;
&nbsp;{
&nbsp;    if (obj == uwep)
&nbsp;        setuwep((struct obj *) 0);
&nbsp;    if (obj == uquiver)
&nbsp;        setuqwep((struct obj *) 0);
&nbsp;    if (obj == uswapwep)
&nbsp;        setuswapwep((struct obj *) 0);
&nbsp;
&nbsp;    if (!u.uswallow &amp;&amp; flooreffects(obj, u.ux, u.uy, "drop"))
&nbsp;        return;
&nbsp;    /* uswallow check done by GAN 01/29/87 */
&nbsp;    if (u.uswallow) {
&nbsp;        boolean could_petrify = FALSE;
&nbsp;        boolean could_poly = FALSE;
&nbsp;        boolean could_slime = FALSE;
&nbsp;        boolean could_grow = FALSE;
&nbsp;        boolean could_heal = FALSE;
&nbsp;
&nbsp;        if (obj != uball) { /* mon doesn't pick up ball */
&nbsp;            if (obj-&gt;otyp == CORPSE) {
&nbsp;                could_petrify = touch_petrifies(&amp;mons[obj-&gt;corpsenm]);
&nbsp;                could_poly = polyfodder(obj);
&nbsp;                could_slime = (obj-&gt;corpsenm == PM_GREEN_SLIME);
&nbsp;                could_grow = (obj-&gt;corpsenm == PM_WRAITH);
&nbsp;                could_heal = (obj-&gt;corpsenm == PM_NURSE);
&nbsp;            }
&nbsp;            (void) mpickobj(u.ustuck, obj);
&nbsp;            if (is_animal(u.ustuck-&gt;data)) {
&nbsp;                if (could_poly || could_slime) {
&nbsp;                    (void) newcham(u.ustuck,
&nbsp;                                   could_poly ? (struct permonst *) 0
&nbsp;                                              : &amp;mons[PM_GREEN_SLIME],
&nbsp;                                   FALSE, could_slime);
&nbsp;                    delobj(obj); /* corpse is digested */
&nbsp;                } else if (could_petrify) {
&nbsp;                    minstapetrify(u.ustuck, TRUE);
&nbsp;                    /* Don't leave a cockatrice corpse in a statue */
&nbsp;                    if (!u.uswallow)
&nbsp;                        delobj(obj);
&nbsp;                } else if (could_grow) {
&nbsp;                    (void) grow_up(u.ustuck, (struct monst *) 0);
&nbsp;                    delobj(obj); /* corpse is digested */
&nbsp;                } else if (could_heal) {
&nbsp;                    u.ustuck-&gt;mhp = u.ustuck-&gt;mhpmax;
&nbsp;                    delobj(obj); /* corpse is digested */
&nbsp;                }
&nbsp;            }
&nbsp;        }
&nbsp;    } else {
&nbsp;        place_object(obj, u.ux, u.uy);
&nbsp;        if (with_impact)
&nbsp;            container_impact_dmg(obj, u.ux, u.uy);
&nbsp;        if (obj == uball)
&nbsp;            drop_ball(u.ux, u.uy);
&nbsp;        else if (level.flags.has_shop)
&nbsp;            sellobj(obj, u.ux, u.uy);
&nbsp;        stackobj(obj);
&nbsp;        if (Blind &amp;&amp; Levitation)
&nbsp;            map_object(obj, 0);
&nbsp;        newsym(u.ux, u.uy); /* remap location under self */
&nbsp;    }
&nbsp;}
&nbsp;
obj_no_longer_held
&nbsp;/* things that must change when not held; recurse into containers.
&nbsp;   Called for both player and monsters */
&nbsp;void
&nbsp;obj_no_longer_held(obj)
&nbsp;struct obj *obj;
&nbsp;{
&nbsp;    if (!obj) {
&nbsp;        return;
&nbsp;    } else if (Has_contents(obj)) {
&nbsp;        struct obj *contents;
&nbsp;
&nbsp;        for (contents = obj-&gt;cobj; contents; contents = contents-&gt;nobj)
&nbsp;            obj_no_longer_held(contents);
&nbsp;    }
&nbsp;    switch (obj-&gt;otyp) {
&nbsp;    case CRYSKNIFE:
&nbsp;        /* Normal crysknife reverts to worm tooth when not held by hero
&nbsp;         * or monster; fixed crysknife has only 10% chance of reverting.
&nbsp;         * When a stack of the latter is involved, it could be worthwhile
&nbsp;         * to give each individual crysknife its own separate 10% chance,
&nbsp;         * but we aren't in any position to handle stack splitting here.
&nbsp;         */
&nbsp;        if (!obj-&gt;oerodeproof || !rn2(10)) {
&nbsp;            /* if monsters aren't moving, assume player is responsible */
&nbsp;            if (!context.mon_moving &amp;&amp; !program_state.gameover)
&nbsp;                costly_alteration(obj, COST_DEGRD);
&nbsp;            obj-&gt;otyp = WORM_TOOTH;
&nbsp;            obj-&gt;oerodeproof = 0;
&nbsp;        }
&nbsp;        break;
&nbsp;    }
&nbsp;}
&nbsp;
doddrop
&nbsp;/* 'D' command: drop several things */
&nbsp;int
&nbsp;doddrop()
&nbsp;{
&nbsp;    int result = 0;
&nbsp;
&nbsp;    add_valid_menu_class(0); /* clear any classes already there */
&nbsp;    if (*u.ushops)
&nbsp;        sellobj_state(SELL_DELIBERATE);
&nbsp;    if (flags.menu_style != MENU_TRADITIONAL
&nbsp;        || (result = ggetobj("drop", drop, 0, FALSE, (unsigned *) 0)) &lt; -1)
&nbsp;        result = menu_drop(result);
&nbsp;    if (*u.ushops)
&nbsp;        sellobj_state(SELL_NORMAL);
&nbsp;    reset_occupations();
&nbsp;
&nbsp;    return result;
&nbsp;}
&nbsp;
menu_drop
&nbsp;/* Drop things from the hero's inventory, using a menu. */
&nbsp;STATIC_OVL int
&nbsp;menu_drop(retry)
&nbsp;int retry;
&nbsp;{
&nbsp;    int n, i, n_dropped = 0;
&nbsp;    long cnt;
&nbsp;    struct obj *otmp, *otmp2;
&nbsp;    menu_item *pick_list;
&nbsp;    boolean all_categories = TRUE;
&nbsp;    boolean drop_everything = FALSE;
&nbsp;
&nbsp;    if (retry) {
&nbsp;        all_categories = (retry == -2);
&nbsp;    } else if (flags.menu_style == MENU_FULL) {
&nbsp;        all_categories = FALSE;
&nbsp;        n = query_category("Drop what type of items?", invent,
&nbsp;                           UNPAID_TYPES | ALL_TYPES | CHOOSE_ALL | BUC_BLESSED
&nbsp;                               | BUC_CURSED | BUC_UNCURSED | BUC_UNKNOWN,
&nbsp;                           &amp;pick_list, PICK_ANY);
&nbsp;        if (!n)
&nbsp;            goto drop_done;
&nbsp;        for (i = 0; i &lt; n; i++) {
&nbsp;            if (pick_list[i].item.a_int == ALL_TYPES_SELECTED)
&nbsp;                all_categories = TRUE;
&nbsp;            else if (pick_list[i].item.a_int == 'A')
&nbsp;                drop_everything = TRUE;
&nbsp;            else
&nbsp;                add_valid_menu_class(pick_list[i].item.a_int);
&nbsp;        }
&nbsp;        free((genericptr_t) pick_list);
&nbsp;    } else if (flags.menu_style == MENU_COMBINATION) {
&nbsp;        unsigned ggoresults = 0;
&nbsp;        all_categories = FALSE;
&nbsp;        /* Gather valid classes via traditional NetHack method */
&nbsp;        i = ggetobj("drop", drop, 0, TRUE, &amp;ggoresults);
&nbsp;        if (i == -2)
&nbsp;            all_categories = TRUE;
&nbsp;        if (ggoresults &amp; ALL_FINISHED) {
&nbsp;            n_dropped = i;
&nbsp;            goto drop_done;
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    if (drop_everything) {
&nbsp;        /*
&nbsp;         * Dropping a burning potion of oil while levitating can cause
&nbsp;         * an explosion which might destroy some of hero's inventory,
&nbsp;         * so the old code
&nbsp;         *      for (otmp = invent; otmp; otmp = otmp2) {
&nbsp;         *          otmp2 = otmp-&gt;nobj;
&nbsp;         *          n_dropped += drop(otmp);
&nbsp;         *      }
&nbsp;         * was unreliable and could lead to an "object lost" panic.
&nbsp;         *
&nbsp;         * Use the bypass bit to mark items already processed (hence
&nbsp;         * not droppable) and rescan inventory until no unbypassed
&nbsp;         * items remain.
&nbsp;         */
&nbsp;        bypass_objlist(invent, FALSE); /* clear bypass bit for invent */
&nbsp;        while ((otmp = nxt_unbypassed_obj(invent)) != 0)
&nbsp;            n_dropped += drop(otmp);
&nbsp;        /* we might not have dropped everything (worn armor, welded weapon,
&nbsp;           cursed loadstones), so reset any remaining inventory to normal */
&nbsp;        bypass_objlist(invent, FALSE);
&nbsp;    } else {
&nbsp;        /* should coordinate with perm invent, maybe not show worn items */
&nbsp;        n = query_objlist("What would you like to drop?", invent,
&nbsp;                          USE_INVLET | INVORDER_SORT, &amp;pick_list, PICK_ANY,
&nbsp;                          all_categories ? allow_all : allow_category);
&nbsp;        if (n &gt; 0) {
&nbsp;            /*
&nbsp;             * picklist[] contains a set of pointers into inventory, but
&nbsp;             * as soon as something gets dropped, they might become stale
&nbsp;             * (see the drop_everything code above for an explanation).
&nbsp;             * Just checking to see whether one is still in the invent
&nbsp;             * chain is not sufficient validation since destroyed items
&nbsp;             * will be freed and items we've split here might have already
&nbsp;             * reused that memory and put the same pointer value back into
&nbsp;             * invent.  Ditto for using invlet to validate.  So we start
&nbsp;             * by setting bypass on all of invent, then check each pointer
&nbsp;             * to verify that it is in invent and has that bit set.
&nbsp;             */
&nbsp;            bypass_objlist(invent, TRUE);
&nbsp;            for (i = 0; i &lt; n; i++) {
&nbsp;                otmp = pick_list[i].item.a_obj;
&nbsp;                for (otmp2 = invent; otmp2; otmp2 = otmp2-&gt;nobj)
&nbsp;                    if (otmp2 == otmp)
&nbsp;                        break;
&nbsp;                if (!otmp2 || !otmp2-&gt;bypass)
&nbsp;                    continue;
&nbsp;                /* found next selected invent item */
&nbsp;                cnt = pick_list[i].count;
&nbsp;                if (cnt &lt; otmp-&gt;quan) {
&nbsp;                    if (welded(otmp)) {
&nbsp;                        ; /* don't split */
&nbsp;                    } else if (otmp-&gt;otyp == LOADSTONE &amp;&amp; otmp-&gt;cursed) {
&nbsp;                        /* same kludge as getobj(), for canletgo()'s use */
&nbsp;                        otmp-&gt;corpsenm = (int) cnt; /* don't split */
&nbsp;                    } else {
&nbsp;                        otmp = splitobj(otmp, cnt);
&nbsp;                    }
&nbsp;                }
&nbsp;                n_dropped += drop(otmp);
&nbsp;            }
&nbsp;            bypass_objlist(invent, FALSE); /* reset invent to normal */
&nbsp;            free((genericptr_t) pick_list);
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;drop_done:
&nbsp;    return n_dropped;
&nbsp;}
&nbsp;
dodown
&nbsp;/* on a ladder, used in goto_level */
&nbsp;static NEARDATA boolean at_ladder = FALSE;
&nbsp;
&nbsp;/* the '&gt;' command */
&nbsp;int
&nbsp;dodown()
&nbsp;{
&nbsp;    struct trap *trap = 0;
&nbsp;    boolean stairs_down = ((u.ux == xdnstair &amp;&amp; u.uy == ydnstair)
&nbsp;                           || (u.ux == sstairs.sx &amp;&amp; u.uy == sstairs.sy
&nbsp;                               &amp;&amp; !sstairs.up)),
&nbsp;            ladder_down = (u.ux == xdnladder &amp;&amp; u.uy == ydnladder);
&nbsp;
&nbsp;    if (u_rooted())
&nbsp;        return 1;
&nbsp;
&nbsp;    if (stucksteed(TRUE)) {
&nbsp;        return 0;
&nbsp;    }
&nbsp;    /* Levitation might be blocked, but player can still use '&gt;' to
&nbsp;       turn off controlled levitation */
&nbsp;    if (HLevitation || ELevitation) {
&nbsp;        if ((HLevitation &amp; I_SPECIAL) || (ELevitation &amp; W_ARTI)) {
&nbsp;            /* end controlled levitation */
&nbsp;            if (ELevitation &amp; W_ARTI) {
&nbsp;                struct obj *obj;
&nbsp;
&nbsp;                for (obj = invent; obj; obj = obj-&gt;nobj) {
&nbsp;                    if (obj-&gt;oartifact
&nbsp;                        &amp;&amp; artifact_has_invprop(obj, LEVITATION)) {
&nbsp;                        if (obj-&gt;age &lt; monstermoves)
&nbsp;                            obj-&gt;age = monstermoves;
&nbsp;                        obj-&gt;age += rnz(100);
&nbsp;                    }
&nbsp;                }
&nbsp;            }
&nbsp;            if (float_down(I_SPECIAL | TIMEOUT, W_ARTI)) {
&nbsp;                return 1; /* came down, so moved */
&nbsp;            } else if (!HLevitation &amp;&amp; !ELevitation) {
&nbsp;                Your("latent levitation ceases.");
&nbsp;                return 1; /* did something, effectively moved */
&nbsp;            }
&nbsp;        }
&nbsp;        if (BLevitation) {
&nbsp;            ; /* weren't actually floating after all */
&nbsp;        } else if (Blind) {
&nbsp;            /* Avoid alerting player to an unknown stair or ladder.
&nbsp;             * Changes the message for a covered, known staircase
&nbsp;             * too; staircase knowledge is not stored anywhere.
&nbsp;             */
&nbsp;            if (stairs_down)
&nbsp;                stairs_down =
&nbsp;                    (glyph_to_cmap(levl[u.ux][u.uy].glyph) == S_dnstair);
&nbsp;            else if (ladder_down)
&nbsp;                ladder_down =
&nbsp;                    (glyph_to_cmap(levl[u.ux][u.uy].glyph) == S_dnladder);
&nbsp;        }
&nbsp;        floating_above(stairs_down ? "stairs" : ladder_down
&nbsp;                                                    ? "ladder"
&nbsp;                                                    : surface(u.ux, u.uy));
&nbsp;        return 0; /* didn't move */
&nbsp;    }
&nbsp;    if (!stairs_down &amp;&amp; !ladder_down) {
&nbsp;        trap = t_at(u.ux, u.uy);
&nbsp;        if (trap &amp;&amp; uteetering_at_seen_pit(trap)) {
&nbsp;            dotrap(trap, TOOKPLUNGE);
&nbsp;            return 1;
&nbsp;        } else if (!trap || (trap-&gt;ttyp != TRAPDOOR &amp;&amp; trap-&gt;ttyp != HOLE)
&nbsp;                   || !Can_fall_thru(&amp;u.uz) || !trap-&gt;tseen) {
&nbsp;            if (flags.autodig &amp;&amp; !context.nopick &amp;&amp; uwep &amp;&amp; is_pick(uwep)) {
&nbsp;                return use_pick_axe2(uwep);
&nbsp;            } else {
&nbsp;                You_cant("go down here.");
&nbsp;                return 0;
&nbsp;            }
&nbsp;        }
&nbsp;    }
&nbsp;    if (u.ustuck) {
&nbsp;        You("are %s, and cannot go down.",
&nbsp;            !u.uswallow ? "being held" : is_animal(u.ustuck-&gt;data)
&nbsp;                                             ? "swallowed"
&nbsp;                                             : "engulfed");
&nbsp;        return 1;
&nbsp;    }
&nbsp;    if (on_level(&amp;valley_level, &amp;u.uz) &amp;&amp; !u.uevent.gehennom_entered) {
&nbsp;        You("are standing at the gate to Gehennom.");
&nbsp;        pline("Unspeakable cruelty and harm lurk down there.");
&nbsp;        if (yn("Are you sure you want to enter?") != 'y')
&nbsp;            return 0;
&nbsp;        else
&nbsp;            pline("So be it.");
&nbsp;        u.uevent.gehennom_entered = 1; /* don't ask again */
&nbsp;    }
&nbsp;
&nbsp;    if (!next_to_u()) {
&nbsp;        You("are held back by your pet!");
&nbsp;        return 0;
&nbsp;    }
&nbsp;
&nbsp;    if (trap)
&nbsp;        You("%s %s.", Flying ? "fly" : locomotion(youmonst.data, "jump"),
&nbsp;            trap-&gt;ttyp == HOLE ? "down the hole" : "through the trap door");
&nbsp;
&nbsp;    if (trap &amp;&amp; Is_stronghold(&amp;u.uz)) {
&nbsp;        goto_hell(FALSE, TRUE);
&nbsp;    } else {
&nbsp;        at_ladder = (boolean) (levl[u.ux][u.uy].typ == LADDER);
&nbsp;        next_level(!trap);
&nbsp;        at_ladder = FALSE;
&nbsp;    }
&nbsp;    return 1;
&nbsp;}
&nbsp;
doup
&nbsp;/* the '&lt;' command */
&nbsp;int
&nbsp;doup()
&nbsp;{
&nbsp;    if (u_rooted())
&nbsp;        return 1;
&nbsp;
&nbsp;    /* "up" to get out of a pit... */
&nbsp;    if (u.utrap &amp;&amp; u.utraptype == TT_PIT) {
&nbsp;        climb_pit();
&nbsp;        return 1;
&nbsp;    }
&nbsp;
&nbsp;    if ((u.ux != xupstair || u.uy != yupstair)
&nbsp;        &amp;&amp; (!xupladder || u.ux != xupladder || u.uy != yupladder)
&nbsp;        &amp;&amp; (!sstairs.sx || u.ux != sstairs.sx || u.uy != sstairs.sy
&nbsp;            || !sstairs.up)) {
&nbsp;        You_cant("go up here.");
&nbsp;        return 0;
&nbsp;    }
&nbsp;    if (stucksteed(TRUE)) {
&nbsp;        return 0;
&nbsp;    }
&nbsp;    if (u.ustuck) {
&nbsp;        You("are %s, and cannot go up.",
&nbsp;            !u.uswallow ? "being held" : is_animal(u.ustuck-&gt;data)
&nbsp;                                             ? "swallowed"
&nbsp;                                             : "engulfed");
&nbsp;        return 1;
&nbsp;    }
&nbsp;    if (near_capacity() &gt; SLT_ENCUMBER) {
&nbsp;        /* No levitation check; inv_weight() already allows for it */
&nbsp;        Your("load is too heavy to climb the %s.",
&nbsp;             levl[u.ux][u.uy].typ == STAIRS ? "stairs" : "ladder");
&nbsp;        return 1;
&nbsp;    }
&nbsp;    if (ledger_no(&amp;u.uz) == 1) {
&nbsp;        if (yn("Beware, there will be no return! Still climb?") != 'y')
&nbsp;            return 0;
&nbsp;    }
&nbsp;    if (!next_to_u()) {
&nbsp;        You("are held back by your pet!");
&nbsp;        return 0;
&nbsp;    }
&nbsp;    at_ladder = (boolean) (levl[u.ux][u.uy].typ == LADDER);
&nbsp;    prev_level(TRUE);
&nbsp;    at_ladder = FALSE;
&nbsp;    return 1;
&nbsp;}
&nbsp;
currentlevel_rewrite
&nbsp;d_level save_dlevel = { 0, 0 };
&nbsp;
&nbsp;/* check that we can write out the current level */
&nbsp;STATIC_OVL int
&nbsp;currentlevel_rewrite()
&nbsp;{
&nbsp;    register int fd;
&nbsp;    char whynot[BUFSZ];
&nbsp;
&nbsp;    /* since level change might be a bit slow, flush any buffered screen
&nbsp;     *  output (like "you fall through a trap door") */
&nbsp;    mark_synch();
&nbsp;
&nbsp;    fd = create_levelfile(ledger_no(&amp;u.uz), whynot);
&nbsp;    if (fd &lt; 0) {
&nbsp;        /*
&nbsp;         * This is not quite impossible: e.g., we may have
&nbsp;         * exceeded our quota. If that is the case then we
&nbsp;         * cannot leave this level, and cannot save either.
&nbsp;         * Another possibility is that the directory was not
&nbsp;         * writable.
&nbsp;         */
&nbsp;        pline1(whynot);
&nbsp;        return -1;
&nbsp;    }
&nbsp;
&nbsp;#ifdef MFLOPPY
&nbsp;    if (!savelev(fd, ledger_no(&amp;u.uz), COUNT_SAVE)) {
&nbsp;        (void) nhclose(fd);
&nbsp;        delete_levelfile(ledger_no(&amp;u.uz));
&nbsp;        pline("NetHack is out of disk space for making levels!");
&nbsp;        You("can save, quit, or continue playing.");
&nbsp;        return -1;
&nbsp;    }
&nbsp;#endif
&nbsp;    return fd;
&nbsp;}
&nbsp;
save_currentstate
&nbsp;#ifdef INSURANCE
&nbsp;void
&nbsp;save_currentstate()
&nbsp;{
&nbsp;    int fd;
&nbsp;
&nbsp;    if (flags.ins_chkpt) {
&nbsp;        /* write out just-attained level, with pets and everything */
&nbsp;        fd = currentlevel_rewrite();
&nbsp;        if (fd &lt; 0)
&nbsp;            return;
&nbsp;        bufon(fd);
&nbsp;        savelev(fd, ledger_no(&amp;u.uz), WRITE_SAVE);
&nbsp;        bclose(fd);
&nbsp;    }
&nbsp;
&nbsp;    /* write out non-level state */
&nbsp;    savestateinlock();
&nbsp;}
&nbsp;#endif
&nbsp;
&nbsp;/*
&nbsp;static boolean
&nbsp;badspot(x, y)
&nbsp;register xchar x, y;
&nbsp;{
&nbsp;    return (boolean) ((levl[x][y].typ != ROOM
&nbsp;                       &amp;&amp; levl[x][y].typ != AIR
&nbsp;                       &amp;&amp; levl[x][y].typ != CORR)
&nbsp;                      || MON_AT(x, y));
&nbsp;}
&nbsp;*/
&nbsp;
goto_level
&nbsp;void
&nbsp;goto_level(newlevel, at_stairs, falling, portal)
&nbsp;d_level *newlevel;
&nbsp;boolean at_stairs, falling, portal;
&nbsp;{
&nbsp;    int fd, l_idx;
&nbsp;    xchar new_ledger;
&nbsp;    boolean cant_go_back, up = (depth(newlevel) &lt; depth(&amp;u.uz)),
&nbsp;                          newdungeon = (u.uz.dnum != newlevel-&gt;dnum),
&nbsp;                          was_in_W_tower = In_W_tower(u.ux, u.uy, &amp;u.uz),
&nbsp;                          familiar = FALSE;
&nbsp;    boolean new = FALSE; /* made a new level? */
&nbsp;    struct monst *mtmp;
&nbsp;    char whynot[BUFSZ];
&nbsp;    char *annotation;
&nbsp;
&nbsp;    if (dunlev(newlevel) &gt; dunlevs_in_dungeon(newlevel))
&nbsp;        newlevel-&gt;dlevel = dunlevs_in_dungeon(newlevel);
&nbsp;    if (newdungeon &amp;&amp; In_endgame(newlevel)) { /* 1st Endgame Level !!! */
&nbsp;        if (!u.uhave.amulet)
&nbsp;            return;  /* must have the Amulet */
&nbsp;        if (!wizard) /* wizard ^V can bypass Earth level */
&nbsp;            assign_level(newlevel, &amp;earth_level); /* (redundant) */
&nbsp;    }
&nbsp;    new_ledger = ledger_no(newlevel);
&nbsp;    if (new_ledger &lt;= 0)
&nbsp;        done(ESCAPED); /* in fact &lt; 0 is impossible */
&nbsp;
&nbsp;    /* If you have the amulet and are trying to get out of Gehennom,
&nbsp;     * going up a set of stairs sometimes does some very strange things!
&nbsp;     * Biased against law and towards chaos.  (The chance to be sent
&nbsp;     * down multiple levels when attempting to go up are significantly
&nbsp;     * less than the corresponding comment in older versions indicated
&nbsp;     * due to overlooking the effect of the call to assign_rnd_lvl().)
&nbsp;     *
&nbsp;     * Odds for making it to the next level up, or of being sent down:
&nbsp;     *  "up"    L      N      C
&nbsp;     *   +1   75.0   75.0   75.0
&nbsp;     *    0    6.25   8.33  12.5
&nbsp;     *   -1   11.46  12.50  12.5
&nbsp;     *   -2    5.21   4.17   0.0
&nbsp;     *   -3    2.08   0.0    0.0
&nbsp;     */
&nbsp;    if (Inhell &amp;&amp; up &amp;&amp; u.uhave.amulet &amp;&amp; !newdungeon &amp;&amp; !portal
&nbsp;        &amp;&amp; (dunlev(&amp;u.uz) &lt; dunlevs_in_dungeon(&amp;u.uz) - 3)) {
&nbsp;        if (!rn2(4)) {
&nbsp;            int odds = 3 + (int) u.ualign.type,   /* 2..4 */
&nbsp;                diff = odds &lt;= 1 ? 0 : rn2(odds); /* paranoia */
&nbsp;
&nbsp;            if (diff != 0) {
&nbsp;                assign_rnd_level(newlevel, &amp;u.uz, diff);
&nbsp;                /* if inside the tower, stay inside */
&nbsp;                if (was_in_W_tower &amp;&amp; !On_W_tower_level(newlevel))
&nbsp;                    diff = 0;
&nbsp;            }
&nbsp;            if (diff == 0)
&nbsp;                assign_level(newlevel, &amp;u.uz);
&nbsp;
&nbsp;            new_ledger = ledger_no(newlevel);
&nbsp;
&nbsp;            pline("A mysterious force momentarily surrounds you...");
&nbsp;            if (on_level(newlevel, &amp;u.uz)) {
&nbsp;                (void) safe_teleds(FALSE);
&nbsp;                (void) next_to_u();
&nbsp;                return;
&nbsp;            } else
&nbsp;                at_stairs = at_ladder = FALSE;
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    /* Prevent the player from going past the first quest level unless
&nbsp;     * (s)he has been given the go-ahead by the leader.
&nbsp;     */
&nbsp;    if (on_level(&amp;u.uz, &amp;qstart_level) &amp;&amp; !newdungeon &amp;&amp; !ok_to_quest()) {
&nbsp;        pline("A mysterious force prevents you from descending.");
&nbsp;        return;
&nbsp;    }
&nbsp;
&nbsp;    if (on_level(newlevel, &amp;u.uz))
&nbsp;        return; /* this can happen */
&nbsp;
&nbsp;    /* tethered movement makes level change while trapped feasible */
&nbsp;    if (u.utrap &amp;&amp; u.utraptype == TT_BURIEDBALL)
&nbsp;        buried_ball_to_punishment(); /* (before we save/leave old level) */
&nbsp;
&nbsp;    fd = currentlevel_rewrite();
&nbsp;    if (fd &lt; 0)
&nbsp;        return;
&nbsp;
&nbsp;    if (falling) /* assuming this is only trap door or hole */
&nbsp;        impact_drop((struct obj *) 0, u.ux, u.uy, newlevel-&gt;dlevel);
&nbsp;
&nbsp;    check_special_room(TRUE); /* probably was a trap door */
&nbsp;    if (Punished)
&nbsp;        unplacebc();
&nbsp;    u.utrap = 0; /* needed in level_tele */
&nbsp;    fill_pit(u.ux, u.uy);
&nbsp;    u.ustuck = 0; /* idem */
&nbsp;    u.uinwater = 0;
&nbsp;    u.uundetected = 0; /* not hidden, even if means are available */
&nbsp;    keepdogs(FALSE);
&nbsp;    if (u.uswallow) /* idem */
&nbsp;        u.uswldtim = u.uswallow = 0;
&nbsp;    recalc_mapseen(); /* recalculate map overview before we leave the level */
&nbsp;    /*
&nbsp;     *  We no longer see anything on the level.  Make sure that this
&nbsp;     *  follows u.uswallow set to null since uswallow overrides all
&nbsp;     *  normal vision.
&nbsp;     */
&nbsp;    vision_recalc(2);
&nbsp;
&nbsp;    /*
&nbsp;     * Save the level we're leaving.  If we're entering the endgame,
&nbsp;     * we can get rid of all existing levels because they cannot be
&nbsp;     * reached any more.  We still need to use savelev()'s cleanup
&nbsp;     * for the level being left, to recover dynamic memory in use and
&nbsp;     * to avoid dangling timers and light sources.
&nbsp;     */
&nbsp;    cant_go_back = (newdungeon &amp;&amp; In_endgame(newlevel));
&nbsp;    if (!cant_go_back) {
&nbsp;        update_mlstmv(); /* current monsters are becoming inactive */
&nbsp;        bufon(fd);       /* use buffered output */
&nbsp;    }
&nbsp;    savelev(fd, ledger_no(&amp;u.uz),
&nbsp;            cant_go_back ? FREE_SAVE : (WRITE_SAVE | FREE_SAVE));
&nbsp;    bclose(fd);
&nbsp;    if (cant_go_back) {
&nbsp;        /* discard unreachable levels; keep #0 */
&nbsp;        for (l_idx = maxledgerno(); l_idx &gt; 0; --l_idx)
&nbsp;            delete_levelfile(l_idx);
&nbsp;        /* mark #overview data for all dungeon branches as uninteresting */
&nbsp;        for (l_idx = 0; l_idx &lt; n_dgns; ++l_idx)
&nbsp;            remdun_mapseen(l_idx);
&nbsp;    }
&nbsp;
&nbsp;    if (Is_rogue_level(newlevel) || Is_rogue_level(&amp;u.uz))
&nbsp;        assign_graphics(Is_rogue_level(newlevel) ? ROGUESET : PRIMARY);
&nbsp;#ifdef USE_TILES
&nbsp;    substitute_tiles(newlevel);
&nbsp;#endif
&nbsp;    /* record this level transition as a potential seen branch unless using
&nbsp;     * some non-standard means of transportation (level teleport).
&nbsp;     */
&nbsp;    if ((at_stairs || falling || portal) &amp;&amp; (u.uz.dnum != newlevel-&gt;dnum))
&nbsp;        recbranch_mapseen(&amp;u.uz, newlevel);
&nbsp;    assign_level(&amp;u.uz0, &amp;u.uz);
&nbsp;    assign_level(&amp;u.uz, newlevel);
&nbsp;    assign_level(&amp;u.utolev, newlevel);
&nbsp;    u.utotype = 0;
&nbsp;    if (!builds_up(&amp;u.uz)) { /* usual case */
&nbsp;        if (dunlev(&amp;u.uz) &gt; dunlev_reached(&amp;u.uz))
&nbsp;            dunlev_reached(&amp;u.uz) = dunlev(&amp;u.uz);
&nbsp;    } else {
&nbsp;        if (dunlev_reached(&amp;u.uz) == 0
&nbsp;            || dunlev(&amp;u.uz) &lt; dunlev_reached(&amp;u.uz))
&nbsp;            dunlev_reached(&amp;u.uz) = dunlev(&amp;u.uz);
&nbsp;    }
&nbsp;    reset_rndmonst(NON_PM); /* u.uz change affects monster generation */
&nbsp;
&nbsp;    /* set default level change destination areas */
&nbsp;    /* the special level code may override these */
&nbsp;    (void) memset((genericptr_t) &amp;updest, 0, sizeof updest);
&nbsp;    (void) memset((genericptr_t) &amp;dndest, 0, sizeof dndest);
&nbsp;
&nbsp;    if (!(level_info[new_ledger].flags &amp; LFILE_EXISTS)) {
&nbsp;        /* entering this level for first time; make it now */
&nbsp;        if (level_info[new_ledger].flags &amp; (FORGOTTEN | VISITED)) {
&nbsp;            impossible("goto_level: returning to discarded level?");
&nbsp;            level_info[new_ledger].flags &amp;= ~(FORGOTTEN | VISITED);
&nbsp;        }
&nbsp;        mklev();
&nbsp;        new = TRUE; /* made the level */
&nbsp;    } else {
&nbsp;        /* returning to previously visited level; reload it */
&nbsp;        fd = open_levelfile(new_ledger, whynot);
&nbsp;        if (tricked_fileremoved(fd, whynot)) {
&nbsp;            /* we'll reach here if running in wizard mode */
&nbsp;            error("Cannot continue this game.");
&nbsp;        }
&nbsp;        minit(); /* ZEROCOMP */
&nbsp;        getlev(fd, hackpid, new_ledger, FALSE);
&nbsp;        (void) nhclose(fd);
&nbsp;        oinit(); /* reassign level dependent obj probabilities */
&nbsp;    }
&nbsp;    reglyph_darkroom();
&nbsp;    /* do this prior to level-change pline messages */
&nbsp;    vision_reset();         /* clear old level's line-of-sight */
&nbsp;    vision_full_recalc = 0; /* don't let that reenable vision yet */
&nbsp;    flush_screen(-1);       /* ensure all map flushes are postponed */
&nbsp;
&nbsp;    if (portal &amp;&amp; !In_endgame(&amp;u.uz)) {
&nbsp;        /* find the portal on the new level */
&nbsp;        register struct trap *ttrap;
&nbsp;
&nbsp;        for (ttrap = ftrap; ttrap; ttrap = ttrap-&gt;ntrap)
&nbsp;            if (ttrap-&gt;ttyp == MAGIC_PORTAL)
&nbsp;                break;
&nbsp;
&nbsp;        if (!ttrap)
&nbsp;            panic("goto_level: no corresponding portal!");
&nbsp;        seetrap(ttrap);
&nbsp;        u_on_newpos(ttrap-&gt;tx, ttrap-&gt;ty);
&nbsp;    } else if (at_stairs &amp;&amp; !In_endgame(&amp;u.uz)) {
&nbsp;        if (up) {
&nbsp;            if (at_ladder)
&nbsp;                u_on_newpos(xdnladder, ydnladder);
&nbsp;            else if (newdungeon)
&nbsp;                u_on_sstairs(1);
&nbsp;            else
&nbsp;                u_on_dnstairs();
&nbsp;            /* you climb up the {stairs|ladder};
&nbsp;               fly up the stairs; fly up along the ladder */
&nbsp;            pline("%s %s up%s the %s.",
&nbsp;                  (Punished &amp;&amp; !Levitation) ? "With great effort you" : "You",
&nbsp;                  Flying ? "fly" : "climb",
&nbsp;                  (Flying &amp;&amp; at_ladder) ? " along" : "",
&nbsp;                  at_ladder ? "ladder" : "stairs");
&nbsp;        } else { /* down */
&nbsp;            if (at_ladder)
&nbsp;                u_on_newpos(xupladder, yupladder);
&nbsp;            else if (newdungeon)
&nbsp;                u_on_sstairs(0);
&nbsp;            else
&nbsp;                u_on_upstairs();
&nbsp;            if (!u.dz) {
&nbsp;                ; /* stayed on same level? (no transit effects) */
&nbsp;            } else if (Flying) {
&nbsp;                if (flags.verbose)
&nbsp;                    You("fly down %s.",
&nbsp;                        at_ladder ? "along the ladder" : "the stairs");
&nbsp;            } else if (near_capacity() &gt; UNENCUMBERED || Punished
&nbsp;                       || Fumbling) {
&nbsp;                You("fall down the %s.", at_ladder ? "ladder" : "stairs");
&nbsp;                if (Punished) {
&nbsp;                    drag_down();
&nbsp;                    ballrelease(FALSE);
&nbsp;                }
&nbsp;                /* falling off steed has its own losehp() call */
&nbsp;                if (u.usteed)
&nbsp;                    dismount_steed(DISMOUNT_FELL);
&nbsp;                else
&nbsp;                    losehp(Maybe_Half_Phys(rnd(3)),
&nbsp;                           at_ladder ? "falling off a ladder"
&nbsp;                                     : "tumbling down a flight of stairs",
&nbsp;                           KILLED_BY);
&nbsp;                selftouch("Falling, you");
&nbsp;            } else { /* ordinary descent */
&nbsp;                if (flags.verbose)
&nbsp;                    You("%s.", at_ladder ? "climb down the ladder"
&nbsp;                                         : "descend the stairs");
&nbsp;            }
&nbsp;        }
&nbsp;    } else { /* trap door or level_tele or In_endgame */
&nbsp;        u_on_rndspot((up ? 1 : 0) | (was_in_W_tower ? 2 : 0));
&nbsp;        if (falling) {
&nbsp;            if (Punished)
&nbsp;                ballfall();
&nbsp;            selftouch("Falling, you");
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    if (Punished)
&nbsp;        placebc();
&nbsp;    obj_delivery(FALSE);
&nbsp;    losedogs();
&nbsp;    kill_genocided_monsters(); /* for those wiped out while in limbo */
&nbsp;    /*
&nbsp;     * Expire all timers that have gone off while away.  Must be
&nbsp;     * after migrating monsters and objects are delivered
&nbsp;     * (losedogs and obj_delivery).
&nbsp;     */
&nbsp;    run_timers();
&nbsp;
&nbsp;    initrack();
&nbsp;
&nbsp;    if ((mtmp = m_at(u.ux, u.uy)) != 0 &amp;&amp; mtmp != u.usteed) {
&nbsp;        /* There's a monster at your target destination; it might be one
&nbsp;           which accompanied you--see mon_arrive(dogmove.c)--or perhaps
&nbsp;           it was already here.  Randomly move you to an adjacent spot
&nbsp;           or else the monster to any nearby location.  Prior to 3.3.0
&nbsp;           the latter was done unconditionally. */
&nbsp;        coord cc;
&nbsp;
&nbsp;        if (!rn2(2) &amp;&amp; enexto(&amp;cc, u.ux, u.uy, youmonst.data)
&nbsp;            &amp;&amp; distu(cc.x, cc.y) &lt;= 2)
&nbsp;            u_on_newpos(cc.x, cc.y); /*[maybe give message here?]*/
&nbsp;        else
&nbsp;            mnexto(mtmp);
&nbsp;
&nbsp;        if ((mtmp = m_at(u.ux, u.uy)) != 0) {
&nbsp;            /* there was an unconditional impossible("mnearto failed")
&nbsp;               here, but it's not impossible and we're prepared to cope
&nbsp;               with the situation, so only say something when debugging */
&nbsp;            if (wizard)
&nbsp;                pline("(monster in hero's way)");
&nbsp;            if (!rloc(mtmp, TRUE))
&nbsp;                /* no room to move it; send it away, to return later */
&nbsp;                migrate_to_level(mtmp, ledger_no(&amp;u.uz), MIGR_RANDOM,
&nbsp;                                 (coord *) 0);
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    /* initial movement of bubbles just before vision_recalc */
&nbsp;    if (Is_waterlevel(&amp;u.uz) || Is_airlevel(&amp;u.uz))
&nbsp;        movebubbles();
&nbsp;    else if (Is_firelevel(&amp;u.uz))
&nbsp;        fumaroles();
&nbsp;
&nbsp;    if (level_info[new_ledger].flags &amp; FORGOTTEN) {
&nbsp;        forget_map(ALL_MAP); /* forget the map */
&nbsp;        forget_traps();      /* forget all traps too */
&nbsp;        familiar = TRUE;
&nbsp;        level_info[new_ledger].flags &amp;= ~FORGOTTEN;
&nbsp;    }
&nbsp;
&nbsp;    /* Reset the screen. */
&nbsp;    vision_reset(); /* reset the blockages */
&nbsp;    docrt();        /* does a full vision recalc */
&nbsp;    flush_screen(-1);
&nbsp;
&nbsp;    /*
&nbsp;     *  Move all plines beyond the screen reset.
&nbsp;     */
&nbsp;
&nbsp;    /* special levels can have a custom arrival message */
&nbsp;    deliver_splev_message();
&nbsp;
&nbsp;    /* give room entrance message, if any */
&nbsp;    check_special_room(FALSE);
&nbsp;
&nbsp;    /* deliver objects traveling with player */
&nbsp;    obj_delivery(TRUE);
&nbsp;
&nbsp;    /* Check whether we just entered Gehennom. */
&nbsp;    if (!In_hell(&amp;u.uz0) &amp;&amp; Inhell) {
&nbsp;        if (Is_valley(&amp;u.uz)) {
&nbsp;            You("arrive at the Valley of the Dead...");
&nbsp;            pline_The("odor of burnt flesh and decay pervades the air.");
&nbsp;#ifdef MICRO
&nbsp;            display_nhwindow(WIN_MESSAGE, FALSE);
&nbsp;#endif
&nbsp;            You_hear("groans and moans everywhere.");
&nbsp;        } else
&nbsp;            pline("It is hot here.  You smell smoke...");
&nbsp;        u.uachieve.enter_gehennom = 1;
&nbsp;    }
&nbsp;    /* in case we've managed to bypass the Valley's stairway down */
&nbsp;    if (Inhell &amp;&amp; !Is_valley(&amp;u.uz))
&nbsp;        u.uevent.gehennom_entered = 1;
&nbsp;
&nbsp;    if (familiar) {
&nbsp;        static const char *const fam_msgs[4] = {
&nbsp;            "You have a sense of deja vu.",
&nbsp;            "You feel like you've been here before.",
&nbsp;            "This place %s familiar...", 0 /* no message */
&nbsp;        };
&nbsp;        static const char *const halu_fam_msgs[4] = {
&nbsp;            "Whoa!  Everything %s different.",
&nbsp;            "You are surrounded by twisty little passages, all alike.",
&nbsp;            "Gee, this %s like uncle Conan's place...", 0 /* no message */
&nbsp;        };
&nbsp;        const char *mesg;
&nbsp;        char buf[BUFSZ];
&nbsp;        int which = rn2(4);
&nbsp;
&nbsp;        if (Hallucination)
&nbsp;            mesg = halu_fam_msgs[which];
&nbsp;        else
&nbsp;            mesg = fam_msgs[which];
&nbsp;        if (mesg &amp;&amp; index(mesg, '%')) {
&nbsp;            Sprintf(buf, mesg, !Blind ? "looks" : "seems");
&nbsp;            mesg = buf;
&nbsp;        }
&nbsp;        if (mesg)
&nbsp;            pline1(mesg);
&nbsp;    }
&nbsp;
&nbsp;    /* special location arrival messages/events */
&nbsp;    if (In_endgame(&amp;u.uz)) {
&nbsp;        if (new &amp;&amp;on_level(&amp;u.uz, &amp;astral_level))
&nbsp;            final_level(); /* guardian angel,&amp;c */
&nbsp;        else if (newdungeon &amp;&amp; u.uhave.amulet)
&nbsp;            resurrect(); /* force confrontation with Wizard */
&nbsp;    } else if (In_quest(&amp;u.uz)) {
&nbsp;        onquest(); /* might be reaching locate|goal level */
&nbsp;    } else if (In_V_tower(&amp;u.uz)) {
&nbsp;        if (newdungeon &amp;&amp; In_hell(&amp;u.uz0))
&nbsp;            pline_The("heat and smoke are gone.");
&nbsp;    } else if (Is_knox(&amp;u.uz)) {
&nbsp;        /* alarm stops working once Croesus has died */
&nbsp;        if (new || !mvitals[PM_CROESUS].died) {
&nbsp;            You("have penetrated a high security area!");
&nbsp;            pline("An alarm sounds!");
&nbsp;            for (mtmp = fmon; mtmp; mtmp = mtmp-&gt;nmon) {
&nbsp;                if (DEADMONSTER(mtmp))
&nbsp;                    continue;
&nbsp;                mtmp-&gt;msleeping = 0;
&nbsp;            }
&nbsp;        }
&nbsp;    } else {
&nbsp;        if (new &amp;&amp; Is_rogue_level(&amp;u.uz))
&nbsp;            You("enter what seems to be an older, more primitive world.");
&nbsp;        /* main dungeon message from your quest leader */
&nbsp;        if (!In_quest(&amp;u.uz0) &amp;&amp; at_dgn_entrance("The Quest")
&nbsp;            &amp;&amp; !(u.uevent.qcompleted || u.uevent.qexpelled
&nbsp;                 || quest_status.leader_is_dead)) {
&nbsp;            if (!u.uevent.qcalled) {
&nbsp;                u.uevent.qcalled = 1;
&nbsp;                com_pager(2); /* main "leader needs help" message */
&nbsp;            } else {          /* reminder message */
&nbsp;                com_pager(Role_if(PM_ROGUE) ? 4 : 3);
&nbsp;            }
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    assign_level(&amp;u.uz0, &amp;u.uz); /* reset u.uz0 */
&nbsp;#ifdef INSURANCE
&nbsp;    save_currentstate();
&nbsp;#endif
&nbsp;
&nbsp;    if ((annotation = get_annotation(&amp;u.uz)))
&nbsp;        You("remember this level as %s.", annotation);
&nbsp;
&nbsp;    /* assume this will always return TRUE when changing level */
&nbsp;    (void) in_out_region(u.ux, u.uy);
&nbsp;    (void) pickup(1);
&nbsp;    context.polearm.hitmon = NULL;
&nbsp;}
&nbsp;
final_level
&nbsp;STATIC_OVL void
&nbsp;final_level()
&nbsp;{
&nbsp;    struct monst *mtmp;
&nbsp;
&nbsp;    /* reset monster hostility relative to player */
&nbsp;    for (mtmp = fmon; mtmp; mtmp = mtmp-&gt;nmon) {
&nbsp;        if (DEADMONSTER(mtmp))
&nbsp;            continue;
&nbsp;        reset_hostility(mtmp);
&nbsp;    }
&nbsp;
&nbsp;    /* create some player-monsters */
&nbsp;    create_mplayers(rn1(4, 3), TRUE);
&nbsp;
&nbsp;    /* create a guardian angel next to player, if worthy */
&nbsp;    gain_guardian_angel();
&nbsp;}
&nbsp;
schedule_goto
&nbsp;static char *dfr_pre_msg = 0,  /* pline() before level change */
&nbsp;            *dfr_post_msg = 0; /* pline() after level change */
&nbsp;
&nbsp;/* change levels at the end of this turn, after monsters finish moving */
&nbsp;void
&nbsp;schedule_goto(tolev, at_stairs, falling, portal_flag, pre_msg, post_msg)
&nbsp;d_level *tolev;
&nbsp;boolean at_stairs, falling;
&nbsp;int portal_flag;
&nbsp;const char *pre_msg, *post_msg;
&nbsp;{
&nbsp;    int typmask = 0100; /* non-zero triggers `deferred_goto' */
&nbsp;
&nbsp;    /* destination flags (`goto_level' args) */
&nbsp;    if (at_stairs)
&nbsp;        typmask |= 1;
&nbsp;    if (falling)
&nbsp;        typmask |= 2;
&nbsp;    if (portal_flag)
&nbsp;        typmask |= 4;
&nbsp;    if (portal_flag &lt; 0)
&nbsp;        typmask |= 0200; /* flag for portal removal */
&nbsp;    u.utotype = typmask;
&nbsp;    /* destination level */
&nbsp;    assign_level(&amp;u.utolev, tolev);
&nbsp;
&nbsp;    if (pre_msg)
&nbsp;        dfr_pre_msg = dupstr(pre_msg);
&nbsp;    if (post_msg)
&nbsp;        dfr_post_msg = dupstr(post_msg);
&nbsp;}
&nbsp;
deferred_goto
&nbsp;/* handle something like portal ejection */
&nbsp;void
&nbsp;deferred_goto()
&nbsp;{
&nbsp;    if (!on_level(&amp;u.uz, &amp;u.utolev)) {
&nbsp;        d_level dest;
&nbsp;        int typmask = u.utotype; /* save it; goto_level zeroes u.utotype */
&nbsp;
&nbsp;        assign_level(&amp;dest, &amp;u.utolev);
&nbsp;        if (dfr_pre_msg)
&nbsp;            pline1(dfr_pre_msg);
&nbsp;        goto_level(&amp;dest, !!(typmask &amp; 1), !!(typmask &amp; 2), !!(typmask &amp; 4));
&nbsp;        if (typmask &amp; 0200) { /* remove portal */
&nbsp;            struct trap *t = t_at(u.ux, u.uy);
&nbsp;
&nbsp;            if (t) {
&nbsp;                deltrap(t);
&nbsp;                newsym(u.ux, u.uy);
&nbsp;            }
&nbsp;        }
&nbsp;        if (dfr_post_msg)
&nbsp;            pline1(dfr_post_msg);
&nbsp;    }
&nbsp;    u.utotype = 0; /* our caller keys off of this */
&nbsp;    if (dfr_pre_msg)
&nbsp;        free((genericptr_t) dfr_pre_msg), dfr_pre_msg = 0;
&nbsp;    if (dfr_post_msg)
&nbsp;        free((genericptr_t) dfr_post_msg), dfr_post_msg = 0;
&nbsp;}
&nbsp;
revive_corpse
&nbsp;/*
&nbsp; * Return TRUE if we created a monster for the corpse.  If successful, the
&nbsp; * corpse is gone.
&nbsp; */
&nbsp;boolean
&nbsp;revive_corpse(corpse)
&nbsp;struct obj *corpse;
&nbsp;{
&nbsp;    struct monst *mtmp, *mcarry;
&nbsp;    boolean is_uwep, chewed;
&nbsp;    xchar where;
&nbsp;    char cname[BUFSZ];
&nbsp;    struct obj *container = (struct obj *) 0;
&nbsp;    int container_where = 0;
&nbsp;
&nbsp;    where = corpse-&gt;where;
&nbsp;    is_uwep = (corpse == uwep);
&nbsp;    chewed = (corpse-&gt;oeaten != 0);
&nbsp;    Strcpy(cname,
&nbsp;           corpse_xname(corpse, chewed ? "bite-covered" : (const char *) 0,
&nbsp;                        CXN_SINGULAR));
&nbsp;    mcarry = (where == OBJ_MINVENT) ? corpse-&gt;ocarry : 0;
&nbsp;
&nbsp;    if (where == OBJ_CONTAINED) {
&nbsp;        struct monst *mtmp2;
&nbsp;
&nbsp;        container = corpse-&gt;ocontainer;
&nbsp;        mtmp2 =
&nbsp;            get_container_location(container, &amp;container_where, (int *) 0);
&nbsp;        /* container_where is the outermost container's location even if
&nbsp;         * nested */
&nbsp;        if (container_where == OBJ_MINVENT &amp;&amp; mtmp2)
&nbsp;            mcarry = mtmp2;
&nbsp;    }
&nbsp;    mtmp = revive(corpse, FALSE); /* corpse is gone if successful */
&nbsp;
&nbsp;    if (mtmp) {
&nbsp;        switch (where) {
&nbsp;        case OBJ_INVENT:
&nbsp;            if (is_uwep)
&nbsp;                pline_The("%s writhes out of your grasp!", cname);
&nbsp;            else
&nbsp;                You_feel("squirming in your backpack!");
&nbsp;            break;
&nbsp;
&nbsp;        case OBJ_FLOOR:
&nbsp;            if (cansee(mtmp-&gt;mx, mtmp-&gt;my))
&nbsp;                pline("%s rises from the dead!",
&nbsp;                      chewed ? Adjmonnam(mtmp, "bite-covered")
&nbsp;                             : Monnam(mtmp));
&nbsp;            break;
&nbsp;
&nbsp;        case OBJ_MINVENT: /* probably a nymph's */
&nbsp;            if (cansee(mtmp-&gt;mx, mtmp-&gt;my)) {
&nbsp;                if (canseemon(mcarry))
&nbsp;                    pline("Startled, %s drops %s as it revives!",
&nbsp;                          mon_nam(mcarry), an(cname));
&nbsp;                else
&nbsp;                    pline("%s suddenly appears!",
&nbsp;                          chewed ? Adjmonnam(mtmp, "bite-covered")
&nbsp;                                 : Monnam(mtmp));
&nbsp;            }
&nbsp;            break;
&nbsp;        case OBJ_CONTAINED: {
&nbsp;            char sackname[BUFSZ];
&nbsp;
&nbsp;            if (container_where == OBJ_MINVENT &amp;&amp; cansee(mtmp-&gt;mx, mtmp-&gt;my)
&nbsp;                &amp;&amp; mcarry &amp;&amp; canseemon(mcarry) &amp;&amp; container) {
&nbsp;                pline("%s writhes out of %s!", Amonnam(mtmp),
&nbsp;                      yname(container));
&nbsp;            } else if (container_where == OBJ_INVENT &amp;&amp; container) {
&nbsp;                Strcpy(sackname, an(xname(container)));
&nbsp;                pline("%s %s out of %s in your pack!",
&nbsp;                      Blind ? Something : Amonnam(mtmp),
&nbsp;                      locomotion(mtmp-&gt;data, "writhes"), sackname);
&nbsp;            } else if (container_where == OBJ_FLOOR &amp;&amp; container
&nbsp;                       &amp;&amp; cansee(mtmp-&gt;mx, mtmp-&gt;my)) {
&nbsp;                Strcpy(sackname, an(xname(container)));
&nbsp;                pline("%s escapes from %s!", Amonnam(mtmp), sackname);
&nbsp;            }
&nbsp;            break;
&nbsp;        }
&nbsp;        default:
&nbsp;            /* we should be able to handle the other cases... */
&nbsp;            impossible("revive_corpse: lost corpse @ %d", where);
&nbsp;            break;
&nbsp;        }
&nbsp;        return TRUE;
&nbsp;    }
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
revive_mon
&nbsp;/* Revive the corpse via a timeout. */
&nbsp;/*ARGSUSED*/
&nbsp;void
&nbsp;revive_mon(arg, timeout)
&nbsp;anything *arg;
&nbsp;long timeout UNUSED;
&nbsp;{
&nbsp;    struct obj *body = arg-&gt;a_obj;
&nbsp;    struct permonst *mptr = &amp;mons[body-&gt;corpsenm];
&nbsp;    struct monst *mtmp;
&nbsp;    xchar x, y;
&nbsp;
&nbsp;    /* corpse will revive somewhere else if there is a monster in the way;
&nbsp;       Riders get a chance to try to bump the obstacle out of their way */
&nbsp;    if ((mptr-&gt;mflags3 &amp; M3_DISPLACES) != 0 &amp;&amp; body-&gt;where == OBJ_FLOOR
&nbsp;        &amp;&amp; get_obj_location(body, &amp;x, &amp;y, 0) &amp;&amp; (mtmp = m_at(x, y)) != 0) {
&nbsp;        boolean notice_it = canseemon(mtmp); /* before rloc() */
&nbsp;        char *monname = Monnam(mtmp);
&nbsp;
&nbsp;        if (rloc(mtmp, TRUE)) {
&nbsp;            if (notice_it &amp;&amp; !canseemon(mtmp))
&nbsp;                pline("%s vanishes.", monname);
&nbsp;            else if (!notice_it &amp;&amp; canseemon(mtmp))
&nbsp;                pline("%s appears.", Monnam(mtmp)); /* not pre-rloc monname */
&nbsp;            else if (notice_it &amp;&amp; dist2(mtmp-&gt;mx, mtmp-&gt;my, x, y) &gt; 2)
&nbsp;                pline("%s teleports.", monname); /* saw it and still see it */
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    /* if we succeed, the corpse is gone */
&nbsp;    if (!revive_corpse(body)) {
&nbsp;        long when;
&nbsp;        int action;
&nbsp;
&nbsp;        if (is_rider(mptr) &amp;&amp; rn2(99)) { /* Rider usually tries again */
&nbsp;            action = REVIVE_MON;
&nbsp;            for (when = 3L; when &lt; 67L; when++)
&nbsp;                if (!rn2(3))
&nbsp;                    break;
&nbsp;        } else { /* rot this corpse away */
&nbsp;            You_feel("%sless hassled.", is_rider(mptr) ? "much " : "");
&nbsp;            action = ROT_CORPSE;
&nbsp;            when = 250L - (monstermoves - body-&gt;age);
&nbsp;            if (when &lt; 1L)
&nbsp;                when = 1L;
&nbsp;        }
&nbsp;        (void) start_timer(when, TIMER_OBJECT, action, arg);
&nbsp;    }
&nbsp;}
&nbsp;
donull
&nbsp;int
&nbsp;donull()
&nbsp;{
&nbsp;    return 1; /* Do nothing, but let other things happen */
&nbsp;}
&nbsp;
wipeoff
&nbsp;STATIC_PTR int
&nbsp;wipeoff(VOID_ARGS)
&nbsp;{
&nbsp;    if (u.ucreamed &lt; 4)
&nbsp;        u.ucreamed = 0;
&nbsp;    else
&nbsp;        u.ucreamed -= 4;
&nbsp;    if (Blinded &lt; 4)
&nbsp;        Blinded = 0;
&nbsp;    else
&nbsp;        Blinded -= 4;
&nbsp;    if (!Blinded) {
&nbsp;        pline("You've got the glop off.");
&nbsp;        u.ucreamed = 0;
&nbsp;        if (!gulp_blnd_check()) {
&nbsp;            Blinded = 1;
&nbsp;            make_blinded(0L, TRUE);
&nbsp;        }
&nbsp;        return 0;
&nbsp;    } else if (!u.ucreamed) {
&nbsp;        Your("%s feels clean now.", body_part(FACE));
&nbsp;        return 0;
&nbsp;    }
&nbsp;    return 1; /* still busy */
&nbsp;}
&nbsp;
dowipe
&nbsp;int
&nbsp;dowipe()
&nbsp;{
&nbsp;    if (u.ucreamed) {
&nbsp;        static NEARDATA char buf[39];
&nbsp;
&nbsp;        Sprintf(buf, "wiping off your %s", body_part(FACE));
&nbsp;        set_occupation(wipeoff, buf, 0);
&nbsp;        /* Not totally correct; what if they change back after now
&nbsp;         * but before they're finished wiping?
&nbsp;         */
&nbsp;        return 1;
&nbsp;    }
&nbsp;    Your("%s is already clean.", body_part(FACE));
&nbsp;    return 1;
&nbsp;}
&nbsp;
set_wounded_legs
&nbsp;void
&nbsp;set_wounded_legs(side, timex)
&nbsp;register long side;
&nbsp;register int timex;
&nbsp;{
&nbsp;    /* KMH -- STEED
&nbsp;     * If you are riding, your steed gets the wounded legs instead.
&nbsp;     * You still call this function, but don't lose hp.
&nbsp;     * Caller is also responsible for adjusting messages.
&nbsp;     */
&nbsp;
&nbsp;    if (!Wounded_legs) {
&nbsp;        ATEMP(A_DEX)--;
&nbsp;        context.botl = 1;
&nbsp;    }
&nbsp;
&nbsp;    if (!Wounded_legs || (HWounded_legs &amp; TIMEOUT))
&nbsp;        HWounded_legs = timex;
&nbsp;    EWounded_legs = side;
&nbsp;    (void) encumber_msg();
&nbsp;}
&nbsp;
heal_legs
&nbsp;void
&nbsp;heal_legs()
&nbsp;{
&nbsp;    if (Wounded_legs) {
&nbsp;        if (ATEMP(A_DEX) &lt; 0) {
&nbsp;            ATEMP(A_DEX)++;
&nbsp;            context.botl = 1;
&nbsp;        }
&nbsp;
&nbsp;        if (!u.usteed) {
&nbsp;            const char *legs = body_part(LEG);
&nbsp;
&nbsp;            if ((EWounded_legs &amp; BOTH_SIDES) == BOTH_SIDES)
&nbsp;                legs = makeplural(legs);
&nbsp;            /* this used to say "somewhat better" but that was
&nbsp;               misleading since legs are being fully healed */
&nbsp;            Your("%s %s better.", legs, vtense(legs, "feel"));
&nbsp;        }
&nbsp;
&nbsp;        HWounded_legs = EWounded_legs = 0;
&nbsp;
&nbsp;        /* Wounded_legs reduces carrying capacity, so we want
&nbsp;           an encumbrance check when they're healed.  However,
&nbsp;           while dismounting, first steed's legs get healed,
&nbsp;           then hero is dropped to floor and a new encumbrance
&nbsp;           check is made [in dismount_steed()].  So don't give
&nbsp;           encumbrance feedback during the dismount stage
&nbsp;           because it could seem to be shown out of order and
&nbsp;           it might be immediately contradicted [able to carry
&nbsp;           more when steed becomes healthy, then possible floor
&nbsp;           feedback, then able to carry less when back on foot]. */
&nbsp;        if (!in_steed_dismounting)
&nbsp;            (void) encumber_msg();
&nbsp;    }
&nbsp;}
&nbsp;
&nbsp;/*do.c*/