From: PatR Date: Mon, 28 Mar 2022 17:38:04 +0000 (-0700) Subject: enlightenment about temp resist and item resist X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0b42404ad6fe8850eec0b345f92a471bd8201596;p=nethack enlightenment about temp resist and item resist For timed acid resistance and timed stoning resistance, report "You {are,were} temporarily {acid,petrification} resistant." For items being protected by worn equipment, add "by your {armor,&c}" similar to the existing feeback about you being protected "because ". Wizard mode only. --- diff --git a/include/extern.h b/include/extern.h index 4294952a3..78036bc91 100644 --- a/include/extern.h +++ b/include/extern.h @@ -3306,6 +3306,7 @@ extern int zap_over_floor(xchar, xchar, int, boolean *, short); extern void fracture_rock(struct obj *); extern boolean break_statue(struct obj *); extern boolean u_adtyp_resistance_obj(int); +extern char *item_what(int); extern void destroy_item(int, int); extern int destroy_mitem(struct monst *, int, int); extern int resist(struct monst *, char, int, int); diff --git a/src/insight.c b/src/insight.c index 7ca9bfcb7..bbcf66d72 100644 --- a/src/insight.c +++ b/src/insight.c @@ -1402,8 +1402,8 @@ weapon_insight(int final) static void attributes_enlightenment(int unused_mode UNUSED, int final) { - static NEARDATA const char if_surroundings_permitted[] = - " if surroundings permitted"; + static NEARDATA const char + if_surroundings_permitted[] = " if surroundings permitted"; int ltmp, armpro; char buf[BUFSZ]; @@ -1439,33 +1439,46 @@ attributes_enlightenment(int unused_mode UNUSED, int final) if (Fire_resistance) you_are("fire resistant", from_what(FIRE_RES)); if (u_adtyp_resistance_obj(AD_FIRE)) - enl_msg("Your items ", "are", "were", " protected from fire", ""); + enl_msg("Your items ", "are", "were", " protected from fire", + item_what(AD_FIRE)); if (Cold_resistance) you_are("cold resistant", from_what(COLD_RES)); if (u_adtyp_resistance_obj(AD_COLD)) - enl_msg("Your items ", "are", "were", " protected from cold", ""); + enl_msg("Your items ", "are", "were", " protected from cold", + item_what(AD_COLD)); if (Sleep_resistance) you_are("sleep resistant", from_what(SLEEP_RES)); if (Disint_resistance) you_are("disintegration-resistant", from_what(DISINT_RES)); if (u_adtyp_resistance_obj(AD_DISN)) - enl_msg("Your items ", "are", "were", " protected from disintegration", ""); + enl_msg("Your items ", "are", "were", + " protected from disintegration", item_what(AD_DISN)); if (Shock_resistance) you_are("shock resistant", from_what(SHOCK_RES)); if (u_adtyp_resistance_obj(AD_ELEC)) - enl_msg("Your items ", "are", "were", " protected from electric shocks", ""); + enl_msg("Your items ", "are", "were", + " protected from electric shocks", item_what(AD_ELEC)); if (Poison_resistance) you_are("poison resistant", from_what(POISON_RES)); - if (Acid_resistance) - you_are("acid resistant", from_what(ACID_RES)); + if (Acid_resistance) { + Sprintf(buf, "%.20s%.30s", + temp_resist(ACID_RES) ? "temporarily " : "", + "acid resistant"); + you_are(buf, from_what(ACID_RES)); + } if (u_adtyp_resistance_obj(AD_ACID)) - enl_msg("Your items ", "are", "were", " protected from acid", ""); + enl_msg("Your items ", "are", "were", " protected from acid", + item_what(AD_ACID)); if (Drain_resistance) you_are("level-drain resistant", from_what(DRAIN_RES)); if (Sick_resistance) you_are("immune to sickness", from_what(SICK_RES)); - if (Stone_resistance) - you_are("petrification resistant", from_what(STONE_RES)); + if (Stone_resistance) { + Sprintf(buf, "%.20s%.30s", + temp_resist(STONE_RES) ? "temporarily " : "", + "petrification resistant"); + you_are(buf, from_what(STONE_RES)); + } if (Halluc_resistance) enl_msg(You_, "resist", "resisted", " hallucinations", from_what(HALLUC_RES)); diff --git a/src/zap.c b/src/zap.c index 485bc45aa..b5a47b61c 100644 --- a/src/zap.c +++ b/src/zap.c @@ -5014,13 +5014,20 @@ static int adtyp_to_prop(int dmgtyp) { switch (dmgtyp) { - case AD_COLD: return COLD_RES; - case AD_FIRE: return FIRE_RES; - case AD_ELEC: return SHOCK_RES; - case AD_ACID: return ACID_RES; - case AD_DISN: return DISINT_RES; - default: return 0; /* prop_types start at 1 */ + case AD_COLD: + return COLD_RES; + case AD_FIRE: + return FIRE_RES; + case AD_ELEC: + return SHOCK_RES; + case AD_ACID: + return ACID_RES; + case AD_DISN: + return DISINT_RES; + default: + break; } + return 0; /* prop_types start at 1 */ } /* is hero wearing or wielding an object with resistance @@ -5039,6 +5046,51 @@ u_adtyp_resistance_obj(int dmgtyp) return FALSE; } +/* for enlightenment; currently only useful in wizard mode; cf from_what() */ +char * +item_what(int dmgtyp) +{ + static char whatbuf[50]; + const char *what = 0; + int prop = adtyp_to_prop(dmgtyp); + long xtrinsic = u.uprops[prop].extrinsic; + + whatbuf[0] = '\0'; + if (wizard) { + if (!prop || !xtrinsic) { + ; /* 'what' stays Null */ + } else if (xtrinsic & W_ARMC) { + what = cloak_simple_name(uarmc); + } else if (xtrinsic & W_ARM) { + what = suit_simple_name(uarm); /* "dragon {scales,mail}" */ + } else if (xtrinsic & W_ARMU) { + what = shirt_simple_name(uarmu); + } else if (xtrinsic & W_ARMH) { + what = helm_simple_name(uarmh); + } else if (xtrinsic & W_ARMG) { + what = gloves_simple_name(uarmg); + } else if (xtrinsic & W_ARMF) { + what = boots_simple_name(uarmf); + } else if (xtrinsic & W_ARMS) { + what = shield_simple_name(uarms); + } else if (xtrinsic & (W_AMUL | W_TOOL)) { + what = simpleonames((xtrinsic & W_AMUL) ? uamul : ublindf); + } else if (xtrinsic & W_RING) { + if ((xtrinsic & W_RING) == W_RING) /* both */ + what = "rings"; + else + what = simpleonames((xtrinsic & W_RINGL) ? uleft : uright); + } else if (xtrinsic & W_WEP) { + what = simpleonames(uwep); + } + /* format the output to be ready for enl_msg() to append it to + "Your items {are,were} protected against " */ + if (what) /* strlen(what) will be less than 30 */ + Sprintf(whatbuf, " by your %.40s", what); + } + return whatbuf; +} + /* * destroy_strings[dindx][0:singular,1:plural,2:killer_reason] * [0] freezing potion