command2.c revision 1.5 1 1.5 rillig /* $NetBSD: command2.c,v 1.5 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[] = "@(#)com2.c 8.2 (Berkeley) 4/28/95";
36 1.1 tv #else
37 1.5 rillig __RCSID("$NetBSD: command2.c,v 1.5 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 int
44 1.3 jmc wearit(void)
45 1.1 tv { /* synonyms = {sheathe, sheath} */
46 1.1 tv int firstnumber, value;
47 1.1 tv
48 1.1 tv firstnumber = wordnumber;
49 1.1 tv wordnumber++;
50 1.1 tv while (wordnumber <= wordcount && (wordtype[wordnumber] == OBJECT ||
51 1.1 tv wordtype[wordnumber] == NOUNS) && wordvalue[wordnumber] != DOOR) {
52 1.1 tv value = wordvalue[wordnumber];
53 1.1 tv if (value >= 0 && objsht[value] == NULL)
54 1.1 tv break;
55 1.1 tv switch (value) {
56 1.1 tv
57 1.1 tv case -1:
58 1.1 tv puts("Wear what?");
59 1.1 tv return (firstnumber);
60 1.1 tv
61 1.1 tv default:
62 1.1 tv printf("You can't wear %s%s!\n",
63 1.1 tv A_OR_AN_OR_BLANK(value), objsht[value]);
64 1.1 tv return (firstnumber);
65 1.1 tv
66 1.1 tv case KNIFE:
67 1.1 tv /* case SHIRT: */
68 1.1 tv case ROBE:
69 1.1 tv case LEVIS: /* wearable things */
70 1.1 tv case SWORD:
71 1.1 tv case MAIL:
72 1.1 tv case HELM:
73 1.1 tv case SHOES:
74 1.1 tv case PAJAMAS:
75 1.1 tv case COMPASS:
76 1.1 tv case LASER:
77 1.1 tv case AMULET:
78 1.1 tv case TALISMAN:
79 1.1 tv case MEDALION:
80 1.1 tv case ROPE:
81 1.1 tv case RING:
82 1.1 tv case BRACELET:
83 1.1 tv case GRENADE:
84 1.1 tv
85 1.1 tv if (testbit(inven, value)) {
86 1.1 tv clearbit(inven, value);
87 1.1 tv setbit(wear, value);
88 1.1 tv carrying -= objwt[value];
89 1.1 tv encumber -= objcumber[value];
90 1.1 tv ourtime++;
91 1.1 tv printf("You are now wearing %s%s.\n",
92 1.1 tv A_OR_AN_OR_THE(value), objsht[value]);
93 1.1 tv } else
94 1.3 jmc if (testbit(wear, value)) {
95 1.3 jmc printf("You are already wearing the %s",
96 1.1 tv objsht[value]);
97 1.3 jmc printf(".\n");
98 1.3 jmc } else
99 1.1 tv printf("You aren't holding the %s.\n",
100 1.1 tv objsht[value]);
101 1.1 tv if (wordnumber < wordcount - 1 &&
102 1.1 tv wordvalue[++wordnumber] == AND)
103 1.1 tv wordnumber++;
104 1.1 tv else
105 1.1 tv return (firstnumber);
106 1.1 tv } /* end switch */
107 1.1 tv } /* end while */
108 1.1 tv puts("Don't be ridiculous.");
109 1.1 tv return (firstnumber);
110 1.1 tv }
111 1.1 tv
112 1.1 tv int
113 1.3 jmc put(void)
114 1.1 tv { /* synonyms = {buckle, strap, tie} */
115 1.1 tv if (wordvalue[wordnumber + 1] == ON) {
116 1.1 tv wordvalue[++wordnumber] = PUTON;
117 1.1 tv wordtype[wordnumber] = VERB;
118 1.1 tv return (cypher());
119 1.1 tv }
120 1.1 tv if (wordvalue[wordnumber + 1] == DOWN) {
121 1.1 tv wordvalue[++wordnumber] = DROP;
122 1.1 tv wordtype[wordnumber] = VERB;
123 1.1 tv return (cypher());
124 1.1 tv }
125 1.1 tv puts("I don't understand what you want to put.");
126 1.1 tv return (-1);
127 1.1 tv
128 1.1 tv }
129 1.1 tv
130 1.1 tv int
131 1.3 jmc draw(void)
132 1.1 tv { /* synonyms = {pull, carry} */
133 1.1 tv return (take(wear));
134 1.1 tv }
135 1.1 tv
136 1.1 tv int
137 1.3 jmc use(void)
138 1.1 tv {
139 1.1 tv wordnumber++;
140 1.1 tv if (wordvalue[wordnumber] == AMULET && testbit(inven, AMULET) &&
141 1.1 tv position != FINAL) {
142 1.1 tv puts("The amulet begins to glow.");
143 1.1 tv if (testbit(inven, MEDALION)) {
144 1.1 tv puts("The medallion comes to life too.");
145 1.1 tv if (position == 114) {
146 1.1 tv location[position].down = 160;
147 1.1 tv whichway(location[position]);
148 1.3 jmc printf("The waves subside and it is possible ");
149 1.3 jmc puts("to descend to the sea cave now.");
150 1.1 tv ourtime++;
151 1.1 tv return (-1);
152 1.1 tv }
153 1.1 tv }
154 1.3 jmc printf("A light mist falls over your eyes and the sound of ");
155 1.3 jmc puts("purling water trickles in");
156 1.3 jmc printf("your ears. When the mist lifts you are standing ");
157 1.3 jmc puts("beside a cool stream.");
158 1.1 tv if (position == 229)
159 1.1 tv position = 224;
160 1.1 tv else
161 1.1 tv position = 229;
162 1.1 tv ourtime++;
163 1.1 tv notes[CANTSEE] = 0;
164 1.1 tv return (0);
165 1.1 tv } else if (position == FINAL)
166 1.1 tv puts("The amulet won't work in here.");
167 1.1 tv else if (wordvalue[wordnumber] == COMPASS && testbit(inven, COMPASS))
168 1.1 tv printf("Your compass points %s.\n", truedirec(NORTH, '-'));
169 1.1 tv else if (wordvalue[wordnumber] == COMPASS)
170 1.1 tv puts("You aren't holding the compass.");
171 1.1 tv else if (wordvalue[wordnumber] == AMULET)
172 1.1 tv puts("You aren't holding the amulet.");
173 1.1 tv else
174 1.1 tv puts("There is no apparent use.");
175 1.1 tv return (-1);
176 1.1 tv }
177 1.1 tv
178 1.1 tv void
179 1.3 jmc murder(void)
180 1.1 tv {
181 1.1 tv int n;
182 1.1 tv
183 1.5 rillig for (n = 0;
184 1.5 rillig !((n == SWORD || n == KNIFE || n == TWO_HANDED || n == MACE ||
185 1.5 rillig n == CLEAVER || n == BROAD || n == CHAIN || n == SHOVEL ||
186 1.5 rillig n == HALBERD) && testbit(inven, n)) && n < NUMOFOBJECTS;
187 1.3 jmc n++);
188 1.1 tv if (n == NUMOFOBJECTS) {
189 1.1 tv if (testbit(inven, LASER)) {
190 1.1 tv printf("Your laser should do the trick.\n");
191 1.1 tv wordnumber++;
192 1.1 tv switch(wordvalue[wordnumber]) {
193 1.1 tv case NORMGOD:
194 1.1 tv case TIMER:
195 1.1 tv case NATIVE:
196 1.1 tv case MAN:
197 1.1 tv wordvalue[--wordnumber] = SHOOT;
198 1.1 tv cypher();
199 1.1 tv break;
200 1.1 tv case -1:
201 1.1 tv puts("Kill what?");
202 1.1 tv break;
203 1.1 tv default:
204 1.1 tv if (wordtype[wordnumber] != OBJECT ||
205 1.1 tv wordvalue[wordnumber] == EVERYTHING)
206 1.1 tv puts("You can't kill that!");
207 1.1 tv else
208 1.1 tv printf("You can't kill %s%s!\n",
209 1.1 tv A_OR_AN_OR_BLANK(wordvalue[wordnumber]),
210 1.1 tv objsht[wordvalue[wordnumber]]);
211 1.1 tv break;
212 1.1 tv }
213 1.1 tv } else
214 1.1 tv puts("You don't have suitable weapons to kill.");
215 1.1 tv } else {
216 1.1 tv printf("Your %s should do the trick.\n", objsht[n]);
217 1.1 tv wordnumber++;
218 1.1 tv switch (wordvalue[wordnumber]) {
219 1.1 tv
220 1.1 tv case NORMGOD:
221 1.1 tv if (testbit(location[position].objects, BATHGOD)) {
222 1.3 jmc printf("The goddess's head slices off. Her ");
223 1.3 jmc puts("corpse floats in the water.");
224 1.1 tv clearbit(location[position].objects, BATHGOD);
225 1.1 tv setbit(location[position].objects, DEADGOD);
226 1.1 tv power += 5;
227 1.1 tv notes[JINXED]++;
228 1.1 tv } else
229 1.5 rillig if (testbit(location[position].objects,
230 1.3 jmc NORMGOD)) {
231 1.3 jmc printf("The goddess pleads but you ");
232 1.3 jmc printf("strike her mercilessly. Her ");
233 1.3 jmc printf("broken body lies in a\n");
234 1.3 jmc puts("pool of blood.");
235 1.5 rillig clearbit(location[position].objects,
236 1.3 jmc NORMGOD);
237 1.5 rillig setbit(location[position].objects,
238 1.3 jmc DEADGOD);
239 1.1 tv power += 5;
240 1.1 tv notes[JINXED]++;
241 1.1 tv if (wintime)
242 1.1 tv live();
243 1.1 tv } else
244 1.1 tv puts("I don't see her anywhere.");
245 1.1 tv break;
246 1.1 tv case TIMER:
247 1.1 tv if (testbit(location[position].objects, TIMER)) {
248 1.1 tv puts("The old man offers no resistance.");
249 1.1 tv clearbit(location[position].objects, TIMER);
250 1.1 tv setbit(location[position].objects, DEADTIME);
251 1.1 tv power++;
252 1.1 tv notes[JINXED]++;
253 1.1 tv } else
254 1.1 tv puts("Who?");
255 1.1 tv break;
256 1.1 tv case NATIVE:
257 1.1 tv if (testbit(location[position].objects, NATIVE)) {
258 1.3 jmc printf("The girl screams as you cut her ");
259 1.3 jmc puts("body to shreds. She is dead.");
260 1.1 tv clearbit(location[position].objects, NATIVE);
261 1.1 tv setbit(location[position].objects, DEADNATIVE);
262 1.1 tv power += 5;
263 1.1 tv notes[JINXED]++;
264 1.1 tv } else
265 1.1 tv puts("What girl?");
266 1.1 tv break;
267 1.1 tv case MAN:
268 1.1 tv if (testbit(location[position].objects, MAN)) {
269 1.3 jmc printf("You strike him to the ground, and ");
270 1.3 jmc puts("he coughs up blood.");
271 1.1 tv puts("Your fantasy is over.");
272 1.1 tv die();
273 1.1 tv }
274 1.4 mrg /* FALLTHROUGH */
275 1.1 tv case -1:
276 1.1 tv puts("Kill what?");
277 1.1 tv break;
278 1.1 tv
279 1.1 tv default:
280 1.1 tv if (wordtype[wordnumber] != OBJECT ||
281 1.1 tv wordvalue[wordnumber] == EVERYTHING)
282 1.1 tv puts("You can't kill that!");
283 1.1 tv else
284 1.1 tv printf("You can't kill the %s!\n",
285 1.1 tv objsht[wordvalue[wordnumber]]);
286 1.1 tv }
287 1.1 tv }
288 1.1 tv }
289 1.1 tv
290 1.1 tv void
291 1.3 jmc ravage(void)
292 1.1 tv {
293 1.1 tv while (wordtype[++wordnumber] != NOUNS && wordnumber <= wordcount)
294 1.1 tv continue;
295 1.5 rillig if (wordtype[wordnumber] == NOUNS &&
296 1.3 jmc (testbit(location[position].objects, wordvalue[wordnumber])
297 1.5 rillig || (wordvalue[wordnumber] == NORMGOD &&
298 1.3 jmc testbit(location[position].objects, BATHGOD)))) {
299 1.1 tv ourtime++;
300 1.1 tv switch (wordvalue[wordnumber]) {
301 1.1 tv case NORMGOD:
302 1.3 jmc printf("You attack the goddess, and she screams as ");
303 1.3 jmc puts("you beat her. She falls down");
304 1.3 jmc if (testbit(location[position].objects, BATHGOD)) {
305 1.3 jmc printf("crying and tries to cover her ");
306 1.3 jmc puts("nakedness.");
307 1.3 jmc } else {
308 1.3 jmc printf("crying and tries to hold her torn ");
309 1.3 jmc puts("and bloodied dress around her.");
310 1.3 jmc }
311 1.1 tv power += 5;
312 1.1 tv pleasure += 8;
313 1.1 tv ego -= 10;
314 1.1 tv wordnumber--;
315 1.1 tv godready = -30000;
316 1.1 tv murder();
317 1.1 tv win = -30000;
318 1.1 tv break;
319 1.1 tv case NATIVE:
320 1.3 jmc printf("The girl tries to run, but you catch her and ");
321 1.3 jmc puts("throw her down. Her face is");
322 1.3 jmc printf("bleeding, and she screams as you tear off ");
323 1.3 jmc puts("her clothes.");
324 1.1 tv power += 3;
325 1.1 tv pleasure += 5;
326 1.1 tv ego -= 10;
327 1.1 tv wordnumber--;
328 1.1 tv murder();
329 1.1 tv if (rnd(100) < 50) {
330 1.3 jmc printf("Her screams have attracted ");
331 1.3 jmc puts("attention. I think we are surrounded.");
332 1.1 tv setbit(location[ahead].objects, WOODSMAN);
333 1.1 tv setbit(location[ahead].objects, DEADWOOD);
334 1.1 tv setbit(location[ahead].objects, MALLET);
335 1.1 tv setbit(location[back].objects, WOODSMAN);
336 1.1 tv setbit(location[back].objects, DEADWOOD);
337 1.1 tv setbit(location[back].objects, MALLET);
338 1.1 tv setbit(location[left].objects, WOODSMAN);
339 1.1 tv setbit(location[left].objects, DEADWOOD);
340 1.1 tv setbit(location[left].objects, MALLET);
341 1.1 tv setbit(location[right].objects, WOODSMAN);
342 1.1 tv setbit(location[right].objects, DEADWOOD);
343 1.1 tv setbit(location[right].objects, MALLET);
344 1.1 tv }
345 1.1 tv break;
346 1.1 tv default:
347 1.1 tv puts("You are perverted.");
348 1.1 tv }
349 1.1 tv } else
350 1.1 tv puts("Who?");
351 1.1 tv }
352 1.1 tv
353 1.1 tv int
354 1.3 jmc follow(void)
355 1.1 tv {
356 1.1 tv if (followfight == ourtime) {
357 1.3 jmc printf("The Dark Lord leaps away and runs down secret ");
358 1.3 jmc puts("tunnels and corridors.");
359 1.3 jmc printf("You chase him through the darkness and splash in ");
360 1.3 jmc puts("pools of water.");
361 1.3 jmc printf("You have cornered him. His laser sword extends ");
362 1.3 jmc puts("as he steps forward.");
363 1.1 tv position = FINAL;
364 1.1 tv fight(DARK, 75);
365 1.1 tv setbit(location[position].objects, TALISMAN);
366 1.1 tv setbit(location[position].objects, AMULET);
367 1.1 tv return (0);
368 1.1 tv } else
369 1.1 tv if (followgod == ourtime) {
370 1.3 jmc printf("The goddess leads you down a steamy tunnel ");
371 1.3 jmc puts("and into a high, wide chamber.");
372 1.1 tv puts("She sits down on a throne.");
373 1.1 tv position = 268;
374 1.1 tv setbit(location[position].objects, NORMGOD);
375 1.1 tv notes[CANTSEE] = 1;
376 1.1 tv return (0);
377 1.1 tv } else
378 1.1 tv puts("There is no one to follow.");
379 1.1 tv return (-1);
380 1.1 tv }
381