More goto elimination.
[open-adventure.git] / main.c
diff --git a/main.c b/main.c
index 8e40605cd4f0dd6d3773b1295ede8bdf789389e1..681ad8a3efce6687b125491c97dbdf4930fb71e1 100644 (file)
--- a/main.c
+++ b/main.c
@@ -581,34 +581,33 @@ static bool playermove(FILE *cmdin, token_t verb)
     }
     LL=LL/1000;
 
-L11:
-    game.newloc=LL/1000;
-    K=MOD(game.newloc,100);
-    if (game.newloc <= 300) {
-       if (game.newloc <= 100)
-           goto L14;
-       if (TOTING(K) || (game.newloc > 200 && AT(K)))
-           goto L16;
-       goto L12;
+    for (;;) {
+       game.newloc=LL/1000;
+       K=MOD(game.newloc,100);
+       if (game.newloc <= 300) {
+           if (game.newloc <= 100) {
+               if (game.newloc == 0 || PCT(game.newloc))
+                   break;
+               /* else fall through */
+           } if (TOTING(K) || (game.newloc > 200 && AT(K)))
+                 break;
+           /* else fall through */
+       }
+       else if (game.prop[K] != game.newloc/100-3)
+           break;
+    L12:
+       do {
+           if (TRAVEL[KK] < 0)BUG(25);
+           ++KK;
+           game.newloc=labs(TRAVEL[KK])/1000;
+       } while
+           (game.newloc == LL);
+       LL=game.newloc;
     }
-    if (game.prop[K] != game.newloc/100-3)
-       goto L16;
-L12:
-    do {
-       if (TRAVEL[KK] < 0)BUG(25);
-       ++KK;
-       game.newloc=labs(TRAVEL[KK])/1000;
-    } while
-        (game.newloc == LL);
-    LL=game.newloc;
-    goto L11;
 
-L14:
-    if (game.newloc != 0 && !PCT(game.newloc))
-       goto L12;
-L16:
     game.newloc=MOD(LL,1000);
-    if (game.newloc <= 300) return true;
+    if (game.newloc <= 300)
+       return true;
     if (game.newloc <= 500) {
        game.newloc=game.newloc-300;
        switch (game.newloc)
@@ -713,7 +712,7 @@ L2000:      if (game.loc == 0)
        KK=STEXT[game.loc];
        if (MOD(game.abbrev[game.loc],game.abbnum) == 0 || KK == 0)
            KK=LTEXT[game.loc];
-       if (!FORCED(game.loc) && DARK(0)) {
+       if (!FORCED(game.loc) && DARK(game.loc)) {
            /*  The easiest way to get killed is to fall into a pit in
             *  pitch darkness. */
            if (game.wzdark && PCT(35)) {
@@ -727,8 +726,9 @@ L2000:      if (game.loc == 0)
        if (TOTING(BEAR))RSPEAK(141);
        SPEAK(KK);
        K=1;
-       if (FORCED(game.loc))
+       if (FORCED(game.loc)) {
            goto L8;
+       }
        if (game.loc == 33 && PCT(25) && !game.closng)RSPEAK(7);
 
        /*  Print out descriptions of objects at this location.  If
@@ -739,7 +739,7 @@ L2000:      if (game.loc == 0)
         *  bear).  These hacks are because game.prop=0 is needed to
         *  get full score. */
 
-       if (DARK(0)) goto L2012;
+       if (DARK(game.loc)) goto L2012;
        ++game.abbrev[game.loc];
        i=game.atloc[game.loc];
 L2004: if (i == 0) goto L2012;
@@ -805,7 +805,7 @@ L2603:      if (game.closed) {
                    game.prop[i] = -1-game.prop[i];
            }
        }
-       game.wzdark=DARK(0);
+       game.wzdark=DARK(game.loc);
        if (game.knfloc > 0 && game.knfloc != game.loc)
            game.knfloc=0;
 
@@ -889,8 +889,7 @@ L2607:      game.foobar=(game.foobar>0 ? -game.foobar : 0);
            game.clock1= -1;
            game.closng=true;
            goto L19999;
-       }
-       if (game.clock1 < 0)
+       } else if (game.clock1 < 0)
            --game.clock2;
        if (game.clock2 == 0) {
            /*  Once he's panicked, and clock2 has run out, we come here
@@ -963,12 +962,13 @@ L2607:    game.foobar=(game.foobar>0 ? -game.foobar : 0);
            game.prop[LAMP]=0;
            if (HERE(LAMP))RSPEAK(184);
        } else if (game.limit <= 30) {
-           if (game.lmwarn || !HERE(LAMP)) goto L19999;
-           game.lmwarn=true;
-           SPK=187;
-           if (game.place[BATTER] == 0)SPK=183;
-           if (game.prop[BATTER] == 1)SPK=189;
-           RSPEAK(SPK);
+           if (!game.lmwarn && HERE(LAMP)) {
+               game.lmwarn=true;
+               SPK=187;
+               if (game.place[BATTER] == 0)SPK=183;
+               if (game.prop[BATTER] == 1)SPK=189;
+               RSPEAK(SPK);
+           }
        }
 L19999: K=43;
        if (LIQLOC(game.loc) == WATER)K=70;
@@ -1039,34 +1039,27 @@ Laction:
           case 2607: goto L2607;
           case 2630: goto L2630;
           case 2800: goto L2800;
-          case 8000: goto L8000;
-          case 18999: goto L18999;
-          case 19000: goto L19000;
+          case 8000:
+              /*  Random intransitive verbs come here.  Clear obj just in case
+               *  (see attack()). */
+              SETPRM(1,WD1,WD1X);
+              RSPEAK(257);
+              obj=0;
+              goto L2600;
+          case 18999:
+              /*  Oh dear, he's disturbed the dwarves. */
+               RSPEAK(SPK);
+              /* fall through */
+          case 19000:
+                RSPEAK(136);
+                score(0);
+                return true;
           }
        BUG(99);
 
-       /*  Random intransitive verbs come here.  Clear obj just in case
-        *  (see attack()). */
-L8000: SETPRM(1,WD1,WD1X);
-       RSPEAK(257);
-       obj=0;
-       goto L2600;
-
-
        /*  Figure out the new location */
 L8:    if (playermove(cmdin, VERB))
            return true;
        else
            goto L2000;
-
-/*  Cave closing and scoring */
-
-
-
-/*  Oh dear, he's disturbed the dwarves. */
-
-L18999: RSPEAK(SPK);
-L19000: RSPEAK(136);
-       score(0);
-       return true;
 }