From daeec9291c53d183ed437a13a279715714669b45 Mon Sep 17 00:00:00 2001 From: PatR Date: Wed, 14 Dec 2022 07:37:04 -0800 Subject: [PATCH] refine PR #946 - named armor Move the new stuff from PR #946 out of xname() into new routine armor_simple_name(). Noticed while testing: tweak 'call object type' so that it doesn't list instances of pre-discovered armor as likely candidates since assigning a name to such wasn't showing up in the discoveries list. Add "silver shield" as wishing synonym for "polished silver shield". --- include/extern.h | 2 ++ src/do_name.c | 3 ++ src/o_init.c | 8 +++--- src/objnam.c | 74 ++++++++++++++++++++++++++++++++---------------- 4 files changed, 58 insertions(+), 29 deletions(-) diff --git a/include/extern.h b/include/extern.h index 795ac92ad..d9bbc5acf 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1906,6 +1906,7 @@ extern void savenames(NHFILE *); extern void restnames(NHFILE *); extern void discover_object(int, boolean, boolean); extern void undiscover_object(int); +extern boolean interesting_to_discover(int); extern int choose_disco_sort(int); extern int dodiscovered(void); extern int doclassdisco(void); @@ -1968,6 +1969,7 @@ extern char *makeplural(const char *); extern char *makesingular(const char *); extern struct obj *readobjnam(char *, struct obj *); extern int rnd_class(int, int); +extern const char *armor_simple_name(struct obj *); extern const char *suit_simple_name(struct obj *); extern const char *cloak_simple_name(struct obj *); extern const char *helm_simple_name(struct obj *); diff --git a/src/do_name.c b/src/do_name.c index ce0257724..9022bf31e 100644 --- a/src/do_name.c +++ b/src/do_name.c @@ -1489,6 +1489,9 @@ call_ok(struct obj *obj) if (!obj || !objtyp_is_callable(obj->otyp)) return GETOBJ_EXCLUDE; + if (!interesting_to_discover(obj->otyp)) + return GETOBJ_DOWNPLAY; + return GETOBJ_SUGGEST; } diff --git a/src/o_init.c b/src/o_init.c index 00da96cd7..502069cd5 100644 --- a/src/o_init.c +++ b/src/o_init.c @@ -8,7 +8,6 @@ static void setgemprobs(d_level *); static void shuffle(int, int, boolean); static void shuffle_all(void); -static boolean interesting_to_discover(int); static int QSORTCALLBACK discovered_cmp(const genericptr, const genericptr); static char *oclass_to_name(char, char *); @@ -447,8 +446,9 @@ undiscover_object(int oindx) register boolean found = FALSE; /* find the object; shift those behind it forward one slot */ - for (dindx = gb.bases[acls]; dindx < NUM_OBJECTS && gd.disco[dindx] != 0 - && objects[dindx].oc_class == acls; + for (dindx = gb.bases[acls]; + dindx < NUM_OBJECTS && gd.disco[dindx] != 0 + && objects[dindx].oc_class == acls; dindx++) if (found) gd.disco[dindx - 1] = gd.disco[dindx]; @@ -467,7 +467,7 @@ undiscover_object(int oindx) } } -static boolean +boolean interesting_to_discover(int i) { /* Pre-discovered objects are now printed with a '*' */ diff --git a/src/objnam.c b/src/objnam.c index a990bdbe2..b857286d4 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -621,34 +621,21 @@ xname_flags( if (is_boots(obj) || is_gloves(obj)) Strcpy(buf, "pair of "); - if (obj->otyp >= ELVEN_SHIELD && obj->otyp <= ORCISH_SHIELD - && !dknown) { - Strcpy(buf, "shield"); - break; - } - if (obj->otyp == SHIELD_OF_REFLECTION && !dknown) { - Strcpy(buf, "smooth shield"); - break; + if (!dknown) { + if (obj->otyp >= ELVEN_SHIELD && obj->otyp <= ORCISH_SHIELD) { + Strcpy(buf, "shield"); + break; + } else if (obj->otyp == SHIELD_OF_REFLECTION) { + Strcpy(buf, "smooth shield"); + break; + } } - if (nn) { + if (nn) Strcat(buf, actualn); - } else if (un) { - if (is_boots(obj)) - Strcat(buf, boots_simple_name(obj)); - else if (is_gloves(obj)) - Strcat(buf, gloves_simple_name(obj)); - else if (is_cloak(obj)) - Strcpy(buf, cloak_simple_name(obj)); - else if (is_helmet(obj)) - Strcpy(buf, helm_simple_name(obj)); - else if (is_shield(obj)) - Strcpy(buf, shield_simple_name(obj)); - else - Strcpy(buf, "armor"); - Strcat(buf, " called "); - Strcat(buf, un); - } else + else if (un) + Sprintf(eos(buf), "%s called %s", armor_simple_name(obj), un); + else Strcat(buf, dn); break; case FOOD_CLASS: @@ -3071,6 +3058,7 @@ static const struct alt_spellings { { "gauntlets of ogre power", GAUNTLETS_OF_POWER }, { "gauntlets of giant strength", GAUNTLETS_OF_POWER }, { "elven chain mail", ELVEN_MITHRIL_COAT }, + { "silver shield", SHIELD_OF_REFLECTION }, { "potion of sleep", POT_SLEEPING }, { "scroll of recharging", SCR_CHARGING }, { "recharging", SCR_CHARGING }, @@ -4981,6 +4969,42 @@ Japanese_item_name(int i) return (const char *) 0; } +const char * +armor_simple_name(struct obj *armor) +{ + const char *result = 0; + unsigned armcat = objects[armor->otyp].oc_armcat; + + switch (armcat) { + case ARM_SUIT: + result = suit_simple_name(armor); + break; + case ARM_CLOAK: + result = cloak_simple_name(armor); + break; + case ARM_HELM: + result = helm_simple_name(armor); + break; + case ARM_GLOVES: + result = gloves_simple_name(armor); + break; + case ARM_BOOTS: + result = boots_simple_name(armor); + break; + case ARM_SHIELD: + result = shield_simple_name(armor); + break; + case ARM_SHIRT: + result = shirt_simple_name(armor); + break; + default: + result = simpleonames(armor); + impossible("unknown armor category (%s => %u)", result, armcat); + break; + } + return result; +} + const char * suit_simple_name(struct obj *suit) {