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