prest.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 /** \file prest.c Handles all the prestige related code.
00019  */
00020 
00021 #include "Buzz_inc.h"
00022 #include "externs.h"
00023 
00024 extern struct mStr Mis;
00025 extern struct MisEval Mev[60];
00026 extern struct Prest_Upd MP[3];
00027 extern struct MisAst MA[2][4];
00028 extern char STEPnum,AI[2],MANNED[2];
00029 //extern char tame[29][40];
00030 extern char hero,death;
00031 extern char Option,MAIL;
00032 
00033 char tYr,tMo,tIDX,bIDX;
00034 FILE *ft;
00035 
00036 void Set_Dock(char plr, char total)
00037 {
00038   int i;
00039   for (i=0;i<total;i++) {
00040    if (Mev[i].loc==8 && Mev[i].StepInfo==1) 
00041      {Data->Prestige[24].Goal[plr]++;return;};
00042    }
00043   return;
00044 }
00045 
00046 void Set_LM(char plr, char total)
00047 {
00048   int i;
00049   for (i=0;i<total;i++) {
00050    if (Mev[i].loc==26 && Mev[i].StepInfo==1) Data->P[plr].LMpts++;
00051    }
00052   return;
00053 }
00054 
00055 int Check_Photo(void)
00056 {
00057   int i;
00058   for (i=0;i<STEPnum;i++) {
00059    if (Mev[i].loc==20 && Mev[i].StepInfo==1) return 1;
00060    if (Mev[i].loc==22 && i==4 && Mev[i].StepInfo==1) return 1;
00061    if (Mev[i].loc==20 && Mev[i].StepInfo>1) return 2;
00062    }
00063   return 0;
00064 }
00065 
00066 int Check_Lab(void)
00067 {
00068   int i;
00069   for (i=0;i<STEPnum;i++) {
00070    if (Mev[i].loc==28 && Mev[i].StepInfo==1) return 1;
00071    }
00072   return 0;
00073 }
00074 
00075 int Check_Dock(int limit)
00076 {
00077   int i;
00078   for (i=0;i<STEPnum;i++) {
00079    if (Mev[i].loc==8 && Mev[i].StepInfo == 0) return 0;
00080    if (Mev[i].loc==8 && Mev[i].StepInfo <= limit) return 2;
00081    if (Mev[i].loc==8 && Mev[i].StepInfo > limit) return 1;
00082    }
00083   return 0;
00084 }
00085 
00086 int Check_EVA(int limit)
00087 {
00088   int i;
00089   for (i=0;i<STEPnum;i++) {
00090    if (Mev[i].loc==7 && Mev[i].StepInfo == 0) return 0;
00091    if (Mev[i].loc==7 && Mev[i].StepInfo <= limit) return 2;
00092    if (Mev[i].loc==7 && Mev[i].StepInfo > limit) return 1;
00093    }
00094   return 0;
00095 }
00096 
00097 int PrestMap(int val)
00098 {
00099    if (val==ORBSAT) return MILE_OSAT;
00100    if (val==MANSPACE) return MILE_MAN;
00101    if (val==EORBIT) return MILE_EORBIT;
00102    if (val==LUNFLY) return MILE_LFLY;
00103    if (val==PROBELAND) return MILE_LPL;
00104    if (val==LPASS) return MILE_LPASS;
00105    if (val==LORBIT) return MILE_LORBIT;
00106    if (val==LLAND) return MILE_LLAND;
00107    return -1;  // default
00108 }
00109 
00110 char PrestMin(char plr)      // Call only after a Mis Struct is filled
00111 {
00112   int i,j,Neg=0;
00113   Neg=0;
00114   j=0;
00115   if (Mis.Index==0) return 0;
00116   for (i=0;i<5;i++)
00117     j=maxx(j,PrestMap(Mis.PCat[i]));
00118 
00119   if (j>=MILE_OSAT) {
00120     if (isMile(plr,MILE_OSAT)==0) Neg+=3;
00121     if (j>=MILE_MAN) {
00122       if (isMile(plr,MILE_MAN)==0) Neg+=3;
00123       if (j>=MILE_EORBIT) {
00124         if (isMile(plr,MILE_EORBIT)==0) Neg+=3;
00125         if (j>=MILE_LFLY) {
00126           if (isMile(plr,MILE_LFLY)==0) Neg+=3;
00127           if (j>=MILE_LPL) {
00128             if (isMile(plr,MILE_LPL)==0) Neg+=3;
00129             if (j>=MILE_LPASS) {
00130               if (isMile(plr,MILE_LPASS)==0) Neg+=3;
00131               if (j>=MILE_LORBIT) {
00132                 if (isMile(plr,MILE_LORBIT)==0) Neg+=3;
00133                 if (j>=MILE_LLAND) {
00134                   if (isMile(plr,MILE_LLAND)==0) Neg+=3;
00135                 }
00136               }
00137             }
00138           }
00139         }
00140       }
00141     }
00142   }
00143 
00144   Neg-=(2-((plr==0)?Data->Def.Lev1:Data->Def.Lev2));
00145   Neg=maxx(Neg,0);
00146 
00147   if( (Mis.Index!=2 && Mis.Index!=4 && Mis.Index!=6) && (Mis.Days-Data->P[plr].DurLevel) > 0 ) {
00148     Neg+=5*abs(Mis.Days-Data->P[plr].DurLevel);
00149   }
00150   
00151   return Neg;
00152 }
00153 
00154 
00155 /** Returns the amount of prestige added
00156  * 
00157  * \note Assumes that the Mis Structure is Loaded
00158  */
00159 int PrestCheck(char plr)
00160 {
00161  int i,total=0; char prg,tm;
00162 
00163  prg=Mis.mEq;
00164 
00165   for (i=0;i<5;i++) {   // Sum all first/second Nation Bonus's
00166     tm=Mis.PCat[i];
00167     if (tm!=-1 && Data->Prestige[tm].Goal[plr]==0) { // First Mission Bonus
00168       if (Data->Prestige[tm].Goal[other(plr)]==0 && tm<27)
00169     total+=Data->Prestige[tm].Add[0];  //your first
00170       else total+=Data->Prestige[tm].Add[1];  // your second 
00171     }
00172   }
00173 
00174   if (Mis.Doc==1 && Data->Prestige[24].Goal[plr]==0) {
00175     if (Data->Prestige[24].Goal[other(plr)]==0)
00176       total+=Data->Prestige[24].Add[0];  // your first
00177     else total+=Data->Prestige[24].Add[1];  // your second 
00178   }
00179 
00180   if (Mis.EVA==1 && Data->Prestige[26].Goal[plr]==0) {
00181     if (Data->Prestige[26].Goal[other(plr)]==0)
00182       total+=Data->Prestige[26].Add[0];    // your first 
00183     else total+=Data->Prestige[26].Add[1]; // your second
00184   }
00185 
00186   if (Mis.Days>1 && Data->P[plr].DurLevel<Mis.Days) {
00187     if (Mis.Days==6 && Data->Prestige[14-Mis.Days].Goal[plr]==0)
00188       total+=Data->Prestige[14-Mis.Days].Add[0];
00189     else if (Mis.Days==5 && Data->Prestige[14-Mis.Days].Goal[plr]==0)
00190       total+=Data->Prestige[14-Mis.Days].Add[0];
00191     else if (Mis.Days==4 && Data->Prestige[14-Mis.Days].Goal[plr]==0)
00192       total+=Data->Prestige[14-Mis.Days].Add[0];
00193     else if (Mis.Days==3 && Data->Prestige[14-Mis.Days].Goal[plr]==0)
00194       total+=Data->Prestige[14-Mis.Days].Add[0];
00195     else if (Mis.Days==2 && Data->Prestige[14-Mis.Days].Goal[plr]==0) 
00196       total+=Data->Prestige[14-Mis.Days].Add[0];
00197   }
00198 
00199   // Hardware Checks
00200   if (Mis.Days>1 && Data->Prestige[12+prg].Goal[plr]==0) {
00201     if (Data->Prestige[12+prg].Goal[other(plr)]==0)
00202       total+=Data->Prestige[12+prg].Add[0];   // your first
00203     else total+=Data->Prestige[12+prg].Add[1]; // your second
00204   }
00205 
00206   if (total!=0) return total;
00207 
00208   // Other mission bonus
00209 
00210    // Sum all additional Mission Bonues
00211   for (i=0;i<5;i++)
00212     if (Mis.PCat[i]!=-1)
00213       total+=Data->Prestige[Mis.PCat[i]].Add[2];
00214 
00215   if (Mis.Doc==1 && Data->Prestige[24].Goal[plr]==0)
00216     total+=Data->Prestige[24].Add[2];
00217 
00218   if (Mis.EVA==1 && Data->Prestige[26].Goal[plr]==0)
00219     total+=Data->Prestige[26].Add[2];
00220 
00221   return total;
00222 }
00223 
00224 
00225 /** ???
00226  * 
00227  * \note Requires MEV to be packed 
00228  * Only checks goal steps :: 
00229  * returns GOAL value 
00230  * Does not check if entire mission is a success
00231  * 
00232  */
00233 char Was_Goal(char total,char which)
00234 {
00235    char i,val,x=10;
00236 
00237    switch(which) {
00238       case MANSPACE:val=4; break; // RECOVERY
00239       case EORBIT:val=1;break;    // OIB
00240       case LPASS:val=14;break;    // LIRA
00241       case LORBIT:val=12;break;   // LOA
00242       case LLAND:val=18;break;    // LLAND
00243       case ORBSAT:val=2;break;    // POWERON
00244       case LUNFLY: case ME_FB: case VE_FB: case MA_FB: case JU_FB: case SA_FB:
00245          val=22;break;                   // P.ACT
00246       case PROBELAND: val=18; break;     // LLAND
00247       case OLAB:val=28;break;            // Jt Dur
00248       case DOCK:val=8;break;             // Docking
00249       case EWALK:val=7;break;     // E EVA
00250       case LWALK:val=15;break;    // L EVA
00251       case -1: 
00252             default:
00253                     return -1;
00254       }
00255 
00256    i=0;
00257 
00258    while ( i != 0x7f) {                               // not branched
00259       if (Mev[i].loc==val && Mev[i].StepInfo<3000 ) x=minn(1,x);
00260       if ((which==ORBSAT || which==LUNFLY || which==PROBELAND) && Mev[i].StepInfo>500) x=-1;
00261       if (Mev[i].StepInfo>=3000) x=-1;  // Manned will only be affected
00262       i=Mev[i].trace;
00263       };
00264 
00265    if (x>0 && x<10) return which;
00266 
00267   switch(which) {
00268     case EORBIT:return Was_Goal(total,MANSPACE);
00269     case LPASS:return Was_Goal(total,EORBIT);
00270     case LORBIT:return Was_Goal(total,LPASS);
00271     case LLAND:return Was_Goal(total,LORBIT);
00272     case EWALK:return Was_Goal(total,LWALK);
00273     default: return -1;  // no goal step achieved
00274   }
00275 }
00276 
00277 char HeroCheck(int which)
00278 {
00279    switch(which) {
00280       case MANSPACE: return 0x01;// RECOVERY
00281       case EORBIT: return 0x01;  // OIB
00282       case LPASS:return 0x01;    // LIRA
00283       case LLAND:return 0x01;    // LLAND
00284       case EWALK:return 0x02;    // E EVA
00285       case LWALK:return 0x02;    // L EVA
00286       default: return 0;
00287       }
00288 }
00289 
00290 /** Sets Goal Values and Sums into Data Structure
00291  * control should be always called with a value of 0
00292  * Successful Steps Only
00293  * Requires MEV to be packed
00294  */
00295 char Set_Goal(char plr,char which,char control)
00296 {
00297   char sum,pd,qt;
00298 
00299   sum=0;
00300   if (control!=3) {
00301       if (MaxFail()>1999) return -1;
00302   }
00303   else control=0;
00304 
00305     if (control==1 || which>=0) {  // Means successful to this part
00306 
00307       if (Data->Prestige[which].Place==-1) {
00308         switch(which) {  // flag milestones
00309          case ORBSAT: isMile(plr,MILE_OSAT)=1;break;
00310          case MANSPACE: isMile(plr,MILE_MAN)=1;break;
00311          case EORBIT: isMile(plr,MILE_EORBIT)=1;break;
00312          case LUNFLY: isMile(plr,MILE_LFLY)=1;break;
00313          case PROBELAND:  isMile(plr,MILE_LPL)=1;break;
00314          case LPASS: isMile(plr,MILE_LPASS)=1;break;
00315          case LORBIT: isMile(plr,MILE_LORBIT)=1;break;
00316          case LLAND: isMile(plr,MILE_LLAND)=1;break;
00317         }
00318 
00319          if (control==0) {
00320            Data->P[plr].Other|=4;  // for astros
00321 
00322 
00323         if (Option==1)
00324          {
00325           pd=Mev[0].pad;
00326           qt=MP[pd].Qty; 
00327           MP[pd].HInd=Data->P[1].PastMis;
00328           MP[pd].Poss[qt]=which;
00329           MP[pd].PossVal[qt]=0;
00330           MP[pd].Mnth=tMo;
00331           ++MP[pd].Qty;
00332          }
00333         else if (MAIL==0) {
00334           pd=Mev[0].pad;
00335           qt=Data->P[0].Udp[pd].Qty; 
00336           Data->P[0].Udp[pd].HInd=Data->P[0].PastMis;
00337           Data->P[0].Udp[pd].Poss[qt]=which;
00338           Data->P[0].Udp[pd].PossVal[qt]=0;
00339           Data->P[0].Udp[pd].Mnth=tMo;
00340           ++Data->P[0].Udp[pd].Qty;
00341          }
00342         else 
00343          {
00344           Data->Prestige[which].Place=plr;
00345           Data->Prestige[which].Indec=Data->P[plr].PastMis;
00346           Data->Prestige[which].Year=tYr;
00347           Data->Prestige[which].Month=tMo;
00348            Data->Prestige[which].Goal[plr]++;  // increment count
00349            Data->Prestige[which].Points[plr]+=Data->Prestige[which].Add[0];
00350            sum+=Data->Prestige[which].Add[0];
00351          }
00352 
00353           hero|=HeroCheck(which);
00354          } else if (control==1) {
00355           switch(which) {
00356             case DUR_B:
00357             case DUR_C:
00358             case DUR_D:
00359             case DUR_E:
00360             case DUR_F:
00361              if (Option==1)
00362               {
00363                pd=Mev[0].pad;
00364                qt=MP[pd].Qty;
00365                MP[pd].HInd=Data->P[1].PastMis;
00366                MP[pd].Poss[qt]=which;
00367                MP[pd].PossVal[qt]=0;
00368                MP[pd].Mnth=tMo;
00369                ++MP[pd].Qty;
00370               }
00371              else if (MAIL==0) {
00372                pd=Mev[0].pad;
00373                qt=Data->P[0].Udp[pd].Qty;
00374                Data->P[0].Udp[pd].HInd=Data->P[0].PastMis;
00375                Data->P[0].Udp[pd].Poss[qt]=which;
00376                Data->P[0].Udp[pd].PossVal[qt]=0;
00377                Data->P[0].Udp[pd].Mnth=tMo;
00378                ++Data->P[0].Udp[pd].Qty;
00379               }
00380              else {
00381                Data->Prestige[which].Place=plr;
00382               Data->Prestige[which].Indec=Data->P[plr].PastMis;
00383               Data->Prestige[which].Year=tYr;
00384               Data->Prestige[which].Month=tMo;
00385              }
00386             default: break;
00387           };
00388         }
00389      }   
00390       else if (Data->Prestige[which].mPlace==-1 && Data->Prestige[which].Place!=plr){
00391          Data->P[plr].Other|=4;  // for astros
00392 
00393 
00394         Data->Prestige[which].mPlace=plr;
00395 
00396         switch(which) {  // flag milestones
00397          case ORBSAT: isMile(plr,MILE_OSAT)=1;break;
00398          case MANSPACE: isMile(plr,MILE_MAN)=1;break;
00399          case EORBIT: isMile(plr,MILE_EORBIT)=1;break;
00400          case LUNFLY: isMile(plr,MILE_LFLY)=1;break;
00401          case PROBELAND: isMile(plr,MILE_LPL)=1;break;
00402          case LPASS: isMile(plr,MILE_LPASS)=1;break;
00403          case LORBIT: isMile(plr,MILE_LORBIT)=1;break;
00404          case LLAND: isMile(plr,MILE_LLAND)=1;break;
00405         }
00406 
00407          if (control==0) {
00408         if (Option==1) {
00409           pd=Mev[0].pad;
00410           qt=MP[pd].Qty;
00411           MP[pd].HInd=Data->P[1].PastMis;
00412           MP[pd].Poss[qt]=which;
00413           MP[pd].PossVal[qt]=1;
00414           MP[pd].Mnth=tMo;
00415           ++MP[pd].Qty;
00416          }
00417          else {
00418            Data->Prestige[which].Goal[plr]++;  // increment count
00419            sum+=Data->Prestige[which].Add[1];
00420            Data->Prestige[which].Points[plr]+=Data->Prestige[which].Add[1];
00421         }
00422          hero|=HeroCheck(which);
00423            }
00424         }
00425       else if(sum<3) {  // Other
00426          if (control==0) {
00427          if (Option==1) {
00428           pd=Mev[0].pad;
00429           qt=MP[pd].Qty;
00430           MP[pd].HInd=Data->P[1].PastMis;
00431           MP[pd].Poss[qt]=which;
00432           MP[pd].PossVal[qt]=2;
00433           MP[pd].Mnth=tMo;
00434           ++MP[pd].Qty;
00435          }
00436          else {
00437            Data->Prestige[which].Goal[plr]++;  // increment count
00438            sum+=Data->Prestige[which].Add[2];
00439            Data->Prestige[which].Points[plr]+=Data->Prestige[which].Add[2];
00440         }
00441            }
00442         }
00443      }
00444 
00445   //----------------------------------------
00446   //Specs: Lunar Landing klugge (Duration D)
00447   //----------------------------------------
00448   if (which==LLAND || Data->Prestige[22].Place==plr)
00449    Data->P[plr].History[Data->P[plr].PastMis].Duration=4;
00450 
00451   switch(which) {
00452     case ORBSAT: return(sum); 
00453     case MANSPACE:return(sum);
00454     case EORBIT:return(sum+Set_Goal(plr,ORBSAT,1));
00455     case LUNFLY:return(sum+Set_Goal(plr,EORBIT,1));
00456     case PROBELAND:return(sum+Set_Goal(plr,LUNFLY,1));
00457     case LPASS:return(sum+Set_Goal(plr,PROBELAND,1));
00458     case LORBIT:return(sum+Set_Goal(plr,LPASS,1));
00459     case LLAND:return(sum+Set_Goal(plr,LORBIT,1));
00460     case DUR_A: return(sum);
00461     case DUR_B: return(sum);
00462     case DUR_C:return(sum+Set_Goal(plr,DUR_B,1));
00463     case DUR_D:return(sum+Set_Goal(plr,DUR_C,1));
00464     case DUR_E:return(sum+Set_Goal(plr,DUR_D,1));
00465     case DUR_F:return(sum+Set_Goal(plr,DUR_E,1));
00466     case CAP1: return(sum);
00467     case CAP2:return(sum+Set_Goal(plr,CAP1,1));
00468     case CAP3:return(sum+Set_Goal(plr,CAP2,1));
00469     case CAPMS:return(sum+Set_Goal(plr,CAP3,1));
00470     case CAP4:return(sum+Set_Goal(plr,CAPMS,1));
00471     case ME_FB: case VE_FB: case MA_FB: case JU_FB: case SA_FB:
00472     case OLAB: case EWALK: case DOCK: case WOMAN:return (sum);
00473     default: return 0;
00474   }
00475 }
00476 
00477 /** Only sets negative for highest failed goal step
00478  * 
00479  * checks if entire mission was a failure
00480  */
00481 char Did_Fail(void)
00482 {
00483    char i,bra;
00484    unsigned int fail;
00485 
00486    fail=0;bra=0;i=0;
00487    while ( i != 0x7f) {
00488       if (Mev[i].StepInfo>=5000) fail+=1000;
00489       if (Mev[i].StepInfo>=4000 && Mev[i].StepInfo<=4999) fail+=1000;
00490       if (Mev[i].StepInfo>=3000 && Mev[i].StepInfo<=3999) fail+=100;
00491       if (Mev[i].StepInfo>=2000 && Mev[i].StepInfo<=2999) fail+=10;
00492       if (Mev[i].StepInfo>=1000 && Mev[i].StepInfo<=1999) fail+=1;
00493       if (Mev[i].trace!=(i+1)) bra++;
00494       i=Mev[i].trace;
00495       }
00496 
00497    if (fail<90 && bra==0) return 1;
00498    else return -1;
00499 }
00500 
00501 int MaxFail(void)
00502 {
00503    int i=0,t=0,bra=0,count=0;
00504 
00505    while (i != 0x7f && count<54) {
00506       if (Mev[i].StepInfo==0) Mev[i].StepInfo=1003;
00507       t=maxx(Mev[i].StepInfo,t);
00508       if (Mev[i].trace!=(i+1)) bra++;
00509       i=Mev[i].trace;
00510       ++count;
00511     }
00512  if (count>=54) return 1; else return t;
00513 }       
00514 
00515 #define PSTS(a)  (PVal[a]==1 || PVal[a]==2)
00516 #define NSTS(a)  (PVal[a]==4)
00517 #define SSTS(a)  (PVal[a]==3)
00518 #define STSp(a)  (PVal[a]==1 || PVal[a]==2)
00519 #define STSn(a)  (PVal[a]==4)
00520 #define IsGoal(a) ( (18)==18 || (a)==19 || (a)==20 || (a)==22 || (a)==27) )
00521 
00522 
00523 char PosGoal(char *PVal)
00524 {
00525    if (PSTS(22)) return 22;
00526    else if (PSTS(20)) return 20;
00527    else if (PSTS(19)) return 19;
00528    else if (PSTS(18)) return 18;
00529    else if (PSTS(27)) return 27;
00530    else return -1;
00531 }
00532 
00533 char NegGoal(char *PVal)
00534 {
00535    if (NSTS(22)) return 22;
00536    else if (NSTS(20)) return 20;
00537    else if (NSTS(19)) return 19;
00538    else if (NSTS(18)) return 18;
00539    else if (NSTS(27)) return 27;
00540    else return -1;
00541 }
00542 
00543 char SupGoal(char *PVal)
00544 {
00545    if (SSTS(22)) return 22;
00546    else if (SSTS(20)) return 20;
00547    else if (SSTS(19)) return 19;
00548    else if (SSTS(18)) return 18;
00549    else if (SSTS(27)) return 27;
00550    else return -1;
00551 }
00552 
00553 int PrestNeg(char plr,int i)
00554 {
00555   int negs=0;
00556   char pd,qt;
00557 
00558   if (Option==1)
00559    {
00560     pd=Mev[0].pad;
00561     qt=MP[pd].Qty;
00562     MP[pd].HInd=Data->P[1].PastMis;
00563     MP[pd].Poss[qt]=i;
00564     MP[pd].PossVal[qt]=3;
00565     ++MP[pd].Qty;
00566    }
00567   else {
00568     negs=Data->Prestige[i].Add[3];
00569     Data->Prestige[i].Goal[plr]++;
00570       Data->Prestige[i].Points[plr]+=Data->Prestige[i].Add[3];
00571   }
00572 
00573   return negs;
00574 }
00575 
00576 
00577 int AllotPrest(char plr,char mis)
00578 {
00579    int i,total,other,negs,mcode,mike,P_Goal,N_Goal,S_Goal,ival,cval;
00580    extern struct mStr Mis;
00581    char PVal[28];
00582 
00583    hero=0;
00584    tMo=Data->P[plr].Mission[mis].Month;
00585    tYr=Data->Year;
00586    tIDX=bIDX=0;
00587    memset(PVal,0x00,sizeof PVal);
00588    
00589    // SETUP INFO
00590    mcode=Data->P[plr].Mission[mis].MissionCode;
00591 
00592    GetMisType(mcode);
00593 
00594    other=MaxFail();
00595    total=negs=0;
00596 
00597    for (i=0;i<STEPnum;i++) {
00598       if (Mev[i].PComp==5 && Mev[i].StepInfo==0) {
00599          Mev[i].PComp=0;Mev[i].Prest=-100;
00600          }
00601       if ((MANNED[0]+MANNED[1])>0) {
00602          if (other>=3000) Mev[i].PComp=4;
00603          else if (Mev[i].Prest>=-28 && Mev[i].StepInfo>2999) Mev[i].PComp=4;
00604          }
00605       }
00606 
00607    // FEMALE 'NAUTS
00608      PVal[25]= (MA[0][0].A!=NULL && MA[0][0].A->Sex)
00609         || (MA[0][1].A!=NULL && MA[0][1].A->Sex) 
00610         || (MA[0][2].A!=NULL && MA[0][2].A->Sex) 
00611         || (MA[0][3].A!=NULL && MA[0][3].A->Sex)
00612         || (MA[1][0].A!=NULL && MA[1][0].A->Sex)
00613         || (MA[1][1].A!=NULL && MA[1][1].A->Sex) 
00614         || (MA[1][2].A!=NULL && MA[1][2].A->Sex) 
00615         || (MA[1][3].A!=NULL && MA[1][3].A->Sex);
00616 
00617    for (i=0;i<STEPnum;i++) {
00618       ival=abs(Mev[i].Prest);
00619       cval=Mev[i].PComp;
00620             
00621             // ival of 100 seems to mean "don't record this in PVal[]"
00622             // Regardless of intention, it's out of bounds, so don't access or overwrite it
00623             if (ival != 100) {
00624                 if (Mev[i].StepInfo==0 && PVal[ival]==0)
00625                     cval=4;
00626                 
00627                 if (PVal[ival]!=4)
00628                     PVal[ival]=cval;
00629             }
00630      }
00631 
00632    // EVA FIX FOR ALTERNATE STEPS LATER IN MISSION
00633    if (Mis.EVA==1 && (PVal[26]==0 || PVal[26]==5)) PVal[26]=4;
00634    else if (Mis.EVA==0 && PVal[26]==5) PVal[26]=0;
00635 
00636    // DOCKING FIX FOR ALTERNATE STEPS LATER IN SESSION
00637    if (Mis.Doc==1 && (PVal[24]==0 || PVal[24]==5)) PVal[27]=4;
00638    else if (Mis.EVA==0 && PVal[24]==5) PVal[24]=0;
00639 
00640    // CLEAR TOTAL VALUE
00641    total=0; negs=0;
00642 
00643    // PHOTO RECON
00644    if (PVal[19]>0 && PVal[19]<4) Data->P[plr].Misc[5].Safety+=5;  // manned stuff gets 5
00645 
00646    Data->P[plr].Misc[5].Safety=minn(Data->P[plr].Misc[5].Safety,99);
00647 
00648    if (death==1) {
00649      for (i=0;i<28;i++) if (PVal[i]>0 && PVal[i]<4) PVal[i]=4;
00650    }
00651 
00652    // GOAL FILTER : MANNED
00653    P_Goal=PosGoal(PVal);
00654    N_Goal=NegGoal(PVal);
00655    S_Goal=SupGoal(PVal);
00656 
00657    if (P_Goal==LLAND) {  // make sure EVA was done
00658       if (!(PVal[26]>=1 && PVal[26]<=3)) {
00659          P_Goal=LORBIT;
00660          PVal[LLAND]=0;
00661       }
00662    }
00663 
00664    if ((P_Goal==-1 && S_Goal==-1) && (PVal[25]>0)) PVal[25]=4;
00665 
00666      if (Check_Dock(500)==2) {    // Success
00667          Data->P[plr].Misc[4].Safety+=10;
00668          Data->P[plr].Misc[4].Safety=minn(Data->P[plr].Misc[4].Safety,Data->P[plr].Misc[4].MaxSafety);
00669        }
00670      else if (Check_Dock(500)==1) {
00671          Data->P[plr].Misc[4].Safety+=5;
00672          Data->P[plr].Misc[4].Safety=minn(Data->P[plr].Misc[4].Safety,Data->P[plr].Misc[4].MaxSafety);
00673        }
00674 
00675    if (STSp(27) || STSn(27)) PVal[27]=0;  // Clear All Firsts/Negative Goals
00676    if (STSp(18) || STSn(18)) PVal[18]=0;
00677    if (STSp(19) || STSn(19)) PVal[19]=0;
00678    if (STSp(20) || STSn(20)) PVal[20]=0;
00679    if (STSp(22) || STSn(22)) PVal[22]=0;
00680 
00681    // DURATION FIRSTS
00682    Data->P[plr].Mission[mis].Duration=maxx(Data->P[plr].Mission[mis].Duration,1);
00683 
00684    if (!Mis.Dur) {
00685      switch(P_Goal) {
00686        case MANSPACE:
00687          mike=7;
00688          Data->P[plr].Mission[mis].Duration=1;
00689          break;
00690        case EORBIT:
00691          mike= (Mis.Index<=6) ? (Data->P[plr].Mission[mis].Duration=1,7) : (Data->P[plr].Mission[mis].Duration=2,12);break;
00692        case LPASS:
00693          mike=11;
00694          Data->P[plr].Mission[mis].Duration=3;
00695          break;
00696        case LORBIT:
00697          mike=10;
00698          Data->P[plr].Mission[mis].Duration=4;
00699          break;
00700        case LLAND:
00701          mike=10;
00702          Data->P[plr].Mission[mis].Duration=4;
00703          break;
00704        default: mike=0; break;
00705      }
00706    } else {
00707       mike=14-Data->P[plr].Mission[mis].Duration;
00708    }
00709 
00710    if (mike>=8 && mike<=12)
00711       if (P_Goal>=18 || S_Goal>=18)
00712          PVal[mike]=1;
00713            //total+=(char) Set_Goal(plr,mike,0);
00714 
00715    // GOAL POSTIVE
00716    if (P_Goal!=-1) {
00717       total=Set_Goal(plr,P_Goal,0);
00718       if (P_Goal!=27) {total+=Set_Goal(plr,27,0);PVal[27]=0;}
00719       //if (!(Data->Prestige[27].Place==plr || Data->Prestige[27].mPlace==plr))
00720       //    total+=Set_Goal(plr,27,0);
00721       }
00722 
00723    // GOAL NEGATIVE 
00724    if (N_Goal!=-1) {
00725      negs+=PrestNeg(plr,N_Goal);
00726      PVal[N_Goal]=0;
00727    }
00728 
00729    if (mcode==32 || mcode==36) PVal[23]=Check_Lab();
00730 
00731    // TOTAL ALL MISSION FIRSTS
00732    for (i=0;i<28;i++) 
00733       if (PVal[i]==1 || (PVal[i]==2 && other<3000))
00734          total+=(char) Set_Goal(plr,i,0);
00735       //else if (PVal[i]==4) negs+=Set_Goal(plr,i,0);
00736 
00737    // CAPSULE FIRSTS   need to check for failure on capsule
00738    if ((P_Goal!=-1 || S_Goal!=-1) && other<3000 && MANNED[0]>0 && Data->P[plr].Mission[mis].Hard[Mission_Capsule]!=-1) {  // Hardware on first part
00739      total+=Set_Goal(plr,12+Data->P[plr].Mission[mis].Prog,0);
00740       }
00741    if ((P_Goal!=-1 || S_Goal!=-1) && other<3000 && MANNED[1]>0 && Data->P[plr].Mission[mis+1].Hard[Mission_Capsule]!=-1 &&
00742      Data->P[plr].Mission[mis+1].part==1) {
00743      total+=Set_Goal(plr,12+Data->P[plr].Mission[mis+1].Prog,0);
00744      }
00745 
00746 #define DNE(a,b) (Data->Prestige[b].Place==(a) || Data->Prestige[b].mPlace==(a))
00747 
00748    if (DNE(plr,8)) Data->P[plr].DurLevel=6;
00749    else if (DNE(plr,9)) Data->P[plr].DurLevel=5;
00750    else if (DNE(plr,10)) Data->P[plr].DurLevel=4;
00751    else if (DNE(plr,11)) Data->P[plr].DurLevel=3;
00752    else if (DNE(plr,12)) Data->P[plr].DurLevel=2;
00753    else if (DNE(plr,27)) Data->P[plr].DurLevel=1;
00754 
00755    // TOTAL ALL MISSION SUBSEQUENTS
00756    if (total==0) {
00757       // SET SUBSEQUENT Goal
00758       if (S_Goal!=-1 && other<3000) total=Set_Goal(plr,S_Goal,0);
00759 
00760       for (i=0;i<28;i++) 
00761          if (PVal[i]==1 || (PVal[i]==2 && other<3000))
00762             total+=(char) Set_Goal(plr,i,0);
00763          else if (PVal[i]==3) Set_Goal(plr,i,0);
00764       }
00765 
00766    // LM POINTS
00767    Set_LM(plr,STEPnum);
00768    if (mcode>=48 && mcode<=52 && other<3000) Set_LM(plr,STEPnum);
00769 
00770    // ADD IN NEGATIVES AND RETURN MIN of -10
00771    total=((total+negs) < -10) ? -10 : total+negs;
00772 
00773    return total;
00774 }
00775 
00776 // EOF
00777 
00778 
00779 char PosGoal_Check(char *PVal)
00780 {
00781    if (PSTS(22)) return 22;
00782    else if (PSTS(20)) return 20;
00783    else if (PSTS(19)) return 19;
00784    else if (PSTS(7)) return 7;
00785    else if (PSTS(1)) return 1;
00786    else if (PSTS(18)) return 18;
00787    else if (PSTS(27)) return 27;
00788    else if (PSTS(0)) return 0;
00789 
00790    else return -1;
00791 }
00792 
00793 
00794 int Find_MaxGoal(void)
00795 {
00796    int i,ival,cval;
00797    char PVal[28];
00798    memset(PVal,0x00,sizeof PVal);
00799    
00800    for (i=0;i<STEPnum;i++) {
00801       ival=abs(Mev[i].Prest);
00802       cval=Mev[i].PComp;
00803       if (ival!=100) {
00804          PVal[ival]=cval;
00805          }
00806       }
00807 
00808    return PosGoal_Check(PVal);
00809 }
00810 
00811 int U_AllotPrest(char plr,char mis)
00812 {
00813    int i=0,total,other,negs,mcode,lun;
00814    extern struct mStr Mis;
00815    char PVal[28];
00816 
00817    memset(PVal,0x00,sizeof PVal);     // CLEAR TOTAL VALUE
00818    total=0, negs=0, lun=0;
00819    tMo=Data->P[plr].Mission[mis].Month;
00820    tYr=Data->Year;
00821    tIDX=bIDX=0;
00822 
00823    // SETUP INFO
00824    mcode=Data->P[plr].Mission[mis].MissionCode;
00825    GetMisType(mcode);
00826 
00827    lun=Check_Photo();
00828 
00829    other=MaxFail();
00830 
00831    if ((mcode>=7 && mcode<=13) || mcode==1) {  // Unmanned Probes
00832        switch (mcode) {
00833          case 1:  i=0;break; // O.S.
00834          case 7:  i=1;break; // L.F.B.
00835          case 8:  i=7;break; // L.P.L.
00836          case 9:  i=3;break;
00837          case 10: i=4;break;
00838          case 11: i=2;break;
00839          case 12: i=5;break;
00840          case 13: i=6;break;
00841          }
00842   
00843 
00844       if (other==1) {
00845         if (mcode==10 || mcode==12 || mcode==13) return 0;
00846         total=Set_Goal(plr,i,0);
00847       }
00848       else negs=PrestNeg(plr,i);
00849 
00850      if (mcode==7 || mcode==8) {
00851        if (lun==1) {  // UNMANNED PHOTO RECON
00852          Data->P[plr].Misc[5].Safety+=5;
00853          Data->P[plr].Misc[5].Safety=minn(Data->P[plr].Misc[5].Safety,99);
00854        } // if
00855       } // if
00856 
00857      if (mcode==8 && MaxFail()==1) {  // extra 10 for landing on moon
00858        if (lun==1) {  // UNMANNED PHOTO RECON
00859          Data->P[plr].Misc[5].Safety+=10;
00860          Data->P[plr].Misc[5].Safety=minn(Data->P[plr].Misc[5].Safety,99);
00861        } // if
00862       } // if
00863 
00864    } // if
00865 
00866      if (Check_Dock(2)==2) {
00867          Data->P[plr].Misc[4].Safety+=10;
00868          Data->P[plr].Misc[4].Safety=minn(Data->P[plr].Misc[4].Safety,Data->P[plr].Misc[4].MaxSafety);
00869        }
00870      else if (Check_Dock(2)==1) {
00871          Data->P[plr].Misc[4].Safety+=5;
00872          Data->P[plr].Misc[4].Safety=minn(Data->P[plr].Misc[4].Safety,Data->P[plr].Misc[4].MaxSafety);
00873        }
00874   return total+negs;
00875 }
00876 
00877 
00878 // EOF
00879 

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