Structurize the informaruin about dwarves.
authorEric S. Raymond <esr@thyrsus.com>
Fri, 7 Apr 2023 13:15:20 +0000 (09:15 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Fri, 7 Apr 2023 13:15:20 +0000 (09:15 -0400)
actions.c
advent.h
init.c
main.c
misc.c
saveresume.c

index d8b1546b3a55ea61190a45674fa88702af2edf2a..06149d3574a06aee97fa237cda54885ddbcfe8ee 100644 (file)
--- a/actions.c
+++ b/actions.c
@@ -145,10 +145,10 @@ static phase_codes_t attack(command_t command)
         DESTROY(OGRE);
         int dwarves = 0;
         for (int i = 1; i < PIRATE; i++) {
-            if (game.dloc[i] == game.loc) {
+            if (game.dwarves[i].loc == game.loc) {
                 ++dwarves;
-                game.dloc[i] = LOC_LONGWEST;
-                game.dseen[i] = false;
+                game.dwarves[i].loc = LOC_LONGWEST;
+                game.dwarves[i].seen = false;
             }
         }
         rspeak((dwarves > 1) ?
@@ -1245,8 +1245,8 @@ static phase_codes_t throwit(command_t command)
             return throw_support(DWARF_DODGES);
         } else {
             int i = atdwrf(game.loc);
-            game.dseen[i] = false;
-            game.dloc[i] = LOC_NOWHERE;
+            game.dwarves[i].seen = false;
+            game.dwarves[i].loc = LOC_NOWHERE;
             return throw_support((++game.dkill == 1) ?
                                  DWARF_SMOKE :
                                  KILLED_DWARF);
index c1d3132a6b243a44648743c1963058ae68ffb62b..56dcbe5fe0a29257d80a7f83cdbaa73e19d803ce 100644 (file)
--- a/advent.h
+++ b/advent.h
@@ -184,9 +184,11 @@ struct game_t {
     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 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
diff --git a/init.c b/init.c
index 202bf65759835fb082158e935842acf6a08aee2f..b84f5fcf9b14cf97144787d48712ba50da50ae19 100644 (file)
--- a/init.c
+++ b/init.c
@@ -21,17 +21,17 @@ struct settings_t settings = {
 };
 
 struct game_t game = {
-    .dloc[1] = LOC_KINGHALL,
-    .dloc[2] = LOC_WESTBANK,
-    .dloc[3] = LOC_Y2,
-    .dloc[4] = LOC_ALIKE3,
-    .dloc[5] = LOC_COMPLEX,
+    .dwarves[1].loc = LOC_KINGHALL,
+    .dwarves[2].loc = LOC_WESTBANK,
+    .dwarves[3].loc = LOC_Y2,
+    .dwarves[4].loc = LOC_ALIKE3,
+    .dwarves[5].loc = LOC_COMPLEX,
 
     /*  Sixth dwarf is special (the pirate).  He always starts at his
      *  chest's eventual location inside the maze. This loc is saved
      *  in chloc for ref. The dead end in the other maze has its
      *  loc stored in chloc2. */
-    .dloc[6] = LOC_MAZEEND12,
+    .dwarves[6].loc = LOC_MAZEEND12,
     .chloc   = LOC_MAZEEND12,
     .chloc2  = LOC_DEADEND13,
     .abbnum  = 5,
diff --git a/main.c b/main.c
index e3e6a96dc29f3e4ea87a5f0636972cf2887cddb7..3d17ec9c160b1a775eed7a777947f72086aef555 100644 (file)
--- a/main.c
+++ b/main.c
@@ -229,13 +229,13 @@ static bool spotted_by_pirate(int i)
     if (movechest) {
         move(CHEST, game.chloc);
         move(MESSAG, game.chloc2);
-        game.dloc[PIRATE] = game.chloc;
-        game.odloc[PIRATE] = game.chloc;
-        game.dseen[PIRATE] = false;
+        game.dwarves[PIRATE].loc = game.chloc;
+        game.dwarves[PIRATE].oldloc = game.chloc;
+        game.dwarves[PIRATE].seen = false;
     } else {
         /* You might get a hint of the pirate's presence even if the
          * chest doesn't move... */
-        if (game.odloc[PIRATE] != game.dloc[PIRATE] && PCT(20))
+        if (game.dwarves[PIRATE].oldloc != game.dwarves[PIRATE].loc && PCT(20))
             rspeak(PIRATE_RUSTLES);
     }
     if (robplayer) {
@@ -295,15 +295,15 @@ static bool dwarfmove(void)
         for (int i = 1; i <= 2; i++) {
             int j = 1 + randrange(NDWARVES - 1);
             if (PCT(50))
-                game.dloc[j] = 0;
+                game.dwarves[j].loc = 0;
         }
 
         /* Alternate initial loc for dwarf, in case one of them
         *  starts out on top of the adventurer. */
         for (int i = 1; i <= NDWARVES - 1; i++) {
-            if (game.dloc[i] == game.loc)
-                game.dloc[i] = DALTLC; //
-            game.odloc[i] = game.dloc[i];
+            if (game.dwarves[i].loc == game.loc)
+                game.dwarves[i].loc = DALTLC; //
+            game.dwarves[i].oldloc = game.dwarves[i].loc;
         }
         rspeak(DWARF_RAN);
         drop(AXE, game.loc);
@@ -320,11 +320,11 @@ static bool dwarfmove(void)
     attack = 0;
     stick = 0;
     for (int i = 1; i <= NDWARVES; i++) {
-        if (game.dloc[i] == 0)
+        if (game.dwarves[i].loc == 0)
             continue;
         /*  Fill tk array with all the places this dwarf might go. */
         unsigned int j = 1;
-        kk = tkey[game.dloc[i]];
+        kk = tkey[game.dwarves[i].loc];
         if (kk != 0)
             do {
                 enum desttype_t desttype = travel[kk].desttype;
@@ -334,14 +334,14 @@ static bool dwarfmove(void)
                     continue;
                 else if (!INDEEP(game.newloc))
                     continue;
-                else if (game.newloc == game.odloc[i])
+                else if (game.newloc == game.dwarves[i].oldloc)
                     continue;
                 else if (j > 1 && game.newloc == tk[j - 1])
                     continue;
                 else if (j >= DIM(tk) - 1)
                     /* This can't actually happen. */
                     continue; // LCOV_EXCL_LINE
-                else if (game.newloc == game.dloc[i])
+                else if (game.newloc == game.dwarves[i].loc)
                     continue;
                 else if (FORCED(game.newloc))
                     continue;
@@ -352,23 +352,23 @@ static bool dwarfmove(void)
                 tk[j++] = game.newloc;
             } while
             (!travel[kk++].stop);
-        tk[j] = game.odloc[i];
+        tk[j] = game.dwarves[i].oldloc;
         if (j >= 2)
             --j;
         j = 1 + randrange(j);
-        game.odloc[i] = game.dloc[i];
-        game.dloc[i] = tk[j];
-        game.dseen[i] = (game.dseen[i] && INDEEP(game.loc)) ||
-                        (game.dloc[i] == game.loc ||
-                         game.odloc[i] == game.loc);
-        if (!game.dseen[i])
+        game.dwarves[i].oldloc = game.dwarves[i].loc;
+        game.dwarves[i].loc = tk[j];
+        game.dwarves[i].seen = (game.dwarves[i].seen && INDEEP(game.loc)) ||
+                        (game.dwarves[i].loc == game.loc ||
+                         game.dwarves[i].oldloc == game.loc);
+        if (!game.dwarves[i].seen)
             continue;
-        game.dloc[i] = game.loc;
+        game.dwarves[i].loc = game.loc;
         if (spotted_by_pirate(i))
             continue;
         /* This threatening little dwarf is in the room with him! */
         ++game.dtotal;
-        if (game.odloc[i] == game.dloc[i]) {
+        if (game.dwarves[i].oldloc == game.dwarves[i].loc) {
             ++attack;
             if (game.knfloc >= LOC_NOWHERE)
                 game.knfloc = game.loc;
@@ -827,8 +827,8 @@ static bool closecheck(void)
         game.prop[GRATE] = GRATE_CLOSED;
         game.prop[FISSURE] = UNBRIDGED;
         for (int i = 1; i <= NDWARVES; i++) {
-            game.dseen[i] = false;
-            game.dloc[i] = LOC_NOWHERE;
+            game.dwarves[i].seen = false;
+            game.dwarves[i].loc = LOC_NOWHERE;
         }
         DESTROY(TROLL);
         move(TROLL + NOBJECTS, IS_FREE);
@@ -1044,7 +1044,7 @@ static bool do_move(void)
      *  place) let him get out (and attacked). */
     if (game.newloc != game.loc && !FORCED(game.loc) && !CNDBIT(game.loc, COND_NOARRR)) {
         for (size_t i = 1; i <= NDWARVES - 1; i++) {
-            if (game.odloc[i] == game.newloc && game.dseen[i]) {
+            if (game.dwarves[i].oldloc == game.newloc && game.dwarves[i].seen) {
                 game.newloc = game.loc;
                 rspeak(DWARF_BLOCK);
                 break;
diff --git a/misc.c b/misc.c
index 9971cb5eb18c92bb9bfcf4b38cfc78b8570d167f..9502c8b039228e1e8e5ac790d66dae43a6772812 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -672,9 +672,9 @@ int atdwrf(loc_t where)
         return at;
     at = -1;
     for (int i = 1; i <= NDWARVES - 1; i++) {
-        if (game.dloc[i] == where)
+        if (game.dwarves[i].loc == where)
             return i;
-        if (game.dloc[i] != 0)
+        if (game.dwarves[i].loc != 0)
             at = 0;
     }
     return at;
index f77925ab948649df9498957087d10cb217597e80..d66b52c928285b52bb88d12f41bebc8234054a1a 100644 (file)
@@ -190,8 +190,8 @@ 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
         }
     }