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