]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - battlestar/cypher.c
1 /* $NetBSD: cypher.c,v 1.18 2000/09/24 09:41:53 jsm 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. 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.
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
36 #include <sys/cdefs.h>
39 static char sccsid
[] = "@(#)cypher.c 8.2 (Berkeley) 4/28/95";
41 __RCSID("$NetBSD: cypher.c,v 1.18 2000/09/24 09:41:53 jsm Exp $");
54 char *filename
, *rfilename
;
57 while (wordnumber
<= wordcount
) {
58 switch (wordvalue
[wordnumber
]) {
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
))
67 puts("There is no way up.");
74 if (!moveplayer(location
[position
].down
, AHEAD
))
80 if (!moveplayer(left
, LEFT
))
86 if (!moveplayer(right
, RIGHT
))
92 if (!moveplayer(ahead
, AHEAD
))
98 if (!moveplayer(back
, BACK
))
104 if (wordnumber
< wordcount
&& wordvalue
[wordnumber
+ 1] == EVERYTHING
) {
107 for (n
= 0; n
< NUMOFOBJECTS
; n
++)
108 if (testbit(location
[position
].objects
, n
) && objsht
[n
]) {
110 wordvalue
[wordnumber
+ 1] = n
;
111 wordnumber
= shoot();
114 puts("Nothing to shoot at!");
122 if (wordnumber
< wordcount
&& wordvalue
[wordnumber
+ 1] == EVERYTHING
) {
125 for (n
= 0; n
< NUMOFOBJECTS
; n
++)
126 if (testbit(location
[position
].objects
, n
) && objsht
[n
]) {
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. */
146 wordvalue
[wordnumber
+ 1] = NORMGOD
;
155 wordtype
[wordnumber
+ 1] = NOUNS
;
158 wordtype
[wordnumber
+ 1] = OBJECT
;
160 wordnumber
= take(location
[position
].objects
);
165 puts("Nothing to take!");
167 take(location
[position
].objects
);
172 if (wordnumber
< wordcount
&& wordvalue
[wordnumber
+ 1] == EVERYTHING
) {
175 for (n
= 0; n
< NUMOFOBJECTS
; n
++)
176 if (testbit(inven
, n
)) {
178 wordvalue
[wordnumber
+ 1] = n
;
179 wordnumber
= drop("Dropped");
184 puts("Nothing to drop!");
192 if (wordnumber
< wordcount
&& wordvalue
[wordnumber
+ 1] == EVERYTHING
) {
195 wv
= wordvalue
[wordnumber
];
196 for (n
= 0; n
< NUMOFOBJECTS
; n
++)
197 if (testbit(inven
, n
) ||
198 (testbit(location
[position
].objects
, n
) && objsht
[n
])) {
200 wordvalue
[wordnumber
+ 1] = n
;
201 wordnumber
= throw(wordvalue
[wordnumber
] == KICK
? "Kicked" : "Thrown");
205 printf("Nothing to %s!\n", wv
== KICK
? "kick" : "throw");
207 throw(wordvalue
[wordnumber
] == KICK
? "Kicked" : "Thrown");
211 if (wordnumber
< wordcount
&& wordvalue
[wordnumber
+ 1] == EVERYTHING
) {
214 for (n
= 0; n
< NUMOFOBJECTS
; n
++)
215 if (testbit(wear
, n
)) {
217 wordvalue
[wordnumber
+ 1] = n
;
218 wordnumber
= takeoff();
222 puts("Nothing to take off!");
230 if (wordnumber
< wordcount
&& wordvalue
[wordnumber
+ 1] == EVERYTHING
) {
233 for (n
= 0; n
< NUMOFOBJECTS
; n
++)
234 if (testbit(wear
, n
)) {
236 wordvalue
[wordnumber
+ 1] = n
;
241 puts("Nothing to draw!");
249 if (wordnumber
< wordcount
&& wordvalue
[wordnumber
+ 1] == EVERYTHING
) {
252 for (n
= 0; n
< NUMOFOBJECTS
; n
++)
253 if (testbit(location
[position
].objects
, n
) && objsht
[n
]) {
255 wordvalue
[wordnumber
+ 1] = n
;
256 wordnumber
= puton();
260 puts("Nothing to put on!");
267 if (wordnumber
< wordcount
&& wordvalue
[wordnumber
+ 1] == EVERYTHING
) {
270 for (n
= 0; n
< NUMOFOBJECTS
; n
++)
271 if (testbit(inven
, n
)) {
273 wordvalue
[wordnumber
+ 1] = n
;
274 wordnumber
= wearit();
278 puts("Nothing to wear!");
286 if (wordnumber
< wordcount
&& wordvalue
[wordnumber
+ 1] == EVERYTHING
) {
289 for (n
= 0; n
< NUMOFOBJECTS
; n
++)
290 if (testbit(inven
, n
)) {
292 wordvalue
[wordnumber
+ 1] = n
;
297 puts("Nothing to eat!");
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",
316 (CUMBER
? encumber
* 100 / CUMBER
: -1));
318 puts("You aren't carrying anything.");
321 puts("\nYou are wearing:\n");
322 for (n
= 0; n
< NUMOFOBJECTS
; n
++)
323 if (testbit(wear
, n
))
324 printf("\t%s\n", objsht
[n
]);
326 puts("\nYou are stark naked.");
327 if (card(injuries
, NUMOFINJURIES
)) {
328 puts("\nYou have suffered:\n");
329 for (n
= 0; n
< NUMOFINJURIES
; n
++)
331 printf("\t%s\n", ouch
[n
]);
332 printf("\nYou can still carry up to %d kilogram%s\n", WEIGHT
, (WEIGHT
== 1 ? "." : "s."));
334 puts("\nYou are in perfect health.");
343 if (wordnumber
< wordcount
&& wordvalue
[wordnumber
+ 1] == EVERYTHING
) {
346 for (n
= 0; n
< NUMOFOBJECTS
; n
++)
347 if (testbit(inven
, n
)) {
349 wordvalue
[wordnumber
+ 1] = n
;
354 puts("Nothing to open!");
360 if (!notes
[CANTSEE
] || testbit(inven
, LAMPON
) ||
361 testbit(location
[position
].objects
, LAMPON
)
363 beenthere
[position
] = 2;
367 puts("\nYour match splutters out.");
371 puts("I can't see anything.");
376 if (wiz
|| tempwiz
) {
377 printf("\nRoom (was %d) = ", position
);
378 fgets(buffer
, 10, stdin
);
380 sscanf(buffer
, "%d", &position
);
381 printf("Time (was %d) = ", ourtime
);
382 fgets(buffer
, 10, stdin
);
384 sscanf(buffer
, "%d", &ourtime
);
385 printf("Fuel (was %d) = ", fuel
);
386 fgets(buffer
, 10, stdin
);
388 sscanf(buffer
, "%d", &fuel
);
389 printf("Torps (was %d) = ", torps
);
390 fgets(buffer
, 10, stdin
);
392 sscanf(buffer
, "%d", &torps
);
393 printf("CUMBER (was %d) = ", CUMBER
);
394 fgets(buffer
, 10, stdin
);
396 sscanf(buffer
, "%d", &CUMBER
);
397 printf("WEIGHT (was %d) = ", WEIGHT
);
398 fgets(buffer
, 10, stdin
);
400 sscanf(buffer
, "%d", &WEIGHT
);
401 printf("Clock (was %d) = ", ourclock
);
402 fgets(buffer
, 10, stdin
);
404 sscanf(buffer
, "%d", &ourclock
);
405 printf("Wizard (was %d, %d) = ", wiz
, tempwiz
);
406 fgets(buffer
, 10, stdin
);
407 if (*buffer
!= '\n') {
408 sscanf(buffer
, "%d", &junk
);
415 puts("You aren't a wizard.");
419 printf("\tPLEASURE\tPOWER\t\tEGO\n");
420 printf("\t%3d\t\t%3d\t\t%3d\n\n", pleasure
, power
, ego
);
421 printf("This gives you the rating of %s in %d turns.\n", rate(), ourtime
);
422 printf("You have visited %d out of %d rooms this run (%d%%).\n", card(beenthere
, NUMOFROOMS
), NUMOFROOMS
, card(beenthere
, NUMOFROOMS
) * 100 / NUMOFROOMS
);
436 printf("\nSave file name (default %s): ",
438 filename
= fgetln(stdin
, &filename_len
);
439 if (filename_len
== 0
440 || (filename_len
== 1 && filename
[0] == '\n'))
441 rfilename
= save_file_name(DEFAULT_SAVE_FILE
,
442 strlen(DEFAULT_SAVE_FILE
));
444 if (filename
[filename_len
- 1] == '\n')
446 rfilename
= save_file_name(filename
,
455 printf("[Maximum verbosity]\n");
460 printf("[Standard verbosity]\n");
543 if (wordnumber
< wordcount
&& *words
[wordnumber
++] == ',')