De-gotoify feed().
[open-adventure.git] / actions2.c
1 #include "advent.h"
2 #include "funcs.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 /*  Throw.  Same as discard unless axe.  Then same as attack except ignore bird,
223  *  and if dwarf is present then one might be killed.  (Only way to do so!)
224  *  Axe also special for dragon, bear, and troll.  Treasures special for troll. */
225
226 int throw(FILE *cmdin, long obj, long verb) {
227         if (TOTING(ROD2) && obj == ROD && !TOTING(ROD))obj=ROD2;
228         if (!TOTING(obj)) return(2011);
229         if (obj >= 50 && obj <= MAXTRS && AT(TROLL)) goto L9178;
230         if (obj == FOOD && HERE(BEAR)) goto L9177;
231         if (obj != AXE) return(discard(obj, false));
232         I=ATDWRF(game.loc);
233         if (I > 0) goto L9172;
234         SPK=152;
235         if (AT(DRAGON) && game.prop[DRAGON] == 0) goto L9175;
236         SPK=158;
237         if (AT(TROLL)) goto L9175;
238         SPK=203;
239         if (AT(OGRE)) goto L9175;
240         if (HERE(BEAR) && game.prop[BEAR] == 0) goto L9176;
241         obj=0;
242         return(attack(cmdin, obj, verb));
243
244 L9172:  SPK=48;
245         if (randrange(NDWARVES+1) < game.dflag) goto L9175;
246         game.dseen[I]=false;
247         game.dloc[I]=0;
248         SPK=47;
249         game.dkill=game.dkill+1;
250         if (game.dkill == 1)SPK=149;
251 L9175:  RSPEAK(SPK);
252         DROP(AXE,game.loc);
253         K=NUL;
254          return(8);
255
256 /*  This'll teach him to throw the axe at the bear! */
257 L9176:  SPK=164;
258         DROP(AXE,game.loc);
259         game.fixed[AXE]= -1;
260         game.prop[AXE]=1;
261         JUGGLE(BEAR);
262          return(2011);
263
264 /*  But throwing food is another story. */
265 L9177:  obj=BEAR;
266         return(feed(obj));
267
268 L9178:  SPK=159;
269 /*  Snarf a treasure for the troll. */
270         DROP(obj,0);
271         MOVE(TROLL,0);
272         MOVE(TROLL+NOBJECTS,0);
273         DROP(TROLL2,PLAC[TROLL]);
274         DROP(TROLL2+NOBJECTS,FIXD[TROLL]);
275         JUGGLE(CHASM);
276          return(2011);
277 }
278
279 int feed(long obj)
280 /*  Feed.  If bird, no seed.  Snake, dragon, troll: quip.  If dwarf, make him
281  *  mad.  Bear, special. */
282 {
283     if (obj == BIRD) {
284         SPK=100;
285         return(2011);
286     }
287
288     if (!(obj != SNAKE && obj != DRAGON && obj != TROLL)) {
289         SPK=102;
290         if (obj == DRAGON && game.prop[DRAGON] != 0)SPK=110;
291         if (obj == TROLL)SPK=182;
292         if (obj != SNAKE || game.closed || !HERE(BIRD))
293             return(2011);
294         SPK=101;
295         DSTROY(BIRD);
296         game.prop[BIRD]=0;
297         return(2011);
298     }
299
300     if (obj == DWARF) {
301         if (!HERE(FOOD))
302             return(2011);
303         SPK=103;
304         game.dflag=game.dflag+2;
305         return(2011);
306     }
307
308     if (obj == BEAR) {
309         if (game.prop[BEAR] == 0)SPK=102;
310         if (game.prop[BEAR] == 3)SPK=110;
311         if (!HERE(FOOD))
312             return(2011);
313         DSTROY(FOOD);
314         game.prop[BEAR]=1;
315         game.fixed[AXE]=0;
316         game.prop[AXE]=0;
317         SPK=168;
318         return(2011);
319     }
320
321     if (obj == OGRE) {
322         if (HERE(FOOD))
323             SPK=202;
324         return(2011);
325     }
326
327     SPK=14;
328     return(2011);
329 }
330
331 int fill(long obj)
332 /*  Fill.  Bottle or urn must be empty, and liquid available.  (Vase
333  *  is nasty.) */
334 {
335     if (obj == VASE) {
336         SPK=29;
337         if (LIQLOC(game.loc) == 0)SPK=144;
338         if (LIQLOC(game.loc) == 0 || !TOTING(VASE))
339             return(2011);
340         RSPEAK(145);
341         game.prop[VASE]=2;
342         game.fixed[VASE]= -1;
343         return(discard(obj, true));
344     }
345
346     if (obj == URN){
347         SPK=213;
348         if (game.prop[URN] != 0) return(2011);
349         SPK=144;
350         K=LIQ(0);
351         if (K == 0 || !HERE(BOTTLE)) return(2011);
352         game.place[K]=0;
353         game.prop[BOTTLE]=1;
354         if (K == OIL)game.prop[URN]=1;
355         SPK=211+game.prop[URN];
356         return(2011);
357     }
358
359     if (obj != 0 && obj != BOTTLE)
360         return(2011);
361     if (obj == 0 && !HERE(BOTTLE))
362         return(8000);
363     SPK=107;
364     if (LIQLOC(game.loc) == 0)
365         SPK=106;
366     if (HERE(URN) && game.prop[URN] != 0)
367         SPK=214;
368     if (LIQ(0) != 0)
369         SPK=105;
370     if (SPK != 107)
371         return(2011);
372     game.prop[BOTTLE]=MOD(COND[game.loc],4)/2*2;
373     K=LIQ(0);
374     if (TOTING(BOTTLE))
375         game.place[K]= -1;
376     if (K == OIL)
377         SPK=108;
378     return(2011);
379 }