status_hilite for Xp and Exp by percent rules

Extend support for highlight rules that specify percentages from HP
and spell power to experience level and experience points.  For both
of those, the percentage is based on progress from the start of the
current Xp level to the start of the next Xp level.  100% isn't
possible so is used to enable highlighting a special case:  1 point
shy of next level, most likely to occur after losing a level.

This is something I had in mind a long time ago and then forgot all
about until fiddling with the final disclosure of experience points
recently.  It turned out to be trickier than expected because it needs
to check whether Xp should have a status update when it hasn't changed
but Exp has gone up.  The latter might hit a percentage threshold that
switches to another highlight rule.  Fortunately changes to Exp, at
least that aren't part of level gain or loss (which always trigger
status updating), are all funnelled through a single place (I hope).
This commit is contained in:
PatR
2019-07-02 17:39:23 -07:00
parent ad88205229
commit 1e7fb839a3
6 changed files with 165 additions and 29 deletions

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 exper.c $NHDT-Date: 1553296396 2019/03/22 23:13:16 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.32 $ */
/* NetHack 3.6 exper.c $NHDT-Date: 1562114352 2019/07/03 00:39:12 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.33 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2007. */
/* NetHack may be freely redistributed. See license for details. */
@@ -14,6 +14,8 @@ long
newuexp(lev)
int lev;
{
if (lev < 1) /* for newuexp(u.ulevel - 1) when u.ulevel is 1 */
return 0L;
if (lev < 10)
return (10L * (1L << lev));
if (lev < 20)
@@ -177,6 +179,11 @@ register int exper, rexp;
u.uexp = newexp;
if (flags.showexp)
context.botl = TRUE;
/* even when experience points aren't being shown, experience level
might be highlighted with a percentage highlight rule and that
percentage depends upon experience points */
if (!context.botl && exp_percent_changing())
context.botl = TRUE;
}
/* newrexp will always differ from oldrexp unless they're LONG_MAX */
if (newrexp != oldrexp) {
@@ -303,7 +310,7 @@ boolean incr; /* true iff via incremental experience growth */
}
++u.ulevel;
pline("Welcome %sto experience level %d.",
u.ulevelmax < u.ulevel ? "" : "back ",
(u.ulevelmax < u.ulevel) ? "" : "back ",
u.ulevel);
if (u.ulevelmax < u.ulevel)
u.ulevelmax = u.ulevel;