From e1dbad9194817620575dbe075bb9f64b310d544d Mon Sep 17 00:00:00 2001 From: PatR Date: Sat, 12 Oct 2024 00:17:58 -0700 Subject: [PATCH] monster swapping armor While testing the Demonbane change, I saw | The Angel of Crom removes a robe and puts on a robe. which looks a bit silly. Change that to be | The Angel of Crom removes a robe and puts on another robe. when the two items have the same formatted description. (The second robe evidently has a better enchantment than the first one.) --- src/worn.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/worn.c b/src/worn.c index 1f35776d4..473765764 100644 --- a/src/worn.c +++ b/src/worn.c @@ -723,7 +723,7 @@ staticfn void m_dowear_type( struct monst *mon, long flag, /* wornmask value */ - boolean creation, + boolean creation, /* no wear messages when mon is being created */ boolean racialexception) /* small monsters that are allowed for player * races (gnomes) can wear suits */ { @@ -847,14 +847,32 @@ m_dowear_type( if (!creation) { if (sawmon) { - char buf[BUFSZ]; + char buf[BUFSZ], oldarm[BUFSZ], newarm[BUFSZ]; - if (old) - Sprintf(buf, " removes %s and", distant_name(old, doname)); - else - buf[0] = '\0'; - pline("%s%s puts on %s.", Monnam(mon), buf, - distant_name(best, doname)); + /* " [removes and ]puts on ." + uses accessory verbs for armor but we can live with that */ + if (old) { + Strcpy(oldarm, distant_name(old, doname)); + Snprintf(buf, sizeof buf, " removes %s and", oldarm); + } else { + buf[0] = oldarm[0] = '\0'; + } + Strcpy(newarm, distant_name(best, doname)); + /* a monster will swap an item of the same type as the one it + is replacing when the enchantment is better; + if newarm and oldarm have identical descriptions, substitute + "another " for "a|an " */ + if (!strcmpi(newarm, oldarm)) { + if (!strncmpi(newarm, "a ", 2) + && strlen(newarm) + sizeof "another " - sizeof "a " + < sizeof newarm) + (void) strsubst(newarm, "a ", "another "); + else if (!strncmpi(newarm, "an ", 3) + && strlen(newarm) + sizeof "another " - sizeof "an " + < sizeof newarm) + (void) strsubst(newarm, "an ", "another "); + } + pline("%s%s puts on %s.", Monnam(mon), buf, newarm); if (autocurse) pline("%s %s %s %s for a moment.", s_suffix(Monnam(mon)), simpleonames(best), otense(best, "glow"),