2 * 'cheat' is a tool for generating save game files to test states that ought
3 * not happen. It leverages chunks of advent, mostly initialize() and
4 * savefile(), so we know we're always outputing save files that advent
13 int main(int argc, char *argv[])
16 char *savefilename = NULL;
20 // Initialize game variables
23 /* we're generating a saved game, so saved once by default,
24 * unless overridden with command-line options below.
29 const char* opts = "d:l:s:t:v:o:";
30 const char* usage = "Usage: %s [-d numdie] [-s numsaves] [-v version] -o savefilename \n"
31 " -d number of deaths. Signed integer.\n"
32 " -l lifetime of lamp in turns. Signed integer.\n"
33 " -s number of saves. Signed integer.\n"
34 " -t number of turns. Signed integer.\n"
35 " -v version number of save format.\n"
36 " -o required. File name of save game to write.\n";
38 while ((ch = getopt(argc, argv, opts)) != EOF) {
41 game.numdie = (long)atoi(optarg);
42 printf("cheat: game.numdie = %ld\n", game.numdie);
45 game.limit = (long)atoi(optarg);
46 printf("cheat: game.limit = %ld\n", game.limit);
49 game.saved = (long)atoi(optarg);
50 printf("cheat: game.saved = %ld\n", game.saved);
53 game.turns = (long)atoi(optarg);
54 printf("cheat: game.turns = %ld\n", game.turns);
57 version = (long)atoi(optarg);
58 printf("cheat: version = %ld\n", version);
61 savefilename = optarg;
71 // Save filename required; the point of cheat is to generate save file
72 if (savefilename == NULL) {
76 "ERROR: filename required\n");
80 fp = fopen(savefilename, WRITE_MODE);
83 "Can't open file %s. Exiting.\n", savefilename);
87 savefile(fp, version);
91 printf("cheat: %s created.\n", savefilename);