xref: /original-bsd/games/battlestar/com4.c (revision 65d10654)
1 /*
2  * Copyright (c) 1983, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)com4.c	8.2 (Berkeley) 04/28/95";
10 #endif /* not lint */
11 
12 #include "extern.h"
13 
14 take(from)
15 unsigned int from[];
16 {
17 	int firstnumber, heavy, bulky, value;
18 	register int n;
19 
20 	firstnumber = wordnumber;
21 	if (wordnumber < wordcount && wordvalue[wordnumber+1] == OFF){
22 		wordnumber++;
23 		wordvalue[wordnumber] = TAKEOFF;
24 		return(cypher());
25 	}
26 	else {
27 		while(wordtype[++wordnumber] == ADJS);
28 		while(wordnumber<=wordcount && wordtype[wordnumber] == OBJECT){
29 			value = wordvalue[wordnumber];
30 			printf("%s:\n", objsht[value]);
31 			for (n=0; objsht[value][n]; n++);
32 			heavy = (carrying + objwt[value]) <= WEIGHT;
33 			bulky = (encumber + objcumber[value]) <= CUMBER;
34 			if ((testbit(from,value) || wiz || tempwiz) && heavy && bulky && !testbit(inven,value)){
35 				setbit(inven,value);
36 				carrying += objwt[value];
37 				encumber += objcumber[value];
38 				time++;
39 				if (testbit(from,value))
40 					printf("Taken.\n");
41 				else
42 					printf("Zap! Taken from thin air.\n");
43 				clearbit(from,value);
44 				if (value == MEDALION)
45 					win--;
46 			}
47 			else if (testbit(inven,value))
48 				printf("You're already holding%s%s.\n", (objsht[value][n-1] == 's' ? " " : " a "),objsht[value]);
49 			else if (!heavy)
50 				printf("The %s %s too heavy.\n", objsht[value],(objsht[value][n-1] == 's' ? "are" : "is"));
51 			else if (!bulky)
52 				printf("The %s %s too cumbersome to hold.\n", objsht[value],(objsht[value][n-1] == 's' ? "are" : "is"));
53 			else
54 				printf("I dont see any %s around here.\n", objsht[value]);
55 			if (wordnumber < wordcount -1 && wordvalue[++wordnumber] == AND)
56 				wordnumber++;
57 			else
58 				return(firstnumber);
59 		}
60 	}
61 			    /* special cases with their own return()'s */
62 
63 	if (wordnumber <= wordcount && wordtype[wordnumber] == NOUNS)
64 		switch(wordvalue[wordnumber]){
65 
66 			case SWORD:
67 				if (testbit(from, SWORD)){
68 					wordtype[wordnumber--] = OBJECT;
69 					return(take(from));
70 				}
71 				if (testbit(from, TWO_HANDED)){
72 					wordvalue[wordnumber] = TWO_HANDED;
73 					wordtype[wordnumber--] = OBJECT;
74 					return(take(from));
75 				}
76 				wordvalue[wordnumber] = BROAD;
77 				wordtype[wordnumber--] = OBJECT;
78 				return(take(from));
79 
80 			case BODY:
81 				if (testbit(from,MAID)){
82 					wordvalue[wordnumber] = MAID;
83 					wordtype[wordnumber--] = OBJECT;
84 					return(take(from));
85 				}
86 				else if (testbit(from,DEADWOOD)){
87 					wordvalue[wordnumber] = DEADWOOD;
88 					wordtype[wordnumber--] = OBJECT;
89 					return(take(from));
90 				}
91 				else if (testbit(from,DEADNATIVE)){
92 					wordvalue[wordnumber] = DEADNATIVE;
93 					wordtype[wordnumber--] = OBJECT;
94 					return(take(from));
95 				}
96 				else if (testbit(from,DEADGOD)){
97 					wordvalue[wordnumber] = DEADGOD;
98 					wordtype[wordnumber--] = OBJECT;
99 					return(take(from));
100 				}
101 				else {
102 					wordvalue[wordnumber] = DEADTIME;
103 					wordtype[wordnumber--] = OBJECT;
104 					return(take(from));
105 				}
106 				break;
107 
108 			case AMULET:
109 				if (testbit(location[position].objects,AMULET)){
110 					puts("The amulet is warm to the touch, and its beauty catches your breath.");
111 					puts("A mist falls over your eyes, but then it is gone.  Sounds seem clearer");
112 					puts("and sharper but far away as if in a dream.  The sound of purling water reaches");
113 					puts("you from afar.  The mist falls again, and your heart leaps in horror.  The gold");
114 					puts("freezes your hands and fathomless darkness engulfs your soul.");
115 				}
116 				wordtype[wordnumber--] = OBJECT;
117 				return(take(from));
118 
119 			case MEDALION:
120 				if (testbit(location[position].objects, MEDALION)){
121 					puts("The medallion is warm, and it rekindles your spirit with the warmth of life.");
122 					puts("Your amulet begins to glow as the medallion is brought near to it, and together\nthey radiate.");
123 				}
124 				wordtype[wordnumber--] = OBJECT;
125 				return(take(from));
126 
127 			case TALISMAN:
128 				if (testbit(location[position].objects,TALISMAN)){
129 					puts("The talisman is cold to the touch, and it sends a chill down your spine.");
130 				}
131 				wordtype[wordnumber--] = OBJECT;
132 				return(take(from));
133 
134 			case NORMGOD:
135 				if (testbit(location[position].objects,BATHGOD) && (testbit(wear,AMULET) || testbit(inven,AMULET))){
136 					puts("She offers a delicate hand, and you help her out of the sparkling springs.");
137 					puts("Water droplets like liquid silver bedew her golden skin, but when they part");
138 					puts("from her, they fall as teardrops.  She wraps a single cloth around her and");
139 					puts("ties it at the waist.  Around her neck hangs a golden amulet.");
140 					puts("She bids you to follow her.");
141 					pleasure++;
142 					followgod = time;
143 					clearbit(location[position].objects,BATHGOD);
144 				} else if (!testbit(location[position].objects,BATHGOD))
145 					puts("You're in no position to take her.");
146 				else
147 					puts("She moves away from you.");
148 				break;
149 
150 			default:
151 				puts("It doesn't seem to work.");
152 		}
153 	else
154 		puts("You've got to be kidding.");
155 	return(firstnumber);
156 }
157 
158 throw(name)
159 	char *name;
160 {
161 	int n;
162 	int deposit = 0;
163 	int first, value;
164 
165 	first = wordnumber;
166 	if (drop(name) != -1){
167 		switch(wordvalue[wordnumber]){
168 
169 			case AHEAD:
170 				deposit = ahead;
171 				break;
172 
173 			case BACK:
174 				deposit = back;
175 				break;
176 
177 			case LEFT:
178 				deposit = left;
179 				break;
180 
181 			case RIGHT:
182 				deposit = right;
183 				break;
184 
185 			case UP:
186 				deposit = location[position].up * (location[position].access || position == FINAL);
187 				break;
188 
189 			case DOWN:
190 				deposit = location[position].down;
191 				break;
192 		}
193 		wordnumber = first;
194 		while (wordtype[++wordnumber] == ADJS);
195 		while (wordnumber <= wordcount){
196 			value = wordvalue[wordnumber];
197 			if (deposit && testbit(location[position].objects,value)){
198 				clearbit(location[position].objects,value);
199 				if (value != GRENADE)
200 					setbit(location[deposit].objects,value);
201 				else{
202 					puts("A thundering explosion nearby sends up a cloud of smoke and shrapnel.");
203 					for (n = 0; n < NUMOFWORDS; n ++)
204 						location[deposit].objects[n] = 0;
205 					setbit(location[deposit].objects,CHAR);
206 				}
207 				if (value == ROPE && position == FINAL)
208 					location[position].access = 1;
209 				switch(deposit){
210 					case 189:
211 					case 231:
212 						puts("The stone door is unhinged.");
213 						location[189].north = 231;
214 						location[231].south = 189;
215 						break;
216 					case 30:
217 						puts("The wooden door is blown open.");
218 						location[30].west = 25;
219 						break;
220 					case 31:
221 						puts("The door is not damaged.");
222 				}
223 			}
224 			else if (value == GRENADE && testbit(location[position].objects,value)){
225 				puts("You are blown into shreds when your grenade explodes.");
226 				die();
227 			}
228 			if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND)
229 				wordnumber++;
230 			else
231 				return(first);
232 		}
233 		return(first);
234 	}
235 	return(first);
236 }
237 
238 drop(name)
239 char *name;
240 {
241 
242 	int firstnumber, value;
243 
244 	firstnumber = wordnumber;
245 	while (wordtype[++wordnumber] == ADJS)
246 		;
247 	while (wordnumber<=wordcount && (wordtype[wordnumber] == OBJECT || wordtype[wordnumber] == NOUNS)) {
248 		value = wordvalue[wordnumber];
249 		printf("%s:\n", objsht[value]);
250 		if (testbit(inven,value)){
251 			clearbit(inven,value);
252 			carrying -= objwt[value];
253 			encumber -= objcumber[value];
254 			if (value == BOMB){
255 				puts("The bomb explodes.  A blinding white light and immense concussion obliterate us.");
256 				die();
257 			}
258 			if (value != AMULET && value != MEDALION && value != TALISMAN)
259 				setbit(location[position].objects,value);
260 			else
261 				tempwiz = 0;
262 			time++;
263 			if (*name == 'K')
264 				puts("Drop kicked.");
265 			else
266 				printf("%s.\n", name);
267 		}
268 		else {
269 			if (*name != 'K') {
270 				printf("You aren't holding the %s.\n", objsht[value]);
271 				if (testbit(location[position].objects,value)) {
272 					if (*name == 'T')
273 						puts("Kicked instead.");
274 					else if (*name == 'G')
275 						puts("Given anyway.");
276 				}
277 			} else
278 				puts("Kicked.");
279 		}
280 		if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND)
281 			wordnumber++;
282 		else
283 			return(firstnumber);
284 	}
285 	puts("Do what?");
286 	return(-1);
287 }
288 
289 takeoff()
290 {
291 	wordnumber = take(wear);
292 	return(drop("Dropped"));
293 }
294 
295 puton()
296 {
297 	wordnumber = take(location[position].objects);
298 	return(wearit());
299 }
300 
301 eat()
302 {
303 	int firstnumber, value;
304 
305 	firstnumber = wordnumber;
306 	while(wordtype[++wordnumber] == ADJS);
307 	while(wordnumber <= wordcount){
308 		value = wordvalue[wordnumber];
309 		switch(value){
310 
311 			case -1:
312 				puts("Eat what?");
313 				return(firstnumber);
314 
315 			default:
316 				printf("You can't eat%s%s!\n",
317 					wordtype[wordnumber] == OBJECT &&
318 					objsht[value]
319 					[strlen(objsht[value]) - 1] == 's' ?
320 					" " : " a ",
321 					words[wordnumber]);
322 				return(firstnumber);
323 
324 			case PAPAYAS:
325 			case PINEAPPLE:
326 			case KIWI:
327 			case COCONUTS:	/* eatable things */
328 			case MANGO:
329 
330 				printf("%s:\n",objsht[value]);
331 				if (testbit(inven,value) && time > ate - CYCLE && testbit(inven,KNIFE)){
332 					clearbit(inven,value);
333 					carrying -= objwt[value];
334 					encumber -= objcumber[value];
335 					ate = max(time,ate) + CYCLE/3;
336 					snooze += CYCLE/10;
337 					time++;
338 					puts("Eaten.  You can explore a little longer now.");
339 				}
340 				else if (time < ate - CYCLE)
341 					puts("You're stuffed.");
342 				else if (!testbit(inven,KNIFE))
343 					puts("You need a knife.");
344 				else
345 					printf("You aren't holding the %s.\n", objsht[value]);
346 				if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND)
347 					wordnumber++;
348 				else
349 					return(firstnumber);
350 		} /* end switch */
351 	} /* end while */
352 	return(firstnumber);
353 }
354