recalc_mapseen() followup

Update several places where lazy lastseentyp[] might be an issue.

I think it isn't updated in a timely fashion when newsym() shows
a spot covered by an object or trap, but didn't manage to find any
cases where that caused a problem.  This is more in the nature of
a precaution.
This commit is contained in:
PatR
2023-12-20 03:17:29 -08:00
parent 60dc6343e4
commit 0713b91beb
7 changed files with 94 additions and 64 deletions
+3 -2
View File
@@ -1,4 +1,4 @@
/* NetHack 3.7 extern.h $NHDT-Date: 1702349265 2023/12/12 02:47:45 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.1328 $ */ /* NetHack 3.7 extern.h $NHDT-Date: 1703070179 2023/12/20 11:02:59 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.1344 $ */
/* Copyright (c) Steve Creps, 1988. */ /* Copyright (c) Steve Creps, 1988. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -414,7 +414,7 @@ extern int food_detect(struct obj *);
extern int object_detect(struct obj *, int); extern int object_detect(struct obj *, int);
extern int monster_detect(struct obj *, int); extern int monster_detect(struct obj *, int);
extern int trap_detect(struct obj *); extern int trap_detect(struct obj *);
extern const char *level_distance(d_level *) NONNULLARG1; extern const char *level_distance(d_level *) NONNULL NONNULLARG1;
extern void use_crystal_ball(struct obj **) NONNULLARG1; extern void use_crystal_ball(struct obj **) NONNULLARG1;
extern void show_map_spot(coordxy, coordxy, boolean); extern void show_map_spot(coordxy, coordxy, boolean);
extern void do_mapping(void); extern void do_mapping(void);
@@ -829,6 +829,7 @@ extern void show_overview(int, int);
extern void rm_mapseen(int); extern void rm_mapseen(int);
extern void init_mapseen(d_level *) NONNULLARG1; extern void init_mapseen(d_level *) NONNULLARG1;
extern void update_lastseentyp(coordxy, coordxy); extern void update_lastseentyp(coordxy, coordxy);
extern int update_mapseen_for(coordxy, coordxy);
extern void recalc_mapseen(void); extern void recalc_mapseen(void);
extern void mapseen_temple(struct monst *); extern void mapseen_temple(struct monst *);
extern void room_discovered(int); extern void room_discovered(int);
+5 -1
View File
@@ -1,4 +1,4 @@
/* NetHack 3.7 cmd.c $NHDT-Date: 1702123758 2023/12/09 12:09:18 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.694 $ */ /* NetHack 3.7 cmd.c $NHDT-Date: 1703070187 2023/12/20 11:03:07 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.695 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2013. */ /*-Copyright (c) Robert Patrick Rankin, 2013. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -2159,6 +2159,10 @@ doterrain(void)
int which; int which;
int clr = NO_COLOR; int clr = NO_COLOR;
/* this used to be done each time vision was recalculated, so would
always be up to date (hopefully); now we do it on demand instead */
recalc_mapseen();
/* /*
* normal play: choose between known map without mons, obj, and traps * normal play: choose between known map without mons, obj, and traps
* (to see underlying terrain only), or * (to see underlying terrain only), or
+44 -34
View File
@@ -1,4 +1,4 @@
/* NetHack 3.7 detect.c $NHDT-Date: 1613721262 2021/02/19 07:54:22 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.131 $ */ /* NetHack 3.7 detect.c $NHDT-Date: 1703070189 2023/12/20 11:03:09 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.171 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2018. */ /*-Copyright (c) Robert Patrick Rankin, 2018. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -930,10 +930,11 @@ display_trap_map(int cursed_src)
cls(); cls();
(void) unconstrain_map(); (void) unconstrain_map();
/* show chest traps first, so that subsequent floor trap display /* show chest traps first, first buried chests then floor chests, so
will override if both types are present at the same location */ that subsequent floor trap display will override if both types are
(void) detect_obj_traps(fobj, TRUE, cursed_src); present at the same location */
(void) detect_obj_traps(gl.level.buriedobjlist, TRUE, cursed_src); (void) detect_obj_traps(gl.level.buriedobjlist, TRUE, cursed_src);
(void) detect_obj_traps(fobj, TRUE, cursed_src);
for (mon = fmon; mon; mon = mon->nmon) { for (mon = fmon; mon; mon = mon->nmon) {
if (DEADMONSTER(mon) || (mon->isgd && !mon->mx)) if (DEADMONSTER(mon) || (mon->isgd && !mon->mx))
continue; continue;
@@ -974,8 +975,8 @@ display_trap_map(int cursed_src)
* returns 0 if something was detected * returns 0 if something was detected
*/ */
int int
trap_detect(struct obj *sobj) /* null if crystal ball, trap_detect(
*scroll if gold detection scroll */ struct obj *sobj) /* Null if crystal ball, scroll if gold detection */
{ {
register struct trap *ttmp; register struct trap *ttmp;
struct monst *mon; struct monst *mon;
@@ -992,7 +993,7 @@ trap_detect(struct obj *sobj) /* null if crystal ball,
if (ttmp->tx != u.ux || ttmp->ty != u.uy) { if (ttmp->tx != u.ux || ttmp->ty != u.uy) {
display_trap_map(cursed_src); display_trap_map(cursed_src);
return 0; return 0;
} else }
found = TRUE; found = TRUE;
} }
/* chest traps (might be buried or carried) */ /* chest traps (might be buried or carried) */
@@ -1000,7 +1001,7 @@ trap_detect(struct obj *sobj) /* null if crystal ball,
if (tr & OTRAP_THERE) { if (tr & OTRAP_THERE) {
display_trap_map(cursed_src); display_trap_map(cursed_src);
return 0; return 0;
} else }
found = TRUE; found = TRUE;
} }
if ((tr = detect_obj_traps(gl.level.buriedobjlist, FALSE, 0)) if ((tr = detect_obj_traps(gl.level.buriedobjlist, FALSE, 0))
@@ -1008,7 +1009,7 @@ trap_detect(struct obj *sobj) /* null if crystal ball,
if (tr & OTRAP_THERE) { if (tr & OTRAP_THERE) {
display_trap_map(cursed_src); display_trap_map(cursed_src);
return 0; return 0;
} else }
found = TRUE; found = TRUE;
} }
for (mon = fmon; mon; mon = mon->nmon) { for (mon = fmon; mon; mon = mon->nmon) {
@@ -1018,7 +1019,7 @@ trap_detect(struct obj *sobj) /* null if crystal ball,
if (tr & OTRAP_THERE) { if (tr & OTRAP_THERE) {
display_trap_map(cursed_src); display_trap_map(cursed_src);
return 0; return 0;
} else }
found = TRUE; found = TRUE;
} }
} }
@@ -1036,7 +1037,7 @@ trap_detect(struct obj *sobj) /* null if crystal ball,
if (cc.x != u.ux || cc.y != u.uy) { if (cc.x != u.ux || cc.y != u.uy) {
display_trap_map(cursed_src); display_trap_map(cursed_src);
return 0; return 0;
} else }
found = TRUE; found = TRUE;
} }
} }
@@ -1098,46 +1099,55 @@ furniture_detect(void)
return 0; return 0;
} }
/* way back in 3.0plN and/or 2.x, you could use a crystal ball to find out
where the wizard was relative to your current location; that was when the
Wizard guarded the Amulet and was located on a random maze level, and you
were expected to level teleport deep into Hell and hunt for him while
working your way up; this isn't of much use anymore */
const char * const char *
level_distance(d_level *where) level_distance(d_level *where)
{ {
register schar ll = depth(&u.uz) - depth(where); schar ll = depth(&u.uz) - depth(where);
register boolean indun = (u.uz.dnum == where->dnum); boolean indun = (u.uz.dnum == where->dnum);
const char *res = ""; /* always replaced by some other non-Null value */
if (ll < 0) { if (ll < 0) {
if (ll < (-8 - rn2(3))) if (ll < (-8 - rn2(3)))
if (!indun) if (!indun)
return "far away"; res = "far away";
else else
return "far below"; res = "far below";
else if (ll < -1) else if (ll < -1)
if (!indun) if (!indun)
return "away below you"; res = "away below you";
else else
return "below you"; res = "below you";
else if (!indun) else if (!indun)
return "in the distance"; res = "in the distance";
else else
return "just below"; res = "just below";
} else if (ll > 0) { } else if (ll > 0) {
if (ll > (8 + rn2(3))) if (ll > (8 + rn2(3)))
if (!indun) if (!indun)
return "far away"; res = "far away";
else else
return "far above"; res = "far above";
else if (ll > 1) else if (ll > 1)
if (!indun) if (!indun)
return "away above you"; res = "away above you";
else else
return "above you"; res = "above you";
else if (!indun) else if (!indun)
return "in the distance"; res = "in the distance";
else else
return "just above"; res = "just above";
} else if (!indun) } else { /* l1 == 0 */
return "in the distance"; if (!indun)
res = "in the distance";
else else
return "near you"; res = "near you";
}
return res;
} }
/* /*
@@ -1360,7 +1370,7 @@ show_map_spot(coordxy x, coordxy y, boolean cnf)
if (!IS_FURNITURE(lev->typ)) { if (!IS_FURNITURE(lev->typ)) {
if ((t = t_at(x, y)) != 0 && t->tseen) { if ((t = t_at(x, y)) != 0 && t->tseen) {
map_trap(t, 1); map_trap(t, 1);
} else if ((ep = engr_at(x,y)) != 0) { } else if ((ep = engr_at(x, y)) != 0) {
map_engraving(ep, 1); map_engraving(ep, 1);
} else if (glyph_is_trap(oldglyph) || glyph_is_object(oldglyph)) { } else if (glyph_is_trap(oldglyph) || glyph_is_object(oldglyph)) {
show_glyph(x, y, oldglyph); show_glyph(x, y, oldglyph);
@@ -1442,7 +1452,7 @@ do_vicinity_map(struct obj *sobj) /* scroll--actually fake spellbook--object */
/* if hero is engulfed, show engulfer at <u.ux,u.uy> */ /* if hero is engulfed, show engulfer at <u.ux,u.uy> */
save_viz_uyux = gv.viz_array[u.uy][u.ux]; save_viz_uyux = gv.viz_array[u.uy][u.ux];
if (u.uswallow) if (u.uswallow)
gv.viz_array[u.uy][u.ux] |= IN_SIGHT; /* <x,y> are reversed to [y][x] */ gv.viz_array[u.uy][u.ux] |= IN_SIGHT; /* <x,y> are reversed, [y][x] */
save_EDetect_mons = EDetect_monsters; save_EDetect_mons = EDetect_monsters;
/* for skilled spell, getpos() scanning of the map will display all /* for skilled spell, getpos() scanning of the map will display all
monsters within range; otherwise, "unseen creature" will be shown */ monsters within range; otherwise, "unseen creature" will be shown */
@@ -2027,9 +2037,9 @@ reveal_terrain_getglyph(
glyph = back_to_glyph(x, y); glyph = back_to_glyph(x, y);
levl[x][y].seenv = seenv; levl[x][y].seenv = seenv;
} else { } else {
levl_glyph = gl.level.flags.hero_memory levl_glyph = gl.level.flags.hero_memory ? levl[x][y].glyph
? levl[x][y].glyph : seenv ? back_to_glyph(x, y)
: seenv ? back_to_glyph(x, y): default_glyph; : default_glyph;
/* glyph_at() returns the displayed glyph, which might /* glyph_at() returns the displayed glyph, which might
be a monster. levl[][].glyph contains the remembered be a monster. levl[][].glyph contains the remembered
glyph, which will never be a monster (unless it is glyph, which will never be a monster (unless it is
@@ -2181,7 +2191,7 @@ reveal_terrain(
for (x = 1; x < COLNO; x++) for (x = 1; x < COLNO; x++)
for (y = 0; y < ROWNO; y++) { for (y = 0; y < ROWNO; y++) {
glyph = reveal_terrain_getglyph(x,y, swallowed, glyph = reveal_terrain_getglyph(x, y, swallowed,
default_glyph, which_subset); default_glyph, which_subset);
show_glyph(x, y, glyph); show_glyph(x, y, glyph);
} }
+24 -10
View File
@@ -1,4 +1,4 @@
/* NetHack 3.7 dungeon.c $NHDT-Date: 1700012885 2023/11/15 01:48:05 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.197 $ */ /* NetHack 3.7 dungeon.c $NHDT-Date: 1703070190 2023/12/20 11:03:10 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.205 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2012. */ /*-Copyright (c) Robert Patrick Rankin, 2012. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -1687,13 +1687,13 @@ u_on_dnstairs(void)
boolean boolean
On_stairs(coordxy x, coordxy y) On_stairs(coordxy x, coordxy y)
{ {
return (stairway_at(x,y) != NULL); return (stairway_at(x, y) != NULL);
} }
boolean boolean
On_ladder(coordxy x, coordxy y) On_ladder(coordxy x, coordxy y)
{ {
stairway *stway = stairway_at(x,y); stairway *stway = stairway_at(x, y);
return (boolean) (stway && stway->isladder); return (boolean) (stway && stway->isladder);
} }
@@ -1701,7 +1701,7 @@ On_ladder(coordxy x, coordxy y)
boolean boolean
On_stairs_up(coordxy x, coordxy y) On_stairs_up(coordxy x, coordxy y)
{ {
stairway *stway = stairway_at(x,y); stairway *stway = stairway_at(x, y);
return (boolean) (stway && stway->up); return (boolean) (stway && stway->up);
} }
@@ -1709,7 +1709,7 @@ On_stairs_up(coordxy x, coordxy y)
boolean boolean
On_stairs_dn(coordxy x, coordxy y) On_stairs_dn(coordxy x, coordxy y)
{ {
stairway *stway = stairway_at(x,y); stairway *stway = stairway_at(x, y);
return (boolean) (stway && !stway->up); return (boolean) (stway && !stway->up);
} }
@@ -3075,16 +3075,31 @@ update_lastseentyp(coordxy x, coordxy y)
gl.lastseentyp[x][y] = ltyp; gl.lastseentyp[x][y] = ltyp;
} }
/* for some cases where deferred update needs to be done immediately;
hide details from caller */
int
update_mapseen_for(coordxy x, coordxy y)
{
recalc_mapseen(); /* whole level */
return gl.lastseentyp[x][y];
}
/* count mapseen feature from lastseentyp at x,y */ /* count mapseen feature from lastseentyp at x,y */
static void static void
count_feat_lastseentyp(mapseen *mptr, count_feat_lastseentyp(
mapseen *mptr, /* remembered data for a level; update feat.X counts */
coordxy x, coordxy y) coordxy x, coordxy y)
{ {
int count; int count;
unsigned atmp; unsigned atmp;
switch (gl.lastseentyp[x][y]) { switch (gl.lastseentyp[x][y]) {
#if 0 #if 0 /* levels that have these tend of have a lot of them */
/*
* FIXME? due to theme rooms, lots of levels have an incresed
* chance of having these so automatic annotations for them may
* have become more worthwhile now.
*/
case ICE: case ICE:
count = mptr->feat.ice + 1; count = mptr->feat.ice + 1;
if (count <= 3) if (count <= 3)
@@ -3133,8 +3148,7 @@ count_feat_lastseentyp(mapseen *mptr,
/* get the altarmask for this location; might be a mimic */ /* get the altarmask for this location; might be a mimic */
atmp = altarmask_at(x, y); atmp = altarmask_at(x, y);
/* convert to index: 0..3 */ /* convert to index: 0..3 */
atmp = (Is_astralevel(&u.uz) atmp = (Is_astralevel(&u.uz) && (levl[x][y].seenv & SVALL) != SVALL)
&& (levl[x][y].seenv & SVALL) != SVALL)
? MSA_NONE ? MSA_NONE
: Amask2msa(atmp); : Amask2msa(atmp);
if (!mptr->feat.naltar) if (!mptr->feat.naltar)
@@ -3163,7 +3177,7 @@ count_feat_lastseentyp(mapseen *mptr,
if (Is_knox(&u.uz)) { if (Is_knox(&u.uz)) {
int ty, tx = x - 4; int ty, tx = x - 4;
/* Throne is four columns left, either directly in /* Throne is four columns to left, either directly in
* line or one row higher or lower, and doesn't have * line or one row higher or lower, and doesn't have
* to have been seen yet. * to have been seen yet.
* ......|}}}. * ......|}}}.
+4 -4
View File
@@ -1,4 +1,4 @@
/* NetHack 3.7 lock.c $NHDT-Date: 1654464994 2022/06/05 21:36:34 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.114 $ */ /* NetHack 3.7 lock.c $NHDT-Date: 1703070191 2023/12/20 11:03:11 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.131 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2011. */ /*-Copyright (c) Robert Patrick Rankin, 2011. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -569,7 +569,7 @@ pick_lock(
} }
if (!IS_DOOR(door->typ)) { if (!IS_DOOR(door->typ)) {
int res = PICKLOCK_DID_NOTHING, oldglyph = door->glyph; int res = PICKLOCK_DID_NOTHING, oldglyph = door->glyph;
schar oldlastseentyp = gl.lastseentyp[cc.x][cc.y]; schar oldlastseentyp = update_mapseen_for(cc.x, cc.y);
/* this is probably only relevant when blind */ /* this is probably only relevant when blind */
feel_location(cc.x, cc.y); feel_location(cc.x, cc.y);
@@ -819,7 +819,7 @@ doopen_indir(coordxy x, coordxy y)
/* this used to be 'if (Blind)' but using a key skips that so we do too */ /* this used to be 'if (Blind)' but using a key skips that so we do too */
{ {
int oldglyph = door->glyph; int oldglyph = door->glyph;
schar oldlastseentyp = gl.lastseentyp[cc.x][cc.y]; schar oldlastseentyp = update_mapseen_for(cc.x, cc.y);
newsym(cc.x, cc.y); newsym(cc.x, cc.y);
if (door->glyph != oldglyph if (door->glyph != oldglyph
@@ -979,7 +979,7 @@ doclose(void)
portcullis = (is_drawbridge_wall(x, y) >= 0); portcullis = (is_drawbridge_wall(x, y) >= 0);
if (Blind) { if (Blind) {
int oldglyph = door->glyph; int oldglyph = door->glyph;
schar oldlastseentyp = gl.lastseentyp[x][y]; schar oldlastseentyp = update_mapseen_for(x, y);
feel_location(x, y); feel_location(x, y);
if (door->glyph != oldglyph || gl.lastseentyp[x][y] != oldlastseentyp) if (door->glyph != oldglyph || gl.lastseentyp[x][y] != oldlastseentyp)
+3 -2
View File
@@ -1,4 +1,4 @@
/* NetHack 3.7 trap.c $NHDT-Date: 1702274034 2023/12/11 05:53:54 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.559 $ */ /* NetHack 3.7 trap.c $NHDT-Date: 1703070192 2023/12/20 11:03:12 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.562 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2013. */ /*-Copyright (c) Robert Patrick Rankin, 2013. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -4774,7 +4774,8 @@ rescued_from_terrain(int how)
iflags.last_msg = PLNMSG_BACK_ON_GROUND; /* for describe_decor() */ iflags.last_msg = PLNMSG_BACK_ON_GROUND; /* for describe_decor() */
/* feedback just disclosed this */ /* feedback just disclosed this */
iflags.prev_decor = gl.lastseentyp[u.ux][u.uy] = lev->typ; update_lastseentyp(u.ux, u.uy);
iflags.prev_decor = gl.lastseentyp[u.ux][u.uy];
} }
/* return TRUE iff player relocated */ /* return TRUE iff player relocated */
+2 -2
View File
@@ -1,4 +1,4 @@
/* NetHack 3.7 zap.c $NHDT-Date: 1702023277 2023/12/08 08:14:37 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.498 $ */ /* NetHack 3.7 zap.c $NHDT-Date: 1703070194 2023/12/20 11:03:14 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.501 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2013. */ /*-Copyright (c) Robert Patrick Rankin, 2013. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -3113,7 +3113,7 @@ zap_updown(struct obj *obj) /* wand or spell */
You("probe towards the %s.", ceiling(x, y)); You("probe towards the %s.", ceiling(x, y));
} else { /* down */ } else { /* down */
const char *surf; const char *surf;
schar ltyp, rememberedltyp = gl.lastseentyp[x][y]; schar ltyp, rememberedltyp = update_mapseen_for(x, y);
ptmp += bhitpile(obj, bhito, x, y, u.dz); ptmp += bhitpile(obj, bhito, x, y, u.dz);
/* sequencing: zap_map() calls force_decor() for ice or furniture; /* sequencing: zap_map() calls force_decor() for ice or furniture;