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 */
32 /* Suspend and resume */
33 int suspend(FILE *input)
34 { /* Suspend. Offer to save things in a file, but charging
35 * some points (so can't win by using saved games to retry
36 * battles or to start over after learning zzword).
37 * If ADVENT_NOSAVE is defined, do nothing instead. */
45 RSPEAK(SUSPEND_WARNING);
46 if (!YES(input,THIS_ACCEPTABLE,OK_MAN,OK_MAN)) return GO_CLEAROBJ;
47 game.saved=game.saved+5;
50 char* name = linenoise("\nFile name: ");
53 fp = fopen(name, WRITE_MODE);
55 printf("Can't open file %s, try again.\n", name);
63 save.version = VRSION;
64 memcpy(&save.game, &game, sizeof(struct game_t));
65 save.bird = OBJSND[BIRD];
66 save.bivalve = OBJTXT[OYSTER];
67 IGNORE(fwrite(&save, sizeof(struct save_t), 1, fp));
73 int resume(FILE *input)
74 { /* Resume. Read a suspended game back from a file.
75 * If ADVENT_NOSAVE is defined, do nothing instead. */
82 if (game.loc != 1 || game.abbrev[1] != 1) {
83 RSPEAK(RESUME_ABANDON);
84 if (!YES(input,THIS_ACCEPTABLE,OK_MAN,OK_MAN)) return GO_CLEAROBJ;
88 char* name = linenoise("\nFile name: ");
91 fp = fopen(name, READ_MODE);
93 printf("Can't open file %s, try again.\n", name);
100 int restore(FILE* fp)
101 { /* Read and restore game state from file, assuming
102 * sane initial state.
103 * If ADVENT_NOSAVE is defined, do nothing instead. */
108 IGNORE(fread(&save, sizeof(struct save_t), 1, fp));
110 if (save.version != VRSION) {
111 SETPRM(1,save.version/10,MOD(save.version,10));
112 SETPRM(3,VRSION/10,MOD(VRSION,10));
113 RSPEAK(VERSION_SKEW);
115 memcpy(&game, &save.game, sizeof(struct game_t));
116 OBJSND[BIRD] = save.bird;
117 OBJTXT[OYSTER] = save.bivalve;
118 game.zzword=RNDVOC(3,game.zzword);