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