Reduce code duplication in extrinsics-protect-items code

The same checks were being repeated for every damage type; this
sends them through two centralised functions (one for checking
whether an extrinsic blocks a specific instance of item destruction
and one for the enlightenment message), so that new mechanisms of
item destruction prevention will need to change only one point in
the code.
This commit is contained in:
Alex Smith
2023-12-05 04:34:24 +00:00
parent 2d8ba944e1
commit 7ca9951996
5 changed files with 55 additions and 29 deletions

View File

@@ -1429,6 +1429,19 @@ weapon_insight(int final)
} /* skill applies */
}
static void
item_resistance_message(int adtyp, const char *prot_message, int final)
{
int protection = u_adtyp_resistance_obj(adtyp);
if (protection) {
boolean somewhat = protection < 99;
enl_msg("Your items ",
somewhat ? "are somewhat" : "are",
somewhat ? "were somewhat" : "were",
prot_message, item_what(adtyp));
}
}
/* attributes: intrinsics and the like, other non-obvious capabilities */
static void
attributes_enlightenment(int unused_mode UNUSED, int final)
@@ -1469,26 +1482,18 @@ attributes_enlightenment(int unused_mode UNUSED, int final)
you_are("magic-protected", from_what(ANTIMAGIC));
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",
item_what(AD_FIRE));
item_resistance_message(AD_FIRE, " protected from fire", final);
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",
item_what(AD_COLD));
item_resistance_message(AD_COLD, " protected from cold", final);
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", item_what(AD_DISN));
item_resistance_message(AD_DISN, " protected from disintegration", final);
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", item_what(AD_ELEC));
item_resistance_message(AD_ELEC, " protected from electric shocks", final);
if (Poison_resistance)
you_are("poison resistant", from_what(POISON_RES));
if (Acid_resistance) {
@@ -1497,9 +1502,7 @@ attributes_enlightenment(int unused_mode UNUSED, int final)
"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",
item_what(AD_ACID));
item_resistance_message(AD_ACID, " protected from acid", final);
if (Drain_resistance)
you_are("level-drain resistant", from_what(DRAIN_RES));
if (Sick_resistance)