whatis fix for boulders

In the past couple of days the code for '/' and ';' to examine
objects was changed to handle ROCK_CLASS differently (as part of
revising looking at map spots showing the engraving symbol).  It
could potentially set up a static buffer in the object classes loop
and then overwrite that when processing another class.  I couldn't
trigger any feedback anomalies, even when changing bouldersym to
various values including class characters both before and after '`',
but this redoes the suspect code to make it more robust.

Also, refine the test for whether a screen symbol matches an object
symbol.
This commit is contained in:
PatR
2023-11-20 00:29:16 -08:00
parent 5c8b36e95a
commit 490b60da4d
+18 -15
View File
@@ -1269,8 +1269,7 @@ do_screen_description(
/* Now check for objects */ /* Now check for objects */
if (!iflags.terrainmode || (iflags.terrainmode & TER_OBJ) != 0) { if (!iflags.terrainmode || (iflags.terrainmode & TER_OBJ) != 0) {
/* need a static buffer in case it gets returned as *firstmatch */ const char *oc_ptr;
static char oc_buf[40]; /* does not need to be in 'struct g' */
nhsym bouldersym; nhsym bouldersym;
j = SYM_BOULDER + SYM_OFF_X; j = SYM_BOULDER + SYM_OFF_X;
@@ -1280,21 +1279,21 @@ do_screen_description(
bouldersym = def_oc_syms[ROCK_CLASS].sym; bouldersym = def_oc_syms[ROCK_CLASS].sym;
for (i = 1; i < MAXOCLASSES; i++) { for (i = 1; i < MAXOCLASSES; i++) {
if (sym == (looked ? gs.showsyms[i + SYM_OFF_O] if ((i != ROCK_CLASS)
: def_oc_syms[i].sym) ? (sym == (looked ? gs.showsyms[i + SYM_OFF_O]
|| (i == ROCK_CLASS && (glyph_is_statue(glyph) : def_oc_syms[i].sym))
|| sym == bouldersym))) {
Strcpy(oc_buf, def_oc_syms[i].explain);
/* ROCK_CLASS is complicated; statues are displayed as the /* ROCK_CLASS is complicated; statues are displayed as the
monster they depict rather than as S_rock; boulders might monster they depict rather than as S_rock; boulders might
be displayed as a custom symbol rather than as S_rock; be displayed as a custom symbol rather than as S_rock */
for added fun, engravings are shown with the same symbol : (glyph_is_statue(glyph) || sym == bouldersym)) {
oc_ptr = def_oc_syms[i].explain;
/* for added fun, engravings are shown with the same symbol
as S_rock which is why we want to shorten this */ as S_rock which is why we want to shorten this */
if (i == ROCK_CLASS && !strcmp(oc_buf, "boulder or statue")) { if (i == ROCK_CLASS && !strcmp(oc_ptr, "boulder or statue")) {
if (sym == bouldersym) if (sym == bouldersym)
Strcpy(oc_buf, "boulder"); /* discard "or statue" */ oc_ptr = "boulder"; /* discard "or statue" */
else if (glyph_is_statue(glyph)) else if (glyph_is_statue(glyph))
Strcpy(oc_buf, "statue"); /* discard "boulder or" */ oc_ptr = "statue"; /* discard "boulder or" */
else if (looked) else if (looked)
continue; /* discard both */ continue; /* discard both */
} }
@@ -1304,11 +1303,15 @@ do_screen_description(
continue; continue;
} }
if (!found) { if (!found) {
Sprintf(out_str, "%s%s", prefix, an(oc_buf)); Sprintf(out_str, "%s%s", prefix, an(oc_ptr));
*firstmatch = oc_buf; /* note: if the value assigned to *firstmatch ever
becomes dynamically constructed, it will need to be
copied into a static buffer; as of now, all alternate
values are string literals and implicitly static */
*firstmatch = oc_ptr;
found++; found++;
} else { } else {
found += append_str(out_str, an(oc_buf)); found += append_str(out_str, an(oc_ptr));
} }
} }
} }