]> granicus.if.org Git - nethack/commitdiff
context-sensitive inventory item-action split
authorPatR <rankin@nethack.org>
Wed, 18 May 2022 08:17:14 +0000 (01:17 -0700)
committerPatR <rankin@nethack.org>
Wed, 18 May 2022 08:17:14 +0000 (01:17 -0700)
When picking an item from inventory and then picking 'I - adjust
inventory by splitting this stack' in the item-action menu,
yn_function("Split off how many?") is used to start getting the
count without needing to wait for <return>.  It includes the response
in message history (so review of history will see that first digit).
The code then uses get_count() to obtain any additional digits.  Tell
the latter to store "Count: N" in message history if N is different
from the first digit.

That's not as good as updating message history to replace the entry
showing the prompt with the first digit with one that shows the full
count but at least it's accurate when the count is 10 or more.

include/hack.h
src/cmd.c
src/invent.c

index 040cb7a37fcd5b7ca96e05a99140726984761362..a3aa8ae6c48dfb4bb98e188c6dac3e3d054ae7f9 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 hack.h  $NHDT-Date: 1601595709 2020/10/01 23:41:49 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.141 $ */
+/* NetHack 3.7 hack.h  $NHDT-Date: 1652861829 2022/05/18 08:17:09 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.181 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Pasi Kallinen, 2017. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -479,7 +479,9 @@ typedef uint32_t mmflags_nht;     /* makemon MM_ flags */
 /* get_count flags */
 #define GC_NOFLAGS   0
 #define GC_SAVEHIST  1 /* save "Count: 123" in message history */
-#define GC_ECHOFIRST 2 /* echo "Count: 1" even when there's only one digit */
+#define GC_CONDHIST  2 /* save "Count: N" in message history unless the
+                        * first digit is passed in and N matches it */
+#define GC_ECHOFIRST 4 /* echo "Count: 1" even when there's only one digit */
 
 /* rloc() flags */
 #define RLOC_NONE    0x00
index 99804960c762d5f46d032ca94d60127098c1775e..642c4e3d86778b94828decf910ab4bf41885f139 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -1,4 +1,4 @@
-/* NetHack 3.7 cmd.c   $NHDT-Date: 1652719274 2022/05/16 16:41:14 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.564 $ */
+/* NetHack 3.7 cmd.c   $NHDT-Date: 1652861829 2022/05/18 08:17:09 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.565 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Robert Patrick Rankin, 2013. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -5152,10 +5152,13 @@ get_count(
 {
     char qbuf[QBUFSZ];
     int key;
-    long cnt = 0L;
+    long cnt = 0L, first = inkey ? (long) (inkey - '0') : 0L;
     boolean backspaced = FALSE, showzero = TRUE,
             /* should "Count: 123" go into message history? */
             historicmsg = (gc_flags & GC_SAVEHIST) != 0,
+            /* put "Count: N" into mesg hist unless N is the same as the
+               [first digit] value passed in via 'inkey' */
+            conditionalmsg = (gc_flags & GC_CONDHIST) != 0,
             /* normally "Count: 12" isn't echoed until the second digit */
             echoalways = (gc_flags & GC_ECHOFIRST) != 0;
     /* this should be done in port code so that we have erase_char
@@ -5206,7 +5209,7 @@ get_count(
         }
     }
 
-    if (historicmsg) {
+    if (historicmsg || (conditionalmsg && *count != first)) {
         Sprintf(qbuf, "Count: %ld ", *count);
         (void) key2txt((uchar) key, eos(qbuf));
         putmsghistory(qbuf, FALSE);
index 1101be42dc5d4a86d2071170e7e65d909f6de3be..3fe7e29f51e65e3a8996ab4f8db693a48de7ba3f 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 invent.c        $NHDT-Date: 1652831520 2022/05/17 23:52:00 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.388 $ */
+/* NetHack 3.7 invent.c        $NHDT-Date: 1652861830 2022/05/18 08:17:10 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.389 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Derek S. Ray, 2015. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -4831,7 +4831,16 @@ adjust_split(void)
         /* got first digit, get more until next non-digit (except for
            backspace/delete which will take away most recent digit and
            keep going; we expect one of ' ', '\n', or '\r') */
-        let = get_count(NULL, dig, LARGEST_INT, &splitamount, GC_ECHOFIRST);
+        let = get_count(NULL, dig, 0L, &splitamount,
+                        /* yn_function() added the first digit to the
+                           prompt when recording message history; have
+                           get_count() display "Count: N" when waiting
+                           for additional digits (ordinarily that won't be
+                           shown until a second digit is entered) and also
+                           add "Count: N" to message history if more than
+                           one digit gets entered or the original N is
+                           deleted and replaced with different digit */
+                        GC_ECHOFIRST | GC_CONDHIST);
         /* \033 is in quitchars[] so we need to check for it separately
            in order to treat it as cancel rather than as accept */
         if (!let || let == '\033' || !index(quitchars, let)) {