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

View 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);

View File

@@ -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;
}

View 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 */