start.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 
00026 #include "Buzz_inc.h"
00027 #include "externs.h"
00028 
00029 extern char pNeg[NUM_PLAYERS][MAX_MISSIONS];
00030 extern char MAIL;
00031 
00032 char Nums[30][7]={"I","II","III","IV","V","VI","VII","VIII","IX","X",
00033    "XI","XII","XIII","XIV","XV","XVI","XVII","XVIII","XIX",
00034    "XX","XXI","XXII","XXIII","XXIV","XXV","XXVI","XXVII",
00035    "XXVIII","XXIX","XXX"};
00036 
00037 void SetEvents(void)
00038 {
00039   int i,j,k,rans,tag,mx=2;
00040   FILE *fout;
00041   char s[100],qant[6]={2,8,8,12,16,52};
00042   char Per[6][5]={{100,0,0,0,0},{0,100,0,0,0},{0,62,38,0,0},{0,50,20,30,0},
00043           {0,35,20,20,25},{0,25,25,25,25}};
00044   struct Q{char fir,qty,pic;} D[5]= {{1,3,0},{4,40,0},{44,19,0},{63,17,0},{80,20,0}};
00045   REPLAY Rep;
00046   ONEWS oNews;
00047   memset(&Rep,0x00,sizeof Rep);
00048 
00049   for (i=0;i<100;i++) s[i]=Data->Events[i]=0;
00050   for (i=0;i<6;i++)
00051     for (k=0;k<qant[i];k++) {
00052       rcard:rans=random(100)+1; j=tag=0;
00053       while(rans>tag) tag+=Per[i][j++];
00054       j--;if (D[j].qty==D[j].pic) goto rcard;
00055       tag=random(D[j].qty)+D[j].fir;
00056       while(s[tag]==1) tag=(tag==(D[j].qty+D[j].fir-1))?D[j].fir:tag+1;
00057       s[tag]=1;Data->Events[mx++]=tag;D[j].pic++;
00058     }
00059   for (i=0;i<28;i++) Data->Prestige[i].Place=Data->Prestige[i].mPlace=-1;
00060 
00061 
00062   // EVENT.AI is nowhere to be found so this doesn't make any sense MKM 9/3/93
00063 #if 0
00064   for (j=0;j<30;j++) {
00065 
00066     in=sOpen("EVENT.AI","rb",0);
00067     fseek(in,23*Data->Events[j]+(j&0x01)*23,0);
00068     fread(&chai[0],sizeof chai,1,in);
00069     fclose(in);
00070  
00071     if (j&0x01) {  // Player 1  SOV
00072       for(i=0;i<23;i++) {
00073         if (j==5 && chai[i]>0) Data->P[1].AIpath[i]=chai[i]+2;
00074         else Data->P[1].AIpath[i]+=chai[i];
00075         }
00076       }
00077     else {         // Player 0  US
00078       for(i=0;i<23;i++) {
00079         if (j==4 && chai[i]>0) Data->P[0].AIpath[i]=chai[i]+2;
00080         else Data->P[0].AIpath[i]+=chai[i];
00081         }
00082       }
00083     }
00084 #endif
00085           
00086 
00087    i=-1;
00088    fout=sOpen("REPLAY.DAT","wb",1);
00089    for (j=0;j<200;j++)
00090       fwrite(&Rep,sizeof Rep,1,fout);
00091    fclose(fout);
00092 
00093    fout=sOpen("EVENT.TMP","wb",1);
00094    memset(&oNews,0x00,sizeof oNews);
00095    for (j=0;j<84;j++)
00096          fwrite(&oNews,sizeof (struct oldNews),1,fout);
00097    fclose(fout);
00098 
00099   return;
00100 }
00101 
00102 /** \todo: This code must be split... it's cluttered beyond hope */
00103 void
00104 AstroTurn(void)
00105 {
00106     int i, j, k, l, num, temp, cnt, Compat[5];
00107     int ActTotal[2];            /* Count of active astronauts per player */
00108 
00109     ActTotal[0] = 0;
00110     ActTotal[1] = 0;
00111     cnt = 0;
00112 
00113     /* Count total number of active astronauts */
00114     for (j = 0; j < NUM_PLAYERS; j++)
00115         for (i = 0; i < Data->P[j].AstroCount; i++)
00116             if (Data->P[j].Pool[i].Status == 0)
00117                 ActTotal[j]++;
00118 
00119     /* Update All Astronauts */
00120     for (j = 0; j < NUM_PLAYERS; j++)
00121         if (MAIL == -1 || (MAIL == j))
00122             for (i = 0; i < Data->P[j].AstroCount; i++)
00123             {
00124 
00125                 if (Data->P[j].Pool[i].Moved == 0)  /* Moved to better prog */
00126                     if (Data->P[j].Pool[i].oldAssign <
00127                         Data->P[j].Pool[i].Assign)
00128                         Data->P[j].Pool[i].Mood += 5;
00129 
00130                 /* 1 = dead, 2 = retired */
00131                 if (Data->P[j].Pool[i].Status == 0
00132                     || Data->P[j].Pool[i].Status > 2)
00133                     Data->P[j].Pool[i].Active++;
00134 
00135                 /* Move All unassign astros to limbo */
00136                 if (Data->P[j].Pool[i].Una == 0
00137                     && Data->P[j].Pool[i].Status == 0
00138                     && Data->P[j].Pool[i].Assign != 0)
00139                 {
00140                     Data->P[j].Pool[i].Assign = 0;
00141                     Data->P[j].Pool[i].Moved = 0;
00142                     Data->P[j].Pool[i].Special = 11 + j;
00143                 };
00144 
00145                 if (Data->P[j].Pool[i].Status == 6)
00146                 {                  /* Basic */
00147                     Data->P[j].Pool[i].Special = 7;
00148                     Data->P[j].Pool[i].TrainingLevel =
00149                         Data->P[j].Pool[i].Status;
00150                     Data->P[j].Pool[i].Status = 0;  /* Make Active */
00151                     Data->P[j].Pool[i].Assign = 0;  /* Put in Limbo */
00152                     temp = 0;
00153                     if (random(100) > 70)
00154                         k = 2;
00155                     else
00156                         k = 1;
00157                     while (temp == 0)
00158                     {
00159                         switch (random(5))
00160                         {
00161                             case 0:
00162                                 if (Data->P[j].Pool[i].Cap == 4)
00163                                     break;
00164                                 else
00165                                     Data->P[j].Pool[i].Cap += k;
00166                                 if (Data->P[j].Pool[i].Cap > 4)
00167                                     Data->P[j].Pool[i].Cap = 4;
00168                                 temp = 1;
00169                                 break;
00170                             case 1:
00171                                 if (Data->P[j].Pool[i].LM == 4)
00172                                     break;
00173                                 else
00174                                     Data->P[j].Pool[i].LM += k;
00175                                 if (Data->P[j].Pool[i].LM > 4)
00176                                     Data->P[j].Pool[i].LM = 4;
00177                                 temp = 1;
00178                                 break;
00179                             case 2:
00180                                 if (Data->P[j].Pool[i].EVA == 4)
00181                                     break;
00182                                 else
00183                                     Data->P[j].Pool[i].EVA += k;
00184                                 if (Data->P[j].Pool[i].EVA > 4)
00185                                     Data->P[j].Pool[i].EVA = 4;
00186                                 temp = 1;
00187                                 break;
00188                             case 3:
00189                                 if (Data->P[j].Pool[i].Docking == 4)
00190                                     break;
00191                                 else
00192                                     Data->P[j].Pool[i].Docking += k;
00193                                 if (Data->P[j].Pool[i].Docking > 4)
00194                                     Data->P[j].Pool[i].Docking = 4;
00195                                 temp = 1;
00196                                 break;
00197                             case 4:
00198                                 if (Data->P[j].Pool[i].Endurance == 4)
00199                                     break;
00200                                 else
00201                                     Data->P[j].Pool[i].Endurance += k;
00202                                 if (Data->P[j].Pool[i].Endurance > 4)
00203                                     Data->P[j].Pool[i].Endurance = 4;
00204                                 temp = 1;
00205                                 break;
00206                         }
00207                     }
00208                     if (Data->P[j].Pool[i].Cap < 0)
00209                         Data->P[j].Pool[i].Endurance = 0;
00210                     if (Data->P[j].Pool[i].LM < 0)
00211                         Data->P[j].Pool[i].LM = 0;
00212                     if (Data->P[j].Pool[i].EVA < 0)
00213                         Data->P[j].Pool[i].EVA = 0;
00214                     if (Data->P[j].Pool[i].Docking < 0)
00215                         Data->P[j].Pool[i].Docking = 0;
00216                     if (Data->P[j].Pool[i].Endurance < 0)
00217                         Data->P[j].Pool[i].Endurance = 0;
00218 
00219                 }
00220                 else if (Data->P[j].Pool[i].Status == 10)
00221                 {                  /* Advanced Graduation */
00222                     Data->P[j].Pool[i].Special = 8;
00223                     Data->P[j].Pool[i].TrainingLevel =
00224                         Data->P[j].Pool[i].Status;
00225                     Data->P[j].Pool[i].Status = 0;  /* Make Active */
00226                     Data->P[j].Pool[i].Assign = 0;  /* Put in Limbo */
00227                     switch (Data->P[j].Pool[i].Focus - 1)
00228                     {
00229                         case 0:
00230                             Data->P[j].Pool[i].Cap += 2;
00231                             if (Data->P[j].Pool[i].Cap > 4)
00232                                 Data->P[j].Pool[i].Cap = 4;
00233                             break;
00234                         case 1:
00235                             Data->P[j].Pool[i].LM += 2;
00236                             if (Data->P[j].Pool[i].LM > 4)
00237                                 Data->P[j].Pool[i].LM = 4;
00238                             break;
00239                         case 2:
00240                             Data->P[j].Pool[i].EVA += 2;
00241                             if (Data->P[j].Pool[i].EVA > 4)
00242                                 Data->P[j].Pool[i].EVA = 4;
00243                             break;
00244                         case 3:
00245                             Data->P[j].Pool[i].Docking += 2;
00246                             if (Data->P[j].Pool[i].Docking > 4)
00247                                 Data->P[j].Pool[i].Docking = 4;
00248                             break;
00249                         case 4:
00250                             Data->P[j].Pool[i].Endurance += 2;
00251                             if (Data->P[j].Pool[i].Endurance > 4)
00252                                 Data->P[j].Pool[i].Endurance = 4;
00253                             break;
00254                     }
00255 
00256                 }
00257                 else if (Data->P[j].Pool[i].Status == 4
00258                     || Data->P[j].Pool[i].Status == 5)
00259                 {
00260                     Data->P[j].Pool[i].TrainingLevel =
00261                         Data->P[j].Pool[i].Status;
00262                     Data->P[j].Pool[i].Status++;
00263                     temp = 0;
00264                     if (random(10) > 70)
00265                         k = 2;
00266                     else
00267                         k = 1;
00268                     while (temp == 0)
00269                     {
00270                         switch (random(5))
00271                         {
00272                             case 0:
00273                                 if (Data->P[j].Pool[i].Cap == 4)
00274                                     break;
00275                                 else
00276                                     Data->P[j].Pool[i].Cap += k;
00277                                 temp = 1;
00278                                 break;
00279                             case 1:
00280                                 if (Data->P[j].Pool[i].LM == 4)
00281                                     break;
00282                                 else
00283                                     Data->P[j].Pool[i].LM += k;
00284                                 temp = 1;
00285                                 break;
00286                             case 2:
00287                                 if (Data->P[j].Pool[i].EVA == 4)
00288                                     break;
00289                                 else
00290                                     Data->P[j].Pool[i].EVA += k;
00291                                 temp = 1;
00292                                 break;
00293                             case 3:
00294                                 if (Data->P[j].Pool[i].Docking == 4)
00295                                     break;
00296                                 else
00297                                     Data->P[j].Pool[i].Docking += k;
00298                                 temp = 1;
00299                                 break;
00300                             case 4:
00301                                 if (Data->P[j].Pool[i].Endurance == 4)
00302                                     break;
00303                                 else
00304                                     Data->P[j].Pool[i].Endurance += k;
00305                                 temp = 1;
00306                                 break;
00307                         }
00308                     }
00309                 }
00310                 else if (Data->P[j].Pool[i].Status == 7
00311                     || Data->P[j].Pool[i].Status == 8
00312                     || Data->P[j].Pool[i].Status == 9)
00313                 {
00314                     Data->P[j].Pool[i].TrainingLevel =
00315                         Data->P[j].Pool[i].Status;
00316                     Data->P[j].Pool[i].Status++;
00317                 };
00318             };
00319 
00320     for (j = 0; j < NUM_PLAYERS; j++)   /* Player Analysis */
00321     {
00322         if (MAIL == -1 || (MAIL == j))
00323             for (i = 0; i < Data->P[j].AstroCount; i++)
00324             {
00325 
00326                 /* Injury Resolution */
00327                 if (Data->P[j].Pool[i].Status == 3)
00328                 {
00329                     Data->P[j].Pool[i].IDelay--;
00330                     if (Data->P[j].Pool[i].IDelay == 0)
00331                     {
00332                         Data->P[j].Pool[i].Status = 0;
00333                         Data->P[j].Pool[i].Assign = 0;
00334                         Data->P[j].Pool[i].Special = 5;
00335                     }
00336                 }
00337                 /* Mustering Out - even seasons after 8 */
00338                 if ((Data->P[j].Pool[i].Active >= 8)
00339                     && Data->P[j].Pool[i].Status == 0
00340                     && Data->P[j].Pool[i].RDelay == 0)
00341                 {
00342                     num = random(100);
00343                     if (num > 89)
00344                     {              /* Guy retires */
00345                         if (j == 0)
00346                         {
00347                             Data->P[j].Pool[i].RDelay = 3;  /* US Guy Retires in 2 */
00348                             Data->P[j].Pool[i].Special = 1;
00349                         };
00350                         if (j == 1)
00351                         {
00352                             Data->P[j].Pool[i].RDelay = 2;  /* URS Guy Retires in 1 */
00353                             Data->P[j].Pool[i].Special = 1;
00354                         };
00355                         Data->P[j].Pool[i].RetReas = random(6) + 1; /* Reason for Retirement */
00356                     }
00357                 }
00358 
00359                 if (Data->P[j].Other & 1 && Data->P[j].Pool[i].RDelay == 0 &&
00360                     Data->P[j].Pool[i].Status == 0)
00361                 {                  /* Catastrophic Failure */
00362                     num = random(100);
00363                     if (j == 1)
00364                         temp = 89;
00365                     else
00366                         temp = 79;
00367                     if (num > temp && cnt < (ActTotal[j] * .4))
00368                     {              /* Guy retires due to being scared */
00369                         if (j == 0)
00370                         {
00371                             Data->P[j].Pool[i].RDelay = 3;  /* US Guy Retires in 2 */
00372                             Data->P[j].Pool[i].Special = 1;
00373                         };
00374                         if (j == 1)
00375                         {
00376                             Data->P[j].Pool[i].RDelay = 2;  /* URS Guy Retires Now */
00377                             Data->P[j].Pool[i].Special = 1;
00378                         };
00379                         Data->P[j].Pool[i].RetReas = 11;    /* Reason=Scared */
00380                         cnt++;
00381                     };
00382                     cnt = 0;
00383                 };
00384                 /* Training Washout */
00385                 if (Data->P[j].Pool[i].Status >= 4
00386                     && Data->P[j].Pool[i].Status <= 6
00387                     && strncmp(Data->P[j].Pool[i].Name, "ALDRIN", 6) != 0)
00388                 {
00389                     num = random(100);
00390                     if (num > 94)
00391                     {
00392                         num = random(100);
00393                         if (num > 74)
00394                         {
00395                             Data->P[j].Pool[i].Status = 3;
00396                             Data->P[j].Pool[i].IDelay = 2;
00397                             Data->P[j].Pool[i].Special = 9;
00398                         }
00399                         else
00400                         {
00401                             Data->P[j].Pool[i].Status = 2;
00402                             Data->P[j].Pool[i].Special = 10;
00403                             Data->P[j].Pool[i].RetReas = 12;    /* Washout */
00404                         }
00405 
00406                         /** \todo: This is probably a bug! Should be Cap == 0 ?? */
00407                         if (Data->P[j].Pool[i].Cap < 0)
00408                             Data->P[j].Pool[i].Endurance = 0;
00409                         if (Data->P[j].Pool[i].LM < 0)
00410                             Data->P[j].Pool[i].LM = 0;
00411                         if (Data->P[j].Pool[i].EVA < 0)
00412                             Data->P[j].Pool[i].EVA = 0;
00413                         if (Data->P[j].Pool[i].Docking < 0)
00414                             Data->P[j].Pool[i].Docking = 0;
00415                         if (Data->P[j].Pool[i].Endurance < 0)
00416                             Data->P[j].Pool[i].Endurance = 0;
00417                     }
00418                 }
00419 
00420                 if (Data->P[j].Pool[i].RDelay >= 1
00421                     && (Data->P[j].Pool[i].Status > 3
00422                         || Data->P[j].Pool[i].Status == 0))
00423                 {                  /* Actual retirement */
00424                     Data->P[j].Pool[i].RDelay--;
00425                     if (Data->P[j].Pool[i].RDelay == 0)
00426                     {
00427                         Data->P[j].Pool[i].Status = 2;
00428                         Data->P[j].Pool[i].Assign = 0;
00429                         Data->P[j].Pool[i].Special = 2;
00430                     }
00431                 }
00432                 /* END OF SEASON - Positive */
00433                 if (Data->P[j].Other & 4)
00434                 {                  /* Program First */
00435                     Data->P[j].Pool[i].Mood += 5;
00436                     if (Data->P[j].Pool[i].Mis == 2)
00437                         Data->P[j].Pool[i].Mood += 20;  /* Self */
00438                 }
00439 
00440                 if (Data->P[j].Pool[i].Mis == 1)
00441                 {
00442                     if (j == 0 && Data->Def.Ast1 == 0)
00443                         Data->P[j].Pool[i].Mood += 20;
00444                     else
00445                         Data->P[j].Pool[i].Mood += 15;
00446                     if (j == 1 && Data->Def.Ast2 == 0)
00447                         Data->P[j].Pool[i].Mood += 20;
00448                     else
00449                         Data->P[j].Pool[i].Mood += 15;
00450                 }
00451 
00452                 if (Data->Season == 1)
00453                 {                  /* End of turn what the hell 5% happy */
00454                     num = random(100);
00455                     if (num > 94)
00456                         Data->P[j].Pool[i].Mood += 5;
00457                 }
00458 
00459                 temp = 0;
00460                 cnt = Data->P[j].Pool[i].Crew;  /* Crew in */
00461                 l = Data->P[j].Pool[i].Assign;  /* Prog in */
00462 
00463                 for (k = 0; k < ASTRONAUT_FLT_CREW_MAX; k++)
00464                     if (Data->P[j].Pool[Data->P[j].Crew[l][cnt][k] -
00465                             1].Hero == 1)
00466                         temp++;
00467                 if (temp > 1)
00468                     Data->P[j].Pool[i].Mood += 5;   /* Hero Mod */
00469 
00470                 /* END OF SEASON - Negative */
00471 
00472                 /* In Merc for too long */
00473                 if (Data->P[j].Pool[i].Assign == 1
00474                     && Data->P[j].Pool[i].Moved >= 6)
00475                     Data->P[j].Pool[i].Mood -= 4;
00476 
00477                 /* Moved Around */
00478                 if (Data->P[j].Pool[i].Moved == 0)
00479                     Data->P[j].Pool[i].Mood -= 4;
00480 
00481                 // Mission Stuff
00482                 if (Data->P[j].Pool[i].Prime == 3
00483                     || Data->P[j].Pool[i].Prime == 1)
00484                     Data->P[j].Pool[i].Prime = 0;
00485                 if (Data->P[j].Pool[i].Prime == 4
00486                     || Data->P[j].Pool[i].Prime == 2)
00487                     Data->P[j].Pool[i].Prime--;
00488 
00489                 if (Data->P[j].Pool[i].Status != 3)
00490                 {
00491                     if (Data->P[j].Pool[i].Prime == 0)
00492                         Data->P[j].Pool[i].Mood -= 6;
00493                     if (Data->P[j].Pool[i].Prime > 0)
00494                         Data->P[j].Pool[i].Mood -= 3;
00495 
00496                     /* scrubbed mission */
00497                     if (Data->P[j].Pool[i].Mis == 3)
00498                         Data->P[j].Pool[i].Mood -= 5;
00499                     /* successful mission */
00500                 }
00501                 else
00502                     Data->P[j].Pool[i].Mood -= 4;
00503 
00504                 /* catastrophic death */
00505                 if (Data->P[j].Other & 1)
00506                     Data->P[j].Pool[i].Mood -= 5;
00507 
00508                 /* card death */
00509                 if (Data->P[j].Other & 2)
00510                     Data->P[j].Pool[i].Mood -= random(2) + 1;
00511 
00512                 /* Compatability */
00513                 for (k = 0; k < 5; k++)
00514                     Compat[k] = 0;
00515                 cnt = 0;
00516                 if (Data->P[j].Pool[i].Compat == 1)
00517                 {
00518                     if (Data->P[j].Pool[i].CL == 2)
00519                         Compat[cnt++] = 9;
00520                     Compat[cnt++] = 10;
00521                     Compat[cnt++] = 1;
00522                     Compat[cnt++] = 2;
00523                     if (Data->P[j].Pool[i].CR == 2)
00524                         Compat[cnt++] = 3;
00525                 }
00526                 if (Data->P[j].Pool[i].Compat == 2)
00527                 {
00528                     if (Data->P[j].Pool[i].CL == 2)
00529                         Compat[cnt++] = 10;
00530                     Compat[cnt++] = 1;
00531                     Compat[cnt++] = 2;
00532                     Compat[cnt++] = 3;
00533                     if (Data->P[j].Pool[i].CR == 2)
00534                         Compat[cnt++] = 4;
00535                 }
00536                 if (Data->P[j].Pool[i].Compat >= 3
00537                     && Data->P[j].Pool[i].Compat <= 8)
00538                 {
00539                     if (Data->P[j].Pool[i].CL == 2)
00540                         Compat[cnt++] = Data->P[j].Pool[i].Compat - 2;
00541                     Compat[cnt++] = Data->P[j].Pool[i].Compat - 1;
00542                     Compat[cnt++] = Data->P[j].Pool[i].Compat;
00543                     Compat[cnt++] = Data->P[j].Pool[i].Compat + 1;
00544                     if (Data->P[j].Pool[i].CR == 2)
00545                         Compat[cnt++] = Data->P[j].Pool[i].Compat + 2;
00546                 }
00547                 if (Data->P[j].Pool[i].Compat == 9)
00548                 {
00549                     if (Data->P[j].Pool[i].CL == 2)
00550                         Compat[cnt++] = 7;
00551                     Compat[cnt++] = 8;
00552                     Compat[cnt++] = 9;
00553                     Compat[cnt++] = 10;
00554                     if (Data->P[j].Pool[i].CR == 2)
00555                         Compat[cnt++] = 1;
00556                 }
00557                 if (Data->P[j].Pool[i].Compat == 10)
00558                 {
00559                     if (Data->P[j].Pool[i].CL == 2)
00560                         Compat[cnt++] = 8;
00561                     Compat[cnt++] = 9;
00562                     Compat[cnt++] = 10;
00563                     Compat[cnt++] = 1;
00564                     if (Data->P[j].Pool[i].CR == 2)
00565                         Compat[cnt++] = 2;
00566                 }
00567                 temp = 0;
00568                 for (k = 0; k < ASTRONAUT_FLT_CREW_MAX; k++)
00569                 {
00570                     for (l = 0; l < cnt; l++)
00571                     {
00572                         if (Compat[l] ==
00573                             Data->P[j].Crew[Data->P[j].Pool[i].Assign][Data->
00574                                 P[j].Pool[i].Crew][k])
00575                             temp++;
00576                     }
00577                 }
00578 
00579                 if (temp > 0)
00580                     Data->P[j].Pool[i].Mood -= 4;
00581 
00582                 /* Final record updating */
00583 
00584                 if (Data->P[j].Pool[i].Mood > 100)
00585                     Data->P[j].Pool[i].Mood = 100;
00586                 if (Data->P[j].Pool[i].Mood < 0)
00587                     Data->P[j].Pool[i].Mood = 0;
00588                 Data->P[j].Pool[i].Moved++;
00589 
00590                 /* Retirement stuff */
00591 
00592                 if (Data->P[j].Pool[i].Mood < 20
00593                     && Data->P[j].Pool[i].RDelay == 0
00594                     && Data->P[j].Pool[i].Status == 0)
00595                 {
00596                     if (j == 0)
00597                     {
00598                         Data->P[j].Pool[i].RDelay = 2;  /* US Guy Retires in 2 */
00599                         Data->P[j].Pool[i].Special = 1;
00600                     };
00601                     if (j == 1)
00602                     {
00603                         Data->P[j].Pool[i].Status = 2;  /* URS Guy Retires Now */
00604                         Data->P[j].Pool[i].Special = 2;
00605                     };
00606                     Data->P[j].Pool[i].RetReas = 13;    /* Reason=Unhappy */
00607                 }
00608                 Data->P[j].Pool[i].Mis = 0;
00609             }
00610         Data->P[j].Other = 0;
00611     }
00612 
00613     //      break all groups with dead, injured or retired folks.
00614     for (j = 0; j < NUM_PLAYERS; j++)   // for each player
00615     {
00616         if (MAIL == -1 || (MAIL == j))
00617             for (k = 0; k < ASTRONAUT_POOLS; k++)
00618             {
00619                 for (l = 0; l < ASTRONAUT_CREW_MAX; l++)
00620                 {
00621                     temp = 0;
00622                     if (Data->P[j].Gcnt[k][l] > 0)
00623                     {
00624                         for (i = 0; i < Data->P[j].Gcnt[k][l]; i++)
00625                         {
00626                             if (Data->P[j].Pool[Data->P[j].Crew[k][l][i] -
00627                                     1].Status == 1
00628                                 || Data->P[j].Pool[Data->P[j].Crew[k][l][i] -
00629                                     1].Status == 2
00630                                 || Data->P[j].Pool[Data->P[j].Crew[k][l][i] -
00631                                     1].Status == 3)
00632                                 temp++;
00633                         }          /* for i */
00634                         if (temp > 0)
00635                         {
00636                             for (i = 0; i < Data->P[j].Gcnt[k][l]; i++)
00637                             {
00638                                 Data->P[j].Pool[Data->P[j].Crew[k][l][i] -
00639                                     1].oldAssign =
00640                                     Data->P[j].Pool[Data->P[j].
00641                                     Crew[k][l][i] - 1].Assign;
00642                                 Data->P[j].Pool[Data->P[j].Crew[k][l][i] -
00643                                     1].Assign = 0;
00644                                 Data->P[j].Pool[Data->P[j].Crew[k][l][i] -
00645                                     1].Prime = 0;
00646                                 Data->P[j].Pool[Data->P[j].Crew[k][l][i] -
00647                                     1].Crew = 0;
00648                                 Data->P[j].Pool[Data->P[j].Crew[k][l][i] -
00649                                     1].Task = 0;
00650                                 Data->P[j].Pool[Data->P[j].Crew[k][l][i] -
00651                                     1].Moved = 0;
00652                                 if (Data->P[j].Pool[Data->P[j].
00653                                         Crew[k][l][i] - 1].Special == 0)
00654                                     Data->P[j].Pool[Data->P[j].
00655                                         Crew[k][l][i] - 1].Special = 6;
00656                                 Data->P[j].Crew[k][l][i] = 0;
00657                             }      /* for i */
00658                             Data->P[j].Gcnt[k][l] = 0;
00659                         }          /* it temp */
00660                     }              /* if Gcnt */
00661                 }                  /* for l */
00662             }                      /* for k */
00663     }                              /* for j */
00664 
00665     if (MAIL == -1 || MAIL == 0)
00666         UpdateHardTurn(0);
00667     if (MAIL == -1 || MAIL == 1)
00668         UpdateHardTurn(1);
00669 
00670     return;
00671 }
00672 
00673 void Update(void)
00674 {
00675   int i,j,k;
00676   char p0,p1;
00677   char tName[20];
00678 
00679   if (Data->P[0].DMod>0) Data->P[0].DMod--;
00680   if (Data->P[1].DMod>0) Data->P[1].DMod--;
00681 
00682   if (Data->P[0].AstroDelay!=0) Data->P[0].AstroDelay-=1;
00683   if (Data->P[1].AstroDelay!=0) Data->P[1].AstroDelay-=1;
00684   for (j=0;j<NUM_PLAYERS;j++) {
00685     for (i=0;i<MAX_MISSIONS;i++) {
00686       memcpy(&Data->P[j].Mission[i],&Data->P[j].Future[i],sizeof (struct MissionType));
00687       memset(&Data->P[j].Future[i],0x00,sizeof (struct MissionType));
00688       strcpy(Data->P[j].Future[i].Name,"UNDETERMINED");
00689 
00690    }; /* End j for loop */
00691   }; /* End i for loop */
00692 
00693   // Name the Missions
00694 
00695   for (j=0;j<NUM_PLAYERS;j++) {
00696     for (i=0;i<MAX_MISSIONS;i++) {
00697     if (Data->P[j].Mission[i].MissionCode==1) {
00698       Data->P[j].Mission[i].Patch=-1;
00699       strcpy(&tName[0],&Data->P[j].Probe[0].Name[0]);strcat(&tName[0]," ");
00700       strcat(&tName[0],&Nums[(Data->P[j].Probe[0].Code)%30][0]);
00701       strcpy(&Data->P[j].Mission[i].Name[0],&tName[0]); // copy into struct
00702       Data->P[j].Probe[0].Code++;  // Increase Planned Mission Count
00703     } else if (Data->P[j].Mission[i].MissionCode==8) {
00704       Data->P[j].Mission[i].Patch=-1;
00705       strcpy(&tName[0],&Data->P[j].Probe[2].Name[0]);strcat(&tName[0]," ");
00706       strcat(&tName[0],&Nums[(Data->P[j].Probe[2].Code)%30][0]);
00707       strcpy(&Data->P[j].Mission[i].Name[0],&tName[0]); // copy into struct
00708       Data->P[j].Probe[2].Code++;  // Increase Planned Mission Count
00709     } else if (Data->P[j].Mission[i].MissionCode==7 || 
00710         (Data->P[j].Mission[i].MissionCode>=9 && 
00711         Data->P[j].Mission[i].MissionCode<=13)) {
00712       Data->P[j].Mission[i].Patch=-1;
00713       strcpy(&tName[0],&Data->P[j].Probe[1].Name[0]);strcat(&tName[0]," ");
00714       strcat(&tName[0],&Nums[Data->P[j].Probe[1].Code][0]);
00715       strcpy(&Data->P[j].Mission[i].Name[0],&tName[0]); // copy into struct
00716       Data->P[j].Probe[1].Code++;  // Increase Planned Mission Count
00717     } else if (Data->P[j].Mission[i].MissionCode>0) {
00718       if (Data->P[j].Mission[i].Joint==0) {
00719         k=Data->P[j].Mission[i].Prog-1;
00720         Data->P[j].Mission[i].Patch=Data->P[j].Manned[k].Code%10;
00721         strcpy(&tName[0],&Data->P[j].Manned[k].Name[0]);strcat(&tName[0]," ");
00722         strcat(&tName[0],&Nums[Data->P[j].Manned[k].Code][0]);
00723         strcpy(&Data->P[j].Mission[i].Name[0],&tName[0]); // copy into struct
00724         Data->P[j].Manned[k].Code++;  // Increase Planned Mission Count
00725       } else {
00726         if (Data->P[j].Mission[i].Prog==0) {
00727           k=Data->P[j].Mission[i+1].Prog-1;
00728           Data->P[j].Mission[i].Patch=Data->P[j].Manned[k].Code%10;
00729           strcpy(&tName[0],&Data->P[j].Manned[k].Name[0]);strcat(&tName[0]," ");
00730           strcat(&tName[0],&Nums[Data->P[j].Manned[k].Code][0]);
00731           strcpy(&Data->P[j].Mission[i].Name[0],&tName[0]); // copy into struct
00732         } else {
00733           k=Data->P[j].Mission[i].Prog-1;
00734           Data->P[j].Mission[i].Patch=Data->P[j].Manned[k].Code%10;
00735           strcpy(&tName[0],&Data->P[j].Manned[k].Name[0]);strcat(&tName[0]," ");
00736           strcat(&tName[0],&Nums[Data->P[j].Manned[k].Code][0]);
00737           strcpy(&Data->P[j].Mission[i].Name[0],&tName[0]); // copy into struct
00738           Data->P[j].Manned[k].Code++;  // Increase Planned Mission Count
00739         }
00740     }
00741       }
00742     }
00743   }
00744 
00745   // Reset R&D Purchasing Ability
00746   memset(Data->P[0].Buy, 0x00, sizeof(Data->P[0].Buy));
00747   memset(Data->P[1].Buy, 0x00, sizeof(Data->P[1].Buy));
00748   
00749   AstroTurn();   /* Process all astronauts */
00750 
00751   for (j=0;j<NUM_PLAYERS;j++) {
00752     Data->P[j].RDMods=0;
00753     if (Data->P[j].RDYear>0) {
00754       Data->P[j].RDMods=Data->P[j].RDYear;
00755       Data->P[j].RDYear=0;
00756     };
00757   Data->P[j].TurnOnly=Data->P[j].Other=Data->P[j].Block=0;
00758   };
00759 
00760   // Update any delayed Missions
00761   p0=p1=0;
00762   while (p0<Data->P[0].PastMis && p1<Data->P[1].PastMis) {
00763      if (Data->P[0].History[p0].MissionYear < Data->P[1].History[p1].MissionYear) {
00764         TestFMis(0,p0);p0++;}
00765      else if (Data->P[0].History[p0].MissionYear > Data->P[1].History[p1].MissionYear) {
00766         TestFMis(1,p1);p1++;}
00767      else if (Data->P[0].History[p0].MissionYear == Data->P[1].History[p1].MissionYear) {
00768         if (Data->P[0].History[p0].Month < Data->P[1].History[p1].Month) {
00769            TestFMis(0,p0);p0++;}
00770         else if (Data->P[0].History[p0].Month > Data->P[1].History[p1].Month) {
00771            TestFMis(1,p1);p1++;}
00772         else if (Data->P[0].History[p0].Month==Data->P[1].History[p1].Month) {
00773            if (Data->P[0].Budget<Data->P[1].Budget && (p0 < Data->P[0].PastMis)) 
00774               {TestFMis(0,p0);p0++;}
00775            else if (Data->P[0].Budget>Data->P[1].Budget && (p1 < Data->P[1].PastMis))
00776               {TestFMis(1,p1);p1++;}
00777            else if ((p0 < Data->P[0].PastMis) && (p1 < Data->P[1].PastMis) ){
00778               if (random(100) < 50 ) {TestFMis(0,p0);p0++;}
00779               else {TestFMis(1,p1);p1++;}
00780            }
00781         }
00782      }
00783   };  // end while
00784 
00785   memset(pNeg,0x00,sizeof pNeg);
00786 
00787   while (p0<Data->P[0].PastMis) {TestFMis(0,p0);p0++;}
00788   while (p1<Data->P[1].PastMis) {TestFMis(1,p1);p1++;}
00789 
00790   // Fix Prestige Values for Mars, Jup, Sat.
00791   for (j=0;j<NUM_PLAYERS;j++) {
00792      Data->Prestige[4].Goal[j]=0; // Clear Mars
00793      Data->Prestige[5].Goal[j]=0; // Clear Jupiter
00794      Data->Prestige[6].Goal[j]=0; // Clear Saturn
00795      Data->P[j].Probe[0].Failures=Data->P[j].Probe[2].Failures=0;
00796      Data->P[j].Probe[0].Used=Data->P[j].Probe[2].Used=0;
00797 
00798      for (i=0;i<Data->P[j].PastMis;i++) {
00799        if (Data->P[j].History[i].Event==0) {
00800          switch (Data->P[j].History[i].MissionCode)
00801          {
00802           case 10: Data->Prestige[4].Goal[j]++;break;  // Mars
00803           case 12: Data->Prestige[5].Goal[j]++;break;  // Juptier
00804           case 13: Data->Prestige[6].Goal[j]++;break;  // Saturn
00805           default: break;
00806          }
00807        }
00808 
00809        switch (Data->P[j].History[i].MissionCode) {
00810           case 1: if (Data->P[j].History[i].spResult!=1)
00811                      Data->P[j].Probe[0].Failures++;
00812                   Data->P[j].Probe[0].Used++;
00813                   break;
00814           case 8: if (Data->P[j].History[i].spResult!=1)
00815                      Data->P[j].Probe[2].Failures++;
00816                   Data->P[j].Probe[2].Used++;
00817                   break;
00818        }
00819 
00820      }
00821   }
00822 
00823   return;
00824 }
00825 
00826 void UpdAll(char side)
00827 {
00828   int i,k;
00829   char p0=0,p1=0;
00830   char tName[20];
00831 
00832   if (Data->P[side].DMod>0) Data->P[side].DMod--;
00833   if (Data->P[side].AstroDelay!=0) Data->P[side].AstroDelay-=1;
00834 
00835   for (i=0;i<3;i++)
00836    {
00837     memcpy(&Data->P[side].Mission[i],&Data->P[side].Future[i],sizeof (struct MissionType));
00838     memset(&Data->P[side].Future[i],0x00,sizeof (struct MissionType));
00839     strcpy(Data->P[side].Future[i].Name,"UNDETERMINED");
00840    }; 
00841 
00842   for (i=0;i<3;i++) {
00843     if (Data->P[side].Mission[i].MissionCode==1) {
00844       Data->P[side].Mission[i].Patch=-1;
00845       strcpy(&tName[0],&Data->P[side].Probe[0].Name[0]);strcat(&tName[0]," ");
00846       strcat(&tName[0],&Nums[(Data->P[side].Probe[0].Code)%30][0]);
00847       strcpy(&Data->P[side].Mission[i].Name[0],&tName[0]); // copy into struct
00848       Data->P[side].Probe[0].Code++;  // Increase Planned Mission Count
00849     } else if (Data->P[side].Mission[i].MissionCode==8) {
00850       Data->P[side].Mission[i].Patch=-1;
00851       strcpy(&tName[0],&Data->P[side].Probe[2].Name[0]);strcat(&tName[0]," ");
00852       strcat(&tName[0],&Nums[(Data->P[side].Probe[2].Code)%30][0]);
00853       strcpy(&Data->P[side].Mission[i].Name[0],&tName[0]); // copy into struct
00854       Data->P[side].Probe[2].Code++;  // Increase Planned Mission Count
00855     } else if (Data->P[side].Mission[i].MissionCode==7 || 
00856         (Data->P[side].Mission[i].MissionCode>=9 && 
00857         Data->P[side].Mission[i].MissionCode<=13)) {
00858       Data->P[side].Mission[i].Patch=-1;
00859       strcpy(&tName[0],&Data->P[side].Probe[1].Name[0]);strcat(&tName[0]," ");
00860       strcat(&tName[0],&Nums[Data->P[side].Probe[1].Code][0]);
00861       strcpy(&Data->P[side].Mission[i].Name[0],&tName[0]); // copy into struct
00862       Data->P[side].Probe[1].Code++;  // Increase Planned Mission Count
00863     } else if (Data->P[side].Mission[i].MissionCode>0) {
00864       if (Data->P[side].Mission[i].Joint==0) {
00865         k=Data->P[side].Mission[i].Prog-1;
00866         Data->P[side].Mission[i].Patch=Data->P[side].Manned[k].Code%10;
00867         strcpy(&tName[0],&Data->P[side].Manned[k].Name[0]);strcat(&tName[0]," ");
00868         strcat(&tName[0],&Nums[Data->P[side].Manned[k].Code][0]);
00869         strcpy(&Data->P[side].Mission[i].Name[0],&tName[0]); // copy into struct
00870         Data->P[side].Manned[k].Code++;  // Increase Planned Mission Count
00871       } else {
00872         if (Data->P[side].Mission[i].Prog==0) {
00873           k=Data->P[side].Mission[i+1].Prog-1;
00874           Data->P[side].Mission[i].Patch=Data->P[side].Manned[k].Code%10;
00875           strcpy(&tName[0],&Data->P[side].Manned[k].Name[0]);strcat(&tName[0]," ");
00876           strcat(&tName[0],&Nums[Data->P[side].Manned[k].Code][0]);
00877           strcpy(&Data->P[side].Mission[i].Name[0],&tName[0]); // copy into struct
00878         } else {
00879           k=Data->P[side].Mission[i].Prog-1;
00880           Data->P[side].Mission[i].Patch=Data->P[side].Manned[k].Code%10;
00881           strcpy(&tName[0],&Data->P[side].Manned[k].Name[0]);strcat(&tName[0]," ");
00882           strcat(&tName[0],&Nums[Data->P[side].Manned[k].Code][0]);
00883           strcpy(&Data->P[side].Mission[i].Name[0],&tName[0]); // copy into struct
00884           Data->P[side].Manned[k].Code++;  // Increase Planned Mission Count
00885         }
00886       }
00887    }    
00888  }
00889 
00890   // Reset R&D Purchasing Ability
00891   memset(Data->P[side].Buy, 0x00, sizeof(Data->P[side].Buy));
00892   
00893   AstroTurn();   /* Process all astronauts */
00894 
00895   Data->P[side].RDMods=0;
00896   if (Data->P[side].RDYear>0)
00897    {
00898     Data->P[side].RDMods=Data->P[side].RDYear;
00899     Data->P[side].RDYear=0;
00900    };
00901   Data->P[side].TurnOnly=Data->P[side].Other=Data->P[side].Block=0;
00902 
00903 
00904  if (side==1) {
00905   p0=p1=0;
00906   while (p0<Data->P[0].PastMis && p1<Data->P[1].PastMis)
00907    {
00908     if (Data->P[0].History[p0].MissionYear < Data->P[1].History[p1].MissionYear) {
00909      TestFMis(0,p0);p0++;}
00910     else if (Data->P[0].History[p0].MissionYear > Data->P[1].History[p1].MissionYear) {
00911         TestFMis(1,p1);p1++;}
00912     else if (Data->P[0].History[p0].MissionYear == Data->P[1].History[p1].MissionYear) {
00913         if (Data->P[0].History[p0].Month < Data->P[1].History[p1].Month) {
00914            TestFMis(0,p0);p0++;}
00915         else if (Data->P[0].History[p0].Month > Data->P[1].History[p1].Month) {
00916            TestFMis(1,p1);p1++;}
00917         else if (Data->P[0].History[p0].Month==Data->P[1].History[p1].Month) {
00918            if (Data->P[0].Budget<Data->P[1].Budget && (p0 < Data->P[0].PastMis)) 
00919               {TestFMis(0,p0);p0++;}
00920            else if (Data->P[0].Budget>Data->P[1].Budget && (p1 < Data->P[1].PastMis))
00921               {TestFMis(1,p1);p1++;}
00922            else if ((p0 < Data->P[0].PastMis) && (p1 < Data->P[1].PastMis) ){
00923               if (random(100) < 50 ) {TestFMis(0,p0);p0++;}
00924               else {TestFMis(1,p1);p1++;}
00925            }
00926         }
00927      }
00928   };  // end while
00929  } 
00930 
00931   memset(pNeg,0x00,sizeof pNeg);
00932 
00933   if (side==1)
00934    {
00935     while (p0<Data->P[0].PastMis) {TestFMis(0,p0);p0++;}
00936     while (p1<Data->P[1].PastMis) {TestFMis(1,p1);p1++;}
00937    }
00938 
00939   // Fix Prestige Values for Mars, Jup, Sat.
00940   Data->Prestige[4].Goal[side]=0; // Clear Mars
00941   Data->Prestige[5].Goal[side]=0; // Clear Jupiter
00942   Data->Prestige[6].Goal[side]=0; // Clear Saturn
00943   Data->P[side].Probe[0].Failures=Data->P[side].Probe[2].Failures=0;
00944   Data->P[side].Probe[0].Used=Data->P[side].Probe[2].Used=0;
00945 
00946   for (i=0;i<Data->P[side].PastMis;i++)
00947    {
00948     if (Data->P[side].History[i].Event==0)
00949      {
00950       switch (Data->P[side].History[i].MissionCode)
00951        {
00952         case 10: Data->Prestige[4].Goal[side]++;break;  // Mars
00953         case 12: Data->Prestige[5].Goal[side]++;break;  // Juptier
00954         case 13: Data->Prestige[6].Goal[side]++;break;  // Saturn
00955         default: break;
00956        }
00957      }
00958      switch (Data->P[side].History[i].MissionCode)
00959       {
00960        case 1:if (Data->P[side].History[i].spResult!=1)
00961                Data->P[side].Probe[0].Failures++;
00962                Data->P[side].Probe[0].Used++;
00963               break;
00964        case 8:if (Data->P[side].History[i].spResult!=1)
00965                Data->P[side].Probe[2].Failures++;
00966               Data->P[side].Probe[2].Used++;
00967               break;
00968        }
00969    }
00970  return;
00971 }
00972 
00973 void
00974 TestFMis(int j, int i)
00975 {
00976     int k;
00977 
00978     if (Data->P[j].History[i].Saf == 0)
00979         return;
00980     if (Data->P[j].History[i].Event > 0)
00981     {
00982         Data->P[j].History[i].Event--;
00983         if (random(100) > Data->P[j].History[i].Saf)
00984         {                          /* Failed Mission */
00985             k = Data->P[j].History[i].MissionCode;
00986             Data->P[j].History[i].Event = Data->P[j].History[i].Saf = 0;
00987             Data->P[j].History[i].Prestige =
00988                 PrestNeg(j, (k == 10) ? 4 : (k == 12) ? 5 : 6);
00989             Data->P[j].Plans |= (k == 10) ? 0x01 : (k == 12) ? 0x02 : 0x04;
00990             Data->P[j].History[i].spResult = 5000;
00991         }
00992         if (Data->P[j].History[i].Event == 0
00993             && Data->P[j].History[i].Prestige == 0)
00994         {
00995             k = Data->P[j].History[i].MissionCode;
00996             Data->P[j].History[i].Prestige =
00997                 Set_Goal(j, (k == 10) ? 4 : (k == 12) ? 5 : 6, 3);
00998             Data->P[j].Plans |= (k == 10) ? 0x10 : (k == 12) ? 0x20 : 0x40;
00999             Data->P[j].History[i].spResult = 1;
01000             Data->P[j].History[i].Saf = 0;
01001         }
01002     };
01003 }
01004 
01005 /** Update equipment
01006  * \todo limit of hardcoded 28 hardware types
01007  * 
01008  * \todo Should this not handle all four types of hardware?
01009  */
01010 void
01011 UpdateHardTurn(char plr)
01012 {
01013     int i;
01014     Equipment *px;
01015 
01016     for (i = 0; i < 28; i++)
01017     {
01018         px = (Equipment *) & Data->P[plr].Probe[i];
01019         if (px->Delay > 0)
01020             px->Delay--;
01021         if (px->Num >= 0)
01022             px->Seas++;
01023         px->Spok = 0;
01024     }
01025 }
01026 
01027 /* vim: set noet ts=4 sw=4 tw=77: */

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