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