]> granicus.if.org Git - nethack/commitdiff
ensure condition menu always starts the same way even under "play again"
authornhmall <nhmall@nethack.org>
Fri, 21 Feb 2020 01:36:37 +0000 (20:36 -0500)
committernhmall <nhmall@nethack.org>
Fri, 21 Feb 2020 01:36:37 +0000 (20:36 -0500)
include/decl.h
src/botl.c
src/decl.c

index 335eaec92caebdc8b518c48baae5c37848fc5ccb..3488771f9f88627a5898cff22b08b5a1beacdb37 100644 (file)
@@ -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 */
index d52b184535eeff2c6aa72451905dec1d35656135..4a80ed43be874bd36ff2e6ce9a1bd77dd64f609a 100644 (file)
@@ -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 {
index 6bf82e986b4025590ca1d2a862719482142bfc5f..5604140d29fa25216807c000a2fc08a37fb4890e 100644 (file)
@@ -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 */