aipur.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 aipur.c AI Purchasing Routines
00026  */
00027 
00028 #include "Buzz_inc.h"
00029 #include "externs.h"
00030 
00031 struct ManPool *Men;
00032 char AIsel[25],AIMaxSel,Obs[6]; //indexed 1 thru 5
00033 extern char AI[2],Option;
00034 
00035 void DrawStatistics(char Win)
00036 {
00037  GXHEADER local;
00038  char AImg[7]={8,9,10,11,13,14,0};
00039  char Digit[2];
00040  int starty,qty,i;
00041  FILE *fin;
00042  strncpy(IDT,"i145",4);strncpy(IKEY,"k045",4);
00043  FadeOut(2,pal,10,0,0);
00044  PortPal(0);
00045  
00046  gxClearDisplay(0,0);
00047  ShBox(35,33,288,159);
00048  InBox(40,69,111,109);InBox(116,69,283,109);
00049  InBox(40,114,111,154);InBox(116,114,283,154);
00050  IOBox(191,40,280,62);
00051  Flag(41,70,Win);
00052  Flag(41,115,other(Win));
00053  DispBig(48,44,"STATISTICS",1,-1);
00054  DispBig(215,45,"EXIT",1,-1);
00055  grSetColor(6);
00056  PrintAt(122,78,"WINNING DIRECTOR: ");
00057  grSetColor(8);
00058  if (AI[Win])
00059   {
00060    PrintAt(0,0,"COMPUTER");
00061    sprintf(&Digit[0],"%d",Data->P[Win].Track[3]);
00062    PrintAt(0,0,&Digit[0]);
00063   }     
00064   else if (Win==0) PrintAt(0,0,&Data->P[Data->Def.Plr1].Name[0]);
00065    else PrintAt(0,0,&Data->P[ Data->Def.Plr2 ].Name[0]);
00066  grSetColor(6);
00067  PrintAt(122,125,"LOSING DIRECTOR: ");
00068  grSetColor(8);
00069  if (AI[other(Win)])
00070   {
00071    PrintAt(0,0,"COMPUTER");
00072    sprintf(&Digit[0],"%d",Data->P[other(Win)].Track[3]);
00073    PrintAt(0,0,&Digit[0]);
00074   }
00075   else if (Win==0) PrintAt(0,0,&Data->P[Data->Def.Plr2].Name[0]);
00076    else PrintAt(0,0,&Data->P[ Data->Def.Plr1 ].Name[0]);
00077  qty=6;starty=118;
00078  GV(&local,30,19);
00079  fin=sOpen("PORTBUT.BUT","rb",0);
00080  OutBox(152,41,183,61); //directors ranking
00081  for (i=0;i<qty;i++)
00082   {
00083    if (i<=4 && AI[Win]==0) OutBox(starty+(i*33),87,31+starty+(i*33),107);
00084    if (i<=4 && AI[other(Win)]==0) OutBox(starty+(i*33),132,31+starty+(i*33),152);
00085    fseek(fin,AImg[i]*570,SEEK_SET);
00086    fread((char *)local.vptr,570,1,fin);
00087    if (i==0) gxPutImage(&local,gxSET,153,42,0);
00088     else
00089      {
00090       if (AI[Win]==0) gxPutImage(&local,gxSET,starty+((i-1)*33)+1,88,0);
00091       if (AI[other(Win)]==0) gxPutImage(&local,gxSET,starty+((i-1)*33)+1,133,0);
00092      }
00093   }
00094  fclose(fin);
00095  DV(&local);
00096  FadeIn(2,pal,10,0,0);
00097  
00098  return;
00099 }
00100 
00101 void Stat(char Win)
00102 {
00103  int j,i,starty;
00104  DrawStatistics(Win);
00105  WaitForMouseUp();
00106  i=0;key=0;starty=118;
00107   while (i==0)
00108   {
00109     key=0;GetMouse();
00110     if ((x>=193 && y>=42 && x<=278 && y<=60 && mousebuttons>0) || key==K_ENTER)
00111       {
00112        InBox(193,42,278,60);
00113        WaitForMouseUp();
00114       if (key>0) delay(150);
00115        i=1;key=0;
00116        OutBox(193,42,278,60);
00117       }
00118    else
00119    if ((x>=152 && y>=41 && x<=183 && y<=61 && mousebuttons>0) || key=='D')
00120       {
00121        InBox(152,41,183,61);
00122        WaitForMouseUp();
00123       if (key>0) delay(150);
00124       RankMe(Win);DrawStatistics(Win);
00125        key=0;i=0;
00126        OutBox(152,41,183,61);
00127       };
00128    for (j=0;j<5;j++)
00129    {
00130     if (AI[Win]==0)
00131      {
00132        if ((x>=starty+(j*33) && y>=87 && x<=31+starty+(j*33) && y<=107 && mousebuttons>0) || ((key>='1' && key<='4') || key=='0'))
00133        {
00134         if (key>0)
00135          {
00136           switch(key)
00137            {
00138             case '0':j=0;break;
00139             case '1':j=1;break;
00140             case '2':j=2;break;
00141             case '3':j=3;break;
00142             case '4':j=4;break;
00143             default:break;
00144            }
00145          }
00146         InBox(starty+(j*33),87,31+starty+(j*33),107);
00147          WaitForMouseUp();
00148         key=0;strncpy(IKEY,"k999",4);
00149         switch(j)
00150          {
00151             case 0: strncpy(IDT,"i130",4);strncpy(IKEY,"k031",4);
00152                   if (Option==-1 || (Option==Win)) ShowSpHist(Win);
00153                   //ShowSpHist(Win);
00154                   break;
00155             case 1: strncpy(IDT,"i131",4);strncpy(IKEY,"k321",4);
00156                 Records(Win);break;
00157             case 2: strncpy(IDT,"i132",4);strncpy(IKEY,"k033",4);
00158                 ShowPrest(Win);break;
00159             case 3: strncpy(IDT,"i034",4);ShowHard(Win);break;
00160             case 4: strncpy(IDT,(Win==0)? "i133" :"i134",4);
00161                 strncpy(IKEY,(Win==0)? "k035" :"k441",4);
00162                 if (Data->P[Win].AstroCount>0)
00163                  if (Option==-1 || Option==Win) ShowAstrosHist(Win);
00164           default:break;
00165          }
00166         strncpy(IDT,"i000",4);strncpy(IKEY,"k000",4);
00167         DrawStatistics(Win);
00168          key=0;i=0;
00169          OutBox(starty+(j*33),87,31+starty+(j*33),107);
00170        }
00171       } // matches AI[Win]==0
00172      }
00173     for (j=0;j<5;j++)
00174      {
00175      if (AI[other(Win)]==0)
00176       {
00177        if ((x>=starty+(j*33) && y>=132 && x<=31+starty+(j*33) && y<=152 && mousebuttons>0) || (key>='5' && key<='9'))
00178         {
00179          if (key>0)
00180           {
00181            switch(key)
00182             {
00183              case '5':j=0;break;
00184              case '6':j=1;break;
00185              case '7':j=2;break;
00186              case '8':j=3;break;
00187              case '9':j=4;break;
00188              default:break;
00189             }
00190           }
00191          InBox(starty+(j*33),132,31+starty+(j*33),152);
00192           WaitForMouseUp();
00193          key=0;
00194          switch(j)
00195           {
00196             case 0:strncpy(IDT,"i130",4);strncpy(IKEY,"k031",4);
00197                  if (Option==-1 || Option==other(Win)) ShowSpHist(other(Win));
00198                  //ShowSpHist(other(Win));
00199                  break;
00200             case 1:strncpy(IDT,"i131",4);strncpy(IKEY,"k321",4);
00201                  Records(other(Win));break;
00202             case 2:strncpy(IDT,"i132",4);strncpy(IKEY,"k033",4);
00203                  ShowPrest(other(Win));break;
00204             case 3:strncpy(IDT,"i034",4);strncpy(IKEY,"k999",4);
00205                  ShowHard(other(Win));break;
00206             case 4:strncpy(IDT,(Win==0)?"i133":"i134",4);
00207                  strncpy(IKEY,(Win==0)?"k035":"k441",4);
00208                  if (Data->P[other(Win)].AstroCount>0)
00209                   if (Option==-1 || Option==other(Win))
00210                    ShowAstrosHist(other(Win));break;
00211            default:break;
00212           }
00213          strncpy(IDT,"i000",4);strncpy(IKEY,"k000",4);
00214          DrawStatistics(Win);
00215           key=0;i=0;
00216           OutBox(starty+(j*33),132,31+starty+(j*33),152);
00217         }
00218       }
00219     }
00220   }  
00221  return;
00222 }
00223 
00224 /** AI Wants to purchase Astronauts
00225  */
00226 void AIAstroPur(char plr)
00227 {
00228     int cost;
00229     int astrosInPool = 0;
00230 
00231     if (Data->P[plr].AstroLevel==0) 
00232         cost=20;
00233     else 
00234         cost=15;
00235 
00236     // Player has no cash, no astronauts
00237     if (cost>Data->P[plr].Cash) 
00238         return;
00239 
00240     switch (Data->P[plr].AstroLevel) {
00241         case 0:astrosInPool=ASTRO_POOL_LVL1;break;
00242         case 1:astrosInPool=ASTRO_POOL_LVL2;break;
00243         case 2:astrosInPool=ASTRO_POOL_LVL3;break;
00244         case 3:astrosInPool=ASTRO_POOL_LVL4;break;
00245         case 4:astrosInPool=ASTRO_POOL_LVL5;break;
00246         default:break;
00247     };
00248     // Select best astronauts out of number of positions to fill
00249     SelectBest(plr,astrosInPool);
00250     return;
00251 }
00252 
00253 
00254 /** Select the best crew for the mission
00255  */
00256 void SelectBest(char plr,int pos)
00257 {
00258  int count=0,now,MaxMen = 0,Index,AIMaxSel=0,i,j,k;
00259  FILE *fin;
00260  char tot,done;
00261 
00262  for (i=0;i<25;i++) AIsel[i]=0;
00263 
00264  memset(buffer,0x00,5000);
00265  Men=(struct ManPool *)buffer;
00266  fin = sOpen("CREW.DAT","rb",0);   
00267  fseek(fin,((sizeof (struct ManPool))*106)*plr,SEEK_SET);
00268  fread(Men,(sizeof (struct ManPool)*106),1,fin); 
00269  fclose(fin);
00270  switch(Data->P[plr].AstroLevel)
00271   {
00272     case 0:MaxMen=10;AIMaxSel=ASTRO_POOL_LVL1;Index=0;
00273             if (Data->P[plr].Female==1) MaxMen+=3;break;
00274     case 1:MaxMen=17;AIMaxSel=ASTRO_POOL_LVL2;Index=14;
00275             if (Data->P[plr].Female==1) MaxMen+=3;break;
00276     case 2:MaxMen=19;AIMaxSel=ASTRO_POOL_LVL3;Index=35;
00277             if (Data->P[plr].Female==1) MaxMen+=3;break;
00278     case 3:MaxMen=27;AIMaxSel=ASTRO_POOL_LVL4;Index=58;break;
00279     case 4:MaxMen=19;AIMaxSel=ASTRO_POOL_LVL5;Index=86;break;
00280     default: MaxMen = 0; AIMaxSel = 0; Index = 0;break;
00281   }; 
00282   now=Index;count=0;done=0;
00283   for (i=16;i>0;i--)
00284    {
00285     done=0;
00286      while (count<=AIMaxSel && done==0)
00287       {
00288        for (j=now;j<now+MaxMen+1;j++)
00289          {
00290           tot=0;
00291           tot= Men[j].Cap + Men[j].LM + Men[j].EVA + Men[j].Docking;
00292           if (i==tot) AIsel[count++]=j;
00293          else
00294          if (Data->P[plr].Female==1 && Men[j].Sex==1) {
00295            AIsel[count++]=j;
00296           }
00297          }
00298        done=1;
00299       }
00300    };
00301     for (i=0;i<AIMaxSel;i++)
00302       {
00303        strcpy(&Data->P[plr].Pool[i+Data->P[plr].AstroCount].Name[0],&Men[AIsel[i]].Name[0]);
00304        Data->P[plr].Pool[i+Data->P[plr].AstroCount].Sex=Men[AIsel[i]].Sex;
00305        Data->P[plr].Pool[i+Data->P[plr].AstroCount].Cap=Men[AIsel[i]].Cap;
00306        Data->P[plr].Pool[i+Data->P[plr].AstroCount].LM=Men[AIsel[i]].LM;
00307        Data->P[plr].Pool[i+Data->P[plr].AstroCount].EVA=Men[AIsel[i]].EVA;
00308        Data->P[plr].Pool[i+Data->P[plr].AstroCount].Docking=Men[AIsel[i]].Docking;
00309        Data->P[plr].Pool[i+Data->P[plr].AstroCount].Endurance=Men[AIsel[i]].Endurance;
00310        Data->P[plr].Pool[i+Data->P[plr].AstroCount].Status=0;
00311        Data->P[plr].Pool[i+Data->P[plr].AstroCount].oldAssign=-1;
00312        Data->P[plr].Pool[i+Data->P[plr].AstroCount].TrainingLevel=1;
00313        Data->P[plr].Pool[i+Data->P[plr].AstroCount].Group=Data->P[plr].AstroLevel;
00314        Data->P[plr].Pool[i+Data->P[plr].AstroCount].CR=random(2)+1;
00315        Data->P[plr].Pool[i+Data->P[plr].AstroCount].CL=random(2)+1;
00316        Data->P[plr].Pool[i+Data->P[plr].AstroCount].Task=0;
00317        Data->P[plr].Pool[i+Data->P[plr].AstroCount].Crew=0;
00318        Data->P[plr].Pool[i+Data->P[plr].AstroCount].Una=0;
00319        Data->P[plr].Pool[i+Data->P[plr].AstroCount].Pool=0;
00320        Data->P[plr].Pool[i+Data->P[plr].AstroCount].Compat=random(10)+1;
00321        Data->P[plr].Pool[i+Data->P[plr].AstroCount].Mood=100;
00322       Data->P[plr].Pool[i+Data->P[plr].AstroCount].Face=random(77);
00323        if (Data->P[plr].Pool[i+Data->P[plr].AstroCount].Sex==1) 
00324          Data->P[plr].Pool[i+Data->P[plr].AstroCount].Face=77+random(8);    
00325        k=random(10)+1;
00326       }; 
00327    if (k)EMPTY_BODY;
00328     Data->P[plr].AstroLevel++;
00329     Data->P[plr].AstroCount=Data->P[plr].AstroCount+pos;
00330     switch(Data->P[plr].AstroLevel)
00331       {
00332        case 1:Data->P[plr].AstroDelay=6;break;
00333        case 2: case 3: Data->P[plr].AstroDelay=4;break;
00334        case 4:Data->P[plr].AstroDelay=8;break;
00335        case 5: Data->P[plr].AstroDelay=99;break;
00336        default:break;
00337       };
00338    // remove from the bottom up out of training
00339    for(i=0;i<Data->P[plr].AstroCount;i++)
00340      if (Data->P[plr].Pool[i].Status==4) Data->P[plr].Pool[i].Status=0;
00341  return;
00342 }
00343 
00344 void DumpAstro(char plr,int inx)
00345 {
00346  int i,j;
00347  for (i=0;i<Data->P[plr].AstroCount;i++)
00348     if (Data->P[plr].Pool[i].Assign==inx && Data->P[plr].Pool[i].Prime<1)
00349       {
00350        Data->P[plr].Pool[i].Assign=0; // back to limbo
00351        Data->P[plr].Pool[i].Una=0;
00352       }
00353  for (i=0;i<8;i++)
00354     {
00355      for (j=0;j<4;j++)
00356        if (Data->P[plr].Pool[Data->P[plr].Crew[inx][i][j]-1].Prime<1)
00357          {
00358           Data->P[plr].Crew[inx][i][j]=0;
00359           Data->P[plr].Gcnt[inx][i]=0;
00360          }
00361     }
00362  return;
00363 }
00364 
00365 char Skill(char plr,char type)
00366 {
00367  char m,hgh=0,tst,ind=0;
00368  for (m=0;m<Data->P[plr].AstroCount;m++)
00369    {
00370     if (Data->P[plr].Pool[m].Status==0 && Data->P[plr].Pool[m].Assign==0 && Data->P[plr].Pool[m].Prime<1)
00371       {
00372        tst=0;
00373        switch(type)
00374         {
00375          case 1:tst=Data->P[plr].Pool[m].Cap+Data->P[plr].Pool[m].EVA;break;
00376          case 2:tst=Data->P[plr].Pool[m].LM+Data->P[plr].Pool[m].EVA;break;
00377          case 3:tst=Data->P[plr].Pool[m].Docking;break;
00378          case 4:tst=Data->P[plr].Pool[m].Cap;break;
00379          case 5:tst=Data->P[plr].Pool[m].EVA;break;
00380          default:break;
00381         }
00382        if (tst>=hgh)
00383          {
00384           ind=m;
00385           hgh=tst;
00386          }
00387       }
00388     }
00389  return(ind);
00390 }
00391 
00392 void TransAstro(char plr,int inx)
00393                                     // indexed 1 thru 5
00394 {
00395  int i,j,w,count=0,max,found,flt1,flt2,bug=1;
00396  while (bug==1) { count=0;max=0;found=0;flt1=0;flt2=0;
00397  if (inx==5) max=4;
00398   else if (inx==4) max=3;
00399     else max=inx;
00400  if (Data->P[plr].AstroCount==0) return;
00401  for (i=0;i<Data->P[plr].AstroCount;i++)
00402     {
00403      Data->P[plr].Pool[i].Mood=100;
00404      if (Data->P[plr].Pool[i].Status==1 || Data->P[plr].Pool[i].Status==2)
00405       {
00406        Data->P[plr].Pool[i].Status=0;
00407        Data->P[plr].Pool[i].Assign=0;
00408        Data->P[plr].Pool[i].Una=0;
00409        Data->P[plr].Pool[i].Prime=0;
00410        Data->P[plr].Pool[i].oldAssign=-1;
00411        Data->P[plr].Pool[i].Crew=0;
00412       }
00413      Data->P[plr].Pool[i].RetReas=0;
00414      Data->P[plr].Pool[i].Hero=0; //clear hero flag
00415    if (Data->P[plr].Pool[i].Status==0 && Data->P[plr].Pool[i].Assign==0 && Data->P[plr].Pool[i].Prime<1)
00416      ++count;
00417     }
00418  if (count<max*2) {CheckAdv(plr);return;}
00419  found=0;flt1=-1;flt2=-1;
00420  for (i=0;i<8;i++) {
00421    if (Data->P[plr].Gcnt[inx][i]==0) {
00422      if (flt1==-1) flt1=i;
00423        else if (flt2==-1) flt2=i;
00424    }
00425  }
00426  if (flt1==-1 || flt2==-1) {CheckAdv(plr);return;}
00427  for (i=0;i<2;i++)
00428    {
00429     for (j=1;j<=max;j++)
00430       {
00431        w=0;found=0;
00432        while (w < Data->P[plr].AstroCount && found==0)
00433          {
00434           if (Data->P[plr].Pool[w].Status==0 && Data->P[plr].Pool[w].Assign==0 && Data->P[plr].Pool[w].Prime<1)
00435             {
00436              // based on [j] an program and position pick best skill
00437              switch(inx)
00438               {
00439                case 1:w=Skill(plr,1);
00440                       break;
00441                case 2:if (j==1) w=Skill(plr,1);
00442                         else w=Skill(plr,2);
00443                       break;
00444                case 3:if (j==1) w=Skill(plr,1);
00445                         else if (j==2) w=Skill(plr,2);
00446                           else w=Skill(plr,3);
00447                       break;
00448                case 4:if (j==1) w=Skill(plr,4);
00449                         else if (j==2) w=Skill(plr,2);
00450                           else w=Skill(plr,3);
00451                       break;
00452                case 5:if (j==1) w=Skill(plr,4);
00453                         else if (j==2) w=Skill(plr,4);
00454                           else if (j==3) w=Skill(plr,5);
00455                           else w=Skill(plr,5);break;
00456                default:break;
00457               }
00458              if (i==0)
00459                {
00460                 Data->P[plr].Pool[w].Assign=inx;
00461                 Data->P[plr].Pool[w].Una=1;
00462                 Data->P[plr].Crew[inx][flt1][j-1]=w+1;
00463                 found=1;
00464                }
00465              else
00466                {
00467                 Data->P[plr].Pool[w].Assign=inx;
00468                 Data->P[plr].Pool[w].Una=1;
00469                 Data->P[plr].Crew[inx][flt2][j-1]=w+1;
00470                 found=1;
00471                }
00472             } // end if
00473           ++w;
00474          } // end while
00475       }
00476     Data->P[plr].Gcnt[inx][flt1]=max;
00477     Data->P[plr].Gcnt[inx][flt2]=max;
00478    }
00479  } // end while
00480  return;
00481 }
00482 
00483 void CheckAdv(char plr)
00484 {
00485  int i,count;
00486  count=0;
00487  for (i=0;i<Data->P[plr].AstroCount;i++)
00488    if (Data->P[plr].Pool[i].Status==0 && Data->P[plr].Pool[i].Assign==0)
00489      ++count;
00490  if (count<=3)
00491    {
00492     for (i=0;i<Data->P[plr].AstroCount;i++)
00493        if (Data->P[plr].Pool[i].Status==0 && Data->P[plr].Pool[i].Assign==0)
00494      {
00495       Data->P[plr].Pool[i].Focus=random(4)+1;
00496       if (Data->P[plr].Pool[i].Focus>0)
00497        {
00498         Data->P[plr].Cash-=3;
00499         Data->P[plr].Pool[i].Assign=0;
00500         Data->P[plr].Pool[i].Status=7;
00501        }
00502      }
00503    }
00504  return;
00505 }
00506 
00507 
00508 
00509 /** Remove unhappy astro's
00510  */
00511 void RemoveUnhappy(char plr)
00512 {
00513     int i,l,astroClass=0,fltCrew=0;
00514 
00515     for (i=0;i<Data->P[plr].AstroCount;i++)
00516     {
00517         // Find an Astronaut with in a bad mood
00518         if (Data->P[plr].Pool[i].Mood < ASTRONAUT_MOOD_THRESHOLD)
00519             if (Data->P[plr].Pool[i].Assign!=0 && Data->P[plr].Pool[i].Status==0)
00520             {
00521                 Data->P[plr].Pool[i].Assign=0; // back to limbo
00522                 Data->P[plr].Pool[i].Una=0;
00523                 for (astroClass=0; astroClass<ASTRONAUT_POOLS; astroClass++)
00524                 {
00525                     for (fltCrew=0; fltCrew<ASTRONAUT_CREW_MAX; fltCrew++)
00526                     {
00527                         for (l=0; l<ASTRONAUT_FLT_CREW_MAX; l++)
00528                         {
00529                             if (Data->P[plr].Crew[astroClass][fltCrew][l]==i)
00530                                 break;
00531                         }
00532                     }
00533                 }
00534 
00535                 for (l=0; l<ASTRONAUT_FLT_CREW_MAX; l++)
00536                 {
00537                     Data->P[plr].Crew[astroClass][fltCrew][l]=0;
00538                     Data->P[plr].Pool[Data->P[plr].Crew[astroClass][fltCrew][l]].Assign=0;
00539                     Data->P[plr].Pool[Data->P[plr].Crew[astroClass][fltCrew][l]].Una=0;
00540                 }
00541             }
00542     }
00543     return;
00544 }
00545 
00546 int AIQUnit(short hwx,short unx,char plr)
00547 {
00548   int b=0;
00549   if (hwx==0) b=(Data->P[plr].Probe[unx].Num==-1) ? 0:1;
00550   if (hwx==1) b=(Data->P[plr].Rocket[unx].Num==-1) ? 0:1;
00551   if (hwx==2) b=(Data->P[plr].Manned[unx].Num==-1) ? 0:1;
00552   if (hwx==3) b=(Data->P[plr].Misc[unx].Num==-1) ? 0:1;
00553   return(b);
00554 }
00555 
00556 void RDafford(char plr,int class,int index)
00557 {
00558  i16 b=0,roll=0,ok=0;
00559  if (class==0) b+=Data->P[plr].Probe[index].RDCost;
00560  if (class==1) b+=Data->P[plr].Rocket[index].RDCost;
00561  if (class==2) b+=Data->P[plr].Manned[index].RDCost;
00562  if (class==3) b+=Data->P[plr].Misc[index].RDCost;
00563 
00564  if (class==0) roll+=Data->P[plr].Probe[index].MaxRD - Data->P[plr].Probe[index].Safety;
00565  if (class==1) roll+=Data->P[plr].Rocket[index].MaxRD - Data->P[plr].Rocket[index].Safety;
00566  if (class==2) roll+=Data->P[plr].Manned[index].MaxRD - Data->P[plr].Manned[index].Safety;
00567  if (class==3) roll+=Data->P[plr].Misc[index].MaxRD - Data->P[plr].Misc[index].Safety;
00568 
00569  roll= (roll*10) / 35; ok=0;
00570 
00571  if (roll>5) roll=5;
00572  if (Data->P[plr].Buy[class][index]>0) return;
00573    while (ok==0 && roll!=0)
00574      {
00575       if ( (b*roll <= Data->P[plr].Cash) && AIQUnit(class,index,plr)==1
00576         && MaxChk(class+1,index+1,plr))
00577         {
00578          Data->P[plr].Buy[class][index]=RDUnit(class+1,index+1,roll,plr);
00579          Data->P[plr].Cash= (Data->P[plr].Cash - (b*roll));
00580          ok=1; // jump out of the loop
00581         }
00582        else roll-=1;
00583      }
00584  return;
00585 }
00586 
00587 int CheckMax(char plr,int m)
00588 {
00589  switch(m)
00590   {
00591    case 1: if (Data->P[plr].Probe[0].Num<1 || Data->P[plr].Probe[0].Safety<90) return(1);
00592              else return(0);
00593    case 2: if (Data->P[plr].Probe[1].Num<1 || Data->P[plr].Probe[1].Safety<90) return(1);
00594              else return(0);
00595    case 3: if (Data->P[plr].Probe[2].Num<1 || Data->P[plr].Probe[2].Safety<90) return(1);
00596              else return(0);
00597    case 4: if (Data->P[plr].Manned[0].Num<1 || Data->P[plr].Manned[0].Safety<90) return(1);
00598              else return(0);
00599    case 5: if (Data->P[plr].Manned[1].Num<1 || Data->P[plr].Manned[1].Safety<90) return(1);
00600              else return(0);
00601    default:return 0;
00602   }
00603 }
00604 
00605 char SF(char plr,char m)
00606 {
00607  char num=0;
00608  switch(m)
00609   {
00610    case 1:num=Data->P[plr].Probe[0].Safety;break;
00611    case 2:num=Data->P[plr].Probe[1].Safety;break;
00612    case 3:num=Data->P[plr].Probe[2].Safety;break;
00613    case 4:num=Data->P[plr].Manned[0].Safety;break;
00614    case 5:num=Data->P[plr].Manned[1].Safety;break;
00615    default:break;
00616   }
00617  return(num);
00618 }
00619 
00620 char SN(char plr,char m)
00621 {
00622  char num=0;
00623  switch(m)
00624   {
00625    case 1:num=Data->P[plr].Probe[0].Num;break;
00626    case 2:num=Data->P[plr].Probe[1].Num;break;
00627    case 3:num=Data->P[plr].Probe[2].Num;break;
00628    case 4:num=Data->P[plr].Manned[0].Num;break;
00629    case 5:num=Data->P[plr].Manned[1].Num;break;
00630    default:break;
00631   }
00632  return(num);
00633 }
00634 
00635 void AIPur(char plr)
00636 {
00637  if (Data->P[plr].AIStat==0) Data->P[plr].AIStat=1;
00638  if (Data->P[plr].Track[0]==0) Data->P[plr].Track[0]=1;
00639  if (Data->P[plr].Probe[0].Num<=Data->P[plr].Rocket[0].Num)
00640   {
00641     if (GenPur(plr,0,0)) RDafford(plr,0,0);
00642      else RDafford(plr,0,0);
00643     if (GenPur(plr,1,0)) RDafford(plr,1,0);
00644      else RDafford(plr,1,0);
00645   }
00646   else
00647     {
00648      if (GenPur(plr,1,0)) RDafford(plr,1,0);
00649       else RDafford(plr,1,0);
00650      if (GenPur(plr,0,0)) RDafford(plr,0,0);
00651       else RDafford(plr,0,0);
00652     }
00653  return;
00654 }
00655 
00656 int GenPur(char plr,int hwx,int unx)
00657 {
00658  char RT_value=0,newf,n1,n2,n3,n4,n5,n6,n7;
00659 
00660  newf=0; // reinitialize
00661  //special case DM before Kickers
00662  if (hwx==3 && unx<=1 && Data->P[plr].Misc[4].Num==-1)
00663   {
00664    hwx=3;unx=4;
00665   };
00666  switch(hwx)
00667  {
00668   case 0: if (Data->P[plr].Probe[unx].Num<2)
00669         { // Probe Programs
00670          if (Data->P[plr].Probe[unx].Num==-1)
00671            {
00672             if (Data->P[plr].Probe[unx].InitCost < Data->P[plr].Cash)
00673               {
00674                Data->P[plr].Cash = Data->P[plr].Cash - Data->P[plr].Probe[unx].InitCost;
00675                if (Data->P[plr].Probe[unx].Num==-1) Data->P[plr].Probe[unx].Num=1;
00676                 else Data->P[plr].Probe[unx].Num = Data->P[plr].Probe[unx].Num = 1;
00677                RT_value=1;newf=1;
00678               }
00679            }
00680          else
00681             {
00682              if (Data->P[plr].Probe[unx].UnitCost < Data->P[plr].Cash)
00683                {
00684                 Data->P[plr].Cash = Data->P[plr].Cash - Data->P[plr].Probe[unx].UnitCost;
00685                 Data->P[plr].Probe[unx].Num = Data->P[plr].Probe[unx].Num + 1;
00686                 RT_value=1;
00687                }
00688           else {
00689              RT_value=1;++Data->P[plr].Probe[unx].Num;
00690             }
00691             }
00692        }; // end case 1
00693      break;
00694   case 1:if (Data->P[plr].Rocket[unx].Num<2)
00695             { // Rocket Programs Purchasing
00696             if (Data->P[plr].Rocket[unx].Num==-1)
00697               {
00698                if (Data->P[plr].Rocket[unx].InitCost < Data->P[plr].Cash)
00699                 { 
00700                  Data->P[plr].Cash = Data->P[plr].Cash - Data->P[plr].Rocket[unx].InitCost;
00701                  if (Data->P[plr].Rocket[unx].Num==-1) Data->P[plr].Rocket[unx].Num=1;
00702                   else ++Data->P[plr].Rocket[unx].Num;
00703                  RT_value=1;newf=1;
00704                 }
00705               }
00706               else
00707               {
00708                if (Data->P[plr].Rocket[unx].Num==1 && (Data->P[plr].Rocket[unx].Safety<Data->P[plr].Rocket[unx].MaxRD-15))
00709                  {
00710                   RDafford(plr,1,unx);
00711                Data->P[plr].Buy[1][unx]=0;
00712                   RT_value=1;
00713                  }
00714              else
00715                if (Data->P[plr].Rocket[unx].Num>=0)
00716                  {
00717                   if (Data->P[plr].Rocket[unx].UnitCost < Data->P[plr].Cash)
00718                    {
00719                      Data->P[plr].Cash = Data->P[plr].Cash - Data->P[plr].Rocket[unx].UnitCost;
00720                      ++Data->P[plr].Rocket[unx].Num;
00721                      RT_value=1;
00722                    }
00723                else
00724                 { 
00725                  RT_value=1;++Data->P[plr].Rocket[unx].Num;
00726                 }
00727                  }
00728               }
00729        }; // end case 2
00730      break;
00731    case 2:if (unx==3 && Data->P[plr].Manned[3].Num==1) return(1);
00732             else
00733               if (Data->P[plr].Manned[unx].Num<2)
00734                 { // Manned Programs
00735                  if (Data->P[plr].Manned[unx].Num==-1)
00736                    {
00737                     if (Data->P[plr].Manned[unx].InitCost < Data->P[plr].Cash)
00738                       {
00739                        Data->P[plr].Cash = Data->P[plr].Cash - Data->P[plr].Manned[unx].InitCost;
00740                        if (Data->P[plr].Manned[unx].Num==-1) Data->P[plr].Manned[unx].Num=1;
00741                          else ++Data->P[plr].Manned[unx].Num;
00742                        RT_value=1;newf=1;
00743                       }
00744                    }
00745                  else
00746                   {
00747                    if (Data->P[plr].Manned[unx].Num==1 && (Data->P[plr].Manned[unx].Safety<Data->P[plr].Manned[unx].MaxRD-15))
00748                      {
00749                       RDafford(plr,2,unx);
00750                  Data->P[plr].Buy[2][unx]=0;
00751                       RT_value=1;
00752                      }
00753               else
00754                   if (Data->P[plr].Manned[unx].Num>=0)
00755                     {
00756                      if (Data->P[plr].Manned[unx].UnitCost < Data->P[plr].Cash)
00757                        {
00758                         Data->P[plr].Cash = Data->P[plr].Cash - Data->P[plr].Manned[unx].UnitCost;
00759                         ++Data->P[plr].Manned[unx].Num;
00760                         RT_value=1;
00761                        }
00762                 else {
00763                   RT_value=1;++Data->P[plr].Manned[unx].Num;
00764                   }
00765                     }
00766                  }
00767        }; // end case 3
00768      break;
00769    case 3: if (Data->P[plr].Misc[unx].Num<2) { // Misc Programs
00770           if (unx==3 && Data->P[plr].Misc[unx].Num==1) return(1);
00771         if (Data->P[plr].Misc[unx].Num==-1)
00772           {
00773            if (Data->P[plr].Misc[unx].InitCost < Data->P[plr].Cash)
00774              {
00775               Data->P[plr].Cash = Data->P[plr].Cash - Data->P[plr].Misc[unx].InitCost;
00776               if (Data->P[plr].Misc[unx].Num==-1) Data->P[plr].Misc[unx].Num=1;
00777             else ++Data->P[plr].Misc[unx].Num;
00778              RT_value=1;newf=1;
00779              }
00780          }
00781         else
00782           if (Data->P[plr].Misc[unx].Num>=0)
00783             {
00784              if (Data->P[plr].Misc[unx].UnitCost < Data->P[plr].Cash)
00785                {
00786                 Data->P[plr].Cash = Data->P[plr].Cash - Data->P[plr].Misc[unx].UnitCost;
00787                 ++Data->P[plr].Misc[unx].Num;
00788                 RT_value=1;
00789                }
00790           else {
00791             RT_value=1;++Data->P[plr].Misc[unx].Num;
00792             }
00793            }
00794        }; // end case 4
00795      break;
00796   default:break;
00797    } // end switch
00798 
00799   // starting bonuses and cost bonuses
00800   if (hwx==0 && newf==1) {
00801     n1=Data->P[plr].Probe[0].Safety;
00802     n2=Data->P[plr].Probe[1].Safety;
00803     n3=Data->P[plr].Probe[2].Safety;
00804     switch(unx) {
00805       case 0: if (n2>=75) Data->P[plr].Probe[0].Safety=50;
00806           if (n3>=75) Data->P[plr].Probe[0].Safety=60;
00807           break;
00808       case 1: if (n1>=75) Data->P[plr].Probe[1].Safety=45;
00809           if (n3>=75) Data->P[plr].Probe[1].Safety=50;
00810           break;
00811       case 2: if (n1>=75) Data->P[plr].Probe[2].Safety=45;
00812           if (n2>=75) Data->P[plr].Probe[2].Safety=50;
00813           break;
00814     };
00815     Data->P[plr].Probe[unx].Base=Data->P[plr].Probe[unx].Safety;
00816   };
00817   if (hwx==1 && newf==1) {
00818     n1=Data->P[plr].Rocket[0].Safety; /* One - A     */
00819     n2=Data->P[plr].Rocket[1].Safety; /* Two - B     */
00820     n3=Data->P[plr].Rocket[2].Safety; /* Three - C   */
00821     n4=Data->P[plr].Rocket[3].Safety; /* Mega - G    */
00822     n5=Data->P[plr].Rocket[4].Safety; /* Booster - D */
00823     switch(unx) {
00824       case 0: if (n2>=75 || n3>=75 || n4>=75 || n5>=75)
00825         Data->P[plr].Rocket[0].Safety=35;
00826           break;
00827       case 1: if (n1>=75 || n5>=75) Data->P[plr].Rocket[1].Safety=25;
00828           if (n3>=75 || n4>=75) Data->P[plr].Rocket[1].Safety=40;
00829           if ((n1>=75 || n5>=75) && (n3>=75 || n4>=75))
00830         Data->P[plr].Rocket[1].Safety=65;
00831           break;
00832       case 2: if (n1>=75 || n5>=75) Data->P[plr].Rocket[2].Safety=15;
00833           if (n2>=75 || n4>=75) Data->P[plr].Rocket[2].Safety=35;
00834           if ((n1>=75 || n5>=75) && (n2>=75 || n4>=75))
00835         Data->P[plr].Rocket[2].Safety=60;
00836           break;
00837       case 3: if (n1>=75 || n5>=75) Data->P[plr].Rocket[3].Safety=10;
00838           if (n2>=75 || n3>=75) Data->P[plr].Rocket[3].Safety=25;
00839           if ((n1>=75 || n5>=75) && (n2>=75 || n3>=75))
00840         Data->P[plr].Rocket[3].Safety=35;
00841           break;
00842       case 4: if (n1>=75 || n2>=75 || n3>=75 || n4>=75)
00843         Data->P[plr].Rocket[4].Safety=30;
00844           break;
00845     };
00846     Data->P[plr].Rocket[unx].Base=Data->P[plr].Rocket[unx].Safety;
00847   };
00848   if (hwx==2 && newf==1) {
00849     n1=Data->P[plr].Manned[0].Safety; /* One - a         */
00850     n2=Data->P[plr].Manned[1].Safety; /* Two - b         */
00851     n3=Data->P[plr].Manned[2].Safety; /* Three - c       */
00852     n4=Data->P[plr].Manned[3].Safety; /* Minishuttle - f */
00853     n5=Data->P[plr].Manned[4].Safety; /* cap/mod - h     */
00854     n6=Data->P[plr].Manned[5].Safety; /* 2 mod - d       */
00855     n7=Data->P[plr].Manned[6].Safety; /* 1 mod - e       */
00856     switch(unx) {
00857       case 0: if (n2>=75 || n3>=75 || n5>=75)
00858         Data->P[plr].Manned[0].Safety=40;
00859           break;
00860       case 1: if (n1>=75) Data->P[plr].Manned[1].Safety=20;
00861           if (n3>=75 || n5>=75) Data->P[plr].Manned[1].Safety=40;
00862           break;
00863       case 2: if (n1>=75 || n5>=75) Data->P[plr].Manned[2].Safety=20;
00864           if (n2>=75 || n4>=75) Data->P[plr].Manned[2].Safety=30;
00865           if ((n1>=75 || n5>=75) && (n2>=75 || n4>=75))
00866         Data->P[plr].Manned[2].Safety=40;
00867           break;
00868       case 3: break;
00869       case 4: if (n1>=75) Data->P[plr].Manned[4].Safety=10;
00870           if (n2>=75) Data->P[plr].Manned[4].Safety=15;
00871           if (n3>=75) Data->P[plr].Manned[4].Safety=25;
00872           if ((n1>=75 || n2>=75 || n3>=75) && (n6>=75 || n7>=75))
00873          Data->P[plr].Manned[4].Safety=35;
00874           break;
00875       case 5: if (n7>=75) Data->P[plr].Manned[5].Safety=30;
00876           if (n5>=75) Data->P[plr].Manned[5].Safety=40;
00877           break;
00878       case 6: if (n6>=75) Data->P[plr].Manned[6].Safety=30;
00879           if (n5>=75) Data->P[plr].Manned[6].Safety=40;
00880           break;
00881     };
00882     Data->P[plr].Manned[unx].Base=Data->P[plr].Manned[unx].Safety;
00883 
00884   };
00885 
00886   if (hwx==3 && newf==1) {
00887     n1=Data->P[plr].Rocket[0].Safety; /* One - A     */
00888     n2=Data->P[plr].Rocket[1].Safety; /* Two - B     */
00889     n3=Data->P[plr].Rocket[2].Safety; /* Three - C   */
00890     n4=Data->P[plr].Rocket[3].Safety; /* Mega - G    */
00891     n5=Data->P[plr].Rocket[4].Safety; /* Booster - D */
00892     switch(unx) {
00893       case 0: if (n2>=75)
00894         Data->P[plr].Misc[0].Safety=40;
00895           break;
00896       case 1: if (n1>=75) Data->P[plr].Misc[1].Safety=35;
00897           break;
00898       case 2: if (n1>=75 || n2>=75) Data->P[plr].Misc[2].Safety=25;
00899           break;
00900       default: break;
00901     };
00902     Data->P[plr].Misc[unx].Base=Data->P[plr].Misc[unx].Safety;
00903 
00904   };
00905  return(RT_value);
00906 }
00907 
00908 
00909 
00910 /* EOF */

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