/* Analyse an intransitive verb (ie, no object given yet). */
-L4080: switch (VERB-1) { case 0: goto L8010; case 1: return(8000); case 2:
+ switch (VERB-1) { case 0: goto L8010; case 1: return(8000); case 2:
return(8000); case 3: goto L8040; case 4: return(2009); case 5: goto L8040;
case 6: goto L8070; case 7: goto L8080; case 8: return(8000); case
9: return(8000); case 10: return(2011); case 11: goto L9120; case 12:
/* Read. Print stuff based on objtxt. Oyster (?) is special case. */
-L8270: /* 8275 */ for (I=1; I<=100; I++) {
-L8275: if(HERE(I) && OBJTXT[I] != 0 && PROP[I] >= 0)OBJ=OBJ*100+I;
+L8270: for (I=1; I<=100; I++) {
+ if(HERE(I) && OBJTXT[I] != 0 && PROP[I] >= 0)OBJ=OBJ*100+I;
} /* end loop */
if(OBJ > 100 || OBJ == 0 || DARK(0)) return(8000);
MOVE(DRAGON,K);
MOVE(RUG,K);
DROP(BLOOD,K);
- /* 9127 */ for (OBJ=1; OBJ<=100; OBJ++) {
+ for (OBJ=1; OBJ<=100; OBJ++) {
if(PLACE[OBJ] == PLAC[DRAGON] || PLACE[OBJ] == FIXD[DRAGON])MOVE(OBJ,K);
-L9127: /*etc*/ ;
+ /*etc*/ ;
} /* end loop */
LOC=K;
K=NUL;
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdbool.h>
+
#include "misc.h"
#include "main.h"
#include "share.h"
#include "funcs.h"
-#include <stdio.h>
-#include <stdbool.h>
/*
* Initialisation
static int raw_init(void) {
printf("Couldn't find adventure.data, using adventure.text...\n");
+ FILE *OPENED=fopen("adventure.text","r" /* NOT binary */);
+ if(!OPENED){printf("Can't read adventure.text!\n"); exit(0);}
+
/* Clear out the various text-pointer arrays. All text is stored in array
* lines; each line is preceded by a word pointing to the next pointer (i.e.
* the word following the end of the line). The pointer is negative if this is
/* Start new data section. sect is the section number. */
-L1002: SECT=GETNUM(1);
+L1002: SECT=GETNUM(OPENED);
OLDLOC= -1;
switch (SECT) { case 0: return(0); case 1: goto L1004; case 2: goto
L1004; case 3: goto L1030; case 4: goto L1040; case 5: goto L1004;
L1004: KK=LINUSE;
L1005: LINUSE=KK;
- LOC=GETNUM(1);
+ LOC=GETNUM(OPENED);
if(LNLENG >= LNPOSN+70)BUG(0);
if(LOC == -1) goto L1002;
if(LNLENG < LNPOSN)BUG(1);
* this is the last entry for this location. KEY(N) is the index in travel
* of the first option at location N. */
-L1030: LOC=GETNUM(1);
+L1030: LOC=GETNUM(OPENED);
if(LOC == -1) goto L1002;
- NEWLOC=GETNUM(0);
+ NEWLOC=GETNUM(NULL);
if(KEY[LOC] != 0) goto L1033;
KEY[LOC]=TRVS;
goto L1035;
L1033: TRVS--; TRAVEL[TRVS]= -TRAVEL[TRVS]; TRVS++;
-L1035: L=GETNUM(0);
+L1035: L=GETNUM(NULL);
if(L == 0) goto L1039;
TRAVEL[TRVS]=NEWLOC*1000+L;
TRVS=TRVS+1;
* would make it harder to detect particular input words.) */
L1040: J=10000;
- /* 1042 */ for (TABNDX=1; TABNDX<=TABSIZ; TABNDX++) {
-L1043: KTAB[TABNDX]=GETNUM(1);
+ for (TABNDX=1; TABNDX<=TABSIZ; TABNDX++) {
+ KTAB[TABNDX]=GETNUM(OPENED);
if(KTAB[TABNDX] == -1) goto L1002;
J=J+7;
-L1042: ATAB[TABNDX]=GETTXT(true,true,true,0)+J*J;
+ ATAB[TABNDX]=GETTXT(true,true,true,0)+J*J;
} /* end loop */
BUG(4);
* plac contains initial locations of objects. FIXD is -1 for immovable
* objects (including the snake), or = second loc for two-placed objects. */
-L1050: OBJ=GETNUM(1);
+L1050: OBJ=GETNUM(OPENED);
if(OBJ == -1) goto L1002;
- PLAC[OBJ]=GETNUM(0);
- FIXD[OBJ]=GETNUM(0);
+ PLAC[OBJ]=GETNUM(NULL);
+ FIXD[OBJ]=GETNUM(NULL);
goto L1050;
/* Read default message numbers for action verbs, store in ACTSPK. */
-L1060: VERB=GETNUM(1);
+L1060: VERB=GETNUM(OPENED);
if(VERB == -1) goto L1002;
- ACTSPK[VERB]=GETNUM(0);
+ ACTSPK[VERB]=GETNUM(NULL);
goto L1060;
/* Read info about available liquids and other conditions, store in COND. */
-L1070: K=GETNUM(1);
+L1070: K=GETNUM(OPENED);
if(K == -1) goto L1002;
-L1071: LOC=GETNUM(0);
+L1071: LOC=GETNUM(NULL);
if(LOC == 0) goto L1070;
if(CNDBIT(LOC,K)) BUG(8);
COND[LOC]=COND[LOC]+SETBIT(K);
/* Read data for hints. */
L1080: HNTMAX=0;
-L1081: K=GETNUM(1);
+L1081: K=GETNUM(OPENED);
if(K == -1) goto L1002;
if(K <= 0 || K > HNTSIZ)BUG(7);
- /* 1083 */ for (I=1; I<=4; I++) {
-L1083: HINTS[K][I] =GETNUM(0);
+ for (I=1; I<=4; I++) {
+ HINTS[K][I] =GETNUM(NULL);
} /* end loop */
HNTMAX=(HNTMAX>K ? HNTMAX : K);
goto L1081;
/* Read the sound/text info, store in OBJSND, OBJTXT, LOCSND. */
-L1090: K=GETNUM(1);
+L1090: K=GETNUM(OPENED);
if(K == -1) goto L1002;
- KK=GETNUM(0);
- I=GETNUM(0);
+ KK=GETNUM(NULL);
+ I=GETNUM(NULL);
if(I == 0) goto L1092;
OBJSND[K]=(KK>0 ? KK : 0);
OBJTXT[K]=(I>0 ? I : 0);
* description is printed. Counts modulo 5 unless "LOOK" is used. */
static int finish_init(void) {
- /* 1101 */ for (I=1; I<=100; I++) {
+ for (I=1; I<=100; I++) {
PLACE[I]=0;
PROP[I]=0;
LINK[I]=0;
-L1101: {long x = I+100; LINK[x]=0;}
+ {long x = I+100; LINK[x]=0;}
} /* end loop */
/* 1102 */ for (I=1; I<=LOCSIZ; I++) {
L1106: /*etc*/ ;
} /* end loop */
- /* 1107 */ for (I=1; I<=100; I++) {
+ for (I=1; I<=100; I++) {
K=101-I;
FIXED[K]=FIXD[K];
-L1107: if(PLAC[K] != 0 && FIXD[K] <= 0)DROP(K,PLAC[K]);
+ if(PLAC[K] != 0 && FIXD[K] <= 0)DROP(K,PLAC[K]);
} /* end loop */
/* Treasures, as noted earlier, are objects 50 through MAXTRS (CURRENTLY 79).
MAXTRS=79;
TALLY=0;
- /* 1200 */ for (I=50; I<=MAXTRS; I++) {
+ for (I=50; I<=MAXTRS; I++) {
if(PTEXT[I] != 0)PROP[I]= -1;
-L1200: TALLY=TALLY-PROP[I];
+ TALLY=TALLY-PROP[I];
} /* end loop */
/* Clear the hint stuff. HINTLC(I) is how long he's been at LOC with cond bit
* I. HINTED(I) is true iff hint I has been used. */
- /* 1300 */ for (I=1; I<=HNTMAX; I++) {
+ for (I=1; I<=HNTMAX; I++) {
HINTED[I]=false;
-L1300: HINTLC[I]=0;
+ HINTLC[I]=0;
} /* end loop */
/* Define some handy mnemonics. these correspond to object numbers. */
CHLOC=114;
CHLOC2=140;
- /* 1700 */ for (I=1; I<=6; I++) {
-L1700: DSEEN[I]=false;
+ for (I=1; I<=6; I++) {
+ DSEEN[I]=false;
} /* end loop */
DFLAG=0;
DLOC[1]=19;
KNFLOC=0;
DETAIL=0;
ABBNUM=5;
- /* 1800 */ for (I=0; I<=4; I++) {
-L1800: {long x = 2*I+81; if(RTEXT[x] != 0)MAXDIE=I+1;}
+ for (I=0; I<=4; I++) {
+ {long x = 2*I+81; if(RTEXT[x] != 0)MAXDIE=I+1;}
} /* end loop */
NUMDIE=0;
HOLDNG=0;
/* Report on amount of arrays actually used, to permit reductions. */
static void report(void) {
- /* 1998 */ for (K=1; K<=LOCSIZ; K++) {
+ for (K=1; K<=LOCSIZ; K++) {
KK=LOCSIZ+1-K;
if(LTEXT[KK] != 0) goto L1997;
-L1998: /*etc*/ ;
+ /*etc*/ ;
} /* end loop */
OBJ=0;
-L1997: /* 1996 */ for (K=1; K<=100; K++) {
-L1996: if(PTEXT[K] != 0)OBJ=OBJ+1;
+L1997: for (K=1; K<=100; K++) {
+ if(PTEXT[K] != 0)OBJ=OBJ+1;
} /* end loop */
- /* 1995 */ for (K=1; K<=TABNDX; K++) {
-L1995: if(KTAB[K]/1000 == 2)VERB=KTAB[K]-2000;
+ for (K=1; K<=TABNDX; K++) {
+ if(KTAB[K]/1000 == 2)VERB=KTAB[K]-2000;
} /* end loop */
- /* 1994 */ for (K=1; K<=RTXSIZ; K++) {
+ for (K=1; K<=RTXSIZ; K++) {
J=RTXSIZ+1-K;
if(RTEXT[J] != 0) goto L1993;
-L1994: /*etc*/ ;
+ /*etc*/ ;
} /* end loop */
L1993: SETPRM(1,LINUSE,LINSIZ);
}
static void quick_item(W)long *W; {
- if(init_reading && fread(W,sizeof(long),1,f) != 1)return;
+ if(init_reading && fread(W,sizeof(long),1,f) != 1)return;
init_cksum = MOD(init_cksum*13+(*W),60000000);
if(!init_reading)fwrite(W,sizeof(long),1,f);
}
L6000: if(DFLAG != 1) goto L6010;
if(!INDEEP(LOC) || (PCT(95) && (!CNDBIT(LOC,4) || PCT(85)))) goto L2000;
DFLAG=2;
- /* 6001 */ for (I=1; I<=2; I++) {
+ for (I=1; I<=2; I++) {
J=1+RAN(5);
-L6001: if(PCT(50))DLOC[J]=0;
+ if(PCT(50))DLOC[J]=0;
} /* end loop */
- /* 6002 */ for (I=1; I<=5; I++) {
+ for (I=1; I<=5; I++) {
if(DLOC[I] == LOC)DLOC[I]=DALTLC;
-L6002: ODLOC[I]=DLOC[I];
+ ODLOC[I]=DLOC[I];
} /* end loop */
RSPEAK(3);
DROP(AXE,LOC);
L2603: if(!CLOSED) goto L2605;
if(PROP[OYSTER] < 0 && TOTING(OYSTER))PSPEAK(OYSTER,1);
- /* 2604 */ for (I=1; I<=100; I++) {
-L2604: if(TOTING(I) && PROP[I] < 0)PROP[I]= -1-PROP[I];
+ for (I=1; I<=100; I++) {
+ if(TOTING(I) && PROP[I] < 0)PROP[I]= -1-PROP[I];
} /* end loop */
L2605: WZDARK=DARK(0);
if(KNFLOC > 0 && KNFLOC != LOC)KNFLOC=0;
L10000: PROP[GRATE]=0;
PROP[FISSUR]=0;
- /* 10010 */ for (I=1; I<=6; I++) {
+ for (I=1; I<=6; I++) {
DSEEN[I]=false;
-L10010: DLOC[I]=0;
+ DLOC[I]=0;
} /* end loop */
MOVE(TROLL,0);
MOVE(TROLL+100,0);
PROP[MIRROR]=PUT(MIRROR,115,0);
FIXED[MIRROR]=116;
- /* 11010 */ for (I=1; I<=100; I++) {
-L11010: if(TOTING(I))DSTROY(I);
+ for (I=1; I<=100; I++) {
+ if(TOTING(I))DSTROY(I);
} /* end loop */
RSPEAK(132);
L10: if(BLKLIN)TYPE0();
- MAPLIN(false);
+ MAPLIN(stdin);
+ if(feof(stdin)) score(1);
WORD1=GETTXT(true,true,true,0);
if(BLKLIN && WORD1 < 0) goto L10;
WORD1X=GETTXT(false,true,true,0);
#define YES(X,Y,Z) fYES(X,Y,Z)
#undef GETNUM
-long fGETNUM(long K) {
+long fGETNUM(FILE *source) {
long DIGIT, GETNUM, SIGN;
/* Obtain the next integer from an input line. If K>0, we first read a
* character (not a digit, hyphen, or blank), we return 0. */
- if(K != 0)MAPLIN(K > 0);
+ if(source != NULL)MAPLIN(source);
GETNUM=0;
L10: if(LNPOSN > LNLENG)return(GETNUM);
if(INLINE[LNPOSN] != 0) goto L20;
#define BUG(NUM) fBUG(NUM)
#undef MAPLIN
-void fMAPLIN(long FIL) {
-long I, VAL; static FILE *OPENED = NULL;
+void fMAPLIN(FILE *OPENED) {
+long I, VAL;
-/* Read a line of input, either from a file (if FIL=true) or from the
- * keyboard, translate the chars to integers in the range 0-126 and store
+/* Read a line of input, from the specified input source,
+ * translate the chars to integers in the range 0-126 and store
* them in the common array "INLINE". Integer values are as follows:
* 0 = space [ASCII CODE 40 octal, 32 decimal]
* 1-2 = !" [ASCII 41-42 octal, 33-34 decimal]
* This procedure may use the map1,map2 arrays to maintain static data for
* the mapping. MAP2(1) is set to 0 when the program starts
* and is not changed thereafter unless the routines on this page choose
- * to do so.
- *
- * Note that MAPLIN is expected to open the file the first time it is
- * asked to read a line from it. that is, there is no other place where
- * the data file is opened. */
-
+ * to do so. */
if(MAP2[1] == 0)MPINIT();
- if(FIL) goto L15;
- IGNORE(fgets(INLINE+1, sizeof(INLINE)-1, stdin));
- if(feof(stdin)) score(1);
- goto L20;
-
-L15: if(!OPENED){
- OPENED=fopen("adventure.text","r" /* NOT binary */);
- if(!OPENED){printf("Can't read adventure.text!\n"); exit(0);}
- }
- IGNORE(fgets(INLINE+1,sizeof(INLINE)-1,OPENED));
-
-L20: LNLENG=0;
- for (I=1; I<=sizeof(INLINE) && INLINE[I]!=0; I++) {
- VAL=INLINE[I]+1;
- INLINE[I]=MAP1[VAL];
- if(INLINE[I] != 0)LNLENG=I;
- } /* end loop */
- LNPOSN=1;
- if(FIL && LNLENG == 0) goto L15;
-/* Above is to get around an F40 compiler bug wherein it reads a blank
- * line whenever a crlf is broken across a record boundary. */
- return;
+ IGNORE(fgets(INLINE+1,sizeof(INLINE)-1,OPENED));
+ if (!feof(OPENED)) {
+ LNLENG=0;
+ for (I=1; I<=sizeof(INLINE) && INLINE[I]!=0; I++) {
+ VAL=INLINE[I]+1;
+ INLINE[I]=MAP1[VAL];
+ if(INLINE[I] != 0)LNLENG=I;
+ } /* end loop */
+ LNPOSN=1;
+ }
}
-
-
-
#define MAPLIN(FIL) fMAPLIN(FIL)
+
#undef TYPE
void fTYPE(void) {
long I, VAL;
#include <time.h>
+#include <stdio.h>
/* b is not needed for POSIX but harmless */
#define READ_MODE "rb"
#define GETIN(WORD1,WORD1X,WORD2,WORD2X) fGETIN(&WORD1,&WORD1X,&WORD2,&WORD2X)
extern long fYES(long,long,long);
#define YES(X,Y,Z) fYES(X,Y,Z)
-extern long fGETNUM(long);
+extern long fGETNUM(FILE *);
#define GETNUM(K) fGETNUM(K)
extern long fGETTXT(long,long,long,long);
#define GETTXT(SKIP,ONEWRD,UPPER,HASH) fGETTXT(SKIP,ONEWRD,UPPER,HASH)
#define RNDVOC(CHAR,FORCE) fRNDVOC(CHAR,FORCE)
extern void fBUG(long);
#define BUG(NUM) fBUG(NUM)
-extern void fMAPLIN(long);
+extern void fMAPLIN(FILE *);
#define MAPLIN(FIL) fMAPLIN(FIL)
extern void fTYPE();
#define TYPE() fTYPE()
* Points can also be deducted for using hints or too many turns, or for
* saving intermediate positions. */
-L20000: SCORE=0;
+ SCORE=0;
MXSCOR=0;
/* First tally up the treasures. must be in building and not broken.
/* Deduct for hints/turns/saves. Hints < 4 are special; see database desc. */
- /* 20030 */ for (I=1; I<=HNTMAX; I++) {
-L20030: if(HINTED[I])SCORE=SCORE-HINTS[I][2];
+ for (I=1; I<=HNTMAX; I++) {
+ if(HINTED[I])SCORE=SCORE-HINTS[I][2];
} /* end loop */
if(NOVICE)SCORE=SCORE-5;
if(CLSHNT)SCORE=SCORE-10;
SETPRM(1,SCORE,MXSCOR);
SETPRM(3,TURNS,TURNS);
RSPEAK(262);
- /* 20200 */ for (I=1; I<=CLSSES; I++) {
+ for (I=1; I<=CLSSES; I++) {
if(CVAL[I] >= SCORE) goto L20210;
-L20200: /*etc*/ ;
+ /*etc*/ ;
} /* end loop */
SPK=265;
goto L25000;