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