From 6f8c1127edb07f81f727647fbd88e69e0b72610a Mon Sep 17 00:00:00 2001 From: PatR Date: Mon, 13 Oct 2025 23:13:15 -0700 Subject: [PATCH] item action 'W' for armor In the context-sensitive menu when picking an item of armor from an inventory listing, distinguish between wear-this-armor from could- wear-this-armor-if-something-else-wasn't-already-worn-in-its-slot. --- include/extern.h | 2 ++ src/invent.c | 18 ++++++++++++-- src/worn.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 2 deletions(-) diff --git a/include/extern.h b/include/extern.h index d533e0d49..34d20129c 100644 --- a/include/extern.h +++ b/include/extern.h @@ -3866,6 +3866,8 @@ extern void setworn(struct obj *, long) NO_NNARGS; /* has tests for obj */ extern void setnotworn(struct obj *) NO_NNARGS; /* has tests for obj */ extern void allunworn(void); extern struct obj *wearmask_to_obj(long); +extern int wornmask_to_armcat(long); +extern long armcat_to_wornmask(int); extern long wearslot(struct obj *) NONNULLARG1; extern void check_wornmask_slots(void); extern void mon_set_minvis(struct monst *) NONNULLARG1; diff --git a/src/invent.c b/src/invent.c index ef5a78dea..12c3a109a 100644 --- a/src/invent.c +++ b/src/invent.c @@ -3444,8 +3444,22 @@ itemactions(struct obj *otmp) /* W: wear armor */ if (!already_worn) { - if (otmp->oclass == ARMOR_CLASS) - ia_addmenu(win, IA_WEAR_OBJ, 'W', "Wear this armor"); + if (otmp->oclass == ARMOR_CLASS) { + /* if 'otmp' is worn we skip 'W' (and show 'T' above instead); + if it isn't, we either show "W - wear this" if otmp's slot + isn't populated, or "W - [already wearing ]"; + for the latter, picking 'W' will fail but we don't want to + omit 'W' in this situation */ + long Wmask = armcat_to_wornmask(objects[otmp->otyp].oc_armcat); + struct obj *o = wearmask_to_obj(Wmask); + + if (!o) + Strcpy(buf, "Wear this armor"); + else + Sprintf(buf, "[already wearing %s]", an(armor_simple_name(o))); + + ia_addmenu(win, IA_WEAR_OBJ, 'W', buf); + } } /* x: Swap main and readied weapon */ diff --git a/src/worn.c b/src/worn.c index b7db2d94a..e3464d04a 100644 --- a/src/worn.c +++ b/src/worn.c @@ -205,6 +205,70 @@ wearmask_to_obj(long wornmask) return (struct obj *) 0; } +/* convert an armor wornmask to corresponding category */ +int +wornmask_to_armcat(long mask) +{ + int cat = 0; + + switch (mask & W_ARMOR) { + case W_ARM: + cat = ARM_SUIT; + break; + case W_ARMC: + cat = ARM_CLOAK; + break; + case W_ARMH: + cat = ARM_HELM; + break; + case W_ARMS: + cat = ARM_SHIELD; + break; + case W_ARMG: + cat = ARM_GLOVES; + break; + case W_ARMF: + cat = ARM_BOOTS; + break; + case W_ARMU: + cat = ARM_SHIRT; + break; + } + return cat; +} + +/* convert an armor category to corresponding wornmask */ +long +armcat_to_wornmask(int cat) +{ + long mask = 0L; + + switch (cat) { + case ARM_SUIT: + mask = W_ARM; + break; + case ARM_CLOAK: + mask = W_ARMC; + break; + case ARM_HELM: + mask = W_ARMH; + break; + case ARM_SHIELD: + mask = W_ARMS; + break; + case ARM_GLOVES: + mask = W_ARMG; + break; + case ARM_BOOTS: + mask = W_ARMF; + break; + case ARM_SHIRT: + mask = W_ARMU; + break; + } + return mask; +} + /* return a bitmask of the equipment slot(s) a given item might be worn in */ long wearslot(struct obj *obj)