From: Eric S. Raymond Date: Sun, 12 Mar 2023 14:03:43 +0000 (-0400) Subject: Relax the savefile validity check a little. X-Git-Tag: 1.15~62 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=0ffb2978016618ce2ac500a098de7566d0b37add;p=open-adventure.git Relax the savefile validity check a little. There was a very old bug, probably predating the OpenAdventure port, that would poke a stashed value of -1 into the snake object if you did a save in endgame, and then fail the savefile validation on resume. This was masked for a long time by a bug in put() just fixed a couple of revisions ago. --- diff --git a/advent.h b/advent.h index 8cecf31..4d1c9f3 100644 --- a/advent.h +++ b/advent.h @@ -32,7 +32,7 @@ #define WRITE_MODE "wb" // b is not needed for POSIX but harmless /* Special object-state values - integers > 0 are object-specific */ -#define STATE_NOTFOUND -1 // 'Not found" state of treasures */ +#define STATE_NOTFOUND -1 // 'Not found" state of treasures #define STATE_FOUND 0 // After discovered, before messed with #define STATE_IN_CAVITY 1 // State value common to all gemstones @@ -42,7 +42,7 @@ /* Map a state property value to a negative range, where the object cannot be * picked up but the value can be recovered later. Avoid colliding with -1, - * which has its own meaning. */ + * which has its own meaning as STATE_NOTFOUND. */ #define STASHED(obj) (-1 - game.prop[obj]) #define PROMPT "> " diff --git a/saveresume.c b/saveresume.c index c9278a4..af71b5e 100644 --- a/saveresume.c +++ b/saveresume.c @@ -219,7 +219,8 @@ bool is_valid(struct game_t valgame) /* Check that properties of objects aren't beyond expected */ for (obj_t obj = 0; obj <= NOBJECTS; obj++) { - if (valgame.prop[obj] < STATE_NOTFOUND || valgame.prop[obj] > 1) { + /* Magic number -2 allows a STASHED version of state 1 */ + if (valgame.prop[obj] < -2 || valgame.prop[obj] > 1) { switch (obj) { case RUG: case DRAGON: diff --git a/tests/saveresume.4.chk b/tests/saveresume.4.chk index 1280b2b..260cbf3 100644 --- a/tests/saveresume.4.chk +++ b/tests/saveresume.4.chk @@ -10,9 +10,19 @@ down a gully. > resume Can't open file y, try again. -A dark fog creeps in to surround you. From somewhere in the fog you -hear a stern voice. "This Adventure has been tampered with! You have -been dabbling in magic, knowing not the havoc you might cause thereby. -Leave at once, before you do irrevocable harm!" The fog thickens, -until at last you can see nothing at all. Your vision then clears, -and you find yourself back in The Real World. +You're at sw end. + +The grate is locked. + +> blast + +There is a loud explosion, and a twenty-foot hole appears in the far +wall, burying the dwarves in the rubble. You march through the hole +and find yourself in the main office, where a cheering band of +friendly elves carry the conquering adventurer off into the sunset. + +You scored 423 out of a possible 430, using 468 turns. + +Your score puts you in Master Adventurer Class A. + +To achieve the next higher rating, you need 4 more points.