rdplex.c

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2005 Michael K. McCarty & Fritz Bronner
00003 
00004     This program is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or
00007     (at your option) any later version.
00008 
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software
00016     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 */
00018 // Interplay's BUZZ ALDRIN's RACE into SPACE
00019 //
00020 // Formerly -=> LiftOff : Race to the Moon :: IBM version MCGA
00021 // Copyright 1991 by Strategic Visions, Inc.
00022 // Designed by Fritz Bronner
00023 // Programmed by Michael K McCarty
00024 //
00025 /** \file rdplex.c Research and Development Complex
00026  */
00027 
00028 #include "Buzz_inc.h"
00029 #include "externs.h"
00030 
00031 int call,wh;
00032 GXHEADER but,mans;
00033 extern char HARD1,UNIT1,BUTLOAD;
00034 
00035 void SRPrintAt(int x, int y, char *text,char fgd,char bck)
00036 {
00037    grSetColor(bck);PrintAt(x+1,y+1,text);
00038    grSetColor(fgd);PrintAt(x,y,text);
00039    return;
00040 }
00041 
00042 
00043 void Load_RD_BUT(char plr)
00044 {
00045   FILE *fin;
00046   struct {char na[4];uint32_t size;} Boo;
00047   if (BUTLOAD==1) return;
00048   GV(&but,282,61);
00049   GV(&mans,119,17);
00050 
00051   fin=sOpen("RDBOX.BUT","rb",0);
00052   fread(&Boo,sizeof Boo,1,fin);
00053     Swap32bit(Boo.size);
00054 
00055   if (plr==1)
00056     while( strncmp("SBUT",&Boo.na[0],4)!=0) {
00057       fseek(fin,Boo.size,SEEK_CUR);
00058       fread(&Boo,sizeof Boo,1,fin);
00059             Swap32bit(Boo.size);
00060     }
00061   fread((char *)buffer,Boo.size,1,fin);
00062   RLED_img((char *)buffer,(char *)but.vptr,Boo.size,but.w,but.h);
00063   fread(&Boo,sizeof Boo,1,fin);
00064     Swap32bit(Boo.size);
00065   fread((char *)buffer,Boo.size,1,fin); fclose(fin);
00066   RLED_img((char *)buffer,mans.vptr,Boo.size,mans.w,mans.h);
00067   BUTLOAD=1;
00068   return;
00069 }
00070 
00071 void Del_RD_BUT(void)
00072 {
00073   BUTLOAD=0;
00074   DV(&but);
00075   DV(&mans);
00076   return;
00077 }
00078 
00079 void DrawRD(char plr)
00080 {
00081   int i;
00082   FILE *fin;
00083   strcpy(IDT,"i009");strcpy(IKEY,"k009");
00084   
00085   FadeOut(2,pal,10,0,0);
00086   fin=sOpen("VAB.IMG","rb",0);
00087   fread(&pal[0],768,1,fin); fclose(fin);
00088 
00089   gxClearDisplay(0,0);
00090   Load_RD_BUT(plr);
00091   ShBox(0,0,319,22);ShBox(0,24,319,65);
00092 
00093   ShBox(0,68,158,199); IOBox(3,71,154,85);
00094   IOBox(3,182,76,196);IOBox(81,182,154,196);
00095 
00096   ShBox(161,68,319,199);
00097   IOBox(163,155,187,177);IOBox(189,155,213,177);IOBox(215,155,239,177);
00098   IOBox(241,155,265,177);IOBox(267,155,291,177);IOBox(293,155,317,177);
00099 
00100   IOBox(5,27,77,62);IOBox(81,27,158,62);
00101   IOBox(162,27,239,62);IOBox(243,27,315,62);
00102 
00103   IOBox(243,3,316,19);
00104   InBox(3,3,30,19);
00105   InBox(165,157,185,175);
00106   IOBox(163,182,317,196);
00107 
00108   OutBox(21,90,136,176);InBox(26,94,131,172);
00109 
00110   LTArrow(24,186);RTArrow(101,186);
00111 
00112   //GradRect(27,95,130,171,plr*16+128);
00113   RectFill(27,95,130,171,0);
00114 
00115   grSetColor(1);
00116   PrintAt(13,80,"VISIT PURCHASING FACILITY");
00117 
00118   for (i=0;i<6;i++)
00119     gxVirtualDisplay(&mans,i*20,0,166+i*26,158,184+i*26,174,0);
00120 
00121   grSetColor(3);grMoveTo(296,174);grLineTo(314,174);
00122 
00123   gxVirtualDisplay(&but,0,0,8,30,74,59,0);  // Unmanned
00124   gxVirtualDisplay(&but,68,0,84,30,155,59,0); // Rocket
00125   gxVirtualDisplay(&but,141,0,165,30,236,59,0);// Manned
00126   gxVirtualDisplay(&but,214,0,246,30,312,59,0);// Misc
00127 
00128   grSetColor(1);
00129   DispBig(50,5,"RESEARCH",0,-1);
00130   grSetColor(11);
00131   PrintAt(200,8,"CASH:");
00132   DispMB(201,15,Data->P[plr].Cash);
00133 
00134   grSetColor(1);
00135   PrintAt(258,13,"CONTINUE");
00136   FlagSm(plr,4,4);
00137   QUnit(1,1,plr);
00138   ShowUnit(1,1,plr);
00139   
00140   return;
00141 } // End of DrawRD
00142 
00143 
00144 void BButs(char old,char nw)
00145 {
00146   
00147   switch(old) {
00148     case 1:OutBox(7,29,75,60);
00149        gxVirtualDisplay(&but,0,0,8,30,74,59,0);  // Unmanned
00150        break;
00151     case 2:OutBox(83,29,156,60);
00152        gxVirtualDisplay(&but,68,0,84,30,155,59,0); // Rocket
00153        break;
00154     case 3:OutBox(164,29,237,60);
00155        gxVirtualDisplay(&but,141,0,165,30,236,59,0);// Manned
00156        break;
00157     case 4:OutBox(245,29,313,60);
00158        gxVirtualDisplay(&but,214,0,246,30,312,59,0);// Misc
00159        break;
00160   }
00161   switch(nw) {
00162     case 1:InBox(7,29,75,60);
00163        gxVirtualDisplay(&but,0,31,8,30,74,59,0);  // Unmanned
00164        break;
00165     case 2:InBox(83,29,156,60);
00166        gxVirtualDisplay(&but,68,31,84,30,155,59,0); // Rocket
00167        break;
00168     case 3:InBox(164,29,237,60);
00169        gxVirtualDisplay(&but,141,31,165,30,236,59,0);// Manned
00170        break;
00171     case 4:InBox(245,29,313,60);
00172        gxVirtualDisplay(&but,214,31,246,30,312,59,0);// Misc
00173        break;
00174   }
00175 
00176   
00177   return;
00178 }
00179 
00180 void RDButTxt(int v1,int val,char plr)
00181 {
00182   RectFill(166,185,314,193,3);
00183   grSetColor(1);
00184   if (val==0) {
00185     PrintAt(169,191,"RESEARCH PROGRAM FOR ");
00186     grSetColor(9);DispNum(0,0,v1);
00187     grSetColor(1);PrintAt(0,0," MB");
00188   } else {
00189     grSetColor(11);PrintAt(195,191,"R&D ");
00190     DispNum(0,0,val);
00191     PrintAt(0,0,"% IMPROVEMENT");
00192     if (Data->P[plr].RDMods>0) PrintAt(0,0,"+");
00193   }
00194   
00195   return;
00196 }
00197 
00198 
00199 char RD(char plr)
00200 {
00201   short hardware=1,roll=0,unit=1,buy[4][10],i,j,b;
00202 
00203   b = 0; /* XXX check uninitialized */
00204 
00205   for(i=0;i<4;i++) for(j=0;j<7;j++) buy[i][j]=Data->P[plr].Buy[i][j];
00206   hardware=HARD1; unit=UNIT1;
00207   strcpy(IDT,"i009");strcpy(IKEY,"k009");
00208 
00209   DrawRD(plr);
00210   BButs(1,hardware);
00211   ShowUnit(hardware,unit,plr);
00212   RDButTxt(b*roll,buy[hardware-1][unit-1],plr);
00213   if (buy[hardware-1][unit-1]==0) QUnit(hardware,unit,plr);
00214   else {InBox(165,184,315,194);};
00215   strcpy(IDT,"i009");strcpy(IKEY,"k009");
00216   FadeIn(2,pal,10,0,0);
00217   music_start(M_HARDWARE);
00218   WaitForMouseUp();
00219   while (1)
00220   {
00221     key=0;GetMouse();
00222     if (mousebuttons>0 || key>0)
00223      {
00224       if ((y>=29 && y<=60 && mousebuttons>0) || (key=='U' || key=='R' || key=='M' || key=='C'))
00225        {
00226         if (((x>=7 && x<=75 && mousebuttons>0) || key=='U') && hardware != 1)  /* Unmanned */
00227         {
00228          roll=0;
00229           BButs(hardware,1);
00230           hardware=1;unit=1;
00231           if (buy[hardware-1][unit-1]==0) QUnit(hardware,unit,plr);
00232            else {InBox(165,184,315,194);};
00233           ManSel(buy[hardware-1][unit-1]);ShowUnit(hardware,unit,plr);
00234           b=Data->P[plr].Probe[unit-1].RDCost;
00235           RDButTxt(b*roll,buy[hardware-1][unit-1],plr);
00236          }
00237       else
00238        if (((x>=83 && x<=156 && mousebuttons>0) || key=='R') && hardware != 2)  /* Rockets */
00239         {
00240         roll=0;
00241          BButs(hardware,2);
00242          hardware=2;unit=1;
00243          if (buy[hardware-1][unit-1]==0) QUnit(hardware,unit,plr);
00244           else {InBox(165,184,315,194);};
00245          ManSel(buy[hardware-1][unit-1]);ShowUnit(hardware,unit,plr);
00246          b=Data->P[plr].Rocket[unit-1].RDCost;
00247          RDButTxt(b*roll,buy[hardware-1][unit-1],plr);
00248         }
00249       else
00250        if (((x>=164 && x<=237 && mousebuttons>0) || key=='C') && hardware != 3)    /* Manned */
00251         {
00252         roll=0;
00253          BButs(hardware,3);
00254          hardware=3;unit=1;
00255          if (buy[hardware-1][unit-1]==0) QUnit(hardware,unit,plr);
00256           else {InBox(165,184,315,194);};
00257          ManSel(buy[hardware-1][unit-1]);ShowUnit(hardware,unit,plr);
00258          b=Data->P[plr].Manned[unit-1].RDCost;
00259          RDButTxt(b*roll,buy[hardware-1][unit-1],plr);
00260         }
00261       else
00262        if (((x>=245 && x<=313 && mousebuttons>0) || key=='M') && hardware !=4)     /* Misc */
00263          {
00264          roll=0;
00265           BButs(hardware,4);
00266           hardware=4;unit=1;
00267           if (buy[hardware-1][unit-1]==0) QUnit(hardware,unit,plr);
00268             else {InBox(165,184,315,194);};
00269           ManSel(buy[hardware-1][unit-1]);ShowUnit(hardware,unit,plr);
00270           b=Data->P[plr].Misc[unit-1].RDCost;
00271           RDButTxt(b*roll,buy[hardware-1][unit-1],plr);
00272          }
00273       }
00274       else
00275       if (((y>=157 && y<=175 && mousebuttons>0) || (key>='0'&& key<='5')) && buy[hardware-1][unit-1]==0)
00276       {         /*  R&D Amount */
00277        if (((x>=165 && x<=185 && mousebuttons>0) || key=='0') && roll!=0) roll=0;
00278        if (((x>=191 && x<=211 && mousebuttons>0) || key=='1') && roll!=1) roll=1;
00279        if (((x>=217 && x<=238 && mousebuttons>0) || key=='2') && roll!=2) roll=2;
00280        if (((x>=243 && x<=263 && mousebuttons>0) || key=='3') && roll!=3) roll=3;
00281        if (((x>=269 && x<=289 && mousebuttons>0) || key=='4') && roll!=4) roll=4;
00282        if (((x>=295 && x<=315 && mousebuttons>0) || key=='5') && roll!=5) roll=5;
00283        if (hardware==1) b=Data->P[plr].Probe[unit-1].RDCost;
00284        if (hardware==2) b=Data->P[plr].Rocket[unit-1].RDCost;
00285        if (hardware==3) b=Data->P[plr].Manned[unit-1].RDCost;
00286        if (hardware==4) b=Data->P[plr].Misc[unit-1].RDCost;
00287        RDButTxt(b*roll,buy[hardware-1][unit-1],plr);
00288        ManSel(roll);
00289        WaitForMouseUp();
00290       }
00291       else
00292       if ((x>=5 && y>=184 && x<=74 && y<=194 && mousebuttons>0) || key==LT_ARROW)  /* LEFT ARROW */
00293       {
00294         roll=0;
00295         InBox(5,184,74,194);
00296         WaitForMouseUp();
00297         switch(hardware)
00298          {
00299           case 1: unit= (unit-1 == 0) ? 3 : unit-1;break;
00300           case 2: unit= (unit-1 == 0) ? 5 : unit-1;break;
00301           case 3: unit= (unit-1 == 0) ? 7 : unit-1;break;
00302           case 4: unit= (unit-1 == 0) ? 4 : unit-1;if (plr==0 && unit==3) unit--;break;
00303          default:break;
00304          };
00305         RDButTxt(b*roll,buy[hardware-1][unit-1],plr);
00306         ManSel(buy[hardware-1][unit-1]);
00307         if (buy[hardware-1][unit-1]==0) QUnit(hardware,unit,plr);
00308           else {InBox(165,184,315,194);};
00309         ShowUnit(hardware,unit,plr);
00310         OutBox(5,184,74,194);
00311       }
00312       else
00313       if ((x>=83 && y>=184 && x<=152 && y<=194 && mousebuttons>0) || key==RT_ARROW) /* RIGHT ARROW */
00314       {
00315         roll=0;
00316         InBox(83,184,152,194);
00317         WaitForMouseUp();
00318         switch(hardware)
00319          {
00320           case 1: unit = (unit+1 > 3) ? 1 : unit+1;break;
00321           case 2: unit = (unit+1 > 5) ? 1 : unit+1;break;
00322           case 3: unit = (unit+1 > 7) ? 1 : unit+1;break;
00323           case 4: unit = (unit+1 > 4) ? 1 : unit+1;if (plr==0 && unit==3) unit++;break;
00324          default:break;
00325          };
00326         RDButTxt(b*roll,buy[hardware-1][unit-1],plr);
00327         ManSel(buy[hardware-1][unit-1]);
00328         if (buy[hardware-1][unit-1]==0) QUnit(hardware,unit,plr);
00329           else {InBox(165,184,315,194);};
00330         ShowUnit(hardware,unit,plr);
00331         RDButTxt(b*roll,buy[hardware-1][unit-1],plr);
00332         OutBox(83,184,152,194);
00333       }
00334       else
00335       if (((x>=165 && y>=184 && x<=315 && y<=194 && mousebuttons>0) || key=='S') && buy[hardware-1][unit-1]==0
00336          && roll !=0)
00337       {           // b is the cost per roll
00338     if (hardware==1)
00339      b=Data->P[plr].Probe[unit-1].RDCost;
00340     if (hardware==2)
00341      b=Data->P[plr].Rocket[unit-1].RDCost;
00342     if (hardware==3)
00343      b=Data->P[plr].Manned[unit-1].RDCost;
00344     if (hardware==4)
00345      b=Data->P[plr].Misc[unit-1].RDCost;
00346     // Add to the expenditure data
00347 
00348     if ( (b*roll <= Data->P[plr].Cash) && QUnit(hardware,unit,plr)
00349          && MaxChk(hardware,unit,plr))
00350     {
00351       buy[hardware-1][unit-1]=RDUnit(hardware,unit,roll,plr);
00352       if (buy[hardware-1][unit-1]==0) QUnit(hardware,unit,plr);
00353       else {InBox(165,184,315,194);};
00354       Data->P[plr].Cash-=b*roll;
00355       // add the amount to the expenditure budget
00356       switch(hardware) {
00357         case 1: Data->P[plr].Spend[0][0] += b*roll;break;
00358         case 2: Data->P[plr].Spend[0][1] += b*roll;break;
00359         case 3: Data->P[plr].Spend[0][2] += b*roll;break;
00360         case 4: Data->P[plr].Spend[0][3] += b*roll;break;
00361       }
00362       ShowUnit(hardware,unit,plr);
00363       RDButTxt(b*roll,buy[hardware-1][unit-1],plr);
00364     }
00365     else QUnit(hardware,unit,plr);
00366       }
00367      else
00368       if (((y>=3 && y<=19) && (x>=243 && x<=316 && mousebuttons>0)) || key==K_ENTER)
00369       {
00370         InBox(245,5,314,17);
00371      WaitForMouseUp();
00372         for(i=0;i<4;i++) for(j=0;j<7;j++) Data->P[plr].Buy[i][j]=buy[i][j];
00373        music_stop();
00374         Del_RD_BUT();
00375         call=0;
00376         HARD1=1;UNIT1=1;
00377         return 0;
00378       }
00379       else
00380       if ((x>=5 && y>=73 && x<=152 && y<=83 && mousebuttons>0) || key=='V')
00381       {
00382         InBox(5,73,152,83);
00383         HARD1=hardware;UNIT1=unit;
00384         for(i=0;i<4;i++) for(j=0;j<7;j++)
00385          Data->P[plr].Buy[i][j]=buy[i][j];
00386        music_stop();
00387       if (hardware==4 && unit==5) {hardware=unit=HARD1=UNIT1=1;}
00388         if (call==1) return 1;        // go back through gateway
00389         call=1;
00390         wh=HPurc(plr);
00391         if (call==0) return 0;
00392         hardware=HARD1;unit=UNIT1;
00393         call=0; 
00394         for(i=0;i<4;i++) for(j=0;j<10;j++) buy[i][j]=Data->P[plr].Buy[i][j];
00395         DrawRD(plr);
00396       if (hardware==4 && unit==5) {hardware=unit=HARD1=UNIT1=1;}
00397         BButs(1,hardware);
00398         ShowUnit(hardware,unit,plr);
00399         RDButTxt(0,buy[hardware-1][unit-1],plr);
00400        if (buy[hardware-1][unit-1]==0) QUnit(hardware,unit,plr);
00401        else {InBox(165,184,315,194);};
00402 
00403         FadeIn(2,pal,10,0,0);
00404             music_start(M_HARDWARE);
00405         WaitForMouseUp();
00406       };
00407     };
00408     gr_maybe_sync();
00409   };
00410 }
00411 
00412 void ManSel(int mm)
00413 {
00414     int dx = 26;
00415     int i;
00416 
00417     for (i = 0; i < 6; ++i)
00418     {
00419         if (i == mm)
00420             InBox(165+i*dx, 157, 185+i*dx, 175);
00421         else
00422             OutBox(165+i*dx, 157, 185+i*dx, 175);
00423     }
00424 
00425     av_need_update_xy(165, 157, 165+i*dx, 175);
00426 }
00427 
00428 char QUnit(char hwx,char unx,char plr)
00429 {
00430   int b=0;
00431   if (hwx==1) b=(Data->P[plr].Probe[unx-1].Num==-1) ? 0:1;
00432   if (hwx==2) b=(Data->P[plr].Rocket[unx-1].Num==-1) ? 0:1;
00433   if (hwx==3) b=(Data->P[plr].Manned[unx-1].Num==-1) ? 0:1;
00434   if (hwx==4) b=(Data->P[plr].Misc[unx-1].Num==-1) ? 0:1;
00435   
00436   if (b==0) InBox(165,184,315,194);
00437   else OutBox(165,184,315,194);
00438   
00439   return(b);
00440 }
00441 
00442 
00443 char MaxChk(char hwx,char unx,char plr)
00444 {
00445   if (hwx==1) return(Data->P[plr].Probe[unx-1].Safety < Data->P[plr].Probe[unx-1].MaxRD);
00446   if (hwx==2) return(Data->P[plr].Rocket[unx-1].Safety < Data->P[plr].Rocket[unx-1].MaxRD);
00447   if (hwx==3) return(Data->P[plr].Manned[unx-1].Safety < Data->P[plr].Manned[unx-1].MaxRD);
00448   if (hwx==4) return(Data->P[plr].Misc[unx-1].Safety < Data->P[plr].Misc[unx-1].MaxRD);
00449   return(0);
00450 }
00451 
00452 char RDUnit(char rhard,char runit,char r,char plr)
00453 {
00454   int dice,i;
00455   dice=0;
00456   for (i=0;i<r;i++) dice+=rand()%(6+Data->P[plr].RDMods)+1;
00457   if (rhard==1) {
00458     Data->P[plr].Probe[runit-1].Safety+=dice;
00459     if (Data->P[plr].Probe[runit-1].Safety > Data->P[plr].Probe[runit-1].MaxRD)
00460     Data->P[plr].Probe[runit-1].Safety=Data->P[plr].Probe[runit-1].MaxRD;
00461   }; // End if
00462   if (rhard==2) {
00463     Data->P[plr].Rocket[runit-1].Safety+=dice;
00464     if (Data->P[plr].Rocket[runit-1].Safety > Data->P[plr].Rocket[runit-1].MaxRD)
00465     Data->P[plr].Rocket[runit-1].Safety=Data->P[plr].Rocket[runit-1].MaxRD;
00466   }; // End if
00467   if (rhard==3) {
00468     Data->P[plr].Manned[runit-1].Safety+=dice;
00469     if (Data->P[plr].Manned[runit-1].Safety > Data->P[plr].Manned[runit-1].MaxRD)
00470     Data->P[plr].Manned[runit-1].Safety=Data->P[plr].Manned[runit-1].MaxRD;
00471   }; // End if
00472   if (rhard==4) {
00473     Data->P[plr].Misc[runit-1].Safety+=dice;
00474     if (Data->P[plr].Misc[runit-1].Safety > Data->P[plr].Misc[runit-1].MaxRD)
00475     Data->P[plr].Misc[runit-1].Safety=Data->P[plr].Misc[runit-1].MaxRD;
00476   }; // End if
00477 
00478   return dice;
00479 }
00480 
00481 void ShowUnit(char hw,char un,char plr)
00482 {
00483   Equipment *PL;
00484   char qty=1,SCol=0;
00485   int Unit_Cost,Init_Cost;
00486 
00487   PL = NULL; /* XXX check uninitialized */
00488 
00489   switch(hw) {
00490    case 1: PL=(Equipment *)&Data->P[plr].Probe[un-1].Name[0];break;
00491    case 2: PL=(Equipment *)&Data->P[plr].Rocket[un-1].Name[0];break;
00492    case 3: PL=(Equipment *)&Data->P[plr].Manned[un-1].Name[0];break;
00493    case 4: PL=(Equipment *)&Data->P[plr].Misc[un-1].Name[0];break;
00494    }
00495   
00496   grSetColor(1);
00497   
00498   RectFill(162,69,318,154,3);RectFill(200,9,238,21,3);
00499   grSetColor(1);
00500   PrintAt(170,97,"INITIAL COST:");
00501   PrintAt(170,104,"UNIT COST:");
00502   PrintAt(170,118,"R&D COST PER TEAM:");
00503   PrintAt(170,125,"UNIT WEIGHT:");
00504   PrintAt(170,132,"MAXIMUM PAYLOAD:");
00505   PrintAt(170,146,"MAXIMUM SAFETY:");
00506   grSetColor(20);PrintAt(170,139,"MAXIMUM R&D:");
00507 
00508   SCol=(PL->Num<0) ? 20 : ((PL->Safety<75) ? 8 : 16);
00509   grSetColor(SCol);PrintAt(170,111,"SAFETY FACTOR:");
00510 
00511   grSetColor(11);
00512   DispMB(201,15,Data->P[plr].Cash);
00513 
00514   grSetColor(11);
00515   if (!(plr==1 && hw==2 && un==5)) PrintAt(170,80,&PL->Name[0]);
00516   switch (hw) {
00517    case 1: switch(un-1){
00518      case 0: case 1: PrintAt(0,0," SATELLITE");break;
00519      case 2: PrintAt(0,0," PROBE");break;
00520      default: break;
00521      };break;
00522    case 2: switch(un-1) {
00523      case 0: case 1: case 2: case 3:PrintAt(0,0," ROCKET");break;
00524      case 4:
00525        if (plr==0) PrintAt(0,0," STRAP-ON");
00526        else PrintAt(170,80,"BOOSTER STAGE");
00527        break;
00528      default: break;
00529      };break;
00530    case 3: switch(un-1) {
00531      case 0: case 1: case 2: PrintAt(0,0," CAPSULE");break;
00532      case 3: PrintAt(0,0," MINISHUTTLE");break;
00533      case 4: PrintAt(0,0," SPACECRAFT");break;
00534      case 5: case 6: PrintAt(0,0," MODULE");break;
00535      default: break;
00536     };break;
00537    case 4:
00538       if ((un-1)<3) PrintAt(0,0," BOOSTER");
00539       if ((un-1)==4) PrintAt(0,0," MODULE");
00540       break;
00541    }
00542    Init_Cost=PL->InitCost;
00543    Unit_Cost=PL->UnitCost;
00544    if (Data->P[plr].TurnOnly==3)
00545     {
00546      Init_Cost/=2;Init_Cost=maxx(1,Init_Cost);
00547      if (Unit_Cost>1) Unit_Cost/=2;
00548     };
00549     DispNum(241,97,Init_Cost);
00550     DispNum(230,104,Unit_Cost);
00551     DispNum(275,118,PL->RDCost);
00552 
00553     if (hw!=2) DispNum(240,125,PL->UnitWeight);
00554     else PrintAt(240,125,"N/A");
00555 
00556     grSetColor(20);DispNum(242,139,PL->MaxRD);DispChr('%');
00557     grSetColor(11);DispNum(254,146,PL->MaxSafety);DispChr('%');
00558 
00559     if (hw!=2) PrintAt(268,132,"N/A"); /* Payload */
00560     else DispNum(268,132,PL->MaxPay);
00561 
00562     if (PL->Num==-1) {
00563       grSetColor(8);
00564       PrintAt(170,90,"NO PROGRAM INITIATED");
00565       grSetColor(20);
00566       DispNum(256,111,0);DispChr('%');
00567     }
00568     else {
00569       OnHand(PL->Num);
00570       grSetColor(SCol);
00571       DispNum(256,111,PL->Safety);DispChr('%');
00572       qty=0;
00573     };
00574   RectFill(27,95,130,171,0);
00575   BigHardMe(plr,27,95,hw-1,un-1,qty,32);
00576   
00577   return;
00578 }
00579 
00580 void OnHand(char qty)
00581 {
00582   if (qty>0) grSetColor(16);
00583   else grSetColor(9);
00584   PrintAt(170,90,"UNITS ON HAND:");
00585   DispNum(251,90,qty);
00586   return;
00587 }
00588 
00589 void DrawHPurc(char plr)
00590 {
00591   FILE *fin;
00592   
00593   FadeOut(2,pal,10,0,0);
00594   fin=sOpen("VAB.IMG","rb",0);
00595   fread(&pal[0],768,1,fin);
00596   fclose(fin);
00597 
00598   Load_RD_BUT(plr);
00599   gxClearDisplay(0,0);
00600   ShBox(0,0,319,22);  ShBox(0,24,319,65);
00601   ShBox(17,68,143,199);
00602   ShBox(21,71,139,87); ShBox(161,68,319,199);
00603 
00604   ShBox(0,68,158,199); IOBox(3,71,154,85);
00605   IOBox(3,182,76,196);IOBox(81,182,154,196);
00606 
00607   IOBox(5,27,77,62);IOBox(81,27,158,62);
00608   IOBox(162,27,239,62);IOBox(243,27,315,62);
00609   IOBox(163,180,317,197);
00610   IOBox(243,3,316,19);
00611   InBox(3,3,30,19);
00612   FlagSm(plr,4,4);
00613 
00614   IOBox(264,162,316,176);
00615   grSetColor(11);PrintAt(280,171,"UNDO");
00616 
00617   OutBox(21,90,136,176);InBox(26,94,131,172);
00618 
00619   grSetColor(1);
00620   DispBig(35,5,"PURCHASING",0,-1);
00621   //GradRect(27,95,130,171,plr*16+128);
00622   RectFill(27,95,130,171,0);
00623 
00624   LTArrow(24,186);RTArrow(101,186);
00625   grSetColor(1);
00626   PrintAt(34,80,"VISIT R&D FACILITY");
00627 
00628   gxVirtualDisplay(&but,0,0,8,30,74,59,0);  // Unmanned
00629   gxVirtualDisplay(&but,68,0,84,30,155,59,0); // Rocket
00630   gxVirtualDisplay(&but,141,0,165,30,236,59,0);// Manned
00631   gxVirtualDisplay(&but,214,0,246,30,312,59,0);// Misc
00632 
00633   grSetColor(11);
00634   PrintAt(195,190,"PURCHASE EQUIPMENT");
00635   PrintAt(200,8,"CASH:");
00636   DispMB(201,15,Data->P[plr].Cash);
00637 
00638   grSetColor(1);PrintAt(258,13,"CONTINUE");
00639   ShowUnit(1,1,plr);
00640   strcpy(IDT,"i008");strcpy(IKEY,"k008");
00641   
00642   return;
00643 }
00644 
00645 char HPurc(char plr)
00646 {
00647   short hardware,unit;
00648   FILE *undo;
00649 
00650   remove_savedat("UNDO.TMP");
00651   undo=sOpen("UNDO.TMP","wb",1);
00652   fwrite(Data,sizeof (struct Players),1,undo);
00653   fclose(undo);
00654 
00655   hardware=HARD1; unit=UNIT1;
00656   strcpy(IDT,"i008");strcpy(IKEY,"k008");
00657   DrawHPurc(plr);
00658   BButs(1,hardware);
00659   ShowUnit(hardware,unit,plr);
00660 
00661   //Specs: undo fix 
00662   //memset(vhptr.vptr,0x00,64000);
00663   //memcpy(vhptr.vptr,Data,sizeof(struct Players));
00664 
00665   FadeIn(2,pal,10,0,0);
00666   music_start(M_FILLER);
00667   WaitForMouseUp();
00668   while (1)
00669   {
00670     key=0;GetMouse();
00671     if ((x>266 && y>164 && x<314 && y<174 && mousebuttons>0) || key=='Z') {
00672       InBox(266,164,314,174);
00673             WaitForMouseUp();
00674   //    memcpy(Data,vhptr.vptr,sizeof(struct Players));
00675       undo=sOpen("UNDO.TMP","rb",1);
00676       fread(Data,sizeof (struct Players),1,undo);
00677       fclose(undo);
00678       ShowUnit(hardware,unit,plr);
00679       OutBox(266,164,314,174);
00680       key=0;
00681     }
00682      if ((y>=29 && y<=60 && mousebuttons>0) || (key=='U' || key=='R' || key=='M' || key=='C'))
00683       {
00684         if (((x>=7 && x<=75 && mousebuttons>0) || key=='U') && hardware != 1)   /* PROBES */
00685          {
00686           BButs(hardware,1);
00687           hardware=1;unit=1;
00688           ShowUnit(hardware,unit,plr);
00689          }
00690       else
00691        if (((x>=83 && x<=156 && mousebuttons>0) || key=='R') && hardware != 2)   /* ROCKETS  */
00692         {
00693          BButs(hardware,2);
00694          hardware=2;unit=1;
00695          ShowUnit(hardware,unit,plr);
00696         }
00697       else
00698        if (((x>=164 && x<=237 && mousebuttons>0) || key=='C') && hardware != 3) /* MODULES-CAPSULES */
00699         {
00700          BButs(hardware,3);
00701          hardware=3;unit=1;
00702          ShowUnit(hardware,unit,plr);
00703         }
00704       else
00705        if (((x>=245 && x<=313 && mousebuttons>0) || key=='M') && hardware !=4)   /* MISC */
00706         {
00707          BButs(hardware,4);
00708          hardware=4;unit=1;
00709          ShowUnit(hardware,unit,plr);
00710         }
00711      }
00712      else 
00713      if ((x>=5 && y>=184 && x<=74 && y<=194 && mousebuttons>0) || key==LT_ARROW) /* LEFT ARROW */
00714       {
00715         InBox(5,184,74,194);
00716         delay(5);
00717         WaitForMouseUp();
00718         OutBox(5,184,74,194);
00719         switch(hardware) {
00720          case 1: unit= (unit-1 == 0) ? 3 : unit-1;break;
00721          case 2: unit= (unit-1 == 0) ? 5 : unit-1;break;
00722          case 3: unit= (unit-1 == 0) ? 7 : unit-1;break;
00723          case 4: unit= (unit-1 == 0) ? 5 : unit-1;if (plr==0 && unit==3) unit--;break;
00724         default:break;
00725         };
00726         ShowUnit(hardware,unit,plr);
00727       }
00728       else
00729       if ((x>=83 && y>=184 && x<=152 && y<=194 && mousebuttons>0) || key==RT_ARROW) /* RIGHT ARROW */
00730       {
00731      InBox(83,184,152,194);
00732         WaitForMouseUp();
00733      OutBox(83,184,152,194);
00734          switch(hardware) {
00735            case 1: unit = (unit+1 > 3 ) ? 1 : unit+1;break;
00736           case 2: unit = (unit+1 > 5 ) ? 1 : unit+1;break;
00737            case 3: unit = (unit+1 > 7 ) ? 1 : unit+1;break;
00738           case 4: unit = (unit+1 > 5 ) ? 1 : unit+1;if (plr==0 && unit==3) unit++;break;
00739          default:break;
00740      };
00741         ShowUnit(hardware,unit,plr);
00742       }
00743       else
00744       if ((y>=182 && y<=195 && x>=166 && x<=314 && mousebuttons>0) || key=='P')  /* PURCHASE */
00745        {
00746            InBox(165,182,315,195);
00747        WaitForMouseUp();
00748        OutBox(165,182,315,195);
00749         // NEED DELAY CHECK
00750         switch(hardware)
00751          {
00752           case 1:if (Data->P[plr].Probe[unit-1].Delay==0) BuyUnit(hardware,unit,plr);
00753                   else Help("i135");
00754                 break;
00755           case 2:if (Data->P[plr].Rocket[unit-1].Delay==0) BuyUnit(hardware,unit,plr);
00756                   else Help("i135");
00757                 break;
00758           case 3:if (Data->P[plr].Manned[unit-1].Delay==0) BuyUnit(hardware,unit,plr);
00759                   else Help("i135");
00760                 break;
00761           case 4:if (Data->P[plr].Misc[unit-1].Delay==0) BuyUnit(hardware,unit,plr);
00762                   else Help("i135");
00763                 break;
00764          default:break;
00765         }
00766       }
00767       else
00768       if (((y>=3 && y<=19) && (x>=243 && x<=316 && mousebuttons>0)) || key==K_ENTER)
00769        {
00770           InBox(245,5,314,17);
00771                 WaitForMouseUp();
00772         music_stop();
00773         Del_RD_BUT(); call=0;
00774         HARD1=1;UNIT1=1;
00775         remove_savedat("UNDO.TMP");
00776       return 0;   // Continue
00777        }
00778       else
00779       if ((x>=5 && y>=73 && x<=152 && y<=83 && mousebuttons>0) || key=='V')         // Gateway to RD
00780        {
00781          InBox(5,73,152,83);
00782              WaitForMouseUp();
00783          HARD1=hardware; UNIT1=unit;
00784        music_stop();
00785        remove_savedat("UNDO.TMP");
00786       if (hardware==4 && unit==5) {hardware=unit=HARD1=UNIT1=1;}
00787          if (call==1) return 1;
00788      call=1;
00789      wh=RD(plr);
00790      if (call==0) return 0;   // Exit
00791      call=0;
00792      hardware=HARD1; unit=UNIT1;
00793        if (hardware==4 && unit==5) {hardware=unit=HARD1=UNIT1=1;}
00794      DrawHPurc(plr);
00795    //    memcpy(vhptr.vptr,Data,sizeof(struct Players));
00796      ShowUnit(hardware,unit,plr);
00797      BButs(1,hardware);
00798 
00799      // Just Added stuff by mike
00800      undo=sOpen("UNDO.TMP","wb",1);
00801      fwrite(Data,sizeof (struct Players),1,undo);
00802      fclose(undo);
00803 
00804      FadeIn(2,pal,10,0,0);
00805        music_start(M_FILLER);
00806      WaitForMouseUp();
00807       };
00808   };
00809 }
00810 
00811 void BuyUnit(char hw2,char un2,char plr)
00812 {
00813   short n1,n2,n3,n4,n5,n6,n7;
00814   char newf=0;
00815   int Init_Cost,Unit_Cost;
00816 
00817   Unit_Cost = Init_Cost = 0; /* XXX check uninitialized */
00818 
00819   switch(hw2)
00820   {
00821    case 1:Init_Cost=Data->P[plr].Probe[un2-1].InitCost;
00822           Unit_Cost=Data->P[plr].Probe[un2-1].UnitCost;
00823           break;
00824    case 2:Init_Cost=Data->P[plr].Rocket[un2-1].InitCost;
00825           Unit_Cost=Data->P[plr].Rocket[un2-1].UnitCost;
00826           break;
00827    case 3:Init_Cost=Data->P[plr].Manned[un2-1].InitCost;
00828           Unit_Cost=Data->P[plr].Manned[un2-1].UnitCost;
00829           break;
00830    case 4:Init_Cost=Data->P[plr].Misc[un2-1].InitCost;
00831           Unit_Cost=Data->P[plr].Misc[un2-1].UnitCost;
00832           break;
00833    default:break;
00834   }
00835   if (Data->P[plr].TurnOnly==3)
00836    {
00837     Init_Cost/=2;Init_Cost=maxx(1,Init_Cost);
00838     Unit_Cost/=2;Unit_Cost=maxx(1,Unit_Cost);
00839    }           
00840   if (hw2==1) {
00841     if (Data->P[plr].Probe[un2-1].Num==-1 &&
00842     Data->P[plr].Cash>=Init_Cost) {
00843       Data->P[plr].Cash-=Init_Cost;
00844       Data->P[plr].Probe[un2-1].Num=1;
00845         newf=1;
00846         Data->P[plr].Spend[0][hw2-1] += Init_Cost;
00847     }
00848     else if (Data->P[plr].Probe[un2-1].Num>=0 &&
00849          Data->P[plr].Probe[un2-1].Num<6 &&
00850          Data->P[plr].Cash>=Unit_Cost) {
00851       Data->P[plr].Cash-=Unit_Cost;
00852         Data->P[plr].Probe[un2-1].Num+=1;
00853         Data->P[plr].Spend[0][hw2-1] += Unit_Cost;
00854     };
00855   }
00856   if (hw2==2) {
00857     if (Data->P[plr].Rocket[un2-1].Num==-1 &&
00858     Data->P[plr].Cash>=Init_Cost) {
00859       Data->P[plr].Cash-=Init_Cost;
00860       Data->P[plr].Rocket[un2-1].Num=1;
00861         newf=1;
00862         Data->P[plr].Spend[0][hw2-1] += Init_Cost;
00863      }
00864      else if (Data->P[plr].Rocket[un2-1].Num>=0 &&
00865           Data->P[plr].Rocket[un2-1].Num<6 &&
00866           Data->P[plr].Cash>=Unit_Cost) {
00867         Data->P[plr].Cash-=Unit_Cost;
00868         Data->P[plr].Rocket[un2-1].Num+=1;
00869         Data->P[plr].Spend[0][hw2-1] += Unit_Cost;
00870      };
00871   }
00872   if (hw2==3) {
00873      if (Data->P[plr].Manned[un2-1].Num==-1 &&
00874     Data->P[plr].Cash>=Init_Cost) {
00875         Data->P[plr].Cash-=Init_Cost;
00876         Data->P[plr].Manned[un2-1].Num=1;
00877         newf=1;
00878         Data->P[plr].Spend[0][hw2-1] += Init_Cost;
00879      }
00880      else if (Data->P[plr].Manned[un2-1].Num>=0 &&
00881           Data->P[plr].Manned[un2-1].Num<6 &&
00882           Data->P[plr].Cash>=Unit_Cost) {
00883         Data->P[plr].Cash-=Unit_Cost;
00884         Data->P[plr].Manned[un2-1].Num+=1;
00885         Data->P[plr].Spend[0][hw2-1] += Unit_Cost;
00886      };
00887   }
00888   if (hw2==4) {
00889      if (Data->P[plr].Misc[un2-1].Num==-1 &&
00890     Data->P[plr].Cash>=Init_Cost) {
00891         Data->P[plr].Cash-=Init_Cost;
00892         Data->P[plr].Misc[un2-1].Num=1;
00893         newf=1;
00894         Data->P[plr].Spend[0][hw2-1] += Init_Cost;
00895      }
00896      else if (Data->P[plr].Misc[un2-1].Num>=0 &&
00897           Data->P[plr].Misc[un2-1].Num<6 &&
00898           Data->P[plr].Cash>=Unit_Cost) {
00899         Data->P[plr].Cash-=Unit_Cost;
00900         Data->P[plr].Misc[un2-1].Num+=1;
00901         Data->P[plr].Spend[0][hw2-1] += Unit_Cost;
00902     };
00903   }
00904 /* Figure out any starting bonus for existing programs */
00905   if (hw2==1 && newf==1) {
00906     n1=Data->P[plr].Probe[0].Safety;
00907     n2=Data->P[plr].Probe[1].Safety;
00908     n3=Data->P[plr].Probe[2].Safety;
00909     switch(un2-1) {
00910       case 0: if (n2>=75) Data->P[plr].Probe[0].Safety=50;
00911           if (n3>=75) Data->P[plr].Probe[0].Safety=60;
00912           break;
00913       case 1: if (n1>=75) Data->P[plr].Probe[1].Safety=45;
00914           if (n3>=75) Data->P[plr].Probe[1].Safety=50;
00915           break;
00916       case 2: if (n1>=75) Data->P[plr].Probe[2].Safety=45;
00917           if (n2>=75) Data->P[plr].Probe[2].Safety=50;
00918           break;
00919     };
00920     Data->P[plr].Probe[un2-1].Base=Data->P[plr].Probe[un2-1].Safety;
00921   };
00922   if (hw2==2 && newf==1) {
00923     n1=Data->P[plr].Rocket[0].Safety; /* One - A     */
00924     n2=Data->P[plr].Rocket[1].Safety; /* Two - B     */
00925     n3=Data->P[plr].Rocket[2].Safety; /* Three - C   */
00926     n4=Data->P[plr].Rocket[3].Safety; /* Mega - G    */
00927     n5=Data->P[plr].Rocket[4].Safety; /* Booster - D */
00928     switch(un2-1) {
00929       case 0: if (n2>=75 || n3>=75 || n4>=75 || n5>=75)
00930         Data->P[plr].Rocket[0].Safety=35;
00931           break;
00932       case 1: if (n1>=75 || n5>=75) Data->P[plr].Rocket[1].Safety=25;
00933           if (n3>=75 || n4>=75) Data->P[plr].Rocket[1].Safety=40;
00934           if ((n1>=75 || n5>=75) && (n3>=75 || n4>=75))
00935         Data->P[plr].Rocket[1].Safety=65;
00936           break;
00937       case 2: if (n1>=75 || n5>=75) Data->P[plr].Rocket[2].Safety=15;
00938           if (n2>=75 || n4>=75) Data->P[plr].Rocket[2].Safety=35;
00939           if ((n1>=75 || n5>=75) && (n2>=75 || n4>=75))
00940         Data->P[plr].Rocket[2].Safety=60;
00941           break;
00942       case 3: if (n1>=75 || n5>=75) Data->P[plr].Rocket[3].Safety=10;
00943           if (n2>=75 || n3>=75) Data->P[plr].Rocket[3].Safety=25;
00944           if ((n1>=75 || n5>=75) && (n2>=75 || n3>=75))
00945         Data->P[plr].Rocket[3].Safety=35;
00946           break;
00947       case 4: if (n1>=75 || n2>=75 || n3>=75 || n4>=75)
00948         Data->P[plr].Rocket[4].Safety=30;
00949           break;
00950     };
00951     Data->P[plr].Rocket[un2-1].Base=Data->P[plr].Rocket[un2-1].Safety;
00952   };
00953   if (hw2==3 && newf==1) {
00954     n1=Data->P[plr].Manned[0].Safety; /* One - a         */
00955     n2=Data->P[plr].Manned[1].Safety; /* Two - b         */
00956     n3=Data->P[plr].Manned[2].Safety; /* Three - c       */
00957     n4=Data->P[plr].Manned[3].Safety; /* Minishuttle - f */
00958     n5=Data->P[plr].Manned[4].Safety; /* cap/mod - h     */
00959     n6=Data->P[plr].Manned[5].Safety; /* 2 mod - d       */
00960     n7=Data->P[plr].Manned[6].Safety; /* 1 mod - e       */
00961     switch(un2-1) {
00962       case 0: if (n2>=75 || n3>=75 || n5>=75)
00963         Data->P[plr].Manned[0].Safety=40;
00964           break;
00965       case 1: if (n1>=75) Data->P[plr].Manned[1].Safety=20;
00966           if (n3>=75 || n5>=75) Data->P[plr].Manned[1].Safety=40;
00967           break;
00968       case 2: if (n1>=75 || n5>=75) Data->P[plr].Manned[2].Safety=20;
00969           if (n2>=75 || n4>=75) Data->P[plr].Manned[2].Safety=30;
00970           if ((n1>=75 || n5>=75) && (n2>=75 || n4>=75))
00971         Data->P[plr].Manned[2].Safety=40;
00972           break;
00973       case 3: break;
00974       case 4: if (n1>=75) Data->P[plr].Manned[4].Safety=10;
00975           if (n2>=75) Data->P[plr].Manned[4].Safety=15;
00976           if (n3>=75) Data->P[plr].Manned[4].Safety=25;
00977           if ((n1>=75 || n2>=75 || n3>=75) && (n6>=75 || n7>=75))
00978          Data->P[plr].Manned[4].Safety=35;
00979           break;
00980       case 5: if (n7>=75) Data->P[plr].Manned[5].Safety=30;
00981           if (n5>=75) Data->P[plr].Manned[5].Safety=40;
00982           break;
00983       case 6: if (n6>=75) Data->P[plr].Manned[6].Safety=30;
00984           if (n5>=75) Data->P[plr].Manned[6].Safety=40;
00985           break;
00986     };
00987     Data->P[plr].Manned[un2-1].Base=Data->P[plr].Manned[un2-1].Safety;
00988 
00989   };
00990 
00991   if (hw2==4 && newf==1) {
00992     n1=Data->P[plr].Rocket[0].Safety; /* One - A     */
00993     n2=Data->P[plr].Rocket[1].Safety; /* Two - B     */
00994     n3=Data->P[plr].Rocket[2].Safety; /* Three - C   */
00995     n4=Data->P[plr].Rocket[3].Safety; /* Mega - G    */
00996     n5=Data->P[plr].Rocket[4].Safety; /* Booster - D */
00997     switch(un2-1) {
00998       case 0: if (n2>=75)
00999         Data->P[plr].Misc[0].Safety=40;
01000           break;
01001       case 1: if (n1>=75) Data->P[plr].Misc[1].Safety=35;
01002           break;
01003       case 2: if (n1>=75 || n2>=75) Data->P[plr].Misc[2].Safety=25;
01004           break;
01005       default: break;
01006     };
01007     Data->P[plr].Misc[un2-1].Base=Data->P[plr].Misc[un2-1].Safety;
01008 
01009   };
01010 
01011    ShowUnit(hw2,un2,plr);
01012    return;
01013 }

Generated on Fri Sep 28 00:35:27 2007 for raceintospace by  doxygen 1.5.3