]> granicus.if.org Git - nethack/commitdiff
fix wiz identify bugs
authorPatR <rankin@nethack.org>
Thu, 30 Aug 2018 02:19:49 +0000 (19:19 -0700)
committerPatR <rankin@nethack.org>
Thu, 30 Aug 2018 02:19:49 +0000 (19:19 -0700)
Fixes #124

Fix github pull request #124 which was also reported directly (but not
through the contact form so #Hxxx number).  Using ^I or #wizidentify
displays inventory with everything ID'd for that command only and adds
a menu entry "_ - use '^I' to identify" that can be chosen to make
those ID's persistent.  Picking underscore would work but picking the
alternate '^I' wouldn't work if the platform had unsigned characters
for plain 'char'.  Switch the return value from magic number -1 to
magic number ^I which isn't a valid inventory letter and isn't subject
to sign conversion.  Casting -1 to '(char) -1' would have worked too
despite some confusion expressed in discussion of the pull request.

If ^I has been bound to some other command and #wizidentify hasn't
been bound to any keystroke, temporary ID didn't disclose any extra
information (ie, acted like ordinary inventory display) and the extra
menu entry to make temporary ID become persistent wasn't available.
This fixes that too.

doc/fixes36.2
src/cmd.c
src/end.c
src/invent.c

index 0d95c8fde115e3a26ff75e623a5a9207fd397a16..576701c5319f57098e7e706ffc2a479f1d9b519e 100644 (file)
@@ -100,6 +100,10 @@ parchment and vellum are made from animal skin so change material composition
        and color for spellbooks with those descriptions from paper to leather;
        eating those books now breaks vegetarian conduct
 fix monsters not wielding digging implements
+wizard mode ^I^I didn't make temporary identifications become persistent if
+       the build configuration makes plain 'char' unsigned
+wizard mode #wizidentify didn't disclose extra information for unID'd items if
+       key bindings took away ^I and didn't bind #wizidentify to another key
 
 
 Fixes to Post-3.6.1 Problems that Were Exposed Via git Repository
index d7303ec18f4755bd19aabe1d6bf1a1505d479ea7..3afa198b0beee1c504476e838a8f55d57e8e912d 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -7,6 +7,22 @@
 #include "lev.h"
 #include "func_tab.h"
 
+/* Macros for meta and ctrl modifiers:
+ *   M and C return the meta/ctrl code for the given character;
+ *     e.g., (C('c') is ctrl-c
+ */
+#ifndef M
+#ifndef NHSTDC
+#define M(c) (0x80 | (c))
+#else
+#define M(c) ((c) - 128)
+#endif /* NHSTDC */
+#endif
+
+#ifndef C
+#define C(c) (0x1f & (c))
+#endif
+
 #ifdef ALTMETA
 STATIC_VAR boolean alt_esc = FALSE;
 #endif
@@ -625,8 +641,18 @@ wiz_identify(VOID_ARGS)
 {
     if (wizard) {
         iflags.override_ID = (int) cmd_from_func(wiz_identify);
-        if (display_inventory((char *) 0, TRUE) == -1)
+        /* command remapping might leave #wizidentify as the only way
+           to invoke us, in which case cmd_from_func() will yield NUL;
+           it won't matter to display_inventory()/display_pickinv()
+           if ^I invokes some other command--what matters is that it
+           is never an inventory letter */
+        if (!iflags.override_ID)
+            iflags.override_ID = C('I');
+        /* C('I') == ^I == default keystroke for wiz_identify;
+           it doesn't matter whether the command has been remapped */
+        if (display_inventory((char *) 0, TRUE) == C('I'))
             identify_pack(0, FALSE);
+        /* [TODO?  if player picks a specific inventory item, ID it] */
         iflags.override_ID = 0;
     } else
         pline("Unavailable command '%s'.",
@@ -2859,22 +2885,6 @@ int final;
     en_win = WIN_ERR;
 }
 
-/* Macros for meta and ctrl modifiers:
- *   M and C return the meta/ctrl code for the given character;
- *     e.g., (C('c') is ctrl-c
- */
-#ifndef M
-#ifndef NHSTDC
-#define M(c) (0x80 | (c))
-#else
-#define M(c) ((c) - 128)
-#endif /* NHSTDC */
-#endif
-
-#ifndef C
-#define C(c) (0x1f & (c))
-#endif
-
 /* ordered by command name */
 struct ext_func_tab extcmdlist[] = {
     { '#', "#", "perform an extended command",
index 58973307875be7e077efd0a9a36e2d18af0535df..4d176323b20eb9a0362f6ffddedbf19a5840e3a5 100644 (file)
--- a/src/end.c
+++ b/src/end.c
@@ -748,7 +748,7 @@ time_t when; /* date+time at end of game */
     dump_plines();
     putstr(0, 0, "");
     putstr(0, 0, "Inventory:");
-    display_inventory((char *) 0, TRUE);
+    (void) display_inventory((char *) 0, TRUE);
     container_contents(invent, TRUE, TRUE, FALSE);
     enlightenment((BASICENLIGHTENMENT | MAGICENLIGHTENMENT),
                   (how >= PANICKED) ? ENL_GAMEOVERALIVE : ENL_GAMEOVERDEAD);
index 9ea9746989e40f12477d082ab3b2a155b6f87694..6355a255ae5df4b2a52b3a4099d0d1fe8094e27e 100644 (file)
@@ -5,6 +5,10 @@
 
 #include "hack.h"
 
+#ifndef C /* same as cmd.c */
+#define C(c) (0x1f & (c))
+#endif
+
 #define NOINVSYM '#'
 #define CONTAINED_SYM '>' /* designator for inside a container */
 #define HANDS_SYM '-'
@@ -2580,9 +2584,15 @@ long *out_cnt;
     if (wizard && iflags.override_ID) {
         char prompt[QBUFSZ];
 
-        any.a_char = -1;
+        /* C('I') == ^I == default keystroke for wiz_identify;
+           it is guaranteed not to be in use as an inventory letter
+           (wiz_identify might be remapped to an ordinary letter,
+           making iflags.override_ID ambiguous as a return value) */
+        any.a_char = C('I');
         /* wiz_identify stuffed the wiz_identify command character (^I)
-           into iflags.override_ID for our use as an accelerator */
+           into iflags.override_ID for our use as an accelerator;
+           it could be ambiguous as a selector but the only time it
+           is wanted is in case where no item is being selected */
         Sprintf(prompt, "Debug Identify (%s to permanently identify)",
                 visctrl(iflags.override_ID));
         add_menu(win, NO_GLYPH, &any, '_', iflags.override_ID, ATR_NONE,