keep propertynames static in timeout.c

This commit is contained in:
nhmall
2022-11-06 10:02:27 -05:00
parent 38ff4029aa
commit 9e92fefdd8
3 changed files with 17 additions and 10 deletions
+1
View File
@@ -2749,6 +2749,7 @@ extern void substitute_tiles(d_level *);
/* ### timeout.c ### */ /* ### timeout.c ### */
extern const char *property_by_index(int, int *);
extern void burn_away_slime(void); extern void burn_away_slime(void);
extern void nh_timeout(void); extern void nh_timeout(void);
extern void fall_asleep(int, boolean); extern void fall_asleep(int, boolean);
+4 -9
View File
@@ -1955,16 +1955,12 @@ static int
wiz_intrinsic(void) wiz_intrinsic(void)
{ {
if (wizard) { if (wizard) {
extern const struct propname {
int prop_num;
const char *prop_name;
} propertynames[]; /* timeout.c */
static const char wizintrinsic[] = "#wizintrinsic"; static const char wizintrinsic[] = "#wizintrinsic";
static const char fmt[] = "You are%s %s."; static const char fmt[] = "You are%s %s.";
winid win; winid win;
anything any; anything any;
char buf[BUFSZ]; char buf[BUFSZ];
int i, j, n, p, amt, typ; int i, j, n, amt, typ, p = 0;
long oldtimeout, newtimeout; long oldtimeout, newtimeout;
const char *propname; const char *propname;
menu_item *pick_list = (menu_item *) 0; 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, add_menu(win, &nul_glyphinfo, &any, 0, 0, ATR_NONE, clr, buf,
MENU_ITEMFLAGS_NONE); MENU_ITEMFLAGS_NONE);
} }
for (i = 0; (propname = propertynames[i].prop_name) != 0; ++i) { for (i = 0; (propname = property_by_index(i, &p)) != 0; ++i) {
p = propertynames[i].prop_num;
if (p == HALLUC_RES) { if (p == HALLUC_RES) {
/* Grayswandir vs hallucination; ought to be redone to /* Grayswandir vs hallucination; ought to be redone to
use u.uprops[HALLUC].blocked instead of being treated use u.uprops[HALLUC].blocked instead of being treated
@@ -2014,7 +2009,7 @@ wiz_intrinsic(void)
for (j = 0; j < n; ++j) { for (j = 0; j < n; ++j) {
i = pick_list[j].item.a_int - 1; /* -1: reverse +1 above */ 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; oldtimeout = u.uprops[p].intrinsic & TIMEOUT;
amt = (pick_list[j].count == -1L) ? DEFAULT_TIMEOUT_INCR amt = (pick_list[j].count == -1L) ? DEFAULT_TIMEOUT_INCR
: (int) pick_list[j].count; : (int) pick_list[j].count;
@@ -2087,7 +2082,7 @@ wiz_intrinsic(void)
if (p != GLIB) if (p != GLIB)
incr_itimeout(&u.uprops[p].intrinsic, amt); incr_itimeout(&u.uprops[p].intrinsic, amt);
g.context.botl = 1; /* have pline() do a status update */ 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); oldtimeout ? "increased by" : "set to", amt);
break; break;
} }
+12 -1
View File
@@ -21,7 +21,7 @@ static void cleanup_burn(ANY_P *, long);
/* used by wizard mode #timeout and #wizintrinsic; order by 'interest' /* used by wizard mode #timeout and #wizintrinsic; order by 'interest'
for timeout countdown, where most won't occur in normal play */ for timeout countdown, where most won't occur in normal play */
const struct propname { static const struct propname {
int prop_num; int prop_num;
const char *prop_name; const char *prop_name;
} propertynames[] = { } propertynames[] = {
@@ -105,6 +105,17 @@ const struct propname {
{ 0, 0 }, { 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 */ /* He is being petrified - dialogue by inmet!tower */
static NEARDATA const char *const stoned_texts[] = { static NEARDATA const char *const stoned_texts[] = {
"You are slowing down.", /* 5 */ "You are slowing down.", /* 5 */