From: PatR Date: Sat, 23 Apr 2022 18:58:52 +0000 (-0700) Subject: inventory item-action: add '-' for uswapwep X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c2ac36f0c983c83f9590e23df5dd70daea9bda60;p=nethack inventory item-action: add '-' for uswapwep 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. --- diff --git a/include/extern.h b/include/extern.h index 255dcef04..337d41e61 100644 --- a/include/extern.h +++ b/include/extern.h @@ -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); diff --git a/src/cmd.c b/src/cmd.c index 3050db6a0..9a57f2bfa 100644 --- 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 */ }; diff --git a/src/do_wear.c b/src/do_wear.c index 768df4139..0659e257f 100644 --- a/src/do_wear.c +++ b/src/do_wear.c @@ -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) { diff --git a/src/invent.c b/src/invent.c index 3d91eb131..b83417eaf 100644 --- a/src/invent.c +++ b/src/invent.c @@ -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: