De-gotoize throw().
[open-adventure.git] / actions2.c
1 #include "advent.h"
2 #include "database.h"
3
4 /*  Carry an object.  Special cases for bird and cage (if bird in cage, can't
5  *  take one without the other).  Liquids also special, since they depend on
6  *  status of bottle.  Also various side effects, etc. */
7
8 int carry(long obj)
9 {
10     if (TOTING(obj)) return(2011);
11     SPK=25;
12     if (obj == PLANT && game.prop[PLANT] <= 0)SPK=115;
13     if (obj == BEAR && game.prop[BEAR] == 1)SPK=169;
14     if (obj == CHAIN && game.prop[BEAR] != 0)SPK=170;
15     if (obj == URN)SPK=215;
16     if (obj == CAVITY)SPK=217;
17     if (obj == BLOOD)SPK=239;
18     if (obj == RUG && game.prop[RUG] == 2)SPK=222;
19     if (obj == SIGN)SPK=196;
20     if (obj == MESSAG) {
21         SPK=190;
22         DSTROY(MESSAG);
23     }
24     if (game.fixed[obj] != 0)
25         return(2011);
26     if (obj == WATER || obj == OIL) {
27         if (!HERE(BOTTLE) || LIQ(0) != obj) {
28             if (TOTING(BOTTLE) && game.prop[BOTTLE] == 1)
29                 return(fill(BOTTLE));
30             if (game.prop[BOTTLE] != 1)SPK=105;
31             if (!TOTING(BOTTLE))SPK=104;
32             return(2011);
33         }
34         obj = BOTTLE;
35     }
36
37     SPK=92;
38     if (game.holdng >= INVLIMIT)
39         return(2011);
40     if (obj == BIRD && game.prop[BIRD] != 1 && -1-game.prop[BIRD] != 1) {
41         if (game.prop[BIRD] == 2) {
42             SPK=238;
43             DSTROY(BIRD);
44             return(2011);
45         }
46         if (!TOTING(CAGE))SPK=27;
47         if (TOTING(ROD))SPK=26;
48         if (SPK/2 == 13) return(2011);
49         game.prop[BIRD]=1;
50     }
51     if ((obj==BIRD || obj==CAGE) && (game.prop[BIRD]==1 || -1-game.prop[BIRD]==1))
52         CARRY(BIRD+CAGE-obj,game.loc);
53     CARRY(obj,game.loc);
54     if (obj == BOTTLE && LIQ(0) != 0)
55         game.place[LIQ(0)] = -1;
56     if (!GSTONE(obj) || game.prop[obj] == 0)
57         return(2009);
58     game.prop[obj]=0;
59     game.prop[CAVITY]=1;
60     return(2009);
61 }
62
63 /*  Discard object.  "Throw" also comes here for most objects.  Special cases for
64  *  bird (might attack snake or dragon) and cage (might contain bird) and vase.
65  *  Drop coins at vending machine for extra batteries. */
66
67 int discard(long obj, bool just_do_it) {
68         if (just_do_it) goto L9021;
69         if (TOTING(ROD2) && obj == ROD && !TOTING(ROD))obj=ROD2;
70         if (!TOTING(obj)) return(2011);
71         if (obj != BIRD || !HERE(SNAKE)) goto L9023;
72         RSPEAK(30);
73         if (game.closed) return(19000);
74         DSTROY(SNAKE);
75         /* Set game.prop for use by travel options */
76         game.prop[SNAKE]=1;
77 L9021:  K=LIQ(0);
78         if (K == obj)obj=BOTTLE;
79         if (obj == BOTTLE && K != 0)game.place[K]=0;
80         if (obj == CAGE && game.prop[BIRD] == 1)DROP(BIRD,game.loc);
81         DROP(obj,game.loc);
82         if (obj != BIRD) return(2012);
83         game.prop[BIRD]=0;
84         if (FOREST(game.loc))game.prop[BIRD]=2;
85          return(2012);
86
87 L9023:  if (!(GSTONE(obj) && AT(CAVITY) && game.prop[CAVITY] != 0)) goto L9024;
88         RSPEAK(218);
89         game.prop[obj]=1;
90         game.prop[CAVITY]=0;
91         if (!HERE(RUG) || !((obj == EMRALD && game.prop[RUG] != 2) || (obj == RUBY &&
92                 game.prop[RUG] == 2))) goto L9021;
93         SPK=219;
94         if (TOTING(RUG))SPK=220;
95         if (obj == RUBY)SPK=221;
96         RSPEAK(SPK);
97         if (SPK == 220) goto L9021;
98         K=2-game.prop[RUG];
99         game.prop[RUG]=K;
100         if (K == 2)K=PLAC[SAPPH];
101         MOVE(RUG+NOBJECTS,K);
102          goto L9021;
103
104 L9024:  if (obj != COINS || !HERE(VEND)) goto L9025;
105         DSTROY(COINS);
106         DROP(BATTER,game.loc);
107         PSPEAK(BATTER,0);
108          return(2012);
109
110 L9025:  if (obj != BIRD || !AT(DRAGON) || game.prop[DRAGON] != 0) goto L9026;
111         RSPEAK(154);
112         DSTROY(BIRD);
113         game.prop[BIRD]=0;
114          return(2012);
115
116 L9026:  if (obj != BEAR || !AT(TROLL)) goto L9027;
117         RSPEAK(163);
118         MOVE(TROLL,0);
119         MOVE(TROLL+NOBJECTS,0);
120         MOVE(TROLL2,PLAC[TROLL]);
121         MOVE(TROLL2+NOBJECTS,FIXD[TROLL]);
122         JUGGLE(CHASM);
123         game.prop[TROLL]=2;
124          goto L9021;
125
126 L9027:  if (obj == VASE && game.loc != PLAC[PILLOW]) goto L9028;
127         RSPEAK(54);
128          goto L9021;
129
130 L9028:  game.prop[VASE]=2;
131         if (AT(PILLOW))game.prop[VASE]=0;
132         PSPEAK(VASE,game.prop[VASE]+1);
133         if (game.prop[VASE] != 0)game.fixed[VASE]= -1;
134          goto L9021;
135 }
136
137 /*  Attack.  Assume target if unambiguous.  "Throw" also links here.  Attackable
138  *  objects fall into two categories: enemies (snake, dwarf, etc.)  and others
139  *  (bird, clam, machine).  Ambiguous if 2 enemies, or no enemies but 2 others. */
140
141 int attack(FILE *input, long obj, long verb) {
142         I=ATDWRF(game.loc);
143         if (obj != 0) goto L9124;
144         if (I > 0)obj=DWARF;
145         if (HERE(SNAKE))obj=obj*NOBJECTS+SNAKE;
146         if (AT(DRAGON) && game.prop[DRAGON] == 0)obj=obj*NOBJECTS+DRAGON;
147         if (AT(TROLL))obj=obj*NOBJECTS+TROLL;
148         if (AT(OGRE))obj=obj*NOBJECTS+OGRE;
149         if (HERE(BEAR) && game.prop[BEAR] == 0)obj=obj*NOBJECTS+BEAR;
150         if (obj > NOBJECTS) return(8000);
151         if (obj != 0) goto L9124;
152         /* Can't attack bird or machine by throwing axe. */
153         if (HERE(BIRD) && verb != THROW)obj=BIRD;
154         if (HERE(VEND) && verb != THROW)obj=obj*NOBJECTS+VEND;
155         /* Clam and oyster both treated as clam for intransitive case;
156          * no harm done. */
157         if (HERE(CLAM) || HERE(OYSTER))obj=NOBJECTS*obj+CLAM;
158         if (obj > NOBJECTS) return(8000);
159 L9124:  if (obj == BIRD) {
160                 SPK=137;
161                 if (game.closed) return(2011);
162                 DSTROY(BIRD);
163                 game.prop[BIRD]=0;
164                 SPK=45;
165         }
166 L9125:  if (obj == VEND) {
167             PSPEAK(VEND,game.prop[VEND]+2);
168             game.prop[VEND]=3-game.prop[VEND];
169             return(2012);
170         }
171
172         if (obj == 0)SPK=44;
173         if (obj == CLAM || obj == OYSTER)SPK=150;
174         if (obj == SNAKE)SPK=46;
175         if (obj == DWARF)SPK=49;
176         if (obj == DWARF && game.closed) return(19000);
177         if (obj == DRAGON)SPK=167;
178         if (obj == TROLL)SPK=157;
179         if (obj == OGRE)SPK=203;
180         if (obj == OGRE && I > 0) goto L9128;
181         if (obj == BEAR)SPK=165+(game.prop[BEAR]+1)/2;
182         if (obj != DRAGON || game.prop[DRAGON] != 0) return(2011);
183         /*  Fun stuff for dragon.  If he insists on attacking it, win!
184          *  Set game.prop to dead, move dragon to central loc (still
185          *  fixed), move rug there (not fixed), and move him there,
186          *  too.  Then do a null motion to get new description. */
187         RSPEAK(49);
188         GETIN(input,WD1,WD1X,WD2,WD2X);
189         if (WD1 != MAKEWD(25) && WD1 != MAKEWD(250519)) return(2607);
190         PSPEAK(DRAGON,3);
191         game.prop[DRAGON]=1;
192         game.prop[RUG]=0;
193         K=(PLAC[DRAGON]+FIXD[DRAGON])/2;
194         MOVE(DRAGON+NOBJECTS,-1);
195         MOVE(RUG+NOBJECTS,0);
196         MOVE(DRAGON,K);
197         MOVE(RUG,K);
198         DROP(BLOOD,K);
199         for (obj=1; obj<=NOBJECTS; obj++) {
200         if (game.place[obj] == PLAC[DRAGON] || game.place[obj] == FIXD[DRAGON])MOVE(obj,K);
201         /*etc*/ ;
202         } /* end loop */
203         game.loc=K;
204         K=NUL;
205          return(8);
206
207 L9128:  RSPEAK(SPK);
208         RSPEAK(6);
209         DSTROY(OGRE);
210         K=0;
211         for (I=1; I < PIRATE; I++) {
212                 if (game.dloc[I] == game.loc) {
213                         K=K+1;
214                         game.dloc[I]=61;
215                         game.dseen[I]=false;
216                 }
217         }
218         SPK=SPK+1+1/K;
219         return(2011);
220 }
221
222 int throw_support(long spk)
223 {
224     RSPEAK(spk);
225     DROP(AXE,game.loc);
226     K=NUL;
227     return(8);
228 }
229
230 int throw(FILE *cmdin, long obj, long verb)
231 /*  Throw.  Same as discard unless axe.  Then same as attack except
232  *  ignore bird, and if dwarf is present then one might be killed.
233  *  (Only way to do so!)  Axe also special for dragon, bear, and
234  *  troll.  Treasures special for troll. */
235 {
236     if (TOTING(ROD2) && obj == ROD && !TOTING(ROD))obj=ROD2;
237     if (!TOTING(obj))
238         return(2011);
239     if (obj >= 50 && obj <= MAXTRS && AT(TROLL)) {
240         SPK=159;
241         /*  Snarf a treasure for the troll. */
242         DROP(obj,0);
243         MOVE(TROLL,0);
244         MOVE(TROLL+NOBJECTS,0);
245         DROP(TROLL2,PLAC[TROLL]);
246         DROP(TROLL2+NOBJECTS,FIXD[TROLL]);
247         JUGGLE(CHASM);
248         return(2011);
249     }
250     if (obj == FOOD && HERE(BEAR)) {
251     /* But throwing food is another story. */
252         obj=BEAR;
253         return(feed(obj));
254     }
255     if (obj != AXE)
256         return(discard(obj, false));
257     I=ATDWRF(game.loc);
258     if (I <= 0) {
259         if (AT(DRAGON) && game.prop[DRAGON] == 0) {
260             SPK=152;
261             return throw_support(SPK);
262         }
263         if (AT(TROLL)) {
264             SPK=158;
265             return throw_support(SPK);
266         }
267         if (AT(OGRE)) {
268             SPK=203;
269             return throw_support(SPK);
270         }
271         if (HERE(BEAR) && game.prop[BEAR] == 0) {
272             /* This'll teach him to throw the axe at the bear! */
273             SPK=164;
274             DROP(AXE,game.loc);
275             game.fixed[AXE]= -1;
276             game.prop[AXE]=1;
277             JUGGLE(BEAR);
278             return(2011);
279         }
280         return(attack(cmdin, 0, verb));
281     }
282
283     if (randrange(NDWARVES+1) < game.dflag) {
284         SPK=48;
285         return throw_support(SPK);
286     }
287     game.dseen[I]=false;
288     game.dloc[I]=0;
289     SPK=47;
290     game.dkill=game.dkill+1;
291     if (game.dkill == 1)SPK=149;
292
293     return throw_support(SPK);
294 }
295
296 int feed(long obj)
297 /*  Feed.  If bird, no seed.  Snake, dragon, troll: quip.  If dwarf, make him
298  *  mad.  Bear, special. */
299 {
300     if (obj == BIRD) {
301         SPK=100;
302         return(2011);
303     }
304
305     if (!(obj != SNAKE && obj != DRAGON && obj != TROLL)) {
306         SPK=102;
307         if (obj == DRAGON && game.prop[DRAGON] != 0)SPK=110;
308         if (obj == TROLL)SPK=182;
309         if (obj != SNAKE || game.closed || !HERE(BIRD))
310             return(2011);
311         SPK=101;
312         DSTROY(BIRD);
313         game.prop[BIRD]=0;
314         return(2011);
315     }
316
317     if (obj == DWARF) {
318         if (!HERE(FOOD))
319             return(2011);
320         SPK=103;
321         game.dflag=game.dflag+2;
322         return(2011);
323     }
324
325     if (obj == BEAR) {
326         if (game.prop[BEAR] == 0)SPK=102;
327         if (game.prop[BEAR] == 3)SPK=110;
328         if (!HERE(FOOD))
329             return(2011);
330         DSTROY(FOOD);
331         game.prop[BEAR]=1;
332         game.fixed[AXE]=0;
333         game.prop[AXE]=0;
334         SPK=168;
335         return(2011);
336     }
337
338     if (obj == OGRE) {
339         if (HERE(FOOD))
340             SPK=202;
341         return(2011);
342     }
343
344     SPK=14;
345     return(2011);
346 }
347
348 int fill(long obj)
349 /*  Fill.  Bottle or urn must be empty, and liquid available.  (Vase
350  *  is nasty.) */
351 {
352     int k;
353     if (obj == VASE) {
354         SPK=29;
355         if (LIQLOC(game.loc) == 0)SPK=144;
356         if (LIQLOC(game.loc) == 0 || !TOTING(VASE))
357             return(2011);
358         RSPEAK(145);
359         game.prop[VASE]=2;
360         game.fixed[VASE]= -1;
361         return(discard(obj, true));
362     }
363
364     if (obj == URN){
365         SPK=213;
366         if (game.prop[URN] != 0) return(2011);
367         SPK=144;
368         k=LIQ(0);
369         if (k == 0 || !HERE(BOTTLE)) return(2011);
370         game.place[k]=0;
371         game.prop[BOTTLE]=1;
372         if (k == OIL)game.prop[URN]=1;
373         SPK=211+game.prop[URN];
374         return(2011);
375     }
376
377     if (obj != 0 && obj != BOTTLE)
378         return(2011);
379     if (obj == 0 && !HERE(BOTTLE))
380         return(8000);
381     SPK=107;
382     if (LIQLOC(game.loc) == 0)
383         SPK=106;
384     if (HERE(URN) && game.prop[URN] != 0)
385         SPK=214;
386     if (LIQ(0) != 0)
387         SPK=105;
388     if (SPK != 107)
389         return(2011);
390     game.prop[BOTTLE]=MOD(COND[game.loc],4)/2*2;
391     k=LIQ(0);
392     if (TOTING(BOTTLE))
393         game.place[k]= -1;
394     if (k == OIL)
395         SPK=108;
396     return(2011);
397 }