command3.c revision 1.6 1 1.6 rillig /* $NetBSD: command3.c,v 1.6 2021/05/02 12:50:43 rillig 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.2 agc * 3. Neither the name of the University nor the names of its contributors
16 1.1 tv * may be used to endorse or promote products derived from this software
17 1.1 tv * without specific prior written permission.
18 1.1 tv *
19 1.1 tv * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 1.1 tv * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.1 tv * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.1 tv * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 1.1 tv * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.1 tv * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.1 tv * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.1 tv * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.1 tv * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.1 tv * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.1 tv * SUCH DAMAGE.
30 1.1 tv */
31 1.1 tv
32 1.1 tv #include <sys/cdefs.h>
33 1.1 tv #ifndef lint
34 1.1 tv #if 0
35 1.1 tv static char sccsid[] = "@(#)com3.c 8.2 (Berkeley) 4/28/95";
36 1.1 tv #else
37 1.6 rillig __RCSID("$NetBSD: command3.c,v 1.6 2021/05/02 12:50:43 rillig Exp $");
38 1.1 tv #endif
39 1.1 tv #endif /* not lint */
40 1.1 tv
41 1.1 tv #include "extern.h"
42 1.1 tv
43 1.1 tv void
44 1.3 jmc dig(void)
45 1.1 tv {
46 1.1 tv if (testbit(inven, SHOVEL)) {
47 1.1 tv puts("OK");
48 1.1 tv ourtime++;
49 1.1 tv switch (position) {
50 1.1 tv case 144: /* copse near beach */
51 1.1 tv if (!notes[DUG]) {
52 1.1 tv setbit(location[position].objects, DEADWOOD);
53 1.1 tv setbit(location[position].objects, COMPASS);
54 1.1 tv setbit(location[position].objects, KNIFE);
55 1.1 tv setbit(location[position].objects, MACE);
56 1.1 tv notes[DUG] = 1;
57 1.1 tv }
58 1.1 tv break;
59 1.1 tv
60 1.1 tv default:
61 1.1 tv puts("Nothing happens.");
62 1.1 tv }
63 1.1 tv } else
64 1.1 tv puts("You don't have a shovel.");
65 1.1 tv }
66 1.1 tv
67 1.1 tv int
68 1.3 jmc jump(void)
69 1.1 tv {
70 1.1 tv int n;
71 1.1 tv
72 1.1 tv switch (position) {
73 1.1 tv default:
74 1.1 tv puts("Nothing happens.");
75 1.1 tv return (-1);
76 1.1 tv
77 1.1 tv case 242:
78 1.1 tv position = 133;
79 1.1 tv break;
80 1.1 tv case 214:
81 1.1 tv case 215:
82 1.1 tv case 162:
83 1.1 tv case 159:
84 1.1 tv position = 145;
85 1.1 tv break;
86 1.1 tv case 232:
87 1.1 tv position = FINAL;
88 1.1 tv break;
89 1.1 tv case 3:
90 1.1 tv position = 1;
91 1.1 tv break;
92 1.1 tv case 172:
93 1.1 tv position = 201;
94 1.1 tv }
95 1.1 tv puts("Ahhhhhhh...");
96 1.1 tv injuries[12] = injuries[8] = injuries[7] = injuries[6] = 1;
97 1.1 tv for (n = 0; n < NUMOFOBJECTS; n++)
98 1.1 tv if (testbit(inven, n)) {
99 1.1 tv clearbit(inven, n);
100 1.1 tv setbit(location[position].objects, n);
101 1.1 tv }
102 1.1 tv carrying = 0;
103 1.1 tv encumber = 0;
104 1.1 tv return (0);
105 1.1 tv }
106 1.1 tv
107 1.1 tv void
108 1.3 jmc bury(void)
109 1.1 tv {
110 1.1 tv int value;
111 1.1 tv
112 1.1 tv if (testbit(inven, SHOVEL)) {
113 1.6 rillig while (wordtype[++wordnumber] != OBJECT &&
114 1.3 jmc wordtype[wordnumber] != NOUNS && wordnumber < wordcount)
115 1.1 tv continue;
116 1.1 tv value = wordvalue[wordnumber];
117 1.6 rillig if (wordtype[wordnumber] == NOUNS &&
118 1.6 rillig (testbit(location[position].objects, value) ||
119 1.3 jmc value == BODY))
120 1.1 tv switch (value) {
121 1.1 tv case BODY:
122 1.1 tv wordtype[wordnumber] = OBJECT;
123 1.6 rillig if (testbit(inven, MAID) ||
124 1.3 jmc testbit(location[position].objects, MAID))
125 1.1 tv value = MAID;
126 1.6 rillig if (testbit(inven, DEADWOOD) ||
127 1.6 rillig testbit(location[position].objects,
128 1.3 jmc DEADWOOD))
129 1.1 tv value = DEADWOOD;
130 1.6 rillig if (testbit(inven, DEADGOD) ||
131 1.6 rillig testbit(location[position].objects,
132 1.3 jmc DEADGOD))
133 1.1 tv value = DEADGOD;
134 1.6 rillig if (testbit(inven, DEADTIME) ||
135 1.6 rillig testbit(location[position].objects,
136 1.3 jmc DEADTIME))
137 1.1 tv value = DEADTIME;
138 1.6 rillig if (testbit(inven, DEADNATIVE) ||
139 1.6 rillig testbit(location[position].objects,
140 1.3 jmc DEADNATIVE))
141 1.1 tv value = DEADNATIVE;
142 1.1 tv break;
143 1.1 tv
144 1.1 tv case NATIVE:
145 1.1 tv case NORMGOD:
146 1.3 jmc printf("She screams as you wrestle her into ");
147 1.3 jmc puts("the hole.");
148 1.5 mrg /* FALLTHROUGH */
149 1.1 tv case TIMER:
150 1.1 tv power += 7;
151 1.1 tv ego -= 10;
152 1.5 mrg /* FALLTHROUGH */
153 1.1 tv case AMULET:
154 1.1 tv case MEDALION:
155 1.1 tv case TALISMAN:
156 1.1 tv wordtype[wordnumber] = OBJECT;
157 1.1 tv break;
158 1.1 tv
159 1.1 tv default:
160 1.1 tv puts("Wha..?");
161 1.1 tv }
162 1.6 rillig if (wordtype[wordnumber] == OBJECT && position > 88 &&
163 1.6 rillig (testbit(inven, value) ||
164 1.3 jmc testbit(location[position].objects, value))) {
165 1.1 tv puts("Buried.");
166 1.1 tv if (testbit(inven, value)) {
167 1.1 tv clearbit(inven, value);
168 1.1 tv carrying -= objwt[value];
169 1.1 tv encumber -= objcumber[value];
170 1.1 tv }
171 1.1 tv clearbit(location[position].objects, value);
172 1.1 tv switch (value) {
173 1.1 tv case MAID:
174 1.1 tv case DEADWOOD:
175 1.1 tv case DEADNATIVE:
176 1.1 tv case DEADTIME:
177 1.1 tv case DEADGOD:
178 1.1 tv ego += 2;
179 1.6 rillig printf("The %s should rest easier now.\n",
180 1.3 jmc objsht[value]);
181 1.1 tv }
182 1.1 tv } else
183 1.1 tv puts("It doesn't seem to work.");
184 1.1 tv } else
185 1.1 tv puts("You aren't holding a shovel.");
186 1.1 tv }
187 1.1 tv
188 1.1 tv void
189 1.3 jmc drink(void)
190 1.1 tv {
191 1.1 tv int n;
192 1.1 tv
193 1.1 tv if (testbit(inven, POTION)) {
194 1.3 jmc printf("The cool liquid runs down your throat but turns to ");
195 1.3 jmc puts("fire and you choke.");
196 1.3 jmc printf("The heat reaches your limbs and tingles your spirit.");
197 1.3 jmc puts(" You feel like falling");
198 1.1 tv puts("asleep.");
199 1.1 tv clearbit(inven, POTION);
200 1.1 tv WEIGHT = MAXWEIGHT;
201 1.1 tv CUMBER = MAXCUMBER;
202 1.1 tv for (n = 0; n < NUMOFINJURIES; n++)
203 1.1 tv injuries[n] = 0;
204 1.1 tv ourtime++;
205 1.1 tv zzz();
206 1.1 tv } else
207 1.1 tv puts("I'm not thirsty.");
208 1.1 tv }
209 1.1 tv
210 1.1 tv int
211 1.3 jmc shoot(void)
212 1.1 tv {
213 1.1 tv int firstnumber, value;
214 1.1 tv
215 1.1 tv firstnumber = wordnumber;
216 1.1 tv if (!testbit(inven, LASER))
217 1.1 tv puts("You aren't holding a blaster.");
218 1.1 tv else {
219 1.1 tv wordnumber++;
220 1.6 rillig while (wordnumber <= wordcount &&
221 1.3 jmc wordtype[wordnumber] == OBJECT) {
222 1.1 tv value = wordvalue[wordnumber];
223 1.1 tv printf("%s:\n", objsht[value]);
224 1.1 tv if (testbit(location[position].objects, value)) {
225 1.1 tv clearbit(location[position].objects, value);
226 1.1 tv ourtime++;
227 1.1 tv printf("The %s explode%s\n", objsht[value],
228 1.1 tv (is_plural_object(value) ? "." : "s."));
229 1.1 tv if (value == BOMB)
230 1.1 tv die();
231 1.1 tv } else
232 1.6 rillig printf("I don't see any %s around here.\n",
233 1.3 jmc objsht[value]);
234 1.6 rillig if (wordnumber < wordcount - 1 &&
235 1.3 jmc wordvalue[++wordnumber] == AND)
236 1.1 tv wordnumber++;
237 1.1 tv else
238 1.1 tv return (firstnumber);
239 1.1 tv }
240 1.1 tv /* special cases with their own return()'s */
241 1.1 tv
242 1.1 tv if (wordnumber <= wordcount && wordtype[wordnumber] == NOUNS) {
243 1.1 tv ourtime++;
244 1.1 tv switch (wordvalue[wordnumber]) {
245 1.1 tv
246 1.1 tv case DOOR:
247 1.1 tv switch (position) {
248 1.1 tv case 189:
249 1.1 tv case 231:
250 1.1 tv puts("The door is unhinged.");
251 1.1 tv location[189].north = 231;
252 1.1 tv location[231].south = 189;
253 1.1 tv whichway(location[position]);
254 1.1 tv break;
255 1.1 tv case 30:
256 1.1 tv puts("The wooden door splinters.");
257 1.1 tv location[30].west = 25;
258 1.1 tv whichway(location[position]);
259 1.1 tv break;
260 1.1 tv case 31:
261 1.3 jmc printf("The laser blast has no ");
262 1.3 jmc puts("effect on the door.");
263 1.1 tv break;
264 1.1 tv case 20:
265 1.3 jmc printf("The blast hits the door and ");
266 1.3 jmc printf("it explodes into flame. The ");
267 1.3 jmc puts("magnesium burns");
268 1.3 jmc printf("so rapidly that we have no ");
269 1.3 jmc puts("chance to escape.");
270 1.1 tv die();
271 1.1 tv default:
272 1.1 tv puts("Nothing happens.");
273 1.1 tv }
274 1.1 tv break;
275 1.1 tv
276 1.1 tv case NORMGOD:
277 1.6 rillig if (testbit(location[position].objects,
278 1.3 jmc BATHGOD)) {
279 1.3 jmc printf("The goddess is hit in the ");
280 1.3 jmc printf("chest and splashes back ");
281 1.3 jmc puts("against the rocks.");
282 1.3 jmc printf("Dark blood oozes from the ");
283 1.3 jmc printf("charred blast hole. Her ");
284 1.3 jmc puts("naked body floats in the");
285 1.1 tv puts("pools and then off downstream.");
286 1.6 rillig clearbit(location[position].objects,
287 1.3 jmc BATHGOD);
288 1.1 tv setbit(location[180].objects, DEADGOD);
289 1.1 tv power += 5;
290 1.1 tv ego -= 10;
291 1.1 tv notes[JINXED]++;
292 1.1 tv } else
293 1.3 jmc if (testbit(location[position].objects,
294 1.3 jmc NORMGOD)) {
295 1.3 jmc printf("The blast catches ");
296 1.3 jmc printf("the goddess in the ");
297 1.3 jmc printf("stomach, knocking ");
298 1.3 jmc puts("her to the ground.");
299 1.3 jmc printf("She writhes in the ");
300 1.3 jmc printf("dirt as the agony of ");
301 1.3 jmc puts("death taunts her.");
302 1.1 tv puts("She has stopped moving.");
303 1.1 tv clearbit(location[position].objects, NORMGOD);
304 1.1 tv setbit(location[position].objects, DEADGOD);
305 1.1 tv power += 5;
306 1.1 tv ego -= 10;
307 1.1 tv notes[JINXED]++;
308 1.1 tv if (wintime)
309 1.1 tv live();
310 1.1 tv break;
311 1.4 mrg } else {
312 1.3 jmc printf("I don't see any ");
313 1.3 jmc puts("goddess around here.");
314 1.4 mrg }
315 1.1 tv break;
316 1.1 tv
317 1.1 tv case TIMER:
318 1.6 rillig if (testbit(location[position].objects,
319 1.3 jmc TIMER)) {
320 1.3 jmc printf("The old man slumps over ");
321 1.3 jmc puts("the bar.");
322 1.1 tv power++;
323 1.1 tv ego -= 2;
324 1.1 tv notes[JINXED]++;
325 1.6 rillig clearbit(location[position].objects,
326 1.3 jmc TIMER);
327 1.6 rillig setbit(location[position].objects,
328 1.3 jmc DEADTIME);
329 1.1 tv } else
330 1.1 tv puts("What old-timer?");
331 1.1 tv break;
332 1.1 tv case MAN:
333 1.1 tv if (testbit(location[position].objects, MAN)) {
334 1.3 jmc printf("The man falls to the ground ");
335 1.3 jmc printf("with blood pouring all over ");
336 1.3 jmc puts("his white suit.");
337 1.1 tv puts("Your fantasy is over.");
338 1.1 tv die();
339 1.1 tv } else
340 1.1 tv puts("What man?");
341 1.1 tv break;
342 1.1 tv case NATIVE:
343 1.6 rillig if (testbit(location[position].objects,
344 1.3 jmc NATIVE)) {
345 1.3 jmc printf("The girl is blown backwards ");
346 1.3 jmc printf("several feet and lies in a ");
347 1.3 jmc puts("pool of blood.");
348 1.6 rillig clearbit(location[position].objects,
349 1.3 jmc NATIVE);
350 1.6 rillig setbit(location[position].objects,
351 1.3 jmc DEADNATIVE);
352 1.1 tv power += 5;
353 1.1 tv ego -= 2;
354 1.1 tv notes[JINXED]++;
355 1.1 tv } else
356 1.1 tv puts("There is no girl here.");
357 1.1 tv break;
358 1.1 tv case -1:
359 1.1 tv puts("Shoot what?");
360 1.1 tv break;
361 1.1 tv
362 1.1 tv default:
363 1.6 rillig printf("You can't shoot the %s.\n",
364 1.3 jmc objsht[wordvalue[wordnumber]]);
365 1.1 tv }
366 1.1 tv } else
367 1.1 tv puts("You must be a looney.");
368 1.1 tv }
369 1.1 tv return (firstnumber);
370 1.1 tv }
371