]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - hack/hack.apply.c
Fix Coverity issues 2366 and 2365 -- REVERSE_INULL.
[bsdgames-darwin.git] / hack / hack.apply.c
index dc51290571faba7701338c7f59616b1e4ccf9d49..391cbf413bd6aa5ed694e45e882958d596b9ef17 100644 (file)
+/*     $NetBSD: hack.apply.c,v 1.8 2004/01/27 20:30:29 jsm Exp $       */
+
+/*
+ * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
+ * Amsterdam
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - Neither the name of the Stichting Centrum voor Wiskunde en
+ * Informatica, nor the names of its contributors may be used to endorse or
+ * promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
 /*
- * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
+ * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <sys/cdefs.h>
 #ifndef lint
-static char rcsid[] = "$Id: hack.apply.c,v 1.3 1993/08/02 17:16:58 mycroft Exp $";
-#endif /* not lint */
+__RCSID("$NetBSD: hack.apply.c,v 1.8 2004/01/27 20:30:29 jsm Exp $");
+#endif                         /* not lint */
 
 #include       "hack.h"
+#include       "extern.h"
 #include       "def.edog.h"
 #include       "def.mkroom.h"
-static struct monst *bchit();
-extern struct obj *addinv();
-extern struct trap *maketrap();
-extern int (*occupation)();
-extern char *occtxt;
-extern char quitchars[];
-extern char pl_character[];
 
-static void use_camera(), use_ice_box(), use_whistle(), use_magic_whistle();
-static int use_pick_axe();
+static void use_camera(struct obj *);
+static int in_ice_box(struct obj *);
+static int ck_ice_box(struct obj *);
+static int out_ice_box(struct obj *);
+static void use_ice_box(struct obj *);
+static struct monst *bchit(int, int , int , int);
+static void use_whistle(struct obj *);
+static void use_magic_whistle(struct obj *);
+static int dig(void);
+static int use_pick_axe(struct obj *);
 
