]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - adventure/main.c
avoid strange typcast.
[bsdgames-darwin.git] / adventure / main.c
1 /* $NetBSD: main.c,v 1.16 2000/07/03 03:57:39 matt Exp $ */
2
3 /*-
4 * Copyright (c) 1991, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
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.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
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.
27 *
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
38 * SUCH DAMAGE.
39 */
40
41 #include <sys/cdefs.h>
42 #ifndef lint
43 __COPYRIGHT("@(#) Copyright (c) 1991, 1993\n\
44 The Regents of the University of California. All rights reserved.\n");
45 #endif /* not lint */
46
47 #ifndef lint
48 #if 0
49 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/2/93";
50 #else
51 __RCSID("$NetBSD: main.c,v 1.16 2000/07/03 03:57:39 matt Exp $");
52 #endif
53 #endif /* not lint */
54
55 /* Re-coding of advent in C: main program */
56
57 #include <sys/file.h>
58 #include <err.h>
59 #include <signal.h>
60 #include <stdio.h>
61 #include <stdlib.h>
62 #include <unistd.h>
63 #include "hdr.h"
64 #include "extern.h"
65
66 int main __P((int, char **));
67
68 int
69 main(argc, argv)
70 int argc;
71 char **argv;
72 {
73 int i;
74 int rval, ll;
75 struct text *kk;
76
77 /* revoke setgid privileges from dm */
78 setgid(getgid());
79
80 init(); /* Initialize everything */
81 signal(SIGINT, trapdel);
82
83 if (argc > 1) { /* Restore file specified */
84 /* Restart is label 8305 (Fortran) */
85 i = restore(argv[1]); /* See what we've got */
86 switch (i) {
87 case 0: /* The restore worked fine */
88 yea = Start();
89 k = null;
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. */
98 }
99 startup(); /* prepare for a user */
100
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 */
105 if (!panic)
106 clock2 = 15;
107 panic = TRUE;
108 }
109 rval = fdwarf(); /* dwarf stuff */
110 if (rval == 99)
111 die(99);
112
113 l2000: if (loc == 0)
114 die(99); /* label 2000 */
115 kk = &stext[loc];
116 if ((abb[loc] % abbnum) == 0 || kk->seekadr == 0)
117 kk = &ltext[loc];
118 if (!forced(loc) && dark()) {
119 if (wzdark && pct(35)) {
120 die(90);
121 goto l2000;
122 }
123 kk = &rtext[16];
124 }
125 #if 0
126 l2001:
127 #endif
128 if (toting(bear))
129 rspeak(141); /* 2001 */
130 speak(kk);
131 k = 1;
132 if (forced(loc))
133 goto l8;
134 if (loc == 33 && pct(25) && !closng)
135 rspeak(8);
136 if (!dark()) {
137 abb[loc]++;
138 for (i = atloc[loc]; i != 0; i = links[i]) { /* 2004 */
139 obj = i;
140 if (obj > 100)
141 obj -= 100;
142 if (obj == steps && toting(nugget))
143 continue;
144 if (prop[obj] < 0) {
145 if (closed)
146 continue;
147 prop[obj] = 0;
148 if (obj == rug || obj == chain)
149 prop[obj] = 1;
150 tally--;
151 if (tally == tally2 && tally != 0)
152 if (limit > 35)
153 limit = 35;
154 }
155 ll = prop[obj]; /* 2006 */
156 if (obj == steps && loc == fixed[steps])
157 ll = 1;
158 pspeak(obj, ll);
159 } /* 2008 */
160 goto l2012;
161 l2009: k = 54; /* 2009 */
162 l2010: spk = k;
163 l2011: rspeak(spk);
164 }
165 l2012: verb = 0; /* 2012 */
166 obj = 0;
167 l2600: checkhints(); /* to 2600-2602 */
168 if (closed) {
169 if (prop[oyster] < 0 && toting(oyster))
170 pspeak(oyster, 1);
171 for (i = 1; i < 100; i++)
172 if (toting(i) && prop[i] < 0) /* 2604 */
173 prop[i] = -1 - prop[i];
174 }
175 wzdark = dark(); /* 2605 */
176 if (knfloc > 0 && knfloc != loc)
177 knfloc = 1;
178 getin(&wd1, &wd2);
179 if (delhit) { /* user typed a DEL */
180 delhit = 0; /* reset counter */
181 copystr("quit", wd1); /* pretend he's quitting */
182 *wd2 = 0;
183 }
184 l2608: if ((foobar = -foobar) > 0)
185 foobar = 0; /* 2608 */
186 /* should check here for "magic mode" */
187 turns++;
188 if (demo && turns >= SHORT)
189 done(1); /* to 13000 */
190
191 if (verb == say && *wd2 != 0)
192 verb = 0;
193 if (verb == say)
194 goto l4090;
195 if (tally == 0 && loc >= 15 && loc != 33)
196 clock1--;
197 if (clock1 == 0) {
198 closing(); /* to 10000 */
199 goto l19999;
200 }
201 if (clock1 < 0)
202 clock2--;
203 if (clock2 == 0) {
204 caveclose(); /* to 11000 */
205 continue; /* back to 2 */
206 }
207 if (prop[lamp] == 1)
208 limit--;
209 if (limit <= 30 && here(batter) && prop[batter] == 0
210 && here(lamp)) {
211 rspeak(188); /* 12000 */
212 prop[batter] = 1;
213 if (toting(batter))
214 drop(batter, loc);
215 limit = limit + 2500;
216 lmwarn = FALSE;
217 goto l19999;
218 }
219 if (limit == 0) {
220 limit = -1; /* 12400 */
221 prop[lamp] = 0;
222 rspeak(184);
223 goto l19999;
224 }
225 if (limit < 0 && loc <= 8) {
226 rspeak(185); /* 12600 */
227 gaveup = TRUE;
228 done(2); /* to 20000 */
229 }
230 if (limit <= 30) {
231 if (lmwarn || !here(lamp))
232 goto l19999; /* 12200 */
233 lmwarn = TRUE;
234 spk = 187;
235 if (place[batter] == 0)
236 spk = 183;
237 if (prop[batter] == 1)
238 spk = 189;
239 rspeak(spk);
240 }
241 l19999: k = 43;
242 if (liqloc(loc) == water)
243 k = 70;
244 if (weq(wd1, "enter") &&
245 (weq(wd2, "strea") || weq(wd2, "water")))
246 goto l2010;
247 if (weq(wd1, "enter") && *wd2 != 0)
248 goto l2800;
249 if ((!weq(wd1, "water") && !weq(wd1, "oil"))
250 || (!weq(wd2, "plant") && !weq(wd2, "door")))
251 goto l2610;
252 if (at(vocab(wd2, 1, 0)))
253 copystr("pour", wd2);
254
255 l2610: if (weq(wd1, "west"))
256 if (++iwest == 10)
257 rspeak(17);
258 l2630: i = vocab(wd1, -1, 0);
259 if (i == -1) {
260 spk = 60; /* 3000 */
261 if (pct(20))
262 spk = 61;
263 if (pct(20))
264 spk = 13;
265 rspeak(spk);
266 goto l2600;
267 }
268 k = i % 1000;
269 kq = i / 1000 + 1;
270 switch (kq) {
271 case 1:
272 goto l8;
273 case 2:
274 goto l5000;
275 case 3:
276 goto l4000;
277 case 4:
278 goto l2010;
279 default:
280 bug(22);
281 }
282
283 l8:
284 switch (march()) {
285 case 2:
286 continue; /* i.e. goto l2 */
287 case 99:
288 die(99);
289 goto l2000;
290 default:
291 bug(110);
292 }
293
294 l2800: copystr(wd2, wd1);
295 *wd2 = 0;
296 goto l2610;
297
298 l4000: verb = k;
299 spk = actspk[verb];
300 if (*wd2 != 0 && verb != say)
301 goto l2800;
302 if (verb == say)
303 obj = *wd2;
304 if (obj != 0)
305 goto l4090;
306 #if 0
307 l4080:
308 #endif
309 switch (verb) {
310 case 1: /* take = 8010 */
311 if (atloc[loc] == 0 || links[atloc[loc]] != 0)
312 goto l8000;
313 for (i = 1; i <= 5; i++)
314 if (dloc[i] == loc && dflag >= 2)
315 goto l8000;
316 obj = atloc[loc];
317 goto l9010;
318 case 2:
319 case 3:
320 case 9: /* 8000 : drop,say,wave */
321 case 10:
322 case 16:
323 case 17: /* calm,rub,toss */
324 case 19:
325 case 21:
326 case 28: /* find,feed,break */
327 case 29: /* wake */
328 l8000: printf("%s what?\n", wd1);
329 obj = 0;
330 goto l2600;
331 case 4:
332 case 6: /* 8040 open,lock */
333 spk = 28;
334 if (here(clam))
335 obj = clam;
336 if (here(oyster))
337 obj = oyster;
338 if (at(door))
339 obj = door;
340 if (at(grate))
341 obj = grate;
342 if (obj != 0 && here(chain))
343 goto l8000;
344 if (here(chain))
345 obj = chain;
346 if (obj == 0)
347 goto l2011;
348 goto l9040;
349 case 5:
350 goto l2009; /* nothing */
351 case 7:
352 goto l9070; /* on */
353 case 8:
354 goto l9080; /* off */
355 case 11:
356 goto l8000; /* walk */
357 case 12:
358 goto l9120; /* kill */
359 case 13:
360 goto l9130; /* pour */
361 case 14: /* eat: 8140 */
362 if (!here(food))
363 goto l8000;
364 l8142: dstroy(food);
365 spk = 72;
366 goto l2011;
367 case 15:
368 goto l9150; /* drink */
369 case 18: /* quit: 8180 */
370 gaveup = yes(22, 54, 54);
371 if (gaveup)
372 done(2); /* 8185 */
373 goto l2012;
374 case 20: /* invent=8200 */
375 spk = 98;
376 for (i = 1; i <= 100; i++) {
377 if (i != bear && toting(i)) {
378 if (spk == 98)
379 rspeak(99);
380 blklin = FALSE;
381 pspeak(i, -1);
382 blklin = TRUE;
383 spk = 0;
384 }
385 }
386 if (toting(bear))
387 spk = 141;
388 goto l2011;
389 case 22:
390 goto l9220; /* fill */
391 case 23:
392 goto l9230; /* blast */
393 case 24: /* score: 8240 */
394 scorng = TRUE;
395 printf("If you were to quit now, you would score");
396 printf(" %d out of a possible ", score());
397 printf("%d.", mxscor);
398 scorng = FALSE;
399 gaveup = yes(143, 54, 54);
400 if (gaveup)
401 done(2);
402 goto l2012;
403 case 25: /* foo: 8250 */
404 k = vocab(wd1, 3, 0);
405 spk = 42;
406 if (foobar == 1 - k)
407 goto l8252;
408 if (foobar != 0)
409 spk = 151;
410 goto l2011;
411 l8252: foobar = k;
412 if (k != 4)
413 goto l2009;
414 foobar = 0;
415 if (place[eggs] == plac[eggs]
416 || (toting(eggs) && loc == plac[eggs]))
417 goto l2011;
418 if (place[eggs] == 0 && place[troll] == 0 && prop[troll] == 0)
419 prop[troll] = 1;
420 k = 2;
421 if (here(eggs))
422 k = 1;
423 if (loc == plac[eggs])
424 k = 0;
425 move(eggs, plac[eggs]);
426 pspeak(eggs, k);
427 goto l2012;
428 case 26: /* brief=8260 */
429 spk = 156;
430 abbnum = 10000;
431 detail = 3;
432 goto l2011;
433 case 27: /* read=8270 */
434 if (here(magzin))
435 obj = magzin;
436 if (here(tablet))
437 obj = obj * 100 + tablet;
438 if (here(messag))
439 obj = obj * 100 + messag;
440 if (closed && toting(oyster))
441 obj = oyster;
442 if (obj > 100 || obj == 0 || dark())
443 goto l8000;
444 goto l9270;
445 case 30: /* suspend=8300 */
446 spk = 201;
447 if (demo)
448 goto l2011;
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))
454 goto l2012;
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");
461 goto l2012;
462 default:
463 bug(23);
464 }
465
466 l4090:
467 switch (verb) {
468 case 1: /* take = 9010 */
469 l9010: switch (trtake()) {
470 case 2011:
471 goto l2011;
472 case 9220:
473 goto l9220;
474 case 2009:
475 goto l2009;
476 case 2012:
477 goto l2012;
478 default:
479 bug(102);
480 }
481 l9020: case 2: /* drop = 9020 */
482 switch (trdrop()) {
483 case 2011:
484 goto l2011;
485 case 19000:
486 done(3);
487 case 2012:
488 goto l2012;
489 default:
490 bug(105);
491 }
492 #if 0
493 l9030:
494 #endif
495 case 3:
496 switch (trsay()) {
497 case 2012:
498 goto l2012;
499 case 2630:
500 goto l2630;
501 default:
502 bug(107);
503 }
504 l9040: case 4:
505 case 6: /* open, close */
506 switch (tropen()) {
507 case 2011:
508 goto l2011;
509 case 2010:
510 goto l2010;
511 default:
512 bug(106);
513 }
514 case 5:
515 goto l2009; /* nothing */
516 case 7: /* on 9070 */
517 l9070: if (!here(lamp))
518 goto l2011;
519 spk = 184;
520 if (limit < 0)
521 goto l2011;
522 prop[lamp] = 1;
523 rspeak(39);
524 if (wzdark)
525 goto l2000;
526 goto l2012;
527
528 case 8: /* off */
529 l9080: if (!here(lamp))
530 goto l2011;
531 prop[lamp] = 0;
532 rspeak(40);
533 if (dark())
534 rspeak(16);
535 goto l2012;
536
537 case 9: /* wave */
538 if ((!toting(obj)) && (obj != rod || !toting(rod2)))
539 spk = 29;
540 if (obj != rod || !at(fissur) || !toting(obj) || closng)
541 goto l2011;
542 prop[fissur] = 1 - prop[fissur];
543 pspeak(fissur, 2 - prop[fissur]);
544 goto l2012;
545 case 10:
546 case 11:
547 case 18: /* calm, walk, quit */
548 case 24:
549 case 25:
550 case 26: /* score, foo, brief */
551 case 30:
552 case 31: /* suspend, hours */
553 goto l2011;
554 l9120: case 12:/* kill */
555 switch (trkill()) {
556 case 8000:
557 goto l8000;
558 case 8:
559 goto l8;
560 case 2011:
561 goto l2011;
562 case 2608:
563 goto l2608;
564 case 19000:
565 done(3);
566 default:
567 bug(112);
568 }
569 l9130: case 13:/* pour */
570 if (obj == bottle || obj == 0)
571 obj = liq();
572 if (obj == 0)
573 goto l8000;
574 if (!toting(obj))
575 goto l2011;
576 spk = 78;
577 if (obj != oil && obj != water)
578 goto l2011;
579 prop[bottle] = 1;
580 place[obj] = 0;
581 spk = 77;
582 if (!(at(plant) || at(door)))
583 goto l2011;
584 if (at(door)) {
585 prop[door] = 0; /* 9132 */
586 if (obj == oil)
587 prop[door] = 1;
588 spk = 113 + prop[door];
589 goto l2011;
590 }
591 spk = 112;
592 if (obj != water)
593 goto l2011;
594 pspeak(plant, prop[plant] + 1);
595 prop[plant] = (prop[plant] + 2) % 6;
596 prop[plant2] = prop[plant] / 2;
597 k = null;
598 goto l8;
599 case 14: /* 9140 - eat */
600 if (obj == food)
601 goto l8142;
602 if (obj == bird || obj == snake || obj == clam || obj == oyster
603 || obj == dwarf || obj == dragon || obj == troll
604 || obj == bear)
605 spk = 71;
606 goto l2011;
607 l9150: case 15:/* 9150 - drink */
608 if (obj == 0 && liqloc(loc) != water && (liq() != water
609 || !here(bottle)))
610 goto l8000;
611 if (obj != 0 && obj != water)
612 spk = 110;
613 if (spk == 110 || liq() != water || !here(bottle))
614 goto l2011;
615 prop[bottle] = 1;
616 place[water] = 0;
617 spk = 74;
618 goto l2011;
619 case 16: /* 9160: rub */
620 if (obj != lamp)
621 spk = 76;
622 goto l2011;
623 case 17: /* 9170: throw */
624 switch (trtoss()) {
625 case 2011:
626 goto l2011;
627 case 9020:
628 goto l9020;
629 case 9120:
630 goto l9120;
631 case 8:
632 goto l8;
633 case 9210:
634 goto l9210;
635 default:
636 bug(113);
637 }
638 case 19:
639 case 20: /* 9190: find, invent */
640 if (at(obj) || (liq() == obj && at(bottle))
641 || k == liqloc(loc))
642 spk = 94;
643 for (i = 1; i <= 5; i++)
644 if (dloc[i] == loc && dflag >= 2 && obj == dwarf)
645 spk = 94;
646 if (closed)
647 spk = 138;
648 if (toting(obj))
649 spk = 24;
650 goto l2011;
651 l9210: case 21:/* feed */
652 switch (trfeed()) {
653 case 2011:
654 goto l2011;
655 default:
656 bug(114);
657 }
658 l9220: case 22:/* fill */
659 switch (trfill()) {
660 case 2011:
661 goto l2011;
662 case 8000:
663 goto l8000;
664 case 9020:
665 goto l9020;
666 default:
667 bug(115);
668 }
669 l9230: case 23:/* blast */
670 if (prop[rod2] < 0 || !closed)
671 goto l2011;
672 bonus = 133;
673 if (loc == 115)
674 bonus = 134;
675 if (here(rod2))
676 bonus = 135;
677 rspeak(bonus);
678 done(2);
679 l9270: case 27:/* read */
680 if (dark())
681 goto l5190;
682 if (obj == magzin)
683 spk = 190;
684 if (obj == tablet)
685 spk = 196;
686 if (obj == messag)
687 spk = 191;
688 if (obj == oyster && hinted[2] && toting(oyster))
689 spk = 194;
690 if (obj != oyster || hinted[2] || !toting(oyster)
691 || !closed)
692 goto l2011;
693 hinted[2] = yes(192, 193, 54);
694 goto l2012;
695 #if 0
696 l9280:
697 #endif
698 case 28: /* break */
699 if (obj == mirror)
700 spk = 148;
701 if (obj == vase && prop[vase] == 0) {
702 spk = 198;
703 if (toting(vase))
704 drop(vase, loc);
705 prop[vase] = 2;
706 fixed[vase] = -1;
707 goto l2011;
708 }
709 if (obj != mirror || !closed)
710 goto l2011;
711 rspeak(197);
712 done(3);
713 #if 0
714 l9290:
715 #endif
716 case 29: /* wake */
717 if (obj != dwarf || !closed)
718 goto l2011;
719 rspeak(199);
720 done(3);
721
722 default:
723 bug(24);
724 }
725
726 l5000:
727 obj = k;
728 if (fixed[k] != loc && !here(k))
729 goto l5100;
730 l5010: if (*wd2 != 0)
731 goto l2800;
732 if (verb != 0)
733 goto l4090;
734 printf("What do you want to do with the %s?\n", wd1);
735 goto l2600;
736 l5100: if (k != grate)
737 goto l5110;
738 if (loc == 1 || loc == 4 || loc == 7)
739 k = dprssn;
740 if (loc > 9 && loc < 15)
741 k = entrnc;
742 if (k != grate)
743 goto l8;
744 l5110: if (k != dwarf)
745 goto l5120;
746 for (i = 1; i <= 5; i++)
747 if (dloc[i] == loc && dflag >= 2)
748 goto l5010;
749 l5120: if ((liq() == k && here(bottle)) || k == liqloc(loc))
750 goto l5010;
751 if (obj != plant || !at(plant2) || prop[plant2] == 0)
752 goto l5130;
753 obj = plant2;
754 goto l5010;
755 l5130: if (obj != knife || knfloc != loc)
756 goto l5140;
757 knfloc = -1;
758 spk = 116;
759 goto l2011;
760 l5140: if (obj != rod || !here(rod2))
761 goto l5190;
762 obj = rod2;
763 goto l5010;
764 l5190: if ((verb == find || verb == invent) && *wd2 == 0)
765 goto l5010;
766 printf("I see no %s here\n", wd1);
767 goto l2012;
768 }
769 }