1 /* $NetBSD: main.c,v 1.20 2008/07/20 01:03:20 lukem Exp $ */
4 * Copyright (c) 1991, 1993
5 * The Regents of the University of California. All rights reserved.
7 * The game adventure was originally written in Fortran by Will Crowther
8 * and Don Woods. It was later translated to C and enhanced by Jim
9 * Gillogly. This code is derived from software contributed to Berkeley
10 * by Jim Gillogly at The Rand Corporation.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 #include <sys/cdefs.h>
39 __COPYRIGHT("@(#) Copyright (c) 1991, 1993\
40 The Regents of the University of California. All rights reserved.");
45 static char sccsid
[] = "@(#)main.c 8.1 (Berkeley) 6/2/93";
47 __RCSID("$NetBSD: main.c,v 1.20 2008/07/20 01:03:20 lukem Exp $");
51 /* Re-coding of advent in C: main program */
63 main(int argc
, char **argv
)
69 /* revoke setgid privileges from dm */
72 init(); /* Initialize everything */
73 signal(SIGINT
, trapdel
);
75 if (argc
> 1) { /* Restore file specified */
76 /* Restart is label 8305 (Fortran) */
77 i
= restore(argv
[1]); /* See what we've got */
79 case 0: /* The restore worked fine */
82 unlink(argv
[1]); /* Don't re-use the save */
83 goto l8
; /* Get where we're going */
84 case 1: /* Couldn't open it */
85 errx(1,"can't open file"); /* So give up */
86 case 2: /* Oops -- file was altered */
87 rspeak(202); /* You dissolve */
88 exit(1); /* File could be non-adventure */
89 } /* So don't unlink it. */
91 startup(); /* prepare for a user */
93 for (;;) { /* main command loop (label 2) */
94 if (newloc
< 9 && newloc
!= 0 && isclosing
) {
95 rspeak(130); /* if closing leave only by */
96 newloc
= loc
; /* main office */
101 rval
= fdwarf(); /* dwarf stuff */
106 die(99); /* label 2000 */
108 if ((abb
[loc
] % abbnum
) == 0 || kk
->seekadr
== 0)
110 if (!forced(loc
) && dark()) {
111 if (wasdark
&& pct(35)) {
121 rspeak(141); /* 2001 */
126 if (loc
== 33 && pct(25) && !isclosing
)
130 for (i
= atloc
[loc
]; i
!= 0; i
= links
[i
]) { /* 2004 */
134 if (obj
== steps
&& toting(nugget
))
140 if (obj
== rug
|| obj
== chain
)
143 if (tally
== tally2
&& tally
!= 0)
147 ll
= prop
[obj
]; /* 2006 */
148 if (obj
== steps
&& loc
== fixed
[steps
])
153 l2009
: k
= 54; /* 2009 */
157 l2012
: verb
= 0; /* 2012 */
159 l2600
: checkhints(); /* to 2600-2602 */
161 if (prop
[oyster
] < 0 && toting(oyster
))
163 for (i
= 1; i
< 100; i
++)
164 if (toting(i
) && prop
[i
] < 0) /* 2604 */
165 prop
[i
] = -1 - prop
[i
];
167 wasdark
= dark(); /* 2605 */
168 if (knfloc
> 0 && knfloc
!= loc
)
171 if (delhit
) { /* user typed a DEL */
172 delhit
= 0; /* reset counter */
173 copystr("quit", wd1
); /* pretend he's quitting */
176 l2608
: if ((foobar
= -foobar
) > 0)
177 foobar
= 0; /* 2608 */
178 /* should check here for "magic mode" */
180 if (demo
&& turns
>= SHORT
)
181 done(1); /* to 13000 */
183 if (verb
== say
&& *wd2
!= 0)
187 if (tally
== 0 && loc
>= 15 && loc
!= 33)
190 closing(); /* to 10000 */
196 caveclose(); /* to 11000 */
197 continue; /* back to 2 */
201 if (limit
<= 30 && here(batter
) && prop
[batter
] == 0
203 rspeak(188); /* 12000 */
207 limit
= limit
+ 2500;
212 limit
= -1; /* 12400 */
217 if (limit
< 0 && loc
<= 8) {
218 rspeak(185); /* 12600 */
220 done(2); /* to 20000 */
223 if (lmwarn
|| !here(lamp
))
224 goto l19999
; /* 12200 */
227 if (place
[batter
] == 0)
229 if (prop
[batter
] == 1)
234 if (liqloc(loc
) == water
)
236 if (weq(wd1
, "enter") &&
237 (weq(wd2
, "strea") || weq(wd2
, "water")))
239 if (weq(wd1
, "enter") && *wd2
!= 0)
241 if ((!weq(wd1
, "water") && !weq(wd1
, "oil"))
242 || (!weq(wd2
, "plant") && !weq(wd2
, "door")))
244 if (at(vocab(wd2
, 1, 0)))
245 copystr("pour", wd2
);
247 l2610
: if (weq(wd1
, "west"))
250 l2630
: i
= vocab(wd1
, -1, 0);
278 continue; /* i.e. goto l2 */
286 l2800
: copystr(wd2
, wd1
);
291 spk
= actspeak
[verb
];
292 if (*wd2
!= 0 && verb
!= say
)
302 case 1: /* take = 8010 */
303 if (atloc
[loc
] == 0 || links
[atloc
[loc
]] != 0)
305 for (i
= 1; i
<= 5; i
++)
306 if (dloc
[i
] == loc
&& dflag
>= 2)
312 case 9: /* 8000 : drop,say,wave */
315 case 17: /* calm,rub,toss */
318 case 28: /* find,feed,break */
320 l8000
: printf("%s what?\n", wd1
);
324 case 6: /* 8040 open,lock */
334 if (obj
!= 0 && here(chain
))
342 goto l2009
; /* nothing */
346 goto l9080
; /* off */
348 goto l8000
; /* walk */
350 goto l9120
; /* kill */
352 goto l9130
; /* pour */
353 case 14: /* eat: 8140 */
356 l8142
: destroy(food
);
360 goto l9150
; /* drink */
361 case 18: /* quit: 8180 */
362 gaveup
= yes(22, 54, 54);
366 case 20: /* invent=8200 */
368 for (i
= 1; i
<= 100; i
++) {
369 if (i
!= bear
&& toting(i
)) {
382 goto l9220
; /* fill */
384 goto l9230
; /* blast */
385 case 24: /* score: 8240 */
387 printf("If you were to quit now, you would score");
388 printf(" %d out of a possible ", score());
389 printf("%d.", maxscore
);
391 gaveup
= yes(143, 54, 54);
395 case 25: /* foo: 8250 */
396 k
= vocab(wd1
, 3, 0);
407 if (place
[eggs
] == plac
[eggs
]
408 || (toting(eggs
) && loc
== plac
[eggs
]))
410 if (place
[eggs
] == 0 && place
[troll
] == 0 &&
416 if (loc
== plac
[eggs
])
418 move(eggs
, plac
[eggs
]);
421 case 26: /* brief=8260 */
426 case 27: /* read=8270 */
430 obj
= obj
* 100 + tablet
;
432 obj
= obj
* 100 + message
;
433 if (closed
&& toting(oyster
))
435 if (obj
> 100 || obj
== 0 || dark())
438 case 30: /* suspend=8300 */
442 printf("I can suspend your adventure for you so");
443 printf(" you can resume later, but\n");
444 printf("you will have to wait at least");
445 printf(" %d minutes before continuing.", latency
);
446 if (!yes(200, 54, 54))
448 datime(&saveday
, &savet
);
449 ciao(); /* Do we quit? */
450 continue; /* Maybe not */
451 case 31: /* hours=8310 */
452 printf("Colossal cave is closed 9am-5pm Mon ");
453 printf("through Fri except holidays.\n");
461 case 1: /* take = 9010 */
462 l9010
: switch (trtake()) {
474 l9020
: case 2: /* drop = 9020 */
498 case 6: /* open, close */
508 goto l2009
; /* nothing */
509 case 7: /* on 9070 */
510 l9070
: if (!here(lamp
))
522 l9080
: if (!here(lamp
))
531 if ((!toting(obj
)) && (obj
!= rod
|| !toting(rod2
)))
533 if (obj
!= rod
|| !at(fissure
) || !toting(obj
) || isclosing
)
535 prop
[fissure
] = 1 - prop
[fissure
];
536 pspeak(fissure
, 2 - prop
[fissure
]);
540 case 18: /* calm, walk, quit */
543 case 26: /* score, foo, brief */
545 case 31: /* suspend, hours */
547 l9120
: case 12:/* kill */
562 l9130
: case 13:/* pour */
563 if (obj
== bottle
|| obj
== 0)
570 if (obj
!= oil
&& obj
!= water
)
575 if (!(at(plant
) || at(door
)))
578 prop
[door
] = 0; /* 9132 */
581 spk
= 113 + prop
[door
];
587 pspeak(plant
, prop
[plant
] + 1);
588 prop
[plant
] = (prop
[plant
] + 2) % 6;
589 prop
[plant2
] = prop
[plant
] / 2;
592 case 14: /* 9140 - eat */
595 if (obj
== bird
|| obj
== snake
|| obj
== clam
596 || obj
== oyster
|| obj
== dwarf
|| obj
== dragon
597 || obj
== troll
|| obj
== bear
)
600 l9150
: case 15:/* 9150 - drink */
601 if (obj
== 0 && liqloc(loc
) != water
&& (liq() != water
604 if (obj
!= 0 && obj
!= water
)
606 if (spk
== 110 || liq() != water
|| !here(bottle
))
612 case 16: /* 9160: rub */
616 case 17: /* 9170: throw */
632 case 20: /* 9190: find, invent */
633 if (at(obj
) || (liq() == obj
&& at(bottle
))
636 for (i
= 1; i
<= 5; i
++)
637 if (dloc
[i
] == loc
&& dflag
>= 2
645 l9210
: case 21:/* feed */
652 l9220
: case 22:/* fill */
663 l9230
: case 23:/* blast */
664 if (prop
[rod2
] < 0 || !closed
)
673 l9270
: case 27:/* read */
682 if (obj
== oyster
&& hinted
[2] && toting(oyster
))
684 if (obj
!= oyster
|| hinted
[2] || !toting(oyster
)
687 hinted
[2] = yes(192, 193, 54);
695 if (obj
== vase
&& prop
[vase
] == 0) {
703 if (obj
!= mirror
|| !closed
)
711 if (obj
!= dwarf
|| !closed
)
722 if (fixed
[k
] != loc
&& !here(k
))
724 l5010
: if (*wd2
!= 0)
728 printf("What do you want to do with the %s?\n", wd1
);
730 l5100
: if (k
!= grate
)
732 if (loc
== 1 || loc
== 4 || loc
== 7)
734 if (loc
> 9 && loc
< 15)
738 l5110
: if (k
!= dwarf
)
740 for (i
= 1; i
<= 5; i
++)
741 if (dloc
[i
] == loc
&& dflag
>= 2)
743 l5120
: if ((liq() == k
&& here(bottle
)) || k
== liqloc(loc
))
745 if (obj
!= plant
|| !at(plant2
) || prop
[plant2
] == 0)
749 l5130
: if (obj
!= knife
|| knfloc
!= loc
)
754 l5140
: if (obj
!= rod
|| !here(rod2
))
758 l5190
: if ((verb
== find
|| verb
== invent
) && *wd2
== 0)
760 printf("I see no %s here\n", wd1
);