Structurize locatiuon info.
[open-adventure.git] / advent.h
index faf298e04af52eee8aed786dbfcecd0b56c235b1..8150aa25accacfca6526ddcb41303f610f0e5f99 100644 (file)
--- a/advent.h
+++ b/advent.h
@@ -167,7 +167,7 @@ struct game_t {
     int holdng;                  // number of objects being carried
     int igo;                     // # uses of "go" instead of a direction
     int iwest;                   // # times he's said "west" instead of "w"
-    int knfloc;                  // knife location; 0 if none, -1 after caveat
+    loc_t knfloc;                // knife location; LOC_NOWERE if none, -1 after caveat
     turn_t limit;                // lifetime of lamp
     loc_t loc;                   // where player is now
     loc_t newloc;                // where player is going
@@ -178,20 +178,24 @@ struct game_t {
     int saved;                   // point penalty for saves
     int tally;                   // count of treasures gained
     int thresh;                  // current threshold for endgame scoring tier
-    bool seenbigwords;           // have we red the grafitti in the Giant's Room? 
+    bool seenbigwords;           // have we red the graffiti in the Giant's Room? 
     turn_t trnluz;               // # points lost so far due to turns used
     turn_t turns;                // counts commands given (ignores yes/no)
     char zzword[TOKLEN + 1];     // randomly generated magic word from bird
-    int abbrev[NLOCATIONS + 1];  // has location been seen?
-    int atloc[NLOCATIONS + 1];   // head of object linked list per location
-    int dseen[NDWARVES + 1];     // true if dwarf has seen him
-    loc_t dloc[NDWARVES + 1];    // location of dwarves, initially hard-wired in
-    loc_t odloc[NDWARVES + 1];   // prior loc of each dwarf, initially garbage
+    struct {
+       int abbrev;              // has location been seen?
+       int atloc;               // head of object linked list per location
+    } locs[NLOCATIONS + 1];
+    struct {
+       int seen;                // true if dwarf has seen him
+       loc_t loc;               // location of dwarves, initially hard-wired in
+       loc_t oldloc;            // prior loc of each dwarf, initially garbage
+    } dwarves[NDWARVES + 1];
     loc_t fixed[NOBJECTS + 1];   // fixed location of object (if  not IS_FREE)
     obj_t link[NOBJECTS * 2 + 1];// object-list links
     loc_t place[NOBJECTS + 1];   // location of object
-    int hinted[NHINTS];          // hinted[i] = true iff hint i has been used.
-    int hintlc[NHINTS];          // hintlc[i] = how int at LOC with cond bit i
+    bool hinted[NHINTS];         // hinted[i] = true iff hint i has been used.
+    int hintlc[NHINTS];          // hintlc[i] = show int at LOC with cond bit i
     int prop[NOBJECTS + 1];      // object state array */
 };
 
@@ -233,7 +237,12 @@ typedef struct {
  * files afterwards.  Otherwise you will get a spurious failure due to the old version
  * having been generated into a check file.
  */
-#define SAVE_VERSION   29
+#define SAVE_VERSION   30
+
+/*
+ * Goes at start of file so saves can be identified by file(1) and the like.
+ */
+#define ADVENT_MAGIC   "open-adventure\n"
 
 /*
  * If you change the first three members, the resume function may not properly
@@ -241,9 +250,9 @@ typedef struct {
  * when you do that.
  */
 struct save_t {
-    int64_t savetime;
-    int32_t mode;              /* not used, must be present for version detection */
+    char magic[sizeof(ADVENT_MAGIC)];
     int32_t version;
+    int32_t canary;
     struct game_t game;
 };
 
@@ -273,7 +282,7 @@ extern void set_seed(int32_t);
 extern int32_t randrange(int32_t);
 extern int score(enum termination);
 extern void terminate(enum termination) __attribute__((noreturn));
-extern int savefile(FILE *, int32_t);
+extern int savefile(FILE *);
 #if defined ADVENT_AUTOSAVE
 extern void autosave(void);
 #endif