From: nhmall Date: Thu, 20 Feb 2020 06:22:27 +0000 (-0500) Subject: some more status condition follow-up X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d50c3577e9d8775e620114542f860111c1a753b1;p=nethack some more status condition follow-up - Don't display 'Held' when swallowed. - Don't display 'Held' when the hero is doing the holding; add a condition display entry "UHold" for that (the opt_in option is "holding") - Allow resorting of the 'O' menu for status condition fields. Default is alphabetical, but you can sort by condition field ranking now. --- diff --git a/doc/window.doc b/doc/window.doc index 2ff17f114..8789783cb 100644 --- a/doc/window.doc +++ b/doc/window.doc @@ -449,6 +449,7 @@ status_update(int fldindex, genericptr_t ptr, int chg, int percentage, int color BL_MASK_TRAPPED 0x04000000L BL_MASK_UNCONSC 0x08000000L BL_MASK_WOUNDEDL 0x10000000L + BL_MASK_HOLDING 0x20000000L -- The value passed for BL_GOLD includes a leading symbol for GOLD "$:nnn". If the window port needs to use the textual gold amount without the leading "$:" the port diff --git a/include/botl.h b/include/botl.h index 579e2efdb..92167a9f2 100644 --- a/include/botl.h +++ b/include/botl.h @@ -78,6 +78,7 @@ enum blconditions { bl_trapped, bl_unconsc, bl_woundedl, + bl_holding, CONDITION_COUNT }; @@ -114,7 +115,8 @@ enum blconditions { #define BL_MASK_TRAPPED 0x04000000L #define BL_MASK_UNCONSC 0x08000000L #define BL_MASK_WOUNDEDL 0x10000000L -#define BL_MASK_BITS 29 /* number of mask bits that can be set */ +#define BL_MASK_HOLDING 0x20000000L +#define BL_MASK_BITS 30 /* number of mask bits that can be set */ /* clang-format on */ struct conditions_t { diff --git a/src/botl.c b/src/botl.c index 03e80c885..8a2fe8e43 100644 --- a/src/botl.c +++ b/src/botl.c @@ -422,6 +422,7 @@ static char *FDECL(anything_to_s, (char *, anything *, int)); static int FDECL(percentage, (struct istat_s *, struct istat_s *)); static int NDECL(exp_percentage); static int FDECL(CFDECLSPEC cond_cmp, (const genericptr, const genericptr)); +static int FDECL(CFDECLSPEC menualpha_cmp, (const genericptr, const genericptr)); #ifdef STATUS_HILITES static void FDECL(s_to_anything, (anything *, char *, int)); @@ -523,8 +524,9 @@ const struct condmap condition_aliases[] = { | BL_MASK_PARLYZ | BL_MASK_RIDE | BL_MASK_SLEEPING | BL_MASK_SLIME | BL_MASK_SLIPPERY | BL_MASK_STONE | BL_MASK_STRNGL | BL_MASK_STUN | BL_MASK_SUBMERGED - | BL_MASK_TERMILL | BL_MASK_TETHERED | BL_MASK_TRAPPED - | BL_MASK_UNCONSC | BL_MASK_WOUNDEDL }, + | BL_MASK_TERMILL | BL_MASK_TETHERED + | BL_MASK_TRAPPED | BL_MASK_UNCONSC + | BL_MASK_WOUNDEDL | BL_MASK_HOLDING }, { "major_troubles", BL_MASK_FOODPOIS | BL_MASK_GRAB | BL_MASK_INLAVA | BL_MASK_SLIME | BL_MASK_STONE | BL_MASK_STRNGL | BL_MASK_TERMILL }, @@ -536,7 +538,8 @@ const struct condmap condition_aliases[] = { | BL_MASK_HELD | BL_MASK_ICY | BL_MASK_PARLYZ | BL_MASK_SLEEPING | BL_MASK_SLIPPERY | BL_MASK_SUBMERGED | BL_MASK_TETHERED | BL_MASK_TRAPPED - | BL_MASK_UNCONSC | BL_MASK_WOUNDEDL }, + | BL_MASK_UNCONSC | BL_MASK_WOUNDEDL + | BL_MASK_HOLDING }, }; #endif /* STATUS_HILITES */ @@ -572,6 +575,7 @@ const struct conditions_t conditions[] = { { 20, BL_MASK_TRAPPED, bl_trapped, { "Trap", "Trp", "Tr" } }, { 20, BL_MASK_UNCONSC, bl_unconsc, { "Out", "Out", "KO" } }, { 20, BL_MASK_WOUNDEDL, bl_woundedl, { "Legs", "Leg", "Lg" } }, + { 20, BL_MASK_HOLDING, bl_holding, { "UHold", "UHld", "UHd" } }, }; struct condtests_t condtests[CONDITION_COUNT] = { @@ -605,6 +609,7 @@ struct condtests_t condtests[CONDITION_COUNT] = { { bl_trapped, "trap", opt_in, FALSE, FALSE, FALSE }, { bl_unconsc, "unconscious", opt_in, FALSE, FALSE, FALSE }, { bl_woundedl, "woundedlegs", opt_in, FALSE, FALSE, FALSE }, + { bl_holding, "holding", opt_in, FALSE, FALSE, FALSE }, }; /* condition indexing */ int cond_idx[CONDITION_COUNT] = { 0 }; @@ -834,7 +839,8 @@ bot_via_windowport() condtests[bl_conf].test = (Confusion) ? TRUE : FALSE; condtests[bl_deaf].test = (Deaf); condtests[bl_fly].test = (Flying); - condtests[bl_foodpois].test = (Sick && (u.usick_type & SICK_VOMITABLE) != 0); + condtests[bl_foodpois].test = (Sick + && (u.usick_type & SICK_VOMITABLE) != 0); condtests[bl_glowhands].test = (u.umconf); condtests[bl_grab].test = (u.ustuck && u.ustuck->data->mlet == S_EEL); condtests[bl_hallu].test = (Hallucination); @@ -845,10 +851,17 @@ bot_via_windowport() condtests[bl_stone].test = (Stoned) ? TRUE : FALSE; condtests[bl_strngl].test = (Strangled) ? TRUE : FALSE; condtests[bl_stun].test = (Stunned) ? TRUE : FALSE; - condtests[bl_termill].test = (Sick && (u.usick_type & SICK_NONVOMITABLE) != 0); + condtests[bl_termill].test = (Sick + && (u.usick_type & SICK_NONVOMITABLE) + != 0); test_if_enabled(bl_elf_iron) = (FALSE); test_if_enabled(bl_bareh) = (!uarmg && !uwep); - test_if_enabled(bl_held) = (u.ustuck && !condtests[bl_grab].test); + /* do this next one before bl_held */ + condtests[bl_holding].test = (u.ustuck && !u.uswallow + && Upolyd && sticks(g.youmonst.data)); + test_if_enabled(bl_held) = (u.ustuck && !u.uswallow + && !condtests[bl_holding].test + && !condtests[bl_grab].test); test_if_enabled(bl_icy) = levl[u.ux][u.uy].typ == ICE; test_if_enabled(bl_slippery) = (Glib) ? TRUE : FALSE; test_if_enabled(bl_trapped) = (u.utrap && u.utraptype != TT_BURIEDBALL @@ -906,7 +919,9 @@ bot_via_windowport() g.blstats[idx][BL_CONDITION].a.a_ulong |= conditions[(c)].mask; for (i = 0; i < CONDITION_COUNT; ++i) { - if (condtests[i].enabled && condtests[i].test) + if (condtests[i].enabled + /* && i != bl_holding */ /* uncomment to suppress UHold */ + && condtests[i].test) cond_bitset(i); } evaluate_and_notify_windowport(g.valset, idx); @@ -976,7 +991,18 @@ const genericptr vptr2; if (c1 != c2) return c1 - c2; /* tie-breaker - visible alpha by name */ - return strcmpi(conditions[indx1].text[0], conditions[indx2].text[0]); + return strcmpi(condtests[indx1].useroption, condtests[indx2].useroption); +} + +/* qsort callback routine for alphabetical sorting of index */ +static int CFDECLSPEC +menualpha_cmp(vptr1, vptr2) +const genericptr vptr1; +const genericptr vptr2; +{ + int indx1 = *(int *) vptr1, indx2 = *(int *) vptr2; + + return strcmpi(condtests[indx1].useroption, condtests[indx2].useroption); } int @@ -1005,41 +1031,70 @@ char *opts; void cond_menu(VOID_ARGS) { - int i, res, idx = 0; + int i, res, idx = 0, sortorder = 0; + int sequence[CONDITION_COUNT]; winid tmpwin; anything any; menu_item *picks = (menu_item *) 0; char mbuf[QBUFSZ]; + static const char *menutitle[2] = { "alphabetically", "by ranking"}; + boolean showmenu = TRUE; - tmpwin = create_nhwindow(NHW_MENU); - start_menu(tmpwin); + do { + for (i = 0; i < CONDITION_COUNT; ++i) { + sequence[i] = i; + } + qsort((genericptr_t) sequence, CONDITION_COUNT, + sizeof sequence[0], + (sortorder) ? cond_cmp : menualpha_cmp); + + tmpwin = create_nhwindow(NHW_MENU); + start_menu(tmpwin); - any = cg.zeroany; - Sprintf(mbuf, "%-21s (ranking)", "field option"); - add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings, mbuf, - MENU_ITEMFLAGS_NONE); - for (i = 0; i < SIZE(conditions); i++) { - Sprintf(mbuf, "cond_%-14s (%3d)", condtests[i].useroption, cond_idx[i]); any = cg.zeroany; - any.a_int = i + 1; /* avoid zero */ - condtests[i].choice = FALSE; - add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, - mbuf, - condtests[i].enabled - ? MENU_ITEMFLAGS_SELECTED : MENU_ITEMFLAGS_NONE); - } + any.a_int = 1; + Sprintf(mbuf, "change sort order from \"%s\" to \"%s\"", + menutitle[sortorder], menutitle[1 - sortorder]); + add_menu(tmpwin, NO_GLYPH, &any, 'S', 0, ATR_NONE, mbuf, + MENU_ITEMFLAGS_NONE); + any = cg.zeroany; + Sprintf(mbuf, "sorted %s", menutitle[sortorder]); + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings, mbuf, + MENU_ITEMFLAGS_NONE); + for (i = 0; i < SIZE(condtests); i++) { + idx = sequence[i]; + Sprintf(mbuf, "cond_%-14s", condtests[idx].useroption); + any = cg.zeroany; + any.a_int = idx + 2; /* avoid zero and the sort change pick */ + condtests[idx].choice = FALSE; + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, + mbuf, + condtests[idx].enabled + ? MENU_ITEMFLAGS_SELECTED : MENU_ITEMFLAGS_NONE); + } - end_menu(tmpwin, "Choose status conditions to toggle"); + end_menu(tmpwin, "Choose status conditions to toggle"); - res = select_menu(tmpwin, PICK_ANY, &picks); - destroy_nhwindow(tmpwin); - if (res > 0) { - for (i = 0; i < res; i++) { - idx = picks[i].item.a_int - 1; - condtests[idx].choice = TRUE; + res = select_menu(tmpwin, PICK_ANY, &picks); + destroy_nhwindow(tmpwin); + showmenu = FALSE; + if (res > 0) { + for (i = 0; i < res; i++) { + idx = picks[i].item.a_int; + if (idx == 1) { + /* sort change requested */ + sortorder = 1 - sortorder; + showmenu = TRUE; + break; /* for loop */ + } else { + idx -= 2; + condtests[idx].choice = TRUE; + } + } + free((genericptr_t) picks); } - free((genericptr_t) picks); - } + } while (showmenu); + for (i = 0; i < CONDITION_COUNT; ++i) { if (condtests[i].enabled != condtests[i].choice) condtests[i].enabled = condtests[i].choice; diff --git a/win/tty/wintty.c b/win/tty/wintty.c index e5a9fcb95..11e2a5b24 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -3845,6 +3845,7 @@ boolean enable; * BL_MASK_TRAPPED 0x04000000L * BL_MASK_UNCONSC 0x08000000L * BL_MASK_WOUNDEDL 0x10000000L + * BL_MASK_HOLDING 0x20000000L * * -- The value passed for BL_GOLD usually includes an encoded leading * symbol for GOLD "\GXXXXNNNN:nnn". If the window port needs to use diff --git a/win/win32/mswproc.c b/win/win32/mswproc.c index 1958a3260..65225f7b2 100644 --- a/win/win32/mswproc.c +++ b/win/win32/mswproc.c @@ -2831,6 +2831,7 @@ static mswin_condition_field _condition_fields[CONDITION_COUNT] = { { BL_MASK_TRAPPED, "Trap" }, { BL_MASK_UNCONSC, "Out" }, { BL_MASK_WOUNDEDL, "Legs" }, + { BL_MASK_HOLDING, "Uhold" }, }; extern winid WIN_STATUS;