PR #862 - try XLII

When strength loss is so big as to cause HP damage, but reduce
strength if the damage causes hero to revert to normal form.  There's
no point in adjusting strength before rehumanization and not fair to
do so afterward.

Also, validate strength and its intended adjustment before doing
anything else.  (Just paranoia; there's no reason to suspect that any
bad data ever gets passed in.)
This commit is contained in:
PatR
2022-10-11 14:49:14 -07:00
parent e2599c2e99
commit b01fd1b849
2 changed files with 33 additions and 21 deletions

View File

@@ -216,7 +216,12 @@ losestr(int num, const char *knam, schar k_format)
{
int uhpmin = minuhpmax(1), olduhpmax = u.uhpmax;
int ustr = ABASE(A_STR) - num, amt, dmg;
boolean waspolyd = Upolyd;
if (num <= 0 || ABASE(A_STR) < ATTRMIN(A_STR)) {
impossible("losestr: %d - %d", ABASE(A_STR), num);
return;
}
dmg = 0;
while (ustr < ATTRMIN(A_STR)) {
++ustr;
@@ -225,8 +230,6 @@ losestr(int num, const char *knam, schar k_format)
dmg += amt;
}
if (dmg) {
boolean waspolyd = Upolyd;
/* in case damage is fatal and caller didn't supply killer reason */
if (!knam || !*knam) {
knam = "terminal frailty";
@@ -237,10 +240,9 @@ losestr(int num, const char *knam, schar k_format)
if (Upolyd) {
/* if still polymorhed, reduce you-as-monst maxHP; never below 1 */
u.mhmax -= min(dmg, u.mhmax - 1);
} else if (waspolyd) {
; /* rehumanization was triggered; don't reduce no-polyd HP */
} else {
/* not polymorphed; reduce max HP, but not below below uhpmin */
} else if (!waspolyd) {
/* not polymorphed now and didn't rehumanize when taking damage;
reduce max HP, but not below below uhpmin */
if (u.uhpmax > uhpmin)
setuhpmax(max(u.uhpmax - dmg, uhpmin));
}
@@ -255,7 +257,10 @@ losestr(int num, const char *knam, schar k_format)
#else
nhUse(olduhpmax);
#endif
(void) adjattrib(A_STR, -num, 1);
/* 'num' chould have been reduced to 0 in the minimum strength loop;
'(Upolyd || !waspolyd)' is True unless damage caused rehumanization */
if (num > 0 && (Upolyd || !waspolyd))
(void) adjattrib(A_STR, -num, 1);
}
/* combined strength loss and damage from some poisons */