Fix up copyright notices. SPDX wants only one per file.
[open-adventure.git] / saveresume.c
index c6d0ba0f274d3e73271e92b171a95521caf96694..0d1fbf445cea13fd90efb6b98a965b2366dfc05d 100644 (file)
@@ -4,8 +4,7 @@
  * (ESR) This replaces  a bunch of particularly nasty FORTRAN-derived code;
  * see the history.adoc file in the source distribution for discussion.
  *
- * SPDX-FileCopyrightText: 1977, 2005 by Will Crowther and Don Woods
- * SPDX-FileCopyrightText: 2017 by Eric S. Raymond
+ * SPDX-FileCopyrightText: Copyright 1977, 2005 by Will Crowther and Don Woods, Copyright 2017 by Eric S. Raymond
  * SPDX-License-Identifier: BSD-2-Clause
  */
 
 #include <inttypes.h>
 
 #include "advent.h"
-#include "dungeon.h"
 
 /*
- * Use this to detect endianness mismatch.  Can't be unchanges by byte-swapping.
+ * Use this to detect endianness mismatch.  Can't be unchanged by byte-swapping.
  */
 #define ENDIAN_MAGIC   2317
 
@@ -109,7 +107,7 @@ int resume(void)
 #endif
     FILE *fp = NULL;
 
-    if (game.loc != LOC_START || game.abbrev[LOC_START] != 1) {
+    if (game.loc != LOC_START || game.locs[LOC_START].abbrev != 1) {
         rspeak(RESUME_ABANDON);
         if (!yes_or_no(arbitrary_messages[THIS_ACCEPTABLE], arbitrary_messages[OK_MAN], arbitrary_messages[OK_MAN]))
             return GO_CLEAROBJ;
@@ -137,7 +135,7 @@ int restore(FILE* fp)
      *  sane initial state.
      *  If ADVENT_NOSAVE is defined, gripe instead. */
 #ifdef ADVENT_NOSAVE
-    rspeak(SAVERESUME_DISABLED)
+    rspeak(SAVERESUME_DISABLED);
     return GO_TOP;
 #endif
 
@@ -190,15 +188,15 @@ bool is_valid(struct game_t valgame)
     }
     /*  Bounds check for location arrays */
     for (int i = 0; i <= NDWARVES; i++) {
-        if (valgame.dloc[i]  < -1 || valgame.dloc[i]  > NLOCATIONS  ||
-            valgame.odloc[i] < -1 || valgame.odloc[i] > NLOCATIONS) {
+        if (valgame.dwarves[i].loc  < -1 || valgame.dwarves[i].loc  > NLOCATIONS  ||
+            valgame.dwarves[i].oldloc < -1 || valgame.dwarves[i].oldloc > NLOCATIONS) {
             return false;      // LCOV_EXCL_LINE
         }
     }
 
     for (int i = 0; i <= NOBJECTS; i++) {
-        if (valgame.place[i] < -1 || valgame.place[i] > NLOCATIONS  ||
-            valgame.fixed[i] < -1 || valgame.fixed[i] > NLOCATIONS) {
+        if (valgame.objects[i].place < -1 || valgame.objects[i].place > NLOCATIONS  ||
+            valgame.objects[i].fixed < -1 || valgame.objects[i].fixed > NLOCATIONS) {
             return false;      // LCOV_EXCL_LINE
         }
     }
@@ -218,7 +216,7 @@ bool is_valid(struct game_t valgame)
     int temp_tally = 0;
     for (int treasure = 1; treasure <= NOBJECTS; treasure++) {
         if (objects[treasure].is_treasure) {
-            if (valgame.prop[treasure] == STATE_NOTFOUND) {
+            if (PROP_IS_NOTFOUND2(valgame, treasure)) {
                 ++temp_tally;
             }
         }
@@ -229,36 +227,14 @@ bool is_valid(struct game_t valgame)
 
     /* Check that properties of objects aren't beyond expected */
     for (obj_t obj = 0; obj <= NOBJECTS; obj++) {
-       /* Magic number -2 allows a STASHED version of state 1 */
-        if (valgame.prop[obj] < -2 || valgame.prop[obj] > 1) {
-            switch (obj) {
-            case RUG:
-            case DRAGON:
-            case BIRD:
-            case BOTTLE:
-            case PLANT:
-            case PLANT2:
-            case TROLL:
-            case URN:
-            case EGGS:
-            case VASE:
-            case CHAIN:
-                if (valgame.prop[obj] == 2) // There are multiple different states, but it's convenient to clump them together
-                    continue;  // LCOV_EXCL_LINE
-            /* FALLTHRU */
-            case BEAR:
-                if (valgame.prop[BEAR] == CONTENTED_BEAR || valgame.prop[BEAR] == BEAR_DEAD)
-                    continue;
-            /* FALLTHRU */
-            default:
-                return false;  // LCOV_EXCL_LINE
-            }
+        if (PROP_IS_INVALID(valgame.objects[obj].prop)) {
+           return false;       // LCOV_EXCL_LINE
         }
     }
 
     /* Check that values in linked lists for objects in locations are inside bounds */
     for (loc_t loc = LOC_NOWHERE; loc <= NLOCATIONS; loc++) {
-        if (valgame.atloc[loc] < NO_OBJECT || valgame.atloc[loc] > NOBJECTS * 2) {
+        if (valgame.locs[loc].atloc < NO_OBJECT || valgame.locs[loc].atloc > NOBJECTS * 2) {
             return false;      // LCOV_EXCL_LINE
         }
     }