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)
38 /* Suspend. Offer to save things in a file, but charging
39 * some points (so can't win by using saved games to retry
40 * battles or to start over after learning zzword). */
41 RSPEAK(SUSPEND_WARNING);
42 if (!YES(input,THIS_ACCEPTABLE,OK_MAN,OK_MAN)) return GO_CLEAROBJ;
43 game.saved=game.saved+5;
46 char* name = linenoise("\nFile name: ");
49 fp = fopen(name, WRITE_MODE);
51 printf("Can't open file %s, try again.\n", name);
59 save.version = VRSION;
60 memcpy(&save.game, &game, sizeof(struct game_t));
61 save.bird = OBJSND[BIRD];
62 save.bivalve = OBJTXT[OYSTER];
63 IGNORE(fwrite(&save, sizeof(struct save_t), 1, fp));
69 int resume(FILE *input)
73 /* Resume. Read a suspended game back from a file. */
74 if (game.loc != 1 || game.abbrev[1] != 1) {
75 RSPEAK(RESUME_ABANDON);
76 if (!YES(input,THIS_ACCEPTABLE,OK_MAN,OK_MAN)) return GO_CLEAROBJ;
80 char* name = linenoise("\nFile name: ");
83 fp = fopen(name, READ_MODE);
85 printf("Can't open file %s, try again.\n", name);
92 int restore(FILE* fp){
93 IGNORE(fread(&save, sizeof(struct save_t), 1, fp));
95 if (save.version != VRSION) {
96 SETPRM(1,save.version/10,MOD(save.version,10));
97 SETPRM(3,VRSION/10,MOD(VRSION,10));
100 memcpy(&game, &save.game, sizeof(struct game_t));
101 OBJSND[BIRD] = save.bird;
102 OBJTXT[OYSTER] = save.bivalve;
103 game.zzword=RNDVOC(3,game.zzword);