1*166ddc28Sdaniel /* $OpenBSD: command2.c,v 1.1 2020/12/15 00:38:18 daniel Exp $ */
2*166ddc28Sdaniel /* $NetBSD: com2.c,v 1.3 1995/03/21 15:06:55 cgd Exp $ */
3*166ddc28Sdaniel
4*166ddc28Sdaniel /*
5*166ddc28Sdaniel * Copyright (c) 1983, 1993
6*166ddc28Sdaniel * The Regents of the University of California. All rights reserved.
7*166ddc28Sdaniel *
8*166ddc28Sdaniel * Redistribution and use in source and binary forms, with or without
9*166ddc28Sdaniel * modification, are permitted provided that the following conditions
10*166ddc28Sdaniel * are met:
11*166ddc28Sdaniel * 1. Redistributions of source code must retain the above copyright
12*166ddc28Sdaniel * notice, this list of conditions and the following disclaimer.
13*166ddc28Sdaniel * 2. Redistributions in binary form must reproduce the above copyright
14*166ddc28Sdaniel * notice, this list of conditions and the following disclaimer in the
15*166ddc28Sdaniel * documentation and/or other materials provided with the distribution.
16*166ddc28Sdaniel * 3. Neither the name of the University nor the names of its contributors
17*166ddc28Sdaniel * may be used to endorse or promote products derived from this software
18*166ddc28Sdaniel * without specific prior written permission.
19*166ddc28Sdaniel *
20*166ddc28Sdaniel * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21*166ddc28Sdaniel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22*166ddc28Sdaniel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23*166ddc28Sdaniel * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24*166ddc28Sdaniel * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25*166ddc28Sdaniel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26*166ddc28Sdaniel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27*166ddc28Sdaniel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28*166ddc28Sdaniel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29*166ddc28Sdaniel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30*166ddc28Sdaniel * SUCH DAMAGE.
31*166ddc28Sdaniel */
32*166ddc28Sdaniel
33*166ddc28Sdaniel #include <stdio.h>
34*166ddc28Sdaniel #include <stdlib.h>
35*166ddc28Sdaniel
36*166ddc28Sdaniel #include "extern.h"
37*166ddc28Sdaniel
38*166ddc28Sdaniel int
wearit(void)39*166ddc28Sdaniel wearit(void)
40*166ddc28Sdaniel { /* synonyms = {sheathe, sheath} */
41*166ddc28Sdaniel int firstnumber, value;
42*166ddc28Sdaniel
43*166ddc28Sdaniel firstnumber = wordnumber;
44*166ddc28Sdaniel wordnumber++;
45*166ddc28Sdaniel while (wordnumber <= wordcount && (wordtype[wordnumber] == OBJECT ||
46*166ddc28Sdaniel (wordtype[wordnumber] == NOUNS && wordvalue[wordnumber] != DOOR))) {
47*166ddc28Sdaniel value = wordvalue[wordnumber];
48*166ddc28Sdaniel if (value >= 0 && objsht[value] == NULL)
49*166ddc28Sdaniel break;
50*166ddc28Sdaniel switch (value) {
51*166ddc28Sdaniel
52*166ddc28Sdaniel case -1:
53*166ddc28Sdaniel puts("Wear what?");
54*166ddc28Sdaniel return (firstnumber);
55*166ddc28Sdaniel
56*166ddc28Sdaniel default:
57*166ddc28Sdaniel printf("You can't wear %s%s!\n",
58*166ddc28Sdaniel A_OR_AN_OR_BLANK(value), objsht[value]);
59*166ddc28Sdaniel return (firstnumber);
60*166ddc28Sdaniel
61*166ddc28Sdaniel case KNIFE:
62*166ddc28Sdaniel /* case SHIRT: */
63*166ddc28Sdaniel case ROBE:
64*166ddc28Sdaniel case LEVIS: /* wearable things */
65*166ddc28Sdaniel case SWORD:
66*166ddc28Sdaniel case MAIL:
67*166ddc28Sdaniel case HELM:
68*166ddc28Sdaniel case SHOES:
69*166ddc28Sdaniel case PAJAMAS:
70*166ddc28Sdaniel case COMPASS:
71*166ddc28Sdaniel case LASER:
72*166ddc28Sdaniel case AMULET:
73*166ddc28Sdaniel case TALISMAN:
74*166ddc28Sdaniel case MEDALION:
75*166ddc28Sdaniel case ROPE:
76*166ddc28Sdaniel case RING:
77*166ddc28Sdaniel case BRACELET:
78*166ddc28Sdaniel case GRENADE:
79*166ddc28Sdaniel
80*166ddc28Sdaniel if (TestBit(inven, value)) {
81*166ddc28Sdaniel ClearBit(inven, value);
82*166ddc28Sdaniel SetBit(wear, value);
83*166ddc28Sdaniel carrying -= objwt[value];
84*166ddc28Sdaniel encumber -= objcumber[value];
85*166ddc28Sdaniel ourtime++;
86*166ddc28Sdaniel printf("You are now wearing %s%s.\n",
87*166ddc28Sdaniel A_OR_AN_OR_THE(value), objsht[value]);
88*166ddc28Sdaniel } else
89*166ddc28Sdaniel if (TestBit(wear, value))
90*166ddc28Sdaniel printf("You are already wearing the %s.\n",
91*166ddc28Sdaniel objsht[value]);
92*166ddc28Sdaniel else
93*166ddc28Sdaniel printf("You aren't holding the %s.\n",
94*166ddc28Sdaniel objsht[value]);
95*166ddc28Sdaniel if (wordnumber < wordcount - 1 &&
96*166ddc28Sdaniel wordvalue[++wordnumber] == AND)
97*166ddc28Sdaniel wordnumber++;
98*166ddc28Sdaniel else
99*166ddc28Sdaniel return (firstnumber);
100*166ddc28Sdaniel } /* end switch */
101*166ddc28Sdaniel } /* end while */
102*166ddc28Sdaniel puts("Don't be ridiculous.");
103*166ddc28Sdaniel return (firstnumber);
104*166ddc28Sdaniel }
105*166ddc28Sdaniel
106*166ddc28Sdaniel int
put(void)107*166ddc28Sdaniel put(void)
108*166ddc28Sdaniel { /* synonyms = {buckle, strap, tie} */
109*166ddc28Sdaniel if (inc_wordnumber(words[wordnumber], "what"))
110*166ddc28Sdaniel return(-1);
111*166ddc28Sdaniel if (wordvalue[wordnumber] == ON) {
112*166ddc28Sdaniel wordvalue[wordnumber] = PUTON;
113*166ddc28Sdaniel wordtype[wordnumber] = VERB;
114*166ddc28Sdaniel return (cypher() - 1);
115*166ddc28Sdaniel }
116*166ddc28Sdaniel if (wordvalue[wordnumber] == DOWN) {
117*166ddc28Sdaniel wordvalue[wordnumber] = DROP;
118*166ddc28Sdaniel wordtype[wordnumber] = VERB;
119*166ddc28Sdaniel return (cypher() - 1);
120*166ddc28Sdaniel }
121*166ddc28Sdaniel puts("I don't understand what you want to put.");
122*166ddc28Sdaniel return (-1);
123*166ddc28Sdaniel }
124*166ddc28Sdaniel
125*166ddc28Sdaniel int
draw(void)126*166ddc28Sdaniel draw(void)
127*166ddc28Sdaniel { /* synonyms = {pull, carry} */
128*166ddc28Sdaniel return (take(wear));
129*166ddc28Sdaniel }
130*166ddc28Sdaniel
131*166ddc28Sdaniel int
use(void)132*166ddc28Sdaniel use(void)
133*166ddc28Sdaniel {
134*166ddc28Sdaniel if (inc_wordnumber(words[wordnumber], "what"))
135*166ddc28Sdaniel return(-1);
136*166ddc28Sdaniel if (wordvalue[wordnumber] == AMULET && TestBit(inven, AMULET) &&
137*166ddc28Sdaniel position != FINAL) {
138*166ddc28Sdaniel puts("The amulet begins to glow.");
139*166ddc28Sdaniel if (TestBit(inven, MEDALION)) {
140*166ddc28Sdaniel puts("The medallion comes to life too.");
141*166ddc28Sdaniel if (position == 114) {
142*166ddc28Sdaniel location[position].down = 160;
143*166ddc28Sdaniel whichway(location[position]);
144*166ddc28Sdaniel puts("The waves subside and it is possible to descend to the sea cave now.");
145*166ddc28Sdaniel ourtime++;
146*166ddc28Sdaniel wordnumber++;
147*166ddc28Sdaniel return (-1);
148*166ddc28Sdaniel }
149*166ddc28Sdaniel }
150*166ddc28Sdaniel puts("A light mist falls over your eyes and the sound of purling water trickles in");
151*166ddc28Sdaniel puts("your ears. When the mist lifts you are standing beside a cool stream.");
152*166ddc28Sdaniel if (position == 229)
153*166ddc28Sdaniel position = 224;
154*166ddc28Sdaniel else
155*166ddc28Sdaniel position = 229;
156*166ddc28Sdaniel ourtime++;
157*166ddc28Sdaniel notes[CANTSEE] = 0;
158*166ddc28Sdaniel wordnumber++;
159*166ddc28Sdaniel return (0);
160*166ddc28Sdaniel }
161*166ddc28Sdaniel else if (position == FINAL)
162*166ddc28Sdaniel puts("The amulet won't work in here.");
163*166ddc28Sdaniel else if (wordvalue[wordnumber] == COMPASS && TestBit(inven, COMPASS))
164*166ddc28Sdaniel printf("Your compass points %s.\n", truedirec(NORTH,'-'));
165*166ddc28Sdaniel else if (wordvalue[wordnumber] == COMPASS)
166*166ddc28Sdaniel puts("You aren't holding the compass.");
167*166ddc28Sdaniel else if (wordvalue[wordnumber] == AMULET)
168*166ddc28Sdaniel puts("You aren't holding the amulet.");
169*166ddc28Sdaniel else
170*166ddc28Sdaniel puts("There is no apparent use.");
171*166ddc28Sdaniel wordnumber++;
172*166ddc28Sdaniel return (-1);
173*166ddc28Sdaniel }
174*166ddc28Sdaniel
175*166ddc28Sdaniel void
murder(void)176*166ddc28Sdaniel murder(void)
177*166ddc28Sdaniel {
178*166ddc28Sdaniel int n;
179*166ddc28Sdaniel
180*166ddc28Sdaniel if (inc_wordnumber(words[wordnumber], "whom"))
181*166ddc28Sdaniel return;
182*166ddc28Sdaniel for (n = 0; n < NUMOFOBJECTS &&
183*166ddc28Sdaniel !((n == SWORD || n == KNIFE || n == TWO_HANDED || n == MACE ||
184*166ddc28Sdaniel n == CLEAVER || n == BROAD || n == CHAIN || n == SHOVEL ||
185*166ddc28Sdaniel n == HALBERD) && TestBit(inven, n)); n++)
186*166ddc28Sdaniel continue;
187*166ddc28Sdaniel if (n == NUMOFOBJECTS) {
188*166ddc28Sdaniel if (TestBit(inven, LASER)) {
189*166ddc28Sdaniel printf("Your laser should do the trick.\n");
190*166ddc28Sdaniel switch(wordvalue[wordnumber]) {
191*166ddc28Sdaniel case NORMGOD:
192*166ddc28Sdaniel case TIMER:
193*166ddc28Sdaniel case NATIVE:
194*166ddc28Sdaniel case MAN:
195*166ddc28Sdaniel wordvalue[--wordnumber] = SHOOT;
196*166ddc28Sdaniel cypher();
197*166ddc28Sdaniel break;
198*166ddc28Sdaniel case -1:
199*166ddc28Sdaniel puts("Kill what?");
200*166ddc28Sdaniel break;
201*166ddc28Sdaniel default:
202*166ddc28Sdaniel if (wordtype[wordnumber] != OBJECT ||
203*166ddc28Sdaniel wordvalue[wordnumber] == EVERYTHING)
204*166ddc28Sdaniel puts("You can't kill that!");
205*166ddc28Sdaniel else
206*166ddc28Sdaniel printf("You can't kill %s%s!\n",
207*166ddc28Sdaniel A_OR_AN_OR_BLANK(wordvalue[wordnumber]),
208*166ddc28Sdaniel objsht[wordvalue[wordnumber]]);
209*166ddc28Sdaniel break;
210*166ddc28Sdaniel }
211*166ddc28Sdaniel } else
212*166ddc28Sdaniel puts("You don't have suitable weapons to kill.");
213*166ddc28Sdaniel } else {
214*166ddc28Sdaniel printf("Your %s should do the trick.\n", objsht[n]);
215*166ddc28Sdaniel switch (wordvalue[wordnumber]) {
216*166ddc28Sdaniel
217*166ddc28Sdaniel case NORMGOD:
218*166ddc28Sdaniel if (TestBit(location[position].objects, BATHGOD)) {
219*166ddc28Sdaniel puts("The goddess's head slices off. Her corpse floats in the water.");
220*166ddc28Sdaniel ClearBit(location[position].objects, BATHGOD);
221*166ddc28Sdaniel SetBit(location[position].objects, DEADGOD);
222*166ddc28Sdaniel power += 5;
223*166ddc28Sdaniel notes[JINXED]++;
224*166ddc28Sdaniel } else
225*166ddc28Sdaniel if (TestBit(location[position].objects, NORMGOD)) {
226*166ddc28Sdaniel puts("The goddess pleads but you strike her mercilessly. Her broken body lies in a\npool of blood.");
227*166ddc28Sdaniel ClearBit(location[position].objects, NORMGOD);
228*166ddc28Sdaniel SetBit(location[position].objects, DEADGOD);
229*166ddc28Sdaniel power += 5;
230*166ddc28Sdaniel notes[JINXED]++;
231*166ddc28Sdaniel if (wintime)
232*166ddc28Sdaniel live();
233*166ddc28Sdaniel } else
234*166ddc28Sdaniel puts("I don't see her anywhere.");
235*166ddc28Sdaniel break;
236*166ddc28Sdaniel case TIMER:
237*166ddc28Sdaniel if (TestBit(location[position].objects, TIMER)) {
238*166ddc28Sdaniel puts("The old man offers no resistance.");
239*166ddc28Sdaniel ClearBit(location[position].objects, TIMER);
240*166ddc28Sdaniel SetBit(location[position].objects, DEADTIME);
241*166ddc28Sdaniel power++;
242*166ddc28Sdaniel notes[JINXED]++;
243*166ddc28Sdaniel } else
244*166ddc28Sdaniel puts("Who?");
245*166ddc28Sdaniel break;
246*166ddc28Sdaniel case NATIVE:
247*166ddc28Sdaniel if (TestBit(location[position].objects, NATIVE)) {
248*166ddc28Sdaniel puts("The girl screams as you cut her body to shreds. She is dead.");
249*166ddc28Sdaniel ClearBit(location[position].objects, NATIVE);
250*166ddc28Sdaniel SetBit(location[position].objects, DEADNATIVE);
251*166ddc28Sdaniel power += 5;
252*166ddc28Sdaniel notes[JINXED]++;
253*166ddc28Sdaniel } else
254*166ddc28Sdaniel puts("What girl?");
255*166ddc28Sdaniel break;
256*166ddc28Sdaniel case MAN:
257*166ddc28Sdaniel if (TestBit(location[position].objects, MAN)) {
258*166ddc28Sdaniel puts("You strike him to the ground, and he coughs up blood.");
259*166ddc28Sdaniel puts("Your fantasy is over.");
260*166ddc28Sdaniel die(0);
261*166ddc28Sdaniel }
262*166ddc28Sdaniel case -1:
263*166ddc28Sdaniel puts("Kill what?");
264*166ddc28Sdaniel break;
265*166ddc28Sdaniel
266*166ddc28Sdaniel default:
267*166ddc28Sdaniel if (wordtype[wordnumber] != OBJECT ||
268*166ddc28Sdaniel wordvalue[wordnumber] == EVERYTHING)
269*166ddc28Sdaniel puts("You can't kill that!");
270*166ddc28Sdaniel else
271*166ddc28Sdaniel printf("You can't kill the %s!\n",
272*166ddc28Sdaniel objsht[wordvalue[wordnumber]]);
273*166ddc28Sdaniel }
274*166ddc28Sdaniel }
275*166ddc28Sdaniel wordnumber++;
276*166ddc28Sdaniel }
277*166ddc28Sdaniel
278*166ddc28Sdaniel void
ravage(void)279*166ddc28Sdaniel ravage(void)
280*166ddc28Sdaniel {
281*166ddc28Sdaniel if (inc_wordnumber(words[wordnumber], "whom"))
282*166ddc28Sdaniel return;
283*166ddc28Sdaniel if (wordtype[wordnumber] == NOUNS && (TestBit(location[position].objects, wordvalue[wordnumber])
284*166ddc28Sdaniel || (wordvalue[wordnumber] == NORMGOD && TestBit(location[position].objects, BATHGOD)))) {
285*166ddc28Sdaniel ourtime++;
286*166ddc28Sdaniel switch (wordvalue[wordnumber]) {
287*166ddc28Sdaniel case NORMGOD:
288*166ddc28Sdaniel puts("You attack the goddess, and she screams as you beat her. She falls down");
289*166ddc28Sdaniel if (TestBit(location[position].objects, BATHGOD))
290*166ddc28Sdaniel puts("crying and tries to cover her nakedness.");
291*166ddc28Sdaniel else
292*166ddc28Sdaniel puts("crying and tries to hold her torn and bloodied dress around her.");
293*166ddc28Sdaniel power += 5;
294*166ddc28Sdaniel pleasure += 8;
295*166ddc28Sdaniel ego -= 10;
296*166ddc28Sdaniel wordnumber--;
297*166ddc28Sdaniel godready = -30000;
298*166ddc28Sdaniel murder();
299*166ddc28Sdaniel win = -30000;
300*166ddc28Sdaniel break;
301*166ddc28Sdaniel case NATIVE:
302*166ddc28Sdaniel puts("The girl tries to run, but you catch her and throw her down. Her face is");
303*166ddc28Sdaniel puts("bleeding, and she screams as you tear off her clothes.");
304*166ddc28Sdaniel power += 3;
305*166ddc28Sdaniel pleasure += 5;
306*166ddc28Sdaniel ego -= 10;
307*166ddc28Sdaniel wordnumber--;
308*166ddc28Sdaniel murder();
309*166ddc28Sdaniel if (rnd(100) < 50) {
310*166ddc28Sdaniel puts("Her screams have attracted attention. I think we are surrounded.");
311*166ddc28Sdaniel SetBit(location[ahead].objects, WOODSMAN);
312*166ddc28Sdaniel SetBit(location[ahead].objects, DEADWOOD);
313*166ddc28Sdaniel SetBit(location[ahead].objects, MALLET);
314*166ddc28Sdaniel SetBit(location[back].objects, WOODSMAN);
315*166ddc28Sdaniel SetBit(location[back].objects, DEADWOOD);
316*166ddc28Sdaniel SetBit(location[back].objects, MALLET);
317*166ddc28Sdaniel SetBit(location[left].objects, WOODSMAN);
318*166ddc28Sdaniel SetBit(location[left].objects, DEADWOOD);
319*166ddc28Sdaniel SetBit(location[left].objects, MALLET);
320*166ddc28Sdaniel SetBit(location[right].objects, WOODSMAN);
321*166ddc28Sdaniel SetBit(location[right].objects, DEADWOOD);
322*166ddc28Sdaniel SetBit(location[right].objects, MALLET);
323*166ddc28Sdaniel }
324*166ddc28Sdaniel break;
325*166ddc28Sdaniel default:
326*166ddc28Sdaniel puts("You are perverted.");
327*166ddc28Sdaniel wordnumber++;
328*166ddc28Sdaniel }
329*166ddc28Sdaniel } else {
330*166ddc28Sdaniel printf("%s: Who?\n", words[wordnumber]);
331*166ddc28Sdaniel wordnumber++;
332*166ddc28Sdaniel }
333*166ddc28Sdaniel }
334*166ddc28Sdaniel
335*166ddc28Sdaniel int
follow(void)336*166ddc28Sdaniel follow(void)
337*166ddc28Sdaniel {
338*166ddc28Sdaniel if (followfight == ourtime) {
339*166ddc28Sdaniel puts("The Dark Lord leaps away and runs down secret tunnels and corridors.");
340*166ddc28Sdaniel puts("You chase him through the darkness and splash in pools of water.");
341*166ddc28Sdaniel puts("You have cornered him. His laser sword extends as he steps forward.");
342*166ddc28Sdaniel position = FINAL;
343*166ddc28Sdaniel fight(DARK, 75);
344*166ddc28Sdaniel SetBit(location[position].objects, TALISMAN);
345*166ddc28Sdaniel SetBit(location[position].objects, AMULET);
346*166ddc28Sdaniel return (0);
347*166ddc28Sdaniel } else
348*166ddc28Sdaniel if (followgod == ourtime) {
349*166ddc28Sdaniel puts("The goddess leads you down a steamy tunnel and into a high, wide chamber.");
350*166ddc28Sdaniel puts("She sits down on a throne.");
351*166ddc28Sdaniel position = 268;
352*166ddc28Sdaniel SetBit(location[position].objects, NORMGOD);
353*166ddc28Sdaniel notes[CANTSEE] = 1;
354*166ddc28Sdaniel return (0);
355*166ddc28Sdaniel } else
356*166ddc28Sdaniel puts("There is no one to follow.");
357*166ddc28Sdaniel return (-1);
358*166ddc28Sdaniel }
359*166ddc28Sdaniel
360*166ddc28Sdaniel void
undress(void)361*166ddc28Sdaniel undress(void)
362*166ddc28Sdaniel {
363*166ddc28Sdaniel if (inc_wordnumber(words[wordnumber], "whom"))
364*166ddc28Sdaniel return;
365*166ddc28Sdaniel if (wordvalue[wordnumber] == NORMGOD &&
366*166ddc28Sdaniel (TestBit(location[position].objects, NORMGOD)) && godready >= 2) {
367*166ddc28Sdaniel wordnumber--;
368*166ddc28Sdaniel love();
369*166ddc28Sdaniel } else {
370*166ddc28Sdaniel wordnumber--;
371*166ddc28Sdaniel ravage();
372*166ddc28Sdaniel }
373*166ddc28Sdaniel }
374