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