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