]> granicus.if.org Git - nethack/commitdiff
fix #K3656 - chest in pit
authorPatR <rankin@nethack.org>
Sun, 7 Aug 2022 23:02:44 +0000 (16:02 -0700)
committerPatR <rankin@nethack.org>
Sun, 7 Aug 2022 23:02:44 +0000 (16:02 -0700)
Using #loot while in a pit allows looting containers in that pit.
Using open and specifying the hero's spot when not in a pit allows
looting containers at hero's spot.  But using open while in a pit
complained about not being able to reach out of the pit before player
had a chance to give hero's spot at the place of interest, so did not
allow looting any container there.

Get a target spot before rejecting use of 'open' while in a pit.
The alternate prompt might be tty-centric.

doc/fixes3-7-0.txt
include/extern.h
src/lock.c

index 2e2d4b142b050a4d68c17b62810902cadd06df39..e5ebf68d8774923fbf2c3c037ecdbb86289ec034 100644 (file)
@@ -1336,6 +1336,8 @@ if the game crashed or the process was killed, recovering a save file ended
 when using --nethackrc=file on the command line (currently only implemented
        for ports that use unixmain.c), options parsing freed the string
        containing 'file' before using it as the RC file name
+using 'o'pen as a synonym for #loot of a container at the hero's location did
+       not work if the hero was in a pit
 
 curses: 'msg_window' option wasn't functional for curses unless the binary
        also included tty support
index 7fac7b2ba5da3e698fc68b133c1fadabb2d1d523..15f27d0011358fff7089cf48def2d870762a810c 100644 (file)
@@ -288,7 +288,8 @@ extern int getdir(const char *);
 extern void confdir(boolean);
 extern const char *directionname(int);
 extern int isok(coordxy, coordxy);
-extern int get_adjacent_loc(const char *, const char *, coordxy, coordxy, coord *);
+extern int get_adjacent_loc(const char *, const char *, coordxy, coordxy,
+                            coord *);
 extern const char *click_to_cmd(coordxy, coordxy, int);
 extern char get_count(const char *, char, long, cmdcount_nht *, unsigned);
 #ifdef HANGUPHANDLING
index cc07ab82ce2527097a5b43de3fca2d02d57c120f..9c9edefff4cdfd216bb0f8719142c342192b2256 100644 (file)
@@ -756,6 +756,7 @@ doopen_indir(coordxy x, coordxy y)
     coord cc;
     register struct rm *door;
     boolean portcullis;
+    const char *dirprompt;
     int res = ECMD_OK;
 
     if (nohands(g.youmonst.data)) {
@@ -763,21 +764,32 @@ doopen_indir(coordxy x, coordxy y)
         return ECMD_OK;
     }
 
-    if (u.utrap && u.utraptype == TT_PIT) {
-        You_cant("reach over the edge of the pit.");
-        return ECMD_OK;
-    }
+    dirprompt = NULL; /* have get_adjacent_loc() -> getdir() use default */
+    if (u.utrap && u.utraptype == TT_PIT && container_at(u.ux, u.uy, FALSE))
+        dirprompt = "Open where? [.>]";
 
-    if (x > 0 && y > 0) {
+    if (x > 0 && y >= 0) {
+        /* nonzero <x,y> is used when hero in amorphous form tries to
+           flow under a closed door at <x,y>; the test here was using
+           'y > 0' but that would give incorrect results if doors are
+           ever allowed to be placed on the top row of the map */
         cc.x = x;
         cc.y = y;
-    } else if (!get_adjacent_loc((char *) 0, (char *) 0, u.ux, u.uy, &cc))
+    } else if (!get_adjacent_loc(dirprompt, (char *) 0, u.ux, u.uy, &cc)) {
         return ECMD_OK;
+    }
 
     /* open at yourself/up/down */
     if (u_at(cc.x, cc.y))
         return doloot();
 
+    /* this used to be done prior to get_adjacent_loc() but doing so was
+       incorrect once open at hero's spot became an alternate way to loot */
+    if (u.utrap && u.utraptype == TT_PIT) {
+        You_cant("reach over the edge of the pit.");
+        return ECMD_OK;
+    }
+
     if (stumble_on_door_mimic(cc.x, cc.y))
         return ECMD_TIME;