Because (almost) everything is done in handlers now, merge the action files.
[open-adventure.git] / actions.c
1 #include <stdlib.h>
2 #include <stdbool.h>
3 #include "advent.h"
4 #include "database.h"
5
6 /*
7  * Action handlers.  Eventually we'll do lookup through a method table
8  * that calls these.  Absolutely nothing like the original FORTRAN.
9  */
10
11 static int fill(long);
12
13 static int attack(FILE *input, long verb, long obj)
14 /*  Attack.  Assume target if unambiguous.  "Throw" also links here.
15  *  Attackable objects fall into two categories: enemies (snake,
16  *  dwarf, etc.)  and others (bird, clam, machine).  Ambiguous if 2
17  *  enemies, or no enemies but 2 others. */
18 {
19     int i =ATDWRF(game.loc);
20     if (obj == 0) {
21         if (i > 0)
22             obj=DWARF;
23         if (HERE(SNAKE))obj=obj*NOBJECTS+SNAKE;
24         if (AT(DRAGON) && game.prop[DRAGON] == 0)obj=obj*NOBJECTS+DRAGON;
25         if (AT(TROLL))obj=obj*NOBJECTS+TROLL;
26         if (AT(OGRE))obj=obj*NOBJECTS+OGRE;
27         if (HERE(BEAR) && game.prop[BEAR] == 0)obj=obj*NOBJECTS+BEAR;
28         if (obj > NOBJECTS) return(8000);
29         if (obj == 0) {
30             /* Can't attack bird or machine by throwing axe. */
31             if (HERE(BIRD) && verb != THROW)obj=BIRD;
32             if (HERE(VEND) && verb != THROW)obj=obj*NOBJECTS+VEND;
33             /* Clam and oyster both treated as clam for intransitive case;
34              * no harm done. */
35             if (HERE(CLAM) || HERE(OYSTER))obj=NOBJECTS*obj+CLAM;
36             if (obj > NOBJECTS) return(8000);
37         }
38     }
39     if (obj == BIRD) {
40         SPK=137;
41         if (game.closed) return(2011);
42         DSTROY(BIRD);
43         game.prop[BIRD]=0;
44         SPK=45;
45     }
46     if (obj == VEND) {
47         PSPEAK(VEND,game.prop[VEND]+2);
48         game.prop[VEND]=3-game.prop[VEND];
49         return(2012);
50     }
51
52     if (obj == 0)SPK=44;
53     if (obj == CLAM || obj == OYSTER)SPK=150;
54     if (obj == SNAKE)SPK=46;
55     if (obj == DWARF)SPK=49;
56     if (obj == DWARF && game.closed) return(19000);
57     if (obj == DRAGON)SPK=167;
58     if (obj == TROLL)SPK=157;
59     if (obj == OGRE)SPK=203;
60     if (obj == OGRE && i > 0) {
61         RSPEAK(SPK);
62         RSPEAK(6);
63         DSTROY(OGRE);
64         int k=0;
65         for (i=1; i < PIRATE; i++) {
66             if (game.dloc[i] == game.loc) {
67                 ++k;
68                 game.dloc[i]=61;
69                 game.dseen[i]=false;
70             }
71         }
72         SPK=SPK+1+1/k;
73         return(2011);
74     }
75     if (obj == BEAR)SPK=165+(game.prop[BEAR]+1)/2;
76     if (obj != DRAGON || game.prop[DRAGON] != 0) return(2011);
77     /*  Fun stuff for dragon.  If he insists on attacking it, win!
78      *  Set game.prop to dead, move dragon to central loc (still
79      *  fixed), move rug there (not fixed), and move him there,
80      *  too.  Then do a null motion to get new description. */
81     RSPEAK(49);
82     GETIN(input,WD1,WD1X,WD2,WD2X);
83     if (WD1 != MAKEWD(25) && WD1 != MAKEWD(250519)) return(2607);
84     PSPEAK(DRAGON,3);
85     game.prop[DRAGON]=1;
86     game.prop[RUG]=0;
87     K=(PLAC[DRAGON]+FIXD[DRAGON])/2;
88     MOVE(DRAGON+NOBJECTS,-1);
89     MOVE(RUG+NOBJECTS,0);
90     MOVE(DRAGON,K);
91     MOVE(RUG,K);
92     DROP(BLOOD,K);
93     for (obj=1; obj<=NOBJECTS; obj++) {
94         if (game.place[obj] == PLAC[DRAGON] || game.place[obj] == FIXD[DRAGON])MOVE(obj,K);
95         /*etc*/ ;
96     } /* end loop */
97     game.loc=K;
98     K=NUL;
99     return(8);
100 }
101
102 static int bigwords(long foo)
103 /*  FEE FIE FOE FOO (AND FUM).  Advance to next state if given in proper order.
104  *  Look up WD1 in section 3 of vocab to determine which word we've got.  Last
105  *  word zips the eggs back to the giant room (unless already there). */
106 {
107     int k=VOCAB(foo,3);
108     SPK=42;
109     if (game.foobar != 1-k) {
110         if (game.foobar != 0)SPK=151;
111         return(2011);
112     } else {
113
114         game.foobar=k;
115         if (k != 4) return(2009);
116         game.foobar=0;
117         if (game.place[EGGS] == PLAC[EGGS] || (TOTING(EGGS) && game.loc == PLAC[EGGS])) 
118             return(2011);
119         /*  Bring back troll if we steal the eggs back from him before
120          *  crossing. */
121         if (game.place[EGGS]==0 && game.place[TROLL]==0 && game.prop[TROLL]==0)
122             game.prop[TROLL]=1;
123         k=2;
124         if (HERE(EGGS))k=1;
125         if (game.loc == PLAC[EGGS])k=0;
126         MOVE(EGGS,PLAC[EGGS]);
127         PSPEAK(EGGS,k);
128         return(2012);
129     }
130 }
131
132 static int bivalve(token_t verb, token_t obj)
133 /* Clam/oyster actions */
134 {
135     int k=0;
136     if (obj == OYSTER)k=1;
137     SPK=124+k;
138     if (TOTING(obj))SPK=120+k;
139     if (!TOTING(TRIDNT))SPK=122+k;
140     if (verb == LOCK)SPK=61;
141     if (SPK != 124)
142         return(2011);
143     DSTROY(CLAM);
144     DROP(OYSTER,game.loc);
145     DROP(PEARL,105);
146     return(2011);
147 }
148
149 static int blast(void)
150 /*  Blast.  No effect unless you've got dynamite, which is a neat trick! */
151 {
152     if (game.prop[ROD2] < 0 || !game.closed) return(2011);
153     game.bonus=133;
154     if (game.loc == 115)game.bonus=134;
155     if (HERE(ROD2))game.bonus=135;
156     RSPEAK(game.bonus);
157     score(0);
158 }
159
160 static int vbreak(token_t obj)
161 /*  Break.  Only works for mirror in repository and, of course, the vase. */
162 {
163     if (obj == MIRROR)SPK=148;
164     if (obj == VASE && game.prop[VASE] == 0) {
165         SPK=198;
166         if (TOTING(VASE))DROP(VASE,game.loc);
167         game.prop[VASE]=2;
168         game.fixed[VASE]= -1;
169         return(2011);
170     } else {
171         if (obj != MIRROR || !game.closed) return(2011);
172         SPK=197;
173         return(18999);
174     }
175 }
176
177
178 static int brief(void)
179 /*  Brief.  Intransitive only.  Suppress long descriptions after first time. */
180 {
181     SPK=156;
182     game.abbnum=10000;
183     game.detail=3;
184     return(2011);
185 }
186
187 static int carry(long obj)
188 /*  Carry an object.  Special cases for bird and cage (if bird in cage, can't
189  *  take one without the other).  Liquids also special, since they depend on
190  *  status of bottle.  Also various side effects, etc. */
191 {
192     if (obj == INTRANSITIVE) {
193         /*  Carry, no object given yet.  OK if only one object present. */
194         if(game.atloc[game.loc] == 0 ||
195            game.link[game.atloc[game.loc]] != 0 ||
196            ATDWRF(game.loc) > 0)
197             return(8000);
198         obj=game.atloc[game.loc];
199     }
200
201     if (TOTING(obj)) return(2011);
202     SPK=25;
203     if (obj == PLANT && game.prop[PLANT] <= 0)SPK=115;
204     if (obj == BEAR && game.prop[BEAR] == 1)SPK=169;
205     if (obj == CHAIN && game.prop[BEAR] != 0)SPK=170;
206     if (obj == URN)SPK=215;
207     if (obj == CAVITY)SPK=217;
208     if (obj == BLOOD)SPK=239;
209     if (obj == RUG && game.prop[RUG] == 2)SPK=222;
210     if (obj == SIGN)SPK=196;
211     if (obj == MESSAG) {
212         SPK=190;
213         DSTROY(MESSAG);
214     }
215     if (game.fixed[obj] != 0)
216         return(2011);
217     if (obj == WATER || obj == OIL) {
218         if (!HERE(BOTTLE) || LIQ(0) != obj) {
219             if (TOTING(BOTTLE) && game.prop[BOTTLE] == 1)
220                 return(fill(BOTTLE));
221             if (game.prop[BOTTLE] != 1)SPK=105;
222             if (!TOTING(BOTTLE))SPK=104;
223             return(2011);
224         }
225         obj = BOTTLE;
226     }
227
228     SPK=92;
229     if (game.holdng >= INVLIMIT)
230         return(2011);
231     if (obj == BIRD && game.prop[BIRD] != 1 && -1-game.prop[BIRD] != 1) {
232         if (game.prop[BIRD] == 2) {
233             SPK=238;
234             DSTROY(BIRD);
235             return(2011);
236         }
237         if (!TOTING(CAGE))SPK=27;
238         if (TOTING(ROD))SPK=26;
239         if (SPK/2 == 13) return(2011);
240         game.prop[BIRD]=1;
241     }
242     if ((obj==BIRD || obj==CAGE) && (game.prop[BIRD]==1 || -1-game.prop[BIRD]==1))
243         CARRY(BIRD+CAGE-obj,game.loc);
244     CARRY(obj,game.loc);
245     if (obj == BOTTLE && LIQ(0) != 0)
246         game.place[LIQ(0)] = -1;
247     if (!GSTONE(obj) || game.prop[obj] == 0)
248         return(2009);
249     game.prop[obj]=0;
250     game.prop[CAVITY]=1;
251     return(2009);
252 }
253
254 static int chain(token_t verb)
255 /* Do something to the bear's chain */
256 {
257     if (verb != LOCK) {
258         SPK=171;
259         if (game.prop[BEAR] == 0)SPK=41;
260         if (game.prop[CHAIN] == 0)SPK=37;
261         if (SPK != 171) return(2011);
262         game.prop[CHAIN]=0;
263         game.fixed[CHAIN]=0;
264         if (game.prop[BEAR] != 3)game.prop[BEAR]=2;
265         game.fixed[BEAR]=2-game.prop[BEAR];
266         return(2011);
267     } else {
268         SPK=172;
269         if (game.prop[CHAIN] != 0)SPK=34;
270         if (game.loc != PLAC[CHAIN])SPK=173;
271         if (SPK != 172) return(2011);
272         game.prop[CHAIN]=2;
273         if (TOTING(CHAIN))DROP(CHAIN,game.loc);
274         game.fixed[CHAIN]= -1;
275         return(2011);
276     }
277 }
278
279 static int discard(long obj, bool just_do_it)
280 /*  Discard object.  "Throw" also comes here for most objects.  Special cases for
281  *  bird (might attack snake or dragon) and cage (might contain bird) and vase.
282  *  Drop coins at vending machine for extra batteries. */
283 {
284     if (!just_do_it) {
285         if (TOTING(ROD2) && obj == ROD && !TOTING(ROD))obj=ROD2;
286         if (!TOTING(obj)) return(2011);
287         if (obj == BIRD && HERE(SNAKE)) {
288             RSPEAK(30);
289             if (game.closed) return(19000);
290             DSTROY(SNAKE);
291             /* Set game.prop for use by travel options */
292             game.prop[SNAKE]=1;
293
294         } else if ((GSTONE(obj) && AT(CAVITY) && game.prop[CAVITY] != 0)) {
295             RSPEAK(218);
296             game.prop[obj]=1;
297             game.prop[CAVITY]=0;
298             if (HERE(RUG) && ((obj == EMRALD && game.prop[RUG] != 2) || (obj == RUBY &&
299                                                                          game.prop[RUG] == 2))) {
300                 SPK=219;
301                 if (TOTING(RUG))SPK=220;
302                 if (obj == RUBY)SPK=221;
303                 RSPEAK(SPK);
304                 if (SPK != 220) {
305                     K=2-game.prop[RUG];
306                     game.prop[RUG]=K;
307                     if (K == 2)K=PLAC[SAPPH];
308                     MOVE(RUG+NOBJECTS,K);
309                 }
310             }
311         } else if (obj == COINS && HERE(VEND)) {
312             DSTROY(COINS);
313             DROP(BATTER,game.loc);
314             PSPEAK(BATTER,0);
315             return(2012);
316         } else if (obj == BIRD && AT(DRAGON) && game.prop[DRAGON] == 0) {
317             RSPEAK(154);
318             DSTROY(BIRD);
319             game.prop[BIRD]=0;
320             return(2012);
321         } else if (obj == BEAR && AT(TROLL)) {
322             RSPEAK(163);
323             MOVE(TROLL,0);
324             MOVE(TROLL+NOBJECTS,0);
325             MOVE(TROLL2,PLAC[TROLL]);
326             MOVE(TROLL2+NOBJECTS,FIXD[TROLL]);
327             JUGGLE(CHASM);
328             game.prop[TROLL]=2;
329         } else if (obj != VASE || game.loc == PLAC[PILLOW]) {
330             RSPEAK(54);
331         } else {
332             game.prop[VASE]=2;
333             if (AT(PILLOW))game.prop[VASE]=0;
334             PSPEAK(VASE,game.prop[VASE]+1);
335             if (game.prop[VASE] != 0)game.fixed[VASE]= -1;
336         }
337     }
338     K=LIQ(0);
339     if (K == obj)obj=BOTTLE;
340     if (obj == BOTTLE && K != 0)game.place[K]=0;
341     if (obj == CAGE && game.prop[BIRD] == 1)DROP(BIRD,game.loc);
342     DROP(obj,game.loc);
343     if (obj != BIRD) return(2012);
344     game.prop[BIRD]=0;
345     if (FOREST(game.loc))game.prop[BIRD]=2;
346     return(2012);
347 }
348
349 static int drink(token_t obj)
350 /*  Drink.  If no object, assume water and look for it here.  If water is in
351  *  the bottle, drink that, else must be at a water loc, so drink stream. */
352 {
353     if (obj == 0 && LIQLOC(game.loc) != WATER && (LIQ(0) != WATER || !HERE(BOTTLE)))
354         return(8000);
355     if (obj != BLOOD) {
356         if (obj != 0 && obj != WATER)SPK=110;
357         if (SPK == 110 || LIQ(0) != WATER || !HERE(BOTTLE)) return(2011);
358         game.prop[BOTTLE]=1;
359         game.place[WATER]=0;
360         SPK=74;
361         return(2011);
362     } else {
363         DSTROY(BLOOD);
364         game.prop[DRAGON]=2;
365         OBJSND[BIRD]=OBJSND[BIRD]+3;
366         SPK=240;
367         return(2011);
368     }
369 }
370
371 static int eat(token_t obj)
372 /*  Eat.  Intransitive: assume food if present, else ask what.  Transitive: food
373  *  ok, some things lose appetite, rest are ridiculous. */
374 {
375     if (obj == INTRANSITIVE) {
376         if (!HERE(FOOD))
377             return(8000);
378         DSTROY(FOOD);
379         SPK=72;
380         return(2011);
381     } else {
382         if (obj == FOOD) {
383             DSTROY(FOOD);
384             SPK=72;
385             return(2011);
386         }
387         if (obj == BIRD || obj == SNAKE || obj == CLAM || obj == OYSTER || obj ==
388            DWARF || obj == DRAGON || obj == TROLL || obj == BEAR || obj ==
389            OGRE)SPK=71;
390         return(2011);
391     }
392 }
393
394 static int extinguish(int obj)
395 /* Extinguish.  Lamp, urn, dragon/volcano (nice try). */
396 {
397     if (obj == INTRANSITIVE) {
398         if (HERE(LAMP) && game.prop[LAMP] == 1)obj=LAMP;
399         if (HERE(URN) && game.prop[URN] == 2)obj=obj*NOBJECTS+URN;
400         if (obj == 0 || obj > NOBJECTS) return(8000);
401     }
402
403     if (obj == URN) {
404         game.prop[URN]=game.prop[URN]/2;
405         SPK=210;
406         return(2011);
407     }
408     if (obj == LAMP) {
409         game.prop[LAMP]=0;
410         RSPEAK(40);
411         if (DARK(0))
412             RSPEAK(16);
413         return(2012);
414     }
415     if (obj == DRAGON || obj == VOLCAN)
416         SPK=146;
417     return(2011);
418 }
419
420 static int feed(long obj)
421 /*  Feed.  If bird, no seed.  Snake, dragon, troll: quip.  If dwarf, make him
422  *  mad.  Bear, special. */
423 {
424     if (obj == BIRD) {
425         SPK=100;
426         return(2011);
427     }
428
429     if (!(obj != SNAKE && obj != DRAGON && obj != TROLL)) {
430         SPK=102;
431         if (obj == DRAGON && game.prop[DRAGON] != 0)SPK=110;
432         if (obj == TROLL)SPK=182;
433         if (obj != SNAKE || game.closed || !HERE(BIRD))
434             return(2011);
435         SPK=101;
436         DSTROY(BIRD);
437         game.prop[BIRD]=0;
438         return(2011);
439     }
440
441     if (obj == DWARF) {
442         if (!HERE(FOOD))
443             return(2011);
444         SPK=103;
445         game.dflag=game.dflag+2;
446         return(2011);
447     }
448
449     if (obj == BEAR) {
450         if (game.prop[BEAR] == 0)SPK=102;
451         if (game.prop[BEAR] == 3)SPK=110;
452         if (!HERE(FOOD))
453             return(2011);
454         DSTROY(FOOD);
455         game.prop[BEAR]=1;
456         game.fixed[AXE]=0;
457         game.prop[AXE]=0;
458         SPK=168;
459         return(2011);
460     }
461
462     if (obj == OGRE) {
463         if (HERE(FOOD))
464             SPK=202;
465         return(2011);
466     }
467
468     SPK=14;
469     return(2011);
470 }
471
472 int fill(long obj)
473 /*  Fill.  Bottle or urn must be empty, and liquid available.  (Vase
474  *  is nasty.) */
475 {
476     int k;
477     if (obj == VASE) {
478         SPK=29;
479         if (LIQLOC(game.loc) == 0)SPK=144;
480         if (LIQLOC(game.loc) == 0 || !TOTING(VASE))
481             return(2011);
482         RSPEAK(145);
483         game.prop[VASE]=2;
484         game.fixed[VASE]= -1;
485         return(discard(obj, true));
486     }
487
488     if (obj == URN){
489         SPK=213;
490         if (game.prop[URN] != 0) return(2011);
491         SPK=144;
492         k=LIQ(0);
493         if (k == 0 || !HERE(BOTTLE)) return(2011);
494         game.place[k]=0;
495         game.prop[BOTTLE]=1;
496         if (k == OIL)game.prop[URN]=1;
497         SPK=211+game.prop[URN];
498         return(2011);
499     }
500
501     if (obj != 0 && obj != BOTTLE)
502         return(2011);
503     if (obj == 0 && !HERE(BOTTLE))
504         return(8000);
505     SPK=107;
506     if (LIQLOC(game.loc) == 0)
507         SPK=106;
508     if (HERE(URN) && game.prop[URN] != 0)
509         SPK=214;
510     if (LIQ(0) != 0)
511         SPK=105;
512     if (SPK != 107)
513         return(2011);
514     game.prop[BOTTLE]=MOD(COND[game.loc],4)/2*2;
515     k=LIQ(0);
516     if (TOTING(BOTTLE))
517         game.place[k]= -1;
518     if (k == OIL)
519         SPK=108;
520     return(2011);
521 }
522
523 static int find(token_t obj)
524 /* Find.  Might be carrying it, or it might be here.  Else give caveat. */
525 {
526     if (AT(obj) ||
527        (LIQ(0) == obj && AT(BOTTLE)) ||
528        K == LIQLOC(game.loc) ||
529        (obj == DWARF && ATDWRF(game.loc) > 0))
530         SPK=94;
531     if (game.closed)SPK=138;
532     if (TOTING(obj))SPK=24;
533     return(2011);
534 }
535
536 static int fly(token_t obj)
537 /* Fly.  Snide remarks unless hovering rug is here. */
538 {
539     if (obj == INTRANSITIVE) {
540         if (game.prop[RUG] != 2)SPK=224;
541         if (!HERE(RUG))SPK=225;
542         if (SPK/2 == 112) return(2011);
543         obj=RUG;
544     }
545
546     if (obj != RUG) return(2011);
547     SPK=223;
548     if (game.prop[RUG] != 2) return(2011);
549     game.oldlc2=game.oldloc;
550     game.oldloc=game.loc;
551     game.newloc=game.place[RUG]+game.fixed[RUG]-game.loc;
552     SPK=226;
553     if (game.prop[SAPPH] >= 0)SPK=227;
554     RSPEAK(SPK);
555     return(2);
556 }
557     
558 static int inven(token_t obj)
559 /* Inventory. If object, treat same as find.  Else report on current burden. */
560 {
561     int i;
562     SPK=98;
563     for (i=1; i<=NOBJECTS; i++) {
564         if (i == BEAR || !TOTING(i))
565             continue;
566         if (SPK == 98)RSPEAK(99);
567         game.blklin=false;
568         PSPEAK(i,-1);
569         game.blklin=true;
570         SPK=0;
571     }
572     if (TOTING(BEAR))
573         SPK=141;
574     return(2011);
575 }
576
577 int light(token_t obj)
578 /*  Light.  Applicable only to lamp and urn. */
579 {
580     if (obj == INTRANSITIVE) {
581         if (HERE(LAMP) && game.prop[LAMP] == 0 && game.limit >= 0)obj=LAMP;
582         if (HERE(URN) && game.prop[URN] == 1)obj=obj*NOBJECTS+URN;
583         if (obj == 0 || obj > NOBJECTS) return(8000);
584     }
585
586     if (obj == URN) {
587         SPK=38;
588         if (game.prop[URN] == 0)
589             return(2011);
590         SPK=209;
591         game.prop[URN]=2;
592         return(2011);
593     } else {
594         if (obj != LAMP) return(2011);
595         SPK=184;
596         if (game.limit < 0) return(2011);
597         game.prop[LAMP]=1;
598         RSPEAK(39);
599         if (game.wzdark) return(2000);
600         return(2012);
601     }    
602 }
603
604 static int listen(void)
605 /*  Listen.  Intransitive only.  Print stuff based on objsnd/locsnd. */
606 {
607     int i, k;
608     SPK=228;
609     k=LOCSND[game.loc];
610     if (k != 0) {
611         RSPEAK(labs(k));
612         if (k < 0) return(2012);
613         SPK=0;
614     }
615     SETPRM(1,game.zzword,0);
616     for (i=1; i<=NOBJECTS; i++) {
617         if (!HERE(i) || OBJSND[i] == 0 || game.prop[i] < 0)
618             continue;
619         PSPEAK(i,OBJSND[i]+game.prop[i]);
620         SPK=0;
621         if (i == BIRD && OBJSND[i]+game.prop[i] == 8)
622             DSTROY(BIRD);
623     }
624     return(2011);
625 }
626
627 static int lock(token_t verb, token_t obj)
628 /* Lock, unlock, no object given.  Assume various things if present. */
629 {
630     int k;
631     if (obj == INTRANSITIVE) {
632         SPK=28;
633         if (HERE(CLAM))obj=CLAM;
634         if (HERE(OYSTER))obj=OYSTER;
635         if (AT(DOOR))obj=DOOR;
636         if (AT(GRATE))obj=GRATE;
637         if (obj != 0 && HERE(CHAIN)) return(8000);
638         if (HERE(CHAIN))obj=CHAIN;
639         if (obj == 0) return(2011);
640     }
641         
642     /*  Lock, unlock object.  Special stuff for opening clam/oyster
643      *  and for chain. */
644     if (obj == CLAM || obj == OYSTER)
645         return bivalve(verb, obj);
646     if (obj == DOOR)SPK=111;
647     if (obj == DOOR && game.prop[DOOR] == 1)SPK=54;
648     if (obj == CAGE)SPK=32;
649     if (obj == KEYS)SPK=55;
650     if (obj == GRATE || obj == CHAIN)SPK=31;
651     if (SPK != 31 || !HERE(KEYS)) return(2011);
652     if (obj == CHAIN)
653         return chain(verb);
654     if (game.closng) {
655         SPK=130;
656         if (!game.panic)game.clock2=15;
657         game.panic=true;
658         return(2011);
659     }
660     SPK=34+game.prop[GRATE];
661     game.prop[GRATE]=1;
662     if (verb == LOCK)game.prop[GRATE]=0;
663     SPK=SPK+2*game.prop[GRATE];
664     return(2011);
665 }
666
667 static int pour(token_t obj)
668 /*  Pour.  If no object, or object is bottle, assume contents of bottle.
669  *  special tests for pouring water or oil on plant or rusty door. */
670 {
671     if (obj == BOTTLE || obj == 0)obj=LIQ(0);
672     if (obj == 0) return(8000);
673     if (!TOTING(obj)) return(2011);
674     SPK=78;
675     if (obj != OIL && obj != WATER) return(2011);
676     if (HERE(URN) && game.prop[URN] == 0)
677         return fill(URN);
678     game.prop[BOTTLE]=1;
679     game.place[obj]=0;
680     SPK=77;
681     if (!(AT(PLANT) || AT(DOOR)))
682         return(2011);
683     if (!AT(DOOR)) {
684         SPK=112;
685         if (obj != WATER) return(2011);
686         PSPEAK(PLANT,game.prop[PLANT]+3);
687         game.prop[PLANT]=MOD(game.prop[PLANT]+1,3);
688         game.prop[PLANT2]=game.prop[PLANT];
689         K=NUL;
690         return(8);
691     } else {
692         game.prop[DOOR]=0;
693         if (obj == OIL)game.prop[DOOR]=1;
694         SPK=113+game.prop[DOOR];
695         return(2011);
696     }
697 }
698
699 static int quit(FILE *input)
700 /*  Quit.  Intransitive only.  Verify intent and exit if that's what he wants. */
701 {
702     if (YES(input,22,54,54))
703         score(1);
704     return(2012);
705 }
706
707 static int read(FILE *input, token_t obj)
708 /*  Read.  Print stuff based on objtxt.  Oyster (?) is special case. */
709 {
710     int i;
711     if (obj == INTRANSITIVE) {
712         obj = 0;
713         for (i=1; i<=NOBJECTS; i++) {
714             if (HERE(i) && OBJTXT[i] != 0 && game.prop[i] >= 0)
715                 obj = obj * NOBJECTS + i;
716         }
717         if (obj > NOBJECTS || obj == 0 || DARK(0)) return(8000);
718     }
719         
720     if (DARK(0)) {
721         SETPRM(1,WD1,WD1X);
722         RSPEAK(256);
723         return(2012);
724     }
725     if (OBJTXT[obj] == 0 || game.prop[obj] < 0)
726         return(2011);
727     if (obj == OYSTER && !game.clshnt) {
728         game.clshnt=YES(input,192,193,54);
729         return(2012);
730     }
731     PSPEAK(obj,OBJTXT[obj]+game.prop[obj]);
732     return(2012);
733 }
734
735 static int reservoir(void)
736 /*  Z'ZZZ (word gets recomputed at startup; different each game). */
737 {
738     if (!AT(RESER) && game.loc != game.fixed[RESER]-1) return(2011);
739     PSPEAK(RESER,game.prop[RESER]+1);
740     game.prop[RESER]=1-game.prop[RESER];
741     if (AT(RESER)) return(2012);
742     game.oldlc2=game.loc;
743     game.newloc=0;
744     RSPEAK(241);
745     return(2);
746 }
747
748 static int rub(token_t obj)
749 /* Rub.  Yields various snide remarks except for lit urn. */
750 {
751     if (obj != LAMP)SPK=76;
752     if (obj != URN || game.prop[URN] != 2) return(2011);
753     DSTROY(URN);
754     DROP(AMBER,game.loc);
755     game.prop[AMBER]=1;
756     game.tally=game.tally-1;
757     DROP(CAVITY,game.loc);
758     SPK=216;
759     return(2011);
760 }
761
762 static int say(void)
763 /* SAY.  Echo WD2 (or WD1 if no WD2 (SAY WHAT?, etc.).)  Magic words override. */
764 {
765     /* FIXME: ugly use of globals */
766     SETPRM(1,WD2,WD2X); if (WD2 <= 0)SETPRM(1,WD1,WD1X);
767     if (WD2 > 0)WD1=WD2;
768     int wd=VOCAB(WD1,-1);
769     if (wd == 62 || wd == 65 || wd == 71 || wd == 2025 || wd == 2034) {
770         WD2=0;
771         return(2630);
772     }
773     RSPEAK(258);
774     return(2012);
775
776 }
777
778 static int throw_support(long spk)
779 {
780     RSPEAK(spk);
781     DROP(AXE,game.loc);
782     K=NUL;
783     return(8);
784 }
785
786 static int throw(FILE *cmdin, long verb, long obj)
787 /*  Throw.  Same as discard unless axe.  Then same as attack except
788  *  ignore bird, and if dwarf is present then one might be killed.
789  *  (Only way to do so!)  Axe also special for dragon, bear, and
790  *  troll.  Treasures special for troll. */
791 {
792     if (TOTING(ROD2) && obj == ROD && !TOTING(ROD))obj=ROD2;
793     if (!TOTING(obj))
794         return(2011);
795     if (obj >= 50 && obj <= MAXTRS && AT(TROLL)) {
796         SPK=159;
797         /*  Snarf a treasure for the troll. */
798         DROP(obj,0);
799         MOVE(TROLL,0);
800         MOVE(TROLL+NOBJECTS,0);
801         DROP(TROLL2,PLAC[TROLL]);
802         DROP(TROLL2+NOBJECTS,FIXD[TROLL]);
803         JUGGLE(CHASM);
804         return(2011);
805     }
806     if (obj == FOOD && HERE(BEAR)) {
807     /* But throwing food is another story. */
808         obj=BEAR;
809         return(feed(obj));
810     }
811     if (obj != AXE)
812         return(discard(obj, false));
813     I=ATDWRF(game.loc);
814     if (I <= 0) {
815         if (AT(DRAGON) && game.prop[DRAGON] == 0) {
816             SPK=152;
817             return throw_support(SPK);
818         }
819         if (AT(TROLL)) {
820             SPK=158;
821             return throw_support(SPK);
822         }
823         if (AT(OGRE)) {
824             SPK=203;
825             return throw_support(SPK);
826         }
827         if (HERE(BEAR) && game.prop[BEAR] == 0) {
828             /* This'll teach him to throw the axe at the bear! */
829             SPK=164;
830             DROP(AXE,game.loc);
831             game.fixed[AXE]= -1;
832             game.prop[AXE]=1;
833             JUGGLE(BEAR);
834             return(2011);
835         }
836         return(attack(cmdin, verb, 0));
837     }
838
839     if (randrange(NDWARVES+1) < game.dflag) {
840         SPK=48;
841         return throw_support(SPK);
842     }
843     game.dseen[I]=false;
844     game.dloc[I]=0;
845     SPK=47;
846     game.dkill=game.dkill+1;
847     if (game.dkill == 1)SPK=149;
848
849     return throw_support(SPK);
850 }
851
852 static int vscore(void)
853 /* Score.  Call scoring routine but tell it to return. */
854 {
855     score(-1);
856     return(2012);
857 }
858
859 static int wake(token_t obj)
860 /* Wake.  Only use is to disturb the dwarves. */
861 {
862     if (obj != DWARF || !game.closed) return(2011);
863     SPK=199;
864     return(18999);
865 }
866
867 static int wave(token_t obj)
868 /* Wave.  No effect unless waving rod at fissure or at bird. */
869 {
870     if ((!TOTING(obj)) && (obj != ROD || !TOTING(ROD2)))SPK=29;
871     if (obj != ROD ||
872        !TOTING(obj) ||
873        (!HERE(BIRD) && (game.closng || !AT(FISSUR))))
874         return(2011);
875     if (HERE(BIRD))SPK=206+MOD(game.prop[BIRD],2);
876     if (SPK == 206 && game.loc == game.place[STEPS] && game.prop[JADE] < 0) {
877         DROP(JADE,game.loc);
878         game.prop[JADE]=0;
879         game.tally=game.tally-1;
880         SPK=208;
881         return(2011);
882     } else {
883         if (game.closed) return(18999);
884         if (game.closng || !AT(FISSUR)) return(2011);
885         if (HERE(BIRD))RSPEAK(SPK);
886         game.prop[FISSUR]=1-game.prop[FISSUR];
887         PSPEAK(FISSUR,2-game.prop[FISSUR]);
888         return(2012);
889     }
890 }
891
892 /* This stuff was broken off as part of an effort to get the main program
893  * to compile without running out of memory.  We're called with a number
894  * that says what label the caller wanted to "goto", and we return a
895  * similar label number for the caller to "goto".
896  */
897
898 /*  Analyse a verb.  Remember what it was, go back for object if second word
899  *  unless verb is "say", which snarfs arbitrary second word.
900  */
901
902 int action(FILE *input, long STARTAT, long verb, long obj) {
903         int kk;
904         switch(STARTAT) {
905            case 4000: goto L4000;
906            case 4090: goto L4090;
907            case 5000: goto L5000;
908            }
909         BUG(99);
910
911 L4000:  
912         SPK=ACTSPK[verb];
913         if (WD2 > 0 && verb != SAY) return(2800);
914         if (verb == SAY)obj=WD2;
915         if (obj > 0) goto L4090;
916
917 /*  Analyse an intransitive verb (ie, no object given yet). */
918
919         switch (verb-1) {
920                 case  0: /* CARRY */ goto L8010;
921                 case  1: /* DROP  */ return(8000); 
922                 case  2: /* SAY   */ return(8000); 
923                 case  3: /* UNLOC */ goto L8040;    
924                 case  4: /* NOTHI */ return(2009); 
925                 case  5: /* LOCK  */ goto L8040;    
926                 case  6: /* LIGHT */ goto L8070;    
927                 case  7: /* EXTIN */ goto L8080;    
928                 case  8: /* WAVE  */ return(8000); 
929                 case  9: /* CALM  */ return(8000); 
930                 case 10: /* WALK  */ return(2011); 
931                 case 11: /* ATTAC */ goto L9120;   
932                 case 12: /* POUR  */ goto L9130;   
933                 case 13: /* EAT   */ goto L8140;   
934                 case 14: /* DRINK */ goto L9150;   
935                 case 15: /* RUB   */ return(8000); 
936                 case 16: /* TOSS  */ return(8000); 
937                 case 17: /* QUIT  */ goto L8180;   
938                 case 18: /* FIND  */ return(8000); 
939                 case 19: /* INVEN */ goto L8200;   
940                 case 20: /* FEED  */ return(8000); 
941                 case 21: /* FILL  */ goto L9220;   
942                 case 22: /* BLAST */ goto L9230;   
943                 case 23: /* SCOR  */ goto L8240;   
944                 case 24: /* FOO   */ goto L8250;   
945                 case 25: /* BRIEF */ goto L8260;   
946                 case 26: /* READ  */ goto L8270;   
947                 case 27: /* BREAK */ return(8000); 
948                 case 28: /* WAKE  */ return(8000); 
949                 case 29: /* SUSP  */ goto L8300;   
950                 case 30: /* RESU  */ goto L8310;   
951                 case 31: /* FLY   */ goto L8320;   
952                 case 32: /* LISTE */ goto L8330;   
953                 case 33: /* ZZZZ  */ goto L8340;   
954         }
955         BUG(23);
956
957 /*  Analyse a transitive verb. */
958
959 L4090:  switch (verb-1) {
960                 case  0: /* CARRY */ goto L9010;    
961                 case  1: /* DROP  */ goto L9020;    
962                 case  2: /* SAY   */ goto L9030;    
963                 case  3: /* UNLOC */ goto L9040;    
964                 case  4: /* NOTHI */ return(2009); 
965                 case  5: /* LOCK  */ goto L9040;    
966                 case  6: /* LIGHT */ goto L9070;    
967                 case  7: /* EXTI  */ goto L9080;    
968                 case  8: /* WAVE  */ goto L9090;    
969                 case  9: /* CALM  */ return(2011); 
970                 case 10: /* WALK  */ return(2011); 
971                 case 11: /* ATTAC */ goto L9120;   
972                 case 12: /* POUR  */ goto L9130;   
973                 case 13: /* EAT   */ goto L9140;   
974                 case 14: /* DRINK */ goto L9150;   
975                 case 15: /* RUB   */ goto L9160;   
976                 case 16: /* TOSS  */ goto L9170;   
977                 case 17: /* QUIT  */ return(2011); 
978                 case 18: /* FIND  */ goto L9190;   
979                 case 19: /* INVEN */ goto L9190;   
980                 case 20: /* FEED  */ goto L9210;   
981                 case 21: /* FILL  */ goto L9220;   
982                 case 22: /* BLAST */ goto L9230;   
983                 case 23: /* SCOR  */ return(2011); 
984                 case 24: /* FOO   */ return(2011); 
985                 case 25: /* BRIEF */ return(2011); 
986                 case 26: /* READ  */ goto L9270;   
987                 case 27: /* BREAK */ goto L9280;   
988                 case 28: /* WAKE  */ goto L9290;   
989                 case 29: /* SUSP  */ return(2011); 
990                 case 30: /* RESU  */ return(2011); 
991                 case 31: /* FLY   */ goto L9320;   
992                 case 32: /* LISTE */ return(2011); 
993                 case 33: /* ZZZZ  */ goto L8340;   
994         }
995         BUG(24);
996
997 /*  Analyse an object word.  See if the thing is here, whether we've got a verb
998  *  yet, and so on.  Object must be here unless verb is "find" or "invent(ory)"
999  *  (and no new verb yet to be analysed).  Water and oil are also funny, since
1000  *  they are never actually dropped at any location, but might be here inside
1001  *  the bottle or urn or as a feature of the location. */
1002
1003 L5000:  obj=K;
1004         if (!HERE(K)) goto L5100;
1005 L5010:  if (WD2 > 0) return(2800);
1006         if (verb != 0) goto L4090;
1007         SETPRM(1,WD1,WD1X);
1008         RSPEAK(255);
1009          return(2600);
1010
1011 L5100:  if (K != GRATE) goto L5110;
1012         if (game.loc == 1 || game.loc == 4 || game.loc == 7)K=DPRSSN;
1013         if (game.loc > 9 && game.loc < 15)K=ENTRNC;
1014         if (K != GRATE) return(8);
1015 L5110:  if (K == DWARF && ATDWRF(game.loc) > 0) goto L5010;
1016         if ((LIQ(0) == K && HERE(BOTTLE)) || K == LIQLOC(game.loc)) goto L5010;
1017         if (obj != OIL || !HERE(URN) || game.prop[URN] == 0) goto L5120;
1018         obj=URN;
1019          goto L5010;
1020 L5120:  if (obj != PLANT || !AT(PLANT2) || game.prop[PLANT2] == 0) goto L5130;
1021         obj=PLANT2;
1022          goto L5010;
1023 L5130:  if (obj != KNIFE || game.knfloc != game.loc) goto L5140;
1024         game.knfloc= -1;
1025         SPK=116;
1026          return(2011);
1027 L5140:  if (obj != ROD || !HERE(ROD2)) goto L5190;
1028         obj=ROD2;
1029          goto L5010;
1030 L5190:  if ((verb == FIND || verb == INVENT) && WD2 <= 0) goto L5010;
1031         SETPRM(1,WD1,WD1X);
1032         RSPEAK(256);
1033          return(2012);
1034
1035
1036 /*  Statement numbers in this section are 8000 for intransitive verbs, 9000 for
1037  *  transitive, plus ten times the verb number.  Many intransitive verbs use the
1038  *  transitive code, and some verbs use code for other verbs, as noted below. */
1039
1040 L8010: return carry(INTRANSITIVE);
1041 L9010: return carry(obj);
1042 L9020: return discard(obj, false);
1043 L9030: return say();
1044 L8040: return lock(verb, INTRANSITIVE);
1045 L9040: return lock(verb, obj);
1046 L9046: return bivalve(verb, obj);
1047 L9048: return chain(verb);
1048 L8070: return light(INTRANSITIVE);
1049 L9070: return light(obj);
1050 L8080: return extinguish(INTRANSITIVE);
1051 L9080: return extinguish(obj);
1052 L9090: return wave(obj);
1053 L9120: return attack(input, verb, obj);
1054 L9130: return pour(obj);
1055 L8140: return eat(INTRANSITIVE);
1056 L9140: return eat(obj);
1057 L9150: return drink(obj);
1058 L9160: return rub(obj);
1059 L9170: return throw(input, verb, obj);
1060 L8180: return quit(input);
1061 L9190: return find(obj);
1062 L8200: return inven(obj);
1063 L9210: return feed(obj);
1064 L9220: return fill(obj);
1065 L9230: return blast();
1066 L8240: return vscore();
1067 L8250: return bigwords(WD1);
1068 L8260: return brief();
1069 L8270: return read(input, INTRANSITIVE);
1070 L9270: return read(input, obj);
1071 L9280: return vbreak(obj);
1072 L9290: return wake(obj);
1073
1074 /*  Suspend.  Offer to save things in a file, but charging some points (so
1075  *  can't win by using saved games to retry battles or to start over after
1076  *  learning zzword). */
1077
1078 L8300:  SPK=201;
1079         RSPEAK(260);
1080         if (!YES(input,200,54,54)) return(2012);
1081         game.saved=game.saved+5;
1082         kk= -1;
1083
1084 /*  This next part is shared with the "resume" code.  The two cases are
1085  *  distinguished by the value of kk (-1 for suspend, +1 for resume). */
1086
1087 L8305:  DATIME(&I,&K);
1088         K=I+650*K;
1089         SAVWRD(kk,K);
1090         K=VRSION;
1091         SAVWRD(0,K);
1092         if (K != VRSION) goto L8312;
1093 /*  Herewith are all the variables whose values can change during a game,
1094  *  omitting a few (such as I, J, ATTACK) whose values between turns are
1095  *  irrelevant and some whose values when a game is
1096  *  suspended or resumed are guaranteed to match.  If unsure whether a value
1097  *  needs to be saved, include it.  Overkill can't hurt.  Pad the last savwds
1098  *  with junk variables to bring it up to 7 values. */
1099         SAVWDS(game.abbnum,game.blklin,game.bonus,game.clock1,game.clock2,game.closed,game.closng);
1100         SAVWDS(game.detail,game.dflag,game.dkill,game.dtotal,game.foobar,game.holdng,game.iwest);
1101         SAVWDS(game.knfloc,game.limit,K,game.lmwarn,game.loc,game.newloc,game.numdie);
1102         SAVWDS(K,game.oldlc2,game.oldloc,game.oldobj,game.panic,game.saved,game.setup);
1103         SAVWDS(SPK,game.tally,game.thresh,game.trndex,game.trnluz,game.turns,OBJTXT[OYSTER]);
1104         SAVWDS(K,WD1,WD1X,WD2,game.wzdark,game.zzword,OBJSND[BIRD]);
1105         SAVWDS(OBJTXT[SIGN],game.clshnt,game.novice,K,K,K,K);
1106         SAVARR(game.abbrev,LOCSIZ);
1107         SAVARR(game.atloc,LOCSIZ);
1108         SAVARR(game.dloc,NDWARVES);
1109         SAVARR(game.dseen,NDWARVES);
1110         SAVARR(game.fixed,NOBJECTS);
1111         SAVARR(game.hinted,HNTSIZ);
1112         SAVARR(game.hintlc,HNTSIZ);
1113         SAVARR(game.link,NOBJECTS*2);
1114         SAVARR(game.odloc,NDWARVES);
1115         SAVARR(game.place,NOBJECTS);
1116         SAVARR(game.prop,NOBJECTS);
1117         SAVWRD(kk,K);
1118         if (K != 0) goto L8318;
1119         K=NUL;
1120         game.zzword=RNDVOC(3,game.zzword);
1121         if (kk > 0) return(8);
1122         RSPEAK(266);
1123         exit(0);
1124
1125 /*  Resume.  Read a suspended game back from a file. */
1126
1127 L8310:  kk=1;
1128         if (game.loc == 1 && game.abbrev[1] == 1) goto L8305;
1129         RSPEAK(268);
1130         if (!YES(input,200,54,54)) return(2012);
1131          goto L8305;
1132
1133 L8312:  SETPRM(1,K/10,MOD(K,10));
1134         SETPRM(3,VRSION/10,MOD(VRSION,10));
1135         RSPEAK(269);
1136          return(2000);
1137
1138 L8318:  RSPEAK(270);
1139         exit(0);
1140
1141 L8320: return fly(INTRANSITIVE);
1142 L9320: return fly(obj);
1143 L8330: return listen();
1144 L8340: return reservoir();
1145 }