]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - adventure/main.c
1 /* $NetBSD: main.c,v 1.18 2004/01/27 20:30:28 jsm 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\n\
40 The Regents of the University of California. All rights reserved.\n");
45 static char sccsid
[] = "@(#)main.c 8.1 (Berkeley) 6/2/93";
47 __RCSID("$NetBSD: main.c,v 1.18 2004/01/27 20:30:28 jsm Exp $");
51 /* Re-coding of advent in C: main program */
62 int main(int, char **);
73 /* revoke setgid privileges from dm */
76 init(); /* Initialize everything */
77 signal(SIGINT
, trapdel
);
79 if (argc
> 1) { /* Restore file specified */
80 /* Restart is label 8305 (Fortran) */
81 i
= restore(argv
[1]); /* See what we've got */
83 case 0: /* The restore worked fine */
86 unlink(argv
[1]); /* Don't re-use the save */
87 goto l8
; /* Get where we're going */
88 case 1: /* Couldn't open it */
89 errx(1,"can't open file"); /* So give up */
90 case 2: /* Oops -- file was altered */
91 rspeak(202); /* You dissolve */
92 exit(1); /* File could be non-adventure */
93 } /* So don't unlink it. */
95 startup(); /* prepare for a user */
97 for (;;) { /* main command loop (label 2) */
98 if (newloc
< 9 && newloc
!= 0 && closng
) {
99 rspeak(130); /* if closing leave only by */
100 newloc
= loc
; /* main office */
105 rval
= fdwarf(); /* dwarf stuff */
110 die(99); /* label 2000 */
112 if ((abb
[loc
] % abbnum
) == 0 || kk
->seekadr
== 0)
114 if (!forced(loc
) && dark()) {
115 if (wzdark
&& pct(35)) {
125 rspeak(141); /* 2001 */
130 if (loc
== 33 && pct(25) && !closng
)
134 for (i
= atloc
[loc
]; i
!= 0; i
= links
[i
]) { /* 2004 */
138 if (obj
== steps
&& toting(nugget
))
144 if (obj
== rug
|| obj
== chain
)
147 if (tally
== tally2
&& tally
!= 0)
151 ll
= prop
[obj
]; /* 2006 */
152 if (obj
== steps
&& loc
== fixed
[steps
])
157 l2009
: k
= 54; /* 2009 */
161 l2012
: verb
= 0; /* 2012 */
163 l2600
: checkhints(); /* to 2600-2602 */
165 if (prop
[oyster
] < 0 && toting(oyster
))
167 for (i
= 1; i
< 100; i
++)
168 if (toting(i
) && prop
[i
] < 0) /* 2604 */
169 prop
[i
] = -1 - prop
[i
];
171 wzdark
= dark(); /* 2605 */
172 if (knfloc
> 0 && knfloc
!= loc
)
175 if (delhit
) { /* user typed a DEL */
176 delhit
= 0; /* reset counter */
177 copystr("quit", wd1
); /* pretend he's quitting */
180 l2608
: if ((foobar
= -foobar
) > 0)
181 foobar
= 0; /* 2608 */
182 /* should check here for "magic mode" */
184 if (demo
&& turns
>= SHORT
)
185 done(1); /* to 13000 */
187 if (verb
== say
&& *wd2
!= 0)
191 if (tally
== 0 && loc
>= 15 && loc
!= 33)
194 closing(); /* to 10000 */
200 caveclose(); /* to 11000 */
201 continue; /* back to 2 */
205 if (limit
<= 30 && here(batter
) && prop
[batter
] == 0
207 rspeak(188); /* 12000 */
211 limit
= limit
+ 2500;
216 limit
= -1; /* 12400 */
221 if (limit
< 0 && loc
<= 8) {
222 rspeak(185); /* 12600 */
224 done(2); /* to 20000 */
227 if (lmwarn
|| !here(lamp
))
228 goto l19999
; /* 12200 */
231 if (place
[batter
] == 0)
233 if (prop
[batter
] == 1)
238 if (liqloc(loc
) == water
)
240 if (weq(wd1
, "enter") &&
241 (weq(wd2
, "strea") || weq(wd2
, "water")))
243 if (weq(wd1
, "enter") && *wd2
!= 0)
245 if ((!weq(wd1
, "water") && !weq(wd1
, "oil"))
246 || (!weq(wd2
, "plant") && !weq(wd2
, "door")))
248 if (at(vocab(wd2
, 1, 0)))
249 copystr("pour", wd2
);
251 l2610
: if (weq(wd1
, "west"))
254 l2630
: i
= vocab(wd1
, -1, 0);
282 continue; /* i.e. goto l2 */
290 l2800
: copystr(wd2
, wd1
);
296 if (*wd2
!= 0 && verb
!= say
)
306 case 1: /* take = 8010 */
307 if (atloc
[loc
] == 0 || links
[atloc
[loc
]] != 0)
309 for (i
= 1; i
<= 5; i
++)
310 if (dloc
[i
] == loc
&& dflag
>= 2)
316 case 9: /* 8000 : drop,say,wave */
319 case 17: /* calm,rub,toss */
322 case 28: /* find,feed,break */
324 l8000
: printf("%s what?\n", wd1
);
328 case 6: /* 8040 open,lock */
338 if (obj
!= 0 && here(chain
))
346 goto l2009
; /* nothing */
350 goto l9080
; /* off */
352 goto l8000
; /* walk */
354 goto l9120
; /* kill */
356 goto l9130
; /* pour */
357 case 14: /* eat: 8140 */
364 goto l9150
; /* drink */
365 case 18: /* quit: 8180 */
366 gaveup
= yes(22, 54, 54);
370 case 20: /* invent=8200 */
372 for (i
= 1; i
<= 100; i
++) {
373 if (i
!= bear
&& toting(i
)) {
386 goto l9220
; /* fill */
388 goto l9230
; /* blast */
389 case 24: /* score: 8240 */
391 printf("If you were to quit now, you would score");
392 printf(" %d out of a possible ", score());
393 printf("%d.", mxscor
);
395 gaveup
= yes(143, 54, 54);
399 case 25: /* foo: 8250 */
400 k
= vocab(wd1
, 3, 0);
411 if (place
[eggs
] == plac
[eggs
]
412 || (toting(eggs
) && loc
== plac
[eggs
]))
414 if (place
[eggs
] == 0 && place
[troll
] == 0 && prop
[troll
] == 0)
419 if (loc
== plac
[eggs
])
421 move(eggs
, plac
[eggs
]);
424 case 26: /* brief=8260 */
429 case 27: /* read=8270 */
433 obj
= obj
* 100 + tablet
;
435 obj
= obj
* 100 + messag
;
436 if (closed
&& toting(oyster
))
438 if (obj
> 100 || obj
== 0 || dark())
441 case 30: /* suspend=8300 */
445 printf("I can suspend your adventure for you so");
446 printf(" you can resume later, but\n");
447 printf("you will have to wait at least");
448 printf(" %d minutes before continuing.", latncy
);
449 if (!yes(200, 54, 54))
451 datime(&saveday
, &savet
);
452 ciao(); /* Do we quit? */
453 continue; /* Maybe not */
454 case 31: /* hours=8310 */
455 printf("Colossal cave is closed 9am-5pm Mon ");
456 printf("through Fri except holidays.\n");
464 case 1: /* take = 9010 */
465 l9010
: switch (trtake()) {
477 l9020
: case 2: /* drop = 9020 */
501 case 6: /* open, close */
511 goto l2009
; /* nothing */
512 case 7: /* on 9070 */
513 l9070
: if (!here(lamp
))
525 l9080
: if (!here(lamp
))
534 if ((!toting(obj
)) && (obj
!= rod
|| !toting(rod2
)))
536 if (obj
!= rod
|| !at(fissur
) || !toting(obj
) || closng
)
538 prop
[fissur
] = 1 - prop
[fissur
];
539 pspeak(fissur
, 2 - prop
[fissur
]);
543 case 18: /* calm, walk, quit */
546 case 26: /* score, foo, brief */
548 case 31: /* suspend, hours */
550 l9120
: case 12:/* kill */
565 l9130
: case 13:/* pour */
566 if (obj
== bottle
|| obj
== 0)
573 if (obj
!= oil
&& obj
!= water
)
578 if (!(at(plant
) || at(door
)))
581 prop
[door
] = 0; /* 9132 */
584 spk
= 113 + prop
[door
];
590 pspeak(plant
, prop
[plant
] + 1);
591 prop
[plant
] = (prop
[plant
] + 2) % 6;
592 prop
[plant2
] = prop
[plant
] / 2;
595 case 14: /* 9140 - eat */
598 if (obj
== bird
|| obj
== snake
|| obj
== clam
|| obj
== oyster
599 || obj
== dwarf
|| obj
== dragon
|| obj
== troll
603 l9150
: case 15:/* 9150 - drink */
604 if (obj
== 0 && liqloc(loc
) != water
&& (liq() != water
607 if (obj
!= 0 && obj
!= water
)
609 if (spk
== 110 || liq() != water
|| !here(bottle
))
615 case 16: /* 9160: rub */
619 case 17: /* 9170: throw */
635 case 20: /* 9190: find, invent */
636 if (at(obj
) || (liq() == obj
&& at(bottle
))
639 for (i
= 1; i
<= 5; i
++)
640 if (dloc
[i
] == loc
&& dflag
>= 2 && obj
== dwarf
)
647 l9210
: case 21:/* feed */
654 l9220
: case 22:/* fill */
665 l9230
: case 23:/* blast */
666 if (prop
[rod2
] < 0 || !closed
)
675 l9270
: case 27:/* read */
684 if (obj
== oyster
&& hinted
[2] && toting(oyster
))
686 if (obj
!= oyster
|| hinted
[2] || !toting(oyster
)
689 hinted
[2] = yes(192, 193, 54);
697 if (obj
== vase
&& prop
[vase
] == 0) {
705 if (obj
!= mirror
|| !closed
)
713 if (obj
!= dwarf
|| !closed
)
724 if (fixed
[k
] != loc
&& !here(k
))
726 l5010
: if (*wd2
!= 0)
730 printf("What do you want to do with the %s?\n", wd1
);
732 l5100
: if (k
!= grate
)
734 if (loc
== 1 || loc
== 4 || loc
== 7)
736 if (loc
> 9 && loc
< 15)
740 l5110
: if (k
!= dwarf
)
742 for (i
= 1; i
<= 5; i
++)
743 if (dloc
[i
] == loc
&& dflag
>= 2)
745 l5120
: if ((liq() == k
&& here(bottle
)) || k
== liqloc(loc
))
747 if (obj
!= plant
|| !at(plant2
) || prop
[plant2
] == 0)
751 l5130
: if (obj
!= knife
|| knfloc
!= loc
)
756 l5140
: if (obj
!= rod
|| !here(rod2
))
760 l5190
: if ((verb
== find
|| verb
== invent
) && *wd2
== 0)
762 printf("I see no %s here\n", wd1
);