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

Contents

1 Top of file
2 uint_to_any
3 long_to_any
4 monst_to_any
5 obj_to_any
6 revive_nasty
7 moverock
8 still_chewing
9 movobj
10 dosinkfall
11 may_dig
12 may_passwall
13 bad_rock
14 cant_squeeze_thru
15 invocation_pos
16 test_move
17 wiz_debug_cmd_traveldisplay
18 findtravelpath
19 is_valid_travelpt
20 trapmove
21 u_rooted
22 domove
23 overexertion
24 invocation_message
25 switch_terrain
26 pooleffects
27 spoteffects
28 monstinroom
29 in_rooms
30 in_town
31 move_update
32 check_special_room
33 dopickup
34 lookaround
35 doorless_door
36 crawl_destination
37 monster_nearby
38 nomul
39 unmul
40 maybe_wail
41 losehp
42 weight_cap
43 inv_weight
44 calc_capacity
45 near_capacity
46 max_capacity
47 check_capacity
48 inv_cnt
49 money_cnt

Top of file
&nbsp;/* NetHack 3.6	hack.c	$NHDT-Date: 1518861490 2018/02/17 09:58:10 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.182 $ */
&nbsp;/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
&nbsp;/*-Copyright (c) Derek S. Ray, 2015. */
&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;/* #define DEBUG */ /* uncomment for debugging */
&nbsp;
&nbsp;STATIC_DCL void NDECL(maybe_wail);
&nbsp;STATIC_DCL int NDECL(moverock);
&nbsp;STATIC_DCL int FDECL(still_chewing, (XCHAR_P, XCHAR_P));
&nbsp;STATIC_DCL void NDECL(dosinkfall);
&nbsp;STATIC_DCL boolean FDECL(findtravelpath, (int));
&nbsp;STATIC_DCL boolean FDECL(trapmove, (int, int, struct trap *));
&nbsp;STATIC_DCL void NDECL(switch_terrain);
&nbsp;STATIC_DCL struct monst *FDECL(monstinroom, (struct permonst *, int));
&nbsp;STATIC_DCL boolean FDECL(doorless_door, (int, int));
&nbsp;STATIC_DCL void FDECL(move_update, (BOOLEAN_P));
&nbsp;
&nbsp;#define IS_SHOP(x) (rooms[x].rtype &gt;= SHOPBASE)
&nbsp;
&nbsp;/* mode values for findtravelpath() */
&nbsp;#define TRAVP_TRAVEL 0
&nbsp;#define TRAVP_GUESS  1
&nbsp;#define TRAVP_VALID  2
&nbsp;
&nbsp;static anything tmp_anything;
&nbsp;
uint_to_any
&nbsp;anything *
&nbsp;uint_to_any(ui)
&nbsp;unsigned ui;
&nbsp;{
&nbsp;    tmp_anything = zeroany;
&nbsp;    tmp_anything.a_uint = ui;
&nbsp;    return &amp;tmp_anything;
&nbsp;}
&nbsp;
long_to_any
&nbsp;anything *
&nbsp;long_to_any(lng)
&nbsp;long lng;
&nbsp;{
&nbsp;    tmp_anything = zeroany;
&nbsp;    tmp_anything.a_long = lng;
&nbsp;    return &amp;tmp_anything;
&nbsp;}
&nbsp;
monst_to_any
&nbsp;anything *
&nbsp;monst_to_any(mtmp)
&nbsp;struct monst *mtmp;
&nbsp;{
&nbsp;    tmp_anything = zeroany;
&nbsp;    tmp_anything.a_monst = mtmp;
&nbsp;    return &amp;tmp_anything;
&nbsp;}
&nbsp;
obj_to_any
&nbsp;anything *
&nbsp;obj_to_any(obj)
&nbsp;struct obj *obj;
&nbsp;{
&nbsp;    tmp_anything = zeroany;
&nbsp;    tmp_anything.a_obj = obj;
&nbsp;    return &amp;tmp_anything;
&nbsp;}
&nbsp;
revive_nasty
&nbsp;boolean
&nbsp;revive_nasty(x, y, msg)
&nbsp;int x, y;
&nbsp;const char *msg;
&nbsp;{
&nbsp;    register struct obj *otmp, *otmp2;
&nbsp;    struct monst *mtmp;
&nbsp;    coord cc;
&nbsp;    boolean revived = FALSE;
&nbsp;
&nbsp;    for (otmp = level.objects[x][y]; otmp; otmp = otmp2) {
&nbsp;        otmp2 = otmp-&gt;nexthere;
&nbsp;        if (otmp-&gt;otyp == CORPSE
&nbsp;            &amp;&amp; (is_rider(&amp;mons[otmp-&gt;corpsenm])
&nbsp;                || otmp-&gt;corpsenm == PM_WIZARD_OF_YENDOR)) {
&nbsp;            /* move any living monster already at that location */
&nbsp;            if ((mtmp = m_at(x, y)) &amp;&amp; enexto(&amp;cc, x, y, mtmp-&gt;data))
&nbsp;                rloc_to(mtmp, cc.x, cc.y);
&nbsp;            if (msg)
&nbsp;                Norep("%s", msg);
&nbsp;            revived = revive_corpse(otmp);
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    /* this location might not be safe, if not, move revived monster */
&nbsp;    if (revived) {
&nbsp;        mtmp = m_at(x, y);
&nbsp;        if (mtmp &amp;&amp; !goodpos(x, y, mtmp, 0)
&nbsp;            &amp;&amp; enexto(&amp;cc, x, y, mtmp-&gt;data)) {
&nbsp;            rloc_to(mtmp, cc.x, cc.y);
&nbsp;        }
&nbsp;        /* else impossible? */
&nbsp;    }
&nbsp;
&nbsp;    return revived;
&nbsp;}
&nbsp;
moverock
&nbsp;STATIC_OVL int
&nbsp;moverock()
&nbsp;{
&nbsp;    register xchar rx, ry, sx, sy;
&nbsp;    register struct obj *otmp;
&nbsp;    register struct trap *ttmp;
&nbsp;    register struct monst *mtmp;
&nbsp;
&nbsp;    sx = u.ux + u.dx, sy = u.uy + u.dy; /* boulder starting position */
&nbsp;    while ((otmp = sobj_at(BOULDER, sx, sy)) != 0) {
&nbsp;        /* make sure that this boulder is visible as the top object */
&nbsp;        if (otmp != level.objects[sx][sy])
&nbsp;            movobj(otmp, sx, sy);
&nbsp;
&nbsp;        rx = u.ux + 2 * u.dx; /* boulder destination position */
&nbsp;        ry = u.uy + 2 * u.dy;
&nbsp;        nomul(0);
&nbsp;        if (Levitation || Is_airlevel(&amp;u.uz)) {
&nbsp;            if (Blind)
&nbsp;                feel_location(sx, sy);
&nbsp;            You("don't have enough leverage to push %s.", the(xname(otmp)));
&nbsp;            /* Give them a chance to climb over it? */
&nbsp;            return -1;
&nbsp;        }
&nbsp;        if (verysmall(youmonst.data) &amp;&amp; !u.usteed) {
&nbsp;            if (Blind)
&nbsp;                feel_location(sx, sy);
&nbsp;            pline("You're too small to push that %s.", xname(otmp));
&nbsp;            goto cannot_push;
&nbsp;        }
&nbsp;        if (isok(rx, ry) &amp;&amp; !IS_ROCK(levl[rx][ry].typ)
&nbsp;            &amp;&amp; levl[rx][ry].typ != IRONBARS
&nbsp;            &amp;&amp; (!IS_DOOR(levl[rx][ry].typ) || !(u.dx &amp;&amp; u.dy)
&nbsp;                || doorless_door(rx, ry)) &amp;&amp; !sobj_at(BOULDER, rx, ry)) {
&nbsp;            ttmp = t_at(rx, ry);
&nbsp;            mtmp = m_at(rx, ry);
&nbsp;
&nbsp;            /* KMH -- Sokoban doesn't let you push boulders diagonally */
&nbsp;            if (Sokoban &amp;&amp; u.dx &amp;&amp; u.dy) {
&nbsp;                if (Blind)
&nbsp;                    feel_location(sx, sy);
&nbsp;                pline("%s won't roll diagonally on this %s.",
&nbsp;                      The(xname(otmp)), surface(sx, sy));
&nbsp;                goto cannot_push;
&nbsp;            }
&nbsp;
&nbsp;            if (revive_nasty(rx, ry, "You sense movement on the other side."))
&nbsp;                return -1;
&nbsp;
&nbsp;            if (mtmp &amp;&amp; !noncorporeal(mtmp-&gt;data)
&nbsp;                &amp;&amp; (!mtmp-&gt;mtrapped
&nbsp;                    || !(ttmp &amp;&amp; ((ttmp-&gt;ttyp == PIT)
&nbsp;                                  || (ttmp-&gt;ttyp == SPIKED_PIT))))) {
&nbsp;                if (Blind)
&nbsp;                    feel_location(sx, sy);
&nbsp;                if (canspotmon(mtmp)) {
&nbsp;                    pline("There's %s on the other side.", a_monnam(mtmp));
&nbsp;                } else {
&nbsp;                    You_hear("a monster behind %s.", the(xname(otmp)));
&nbsp;                    map_invisible(rx, ry);
&nbsp;                }
&nbsp;                if (flags.verbose)
&nbsp;                    pline("Perhaps that's why %s cannot move it.",
&nbsp;                          u.usteed ? y_monnam(u.usteed) : "you");
&nbsp;                goto cannot_push;
&nbsp;            }
&nbsp;
&nbsp;            if (ttmp) {
&nbsp;                /* if a trap operates on the boulder, don't attempt
&nbsp;                   to move any others at this location; return -1
&nbsp;                   if another boulder is in hero's way, or 0 if he
&nbsp;                   should advance to the vacated boulder position */
&nbsp;                switch (ttmp-&gt;ttyp) {
&nbsp;                case LANDMINE:
&nbsp;                    if (rn2(10)) {
&nbsp;                        obj_extract_self(otmp);
&nbsp;                        place_object(otmp, rx, ry);
&nbsp;                        newsym(sx, sy);
&nbsp;                        pline("KAABLAMM!!!  %s %s land mine.",
&nbsp;                              Tobjnam(otmp, "trigger"),
&nbsp;                              ttmp-&gt;madeby_u ? "your" : "a");
&nbsp;                        blow_up_landmine(ttmp);
&nbsp;                        /* if the boulder remains, it should fill the pit */
&nbsp;                        fill_pit(u.ux, u.uy);
&nbsp;                        if (cansee(rx, ry))
&nbsp;                            newsym(rx, ry);
&nbsp;                        return sobj_at(BOULDER, sx, sy) ? -1 : 0;
&nbsp;                    }
&nbsp;                    break;
&nbsp;                case SPIKED_PIT:
&nbsp;                case PIT:
&nbsp;                    obj_extract_self(otmp);
&nbsp;                    /* vision kludge to get messages right;
&nbsp;                       the pit will temporarily be seen even
&nbsp;                       if this is one among multiple boulders */
&nbsp;                    if (!Blind)
&nbsp;                        viz_array[ry][rx] |= IN_SIGHT;
&nbsp;                    if (!flooreffects(otmp, rx, ry, "fall")) {
&nbsp;                        place_object(otmp, rx, ry);
&nbsp;                    }
&nbsp;                    if (mtmp &amp;&amp; !Blind)
&nbsp;                        newsym(rx, ry);
&nbsp;                    return sobj_at(BOULDER, sx, sy) ? -1 : 0;
&nbsp;                case HOLE:
&nbsp;                case TRAPDOOR:
&nbsp;                    if (Blind)
&nbsp;                        pline("Kerplunk!  You no longer feel %s.",
&nbsp;                              the(xname(otmp)));
&nbsp;                    else
&nbsp;                        pline("%s%s and %s a %s in the %s!",
&nbsp;                              Tobjnam(otmp, (ttmp-&gt;ttyp == TRAPDOOR)
&nbsp;                                                ? "trigger"
&nbsp;                                                : "fall"),
&nbsp;                              (ttmp-&gt;ttyp == TRAPDOOR) ? "" : " into",
&nbsp;                              otense(otmp, "plug"),
&nbsp;                              (ttmp-&gt;ttyp == TRAPDOOR) ? "trap door" : "hole",
&nbsp;                              surface(rx, ry));
&nbsp;                    deltrap(ttmp);
&nbsp;                    delobj(otmp);
&nbsp;                    bury_objs(rx, ry);
&nbsp;                    levl[rx][ry].wall_info &amp;= ~W_NONDIGGABLE;
&nbsp;                    levl[rx][ry].candig = 1;
&nbsp;                    if (cansee(rx, ry))
&nbsp;                        newsym(rx, ry);
&nbsp;                    return sobj_at(BOULDER, sx, sy) ? -1 : 0;
&nbsp;                case LEVEL_TELEP:
&nbsp;                case TELEP_TRAP: {
&nbsp;                    int newlev = 0; /* lint suppression */
&nbsp;                    d_level dest;
&nbsp;
&nbsp;                    if (ttmp-&gt;ttyp == LEVEL_TELEP) {
&nbsp;                        newlev = random_teleport_level();
&nbsp;                        if (newlev == depth(&amp;u.uz) || In_endgame(&amp;u.uz))
&nbsp;                            /* trap didn't work; skip "disappears" message */
&nbsp;                            goto dopush;
&nbsp;                    }
&nbsp;                    if (u.usteed)
&nbsp;                        pline("%s pushes %s and suddenly it disappears!",
&nbsp;                              upstart(y_monnam(u.usteed)), the(xname(otmp)));
&nbsp;                    else
&nbsp;                        You("push %s and suddenly it disappears!",
&nbsp;                            the(xname(otmp)));
&nbsp;                    if (ttmp-&gt;ttyp == TELEP_TRAP) {
&nbsp;                        (void) rloco(otmp);
&nbsp;                    } else {
&nbsp;                        obj_extract_self(otmp);
&nbsp;                        add_to_migration(otmp);
&nbsp;                        get_level(&amp;dest, newlev);
&nbsp;                        otmp-&gt;ox = dest.dnum;
&nbsp;                        otmp-&gt;oy = dest.dlevel;
&nbsp;                        otmp-&gt;owornmask = (long) MIGR_RANDOM;
&nbsp;                    }
&nbsp;                    seetrap(ttmp);
&nbsp;                    return sobj_at(BOULDER, sx, sy) ? -1 : 0;
&nbsp;                }
&nbsp;                default:
&nbsp;                    break; /* boulder not affected by this trap */
&nbsp;                }
&nbsp;            }
&nbsp;
&nbsp;            if (closed_door(rx, ry))
&nbsp;                goto nopushmsg;
&nbsp;            if (boulder_hits_pool(otmp, rx, ry, TRUE))
&nbsp;                continue;
&nbsp;            /*
&nbsp;             * Re-link at top of fobj chain so that pile order is preserved
&nbsp;             * when level is restored.
&nbsp;             */
&nbsp;            if (otmp != fobj) {
&nbsp;                remove_object(otmp);
&nbsp;                place_object(otmp, otmp-&gt;ox, otmp-&gt;oy);
&nbsp;            }
&nbsp;
&nbsp;            {
&nbsp;#ifdef LINT /* static long lastmovetime; */
&nbsp;                long lastmovetime;
&nbsp;                lastmovetime = 0;
&nbsp;#else
&nbsp;                /* note: reset to zero after save/restore cycle */
&nbsp;                static NEARDATA long lastmovetime;
&nbsp;#endif
&nbsp;            dopush:
&nbsp;                if (!u.usteed) {
&nbsp;                    if (moves &gt; lastmovetime + 2 || moves &lt; lastmovetime)
&nbsp;                        pline("With %s effort you move %s.",
&nbsp;                              throws_rocks(youmonst.data) ? "little"
&nbsp;                                                          : "great",
&nbsp;                              the(xname(otmp)));
&nbsp;                    exercise(A_STR, TRUE);
&nbsp;                } else
&nbsp;                    pline("%s moves %s.", upstart(y_monnam(u.usteed)),
&nbsp;                          the(xname(otmp)));
&nbsp;                lastmovetime = moves;
&nbsp;            }
&nbsp;
&nbsp;            /* Move the boulder *after* the message. */
&nbsp;            if (glyph_is_invisible(levl[rx][ry].glyph))
&nbsp;                unmap_object(rx, ry);
&nbsp;            movobj(otmp, rx, ry); /* does newsym(rx,ry) */
&nbsp;            if (Blind) {
&nbsp;                feel_location(rx, ry);
&nbsp;                feel_location(sx, sy);
&nbsp;            } else {
&nbsp;                newsym(sx, sy);
&nbsp;            }
&nbsp;        } else {
&nbsp;        nopushmsg:
&nbsp;            if (u.usteed)
&nbsp;                pline("%s tries to move %s, but cannot.",
&nbsp;                      upstart(y_monnam(u.usteed)), the(xname(otmp)));
&nbsp;            else
&nbsp;                You("try to move %s, but in vain.", the(xname(otmp)));
&nbsp;            if (Blind)
&nbsp;                feel_location(sx, sy);
&nbsp;        cannot_push:
&nbsp;            if (throws_rocks(youmonst.data)) {
&nbsp;                boolean
&nbsp;                    canpickup = (!Sokoban
&nbsp;                                 /* similar exception as in can_lift():
&nbsp;                                    when poly'd into a giant, you can
&nbsp;                                    pick up a boulder if you have a free
&nbsp;                                    slot or into the overflow ('#') slot
&nbsp;                                    unless already carrying at least one */
&nbsp;                              &amp;&amp; (inv_cnt(FALSE) &lt; 52 || !carrying(BOULDER))),
&nbsp;                    willpickup = (canpickup &amp;&amp; autopick_testobj(otmp, TRUE));
&nbsp;
&nbsp;                if (u.usteed &amp;&amp; P_SKILL(P_RIDING) &lt; P_BASIC) {
&nbsp;                    You("aren't skilled enough to %s %s from %s.",
&nbsp;                        willpickup ? "pick up" : "push aside",
&nbsp;                        the(xname(otmp)), y_monnam(u.usteed));
&nbsp;                } else {
&nbsp;                    /*
&nbsp;                     * willpickup:  you easily pick it up
&nbsp;                     * canpickup:   you could easily pick it up
&nbsp;                     * otherwise:   you easily push it aside
&nbsp;                     */
&nbsp;                    pline("However, you %seasily %s.",
&nbsp;                          (willpickup || !canpickup) ? "" : "could ",
&nbsp;                          (willpickup || canpickup) ? "pick it up"
&nbsp;                                                    : "push it aside");
&nbsp;                    sokoban_guilt();
&nbsp;                    break;
&nbsp;                }
&nbsp;                break;
&nbsp;            }
&nbsp;
&nbsp;            if (!u.usteed
&nbsp;                &amp;&amp; (((!invent || inv_weight() &lt;= -850)
&nbsp;                     &amp;&amp; (!u.dx || !u.dy || (IS_ROCK(levl[u.ux][sy].typ)
&nbsp;                                            &amp;&amp; IS_ROCK(levl[sx][u.uy].typ))))
&nbsp;                    || verysmall(youmonst.data))) {
&nbsp;                pline(
&nbsp;                   "However, you can squeeze yourself into a small opening.");
&nbsp;                sokoban_guilt();
&nbsp;                break;
&nbsp;            } else
&nbsp;                return -1;
&nbsp;        }
&nbsp;    }
&nbsp;    return 0;
&nbsp;}
&nbsp;
still_chewing
&nbsp;/*
&nbsp; *  still_chewing()
&nbsp; *
&nbsp; *  Chew on a wall, door, or boulder.  Returns TRUE if still eating, FALSE
&nbsp; *  when done.
&nbsp; */
&nbsp;STATIC_OVL int
&nbsp;still_chewing(x, y)
&nbsp;xchar x, y;
&nbsp;{
&nbsp;    struct rm *lev = &amp;levl[x][y];
&nbsp;    struct obj *boulder = sobj_at(BOULDER, x, y);
&nbsp;    const char *digtxt = (char *) 0, *dmgtxt = (char *) 0;
&nbsp;
&nbsp;    if (context.digging.down) /* not continuing previous dig (w/ pick-axe) */
&nbsp;        (void) memset((genericptr_t) &amp;context.digging, 0,
&nbsp;                      sizeof (struct dig_info));
&nbsp;
&nbsp;    if (!boulder &amp;&amp; IS_ROCK(lev-&gt;typ) &amp;&amp; !may_dig(x, y)) {
&nbsp;        You("hurt your teeth on the %s.",
&nbsp;            (lev-&gt;typ == IRONBARS)
&nbsp;                ? "bars"
&nbsp;                : IS_TREE(lev-&gt;typ)
&nbsp;                    ? "tree"
&nbsp;                    : "hard stone");
&nbsp;        nomul(0);
&nbsp;        return 1;
&nbsp;    } else if (context.digging.pos.x != x || context.digging.pos.y != y
&nbsp;               || !on_level(&amp;context.digging.level, &amp;u.uz)) {
&nbsp;        context.digging.down = FALSE;
&nbsp;        context.digging.chew = TRUE;
&nbsp;        context.digging.warned = FALSE;
&nbsp;        context.digging.pos.x = x;
&nbsp;        context.digging.pos.y = y;
&nbsp;        assign_level(&amp;context.digging.level, &amp;u.uz);
&nbsp;        /* solid rock takes more work &amp; time to dig through */
&nbsp;        context.digging.effort =
&nbsp;            (IS_ROCK(lev-&gt;typ) &amp;&amp; !IS_TREE(lev-&gt;typ) ? 30 : 60) + u.udaminc;
&nbsp;        You("start chewing %s %s.",
&nbsp;            (boulder || IS_TREE(lev-&gt;typ) || lev-&gt;typ == IRONBARS)
&nbsp;                ? "on a"
&nbsp;                : "a hole in the",
&nbsp;            boulder
&nbsp;                ? "boulder"
&nbsp;                : IS_TREE(lev-&gt;typ)
&nbsp;                    ? "tree"
&nbsp;                    : IS_ROCK(lev-&gt;typ)
&nbsp;                        ? "rock"
&nbsp;                        : (lev-&gt;typ == IRONBARS)
&nbsp;                            ? "bar"
&nbsp;                            : "door");
&nbsp;        watch_dig((struct monst *) 0, x, y, FALSE);
&nbsp;        return 1;
&nbsp;    } else if ((context.digging.effort += (30 + u.udaminc)) &lt;= 100) {
&nbsp;        if (flags.verbose)
&nbsp;            You("%s chewing on the %s.",
&nbsp;                context.digging.chew ? "continue" : "begin",
&nbsp;                boulder
&nbsp;                    ? "boulder"
&nbsp;                    : IS_TREE(lev-&gt;typ)
&nbsp;                        ? "tree"
&nbsp;                        : IS_ROCK(lev-&gt;typ)
&nbsp;                            ? "rock"
&nbsp;                            : (lev-&gt;typ == IRONBARS)
&nbsp;                                ? "bars"
&nbsp;                                : "door");
&nbsp;        context.digging.chew = TRUE;
&nbsp;        watch_dig((struct monst *) 0, x, y, FALSE);
&nbsp;        return 1;
&nbsp;    }
&nbsp;
&nbsp;    /* Okay, you've chewed through something */
&nbsp;    u.uconduct.food++;
&nbsp;    u.uhunger += rnd(20);
&nbsp;
&nbsp;    if (boulder) {
&nbsp;        delobj(boulder);         /* boulder goes bye-bye */
&nbsp;        You("eat the boulder."); /* yum */
&nbsp;
&nbsp;        /*
&nbsp;         *  The location could still block because of
&nbsp;         *      1. More than one boulder
&nbsp;         *      2. Boulder stuck in a wall/stone/door.
&nbsp;         *
&nbsp;         *  [perhaps use does_block() below (from vision.c)]
&nbsp;         */
&nbsp;        if (IS_ROCK(lev-&gt;typ) || closed_door(x, y)
&nbsp;            || sobj_at(BOULDER, x, y)) {
&nbsp;            block_point(x, y); /* delobj will unblock the point */
&nbsp;            /* reset dig state */
&nbsp;            (void) memset((genericptr_t) &amp;context.digging, 0,
&nbsp;                          sizeof (struct dig_info));
&nbsp;            return 1;
&nbsp;        }
&nbsp;
&nbsp;    } else if (IS_WALL(lev-&gt;typ)) {
&nbsp;        if (*in_rooms(x, y, SHOPBASE)) {
&nbsp;            add_damage(x, y, SHOP_WALL_DMG);
&nbsp;            dmgtxt = "damage";
&nbsp;        }
&nbsp;        digtxt = "chew a hole in the wall.";
&nbsp;        if (level.flags.is_maze_lev) {
&nbsp;            lev-&gt;typ = ROOM;
&nbsp;        } else if (level.flags.is_cavernous_lev &amp;&amp; !in_town(x, y)) {
&nbsp;            lev-&gt;typ = CORR;
&nbsp;        } else {
&nbsp;            lev-&gt;typ = DOOR;
&nbsp;            lev-&gt;doormask = D_NODOOR;
&nbsp;        }
&nbsp;    } else if (IS_TREE(lev-&gt;typ)) {
&nbsp;        digtxt = "chew through the tree.";
&nbsp;        lev-&gt;typ = ROOM;
&nbsp;    } else if (lev-&gt;typ == IRONBARS) {
&nbsp;        digtxt = "eat through the bars.";
&nbsp;        dissolve_bars(x, y);
&nbsp;    } else if (lev-&gt;typ == SDOOR) {
&nbsp;        if (lev-&gt;doormask &amp; D_TRAPPED) {
&nbsp;            lev-&gt;doormask = D_NODOOR;
&nbsp;            b_trapped("secret door", 0);
&nbsp;        } else {
&nbsp;            digtxt = "chew through the secret door.";
&nbsp;            lev-&gt;doormask = D_BROKEN;
&nbsp;        }
&nbsp;        lev-&gt;typ = DOOR;
&nbsp;
&nbsp;    } else if (IS_DOOR(lev-&gt;typ)) {
&nbsp;        if (*in_rooms(x, y, SHOPBASE)) {
&nbsp;            add_damage(x, y, SHOP_DOOR_COST);
&nbsp;            dmgtxt = "break";
&nbsp;        }
&nbsp;        if (lev-&gt;doormask &amp; D_TRAPPED) {
&nbsp;            lev-&gt;doormask = D_NODOOR;
&nbsp;            b_trapped("door", 0);
&nbsp;        } else {
&nbsp;            digtxt = "chew through the door.";
&nbsp;            lev-&gt;doormask = D_BROKEN;
&nbsp;        }
&nbsp;
&nbsp;    } else { /* STONE or SCORR */
&nbsp;        digtxt = "chew a passage through the rock.";
&nbsp;        lev-&gt;typ = CORR;
&nbsp;    }
&nbsp;
&nbsp;    unblock_point(x, y); /* vision */
&nbsp;    newsym(x, y);
&nbsp;    if (digtxt)
&nbsp;        You1(digtxt); /* after newsym */
&nbsp;    if (dmgtxt)
&nbsp;        pay_for_damage(dmgtxt, FALSE);
&nbsp;    (void) memset((genericptr_t) &amp;context.digging, 0,
&nbsp;                  sizeof (struct dig_info));
&nbsp;    return 0;
&nbsp;}
&nbsp;
movobj
&nbsp;void
&nbsp;movobj(obj, ox, oy)
&nbsp;register struct obj *obj;
&nbsp;register xchar ox, oy;
&nbsp;{
&nbsp;    /* optimize by leaving on the fobj chain? */
&nbsp;    remove_object(obj);
&nbsp;    newsym(obj-&gt;ox, obj-&gt;oy);
&nbsp;    place_object(obj, ox, oy);
&nbsp;    newsym(ox, oy);
&nbsp;}
&nbsp;
&nbsp;static NEARDATA const char fell_on_sink[] = "fell onto a sink";
&nbsp;
dosinkfall
&nbsp;STATIC_OVL void
&nbsp;dosinkfall()
&nbsp;{
&nbsp;    register struct obj *obj;
&nbsp;    int dmg;
&nbsp;    boolean lev_boots = (uarmf &amp;&amp; uarmf-&gt;otyp == LEVITATION_BOOTS),
&nbsp;            innate_lev = ((HLevitation &amp; (FROMOUTSIDE | FROMFORM)) != 0L),
&nbsp;            ufall = (!innate_lev &amp;&amp; !(HFlying || EFlying)); /* BFlying */
&nbsp;
&nbsp;    if (!ufall) {
&nbsp;        You(innate_lev ? "wobble unsteadily for a moment."
&nbsp;                       : "gain control of your flight.");
&nbsp;    } else {
&nbsp;        long save_ELev = ELevitation, save_HLev = HLevitation;
&nbsp;
&nbsp;        /* fake removal of levitation in advance so that final
&nbsp;           disclosure will be right in case this turns out to
&nbsp;           be fatal; fortunately the fact that rings and boots
&nbsp;           are really still worn has no effect on bones data */
&nbsp;        ELevitation = HLevitation = 0L;
&nbsp;        You("crash to the floor!");
&nbsp;        dmg = rn1(8, 25 - (int) ACURR(A_CON));
&nbsp;        losehp(Maybe_Half_Phys(dmg), fell_on_sink, NO_KILLER_PREFIX);
&nbsp;        exercise(A_DEX, FALSE);
&nbsp;        selftouch("Falling, you");
&nbsp;        for (obj = level.objects[u.ux][u.uy]; obj; obj = obj-&gt;nexthere)
&nbsp;            if (obj-&gt;oclass == WEAPON_CLASS || is_weptool(obj)) {
&nbsp;                You("fell on %s.", doname(obj));
&nbsp;                losehp(Maybe_Half_Phys(rnd(3)), fell_on_sink,
&nbsp;                       NO_KILLER_PREFIX);
&nbsp;                exercise(A_CON, FALSE);
&nbsp;            }
&nbsp;        ELevitation = save_ELev;
&nbsp;        HLevitation = save_HLev;
&nbsp;    }
&nbsp;
&nbsp;    /*
&nbsp;     * Interrupt multi-turn putting on/taking off of armor (in which
&nbsp;     * case we reached the sink due to being teleported while busy;
&nbsp;     * in 3.4.3, Boots_on()/Boots_off() [called via (*afternmv)() when
&nbsp;     * 'multi' reaches 0] triggered a crash if we were donning/doffing
&nbsp;     * levitation boots [because the Boots_off() below causes 'uarmf'
&nbsp;     * to be null by the time 'afternmv' gets called]).
&nbsp;     *
&nbsp;     * Interrupt donning/doffing if we fall onto the sink, or if the
&nbsp;     * code below is going to remove levitation boots even when we
&nbsp;     * haven't fallen (innate floating or flying becoming unblocked).
&nbsp;     */
&nbsp;    if (ufall || lev_boots) {
&nbsp;        (void) stop_donning(lev_boots ? uarmf : (struct obj *) 0);
&nbsp;        /* recalculate in case uarmf just got set to null */
&nbsp;        lev_boots = (uarmf &amp;&amp; uarmf-&gt;otyp == LEVITATION_BOOTS);
&nbsp;    }
&nbsp;
&nbsp;    /* remove worn levitation items */
&nbsp;    ELevitation &amp;= ~W_ARTI;
&nbsp;    HLevitation &amp;= ~(I_SPECIAL | TIMEOUT);
&nbsp;    HLevitation++;
&nbsp;    if (uleft &amp;&amp; uleft-&gt;otyp == RIN_LEVITATION) {
&nbsp;        obj = uleft;
&nbsp;        Ring_off(obj);
&nbsp;        off_msg(obj);
&nbsp;    }
&nbsp;    if (uright &amp;&amp; uright-&gt;otyp == RIN_LEVITATION) {
&nbsp;        obj = uright;
&nbsp;        Ring_off(obj);
&nbsp;        off_msg(obj);
&nbsp;    }
&nbsp;    if (lev_boots) {
&nbsp;        obj = uarmf;
&nbsp;        (void) Boots_off();
&nbsp;        off_msg(obj);
&nbsp;    }
&nbsp;    HLevitation--;
&nbsp;    /* probably moot; we're either still levitating or went
&nbsp;       through float_down(), but make sure BFlying is up to date */
&nbsp;    float_vs_flight();
&nbsp;}
&nbsp;
may_dig
&nbsp;/* intended to be called only on ROCKs or TREEs */
&nbsp;boolean
&nbsp;may_dig(x, y)
&nbsp;register xchar x, y;
&nbsp;{
&nbsp;    struct rm *lev = &amp;levl[x][y];
&nbsp;
&nbsp;    return (boolean) !((IS_STWALL(lev-&gt;typ) || IS_TREE(lev-&gt;typ))
&nbsp;                       &amp;&amp; (lev-&gt;wall_info &amp; W_NONDIGGABLE));
&nbsp;}
&nbsp;
may_passwall
&nbsp;boolean
&nbsp;may_passwall(x, y)
&nbsp;register xchar x, y;
&nbsp;{
&nbsp;    return (boolean) !(IS_STWALL(levl[x][y].typ)
&nbsp;                       &amp;&amp; (levl[x][y].wall_info &amp; W_NONPASSWALL));
&nbsp;}
&nbsp;
bad_rock
&nbsp;boolean
&nbsp;bad_rock(mdat, x, y)
&nbsp;struct permonst *mdat;
&nbsp;register xchar x, y;
&nbsp;{
&nbsp;    return (boolean) ((Sokoban &amp;&amp; sobj_at(BOULDER, x, y))
&nbsp;                      || (IS_ROCK(levl[x][y].typ)
&nbsp;                          &amp;&amp; (!tunnels(mdat) || needspick(mdat)
&nbsp;                              || !may_dig(x, y))
&nbsp;                          &amp;&amp; !(passes_walls(mdat) &amp;&amp; may_passwall(x, y))));
&nbsp;}
&nbsp;
cant_squeeze_thru
&nbsp;/* caller has already decided that it's a tight diagonal; check whether a
&nbsp;   monster--who might be the hero--can fit through, and if not then return
&nbsp;   the reason why:  1: can't fit, 2: possessions won't fit, 3: sokoban
&nbsp;   returns 0 if we can squeeze through */
&nbsp;int
&nbsp;cant_squeeze_thru(mon)
&nbsp;struct monst *mon;
&nbsp;{
&nbsp;    int amt;
&nbsp;    struct permonst *ptr = mon-&gt;data;
&nbsp;
&nbsp;    /* too big? */
&nbsp;    if (bigmonst(ptr)
&nbsp;        &amp;&amp; !(amorphous(ptr) || is_whirly(ptr) || noncorporeal(ptr)
&nbsp;             || slithy(ptr) || can_fog(mon)))
&nbsp;        return 1;
&nbsp;
&nbsp;    /* lugging too much junk? */
&nbsp;    amt = (mon == &amp;youmonst) ? inv_weight() + weight_cap()
&nbsp;                             : curr_mon_load(mon);
&nbsp;    if (amt &gt; 600)
&nbsp;        return 2;
&nbsp;
&nbsp;    /* Sokoban restriction applies to hero only */
&nbsp;    if (mon == &amp;youmonst &amp;&amp; Sokoban)
&nbsp;        return 3;
&nbsp;
&nbsp;    /* can squeeze through */
&nbsp;    return 0;
&nbsp;}
&nbsp;
invocation_pos
&nbsp;boolean
&nbsp;invocation_pos(x, y)
&nbsp;xchar x, y;
&nbsp;{
&nbsp;    return (boolean) (Invocation_lev(&amp;u.uz)
&nbsp;                      &amp;&amp; x == inv_pos.x &amp;&amp; y == inv_pos.y);
&nbsp;}
&nbsp;
test_move
&nbsp;/* return TRUE if (dx,dy) is an OK place to move
&nbsp; * mode is one of DO_MOVE, TEST_MOVE, TEST_TRAV, or TEST_TRAP
&nbsp; */
&nbsp;boolean
&nbsp;test_move(ux, uy, dx, dy, mode)
&nbsp;int ux, uy, dx, dy;
&nbsp;int mode;
&nbsp;{
&nbsp;    int x = ux + dx;
&nbsp;    int y = uy + dy;
&nbsp;    register struct rm *tmpr = &amp;levl[x][y];
&nbsp;    register struct rm *ust;
&nbsp;
&nbsp;    context.door_opened = FALSE;
&nbsp;    /*
&nbsp;     *  Check for physical obstacles.  First, the place we are going.
&nbsp;     */
&nbsp;    if (IS_ROCK(tmpr-&gt;typ) || tmpr-&gt;typ == IRONBARS) {
&nbsp;        if (Blind &amp;&amp; mode == DO_MOVE)
&nbsp;            feel_location(x, y);
&nbsp;        if (Passes_walls &amp;&amp; may_passwall(x, y)) {
&nbsp;            ; /* do nothing */
&nbsp;        } else if (Underwater) {
&nbsp;            /* note: if water_friction() changes direction due to
&nbsp;               turbulence, new target destination will always be water,
&nbsp;               so we won't get here, hence don't need to worry about
&nbsp;               "there" being somewhere the player isn't sure of */
&nbsp;            if (mode == DO_MOVE)
&nbsp;                pline("There is an obstacle there.");
&nbsp;            return FALSE;
&nbsp;        } else if (tmpr-&gt;typ == IRONBARS) {
&nbsp;            if ((dmgtype(youmonst.data, AD_RUST)
&nbsp;                 || dmgtype(youmonst.data, AD_CORR)) &amp;&amp; mode == DO_MOVE
&nbsp;                &amp;&amp; still_chewing(x, y)) {
&nbsp;                return FALSE;
&nbsp;            }
&nbsp;            if (!(Passes_walls || passes_bars(youmonst.data))) {
&nbsp;                if (mode == DO_MOVE &amp;&amp; iflags.mention_walls)
&nbsp;                    You("cannot pass through the bars.");
&nbsp;                return FALSE;
&nbsp;            }
&nbsp;        } else if (tunnels(youmonst.data) &amp;&amp; !needspick(youmonst.data)) {
&nbsp;            /* Eat the rock. */
&nbsp;            if (mode == DO_MOVE &amp;&amp; still_chewing(x, y))
&nbsp;                return FALSE;
&nbsp;        } else if (flags.autodig &amp;&amp; !context.run &amp;&amp; !context.nopick &amp;&amp; uwep
&nbsp;                   &amp;&amp; is_pick(uwep)) {
&nbsp;            /* MRKR: Automatic digging when wielding the appropriate tool */
&nbsp;            if (mode == DO_MOVE)
&nbsp;                (void) use_pick_axe2(uwep);
&nbsp;            return FALSE;
&nbsp;        } else {
&nbsp;            if (mode == DO_MOVE) {
&nbsp;                if (is_db_wall(x, y))
&nbsp;                    pline("That drawbridge is up!");
&nbsp;                /* sokoban restriction stays even after puzzle is solved */
&nbsp;                else if (Passes_walls &amp;&amp; !may_passwall(x, y)
&nbsp;                         &amp;&amp; In_sokoban(&amp;u.uz))
&nbsp;                    pline_The("Sokoban walls resist your ability.");
&nbsp;                else if (iflags.mention_walls)
&nbsp;                    pline("It's %s.",
&nbsp;                          (IS_WALL(tmpr-&gt;typ) || tmpr-&gt;typ == SDOOR) ? "a wall"
&nbsp;                          : IS_TREE(tmpr-&gt;typ) ? "a tree"
&nbsp;                          : "solid stone");
&nbsp;            }
&nbsp;            return FALSE;
&nbsp;        }
&nbsp;    } else if (IS_DOOR(tmpr-&gt;typ)) {
&nbsp;        if (closed_door(x, y)) {
&nbsp;            if (Blind &amp;&amp; mode == DO_MOVE)
&nbsp;                feel_location(x, y);
&nbsp;            if (Passes_walls) {
&nbsp;                ; /* do nothing */
&nbsp;            } else if (can_ooze(&amp;youmonst)) {
&nbsp;                if (mode == DO_MOVE)
&nbsp;                    You("ooze under the door.");
&nbsp;            } else if (Underwater) {
&nbsp;                if (mode == DO_MOVE)
&nbsp;                    pline("There is an obstacle there.");
&nbsp;                return FALSE;
&nbsp;            } else if (tunnels(youmonst.data) &amp;&amp; !needspick(youmonst.data)) {
&nbsp;                /* Eat the door. */
&nbsp;                if (mode == DO_MOVE &amp;&amp; still_chewing(x, y))
&nbsp;                    return FALSE;
&nbsp;            } else {
&nbsp;                if (mode == DO_MOVE) {
&nbsp;                    if (amorphous(youmonst.data))
&nbsp;                        You(
&nbsp;   "try to ooze under the door, but can't squeeze your possessions through.");
&nbsp;                    if (flags.autoopen &amp;&amp; !context.run &amp;&amp; !Confusion
&nbsp;                        &amp;&amp; !Stunned &amp;&amp; !Fumbling) {
&nbsp;                        context.door_opened = context.move =
&nbsp;                            doopen_indir(x, y);
&nbsp;                    } else if (x == ux || y == uy) {
&nbsp;                        if (Blind || Stunned || ACURR(A_DEX) &lt; 10
&nbsp;                            || Fumbling) {
&nbsp;                            if (u.usteed) {
&nbsp;                                You_cant("lead %s through that closed door.",
&nbsp;                                         y_monnam(u.usteed));
&nbsp;                            } else {
&nbsp;                                pline("Ouch!  You bump into a door.");
&nbsp;                                exercise(A_DEX, FALSE);
&nbsp;                            }
&nbsp;                        } else
&nbsp;                            pline("That door is closed.");
&nbsp;                    }
&nbsp;                } else if (mode == TEST_TRAV || mode == TEST_TRAP)
&nbsp;                    goto testdiag;
&nbsp;                return FALSE;
&nbsp;            }
&nbsp;        } else {
&nbsp;        testdiag:
&nbsp;            if (dx &amp;&amp; dy &amp;&amp; !Passes_walls
&nbsp;                &amp;&amp; (!doorless_door(x, y) || block_door(x, y))) {
&nbsp;                /* Diagonal moves into a door are not allowed. */
&nbsp;                if (mode == DO_MOVE) {
&nbsp;                    if (Blind)
&nbsp;                        feel_location(x, y);
&nbsp;                    if (Underwater || iflags.mention_walls)
&nbsp;                        You_cant("move diagonally into an intact doorway.");
&nbsp;                }
&nbsp;                return FALSE;
&nbsp;            }
&nbsp;        }
&nbsp;    }
&nbsp;    if (dx &amp;&amp; dy &amp;&amp; bad_rock(youmonst.data, ux, y)
&nbsp;        &amp;&amp; bad_rock(youmonst.data, x, uy)) {
&nbsp;        /* Move at a diagonal. */
&nbsp;        switch (cant_squeeze_thru(&amp;youmonst)) {
&nbsp;        case 3:
&nbsp;            if (mode == DO_MOVE)
&nbsp;                You("cannot pass that way.");
&nbsp;            return FALSE;
&nbsp;        case 2:
&nbsp;            if (mode == DO_MOVE)
&nbsp;                You("are carrying too much to get through.");
&nbsp;            return FALSE;
&nbsp;        case 1:
&nbsp;            if (mode == DO_MOVE)
&nbsp;                Your("body is too large to fit through.");
&nbsp;            return FALSE;
&nbsp;        default:
&nbsp;            break; /* can squeeze through */
&nbsp;        }
&nbsp;    } else if (dx &amp;&amp; dy &amp;&amp; worm_cross(ux, uy, x, y)) {
&nbsp;        /* consecutive long worm segments are at 

<ux,y> and <x,uy> */
&nbsp;        if (mode == DO_MOVE)
&nbsp;            pline("%s is in your way.", Monnam(m_at(ux, y)));
&nbsp;        return FALSE;
&nbsp;    }
&nbsp;    /* Pick travel path that does not require crossing a trap.
&nbsp;     * Avoid water and lava using the usual running rules.
&nbsp;     * (but not u.ux/u.uy because findtravelpath walks toward u.ux/u.uy) */
&nbsp;    if (context.run == 8 &amp;&amp; (mode != DO_MOVE)
&nbsp;        &amp;&amp; (x != u.ux || y != u.uy)) {
&nbsp;        struct trap *t = t_at(x, y);
&nbsp;
&nbsp;        if ((t &amp;&amp; t-&gt;tseen)
&nbsp;            || (!Levitation &amp;&amp; !Flying &amp;&amp; !is_clinger(youmonst.data)
&nbsp;                &amp;&amp; is_pool_or_lava(x, y) &amp;&amp; levl[x][y].seenv))
&nbsp;            return (mode == TEST_TRAP);
&nbsp;    }
&nbsp;
&nbsp;    if (mode == TEST_TRAP)
&nbsp;        return FALSE; /* do not move through traps */
&nbsp;
&nbsp;    ust = &amp;levl[ux][uy];
&nbsp;
&nbsp;    /* Now see if other things block our way . . */
&nbsp;    if (dx &amp;&amp; dy &amp;&amp; !Passes_walls &amp;&amp; IS_DOOR(ust-&gt;typ)
&nbsp;        &amp;&amp; (!doorless_door(ux, uy) || block_entry(x, y))) {
&nbsp;        /* Can't move at a diagonal out of a doorway with door. */
&nbsp;        if (mode == DO_MOVE &amp;&amp; iflags.mention_walls)
&nbsp;            You_cant("move diagonally out of an intact doorway.");
&nbsp;        return FALSE;
&nbsp;    }
&nbsp;
&nbsp;    if (sobj_at(BOULDER, x, y) &amp;&amp; (Sokoban || !Passes_walls)) {
&nbsp;        if (!(Blind || Hallucination) &amp;&amp; (context.run &gt;= 2)
&nbsp;            &amp;&amp; mode != TEST_TRAV) {
&nbsp;            if (mode == DO_MOVE &amp;&amp; iflags.mention_walls)
&nbsp;                pline("A boulder blocks your path.");
&nbsp;            return FALSE;
&nbsp;        }
&nbsp;        if (mode == DO_MOVE) {
&nbsp;            /* tunneling monsters will chew before pushing */
&nbsp;            if (tunnels(youmonst.data) &amp;&amp; !needspick(youmonst.data)
&nbsp;                &amp;&amp; !Sokoban) {
&nbsp;                if (still_chewing(x, y))
&nbsp;                    return FALSE;
&nbsp;            } else if (moverock() &lt; 0)
&nbsp;                return FALSE;
&nbsp;        } else if (mode == TEST_TRAV) {
&nbsp;            struct obj *obj;
&nbsp;
&nbsp;            /* never travel through boulders in Sokoban */
&nbsp;            if (Sokoban)
&nbsp;                return FALSE;
&nbsp;
&nbsp;            /* don't pick two boulders in a row, unless there's a way thru */
&nbsp;            if (sobj_at(BOULDER, ux, uy) &amp;&amp; !Sokoban) {
&nbsp;                if (!Passes_walls
&nbsp;                    &amp;&amp; !(tunnels(youmonst.data) &amp;&amp; !needspick(youmonst.data))
&nbsp;                    &amp;&amp; !carrying(PICK_AXE) &amp;&amp; !carrying(DWARVISH_MATTOCK)
&nbsp;                    &amp;&amp; !((obj = carrying(WAN_DIGGING))
&nbsp;                         &amp;&amp; !objects[obj-&gt;otyp].oc_name_known))
&nbsp;                    return FALSE;
&nbsp;            }
&nbsp;        }
&nbsp;        /* assume you'll be able to push it when you get there... */
&nbsp;    }
&nbsp;
&nbsp;    /* OK, it is a legal place to move. */
&nbsp;    return TRUE;
&nbsp;}
&nbsp;
&nbsp;#ifdef DEBUG
&nbsp;static boolean trav_debug = FALSE;
&nbsp;
wiz_debug_cmd_traveldisplay
&nbsp;/* in this case, toggle display of travel debug info */
&nbsp;int wiz_debug_cmd_traveldisplay()
&nbsp;{
&nbsp;    trav_debug = !trav_debug;
&nbsp;    return 0;
&nbsp;}
&nbsp;#endif /* DEBUG */
&nbsp;
findtravelpath
&nbsp;/*
&nbsp; * Find a path from the destination (u.tx,u.ty) back to (u.ux,u.uy).
&nbsp; * A shortest path is returned.  If guess is TRUE, consider various
&nbsp; * inaccessible locations as valid intermediate path points.
&nbsp; * Returns TRUE if a path was found.
&nbsp; */
&nbsp;STATIC_OVL boolean
&nbsp;findtravelpath(mode)
&nbsp;int mode;
&nbsp;{
&nbsp;    /* if travel to adjacent, reachable location, use normal movement rules */
&nbsp;    if ((mode == TRAVP_TRAVEL || mode == TRAVP_VALID) &amp;&amp; context.travel1
&nbsp;        &amp;&amp; distmin(u.ux, u.uy, u.tx, u.ty) == 1
&nbsp;        &amp;&amp; !(u.ux != u.tx &amp;&amp; u.uy != u.ty &amp;&amp; NODIAG(u.umonnum))) {
&nbsp;        context.run = 0;
&nbsp;        if (test_move(u.ux, u.uy, u.tx - u.ux, u.ty - u.uy, TEST_MOVE)) {
&nbsp;            if (mode == TRAVP_TRAVEL) {
&nbsp;                u.dx = u.tx - u.ux;
&nbsp;                u.dy = u.ty - u.uy;
&nbsp;                nomul(0);
&nbsp;                iflags.travelcc.x = iflags.travelcc.y = -1;
&nbsp;            }
&nbsp;            return TRUE;
&nbsp;        }
&nbsp;        if (mode == TRAVP_TRAVEL)
&nbsp;            context.run = 8;
&nbsp;    }
&nbsp;    if (u.tx != u.ux || u.ty != u.uy) {
&nbsp;        xchar travel[COLNO][ROWNO];
&nbsp;        xchar travelstepx[2][COLNO * ROWNO];
&nbsp;        xchar travelstepy[2][COLNO * ROWNO];
&nbsp;        xchar tx, ty, ux, uy;
&nbsp;        int n = 1;      /* max offset in travelsteps */
&nbsp;        int set = 0;    /* two sets current and previous */
&nbsp;        int radius = 1; /* search radius */
&nbsp;        int i;
&nbsp;
&nbsp;        /* If guessing, first find an "obvious" goal location.  The obvious
&nbsp;         * goal is the position the player knows of, or might figure out
&nbsp;         * (couldsee) that is closest to the target on a straight path.
&nbsp;         */
&nbsp;        if (mode == TRAVP_GUESS || mode == TRAVP_VALID) {
&nbsp;            tx = u.ux;
&nbsp;            ty = u.uy;
&nbsp;            ux = u.tx;
&nbsp;            uy = u.ty;
&nbsp;        } else {
&nbsp;            tx = u.tx;
&nbsp;            ty = u.ty;
&nbsp;            ux = u.ux;
&nbsp;            uy = u.uy;
&nbsp;        }
&nbsp;
&nbsp;    noguess:
&nbsp;        (void) memset((genericptr_t) travel, 0, sizeof(travel));
&nbsp;        travelstepx[0][0] = tx;
&nbsp;        travelstepy[0][0] = ty;
&nbsp;
&nbsp;        while (n != 0) {
&nbsp;            int nn = 0;
&nbsp;
&nbsp;            for (i = 0; i &lt; n; i++) {
&nbsp;                int dir;
&nbsp;                int x = travelstepx[set][i];
&nbsp;                int y = travelstepy[set][i];
&nbsp;                static int ordered[] = { 0, 2, 4, 6, 1, 3, 5, 7 };
&nbsp;                /* no diagonal movement for grid bugs */
&nbsp;                int dirmax = NODIAG(u.umonnum) ? 4 : 8;
&nbsp;                boolean alreadyrepeated = FALSE;
&nbsp;
&nbsp;                for (dir = 0; dir &lt; dirmax; ++dir) {
&nbsp;                    int nx = x + xdir[ordered[dir]];
&nbsp;                    int ny = y + ydir[ordered[dir]];
&nbsp;
&nbsp;                    /*
&nbsp;                     * When guessing and trying to travel as close as possible
&nbsp;                     * to an unreachable target space, don't include spaces
&nbsp;                     * that would never be picked as a guessed target in the
&nbsp;                     * travel matrix describing hero-reachable spaces.
&nbsp;                     * This stops travel from getting confused and moving
&nbsp;                     * the hero back and forth in certain degenerate
&nbsp;                     * configurations of sight-blocking obstacles, e.g.
&nbsp;                     *
&nbsp;                     *  T         1. Dig this out and carry enough to not be
&nbsp;                     *   ####       able to squeeze through diagonal gaps.
&nbsp;                     *   #--.---    Stand at @ and target travel at space T.
&nbsp;                     *    @.....
&nbsp;                     *    |.....
&nbsp;                     *
&nbsp;                     *  T         2. couldsee() marks spaces marked a and x
&nbsp;                     *   ####       as eligible guess spaces to move the hero
&nbsp;                     *   a--.---    towards.  Space a is closest to T, so it
&nbsp;                     *    @xxxxx    gets chosen.  Travel system moves @ right
&nbsp;                     *    |xxxxx    to travel to space a.
&nbsp;                     *
&nbsp;                     *  T         3. couldsee() marks spaces marked b, c and x
&nbsp;                     *   ####       as eligible guess spaces to move the hero
&nbsp;                     *   a--c---    towards.  Since findtravelpath() is called
&nbsp;                     *    b@xxxx    repeatedly during travel, it doesn't
&nbsp;                     *    |xxxxx    remember that it wanted to go to space a,
&nbsp;                     *              so in comparing spaces b and c, b is
&nbsp;                     *              chosen, since it seems like the closest
&nbsp;                     *              eligible space to T. Travel system moves @
&nbsp;                     *              left to go to space b.
&nbsp;                     *
&nbsp;                     *            4. Go to 2.
&nbsp;                     *
&nbsp;                     * By limiting the travel matrix here, space a in the
&nbsp;                     * example above is never included in it, preventing
&nbsp;                     * the cycle.
&nbsp;                     */
&nbsp;                    if (!isok(nx, ny)
&nbsp;                        || ((mode == TRAVP_GUESS) &amp;&amp; !couldsee(nx, ny)))
&nbsp;                        continue;
&nbsp;                    if ((!Passes_walls &amp;&amp; !can_ooze(&amp;youmonst)
&nbsp;                         &amp;&amp; closed_door(x, y)) || sobj_at(BOULDER, x, y)
&nbsp;                        || test_move(x, y, nx-x, ny-y, TEST_TRAP)) {
&nbsp;                        /* closed doors and boulders usually
&nbsp;                         * cause a delay, so prefer another path */
&nbsp;                        if (travel[x][y] &gt; radius - 3) {
&nbsp;                            if (!alreadyrepeated) {
&nbsp;                                travelstepx[1 - set][nn] = x;
&nbsp;                                travelstepy[1 - set][nn] = y;
&nbsp;                                /* don't change travel matrix! */
&nbsp;                                nn++;
&nbsp;                                alreadyrepeated = TRUE;
&nbsp;                            }
&nbsp;                            continue;
&nbsp;                        }
&nbsp;                    }
&nbsp;                    if (test_move(x, y, nx - x, ny - y, TEST_TRAV)
&nbsp;                        &amp;&amp; (levl[nx][ny].seenv
&nbsp;                            || (!Blind &amp;&amp; couldsee(nx, ny)))) {
&nbsp;                        if (nx == ux &amp;&amp; ny == uy) {
&nbsp;                            if (mode == TRAVP_TRAVEL || mode == TRAVP_VALID) {
&nbsp;                                u.dx = x - ux;
&nbsp;                                u.dy = y - uy;
&nbsp;                                if (mode == TRAVP_TRAVEL
&nbsp;                                    &amp;&amp; x == u.tx &amp;&amp; y == u.ty) {
&nbsp;                                    nomul(0);
&nbsp;                                    /* reset run so domove run checks work */
&nbsp;                                    context.run = 8;
&nbsp;                                    iflags.travelcc.x = iflags.travelcc.y = -1;
&nbsp;                                }
&nbsp;                                return TRUE;
&nbsp;                            }
&nbsp;                        } else if (!travel[nx][ny]) {
&nbsp;                            travelstepx[1 - set][nn] = nx;
&nbsp;                            travelstepy[1 - set][nn] = ny;
&nbsp;                            travel[nx][ny] = radius;
&nbsp;                            nn++;
&nbsp;                        }
&nbsp;                    }
&nbsp;                }
&nbsp;            }
&nbsp;
&nbsp;#ifdef DEBUG
&nbsp;            if (trav_debug) {
&nbsp;                /* Use of warning glyph is arbitrary. It stands out. */
&nbsp;                tmp_at(DISP_ALL, warning_to_glyph(1));
&nbsp;                for (i = 0; i &lt; nn; ++i) {
&nbsp;                    tmp_at(travelstepx[1 - set][i], travelstepy[1 - set][i]);
&nbsp;                }
&nbsp;                delay_output();
&nbsp;                if (flags.runmode == RUN_CRAWL) {
&nbsp;                    delay_output();
&nbsp;                    delay_output();
&nbsp;                }
&nbsp;                tmp_at(DISP_END, 0);
&nbsp;            }
&nbsp;#endif /* DEBUG */
&nbsp;
&nbsp;            n = nn;
&nbsp;            set = 1 - set;
&nbsp;            radius++;
&nbsp;        }
&nbsp;
&nbsp;        /* if guessing, find best location in travel matrix and go there */
&nbsp;        if (mode == TRAVP_GUESS) {
&nbsp;            int px = tx, py = ty; /* pick location */
&nbsp;            int dist, nxtdist, d2, nd2;
&nbsp;
&nbsp;            dist = distmin(ux, uy, tx, ty);
&nbsp;            d2 = dist2(ux, uy, tx, ty);
&nbsp;            for (tx = 1; tx &lt; COLNO; ++tx)
&nbsp;                for (ty = 0; ty &lt; ROWNO; ++ty)
&nbsp;                    if (travel[tx][ty]) {
&nbsp;                        nxtdist = distmin(ux, uy, tx, ty);
&nbsp;                        if (nxtdist == dist &amp;&amp; couldsee(tx, ty)) {
&nbsp;                            nd2 = dist2(ux, uy, tx, ty);
&nbsp;                            if (nd2 &lt; d2) {
&nbsp;                                /* prefer non-zigzag path */
&nbsp;                                px = tx;
&nbsp;                                py = ty;
&nbsp;                                d2 = nd2;
&nbsp;                            }
&nbsp;                        } else if (nxtdist &lt; dist &amp;&amp; couldsee(tx, ty)) {
&nbsp;                            px = tx;
&nbsp;                            py = ty;
&nbsp;                            dist = nxtdist;
&nbsp;                            d2 = dist2(ux, uy, tx, ty);
&nbsp;                        }
&nbsp;                    }
&nbsp;
&nbsp;            if (px == u.ux &amp;&amp; py == u.uy) {
&nbsp;                /* no guesses, just go in the general direction */
&nbsp;                u.dx = sgn(u.tx - u.ux);
&nbsp;                u.dy = sgn(u.ty - u.uy);
&nbsp;                if (test_move(u.ux, u.uy, u.dx, u.dy, TEST_MOVE))
&nbsp;                    return TRUE;
&nbsp;                goto found;
&nbsp;            }
&nbsp;#ifdef DEBUG
&nbsp;            if (trav_debug) {
&nbsp;                /* Use of warning glyph is arbitrary. It stands out. */
&nbsp;                tmp_at(DISP_ALL, warning_to_glyph(2));
&nbsp;                tmp_at(px, py);
&nbsp;                delay_output();
&nbsp;                if (flags.runmode == RUN_CRAWL) {
&nbsp;                    delay_output();
&nbsp;                    delay_output();
&nbsp;                    delay_output();
&nbsp;                    delay_output();
&nbsp;                }
&nbsp;                tmp_at(DISP_END, 0);
&nbsp;            }
&nbsp;#endif /* DEBUG */
&nbsp;            tx = px;
&nbsp;            ty = py;
&nbsp;            ux = u.ux;
&nbsp;            uy = u.uy;
&nbsp;            set = 0;
&nbsp;            n = radius = 1;
&nbsp;            mode = TRAVP_TRAVEL;
&nbsp;            goto noguess;
&nbsp;        }
&nbsp;        return FALSE;
&nbsp;    }
&nbsp;
&nbsp;found:
&nbsp;    u.dx = 0;
&nbsp;    u.dy = 0;
&nbsp;    nomul(0);
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
is_valid_travelpt
&nbsp;boolean
&nbsp;is_valid_travelpt(x,y)
&nbsp;int x,y;
&nbsp;{
&nbsp;    int tx = u.tx;
&nbsp;    int ty = u.ty;
&nbsp;    boolean ret;
&nbsp;    int g = glyph_at(x,y);
&nbsp;    if (x == u.ux &amp;&amp; y == u.uy)
&nbsp;        return TRUE;
&nbsp;    if (isok(x,y) &amp;&amp; glyph_is_cmap(g) &amp;&amp; S_stone == glyph_to_cmap(g)
&nbsp;        &amp;&amp; !levl[x][y].seenv)
&nbsp;        return FALSE;
&nbsp;    u.tx = x;
&nbsp;    u.ty = y;
&nbsp;    ret = findtravelpath(TRAVP_VALID);
&nbsp;    u.tx = tx;
&nbsp;    u.ty = ty;
&nbsp;    return ret;
&nbsp;}
&nbsp;
trapmove
&nbsp;/* try to escape being stuck in a trapped state by walking out of it;
&nbsp;   return true iff moving should continue to intended destination
&nbsp;   (all failures and most successful escapes leave hero at original spot) */
&nbsp;STATIC_OVL boolean
&nbsp;trapmove(x, y, desttrap)
&nbsp;int x, y;              /* targetted destination, <u.ux+u.dx,u.uy+u.dy> */
&nbsp;struct trap *desttrap; /* nonnull if another trap at <x,y> */
&nbsp;{
&nbsp;    boolean anchored = FALSE;
&nbsp;    const char *predicament, *culprit;
&nbsp;    char *steedname = !u.usteed ? (char *) 0 : y_monnam(u.usteed);
&nbsp;
&nbsp;    if (!u.utrap)
&nbsp;        return TRUE; /* sanity check */
&nbsp;
&nbsp;    switch (u.utraptype) {
&nbsp;    case TT_BEARTRAP:
&nbsp;        if (flags.verbose) {
&nbsp;            predicament = "caught in a bear trap";
&nbsp;            if (u.usteed)
&nbsp;                Norep("%s is %s.", upstart(steedname), predicament);
&nbsp;            else
&nbsp;                Norep("You are %s.", predicament);
&nbsp;        }
&nbsp;        /* [why does diagonal movement give quickest escape?] */
&nbsp;        if ((u.dx &amp;&amp; u.dy) || !rn2(5))
&nbsp;            u.utrap--;
&nbsp;        if (!u.utrap)
&nbsp;            goto wriggle_free;
&nbsp;        break;
&nbsp;    case TT_PIT:
&nbsp;        if (desttrap &amp;&amp; desttrap-&gt;tseen
&nbsp;            &amp;&amp; (desttrap-&gt;ttyp == PIT || desttrap-&gt;ttyp == SPIKED_PIT))
&nbsp;            return TRUE; /* move into adjacent pit */
&nbsp;        /* try to escape; position stays same regardless of success */
&nbsp;        climb_pit();
&nbsp;        break;
&nbsp;    case TT_WEB:
&nbsp;        if (uwep &amp;&amp; uwep-&gt;oartifact == ART_STING) {
&nbsp;            u.utrap = 0;
&nbsp;            pline("Sting cuts through the web!");
&nbsp;            break; /* escape trap but don't move */
&nbsp;        }
&nbsp;        if (--u.utrap) {
&nbsp;            if (flags.verbose) {
&nbsp;                predicament = "stuck to the web";
&nbsp;                if (u.usteed)
&nbsp;                    Norep("%s is %s.", upstart(steedname), predicament);
&nbsp;                else
&nbsp;                    Norep("You are %s.", predicament);
&nbsp;            }
&nbsp;        } else {
&nbsp;            if (u.usteed)
&nbsp;                pline("%s breaks out of the web.", upstart(steedname));
&nbsp;            else
&nbsp;                You("disentangle yourself.");
&nbsp;        }
&nbsp;        break;
&nbsp;    case TT_LAVA:
&nbsp;        if (flags.verbose) {
&nbsp;            predicament = "stuck in the lava";
&nbsp;            if (u.usteed)
&nbsp;                Norep("%s is %s.", upstart(steedname), predicament);
&nbsp;            else
&nbsp;                Norep("You are %s.", predicament);
&nbsp;        }
&nbsp;        if (!is_lava(x, y)) {
&nbsp;            u.utrap--;
&nbsp;            if ((u.utrap &amp; 0xff) == 0) {
&nbsp;                u.utrap = 0;
&nbsp;                if (u.usteed)
&nbsp;                    You("lead %s to the edge of the %s.", steedname,
&nbsp;                        hliquid("lava"));
&nbsp;                else
&nbsp;                    You("pull yourself to the edge of the %s.",
&nbsp;                        hliquid("lava"));
&nbsp;            }
&nbsp;        }
&nbsp;        u.umoved = TRUE;
&nbsp;        break;
&nbsp;    case TT_INFLOOR:
&nbsp;    case TT_BURIEDBALL:
&nbsp;        anchored = (u.utraptype == TT_BURIEDBALL);
&nbsp;        if (anchored) {
&nbsp;            coord cc;
&nbsp;
&nbsp;            cc.x = u.ux, cc.y = u.uy;
&nbsp;            /* can move normally within radius 1 of buried ball */
&nbsp;            if (buried_ball(&amp;cc) &amp;&amp; dist2(x, y, cc.x, cc.y) &lt;= 2) {
&nbsp;                /* ugly hack: we need to issue some message here
&nbsp;                   in case "you are chained to the buried ball"
&nbsp;                   was the most recent message given, otherwise
&nbsp;                   our next attempt to move out of tether range
&nbsp;                   after this successful move would have its
&nbsp;                   can't-do-that message suppressed by Norep */
&nbsp;                if (flags.verbose)
&nbsp;                    Norep("You move within the chain's reach.");
&nbsp;                return TRUE;
&nbsp;            }
&nbsp;        }
&nbsp;        if (--u.utrap) {
&nbsp;            if (flags.verbose) {
&nbsp;                if (anchored) {
&nbsp;                    predicament = "chained to the";
&nbsp;                    culprit = "buried ball";
&nbsp;                } else {
&nbsp;                    predicament = "stuck in the";
&nbsp;                    culprit = surface(u.ux, u.uy);
&nbsp;                }
&nbsp;                if (u.usteed) {
&nbsp;                    if (anchored)
&nbsp;                        Norep("You and %s are %s %s.", steedname, predicament,
&nbsp;                              culprit);
&nbsp;                    else
&nbsp;                        Norep("%s is %s %s.", upstart(steedname), predicament,
&nbsp;                              culprit);
&nbsp;                } else
&nbsp;                    Norep("You are %s %s.", predicament, culprit);
&nbsp;            }
&nbsp;        } else {
&nbsp;wriggle_free:
&nbsp;            if (u.usteed)
&nbsp;                pline("%s finally %s free.", upstart(steedname),
&nbsp;                      !anchored ? "lurches" : "wrenches the ball");
&nbsp;            else
&nbsp;                You("finally %s free.",
&nbsp;                    !anchored ? "wriggle" : "wrench the ball");
&nbsp;            if (anchored)
&nbsp;                buried_ball_to_punishment();
&nbsp;        }
&nbsp;        break;
&nbsp;    default:
&nbsp;        impossible("trapmove: stuck in unknown trap? (%d)",
&nbsp;                   (int) u.utraptype);
&nbsp;        break;
&nbsp;    }
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
u_rooted
&nbsp;boolean
&nbsp;u_rooted()
&nbsp;{
&nbsp;    if (!youmonst.data-&gt;mmove) {
&nbsp;        You("are rooted %s.",
&nbsp;            Levitation || Is_airlevel(&amp;u.uz) || Is_waterlevel(&amp;u.uz)
&nbsp;                ? "in place"
&nbsp;                : "to the ground");
&nbsp;        nomul(0);
&nbsp;        return TRUE;
&nbsp;    }
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
domove
&nbsp;void
&nbsp;domove()
&nbsp;{
&nbsp;    register struct monst *mtmp;
&nbsp;    register struct rm *tmpr;
&nbsp;    register xchar x, y;
&nbsp;    struct trap *trap = NULL;
&nbsp;    int wtcap;
&nbsp;    boolean on_ice;
&nbsp;    xchar chainx = 0, chainy = 0,
&nbsp;          ballx = 0, bally = 0;         /* ball&amp;chain new positions */
&nbsp;    int bc_control = 0;                 /* control for ball&amp;chain */
&nbsp;    boolean cause_delay = FALSE;        /* dragging ball will skip a move */
&nbsp;
&nbsp;    u_wipe_engr(rnd(5));
&nbsp;
&nbsp;    if (context.travel) {
&nbsp;        if (!findtravelpath(FALSE))
&nbsp;            (void) findtravelpath(TRUE);
&nbsp;        context.travel1 = 0;
&nbsp;    }
&nbsp;
&nbsp;    if (((wtcap = near_capacity()) &gt;= OVERLOADED
&nbsp;         || (wtcap &gt; SLT_ENCUMBER
&nbsp;             &amp;&amp; (Upolyd ? (u.mh &lt; 5 &amp;&amp; u.mh != u.mhmax)
&nbsp;                        : (u.uhp &lt; 10 &amp;&amp; u.uhp != u.uhpmax))))
&nbsp;        &amp;&amp; !Is_airlevel(&amp;u.uz)) {
&nbsp;        if (wtcap &lt; OVERLOADED) {
&nbsp;            You("don't have enough stamina to move.");
&nbsp;            exercise(A_CON, FALSE);
&nbsp;        } else
&nbsp;            You("collapse under your load.");
&nbsp;        nomul(0);
&nbsp;        return;
&nbsp;    }
&nbsp;    if (u.uswallow) {
&nbsp;        u.dx = u.dy = 0;
&nbsp;        u.ux = x = u.ustuck-&gt;mx;
&nbsp;        u.uy = y = u.ustuck-&gt;my;
&nbsp;        mtmp = u.ustuck;
&nbsp;    } else {
&nbsp;        if (Is_airlevel(&amp;u.uz) &amp;&amp; rn2(4) &amp;&amp; !Levitation &amp;&amp; !Flying) {
&nbsp;            switch (rn2(3)) {
&nbsp;            case 0:
&nbsp;                You("tumble in place.");
&nbsp;                exercise(A_DEX, FALSE);
&nbsp;                break;
&nbsp;            case 1:
&nbsp;                You_cant("control your movements very well.");
&nbsp;                break;
&nbsp;            case 2:
&nbsp;                pline("It's hard to walk in thin air.");
&nbsp;                exercise(A_DEX, TRUE);
&nbsp;                break;
&nbsp;            }
&nbsp;            return;
&nbsp;        }
&nbsp;
&nbsp;        /* check slippery ice */
&nbsp;        on_ice = !Levitation &amp;&amp; is_ice(u.ux, u.uy);
&nbsp;        if (on_ice) {
&nbsp;            static int skates = 0;
&nbsp;
&nbsp;            if (!skates)
&nbsp;                skates = find_skates();
&nbsp;            if ((uarmf &amp;&amp; uarmf-&gt;otyp == skates) || resists_cold(&amp;youmonst)
&nbsp;                || Flying || is_floater(youmonst.data)
&nbsp;                || is_clinger(youmonst.data) || is_whirly(youmonst.data)) {
&nbsp;                on_ice = FALSE;
&nbsp;            } else if (!rn2(Cold_resistance ? 3 : 2)) {
&nbsp;                HFumbling |= FROMOUTSIDE;
&nbsp;                HFumbling &amp;= ~TIMEOUT;
&nbsp;                HFumbling += 1; /* slip on next move */
&nbsp;            }
&nbsp;        }
&nbsp;        if (!on_ice &amp;&amp; (HFumbling &amp; FROMOUTSIDE))
&nbsp;            HFumbling &amp;= ~FROMOUTSIDE;
&nbsp;
&nbsp;        x = u.ux + u.dx;
&nbsp;        y = u.uy + u.dy;
&nbsp;        if (Stunned || (Confusion &amp;&amp; !rn2(5))) {
&nbsp;            register int tries = 0;
&nbsp;
&nbsp;            do {
&nbsp;                if (tries++ &gt; 50) {
&nbsp;                    nomul(0);
&nbsp;                    return;
&nbsp;                }
&nbsp;                confdir();
&nbsp;                x = u.ux + u.dx;
&nbsp;                y = u.uy + u.dy;
&nbsp;            } while (!isok(x, y) || bad_rock(youmonst.data, x, y));
&nbsp;        }
&nbsp;        /* turbulence might alter your actual destination */
&nbsp;        if (u.uinwater) {
&nbsp;            water_friction();
&nbsp;            if (!u.dx &amp;&amp; !u.dy) {
&nbsp;                nomul(0);
&nbsp;                return;
&nbsp;            }
&nbsp;            x = u.ux + u.dx;
&nbsp;            y = u.uy + u.dy;
&nbsp;        }
&nbsp;        if (!isok(x, y)) {
&nbsp;            nomul(0);
&nbsp;            return;
&nbsp;        }
&nbsp;        if (((trap = t_at(x, y)) &amp;&amp; trap-&gt;tseen)
&nbsp;            || (Blind &amp;&amp; !Levitation &amp;&amp; !Flying &amp;&amp; !is_clinger(youmonst.data)
&nbsp;                &amp;&amp; is_pool_or_lava(x, y) &amp;&amp; levl[x][y].seenv)) {
&nbsp;            if (context.run &gt;= 2) {
&nbsp;                if (iflags.mention_walls) {
&nbsp;                    if (trap &amp;&amp; trap-&gt;tseen) {
&nbsp;                        int tt = what_trap(trap-&gt;ttyp);
&nbsp;                        You("stop in front of %s.",
&nbsp;                            an(defsyms[trap_to_defsym(tt)].explanation));
&nbsp;                    } else if (is_pool_or_lava(x,y) &amp;&amp; levl[x][y].seenv) {
&nbsp;                        You("stop at the edge of the %s.",
&nbsp;                            hliquid(is_pool(x,y) ? "water" : "lava"));
&nbsp;                    }
&nbsp;                }
&nbsp;                nomul(0);
&nbsp;                context.move = 0;
&nbsp;                return;
&nbsp;            } else
&nbsp;                nomul(0);
&nbsp;        }
&nbsp;
&nbsp;        if (u.ustuck &amp;&amp; (x != u.ustuck-&gt;mx || y != u.ustuck-&gt;my)) {
&nbsp;            if (distu(u.ustuck-&gt;mx, u.ustuck-&gt;my) &gt; 2) {
&nbsp;                /* perhaps it fled (or was teleported or ... ) */
&nbsp;                u.ustuck = 0;
&nbsp;            } else if (sticks(youmonst.data)) {
&nbsp;                /* When polymorphed into a sticking monster,
&nbsp;                 * u.ustuck means it's stuck to you, not you to it.
&nbsp;                 */
&nbsp;                You("release %s.", mon_nam(u.ustuck));
&nbsp;                u.ustuck = 0;
&nbsp;            } else {
&nbsp;                /* If holder is asleep or paralyzed:
&nbsp;                 *      37.5% chance of getting away,
&nbsp;                 *      12.5% chance of waking/releasing it;
&nbsp;                 * otherwise:
&nbsp;                 *       7.5% chance of getting away.
&nbsp;                 * [strength ought to be a factor]
&nbsp;                 * If holder is tame and there is no conflict,
&nbsp;                 * guaranteed escape.
&nbsp;                 */
&nbsp;                switch (rn2(!u.ustuck-&gt;mcanmove ? 8 : 40)) {
&nbsp;                case 0:
&nbsp;                case 1:
&nbsp;                case 2:
&nbsp;                pull_free:
&nbsp;                    You("pull free from %s.", mon_nam(u.ustuck));
&nbsp;                    u.ustuck = 0;
&nbsp;                    break;
&nbsp;                case 3:
&nbsp;                    if (!u.ustuck-&gt;mcanmove) {
&nbsp;                        /* it's free to move on next turn */
&nbsp;                        u.ustuck-&gt;mfrozen = 1;
&nbsp;                        u.ustuck-&gt;msleeping = 0;
&nbsp;                    }
&nbsp;                /*FALLTHRU*/
&nbsp;                default:
&nbsp;                    if (u.ustuck-&gt;mtame &amp;&amp; !Conflict &amp;&amp; !u.ustuck-&gt;mconf)
&nbsp;                        goto pull_free;
&nbsp;                    You("cannot escape from %s!", mon_nam(u.ustuck));
&nbsp;                    nomul(0);
&nbsp;                    return;
&nbsp;                }
&nbsp;            }
&nbsp;        }
&nbsp;
&nbsp;        mtmp = m_at(x, y);
&nbsp;        if (mtmp &amp;&amp; !is_safepet(mtmp)) {
&nbsp;            /* Don't attack if you're running, and can see it */
&nbsp;            /* It's fine to displace pets, though */
&nbsp;            /* We should never get here if forcefight */
&nbsp;            if (context.run &amp;&amp; ((!Blind &amp;&amp; mon_visible(mtmp)
&nbsp;                                 &amp;&amp; ((mtmp-&gt;m_ap_type != M_AP_FURNITURE
&nbsp;                                      &amp;&amp; mtmp-&gt;m_ap_type != M_AP_OBJECT)
&nbsp;                                     || Protection_from_shape_changers))
&nbsp;                                || sensemon(mtmp))) {
&nbsp;                nomul(0);
&nbsp;                context.move = 0;
&nbsp;                return;
&nbsp;            }
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    u.ux0 = u.ux;
&nbsp;    u.uy0 = u.uy;
&nbsp;    bhitpos.x = x;
&nbsp;    bhitpos.y = y;
&nbsp;    tmpr = &amp;levl[x][y];
&nbsp;
&nbsp;    /* attack monster */
&nbsp;    if (mtmp) {
&nbsp;        /* don't stop travel when displacing pets; if the
&nbsp;           displace fails for some reason, attack() in uhitm.c
&nbsp;           will stop travel rather than domove */
&nbsp;        if (!is_safepet(mtmp) || context.forcefight)
&nbsp;            nomul(0);
&nbsp;        /* only attack if we know it's there */
&nbsp;        /* or if we used the 'F' command to fight blindly */
&nbsp;        /* or if it hides_under, in which case we call attack() to print
&nbsp;         * the Wait! message.
&nbsp;         * This is different from ceiling hiders, who aren't handled in
&nbsp;         * attack().
&nbsp;         */
&nbsp;
&nbsp;        /* If they used a 'm' command, trying to move onto a monster
&nbsp;         * prints the below message and wastes a turn.  The exception is
&nbsp;         * if the monster is unseen and the player doesn't remember an
&nbsp;         * invisible monster--then, we fall through to attack() and
&nbsp;         * attack_check(), which still wastes a turn, but prints a
&nbsp;         * different message and makes the player remember the monster.
&nbsp;         */
&nbsp;        if (context.nopick &amp;&amp; !context.travel
&nbsp;            &amp;&amp; (canspotmon(mtmp) || glyph_is_invisible(levl[x][y].glyph))) {
&nbsp;            if (mtmp-&gt;m_ap_type &amp;&amp; !Protection_from_shape_changers
&nbsp;                &amp;&amp; !sensemon(mtmp))
&nbsp;                stumble_onto_mimic(mtmp);
&nbsp;            else if (mtmp-&gt;mpeaceful &amp;&amp; !Hallucination)
&nbsp;                /* m_monnam(): "dog" or "Fido", no "invisible dog" or "it" */
&nbsp;                pline("Pardon me, %s.", m_monnam(mtmp));
&nbsp;            else
&nbsp;                You("move right into %s.", mon_nam(mtmp));
&nbsp;            return;
&nbsp;        }
&nbsp;        if (context.forcefight || !mtmp-&gt;mundetected || sensemon(mtmp)
&nbsp;            || ((hides_under(mtmp-&gt;data) || mtmp-&gt;data-&gt;mlet == S_EEL)
&nbsp;                &amp;&amp; !is_safepet(mtmp))) {
&nbsp;            /* try to attack; note that it might evade */
&nbsp;            /* also, we don't attack tame when _safepet_ */
&nbsp;            if (attack(mtmp))
&nbsp;                return;
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    if (context.forcefight &amp;&amp; levl[x][y].typ == IRONBARS &amp;&amp; uwep) {
&nbsp;        struct obj *obj = uwep;
&nbsp;
&nbsp;        if (breaktest(obj)) {
&nbsp;            if (obj-&gt;quan &gt; 1L)
&nbsp;                obj = splitobj(obj, 1L);
&nbsp;            else
&nbsp;                setuwep((struct obj *)0);
&nbsp;            freeinv(obj);
&nbsp;        }
&nbsp;        hit_bars(&amp;obj, u.ux, u.uy, x, y, TRUE, TRUE);
&nbsp;        return;
&nbsp;    }
&nbsp;
&nbsp;    /* specifying 'F' with no monster wastes a turn */
&nbsp;    if (context.forcefight
&nbsp;        /* remembered an 'I' &amp;&amp; didn't use a move command */
&nbsp;        || (glyph_is_invisible(levl[x][y].glyph) &amp;&amp; !context.nopick)) {
&nbsp;        struct obj *boulder = 0;
&nbsp;        boolean explo = (Upolyd &amp;&amp; attacktype(youmonst.data, AT_EXPL)),
&nbsp;                solid = !accessible(x, y);
&nbsp;        int glyph = glyph_at(x, y); /* might be monster */
&nbsp;        char buf[BUFSZ];
&nbsp;
&nbsp;        if (!Underwater) {
&nbsp;            boulder = sobj_at(BOULDER, x, y);
&nbsp;            /* if a statue is displayed at the target location,
&nbsp;               player is attempting to attack it [and boulder
&nbsp;               handling below is suitable for handling that] */
&nbsp;            if (glyph_is_statue(glyph)
&nbsp;                || (Hallucination &amp;&amp; glyph_is_monster(glyph)))
&nbsp;                boulder = sobj_at(STATUE, x, y);
&nbsp;
&nbsp;            /* force fight at boulder/statue or wall/door while wielding
&nbsp;               pick:  start digging to break the boulder or wall */
&nbsp;            if (context.forcefight
&nbsp;                /* can we dig? */
&nbsp;                &amp;&amp; uwep &amp;&amp; dig_typ(uwep, x, y)
&nbsp;                /* should we dig? */
&nbsp;                &amp;&amp; !glyph_is_invisible(glyph) &amp;&amp; !glyph_is_monster(glyph)) {
&nbsp;                (void) use_pick_axe2(uwep);
&nbsp;                return;
&nbsp;            }
&nbsp;        }
&nbsp;
&nbsp;        /* about to become known empty -- remove 'I' if present */
&nbsp;        unmap_object(x, y);
&nbsp;        if (boulder)
&nbsp;            map_object(boulder, TRUE);
&nbsp;        newsym(x, y);
&nbsp;        glyph = glyph_at(x, y); /* might have just changed */
&nbsp;
&nbsp;        if (boulder) {
&nbsp;            Strcpy(buf, ansimpleoname(boulder));
&nbsp;        } else if (Underwater &amp;&amp; !is_pool(x, y)) {
&nbsp;            /* Underwater, targetting non-water; the map just shows blank
&nbsp;               because you don't see remembered terrain while underwater;
&nbsp;               although the hero can attack an adjacent monster this way,
&nbsp;               assume he can't reach out far enough to distinguish terrain */
&nbsp;            Sprintf(buf, (Is_waterlevel(&amp;u.uz) &amp;&amp; levl[x][y].typ == AIR)
&nbsp;                             ? "an air bubble"
&nbsp;                             : "nothing");
&nbsp;        } else if (solid) {
&nbsp;            /* glyph might indicate unseen terrain if hero is blind;
&nbsp;               unlike searching, this won't reveal what that terrain is
&nbsp;               (except for solid rock, where the glyph would otherwise
&nbsp;               yield ludicrous "dark part of a room") */
&nbsp;            Strcpy(buf, (levl[x][y].typ == STONE) ? "solid rock"
&nbsp;                         : glyph_is_cmap(glyph)
&nbsp;                            ? the(defsyms[glyph_to_cmap(glyph)].explanation)
&nbsp;                            : (const char *) "an unknown obstacle");
&nbsp;            /* note: 'solid' is misleadingly named and catches pools
&nbsp;               of water and lava as well as rock and walls */
&nbsp;        } else {
&nbsp;            Strcpy(buf, "thin air");
&nbsp;        }
&nbsp;        You("%s%s %s.",
&nbsp;            !(boulder || solid) ? "" : !explo ? "harmlessly " : "futilely ",
&nbsp;            explo ? "explode at" : "attack", buf);
&nbsp;
&nbsp;        nomul(0);
&nbsp;        if (explo) {
&nbsp;            wake_nearby();
&nbsp;            u.mh = -1; /* dead in the current form */
&nbsp;            rehumanize();
&nbsp;        }
&nbsp;        return;
&nbsp;    }
&nbsp;    (void) unmap_invisible(x, y);
&nbsp;    /* not attacking an animal, so we try to move */
&nbsp;    if ((u.dx || u.dy) &amp;&amp; u.usteed &amp;&amp; stucksteed(FALSE)) {
&nbsp;        nomul(0);
&nbsp;        return;
&nbsp;    }
&nbsp;
&nbsp;    if (u_rooted())
&nbsp;        return;
&nbsp;
&nbsp;    if (u.utrap) {
&nbsp;        if (!trapmove(x, y, trap))
&nbsp;            return;
&nbsp;    }
&nbsp;
&nbsp;    if (!test_move(u.ux, u.uy, x - u.ux, y - u.uy, DO_MOVE)) {
&nbsp;        if (!context.door_opened) {
&nbsp;            context.move = 0;
&nbsp;            nomul(0);
&nbsp;        }
&nbsp;        return;
&nbsp;    }
&nbsp;
&nbsp;    /* Move ball and chain.  */
&nbsp;    if (Punished)
&nbsp;        if (!drag_ball(x, y, &amp;bc_control, &amp;ballx, &amp;bally, &amp;chainx, &amp;chainy,
&nbsp;                       &amp;cause_delay, TRUE))
&nbsp;            return;
&nbsp;
&nbsp;    /* Check regions entering/leaving */
&nbsp;    if (!in_out_region(x, y))
&nbsp;        return;
&nbsp;
&nbsp;    /* now move the hero */
&nbsp;    mtmp = m_at(x, y);
&nbsp;    u.ux += u.dx;
&nbsp;    u.uy += u.dy;
&nbsp;    /* Move your steed, too */
&nbsp;    if (u.usteed) {
&nbsp;        u.usteed-&gt;mx = u.ux;
&nbsp;        u.usteed-&gt;my = u.uy;
&nbsp;        exercise_steed();
&nbsp;    }
&nbsp;
&nbsp;    /*
&nbsp;     * If safepet at destination then move the pet to the hero's
&nbsp;     * previous location using the same conditions as in attack().
&nbsp;     * there are special extenuating circumstances:
&nbsp;     * (1) if the pet dies then your god angers,
&nbsp;     * (2) if the pet gets trapped then your god may disapprove,
&nbsp;     * (3) if the pet was already trapped and you attempt to free it
&nbsp;     * not only do you encounter the trap but you may frighten your
&nbsp;     * pet causing it to go wild!  moral: don't abuse this privilege.
&nbsp;     *
&nbsp;     * Ceiling-hiding pets are skipped by this section of code, to
&nbsp;     * be caught by the normal falling-monster code.
&nbsp;     */
&nbsp;    if (is_safepet(mtmp) &amp;&amp; !(is_hider(mtmp-&gt;data) &amp;&amp; mtmp-&gt;mundetected)) {
&nbsp;        /* if trapped, there's a chance the pet goes wild */
&nbsp;        if (mtmp-&gt;mtrapped) {
&nbsp;            if (!rn2(mtmp-&gt;mtame)) {
&nbsp;                mtmp-&gt;mtame = mtmp-&gt;mpeaceful = mtmp-&gt;msleeping = 0;
&nbsp;                if (mtmp-&gt;mleashed)
&nbsp;                    m_unleash(mtmp, TRUE);
&nbsp;                growl(mtmp);
&nbsp;            } else {
&nbsp;                yelp(mtmp);
&nbsp;            }
&nbsp;        }
&nbsp;
&nbsp;        /* seemimic/newsym should be done before moving hero, otherwise
&nbsp;           the display code will draw the hero here before we possibly
&nbsp;           cancel the swap below (we can ignore steed mx,my here) */
&nbsp;        u.ux = u.ux0, u.uy = u.uy0;
&nbsp;        mtmp-&gt;mundetected = 0;
&nbsp;        if (mtmp-&gt;m_ap_type)
&nbsp;            seemimic(mtmp);
&nbsp;        else if (!mtmp-&gt;mtame)
&nbsp;            newsym(mtmp-&gt;mx, mtmp-&gt;my);
&nbsp;        u.ux = mtmp-&gt;mx, u.uy = mtmp-&gt;my; /* resume swapping positions */
&nbsp;
&nbsp;        if (mtmp-&gt;mtrapped &amp;&amp; (trap = t_at(mtmp-&gt;mx, mtmp-&gt;my)) != 0
&nbsp;            &amp;&amp; (trap-&gt;ttyp == PIT || trap-&gt;ttyp == SPIKED_PIT)
&nbsp;            &amp;&amp; sobj_at(BOULDER, trap-&gt;tx, trap-&gt;ty)) {
&nbsp;            /* can't swap places with pet pinned in a pit by a boulder */
&nbsp;            u.ux = u.ux0, u.uy = u.uy0; /* didn't move after all */
&nbsp;            if (u.usteed)
&nbsp;                u.usteed-&gt;mx = u.ux, u.usteed-&gt;my = u.uy;
&nbsp;        } else if (u.ux0 != x &amp;&amp; u.uy0 != y &amp;&amp; NODIAG(mtmp-&gt;data - mons)) {
&nbsp;            /* can't swap places when pet can't move to your spot */
&nbsp;            u.ux = u.ux0, u.uy = u.uy0;
&nbsp;            if (u.usteed)
&nbsp;                u.usteed-&gt;mx = u.ux, u.usteed-&gt;my = u.uy;
&nbsp;            You("stop.  %s can't move diagonally.", upstart(y_monnam(mtmp)));
&nbsp;        } else if (u.ux0 != x &amp;&amp; u.uy0 != y &amp;&amp; bad_rock(mtmp-&gt;data, x, u.uy0)
&nbsp;                   &amp;&amp; bad_rock(mtmp-&gt;data, u.ux0, y)
&nbsp;                   &amp;&amp; (bigmonst(mtmp-&gt;data) || (curr_mon_load(mtmp) &gt; 600))) {
&nbsp;            /* can't swap places when pet won't fit thru the opening */
&nbsp;            u.ux = u.ux0, u.uy = u.uy0; /* didn't move after all */
&nbsp;            if (u.usteed)
&nbsp;                u.usteed-&gt;mx = u.ux, u.usteed-&gt;my = u.uy;
&nbsp;            You("stop.  %s won't fit through.", upstart(y_monnam(mtmp)));
&nbsp;        } else {
&nbsp;            char pnambuf[BUFSZ];
&nbsp;
&nbsp;            /* save its current description in case of polymorph */
&nbsp;            Strcpy(pnambuf, y_monnam(mtmp));
&nbsp;            mtmp-&gt;mtrapped = 0;
&nbsp;            remove_monster(x, y);
&nbsp;            place_monster(mtmp, u.ux0, u.uy0);
&nbsp;            newsym(x, y);
&nbsp;            newsym(u.ux0, u.uy0);
&nbsp;
&nbsp;            You("%s %s.", mtmp-&gt;mtame ? "swap places with" : "frighten",
&nbsp;                pnambuf);
&nbsp;
&nbsp;            /* check for displacing it into pools and traps */
&nbsp;            switch (minliquid(mtmp) ? 2 : mintrap(mtmp)) {
&nbsp;            case 0:
&nbsp;                break;
&nbsp;            case 1: /* trapped */
&nbsp;            case 3: /* changed levels */
&nbsp;                /* there's already been a trap message, reinforce it */
&nbsp;                abuse_dog(mtmp);
&nbsp;                adjalign(-3);
&nbsp;                break;
&nbsp;            case 2:
&nbsp;                /* drowned or died...
&nbsp;                 * you killed your pet by direct action, so get experience
&nbsp;                 * and possibly penalties;
&nbsp;                 * we want the level gain message, if it happens, to occur
&nbsp;                 * before the guilt message below
&nbsp;                 */
&nbsp;                {
&nbsp;                    /* minliquid() and mintrap() call mondead() rather than
&nbsp;                       killed() so we duplicate some of the latter here */
&nbsp;                    int tmp, mndx;
&nbsp;
&nbsp;                    u.uconduct.killer++;
&nbsp;                    mndx = monsndx(mtmp-&gt;data);
&nbsp;                    tmp = experience(mtmp, (int) mvitals[mndx].died);
&nbsp;                    more_experienced(tmp, 0);
&nbsp;                    newexplevel(); /* will decide if you go up */
&nbsp;                }
&nbsp;                /* That's no way to treat a pet!  Your god gets angry.
&nbsp;                 *
&nbsp;                 * [This has always been pretty iffy.  Why does your
&nbsp;                 * patron deity care at all, let alone enough to get mad?]
&nbsp;                 */
&nbsp;                if (rn2(4)) {
&nbsp;                    You_feel("guilty about losing your pet like this.");
&nbsp;                    u.ugangr++;
&nbsp;                    adjalign(-15);
&nbsp;                }
&nbsp;                break;
&nbsp;            default:
&nbsp;                pline("that's strange, unknown mintrap result!");
&nbsp;                break;
&nbsp;            }
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    reset_occupations();
&nbsp;    if (context.run) {
&nbsp;        if (context.run &lt; 8)
&nbsp;            if (IS_DOOR(tmpr-&gt;typ) || IS_ROCK(tmpr-&gt;typ)
&nbsp;                || IS_FURNITURE(tmpr-&gt;typ))
&nbsp;                nomul(0);
&nbsp;    }
&nbsp;
&nbsp;    if (hides_under(youmonst.data) || youmonst.data-&gt;mlet == S_EEL
&nbsp;        || u.dx || u.dy)
&nbsp;        (void) hideunder(&amp;youmonst);
&nbsp;
&nbsp;    /*
&nbsp;     * Mimics (or whatever) become noticeable if they move and are
&nbsp;     * imitating something that doesn't move.  We could extend this
&nbsp;     * to non-moving monsters...
&nbsp;     */
&nbsp;    if ((u.dx || u.dy) &amp;&amp; (youmonst.m_ap_type == M_AP_OBJECT
&nbsp;                           || youmonst.m_ap_type == M_AP_FURNITURE))
&nbsp;        youmonst.m_ap_type = M_AP_NOTHING;
&nbsp;
&nbsp;    check_leash(u.ux0, u.uy0);
&nbsp;
&nbsp;    if (u.ux0 != u.ux || u.uy0 != u.uy) {
&nbsp;        u.umoved = TRUE;
&nbsp;        /* Clean old position -- vision_recalc() will print our new one. */
&nbsp;        newsym(u.ux0, u.uy0);
&nbsp;        /* Since the hero has moved, adjust what can be seen/unseen. */
&nbsp;        vision_recalc(1); /* Do the work now in the recover time. */
&nbsp;        invocation_message();
&nbsp;    }
&nbsp;
&nbsp;    if (Punished) /* put back ball and chain */
&nbsp;        move_bc(0, bc_control, ballx, bally, chainx, chainy);
&nbsp;
&nbsp;    if (u.umoved)
&nbsp;        spoteffects(TRUE);
&nbsp;
&nbsp;    /* delay next move because of ball dragging */
&nbsp;    /* must come after we finished picking up, in spoteffects() */
&nbsp;    if (cause_delay) {
&nbsp;        nomul(-2);
&nbsp;        multi_reason = "dragging an iron ball";
&nbsp;        nomovemsg = "";
&nbsp;    }
&nbsp;
&nbsp;    if (context.run &amp;&amp; flags.runmode != RUN_TPORT) {
&nbsp;        /* display every step or every 7th step depending upon mode */
&nbsp;        if (flags.runmode != RUN_LEAP || !(moves % 7L)) {
&nbsp;            if (flags.time)
&nbsp;                context.botl = 1;
&nbsp;            curs_on_u();
&nbsp;            delay_output();
&nbsp;            if (flags.runmode == RUN_CRAWL) {
&nbsp;                delay_output();
&nbsp;                delay_output();
&nbsp;                delay_output();
&nbsp;                delay_output();
&nbsp;            }
&nbsp;        }
&nbsp;    }
&nbsp;}
&nbsp;
overexertion
&nbsp;/* combat increases metabolism */
&nbsp;boolean
&nbsp;overexertion()
&nbsp;{
&nbsp;    /* this used to be part of domove() when moving to a monster's
&nbsp;       position, but is now called by attack() so that it doesn't
&nbsp;       execute if you decline to attack a peaceful monster */
&nbsp;    gethungry();
&nbsp;    if ((moves % 3L) != 0L &amp;&amp; near_capacity() &gt;= HVY_ENCUMBER) {
&nbsp;        int *hp = (!Upolyd ? &amp;u.uhp : &amp;u.mh);
&nbsp;
&nbsp;        if (*hp &gt; 1) {
&nbsp;            *hp -= 1;
&nbsp;        } else {
&nbsp;            You("pass out from exertion!");
&nbsp;            exercise(A_CON, FALSE);
&nbsp;            fall_asleep(-10, FALSE);
&nbsp;        }
&nbsp;    }
&nbsp;    return (boolean) (multi &lt; 0); /* might have fainted (forced to sleep) */
&nbsp;}
&nbsp;
invocation_message
&nbsp;void
&nbsp;invocation_message()
&nbsp;{
&nbsp;    /* a special clue-msg when on the Invocation position */
&nbsp;    if (invocation_pos(u.ux, u.uy) &amp;&amp; !On_stairs(u.ux, u.uy)) {
&nbsp;        char buf[BUFSZ];
&nbsp;        struct obj *otmp = carrying(CANDELABRUM_OF_INVOCATION);
&nbsp;
&nbsp;        nomul(0); /* stop running or travelling */
&nbsp;        if (u.usteed)
&nbsp;            Sprintf(buf, "beneath %s", y_monnam(u.usteed));
&nbsp;        else if (Levitation || Flying)
&nbsp;            Strcpy(buf, "beneath you");
&nbsp;        else
&nbsp;            Sprintf(buf, "under your %s", makeplural(body_part(FOOT)));
&nbsp;
&nbsp;        You_feel("a strange vibration %s.", buf);
&nbsp;        u.uevent.uvibrated = 1;
&nbsp;        if (otmp &amp;&amp; otmp-&gt;spe == 7 &amp;&amp; otmp-&gt;lamplit)
&nbsp;            pline("%s %s!", The(xname(otmp)),
&nbsp;                  Blind ? "throbs palpably" : "glows with a strange light");
&nbsp;    }
&nbsp;}
&nbsp;
switch_terrain
&nbsp;/* moving onto different terrain;
&nbsp;   might be going into solid rock, inhibiting levitation or flight,
&nbsp;   or coming back out of such, reinstating levitation/flying */
&nbsp;STATIC_OVL void
&nbsp;switch_terrain()
&nbsp;{
&nbsp;    struct rm *lev = &amp;levl[u.ux][u.uy];
&nbsp;    boolean blocklev = (IS_ROCK(lev-&gt;typ) || closed_door(u.ux, u.uy)
&nbsp;                        || (Is_waterlevel(&amp;u.uz) &amp;&amp; lev-&gt;typ == WATER));
&nbsp;
&nbsp;    if (blocklev) {
&nbsp;        /* called from spoteffects(), skip float_down() */
&nbsp;        if (Levitation)
&nbsp;            You_cant("levitate in here.");
&nbsp;        BLevitation |= FROMOUTSIDE;
&nbsp;    } else if (BLevitation) {
&nbsp;        BLevitation &amp;= ~FROMOUTSIDE;
&nbsp;        if (Levitation)
&nbsp;            float_up();
&nbsp;    }
&nbsp;    /* the same terrain that blocks levitation also blocks flight */
&nbsp;    if (blocklev) {
&nbsp;        if (Flying)
&nbsp;            You_cant("fly in here.");
&nbsp;        BFlying |= FROMOUTSIDE;
&nbsp;    } else if (BFlying) {
&nbsp;        BFlying &amp;= ~FROMOUTSIDE;
&nbsp;        float_vs_flight(); /* maybe toggle (BFlying &amp; I_SPECIAL) */
&nbsp;        /* [minor bug: we don't know whether this is beginning flight or
&nbsp;           resuming it; that could be tracked so that this message could
&nbsp;           be adjusted to "resume flying", but isn't worth the effort...] */
&nbsp;        if (Flying)
&nbsp;            You("start flying.");
&nbsp;    }
&nbsp;}
&nbsp;
pooleffects
&nbsp;/* extracted from spoteffects; called by spoteffects to check for entering or
&nbsp;   leaving a pool of water/lava, and by moveloop to check for staying on one;
&nbsp;   returns true to skip rest of spoteffects */
&nbsp;boolean
&nbsp;pooleffects(newspot)
&nbsp;boolean newspot;             /* true if called by spoteffects */
&nbsp;{
&nbsp;    /* check for leaving water */
&nbsp;    if (u.uinwater) {
&nbsp;        boolean still_inwater = FALSE; /* assume we're getting out */
&nbsp;
&nbsp;        if (!is_pool(u.ux, u.uy)) {
&nbsp;            if (Is_waterlevel(&amp;u.uz))
&nbsp;                You("pop into an air bubble.");
&nbsp;            else if (is_lava(u.ux, u.uy))
&nbsp;                You("leave the %s...", hliquid("water")); /* oops! */
&nbsp;            else
&nbsp;                You("are on solid %s again.",
&nbsp;                    is_ice(u.ux, u.uy) ? "ice" : "land");
&nbsp;        } else if (Is_waterlevel(&amp;u.uz)) {
&nbsp;            still_inwater = TRUE;
&nbsp;        } else if (Levitation) {
&nbsp;            You("pop out of the %s like a cork!", hliquid("water"));
&nbsp;        } else if (Flying) {
&nbsp;            You("fly out of the %s.", hliquid("water"));
&nbsp;        } else if (Wwalking) {
&nbsp;            You("slowly rise above the surface.");
&nbsp;        } else {
&nbsp;            still_inwater = TRUE;
&nbsp;        }
&nbsp;        if (!still_inwater) {
&nbsp;            boolean was_underwater = (Underwater &amp;&amp; !Is_waterlevel(&amp;u.uz));
&nbsp;
&nbsp;            u.uinwater = 0;       /* leave the water */
&nbsp;            if (was_underwater) { /* restore vision */
&nbsp;                docrt();
&nbsp;                vision_full_recalc = 1;
&nbsp;            }
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    /* check for entering water or lava */
&nbsp;    if (!u.ustuck &amp;&amp; !Levitation &amp;&amp; !Flying &amp;&amp; is_pool_or_lava(u.ux, u.uy)) {
&nbsp;        if (u.usteed
&nbsp;            &amp;&amp; (is_flyer(u.usteed-&gt;data) || is_floater(u.usteed-&gt;data)
&nbsp;                || is_clinger(u.usteed-&gt;data))) {
&nbsp;            /* floating or clinging steed keeps hero safe (is_flyer() test
&nbsp;               is redundant; it can't be true since Flying yielded false) */
&nbsp;            return FALSE;
&nbsp;        } else if (u.usteed) {
&nbsp;            /* steed enters pool */
&nbsp;            dismount_steed(Underwater ? DISMOUNT_FELL : DISMOUNT_GENERIC);
&nbsp;            /* dismount_steed() -&gt; float_down() -&gt; pickup()
&nbsp;               (float_down doesn't do autopickup on Air or Water) */
&nbsp;            if (Is_airlevel(&amp;u.uz) || Is_waterlevel(&amp;u.uz))
&nbsp;                return FALSE;
&nbsp;            /* even if we actually end up at same location, float_down()
&nbsp;               has already done spoteffect()'s trap and pickup actions */
&nbsp;            if (newspot)
&nbsp;                check_special_room(FALSE); /* spoteffects */
&nbsp;            return TRUE;
&nbsp;        }
&nbsp;        /* not mounted */
&nbsp;
&nbsp;        /* drown(),lava_effects() return true if hero changes
&nbsp;           location while surviving the problem */
&nbsp;        if (is_lava(u.ux, u.uy)) {
&nbsp;            if (lava_effects())
&nbsp;                return TRUE;
&nbsp;        } else if (!Wwalking
&nbsp;                   &amp;&amp; (newspot || !u.uinwater || !(Swimming || Amphibious))) {
&nbsp;            if (drown())
&nbsp;                return TRUE;
&nbsp;        }
&nbsp;    }
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
spoteffects
&nbsp;void
&nbsp;spoteffects(pick)
&nbsp;boolean pick;
&nbsp;{
&nbsp;    static int inspoteffects = 0;
&nbsp;    static coord spotloc;
&nbsp;    static int spotterrain;
&nbsp;    static struct trap *spottrap = (struct trap *) 0;
&nbsp;    static unsigned spottraptyp = NO_TRAP;
&nbsp;
&nbsp;    struct monst *mtmp;
&nbsp;    struct trap *trap = t_at(u.ux, u.uy);
&nbsp;
&nbsp;    /* prevent recursion from affecting the hero all over again
&nbsp;       [hero poly'd to iron golem enters water here, drown() inflicts
&nbsp;       damage that triggers rehumanize() which calls spoteffects()...] */
&nbsp;    if (inspoteffects &amp;&amp; u.ux == spotloc.x &amp;&amp; u.uy == spotloc.y
&nbsp;        /* except when reason is transformed terrain (ice -&gt; water) */
&nbsp;        &amp;&amp; spotterrain == levl[u.ux][u.uy].typ
&nbsp;        /* or transformed trap (land mine -&gt; pit) */
&nbsp;        &amp;&amp; (!spottrap || !trap || trap-&gt;ttyp == spottraptyp))
&nbsp;        return;
&nbsp;
&nbsp;    ++inspoteffects;
&nbsp;    spotterrain = levl[u.ux][u.uy].typ;
&nbsp;    spotloc.x = u.ux, spotloc.y = u.uy;
&nbsp;
&nbsp;    /* moving onto different terrain might cause Levitation to toggle */
&nbsp;    if (spotterrain != levl[u.ux0][u.uy0].typ || !on_level(&amp;u.uz, &amp;u.uz0))
&nbsp;        switch_terrain();
&nbsp;
&nbsp;    if (pooleffects(TRUE))
&nbsp;        goto spotdone;
&nbsp;
&nbsp;    check_special_room(FALSE);
&nbsp;    if (IS_SINK(levl[u.ux][u.uy].typ) &amp;&amp; Levitation)
&nbsp;        dosinkfall();
&nbsp;    if (!in_steed_dismounting) { /* if dismounting, we'll check again later */
&nbsp;        boolean pit;
&nbsp;
&nbsp;        /* if levitation is due to time out at the end of this
&nbsp;           turn, allowing it to do so could give the perception
&nbsp;           that a trap here is being triggered twice, so adjust
&nbsp;           the timeout to prevent that */
&nbsp;        if (trap &amp;&amp; (HLevitation &amp; TIMEOUT) == 1L
&nbsp;            &amp;&amp; !(ELevitation || (HLevitation &amp; ~(I_SPECIAL | TIMEOUT)))) {
&nbsp;            if (rn2(2)) { /* defer timeout */
&nbsp;                incr_itimeout(&amp;HLevitation, 1L);
&nbsp;            } else { /* timeout early */
&nbsp;                if (float_down(I_SPECIAL | TIMEOUT, 0L)) {
&nbsp;                    /* levitation has ended; we've already triggered
&nbsp;                       any trap and [usually] performed autopickup */
&nbsp;                    trap = 0;
&nbsp;                    pick = FALSE;
&nbsp;                }
&nbsp;            }
&nbsp;        }
&nbsp;        /*
&nbsp;         * If not a pit, pickup before triggering trap.
&nbsp;         * If pit, trigger trap before pickup.
&nbsp;         */
&nbsp;        pit = (trap &amp;&amp; (trap-&gt;ttyp == PIT || trap-&gt;ttyp == SPIKED_PIT));
&nbsp;        if (pick &amp;&amp; !pit)
&nbsp;            (void) pickup(1);
&nbsp;
&nbsp;        if (trap) {
&nbsp;            /*
&nbsp;             * dotrap on a fire trap calls melt_ice() which triggers
&nbsp;             * spoteffects() (again) which can trigger the same fire
&nbsp;             * trap (again). Use static spottrap to prevent that.
&nbsp;             * We track spottraptyp because some traps morph
&nbsp;             * (landmine to pit) and any new trap type
&nbsp;             * should get triggered.
&nbsp;             */
&nbsp;            if (!spottrap || spottraptyp != trap-&gt;ttyp) {
&nbsp;                spottrap = trap;
&nbsp;                spottraptyp = trap-&gt;ttyp;
&nbsp;                dotrap(trap, 0); /* fall into arrow trap, etc. */
&nbsp;                spottrap = (struct trap *) 0;
&nbsp;                spottraptyp = NO_TRAP;
&nbsp;            }
&nbsp;        }
&nbsp;        if (pick &amp;&amp; pit)
&nbsp;            (void) pickup(1);
&nbsp;    }
&nbsp;    /* Warning alerts you to ice danger */
&nbsp;    if (Warning &amp;&amp; is_ice(u.ux, u.uy)) {
&nbsp;        static const char *const icewarnings[] = {
&nbsp;            "The ice seems very soft and slushy.",
&nbsp;            "You feel the ice shift beneath you!",
&nbsp;            "The ice, is gonna BREAK!", /* The Dead Zone */
&nbsp;        };
&nbsp;        long time_left = spot_time_left(u.ux, u.uy, MELT_ICE_AWAY);
&nbsp;
&nbsp;        if (time_left &amp;&amp; time_left &lt; 15L)
&nbsp;            pline("%s", icewarnings[(time_left &lt; 5L) ? 2
&nbsp;                                    : (time_left &lt; 10L) ? 1
&nbsp;                                      : 0]);
&nbsp;    }
&nbsp;    if ((mtmp = m_at(u.ux, u.uy)) &amp;&amp; !u.uswallow) {
&nbsp;        mtmp-&gt;mundetected = mtmp-&gt;msleeping = 0;
&nbsp;        switch (mtmp-&gt;data-&gt;mlet) {
&nbsp;        case S_PIERCER:
&nbsp;            pline("%s suddenly drops from the %s!", Amonnam(mtmp),
&nbsp;                  ceiling(u.ux, u.uy));
&nbsp;            if (mtmp-&gt;mtame) { /* jumps to greet you, not attack */
&nbsp;                ;
&nbsp;            } else if (uarmh &amp;&amp; is_metallic(uarmh)) {
&nbsp;                pline("Its blow glances off your %s.",
&nbsp;                      helm_simple_name(uarmh));
&nbsp;            } else if (u.uac + 3 &lt;= rnd(20)) {
&nbsp;                You("are almost hit by %s!",
&nbsp;                    x_monnam(mtmp, ARTICLE_A, "falling", 0, TRUE));
&nbsp;            } else {
&nbsp;                int dmg;
&nbsp;
&nbsp;                You("are hit by %s!",
&nbsp;                    x_monnam(mtmp, ARTICLE_A, "falling", 0, TRUE));
&nbsp;                dmg = d(4, 6);
&nbsp;                if (Half_physical_damage)
&nbsp;                    dmg = (dmg + 1) / 2;
&nbsp;                mdamageu(mtmp, dmg);
&nbsp;            }
&nbsp;            break;
&nbsp;        default: /* monster surprises you. */
&nbsp;            if (mtmp-&gt;mtame)
&nbsp;                pline("%s jumps near you from the %s.", Amonnam(mtmp),
&nbsp;                      ceiling(u.ux, u.uy));
&nbsp;            else if (mtmp-&gt;mpeaceful) {
&nbsp;                You("surprise %s!",
&nbsp;                    Blind &amp;&amp; !sensemon(mtmp) ? something : a_monnam(mtmp));
&nbsp;                mtmp-&gt;mpeaceful = 0;
&nbsp;            } else
&nbsp;                pline("%s attacks you by surprise!", Amonnam(mtmp));
&nbsp;            break;
&nbsp;        }
&nbsp;        mnexto(mtmp); /* have to move the monster */
&nbsp;    }
&nbsp;spotdone:
&nbsp;    if (!--inspoteffects) {
&nbsp;        spotterrain = STONE; /* 0 */
&nbsp;        spotloc.x = spotloc.y = 0;
&nbsp;    }
&nbsp;    return;
&nbsp;}
&nbsp;
monstinroom
&nbsp;/* returns first matching monster */
&nbsp;STATIC_OVL struct monst *
&nbsp;monstinroom(mdat, roomno)
&nbsp;struct permonst *mdat;
&nbsp;int roomno;
&nbsp;{
&nbsp;    register struct monst *mtmp;
&nbsp;
&nbsp;    for (mtmp = fmon; mtmp; mtmp = mtmp-&gt;nmon) {
&nbsp;        if (DEADMONSTER(mtmp))
&nbsp;            continue;
&nbsp;        if (mtmp-&gt;data == mdat
&nbsp;            &amp;&amp; index(in_rooms(mtmp-&gt;mx, mtmp-&gt;my, 0), roomno + ROOMOFFSET))
&nbsp;            return mtmp;
&nbsp;    }
&nbsp;    return (struct monst *) 0;
&nbsp;}
&nbsp;
in_rooms
&nbsp;char *
&nbsp;in_rooms(x, y, typewanted)
&nbsp;register xchar x, y;
&nbsp;register int typewanted;
&nbsp;{
&nbsp;    static char buf[5];
&nbsp;    char rno, *ptr = &amp;buf[4];
&nbsp;    int typefound, min_x, min_y, max_x, max_y_offset, step;
&nbsp;    register struct rm *lev;
&nbsp;
&nbsp;#define goodtype(rno)   \
&nbsp;    (!typewanted                                                    \
&nbsp;     || (typefound = rooms[rno - ROOMOFFSET].rtype) == typewanted   \
&nbsp;     || (typewanted == SHOPBASE &amp;&amp; typefound &gt; SHOPBASE))
&nbsp;
&nbsp;    switch (rno = levl[x][y].roomno) {
&nbsp;    case NO_ROOM:
&nbsp;        return ptr;
&nbsp;    case SHARED:
&nbsp;        step = 2;
&nbsp;        break;
&nbsp;    case SHARED_PLUS:
&nbsp;        step = 1;
&nbsp;        break;
&nbsp;    default: /* i.e. a regular room # */
&nbsp;        if (goodtype(rno))
&nbsp;            *(--ptr) = rno;
&nbsp;        return ptr;
&nbsp;    }
&nbsp;
&nbsp;    min_x = x - 1;
&nbsp;    max_x = x + 1;
&nbsp;    if (x &lt; 1)
&nbsp;        min_x += step;
&nbsp;    else if (x &gt;= COLNO)
&nbsp;        max_x -= step;
&nbsp;
&nbsp;    min_y = y - 1;
&nbsp;    max_y_offset = 2;
&nbsp;    if (min_y &lt; 0) {
&nbsp;        min_y += step;
&nbsp;        max_y_offset -= step;
&nbsp;    } else if ((min_y + max_y_offset) &gt;= ROWNO)
&nbsp;        max_y_offset -= step;
&nbsp;
&nbsp;    for (x = min_x; x &lt;= max_x; x += step) {
&nbsp;        lev = &amp;levl[x][min_y];
&nbsp;        y = 0;
&nbsp;        if ((rno = lev[y].roomno) &gt;= ROOMOFFSET &amp;&amp; !index(ptr, rno)
&nbsp;            &amp;&amp; goodtype(rno))
&nbsp;            *(--ptr) = rno;
&nbsp;        y += step;
&nbsp;        if (y &gt; max_y_offset)
&nbsp;            continue;
&nbsp;        if ((rno = lev[y].roomno) &gt;= ROOMOFFSET &amp;&amp; !index(ptr, rno)
&nbsp;            &amp;&amp; goodtype(rno))
&nbsp;            *(--ptr) = rno;
&nbsp;        y += step;
&nbsp;        if (y &gt; max_y_offset)
&nbsp;            continue;
&nbsp;        if ((rno = lev[y].roomno) &gt;= ROOMOFFSET &amp;&amp; !index(ptr, rno)
&nbsp;            &amp;&amp; goodtype(rno))
&nbsp;            *(--ptr) = rno;
&nbsp;    }
&nbsp;    return ptr;
&nbsp;}
&nbsp;
in_town
&nbsp;/* is (x,y) in a town? */
&nbsp;boolean
&nbsp;in_town(x, y)
&nbsp;register int x, y;
&nbsp;{
&nbsp;    s_level *slev = Is_special(&amp;u.uz);
&nbsp;    register struct mkroom *sroom;
&nbsp;    boolean has_subrooms = FALSE;
&nbsp;
&nbsp;    if (!slev || !slev-&gt;flags.town)
&nbsp;        return FALSE;
&nbsp;
&nbsp;    /*
&nbsp;     * See if (x,y) is in a room with subrooms, if so, assume it's the
&nbsp;     * town.  If there are no subrooms, the whole level is in town.
&nbsp;     */
&nbsp;    for (sroom = &amp;rooms[0]; sroom-&gt;hx &gt; 0; sroom++) {
&nbsp;        if (sroom-&gt;nsubrooms &gt; 0) {
&nbsp;            has_subrooms = TRUE;
&nbsp;            if (inside_room(sroom, x, y))
&nbsp;                return TRUE;
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    return !has_subrooms;
&nbsp;}
&nbsp;
move_update
&nbsp;STATIC_OVL void
&nbsp;move_update(newlev)
&nbsp;register boolean newlev;
&nbsp;{
&nbsp;    char *ptr1, *ptr2, *ptr3, *ptr4;
&nbsp;
&nbsp;    Strcpy(u.urooms0, u.urooms);
&nbsp;    Strcpy(u.ushops0, u.ushops);
&nbsp;    if (newlev) {
&nbsp;        u.urooms[0] = '\0';
&nbsp;        u.uentered[0] = '\0';
&nbsp;        u.ushops[0] = '\0';
&nbsp;        u.ushops_entered[0] = '\0';
&nbsp;        Strcpy(u.ushops_left, u.ushops0);
&nbsp;        return;
&nbsp;    }
&nbsp;    Strcpy(u.urooms, in_rooms(u.ux, u.uy, 0));
&nbsp;
&nbsp;    for (ptr1 = &amp;u.urooms[0], ptr2 = &amp;u.uentered[0], ptr3 = &amp;u.ushops[0],
&nbsp;         ptr4 = &amp;u.ushops_entered[0];
&nbsp;         *ptr1; ptr1++) {
&nbsp;        if (!index(u.urooms0, *ptr1))
&nbsp;            *(ptr2++) = *ptr1;
&nbsp;        if (IS_SHOP(*ptr1 - ROOMOFFSET)) {
&nbsp;            *(ptr3++) = *ptr1;
&nbsp;            if (!index(u.ushops0, *ptr1))
&nbsp;                *(ptr4++) = *ptr1;
&nbsp;        }
&nbsp;    }
&nbsp;    *ptr2 = '\0';
&nbsp;    *ptr3 = '\0';
&nbsp;    *ptr4 = '\0';
&nbsp;
&nbsp;    /* filter u.ushops0 -&gt; u.ushops_left */
&nbsp;    for (ptr1 = &amp;u.ushops0[0], ptr2 = &amp;u.ushops_left[0]; *ptr1; ptr1++)
&nbsp;        if (!index(u.ushops, *ptr1))
&nbsp;            *(ptr2++) = *ptr1;
&nbsp;    *ptr2 = '\0';
&nbsp;}
&nbsp;
check_special_room
&nbsp;/* possibly deliver a one-time room entry message */
&nbsp;void
&nbsp;check_special_room(newlev)
&nbsp;register boolean newlev;
&nbsp;{
&nbsp;    register struct monst *mtmp;
&nbsp;    char *ptr;
&nbsp;
&nbsp;    move_update(newlev);
&nbsp;
&nbsp;    if (*u.ushops0)
&nbsp;        u_left_shop(u.ushops_left, newlev);
&nbsp;
&nbsp;    if (!*u.uentered &amp;&amp; !*u.ushops_entered) /* implied by newlev */
&nbsp;        return; /* no entrance messages necessary */
&nbsp;
&nbsp;    /* Did we just enter a shop? */
&nbsp;    if (*u.ushops_entered)
&nbsp;        u_entered_shop(u.ushops_entered);
&nbsp;
&nbsp;    for (ptr = &amp;u.uentered[0]; *ptr; ptr++) {
&nbsp;        int roomno = *ptr - ROOMOFFSET, rt = rooms[roomno].rtype;
&nbsp;        boolean msg_given = TRUE;
&nbsp;
&nbsp;        /* Did we just enter some other special room? */
&nbsp;        /* vault.c insists that a vault remain a VAULT,
&nbsp;         * and temples should remain TEMPLEs,
&nbsp;         * but everything else gives a message only the first time */
&nbsp;        switch (rt) {
&nbsp;        case ZOO:
&nbsp;            pline("Welcome to David's treasure zoo!");
&nbsp;            break;
&nbsp;        case SWAMP:
&nbsp;            pline("It %s rather %s down here.", Blind ? "feels" : "looks",
&nbsp;                  Blind ? "humid" : "muddy");
&nbsp;            break;
&nbsp;        case COURT:
&nbsp;            You("enter an opulent throne room!");
&nbsp;            break;
&nbsp;        case LEPREHALL:
&nbsp;            You("enter a leprechaun hall!");
&nbsp;            break;
&nbsp;        case MORGUE:
&nbsp;            if (midnight()) {
&nbsp;                const char *run = locomotion(youmonst.data, "Run");
&nbsp;                pline("%s away!  %s away!", run, run);
&nbsp;            } else
&nbsp;                You("have an uncanny feeling...");
&nbsp;            break;
&nbsp;        case BEEHIVE:
&nbsp;            You("enter a giant beehive!");
&nbsp;            break;
&nbsp;        case COCKNEST:
&nbsp;            You("enter a disgusting nest!");
&nbsp;            break;
&nbsp;        case ANTHOLE:
&nbsp;            You("enter an anthole!");
&nbsp;            break;
&nbsp;        case BARRACKS:
&nbsp;            if (monstinroom(&amp;mons[PM_SOLDIER], roomno)
&nbsp;                || monstinroom(&amp;mons[PM_SERGEANT], roomno)
&nbsp;                || monstinroom(&amp;mons[PM_LIEUTENANT], roomno)
&nbsp;                || monstinroom(&amp;mons[PM_CAPTAIN], roomno))
&nbsp;                You("enter a military barracks!");
&nbsp;            else
&nbsp;                You("enter an abandoned barracks.");
&nbsp;            break;
&nbsp;        case DELPHI: {
&nbsp;            struct monst *oracle = monstinroom(&amp;mons[PM_ORACLE], roomno);
&nbsp;            if (oracle) {
&nbsp;                if (!oracle-&gt;mpeaceful)
&nbsp;                    verbalize("You're in Delphi, %s.", plname);
&nbsp;                else
&nbsp;                    verbalize("%s, %s, welcome to Delphi!",
&nbsp;                              Hello((struct monst *) 0), plname);
&nbsp;            } else
&nbsp;                msg_given = FALSE;
&nbsp;            break;
&nbsp;        }
&nbsp;        case TEMPLE:
&nbsp;            intemple(roomno + ROOMOFFSET);
&nbsp;        /*FALLTHRU*/
&nbsp;        default:
&nbsp;            msg_given = (rt == TEMPLE);
&nbsp;            rt = 0;
&nbsp;            break;
&nbsp;        }
&nbsp;        if (msg_given)
&nbsp;            room_discovered(roomno);
&nbsp;
&nbsp;        if (rt != 0) {
&nbsp;            rooms[roomno].rtype = OROOM;
&nbsp;            if (!search_special(rt)) {
&nbsp;                /* No more room of that type */
&nbsp;                switch (rt) {
&nbsp;                case COURT:
&nbsp;                    level.flags.has_court = 0;
&nbsp;                    break;
&nbsp;                case SWAMP:
&nbsp;                    level.flags.has_swamp = 0;
&nbsp;                    break;
&nbsp;                case MORGUE:
&nbsp;                    level.flags.has_morgue = 0;
&nbsp;                    break;
&nbsp;                case ZOO:
&nbsp;                    level.flags.has_zoo = 0;
&nbsp;                    break;
&nbsp;                case BARRACKS:
&nbsp;                    level.flags.has_barracks = 0;
&nbsp;                    break;
&nbsp;                case TEMPLE:
&nbsp;                    level.flags.has_temple = 0;
&nbsp;                    break;
&nbsp;                case BEEHIVE:
&nbsp;                    level.flags.has_beehive = 0;
&nbsp;                    break;
&nbsp;                }
&nbsp;            }
&nbsp;            if (rt == COURT || rt == SWAMP || rt == MORGUE || rt == ZOO)
&nbsp;                for (mtmp = fmon; mtmp; mtmp = mtmp-&gt;nmon) {
&nbsp;                    if (DEADMONSTER(mtmp))
&nbsp;                        continue;
&nbsp;                    if (!Stealth &amp;&amp; !rn2(3))
&nbsp;                        mtmp-&gt;msleeping = 0;
&nbsp;                }
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    return;
&nbsp;}
&nbsp;
dopickup
&nbsp;/* the ',' command */
&nbsp;int
&nbsp;dopickup()
&nbsp;{
&nbsp;    int count, tmpcount;
&nbsp;    struct trap *traphere = t_at(u.ux, u.uy);
&nbsp;
&nbsp;    /* awful kludge to work around parse()'s pre-decrement */
&nbsp;    count = (multi || (save_cm &amp;&amp; *save_cm == ',')) ? multi + 1 : 0;
&nbsp;    multi = 0; /* always reset */
&nbsp;    /* uswallow case added by GAN 01/29/87 */
&nbsp;    if (u.uswallow) {
&nbsp;        if (!u.ustuck-&gt;minvent) {
&nbsp;            if (is_animal(u.ustuck-&gt;data)) {
&nbsp;                You("pick up %s tongue.", s_suffix(mon_nam(u.ustuck)));
&nbsp;                pline("But it's kind of slimy, so you drop it.");
&nbsp;            } else
&nbsp;                You("don't %s anything in here to pick up.",
&nbsp;                    Blind ? "feel" : "see");
&nbsp;            return 1;
&nbsp;        } else {
&nbsp;            tmpcount = -count;
&nbsp;            return loot_mon(u.ustuck, &amp;tmpcount, (boolean *) 0);
&nbsp;        }
&nbsp;    }
&nbsp;    if (is_pool(u.ux, u.uy)) {
&nbsp;        if (Wwalking || is_floater(youmonst.data) || is_clinger(youmonst.data)
&nbsp;            || (Flying &amp;&amp; !Breathless)) {
&nbsp;            You("cannot dive into the %s to pick things up.",
&nbsp;                hliquid("water"));
&nbsp;            return 0;
&nbsp;        } else if (!Underwater) {
&nbsp;            You_cant("even see the bottom, let alone pick up %s.", something);
&nbsp;            return 0;
&nbsp;        }
&nbsp;    }
&nbsp;    if (is_lava(u.ux, u.uy)) {
&nbsp;        if (Wwalking || is_floater(youmonst.data) || is_clinger(youmonst.data)
&nbsp;            || (Flying &amp;&amp; !Breathless)) {
&nbsp;            You_cant("reach the bottom to pick things up.");
&nbsp;            return 0;
&nbsp;        } else if (!likes_lava(youmonst.data)) {
&nbsp;            You("would burn to a crisp trying to pick things up.");
&nbsp;            return 0;
&nbsp;        }
&nbsp;    }
&nbsp;    if (!OBJ_AT(u.ux, u.uy)) {
&nbsp;        register struct rm *lev = &amp;levl[u.ux][u.uy];
&nbsp;
&nbsp;        if (IS_THRONE(lev-&gt;typ))
&nbsp;            pline("It must weigh%s a ton!", lev-&gt;looted ? " almost" : "");
&nbsp;        else if (IS_SINK(lev-&gt;typ))
&nbsp;            pline_The("plumbing connects it to the floor.");
&nbsp;        else if (IS_GRAVE(lev-&gt;typ))
&nbsp;            You("don't need a gravestone.  Yet.");
&nbsp;        else if (IS_FOUNTAIN(lev-&gt;typ))
&nbsp;            You("could drink the %s...", hliquid("water"));
&nbsp;        else if (IS_DOOR(lev-&gt;typ) &amp;&amp; (lev-&gt;doormask &amp; D_ISOPEN))
&nbsp;            pline("It won't come off the hinges.");
&nbsp;        else
&nbsp;            There("is nothing here to pick up.");
&nbsp;        return 0;
&nbsp;    }
&nbsp;    if (!can_reach_floor(TRUE)) {
&nbsp;        if (traphere &amp;&amp; uteetering_at_seen_pit(traphere))
&nbsp;            You("cannot reach the bottom of the pit.");
&nbsp;        else if (u.usteed &amp;&amp; P_SKILL(P_RIDING) &lt; P_BASIC)
&nbsp;            rider_cant_reach();
&nbsp;        else if (Blind &amp;&amp; !can_reach_floor(TRUE))
&nbsp;            You("cannot reach anything here.");
&nbsp;        else
&nbsp;            You("cannot reach the %s.", surface(u.ux, u.uy));
&nbsp;        return 0;
&nbsp;    }
&nbsp;
&nbsp;    return pickup(-count);
&nbsp;}
&nbsp;
lookaround
&nbsp;/* stop running if we see something interesting */
&nbsp;/* turn around a corner if that is the only way we can proceed */
&nbsp;/* do not turn left or right twice */
&nbsp;void
&nbsp;lookaround()
&nbsp;{
&nbsp;    register int x, y;
&nbsp;    int i, x0 = 0, y0 = 0, m0 = 1, i0 = 9;
&nbsp;    int corrct = 0, noturn = 0;
&nbsp;    struct monst *mtmp;
&nbsp;    struct trap *trap;
&nbsp;
&nbsp;    /* Grid bugs stop if trying to move diagonal, even if blind.  Maybe */
&nbsp;    /* they polymorphed while in the middle of a long move. */
&nbsp;    if (NODIAG(u.umonnum) &amp;&amp; u.dx &amp;&amp; u.dy) {
&nbsp;        You("cannot move diagonally.");
&nbsp;        nomul(0);
&nbsp;        return;
&nbsp;    }
&nbsp;
&nbsp;    if (Blind || context.run == 0)
&nbsp;        return;
&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 (!isok(x, y) || (x == u.ux &amp;&amp; y == u.uy))
&nbsp;                continue;
&nbsp;            if (NODIAG(u.umonnum) &amp;&amp; x != u.ux &amp;&amp; y != u.uy)
&nbsp;                continue;
&nbsp;
&nbsp;            if ((mtmp = m_at(x, y)) != 0
&nbsp;                &amp;&amp; mtmp-&gt;m_ap_type != M_AP_FURNITURE
&nbsp;                &amp;&amp; mtmp-&gt;m_ap_type != M_AP_OBJECT
&nbsp;                &amp;&amp; (!mtmp-&gt;minvis || See_invisible) &amp;&amp; !mtmp-&gt;mundetected) {
&nbsp;                if ((context.run != 1 &amp;&amp; !mtmp-&gt;mtame)
&nbsp;                    || (x == u.ux + u.dx &amp;&amp; y == u.uy + u.dy
&nbsp;                        &amp;&amp; !context.travel)) {
&nbsp;                    if (iflags.mention_walls)
&nbsp;                        pline("%s blocks your path.", upstart(a_monnam(mtmp)));
&nbsp;                    goto stop;
&nbsp;                }
&nbsp;            }
&nbsp;
&nbsp;            if (levl[x][y].typ == STONE)
&nbsp;                continue;
&nbsp;            if (x == u.ux - u.dx &amp;&amp; y == u.uy - u.dy)
&nbsp;                continue;
&nbsp;
&nbsp;            if (IS_ROCK(levl[x][y].typ) || levl[x][y].typ == ROOM
&nbsp;                || IS_AIR(levl[x][y].typ)) {
&nbsp;                continue;
&nbsp;            } else if (closed_door(x, y) || (mtmp &amp;&amp; is_door_mappear(mtmp))) {
&nbsp;                if (x != u.ux &amp;&amp; y != u.uy)
&nbsp;                    continue;
&nbsp;                if (context.run != 1) {
&nbsp;                    if (iflags.mention_walls)
&nbsp;                        You("stop in front of the door.");
&nbsp;                    goto stop;
&nbsp;                }
&nbsp;                goto bcorr;
&nbsp;            } else if (levl[x][y].typ == CORR) {
&nbsp;            bcorr:
&nbsp;                if (levl[u.ux][u.uy].typ != ROOM) {
&nbsp;                    if (context.run == 1 || context.run == 3
&nbsp;                        || context.run == 8) {
&nbsp;                        i = dist2(x, y, u.ux + u.dx, u.uy + u.dy);
&nbsp;                        if (i &gt; 2)
&nbsp;                            continue;
&nbsp;                        if (corrct == 1 &amp;&amp; dist2(x, y, x0, y0) != 1)
&nbsp;                            noturn = 1;
&nbsp;                        if (i &lt; i0) {
&nbsp;                            i0 = i;
&nbsp;                            x0 = x;
&nbsp;                            y0 = y;
&nbsp;                            m0 = mtmp ? 1 : 0;
&nbsp;                        }
&nbsp;                    }
&nbsp;                    corrct++;
&nbsp;                }
&nbsp;                continue;
&nbsp;            } else if ((trap = t_at(x, y)) &amp;&amp; trap-&gt;tseen) {
&nbsp;                if (context.run == 1)
&nbsp;                    goto bcorr; /* if you must */
&nbsp;                if (x == u.ux + u.dx &amp;&amp; y == u.uy + u.dy) {
&nbsp;                    if (iflags.mention_walls) {
&nbsp;                        int tt = what_trap(trap-&gt;ttyp);
&nbsp;                        You("stop in front of %s.",
&nbsp;                            an(defsyms[trap_to_defsym(tt)].explanation));
&nbsp;                    }
&nbsp;                    goto stop;
&nbsp;                }
&nbsp;                continue;
&nbsp;            } else if (is_pool_or_lava(x, y)) {
&nbsp;                /* water and lava only stop you if directly in front, and stop
&nbsp;                 * you even if you are running
&nbsp;                 */
&nbsp;                if (!Levitation &amp;&amp; !Flying &amp;&amp; !is_clinger(youmonst.data)
&nbsp;                    &amp;&amp; x == u.ux + u.dx &amp;&amp; y == u.uy + u.dy) {
&nbsp;                    /* No Wwalking check; otherwise they'd be able
&nbsp;                     * to test boots by trying to SHIFT-direction
&nbsp;                     * into a pool and seeing if the game allowed it
&nbsp;                     */
&nbsp;                    if (iflags.mention_walls)
&nbsp;                        You("stop at the edge of the %s.",
&nbsp;                            hliquid(is_pool(x,y) ? "water" : "lava"));
&nbsp;                    goto stop;
&nbsp;                }
&nbsp;                continue;
&nbsp;            } else { /* e.g. objects or trap or stairs */
&nbsp;                if (context.run == 1)
&nbsp;                    goto bcorr;
&nbsp;                if (context.run == 8)
&nbsp;                    continue;
&nbsp;                if (mtmp)
&nbsp;                    continue; /* d */
&nbsp;                if (((x == u.ux - u.dx) &amp;&amp; (y != u.uy + u.dy))
&nbsp;                    || ((y == u.uy - u.dy) &amp;&amp; (x != u.ux + u.dx)))
&nbsp;                    continue;
&nbsp;            }
&nbsp;        stop:
&nbsp;            nomul(0);
&nbsp;            return;
&nbsp;        } /* end for loops */
&nbsp;
&nbsp;    if (corrct &gt; 1 &amp;&amp; context.run == 2) {
&nbsp;        if (iflags.mention_walls)
&nbsp;            pline_The("corridor widens here.");
&nbsp;        goto stop;
&nbsp;    }
&nbsp;    if ((context.run == 1 || context.run == 3 || context.run == 8) &amp;&amp; !noturn
&nbsp;        &amp;&amp; !m0 &amp;&amp; i0 &amp;&amp; (corrct == 1 || (corrct == 2 &amp;&amp; i0 == 1))) {
&nbsp;        /* make sure that we do not turn too far */
&nbsp;        if (i0 == 2) {
&nbsp;            if (u.dx == y0 - u.uy &amp;&amp; u.dy == u.ux - x0)
&nbsp;                i = 2; /* straight turn right */
&nbsp;            else
&nbsp;                i = -2; /* straight turn left */
&nbsp;        } else if (u.dx &amp;&amp; u.dy) {
&nbsp;            if ((u.dx == u.dy &amp;&amp; y0 == u.uy) || (u.dx != u.dy &amp;&amp; y0 != u.uy))
&nbsp;                i = -1; /* half turn left */
&nbsp;            else
&nbsp;                i = 1; /* half turn right */
&nbsp;        } else {
&nbsp;            if ((x0 - u.ux == y0 - u.uy &amp;&amp; !u.dy)
&nbsp;                || (x0 - u.ux != y0 - u.uy &amp;&amp; u.dy))
&nbsp;                i = 1; /* half turn right */
&nbsp;            else
&nbsp;                i = -1; /* half turn left */
&nbsp;        }
&nbsp;
&nbsp;        i += u.last_str_turn;
&nbsp;        if (i &lt;= 2 &amp;&amp; i &gt;= -2) {
&nbsp;            u.last_str_turn = i;
&nbsp;            u.dx = x0 - u.ux;
&nbsp;            u.dy = y0 - u.uy;
&nbsp;        }
&nbsp;    }
&nbsp;}
&nbsp;
doorless_door
&nbsp;/* check for a doorway which lacks its door (NODOOR or BROKEN) */
&nbsp;STATIC_OVL boolean
&nbsp;doorless_door(x, y)
&nbsp;int x, y;
&nbsp;{
&nbsp;    struct rm *lev_p = &amp;levl[x][y];
&nbsp;
&nbsp;    if (!IS_DOOR(lev_p-&gt;typ))
&nbsp;        return FALSE;
&nbsp;    /* all rogue level doors are doorless but disallow diagonal access, so
&nbsp;       we treat them as if their non-existant doors were actually present */
&nbsp;    if (Is_rogue_level(&amp;u.uz))
&nbsp;        return FALSE;
&nbsp;    return !(lev_p-&gt;doormask &amp; ~(D_NODOOR | D_BROKEN));
&nbsp;}
&nbsp;
crawl_destination
&nbsp;/* used by drown() to check whether hero can crawl from water to <x,y> */
&nbsp;boolean
&nbsp;crawl_destination(x, y)
&nbsp;int x, y;
&nbsp;{
&nbsp;    /* is location ok in general? */
&nbsp;    if (!goodpos(x, y, &amp;youmonst, 0))
&nbsp;        return FALSE;
&nbsp;
&nbsp;    /* orthogonal movement is unrestricted when destination is ok */
&nbsp;    if (x == u.ux || y == u.uy)
&nbsp;        return TRUE;
&nbsp;
&nbsp;    /* diagonal movement has some restrictions */
&nbsp;    if (NODIAG(u.umonnum))
&nbsp;        return FALSE; /* poly'd into a grid bug... */
&nbsp;    if (Passes_walls)
&nbsp;        return TRUE; /* or a xorn... */
&nbsp;    /* pool could be next to a door, conceivably even inside a shop */
&nbsp;    if (IS_DOOR(levl[x][y].typ) &amp;&amp; (!doorless_door(x, y) || block_door(x, y)))
&nbsp;        return FALSE;
&nbsp;    /* finally, are we trying to squeeze through a too-narrow gap? */
&nbsp;    return !(bad_rock(youmonst.data, u.ux, y)
&nbsp;             &amp;&amp; bad_rock(youmonst.data, x, u.uy));
&nbsp;}
&nbsp;
monster_nearby
&nbsp;/* something like lookaround, but we are not running */
&nbsp;/* react only to monsters that might hit us */
&nbsp;int
&nbsp;monster_nearby()
&nbsp;{
&nbsp;    register int x, y;
&nbsp;    register struct monst *mtmp;
&nbsp;
&nbsp;    /* Also see the similar check in dochugw() in monmove.c */
&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 (!isok(x, y) || (x == u.ux &amp;&amp; y == u.uy))
&nbsp;                continue;
&nbsp;            if ((mtmp = m_at(x, y)) &amp;&amp; mtmp-&gt;m_ap_type != M_AP_FURNITURE
&nbsp;                &amp;&amp; mtmp-&gt;m_ap_type != M_AP_OBJECT
&nbsp;                &amp;&amp; (!mtmp-&gt;mpeaceful || Hallucination)
&nbsp;                &amp;&amp; (!is_hider(mtmp-&gt;data) || !mtmp-&gt;mundetected)
&nbsp;                &amp;&amp; !noattacks(mtmp-&gt;data) &amp;&amp; mtmp-&gt;mcanmove
&nbsp;                &amp;&amp; !mtmp-&gt;msleeping  /* aplvax!jcn */
&nbsp;                &amp;&amp; !onscary(u.ux, u.uy, mtmp) &amp;&amp; canspotmon(mtmp))
&nbsp;                return 1;
&nbsp;        }
&nbsp;    return 0;
&nbsp;}
&nbsp;
nomul
&nbsp;void
&nbsp;nomul(nval)
&nbsp;register int nval;
&nbsp;{
&nbsp;    if (multi &lt; nval)
&nbsp;        return;              /* This is a bug fix by ab@unido */
&nbsp;    u.uinvulnerable = FALSE; /* Kludge to avoid ctrl-C bug -dlc */
&nbsp;    u.usleep = 0;
&nbsp;    multi = nval;
&nbsp;    if (nval == 0)
&nbsp;        multi_reason = NULL;
&nbsp;    context.travel = context.travel1 = context.mv = context.run = 0;
&nbsp;}
&nbsp;
unmul
&nbsp;/* called when a non-movement, multi-turn action has completed */
&nbsp;void
&nbsp;unmul(msg_override)
&nbsp;const char *msg_override;
&nbsp;{
&nbsp;    multi = 0; /* caller will usually have done this already */
&nbsp;    if (msg_override)
&nbsp;        nomovemsg = msg_override;
&nbsp;    else if (!nomovemsg)
&nbsp;        nomovemsg = You_can_move_again;
&nbsp;    if (*nomovemsg)
&nbsp;        pline1(nomovemsg);
&nbsp;    nomovemsg = 0;
&nbsp;    u.usleep = 0;
&nbsp;    multi_reason = NULL;
&nbsp;    if (afternmv) {
&nbsp;        int NDECL((*f)) = afternmv;
&nbsp;        /* clear afternmv before calling it (to override the
&nbsp;           encumbrance hack for levitation--see weight_cap()) */
&nbsp;        afternmv = (int NDECL((*))) 0;
&nbsp;        (void) (*f)();
&nbsp;    }
&nbsp;}
&nbsp;
maybe_wail
&nbsp;STATIC_OVL void
&nbsp;maybe_wail()
&nbsp;{
&nbsp;    static short powers[] = { TELEPORT, SEE_INVIS, POISON_RES, COLD_RES,
&nbsp;                              SHOCK_RES, FIRE_RES, SLEEP_RES, DISINT_RES,
&nbsp;                              TELEPORT_CONTROL, STEALTH, FAST, INVIS };
&nbsp;
&nbsp;    if (moves &lt;= wailmsg + 50)
&nbsp;        return;
&nbsp;
&nbsp;    wailmsg = moves;
&nbsp;    if (Role_if(PM_WIZARD) || Race_if(PM_ELF) || Role_if(PM_VALKYRIE)) {
&nbsp;        const char *who;
&nbsp;        int i, powercnt;
&nbsp;
&nbsp;        who = (Role_if(PM_WIZARD) || Role_if(PM_VALKYRIE)) ? urole.name.m
&nbsp;                                                           : "Elf";
&nbsp;        if (u.uhp == 1) {
&nbsp;            pline("%s is about to die.", who);
&nbsp;        } else {
&nbsp;            for (i = 0, powercnt = 0; i &lt; SIZE(powers); ++i)
&nbsp;                if (u.uprops[powers[i]].intrinsic &amp; INTRINSIC)
&nbsp;                    ++powercnt;
&nbsp;
&nbsp;            pline((powercnt &gt;= 4) ? "%s, all your powers will be lost..."
&nbsp;                                  : "%s, your life force is running out.",
&nbsp;                  who);
&nbsp;        }
&nbsp;    } else {
&nbsp;        You_hear(u.uhp == 1 ? "the wailing of the Banshee..."
&nbsp;                            : "the howling of the CwnAnnwn...");
&nbsp;    }
&nbsp;}
&nbsp;
losehp
&nbsp;void
&nbsp;losehp(n, knam, k_format)
&nbsp;register int n;
&nbsp;register const char *knam;
&nbsp;boolean k_format;
&nbsp;{
&nbsp;    if (Upolyd) {
&nbsp;        u.mh -= n;
&nbsp;        if (u.mhmax &lt; u.mh)
&nbsp;            u.mhmax = u.mh;
&nbsp;        context.botl = 1;
&nbsp;        if (u.mh &lt; 1)
&nbsp;            rehumanize();
&nbsp;        else if (n &gt; 0 &amp;&amp; u.mh * 10 &lt; u.mhmax &amp;&amp; Unchanging)
&nbsp;            maybe_wail();
&nbsp;        return;
&nbsp;    }
&nbsp;
&nbsp;    u.uhp -= n;
&nbsp;    if (u.uhp &gt; u.uhpmax)
&nbsp;        u.uhpmax = u.uhp; /* perhaps n was negative */
&nbsp;    else
&nbsp;        context.travel = context.travel1 = context.mv = context.run = 0;
&nbsp;    context.botl = 1;
&nbsp;    if (u.uhp &lt; 1) {
&nbsp;        killer.format = k_format;
&nbsp;        if (killer.name != knam) /* the thing that killed you */
&nbsp;            Strcpy(killer.name, knam ? knam : "");
&nbsp;        You("die...");
&nbsp;        done(DIED);
&nbsp;    } else if (n &gt; 0 &amp;&amp; u.uhp * 10 &lt; u.uhpmax) {
&nbsp;        maybe_wail();
&nbsp;    }
&nbsp;}
&nbsp;
weight_cap
&nbsp;int
&nbsp;weight_cap()
&nbsp;{
&nbsp;    long carrcap, save_ELev = ELevitation;
&nbsp;
&nbsp;    /* boots take multiple turns to wear but any properties they
&nbsp;       confer are enabled at the start rather than the end; that
&nbsp;       causes message sequencing issues for boots of levitation
&nbsp;       so defer their encumbrance benefit until they're fully worn */
&nbsp;    if (afternmv == Boots_on &amp;&amp; (ELevitation &amp; W_ARMF) != 0L) {
&nbsp;        ELevitation &amp;= ~W_ARMF;
&nbsp;        float_vs_flight(); /* in case Levitation is blocking Flying */
&nbsp;    }
&nbsp;
&nbsp;    carrcap = 25 * (ACURRSTR + ACURR(A_CON)) + 50;
&nbsp;    if (Upolyd) {
&nbsp;        /* consistent with can_carry() in mon.c */
&nbsp;        if (youmonst.data-&gt;mlet == S_NYMPH)
&nbsp;            carrcap = MAX_CARR_CAP;
&nbsp;        else if (!youmonst.data-&gt;cwt)
&nbsp;            carrcap = (carrcap * (long) youmonst.data-&gt;msize) / MZ_HUMAN;
&nbsp;        else if (!strongmonst(youmonst.data)
&nbsp;                 || (strongmonst(youmonst.data)
&nbsp;                     &amp;&amp; (youmonst.data-&gt;cwt &gt; WT_HUMAN)))
&nbsp;            carrcap = (carrcap * (long) youmonst.data-&gt;cwt / WT_HUMAN);
&nbsp;    }
&nbsp;
&nbsp;    if (Levitation || Is_airlevel(&amp;u.uz) /* pugh@cornell */
&nbsp;        || (u.usteed &amp;&amp; strongmonst(u.usteed-&gt;data))) {
&nbsp;        carrcap = MAX_CARR_CAP;
&nbsp;    } else {
&nbsp;        if (carrcap &gt; MAX_CARR_CAP)
&nbsp;            carrcap = MAX_CARR_CAP;
&nbsp;        if (!Flying) {
&nbsp;            if (EWounded_legs &amp; LEFT_SIDE)
&nbsp;                carrcap -= 100;
&nbsp;            if (EWounded_legs &amp; RIGHT_SIDE)
&nbsp;                carrcap -= 100;
&nbsp;        }
&nbsp;        if (carrcap &lt; 0)
&nbsp;            carrcap = 0;
&nbsp;    }
&nbsp;
&nbsp;    if (ELevitation != save_ELev) {
&nbsp;        ELevitation = save_ELev;
&nbsp;        float_vs_flight();
&nbsp;    }
&nbsp;
&nbsp;    return (int) carrcap;
&nbsp;}
&nbsp;
&nbsp;static int wc; /* current weight_cap(); valid after call to inv_weight() */
&nbsp;
inv_weight
&nbsp;/* returns how far beyond the normal capacity the player is currently. */
&nbsp;/* inv_weight() is negative if the player is below normal capacity. */
&nbsp;int
&nbsp;inv_weight()
&nbsp;{
&nbsp;    register struct obj *otmp = invent;
&nbsp;    register int wt = 0;
&nbsp;
&nbsp;    while (otmp) {
&nbsp;        if (otmp-&gt;oclass == COIN_CLASS)
&nbsp;            wt += (int) (((long) otmp-&gt;quan + 50L) / 100L);
&nbsp;        else if (otmp-&gt;otyp != BOULDER || !throws_rocks(youmonst.data))
&nbsp;            wt += otmp-&gt;owt;
&nbsp;        otmp = otmp-&gt;nobj;
&nbsp;    }
&nbsp;    wc = weight_cap();
&nbsp;    return (wt - wc);
&nbsp;}
&nbsp;
calc_capacity
&nbsp;/*
&nbsp; * Returns 0 if below normal capacity, or the number of "capacity units"
&nbsp; * over the normal capacity the player is loaded.  Max is 5.
&nbsp; */
&nbsp;int
&nbsp;calc_capacity(xtra_wt)
&nbsp;int xtra_wt;
&nbsp;{
&nbsp;    int cap, wt = inv_weight() + xtra_wt;
&nbsp;
&nbsp;    if (wt &lt;= 0)
&nbsp;        return UNENCUMBERED;
&nbsp;    if (wc &lt;= 1)
&nbsp;        return OVERLOADED;
&nbsp;    cap = (wt * 2 / wc) + 1;
&nbsp;    return min(cap, OVERLOADED);
&nbsp;}
&nbsp;
near_capacity
&nbsp;int
&nbsp;near_capacity()
&nbsp;{
&nbsp;    return calc_capacity(0);
&nbsp;}
&nbsp;
max_capacity
&nbsp;int
&nbsp;max_capacity()
&nbsp;{
&nbsp;    int wt = inv_weight();
&nbsp;
&nbsp;    return (wt - (2 * wc));
&nbsp;}
&nbsp;
check_capacity
&nbsp;boolean
&nbsp;check_capacity(str)
&nbsp;const char *str;
&nbsp;{
&nbsp;    if (near_capacity() &gt;= EXT_ENCUMBER) {
&nbsp;        if (str)
&nbsp;            pline1(str);
&nbsp;        else
&nbsp;            You_cant("do that while carrying so much stuff.");
&nbsp;        return 1;
&nbsp;    }
&nbsp;    return 0;
&nbsp;}
&nbsp;
inv_cnt
&nbsp;int
&nbsp;inv_cnt(incl_gold)
&nbsp;boolean incl_gold;
&nbsp;{
&nbsp;    register struct obj *otmp = invent;
&nbsp;    register int ct = 0;
&nbsp;
&nbsp;    while (otmp) {
&nbsp;        if (incl_gold || otmp-&gt;invlet != GOLD_SYM)
&nbsp;            ct++;
&nbsp;        otmp = otmp-&gt;nobj;
&nbsp;    }
&nbsp;    return ct;
&nbsp;}
&nbsp;
money_cnt
&nbsp;/* Counts the money in an object chain. */
&nbsp;/* Intended use is for your or some monster's inventory, */
&nbsp;/* now that u.gold/m.gold is gone.*/
&nbsp;/* Counting money in a container might be possible too. */
&nbsp;long
&nbsp;money_cnt(otmp)
&nbsp;struct obj *otmp;
&nbsp;{
&nbsp;    while (otmp) {
&nbsp;        /* Must change when silver &amp; copper is implemented: */
&nbsp;        if (otmp-&gt;oclass == COIN_CLASS)
&nbsp;            return otmp-&gt;quan;
&nbsp;        otmp = otmp-&gt;nobj;
&nbsp;    }
&nbsp;    return 0L;
&nbsp;}
&nbsp;
&nbsp;/*hack.c*/

</x,y></x,y></u.ux+u.dx,u.uy+u.dy></x,uy></ux,y>