]> granicus.if.org Git - nethack/commitdiff
ranking of new status conditions
authornhmall <nhmall@nethack.org>
Sun, 9 Feb 2020 00:51:04 +0000 (19:51 -0500)
committernhmall <nhmall@nethack.org>
Sun, 9 Feb 2020 00:51:04 +0000 (19:51 -0500)
include/botl.h
src/botl.c
win/curses/cursstat.c
win/tty/wintty.c

index 708cfa8a3b2de966b772309e13d66172ffefba84..ecac2fe5d3caf30270e2545c07d043b5a941e8de 100644 (file)
@@ -118,7 +118,7 @@ enum blconditions {
 /* clang-format on */
 
 struct conditions_t {
-    int priority;
+    int ranking;
     long mask;
     enum blconditions c;
     const char *text[3];
@@ -135,6 +135,7 @@ struct condtests_t {
 };
 
 extern struct condtests_t condtests[CONDITION_COUNT];
+extern int cond_idx[CONDITION_COUNT];
 
 #define BEFORE  0
 #define NOW     1
index bb8fc1272ef93a3a462d4bc96071bdc8b5e55bc7..cb7cc9fed9419d00b3e2fc27929488f76d0e96fa 100644 (file)
@@ -421,6 +421,7 @@ static int FDECL(compare_blstats, (struct istat_s *, struct istat_s *));
 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));
 
 #ifdef STATUS_HILITES
 static void FDECL(s_to_anything, (anything *, char *, int));
