Render the ascii<->advent character code mappings to lookup tables.
[open-adventure.git] / main.c
diff --git a/main.c b/main.c
index 835632af8830de7573f0352425fb5403633b4677..00b9ca0e5afcc4b04516200c4af2011bf6a4e15a 100644 (file)
--- a/main.c
+++ b/main.c
@@ -15,7 +15,7 @@
 struct game_t game;
 
 long LNLENG, LNPOSN, PARMS[MAXPARMS+1];
-char rawbuf[LINESIZE], INLINE[LINESIZE+1], MAP1[129], MAP2[129];
+char rawbuf[LINESIZE], INLINE[LINESIZE+1];
 
 long AMBER, AXE, BACK, BATTER, BEAR, BIRD, BLOOD,
                BOTTLE, CAGE, CAVE, CAVITY, CHAIN, CHASM, CHEST,
@@ -28,7 +28,7 @@ long AMBER, AXE, BACK, BATTER, BEAR, BIRD, BLOOD,
                RUBY, RUG, SAPPH, SAY, SIGN, SNAKE,
                STEPS, STREAM, THROW, TRIDNT, TROLL, TROLL2,
                URN, VASE, VEND, VOLCAN, WATER;
-long I, K, SPK, WD1, WD1X, WD2, WD2X;
+long K, SPK, WD1, WD1X, WD2, WD2X;
 
 FILE  *logfp;
 bool oldstyle = false;
@@ -68,7 +68,7 @@ int main(int argc, char *argv[])
 
     while ((ch = getopt(argc, argv, "l:o")) != EOF) {
        switch (ch) {
-       case 'l':
+case 'l':
            logfp = fopen(optarg, "w");
            if (logfp == NULL)
                fprintf(stderr,
@@ -102,7 +102,6 @@ int main(int argc, char *argv[])
     set_seed(seedval);
 
     /*  Initialize game variables */
-    MAP2[1] = 0;
     if (!game.setup)
        initialise();
 
@@ -292,6 +291,7 @@ static bool dwarfmove(void)
     attack=0;
     stick=0;
     for (int i=1; i<=NDWARVES; i++) {
+       int k;
        if(game.dloc[i] == 0)
            continue;
        /*  Fill TK array with all the places this dwarf might go. */
@@ -334,21 +334,41 @@ static bool dwarfmove(void)
             *  (game.prop=0). */
            if(game.loc == game.chloc || game.prop[CHEST] >= 0)
                continue;
-           K=0;
+           k=0;
            for (int j=MINTRS; j<=MAXTRS; j++) {
-               /*  Pirate won't take pyramid from plover room or dark
-               *  room (too easy!). */
-               if(j == PYRAM && (game.loc == PLAC[PYRAM] || game.loc == PLAC[EMRALD]))
-                   goto L6020;
+               /*  Pirate won't take pyramid from plover room or dark
+                *  room (too easy!). */
+               if(j == PYRAM && (game.loc == PLAC[PYRAM] || game.loc == PLAC[EMRALD])) {
+                   if(HERE(j))
+                       k=1;
+                   continue;
+               }
                if(TOTING(j)) {
-                   goto L6021;
+                   if(game.place[CHEST] == 0) {
+                       /*  Install chest only once, to insure it is
+                        *  the last treasure in the list. */
+                       MOVE(CHEST,game.chloc);
+                       MOVE(MESSAG,game.chloc2);
+                   }
+                   RSPEAK(128);
+                   for (int j=MINTRS; j<=MAXTRS; j++) {
+                       if (!(j == PYRAM && (game.loc == PLAC[PYRAM] || game.loc == PLAC[EMRALD]))) {
+                           if(AT(j) && game.fixed[j] == 0)
+                               CARRY(j,game.loc);
+                           if(TOTING(j))
+                               DROP(j,game.chloc);
+                       }
+                   }
+                   game.dloc[PIRATE]=game.chloc;
+                   game.odloc[PIRATE]=game.chloc;
+                   game.dseen[PIRATE]=false;
+                   goto jumpout;
                }
-           L6020:
                if(HERE(j))
-                   K=1;
+                   k=1;
            }
            /* Force chest placement before player finds last treasure */
-           if(game.tally == 1 && K == 0 && game.place[CHEST] == 0 && HERE(LAMP) && game.prop[LAMP] == 1) {
+           if(game.tally == 1 && k == 0 && game.place[CHEST] == 0 && HERE(LAMP) && game.prop[LAMP] == 1) {
                RSPEAK(186);
                MOVE(CHEST,game.chloc);
                MOVE(MESSAG,game.chloc2);
@@ -360,27 +380,6 @@ static bool dwarfmove(void)
            if(game.odloc[PIRATE] != game.dloc[PIRATE] && PCT(20))
                RSPEAK(127);
            continue;
-
-       L6021:
-           if(game.place[CHEST] == 0) {
-               /*  Install chest only once, to insure it is the last treasure in
-                *  the list. */
-               MOVE(CHEST,game.chloc);
-               MOVE(MESSAG,game.chloc2);
-           }
-           RSPEAK(128);
-           for (int j=MINTRS; j<=MAXTRS; j++) {
-               if (!(j == PYRAM && (game.loc == PLAC[PYRAM] || game.loc == PLAC[EMRALD]))) {
-                   if(AT(j) && game.fixed[j] == 0)
-                       CARRY(j,game.loc);
-                   if(TOTING(j))
-                       DROP(j,game.chloc);
-               }
-           }
-           game.dloc[PIRATE]=game.chloc;
-           game.odloc[PIRATE]=game.chloc;
-           game.dseen[PIRATE]=false;
-           continue;
        }
 
        /* This threatening little dwarf is in the room with him! */
@@ -392,6 +391,7 @@ static bool dwarfmove(void)
            if(randrange(1000) < 95*(game.dflag-2))
                ++stick;
        }
+    jumpout:;
     }
 
     /*  Now we know what's happening.  Let's tell the poor sucker about it.
@@ -505,9 +505,9 @@ L2001:      if(TOTING(BEAR))RSPEAK(141);
 
        if(DARK(0)) goto L2012;
        game.abbrev[game.loc]=game.abbrev[game.loc]+1;
-       I=game.atloc[game.loc];
-L2004: if(I == 0) goto L2012;
-       obj=I;
+       i=game.atloc[game.loc];
+L2004: if(i == 0) goto L2012;
+       obj=i;
        if(obj > NOBJECTS)obj=obj-NOBJECTS;
        if(obj == STEPS && TOTING(NUGGET)) goto L2008;
        if(game.prop[obj] >= 0) goto L2006;
@@ -529,7 +529,7 @@ L2004:      if(I == 0) goto L2012;
 L2006: KK=game.prop[obj];
        if(obj == STEPS && game.loc == game.fixed[STEPS])KK=1;
        PSPEAK(obj,KK);
-L2008: I=game.link[I];
+L2008: i=game.link[i];
         goto L2004;
 
 L2009: K=54;
@@ -621,11 +621,11 @@ L2620:    if(WD1 == MAKEWD(23051920)) {
                RSPEAK(276);
        }
 L2630:
-       I=VOCAB(WD1,-1);
-       if(I == -1)
+       i=VOCAB(WD1,-1);
+       if(i == -1)
           goto L3000;
-       K=MOD(I,1000);
-       KQ=I/1000+1;
+       K=MOD(i,1000);
+       KQ=i/1000+1;
         switch (KQ-1) { case 0: goto L8; case 1: goto L5000; case 2: goto L4000;
                case 3: goto L2010; }
        BUG(22);
@@ -647,11 +647,11 @@ L3000:    SETPRM(1,WD1,WD1X);
 
 /* Verb and object analysis moved to separate module. */
 
-L4000: I=4000; VERB=K; goto Laction;
-L4090: I=4090; goto Laction;
-L5000: I=5000; obj = K;
+L4000: i=4000; VERB=K; goto Laction;
+L4090: i=4090; goto Laction;
+L5000: i=5000; obj = K;
 Laction:
-        switch (action(cmdin, I, VERB, obj)) {
+        switch (action(cmdin, i, VERB, obj)) {
           case 2: return true;
           case 8: goto L8;
           case 2000: goto L2000;
@@ -951,8 +951,8 @@ L11000: game.prop[BOTTLE]=PUT(BOTTLE,115,1);
 
 /*  Leave the grate with normal (non-negative) property.  Reuse sign. */
 
-       I=PUT(GRATE,116,0);
-       I=PUT(SIGN,116,0);
+       PUT(GRATE,116,0);
+       PUT(SIGN,116,0);
        OBJTXT[SIGN]=OBJTXT[SIGN]+1;
        game.prop[SNAKE]=PUT(SNAKE,116,1);
        game.prop[BIRD]=PUT(BIRD,116,1);