]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - battlestar/cypher.c
1 /* $NetBSD: cypher.c,v 1.19 2000/09/24 14:42:18 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.19 2000/09/24 14:42:18 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
]);
315 printf("\n= %d kilogram%s (can't lift any weight%s)\n",
317 (carrying
== 1 ? "." : "s."),
318 (carrying
? " or move with what you have" : ""));
320 printf("\n= %d kilogram%s (%d%%)\n",
322 (carrying
== 1 ? "." : "s."),
323 carrying
* 100 / WEIGHT
);
325 printf("Your arms can't pick anything up.\n");
327 printf("Your arms are %d%% full.\n",
328 encumber
* 100 / CUMBER
);
330 puts("You aren't carrying anything.");
333 puts("\nYou are wearing:\n");
334 for (n
= 0; n
< NUMOFOBJECTS
; n
++)
335 if (testbit(wear
, n
))
336 printf("\t%s\n", objsht
[n
]);
338 puts("\nYou are stark naked.");
339 if (card(injuries
, NUMOFINJURIES
)) {
340 puts("\nYou have suffered:\n");
341 for (n
= 0; n
< NUMOFINJURIES
; n
++)
343 printf("\t%s\n", ouch
[n
]);
344 printf("\nYou can still carry up to %d kilogram%s\n", WEIGHT
, (WEIGHT
== 1 ? "." : "s."));
346 puts("\nYou are in perfect health.");
355 if (wordnumber
< wordcount
&& wordvalue
[wordnumber
+ 1] == EVERYTHING
) {
358 for (n
= 0; n
< NUMOFOBJECTS
; n
++)
359 if (testbit(inven
, n
)) {
361 wordvalue
[wordnumber
+ 1] = n
;
366 puts("Nothing to open!");
372 if (!notes
[CANTSEE
] || testbit(inven
, LAMPON
) ||
373 testbit(location
[position
].objects
, LAMPON
)
375 beenthere
[position
] = 2;
379 puts("\nYour match splutters out.");
383 puts("I can't see anything.");
388 if (wiz
|| tempwiz
) {
389 printf("\nRoom (was %d) = ", position
);
390 fgets(buffer
, 10, stdin
);
392 sscanf(buffer
, "%d", &position
);
393 printf("Time (was %d) = ", ourtime
);
394 fgets(buffer
, 10, stdin
);
396 sscanf(buffer
, "%d", &ourtime
);
397 printf("Fuel (was %d) = ", fuel
);
398 fgets(buffer
, 10, stdin
);
400 sscanf(buffer
, "%d", &fuel
);
401 printf("Torps (was %d) = ", torps
);
402 fgets(buffer
, 10, stdin
);
404 sscanf(buffer
, "%d", &torps
);
405 printf("CUMBER (was %d) = ", CUMBER
);
406 fgets(buffer
, 10, stdin
);
408 sscanf(buffer
, "%d", &CUMBER
);
409 printf("WEIGHT (was %d) = ", WEIGHT
);
410 fgets(buffer
, 10, stdin
);
412 sscanf(buffer
, "%d", &WEIGHT
);
413 printf("Clock (was %d) = ", ourclock
);
414 fgets(buffer
, 10, stdin
);
416 sscanf(buffer
, "%d", &ourclock
);
417 printf("Wizard (was %d, %d) = ", wiz
, tempwiz
);
418 fgets(buffer
, 10, stdin
);
419 if (*buffer
!= '\n') {
420 sscanf(buffer
, "%d", &junk
);
427 puts("You aren't a wizard.");
431 printf("\tPLEASURE\tPOWER\t\tEGO\n");
432 printf("\t%3d\t\t%3d\t\t%3d\n\n", pleasure
, power
, ego
);
433 printf("This gives you the rating of %s in %d turns.\n", rate(), ourtime
);
434 printf("You have visited %d out of %d rooms this run (%d%%).\n", card(beenthere
, NUMOFROOMS
), NUMOFROOMS
, card(beenthere
, NUMOFROOMS
) * 100 / NUMOFROOMS
);
448 printf("\nSave file name (default %s): ",
450 filename
= fgetln(stdin
, &filename_len
);
451 if (filename_len
== 0
452 || (filename_len
== 1 && filename
[0] == '\n'))
453 rfilename
= save_file_name(DEFAULT_SAVE_FILE
,
454 strlen(DEFAULT_SAVE_FILE
));
456 if (filename
[filename_len
- 1] == '\n')
458 rfilename
= save_file_name(filename
,
467 printf("[Maximum verbosity]\n");
472 printf("[Standard verbosity]\n");
555 if (wordnumber
< wordcount
&& *words
[wordnumber
++] == ',')