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