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