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