7 #include "linenoise/linenoise.h"
10 * (ESR) This replaces a bunch of particularly nasty FORTRAN-derived code;
11 * see the history.adoc file in the source distribution for discussion.
14 #define VRSION 26 /* bump on save format change */
17 * If you change the first three members, the resume function may not properly
18 * reject saves from older versions. Yes, this glues us to a hardware-
19 * dependent length of long. Later members can change, but bump the version
24 long mode; /* not used, must be present for version detection */
30 /* Suspend and resume */
33 /* Suspend. Offer to save things in a file, but charging
34 * some points (so can't win by using saved games to retry
35 * battles or to start over after learning zzword).
36 * If ADVENT_NOSAVE is defined, do nothing instead. */
44 rspeak(SUSPEND_WARNING);
45 if (!YES(arbitrary_messages[THIS_ACCEPTABLE], arbitrary_messages[OK_MAN], arbitrary_messages[OK_MAN])) return GO_CLEAROBJ;
46 game.saved = game.saved + 5;
49 char* name = linenoise("\nFile name: ");
52 fp = fopen(name, WRITE_MODE);
54 printf("Can't open file %s, try again.\n", name);
62 save.version = VRSION;
63 memcpy(&save.game, &game, sizeof(struct game_t));
64 IGNORE(fwrite(&save, sizeof(struct save_t), 1, fp));
72 /* Resume. Read a suspended game back from a file.
73 * If ADVENT_NOSAVE is defined, do nothing instead. */
80 if (game.loc != 1 || game.abbrev[1] != 1) {
81 rspeak(RESUME_ABANDON);
82 if (!YES(arbitrary_messages[THIS_ACCEPTABLE], arbitrary_messages[OK_MAN], arbitrary_messages[OK_MAN])) return GO_CLEAROBJ;
86 char* name = linenoise("\nFile name: ");
89 fp = fopen(name, READ_MODE);
91 printf("Can't open file %s, try again.\n", name);
100 /* Read and restore game state from file, assuming
101 * sane initial state.
102 * If ADVENT_NOSAVE is defined, do nothing instead. */
107 IGNORE(fread(&save, sizeof(struct save_t), 1, fp));
109 if (save.version != VRSION) {
110 rspeak(VERSION_SKEW, save.version / 10, MOD(save.version, 10), VRSION / 10, MOD(VRSION, 10));
112 memcpy(&game, &save.game, sizeof(struct game_t));
113 game.zzword = RNDVOC(3, game.zzword);