xref: /dragonfly/games/battlestar/cypher.c (revision 984263bc)
1 /*
2  * Copyright (c) 1983, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *	This product includes software developed by the University of
16  *	California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  */
33 
34 #ifndef lint
35 #if 0
36 static char sccsid[] = "@(#)cypher.c	8.1 (Berkeley) 5/31/93";
37 #endif
38 static const char rcsid[] =
39  "$FreeBSD: src/games/battlestar/cypher.c,v 1.7.2.1 2001/03/05 11:45:36 kris Exp $";
40 #endif /* not lint */
41 
42 #include "externs.h"
43 
44 int
45 cypher()
46 {
47 	int n;
48 	int junk;
49 	int lflag = -1;
50 	char buffer[10];
51 
52 	while (wordtype[wordnumber] == ADJS)
53 		wordnumber++;
54 	while (wordnumber <= wordcount) {
55 		switch(wordvalue[wordnumber]) {
56 
57 			case UP:
58 				if (location[position].access || wiz || tempwiz) {
59 					if (!location[position].access)
60 						puts("Zap!  A gust of wind lifts you up.");
61 					if (!battlestar_move(location[position].up, AHEAD))
62 						return(-1);
63 				} else {
64 					puts("There is no way up");
65 					return(-1);
66 				}
67 				lflag = 0;
68 				break;
69 
70 			 case DOWN:
71 				if (!battlestar_move(location[position].down,
72 				     AHEAD))
73 					return(-1);
74 				lflag = 0;
75 				break;
76 
77 			 case LEFT:
78 				if (!battlestar_move(left, LEFT))
79 					return(-1);
80 				lflag = 0;
81 				break;
82 
83 			 case RIGHT:
84 				if (!battlestar_move(right, RIGHT))
85 					return(-1);
86 				lflag = 0;
87 				break;
88 
89 			 case AHEAD:
90 				if (!battlestar_move(ahead, AHEAD))
91 					return(-1);
92 				lflag = 0;
93 				break;
94 
95 			 case BACK:
96 				if (!battlestar_move(back, BACK))
97 					return(-1);
98 				lflag = 0;
99 				break;
100 
101 			 case SHOOT:
102 				if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
103 					for (n=0; n < NUMOFOBJECTS; n++)
104 						if (testbit(location[position].objects,n) && objsht[n]){
105 							wordvalue[wordnumber+1] = n;
106 							wordnumber = shoot();
107 						}
108 				wordnumber++;
109 				wordnumber++;
110 				}
111 				else
112 					shoot();
113 				break;
114 
115 			 case TAKE:
116 				if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
117 					for (n=0; n < NUMOFOBJECTS; n++)
118 						if (testbit(location[position].objects,n) && objsht[n]){
119 							wordvalue[wordnumber+1] = n;
120 							wordnumber = take(location[position].objects);
121 						}
122 				wordnumber++;
123 				wordnumber++;
124 				}
125 				else
126 					take(location[position].objects);
127 				break;
128 
129 			 case DROP:
130 
131 				if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
132 					for (n=0; n < NUMOFOBJECTS; n++)
133 						if (testbit(inven,n)){
134 							wordvalue[wordnumber+1] = n;
135 							wordnumber = drop("Dropped");
136 						}
137 				wordnumber++;
138 				wordnumber++;
139 				}
140 				else
141 					drop("Dropped");
142 				break;
143 
144 
145 			 case KICK:
146 			 case THROW:
147 				if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
148 					for (n=0; n < NUMOFOBJECTS; n++)
149 						if ((testbit(inven,n) ||
150 						  testbit(location[position].objects, n)) && objsht[n]){
151 							wordvalue[wordnumber+1] = n;
152 							wordnumber = throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown");
153 						}
154 					wordnumber += 2;
155 				} else
156 					throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown");
157 				break;
158 
159 			 case TAKEOFF:
160 				if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
161 					for (n=0; n < NUMOFOBJECTS; n++)
162 						if (testbit(wear,n)){
163 							wordvalue[wordnumber+1] = n;
164 							wordnumber = takeoff();
165 						}
166 					wordnumber += 2;
167 				}
168 				else
169 					takeoff();
170 				break;
171 
172 
173 			 case DRAW:
174 
175 				if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
176 					for (n=0; n < NUMOFOBJECTS; n++)
177 						if (testbit(wear,n)){
178 							wordvalue[wordnumber+1] = n;
179 							wordnumber = draw();
180 						}
181 					wordnumber += 2;
182 				}
183 				else
184 					draw();
185 				break;
186 
187 
188 			 case PUTON:
189 
190 				if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
191 					for (n=0; n < NUMOFOBJECTS; n++)
192 						if (testbit(location[position].objects,n) && objsht[n]){
193 							wordvalue[wordnumber+1] = n;
194 							wordnumber = puton();
195 						}
196 					wordnumber += 2;
197 				}
198 				else
199 					puton();
200 				break;
201 
202 			 case WEARIT:
203 
204 				if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
205 					for (n=0; n < NUMOFOBJECTS; n++)
206 						if (testbit(inven,n)){
207 							wordvalue[wordnumber+1] = n;
208 							wordnumber = wearit();
209 						}
210 					wordnumber += 2;
211 				}
212 				else
213 					wearit();
214 				break;
215 
216 
217 			 case EAT:
218 
219 				if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
220 					for (n=0; n < NUMOFOBJECTS; n++)
221 						if (testbit(inven,n)){
222 							wordvalue[wordnumber+1] = n;
223 							wordnumber = eat();
224 						}
225 					wordnumber += 2;
226 				}
227 				else
228 					eat();
229 				break;
230 
231 
232 			case PUT:
233 				put();
234 				break;
235 
236 
237 			case INVEN:
238 				if (ucard(inven)){
239 					puts("You are holding:\n");
240 					for (n=0; n < NUMOFOBJECTS; n++)
241 						if (testbit(inven,n))
242 							printf("\t%s\n", objsht[n]);
243 					printf("\n= %d kilogram%s (%d%%)\n", carrying, (carrying == 1 ? "." : "s."),(WEIGHT ? carrying*100/WEIGHT : -1));
244 					printf("Your arms are %d%% full.\n",encumber*100/CUMBER);
245 				}
246 				else
247 					puts("You aren't carrying anything.");
248 
249 				if (ucard(wear)){
250 					puts("\nYou are wearing:\n");
251 					for (n=0; n < NUMOFOBJECTS; n++)
252 						if (testbit(wear,n))
253 							printf("\t%s\n", objsht[n]);
254 				}
255 				else
256 					puts("\nYou are stark naked.");
257 				if (card(injuries,NUMOFINJURIES)){
258 					puts("\nYou have suffered:\n");
259 					for (n=0; n < NUMOFINJURIES; n++)
260 						if (injuries[n])
261 							printf("\t%s\n",ouch[n]);
262 					printf("\nYou can still carry up to %d kilogram%s\n",WEIGHT,(WEIGHT == 1 ? "." : "s."));
263 				}
264 				else
265 					puts("\nYou are in perfect health.");
266 				break;
267 
268 			case USE:
269 				lflag = use();
270 				break;
271 
272 			case LOOK:
273 				if (!notes[CANTSEE] || testbit(inven,LAMPON) || testbit(location[position].objects,LAMPON) || matchlight){
274 					beenthere[position] = 2;
275 					writedes();
276 					printobjs();
277 					if (matchlight){
278 						puts("\nYour match splutters out.");
279 						matchlight = 0;
280 					}
281 				} else
282 					puts("I can't see anything.");
283 				return(-1);
284 				break;
285 
286 			 case SU:
287 			 if (wiz || tempwiz){
288 				printf("\nRoom (was %d) = ", position);
289 				fgets(buffer,10,stdin);
290 				if (*buffer != '\n')
291 					sscanf(buffer,"%d", &position);
292 				printf("Time (was %d) = ",gtime);
293 				fgets(buffer,10,stdin);
294 				if (*buffer != '\n')
295 					sscanf(buffer,"%d", &gtime);
296 				printf("Fuel (was %d) = ",fuel);
297 				fgets(buffer,10,stdin);
298 				if (*buffer != '\n')
299 					sscanf(buffer,"%d", &fuel);
300 				printf("Torps (was %d) = ",torps);
301 				fgets(buffer,10,stdin);
302 				if (*buffer != '\n')
303 					sscanf(buffer,"%d", &torps);
304 				printf("CUMBER (was %d) = ",CUMBER);
305 				fgets(buffer,10,stdin);
306 				if (*buffer != '\n')
307 					sscanf(buffer,"%d", &CUMBER);
308 				printf("WEIGHT (was %d) = ",WEIGHT);
309 				fgets(buffer,10,stdin);
310 				if (*buffer != '\n')
311 					sscanf(buffer,"%d",&WEIGHT);
312 				printf("Clock (was %d) = ",gclock);
313 				fgets(buffer,10,stdin);
314 				if (*buffer != '\n')
315 					sscanf(buffer,"%d",&gclock);
316 				printf("Wizard (was %d, %d) = ",wiz, tempwiz);
317 				fgets(buffer,10,stdin);
318 				if (*buffer != '\n'){
319 					sscanf(buffer,"%d",&junk);
320 					if (!junk)
321 						tempwiz = wiz = 0;
322 				}
323 				printf("\nDONE.\n");
324 				return(0);
325 			 }
326 			 else
327 				 puts("You aren't a wizard.");
328 			 break;
329 
330 			 case SCORE:
331 				printf("\tPLEASURE\tPOWER\t\tEGO\n");
332 				printf("\t%3d\t\t%3d\t\t%3d\n\n",pleasure,power,ego);
333 				printf("This gives you the rating of %s in %d turns.\n",rate(),gtime);
334 				printf("You have visited %d out of %d rooms this run (%d%%).\n",card(beenthere,NUMOFROOMS),NUMOFROOMS,card(beenthere,NUMOFROOMS)*100/NUMOFROOMS);
335 				break;
336 
337 			 case KNIFE:
338 			 case KILL:
339 				murder();
340 				break;
341 
342 			 case UNDRESS:
343 			 case RAVAGE:
344 				ravage();
345 				break;
346 
347 			 case SAVE:
348 				save();
349 				break;
350 
351 			 case FOLLOW:
352 				lflag = follow();
353 				break;
354 
355 			 case GIVE:
356 				give();
357 				break;
358 
359 			 case KISS:
360 				kiss();
361 				break;
362 
363 			 case LOVE:
364 				 love();
365 				 break;
366 
367 			 case RIDE:
368 				lflag = ride();
369 				break;
370 
371 			 case DRIVE:
372 				lflag = drive();
373 				break;
374 
375 			 case LIGHT:
376 				 light();
377 				 break;
378 
379 			 case LAUNCH:
380 				if (!launch())
381 					return(-1);
382 				else
383 					lflag = 0;
384 				break;
385 
386 			case LANDIT:
387 				if (!land())
388 					return(-1);
389 				else
390 					lflag = 0;
391 				break;
392 
393 			case TIME:
394 				chime();
395 				break;
396 
397 			 case SLEEP:
398 				zzz();
399 				break;
400 
401 			 case DIG:
402 				dig();
403 				break;
404 
405 			 case JUMP:
406 				lflag = jump();
407 				break;
408 
409 			 case BURY:
410 				bury();
411 				break;
412 
413 			 case SWIM:
414 				puts("Surf's up!");
415 				break;
416 
417 			 case DRINK:
418 				drink();
419 				break;
420 
421 			 case QUIT:
422 				die(0);
423 
424 			 default:
425 				puts("How's that?");
426 				return(-1);
427 				break;
428 
429 
430 		}
431 		if (wordnumber < wordcount && *words[wordnumber++] == ',')
432 			continue;
433 		else return(lflag);
434        }
435        return(lflag);
436 }
437