endgame.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 endgame.c End Game Routines
00019  */
00020 
00021 #include "Buzz_inc.h"
00022 #include "externs.h"
00023 
00024 #define NUM_LIGHTS 100
00025 #define FLY_TIME 20
00026 #define GRAVITY 0.6
00027 #define FRICTION 0.3
00028 #define PI 3.1415926
00029 #define MAXINITSPEED 270
00030 #define MAXWAIT 1
00031 #define PutPixel(x,y,col) grPutPixel(x,y,col)
00032 
00033 const int draw_projectiles = 0;
00034 
00035 extern char Month[12][11];
00036 extern char AI[2];
00037 extern char Nums[30][7];
00038 extern char Option,MAIL;
00039 char PF[29][40]={
00040     "ORBITAL SATELLITE","LUNAR FLYBY","MERCURY FLYBY","VENUS FLYBY",
00041     "MARS FLYBY","JUPITER FLYBY","SATURN FLYBY","LUNAR PROBE LANDING",
00042     "DURATION LEVEL F","DURATION LEVEL E","DURATION LEVEL D",
00043     "DURATION LEVEL C","DURATION LEVEL B","ONE-PERSON CRAFT",
00044     "TWO-PERSON CRAFT","THREE-PERSON CRAFT","MINISHUTTLE","FOUR-PERSON CRAFT",
00045     "MANNED ORBITAL","MANNED LUNAR PASS","MANNED LUNAR ORBIT",
00046     "MANNED RESCUE ATTEMPT","MANNED LUNAR LANDING","ORBITING LAB",
00047     "MANNED DOCKING","WOMAN IN SPACE","SPACE WALK","MANNED SPACE MISSION"};
00048 
00049 
00050 char
00051 Burst(char win)
00052 {
00053     float Spsn[2];
00054     char R_value = 0;
00055     struct PROJECTILE
00056     {
00057         char clr;
00058         float vel[2];
00059         float psn[2];
00060         i16 per;
00061     } Bomb[NUM_LIGHTS];
00062     int lp1, lp2, Region, xx, yy;
00063     float Ang, Spd, InitSpd;
00064     char clr = 1;
00065 
00066     key = 0;
00067     strncpy(IDT, "i144", 4);
00068     strncpy(IKEY, "k044", 4);
00069     gxGetImage(&vhptr, 0, 0, 319, 199, 0);
00070     while (1)
00071     {
00072         Region = random(100);
00073         if (Region < 60)
00074         {
00075             Spsn[0] = 132 + random(187);
00076             Spsn[1] = 5 + random(39);
00077         }
00078         else
00079         {
00080             Spsn[0] = 178 + random(66);
00081             Spsn[1] = 11 + random(33);
00082         }
00083         InitSpd = random(MAXINITSPEED);
00084         for (lp1 = 0; lp1 < NUM_LIGHTS; lp1++)
00085         {
00086             Ang = random(2 * PI);
00087             Spd = random(InitSpd);
00088             Bomb[lp1].psn[0] = Spsn[0];
00089             Bomb[lp1].psn[1] = Spsn[1];
00090             Bomb[lp1].vel[0] = Spd * cos(Ang);
00091             Bomb[lp1].vel[1] = Spd * sin(Ang);
00092             Bomb[lp1].clr = clr;
00093             Bomb[lp1].per = random(FLY_TIME);
00094         }
00095         for (lp1 = 0; lp1 < FLY_TIME; lp1++)
00096         {
00097             for (lp2 = 0; lp2 < NUM_LIGHTS; lp2++)
00098             {
00099                 xx = Bomb[lp2].psn[0];
00100                 yy = Bomb[lp2].psn[1];
00101                 /* This is overkill for pixels, but let's see... */
00102                 if (xx >= 0 && xx < 320 && yy >= 0 && yy <= 172)
00103                 {
00104                     PutPixel(xx, yy, vhptr.vptr[xx + 320 * yy]);
00105                     if (draw_projectiles)
00106                         av_need_update_xy(xx, yy, xx, yy);
00107                 }
00108                 key = 0;
00109                 /* We can't wait 30 ms on default timer */
00110                 if (draw_projectiles)
00111                     GetMouse_fast();
00112                 else
00113                     GetMouse();
00114                 if (key > 0 || mousebuttons > 0)
00115                 {
00116                     if ((x >= 14 && y >= 182 && x <= 65 && y <= 190
00117                             && mousebuttons > 0) || key == 'H')
00118                         R_value = 1;
00119                     if ((x >= 74 && y >= 182 && x <= 125 && y <= 190
00120                             && mousebuttons > 0) || key == 'S')
00121                         R_value = 2;
00122                     if ((x >= 134 && y >= 182 && x <= 185 && y <= 190
00123                             && mousebuttons > 0) || key == 'P')
00124                         R_value = 3;
00125                     if ((x >= 194 && y >= 182 && x <= 245 && y <= 190
00126                             && mousebuttons > 0) || key == 'M')
00127                         R_value = 4;
00128                     if ((x >= 254 && y >= 182 && x <= 305 && y <= 190
00129                             && mousebuttons > 0) || key == K_ENTER)
00130                         R_value = 5;
00131                     if (R_value > 0)
00132                     {
00133 
00134                         gxPutImage(&vhptr, gxSET, 0, 0, 0);
00135                         strncpy(IDT, "i144", 4);
00136                         strncpy(IKEY, "k044", 4);
00137 
00138                         return (R_value);
00139                     }
00140                 }
00141                 Bomb[lp2].vel[1] = Bomb[lp2].vel[1] + GRAVITY;
00142                 Bomb[lp2].vel[0] = Bomb[lp2].vel[0] * FRICTION;
00143                 Bomb[lp2].vel[1] = Bomb[lp2].vel[1] * FRICTION;
00144 
00145                 Bomb[lp2].psn[0] =
00146                     (float) Bomb[lp2].psn[0] + Bomb[lp2].vel[0];
00147                 Bomb[lp2].psn[1] =
00148                     (float) Bomb[lp2].psn[1] + Bomb[lp2].vel[1];
00149                 xx = Bomb[lp2].psn[0];
00150                 yy = Bomb[lp2].psn[1];
00151                 if (win == 0)
00152                 {
00153                     if (clr == 1)
00154                         clr = 6;
00155                     else if (clr == 6)
00156                         clr = 9;
00157                     else if (clr == 9)
00158                         clr = 1;
00159                 }
00160                 else
00161                 {
00162                     if (clr == 1)
00163                         clr = 9;
00164                     else if (clr == 9)
00165                         clr = 11;
00166                     else if (clr == 11)
00167                         clr = 9;
00168                 }
00169                 if (lp1 < Bomb[lp2].per && (xx >= 0 && xx < 320 && yy >= 0
00170                         && yy <= 172))
00171                 {
00172                     PutPixel(xx, yy, clr);
00173                     if (draw_projectiles)
00174                         av_need_update_xy(xx, yy, xx, yy);
00175                 }
00176             }
00177             /* XXX: need to optimize SDL_Scale2x for this to work */
00178             if (draw_projectiles)
00179                 av_sync();
00180         }
00181         for (lp2 = 0; lp2 < NUM_LIGHTS; lp2++)
00182         {
00183             xx = Bomb[lp2].psn[0];
00184             yy = Bomb[lp2].psn[1];
00185             if (xx >= 0 && xx < 320 && yy >= 0 && yy <= 172)
00186             {
00187                 PutPixel(xx, yy, vhptr.vptr[xx + 320 * yy]);
00188                 if (draw_projectiles)
00189                     av_need_update_xy(xx, yy, xx, yy);
00190             }
00191         }
00192     }                              // end while
00193 
00194 }
00195 
00196 void EndGame(char win,char pad)
00197 {
00198  int i=0,r,gork;
00199  char miss,prog,man1,man2,man3,man4,bud;
00200 
00201  
00202  FadeOut(2,pal,10,0,0);
00203  strncpy(IDT,"i000",4);strncpy(IKEY,"k000",4);
00204  gxClearDisplay(0,0);
00205  ShBox(0,0,319,22);InBox(3,3,30,19);
00206  IOBox(242,3,315,19);
00207  ShBox(0,24,319,199);RectFill(5,28,314,195,0);
00208  RectFill(5,105,239,110,3);ShBox(101,102,218,113);
00209  grSetColor(6);PrintAt(112,110,"ALTERNATE HISTORY");
00210  if (win==0) DispBig(34,5,"US WINS",1,-1);
00211    else DispBig(34,5,"USSR WINS",1,-1);
00212  FlagSm(win,4,4);
00213  grSetColor(1);PrintAt(258,13,"CONTINUE");
00214 
00215  if (Option==-1 && MAIL==-1) miss=Data->P[win].Mission[pad].MissionCode;
00216   else {
00217    miss=Data->P[win].History[Data->Prestige[22].Indec].MissionCode;
00218   }
00219 
00220  grSetColor(6);PrintAt(10,40,"MISSION: ");grSetColor(8);
00221   if (miss==55  || miss==56 || miss==57) i=1; else i=0;
00222 
00223  MissionName(miss,53,40,24);
00224  grSetColor(6);
00225  PrintAt(10,50,"YEAR: ");grSetColor(8);PrintAt(0,0,"19");DispNum(0,0,Data->Year);
00226 
00227  if (Option==-1 && MAIL==-1)
00228   {
00229    grSetColor(6);PrintAt(75,50,"MONTH: ");grSetColor(8);PrintAt(0,0,Month[Data->P[win].Mission[pad].Month]);
00230    grSetColor(6);PrintAt(10,60,"CAPSULE: ");grSetColor(8);PrintAt(0,0,&Data->P[win].Mission[pad].Name[0]);
00231   }
00232  else {
00233    grSetColor(6);PrintAt(75,50,"MONTH: ");grSetColor(8);PrintAt(0,0,Month[Data->Prestige[22].Month]);
00234    grSetColor(6);PrintAt(10,60,"CAPSULE: ");grSetColor(8);
00235    if (MAIL!=-1 || Option==win) PrintAt(0,0,&Data->P[win].History[Data->Prestige[22].Indec].MissionName[0][0]);
00236     else {
00237      prog=Data->P[win].History[Data->Prestige[22].Indec].Hard[i][0]+1;
00238      PrintAt(0,0,&Data->P[win].Manned[prog-1].Name[0]);
00239      PrintAt(0,0," ");PrintAt(0,0,&Nums[Data->P[win].Manned[prog-1].Used][0]);
00240    }
00241  }
00242 
00243 // correct mission pictures
00244  bud=0; // initialize bud
00245  gork=0;
00246 
00247  if (Option==-1 && MAIL==-1) gork=Data->P[win].PastMis-1;
00248   else gork=Data->Prestige[22].Indec;
00249 
00250  if (win==1 && Data->P[win].History[gork].Hard[i][0]>=3) bud=5;
00251    else if (win==0 && Data->P[win].History[gork].Hard[i][0]==4) bud=2;
00252      else bud=((Data->P[win].History[gork].Hard[i][2]-5)+(win*3));
00253  if (bud<0 || bud>5) bud=0+win;
00254  InBox(241,67,313,112);EndPict(242,68,bud,128);
00255  PatchMe(win,270,34,Data->P[win].History[gork].Hard[i][0],Data->P[win].History[gork].Patch[win],32);
00256  man1=Data->P[win].History[gork].Man[i][0]; 
00257  man2=Data->P[win].History[gork].Man[i][1]; 
00258  man3=Data->P[win].History[gork].Man[i][2]; 
00259  man4=Data->P[win].History[gork].Man[i][3]; 
00260 // no astronaut klugge
00261  r=Data->P[win].AstroCount;
00262  if (man1<=1) man1=random(r);
00263  if (man2<=1) man2=random(r);
00264  if (man3<=1) man3=random(r);
00265  if (man4<=1) man4=random(r);
00266  if (!(Option==-1 || Option==win))
00267   {
00268    Data->P[win].History[gork].Man[i][0]=man1; 
00269    Data->P[win].History[gork].Man[i][1]=man2; 
00270    Data->P[win].History[gork].Man[i][2]=man3; 
00271    Data->P[win].History[gork].Man[i][3]=man4; 
00272   }
00273  prog=Data->P[win].History[gork].Hard[i][0]+1;
00274  for (i=1;i<5;i++)
00275    {
00276     grSetColor(6);
00277     switch(i)
00278       {
00279        case 1:if (prog==1) PrintAt(10,70,"CAPSULE PILOT - EVA: ");
00280              else if (prog==2) PrintAt(10,70,"CAPSULE PILOT - DOCKING: ");
00281                   else if (prog>=3) PrintAt(10,70,"COMMAND PILOT: ");
00282                 grSetColor(8);
00283                 if (man1!=-1)
00284                 PrintAt(0,0,&Data->P[win].Pool[man1].Name[0]);
00285                 break;
00286        case 2:if (prog>1 && prog<5)
00287                   PrintAt(10,79,"LM PILOT - EVA: ");
00288                    else if (prog==5) PrintAt(10,79,"LUNAR PILOT: ");
00289                 grSetColor(8);
00290                 if (man2!=-1)
00291                  PrintAt(0,0,&Data->P[win].Pool[man2].Name[0]);
00292                 break;
00293        case 3:if (prog>2 && prog<5)
00294                   PrintAt(10,88,"DOCKING SPECIALIST: ");
00295                  else if (prog==5) PrintAt(10,88,"EVA SPECIALIST: ");
00296                 grSetColor(8);
00297                 if (man3!=-1 && prog>2)
00298                  PrintAt(0,0,&Data->P[win].Pool[man3].Name[0]);
00299                break;
00300        case 4:if (prog==5)
00301               {
00302                PrintAt(10,97,"EVA SPECIALIST: ");
00303                   grSetColor(8);
00304                   if (man4!=-1)
00305                    PrintAt(0,0,&Data->P[win].Pool[man4].Name[0]);
00306               }
00307                break;
00308        default:break;
00309       }
00310      }
00311  grSetColor(6);
00312  AltHistory(win);
00313  FadeIn(2,pal,10,0,0);
00314  
00315  WaitForMouseUp();
00316  i=0;key=0;
00317  while (i==0)
00318   {
00319     key=0;GetMouse();
00320     if ((x>=244 && y>=5 && x<=313 && y<=17 && mousebuttons>0) || key==K_ENTER)
00321       {
00322        InBox(244,5,313,17);
00323        WaitForMouseUp();
00324       if (key>0) delay(150);
00325        i=1;key=0;
00326        OutBox(244,5,313,17);
00327       };
00328   }
00329  return;
00330 }
00331 
00332 void Load_LenFlag(char win)
00333 {
00334     PatchHdr P;
00335   GXHEADER local,local2;
00336   unsigned int coff;
00337   int j,Off_X,Off_Y;
00338   char poff;
00339   FILE *in;
00340  if (win==1) {in=sOpen("LENIN.BUT","rb",0);Off_X=224;Off_Y=26;}
00341   else {in=sOpen("FLAGGER.BUT","rb",0);Off_X=195;Off_Y=0;}
00342  poff=0;coff=128;
00343  fread(&pal[coff*3],384,1,in);
00344  fseek(in,(poff)*(sizeof P),SEEK_CUR);
00345  fread(&P,sizeof P,1,in);
00346     SwapPatchHdr(&P);
00347     if (win!=1)
00348         P.w++; /* BUGFIX as everywhere */
00349  fseek(in,P.offset,SEEK_SET);
00350  GV(&local,P.w,P.h); GV(&local2,P.w,P.h);
00351  gxClearVirtual(&local2,0);
00352  gxGetImage(&local2,Off_X,Off_Y,Off_X+P.w-1,Off_Y+P.h-1,0);
00353  fread(local.vptr,P.size,1,in);
00354  fclose(in);
00355  for (j=0;j<P.size;j++)
00356     /* now fix the strip */
00357     if (win == 1 || ((j+1) % P.w != 0))
00358         local2.vptr[j]=local.vptr[j]+coff;
00359 
00360  gxPutImage(&local2,gxSET,Off_X,Off_Y,0);
00361  DV(&local); DV(&local2);
00362  return;
00363 }
00364 
00365 void Draw_NewEnd(char win)
00366 {
00367  long size;
00368  FILE *in;
00369  
00370  music_start(M_VICTORY);
00371 
00372  FadeOut(2,pal,10,0,0);
00373  gxClearDisplay(0,0);
00374  in=sOpen("WINNER.BUT","rb",0);
00375  fread(pal,384,1,in);
00376  size=fread(vhptr.vptr,1,vhptr.h*vhptr.w,in);
00377  fclose(in);
00378  PCX_D(vhptr.vptr,screen,size);
00379  ShBox(0,173,319,199);InBox(5,178,314,194);
00380  IOBox(12,180,67,192);IOBox(72,180,127,192);
00381  IOBox(132,180,187,192);IOBox(192,180,247,192);IOBox(252,180,307,192);
00382  grSetColor(1);
00383  PrintAt(21,188,"HISTORY");PrintAt(85,188,"STATS");PrintAt(142,188,"PARADE");
00384  PrintAt(198,188,"MOON EVA");PrintAt(268,188,"EXIT");
00385  FadeIn(0,pal,10,128,0);
00386  Load_LenFlag(win);
00387  FadeIn(1,pal,40,128,1);
00388 }
00389 
00390 void NewEnd(char win,char loc)
00391 {
00392  GXHEADER local;
00393  int i,Re_Draw=0;
00394  char R_V=0;
00395 
00396  music_start(M_VICTORY);
00397  EndGame(win,loc);
00398  Draw_NewEnd(win);
00399  grSetMousePos(159,181);
00400  R_V=Burst(win);
00401  WaitForMouseUp();
00402  i=0;key=0;
00403  GV(&local,162,92);gxClearVirtual(&local,0);
00404 
00405  while (i==0)
00406  {
00407      key=0;GetMouse();
00408    strncpy(IDT,"i144",4);strncpy(IKEY,"k044",4);
00409      
00410      music_start(M_VICTORY);
00411 
00412    if (((key=='P' || key=='M' || key=='H' || key=='S') || mousebuttons>0) || R_V==0)
00413     if (Re_Draw==1)
00414      {
00415       if ((x>=14 && y>=182 && x<=65 && y<=190 && mousebuttons>0) || key=='H') R_V=1;
00416       if ((x>=74 && y>=182 && x<=125 && y<=190 && mousebuttons>0) || key=='S') R_V=2;
00417       if ((x>=134 && y>=182 && x<=185 && y<=190 && mousebuttons>0) || key=='P') R_V=3;
00418       if ((x>=194 && y>=182 && x<=245 && y<=190 && mousebuttons>0) || key=='M') R_V=4;
00419       if ((x>=254 && y>=182 && x<=305 && y<=190 && mousebuttons>0) || key==K_ENTER) R_V=5;
00420       
00421       gxPutImage(&local,gxSET,149,9,0);
00422       memset(&pal[384],0,384);gxSetDisplayPalette(pal);
00423       gxClearVirtual(&local,0);
00424       Load_LenFlag(win);
00425       FadeIn(1,pal,40,128,1);
00426       
00427       if (R_V==0 || R_V==-1) R_V=Burst(win);
00428       Re_Draw=0;
00429       strncpy(IDT,"i144",4);strncpy(IKEY,"k044",4);
00430      }
00431    if (((x>=14 && y>=182 && x<=65 && y<=190 && mousebuttons>0) || key=='H') || R_V==1)
00432     {
00433          // History box
00434      InBox(14,182,65,190);
00435      WaitForMouseUp();
00436      if (key>0 || R_V>0) delay(150);
00437      i=0;key=0;
00438      OutBox(14,182,65,190);
00439      EndGame(win,loc);Draw_NewEnd(win);
00440      grSetMousePos(159,181);
00441      strncpy(IDT,"i144",4);strncpy(IKEY,"k044",4);
00442      R_V=0;
00443      R_V=Burst(win);
00444     }
00445    if (((x>=74 && y>=182 && x<=125 && y<=190 && mousebuttons>0) || key=='S') || R_V==2)
00446     {
00447          // Stats box
00448          music_stop();
00449      InBox(74,182,125,190);
00450      WaitForMouseUp();
00451      if (key>0 || R_V>0) delay(150);
00452      i=0;key=0;
00453      OutBox(74,182,125,190);
00454      music_start(M_THEME);
00455      Stat(win);Draw_NewEnd(win);
00456      strncpy(IDT,"i144",4);strncpy(IKEY,"k044",4);
00457      grSetMousePos(159,181);
00458      R_V=0;
00459      R_V=Burst(win);
00460     }
00461     if (((x>=134 && y>=182 && x<=185 && y<=190 && mousebuttons>0) || key=='P') || R_V==3)
00462     {
00463          // Parade
00464          music_stop();
00465      InBox(134,182,185,190);
00466      WaitForMouseUp();
00467      if (key>0 || R_V>0) delay(150);
00468      if (R_V==3) R_V=-1;
00469      i=0;key=0;
00470      Re_Draw=1;OutBox(134,182,185,190);
00471      FadeOut(1,pal,40,128,1);RectFill(195,0,319,172,0);
00472      gxGetImage(&local,149,9,309,100,0);
00473      ShBox(149,9,309,100);InBox(153,13,305,96);
00474      music_start(M_PRGMTRG);
00475      Replay(win,0,154,14,149,82,(win==0)?"UPAR":"SPAR");
00476          music_stop();
00477      strncpy(IDT,"i144",4);strncpy(IKEY,"k044",4);
00478     }
00479    if (((x>=194 && y>=182 && x<=245 && y<=190 && mousebuttons>0) || key=='M') || R_V==4)
00480     {
00481          // Moon EVA
00482          music_stop();
00483      InBox(194,182,245,190);
00484      WaitForMouseUp();
00485      if (key>0 || R_V>0) delay(150);
00486      if (R_V==4) R_V=-1;
00487      i=0;key=0;
00488      OutBox(194,182,245,190);Re_Draw=1;
00489      FadeOut(1,pal,40,128,1);RectFill(195,0,319,172,0);
00490      gxGetImage(&local,149,9,309,100,0);
00491      ShBox(149,9,309,100);InBox(153,13,305,96);
00492      music_start(M_MISSPLAN);
00493      Replay(win,0,154,14,149,82,(win==0) ? "PUM3C6":"PSM3C6");
00494          music_stop();
00495      strncpy(IDT,"i144",4);strncpy(IKEY,"k044",4);
00496     }
00497    if (((x>=254 && y>=182 && x<=305 && y<=190 && mousebuttons>0) || key==K_ENTER) || R_V==5)
00498     {
00499      music_stop();
00500      InBox(254,182,305,190);
00501      WaitForMouseUp();
00502      if (key>0) delay(150);
00503      i=1;key=0;
00504      OutBox(254,182,305,190);
00505     };
00506   }
00507  DV(&local);
00508  return;
00509 }
00510 
00511 void FakeWin(char win)
00512 {
00513  int i,r;
00514  char miss,prog,man1,man2,man3,man4,bud,yr;
00515  
00516  FadeOut(2,pal,10,0,0);
00517  gxClearDisplay(0,0);
00518  ShBox(0,0,319,22);InBox(3,3,30,19);
00519  IOBox(242,3,315,19);
00520  ShBox(0,24,319,199);RectFill(5,28,314,195,0);
00521  RectFill(5,105,239,110,3);ShBox(101,102,218,113);
00522  grSetColor(6);PrintAt(112,110,"ALTERNATE HISTORY");
00523  if (win==0) DispBig(34,5,"US WINS",1,-1);
00524    else DispBig(34,5,"USSR WINS",1,-1);
00525  FlagSm(win,4,4);
00526  grSetColor(1);PrintAt(258,13,"CONTINUE");
00527  r=random(100);
00528  if (r<45) miss=53;
00529   else if (r<50) miss=54;
00530    else if (r<85) miss=55;
00531     else miss=56;
00532 
00533  grSetColor(6);PrintAt(10,40,"MISSION: ");grSetColor(8);
00534  if (miss==55  || miss==56) i=1; else i=0;
00535  MissionName(miss,53,40,24);
00536  grSetColor(6);
00537 
00538  if (Data->Year<=65) r=65+random(5);
00539   else if (Data->Year<=70) r=70+random(3);
00540     else if (Data->Year<=77) r=Data->Year;
00541 
00542  PrintAt(10,50,"YEAR: ");grSetColor(8);PrintAt(0,0,"19");DispNum(0,0,r);
00543  yr=r;
00544  grSetColor(6);PrintAt(75,50,"MONTH: ");grSetColor(8);PrintAt(0,0,Month[random(12)]);
00545  r=random(100);
00546  if (miss==54) prog=5;
00547   else if (r<20) prog=2;
00548     else if (r<60) prog=3;
00549      else prog=4;
00550  grSetColor(6);PrintAt(10,60,"CAPSULE: ");grSetColor(8);PrintAt(0,0,&Data->P[win].Manned[prog-1].Name[0]);
00551  PrintAt(0,0," ");PrintAt(0,0,&Nums[random(15)+1][0]);
00552  bud=0; // initialize bud
00553  r=random(100);
00554  if (win==1 && prog==5) bud=5;
00555    else if (win==0 && prog==5) bud=2;
00556      else bud= (r<50) ? 0+(win*3) : 1+(win*3);
00557  if (bud<0 || bud>5) bud=0+win;
00558  InBox(241,67,313,112);EndPict(242,68,bud,128);
00559  PatchMe(win,270,34,prog-1,random(9),32);
00560  r=Data->P[win].AstroCount;
00561  man1=random(r);man2=random(r);
00562  man3=random(r);man4=random(r);
00563  while(1)
00564   {
00565    if ((man1!=man2) && (man1!=man3) && (man2!=man4) &&
00566      (man2!=man3) && (man3!=man4) && (man1!=man4)) break;
00567    while (man1==man2) man2=random(r);
00568    while (man1==man3) man3=random(r);
00569    while (man2==man4) man2=random(r);
00570    while (man2==man3) man3=random(r);
00571    while (man3==man4) man4=random(r);
00572    while (man1==man4) man4=random(r);
00573   }
00574  for (i=1;i<5;i++)
00575    {
00576     grSetColor(6);
00577     switch(i)
00578       {
00579        case 1: if (prog>=1 && prog<=3)
00580                  PrintAt(10,70,"CAPSULE PILOT - EVA: ");
00581                if (prog>3)
00582                  PrintAt(10,70,"COMMAND PILOT: ");
00583                grSetColor(8);
00584                if (man1!=-1)
00585                PrintAt(0,0,&Data->P[win].Pool[man1].Name[0]);
00586                break;
00587        case 2: if (prog>1 && prog<5)
00588                  PrintAt(10,79,"LM PILOT - EVA: ");
00589                    else if (prog==5) PrintAt(10,79,"LUNAR PILOT: ");
00590                grSetColor(8);
00591                if (man2!=-1 && (prog>1 && prog<5))
00592                PrintAt(0,0,&Data->P[win].Pool[man2].Name[0]);
00593                break;
00594        case 3: if (prog>2 && prog<5)
00595                  PrintAt(10,88,"DOCKING SPECIALIST: ");
00596                 else if (prog==5) PrintAt(10,88,"EVA SPECIALIST: ");
00597                grSetColor(8);
00598                if (man3!=-1 && prog>2)
00599                PrintAt(0,0,&Data->P[win].Pool[man3].Name[0]);
00600                break;
00601        case 4: if (prog==5)
00602                {
00603                 PrintAt(10,97,"EVA SPECIALIST: ");
00604                    grSetColor(8);
00605                    if (man4!=-1 && prog==5)
00606                     PrintAt(0,0,&Data->P[win].Pool[man4].Name[0]);
00607                }
00608                break;
00609        default:break;
00610       }
00611      }
00612  grSetColor(6);
00613  FakeHistory(win,yr);
00614  music_start(M_INTERLUD);
00615  FadeIn(2,pal,10,0,0);
00616  
00617  WaitForMouseUp();
00618  i=0;key=0;
00619   while (i==0)
00620   {
00621     key=0;GetMouse();
00622     if ((x>=244 && y>=5 && x<=313 && y<=17 && mousebuttons>0) || key==K_ENTER)
00623       {
00624        InBox(244,5,313,17);
00625        WaitForMouseUp();
00626       if (key>0) delay(150);
00627        i=1;key=0;
00628        OutBox(244,5,313,17);
00629       };
00630   }
00631  music_stop();
00632  return;
00633 }
00634 
00635 void FakeHistory(char plr,char Fyear)  // holds the winning player
00636 {
00637  char bud;
00638  memset(buffer, 0, BUFFER_SIZE);
00639  if (Fyear<=65) bud=0+plr;
00640    else if (Fyear<=67) bud=2+plr;
00641      else if (Fyear<=69) bud=4+plr;
00642        else if (Fyear<=71) bud=6+plr;
00643          else if (Fyear>=72) bud=8+plr;
00644            else bud=10+plr;
00645  HistFile(buffer+1000,bud);
00646  PrintHist(buffer+1000);
00647  return;
00648 }
00649 
00650 void HistFile(char *buf,unsigned char bud)
00651 {
00652   FILE *fin; long i;
00653   i=bud*600;
00654   fin=sOpen("ENDGAME.DAT","rb",0);
00655   fseek(fin,i,SEEK_SET);
00656   fread(buf,600,1,fin);
00657   fclose(fin);
00658 }
00659 
00660 void PrintHist(char *buf)
00661 {
00662  int i,k;
00663  grSetColor(8);
00664  k=121;grMoveTo(10,k);
00665   for (i=0;i<(int)strlen(buf);i++)
00666     {
00667      if (buf[i]=='*') {k+=7;grMoveTo(10,k);}
00668        else DispChr(buf[i]);
00669     }
00670 }
00671 
00672 void PrintOne(char *buf,char tken)
00673 {
00674  int i,k;
00675  grSetColor(7);
00676  k=0;
00677  if (tken==0)  k=127; else k=170;
00678  grMoveTo(10,k);
00679   for (i=0;i<(int)strlen(buf);i++)
00680     {
00681      if (buf[i]=='*') {k+=7;grMoveTo(10,k);}
00682        else DispChr(buf[i]);
00683     }
00684 }
00685 
00686 void AltHistory(char plr)  // holds the winning player
00687 {
00688  char bud;
00689  memset(buffer, 0, BUFFER_SIZE);
00690  if (Data->Year<=65) bud=0+plr;
00691    else if (Data->Year<=67) bud=2+plr;
00692      else if (Data->Year<=69) bud=4+plr;
00693        else if (Data->Year<=71) bud=6+plr;
00694          else if (Data->Year>=72) bud=8+plr;
00695            else bud=10+plr;
00696  HistFile(buffer+1000,bud);
00697  PrintHist(buffer+1000);
00698  return;
00699 }
00700 
00701 void SpecialEnd(void)
00702 {
00703  char i;
00704  music_start(M_BADNEWS);
00705  
00706  gxClearDisplay(0,0);
00707  ShBox(0,0,319,24);DispBig(5,5,"FAILED OBJECTIVE",1,-1);
00708  ShBox(0,26,319,199);RectFill(1,27,318,198,7);InBox(5,31,314,194);
00709  RectFill(6,32,313,193,3);
00710  IOBox(242,3,315,19);grSetColor(1);PrintAt(258,13,"CONTINUE");
00711  ShBox(6,109,313,119);ShBox(6,151,313,161);
00712  grSetColor(9);PrintAt(130,116,"UNITED STATES");PrintAt(134,158,"SOVIET UNION");
00713  RectFill(6,32,313,108,0);
00714  InBox(178,3,205,19);FlagSm(0,179,4);
00715  InBox(210,3,237,19);FlagSm(1,211,4);
00716  LoserPict(0,128); // load loser picture 
00717  memset(buffer,0x00,BUFFER_SIZE);    
00718  HistFile(buffer+1000,10);
00719  PrintOne(buffer+1000,0);
00720  memset(buffer,0x00,BUFFER_SIZE);
00721  HistFile(buffer+1000,11);
00722  PrintOne(buffer+1000,1);
00723  FadeIn(2,pal,10,0,0);
00724  
00725  WaitForMouseUp();
00726  i=0;key=0;
00727  while (i==0)
00728   {
00729    key=0;GetMouse();
00730      if ((x>=244 && y>=5 && x<=313 && y<=17 && mousebuttons>0) || key==K_ENTER)
00731       {
00732        InBox(244,5,313,17);
00733        WaitForMouseUp();
00734       if (key>0) delay(150);
00735        i=1;key=0;
00736       };
00737   }
00738  music_stop();
00739  return;
00740 }
00741 
00742 void
00743 EndPict(int x, int y, char poff, unsigned char coff)
00744 {
00745     PatchHdrSmall P;
00746     GXHEADER local, local2;
00747     unsigned int j;
00748     FILE *in;
00749 
00750     in = sOpen("ENDGAME.BUT", "rb", 0);
00751     fread(&pal[coff * 3], 384, 1, in);
00752     fseek(in, (poff) * (sizeof P), SEEK_CUR);
00753     fread(&P, sizeof P, 1, in);
00754     SwapPatchHdrSmall(&P);
00755     /*
00756      * off by one error in data file - again
00757      * P.w += 1 solves the problem, but then
00758      * we get a strip of garbage on the right hand side
00759      */
00760     P.w++;
00761     fseek(in, P.offset, SEEK_SET);
00762     GV(&local, P.w, P.h);
00763     GV(&local2, P.w, P.h);
00764     gxGetImage(&local2, x, y, x + P.w - 1, y + P.h - 1, 0);
00765     fread(local.vptr, P.size, 1, in);
00766     fclose(in);
00767     for (j = 0; j < P.size; j++)
00768         /* fix the strip */
00769         if (local.vptr[j] != 0 && ((j+1) % P.w != 0))
00770             local2.vptr[j] = local.vptr[j] + coff;
00771     gxPutImage(&local2, gxSET, x, y, 0);
00772     DV(&local);
00773     DV(&local2);
00774     return;
00775 }
00776 
00777 void
00778 LoserPict(char poff, unsigned char coff)
00779 {
00780     /* This hasn't got an off-by-one...*/
00781     PatchHdr P;
00782     GXHEADER local, local2;
00783     unsigned int j;
00784     FILE *in;
00785 
00786     in = sOpen("LOSER.BUT", "rb", 0);
00787     fread(&pal[coff * 3], 384, 1, in);
00788     fseek(in, (poff) * (sizeof P), SEEK_CUR);
00789     fread(&P, sizeof P, 1, in);
00790     SwapPatchHdr(&P);
00791     fseek(in, P.offset, SEEK_SET);
00792     GV(&local, P.w, P.h);
00793     GV(&local2, P.w, P.h);
00794     gxGetImage(&local2, 6, 32, 6 + P.w - 1, 32 + P.h - 1, 0);
00795     fread(local.vptr, P.size, 1, in);
00796     fclose(in);
00797     for (j = 0; j < P.size; j++)
00798         if (local.vptr[j] != 0)
00799             local2.vptr[j] = local.vptr[j] + coff;
00800     gxPutImage(&local2, gxSET, 6, 32, 0);
00801     DV(&local);
00802     DV(&local2);
00803     return;
00804 }
00805 
00806 
00807 void PlayFirst(char plr,char first)
00808 {
00809  char i,w=0,index;
00810  int Check=0;
00811 
00812  FadeOut(2,pal,10,0,0);
00813  gxClearDisplay(0,0);
00814  music_start(M_LIFTOFF);
00815  ShBox(80,18,240,39);DispBig(92,22,"PRESTIGE FIRST",0,-1);
00816  ShBox(80,41,240,132);InBox(84,45,236,128);RectFill(85,46,235,127,0);
00817  ShBox(80,134,240,189); //77 first parameter
00818  grSetColor(1);
00819  PrintAt(84,141,"GOAL STEP COMPLETE: ");grSetColor(6);
00820 
00821  //Modem Opponent => assure prestige first that mission
00822  Check=Data->Prestige[first].Indec;
00823  index=plr;
00824 
00825  if (index==0) PrintAt(0,0,"U.S.A.");
00826   else PrintAt(0,0,"SOVIET");
00827 
00828  for (i=first;i<28;i++)
00829   {
00830    grSetColor(9);
00831    if (Data->Prestige[i].Place==index && Data->PD[index][i]==0)
00832     {
00833      if (Option==-1 && MAIL==-1)
00834       {
00835        PrintAt(84,148+w*8,&PF[i][0]);
00836        ++w;
00837        Data->PD[index][i]=1;
00838       }
00839      else
00840       {
00841        //Found prestige first same mission
00842        if (Data->Prestige[i].Indec==Check)
00843         {
00844          PrintAt(84,148+w*8,&PF[i][0]);
00845          ++w;
00846          Data->PD[index][i]=1;
00847         }
00848       }
00849     } 
00850   }
00851  grSetColor(7);
00852  FadeIn(2,pal,10,0,0);
00853  if (Option==-1 && MAIL==-1) Replay(plr,Data->P[plr].PastMis-1,85,46,151,82,"OOOO");
00854   else Replay(index,Data->Prestige[first].Indec,85,46,151,82,"OOOO");
00855  
00856  PauseMouse();
00857  FadeOut(2,pal,10,0,0);
00858  gxClearDisplay(0,0);
00859  music_stop();
00860  return;
00861 }
00862 
00863 /* vim: set noet ts=4 sw=4 tw=77: */

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