From: nhmall Date: Fri, 21 Feb 2020 01:36:37 +0000 (-0500) Subject: ensure condition menu always starts the same way even under "play again" X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=86f5e73ef38d6ce65f05fad8963bc3406652246a;p=nethack ensure condition menu always starts the same way even under "play again" --- diff --git a/include/decl.h b/include/decl.h index 335eaec92..3488771f9 100644 --- a/include/decl.h +++ b/include/decl.h @@ -667,6 +667,7 @@ struct instance_globals { #endif unsigned long cond_hilites[BL_ATTCLR_MAX]; int now_or_before_idx; /* 0..1 for array[2][] first index */ + int condmenu_sortorder; /* cmd.c */ struct cmd Cmd; /* flag.h */ diff --git a/src/botl.c b/src/botl.c index d52b18453..4a80ed43b 100644 --- a/src/botl.c +++ b/src/botl.c @@ -963,6 +963,7 @@ boolean negated; if (!addr) { /* special: indicates a request to init so set the choice values to match the defaults */ + g.condmenu_sortorder = 0; for (i = 0; i < CONDITION_COUNT; ++i) { cond_idx[i] = i; condtests[i].choice = condtests[i].enabled; @@ -1031,7 +1032,6 @@ char *opts; void cond_menu(VOID_ARGS) { - static int sortorder = 0; static const char *menutitle[2] = { "alphabetically", "by ranking"}; int i, res, idx = 0; int sequence[CONDITION_COUNT]; @@ -1047,7 +1047,7 @@ cond_menu(VOID_ARGS) } qsort((genericptr_t) sequence, CONDITION_COUNT, sizeof sequence[0], - (sortorder) ? cond_cmp : menualpha_cmp); + (g.condmenu_sortorder) ? cond_cmp : menualpha_cmp); tmpwin = create_nhwindow(NHW_MENU); start_menu(tmpwin, MENU_BEHAVE_STANDARD); @@ -1055,11 +1055,12 @@ cond_menu(VOID_ARGS) any = cg.zeroany; any.a_int = 1; Sprintf(mbuf, "change sort order from \"%s\" to \"%s\"", - menutitle[sortorder], menutitle[1 - sortorder]); + menutitle[g.condmenu_sortorder], + menutitle[1 - g.condmenu_sortorder]); add_menu(tmpwin, NO_GLYPH, &any, 'S', 0, ATR_NONE, mbuf, MENU_ITEMFLAGS_NONE); any = cg.zeroany; - Sprintf(mbuf, "sorted %s", menutitle[sortorder]); + Sprintf(mbuf, "sorted %s", menutitle[g.condmenu_sortorder]); add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings, mbuf, MENU_ITEMFLAGS_NONE); for (i = 0; i < SIZE(condtests); i++) { @@ -1084,7 +1085,7 @@ cond_menu(VOID_ARGS) idx = picks[i].item.a_int; if (idx == 1) { /* sort change requested */ - sortorder = 1 - sortorder; + g.condmenu_sortorder = 1 - g.condmenu_sortorder; showmenu = TRUE; break; /* for loop */ } else { diff --git a/src/decl.c b/src/decl.c index 6bf82e986..5604140d2 100644 --- a/src/decl.c +++ b/src/decl.c @@ -235,6 +235,7 @@ const struct instance_globals g_init = { #endif UNDEFINED_VALUES, /* cond_hilites */ 0, /* now_or_before_idx */ + 0, /* condmenu_sortorder */ /* cmd.c */ UNDEFINED_VALUES, /* Cmd */