1 /* $NetBSD: cypher.c,v 1.22 2003/08/07 09:37:01 agc Exp $ */
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
35 static char sccsid
[] = "@(#)cypher.c 8.2 (Berkeley) 4/28/95";
37 __RCSID("$NetBSD: cypher.c,v 1.22 2003/08/07 09:37:01 agc Exp $");
50 char *filename
, *rfilename
;
53 while (wordnumber
<= wordcount
) {
54 if (wordtype
[wordnumber
] != VERB
&&
55 !(wordtype
[wordnumber
] == OBJECT
&&
56 wordvalue
[wordnumber
] == KNIFE
)) {
57 printf("%s: How's that?\n",
58 (wordnumber
== wordcount
) ? words
[0] :
63 switch (wordvalue
[wordnumber
]) {
67 * Take the following word as the verb (e.g.
68 * "make love", "climb up").
74 if (location
[position
].access
|| wiz
|| tempwiz
) {
75 if (!location
[position
].access
) {
76 printf("Zap! A gust of wind lifts ");
79 if (!moveplayer(location
[position
].up
, AHEAD
))
82 puts("There is no way up.");
89 if (!moveplayer(location
[position
].down
, AHEAD
))
95 if (!moveplayer(left
, LEFT
))
101 if (!moveplayer(right
, RIGHT
))
107 if (!moveplayer(ahead
, AHEAD
))
113 if (!moveplayer(back
, BACK
))
119 if (wordnumber
< wordcount
&&
120 wordvalue
[wordnumber
+ 1] == EVERYTHING
) {
123 for (n
= 0; n
< NUMOFOBJECTS
; n
++)
124 if (testbit(location
[position
].objects
,
127 wordvalue
[wordnumber
+ 1] = n
;
128 wordnumber
= shoot();
131 puts("Nothing to shoot at!");
139 if (wordnumber
< wordcount
&&
140 wordvalue
[wordnumber
+ 1] == EVERYTHING
) {
143 for (n
= 0; n
< NUMOFOBJECTS
; n
++)
144 if (testbit(location
[position
].objects
,
147 wordvalue
[wordnumber
+ 1] = n
;
148 /* Some objects (type NOUNS)
149 * have special treatment in
150 * take(). For these we
151 * must set the type to NOUNS.
152 * However for SWORD and BODY
153 * all it does is find which
154 * of many objects is meant,
155 * so we need do nothing here.
156 * BATHGOD must become
157 * NORMGOD as well. NOUNS
158 * with no special case
159 * must be included here to
160 * get the right error. DOOR
161 * cannot occur as an object
162 * so need not be included. */
165 wordvalue
[wordnumber
+ 1] = NORMGOD
;
174 wordtype
[wordnumber
+ 1] = NOUNS
;
177 wordtype
[wordnumber
+ 1] = OBJECT
;
179 wordnumber
= take(location
[position
].objects
);
184 puts("Nothing to take!");
186 take(location
[position
].objects
);
190 if (wordnumber
< wordcount
&&
191 wordvalue
[wordnumber
+ 1] == EVERYTHING
) {
194 for (n
= 0; n
< NUMOFOBJECTS
; n
++)
195 if (testbit(inven
, n
)) {
197 wordvalue
[wordnumber
+ 1] = n
;
198 wordnumber
= drop("Dropped");
203 puts("Nothing to drop!");
210 if (wordnumber
< wordcount
&&
211 wordvalue
[wordnumber
+ 1] == EVERYTHING
) {
214 wv
= wordvalue
[wordnumber
];
215 for (n
= 0; n
< NUMOFOBJECTS
; n
++)
216 if (testbit(inven
, n
) ||
217 (testbit(location
[position
].objects
, n
) && objsht
[n
])) {
219 wordvalue
[wordnumber
+ 1] = n
;
220 wordnumber
= throw(wordvalue
[wordnumber
] == KICK
? "Kicked" : "Thrown");
224 printf("Nothing to %s!\n",
225 wv
== KICK
? "kick" : "throw");
227 throw(wordvalue
[wordnumber
] ==
228 KICK
? "Kicked" : "Thrown");
232 if (wordnumber
< wordcount
&&
233 wordvalue
[wordnumber
+ 1] == EVERYTHING
) {
236 for (n
= 0; n
< NUMOFOBJECTS
; n
++)
237 if (testbit(wear
, n
)) {
239 wordvalue
[wordnumber
+ 1] = n
;
240 wordnumber
= takeoff();
244 puts("Nothing to take off!");
250 if (wordnumber
< wordcount
&&
251 wordvalue
[wordnumber
+ 1] == EVERYTHING
) {
254 for (n
= 0; n
< NUMOFOBJECTS
; n
++)
255 if (testbit(wear
, n
)) {
257 wordvalue
[wordnumber
+ 1] = n
;
262 puts("Nothing to draw!");
268 if (wordnumber
< wordcount
&&
269 wordvalue
[wordnumber
+ 1] == EVERYTHING
) {
272 for (n
= 0; n
< NUMOFOBJECTS
; n
++)
273 if (testbit(location
[position
].objects
,
276 wordvalue
[wordnumber
+ 1] = n
;
277 wordnumber
= puton();
281 puts("Nothing to put on!");
287 if (wordnumber
< wordcount
&&
288 wordvalue
[wordnumber
+ 1] == EVERYTHING
) {
291 for (n
= 0; n
< NUMOFOBJECTS
; n
++)
292 if (testbit(inven
, n
)) {
294 wordvalue
[wordnumber
+ 1] = n
;
295 wordnumber
= wearit();
299 puts("Nothing to wear!");
305 if (wordnumber
< wordcount
&&
306 wordvalue
[wordnumber
+ 1] == EVERYTHING
) {
309 for (n
= 0; n
< NUMOFOBJECTS
; n
++)
310 if (testbit(inven
, n
)) {
312 wordvalue
[wordnumber
+ 1] = n
;
317 puts("Nothing to eat!");
328 puts("You are holding:\n");
329 for (n
= 0; n
< NUMOFOBJECTS
; n
++)
330 if (testbit(inven
, n
))
331 printf("\t%s\n", objsht
[n
]);
333 printf("\n= %d kilogram%s",
335 (carrying
== 1 ? "." : "s."));
336 printf(" (can't lift any weight%s)\n",
338 " or move with what you have" :
341 printf("\n= %d kilogram%s (%d%%)\n",
343 (carrying
== 1 ? "." : "s."),
344 carrying
* 100 / WEIGHT
);
346 printf("Your arms can't pick ");
347 printf("anything up.\n");
349 printf("Your arms are %d%% full.\n",
350 encumber
* 100 / CUMBER
);
352 puts("You aren't carrying anything.");
355 puts("\nYou are wearing:\n");
356 for (n
= 0; n
< NUMOFOBJECTS
; n
++)
357 if (testbit(wear
, n
))
358 printf("\t%s\n", objsht
[n
]);
360 puts("\nYou are stark naked.");
361 if (card(injuries
, NUMOFINJURIES
)) {
362 puts("\nYou have suffered:\n");
363 for (n
= 0; n
< NUMOFINJURIES
; n
++)
365 printf("\t%s\n", ouch
[n
]);
366 printf("\nYou can still carry up to ");
367 printf("%d kilogram%s\n", WEIGHT
,
368 (WEIGHT
== 1 ? "." : "s."));
370 puts("\nYou are in perfect health.");
379 if (wordnumber
< wordcount
&&
380 wordvalue
[wordnumber
+ 1] == EVERYTHING
) {
383 for (n
= 0; n
< NUMOFOBJECTS
; n
++)
384 if (testbit(inven
, n
)) {
386 wordvalue
[wordnumber
+ 1] = n
;
391 puts("Nothing to open!");
397 if (!notes
[CANTSEE
] || testbit(inven
, LAMPON
) ||
398 testbit(location
[position
].objects
, LAMPON
)
400 beenthere
[position
] = 2;
404 puts("\nYour match splutters out.");
408 puts("I can't see anything.");
413 if (wiz
|| tempwiz
) {
414 printf("\nRoom (was %d) = ", position
);
415 fgets(buffer
, 10, stdin
);
417 sscanf(buffer
, "%d", &position
);
418 printf("Time (was %d) = ", ourtime
);
419 fgets(buffer
, 10, stdin
);
421 sscanf(buffer
, "%d", &ourtime
);
422 printf("Fuel (was %d) = ", fuel
);
423 fgets(buffer
, 10, stdin
);
425 sscanf(buffer
, "%d", &fuel
);
426 printf("Torps (was %d) = ", torps
);
427 fgets(buffer
, 10, stdin
);
429 sscanf(buffer
, "%d", &torps
);
430 printf("CUMBER (was %d) = ", CUMBER
);
431 fgets(buffer
, 10, stdin
);
433 sscanf(buffer
, "%d", &CUMBER
);
434 printf("WEIGHT (was %d) = ", WEIGHT
);
435 fgets(buffer
, 10, stdin
);
437 sscanf(buffer
, "%d", &WEIGHT
);
438 printf("Clock (was %d) = ", ourclock
);
439 fgets(buffer
, 10, stdin
);
441 sscanf(buffer
, "%d", &ourclock
);
442 printf("Wizard (was %d, %d) = ", wiz
, tempwiz
);
443 fgets(buffer
, 10, stdin
);
444 if (*buffer
!= '\n') {
445 sscanf(buffer
, "%d", &junk
);
452 puts("You aren't a wizard.");
456 printf("\tPLEASURE\tPOWER\t\tEGO\n");
457 printf("\t%3d\t\t%3d\t\t%3d\n\n", pleasure
, power
, ego
);
458 printf("This gives you the rating of ");
459 printf("%s in %d turns.\n", rate(), ourtime
);
460 printf("You have visited %d out of %d rooms ",
461 card(beenthere
, NUMOFROOMS
), NUMOFROOMS
);
462 printf("this run (%d%%).\n",
463 card(beenthere
, NUMOFROOMS
) * 100 / NUMOFROOMS
);
477 printf("\nSave file name (default %s): ",
479 filename
= fgetln(stdin
, &filename_len
);
480 if (filename_len
== 0
481 || (filename_len
== 1 && filename
[0] == '\n'))
482 rfilename
= save_file_name(DEFAULT_SAVE_FILE
,
483 strlen(DEFAULT_SAVE_FILE
));
485 if (filename
[filename_len
- 1] == '\n')
487 rfilename
= save_file_name(filename
,
496 printf("[Maximum verbosity]\n");
501 printf("[Standard verbosity]\n");
583 if (wordnumber
< wordcount
&& *words
[wordnumber
++] == ',')