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