main.c revision 1.5 1 /* $NetBSD: main.c,v 1.5 1996/05/21 21:53:09 mrg 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 #ifndef lint
42 static char copyright[] =
43 "@(#) 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 static char rcsid[] = "$NetBSD: main.c,v 1.5 1996/05/21 21:53:09 mrg 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 <signal.h>
59 #include <stdio.h>
60 #include "hdr.h"
61
62 main(argc,argv)
63 int argc;
64 char **argv;
65 {
66 register int i;
67 int rval,ll;
68 struct text *kk;
69 extern trapdel();
70
71 /* adventure doesn't need setuid-ness, so, just get rid of it */
72 if (setuid(getuid()) < 0)
73 perror("setuid");
74
75 init(); /* Initialize everything */
76 signal(SIGINT,trapdel);
77
78 if (argc > 1) /* Restore file specified */
79 { /* Restart is label 8305 (Fortran) */
80 i = restore(argv[1]); /* See what we've got */
81 switch(i)
82 {
83 case 0: /* The restore worked fine */
84 yea=Start(0);
85 k=null;
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 exit(0); /* So give up */
90 case 2: /* Oops -- file was altered */
91 rspeak(202); /* You dissolve */
92 exit(0); /* File could be non-adventure */
93 } /* So don't unlink it. */
94 }
95
96 startup(); /* prepare for a user */
97
98 for (;;) /* main command loop (label 2) */
99 { if (newloc<9 && newloc!=0 && closng)
100 { rspeak(130); /* if closing leave only by */
101 newloc=loc; /* main office */
102 if (!panic) clock2=15;
103 panic=TRUE;
104 }
105
106 rval=fdwarf(); /* dwarf stuff */
107 if (rval==99) die(99);
108
109 l2000: if (loc==0) die(99); /* label 2000 */
110 kk = &stext[loc];
111 if ((abb[loc]%abbnum)==0 || kk->seekadr==0)
112 kk = <ext[loc];
113 if (!forced(loc) && dark(0))
114 { if (wzdark && pct(35))
115 { die(90);
116 goto l2000;
117 }
118 kk = &rtext[16];
119 }
120 l2001: if (toting(bear)) rspeak(141); /* 2001 */
121 speak(kk);
122 k=1;
123 if (forced(loc))
124 goto l8;
125 if (loc==33 && pct(25)&&!closng) rspeak(8);
126 if (!dark(0))
127 { abb[loc]++;
128 for (i=atloc[loc]; i!=0; i=link[i]) /*2004 */
129 { obj=i;
130 if (obj>100) obj -= 100;
131 if (obj==steps && toting(nugget)) continue;
132 if (prop[obj]<0)
133 { if (closed) continue;
134 prop[obj]=0;
135 if (obj==rug||obj==chain)
136 prop[obj]=1;
137 tally--;
138 if (tally==tally2 && tally != 0)
139 if (limit>35) limit=35;
140 }
141 ll = prop[obj]; /* 2006 */
142 if (obj==steps && loc==fixed[steps])
143 ll = 1;
144 pspeak(obj, ll);
145 } /* 2008 */
146 goto l2012;
147 l2009: k=54; /* 2009 */
148 l2010: spk=k;
149 l2011: rspeak(spk);
150 }
151 l2012: verb=0; /* 2012 */
152 obj=0;
153 l2600: checkhints(); /* to 2600-2602 */
154 if (closed)
155 { if (prop[oyster]<0 && toting(oyster))
156 pspeak(oyster,1);
157 for (i=1; i<100; i++)
158 if (toting(i)&&prop[i]<0) /*2604 */
159 prop[i] = -1-prop[i];
160 }
161 wzdark=dark(0); /* 2605 */
162 if (knfloc>0 && knfloc!=loc) knfloc=1;
163 getin(&wd1,&wd2);
164 if (delhit) /* user typed a DEL */
165 { delhit=0; /* reset counter */
166 copystr("quit",wd1); /* pretend he's quitting*/
167 *wd2=0;
168 }
169 l2608: if ((foobar = -foobar)>0) foobar=0; /* 2608 */
170 /* should check here for "magic mode" */
171 turns++;
172 if (demo && turns>=SHORT) done(1); /* to 13000 */
173
174 if (verb==say && *wd2!=0) verb=0;
175 if (verb==say)
176 goto l4090;
177 if (tally==0 && loc>=15 && loc!=33) clock1--;
178 if (clock1==0)
179 { closing(); /* to 10000 */
180 goto l19999;
181 }
182 if (clock1<0) clock2--;
183 if (clock2==0)
184 { caveclose(); /* to 11000 */
185 continue; /* back to 2 */
186 }
187 if (prop[lamp]==1) limit--;
188 if (limit<=30 && here(batter) && prop[batter]==0
189 && here(lamp))
190 { rspeak(188); /* 12000 */
191 prop[batter]=1;
192 if (toting(batter)) drop(batter,loc);
193 limit=limit+2500;
194 lmwarn=FALSE;
195 goto l19999;
196 }
197 if (limit==0)
198 { limit = -1; /* 12400 */
199 prop[lamp]=0;
200 rspeak(184);
201 goto l19999;
202 }
203 if (limit<0&&loc<=8)
204 { rspeak(185); /* 12600 */
205 gaveup=TRUE;
206 done(2); /* to 20000 */
207 }
208 if (limit<=30)
209 { if (lmwarn|| !here(lamp)) goto l19999; /*12200*/
210 lmwarn=TRUE;
211 spk=187;
212 if (place[batter]==0) spk=183;
213 if (prop[batter]==1) spk=189;
214 rspeak(spk);
215 }
216 l19999: k=43;
217 if (liqloc(loc)==water) k=70;
218 if (weq(wd1,"enter") &&
219 (weq(wd2,"strea")||weq(wd2,"water")))
220 goto l2010;
221 if (weq(wd1,"enter") && *wd2!=0) goto l2800;
222 if ((!weq(wd1,"water")&&!weq(wd1,"oil"))
223 || (!weq(wd2,"plant")&&!weq(wd2,"door")))
224 goto l2610;
225 if (at(vocab(wd2,1))) copystr("pour",wd2);
226
227 l2610: if (weq(wd1,"west"))
228 if (++iwest==10) rspeak(17);
229 l2630: i=vocab(wd1,-1);
230 if (i== -1)
231 { spk=60; /* 3000 */
232 if (pct(20)) spk=61;
233 if (pct(20)) spk=13;
234 rspeak(spk);
235 goto l2600;
236 }
237 k=i%1000;
238 kq=i/1000+1;
239 switch(kq)
240 { case 1: goto l8;
241 case 2: goto l5000;
242 case 3: goto l4000;
243 case 4: goto l2010;
244 default:
245 printf("Error 22\n");
246 exit(0);
247 }
248
249 l8:
250 switch(march())
251 { case 2: continue; /* i.e. goto l2 */
252 case 99:
253 switch(die(99))
254 { case 2000: goto l2000;
255 default: bug(111);
256 }
257 default: bug(110);
258 }
259
260 l2800: copystr(wd2,wd1);
261 *wd2=0;
262 goto l2610;
263
264 l4000: verb=k;
265 spk=actspk[verb];
266 if (*wd2!=0 && verb!=say) goto l2800;
267 if (verb==say) obj= *wd2;
268 if (obj!=0) goto l4090;
269 l4080:
270 switch(verb)
271 { case 1: /* take = 8010 */
272 if (atloc[loc]==0||link[atloc[loc]]!=0) goto l8000;
273 for (i=1; i<=5; i++)
274 if (dloc[i]==loc&&dflag>=2) goto l8000;
275 obj=atloc[loc];
276 goto l9010;
277 case 2: case 3: case 9: /* 8000 : drop,say,wave */
278 case 10: case 16: case 17: /* calm,rub,toss */
279 case 19: case 21: case 28: /* find,feed,break */
280 case 29: /* wake */
281 l8000: printf("%s what?\n",wd1);
282 obj=0;
283 goto l2600;
284 case 4: case 6: /* 8040 open,lock */
285 spk=28;
286 if (here(clam)) obj=clam;
287 if (here(oyster)) obj=oyster;
288 if (at(door)) obj=door;
289 if (at(grate)) obj=grate;
290 if (obj!=0 && here(chain)) goto l8000;
291 if (here(chain)) obj=chain;
292 if (obj==0) goto l2011;
293 goto l9040;
294 case 5: goto l2009; /* nothing */
295 case 7: goto l9070; /* on */
296 case 8: goto l9080; /* off */
297 case 11: goto l8000; /* walk */
298 case 12: goto l9120; /* kill */
299 case 13: goto l9130; /* pour */
300 case 14: /* eat: 8140 */
301 if (!here(food)) goto l8000;
302 l8142: dstroy(food);
303 spk=72;
304 goto l2011;
305 case 15: goto l9150; /* drink */
306 case 18: /* quit: 8180 */
307 gaveup=yes(22,54,54);
308 if (gaveup) done(2); /* 8185 */
309 goto l2012;
310 case 20: /* invent=8200 */
311 spk=98;
312 for (i=1; i<=100; i++)
313 { if (i!=bear && toting(i))
314 { if (spk==98) rspeak(99);
315 blklin=FALSE;
316 pspeak(i,-1);
317 blklin=TRUE;
318 spk=0;
319 }
320 }
321 if (toting(bear)) spk=141;
322 goto l2011;
323 case 22: goto l9220; /* fill */
324 case 23: goto l9230; /* blast */
325 case 24: /* score: 8240 */
326 scorng=TRUE;
327 printf("If you were to quit now, you would score");
328 printf(" %d out of a possible ",score());
329 printf("%d.",mxscor);
330 scorng=FALSE;
331 gaveup=yes(143,54,54);
332 if (gaveup) done(2);
333 goto l2012;
334 case 25: /* foo: 8250 */
335 k=vocab(wd1,3);
336 spk=42;
337 if (foobar==1-k) goto l8252;
338 if (foobar!=0) spk=151;
339 goto l2011;
340 l8252: foobar=k;
341 if (k!=4) goto l2009;
342 foobar=0;
343 if (place[eggs]==plac[eggs]
344 ||(toting(eggs)&&loc==plac[eggs])) goto l2011;
345 if (place[eggs]==0&&place[troll]==0&&prop[troll]==0)
346 prop[troll]=1;
347 k=2;
348 if (here(eggs)) k=1;
349 if (loc==plac[eggs]) k=0;
350 move(eggs,plac[eggs]);
351 pspeak(eggs,k);
352 goto l2012;
353 case 26: /* brief=8260 */
354 spk=156;
355 abbnum=10000;
356 detail=3;
357 goto l2011;
358 case 27: /* read=8270 */
359 if (here(magzin)) obj=magzin;
360 if (here(tablet)) obj=obj*100+tablet;
361 if (here(messag)) obj=obj*100+messag;
362 if (closed&&toting(oyster)) obj=oyster;
363 if (obj>100||obj==0||dark(0)) goto l8000;
364 goto l9270;
365 case 30: /* suspend=8300 */
366 spk=201;
367 if (demo) goto l2011;
368 printf("I can suspend your adventure for you so");
369 printf(" you can resume later, but\n");
370 printf("you will have to wait at least");
371 printf(" %d minutes before continuing.",latncy);
372 if (!yes(200,54,54)) goto l2012;
373 datime(&saved,&savet);
374 ciao(argv[0]); /* Do we quit? */
375 continue; /* Maybe not */
376 case 31: /* hours=8310 */
377 printf("Colossal cave is closed 9am-5pm Mon ");
378 printf("through Fri except holidays.\n");
379 goto l2012;
380 default: bug(23);
381 }
382
383 l4090:
384 switch(verb)
385 { case 1: /* take = 9010 */
386 l9010: switch(trtake())
387 { case 2011: goto l2011;
388 case 9220: goto l9220;
389 case 2009: goto l2009;
390 case 2012: goto l2012;
391 default: bug(102);
392 }
393 l9020: case 2: /* drop = 9020 */
394 switch(trdrop())
395 { case 2011: goto l2011;
396 case 19000: done(3);
397 case 2012: goto l2012;
398 default: bug(105);
399 }
400 l9030: case 3:
401 switch(trsay())
402 { case 2012: goto l2012;
403 case 2630: goto l2630;
404 default: bug(107);
405 }
406 l9040: case 4: case 6: /* open, close */
407 switch(tropen())
408 { case 2011: goto l2011;
409 case 2010: goto l2010;
410 default: bug(106);
411 }
412 case 5: goto l2009; /* nothing */
413 case 7: /* on 9070 */
414 l9070: if (!here(lamp)) goto l2011;
415 spk=184;
416 if (limit<0) goto l2011;
417 prop[lamp]=1;
418 rspeak(39);
419 if (wzdark) goto l2000;
420 goto l2012;
421
422 case 8: /* off */
423 l9080: if (!here(lamp)) goto l2011;
424 prop[lamp]=0;
425 rspeak(40);
426 if (dark(0)) rspeak(16);
427 goto l2012;
428
429 case 9: /* wave */
430 if ((!toting(obj))&&(obj!=rod||!toting(rod2)))
431 spk=29;
432 if (obj!=rod||!at(fissur)||!toting(obj)||closng)
433 goto l2011;
434 prop[fissur]=1-prop[fissur];
435 pspeak(fissur,2-prop[fissur]);
436 goto l2012;
437 case 10: case 11: case 18: /* calm, walk, quit */
438 case 24: case 25: case 26: /* score, foo, brief */
439 case 30: case 31: /* suspend, hours */
440 goto l2011;
441 l9120: case 12: /* kill */
442 switch(trkill())
443 { case 8000: goto l8000;
444 case 8: goto l8;
445 case 2011: goto l2011;
446 case 2608: goto l2608;
447 case 19000: done(3);
448 default: bug(112);
449 }
450 l9130: case 13: /* pour */
451 if (obj==bottle||obj==0) obj=liq(0);
452 if (obj==0) goto l8000;
453 if (!toting(obj)) goto l2011;
454 spk=78;
455 if (obj!=oil&&obj!=water) goto l2011;
456 prop[bottle]=1;
457 place[obj]=0;
458 spk=77;
459 if (!(at(plant)||at(door))) goto l2011;
460 if (at(door))
461 { prop[door]=0; /* 9132 */
462 if (obj==oil) prop[door]=1;
463 spk=113+prop[door];
464 goto l2011;
465 }
466 spk=112;
467 if (obj!=water) goto l2011;
468 pspeak(plant,prop[plant]+1);
469 prop[plant]=(prop[plant]+2)% 6;
470 prop[plant2]=prop[plant]/2;
471 k=null;
472 goto l8;
473 case 14: /* 9140 - eat */
474 if (obj==food) goto l8142;
475 if (obj==bird||obj==snake||obj==clam||obj==oyster
476 ||obj==dwarf||obj==dragon||obj==troll
477 ||obj==bear) spk=71;
478 goto l2011;
479 l9150: case 15: /* 9150 - drink */
480 if (obj==0&&liqloc(loc)!=water&&(liq(0)!=water
481 ||!here(bottle))) goto l8000;
482 if (obj!=0&&obj!=water) spk=110;
483 if (spk==110||liq(0)!=water||!here(bottle))
484 goto l2011;
485 prop[bottle]=1;
486 place[water]=0;
487 spk=74;
488 goto l2011;
489 case 16: /* 9160: rub */
490 if (obj!=lamp) spk=76;
491 goto l2011;
492 case 17: /* 9170: throw */
493 switch(trtoss())
494 { case 2011: goto l2011;
495 case 9020: goto l9020;
496 case 9120: goto l9120;
497 case 8: goto l8;
498 case 9210: goto l9210;
499 default: bug(113);
500 }
501 case 19: case 20: /* 9190: find, invent */
502 if (at(obj)||(liq(0)==obj&&at(bottle))
503 ||k==liqloc(loc)) spk=94;
504 for (i=1; i<=5; i++)
505 if (dloc[i]==loc&&dflag>=2&&obj==dwarf)
506 spk=94;
507 if (closed) spk=138;
508 if (toting(obj)) spk=24;
509 goto l2011;
510 l9210: case 21: /* feed */
511 switch(trfeed())
512 { case 2011: goto l2011;
513 default: bug(114);
514 }
515 l9220: case 22: /* fill */
516 switch(trfill())
517 { case 2011: goto l2011;
518 case 8000: goto l8000;
519 case 9020: goto l9020;
520 default: bug(115);
521 }
522 l9230: case 23: /* blast */
523 if (prop[rod2]<0||!closed) goto l2011;
524 bonus=133;
525 if (loc==115) bonus=134;
526 if (here(rod2)) bonus=135;
527 rspeak(bonus);
528 done(2);
529 l9270: case 27: /* read */
530 if (dark(0)) goto l5190;
531 if (obj==magzin) spk=190;
532 if (obj==tablet) spk=196;
533 if (obj==messag) spk=191;
534 if (obj==oyster&&hinted[2]&&toting(oyster)) spk=194;
535 if (obj!=oyster||hinted[2]||!toting(oyster)
536 ||!closed) goto l2011;
537 hinted[2]=yes(192,193,54);
538 goto l2012;
539 l9280: case 28: /* break */
540 if (obj==mirror) spk=148;
541 if (obj==vase&&prop[vase]==0)
542 { spk=198;
543 if (toting(vase)) drop(vase,loc);
544 prop[vase]=2;
545 fixed[vase]= -1;
546 goto l2011;
547 }
548 if (obj!=mirror||!closed) goto l2011;
549 rspeak(197);
550 done(3);
551
552 l9290: case 29: /* wake */
553 if (obj!=dwarf||!closed) goto l2011;
554 rspeak(199);
555 done(3);
556
557 default: bug(24);
558 }
559
560 l5000:
561 obj=k;
562 if (fixed[k]!=loc && !here(k)) goto l5100;
563 l5010: if (*wd2!=0) goto l2800;
564 if (verb!=0) goto l4090;
565 printf("What do you want to do with the %s?\n",wd1);
566 goto l2600;
567 l5100: if (k!=grate) goto l5110;
568 if (loc==1||loc==4||loc==7) k=dprssn;
569 if (loc>9&&loc<15) k=entrnc;
570 if (k!=grate) goto l8;
571 l5110: if (k!=dwarf) goto l5120;
572 for (i=1; i<=5; i++)
573 if (dloc[i]==loc&&dflag>=2) goto l5010;
574 l5120: if ((liq(0)==k&&here(bottle))||k==liqloc(loc)) goto l5010;
575 if (obj!=plant||!at(plant2)||prop[plant2]==0) goto l5130;
576 obj=plant2;
577 goto l5010;
578 l5130: if (obj!=knife||knfloc!=loc) goto l5140;
579 knfloc = -1;
580 spk=116;
581 goto l2011;
582 l5140: if (obj!=rod||!here(rod2)) goto l5190;
583 obj=rod2;
584 goto l5010;
585 l5190: if ((verb==find||verb==invent)&&*wd2==0) goto l5010;
586 printf("I see no %s here\n",wd1);
587 goto l2012;
588 }
589 }
590