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