Fix #812: recovered stair dlevel
Stair dlevels weren't being restored with the correct values when recovered after the game crashed, apparently because they weren't being reset back to their 'absolute' level from a 'relative' level. I'm not totally sure of why this affected only recovered games (maybe that's the only time when the 'relative' stair values are used?) but this fix seems to work. Fixes #812
This commit is contained in:
@@ -254,6 +254,11 @@ enum saveformats {
|
|||||||
ascii = 3 /* each field, ascii text (just proof of concept) */
|
ascii = 3 /* each field, ascii text (just proof of concept) */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum restore_stages {
|
||||||
|
REST_GSTATE = 1, /* restoring current level and game state */
|
||||||
|
REST_LEVELS = 2, /* restoring remainder of dungeon */
|
||||||
|
};
|
||||||
|
|
||||||
/* sortloot() return type; needed before extern.h */
|
/* sortloot() return type; needed before extern.h */
|
||||||
struct sortloot_item {
|
struct sortloot_item {
|
||||||
struct obj *obj;
|
struct obj *obj;
|
||||||
|
|||||||
@@ -749,7 +749,7 @@ dorecover(NHFILE* nhfp)
|
|||||||
int rtmp;
|
int rtmp;
|
||||||
|
|
||||||
/* suppress map display if some part of the code tries to update that */
|
/* suppress map display if some part of the code tries to update that */
|
||||||
g.program_state.restoring = 1;
|
g.program_state.restoring = REST_GSTATE;
|
||||||
|
|
||||||
get_plname_from_file(nhfp, g.plname);
|
get_plname_from_file(nhfp, g.plname);
|
||||||
getlev(nhfp, 0, (xint8) 0);
|
getlev(nhfp, 0, (xint8) 0);
|
||||||
@@ -776,6 +776,8 @@ dorecover(NHFILE* nhfp)
|
|||||||
if (rtmp < 2)
|
if (rtmp < 2)
|
||||||
return rtmp; /* dorecover called recursively */
|
return rtmp; /* dorecover called recursively */
|
||||||
|
|
||||||
|
g.program_state.restoring = REST_LEVELS;
|
||||||
|
|
||||||
/* these pointers won't be valid while we're processing the
|
/* these pointers won't be valid while we're processing the
|
||||||
* other levels, but they'll be reset again by restlevelstate()
|
* other levels, but they'll be reset again by restlevelstate()
|
||||||
* afterwards, and in the meantime at least u.usteed may mislead
|
* afterwards, and in the meantime at least u.usteed may mislead
|
||||||
@@ -909,7 +911,8 @@ rest_stairs(NHFILE* nhfp)
|
|||||||
if (nhfp->structlevel) {
|
if (nhfp->structlevel) {
|
||||||
mread(nhfp->fd, (genericptr_t) &stway, sizeof (stairway));
|
mread(nhfp->fd, (genericptr_t) &stway, sizeof (stairway));
|
||||||
}
|
}
|
||||||
if (stway.tolev.dnum == u.uz.dnum) {
|
if (g.program_state.restoring != REST_GSTATE
|
||||||
|
&& stway.tolev.dnum == u.uz.dnum) {
|
||||||
/* stairway dlevel is relative, make it absolute */
|
/* stairway dlevel is relative, make it absolute */
|
||||||
stway.tolev.dlevel += u.uz.dlevel;
|
stway.tolev.dlevel += u.uz.dlevel;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -717,7 +717,9 @@ save_stairs(NHFILE* nhfp)
|
|||||||
|
|
||||||
while (stway) {
|
while (stway) {
|
||||||
if (perform_bwrite(nhfp)) {
|
if (perform_bwrite(nhfp)) {
|
||||||
if (stway->tolev.dnum == u.uz.dnum) {
|
boolean use_relative = (g.program_state.restoring != REST_GSTATE
|
||||||
|
&& stway->tolev.dnum == u.uz.dnum);
|
||||||
|
if (use_relative) {
|
||||||
/* make dlevel relative to current level */
|
/* make dlevel relative to current level */
|
||||||
stway->tolev.dlevel -= u.uz.dlevel;
|
stway->tolev.dlevel -= u.uz.dlevel;
|
||||||
}
|
}
|
||||||
@@ -725,7 +727,7 @@ save_stairs(NHFILE* nhfp)
|
|||||||
bwrite(nhfp->fd, (genericptr_t) &buflen, sizeof buflen);
|
bwrite(nhfp->fd, (genericptr_t) &buflen, sizeof buflen);
|
||||||
bwrite(nhfp->fd, (genericptr_t) stway, sizeof *stway);
|
bwrite(nhfp->fd, (genericptr_t) stway, sizeof *stway);
|
||||||
}
|
}
|
||||||
if (stway->tolev.dnum == u.uz.dnum) {
|
if (use_relative) {
|
||||||
/* reset staiway dlevel back to absolute */
|
/* reset staiway dlevel back to absolute */
|
||||||
stway->tolev.dlevel += u.uz.dlevel;
|
stway->tolev.dlevel += u.uz.dlevel;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user