]> granicus.if.org Git - nethack/commitdiff
context-sensitive invent: corpses
authorPatR <rankin@nethack.org>
Mon, 11 Apr 2022 22:02:44 +0000 (15:02 -0700)
committerPatR <rankin@nethack.org>
Mon, 11 Apr 2022 22:02:44 +0000 (15:02 -0700)
Picking a corpse while looking at inventory issued a menu that had
entry for eating that and if on an altar another one for offering
that.  Picking the eat or offer choice worked as long as there
weren't any other corpses on the ground or altar.  If there were
others, they'd be skipped but you'd get prompted for which item in
inventory to eat or offer instead of operating on the one that was
used to initiate the action.

include/extern.h
src/cmd.c
src/do_wear.c
src/eat.c

index 7e09175f2977b27af14be9bede88bb3a5eb94a22..186d671446e40986386392e783040e4d92fa7df4 100644 (file)
@@ -255,6 +255,7 @@ extern void cmdq_add_key(char);
 extern void cmdq_add_dir(schar, schar, schar);
 extern void cmdq_add_userinput(void);
 extern struct _cmd_queue *cmdq_pop(void);
+extern struct _cmd_queue *cmdq_peek(void);
 extern void cmdq_clear(void);
 extern char pgetchar(void);
 extern void pushch(char);
index e5edf78953e533298d3a52e98f31df07e542a166..d0ce9c5010171cac44dcee2195c36cc779b86f13 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -270,7 +270,7 @@ cmdq_add_key(char key)
 void
 cmdq_add_dir(schar dx, schar dy, schar dz)
 {
-    struct _cmd_queue *tmp = (struct _cmd_queue *)alloc(sizeof(struct _cmd_queue));
+    struct _cmd_queue *tmp = (struct _cmd_queue *) alloc(sizeof *tmp);
     struct _cmd_queue *cq = g.command_queue;
 
     tmp->typ = CMDQ_DIR;
@@ -292,7 +292,7 @@ cmdq_add_dir(schar dx, schar dy, schar dz)
 void
 cmdq_add_userinput(void)
 {
-    struct _cmd_queue *tmp = (struct _cmd_queue *)alloc(sizeof(struct _cmd_queue));
+    struct _cmd_queue *tmp = (struct _cmd_queue *) alloc(sizeof *tmp);
     struct _cmd_queue *cq = g.command_queue;
 
     tmp->typ = CMDQ_USER_INPUT;
@@ -322,6 +322,13 @@ cmdq_pop(void)
     return tmp;
 }
 
+/* get the top entry without popping it */
+struct _cmd_queue *
+cmdq_peek(void)
+{
+    return g.command_queue;
+}
+
 /* clear all commands from the command queue */
 void
 cmdq_clear(void)
index 0f3c3baa21fbe1427219366cb81f50cb023fb89f..768df4139150dcb628a382d7dd7984af67f39b13 100644 (file)
@@ -1700,7 +1700,7 @@ dotakeoff(void)
             pline("Not wearing any armor or accessories.");
         return ECMD_OK;
     }
-    if (Narmorpieces != 1 || ParanoidRemove || g.command_queue)
+    if (Narmorpieces != 1 || ParanoidRemove || cmdq_peek())
         otmp = getobj("take off", takeoff_ok, GETOBJ_NOFLAGS);
     if (!otmp)
         return ECMD_CANCEL;
@@ -1719,7 +1719,7 @@ doremring(void)
         pline("Not wearing any accessories or armor.");
         return ECMD_OK;
     }
-    if (Naccessories != 1 || ParanoidRemove || g.command_queue)
+    if (Naccessories != 1 || ParanoidRemove || cmdq_peek())
         otmp = getobj("remove", remove_ok, GETOBJ_NOFLAGS);
     if (!otmp)
         return ECMD_CANCEL;
index 00c8cb09602fce3e60d1e89c5c2f410c3eff4cfb..ab3477a1f0a8f14d651c6d43487151b33af2ef63 100644 (file)
--- a/src/eat.c
+++ b/src/eat.c
@@ -3401,8 +3401,9 @@ tin_ok(struct obj *obj)
  * Object may be either on floor or in inventory.
  */
 struct obj *
-floorfood(const char *verb,
-          int corpsecheck) /* 0, no check, 1, corpses, 2, tinnable corpses */
+floorfood(
+    const char *verb,
+    int corpsecheck) /* 0, no check, 1, corpses, 2, tinnable corpses */
 {
     register struct obj *otmp;
     char qbuf[QBUFSZ];
@@ -3411,8 +3412,10 @@ floorfood(const char *verb,
     boolean feeding = !strcmp(verb, "eat"),        /* corpsecheck==0 */
             offering = !strcmp(verb, "sacrifice"); /* corpsecheck==1 */
 
-    /* if we can't touch floor objects then use invent food only */
-    if (iflags.menu_requested /* command was preceded by 'm' prefix */
+    /* if we can't touch floor objects then use invent food only;
+       same if 'm' prefix was used or we're executing an item action
+       for context-sensitive inventory */
+    if (iflags.menu_requested || cmdq_peek()
         || !can_reach_floor(TRUE) || (feeding && u.usteed)
         || (is_pool_or_lava(u.ux, u.uy)
             && (Wwalking || is_clinger(uptr) || (Flying && !Breathless))))