6 #include "linenoise/linenoise.h"
9 * (ESR) This replaces a bunch of particularly nasty FORTRAN-derived code;
10 * see the history.adoc file in the source distribution for discussion.
13 #define VRSION 26 /* bump on save format change */
16 * If you change the first three members, the resume function may not properly
17 * reject saves from older versions. Yes, this glues us to a hardware-
18 * dependent length of long. Later members can change, but bump the version
23 long mode; /* not used, must be present for version detection */
29 int savefile(FILE *fp, long version)
30 /* Save game to file. No input or output from user. */
38 save.version = (version == 0) ? VRSION : version;
40 memcpy(&save.game, &game, sizeof(struct game_t));
41 IGNORE(fwrite(&save, sizeof(struct save_t), 1, fp));
45 /* Suspend and resume */
48 /* Suspend. Offer to save things in a file, but charging
49 * some points (so can't win by using saved games to retry
50 * battles or to start over after learning zzword).
51 * If ADVENT_NOSAVE is defined, do nothing instead. */
58 rspeak(SUSPEND_WARNING);
59 if (!yes(arbitrary_messages[THIS_ACCEPTABLE], arbitrary_messages[OK_MAN], arbitrary_messages[OK_MAN]))
61 game.saved = game.saved + 5;
64 char* name = linenoise("\nFile name: ");
67 fp = fopen(name, WRITE_MODE);
69 printf("Can't open file %s, try again.\n", name);
81 /* Resume. Read a suspended game back from a file.
82 * If ADVENT_NOSAVE is defined, do nothing instead. */
89 if (game.loc != 1 || game.abbrev[1] != 1) {
90 rspeak(RESUME_ABANDON);
91 if (!yes(arbitrary_messages[THIS_ACCEPTABLE], arbitrary_messages[OK_MAN], arbitrary_messages[OK_MAN]))
96 char* name = linenoise("\nFile name: ");
99 fp = fopen(name, READ_MODE);
101 printf("Can't open file %s, try again.\n", name);
108 int restore(FILE* fp)
110 /* Read and restore game state from file, assuming
111 * sane initial state.
112 * If ADVENT_NOSAVE is defined, do nothing instead. */
117 IGNORE(fread(&save, sizeof(struct save_t), 1, fp));
119 if (save.version != VRSION) {
120 rspeak(VERSION_SKEW, save.version / 10, MOD(save.version, 10), VRSION / 10, MOD(VRSION, 10));
122 memcpy(&game, &save.game, sizeof(struct game_t));
123 //game.zzword = rndvoc(3, game.zzword);
124 make_zzword(game.zzword);