]> granicus.if.org Git - nethack/commitdiff
inventory item-action: add '-' for uswapwep
authorPatR <rankin@nethack.org>
Sat, 23 Apr 2022 18:58:52 +0000 (11:58 -0700)
committerPatR <rankin@nethack.org>
Sat, 23 Apr 2022 18:58:52 +0000 (11:58 -0700)
There's no 'w-' or 'Q-' for alternate weapon, but context-sensitive
inventory is starting from the object rather than the command so can
finesse that.  'A' does allow alternate weapon to be directly unset
(aka reset to bare/gloved hands) but is not friendly to being passed
queued input.

This adds an extra internal command which only handles unset uswapwep,
even though that is something which is awfully specialized to get it's
own command.  Users don't see this command so that shouldn't matter.

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

index 255dcef04746431b4acb5ca1ffc43a66ae544d83..337d41e61eaaee8235d2fb29eb5e2eee62f606da 100644 (file)
@@ -568,6 +568,7 @@ extern struct obj *stuck_ring(struct obj *, int);
 extern struct obj *unchanger(void);
 extern void reset_remarm(void);
 extern int doddoremarm(void);
+extern int remarm_swapwep(void);
 extern int destroy_arm(struct obj *);
 extern void adj_abon(struct obj *, schar);
 extern boolean inaccessible_equipment(struct obj *, const char *, boolean);
index 3050db6a0ba5b5380ea6ab302dce85d5f32394e7..9a57f2bfa0a42194d71aa38c174724df4bb540a2 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -2606,6 +2606,7 @@ struct ext_func_tab extcmdlist[] = {
     { '\0', "clicklook", NULL, doclicklook, INTERNALCMD, NULL },
     { '\0', "altdip", NULL, dip_into, INTERNALCMD, NULL },
     { '\0', "altadjust", NULL, adjust_split, INTERNALCMD, NULL },
+    { '\0', "altunwield", NULL, remarm_swapwep, INTERNALCMD, NULL },
     { '\0', (char *) 0, (char *) 0, donull, 0, (char *) 0 } /* sentinel */
 };
 
index 768df4139150dcb628a382d7dd7984af67f39b13..0659e257f081327e4ce70c35eee6923cfcf95429 100644 (file)
@@ -86,10 +86,10 @@ on_msg(struct obj *otmp)
    give feedback and discover it iff stealth state is changing */
 static
 void
-toggle_stealth(struct obj *obj,
-               long oldprop, /* prop[].extrinsic, with obj->owornmask
-                                stripped by caller */
-               boolean on)
+toggle_stealth(
+    struct obj *obj,
+    long oldprop, /* prop[].extrinsic, with obj->owornmask pre-stripped */
+    boolean on)
 {
     if (on ? g.initial_don : g.context.takeoff.cancelled_don)
         return;
@@ -2825,8 +2825,8 @@ doddoremarm(void)
         You("continue %s.", g.context.takeoff.disrobing);
         set_occupation(take_off, g.context.takeoff.disrobing, 0);
         return ECMD_OK;
-    } else if (!uwep && !uswapwep && !uquiver && !uamul && !ublindf && !uleft
-               && !uright && !wearing_armor()) {
+    } else if (!uwep && !uswapwep && !uquiver && !uamul && !ublindf
+               && !uleft && !uright && !wearing_armor()) {
         You("are not wearing anything.");
         return ECMD_OK;
     }
@@ -2854,6 +2854,36 @@ doddoremarm(void)
     return ECMD_OK;
 }
 
+/* #altunwield - just unwield alternate weapon, item-action '-' when picking
+   uswapwep from context-sensitive inventory */
+int
+remarm_swapwep(void)
+{
+    struct _cmd_queue cq, *cmdq;
+    boolean oldbknown;
+
+    if ((cmdq = cmdq_pop()) != 0) {
+        /* '-' uswapwep item-action picked from context-sensitive invent */
+        cq = *cmdq;
+        free(cmdq);
+    } else {
+        cq.typ = CMDQ_KEY;
+        cq.key = '\0'; /* something other than '-' */
+    }
+    if (cq.typ != CMDQ_KEY || cq.key != '-' || !uswapwep)
+        return ECMD_FAIL;
+
+    oldbknown = uswapwep->bknown; /* when deciding whether this command
+                                   * has done something that takes time,
+                                   * behave as if a cursed secondary weapon
+                                   * can't be unwielded even though things
+                                   * don't work that way... */
+    reset_remarm();
+    g.context.takeoff.what = g.context.takeoff.mask = W_SWAPWEP;
+    (void) do_takeoff();
+    return (!uswapwep || uswapwep->bknown != oldbknown) ? ECMD_TIME : ECMD_OK;
+}
+
 static int
 menu_remarm(int retry)
 {
index 3d91eb13183d7b5f4040fd438288b5fce0e3947d..b83417eaf45b1f213abd6de894f77a783dbac1af 100644 (file)
@@ -2656,7 +2656,7 @@ itemactions(struct obj *otmp)
 
     /* -: unwield; picking current weapon offers an opportunity for 'w-'
        to wield bare/gloved hands; likewise for 'Q-' with quivered item(s) */
-    if (otmp == uwep || otmp == uquiver) {
+    if (otmp == uwep || otmp == uswapwep || otmp == uquiver) {
         const char *verb = (otmp == uquiver) ? "Quiver" : "Wield",
                    *action = (otmp == uquiver) ? "un-ready" : "un-wield",
                    *which = is_plural(otmp) ? "these" : "this",
@@ -2665,8 +2665,6 @@ itemactions(struct obj *otmp)
         /*
          * TODO: if uwep is ammo, tell player that to shoot instead of toss,
          *       the corresponding launcher must be wielded;
-         * TODO too: if otmp is uswapwep, remove it from that slot (possibly
-         *       stopping dual-wielding in the process).
          */
         Sprintf(buf,  "%s '%c' to %s %s %s",
                 verb, HANDS_SYM, action, which,
@@ -2942,8 +2940,9 @@ itemactions(struct obj *otmp)
             break;
         case IA_UNWIELD:
             cmdq_add_ec((otmp == uwep) ? dowield
-                        : (otmp == uquiver) ? dowieldquiver
-                          : donull); /* can't happen */
+                        : (otmp == uswapwep) ? remarm_swapwep
+                          : (otmp == uquiver) ? dowieldquiver
+                            : donull); /* can't happen */
             cmdq_add_key('-');
             break;
         case IA_APPLY_OBJ: