Replace homebrew IABS() with C kubrary labs(3).
[open-adventure.git] / main.c
diff --git a/main.c b/main.c
index 7a065b2fd91ca3dc4f955be85b93f893f99ca558..498236966c31e1937eac05ce599b5918d8b89c41 100644 (file)
--- a/main.c
+++ b/main.c
@@ -9,16 +9,15 @@
 #include <getopt.h>
 #include <signal.h>
 #include <time.h>
-#include "main.h"
+#include "advent.h"
 #include "database.h"
-#include "misc.h"
 
 long ABB[186], ATLOC[186], BLKLIN = true, DFLAG,
                DLOC[7], FIXED[101], HOLDNG,
                LINK[201], LNLENG, LNPOSN,
                PARMS[26], PLACE[101],
                SETUP = 0;
-signed char rawbuf[LINESIZE], INLINE[LINESIZE+1], MAP1[129], MAP2[129];
+char rawbuf[LINESIZE], INLINE[LINESIZE+1], MAP1[129], MAP2[129];
 
 long ABBNUM, AMBER, ATTACK, AXE, BACK, BATTER, BEAR, BIRD, BLOOD, BONUS,
                 BOTTLE, CAGE, CAVE, CAVITY, CHAIN, CHASM, CHEST, CHLOC, CHLOC2,
@@ -110,7 +109,8 @@ int main(int argc, char *argv[]) {
        lcgstate.a = 1093;
        lcgstate.c = 221587;
        lcgstate.m = 1048576;
-       long seedval = (long)time(NULL);
+       srand(time(NULL));
+       long seedval = (long)rand();
        set_seed(seedval);
 
 /*  Read the database if we have not yet done so */
@@ -140,7 +140,7 @@ L1: SETUP= -1;
 
        if (logfp)
            fprintf(logfp, "seed %ld\n", seedval);
-       
+
        for (;;) {
            if (!do_command(stdin))
                break;
@@ -148,13 +148,15 @@ L1:       SETUP= -1;
        score(1);
 }
 
-static bool fallback_handler(signed char *buf)
+static bool fallback_handler(char *buf)
 /* fallback handler for commands not handled by FORTRANish parser */
 {
     long sv;
     if (sscanf(buf, "seed %ld", &sv) == 1) {
        set_seed(sv);
        printf("Seed set to %ld\n", sv);
+       // autogenerated, so don't charge user time for it.
+       --TURNS;
        // here we reconfigure any global game state that uses random numbers
        ZZWORD=RNDVOC(3,0);
        return true;
@@ -234,12 +236,12 @@ L6010:    DTOTAL=0;
        KK=DLOC[I];
        KK=KEY[KK];
        if(KK == 0) goto L6016;
-L6012: NEWLOC=MOD(IABS(TRAVEL[KK])/1000,1000);
+L6012: NEWLOC=MOD(labs(TRAVEL[KK])/1000,1000);
        {long x = J-1;
        if(NEWLOC > 300 || !INDEEP(NEWLOC) || NEWLOC == ODLOC[I] || (J > 1 &&
                NEWLOC == TK[x]) || J >= 20 || NEWLOC == DLOC[I] ||
                FORCED(NEWLOC) || (I == 6 && CNDBIT(NEWLOC,3)) ||
-               IABS(TRAVEL[KK])/1000000 == 100) goto L6014;}
+               labs(TRAVEL[KK])/1000000 == 100) goto L6014;}
        TK[J]=NEWLOC;
        J=J+1;
 L6014: KK=KK+1;
@@ -400,8 +402,7 @@ L2600:      if(COND[LOC] < CONDS) goto L2603;
 L2602: /*etc*/ ;
        } /* end loop */
 
-/*  Kick the random number generator just to add variety to the chase.  Also,
- *  if closing time, check for any objects being toted with PROP < 0 and set
+/*  If closing time, check for any objects being toted with PROP < 0 and set
  *  the prop to -1-PROP.  This way objects won't be described until they've
  *  been picked up and put down separate from their respective piles.  Don't
  *  tick CLOCK1 unless well into cave (and not at Y2). */
@@ -529,7 +530,7 @@ L8: KK=KEY[LOC];
        OLDLC2=OLDLOC;
        OLDLOC=LOC;
 
-L9:    LL=IABS(TRAVEL[KK]);
+L9:    LL=labs(TRAVEL[KK]);
        if(MOD(LL,1000) == 1 || MOD(LL,1000) == K) goto L10;
        if(TRAVEL[KK] < 0) goto L50;
        KK=KK+1;
@@ -542,7 +543,7 @@ L11:        NEWLOC=LL/1000;
        if(PROP[K] != NEWLOC/100-3) goto L16;
 L12:   if(TRAVEL[KK] < 0)BUG(25);
        KK=KK+1;
-       NEWLOC=IABS(TRAVEL[KK])/1000;
+       NEWLOC=labs(TRAVEL[KK])/1000;
        if(NEWLOC == LL) goto L12;
        LL=NEWLOC;
         goto L11;
@@ -629,11 +630,11 @@ L20:      K=OLDLOC;
        RSPEAK(K2);
        return true;
 
-L21:   LL=MOD((IABS(TRAVEL[KK])/1000),1000);
+L21:   LL=MOD((labs(TRAVEL[KK])/1000),1000);
        if(LL == K) goto L25;
        if(LL > 300) goto L22;
        J=KEY[LL];
-       if(FORCED(LL) && MOD((IABS(TRAVEL[J])/1000),1000) == K)K2=KK;
+       if(FORCED(LL) && MOD((labs(TRAVEL[J])/1000),1000) == K)K2=KK;
 L22:   if(TRAVEL[KK] < 0) goto L23;
        KK=KK+1;
         goto L21;
@@ -643,7 +644,7 @@ L23:        KK=K2;
        RSPEAK(140);
        return true;
 
-L25:   K=MOD(IABS(TRAVEL[KK]),1000);
+L25:   K=MOD(labs(TRAVEL[KK]),1000);
        KK=KEY[LOC];
         goto L9;