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 restore.c $NHDT-Date: 1542798626 2018/11/21 11:10:26 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.109 $ */
/* NetHack 3.6 restore.c $NHDT-Date: 1543972193 2018/12/05 01:09:53 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.128 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Michael Allison, 2009. */
/* NetHack may be freely redistributed. See license for details. */
@@ -539,6 +539,7 @@ unsigned int *stuckid, *steedid;
#ifdef SYSFLAGS
struct sysflag newgamesysflags;
#endif
struct context_info newgamecontext; /* all 0, but has some pointers */
struct obj *otmp, *tmp_bc;
char timebuf[15];
unsigned long uid;
@@ -553,9 +554,15 @@ unsigned int *stuckid, *steedid;
if (!wizard)
return FALSE;
}
newgamecontext = context; /* copy statically init'd context */
mread(fd, (genericptr_t) &context, sizeof (struct context_info));
if (context.warntype.speciesidx >= LOW_PM)
context.warntype.species = &mons[context.warntype.speciesidx];
context.warntype.species = (context.warntype.speciesidx >= LOW_PM)
? &mons[context.warntype.speciesidx]
: (struct permonst *) 0;
/* context.victual.piece, .tin.tin, .spellbook.book, and .polearm.hitmon
are pointers which get set to Null during save and will be recovered
via corresponding o_id or m_id while objs or mons are being restored */
/* we want to be able to revert to command line/environment/config
file option values instead of keeping old save file option values
@@ -625,6 +632,7 @@ unsigned int *stuckid, *steedid;
#ifdef SYSFLAGS
sysflags = newgamesysflags;
#endif
context = newgamecontext;
return FALSE;
}
/* in case hangup save occurred in midst of level change */