Replace some spaces with tabs per the database spec.
[open-adventure.git] / main.c
diff --git a/main.c b/main.c
index 42fa5e1123b389c90e72033d31b849da7b593732..0e934ba81e90a12c6e68471489ce0de93913e150 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1,7 +1,16 @@
 /*
+ * There used to be a note that said this:
+ *
  * The author - Don Woods - apologises for the style of the code; it
  * is a result of running the original Fortran IV source through a
  * home-brew Fortran-to-C converter.)
+ *
+ * Now that the code has been restructured into idiomatic C, the following
+ * is more appropriate:
+ *
+ * ESR apologizes for the remaing gotos (now confined to two functions in this
+ * file - they used to be *everywhere*), and the offensive globals.  Applying
+ * the Structured Program Theorem can be hard.
  */
 #include <stdlib.h>
 #include <stdio.h>
@@ -476,7 +485,7 @@ static void croak(FILE *cmdin)
  *  "K", put the new location in "game.newloc".  The current loc is saved
  *  in "game.oldloc" in case he wants to retreat.  The current
  *  game.oldloc is saved in game.oldlc2, in case he dies.  (if he
- *  does, game.newloc will be limbo, and OLgame.dloc will be what killed
+ *  does, game.newloc will be limbo, and game.oldloc will be what killed
  *  him, so we need game.oldlc2, which is the last place he was
  *  safe.) */
 
@@ -488,7 +497,7 @@ static bool playermove(FILE *cmdin, token_t verb)
        BUG(26);
     if (K == NUL)
        return true;
-    if (K == BACK) {
+    else if (K == BACK) {
        /*  Handle "go back".  Look for verb which goes from game.loc to
         *  game.oldloc, or to game.oldlc2 If game.oldloc has forced-motion.
         *  K2 saves entry -> forced loc -> previous loc. */
@@ -501,32 +510,34 @@ static bool playermove(FILE *cmdin, token_t verb)
        if (K == game.loc)K2=91;
        if (CNDBIT(game.loc,4))K2=274;
        if (K2 == 0) {
-       L21:
-           LL=MOD((labs(TRAVEL[KK])/1000),1000);
-           if (LL != K) {
-               if (LL <= 300) {
-                   if (FORCED(LL) && MOD((labs(TRAVEL[KEY[LL]])/1000),1000) == K)
-                       K2=KK;
-               }
-               if (TRAVEL[KK] >= 0) {
-                   ++KK;
-                   goto L21;
-               }
-               KK=K2;
-               if (KK == 0) {
-                   RSPEAK(140);
-                   return true;
+           for (;;) {
+               LL=MOD((labs(TRAVEL[KK])/1000),1000);
+               if (LL != K) {
+                   if (LL <= 300) {
+                       if (FORCED(LL) && MOD((labs(TRAVEL[KEY[LL]])/1000),1000) == K)
+                           K2=KK;
+                   }
+                   if (TRAVEL[KK] >= 0) {
+                       ++KK;
+                       continue;
+                   }
+                   KK=K2;
+                   if (KK == 0) {
+                       RSPEAK(140);
+                       return true;
+                   }
                }
-           }
 
-           K=MOD(labs(TRAVEL[KK]),1000);
-           KK=KEY[game.loc];
-           goto L9;
+               K=MOD(labs(TRAVEL[KK]),1000);
+               KK=KEY[game.loc];
+               break; /* fall through to ordinary travel */
+           }
+       } else {
+           RSPEAK(K2);
+           return true;
        }
-       RSPEAK(K2);
-       return true;
     }
-    if (K == LOOK) {
+    else if (K == LOOK) {
        /*  Look.  Can't give more detail.  Pretend it wasn't dark
         *  (though it may "now" be dark) so he won't fall into a
         *  pit while staring into the gloom. */
@@ -536,15 +547,18 @@ static bool playermove(FILE *cmdin, token_t verb)
        game.abbrev[game.loc]=0;
        return true;
     }
-    if (K == CAVE) {
+    else if (K == CAVE) {
        /*  Cave.  Different messages depending on whether above ground. */
        RSPEAK((OUTSID(game.loc) && game.loc != 8) ? 57 : 58);
        return true;
     }
-    game.oldlc2=game.oldloc;
-    game.oldloc=game.loc;
+    else {
+       /* none of the specials */
+       game.oldlc2=game.oldloc;
+       game.oldloc=game.loc;
+    }
 
-L9:
+    /* ordinary travel */
     for (;;) {
        LL=labs(TRAVEL[KK]);
        if (MOD(LL,1000) == 1 || MOD(LL,1000) == K)