]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - battlestar/cypher.c
Add FALLTHROUGH comment.
[bsdgames-darwin.git] / battlestar / cypher.c
1 /* $NetBSD: cypher.c,v 1.10 1999/09/18 16:41:38 jsm 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[] = "@(#)cypher.c 8.2 (Berkeley) 4/28/95";
40 #else
41 __RCSID("$NetBSD: cypher.c,v 1.10 1999/09/18 16:41:38 jsm Exp $");
42 #endif
43 #endif /* not lint */
44
45 #include "extern.h"
46
47 int
48 cypher()
49 {
50 int n;
51 int junk;
52 int lflag = -1;
53 char buffer[10];
54 char *filename, *rfilename;
55 size_t filename_len;
56
57 while (wordtype[wordnumber] == ADJS)
58 wordnumber++;
59 while (wordnumber <= wordcount) {
60 switch (wordvalue[wordnumber]) {
61
62 case UP:
63 if (location[position].access || wiz || tempwiz) {
64 if (!location[position].access)
65 puts("Zap! A gust of wind lifts you up.");
66 if (!move(location[position].up, AHEAD))
67 return (-1);
68 } else {
69 puts("There is no way up");
70 return (-1);
71 }
72 lflag = 0;
73 break;
74
75 case DOWN:
76 if (!move(location[position].down, AHEAD))
77 return (-1);
78 lflag = 0;
79 break;
80
81 case LEFT:
82 if (!move(left, LEFT))
83 return (-1);
84 lflag = 0;
85 break;
86
87 case RIGHT:
88 if (!move(right, RIGHT))
89 return (-1);
90 lflag = 0;
91 break;
92
93 case AHEAD:
94 if (!move(ahead, AHEAD))
95 return (-1);
96 lflag = 0;
97 break;
98
99 case BACK:
100 if (!move(back, BACK))
101 return (-1);
102 lflag = 0;
103 break;
104
105 case SHOOT:
106 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
107 for (n = 0; n < NUMOFOBJECTS; n++)
108 if (testbit(location[position].objects, n) && objsht[n]) {
109 wordvalue[wordnumber + 1] = n;
110 wordnumber = shoot();
111 }
112 wordnumber++;
113 wordnumber++;
114 } else
115 shoot();
116 break;
117
118 case TAKE:
119 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
120 for (n = 0; n < NUMOFOBJECTS; n++)
121 if (testbit(location[position].objects, n) && objsht[n]) {
122 wordvalue[wordnumber + 1] = n;
123 /* Some objects (type NOUNS)
124 * have special treatment in
125 * take(). For these we
126 * must set the type to NOUNS.
127 * However for SWORD and BODY
128 * all it does is find which
129 * of many objects is meant,
130 * so we need do nothing here.
131 * BATHGOD must become
132 * NORMGOD as well. NOUNS
133 * with no special case
134 * must be included here to
135 * get the right error. DOOR
136 * cannot occur as an object
137 * so need not be included. */
138 switch(n) {
139 case BATHGOD:
140 wordvalue[wordnumber + 1] = NORMGOD;
141 /* FALLTHROUGH */
142 case NORMGOD:
143 case AMULET:
144 case MEDALION:
145 case TALISMAN:
146 case MAN:
147 case TIMER:
148 case NATIVE:
149 wordtype[wordnumber + 1] = NOUNS;
150 break;
151 default:
152 wordtype[wordnumber + 1] = OBJECT;
153 }
154 wordnumber = take(location[position].objects);
155 }
156 wordnumber++;
157 wordnumber++;
158 } else
159 take(location[position].objects);
160 break;
161
162 case DROP:
163
164 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
165 for (n = 0; n < NUMOFOBJECTS; n++)
166 if (testbit(inven, n)) {
167 wordvalue[wordnumber + 1] = n;
168 wordnumber = drop("Dropped");
169 }
170 wordnumber++;
171 wordnumber++;
172 } else
173 drop("Dropped");
174 break;
175
176
177 case KICK:
178 case THROW:
179 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
180 for (n = 0; n < NUMOFOBJECTS; n++)
181 if (testbit(inven, n) ||
182 (testbit(location[position].objects, n) && objsht[n])) {
183 wordvalue[wordnumber + 1] = n;
184 wordnumber = throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown");
185 }
186 wordnumber += 2;
187 } else
188 throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown");
189 break;
190
191 case TAKEOFF:
192 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
193 for (n = 0; n < NUMOFOBJECTS; n++)
194 if (testbit(wear, n)) {
195 wordvalue[wordnumber + 1] = n;
196 wordnumber = takeoff();
197 }
198 wordnumber += 2;
199 } else
200 takeoff();
201 break;
202
203
204 case DRAW:
205
206 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
207 for (n = 0; n < NUMOFOBJECTS; n++)
208 if (testbit(wear, n)) {
209 wordvalue[wordnumber + 1] = n;
210 wordnumber = draw();
211 }
212 wordnumber += 2;
213 } else
214 draw();
215 break;
216
217
218 case PUTON:
219
220 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
221 for (n = 0; n < NUMOFOBJECTS; n++)
222 if (testbit(location[position].objects, n) && objsht[n]) {
223 wordvalue[wordnumber + 1] = n;
224 wordnumber = puton();
225 }
226 wordnumber += 2;
227 } else
228 puton();
229 break;
230
231 case WEARIT:
232
233 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
234 for (n = 0; n < NUMOFOBJECTS; n++)
235 if (testbit(inven, n)) {
236 wordvalue[wordnumber + 1] = n;
237 wordnumber = wearit();
238 }
239 wordnumber += 2;
240 } else
241 wearit();
242 break;
243
244
245 case EAT:
246
247 if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) {
248 for (n = 0; n < NUMOFOBJECTS; n++)
249 if (testbit(inven, n)) {
250 wordvalue[wordnumber + 1] = n;
251 wordnumber = eat();
252 }
253 wordnumber += 2;
254 } else
255 eat();
256 break;
257
258
259 case PUT:
260 put();
261 break;
262
263
264 case INVEN:
265 if (ucard(inven)) {
266 puts("You are holding:\n");
267 for (n = 0; n < NUMOFOBJECTS; n++)
268 if (testbit(inven, n))
269 printf("\t%s\n", objsht[n]);
270 printf("\n= %d kilogram%s (%d%%)\n", carrying, (carrying == 1 ? "." : "s."), (WEIGHT ? carrying * 100 / WEIGHT : -1));
271 printf("Your arms are %d%% full.\n", encumber * 100 / CUMBER);
272 } else
273 puts("You aren't carrying anything.");
274
275 if (ucard(wear)) {
276 puts("\nYou are wearing:\n");
277 for (n = 0; n < NUMOFOBJECTS; n++)
278 if (testbit(wear, n))
279 printf("\t%s\n", objsht[n]);
280 } else
281 puts("\nYou are stark naked.");
282 if (card(injuries, NUMOFINJURIES)) {
283 puts("\nYou have suffered:\n");
284 for (n = 0; n < NUMOFINJURIES; n++)
285 if (injuries[n])
286 printf("\t%s\n", ouch[n]);
287 printf("\nYou can still carry up to %d kilogram%s\n", WEIGHT, (WEIGHT == 1 ? "." : "s."));
288 } else
289 puts("\nYou are in perfect health.");
290 break;
291
292 case USE:
293 lflag = use();
294 break;
295
296 case LOOK:
297 if (!notes[CANTSEE] || testbit(inven, LAMPON) ||
298 testbit(location[position].objects, LAMPON)
299 || matchlight) {
300 beenthere[position] = 2;
301 writedes();
302 printobjs();
303 if (matchlight) {
304 puts("\nYour match splutters out.");
305 matchlight = 0;
306 }
307 } else
308 puts("I can't see anything.");
309 return (-1);
310 break;
311
312 case SU:
313 if (wiz || tempwiz) {
314 printf("\nRoom (was %d) = ", position);
315 fgets(buffer, 10, stdin);
316 if (*buffer != '\n')
317 sscanf(buffer, "%d", &position);
318 printf("Time (was %d) = ", ourtime);
319 fgets(buffer, 10, stdin);
320 if (*buffer != '\n')
321 sscanf(buffer, "%d", &ourtime);
322 printf("Fuel (was %d) = ", fuel);
323 fgets(buffer, 10, stdin);
324 if (*buffer != '\n')
325 sscanf(buffer, "%d", &fuel);
326 printf("Torps (was %d) = ", torps);
327 fgets(buffer, 10, stdin);
328 if (*buffer != '\n')
329 sscanf(buffer, "%d", &torps);
330 printf("CUMBER (was %d) = ", CUMBER);
331 fgets(buffer, 10, stdin);
332 if (*buffer != '\n')
333 sscanf(buffer, "%d", &CUMBER);
334 printf("WEIGHT (was %d) = ", WEIGHT);
335 fgets(buffer, 10, stdin);
336 if (*buffer != '\n')
337 sscanf(buffer, "%d", &WEIGHT);
338 printf("Clock (was %d) = ", ourclock);
339 fgets(buffer, 10, stdin);
340 if (*buffer != '\n')
341 sscanf(buffer, "%d", &ourclock);
342 printf("Wizard (was %d, %d) = ", wiz, tempwiz);
343 fgets(buffer, 10, stdin);
344 if (*buffer != '\n') {
345 sscanf(buffer, "%d", &junk);
346 if (!junk)
347 tempwiz = wiz = 0;
348 }
349 printf("\nDONE.\n");
350 return (0);
351 } else
352 puts("You aren't a wizard.");
353 break;
354
355 case SCORE:
356 printf("\tPLEASURE\tPOWER\t\tEGO\n");
357 printf("\t%3d\t\t%3d\t\t%3d\n\n", pleasure, power, ego);
358 printf("This gives you the rating of %s in %d turns.\n", rate(), ourtime);
359 printf("You have visited %d out of %d rooms this run (%d%%).\n", card(beenthere, NUMOFROOMS), NUMOFROOMS, card(beenthere, NUMOFROOMS) * 100 / NUMOFROOMS);
360 break;
361
362 case KNIFE:
363 case KILL:
364 murder();
365 break;
366
367 case UNDRESS:
368 case RAVAGE:
369 ravage();
370 break;
371
372 case SAVE:
373 printf("\nSave file name (default %s) ",
374 DEFAULT_SAVE_FILE);
375 filename = fgetln(stdin, &filename_len);
376 if (filename_len == 0
377 || (filename_len == 1 && filename[0] == '\n'))
378 rfilename = save_file_name(DEFAULT_SAVE_FILE,
379 strlen(DEFAULT_SAVE_FILE));
380 else {
381 if (filename[filename_len - 1] == '\n')
382 filename_len--;
383 rfilename = save_file_name(filename,
384 filename_len);
385 }
386 save(rfilename);
387 free(rfilename);
388 break;
389
390 case FOLLOW:
391 lflag = follow();
392 break;
393
394 case GIVE:
395 give();
396 break;
397
398 case KISS:
399 kiss();
400 break;
401
402 case LOVE:
403 love();
404 break;
405
406 case RIDE:
407 lflag = ride();
408 break;
409
410 case DRIVE:
411 lflag = drive();
412 break;
413
414 case LIGHT:
415 light();
416 break;
417
418 case LAUNCH:
419 if (!launch())
420 return (-1);
421 else
422 lflag = 0;
423 break;
424
425 case LANDIT:
426 if (!land())
427 return (-1);
428 else
429 lflag = 0;
430 break;
431
432 case TIME:
433 chime();
434 break;
435
436 case SLEEP:
437 zzz();
438 break;
439
440 case DIG:
441 dig();
442 break;
443
444 case JUMP:
445 lflag = jump();
446 break;
447
448 case BURY:
449 bury();
450 break;
451
452 case SWIM:
453 puts("Surf's up!");
454 break;
455
456 case DRINK:
457 drink();
458 break;
459
460 case QUIT:
461 die();
462
463 default:
464 puts("How's that?");
465 return (-1);
466 break;
467
468
469 }
470 if (wordnumber < wordcount && *words[wordnumber++] == ',')
471 continue;
472 else
473 return (lflag);
474 }
475 return (lflag);
476 }