]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - battlestar/com4.c
Don't say "Kicked." of an object not present; give sensible messages.
[bsdgames-darwin.git] / battlestar / com4.c
1 /* $NetBSD: com4.c,v 1.13 2000/09/22 12:38:10 jsm Exp $ */
2
3 /*
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36 #include <sys/cdefs.h>
37 #ifndef lint
38 #if 0
39 static char sccsid[] = "@(#)com4.c 8.2 (Berkeley) 4/28/95";
40 #else
41 __RCSID("$NetBSD: com4.c,v 1.13 2000/09/22 12:38:10 jsm Exp $");
42 #endif
43 #endif /* not lint */
44
45 #include "extern.h"
46
47 int
48 take(from)
49 unsigned int from[];
50 {
51 int firstnumber, heavy, bulky, value;
52 int n;
53
54 firstnumber = wordnumber;
55 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == OFF) {
56 wordnumber++;
57 wordvalue[wordnumber] = TAKEOFF;
58 return (cypher());
59 } else {
60 wordnumber++;
61 while (wordnumber <= wordcount && wordtype[wordnumber] == OBJECT) {
62 value = wordvalue[wordnumber];
63 printf("%s:\n", objsht[value]);
64 for (n = 0; objsht[value][n]; n++);
65 heavy = (carrying + objwt[value]) <= WEIGHT;
66 bulky = (encumber + objcumber[value]) <= CUMBER;
67 if ((testbit(from, value) || wiz || tempwiz) && heavy && bulky && !testbit(inven, value)) {
68 setbit(inven, value);
69 carrying += objwt[value];
70 encumber += objcumber[value];
71 ourtime++;
72 if (testbit(from, value))
73 printf("Taken.\n");
74 else
75 printf("Zap! Taken from thin air.\n");
76 clearbit(from, value);
77 if (value == MEDALION)
78 win--;
79 } else if (testbit(inven, value))
80 printf("You're already holding%s%s.\n", (objsht[value][n - 1] == 's' ? " " : " a "), objsht[value]);
81 else if (!testbit(from, value))
82 printf("I dont see any %s around here.\n", objsht[value]);
83 else if (!heavy)
84 printf("The %s %s too heavy.\n", objsht[value], (objsht[value][n - 1] == 's' ? "are" : "is"));
85 else
86 printf("The %s %s too cumbersome to hold.\n", objsht[value], (objsht[value][n - 1] == 's' ? "are" : "is"));
87 if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND)
88 wordnumber++;
89 else
90 return (firstnumber);
91 }
92 }
93 /* special cases with their own return()'s */
94
95 if (wordnumber <= wordcount && wordtype[wordnumber] == NOUNS)
96 switch (wordvalue[wordnumber]) {
97
98 case SWORD:
99 if (testbit(from, SWORD)) {
100 wordtype[wordnumber--] = OBJECT;
101 return (take(from));
102 }
103 if (testbit(from, TWO_HANDED)) {
104 wordvalue[wordnumber] = TWO_HANDED;
105 wordtype[wordnumber--] = OBJECT;
106 return (take(from));
107 }
108 wordvalue[wordnumber] = BROAD;
109 wordtype[wordnumber--] = OBJECT;
110 return (take(from));
111
112 case BODY:
113 if (testbit(from, MAID)) {
114 wordvalue[wordnumber] = MAID;
115 wordtype[wordnumber--] = OBJECT;
116 return (take(from));
117 } else if (testbit(from, DEADWOOD)) {
118 wordvalue[wordnumber] = DEADWOOD;
119 wordtype[wordnumber--] = OBJECT;
120 return (take(from));
121 } else if (testbit(from, DEADNATIVE)) {
122 wordvalue[wordnumber] = DEADNATIVE;
123 wordtype[wordnumber--] = OBJECT;
124 return (take(from));
125 } else {
126 if (testbit(from, DEADGOD)) {
127 wordvalue[wordnumber] = DEADGOD;
128 wordtype[wordnumber--] = OBJECT;
129 return (take(from));
130 } else {
131 wordvalue[wordnumber] = DEADTIME;
132 wordtype[wordnumber--] = OBJECT;
133 return (take(from));
134 }
135 }
136 break;
137
138 case AMULET:
139 if (testbit(location[position].objects, AMULET)) {
140 puts("The amulet is warm to the touch, and its beauty catches your breath.");
141 puts("A mist falls over your eyes, but then it is gone. Sounds seem clearer");
142 puts("and sharper but far away as if in a dream. The sound of purling water");
143 puts("reaches you from afar. The mist falls again, and your heart leaps in horror.");
144 puts("The gold freezes your hands and fathomless darkness engulfs your soul.");
145 }
146 wordtype[wordnumber--] = OBJECT;
147 return (take(from));
148
149 case MEDALION:
150 if (testbit(location[position].objects, MEDALION)) {
151 puts("The medallion is warm, and it rekindles your spirit with the warmth of life.");
152 puts("Your amulet begins to glow as the medallion is brought near to it, and together\nthey radiate.");
153 }
154 wordtype[wordnumber--] = OBJECT;
155 return (take(from));
156
157 case TALISMAN:
158 if (testbit(location[position].objects, TALISMAN)) {
159 puts("The talisman is cold to the touch, and it sends a chill down your spine.");
160 }
161 wordtype[wordnumber--] = OBJECT;
162 return (take(from));
163
164 case NORMGOD:
165 if (testbit(location[position].objects, BATHGOD) && (testbit(wear, AMULET) || testbit(inven, AMULET))) {
166 puts("She offers a delicate hand, and you help her out of the sparkling springs.");
167 puts("Water droplets like liquid silver bedew her golden skin, but when they part");
168 puts("from her, they fall as teardrops. She wraps a single cloth around her and");
169 puts("ties it at the waist. Around her neck hangs a golden amulet.");
170 puts("She bids you to follow her, and walks away.");
171 pleasure++;
172 followgod = ourtime;
173 clearbit(location[position].objects, BATHGOD);
174 } else
175 if (!testbit(location[position].objects, BATHGOD))
176 puts("You're in no position to take her.");
177 else
178 puts("She moves away from you.");
179 break;
180
181 default:
182 puts("It doesn't seem to work.");
183 }
184 else
185 puts("You've got to be kidding.");
186 return (firstnumber);
187 }
188
189 int
190 throw(name)
191 const char *name;
192 {
193 unsigned int n;
194 int deposit = 0;
195 int first, value;
196
197 first = wordnumber;
198 if (drop(name) != -1) {
199 switch (wordvalue[wordnumber]) {
200
201 case AHEAD:
202 deposit = ahead;
203 break;
204
205 case BACK:
206 deposit = back;
207 break;
208
209 case LEFT:
210 deposit = left;
211 break;
212
213 case RIGHT:
214 deposit = right;
215 break;
216
217 case UP:
218 deposit = location[position].up * (location[position].access || position == FINAL);
219 break;
220
221 case DOWN:
222 deposit = location[position].down;
223 break;
224 }
225 wordnumber = first + 1;
226 while (wordnumber <= wordcount) {
227 value = wordvalue[wordnumber];
228 if (deposit && testbit(location[position].objects, value)) {
229 clearbit(location[position].objects, value);
230 if (value != GRENADE)
231 setbit(location[deposit].objects, value);
232 else {
233 puts("A thundering explosion nearby sends up a cloud of smoke and shrapnel.");
234 for (n = 0; n < NUMOFWORDS; n++)
235 location[deposit].objects[n] = 0;
236 setbit(location[deposit].objects, CHAR);
237 }
238 if (value == ROPE && position == FINAL)
239 location[position].access = 1;
240 switch (deposit) {
241 case 189:
242 case 231:
243 puts("The stone door is unhinged.");
244 location[189].north = 231;
245 location[231].south = 189;
246 break;
247 case 30:
248 puts("The wooden door is blown open.");
249 location[30].west = 25;
250 break;
251 case 31:
252 puts("The door is not damaged.");
253 }
254 } else
255 if (value == GRENADE && testbit(location[position].objects, value)) {
256 puts("You are blown into shreds when your grenade explodes.");
257 die();
258 }
259 if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND)
260 wordnumber++;
261 else
262 return (first);
263 }
264 return (first);
265 }
266 return (first);
267 }
268
269 int
270 drop(name)
271 const char *name;
272 {
273
274 int firstnumber, value;
275
276 firstnumber = wordnumber;
277 wordnumber++;
278 while (wordnumber <= wordcount && (wordtype[wordnumber] == OBJECT || wordtype[wordnumber] == NOUNS)) {
279 value = wordvalue[wordnumber];
280 printf("%s:\n", objsht[value]);
281 if (testbit(inven, value)) {
282 clearbit(inven, value);
283 carrying -= objwt[value];
284 encumber -= objcumber[value];
285 if (value == BOMB) {
286 puts("The bomb explodes. A blinding white light and immense concussion obliterate us.");
287 die();
288 }
289 if (value != AMULET && value != MEDALION && value != TALISMAN)
290 setbit(location[position].objects, value);
291 else
292 tempwiz = 0;
293 ourtime++;
294 if (*name == 'K')
295 puts("Drop kicked.");
296 else
297 printf("%s.\n", name);
298 } else {
299 if (*name != 'K') {
300 printf("You aren't holding the %s.\n", objsht[value]);
301 if (testbit(location[position].objects, value)) {
302 if (*name == 'T')
303 puts("Kicked instead.");
304 else if (*name == 'G')
305 puts("Given anyway.");
306 }
307 } else if (testbit(location[position].objects, value))
308 puts("Kicked.");
309 else if (testbit(wear, value))
310 puts("Not while it's being worn.");
311 else
312 puts("Not found.");
313 }
314 if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND)
315 wordnumber++;
316 else
317 return (firstnumber);
318 }
319 puts("Do what?");
320 return (-1);
321 }
322
323 int
324 takeoff()
325 {
326 wordnumber = take(wear);
327 return (drop("Dropped"));
328 }
329
330 int
331 puton()
332 {
333 wordnumber = take(location[position].objects);
334 return (wearit());
335 }
336
337 int
338 eat()
339 {
340 int firstnumber, value;
341
342 firstnumber = wordnumber;
343 wordnumber++;
344 while (wordnumber <= wordcount) {
345 value = wordvalue[wordnumber];
346 switch (value) {
347
348 case -1:
349 puts("Eat what?");
350 return (firstnumber);
351
352 default:
353 printf("You can't eat%s%s!\n",
354 wordtype[wordnumber] == OBJECT &&
355 objsht[value]
356 [strlen(objsht[value]) - 1] == 's' ?
357 " " : " a ",
358 words[wordnumber]);
359 return (firstnumber);
360
361 case PAPAYAS:
362 case PINEAPPLE:
363 case KIWI:
364 case COCONUTS: /* eatable things */
365 case MANGO:
366
367 printf("%s:\n", objsht[value]);
368 if (testbit(inven, value) &&
369 ourtime > ate - CYCLE &&
370 testbit(inven, KNIFE)) {
371 clearbit(inven, value);
372 carrying -= objwt[value];
373 encumber -= objcumber[value];
374 ate = max(ourtime, ate) + CYCLE / 3;
375 snooze += CYCLE / 10;
376 ourtime++;
377 puts("Eaten. You can explore a little longer now.");
378 } else if (ourtime < ate - CYCLE)
379 puts("You're stuffed.");
380 else if (!testbit(inven, KNIFE))
381 puts("You need a knife.");
382 else
383 printf("You aren't holding the %s.\n", objsht[value]);
384 if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND)
385 wordnumber++;
386 else
387 return (firstnumber);
388 } /* end switch */
389 } /* end while */
390 return (firstnumber);
391 }