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