]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - adventure/main.c
1 /* $NetBSD: main.c,v 1.9 1998/08/24 22:07:37 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.9 1998/08/24 22:07:37 hubertf Exp $");
55 /* Re-coding of advent in C: main program */
74 /* adventure doesn't need setuid-ness, so, just get rid of it */
75 if (setuid(getuid()) < 0)
78 init(); /* Initialize everything */
79 signal(SIGINT
, trapdel
);
81 if (argc
> 1) { /* Restore file specified */
82 /* Restart is label 8305 (Fortran) */
83 i
= restore(argv
[1]); /* See what we've got */
85 case 0: /* The restore worked fine */
88 unlink(argv
[1]); /* Don't re-use the save */
89 goto l8
; /* Get where we're going */
90 case 1: /* Couldn't open it */
91 exit(0); /* So give up */
92 case 2: /* Oops -- file was altered */
93 rspeak(202); /* You dissolve */
94 exit(0); /* File could be non-adventure */
95 } /* So don't unlink it. */
97 startup(); /* prepare for a user */
99 for (;;) { /* main command loop (label 2) */
100 if (newloc
< 9 && newloc
!= 0 && closng
) {
101 rspeak(130); /* if closing leave only by */
102 newloc
= loc
; /* main office */
107 rval
= fdwarf(); /* dwarf stuff */
112 die(99); /* label 2000 */
114 if ((abb
[loc
] % abbnum
) == 0 || kk
->seekadr
== 0)
116 if (!forced(loc
) && dark()) {
117 if (wzdark
&& pct(35)) {
127 rspeak(141); /* 2001 */
132 if (loc
== 33 && pct(25) && !closng
)
136 for (i
= atloc
[loc
]; i
!= 0; i
= links
[i
]) { /* 2004 */
140 if (obj
== steps
&& toting(nugget
))
146 if (obj
== rug
|| obj
== chain
)
149 if (tally
== tally2
&& tally
!= 0)
153 ll
= prop
[obj
]; /* 2006 */
154 if (obj
== steps
&& loc
== fixed
[steps
])
159 l2009
: k
= 54; /* 2009 */
163 l2012
: verb
= 0; /* 2012 */
165 l2600
: checkhints(); /* to 2600-2602 */
167 if (prop
[oyster
] < 0 && toting(oyster
))
169 for (i
= 1; i
< 100; i
++)
170 if (toting(i
) && prop
[i
] < 0) /* 2604 */
171 prop
[i
] = -1 - prop
[i
];
173 wzdark
= dark(); /* 2605 */
174 if (knfloc
> 0 && knfloc
!= loc
)
177 if (delhit
) { /* user typed a DEL */
178 delhit
= 0; /* reset counter */
179 copystr("quit", wd1
); /* pretend he's quitting */
182 l2608
: if ((foobar
= -foobar
) > 0)
183 foobar
= 0; /* 2608 */
184 /* should check here for "magic mode" */
186 if (demo
&& turns
>= SHORT
)
187 done(1); /* to 13000 */
189 if (verb
== say
&& *wd2
!= 0)
193 if (tally
== 0 && loc
>= 15 && loc
!= 33)
196 closing(); /* to 10000 */
202 caveclose(); /* to 11000 */
203 continue; /* back to 2 */
207 if (limit
<= 30 && here(batter
) && prop
[batter
] == 0
209 rspeak(188); /* 12000 */
213 limit
= limit
+ 2500;
218 limit
= -1; /* 12400 */
223 if (limit
< 0 && loc
<= 8) {
224 rspeak(185); /* 12600 */
226 done(2); /* to 20000 */
229 if (lmwarn
|| !here(lamp
))
230 goto l19999
; /* 12200 */
233 if (place
[batter
] == 0)
235 if (prop
[batter
] == 1)
240 if (liqloc(loc
) == water
)
242 if (weq(wd1
, "enter") &&
243 (weq(wd2
, "strea") || weq(wd2
, "water")))
245 if (weq(wd1
, "enter") && *wd2
!= 0)
247 if ((!weq(wd1
, "water") && !weq(wd1
, "oil"))
248 || (!weq(wd2
, "plant") && !weq(wd2
, "door")))
250 if (at(vocab(wd2
, 1, 0)))
251 copystr("pour", wd2
);
253 l2610
: if (weq(wd1
, "west"))
256 l2630
: i
= vocab(wd1
, -1, 0);
278 printf("Error 22\n");
285 continue; /* i.e. goto l2 */
297 l2800
: copystr(wd2
, wd1
);
303 if (*wd2
!= 0 && verb
!= say
)
313 case 1: /* take = 8010 */
314 if (atloc
[loc
] == 0 || links
[atloc
[loc
]] != 0)
316 for (i
= 1; i
<= 5; i
++)
317 if (dloc
[i
] == loc
&& dflag
>= 2)
323 case 9: /* 8000 : drop,say,wave */
326 case 17: /* calm,rub,toss */
329 case 28: /* find,feed,break */
331 l8000
: printf("%s what?\n", wd1
);
335 case 6: /* 8040 open,lock */
345 if (obj
!= 0 && here(chain
))
353 goto l2009
; /* nothing */
357 goto l9080
; /* off */
359 goto l8000
; /* walk */
361 goto l9120
; /* kill */
363 goto l9130
; /* pour */
364 case 14: /* eat: 8140 */
371 goto l9150
; /* drink */
372 case 18: /* quit: 8180 */
373 gaveup
= yes(22, 54, 54);
377 case 20: /* invent=8200 */
379 for (i
= 1; i
<= 100; i
++) {
380 if (i
!= bear
&& toting(i
)) {
393 goto l9220
; /* fill */
395 goto l9230
; /* blast */
396 case 24: /* score: 8240 */
398 printf("If you were to quit now, you would score");
399 printf(" %d out of a possible ", score());
400 printf("%d.", mxscor
);
402 gaveup
= yes(143, 54, 54);
406 case 25: /* foo: 8250 */
407 k
= vocab(wd1
, 3, 0);
418 if (place
[eggs
] == plac
[eggs
]
419 || (toting(eggs
) && loc
== plac
[eggs
]))
421 if (place
[eggs
] == 0 && place
[troll
] == 0 && prop
[troll
] == 0)
426 if (loc
== plac
[eggs
])
428 move(eggs
, plac
[eggs
]);
431 case 26: /* brief=8260 */
436 case 27: /* read=8270 */
440 obj
= obj
* 100 + tablet
;
442 obj
= obj
* 100 + messag
;
443 if (closed
&& toting(oyster
))
445 if (obj
> 100 || obj
== 0 || dark())
448 case 30: /* suspend=8300 */
452 printf("I can suspend your adventure for you so");
453 printf(" you can resume later, but\n");
454 printf("you will have to wait at least");
455 printf(" %d minutes before continuing.", latncy
);
456 if (!yes(200, 54, 54))
458 datime(&saved
, &savet
);
459 ciao(); /* Do we quit? */
460 continue; /* Maybe not */
461 case 31: /* hours=8310 */
462 printf("Colossal cave is closed 9am-5pm Mon ");
463 printf("through Fri except holidays.\n");
471 case 1: /* take = 9010 */
472 l9010
: switch (trtake()) {
484 l9020
: case 2: /* drop = 9020 */
508 case 6: /* open, close */
518 goto l2009
; /* nothing */
519 case 7: /* on 9070 */
520 l9070
: if (!here(lamp
))
532 l9080
: if (!here(lamp
))
541 if ((!toting(obj
)) && (obj
!= rod
|| !toting(rod2
)))
543 if (obj
!= rod
|| !at(fissur
) || !toting(obj
) || closng
)
545 prop
[fissur
] = 1 - prop
[fissur
];
546 pspeak(fissur
, 2 - prop
[fissur
]);
550 case 18: /* calm, walk, quit */
553 case 26: /* score, foo, brief */
555 case 31: /* suspend, hours */
557 l9120
: case 12:/* kill */
572 l9130
: case 13:/* pour */
573 if (obj
== bottle
|| obj
== 0)
580 if (obj
!= oil
&& obj
!= water
)
585 if (!(at(plant
) || at(door
)))
588 prop
[door
] = 0; /* 9132 */
591 spk
= 113 + prop
[door
];
597 pspeak(plant
, prop
[plant
] + 1);
598 prop
[plant
] = (prop
[plant
] + 2) % 6;
599 prop
[plant2
] = prop
[plant
] / 2;
602 case 14: /* 9140 - eat */
605 if (obj
== bird
|| obj
== snake
|| obj
== clam
|| obj
== oyster
606 || obj
== dwarf
|| obj
== dragon
|| obj
== troll
610 l9150
: case 15:/* 9150 - drink */
611 if (obj
== 0 && liqloc(loc
) != water
&& (liq() != water
614 if (obj
!= 0 && obj
!= water
)
616 if (spk
== 110 || liq() != water
|| !here(bottle
))
622 case 16: /* 9160: rub */
626 case 17: /* 9170: throw */
642 case 20: /* 9190: find, invent */
643 if (at(obj
) || (liq() == obj
&& at(bottle
))
646 for (i
= 1; i
<= 5; i
++)
647 if (dloc
[i
] == loc
&& dflag
>= 2 && obj
== dwarf
)
654 l9210
: case 21:/* feed */
661 l9220
: case 22:/* fill */
672 l9230
: case 23:/* blast */
673 if (prop
[rod2
] < 0 || !closed
)
682 l9270
: case 27:/* read */
691 if (obj
== oyster
&& hinted
[2] && toting(oyster
))
693 if (obj
!= oyster
|| hinted
[2] || !toting(oyster
)
696 hinted
[2] = yes(192, 193, 54);
704 if (obj
== vase
&& prop
[vase
] == 0) {
712 if (obj
!= mirror
|| !closed
)
720 if (obj
!= dwarf
|| !closed
)
731 if (fixed
[k
] != loc
&& !here(k
))
733 l5010
: if (*wd2
!= 0)
737 printf("What do you want to do with the %s?\n", wd1
);
739 l5100
: if (k
!= grate
)
741 if (loc
== 1 || loc
== 4 || loc
== 7)
743 if (loc
> 9 && loc
< 15)
747 l5110
: if (k
!= dwarf
)
749 for (i
= 1; i
<= 5; i
++)
750 if (dloc
[i
] == loc
&& dflag
>= 2)
752 l5120
: if ((liq() == k
&& here(bottle
)) || k
== liqloc(loc
))
754 if (obj
!= plant
|| !at(plant2
) || prop
[plant2
] == 0)
758 l5130
: if (obj
!= knife
|| knfloc
!= loc
)
763 l5140
: if (obj
!= rod
|| !here(rod2
))
767 l5190
: if ((verb
== find
|| verb
== invent
) && *wd2
== 0)
769 printf("I see no %s here\n", wd1
);