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