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