]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - adventure/main.c
794e5a3f403a37d8599ccd7c56c05548786be26b
1 /* $NetBSD: main.c,v 1.14 1999/07/16 01:38:20 hubertf 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.14 1999/07/16 01:38:20 hubertf Exp $");
55 /* Re-coding of advent in C: main program */
65 int main
__P((int, char **));
76 /* revoke setgid privileges from dm */
77 setregid(getgid(), getgid());
79 init(); /* Initialize everything */
80 signal(SIGINT
, trapdel
);
82 if (argc
> 1) { /* Restore file specified */
83 /* Restart is label 8305 (Fortran) */
84 i
= restore(argv
[1]); /* See what we've got */
86 case 0: /* The restore worked fine */
89 unlink(argv
[1]); /* Don't re-use the save */
90 goto l8
; /* Get where we're going */
91 case 1: /* Couldn't open it */
92 errx(1,"can't open file"); /* So give up */
93 case 2: /* Oops -- file was altered */
94 rspeak(202); /* You dissolve */
95 exit(1); /* File could be non-adventure */
96 } /* So don't unlink it. */
98 startup(); /* prepare for a user */
100 for (;;) { /* main command loop (label 2) */
101 if (newloc
< 9 && newloc
!= 0 && closng
) {
102 rspeak(130); /* if closing leave only by */
103 newloc
= loc
; /* main office */
108 rval
= fdwarf(); /* dwarf stuff */
113 die(99); /* label 2000 */
115 if ((abb
[loc
] % abbnum
) == 0 || kk
->seekadr
== 0)
117 if (!forced(loc
) && dark()) {
118 if (wzdark
&& pct(35)) {
128 rspeak(141); /* 2001 */
133 if (loc
== 33 && pct(25) && !closng
)
137 for (i
= atloc
[loc
]; i
!= 0; i
= links
[i
]) { /* 2004 */
141 if (obj
== steps
&& toting(nugget
))
147 if (obj
== rug
|| obj
== chain
)
150 if (tally
== tally2
&& tally
!= 0)
154 ll
= prop
[obj
]; /* 2006 */
155 if (obj
== steps
&& loc
== fixed
[steps
])
160 l2009
: k
= 54; /* 2009 */
164 l2012
: verb
= 0; /* 2012 */
166 l2600
: checkhints(); /* to 2600-2602 */
168 if (prop
[oyster
] < 0 && toting(oyster
))
170 for (i
= 1; i
< 100; i
++)
171 if (toting(i
) && prop
[i
] < 0) /* 2604 */
172 prop
[i
] = -1 - prop
[i
];
174 wzdark
= dark(); /* 2605 */
175 if (knfloc
> 0 && knfloc
!= loc
)
178 if (delhit
) { /* user typed a DEL */
179 delhit
= 0; /* reset counter */
180 copystr("quit", wd1
); /* pretend he's quitting */
183 l2608
: if ((foobar
= -foobar
) > 0)
184 foobar
= 0; /* 2608 */
185 /* should check here for "magic mode" */
187 if (demo
&& turns
>= SHORT
)
188 done(1); /* to 13000 */
190 if (verb
== say
&& *wd2
!= 0)
194 if (tally
== 0 && loc
>= 15 && loc
!= 33)
197 closing(); /* to 10000 */
203 caveclose(); /* to 11000 */
204 continue; /* back to 2 */
208 if (limit
<= 30 && here(batter
) && prop
[batter
] == 0
210 rspeak(188); /* 12000 */
214 limit
= limit
+ 2500;
219 limit
= -1; /* 12400 */
224 if (limit
< 0 && loc
<= 8) {
225 rspeak(185); /* 12600 */
227 done(2); /* to 20000 */
230 if (lmwarn
|| !here(lamp
))
231 goto l19999
; /* 12200 */
234 if (place
[batter
] == 0)
236 if (prop
[batter
] == 1)
241 if (liqloc(loc
) == water
)
243 if (weq(wd1
, "enter") &&
244 (weq(wd2
, "strea") || weq(wd2
, "water")))
246 if (weq(wd1
, "enter") && *wd2
!= 0)
248 if ((!weq(wd1
, "water") && !weq(wd1
, "oil"))
249 || (!weq(wd2
, "plant") && !weq(wd2
, "door")))
251 if (at(vocab(wd2
, 1, 0)))
252 copystr("pour", wd2
);
254 l2610
: if (weq(wd1
, "west"))
257 l2630
: i
= vocab(wd1
, -1, 0);
285 continue; /* i.e. goto l2 */
293 l2800
: copystr(wd2
, wd1
);
299 if (*wd2
!= 0 && verb
!= say
)
309 case 1: /* take = 8010 */
310 if (atloc
[loc
] == 0 || links
[atloc
[loc
]] != 0)
312 for (i
= 1; i
<= 5; i
++)
313 if (dloc
[i
] == loc
&& dflag
>= 2)
319 case 9: /* 8000 : drop,say,wave */
322 case 17: /* calm,rub,toss */
325 case 28: /* find,feed,break */
327 l8000
: printf("%s what?\n", wd1
);
331 case 6: /* 8040 open,lock */
341 if (obj
!= 0 && here(chain
))
349 goto l2009
; /* nothing */
353 goto l9080
; /* off */
355 goto l8000
; /* walk */
357 goto l9120
; /* kill */
359 goto l9130
; /* pour */
360 case 14: /* eat: 8140 */
367 goto l9150
; /* drink */
368 case 18: /* quit: 8180 */
369 gaveup
= yes(22, 54, 54);
373 case 20: /* invent=8200 */
375 for (i
= 1; i
<= 100; i
++) {
376 if (i
!= bear
&& toting(i
)) {
389 goto l9220
; /* fill */
391 goto l9230
; /* blast */
392 case 24: /* score: 8240 */
394 printf("If you were to quit now, you would score");
395 printf(" %d out of a possible ", score());
396 printf("%d.", mxscor
);
398 gaveup
= yes(143, 54, 54);
402 case 25: /* foo: 8250 */
403 k
= vocab(wd1
, 3, 0);
414 if (place
[eggs
] == plac
[eggs
]
415 || (toting(eggs
) && loc
== plac
[eggs
]))
417 if (place
[eggs
] == 0 && place
[troll
] == 0 && prop
[troll
] == 0)
422 if (loc
== plac
[eggs
])
424 move(eggs
, plac
[eggs
]);
427 case 26: /* brief=8260 */
432 case 27: /* read=8270 */
436 obj
= obj
* 100 + tablet
;
438 obj
= obj
* 100 + messag
;
439 if (closed
&& toting(oyster
))
441 if (obj
> 100 || obj
== 0 || dark())
444 case 30: /* suspend=8300 */
448 printf("I can suspend your adventure for you so");
449 printf(" you can resume later, but\n");
450 printf("you will have to wait at least");
451 printf(" %d minutes before continuing.", latncy
);
452 if (!yes(200, 54, 54))
454 datime(&saveday
, &savet
);
455 ciao(); /* Do we quit? */
456 continue; /* Maybe not */
457 case 31: /* hours=8310 */
458 printf("Colossal cave is closed 9am-5pm Mon ");
459 printf("through Fri except holidays.\n");
467 case 1: /* take = 9010 */
468 l9010
: switch (trtake()) {
480 l9020
: case 2: /* drop = 9020 */
504 case 6: /* open, close */
514 goto l2009
; /* nothing */
515 case 7: /* on 9070 */
516 l9070
: if (!here(lamp
))
528 l9080
: if (!here(lamp
))
537 if ((!toting(obj
)) && (obj
!= rod
|| !toting(rod2
)))
539 if (obj
!= rod
|| !at(fissur
) || !toting(obj
) || closng
)
541 prop
[fissur
] = 1 - prop
[fissur
];
542 pspeak(fissur
, 2 - prop
[fissur
]);
546 case 18: /* calm, walk, quit */
549 case 26: /* score, foo, brief */
551 case 31: /* suspend, hours */
553 l9120
: case 12:/* kill */
568 l9130
: case 13:/* pour */
569 if (obj
== bottle
|| obj
== 0)
576 if (obj
!= oil
&& obj
!= water
)
581 if (!(at(plant
) || at(door
)))
584 prop
[door
] = 0; /* 9132 */
587 spk
= 113 + prop
[door
];
593 pspeak(plant
, prop
[plant
] + 1);
594 prop
[plant
] = (prop
[plant
] + 2) % 6;
595 prop
[plant2
] = prop
[plant
] / 2;
598 case 14: /* 9140 - eat */
601 if (obj
== bird
|| obj
== snake
|| obj
== clam
|| obj
== oyster
602 || obj
== dwarf
|| obj
== dragon
|| obj
== troll
606 l9150
: case 15:/* 9150 - drink */
607 if (obj
== 0 && liqloc(loc
) != water
&& (liq() != water
610 if (obj
!= 0 && obj
!= water
)
612 if (spk
== 110 || liq() != water
|| !here(bottle
))
618 case 16: /* 9160: rub */
622 case 17: /* 9170: throw */
638 case 20: /* 9190: find, invent */
639 if (at(obj
) || (liq() == obj
&& at(bottle
))
642 for (i
= 1; i
<= 5; i
++)
643 if (dloc
[i
] == loc
&& dflag
>= 2 && obj
== dwarf
)
650 l9210
: case 21:/* feed */
657 l9220
: case 22:/* fill */
668 l9230
: case 23:/* blast */
669 if (prop
[rod2
] < 0 || !closed
)
678 l9270
: case 27:/* read */
687 if (obj
== oyster
&& hinted
[2] && toting(oyster
))
689 if (obj
!= oyster
|| hinted
[2] || !toting(oyster
)
692 hinted
[2] = yes(192, 193, 54);
700 if (obj
== vase
&& prop
[vase
] == 0) {
708 if (obj
!= mirror
|| !closed
)
716 if (obj
!= dwarf
|| !closed
)
727 if (fixed
[k
] != loc
&& !here(k
))
729 l5010
: if (*wd2
!= 0)
733 printf("What do you want to do with the %s?\n", wd1
);
735 l5100
: if (k
!= grate
)
737 if (loc
== 1 || loc
== 4 || loc
== 7)
739 if (loc
> 9 && loc
< 15)
743 l5110
: if (k
!= dwarf
)
745 for (i
= 1; i
<= 5; i
++)
746 if (dloc
[i
] == loc
&& dflag
>= 2)
748 l5120
: if ((liq() == k
&& here(bottle
)) || k
== liqloc(loc
))
750 if (obj
!= plant
|| !at(plant2
) || prop
[plant2
] == 0)
754 l5130
: if (obj
!= knife
|| knfloc
!= loc
)
759 l5140
: if (obj
!= rod
|| !here(rod2
))
763 l5190
: if ((verb
== find
|| verb
== invent
) && *wd2
== 0)
765 printf("I see no %s here\n", wd1
);