-doapply() {
-       register struct obj *obj;
-       register int res = 1;
+int
+doapply()
+{
+       struct obj *obj;
+       int    res = 1;
 
        obj = getobj("(", "use or apply");
-       if(!obj) return(0);
+       if (!obj)
+               return (0);
 
-       switch(obj->otyp){
+       switch (obj->otyp) {
        case EXPENSIVE_CAMERA:
-               use_camera(obj); break;
+               use_camera(obj);
+               break;
        case ICE_BOX:
-               use_ice_box(obj); break;
+               use_ice_box(obj);
+               break;
        case PICK_AXE:
                res = use_pick_axe(obj);
                break;
 
        case MAGIC_WHISTLE:
-               if(pl_character[0] == 'W' || u.ulevel > 9) {
+               if (pl_character[0] == 'W' || u.ulevel > 9) {
                        use_magic_whistle(obj);
                        break;
                }
@@ -47,93 +114,99 @@ doapply() {
                break;
 
        case CAN_OPENER:
-               if(!carrying(TIN)) {
+               if (!carrying(TIN)) {
                        pline("You have no can to open.");
                        goto xit;
                }
                pline("You cannot open a tin without eating its contents.");
                pline("In order to eat, use the 'e' command.");
-               if(obj != uwep)
-    pline("Opening the tin will be much easier if you wield the can-opener.");
+               if (obj != uwep)
+                       pline("Opening the tin will be much easier if you wield the can-opener.");
                goto xit;
 
        default:
                pline("Sorry, I don't know how to use that.");
-       xit:
+xit:
                nomul(0);
-               return(0);
+               return (0);
        }
        nomul(0);
-       return(res);
+       return (res);
 }
 
 /* ARGSUSED */
 static void
-use_camera(obj) /* register */ struct obj *obj; {
-register struct monst *mtmp;
-       if(!getdir(1)){         /* ask: in what direction? */
+use_camera(obj) /* */ 
+       struct obj     *obj __attribute__((__unused__));
+{
+       struct monst *mtmp;
+       if (!getdir(1)) {       /* ask: in what direction? */
                flags.move = multi = 0;
                return;
        }
-       if(u.uswallow) {
+       if (u.uswallow) {
                pline("You take a picture of %s's stomach.", monnam(u.ustuck));
                return;
        }
-       if(u.dz) {
+       if (u.dz) {
                pline("You take a picture of the %s.",
-                       (u.dz > 0) ? "floor" : "ceiling");
+                     (u.dz > 0) ? "floor" : "ceiling");
                return;
        }
-       if(mtmp = bchit(u.dx, u.dy, COLNO, '!')) {
-               if(mtmp->msleep){
+       if ((mtmp = bchit(u.dx, u.dy, COLNO, '!')) != NULL) {
+               if (mtmp->msleep) {
                        mtmp->msleep = 0;
-                       pline("The flash awakens %s.", monnam(mtmp)); /* a3 */
-               } else
-               if(mtmp->data->mlet != 'y')
-               if(mtmp->mcansee || mtmp->mblinded){
-                       register int tmp = dist(mtmp->mx,mtmp->my);
-                       register int tmp2;
-                       if(cansee(mtmp->mx,mtmp->my))
-                         pline("%s is blinded by the flash!", Monnam(mtmp));
-                       setmangry(mtmp);
-                       if(tmp < 9 && !mtmp->isshk && rn2(4)) {
-                               mtmp->mflee = 1;
-                               if(rn2(4)) mtmp->mfleetim = rnd(100);
+                       pline("The flash awakens %s.", monnam(mtmp));   /* a3 */
+               } else if (mtmp->data->mlet != 'y')
+                       if (mtmp->mcansee || mtmp->mblinded) {
+                               int    tmp = dist(mtmp->mx, mtmp->my);
+                               int    tmp2;
+                               if (cansee(mtmp->mx, mtmp->my))
+                                       pline("%s is blinded by the flash!", Monnam(mtmp));
+                               setmangry(mtmp);
+                               if (tmp < 9 && !mtmp->isshk && rn2(4)) {
+                                       mtmp->mflee = 1;
+                                       if (rn2(4))
+                                               mtmp->mfleetim = rnd(100);
+                               }
+                               if (tmp < 3)
+                                       mtmp->mcansee = mtmp->mblinded = 0;
+                               else {
+                                       tmp2 = mtmp->mblinded;
+                                       tmp2 += rnd(1 + 50 / tmp);
+                                       if (tmp2 > 127)
+                                               tmp2 = 127;
+                                       mtmp->mblinded = tmp2;
+                                       mtmp->mcansee = 0;
+                               }
                        }
-                       if(tmp < 3) mtmp->mcansee  = mtmp->mblinded = 0;
-                       else {
-                               tmp2 = mtmp->mblinded;
-                               tmp2 += rnd(1 + 50/tmp);
-                               if(tmp2 > 127) tmp2 = 127;
-                               mtmp->mblinded = tmp2;
-                               mtmp->mcansee = 0;
-                       }
-               }
        }
 }
 
 static
-struct obj *current_ice_box;   /* a local variable of use_ice_box, to be
-                               used by its local procedures in/ck_ice_box */
-static
-in_ice_box(obj) register struct obj *obj; {
-       if(obj == current_ice_box ||
-               (Punished && (obj == uball || obj == uchain))){
+struct obj     *current_ice_box;/* a local variable of use_ice_box, to be
+                                * used by its local procedures in/ck_ice_box */
+static int
+in_ice_box(obj)
+       struct obj *obj;
+{
+       if (obj == current_ice_box ||
+           (Punished && (obj == uball || obj == uchain))) {
                pline("You must be kidding.");
-               return(0);
+               return (0);
        }
-       if(obj->owornmask & (W_ARMOR | W_RING)) {
+       if (obj->owornmask & (W_ARMOR | W_RING)) {
                pline("You cannot refrigerate something you are wearing.");
-               return(0);
+               return (0);
        }
-       if(obj->owt + current_ice_box->owt > 70) {
+       if (obj->owt + current_ice_box->owt > 70) {
                pline("It won't fit.");
-               return(1);      /* be careful! */
+               return (1);     /* be careful! */
        }
-       if(obj == uwep) {
-               if(uwep->cursed) {
+       if (obj == uwep) {
+               if (uwep->cursed) {
                        pline("Your weapon is welded to your hand!");
-                       return(0);
+                       return (0);
                }
                setuwep((struct obj *) 0);
        }
@@ -143,84 +216,102 @@ in_ice_box(obj) register struct obj *obj; {
        obj->nobj = fcobj;
        fcobj = obj;
        obj->age = moves - obj->age;    /* actual age */
-       return(1);
+       return (1);
 }
 
-static
-ck_ice_box(obj) register struct obj *obj; {
-       return(obj->o_cnt_id == current_ice_box->o_id);
+static int
+ck_ice_box(obj)
+       struct obj *obj;
+{
+       return (obj->o_cnt_id == current_ice_box->o_id);
 }
 
-static
-out_ice_box(obj) register struct obj *obj; {
-register struct obj *otmp;
-       if(obj == fcobj) fcobj = fcobj->nobj;
+static int
+out_ice_box(obj)
+       struct obj *obj;
+{
+       struct obj *otmp;
+       if (obj == fcobj)
+               fcobj = fcobj->nobj;
        else {
-               for(otmp = fcobj; otmp->nobj != obj; otmp = otmp->nobj)
-                       if(!otmp->nobj) panic("out_ice_box");
+               for (otmp = fcobj; otmp->nobj != obj; otmp = otmp->nobj)
+                       if (!otmp->nobj)
+                               panic("out_ice_box");
                otmp->nobj = obj->nobj;
        }
        current_ice_box->owt -= obj->owt;
        obj->age = moves - obj->age;    /* simulated point of time */
        (void) addinv(obj);
+       return 0;
 }
 
 static void
-use_ice_box(obj) register struct obj *obj; {
-register int cnt = 0;
-register struct obj *otmp;
+use_ice_box(obj)
+       struct obj *obj;
+{
+       int    cnt = 0;
+       struct obj *otmp;
        current_ice_box = obj;  /* for use by in/out_ice_box */
-       for(otmp = fcobj; otmp; otmp = otmp->nobj)
-               if(otmp->o_cnt_id == obj->o_id)
+       for (otmp = fcobj; otmp; otmp = otmp->nobj)
+               if (otmp->o_cnt_id == obj->o_id)
                        cnt++;
-       if(!cnt) pline("Your ice-box is empty.");
+       if (!cnt)
+               pline("Your ice-box is empty.");
        else {
-           pline("Do you want to take something out of the ice-box? [yn] ");
-           if(readchar() == 'y')
-               if(askchain(fcobj, (char *) 0, 0, out_ice_box, ck_ice_box, 0))
-                   return;
+               pline("Do you want to take something out of the ice-box? [yn] ");
+               if (readchar() == 'y')
+                       if (askchain(fcobj, (char *) 0, 0, out_ice_box, ck_ice_box, 0))
+                               return;
                pline("That was all. Do you wish to put something in? [yn] ");
-               if(readchar() != 'y') return;
+               if (readchar() != 'y')
+                       return;
        }
        /* call getobj: 0: allow cnt; #: allow all types; %: expect food */
        otmp = getobj("0#%", "put in");
-       if(!otmp || !in_ice_box(otmp))
+       if (!otmp || !in_ice_box(otmp))
                flags.move = multi = 0;
 }
 
-static
-struct monst *
-bchit(ddx,ddy,range,sym) register int ddx,ddy,range; char sym; {
-       register struct monst *mtmp = (struct monst *) 0;
-       register int bchx = u.ux, bchy = u.uy;
+static struct monst *
+bchit(ddx, ddy, range, sym)
+       int    ddx, ddy, range;
+       char            sym;
+{
+       struct monst *mtmp = (struct monst *) 0;
+       int    bchx = u.ux, bchy = u.uy;
 
-       if(sym) Tmp_at(-1, sym);        /* open call */
-       while(range--) {
+       if (sym)
+               Tmp_at(-1, sym);/* open call */
+       while (range--) {
                bchx += ddx;
                bchy += ddy;
-               if(mtmp = m_at(bchx,bchy))
+               if ((mtmp = m_at(bchx, bchy)) != NULL)
                        break;
-               if(!ZAP_POS(levl[bchx][bchy].typ)) {
+               if (!ZAP_POS(levl[bchx][bchy].typ)) {
                        bchx -= ddx;
                        bchy -= ddy;
                        break;
                }
-               if(sym) Tmp_at(bchx, bchy);
+               if (sym)
+                       Tmp_at(bchx, bchy);
        }
-       if(sym) Tmp_at(-1, -1);
-       return(mtmp);
+       if (sym)
+               Tmp_at(-1, -1);
+       return (mtmp);
 }
 
 /* ARGSUSED */
 static void
-use_whistle(obj) struct obj *obj; {
-register struct monst *mtmp = fmon;
+use_whistle(obj)
+       struct obj     *obj __attribute__((__unused__));
+{
+       struct monst *mtmp = fmon;
        pline("You produce a high whistling sound.");
-       while(mtmp) {
-               if(dist(mtmp->mx,mtmp->my) < u.ulevel*20) {
-                       if(mtmp->msleep)
+       while (mtmp) {
+               if (dist(mtmp->mx, mtmp->my) < u.ulevel * 20) {
+                       if (mtmp->msleep)
                                mtmp->msleep = 0;
-                       if(mtmp->mtame)
+                       if (mtmp->mtame)
                                EDOG(mtmp)->whistletime = moves;
                }
                mtmp = mtmp->nmon;
@@ -229,185 +320,189 @@ register struct monst *mtmp = fmon;
 
 /* ARGSUSED */
 static void
-use_magic_whistle(obj) struct obj *obj; {
-register struct monst *mtmp = fmon;
+use_magic_whistle(obj)
+       struct obj     *obj __attribute__((__unused__));
+{
+       struct monst *mtmp = fmon;
        pline("You produce a strange whistling sound.");
-       while(mtmp) {
-               if(mtmp->mtame) mnexto(mtmp);
+       while (mtmp) {
+               if (mtmp->mtame)
+                       mnexto(mtmp);
                mtmp = mtmp->nmon;
        }
 }
 
-static int dig_effort; /* effort expended on current pos */
-static uchar dig_level;
-static coord dig_pos;
-static boolean dig_down;
+static int      dig_effort;    /* effort expended on current pos */
+static uchar    dig_level;
+static coord    dig_pos;
+static boolean  dig_down;
 
-static
-dig() {
-       register struct rm *lev;
-       register dpx = dig_pos.x, dpy = dig_pos.y;
+static int
+dig()
+{
+       struct rm *lev;
+       int dpx = dig_pos.x, dpy = dig_pos.y;
 
        /* perhaps a nymph stole his pick-axe while he was busy digging */
        /* or perhaps he teleported away */
-       if(u.uswallow || !uwep || uwep->otyp != PICK_AXE ||
+       if (u.uswallow || !uwep || uwep->otyp != PICK_AXE ||
            dig_level != dlevel ||
            ((dig_down && (dpx != u.ux || dpy != u.uy)) ||
-            (!dig_down && dist(dpx,dpy) > 2)))
-               return(0);
+            (!dig_down && dist(dpx, dpy) > 2)))
+               return (0);
 
        dig_effort += 10 + abon() + uwep->spe + rn2(5);
-       if(dig_down) {
-               if(!xdnstair) {
+       if (dig_down) {
+               if (!xdnstair) {
                        pline("The floor here seems too hard to dig in.");
-                       return(0);
+                       return (0);
                }
-               if(dig_effort > 250) {
+               if (dig_effort > 250) {
                        dighole();
-                       return(0);      /* done with digging */
+                       return (0);     /* done with digging */
                }
-               if(dig_effort > 50) {
-                       register struct trap *ttmp = t_at(dpx,dpy);
+               if (dig_effort > 50) {
+                       struct trap *ttmp = t_at(dpx, dpy);
 
-                       if(!ttmp) {
-                               ttmp = maketrap(dpx,dpy,PIT);
+                       if (!ttmp) {
+                               ttmp = maketrap(dpx, dpy, PIT);
                                ttmp->tseen = 1;
                                pline("You have dug a pit.");
-                               u.utrap = rn1(4,2);
+                               u.utrap = rn1(4, 2);
                                u.utraptype = TT_PIT;
-                               return(0);
+                               return (0);
                        }
                }
-       } else
-       if(dig_effort > 100) {
-               register char *digtxt;
-               register struct obj *obj;
+       } else if (dig_effort > 100) {
+               const char  *digtxt;
+               struct obj *obj;
 
                lev = &levl[dpx][dpy];
-               if(obj = sobj_at(ENORMOUS_ROCK, dpx, dpy)) {
+               if ((obj = sobj_at(ENORMOUS_ROCK, dpx, dpy)) != NULL) {
                        fracture_rock(obj);
                        digtxt = "The rock falls apart.";
-               } else if(!lev->typ || lev->typ == SCORR) {
+               } else if (!lev->typ || lev->typ == SCORR) {
                        lev->typ = CORR;
                        digtxt = "You succeeded in cutting away some rock.";
-               } else if(lev->typ == HWALL || lev->typ == VWALL
-                                           || lev->typ == SDOOR) {
+               } else if (lev->typ == HWALL || lev->typ == VWALL
+                          || lev->typ == SDOOR) {
                        lev->typ = xdnstair ? DOOR : ROOM;
                        digtxt = "You just made an opening in the wall.";
                } else
-                 digtxt = "Now what exactly was it that you were digging in?";
+                       digtxt = "Now what exactly was it that you were digging in?";
                mnewsym(dpx, dpy);
                prl(dpx, dpy);
-               pline(digtxt);          /* after mnewsym & prl */
-               return(0);
+               pline(digtxt);  /* after mnewsym & prl */
+               return (0);
        } else {
-               if(IS_WALL(levl[dpx][dpy].typ)) {
-                       register int rno = inroom(dpx,dpy);
+               if (IS_WALL(levl[dpx][dpy].typ)) {
+                       int    rno = inroom(dpx, dpy);
 
-                       if(rno >= 0 && rooms[rno].rtype >= 8) {
-                         pline("This wall seems too hard to dig into.");
-                         return(0);
+                       if (rno >= 0 && rooms[rno].rtype >= 8) {
+                               pline("This wall seems too hard to dig into.");
+                               return (0);
                        }
                }
                pline("You hit the rock with all your might.");
        }
-       return(1);
+       return (1);
 }
 
 /* When will hole be finished? Very rough indication used by shopkeeper. */
-holetime() {
-       return( (occupation == dig) ? (250 - dig_effort)/20 : -1);
+int
+holetime()
+{
+       return ((occupation == dig) ? (250 - dig_effort) / 20 : -1);
 }
 
+void
 dighole()
 {
-       register struct trap *ttmp = t_at(u.ux, u.uy);
+       struct trap *ttmp = t_at(u.ux, u.uy);
 
-       if(!xdnstair) {
+       if (!xdnstair) {
                pline("The floor here seems too hard to dig in.");
        } else {
-               if(ttmp)
+               if (ttmp)
                        ttmp->ttyp = TRAPDOOR;
                else
                        ttmp = maketrap(u.ux, u.uy, TRAPDOOR);
                ttmp->tseen = 1;
                pline("You've made a hole in the floor.");
-               if(!u.ustuck) {
-                       if(inshop())
+               if (!u.ustuck) {
+                       if (inshop())
                                shopdig(1);
                        pline("You fall through ...");
-                       if(u.utraptype == TT_PIT) {
+                       if (u.utraptype == TT_PIT) {
                                u.utrap = 0;
                                u.utraptype = 0;
                        }
-                       goto_level(dlevel+1, FALSE);
+                       goto_level(dlevel + 1, FALSE);
                }
        }
 }
 
-static
+static int
 use_pick_axe(obj)
-struct obj *obj;
+       struct obj     *obj;
 {
-       char dirsyms[12];
-       extern char sdir[];
-       register char *dsp = dirsyms, *sdp = sdir;
-       register struct monst *mtmp;
-       register struct rm *lev;
-       register int rx, ry, res = 0;
-
-       if(obj != uwep) {
-               if(uwep && uwep->cursed) {
+       char            dirsyms[12];
+       char  *dsp = dirsyms, *sdp = sdir;
+       struct monst *mtmp;
+       struct rm *lev;
+       int    rx, ry, res = 0;
+
+       if (obj != uwep) {
+               if (uwep && uwep->cursed) {
                        /* Andreas Bormann - ihnp4!decvax!mcvax!unido!ab */
                        pline("Since your weapon is welded to your hand,");
                        pline("you cannot use that pick-axe.");
-                       return(0);
+                       return (0);
                }
                pline("You now wield %s.", doname(obj));
                setuwep(obj);
                res = 1;
        }
-       while(*sdp) {
+       while (*sdp) {
                (void) movecmd(*sdp);   /* sets u.dx and u.dy and u.dz */
                rx = u.ux + u.dx;
                ry = u.uy + u.dy;
-               if(u.dz > 0 || (u.dz == 0 && isok(rx, ry) &&
-                   (IS_ROCK(levl[rx][ry].typ)
-                   || sobj_at(ENORMOUS_ROCK, rx, ry))))
+               if (u.dz > 0 || (u.dz == 0 && isok(rx, ry) &&
+                                (IS_ROCK(levl[rx][ry].typ)
+                                 || sobj_at(ENORMOUS_ROCK, rx, ry))))
                        *dsp++ = *sdp;
                sdp++;
        }
        *dsp = 0;
        pline("In what direction do you want to dig? [%s] ", dirsyms);
-       if(!getdir(0))          /* no txt */
-               return(res);
-       if(u.uswallow && attack(u.ustuck)) /* return(1) */;
-       else
-       if(u.dz < 0)
+       if (!getdir(0))         /* no txt */
+               return (res);
+       if (u.uswallow && attack(u.ustuck))     /* return(1) */
+               ;
+       else if (u.dz < 0)
                pline("You cannot reach the ceiling.");
-       else
-       if(u.dz == 0) {
-               if(Confusion)
+       else if (u.dz == 0) {
+               if (Confusion)
                        confdir();
                rx = u.ux + u.dx;
                ry = u.uy + u.dy;
-               if((mtmp = m_at(rx, ry)) && attack(mtmp))
-                       return(1);
-               if(!isok(rx, ry)) {
+               if ((mtmp = m_at(rx, ry)) && attack(mtmp))
+                       return (1);
+               if (!isok(rx, ry)) {
                        pline("Clash!");
-                       return(1);
+                       return (1);
                }
                lev = &levl[rx][ry];
-               if(lev->typ == DOOR)
+               if (lev->typ == DOOR)
                        pline("Your %s against the door.",
-                               aobjnam(obj, "clang"));
-               else if(!IS_ROCK(lev->typ)
-                    && !sobj_at(ENORMOUS_ROCK, rx, ry)) {
+                             aobjnam(obj, "clang"));
+               else if (!IS_ROCK(lev->typ)
+                        && !sobj_at(ENORMOUS_ROCK, rx, ry)) {
                        /* ACCESSIBLE or POOL */
                        pline("You swing your %s through thin air.",
-                               aobjnam(obj, (char *) 0));
+                             aobjnam(obj, (char *) 0));
                } else {
-                       if(dig_pos.x != rx || dig_pos.y != ry
+                       if (dig_pos.x != rx || dig_pos.y != ry
                            || dig_level != dlevel || dig_down) {
                                dig_down = FALSE;
                                dig_pos.x = rx;
@@ -420,10 +515,10 @@ struct obj *obj;
                        occupation = dig;
                        occtxt = "digging";
                }
-       } else if(Levitation) {
+       } else if (Levitation) {
                pline("You cannot reach the floor.");
        } else {
-               if(dig_pos.x != u.ux || dig_pos.y != u.uy
+               if (dig_pos.x != u.ux || dig_pos.y != u.uy
                    || dig_level != dlevel || !dig_down) {
                        dig_down = TRUE;
                        dig_pos.x = u.ux;
@@ -431,12 +526,12 @@ struct obj *obj;
                        dig_level = dlevel;
                        dig_effort = 0;
                        pline("You start digging in the floor.");
-                       if(inshop())
+                       if (inshop())
                                shopdig(0);
                } else
                        pline("You continue digging in the floor.");
                occupation = dig;
                occtxt = "digging";
        }
-       return(1);
+       return (1);
 }