]> granicus.if.org Git - nethack/commitdiff
keep propertynames static in timeout.c
authornhmall <nhmall@nethack.org>
Sun, 6 Nov 2022 15:02:27 +0000 (10:02 -0500)
committernhmall <nhmall@nethack.org>
Sun, 6 Nov 2022 15:02:27 +0000 (10:02 -0500)
include/extern.h
src/cmd.c
src/timeout.c

index 534e4302686f23c74316d9139561b97a6ba06dd0..30579cee2f8889c5359fcb41989ff15db9a102b3 100644 (file)
@@ -2749,6 +2749,7 @@ extern void substitute_tiles(d_level *);
 
 /* ### timeout.c ### */
 
+extern const char *property_by_index(int, int *);
 extern void burn_away_slime(void);
 extern void nh_timeout(void);
 extern void fall_asleep(int, boolean);
index ce76858c0016c474358a3f92b8e0ad4f4d86c6a1..3a3503ce017ee617fd4d8beeb305ed53a4377b58 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -1955,16 +1955,12 @@ static int
 wiz_intrinsic(void)
 {
     if (wizard) {
-        extern const struct propname {
-            int prop_num;
-            const char *prop_name;
-        } propertynames[]; /* timeout.c */
         static const char wizintrinsic[] = "#wizintrinsic";
         static const char fmt[] = "You are%s %s.";
         winid win;
         anything any;
         char buf[BUFSZ];
-        int i, j, n, p, amt, typ;
+        int i, j, n, amt, typ, p = 0;
         long oldtimeout, newtimeout;
         const char *propname;
         menu_item *pick_list = (menu_item *) 0;
@@ -1982,8 +1978,7 @@ wiz_intrinsic(void)
             add_menu(win, &nul_glyphinfo, &any, 0, 0, ATR_NONE, clr, buf,
                      MENU_ITEMFLAGS_NONE);
         }
-        for (i = 0; (propname = propertynames[i].prop_name) != 0; ++i) {
-            p = propertynames[i].prop_num;
+        for (i = 0; (propname = property_by_index(i, &p)) != 0; ++i) {
             if (p == HALLUC_RES) {
                 /* Grayswandir vs hallucination; ought to be redone to
                    use u.uprops[HALLUC].blocked instead of being treated
@@ -2014,7 +2009,7 @@ wiz_intrinsic(void)
 
         for (j = 0; j < n; ++j) {
             i = pick_list[j].item.a_int - 1; /* -1: reverse +1 above */
-            p = propertynames[i].prop_num;
+            propname = property_by_index(i, &p);
             oldtimeout = u.uprops[p].intrinsic & TIMEOUT;
             amt = (pick_list[j].count == -1L) ? DEFAULT_TIMEOUT_INCR
                                               : (int) pick_list[j].count;
@@ -2087,7 +2082,7 @@ wiz_intrinsic(void)
                 if (p != GLIB)
                     incr_itimeout(&u.uprops[p].intrinsic, amt);
                 g.context.botl = 1; /* have pline() do a status update */
-                pline("Timeout for %s %s %d.", propertynames[i].prop_name,
+                pline("Timeout for %s %s %d.", propname,
                       oldtimeout ? "increased by" : "set to", amt);
                 break;
             }
index e7c37cf06d8baf65a1b82bcf1a2535b363fe4d42..0fb8d5d1f2942eb2f7c3c69e4ede4915cad222ca 100644 (file)
@@ -21,7 +21,7 @@ static void cleanup_burn(ANY_P *, long);
 
 /* used by wizard mode #timeout and #wizintrinsic; order by 'interest'
    for timeout countdown, where most won't occur in normal play */
-const struct propname {
+static const struct propname {
     int prop_num;
     const char *prop_name;
 } propertynames[] = {
@@ -105,6 +105,17 @@ const struct propname {
     {  0, 0 },
 };
 
+const char *
+property_by_index(int idx, int *propertynum)
+{
+    if (!(idx >= 0 && idx < SIZE(propertynames) - 1))
+        idx = SIZE(propertynames) - 1;
+
+    if (propertynum)
+        *propertynum = propertynames[idx].prop_num;
+    return propertynames[idx].prop_name;
+}
+
 /* He is being petrified - dialogue by inmet!tower */
 static NEARDATA const char *const stoned_texts[] = {
     "You are slowing down.",            /* 5 */