clean up acurr()

Replace the early returns in acurr() and acurrstr(), eliminating a
bunch of casts.  I hope this doesn't reintroduce 'WIN32_BUG' (judging
by the previous workaround, I think that's extremely unlikely).

Also add an introductory comment to newhp().
This commit is contained in:
PatR
2024-01-01 16:46:03 -08:00
parent 00af468020
commit d86e6e9717

View File

@@ -1026,6 +1026,9 @@ adjabil(int oldlevel, int newlevel)
} }
} }
/* called when gaining a level (before u.ulevel gets incremented);
also called with u.ulevel==0 during hero initialization or for
re-init if hero turns into a "new man/woman/elf/&c" */
int int
newhp(void) newhp(void)
{ {
@@ -1115,55 +1118,67 @@ setuhpmax(int newmax)
u.uhp = u.uhpmax, gc.context.botl = TRUE; u.uhp = u.uhpmax, gc.context.botl = TRUE;
} }
/* return the current effective value of a specific characteristic
(the 'a' in 'acurr()' comes from outdated use of "attribute" for the
six Str/Dex/&c characteristics; likewise for u.abon, u.atemp, u.acurr) */
schar schar
acurr(int x) acurr(int chridx)
{ {
register int tmp = (u.abon.a[x] + u.atemp.a[x] + u.acurr.a[x]); int tmp, result = 0; /* 'result' will always be reset to positive value */
if (x == A_STR) { assert(chridx >= 0 && chridx < A_MAX);
if (tmp >= 125 || (uarmg && uarmg->otyp == GAUNTLETS_OF_POWER)) tmp = u.abon.a[chridx] + u.atemp.a[chridx] + u.acurr.a[chridx];
return (schar) 125;
else /* for Strength: 3 <= result <= 125;
#ifdef WIN32_BUG for all others: 3 <= result <= 25 */
return (x = ((tmp <= 3) ? 3 : tmp)); if (chridx == A_STR) {
#else /* strength value is encoded: 3..18 normal, 19..118 for 18/xx (with
return (schar) ((tmp <= 3) ? 3 : tmp); 1 <= xx <= 100), and 119..125 for other characteristics' 19..25;
#endif STR18(x) yields 18 + x (intended for 0 <= x <= 100; not used here);
} else if (x == A_CHA) { STR19(y) yields 100 + y (intended for 19 <= y <= 25) */
if (tmp < 18 if (tmp >= STR19(25) || (uarmg && uarmg->otyp == GAUNTLETS_OF_POWER))
&& (gy.youmonst.data->mlet == S_NYMPH result = STR19(25); /* 125 */
|| u.umonnum == PM_AMOROUS_DEMON)) } else if (chridx == A_CHA) {
return (schar) 18; if (tmp < 18 && (gy.youmonst.data->mlet == S_NYMPH
} else if (x == A_CON) { || u.umonnum == PM_AMOROUS_DEMON))
result = 18;
} else if (chridx == A_CON) {
if (u_wield_art(ART_OGRESMASHER)) if (u_wield_art(ART_OGRESMASHER))
return (schar) 25; result = 25;
} else if (x == A_INT || x == A_WIS) { } else if (chridx == A_INT || chridx == A_WIS) {
/* yes, this may raise int/wis if player is sufficiently /* Yes, this may raise Int and/or Wis if hero is sufficiently
* stupid. there are lower levels of cognition than "dunce". stupid. There are lower levels of cognition than "dunce". */
*/
if (uarmh && uarmh->otyp == DUNCE_CAP) if (uarmh && uarmh->otyp == DUNCE_CAP)
return (schar) 6; result = 6;
} else if (chridx == A_DEX) {
; /* there aren't any special cases for dexterity */
} }
#ifdef WIN32_BUG
return (x = ((tmp >= 25) ? 25 : (tmp <= 3) ? 3 : tmp)); if (result == 0) /* none of the special cases applied */
#else result = (tmp >= 25) ? 25 : (tmp <= 3) ? 3 : tmp;
return (schar) ((tmp >= 25) ? 25 : (tmp <= 3) ? 3 : tmp);
#endif return (schar) result;
} }
/* condense clumsy ACURR(A_STR) value into value that fits into game formulas /* condense clumsy ACURR(A_STR) value into value that fits into formulas */
*/
schar schar
acurrstr(void) acurrstr(void)
{ {
register int str = ACURR(A_STR); int str = ACURR(A_STR), /* 3..125 after massaging by acurr() */
result; /* 3..25 */
if (str <= 18) if (str <= STR18(0)) /* <= 18; max(,3) here is redundant */
return (schar) str; result = max(str, 3); /* 3..18 */
if (str <= 121) else if (str <= STR19(21)) /* <= 121 */
return (schar) (19 + str / 50); /* map to 19..21 */ /* this converts
else 18/01..18/31 into 19,
return (schar) (min(str, 125) - 100); /* 22..25 */ 18/32..18/81 into 20,
18/82..18/100 and 19..21 into 21 */
result = 19 + str / 50; /* map to 19..21 */
else /* convert 122..125; min(,125) here is redundant */
result = min(str, 125) - 100; /* 22..25 */
return (schar) result;
} }
/* when wearing (or taking off) an unID'd item, this routine is used /* when wearing (or taking off) an unID'd item, this routine is used