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

Defined functions

main defined in line 8; never used

Defined variables

datfd defined in line 7; used 1 times
  • in line 16
sccsid defined in line 5; never used
Last modified: 1982-06-09
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2321
Valid CSS Valid XHTML 1.0 Strict