@@ -542,36 +543,36 @@ const struct condmap condition_aliases[] = {
 #endif /* STATUS_HILITES */
 
 const struct conditions_t conditions[] = {
-    /* priority, mask, identifier, txt1, txt2, txt3 */
-    { 3, BL_MASK_BAREH,     bl_bareh,     { "Bare",     "Bar",   "Bh"  } },
-    { 2, BL_MASK_BLIND,     bl_blind,     { "Blind",    "Blnd",  "Bl"  } },
-    { 3, BL_MASK_BUSY,      bl_busy,      { "Busy",     "Bsy",   "By"  } },
-    { 2, BL_MASK_CONF,      bl_conf,      { "Conf",     "Cnf",   "Cf"  } },
-    { 2, BL_MASK_DEAF,      bl_deaf,      { "Deaf",     "Def",   "Df"  } },
-    { 3, BL_MASK_ELF_IRON,  bl_elf_iron,  { "Iron",     "Irn",   "Fe"  } },
-    { 2, BL_MASK_FLY,       bl_fly,       { "Fly",      "Fly",   "Fl"  } },
-    { 2, BL_MASK_FOODPOIS,  bl_foodpois,  { "FoodPois", "Fpois", "Poi" } },
-    { 3, BL_MASK_GLOWHANDS, bl_glowhands, { "Glow",     "Glo",   "Gl"  } },
-    { 2, BL_MASK_GRAB,      bl_grab,      { "Grab",     "Grb",   "Gr"  } },
-    { 2, BL_MASK_HALLU,     bl_hallu,     { "Hallu",    "Hal",   "Hl"  } },
-    { 3, BL_MASK_HELD,      bl_held,      { "Held",     "Hld",   "Hd"  } },
-    { 3, BL_MASK_ICY,       bl_icy,       { "Icy",      "Icy",   "Ic"  } },
-    { 2, BL_MASK_INLAVA,    bl_inlava,    { "Lava",     "Lav",   "La"  } },
-    { 2, BL_MASK_LEV,       bl_lev,       { "Lev",      "Lev",   "Lv"  } },
-    { 3, BL_MASK_PARLYZ,    bl_parlyz,    { "Parlyz",   "Para",  "Par" } },
-    { 2, BL_MASK_RIDE,      bl_ride,      { "Ride",     "Rid",   "Rd"  } },
-    { 3, BL_MASK_SLEEPING,  bl_sleeping,  { "Zzz",      "Zzz",   "Zz"  } },
-    { 2, BL_MASK_SLIME,     bl_slime,     { "Slime",    "Slim",  "Slm" } },
-    { 3, BL_MASK_SLIPPERY,  bl_slippery,  { "Slip",     "Sli",   "Sl"  } },
-    { 2, BL_MASK_STONE,     bl_stone,     { "Stone",    "Ston",  "Sto" } },
-    { 2, BL_MASK_STRNGL,    bl_strngl,    { "Strngl",   "Stngl", "Str" } },
-    { 2, BL_MASK_STUN,      bl_stun,      { "Stun",     "Stun",  "St"  } },
-    { 3, BL_MASK_SUBMERGED, bl_submerged, { "Sub",      "Sub",   "Sw"  } },
-    { 2, BL_MASK_TERMILL,   bl_termill,   { "TermIll",  "Ill",   "Ill" } },
-    { 3, BL_MASK_TETHERED,  bl_tethered,  { "Teth",     "Tth",   "Te"  } },
-    { 3, BL_MASK_TRAPPED,   bl_trapped,   { "Trap",     "Trp",   "Tr"  } },
-    { 3, BL_MASK_UNCONSC,   bl_unconsc,   { "Out",      "Out",   "KO"  } },
-    { 3, BL_MASK_WOUNDEDL,  bl_woundedl,  { "Legs",     "Leg",   "Lg"  } },
+    /* ranking, mask, identifier, txt1, txt2, txt3 */
+    { 20, BL_MASK_BAREH,     bl_bareh,     { "Bare",     "Bar",   "Bh"  } },
+    { 10, BL_MASK_BLIND,     bl_blind,     { "Blind",    "Blnd",  "Bl"  } },
+    { 20, BL_MASK_BUSY,      bl_busy,      { "Busy",     "Bsy",   "By"  } },
+    { 10, BL_MASK_CONF,      bl_conf,      { "Conf",     "Cnf",   "Cf"  } },
+    { 10, BL_MASK_DEAF,      bl_deaf,      { "Deaf",     "Def",   "Df"  } },
+    { 15, BL_MASK_ELF_IRON,  bl_elf_iron,  { "Iron",     "Irn",   "Fe"  } },
+    { 10, BL_MASK_FLY,       bl_fly,       { "Fly",      "Fly",   "Fl"  } },
+    {  6, BL_MASK_FOODPOIS,  bl_foodpois,  { "FoodPois", "Fpois", "Poi" } },
+    { 20, BL_MASK_GLOWHANDS, bl_glowhands, { "Glow",     "Glo",   "Gl"  } },
+    {  2, BL_MASK_GRAB,      bl_grab,      { "Grab",     "Grb",   "Gr"  } },
+    { 10, BL_MASK_HALLU,     bl_hallu,     { "Hallu",    "Hal",   "Hl"  } },
+    { 20, BL_MASK_HELD,      bl_held,      { "Held",     "Hld",   "Hd"  } },
+    { 20, BL_MASK_ICY,       bl_icy,       { "Icy",      "Icy",   "Ic"  } },
+    {  8, BL_MASK_INLAVA,    bl_inlava,    { "Lava",     "Lav",   "La"  } },
+    { 10, BL_MASK_LEV,       bl_lev,       { "Lev",      "Lev",   "Lv"  } },
+    { 20, BL_MASK_PARLYZ,    bl_parlyz,    { "Parlyz",   "Para",  "Par" } },
+    { 10, BL_MASK_RIDE,      bl_ride,      { "Ride",     "Rid",   "Rd"  } },
+    { 20, BL_MASK_SLEEPING,  bl_sleeping,  { "Zzz",      "Zzz",   "Zz"  } },
+    {  6, BL_MASK_SLIME,     bl_slime,     { "Slime",    "Slim",  "Slm" } },
+    { 20, BL_MASK_SLIPPERY,  bl_slippery,  { "Slip",     "Sli",   "Sl"  } },
+    {  6, BL_MASK_STONE,     bl_stone,     { "Stone",    "Ston",  "Sto" } },
+    {  4, BL_MASK_STRNGL,    bl_strngl,    { "Strngl",   "Stngl", "Str" } },
+    { 10, BL_MASK_STUN,      bl_stun,      { "Stun",     "Stun",  "St"  } },
+    { 15, BL_MASK_SUBMERGED, bl_submerged, { "Sub",      "Sub",   "Sw"  } },
+    {  6, BL_MASK_TERMILL,   bl_termill,   { "TermIll",  "Ill",   "Ill" } },
+    { 20, BL_MASK_TETHERED,  bl_tethered,  { "Teth",     "Tth",   "Te"  } },
+    { 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"  } },
 };
 
 struct condtests_t condtests[CONDITION_COUNT] = {
@@ -606,6 +607,8 @@ struct condtests_t condtests[CONDITION_COUNT] = {
     { bl_unconsc,   opt_in,  FALSE, FALSE, FALSE },
     { bl_woundedl,  opt_in,  FALSE, FALSE, FALSE },
 };
+/* condition indexing */
+int cond_idx[CONDITION_COUNT] = { 0 };
 
 /* cache-related */
 static boolean cache_avail[3] = { FALSE, FALSE, FALSE };
@@ -938,6 +941,49 @@ stat_update_time()
     return;
 }
 
+/* deal with player's choice to change processing of a condition */
+void
+condopt(addr, negated)
+boolean *addr;
+boolean negated;
+{
+    int i;
+    boolean is_init = FALSE;
+
+    for (i = 0; i < CONDITION_COUNT; ++i) {
+        if (!addr) {
+             /* special: indicates a request to init so
+                set the choice values to match the defaults */
+            is_init = TRUE;
+            cond_idx[i] = i;
+            condtests[i].choice = condtests[i].enabled;
+        } else if (addr == &condtests[i].choice) {
+            condtests[i].enabled = negated ? FALSE : TRUE;
+        }
+        /* avoid lingering false positives if test is no longer run */
+        if (!condtests[i].enabled)
+            condtests[i].test = FALSE;
+    }
+    if (is_init)
+        qsort((genericptr_t) cond_idx, CONDITION_COUNT,
+              sizeof cond_idx[0], cond_cmp);
+}
+
+/* qsort callback routine for sorting the condition index */
+static int CFDECLSPEC
+cond_cmp(vptr1, vptr2)
+const genericptr vptr1;
+const genericptr vptr2;
+{
+    int indx1 = *(int *) vptr1, indx2 = *(int *) vptr2,
+        c1 = conditions[indx1].ranking, c2 = conditions[indx2].ranking;
+
+    if (c1 != c2)
+        return c1 - c2;
+    /* tie-breaker - visible alpha by name */
+    return strcmpi(conditions[indx1].text[0], conditions[indx2].text[0]);
+}
+
 static boolean
 eval_notify_windowport_field(fld, valsetlist, idx)
 int fld, idx;
@@ -1587,28 +1633,6 @@ int idx;
     return (const char *) 0;
 }
 
-/* deal with player's choice to change processing of a condition */
-void
-condopt(addr, negated)
-boolean *addr;
-boolean negated;
-{
-    int i;
-
-    for (i = 0; i < CONDITION_COUNT; ++i) {
-        if (!addr) {
-             /* special: indicates a request to init so
-                set the choice values to match the defaults */
-            condtests[i].choice = condtests[i].enabled;
-        } else if (addr == &condtests[i].choice) {
-            condtests[i].enabled = negated ? FALSE : TRUE;
-        }
-        /* avoid lingering false positives if test is no longer run */
-        if (!condtests[i].enabled)
-            condtests[i].test = FALSE;
-    }
-}
-
 #ifdef STATUS_HILITES
 
 /****************************************************************************/
index e92e22c42be1286361f7c2f36fb1a4271cd8561d..9a85be656cbb41a06ca1a96df440067f1c5b4821 100644 (file)
@@ -975,6 +975,7 @@ curs_HPbar(char *text, /* pre-padded with trailing spaces if short */
 /* conditions[] is used primarily for parsing hilite_status rules, but
    we can use it for condition names and mask bits, avoiding duplication */
 extern const struct conditions_t conditions[]; /* botl.c */
+extern int cond_idx[CONDITION_COUNT];
 
 static void
 curs_stat_conds(int vert_cond, /* 0 => horizontal, 1 => vertical */
@@ -983,7 +984,7 @@ curs_stat_conds(int vert_cond, /* 0 => horizontal, 1 => vertical */
                 boolean *nohilite) /* optional output; indicates whether -*/
 {                                  /*+ condbuf[] could be used as-is      */
     char condnam[20];
-    int i;
+    int i, ci;
     long bitmsk;
 
     if (condbuf) {
@@ -996,9 +997,10 @@ curs_stat_conds(int vert_cond, /* 0 => horizontal, 1 => vertical */
         if (nohilite)
             *nohilite = TRUE; /* assume ok */
         for (i = 0; i < BL_MASK_BITS; ++i) {
-            bitmsk = conditions[i].mask;
+            ci = cond_idx[i];
+            bitmsk = conditions[ci].mask;
             if (curses_condition_bits & bitmsk) {
-                Strcpy(condnam, conditions[i].text[0]);
+                Strcpy(condnam, conditions[ci].text[0]);
                 Strcat(strcat(condbuf, " "), upstart(condnam));
 #ifdef STATUS_HILITES
                 if (nohilite && *nohilite
@@ -1024,9 +1026,10 @@ curs_stat_conds(int vert_cond, /* 0 => horizontal, 1 => vertical */
         cond_bits = curses_condition_bits;
         /* show active conditions directly; for vertical, three per line */
         for (i = 0; i < BL_MASK_BITS; ++i) {
-            bitmsk = conditions[i].mask;
+            ci = cond_idx[i];
+            bitmsk = conditions[ci].mask;
             if (cond_bits & bitmsk) {
-                Strcpy(condnam, conditions[i].text[0]);
+                Strcpy(condnam, conditions[ci].text[0]);
                 cndlen = 1 + (int) strlen(condnam); /* count leading space */
                 if (!do_vert) {
                     getyx(win, cy, cx);
index 2fbf28de79fc5db93d9e8c169e6d81e5e01fd5fe..e5a9fcb95297e33cdfc57bcf5d4331426ba87ee8 100644 (file)
@@ -4409,7 +4409,7 @@ static void
 render_status(VOID_ARGS)
 {
     long mask, bits;
-    int i, x, y, idx, c, row, tlth, num_rows, coloridx = 0, attrmask = 0;
+    int i, x, y, idx, c, ci, row, tlth, num_rows, coloridx = 0, attrmask = 0;
     char *text;
     struct WinDesc *cw = 0;
 
@@ -4473,7 +4473,8 @@ render_status(VOID_ARGS)
                         tty_curs(WIN_STATUS, x, y);
                     }
                     for (c = 0; c < SIZE(conditions) && bits != 0L; ++c) {
-                        mask = conditions[c].mask;
+                        ci = cond_idx[c];
+                        mask = conditions[ci].mask;
                         if (bits & mask) {
                             const char *condtext;
 
@@ -4485,7 +4486,7 @@ render_status(VOID_ARGS)
                                 if (coloridx != NO_COLOR)
                                     term_start_color(coloridx);
                             }
-                            condtext = conditions[c].text[cond_shrinklvl];
+                            condtext = conditions[ci].text[cond_shrinklvl];
                             if (x >= cw->cols && !truncation_expected) {
                                 impossible(
                          "Unexpected condition placement overflow for \"%s\"",