From df2799faffdd14e80ca49d8b6cb61bae5a07dfda Mon Sep 17 00:00:00 2001 From: vultur-cadens Date: Sat, 1 Jul 2023 20:14:49 -0700 Subject: [PATCH] add a statushilite option for critically low HP This allows players to specify a highlight for critically low HP in the config file, for example: OPTIONS=hilite_status:hitpoints/criticalhp/purple&inverse This will cause the hitpoints field to be highlighted when HP is low enough to be considered a major trouble. The new "criticalhp" setting only applies to the hitpoints field. Since the critical HP threshold changes with level (and most of the fractions are not integer percents) it was impossible to set highlights to match the critical HP threshold using percentage settings. --- include/botl.h | 2 +- src/botl.c | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/include/botl.h b/include/botl.h index 89ca4f2df..a77116dd9 100644 --- a/include/botl.h +++ b/include/botl.h @@ -210,7 +210,7 @@ extern int cond_idx[CONDITION_COUNT]; #define BL_TH_CONDITION 103 /* threshold is bitmask of conditions */ #define BL_TH_TEXTMATCH 104 /* threshold text value to match against */ #define BL_TH_ALWAYS_HILITE 105 /* highlight regardless of value */ - +#define BL_TH_CRITICALHP 106 /* highlight critically low HP */ #define HL_ATTCLR_DIM CLR_MAX + 0 #define HL_ATTCLR_BLINK CLR_MAX + 1 diff --git a/src/botl.c b/src/botl.c index a1e81e86a..7283a34c9 100644 --- a/src/botl.c +++ b/src/botl.c @@ -2180,6 +2180,11 @@ get_hilite(int idx, int fldidx, genericptr_t vp, int chg, int pc, case BL_TH_ALWAYS_HILITE: rule = hl; break; + case BL_TH_CRITICALHP: + if (critically_low_hp(FALSE)) { + rule = hl; + } + break; case BL_TH_NONE: break; default: @@ -2435,7 +2440,7 @@ parse_status_hl2(char (*s)[QBUFSZ], boolean from_configfile) int coloridx = -1, successes = 0; int disp_attrib = 0; boolean percent, changed, numeric, down, up, - grt, lt, gte, le, eq, txtval, always; + grt, lt, gte, le, eq, txtval, always, criticalhp; const char *txt; enum statusfields fld = BL_FLUSH; struct hilite_s hilite; @@ -2486,6 +2491,7 @@ parse_status_hl2(char (*s)[QBUFSZ], boolean from_configfile) txt = (const char *)0; percent = numeric = always = FALSE; down = up = changed = FALSE; + criticalhp = FALSE; grt = gte = eq = le = lt = txtval = FALSE; #if 0 /* threshold value - return on empty string */ @@ -2530,6 +2536,8 @@ parse_status_hl2(char (*s)[QBUFSZ], boolean from_configfile) txtval = TRUE; } else if (!strcmpi(s[sidx], "changed")) { changed = TRUE; + } else if (fld == BL_HP && !strcmpi(s[sidx], "criticalhp")) { + criticalhp = TRUE; } else if (is_ltgt_percentnumber(s[sidx])) { const char *op; @@ -2693,7 +2701,9 @@ parse_status_hl2(char (*s)[QBUFSZ], boolean from_configfile) hilite.behavior = BL_TH_TEXTMATCH; else if (hilite.value.a_void) hilite.behavior = BL_TH_VAL_ABSOLUTE; - else + else if (criticalhp) + hilite.behavior = BL_TH_CRITICALHP; + else hilite.behavior = BL_TH_NONE; hilite.anytype = dt; @@ -3254,6 +3264,9 @@ status_hilite2str(struct hilite_s *hl) case BL_TH_ALWAYS_HILITE: Sprintf(behavebuf, "always"); break; + case BL_TH_CRITICALHP: + Sprintf(behavebuf, "criticalhp"); + break; case BL_TH_NONE: break; default: @@ -3370,6 +3383,15 @@ status_hilite_menu_choose_behavior(int fld) nopts++; } + if (fld == BL_HP) { + any = cg.zeroany; + any.a_int = onlybeh = BL_TH_CRITICALHP; + Sprintf(buf, "Highlight critically low %s", initblstats[fld].fldname); + add_menu(tmpwin, &nul_glyphinfo, &any, 'C', 0, ATR_NONE, + clr, buf, MENU_ITEMFLAGS_NONE); + nopts++; + } + if (initblstats[fld].anytype == ANY_STR || fld == BL_CAP || fld == BL_HUNGER) { any = cg.zeroany;