home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 8 / amigaformatcd08.iso / screenplay / utilities / scott / source / source.lha / SCOTT.c < prev    next >
C/C++ Source or Header  |  1996-10-30  |  16KB  |  805 lines

  1. #include "SCOTT_A.c"
  2.  
  3. void choice(void)
  4. {
  5.     BYTE key;
  6.  
  7.     put_choice();
  8.     while (1) {
  9.         key = KeyInput();
  10.         //printf("Key: %c\n",key);
  11.         if (tolower(key) == 'e') {
  12.             close_all();
  13.             exit(0);
  14.         }
  15.         if (tolower(key) == 'r') {
  16.             cursor(FALSE);
  17.             WriteCON("Restore\n");
  18.             OutReset();
  19.             if (RestoreGame() == FALSE) {
  20.                 Look();
  21.                 break;
  22.             }
  23.             else put_choice();
  24.         }
  25.         if ((tolower(key) == 's') && RESTART) {
  26.             cursor(FALSE);
  27.             WriteCON("Restart\n");
  28.             OutReset();
  29.             if ((LoadRestart() == FALSE) && RESTART) {
  30.                 WriteCON(CLRSCR);
  31.                 PerformActions(0,0);
  32.                 Look();
  33.                 break;
  34.             }
  35.             else put_choice();
  36.         }
  37.     }
  38. }
  39.  
  40. void SaveBody(FILE *f)
  41. {
  42.     int ct;
  43.  
  44.     for(ct=0;ct<16;ct++)
  45.     {
  46.         fprintf(f,"%d %d\n",Counters[ct],RoomSaved[ct]);
  47.     }
  48.     fprintf(f,"%ld %d %hd %d %d %hd\n",BitFlags, (BitFlags&(1L<<DARKBIT))?1:0,
  49.         MyLoc,CurrentCounter,SavedRoom,GameHeader.LightTime);
  50.     for(ct=0;ct<=GameHeader.NumItems;ct++)
  51.         fprintf(f,"%hd\n",(short)Items[ct].Location);
  52.     fclose(f);
  53. }
  54.  
  55. void LoadBody(FILE *f)
  56. {
  57.     int ct=0;
  58.     short lo;
  59.     short DarkFlag;
  60.  
  61.     for(ct=0;ct<16;ct++)
  62.     {
  63.         fscanf(f,"%d %d\n",&Counters[ct],&RoomSaved[ct]);
  64.     }
  65.     fscanf(f,"%ld %d %hd %d %d %hd\n",
  66.         &BitFlags,&DarkFlag,&MyLoc,&CurrentCounter,&SavedRoom,
  67.         &GameHeader.LightTime);
  68.     /* Backward compatibility */
  69.     if(DarkFlag)
  70.         BitFlags|=(1L<<15);
  71.     for(ct=0;ct<=GameHeader.NumItems;ct++)
  72.     {
  73.         fscanf(f,"%hd\n",&lo);
  74.         Items[ct].Location=(unsigned char)lo;
  75.     }
  76.     fclose(f);
  77. }
  78.  
  79. BOOL SaveRestart()
  80. {
  81.     FILE *f;
  82.  
  83.     f = fopen(restart_file,"w");
  84.     if (f==NULL) return(TRUE);
  85.     SaveBody(f);
  86.     //SetProtection(restart_file,128);
  87.     restart_lock = Lock(restart_file,SHARED_LOCK);
  88.     return(FALSE);
  89. }
  90.  
  91. BOOL LoadRestart()
  92. {
  93.     FILE *f=
  94.  
  95.     f = fopen(restart_file,"r");
  96.     if (f==NULL) return(TRUE);
  97.     LoadBody(f);
  98.     return(FALSE);
  99. }
  100.  
  101. int PerformLine(int ct)
  102. {
  103.     int continuation=0;
  104.     int param[5],pptr=0;
  105.     int act[4];
  106.     int cc=0;
  107.  
  108.     while(cc<5)
  109.     {
  110.         int cv,dv;
  111.         cv=Actions[ct].Condition[cc];
  112.         dv=cv/20;
  113.         cv=cv%20;
  114.         //cv%=20;
  115.         switch(cv)
  116.         {
  117.             case 0:
  118.                 param[pptr++]=dv;
  119.                 break;
  120.             case 1:
  121.                 if(Items[dv].Location!=CARRIED)
  122.                     return(0);
  123.                 break;
  124.             case 2:
  125.                 if(Items[dv].Location!=MyLoc)
  126.                     return(0);
  127.                 break;
  128.             case 3:
  129.                 if(Items[dv].Location!=CARRIED&&
  130.                     Items[dv].Location!=MyLoc)
  131.                     return(0);
  132.                 break;
  133.             case 4:
  134.                 if(MyLoc!=dv)
  135.                     return(0);
  136.                 break;
  137.             case 5:
  138.                 if(Items[dv].Location==MyLoc)
  139.                     return(0);
  140.                 break;
  141.             case 6:
  142.                 if(Items[dv].Location==CARRIED)
  143.                     return(0);
  144.                 break;
  145.             case 7:
  146.                 if(MyLoc==dv)
  147.                     return(0);
  148.                 break;
  149.             case 8:
  150.                 if((BitFlags&(1L<<dv))==0)
  151.                     return(0);
  152.                 break;
  153.             case 9:
  154.                 if(BitFlags&(1L<<dv))
  155.                     return(0);
  156.                 break;
  157.             case 10:
  158.                 if(CountCarried()==0)
  159.                     return(0);
  160.                 break;
  161.             case 11:
  162.                 if(CountCarried())
  163.                     return(0);
  164.                 break;
  165.             case 12:
  166.                 if(Items[dv].Location==CARRIED||Items[dv].Location==MyLoc)
  167.                     return(0);
  168.                 break;
  169.             case 13:
  170.                 if(Items[dv].Location==0)
  171.                     return(0);
  172.                 break;
  173.             case 14:
  174.                 if(Items[dv].Location)
  175.                     return(0);
  176.                 break;
  177.             case 15:
  178.                 if(CurrentCounter>dv)
  179.                     return(0);
  180.                 break;
  181.             case 16:
  182.                 if(CurrentCounter<=dv)
  183.                     return(0);
  184.                 break;
  185.             case 17:
  186.                 if(Items[dv].Location!=Items[dv].InitialLoc)
  187.                     return(0);
  188.                 break;
  189.             case 18:
  190.                 if(Items[dv].Location==Items[dv].InitialLoc)
  191.                     return(0);
  192.                 break;
  193.             case 19: /* Only seen in Brian Howarth games so far */
  194.                 if(CurrentCounter!=dv)
  195.                     return(0);
  196.                 break;
  197.         }
  198.         cc++;
  199.     }
  200.     /* Actions */
  201.     act[0]=Actions[ct].Action[0];
  202.     act[2]=Actions[ct].Action[1];
  203.     act[1]=act[0]%150;
  204.     act[3]=act[2]%150;
  205.     act[0]/=150;
  206.     act[2]/=150;
  207.     cc=0;
  208.     pptr=0;
  209.     while(cc<4)
  210.     {
  211.         if(act[cc]>=1 && act[cc]<52)
  212.         {
  213.             Output(Messages[act[cc]]);
  214.             Output("\n");
  215.         }
  216.         else if(act[cc]>101)
  217.         {
  218.             Output(Messages[act[cc]-50]);
  219.             Output("\n");
  220.         }
  221.         else switch(act[cc])
  222.         {
  223.             case 0: /* NOP */
  224.                 break;
  225.             case 52:
  226.                 if(CountCarried()==GameHeader.MaxCarry)
  227.                 {
  228.                     if(Options&YOUARE)
  229.                         Output("You are carrying too much.\n");
  230.                     else
  231.                         Output("I've too much to carry!\n");
  232.                     break;
  233.                 }
  234.                 if(Items[param[pptr]].Location==MyLoc)
  235.                     Redraw=1;
  236.                 Items[param[pptr++]].Location= CARRIED;
  237.                 break;
  238.             case 53:
  239.                 Redraw=1;
  240.                 Items[param[pptr++]].Location=MyLoc;
  241.                 break;
  242.             case 54:
  243.                 Redraw=1;
  244.                 MyLoc=param[pptr++];
  245.                 break;
  246.             case 55:
  247.                 if(Items[param[pptr]].Location==MyLoc)
  248.                     Redraw=1;
  249.                 Items[param[pptr++]].Location=0;
  250.                 break;
  251.             case 56:
  252.                 BitFlags|=1L<<DARKBIT;
  253.                 break;
  254.             case 57:
  255.                 BitFlags&=~(1L<<DARKBIT);
  256.                 break;
  257.             case 58:
  258.                 BitFlags|=(1L<<param[pptr++]);
  259.                 break;
  260.             case 59:
  261.                 if(Items[param[pptr]].Location==MyLoc)
  262.                     Redraw=1;
  263.                 Items[param[pptr++]].Location=0;
  264.                 break;
  265.             case 60:
  266.                 BitFlags&=~(1L<<param[pptr++]);
  267.                 break;
  268.             case 61:
  269.                 if(Options&YOUARE)
  270.                     Output("You are dead.\n");
  271.                 else
  272.                     Output("I am dead.\n");
  273.                 BitFlags&=~(1L<<DARKBIT);
  274.                 MyLoc=GameHeader.NumRooms; /* It seems to be what the code says! */
  275.                 Look();
  276.                 break;
  277.             case 62:
  278.             {
  279.                 /* Bug fix for some systems - before it could get parameters wrong */
  280.                 int i=param[pptr++];
  281.                 Items[i].Location=param[pptr++];
  282.                 Redraw=1;
  283.                 break;
  284.             }
  285.             case 63:
  286. doneit:         OutBuf("The game is now over!\n");
  287.                 choice();
  288.                 break;
  289.             case 64:
  290.                 Look();
  291.                 break;
  292.             case 65:
  293.             {
  294.                 int ct=0;
  295.                 int n=0;
  296.                 while(ct<=GameHeader.NumItems)
  297.                 {
  298.                     if(Items[ct].Location==GameHeader.TreasureRoom &&
  299.                       *Items[ct].Text=='*')
  300.                         n++;
  301.                     ct++;
  302.                 }
  303.                 if(Options&YOUARE)
  304.                     Output("You have stored ");
  305.                 else
  306.                     Output("I've stored ");
  307.                 OutputNumber(n);
  308.                 Output("treasures.\nOn a scale of 0 to 100, that scores ");
  309.                 OutputNumber((n*100)/GameHeader.Treasures);
  310.                 Output("points.\n");
  311.                 if(n==GameHeader.Treasures)
  312.                 {
  313.                     Output("Well done.\n");
  314.                     goto doneit;
  315.                 }
  316.                 break;
  317.             }
  318.             case 66:
  319.             {
  320.                 int ct=0;
  321.                 int f=0;
  322.                 if(Options&YOUARE)
  323.                     Output("You are carrying:\n");
  324.                 else
  325.                     Output("I'm carrying:\n");
  326.                 while(ct<=GameHeader.NumItems)
  327.                 {
  328.                     if(Items[ct].Location==CARRIED)
  329.                     {
  330.                         if(f==1)
  331.                         {
  332.                             if (Options & TRS80_STYLE)
  333.                                 Output(". ");
  334.                             else
  335.                                 Output(" - ");
  336.                         }
  337.                         f=1;
  338.                         Output(Items[ct].Text);
  339.                     }
  340.                     ct++;
  341.                 }
  342.                 if(f==0)
  343.                     Output("Nothing");
  344.                 Output(".\n");
  345.                 break;
  346.             }
  347.             case 67:
  348.                 BitFlags|=(1L<<0);
  349.                 break;
  350.             case 68:
  351.                 BitFlags&=~(1L<<0);
  352.                 break;
  353.             case 69:
  354.                 GameHeader.LightTime=LightRefill;
  355.                 if(Items[LIGHT_SOURCE].Location==MyLoc)
  356.                     Redraw=1;
  357.                 Items[LIGHT_SOURCE].Location=CARRIED;
  358.                 BitFlags&=~(1L<<LIGHTOUTBIT);
  359.                 break;
  360.             case 70:
  361.                 clrscr(); /* pdd. */
  362.                 OutReset();
  363.                 break;
  364.             case 71:
  365.                 SaveGame();
  366.                 break;
  367.             case 72:
  368.             {
  369.                 int i1=param[pptr++];
  370.                 int i2=param[pptr++];
  371.                 int t=Items[i1].Location;
  372.                 if(t==MyLoc || Items[i2].Location==MyLoc)
  373.                     Redraw=1;
  374.                 Items[i1].Location=Items[i2].Location;
  375.                 Items[i2].Location=t;
  376.                 break;
  377.             }
  378.             case 73:
  379.                 continuation=1;
  380.                 break;
  381.             case 74:
  382.                 if(Items[param[pptr]].Location==MyLoc)
  383.                     Redraw=1;
  384.                 Items[param[pptr++]].Location= CARRIED;
  385.                 break;
  386.             case 75:
  387.             {
  388.                 int i1,i2;
  389.                 i1=param[pptr++];
  390.                 i2=param[pptr++];
  391.                 if(Items[i1].Location==MyLoc)
  392.                     Redraw=1;
  393.                 Items[i1].Location=Items[i2].Location;
  394.                 if(Items[i2].Location==MyLoc)
  395.                     Redraw=1;
  396.                 break;
  397.             }
  398.             case 76:    /* Looking at adventure .. */
  399.                 Look();
  400.                 break;
  401.             case 77:
  402.                 if(CurrentCounter>=0)
  403.                     CurrentCounter--;
  404.                 break;
  405.             case 78:
  406.                 OutputNumber(CurrentCounter);
  407.                 break;
  408.             case 79:
  409.                 CurrentCounter=param[pptr++];
  410.                 break;
  411.             case 80:
  412.             {
  413.                 int t=MyLoc;
  414.                 MyLoc=SavedRoom;
  415.                 SavedRoom=t;
  416.                 Redraw=1;
  417.                 break;
  418.             }
  419.             case 81:
  420.             {
  421.                 /* This is somewhat guessed. Claymorgue always
  422.                    seems to do select counter n, thing, select counter n,
  423.                    but uses one value that always seems to exist. Trying
  424.                    a few options I found this gave sane results on ageing */
  425.                 int t=param[pptr++];
  426.                 int c1=CurrentCounter;
  427.                 CurrentCounter=Counters[t];
  428.                 Counters[t]=c1;
  429.                 break;
  430.             }
  431.             case 82:
  432.                 CurrentCounter+=param[pptr++];
  433.                 break;
  434.             case 83:
  435.                 CurrentCounter-=param[pptr++];
  436.                 if(CurrentCounter< -1)
  437.                     CurrentCounter= -1;
  438.                 /* Note: This seems to be needed. I don't yet
  439.                    know if there is a maximum value to limit too */
  440.                 break;
  441.             case 84:
  442.                 Output(NounText);
  443.                 break;
  444.             case 85:
  445.                 Output(NounText);
  446.                 Output("\n");
  447.                 break;
  448.             case 86:
  449.                 Output("\n");
  450.                 break;
  451.             case 87:
  452.             {
  453.                 /* Changed this to swap location<->roomflag[x]
  454.                    not roomflag 0 and x */
  455.                 int p=param[pptr++];
  456.                 int sr=MyLoc;
  457.                 MyLoc=RoomSaved[p];
  458.                 RoomSaved[p]=sr;
  459.                 Redraw=1;
  460.                 break;
  461.             }
  462.             case 88:
  463.                 Delay(100); /* DOC's say 2 seconds. Spectrum times at 1.5 */
  464.                 break;
  465.             case 89:
  466.                 pptr++;
  467.                 printf("Pic-Nr.: %d (Room)\n",MyLoc);
  468.                 WriteCON("\nPIC!\n");
  469.                 /* SAGA draw picture n */
  470.                 /* Spectrum Seas of Blood - start combat ? */
  471.                 /* Poking this into older spectrum games causes a crash */
  472.                 break;
  473.             default:
  474.                 fprintf(stderr,"Unknown action %d [Param begins %d %d]\n",
  475.                     act[cc],param[pptr],param[pptr+1]);
  476.                 break;
  477.         }
  478.         cc++;
  479.     }
  480.     return(1+continuation);
  481. }
  482.  
  483.  
  484. int PerformActions(int vb,int no)
  485. {
  486.     static int disable_sysfunc=0;   /* Recursion lock */
  487.     int d=BitFlags&(1L<<DARKBIT);
  488.  
  489.     int ct=0;
  490.     int fl;
  491.     int doagain=0;
  492.     if(vb==1 && no == -1 )
  493.     {
  494.         Output("Give me a direction too.\n");
  495.         return(0);
  496.     }
  497.     if(vb==1 && no>=1 && no<=6)
  498.     {
  499.         int nl;
  500.         if(Items[LIGHT_SOURCE].Location==MyLoc ||
  501.            Items[LIGHT_SOURCE].Location==CARRIED)
  502.             d=0;
  503.         if(d)
  504.             Output("Dangerous to move in the dark!\n");
  505.         nl=Rooms[MyLoc].Exits[no-1];
  506.         if(nl!=0)
  507.         {
  508.             MyLoc=nl;
  509.             Output("O.K.\n");
  510.             Look();
  511.             return(0);
  512.         }
  513.         if(d)
  514.         {
  515.             if (Options&YOUARE) Output("You fell down and broke your neck.\n");
  516.             else Output("I fell down and broke my neck.\n");
  517.             choice();
  518.         }
  519.         if(Options&YOUARE)
  520.             Output("You can't go in that direction.\n");
  521.         else
  522.             Output("I can't go in that direction.\n");
  523.         return(0);
  524.     }
  525.     fl= -1;
  526.     while(ct<=GameHeader.NumActions)
  527.     {
  528.         int vv,nv;
  529.         vv=Actions[ct].Vocab;
  530.         /* Think this is now right. If a line we run has an action73
  531.            run all following lines with vocab of 0,0 */
  532.         if(vb!=0 && (doagain&&vv!=0))
  533.             break;
  534.         /* Oops.. added this minor cockup fix 1.11 */
  535.         if(vb!=0 && !doagain && fl== 0)
  536.             break;
  537.         nv=vv%150;
  538.         vv/=150;
  539.         if((vv==vb)||(doagain&&Actions[ct].Vocab==0))
  540.         {
  541.             if((vv==0 && RandomPercent(nv))||doagain||
  542.                 (vv!=0 && (nv==no||nv==0)))
  543.             {
  544.                 int f2;
  545.                 if(fl== -1)
  546.                     fl= -2;
  547.                 if((f2=PerformLine(ct))>0)
  548.                 {
  549.                     /* ahah finally figured it out ! */
  550.                     fl=0;
  551.                     if(f2==2)
  552.                         doagain=1;
  553.                     if(vb!=0 && doagain==0)
  554.                         return(0);
  555.                 }
  556.             }
  557.         }
  558.         ct++;
  559.         if(Actions[ct].Vocab!=0)
  560.             doagain=0;
  561.     }
  562.     if(fl!=0 && disable_sysfunc==0)
  563.     {
  564.         int i;
  565.         if(Items[LIGHT_SOURCE].Location==MyLoc ||
  566.            Items[LIGHT_SOURCE].Location==CARRIED)
  567.             d=0;
  568.         if(vb==10 || vb==18)
  569.         {
  570.             /* Yes they really _are_ hardcoded values */
  571.             if(vb==10)
  572.             {
  573.                 if(stricmp(NounText,"ALL")==0)
  574.                 {
  575.                     int ct=0;
  576.                     int f=0;
  577.  
  578.                     if(d)
  579.                     {
  580.                         Output("It is dark.\n");
  581.                         return 0;
  582.                     }
  583.                     while(ct<=GameHeader.NumItems)
  584.                     {
  585.                         if(Items[ct].Location==MyLoc && Items[ct].AutoGet!=NULL && Items[ct].AutoGet[0]!='*')
  586.                         {
  587.                             no=WhichWord(Items[ct].AutoGet,Nouns);
  588.                             disable_sysfunc=1;  /* Don't recurse into auto get ! */
  589.                             PerformActions(vb,no);  /* Recursively check each items table code */
  590.                             disable_sysfunc=0;
  591.                             if(CountCarried()==GameHeader.MaxCarry)
  592.                             {
  593.                                 if(Options&YOUARE)
  594.                                     Output("You are carrying too much.\n");
  595.                                 else
  596.                                     Output("I've too much to carry.\n");
  597.                                 return(0);
  598.                             }
  599.                             Items[ct].Location= CARRIED;
  600.                             Redraw=1;
  601.                             OutBuf(Items[ct].Text);
  602.                             Output(": O.K.\n");
  603.                             f=1;
  604.                         }
  605.                         ct++;
  606.                     }
  607.                     if(f==0)
  608.                         Output("Nothing taken.\n");
  609.                     return(0);
  610.                 }
  611.                 if(no==-1)
  612.                 {
  613.                     Output("What ?\n");
  614.                     return(0);
  615.                 }
  616.                 if(CountCarried()==GameHeader.MaxCarry)
  617.                 {
  618.                     if(Options&YOUARE)
  619.                         Output("You are carrying too much.\n");
  620.                     else
  621.                         Output("I've too much to carry.\n");
  622.                     return(0);
  623.                 }
  624.                 i=MatchUpItem(NounText,MyLoc);
  625.                 if(i==-1)
  626.                 {
  627.                     if(Options&YOUARE)
  628.                         Output("It is beyond your power to do that.\n");
  629.                     else
  630.                         Output("It's beyond my power to do that.\n");
  631.                     return(0);
  632.                 }
  633.                 Items[i].Location= CARRIED;
  634.                 Output("O.K.\n");
  635.                 Redraw=1;
  636.                 return(0);
  637.             }
  638.             if(vb==18)
  639.             {
  640.                 if(stricmp(NounText,"ALL")==0)
  641.                 {
  642.                     int ct=0;
  643.                     int f=0;
  644.                     while(ct<=GameHeader.NumItems)
  645.                     {
  646.                         if(Items[ct].Location==CARRIED && Items[ct].AutoGet && Items[ct].AutoGet[0]!='*')
  647.                         {
  648.                             no=WhichWord(Items[ct].AutoGet,Nouns);
  649.                             disable_sysfunc=1;
  650.                             PerformActions(vb,no);
  651.                             disable_sysfunc=0;
  652.                             Items[ct].Location=MyLoc;
  653.                             OutBuf(Items[ct].Text);
  654.                             Output(": O.K.\n");
  655.                             Redraw=1;
  656.                             f=1;
  657.                         }
  658.                         ct++;
  659.                     }
  660.                     if(f==0)
  661.                         Output("Nothing dropped.\n");
  662.                     return(0);
  663.                 }
  664.                 if(no==-1)
  665.                 {
  666.                     Output("What ?\n");
  667.                     return(0);
  668.                 }
  669.                 i=MatchUpItem(NounText,CARRIED);
  670.                 if(i==-1)
  671.                 {
  672.                     if(Options&YOUARE)
  673.                         Output("It's beyond your power to do that.\n");
  674.                     else
  675.                         Output("It's beyond my power to do that.\n");
  676.                     return(0);
  677.                 }
  678.                 Items[i].Location=MyLoc;
  679.                 Output("O.K.\n");
  680.                 Redraw=1;
  681.                 return(0);
  682.             }
  683.         }
  684.     }
  685.     return(fl);
  686. }
  687.  
  688. void main(int argc, char *argv[])
  689. {
  690.     //FILE *f;
  691.     int vb,no;
  692.     char prog_name[32];
  693.  
  694.     strcpy(prog_name,argv[0]);
  695.     while(argv[1])
  696.     {
  697.         if(*argv[1]!='-')
  698.             break;
  699.         switch(argv[1][1])
  700.         {
  701.             case 'y':
  702.                 Options|=YOUARE;
  703.                 break;
  704.             case 'i':
  705.                 Options&=~YOUARE;
  706.                 break;
  707.             case 'd':
  708.                 Options|=DEBUGGING;
  709.                 break;
  710.             case 's':
  711.                 Options|=SCOTTLIGHT;
  712.                 break;
  713.             case 't':
  714.                 Options|=TRS80_STYLE;
  715.                 break;
  716.             case 'p':
  717.                 Options|=PREHISTORIC_LAMP;
  718.                 break;
  719.             case 'h':
  720.             default:
  721.                 fprintf(stderr,"%s: [-h] [-y] [-s] [-i] [-t] [-d] [-p] <gamename> [savedgame].\n",
  722.                         argv[0]);
  723.                 exit(1);
  724.         }
  725.         if(argv[1][2]!=0) {
  726.             fprintf(stderr,"%s: option -%c does not take a parameter.\n",argv[0],argv[1][1]);
  727.             exit(1);
  728.         }
  729.         argv++;
  730.         argc--;
  731.     }
  732.  
  733.     //printf("%d, %s, %s, %s\n",argc,argv[0],argv[1],argv[2]);
  734.     if (argc == 0) {
  735.         WBSTART = TRUE;
  736.         WBMessage = (struct WBStartup *) argv;
  737.         Init(WBMessage->sm_ArgList->wa_Name,"","");
  738.     }
  739.     else Init(prog_name,((argc<2)?"":argv[1]),((argc<3)?"":argv[2]));
  740.  
  741.     srand(time(NULL));
  742.     Look();
  743.     while(1)
  744.     {
  745.         if(Redraw!=0)
  746.         {
  747.             Look();
  748.             Redraw=0;
  749.         }
  750.         PerformActions(0,0);
  751.         if(Redraw!=0)
  752.         {
  753.             Look();
  754.             Redraw=0;
  755.         }
  756.         GetInput(&vb,&no);
  757.         switch(PerformActions(vb,no))
  758.         {
  759.             case -1:Output("I don't understand your command.\n");
  760.                 break;
  761.             case -2:Output("I can't do that yet.\n");
  762.                 break;
  763.         }
  764.         /* Brian Howarth games seem to use -1 for forever */
  765.         if(Items[LIGHT_SOURCE].Location/*==-1*/!=DESTROYED && GameHeader.LightTime!= -1)
  766.         {
  767.             GameHeader.LightTime--;
  768.             if(GameHeader.LightTime<1)
  769.             {
  770.                 BitFlags|=(1L<<LIGHTOUTBIT);
  771.                 if(Items[LIGHT_SOURCE].Location==CARRIED ||
  772.                     Items[LIGHT_SOURCE].Location==MyLoc)
  773.                 {
  774.                     if(Options&SCOTTLIGHT)
  775.                         Output("Light has run out! ");
  776.                     else
  777.                         Output("Your light has run out. ");
  778.                 }
  779.                 if(Options&PREHISTORIC_LAMP)
  780.                     Items[LIGHT_SOURCE].Location=DESTROYED;
  781.             }
  782.             else if(GameHeader.LightTime<25)
  783.             {
  784.                 if(Items[LIGHT_SOURCE].Location==CARRIED ||
  785.                     Items[LIGHT_SOURCE].Location==MyLoc)
  786.                 {
  787.  
  788.                     if(Options&SCOTTLIGHT)
  789.                     {
  790.                         Output("Light runs out in ");
  791.                         OutputNumber(GameHeader.LightTime);
  792.                         Output(" turns. ");
  793.                     }
  794.                     else
  795.                     {
  796.                         if(GameHeader.LightTime%5==0)
  797.                             Output("Your light is growing dim. ");
  798.                     }
  799.                 }
  800.             }
  801.         }
  802.     }
  803. }
  804.  
  805.