/* Analyse a verb. Remember what it was, go back for object if second word
* unless verb is "say", which snarfs arbitrary second word. */
-int action(long STARTAT) {
+int action(FILE *input, long STARTAT) {
switch(STARTAT) {
case 4000: goto L4000;
case 4090: goto L4090;
/* Attack also moved into separate module. */
-L9120: return(attack());
+L9120: return(attack(input));
/* Pour. If no object, or object is bottle, assume contents of bottle.
* special tests for pouring water or oil on plant or rusty door. */
/* Throw moved into separate module. */
-L9170: return(throw());
+L9170: return(throw(input));
/* Quit. Intransitive only. Verify intent and exit if that's what he wants. */
-L8180: if(YES(22,54,54)) score(1);
+L8180: if(YES(input,22,54,54)) score(1);
return(2012);
/* Find. Might be carrying it, or it might be here. Else give caveat. */
PSPEAK(OBJ,OBJTXT[OBJ]+PROP[OBJ]);
return(2012);
-L9275: CLSHNT=YES(192,193,54);
+L9275: CLSHNT=YES(input,192,193,54);
return(2012);
/* Break. Only works for mirror in repository and, of course, the vase. */
L8300: SPK=201;
RSPEAK(260);
- if(!YES(200,54,54)) return(2012);
+ if(!YES(input,200,54,54)) return(2012);
SAVED=SAVED+5;
KK= -1;
L8310: KK=1;
if(LOC == 1 && ABB[1] == 1) goto L8305;
RSPEAK(268);
- if(!YES(200,54,54)) return(2012);
+ if(!YES(input,200,54,54)) return(2012);
goto L8305;
L8312: SETPRM(1,K/10,MOD(K,10));
* objects fall into two categories: enemies (snake, dwarf, etc.) and others
* (bird, clam, machine). Ambiguous if 2 enemies, or no enemies but 2 others. */
-int attack() {
+int attack(FILE *input) {
I=ATDWRF(LOC);
if(OBJ != 0) goto L9124;
if(I > 0)OBJ=DWARF;
RSPEAK(49);
VERB=0;
OBJ=0;
- GETIN(WD1,WD1X,WD2,WD2X);
+ GETIN(input,WD1,WD1X,WD2,WD2X);
if(WD1 != MAKEWD(25) && WD1 != MAKEWD(250519)) return(2607);
PSPEAK(DRAGON,3);
PROP[DRAGON]=1;
* and if dwarf is present then one might be killed. (Only way to do so!)
* Axe also special for dragon, bear, and troll. Treasures special for troll. */
-int throw() {
+int throw(FILE *cmdin) {
if(TOTING(ROD2) && OBJ == ROD && !TOTING(ROD))OBJ=ROD2;
if(!TOTING(OBJ)) return(2011);
if(OBJ >= 50 && OBJ <= MAXTRS && AT(TROLL)) goto L9178;
if(AT(OGRE)) goto L9175;
if(HERE(BEAR) && PROP[BEAR] == 0) goto L9176;
OBJ=0;
- return(attack());
+ return(attack(cmdin));
L9172: SPK=48;
if(RAN(7) < DFLAG) goto L9175;
#define OUTSID(LOC) ((LOC) <= 8 || FOREST(LOC) || (LOC) == PLAC[SAPPH] || (LOC) == 180 || (LOC) == 182)
#define INDEEP(LOC) ((LOC) >= 15 && !OUTSID(LOC) && (LOC) != 179)
-extern int carry(void), discard(bool), attack(void), throw(void), feed(void), fill(void);
+extern int carry(void), discard(bool), attack(FILE *), throw(FILE *), feed(void), fill(void);
void score(long);
extern void initialise();
extern void score(long);
-extern int action(long);
+extern int action(FILE *, long);
/*
* MAIN PROGRAM
*/
-static void do_command(void);
+static void do_command(FILE *);
int main(int argc, char *argv[]) {
int ch;
L1: SETUP= -1;
I=RAN(-1);
ZZWORD=RNDVOC(3,0)+MESH*2;
- NOVICE=YES(65,1,0);
+ NOVICE=YES(stdin, 65,1,0);
NEWLOC=1;
LOC=1;
LIMIT=330;
if(NOVICE)LIMIT=1000;
for (;;) {
- do_command();
+ do_command(stdin);
}
}
-static void do_command(void) {
+static void do_command(FILE *cmdin) {
/* Can't leave cave once it's closing (except by main office). */
L2605: WZDARK=DARK(0);
if(KNFLOC > 0 && KNFLOC != LOC)KNFLOC=0;
I=RAN(1);
- GETIN(WD1,WD1X,WD2,WD2X);
+ GETIN(cmdin, WD1,WD1X,WD2,WD2X);
/* Every input, check "FOOBAR" flag. If zero, nothing's going on. If pos,
* make neg. If neg, he skipped a word, so make it zero. */
L4090: I=4090; goto Laction;
L5000: I=5000;
Laction:
- switch (action(I)) {
+ switch (action(cmdin, I)) {
case 2: return;
case 8: goto L8;
case 2000: goto L2000;
L99: if(CLOSNG) goto L95;
NUMDIE=NUMDIE+1;
- if(!YES(79+NUMDIE*2,80+NUMDIE*2,54)) score(0);
+ if(!YES(cmdin,79+NUMDIE*2,80+NUMDIE*2,54)) score(0);
if(NUMDIE == MAXDIE) score(0);
PLACE[WATER]=0;
PLACE[OIL]=0;
BUG(27);
L40010: HINTLC[HINT]=0;
- if(!YES(HINTS[HINT][3],0,54)) goto L2602;
+ if(!YES(cmdin,HINTS[HINT][3],0,54)) goto L2602;
SETPRM(1,HINTS[HINT][2],HINTS[HINT][2]);
RSPEAK(261);
- HINTED[HINT]=YES(175,HINTS[HINT][4],54);
+ HINTED[HINT]=YES(cmdin,175,HINTS[HINT][4],54);
if(HINTED[HINT] && LIMIT > 30)LIMIT=LIMIT+30*HINTS[HINT][2];
L40020: HINTLC[HINT]=0;
L40030: goto L2602;
#define WORD1X (*wORD1X)
#define WORD2 (*wORD2)
#define WORD2X (*wORD2X)
-void fGETIN(long *wORD1, long *wORD1X, long *wORD2, long *wORD2X) {
+void fGETIN(FILE *input, long *wORD1, long *wORD1X, long *wORD2, long *wORD2X) {
long JUNK;
/* Get a command from the adventurer. Snarf out the first word, pad it with
L10: if(BLKLIN)TYPE0();
- MAPLIN(stdin);
- if(feof(stdin)) score(1);
+ MAPLIN(input);
+ if(input == stdin && feof(stdin)) score(1);
WORD1=GETTXT(true,true,true,0);
if(BLKLIN && WORD1 < 0) goto L10;
WORD1X=GETTXT(false,true,true,0);
#undef WORD1X
#undef WORD2
#undef WORD2X
-#define GETIN(WORD1,WORD1X,WORD2,WORD2X) fGETIN(&WORD1,&WORD1X,&WORD2,&WORD2X)
+#define GETIN(SRC,WORD1,WORD1X,WORD2,WORD2X) fGETIN(SRC,&WORD1,&WORD1X,&WORD2,&WORD2X)
#undef YES
-long fYES(long X, long Y, long Z) {
+long fYES(FILE *input, long X, long Y, long Z) {
long YES, REPLY, JUNK1, JUNK2, JUNK3;
* if no, print Z and return false. */
L1: RSPEAK(X);
- GETIN(REPLY,JUNK1,JUNK2,JUNK3);
+ GETIN(input, REPLY,JUNK1,JUNK2,JUNK3);
if(REPLY == MAKEWD(250519) || REPLY == MAKEWD(25)) goto L10;
if(REPLY == MAKEWD(1415) || REPLY == MAKEWD(14)) goto L20;
RSPEAK(185);
#define RSPEAK(I) fRSPEAK(I)
extern void fSETPRM(long,long,long);
#define SETPRM(FIRST,P1,P2) fSETPRM(FIRST,P1,P2)
-extern void fGETIN(long*,long*,long*,long*);
-#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 void fGETIN(FILE *,long*,long*,long*,long*);
+#define GETIN(input,WORD1,WORD1X,WORD2,WORD2X) fGETIN(input,&WORD1,&WORD1X,&WORD2,&WORD2X)
+extern long fYES(FILE *,long,long,long);
+#define YES(input,X,Y,Z) fYES(input,X,Y,Z)
extern long fGETNUM(FILE *);
#define GETNUM(K) fGETNUM(K)
extern long fGETTXT(long,long,long,long);