1 /* @(#)cypher.c 8.2 (Berkeley) 4/28/95 */
2 /* $NetBSD: cypher.c,v 1.23 2005/07/01 06:04:54 jmc Exp $ */
5 * Copyright (c) 1983, 1993
6 * The Regents of the University of California. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 char *filename, *rfilename;
45 while (wordnumber <= wordcount) {
46 if (wordtype[wordnumber] != VERB &&
47 !(wordtype[wordnumber] == OBJECT &&
48 wordvalue[wordnumber] == KNIFE)) {
49 printf("%s: How's that?\n",
50 (wordnumber == wordcount) ? words[0] :
55 switch (wordvalue[wordnumber]) {
59 * Take the following word as the verb (e.g.
60 * "make love", "climb up").
66 if (location[position].access || wiz || tempwiz) {
67 if (!location[position].access) {
68 printf("Zap! A gust of wind lifts ");
71 if (!moveplayer(location[position].up, AHEAD))
74 puts("There is no way up.");
81 if (!moveplayer(location[position].down, AHEAD))
87 if (!moveplayer(left, LEFT))
93 if (!moveplayer(right, RIGHT))
99 if (!moveplayer(ahead, AHEAD))
105 if (!moveplayer(back, BACK))
111 if (wordnumber < wordcount &&
112 wordvalue[wordnumber + 1] == EVERYTHING) {
115 for (n = 0; n < NUMOFOBJECTS; n++)
116 if (testbit(location[position].objects,
119 wordvalue[wordnumber + 1] = n;
120 wordnumber = shoot();
123 puts("Nothing to shoot at!");
131 if (wordnumber < wordcount &&
132 wordvalue[wordnumber + 1] == EVERYTHING) {
135 for (n = 0; n < NUMOFOBJECTS; n++)
136 if (testbit(location[position].objects,
139 wordvalue[wordnumber + 1] = n;
140 /* Some objects (type NOUNS)
141 * have special treatment in
142 * take(). For these we
143 * must set the type to NOUNS.
144 * However for SWORD and BODY
145 * all it does is find which
146 * of many objects is meant,
147 * so we need do nothing here.
148 * BATHGOD must become
149 * NORMGOD as well. NOUNS
150 * with no special case
151 * must be included here to
152 * get the right error. DOOR
153 * cannot occur as an object
154 * so need not be included. */
157 wordvalue[wordnumber + 1] = NORMGOD;
166 wordtype[wordnumber + 1] = NOUNS;
169 wordtype[wordnumber + 1] = OBJECT;
171 wordnumber = take(location[position].objects);
176 puts("Nothing to take!");
178 take(location[position].objects);
182 if (wordnumber < wordcount &&
183 wordvalue[wordnumber + 1] == EVERYTHING) {
186 for (n = 0; n < NUMOFOBJECTS; n++)
187 if (testbit(inven, n)) {
189 wordvalue[wordnumber + 1] = n;
190 wordnumber = drop("Dropped");
195 puts("Nothing to drop!");
202 if (wordnumber < wordcount &&
203 wordvalue[wordnumber + 1] == EVERYTHING) {
206 wv = wordvalue[wordnumber];
207 for (n = 0; n < NUMOFOBJECTS; n++)
208 if (testbit(inven, n) ||
209 (testbit(location[position].objects, n) && objsht[n])) {
211 wordvalue[wordnumber + 1] = n;
212 wordnumber = throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown");
216 printf("Nothing to %s!\n",
217 wv == KICK ? "kick" : "throw");
219 throw(wordvalue[wordnumber] ==
220 KICK ? "Kicked" : "Thrown");
224 if (wordnumber < wordcount &&
225 wordvalue[wordnumber + 1] == EVERYTHING) {
228 for (n = 0; n < NUMOFOBJECTS; n++)
229 if (testbit(wear, n)) {
231 wordvalue[wordnumber + 1] = n;
232 wordnumber = takeoff();
236 puts("Nothing to take off!");
242 if (wordnumber < wordcount &&
243 wordvalue[wordnumber + 1] == EVERYTHING) {
246 for (n = 0; n < NUMOFOBJECTS; n++)
247 if (testbit(wear, n)) {
249 wordvalue[wordnumber + 1] = n;
254 puts("Nothing to draw!");
260 if (wordnumber < wordcount &&
261 wordvalue[wordnumber + 1] == EVERYTHING) {
264 for (n = 0; n < NUMOFOBJECTS; n++)
265 if (testbit(location[position].objects,
268 wordvalue[wordnumber + 1] = n;
269 wordnumber = puton();
273 puts("Nothing to put on!");
279 if (wordnumber < wordcount &&
280 wordvalue[wordnumber + 1] == EVERYTHING) {
283 for (n = 0; n < NUMOFOBJECTS; n++)
284 if (testbit(inven, n)) {
286 wordvalue[wordnumber + 1] = n;
287 wordnumber = wearit();
291 puts("Nothing to wear!");
297 if (wordnumber < wordcount &&
298 wordvalue[wordnumber + 1] == EVERYTHING) {
301 for (n = 0; n < NUMOFOBJECTS; n++)
302 if (testbit(inven, n)) {
304 wordvalue[wordnumber + 1] = n;
309 puts("Nothing to eat!");
320 puts("You are holding:\n");
321 for (n = 0; n < NUMOFOBJECTS; n++)
322 if (testbit(inven, n))
323 printf("\t%s\n", objsht[n]);
325 printf("\n= %d kilogram%s",
327 (carrying == 1 ? "." : "s."));
328 printf(" (can't lift any weight%s)\n",
330 " or move with what you have" :
333 printf("\n= %d kilogram%s (%d%%)\n",
335 (carrying == 1 ? "." : "s."),
336 carrying * 100 / WEIGHT);
338 printf("Your arms can't pick ");
339 printf("anything up.\n");
341 printf("Your arms are %d%% full.\n",
342 encumber * 100 / CUMBER);
344 puts("You aren't carrying anything.");
347 puts("\nYou are wearing:\n");
348 for (n = 0; n < NUMOFOBJECTS; n++)
349 if (testbit(wear, n))
350 printf("\t%s\n", objsht[n]);
352 puts("\nYou are stark naked.");
353 if (card(injuries, NUMOFINJURIES)) {
354 puts("\nYou have suffered:\n");
355 for (n = 0; n < NUMOFINJURIES; n++)
357 printf("\t%s\n", ouch[n]);
358 printf("\nYou can still carry up to ");
359 printf("%d kilogram%s\n", WEIGHT,
360 (WEIGHT == 1 ? "." : "s."));
362 puts("\nYou are in perfect health.");
371 if (wordnumber < wordcount &&
372 wordvalue[wordnumber + 1] == EVERYTHING) {
375 for (n = 0; n < NUMOFOBJECTS; n++)
376 if (testbit(inven, n)) {
378 wordvalue[wordnumber + 1] = n;
383 puts("Nothing to open!");
389 if (!notes[CANTSEE] || testbit(inven, LAMPON) ||
390 testbit(location[position].objects, LAMPON)
392 beenthere[position] = 2;
396 puts("\nYour match splutters out.");
400 puts("I can't see anything.");
405 if (wiz || tempwiz) {
406 printf("\nRoom (was %d) = ", position);
407 fgets(buffer, 10, stdin);
409 sscanf(buffer, "%d", &position);
410 printf("Time (was %d) = ", ourtime);
411 fgets(buffer, 10, stdin);
413 sscanf(buffer, "%d", &ourtime);
414 printf("Fuel (was %d) = ", fuel);
415 fgets(buffer, 10, stdin);
417 sscanf(buffer, "%d", &fuel);
418 printf("Torps (was %d) = ", torps);
419 fgets(buffer, 10, stdin);
421 sscanf(buffer, "%d", &torps);
422 printf("CUMBER (was %d) = ", CUMBER);
423 fgets(buffer, 10, stdin);
425 sscanf(buffer, "%d", &CUMBER);
426 printf("WEIGHT (was %d) = ", WEIGHT);
427 fgets(buffer, 10, stdin);
429 sscanf(buffer, "%d", &WEIGHT);
430 printf("Clock (was %d) = ", ourclock);
431 fgets(buffer, 10, stdin);
433 sscanf(buffer, "%d", &ourclock);
434 printf("Wizard (was %d, %d) = ", wiz, tempwiz);
435 fgets(buffer, 10, stdin);
436 if (*buffer != '\n') {
437 sscanf(buffer, "%d", &junk);
444 puts("You aren't a wizard.");
448 printf("\tPLEASURE\tPOWER\t\tEGO\n");
449 printf("\t%3d\t\t%3d\t\t%3d\n\n", pleasure, power, ego);
450 printf("This gives you the rating of ");
451 printf("%s in %d turns.\n", rate(), ourtime);
452 printf("You have visited %d out of %d rooms ",
453 card(beenthere, NUMOFROOMS), NUMOFROOMS);
454 printf("this run (%d%%).\n",
455 card(beenthere, NUMOFROOMS) * 100 / NUMOFROOMS);
469 printf("\nSave file name (default %s): ",
471 filename = fgetln(stdin, &filename_len);
472 if (filename_len == 0
473 || (filename_len == 1 && filename[0] == '\n'))
474 rfilename = save_file_name(DEFAULT_SAVE_FILE,
475 strlen(DEFAULT_SAVE_FILE));
477 if (filename[filename_len - 1] == '\n')
479 rfilename = save_file_name(filename,
488 printf("[Maximum verbosity]\n");
493 printf("[Standard verbosity]\n");
575 if (wordnumber < wordcount && *words[wordnumber++] == ',')