fix #H7667 - maybe_reset_pick(), other bad context

When deciding whether to discard interrupted lock/unlock context while
changing levels, maybe_reset_pick() checks whether xlock.box is being
carried.  But it was doing so after the old level had been saved and
memory for non-carried container there had been freed.

That led to a couple of other issues.  context.travelcc was using -1
for 'no cached value', but the fields of travelcc have type 'xchar' and
shouldn't be given negative values.  0 should be fine for 'no cache'.

Failed partial restore which occurred after old game's context had been
loaded would begin a new game with old game's stale context.  Restoring
goes out of its way to avoid that for 'flags' but didn't for 'context'.
This commit is contained in:
PatR
2018-12-04 17:10:15 -08:00
parent f6b7ce02d8
commit 36c2aec2ff
7 changed files with 39 additions and 41 deletions

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 do.c $NHDT-Date: 1543052696 2018/11/24 09:44:56 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.175 $ */
/* NetHack 3.6 do.c $NHDT-Date: 1543972190 2018/12/05 01:09:50 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.176 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Derek S. Ray, 2015. */
/* NetHack may be freely redistributed. See license for details. */
@@ -1237,6 +1237,17 @@ boolean at_stairs, falling, portal;
if (fd < 0)
return;
/* discard context which applies to the level we're leaving;
for lock-picking, container may be carried, in which case we
keep context; if on the floor, it's about to be saved+freed and
maybe_reset_pick() needs to do its carried() check before that */
maybe_reset_pick();
reset_trapset(); /* even if to-be-armed trap obj is accompanying hero */
iflags.travelcc.x = iflags.travelcc.y = 0; /* travel destination cache */
context.polearm.hitmon = (struct monst *) 0; /* polearm target */
/* digging context is level-aware and can actually be resumed if
hero returns to the previous level without any intervening dig */
if (falling) /* assuming this is only trap door or hole */
impact_drop((struct obj *) 0, u.ux, u.uy, newlevel->dlevel);
@@ -1576,14 +1587,6 @@ boolean at_stairs, falling, portal;
/* assume this will always return TRUE when changing level */
(void) in_out_region(u.ux, u.uy);
(void) pickup(1);
/* discard context which applied to previous level */
maybe_reset_pick(); /* for door or for box not accompanying hero */
reset_trapset(); /* even if to-be-armed trap obj is accompanying hero */
iflags.travelcc.x = iflags.travelcc.y = -1; /* travel destination cache */
context.polearm.hitmon = (struct monst *) 0; /* polearm target */
/* digging context is level-aware and can actually be resumed if
hero returns to the previous level without any intervening dig */
}
STATIC_OVL void