2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
5 * The game adventure was originally written in Fortran by Will Crowther
6 * and Don Woods. It was later translated to C and enhanced by Jim
7 * Gillogly. This code is derived from software contributed to Berkeley
8 * by Jim Gillogly at The Rand Corporation.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @(#) Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved.
35 * @(#)main.c 8.1 (Berkeley) 6/2/93
36 * $FreeBSD: src/games/adventure/main.c,v 1.9.2.1 2001/03/05 11:43:11 kris Exp $
37 * $DragonFly: src/games/adventure/main.c,v 1.3 2005/03/25 12:56:48 liamfoy Exp $
40 /* Re-coding of advent in C: main program */
44 #include <sys/types.h>
53 main(int argc, char *argv[])
59 /* revoke setgid privileges from dm */
62 init(); /* Initialize everything */
63 signal(SIGINT, trapdel);
65 if (argc > 1) { /* Restore file specified */
66 /* Restart is label 8305 (Fortran) */
67 i = restore(argv[1]); /* See what we've got */
69 case 0: /* The restore worked fine */
72 unlink(argv[1]);/* Don't re-use the save */
73 goto l8; /* Get where we're going */
74 case 1: /* Couldn't open it */
75 exit(1); /* So give up */
76 case 2: /* Oops -- file was altered */
77 rspeak(202); /* You dissolve */
78 exit(1); /* File could be non-adventure */
79 } /* So don't unlink it. */
81 startup(); /* prepare for a user */
83 for (;;) { /* main command loop (label 2) */
84 if (newloc < 9 && newloc != 0 && closng) {
85 rspeak(130); /* if closing leave only by */
86 newloc = loc; /* main office */
91 rval = fdwarf(); /* dwarf stuff */
96 die(99); /* label 2000 */
98 if ((abb[loc] % abbnum) == 0 || kk->seekadr == 0)
100 if (!forced(loc) && dark()) {
101 if (wzdark && pct(35)) {
108 rspeak(141); /* label 2001 */
113 if (loc == 33 && pct(25) && !closng)
117 for (i = atloc[loc]; i != 0; i = linkx[i]) { /* 2004 */
121 if (obj == steps && toting(nugget))
127 if (obj == rug || obj == chain)
130 if (tally == tally2 && tally != 0)
134 ll = prop[obj]; /* 2006 */
135 if (obj == steps && loc == fixed[steps])
140 l2009: k = 54; /* 2009 */
144 l2012: verb = 0; /* 2012 */
146 l2600: checkhints(); /* to 2600-2602 */
148 if (prop[oyster] < 0 && toting(oyster))
150 for (i = 1; i < 100; i++)
151 if (toting(i) && prop[i] < 0) /* 2604 */
152 prop[i] = -1 - prop[i];
154 wzdark = dark(); /* 2605 */
155 if (knfloc > 0 && knfloc != loc)
158 if (delhit) { /* user typed a DEL */
159 delhit = 0; /* reset counter */
160 strcpy(wd1, "quit"); /* pretend he's quitting */
163 l2608: if ((foobar = -foobar) > 0)
164 foobar = 0; /* 2608 */
165 /* should check here for "magic mode" */
167 if (demo && turns >= SHORT)
168 done(1); /* to 13000 */
170 if (verb == say && wd2[0] != 0)
174 if (tally == 0 && loc >= 15 && loc != 33)
177 closing(); /* to 10000 */
183 caveclose(); /* to 11000 */
184 continue; /* back to 2 */
188 if (limit <= 30 && here(batter) && prop[batter] == 0
190 rspeak(188); /* 12000 */
199 limit = -1; /* 12400 */
204 if (limit < 0 && loc <= 8) {
205 rspeak(185); /* 12600 */
207 done(2); /* to 20000 */
210 if (lmwarn || !here(lamp))
211 goto l19999; /* 12200 */
214 if (place[batter] == 0)
216 if (prop[batter] == 1)
221 if (liqloc(loc) == water)
223 if (!strncmp(wd1, "enter", 5) &&
224 (!strncmp(wd2, "strea", 5) || !strncmp(wd2, "water", 5)))
226 if (!strncmp(wd1, "enter", 5) && wd2[0] != 0)
228 if ((strncmp(wd1, "water", 5) && strncmp(wd1, "oil", 3))
229 || (strncmp(wd2, "plant", 5) && strncmp(wd2, "door", 4)))
231 if (at(vocab(wd2, 1, 0)))
234 l2610: if (!strncmp(wd1, "west", 4))
237 l2630: i = vocab(wd1, -1, 0);
265 continue; /* i.e. goto l2 */
273 l2800: strcpy(wd1, wd2);
279 if (wd2[0] != 0 && verb != say)
286 case 1: /* take = 8010 */
287 if (atloc[loc] == 0 || linkx[atloc[loc]] != 0)
289 for (i = 1; i <= 5; i++)
290 if (dloc[i] == loc && dflag >= 2)
294 case 2: /* 8000: drop */
304 l8000: printf("%s what?\n", wd1);
307 case 4: /* 8040: open */
318 if (obj != 0 && here(chain))
325 case 5: /* nothing */
337 case 14: /* eat: 8140 */
345 case 18: /* quit: 8180 */
346 gaveup = yes(22, 54, 54);
350 case 20: /* invent=8200 */
352 for (i = 1; i <= 100; i++) {
353 if (i != bear && toting(i)) {
369 case 24: /* score: 8240 */
371 printf("If you were to quit now, you would score");
372 printf(" %d out of a possible ", score());
373 printf("%d.", mxscor);
375 gaveup = yes(143, 54, 54);
379 case 25: /* foo: 8250 */
380 k = vocab(wd1, 3, 0);
391 if (place[eggs] == plac[eggs]
392 || (toting(eggs) && loc == plac[eggs]))
394 if (place[eggs] == 0 && place[troll] == 0 &&
400 if (loc == plac[eggs])
402 move(eggs, plac[eggs]);
405 case 26: /* brief=8260 */
410 case 27: /* read=8270 */
414 obj = obj * 100 + tablet;
416 obj = obj * 100 + messag;
417 if (closed && toting(oyster))
419 if (obj > 100 || obj == 0 || dark())
422 case 30: /* suspend=8300 */
426 printf("I can suspend your adventure for you so");
427 printf(" you can resume later, but\n");
428 printf("you will have to wait at least");
429 printf(" %d minutes before continuing.", latncy);
430 if (!yes(200, 54, 54))
432 datime(&saved, &savet);
433 ciao(); /* Do we quit? */
434 continue; /* Maybe not */
435 case 31: /* hours=8310 */
436 printf("Colossal cave is closed 9am-5pm Mon ");
437 printf("through Fri except holidays.\n");
445 case 1: /* take = 9010 */
446 l9010: switch (trtake()) {
458 l9020: case 2: /* drop = 9020 */
469 case 3: /* label 9030 */
478 l9040: case 4: /* open */
488 case 5: /* nothing */
490 case 7: /* on 9070 */
491 l9070: if (!here(lamp))
503 l9080: if (!here(lamp))
512 if ((!toting(obj)) && (obj != rod || !toting(rod2)))
514 if (obj != rod || !at(fissur) || !toting(obj) || closng)
516 prop[fissur] = 1 - prop[fissur];
517 pspeak(fissur, 2 - prop[fissur]);
525 case 30: /* suspend */
528 l9120: case 12: /* kill */
543 l9130: case 13: /* pour */
544 if (obj == bottle || obj == 0)
551 if (obj != oil && obj != water)
556 if (!(at(plant) || at(door)))
559 prop[door] = 0; /* 9132 */
562 spk = 113 + prop[door];
568 pspeak(plant, prop[plant] + 1);
569 prop[plant] = (prop[plant] + 2)% 6;
570 prop[plant2] = prop[plant] / 2;
573 case 14: /* 9140: eat */
576 if (obj == bird || obj == snake || obj == clam
577 || obj == oyster || obj == dwarf || obj == dragon
578 || obj == troll || obj == bear)
581 l9150: case 15: /* 9150: drink */
582 if (obj == 0 && liqloc(loc) != water && (liq() != water
585 if (obj != 0 && obj != water)
587 if (spk == 110 || liq() != water || !here(bottle))
593 case 16: /* 9160: rub */
597 case 17: /* 9170: throw */
612 case 19: /* 9190: find */
613 case 20: /* invent */
614 if (at(obj) || (liq() == obj && at(bottle))
617 for (i = 1; i <= 5; i++)
618 if (dloc[i] == loc && dflag >= 2
626 l9210: case 21: /* feed */
633 l9220: case 22: /* fill */
644 l9230: case 23: /* blast */
645 if (prop[rod2] < 0 || !closed)
654 l9270: case 27: /* read */
663 if (obj == oyster && hinted[2] && toting(oyster))
665 if (obj != oyster || hinted[2] || !toting(oyster)
668 hinted[2] = yes(192, 193, 54);
670 case 28: /* 9280: break */
673 if (obj == vase && prop[vase] == 0) {
681 if (obj != mirror || !closed)
685 case 29: /* 9290: wake */
686 if (obj != dwarf || !closed)
697 if (fixed[k] != loc && !here(k))
699 l5010: if (wd2[0] != 0)
703 printf("What do you want to do with the %s?\n", wd1);
705 l5100: if (k != grate)
707 if (loc == 1 || loc == 4 || loc == 7)
709 if (loc > 9 && loc < 15)
713 l5110: if (k != dwarf)
715 for (i = 1; i <= 5; i++)
716 if (dloc[i] == loc && dflag >= 2)
718 l5120: if ((liq() == k && here(bottle)) || k == liqloc(loc))
720 if (obj != plant || !at(plant2) || prop[plant2] == 0)
724 l5130: if (obj != knife || knfloc != loc)
729 l5140: if (obj != rod || !here(rod2))
733 l5190: if ((verb == find || verb == invent) && wd2[0] == 0)
735 printf("I see no %s here\n", wd1);