Localize scope for restore file pointer in main.
[open-adventure.git] / main.c
diff --git a/main.c b/main.c
index 4531be72cb9f2ec82780e34809b3605002248173..345a7b23343daa4d55b5ab96bdf43036498c612d 100644 (file)
--- a/main.c
+++ b/main.c
@@ -25,7 +25,7 @@
 
 #define DIM(a) (sizeof(a)/sizeof(a[0]))
 
-FILE  *logfp = NULL, *rfp = NULL;
+FILE *logfp = NULL;
 bool oldstyle = false;
 bool prompt = true;
 
@@ -61,8 +61,9 @@ int main(int argc, char *argv[])
     /*  Options. */
 
 #ifndef ADVENT_NOSAVE
-    const char* opts = "l:or";
+    const char* opts = "l:or:";
     const char* usage = "Usage: %s [-l logfilename] [-o] [-r restorefilename]\n";
+    FILE *rfp = NULL;
 #else
     const char* opts = "l:o";
     const char* usage = "Usage: %s [-l logfilename] [-o]\n";
@@ -110,9 +111,6 @@ int main(int argc, char *argv[])
     /*  Initialize game variables */
     long seedval = initialise();
 
-    /*  Start-up, dwarf stuff */
-    make_zzword(game.zzword);
-
 #ifndef ADVENT_NOSAVE
     if (!rfp) {
         game.novice = yes(arbitrary_messages[WELCOME_YOU], arbitrary_messages[CAVE_NEARBY], arbitrary_messages[NO_MESSAGE]);
@@ -144,8 +142,6 @@ static bool fallback_handler(char *buf)
         printf("Seed set to %ld\n", sv);
         // autogenerated, so don't charge user time for it.
         --game.turns;
-        // here we reconfigure any global game state that uses random numbers
-        make_zzword(game.zzword);
         return true;
     }
     return false;
@@ -381,21 +377,27 @@ static bool dwarfmove(void)
             do {
                 game.newloc = travel[kk].dest;
                 /* Have we avoided a dwarf encounter? */
-                bool avoided = (SPECIAL(game.newloc) ||
-                                !INDEEP(game.newloc) ||
-                                game.newloc == game.odloc[i] ||
-                                (j > 1 && game.newloc == tk[j - 1]) ||
-                                j >= DIM(tk) - 1 ||
-                                game.newloc == game.dloc[i] ||
-                                FORCED(game.newloc) ||
-                                (i == PIRATE && CNDBIT(game.newloc, COND_NOARRR)) ||
-                                travel[kk].nodwarves);
-                if (!avoided) {
-                    tk[j++] = game.newloc;
-                }
-                ++kk;
+                if (SPECIAL(game.newloc))
+                   continue;
+                else if (!INDEEP(game.newloc))
+                   continue;
+               else if (game.newloc == game.odloc[i])
+                   continue;
+                else if (j > 1 && game.newloc == tk[j - 1])
+                   continue;
+               else if (j >= DIM(tk) - 1)
+                   continue;
+               else if (game.newloc == game.dloc[i])
+                   continue;
+               else if (FORCED(game.newloc))
+                   continue;
+               else if (i == PIRATE && CNDBIT(game.newloc, COND_NOARRR))
+                   continue;
+               else if (travel[kk].nodwarves)
+                   continue;
+               tk[j++] = game.newloc;
             } while
-            (!travel[kk - 1].stop);
+               (!travel[kk++].stop);
         tk[j] = game.odloc[i];
         if (j >= 2)
             --j;