#include <string.h>
#include "advent.h"
-#include "database.h"
-#include "newdb.h"
+#include "dungeon.h"
#include "linenoise/linenoise.h"
/*
};
struct save_t save;
+#define IGNORE(r) do{if (r){}}while(0)
+
+int savefile(FILE *fp, long version)
+/* Save game to file. No input or output from user. */
+{
+ long i, k;
+ datime(&i, &k);
+ k = i + 650 * k;
+ save.savetime = k;
+ save.mode = -1;
+
+ save.version = (version == 0) ? VRSION : version;
+
+ memcpy(&save.game, &game, sizeof(struct game_t));
+ IGNORE(fwrite(&save, sizeof(struct save_t), 1, fp));
+ return (0);
+}
+
/* Suspend and resume */
int suspend(void)
{
#ifdef ADVENT_NOSAVE
return GO_UNKNOWN;
#endif
- long i, k;
FILE *fp = NULL;
rspeak(SUSPEND_WARNING);
- if (!yes(arbitrary_messages[THIS_ACCEPTABLE], arbitrary_messages[OK_MAN], arbitrary_messages[OK_MAN])) return GO_CLEAROBJ;
+ if (!yes(arbitrary_messages[THIS_ACCEPTABLE], arbitrary_messages[OK_MAN], arbitrary_messages[OK_MAN]))
+ return GO_CLEAROBJ;
game.saved = game.saved + 5;
while (fp == NULL) {
linenoiseFree(name);
}
- datime(&i, &k);
- k = i + 650 * k;
- save.savetime = k;
- save.mode = -1;
- save.version = VRSION;
- memcpy(&save.game, &game, sizeof(struct game_t));
- IGNORE(fwrite(&save, sizeof(struct save_t), 1, fp));
+ savefile(fp, VRSION);
fclose(fp);
rspeak(RESUME_HELP);
- exit(0);
+ exit(EXIT_SUCCESS);
}
int resume(void)
if (game.loc != 1 || game.abbrev[1] != 1) {
rspeak(RESUME_ABANDON);
- if (!yes(arbitrary_messages[THIS_ACCEPTABLE], arbitrary_messages[OK_MAN], arbitrary_messages[OK_MAN])) return GO_CLEAROBJ;
+ if (!yes(arbitrary_messages[THIS_ACCEPTABLE], arbitrary_messages[OK_MAN], arbitrary_messages[OK_MAN]))
+ return GO_CLEAROBJ;
}
while (fp == NULL) {
rspeak(VERSION_SKEW, save.version / 10, MOD(save.version, 10), VRSION / 10, MOD(VRSION, 10));
} else {
memcpy(&game, &save.game, sizeof(struct game_t));
- game.zzword = rndvoc(3, game.zzword);
+ //game.zzword = rndvoc(3, game.zzword);
+ make_zzword(game.zzword);
}
return GO_TOP;
}