]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - adventure/main.c
1 /* $NetBSD: main.c,v 1.16 2000/07/03 03:57:39 matt 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. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the University of
23 * California, Berkeley and its contributors.
24 * 4. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 #include <sys/cdefs.h>
43 __COPYRIGHT("@(#) Copyright (c) 1991, 1993\n\
44 The Regents of the University of California. All rights reserved.\n");
49 static char sccsid
[] = "@(#)main.c 8.1 (Berkeley) 6/2/93";
51 __RCSID("$NetBSD: main.c,v 1.16 2000/07/03 03:57:39 matt Exp $");
55 /* Re-coding of advent in C: main program */
66 int main
__P((int, char **));
77 /* revoke setgid privileges from dm */
80 init(); /* Initialize everything */
81 signal(SIGINT
, trapdel
);
83 if (argc
> 1) { /* Restore file specified */
84 /* Restart is label 8305 (Fortran) */
85 i
= restore(argv
[1]); /* See what we've got */
87 case 0: /* The restore worked fine */
90 unlink(argv
[1]); /* Don't re-use the save */
91 goto l8
; /* Get where we're going */
92 case 1: /* Couldn't open it */
93 errx(1,"can't open file"); /* So give up */
94 case 2: /* Oops -- file was altered */
95 rspeak(202); /* You dissolve */
96 exit(1); /* File could be non-adventure */
97 } /* So don't unlink it. */
99 startup(); /* prepare for a user */
101 for (;;) { /* main command loop (label 2) */
102 if (newloc
< 9 && newloc
!= 0 && closng
) {
103 rspeak(130); /* if closing leave only by */
104 newloc
= loc
; /* main office */
109 rval
= fdwarf(); /* dwarf stuff */
114 die(99); /* label 2000 */
116 if ((abb
[loc
] % abbnum
) == 0 || kk
->seekadr
== 0)
118 if (!forced(loc
) && dark()) {
119 if (wzdark
&& pct(35)) {
129 rspeak(141); /* 2001 */
134 if (loc
== 33 && pct(25) && !closng
)
138 for (i
= atloc
[loc
]; i
!= 0; i
= links
[i
]) { /* 2004 */
142 if (obj
== steps
&& toting(nugget
))
148 if (obj
== rug
|| obj
== chain
)
151 if (tally
== tally2
&& tally
!= 0)
155 ll
= prop
[obj
]; /* 2006 */
156 if (obj
== steps
&& loc
== fixed
[steps
])
161 l2009
: k
= 54; /* 2009 */
165 l2012
: verb
= 0; /* 2012 */
167 l2600
: checkhints(); /* to 2600-2602 */
169 if (prop
[oyster
] < 0 && toting(oyster
))
171 for (i
= 1; i
< 100; i
++)
172 if (toting(i
) && prop
[i
] < 0) /* 2604 */
173 prop
[i
] = -1 - prop
[i
];
175 wzdark
= dark(); /* 2605 */
176 if (knfloc
> 0 && knfloc
!= loc
)
179 if (delhit
) { /* user typed a DEL */
180 delhit
= 0; /* reset counter */
181 copystr("quit", wd1
); /* pretend he's quitting */
184 l2608
: if ((foobar
= -foobar
) > 0)
185 foobar
= 0; /* 2608 */
186 /* should check here for "magic mode" */
188 if (demo
&& turns
>= SHORT
)
189 done(1); /* to 13000 */
191 if (verb
== say
&& *wd2
!= 0)
195 if (tally
== 0 && loc
>= 15 && loc
!= 33)
198 closing(); /* to 10000 */
204 caveclose(); /* to 11000 */
205 continue; /* back to 2 */
209 if (limit
<= 30 && here(batter
) && prop
[batter
] == 0
211 rspeak(188); /* 12000 */
215 limit
= limit
+ 2500;
220 limit
= -1; /* 12400 */
225 if (limit
< 0 && loc
<= 8) {
226 rspeak(185); /* 12600 */
228 done(2); /* to 20000 */
231 if (lmwarn
|| !here(lamp
))
232 goto l19999
; /* 12200 */
235 if (place
[batter
] == 0)
237 if (prop
[batter
] == 1)
242 if (liqloc(loc
) == water
)
244 if (weq(wd1
, "enter") &&
245 (weq(wd2
, "strea") || weq(wd2
, "water")))
247 if (weq(wd1
, "enter") && *wd2
!= 0)
249 if ((!weq(wd1
, "water") && !weq(wd1
, "oil"))
250 || (!weq(wd2
, "plant") && !weq(wd2
, "door")))
252 if (at(vocab(wd2
, 1, 0)))
253 copystr("pour", wd2
);
255 l2610
: if (weq(wd1
, "west"))
258 l2630
: i
= vocab(wd1
, -1, 0);
286 continue; /* i.e. goto l2 */
294 l2800
: copystr(wd2
, wd1
);
300 if (*wd2
!= 0 && verb
!= say
)
310 case 1: /* take = 8010 */
311 if (atloc
[loc
] == 0 || links
[atloc
[loc
]] != 0)
313 for (i
= 1; i
<= 5; i
++)
314 if (dloc
[i
] == loc
&& dflag
>= 2)
320 case 9: /* 8000 : drop,say,wave */
323 case 17: /* calm,rub,toss */
326 case 28: /* find,feed,break */
328 l8000
: printf("%s what?\n", wd1
);
332 case 6: /* 8040 open,lock */
342 if (obj
!= 0 && here(chain
))
350 goto l2009
; /* nothing */
354 goto l9080
; /* off */
356 goto l8000
; /* walk */
358 goto l9120
; /* kill */
360 goto l9130
; /* pour */
361 case 14: /* eat: 8140 */
368 goto l9150
; /* drink */
369 case 18: /* quit: 8180 */
370 gaveup
= yes(22, 54, 54);
374 case 20: /* invent=8200 */
376 for (i
= 1; i
<= 100; i
++) {
377 if (i
!= bear
&& toting(i
)) {
390 goto l9220
; /* fill */
392 goto l9230
; /* blast */
393 case 24: /* score: 8240 */
395 printf("If you were to quit now, you would score");
396 printf(" %d out of a possible ", score());
397 printf("%d.", mxscor
);
399 gaveup
= yes(143, 54, 54);
403 case 25: /* foo: 8250 */
404 k
= vocab(wd1
, 3, 0);
415 if (place
[eggs
] == plac
[eggs
]
416 || (toting(eggs
) && loc
== plac
[eggs
]))
418 if (place
[eggs
] == 0 && place
[troll
] == 0 && prop
[troll
] == 0)
423 if (loc
== plac
[eggs
])
425 move(eggs
, plac
[eggs
]);
428 case 26: /* brief=8260 */
433 case 27: /* read=8270 */
437 obj
= obj
* 100 + tablet
;
439 obj
= obj
* 100 + messag
;
440 if (closed
&& toting(oyster
))
442 if (obj
> 100 || obj
== 0 || dark())
445 case 30: /* suspend=8300 */
449 printf("I can suspend your adventure for you so");
450 printf(" you can resume later, but\n");
451 printf("you will have to wait at least");
452 printf(" %d minutes before continuing.", latncy
);
453 if (!yes(200, 54, 54))
455 datime(&saveday
, &savet
);
456 ciao(); /* Do we quit? */
457 continue; /* Maybe not */
458 case 31: /* hours=8310 */
459 printf("Colossal cave is closed 9am-5pm Mon ");
460 printf("through Fri except holidays.\n");
468 case 1: /* take = 9010 */
469 l9010
: switch (trtake()) {
481 l9020
: case 2: /* drop = 9020 */
505 case 6: /* open, close */
515 goto l2009
; /* nothing */
516 case 7: /* on 9070 */
517 l9070
: if (!here(lamp
))
529 l9080
: if (!here(lamp
))
538 if ((!toting(obj
)) && (obj
!= rod
|| !toting(rod2
)))
540 if (obj
!= rod
|| !at(fissur
) || !toting(obj
) || closng
)
542 prop
[fissur
] = 1 - prop
[fissur
];
543 pspeak(fissur
, 2 - prop
[fissur
]);
547 case 18: /* calm, walk, quit */
550 case 26: /* score, foo, brief */
552 case 31: /* suspend, hours */
554 l9120
: case 12:/* kill */
569 l9130
: case 13:/* pour */
570 if (obj
== bottle
|| obj
== 0)
577 if (obj
!= oil
&& obj
!= water
)
582 if (!(at(plant
) || at(door
)))
585 prop
[door
] = 0; /* 9132 */
588 spk
= 113 + prop
[door
];
594 pspeak(plant
, prop
[plant
] + 1);
595 prop
[plant
] = (prop
[plant
] + 2) % 6;
596 prop
[plant2
] = prop
[plant
] / 2;
599 case 14: /* 9140 - eat */
602 if (obj
== bird
|| obj
== snake
|| obj
== clam
|| obj
== oyster
603 || obj
== dwarf
|| obj
== dragon
|| obj
== troll
607 l9150
: case 15:/* 9150 - drink */
608 if (obj
== 0 && liqloc(loc
) != water
&& (liq() != water
611 if (obj
!= 0 && obj
!= water
)
613 if (spk
== 110 || liq() != water
|| !here(bottle
))
619 case 16: /* 9160: rub */
623 case 17: /* 9170: throw */
639 case 20: /* 9190: find, invent */
640 if (at(obj
) || (liq() == obj
&& at(bottle
))
643 for (i
= 1; i
<= 5; i
++)
644 if (dloc
[i
] == loc
&& dflag
>= 2 && obj
== dwarf
)
651 l9210
: case 21:/* feed */
658 l9220
: case 22:/* fill */
669 l9230
: case 23:/* blast */
670 if (prop
[rod2
] < 0 || !closed
)
679 l9270
: case 27:/* read */
688 if (obj
== oyster
&& hinted
[2] && toting(oyster
))
690 if (obj
!= oyster
|| hinted
[2] || !toting(oyster
)
693 hinted
[2] = yes(192, 193, 54);
701 if (obj
== vase
&& prop
[vase
] == 0) {
709 if (obj
!= mirror
|| !closed
)
717 if (obj
!= dwarf
|| !closed
)
728 if (fixed
[k
] != loc
&& !here(k
))
730 l5010
: if (*wd2
!= 0)
734 printf("What do you want to do with the %s?\n", wd1
);
736 l5100
: if (k
!= grate
)
738 if (loc
== 1 || loc
== 4 || loc
== 7)
740 if (loc
> 9 && loc
< 15)
744 l5110
: if (k
!= dwarf
)
746 for (i
= 1; i
<= 5; i
++)
747 if (dloc
[i
] == loc
&& dflag
>= 2)
749 l5120
: if ((liq() == k
&& here(bottle
)) || k
== liqloc(loc
))
751 if (obj
!= plant
|| !at(plant2
) || prop
[plant2
] == 0)
755 l5130
: if (obj
!= knife
|| knfloc
!= loc
)
760 l5140
: if (obj
!= rod
|| !here(rod2
))
764 l5190
: if ((verb
== find
|| verb
== invent
) && *wd2
== 0)
766 printf("I see no %s here\n", wd1
);