7 /* This stuff was broken off as part of an effort to get the main program
8 * to compile without running out of memory. We're called with a number
9 * that says what label the caller wanted to "goto", and we return a
10 * similar label number for the caller to "goto".
13 /* Analyse a verb. Remember what it was, go back for object if second word
14 * unless verb is "say", which snarfs arbitrary second word. */
16 int action(FILE *input, long STARTAT) {
18 case 4000: goto L4000;
19 case 4090: goto L4090;
20 case 5000: goto L5000;
26 if(WD2 > 0 && VERB != SAY) return(2800);
27 if(VERB == SAY)OBJ=WD2;
28 if(OBJ > 0) goto L4090;
30 /* Analyse an intransitive verb (ie, no object given yet). */
33 case 0: goto L8010; /* CARRY */
34 case 1: return(8000); /* DROP */
35 case 2: return(8000); /* SAY */
36 case 3: goto L8040; /* UNLOC */
37 case 4: return(2009); /* NOTHI */
38 case 5: goto L8040; /* LOCK */
39 case 6: goto L8070; /* LIGHT */
40 case 7: goto L8080; /* EXTIN */
41 case 8: return(8000); /* WAVE */
42 case 9: return(8000); /* CALM */
43 case 10: return(2011); /* WALK */
44 case 11: goto L9120; /* ATTAC */
45 case 12: goto L9130; /* POUR */
46 case 13: goto L8140; /* EAT */
47 case 14: goto L9150; /* DRINK */
48 case 15: return(8000); /* RUB */
49 case 16: return(8000); /* TOSS */
50 case 17: goto L8180; /* QUIT */
51 case 18: return(8000); /* FIND */
52 case 19: goto L8200; /* INVEN */
53 case 20: return(8000); /* FEED */
54 case 21: goto L9220; /* FILL */
55 case 22: goto L9230; /* BLAST */
56 case 23: goto L8240; /* SCOR */
57 case 24: goto L8250; /* FOO */
58 case 25: goto L8260; /* BRIEF */
59 case 26: goto L8270; /* READ */
60 case 27: return(8000); /* BREAK */
61 case 28: return(8000); /* WAKE */
62 case 29: goto L8300; /* SUSP */
63 case 30: goto L8310; /* RESU */
64 case 31: goto L8320; /* FLY */
65 case 32: goto L8330; /* LISTEN */
66 case 33: goto L8340; /* ZZZZ */
70 /* Analyse a transitive verb. */
72 L4090: switch (VERB-1) {
73 case 0: goto L9010; /* CARRY */
74 case 1: goto L9020; /* DROP */
75 case 2: goto L9030; /* SAY */
76 case 3: goto L9040; /* UNLOC */
77 case 4: return(2009); /* NOTHI */
78 case 5: goto L9040; /* LOCK */
79 case 6: goto L9070; /* LIGHT */
80 case 7: goto L9080; /* EXTI */
81 case 8: goto L9090; /* WAVE */
82 case 9: return(2011); /* CALM */
83 case 10: return(2011); /* WALK */
84 case 11: goto L9120; /* ATTAC */
85 case 12: goto L9130; /* POUR */
86 case 13: goto L9140; /* EAT */
87 case 14: goto L9150; /* DRINK */
88 case 15: goto L9160; /* RUB */
89 case 16: goto L9170; /* TOSS */
90 case 17: return(2011); /* QUIT */
91 case 18: goto L9190; /* FIND */
92 case 19: goto L9190; /* INVEN */
93 case 20: goto L9210; /* FEED */
94 case 21: goto L9220; /* FILL */
95 case 22: goto L9230; /* BLAST */
96 case 23: return(2011); /* SCOR */
97 case 24: return(2011); /* FOO */
98 case 25: return(2011); /* BRIEF */
99 case 26: goto L9270; /* READ */
100 case 27: goto L9280; /* BREAK */
101 case 28: goto L9290; /* WAKE */
102 case 29: return(2011); /* SUSP */
103 case 30: return(2011); /* RESU */
104 case 31: goto L9320; /* FLY */
105 case 32: return(2011); /* LISTEN */
106 case 33: goto L8340; /* ZZZZ */
110 /* Analyse an object word. See if the thing is here, whether we've got a verb
111 * yet, and so on. Object must be here unless verb is "find" or "invent(ory)"
112 * (and no new verb yet to be analysed). Water and oil are also funny, since
113 * they are never actually dropped at any location, but might be here inside
114 * the bottle or urn or as a feature of the location. */
117 if(!HERE(K)) goto L5100;
118 L5010: if(WD2 > 0) return(2800);
119 if(VERB != 0) goto L4090;
124 L5100: if(K != GRATE) goto L5110;
125 if(LOC == 1 || LOC == 4 || LOC == 7)K=DPRSSN;
126 if(LOC > 9 && LOC < 15)K=ENTRNC;
127 if(K != GRATE) return(8);
128 L5110: if(K == DWARF && ATDWRF(LOC) > 0) goto L5010;
129 if((LIQ(0) == K && HERE(BOTTLE)) || K == LIQLOC(LOC)) goto L5010;
130 if(OBJ != OIL || !HERE(URN) || PROP[URN] == 0) goto L5120;
133 L5120: if(OBJ != PLANT || !AT(PLANT2) || PROP[PLANT2] == 0) goto L5130;
136 L5130: if(OBJ != KNIFE || KNFLOC != LOC) goto L5140;
140 L5140: if(OBJ != ROD || !HERE(ROD2)) goto L5190;
143 L5190: if((VERB == FIND || VERB == INVENT) && WD2 <= 0) goto L5010;
151 /* Routines for performing the various action verbs */
153 /* Statement numbers in this section are 8000 for intransitive verbs, 9000 for
154 * transitive, plus ten times the verb number. Many intransitive verbs use the
155 * transitive code, and some verbs use code for other verbs, as noted below. */
157 /* Carry, no object given yet. OK if only one object present. */
159 L8010: if(ATLOC[LOC] == 0 || LINK[ATLOC[LOC]] != 0 || ATDWRF(LOC) > 0) return(8000);
162 /* Transitive carry/drop are in separate file. */
164 L9010: return(carry());
165 L9020: return(discard(false));
167 /* SAY. Echo WD2 (or WD1 if no WD2 (SAY WHAT?, etc.).) Magic words override. */
169 L9030: SETPRM(1,WD2,WD2X);
170 if(WD2 <= 0)SETPRM(1,WD1,WD1X);
173 if(I == 62 || I == 65 || I == 71 || I == 2025 || I == 2034) goto L9035;
181 /* Lock, unlock, no object given. Assume various things if present. */
184 if(HERE(CLAM))OBJ=CLAM;
185 if(HERE(OYSTER))OBJ=OYSTER;
186 if(AT(DOOR))OBJ=DOOR;
187 if(AT(GRATE))OBJ=GRATE;
188 if(OBJ != 0 && HERE(CHAIN)) return(8000);
189 if(HERE(CHAIN))OBJ=CHAIN;
190 if(OBJ == 0) return(2011);
192 /* Lock, unlock object. Special stuff for opening clam/oyster and for chain. */
194 L9040: if(OBJ == CLAM || OBJ == OYSTER) goto L9046;
195 if(OBJ == DOOR)SPK=111;
196 if(OBJ == DOOR && PROP[DOOR] == 1)SPK=54;
197 if(OBJ == CAGE)SPK=32;
198 if(OBJ == KEYS)SPK=55;
199 if(OBJ == GRATE || OBJ == CHAIN)SPK=31;
200 if(SPK != 31 || !HERE(KEYS)) return(2011);
201 if(OBJ == CHAIN) goto L9048;
202 if(!CLOSNG) goto L9043;
208 L9043: K=34+PROP[GRATE];
210 if(VERB == LOCK)PROP[GRATE]=0;
216 if(OBJ == OYSTER)K=1;
218 if(TOTING(OBJ))SPK=120+K;
219 if(!TOTING(TRIDNT))SPK=122+K;
220 if(VERB == LOCK)SPK=61;
221 if(SPK != 124) return(2011);
228 L9048: if(VERB == LOCK) goto L9049;
230 if(PROP[BEAR] == 0)SPK=41;
231 if(PROP[CHAIN] == 0)SPK=37;
232 if(SPK != 171) return(2011);
235 if(PROP[BEAR] != 3)PROP[BEAR]=2;
236 FIXED[BEAR]=2-PROP[BEAR];
240 if(PROP[CHAIN] != 0)SPK=34;
241 if(LOC != PLAC[CHAIN])SPK=173;
242 if(SPK != 172) return(2011);
244 if(TOTING(CHAIN))DROP(CHAIN,LOC);
248 /* Light. Applicable only to lamp and urn. */
250 L8070: if(HERE(LAMP) && PROP[LAMP] == 0 && LIMIT >= 0)OBJ=LAMP;
251 if(HERE(URN) && PROP[URN] == 1)OBJ=OBJ*100+URN;
252 if(OBJ == 0 || OBJ > 100) return(8000);
254 L9070: if(OBJ == URN) goto L9073;
255 if(OBJ != LAMP) return(2011);
257 if(LIMIT < 0) return(2011);
260 if(WZDARK) return(2000);
264 if(PROP[URN] == 0) return(2011);
269 /* Extinguish. Lamp, urn, dragon/volcano (nice try). */
271 L8080: if(HERE(LAMP) && PROP[LAMP] == 1)OBJ=LAMP;
272 if(HERE(URN) && PROP[URN] == 2)OBJ=OBJ*100+URN;
273 if(OBJ == 0 || OBJ > 100) return(8000);
275 L9080: if(OBJ == URN) goto L9083;
276 if(OBJ == LAMP) goto L9086;
277 if(OBJ == DRAGON || OBJ == VOLCAN)SPK=146;
280 L9083: PROP[URN]=PROP[URN]/2;
286 if(DARK(0))RSPEAK(16);
289 /* Wave. No effect unless waving rod at fissure or at bird. */
291 L9090: if((!TOTING(OBJ)) && (OBJ != ROD || !TOTING(ROD2)))SPK=29;
292 if(OBJ != ROD || !TOTING(OBJ) || (!HERE(BIRD) && (CLOSNG || !AT(FISSUR))))
294 if(HERE(BIRD))SPK=206+MOD(PROP[BIRD],2);
295 if(SPK == 206 && LOC == PLACE[STEPS] && PROP[JADE] < 0) goto L9094;
296 if(CLOSED) return(18999);
297 if(CLOSNG || !AT(FISSUR)) return(2011);
298 if(HERE(BIRD))RSPEAK(SPK);
299 PROP[FISSUR]=1-PROP[FISSUR];
300 PSPEAK(FISSUR,2-PROP[FISSUR]);
303 L9094: DROP(JADE,LOC);
309 /* Attack also moved into separate module. */
311 L9120: return(attack(input));
313 /* Pour. If no object, or object is bottle, assume contents of bottle.
314 * special tests for pouring water or oil on plant or rusty door. */
316 L9130: if(OBJ == BOTTLE || OBJ == 0)OBJ=LIQ(0);
317 if(OBJ == 0) return(8000);
318 if(!TOTING(OBJ)) return(2011);
320 if(OBJ != OIL && OBJ != WATER) return(2011);
321 if(HERE(URN) && PROP[URN] == 0) goto L9134;
325 if(!(AT(PLANT) || AT(DOOR))) return(2011);
327 if(AT(DOOR)) goto L9132;
329 if(OBJ != WATER) return(2011);
330 PSPEAK(PLANT,PROP[PLANT]+3);
331 PROP[PLANT]=MOD(PROP[PLANT]+1,3);
332 PROP[PLANT2]=PROP[PLANT];
337 if(OBJ == OIL)PROP[DOOR]=1;
344 /* Eat. Intransitive: assume food if present, else ask what. Transitive: food
345 * ok, some things lose appetite, rest are ridiculous. */
347 L8140: if(!HERE(FOOD)) return(8000);
352 L9140: if(OBJ == FOOD) goto L8142;
353 if(OBJ == BIRD || OBJ == SNAKE || OBJ == CLAM || OBJ == OYSTER || OBJ ==
354 DWARF || OBJ == DRAGON || OBJ == TROLL || OBJ == BEAR || OBJ ==
358 /* Drink. If no object, assume water and look for it here. If water is in
359 * the bottle, drink that, else must be at a water loc, so drink stream. */
361 L9150: if(OBJ == 0 && LIQLOC(LOC) != WATER && (LIQ(0) != WATER || !HERE(BOTTLE)))
363 if(OBJ == BLOOD) goto L9153;
364 if(OBJ != 0 && OBJ != WATER)SPK=110;
365 if(SPK == 110 || LIQ(0) != WATER || !HERE(BOTTLE)) return(2011);
371 L9153: DSTROY(BLOOD);
373 OBJSND[BIRD]=OBJSND[BIRD]+3;
377 /* Rub. Yields various snide remarks except for lit urn. */
379 L9160: if(OBJ != LAMP)SPK=76;
380 if(OBJ != URN || PROP[URN] != 2) return(2011);
389 /* Throw moved into separate module. */
391 L9170: return(throw(input));
393 /* Quit. Intransitive only. Verify intent and exit if that's what he wants. */
395 L8180: if(YES(input,22,54,54)) score(1);
398 /* Find. Might be carrying it, or it might be here. Else give caveat. */
400 L9190: if(AT(OBJ) || (LIQ(0) == OBJ && AT(BOTTLE)) || K == LIQLOC(LOC) || (OBJ ==
401 DWARF && ATDWRF(LOC) > 0))SPK=94;
403 if(TOTING(OBJ))SPK=24;
406 /* Inventory. If object, treat same as find. Else report on current burden. */
409 /* 8201 */ for (I=1; I<=100; I++) {
410 if(I == BEAR || !TOTING(I)) goto L8201;
411 if(SPK == 98)RSPEAK(99);
418 if(TOTING(BEAR))SPK=141;
421 /* Feed/fill are in the other module. */
423 L9210: return(feed());
424 L9220: return(fill());
426 /* Blast. No effect unless you've got dynamite, which is a neat trick! */
428 L9230: if(PROP[ROD2] < 0 || !CLOSED) return(2011);
430 if(LOC == 115)BONUS=134;
431 if(HERE(ROD2))BONUS=135;
435 /* Score. Call scoring routine but tell it to return. */
438 SETPRM(1,SCORE,MXSCOR);
439 SETPRM(3,TURNS,TURNS);
443 /* FEE FIE FOE FOO (AND FUM). ADVANCE TO NEXT STATE IF GIVEN IN PROPER ORDER.
444 * LOOK UP WD1 IN SECTION 3 OF VOCAB TO DETERMINE WHICH WORD WE'VE GOT. LAST
445 * WORD ZIPS THE EGGS BACK TO THE GIANT ROOM (UNLESS ALREADY THERE). */
447 L8250: K=VOCAB(WD1,3);
449 if(FOOBAR == 1-K) goto L8252;
450 if(FOOBAR != 0)SPK=151;
454 if(K != 4) return(2009);
456 if(PLACE[EGGS] == PLAC[EGGS] || (TOTING(EGGS) && LOC == PLAC[EGGS]))
458 /* Bring back troll if we steal the eggs back from him before crossing. */
459 if(PLACE[EGGS] == 0 && PLACE[TROLL] == 0 && PROP[TROLL] ==
463 if(LOC == PLAC[EGGS])K=0;
464 MOVE(EGGS,PLAC[EGGS]);
468 /* Brief. Intransitive only. Suppress long descriptions after first time. */
475 /* Read. Print stuff based on objtxt. Oyster (?) is special case. */
477 L8270: for (I=1; I<=100; I++) {
478 if(HERE(I) && OBJTXT[I] != 0 && PROP[I] >= 0)OBJ=OBJ*100+I;
480 if(OBJ > 100 || OBJ == 0 || DARK(0)) return(8000);
482 L9270: if(DARK(0)) goto L5190;
483 if(OBJTXT[OBJ] == 0 || PROP[OBJ] < 0) return(2011);
484 if(OBJ == OYSTER && !CLSHNT) goto L9275;
485 PSPEAK(OBJ,OBJTXT[OBJ]+PROP[OBJ]);
488 L9275: CLSHNT=YES(input,192,193,54);
491 /* Break. Only works for mirror in repository and, of course, the vase. */
493 L9280: if(OBJ == MIRROR)SPK=148;
494 if(OBJ == VASE && PROP[VASE] == 0) goto L9282;
495 if(OBJ != MIRROR || !CLOSED) return(2011);
500 if(TOTING(VASE))DROP(VASE,LOC);
505 /* Wake. Only use is to disturb the dwarves. */
507 L9290: if(OBJ != DWARF || !CLOSED) return(2011);
511 /* Suspend. Offer to save things in a file, but charging some points (so
512 * can't win by using saved games to retry battles or to start over after
513 * learning zzword). */
517 if(!YES(input,200,54,54)) return(2012);
521 /* This next part is shared with the "resume" code. The two cases are
522 * distinguished by the value of kk (-1 for suspend, +1 for resume). */
524 L8305: DATIME(&I,&K);
529 if(K != VRSION) goto L8312;
530 /* Herewith are all the variables whose values can change during a game,
531 * omitting a few (such as I, J, ATTACK) whose values between turns are
532 * irrelevant and some whose values when a game is
533 * suspended or resumed are guaranteed to match. If unsure whether a value
534 * needs to be saved, include it. Overkill can't hurt. Pad the last savwds
535 * with junk variables to bring it up to 7 values. */
536 SAVWDS(ABBNUM,BLKLIN,BONUS,CLOCK1,CLOCK2,CLOSED,CLOSNG);
537 SAVWDS(DETAIL,DFLAG,DKILL,DTOTAL,FOOBAR,HOLDNG,IWEST);
538 SAVWDS(KNFLOC,LIMIT,LL,LMWARN,LOC,NEWLOC,NUMDIE);
539 SAVWDS(OBJ,OLDLC2,OLDLOC,OLDOBJ,PANIC,SAVED,SETUP);
540 SAVWDS(SPK,TALLY,THRESH,TRNDEX,TRNLUZ,TURNS,OBJTXT[OYSTER]);
541 SAVWDS(VERB,WD1,WD1X,WD2,WZDARK,ZZWORD,OBJSND[BIRD]);
542 SAVWDS(OBJTXT[SIGN],CLSHNT,NOVICE,K,K,K,K);
544 SAVARR(ATLOC,LOCSIZ);
548 SAVARR(HINTED,HNTSIZ);
549 SAVARR(HINTLC,HNTSIZ);
555 if(K != 0) goto L8318;
557 ZZWORD=RNDVOC(3,ZZWORD);
558 if(KK > 0) return(8);
562 /* Resume. Read a suspended game back from a file. */
565 if(LOC == 1 && ABB[1] == 1) goto L8305;
567 if(!YES(input,200,54,54)) return(2012);
570 L8312: SETPRM(1,K/10,MOD(K,10));
571 SETPRM(3,VRSION/10,MOD(VRSION,10));
578 /* Fly. Snide remarks unless hovering rug is here. */
580 L8320: if(PROP[RUG] != 2)SPK=224;
581 if(!HERE(RUG))SPK=225;
582 if(SPK/2 == 112) return(2011);
585 L9320: if(OBJ != RUG) return(2011);
587 if(PROP[RUG] != 2) return(2011);
590 NEWLOC=PLACE[RUG]+FIXED[RUG]-LOC;
592 if(PROP[SAPPH] >= 0)SPK=227;
596 /* Listen. Intransitive only. Print stuff based on objsnd/locsnd. */
600 if(K == 0) goto L8332;
602 if(K < 0) return(2012);
604 L8332: SETPRM(1,ZZWORD,0);
605 /* 8335 */ for (I=1; I<=100; I++) {
606 if(!HERE(I) || OBJSND[I] == 0 || PROP[I] < 0) goto L8335;
607 PSPEAK(I,OBJSND[I]+PROP[I]);
609 if(I == BIRD && OBJSND[I]+PROP[I] == 8)DSTROY(BIRD);
614 /* Z'ZZZ (word gets recomputed at startup; different each game). */
616 L8340: if(!AT(RESER) && LOC != FIXED[RESER]-1) return(2011);
617 PSPEAK(RESER,PROP[RESER]+1);
618 PROP[RESER]=1-PROP[RESER];
619 if(AT(RESER)) return(2012);