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