Finish moving state arrays into game structure block.
[open-adventure.git] / misc.c
diff --git a/misc.c b/misc.c
index 46772d53498936d296cdfc9333a5d450c2826901..e89442dcc666cf2b62b0a9af9b0ed291fba91694 100644 (file)
--- a/misc.c
+++ b/misc.c
 
 /*  I/O routines (SPEAK, PSPEAK, RSPEAK, SETPRM, GETIN, YES) */
 
-void SPEAK(long N) {
+void SPEAK(vocab_t N) {
 long BLANK, CASE, I, K, L, NEG, NPARMS, PARM, PRMTYP, STATE;
 
 /*  Print the message which starts at LINES(N).  Precede it with a blank line
- *  unless BLKLIN is false. */
+ *  unless game.blklin is false. */
 
        if(N == 0)return;
-       BLANK=BLKLIN;
+       BLANK=game.blklin;
        K=N;
        NPARMS=1;
 L10:   L=labs(LINES[K])-1;
@@ -111,11 +111,11 @@ L40:      if(BLANK)TYPE0();
        return;
 }
 
-void PSPEAK(long MSG,long SKIP) {
+void PSPEAK(vocab_t MSG,int SKIP) {
 long I, M;
 
 /*  Find the skip+1st message from msg and print it.  MSG should be the index of
- *  the inventory message for object.  (INVEN+N+1 message is PROP=N message). */
+ *  the inventory message for object.  (INVEN+N+1 message is game.prop=N message). */
 
 
        M=PTEXT[MSG];
@@ -129,7 +129,7 @@ L9: SPEAK(M);
        return;
 }
 
-void RSPEAK(long I) {
+void RSPEAK(vocab_t I) {
 
 /*  Print the I-TH "random" message (section 6 of database). */
 
@@ -168,12 +168,12 @@ long JUNK;
  *  WORD2 (chars 6 thru 10 in WORD2X), else WORD2 is -1. */
 
 
-L10:   if(BLKLIN)TYPE0();
+L10:   if(game.blklin)TYPE0();
        MAPLIN(input);
        if (feof(input))
            return false;
        WORD1=GETTXT(true,true,true);
-       if(BLKLIN && WORD1 < 0) goto L10;
+       if(game.blklin && WORD1 < 0) goto L10;
        WORD1X=GETTXT(false,true,true);
 L12:   JUNK=GETTXT(false,true,true);
        if(JUNK > 0) goto L12;
@@ -194,8 +194,8 @@ L22:        JUNK=GETTXT(false,true,true);
 #undef WORD2X
 #define GETIN(SRC,WORD1,WORD1X,WORD2,WORD2X) fGETIN(SRC,&WORD1,&WORD1X,&WORD2,&WORD2X)
 
-long YES(FILE *input, long X, long Y, long Z) {
-long YEAH, REPLY, JUNK1, JUNK2, JUNK3;
+long YES(FILE *input, vocab_t X, vocab_t Y, vocab_t Z) {
+token_t YEAH, REPLY, JUNK1, JUNK2, JUNK3;
 
 /*  Print message X, wait for yes/no answer.  If yes, print Y and return true;
  *  if no, print Z and return false. */
@@ -223,7 +223,7 @@ L20:        YEAH=false;
  *  machine dependent i/o stuff is on the following page.  See that page
  *  for a description of MAPCOM's inline array. */
 
-long GETTXT(long SKIP,long ONEWRD, long UPPER) {
+long GETTXT(bool SKIP,bool ONEWRD, bool UPPER) {
 /*  Take characters from an input line and pack them into 30-bit words.
  *  Skip says to skip leading blanks.  ONEWRD says stop if we come to a
  *  blank.  UPPER says to map all letters to uppercase.  If we reach the
@@ -245,7 +245,7 @@ long GETTXT(long SKIP,long ONEWRD, long UPPER) {
   }
 
   TEXT=0;
-  for (int I=1; I<=5; I++) {
+  for (int I=1; I<=TOKLEN; I++) {
     TEXT=TEXT*64;
     if(LNPOSN > LNLENG || (ONEWRD && INLINE[LNPOSN] == 0))
       continue;
@@ -272,25 +272,24 @@ long GETTXT(long SKIP,long ONEWRD, long UPPER) {
   return(TEXT);
 }
 
-long MAKEWD(long LETTRS) {
+token_t MAKEWD(long LETTRS) {
 long I, L, WORD;
 
-/*  Combine five uppercase letters (represented by pairs of decimal digits
- *  in lettrs) to form a 30-bit value matching the one that GETTXT would
- *  return given those characters plus trailing blanks.  Caution:
- *  lettrs will overflow 31 bits if 5-letter word starts with V-Z.  As a
- *  kludgey workaround, you can increment a letter by 5 by adding 50 to
- *  the next pair of digits. */
-
+/*  Combine TOKLEN (currently 5) uppercase letters (represented by
+ *  pairs of decimal digits in lettrs) to form a 30-bit value matching
+ *  the one that GETTXT would return given those characters plus
+ *  trailing blanks.  Caution: lettrs will overflow 31 bits if
+ *  5-letter word starts with V-Z.  As a kludgey workaround, you can
+ *  increment a letter by 5 by adding 50 to the next pair of
+ *  digits. */
 
        WORD=0;
        I=1;
-       L=LETTRS;
-L10:   WORD=WORD+I*(MOD(L,50)+10);
-       I=I*64;
-       if(MOD(L,100) > 50)WORD=WORD+I*5;
-       L=L/100;
-       if(L != 0) goto L10;
+       for (L=LETTRS; L != 0; L=L/100) {
+               WORD=WORD+I*(MOD(L,50)+10);
+               I=I*64;
+               if(MOD(L,100) > 50)WORD=WORD+I*5;
+       }
        I=64L*64L*64L*64L*64L/I;
        WORD=WORD*I;
        return(WORD);
@@ -298,18 +297,20 @@ L10:      WORD=WORD+I*(MOD(L,50)+10);
 
 
 #define STATE (*sTATE)
-void fPUTTXT(long WORD, long *sTATE, long CASE) {
+void fPUTTXT(token_t WORD, long *sTATE, long CASE) {
 long ALPH1, ALPH2, BYTE, DIV, I, W;
 
-/*  Unpack the 30-bit value in word to obtain up to 5 integer-encoded chars,
- *  and store them in inline starting at LNPOSN.  If LNLENG>=LNPOSN, shift
- *  existing characters to the right to make room.  STATE will be zero when
- *  puttxt is called with the first of a sequence of words, but is thereafter
- *  unchanged by the caller, so PUTTXT can use it to maintain state across
- *  calls.  LNPOSN and LNLENG are incremented by the number of chars stored.
- *  If CASE=1, all letters are made uppercase; if -1, lowercase; if 0, as is.
- *  any other value for case is the same as 0 but also causes trailing blanks
- *  to be included (in anticipation of subsequent additional text). */
+/*  Unpack the 30-bit value in word to obtain up to TOKLEN (currently
+ *  5) integer-encoded chars, and store them in inline starting at
+ *  LNPOSN.  If LNLENG>=LNPOSN, shift existing characters to the right
+ *  to make room.  STATE will be zero when puttxt is called with the
+ *  first of a sequence of words, but is thereafter unchanged by the
+ *  caller, so PUTTXT can use it to maintain state across calls.
+ *  LNPOSN and LNLENG are incremented by the number of chars stored.
+ *  If CASE=1, all letters are made uppercase; if -1, lowercase; if 0,
+ *  as is.  any other value for case is the same as 0 but also causes
+ *  trailing blanks to be included (in anticipation of subsequent
+ *  additional text). */
 
 
        ALPH1=13*CASE+24;
@@ -318,7 +319,7 @@ long ALPH1, ALPH2, BYTE, DIV, I, W;
 /*  ALPH1&2 DEFINE RANGE OF WRONG-CASE CHARS, 11-36 OR 37-62 OR EMPTY. */
        DIV=64L*64L*64L*64L;
        W=WORD;
-       /* 18 */ for (I=1; I<=5; I++) {
+       /* 18 */ for (I=1; I<=TOKLEN; I++) {
        if(W <= 0 && STATE == 0 && labs(CASE) <= 1)return;
        BYTE=W/DIV;
        if(STATE != 0 || BYTE != 63) goto L12;
@@ -508,8 +509,8 @@ long I, J;
 /*  Juggle an object by picking it up and putting it down again, the purpose
  *  being to get the object to the front of the chain of things at its loc. */
 
-       I=PLACE[OBJECT];
-       J=FIXED[OBJECT];
+       I=game.place[OBJECT];
+       J=game.fixed[OBJECT];
        MOVE(OBJECT,I);
        MOVE(OBJECT+NOBJECTS,J);
        return;
@@ -520,13 +521,13 @@ long FROM;
 
 /*  Place any object anywhere by picking it up and dropping it.  May already be
  *  toting, in which case the carry is a no-op.  Mustn't pick up objects which
- *  are not at any loc, since carry wants to remove objects from ATLOC chains. */
+ *  are not at any loc, since carry wants to remove objects from game.atloc chains. */
 
 
        if(OBJECT > NOBJECTS) goto L1;
-       FROM=PLACE[OBJECT];
+       FROM=game.place[OBJECT];
         goto L2;
-L1:    {long x = OBJECT-NOBJECTS; FROM=FIXED[x];}
+L1:    {long x = OBJECT-NOBJECTS; FROM=game.fixed[x];}
 L2:    if(FROM > 0 && FROM <= 300)CARRY(OBJECT,FROM);
        DROP(OBJECT,WHERE);
        return;
@@ -536,7 +537,7 @@ long PUT(long OBJECT, long WHERE, long PVAL) {
 long X;
 
 /*  PUT is the same as MOVE, except it returns a value used to set up the
- *  negated PROP values for the repository objects. */
+ *  negated game.prop values for the repository objects. */
 
        MOVE(OBJECT,WHERE);
        X=(-1)-PVAL;
@@ -548,35 +549,35 @@ long TEMP;
 
 /*  Start toting an object, removing it from the list of things at its former
  *  location.  Incr holdng unless it was already being toted.  If OBJECT>NOBJECTS
- *  (moving "fixed" second loc), don't change PLACE or HOLDNG. */
+ *  (moving "fixed" second loc), don't change game.place or game.holdng. */
 
        if(OBJECT > NOBJECTS) goto L5;
-       if(PLACE[OBJECT] == -1)return;
-       PLACE[OBJECT]= -1;
-       HOLDNG=HOLDNG+1;
-L5:    if(ATLOC[WHERE] != OBJECT) goto L6;
-       ATLOC[WHERE]=LINK[OBJECT];
+       if(game.place[OBJECT] == -1)return;
+       game.place[OBJECT]= -1;
+       game.holdng=game.holdng+1;
+L5:    if(game.atloc[WHERE] != OBJECT) goto L6;
+       game.atloc[WHERE]=game.link[OBJECT];
        return;
-L6:    TEMP=ATLOC[WHERE];
-L7:    if(LINK[TEMP] == OBJECT) goto L8;
-       TEMP=LINK[TEMP];
+L6:    TEMP=game.atloc[WHERE];
+L7:    if(game.link[TEMP] == OBJECT) goto L8;
+       TEMP=game.link[TEMP];
         goto L7;
-L8:    LINK[TEMP]=LINK[OBJECT];
+L8:    game.link[TEMP]=game.link[OBJECT];
        return;
 }
 
 void DROP(long OBJECT, long WHERE) {
-/*  Place an object at a given loc, prefixing it onto the ATLOC list.  Decr
- *  HOLDNG if the object was being toted. */
+/*  Place an object at a given loc, prefixing it onto the game.atloc list.  Decr
+ *  game.holdng if the object was being toted. */
 
        if(OBJECT > NOBJECTS) goto L1;
-       if(PLACE[OBJECT] == -1)HOLDNG=HOLDNG-1;
-       PLACE[OBJECT]=WHERE;
+       if(game.place[OBJECT] == -1)game.holdng=game.holdng-1;
+       game.place[OBJECT]=WHERE;
         goto L2;
-L1:    {long x = OBJECT-NOBJECTS; FIXED[x]=WHERE;}
+L1:    {long x = OBJECT-NOBJECTS; game.fixed[x]=WHERE;}
 L2:    if(WHERE <= 0)return;
-       LINK[OBJECT]=ATLOC[WHERE];
-       ATLOC[WHERE]=OBJECT;
+       game.link[OBJECT]=game.atloc[WHERE];
+       game.atloc[WHERE]=OBJECT;
        return;
 }
 
@@ -591,11 +592,11 @@ long AT, I;
 
 
        AT=0;
-       if(DFLAG < 2)return(AT);
+       if(game.dflag < 2)return(AT);
        AT= -1;
        for (I=1; I<=NDWARVES-1; I++) {
-       if(DLOC[I] == WHERE) goto L2;
-       if(DLOC[I] != 0)AT=0;
+       if(game.dloc[I] == WHERE) goto L2;
+       if(game.dloc[I] != 0)AT=0;
        } /* end loop */
        return(AT);