From c04b652e40d096ca0d4b39f67206f16e6dd6564a Mon Sep 17 00:00:00 2001 From: PatR Date: Sun, 24 Jun 2018 17:44:33 -0700 Subject: [PATCH 1/2] hilite_status: score vs !SCORE_ON_BOTL When built without support for SCORE_ON_BOTL (the default), suppress 'score' field from 'O' menus for adding/removing hilite_status rules. Also, add "encumbrance" as field name synonym for "carrying-capacity" and "experience-points" for "experience". Relevant for rules set in config file or via NETHACKOPTIONS. --- doc/fixes36.2 | 5 ++- src/botl.c | 88 ++++++++++++++++++++++++++++++++------------------- 2 files changed, 59 insertions(+), 34 deletions(-) diff --git a/doc/fixes36.2 b/doc/fixes36.2 index 7de916495..23b699ac4 100644 --- a/doc/fixes36.2 +++ b/doc/fixes36.2 @@ -52,12 +52,15 @@ when using the 'O' command to create a status highlight that specifies separate rules for each attribute to be merged when highlighting highlighting status conditions would fail to use attributes if a rule with them was followed by another one without (color only or color&normal) +when using 'O' to set hilite_status rules, hide the 'score' status field if + game has been built without SCORE_ON_BOTL; latent rules for 'score' + can still be set in config file but can't be added or removed via 'O' Fixes to Post-3.6.1 Problems that Were Exposed Via git Repository ------------------------------------------------------------------ fix access violation when --debug:xxxx has no other args after it -Setting the inverse attribute for gold had the space before "$:" +setting the inverse attribute for gold had the space before "$:" getting highlighted along with the gold field sortloot segfaulted when filtering a subset of items (seen with 'A' command) diff --git a/src/botl.c b/src/botl.c index 797e29d0b..03c49395f 100644 --- a/src/botl.c +++ b/src/botl.c @@ -924,6 +924,7 @@ init_blstats() #ifdef STATUS_HILITES struct hilite_s *keep_hilite_chain = blstats[i][j].thresholds; #endif + blstats[i][j] = initblstats[j]; blstats[i][j].a = zeroany; if (blstats[i][j].valwidth) { @@ -932,8 +933,7 @@ init_blstats() } else blstats[i][j].val = (char *) 0; #ifdef STATUS_HILITES - if (keep_hilite_chain) - blstats[i][j].thresholds = keep_hilite_chain; + blstats[i][j].thresholds = keep_hilite_chain; #endif } } @@ -1204,26 +1204,28 @@ static struct fieldid_t { const char *fieldname; enum statusfields fldid; } fieldids_alias[] = { - {"characteristics", BL_CHARACTERISTICS}, - {"dx", BL_DX}, - {"co", BL_CO}, - {"con", BL_CO}, - {"points", BL_SCORE}, - {"cap", BL_CAP}, - {"pw", BL_ENE}, - {"pw-max", BL_ENEMAX}, - {"xl", BL_XP}, - {"xplvl", BL_XP}, - {"ac", BL_AC}, - {"hit-dice", BL_HD}, - {"turns", BL_TIME}, - {"hp", BL_HP}, - {"hp-max", BL_HPMAX}, - {"dgn", BL_LEVELDESC}, - {"xp", BL_EXP}, - {"exp", BL_EXP}, - {"flags", BL_CONDITION}, - {0, BL_FLUSH} + { "characteristics", BL_CHARACTERISTICS }, + { "encumbrance", BL_CAP }, + { "experience-points", BL_EXP }, + { "dx", BL_DX }, + { "co", BL_CO }, + { "con", BL_CO }, + { "points", BL_SCORE }, + { "cap", BL_CAP }, + { "pw", BL_ENE }, + { "pw-max", BL_ENEMAX }, + { "xl", BL_XP }, + { "xplvl", BL_XP }, + { "ac", BL_AC }, + { "hit-dice", BL_HD }, + { "turns", BL_TIME }, + { "hp", BL_HP }, + { "hp-max", BL_HPMAX }, + { "dgn", BL_LEVELDESC }, + { "xp", BL_EXP }, + { "exp", BL_EXP }, + { "flags", BL_CONDITION }, + {0, BL_FLUSH } }; /* format arguments */ @@ -1258,6 +1260,7 @@ const char *name; if (!nmatches) { /* check partial matches to canonical names */ int len = (int) strlen(name); + for (i = 0; i < SIZE(initblstats); i++) if (!strncmpi(name, initblstats[i].fldname, len)) { fld = initblstats[i].fld; @@ -1286,7 +1289,8 @@ long augmented_time; return FALSE; while (tl) { - /* only this style times out */ + /* only this style times out (includes general 'changed' + as well as specific 'up' and 'down') */ if (tl->behavior == BL_TH_UPDOWN) return TRUE; tl = tl->next; @@ -1491,6 +1495,7 @@ int *colorptr; case BL_TH_TEXTMATCH: txtstr = blstats[idx][fldidx].val; if (fldidx == BL_TITLE) + /* " the ", skip past " the " */ txtstr += (strlen(plname) + sizeof " the " - sizeof ""); if (hl->rel == TXT_VALUE && hl->textmatch[0]) { if (fuzzymatch(hl->textmatch, txtstr, "\" -_", TRUE)) { @@ -1523,15 +1528,14 @@ split_clridx(idx, coloridx, attrib) int idx; int *coloridx, *attrib; { - if (coloridx && attrib) { + if (coloridx) *coloridx = idx & 0x00FF; + if (attrib) *attrib = (idx >> 8) & 0x00FF; - } } - /* - * This is the parser for the hilite options + * This is the parser for the hilite options. * * parse_status_hl1() separates each hilite entry into * a set of field threshold/action component strings, @@ -2422,17 +2426,24 @@ STATIC_OVL int status_hilite_linestr_countfield(fld) int fld; { - struct _status_hilite_line_str *tmp = status_hilite_str; + struct _status_hilite_line_str *tmp; + boolean countall = (fld == BL_FLUSH); int count = 0; - while (tmp) { - if (tmp->fld == fld || fld == BL_FLUSH) + for (tmp = status_hilite_str; tmp; tmp = tmp->next) { +#ifndef SCORE_ON_BOTL + /* when SCORE_ON_BOTL is disabled, only count 'score' rules + if explicitly asked to do so; exclude them from 'all' count */ + if (countall && tmp->fld == BL_SCORE) + continue; +#endif + if (countall || tmp->fld == fld) count++; - tmp = tmp->next; } return count; } +/* used by options handling, doset(options.c) */ int count_status_hilites(VOID_ARGS) { @@ -2635,8 +2646,12 @@ status_hilite_menu_choose_field() start_menu(tmpwin); for (i = 0; i < MAXBLSTATS; i++) { +#ifndef SCORE_ON_BOTL + if (initblstats[i].fld == BL_SCORE) + continue; +#endif any = zeroany; - any.a_int = (i+1); + any.a_int = (i + 1); add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, initblstats[i].fldname, MENU_UNSELECTED); } @@ -3427,6 +3442,14 @@ shlmenu_redo: int count = status_hilite_linestr_countfield(i); char buf[BUFSZ]; +#ifndef SCORE_ON_BOTL + /* config file might contain rules for highlighting 'score' + even when SCORE_ON_BOTL is disabled; if so, 'O' command + menus won't manipulate them, but will display them for + the "View all hilites in config format" operation */ + if (initblstats[i].fld == BL_SCORE) + continue; +#endif any = zeroany; any.a_int = i + 1; Sprintf(buf, "%-18s", initblstats[i].fldname); @@ -3436,7 +3459,6 @@ shlmenu_redo: buf, MENU_UNSELECTED); } - end_menu(tmpwin, "Status hilites:"); if ((res = select_menu(tmpwin, PICK_ONE, &picks)) > 0) { i = picks->item.a_int - 1; From 7af51743b739d290cb947c092d3d4f9051c72d37 Mon Sep 17 00:00:00 2001 From: PatR Date: Tue, 26 Jun 2018 17:36:00 -0700 Subject: [PATCH 2/2] hilite_status: score vs !SCORE_ON_BOTL reprise Handle suppression of 'score' from the 'O' menu for viewing and setting hilite_status rules differently so that the count of the number of rules will always match the number of rules shown by the 'a - View all hilites in config format' choice. If there are score rules in the config file for a game running under !SCORE_ON_BOTL configuration, list 'score' normally but if player picks that menu entry, the followup menu will have the existing rule(s) and 'X - remove selected hilites' but not 'Z - Add a new hilite'. If there aren't any score rules--or there were some but they've now all been 'X'd--then 'score' won't be listed as one of the status fields. --- src/botl.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/botl.c b/src/botl.c index 03c49395f..a1ea62483 100644 --- a/src/botl.c +++ b/src/botl.c @@ -2431,12 +2431,6 @@ int fld; int count = 0; for (tmp = status_hilite_str; tmp; tmp = tmp->next) { -#ifndef SCORE_ON_BOTL - /* when SCORE_ON_BOTL is disabled, only count 'score' rules - if explicitly asked to do so; exclude them from 'all' count */ - if (countall && tmp->fld == BL_SCORE) - continue; -#endif if (countall || tmp->fld == fld) count++; } @@ -2647,7 +2641,8 @@ status_hilite_menu_choose_field() for (i = 0; i < MAXBLSTATS; i++) { #ifndef SCORE_ON_BOTL - if (initblstats[i].fld == BL_SCORE) + if (initblstats[i].fld == BL_SCORE + && !blstats[0][BL_SCORE].thresholds) continue; #endif any = zeroany; @@ -3334,10 +3329,21 @@ int fld; "Remove selected hilites", MENU_UNSELECTED); } - any = zeroany; - any.a_int = -2; - add_menu(tmpwin, NO_GLYPH, &any, 'Z', 0, ATR_NONE, - "Add a new hilite", MENU_UNSELECTED); +#ifndef SCORE_ON_BOTL + if (fld == BL_SCORE) { + /* suppress 'Z - Add a new hilite' for 'score' when SCORE_ON_BOTL + is disabled; we wouldn't be called for 'score' unless it has + hilite rules from the config file, so count must be positive + (hence there's no risk that we're putting up an empty menu) */ + ; + } else +#endif + { + any = zeroany; + any.a_int = -2; + add_menu(tmpwin, NO_GLYPH, &any, 'Z', 0, ATR_NONE, + "Add a new hilite", MENU_UNSELECTED); + } Sprintf(buf, "Current %s hilites:", initblstats[fld].fldname); end_menu(tmpwin, buf); @@ -3445,9 +3451,9 @@ shlmenu_redo: #ifndef SCORE_ON_BOTL /* config file might contain rules for highlighting 'score' even when SCORE_ON_BOTL is disabled; if so, 'O' command - menus won't manipulate them, but will display them for - the "View all hilites in config format" operation */ - if (initblstats[i].fld == BL_SCORE) + menus will show them and allow deletions but not additions, + otherwise, it won't show 'score' at all */ + if (initblstats[i].fld == BL_SCORE && !count) continue; #endif any = zeroany;