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