admin.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 // All Administration Main Files
00026 /** \file admin.c Responsible for the Administration office.
00027  * 
00028  */
00029 
00030 #include "Buzz_inc.h"
00031 #include "externs.h"
00032 #include "av.h"
00033 #include "utils.h"
00034 #include "logging.h"
00035 
00036 #define MODEM_ERROR 4
00037 #define NOTSAME 2
00038 #define SAME_REPLACE 1
00039 #define SAME_ABORT 0
00040 #define YES 1
00041 #define NO 0
00042 
00043 LOG_DEFAULT_CATEGORY(LOG_ROOT_CAT);
00044 
00045 extern char Sounds,Option,MAIL;
00046 extern int fOFF;
00047 
00048 SaveFileHdr *SaveHdr;
00049 SFInfo *FList;
00050 
00051 extern struct mStr Mis;
00052 
00053 void Admin(char plr)
00054 {
00055    int i,beg;
00056    char AName[7][22]={"BUDGET OFFICE","HARDWARE PURCHASE","FUTURE MISSIONS",
00057       "ASTRONAUT RECRUITING","PREFERENCES","TIME CAPSULE","EXIT ADMINISTRATION"};
00058    char AImg[7]={1,2,3,4,6,7,0};
00059 
00060   if (plr==1) strncpy(&AName[3][0],"COSMO",5);
00061   if (Data->P[plr].AstroDelay>0) AImg[3]=5;
00062 
00063   //FadeOut(2,pal,10,0,0);
00064   i=0;beg=1;
00065   
00066   do {
00067      if (beg) beg=0;
00068      else {
00069         
00070         FadeOut(2,pal,10,0,0);
00071 
00072         DrawSpaceport(plr);
00073         PortPal(plr);
00074         RectFill(166,191,318,198,3);
00075         grSetColor(0);PrintAt(257,197,"CASH:");DispMB(285,197,Data->P[plr].Cash);
00076         grSetColor(11);PrintAt(256,196,"CASH:");DispMB(284,196,Data->P[plr].Cash);
00077         grSetColor(0);if (Data->Season==0) PrintAt(166,197,"SPRING 19");
00078         else PrintAt(166,197,"FALL 19");DispNum(0,0,Data->Year);
00079         grSetColor(11);if (Data->Season==0) PrintAt(165,196,"SPRING 19");
00080         else PrintAt(165,196,"FALL 19");DispNum(0,0,Data->Year);
00081         
00082         FadeIn(2,pal,10,0,0);
00083      }
00084 
00085      music_start(M_GOOD);
00086 
00087      strncpy(IDT,(plr==0) ?"i702":"i703",4);
00088      strncpy(IKEY,(plr==0) ? "k601":"k602",4);
00089 
00090      i=BChoice(plr,7,(char *)AName,(char *) AImg);
00091 
00092      switch(i) {
00093         case 1: music_stop();
00094               music_start(M_DRUMSM);
00095               strcpy(IDT,"i007");strcpy(IKEY,"k007");
00096               Budget(plr);key=0;
00097               music_stop();
00098               break;
00099 
00100         case 2: music_stop();
00101               strcpy(IDT,"i008");
00102               HPurc(plr);key=0;
00103               break;
00104 
00105         case 3: strcpy(IDT,"i010");strcpy(IKEY,"k010");
00106               music_stop();
00107               music_start(M_MISSPLAN);
00108               Future(plr);
00109               music_stop();key=0;
00110               break;
00111 
00112         case 4: music_stop();
00113               strcpy(IDT,"i012");strcpy(IKEY,"k012");
00114               AstSel(plr);key=0;
00115               break;
00116 
00117         case 5: music_stop();
00118               strcpy(IDT,"i013");strcpy(IKEY,"k013");
00119               Prefs(1);key=0;
00120               break;
00121 
00122         case 6: strcpy(IDT,"i128");strcpy(IKEY,"k128");
00123               FileAccess(0);key=0;
00124               break;
00125 
00126         case 7: break;
00127 
00128         default: key=0;break;
00129 
00130      }
00131      if (Data->P[plr].AstroDelay>0) AImg[3]=5;
00132   } while (!(i==7 || (i==6 && (QUIT || LOAD)) ));
00133 
00134   music_stop();
00135   strcpy(IDT,"i000");strcpy(IKEY,"k000");
00136   WaitForMouseUp();
00137 }
00138 
00139 int GenerateTables(SaveGameType saveType)
00140 {
00141   struct ffblk ffblk;
00142   int i,j,tFiles,done;
00143   FILE *fin;
00144   tFiles=0;
00145 
00146   done=first_saved_game(&ffblk);
00147   while (!done && tFiles<100) {tFiles++;done = next_saved_game(&ffblk);}  // Count Total Files
00148 
00149   memset(buffer,0x00,20480);
00150 
00151   /** \note old code lacked parans, so pointed FList off into space - pace */
00152   FList=(SFInfo *)(buffer+5000);
00153   SaveHdr=(SaveFileHdr *) buffer;
00154 
00155   if (tFiles>0) {
00156     tFiles=0;
00157     done=first_saved_game(&ffblk);
00158     while(!done && tFiles<100)  // Get All Files Names And save Dates.
00159     {
00160      if (strlen (ffblk.ff_name) > sizeof FList[tFiles].Name - 1)
00161          goto next;
00162      memset (&FList[tFiles], 0, sizeof FList[tFiles]);
00163      strcpy(FList[tFiles].Name,ffblk.ff_name);
00164      FList[tFiles].time=ffblk.ff_ftime;
00165      FList[tFiles].date=ffblk.ff_fdate;
00166      fin=sOpen(ffblk.ff_name,"rb",1);
00167      if (fin == NULL)
00168          goto next;
00169      fread(SaveHdr,1,sizeof (SaveFileHdr),fin);
00170      fclose(fin);
00171      if (saveType == SAVEGAME_Normal) {
00172       strcpy(FList[tFiles].Title,SaveHdr->Name);
00173       tFiles++;
00174      }
00175      else if (saveType == SAVEGAME_PlayByMail)
00176       {
00177        if (SaveHdr->Country[0]==8 || SaveHdr->Country[1]==9)
00178         {
00179          strcpy(FList[tFiles].Title,SaveHdr->Name);
00180          tFiles++;
00181         }
00182       }
00183      else if (saveType == SAVEGAME_Modem)
00184       {
00185        if (SaveHdr->Country[0]==6 || SaveHdr->Country[1]==7)
00186         {
00187          strcpy(FList[tFiles].Title,SaveHdr->Name);
00188          tFiles++;
00189         }
00190       }
00191     next:
00192      done=next_saved_game(&ffblk);
00193     }
00194     if (tFiles!=0) {
00195      {
00196       for (i=0;i<tFiles-1;i++)
00197        {
00198         for (j=i+1;j<tFiles;j++)
00199          {
00200            if (xstrcasecmp(FList[j].Title,FList[i].Title)<0)
00201            {
00202              memcpy(&FList[tFiles],&FList[i],sizeof(SFInfo));
00203              memcpy(&FList[i],&FList[j],sizeof(SFInfo));
00204              memcpy(&FList[j],&FList[tFiles],sizeof(SFInfo));
00205             }
00206          }
00207        }
00208      }
00209    }
00210 
00211   } 
00212   return tFiles;
00213 }
00214 
00215 void FileAccess(char mode)
00216 // mode==0 if save allowed
00217 {
00218   char sc=0;
00219   long size;
00220   int tFiles,i,now,done,BarB,temp,left;
00221   FILE *fin,*fout;
00222   char Name[12];
00223   extern char plr[2],AI[2];
00224     SaveGameType saveType = SAVEGAME_Normal;
00225 
00226   //sp. case -> no regular save off mail/modem game
00227   if ((mode==0 || mode==1) && (MAIL!=-1 || Option!=-1)) sc=2;
00228 
00229   if (mode==2) {
00230    mode=0;
00231    sc=1; //only allow mail save
00232   }
00233 
00234   
00235   strcpy(IDT,"i128");strcpy(IKEY,"k128");
00236   FadeOut(2,pal,10,0,0);
00237   gxClearDisplay(0,0);
00238 
00239     saveType = SAVEGAME_Normal;
00240 
00241   if (Option!=-1) 
00242         saveType = SAVEGAME_Modem;
00243     else if (mode==2) 
00244         saveType = SAVEGAME_PlayByMail;
00245 
00246   tFiles=GenerateTables(saveType);
00247   
00248   ShBox(34,32,283,159);
00249   InBox(37,35,204,45);RectFill(38,36,203,44,7);
00250   InBox(207,35,280,45);RectFill(208,36,279,44,10);
00251   InBox(37,48,204,128);RectFill(38,49,203,127,0);
00252   InBox(37,132,280,156);
00253   ShBox(191,50,202,87);UPArrow(194,55);
00254   ShBox(191,89,202,126);DNArrow(194,94);
00255 
00256   if (tFiles>0 && (sc==0 || sc==2)) IOBox(207,48,280,60);else InBox(207,48,280,60);
00257 
00258   if (mode==0)
00259    {
00260     if (sc==0 || sc==2) IOBox(207,62,280,74); //Regular Save game
00261      else InBox(207,62,280,74); 
00262     if (sc==1) IOBox(207,76,280,88); //Mail Save game
00263      else InBox(207,76,280,88);
00264    }   
00265    else {
00266     InBox(207,62,280,74);
00267     InBox(207,76,280,88); 
00268    }
00269   if (tFiles>0) IOBox(207,90,280,102); else InBox(207,90,280,102); //Delete
00270   IOBox(207,104,280,116); //Play
00271   IOBox(207,118,280,130); //Quit
00272 
00273   grSetColor(11);
00274   PrintAt(59,42,"TIME CAPSULE REQUEST");
00275   PrintAt(218,42,"FUNCTIONS");
00276   grSetColor(1);PrintAtKey(233,56,"LOAD",0);
00277   grSetColor(1);PrintAtKey(233,70,"SAVE",0);
00278   grSetColor(1);PrintAtKey(223,84,"MAIL SAVE",0);
00279   grSetColor(1);PrintAtKey(226,98,"DELETE",0);
00280   grSetColor(1);PrintAtKey(233,112,"PLAY",0);
00281   grSetColor(1);PrintAtKey(233,126,"QUIT",0);
00282 
00283   done=BarB=now=0;
00284   ShBox(39,52+BarB*8,189,60+BarB*8);
00285   DrawFiles(0,0,tFiles);
00286   if (tFiles)
00287       FileText(&FList[now].Name[0]);
00288   FadeIn(2,pal,10,0,0);
00289   
00290   
00291   while(!done) {
00292     GetMouse();
00293     
00294     for (i=0;i<9;i++)
00295      {  // Right Select Box
00296       if (x>=40 && y>=(53+i*8) && x<=188 && y<=(59+i*8) && mousebuttons>0 && (now-BarB+i)<=(tFiles-1))
00297        {
00298         
00299           now-=BarB; now+=i; BarB=i;
00300         RectFill(38,49,190,127,0);
00301            ShBox(39,52+BarB*8,189,60+BarB*8);
00302         DrawFiles(now,BarB,tFiles);
00303           FileText(&FList[now].Name[0]);
00304           WaitForMouseUp();        
00305        }
00306     }  
00307     
00308   if ((sc==0 || sc==2) && tFiles>0 && ((x>=209 && y>=50 && x<=278 && y<=58 && mousebuttons>0)
00309    || (key=='L')))
00310    {
00311       int endianSwap = 0;   // Default this to false
00312       char *load_buffer = NULL;
00313       size_t fileLength = 0, eventSize = 0;
00314       size_t readLen = 0;
00315       
00316     InBox(209,50,278,58);
00317       delay(250);
00318     if (mode==1) temp=1;
00319      else {
00320         temp=Help("i101");
00321      }    
00322 
00323      WaitForMouseUp();
00324     if (temp>=0) {
00325             // Read in Saved game data
00326 
00327        fin=sOpen(FList[now].Name,"rb",1);
00328         
00329         fseek(fin,0,SEEK_END);
00330         fileLength = ftell(fin);
00331         rewind(fin);
00332         fread(SaveHdr,1,sizeof (SaveFileHdr),fin);
00333 
00334        // Determine Endian Swap
00335        if (SaveHdr->dataSize!=sizeof(struct Players))
00336            endianSwap = 1;
00337     
00338        if (endianSwap) {
00339            SaveHdr->compSize = _Swap16bit(SaveHdr->compSize);
00340            SaveHdr->dataSize = _Swap16bit(SaveHdr->dataSize);
00341        }
00342       readLen = SaveHdr->compSize;
00343        load_buffer = malloc(readLen);
00344        
00345        readLen = fread(load_buffer,1,readLen,fin);
00346        if (SaveHdr->dataSize==sizeof(struct Players))
00347        {
00348 #ifdef OLD_DOS_ENCRYPT_SAVEDATA
00349                 {
00350                 int moo = 0;
00351         srand(SaveHdr->compSize);
00352         for(moo=0;moo<SaveHdr->compSize;moo++) load_buffer[moo]^=random(256);
00353         randomize();
00354                 }
00355 #endif
00356           RLED((char *) load_buffer,(char *)Data,SaveHdr->compSize);
00357            free(load_buffer);
00358            
00359            // Swap Players Data
00360            if (endianSwap)
00361            {
00362              SwapGameDat();
00363            }
00364            
00365         // Read the Replay Data
00366         load_buffer = malloc((sizeof(REPLAY)) * MAX_REPLAY_ITEMS);
00367         readLen = fread(load_buffer,1,sizeof(REPLAY)*MAX_REPLAY_ITEMS,fin);
00368         if (endianSwap)
00369         {
00370             REPLAY *r = NULL;
00371             r = (REPLAY *) load_buffer;
00372             int i;
00373             for(i = 0; i< MAX_REPLAY_ITEMS; i++)
00374             {
00375                 int ii;
00376                 for (ii = 0; ii < r->Qty; ii++)
00377                     r[i].Off[ii] = _Swap16bit(r[i].Off[ii]);
00378                     
00379             }
00380         }
00381         fout=sOpen("REPLAY.DAT","wb",1);
00382         fwrite(load_buffer,1,sizeof(REPLAY)*MAX_REPLAY_ITEMS,fout);
00383         fclose(fout);
00384         free(load_buffer);
00385 
00386         eventSize = fileLength - ftell(fin);
00387         
00388         // Read the Event Data
00389         load_buffer = malloc(eventSize);
00390         readLen = fread(load_buffer,1,eventSize,fin);
00391         fclose(fin);
00392         
00393         if (endianSwap)
00394         {
00395             int i;
00396             for (i = 0; i < 84; i++)
00397             {
00398                 ONEWS *on = (ONEWS *) load_buffer + (i * sizeof(ONEWS));
00399                 if (on->offset) {
00400                     on->offset = _Swap32bit(on->offset);
00401                     on->size = _Swap16bit(on->size);
00402                 }
00403             }
00404             
00405             // File Structure is 84 longs 42 per side
00406         }
00407         fout=sOpen("EVENT.TMP","wb",1);
00408         fwrite(load_buffer,eventSize,1,fout);
00409         fclose(fout);
00410         free(load_buffer);
00411         
00412          if (!(SaveHdr->Country[0]==6 || SaveHdr->Country[1]==7 || SaveHdr->Country[0]==8 || SaveHdr->Country[1]==9))
00413           {
00414              plr[0]=Data->Def.Plr1;plr[1]=Data->Def.Plr2;
00415              Data->plr[0]=Data->Def.Plr1;
00416              Data->plr[1]=Data->Def.Plr2;
00417              if (plr[0]==2 || plr[0]==3) AI[0]=1; else AI[0]=0;  // SET AI FLAGS
00418              if (plr[1]==2 || plr[1]==3) AI[1]=1; else AI[1]=0;
00419           }
00420 
00421 
00422         if (SaveHdr->Country[0]==8 || SaveHdr->Country[1]==9)
00423          {
00424           //Play-By-Mail save game LOAD
00425           Option=-1;fOFF=-1;
00426           //save file offset
00427           fOFF=now;
00428 
00429           Data->Season=SaveHdr->Season;
00430           Data->Year=SaveHdr->Year;
00431 
00432           if (SaveHdr->Country[0]==8) {MAIL=plr[0]=0;plr[1]=1;}
00433            else {MAIL=plr[1]=1;plr[0]=0;}
00434           AI[0]=AI[1]=0;
00435           Data->Def.Plr1=0;Data->Def.Plr2=1;
00436            Data->plr[0]=Data->Def.Plr1;
00437            Data->plr[1]=Data->Def.Plr2;
00438 
00439           if (Data->Def.Input==0 || Data->Def.Input==2)
00440            { // Hist Crews
00441             fin=sOpen("CREW.DAT","rb",0);
00442             size=fread(buffer,1,BUFFER_SIZE,fin);
00443             fclose(fin);
00444             fin=sOpen("MEN.DAT","wb",1);
00445             fwrite(buffer,size,1,fin);
00446             fclose(fin);
00447             }
00448           else if (Data->Def.Input==1 || Data->Def.Input==3)
00449            { // User Crews
00450              fin=sOpen("USER.DAT","rb",0);
00451              size=fread(buffer,1,BUFFER_SIZE,fin);
00452              fclose(fin);
00453              fin=sOpen("MEN.DAT","wb",1);
00454              fwrite(buffer,size,1,fin);
00455              fclose(fin);
00456             }
00457          } 
00458         else
00459          //Modem save game LOAd
00460         if (SaveHdr->Country[0]==6 || SaveHdr->Country[1]==7)
00461          {
00462           //modem connect up
00463           if (SaveHdr->Country[0]==6) {plr[0]=SaveHdr->Country[0];plr[1]=1;}
00464            else {plr[1]=SaveHdr->Country[1];plr[0]=0;}
00465           //Modem Play => reset the modem
00466           if (Option!=-1) DoModem(2);
00467           Option=MPrefs(1);
00468           //klugge
00469           if (Option==0 || Option==2) Option=0;
00470            else if (Option==1 || Option==3) Option=1;
00471          }
00472         else
00473          {
00474           //Regular save game LOAD
00475           if (Data->Def.Input==0 || Data->Def.Input==2) { // Hist Crews
00476              fin=sOpen("CREW.DAT","rb",0);
00477              size=fread(buffer,1,BUFFER_SIZE,fin);
00478              fclose(fin);
00479              fin=sOpen("MEN.DAT","wb",1);
00480              fwrite(buffer,size,1,fin);
00481              fclose(fin);
00482             }
00483           else if (Data->Def.Input==1 || Data->Def.Input==3) { // User Crews
00484              fin=sOpen("USER.DAT","rb",0);
00485              size=fread(buffer,1,BUFFER_SIZE,fin);
00486              fclose(fin);
00487              fin=sOpen("MEN.DAT","wb",1);
00488              fwrite(buffer,size,1,fin);
00489              fclose(fin);
00490             }
00491         }  
00492           if (Option!=MODEM_ERROR) LOAD=done=1;
00493          else {Option=-1;LOAD=done=0;return;}
00494          }   
00495       else {fclose(fin);BadFileType();};
00496       } // temp
00497        OutBox(209,50,278,58);  // Button Out
00498        key=0;
00499 
00500     } // LOAD
00501       else if ((sc==0 || sc==2) && mode==0 && ((x>=209 && y>=64 && x<=278 && y<=72 && mousebuttons>0)
00502              || (key=='S')))
00503       {
00504           InBox(209,64,278,72);
00505           delay(250);
00506 
00507           WaitForMouseUp();
00508 
00509         memset(SaveHdr->Name,0x00,23);
00510         done=GetBlockName(SaveHdr->Name);  // Checks Free Space
00511                 SaveHdr->ID = RaceIntoSpace_Signature;
00512         SaveHdr->Name[22]=0x1A;
00513           temp=NOTSAME;
00514 
00515           for (i=0;(i<tFiles && temp==2);i++) 
00516              if (strcmp(SaveHdr->Name,FList[i].Title)==0) {
00517                 temp=RequestX("REPLACE FILE",1);
00518               if (temp==SAME_ABORT) done=0;
00519              }
00520 
00521           if (done==YES) {
00522              i--;  // decrement to correct for the FOR loop
00523              strcpy(SaveHdr->PName[0],Data->P[plr[0] % 2].Name);
00524              strcpy(SaveHdr->PName[1],Data->P[plr[1] % 2].Name);
00525            //modem save game hack
00526            if (Option!=-1)
00527             {
00528              if (Option==0) {plr[0]=6;plr[1]=1;}
00529               else if (Option==1) {plr[0]=0;plr[1]=7;}
00530              Data->Def.Plr1=plr[0];Data->Def.Plr2=plr[1];
00531               Data->plr[0]=Data->Def.Plr1;   
00532               Data->plr[1]=Data->Def.Plr2;
00533               AI[0]=0;AI[1]=0;
00534             }
00535              SaveHdr->Country[0]=Data->plr[0];
00536              SaveHdr->Country[1]=Data->plr[1];
00537              SaveHdr->Season=Data->Season;
00538              SaveHdr->Year=Data->Year;
00539              SaveHdr->dataSize=sizeof(struct Players);
00540        
00541              fin=sOpen("ENDTURN.TMP","rb",1);
00542              if (fin) {
00543                 SaveHdr->compSize=fread(vhptr.vptr,1,vhptr.h*vhptr.w,fin);
00544                 fclose(fin);
00545              } else SaveHdr->compSize=0;
00546 
00547           if (temp==NOTSAME)
00548           { 
00549             i=0;
00550            fin=NULL;
00551             do {
00552             if (fin) fclose(fin);
00553              i++;
00554              sprintf(Name,"BUZZ%d.SAV",i);
00555              fin=sOpen(Name,"rb",1);
00556             } while (fin!=NULL);  // Find unique name
00557           fin=sOpen(Name,"wb",1);
00558           }
00559         else fin=sOpen(FList[i].Name,"wb",1);
00560 
00561          fwrite(SaveHdr,sizeof (SaveFileHdr),1,fin);
00562 
00563       //----------------------------------
00564       //Specs: Special Modem Save Klugge |
00565       //----------------------------------
00566         if (Option!=-1)
00567          {
00568           if (Option==0) {plr[0]=0;plr[1]=1;}
00569            else if (Option==1) {plr[0]=0;plr[1]=1;}
00570           Data->Def.Plr1=plr[0];Data->Def.Plr2=plr[1];
00571           Data->plr[0]=Data->Def.Plr1;   
00572           Data->plr[1]=Data->Def.Plr2;
00573            AI[0]=0;AI[1]=0;
00574          }
00575 
00576         fout=sOpen("ENDTURN.TMP","rb",1);
00577         size=16000L;
00578         fseek(fout,0,SEEK_SET);
00579         while (size==16000) {
00580           size=fread(vhptr.vptr,1,size,fout);
00581           fwrite(vhptr.vptr,size,1,fin); // save Replay File
00582         }
00583         fclose(fout);
00584 
00585         fout=sOpen("REPLAY.DAT","rb",1);
00586         fread(vhptr.vptr,(sizeof(REPLAY))*MAX_REPLAY_ITEMS,1,fout);
00587         fclose(fout);
00588         fwrite(vhptr.vptr,(sizeof(REPLAY))*MAX_REPLAY_ITEMS,1,fin); // save Replay File
00589 
00590         fout=sOpen("EVENT.TMP","rb",1);  // Save Event File
00591         left=32000; // copy EVENT.TMP FILE
00592         while (left==32000) {
00593            left=fread(vhptr.vptr,1,32000,fout);
00594            fwrite(vhptr.vptr,left,1,fin);
00595         }
00596         fclose(fout); // close EVENT.TMP
00597        fclose(fin);
00598        }  // end done if
00599        OutBox(209,64,278,72);
00600        key=0;
00601   }
00602    else if (sc==1 && mode==0 && ((x>=209 && y>=78 && x<=278 && y<=86 && mousebuttons>0)
00603     || (key=='M')))  // PLAY-BY-MAIL SAVE GAME
00604     {
00605      InBox(209,78,278,86);
00606      delay(250);
00607      WaitForMouseUp();
00608      memset(SaveHdr->Name,0x00,23);
00609      done=GetBlockName(SaveHdr->Name);  // Checks Free Space
00610          SaveHdr->ID = RaceIntoSpace_Signature;
00611      SaveHdr->Name[22]=0x1A;
00612       temp=NOTSAME;
00613       for (i=0;(i<tFiles && temp==2);i++) 
00614        if (strcmp(SaveHdr->Name,FList[i].Title)==0)
00615        {
00616          temp=RequestX("REPLACE FILE",1);
00617         if (temp==SAME_ABORT) done=0;
00618         }
00619       if (done==YES)
00620       {
00621         i--;  // decrement to correct for the FOR loop
00622         strcpy(SaveHdr->PName[0],Data->P[plr[0] % 2].Name);
00623         strcpy(SaveHdr->PName[1],Data->P[plr[1] % 2].Name);
00624 
00625         // play-by-mail save game hack
00626         // starts US side
00627         plr[0]=0;plr[1]=9;MAIL=-1;
00628         Data->Def.Plr1=plr[0];Data->Def.Plr2=plr[1];
00629          Data->plr[0]=Data->Def.Plr1;   
00630          Data->plr[1]=Data->Def.Plr2;
00631          AI[0]=0;AI[1]=0;
00632 
00633          SaveHdr->Country[0]=Data->plr[0];
00634          SaveHdr->Country[1]=Data->plr[1];
00635          SaveHdr->Season=Data->Season;
00636          SaveHdr->Year=Data->Year;
00637          SaveHdr->dataSize=sizeof(struct Players);
00638 
00639         EndOfTurnSave((char *) Data, sizeof ( struct Players));
00640 
00641         fin=sOpen("ENDTURN.TMP","rb",1);
00642          if (fin)
00643          {
00644            SaveHdr->compSize=fread(vhptr.vptr,1,vhptr.h*vhptr.w,fin);
00645            fclose(fin);
00646           } else SaveHdr->compSize=0;
00647 
00648           if (temp==NOTSAME)
00649           { 
00650             i=0;
00651           fin=NULL;
00652             do {
00653              i++;
00654            if (fin) fclose(fin);
00655             sprintf(Name,"BUZZ%d.SAV",i);
00656              fin=sOpen(Name,"rb",1);
00657             } while (fin!=NULL);  // Find unique name
00658           fin=sOpen(Name,"wb",1);
00659           }
00660         else fin=sOpen(FList[i].Name,"wb",1);
00661        
00662          fwrite(SaveHdr,sizeof (SaveFileHdr),1,fin);
00663         fout=sOpen("ENDTURN.TMP","rb",1);
00664         size=16000L;
00665         fseek(fout,0,SEEK_SET);
00666         while (size==16000)
00667          {
00668           size=fread(vhptr.vptr,1,size,fout);
00669           fwrite(vhptr.vptr,size,1,fin); // save Replay File
00670          }
00671         fclose(fout);
00672         fout=sOpen("REPLAY.DAT","rb",1);
00673         fread(vhptr.vptr,(sizeof(REPLAY))*MAX_REPLAY_ITEMS,1,fout);
00674         fclose(fout);
00675         fwrite(vhptr.vptr,(sizeof(REPLAY))*MAX_REPLAY_ITEMS,1,fin); // save Replay File
00676 
00677         fout=sOpen("EVENT.TMP","rb",1);  // Save Event File
00678         left=32000; // copy EVENT.TMP FILE
00679         while (left==32000)
00680          {
00681           left=fread(vhptr.vptr,1,32000,fout);
00682           fwrite(vhptr.vptr,left,1,fin);
00683          }
00684       fclose(fout); // close EVENT.TMP
00685         fclose(fin);
00686        }  
00687      OutBox(209,78,278,86);
00688      key=0;
00689     }
00690    else if (tFiles>0 && ((x>=209 && y>=92 && x<=278 && y<=100 && mousebuttons>0)
00691      || (key=='D')))
00692     {
00693      InBox(209,92,278,100);
00694      delay(250);
00695      WaitForMouseUp();
00696      OutBox(209,92,278,100);
00697      // perform delete
00698      i=RequestX("DELETE FILE",1);
00699      if (i==1) {
00700        
00701        remove_savedat(FList[now].Name);
00702       memset(Name,0x00,sizeof Name);
00703             saveType = SAVEGAME_Normal;
00704 
00705       if (Option!=-1) saveType = SAVEGAME_Modem;
00706        else if (mode==2) saveType = SAVEGAME_PlayByMail;
00707 
00708        tFiles=GenerateTables(saveType);
00709        now=0;BarB=0;
00710        RectFill(38,49,190,127,0);
00711        ShBox(39,52+BarB*8,189,60+BarB*8);
00712        DrawFiles(now,BarB,tFiles);
00713        FileText(&FList[now].Name[0]);
00714        if (tFiles==0) {
00715          InBox(207,48,280,60);RectFill(208,49,279,59,3);
00716          grSetColor(1);PrintAtKey(233,56,"LOAD",0);
00717          InBox(207,90,280,102);RectFill(208,91,279,101,3);
00718          grSetColor(1);PrintAtKey(226,98,"DELETE",0);
00719        }
00720        
00721      }
00722      key=0;
00723       }
00724       else if ((x>=209 && y>=106 && x<=278 && y<=114 && mousebuttons>0) || (key=='P'))
00725        {
00726           InBox(209,106,278,114);
00727           delay(250);
00728           WaitForMouseUp();
00729           OutBox(209,106,278,114);
00730           key=0;done=1;
00731       }
00732       else if ((x>=209 && y>=120 && x<=278 && y<=128 && mousebuttons>0) || (key=='Q'))
00733       {
00734         InBox(209,120,278,128);
00735          delay(250);
00736          WaitForMouseUp();
00737         OutBox(209,120,278,128);
00738         // perform quit
00739         i=RequestX("QUIT",1);
00740        //Modem Play => reset the modem
00741        if (Option!=-1 && i==1) DoModem(2);
00742         if (i==1)
00743          {
00744           MAIL=Option=-1;
00745           QUIT=done=1;
00746          }
00747         key=0;
00748       }
00749       else if ((x>=191 && y>=50 && x<=202 && y<=87 && mousebuttons>0) || key==UP_ARROW)
00750       {
00751      InBox(191,50,202,87);
00752      if (BarB==0) {
00753        if (now > 0) {
00754          now--;
00755          RectFill(38,49,190,127,0);
00756          ShBox(39,52+BarB*8,189,60+BarB*8);
00757          DrawFiles(now,BarB,tFiles);
00758          FileText(&FList[now].Name[0]);
00759        };
00760      }
00761      if (BarB>0) {
00762        RectFill(38,49,190,127,0);
00763        BarB--;now--;
00764        ShBox(39,52+BarB*8,189,60+BarB*8);
00765        DrawFiles(now,BarB,tFiles);
00766        FileText(&FList[now].Name[0]);
00767      };
00768      
00769      //  WaitForMouseUp();
00770      OutBox(191,50,202,87);
00771      // perform Up Button
00772      key=0;
00773     }
00774     else if (key==0x4900) {  // Page Up
00775      
00776      if (now>0) {
00777        RectFill(38,49,190,127,0);
00778        now-=9;
00779          if (now<0) {now=0;BarB=0;}
00780        ShBox(39,52+BarB*8,189,60+BarB*8);
00781        DrawFiles(now,BarB,tFiles);
00782        FileText(&FList[now].Name[0]);
00783      };
00784      
00785      // perform Up Button
00786        key=0;
00787 
00788       }
00789     else if (key==0x5100) {  // Page Down
00790      
00791        if (now<(tFiles-9)) {
00792          now+=9;
00793            if (now>(tFiles-1)) {
00794             now=tFiles-1;
00795             BarB=8;
00796             }
00797          RectFill(38,49,190,127,0);
00798          ShBox(39,52+BarB*8,189,60+BarB*8);
00799          DrawFiles(now,BarB,tFiles);
00800          FileText(&FList[now].Name[0]);
00801        }
00802      
00803      key=0;
00804       }
00805       else if ((x>=191 && y>=89 && x<=202 && y<=126 && mousebuttons>0) || key==DN_ARROW)
00806       {
00807      InBox(191,89,202,126);
00808      if (BarB==8) {
00809        if (now<(tFiles-1)) {
00810          now++;
00811          RectFill(38,49,190,127,0);
00812          ShBox(39,52+BarB*8,189,60+BarB*8);
00813          DrawFiles(now,BarB,tFiles);
00814          FileText(&FList[now].Name[0]);
00815        }
00816      }
00817      if (BarB<8 && now<(tFiles-1)) {
00818        RectFill(38,49,190,127,0);
00819        BarB++;now++;
00820        ShBox(39,52+BarB*8,189,60+BarB*8);
00821        DrawFiles(now,BarB,tFiles);
00822        FileText(&FList[now].Name[0]);
00823      };
00824      
00825    
00826      //  WaitForMouseUp();
00827      OutBox(191,89,202,126);
00828      // perform Down Button
00829      key=0;
00830       }; //
00831   } //while
00832   if (LOAD==1) {OutBox(209,50,278,60);}  // Button Out
00833   if (mode==1 && QUIT==1) FadeOut(2,pal,10,0,0);
00834 }
00835 
00836 void
00837 save_game (char *name)
00838 {
00839     FILE *inf, *outf;
00840     SaveFileHdr hdr;
00841     size_t buflen = 0;
00842     ssize_t size = 0;
00843     char * buf = NULL;
00844 
00845     EndOfTurnSave((char *) Data, sizeof ( struct Players));
00846 
00847     if ((inf = sOpen("ENDTURN.TMP","rb",1)) == NULL) {
00848         WARNING1("can't read ENDTURN.TMP");
00849         return;
00850     }
00851 
00852     memset (&hdr, 0, sizeof hdr);
00853 
00854     hdr.ID = RaceIntoSpace_Signature;
00855     strcpy (hdr.Name, "AUTOSAVE");
00856     hdr.Name[sizeof hdr.Name - 1] = 0x1a;
00857 
00858     strcpy(hdr.PName[0], Data->P[plr[0] % 2].Name);
00859     strcpy(hdr.PName[1], Data->P[plr[1] % 2].Name);
00860     hdr.Country[0] = Data->plr[0];
00861     hdr.Country[1] = Data->plr[1];
00862     hdr.Season = Data->Season;
00863     hdr.Year = Data->Year;
00864     hdr.dataSize = sizeof(struct Players);
00865     hdr.compSize = 0; //filelength (fileno (inf));
00866        
00867     if ((outf = sOpen (name, "wb", 1)) == NULL) {
00868         WARNING2("can't save to file `%s'", name);
00869         goto cleanup;
00870     }
00871 
00872     size = fread_dyn(&buf, &buflen, inf);
00873     fclose(inf);
00874     inf = NULL;
00875     if (size < 0) {
00876         WARNING1("read error in ENDTURN.TMP");
00877         goto cleanup;
00878     }
00879     hdr.compSize = size;
00880     
00881     fwrite(&hdr,sizeof hdr,1,outf);
00882     fwrite(buf, size, 1, outf);
00883     
00884     if ((inf = sOpen ("REPLAY.DAT", "rb", 1)) != NULL) {
00885         size = fread_dyn(&buf, &buflen, inf);
00886         if (size >= 0)
00887             fwrite(buf, size, 1, outf);
00888         else
00889         {
00890             WARNING1("read error in REPLAY.DAT");
00891             goto cleanup;
00892         }
00893         fclose(inf);
00894         inf = NULL;
00895     }
00896     
00897     if ((inf = sOpen ("EVENT.TMP", "rb", 1)) != NULL) {
00898         size = fread_dyn(&buf, &buflen, inf);
00899         if (size >= 0)
00900             fwrite(buf, size, 1, outf);
00901         else
00902         {
00903             WARNING1("read error in EVENT.TMP");
00904             goto cleanup;
00905         }
00906         fclose(inf);
00907         inf = NULL;
00908     }
00909     else
00910         WARNING1("can't read EVENT.TMP");
00911 
00912 cleanup:
00913     if (outf)
00914         fclose(outf);
00915     if (inf)
00916         fclose(inf);
00917     if (buf)
00918         free(buf);
00919 }
00920 
00921 char GetBlockName(char *Nam)
00922 {
00923   int i,key;
00924   GXHEADER local;
00925   
00926   GV(&local,164,77);
00927   gxGetImage(&local,39,50,202,126,0);
00928   ShBox(39,50,202,126);
00929   i=1;
00930   if (i==1) {
00931     InBox(43,67,197,77);RectFill(44,68,196,76,13);
00932     grSetColor(11); PrintAt(47,74,"ENTER FILE DESCRIPTION");
00933     InBox(51,95,190,105);RectFill(52,96,189,104,0);
00934   } else {
00935     InBox(43,67,197,77);RectFill(44,68,196,76,13);
00936     grSetColor(11);PrintAt(47,74,"NOT ENOUGHT DISK SPACE");
00937     delay(2000);gxPutImage(&local,gxSET,39,50,0);DV(&local);
00938     
00939     return 0;
00940   }
00941   
00942   gr_sync ();
00943   key=0;i=0;
00944   while(!(key==K_ENTER || key==K_ESCAPE)) {
00945     av_block ();
00946     gr_maybe_sync ();
00947     key = bioskey (0);
00948     if (key >= 'a' && key <= 'z')
00949         key = toupper (key);
00950     if (key&0x00ff) {
00951       if ((i<21) && ((key==' ') || ((key>='A' && key<='Z')) ||
00952      (key>='0' && key<='9'))) {  // valid key
00953     Nam[i++]=key;
00954     grSetColor(1);PrintAt(53,102,&Nam[0]);
00955     av_need_update_xy(52,96,189,104);
00956     key=0;
00957       }
00958       if (i>0 && key==0x08) {
00959     Nam[--i]=0x00;
00960   
00961     RectFill(52,96,189,104,0);
00962     grSetColor(1);PrintAt(53,102,&Nam[0]);
00963   
00964     key=0;
00965       }
00966     }
00967   }
00968   
00969   gxPutImage(&local,gxSET,39,50,0);
00970   DV(&local);
00971   
00972   if(key==K_ENTER && i>=1) return 1; else return 0;
00973 }
00974 
00975 
00976 
00977 void DrawFiles(char now,char loc,char tFiles)
00978 {
00979   int i,j,start;
00980   start=now-loc;
00981   grSetColor(1);
00982   j=0;
00983 
00984   for (i=start;i<start+9;i++) {
00985     if (i<tFiles) {
00986       PrintAt(40,58+j*8,FList[i].Title);
00987       j++;
00988     }
00989   }
00990 }
00991 
00992 
00993 void BadFileType(void)
00994 {
00995   GXHEADER local;
00996   GV(&local,164,77);
00997   gxGetImage(&local,39,50,202,126,0);
00998   ShBox(39,50,202,126);
00999     InBox(43,67,197,77);RectFill(44,68,196,76,13);
01000     grSetColor(11);PrintAt(47,74,"CORRUPT SAVE FILE");
01001     delay(2000);gxPutImage(&local,gxSET,39,50,0);
01002     PauseMouse();
01003   gxPutImage(&local,gxSET,39,50,0);
01004   DV(&local);
01005 }
01006 
01007 
01008 void FileText(char *name)
01009 {
01010   FILE *fin;
01011 
01012   RectFill(38,133,279,155,3);
01013   grSetColor(1);
01014   fin=sOpen(name,"rb",1);
01015   if (fin==NULL) {
01016     grSetColor(11);
01017     PrintAt(70,147,"NO HISTORY RECORDED");
01018     return;
01019   };
01020   fread(SaveHdr,sizeof (SaveFileHdr),1,fin);
01021   fclose(fin);
01022   grMoveTo(40,139);
01023   //if (((char)SaveHdr->Country[0])&0x02) grSetColor(7+(SaveHdr->Country[1]-2)*3); 
01024 
01025   grSetColor(5);
01026 
01027   //grSetColor(6+(SaveHdr->Country[0]%2)*3); 
01028   if (SaveHdr->Country[0]==6 || SaveHdr->Country[1]==7) PrintAt(0,0,"MODEM DIRECTOR ");
01029    else if (SaveHdr->Country[0]==8 || SaveHdr->Country[1]==9) PrintAt(0,0,"MAIL DIRECTOR ");
01030     else if (SaveHdr->Country[0]==2) PrintAt(0,0,"COMPUTER DIRECTOR ");
01031      else PrintAt(0,0,"HUMAN DIRECTOR ");
01032   PrintAt(0,0,&SaveHdr->PName[0][0]);
01033   PrintAt(0,0," OF THE U.S.A.");
01034 
01035   grMoveTo(40,147);
01036   //if (((char)SaveHdr->Country[1])&0x02) grSetColor(7+(SaveHdr->Country[1]-2)*3); 
01037 
01038   grSetColor(9);
01039 
01040   if (SaveHdr->Country[0]==6 || SaveHdr->Country[1]==7) PrintAt(0,0,"VS. MODEM DIRECTOR ");
01041    else if (SaveHdr->Country[0]==8 || SaveHdr->Country[1]==9) PrintAt(0,0,"VS. MAIL DIRECTOR ");
01042     else if (SaveHdr->Country[1]==3) PrintAt(0,0,"VS. COMPUTER DIRECTOR ");
01043      else PrintAt(0,0,"VS. HUMAN DIRECTOR ");
01044 
01045   PrintAt(0,0,&SaveHdr->PName[1][0]);
01046   PrintAt(0,0," OF THE U.S.S.R.");
01047 
01048   grMoveTo(40,154);grSetColor(11);
01049   if (SaveHdr->Season==0)
01050    {
01051     if (SaveHdr->Country[0]==8) PrintAt(0,0,"U.S.A. TURN IN THE SPRING OF ");
01052      else if (SaveHdr->Country[1]==9) PrintAt(0,0,"SOVIET TURN IN THE SPRING OF ");
01053       else PrintAt(0,0,"THE SPRING OF ");
01054    }
01055   else {
01056     if (SaveHdr->Country[0]==8) PrintAt(0,0,"U.S.A. TURN IN THE FALL OF ");
01057      else if (SaveHdr->Country[1]==9) PrintAt(0,0,"SOVIET TURN IN THE FALL OF ");
01058       else PrintAt(0,0,"THE FALL OF ");
01059    }   
01060   DispNum(0,0,19);DispNum(0,0,SaveHdr->Year);PrintAt(0,0,".");
01061 }
01062 
01063 
01064 int FutureCheck(char plr,char type)
01065 {
01066   int i,pad,p[3],m[3],t=0,tx[3]={0,0,0};
01067   FILE *fin;
01068   
01069   for (i=0;i<3;i++) {
01070     p[i]=Data->P[plr].LaunchFacility[i];
01071     if (type==0) m[i]=Data->P[plr].Future[i].MissionCode;
01072     if (type==1) m[i]=(Data->P[plr].Mission[i].Hard[4] >0 ) ? 1: 0;
01073   };
01074   FadeOut(2,pal,10,0,0);
01075 
01076 
01077   PortPal(plr);
01078 
01079   fin=sOpen("LPADS.BUT","rb",0);
01080   i=fread(screen, 1, MAX_X*MAX_Y, fin);
01081   fclose(fin);
01082   RLED_img(screen,vhptr.vptr,i, vhptr.w,vhptr.h);
01083   if (type==0) {strcpy(IDT,"i010");strcpy(IKEY,"k010");}
01084    else{strcpy(IDT,"i015");strcpy(IKEY,"k015");}
01085   gxClearDisplay(0,0);
01086   ShBox(59,12,269,186);InBox(64,17,213,29);
01087   RectFill(65,18,212,28,7);
01088   ShBox(217,17,264,29);IOBox(217,17,264,29);grSetColor(9);PrintAt(231,25,"EXIT");
01089   grSetColor(11);
01090   if (type==0) PrintAt(74,25,"FUTURE ");
01091   else if (plr==0) PrintAt(83,25,"VAB "); else PrintAt(83,25,"VIB ");
01092   PrintAt(0,0,"LAUNCH SELECTION");
01093   for (i=0;i<3;i++) {
01094     InBox(64,35+51*i,104,66+51*i);
01095     InBox(64,69+51*i,104,79+51*i);
01096     InBox(108,35+51*i,264,64+51*i);
01097     IOBox(108,67+51*i,264,79+51*i);
01098     if (p[i]>1) {
01099       grSetColor(5);
01100       PrintAt(111,50+i*51,"THIS FACILITY IS DAMAGED");
01101       PrintAt(111,57+i*51,"IT WILL COST ");DispNum(0,0,abs(p[i]));
01102       PrintAt(0,0,"MB TO REPAIR");
01103       if (type==0) PrintAt(113,75+i*51,"REPAIR LAUNCH FACILITY");
01104       else InBox(110,69+i*51,262,77+i*51); t=2;
01105     };
01106     if (p[i]==1) {
01107       grSetColor(1);
01108       if (type==1) {
01109         GetMisType(Data->P[plr].Mission[i].MissionCode);
01110         PrintAt(111,41+i*51,Mis.Abbr);
01111 
01112           if (i<2)
01113              if (Data->P[plr].Mission[i+1].part==1) {
01114                 PrintAt(111,61+i*51,"PRIMARY MISSION PART");
01115                 PrintAt(111,61+(i+1)*51,"SECONDARY MISSION PART");
01116              }
01117         }
01118         else {
01119            if (!Data->P[plr].Future[i].MissionCode) grSetColor(1);
01120            GetMisType(Data->P[plr].Future[i].MissionCode);
01121 
01122            PrintAt(111,41+i*51,Mis.Abbr);
01123              if (i<2)
01124                 if (Data->P[plr].Future[i+1].part==1) {
01125                    PrintAt(111,61+i*51,"PRIMARY MISSION PART");
01126                    PrintAt(111,61+(i+1)*51,"SECONDARY MISSION PART");
01127                 }
01128         }
01129 
01130   if (type==0) {
01131     if (Data->P[plr].Future[i].part==0) {
01132       if (m[i]==0) {PrintAt(113,75+i*51,"ASSIGN FUTURE MISSION");t=1;}
01133       else {PrintAt(113,75+i*51,"REASSIGN FUTURE MISSION");t=0;};
01134     } else {
01135       PrintAt(113,75+i*51,"SECOND PART OF JOINT MISSION");t=0;tx[i]=1;
01136       InBox(110,69+i*51,262,77+i*51);
01137     }
01138       } else {
01139        if (m[i]==0) {PrintAt(113,75+i*51,"ASSEMBLE HARDWARE");t=1;}
01140        else {PrintAt(113,75+i*51,"REASSEMBLE HARDWARE");t=0;};
01141       };
01142     };
01143     if (p[i]==-1) {
01144       grSetColor(9);  // Changed from 5
01145       PrintAt(111,41+i*51,"NO FACILITY EXISTS");
01146       if (type==0) {
01147     PrintAt(111,49+i*51,"PURCHASE LAUNCH FACILITY");
01148     PrintAt(111,57+i*51,"FOR: 20 MB'S");
01149     PrintAt(111,75+i*51,"PURCHASE FACILITY");
01150       }
01151       else InBox(110,69+i*51,262,77+i*51);
01152       t=3;
01153     };
01154     grSetColor(11);PrintAt(72,76+i*51,"PAD ");DispChr(0x41+i);
01155     gxVirtualDisplay(&vhptr,156*plr+t*39,i*30,65,36+i*51,103,65+i*51,0);
01156   }
01157 
01158   FadeIn(2,pal,10,0,0);
01159   
01160   WaitForMouseUp();
01161   pad=-1;x=y=mousebuttons=key=0;
01162   while(pad==-1) {
01163    key=0;GetMouse();
01164      if (x>=219 && y>=19 && x<=262 && y<=27 && mousebuttons>0) 
01165       {
01166        InBox(219,19,262,27);
01167        WaitForMouseUp();
01168        pad=5;key=0;
01169       }
01170      if (((!(x>=59 && y>=12 && x<=269 && y<=186))&&mousebuttons>0) || key==K_ESCAPE || key==K_ENTER || key=='E')
01171       {
01172        InBox(219,19,262,27);
01173        pad=5;key=0;
01174       };
01175      for (i=0;i<3;i++)
01176       {
01177        if ((x>=110 && y>=69+i*51 && x<=262 && y<=77+i*51 && tx[i]!=1 && mousebuttons>0) || (tx[i]!=1 && key=='A'+i)) {
01178          InBox(110,69+i*51,262,77+i*51);
01179      WaitForMouseUp();
01180      key=0;
01181      delay(300);
01182      if (p[i]==1) pad=i;
01183      if (p[i]==-1 && Data->P[plr].Cash>=20 && type==0) {
01184      
01185        gxVirtualDisplay(&vhptr,156*plr+39,i*30,65,36+i*51,103,65+i*51,0);
01186        Data->P[plr].Cash-=20;
01187        Data->P[plr].Spend[0][3]+=20;
01188        Data->P[plr].LaunchFacility[i]=1; p[i]=1;
01189        ShBox(110,69+i*51,262,77+i*51);
01190        RectFill(109,36+51*i,263,63+51*i,3);
01191        grSetColor(5);Missions(plr,111,41+i*51,m[i],0);
01192        PrintAt(113,75+i*51,"ASSIGN FUTURE MISSION");
01193      
01194      }
01195    else if (p[i]==-1 && Data->P[plr].Cash<20 && type==0)
01196     {Help("i129");}
01197 
01198 
01199      if (p[i]>4 && Data->P[plr].Cash>=abs(Data->P[plr].LaunchFacility[i])
01200         && type==0) {
01201      
01202        gxVirtualDisplay(&vhptr,156*plr+39,i*30,65,36+i*51,103,65+i*51,0);
01203        Data->P[plr].Cash-=Data->P[plr].LaunchFacility[i];
01204        Data->P[plr].Spend[0][3]+=Data->P[plr].LaunchFacility[i];
01205        Data->P[plr].LaunchFacility[i]=1; p[i]=1;
01206        RectFill(109,36+51*i,263,63+51*i,3);
01207        ShBox(110,69+i*51,262,77+i*51);
01208        grSetColor(5);Missions(plr,111,41+i*51,m[i],0);
01209        PrintAt(113,75+i*51,"ASSIGN FUTURE MISSION");
01210      
01211      }
01212      else if (p[i]>4 && Data->P[plr].Cash<abs(Data->P[plr].LaunchFacility[i])
01213         && type==0) {Help("i129");}
01214        };
01215      };
01216    };
01217   return pad;
01218 };
01219 
01220 char RequestX(char *s,char md)
01221 {
01222   char i;
01223   GXHEADER local;
01224 
01225   
01226   if (md==1) {  // Save Buffer
01227     GV(&local,196,84);
01228     gxGetImage(&local,85,52,280,135,0);
01229   }
01230   i=strlen(s)>>1;
01231   grSetColor(0);
01232   ShBox(85,52,249,135);
01233   IOBox(170,103,243,130);
01234   IOBox(91,103,164,130);
01235   InBox(92,58,243,97);
01236   grSetColor(1);
01237   DispBig(109,110,"YES",0,0);
01238   DispBig(196,110,"NO",0,0);
01239   grSetColor(11);
01240   DispBig(166-i*10,65,&s[0],0,-1);
01241   PrintAt(138,94,"ARE YOU SURE");
01242   
01243   WaitForMouseUp();
01244   i=2;
01245   while(i==2) {
01246     GetMouse();
01247      if ((x>=172 && y>=105 && x<=241 && y<=128 && mousebuttons!=0)||(key=='N')) {
01248        InBox(172,105,241,128);i=0;
01249        delay(50);key=0;
01250      };
01251      if ((x>93 && y>=105 && x<=162 && y<=128&& mousebuttons!=0)||(key=='Y')) {
01252        InBox(93,105,162,128);i=1;
01253        delay(50);key=0;
01254      };
01255   };
01256 
01257   if (md==1) {
01258     
01259     WaitForMouseUp();
01260     gxPutImage(&local,gxSET,85,52,0);
01261     DV(&local);
01262   }
01263   WaitForMouseUp();
01264   return i;
01265 }
01266 
01267 
01268 void SaveMail(void)
01269 {
01270  long size;
01271  int tFiles,i,done=0,temp,left;
01272  FILE *fin,*fout;
01273  char Name[12];
01274  extern char plr[2],AI[2];
01275 
01276   tFiles=GenerateTables(0);
01277   if (tFiles)EMPTY_BODY;
01278   memset(SaveHdr->Name,0x00,23);
01279   // done=GetBlockName(SaveHdr->Name);  // Checks Free Space
01280   strcpy(SaveHdr->Name,FList[fOFF].Title);
01281     SaveHdr->ID = RaceIntoSpace_Signature;
01282   SaveHdr->Name[22]=0x1A;
01283   temp=NOTSAME;
01284   done=YES;
01285   for (i=0;(i<tFiles && temp==2);i++) 
01286    if (strcmp(SaveHdr->Name,FList[i].Title)==0)
01287     {
01288      temp=1;
01289      if (temp==SAME_ABORT) done=0;
01290     }
01291   if (done==YES)
01292    {
01293      i--;  // decrement to correct for the FOR loop
01294      strcpy(SaveHdr->PName[0],Data->P[plr[0] % 2].Name);
01295      strcpy(SaveHdr->PName[1],Data->P[plr[1] % 2].Name);
01296 
01297     // play-by-mail save game hack
01298     // switch sides
01299 
01300     if (MAIL==0) {plr[0]=0;plr[1]=9;}
01301      else if (MAIL==1) {plr[0]=8;plr[1]=1;}
01302     Data->Def.Plr1=plr[0];Data->Def.Plr2=plr[1];
01303      Data->plr[0]=Data->Def.Plr1;   
01304      Data->plr[1]=Data->Def.Plr2;
01305      AI[0]=0;AI[1]=0;
01306 
01307      SaveHdr->Country[0]=Data->plr[0];
01308      SaveHdr->Country[1]=Data->plr[1];
01309 
01310      SaveHdr->Season=Data->Season;
01311      SaveHdr->Year=Data->Year;
01312      SaveHdr->dataSize=sizeof(struct Players);
01313 
01314         EndOfTurnSave((char *) Data, sizeof ( struct Players));
01315 
01316     MAIL=-1; //Reset Mail
01317      fin=sOpen("ENDTURN.TMP","rb",1);
01318      if (fin)
01319      {
01320        SaveHdr->compSize=fread(vhptr.vptr,1,vhptr.w*vhptr.h,fin);
01321        fclose(fin);
01322       } else SaveHdr->compSize=0;
01323 
01324      if (temp==NOTSAME)
01325      { 
01326        i=0;
01327      fin=NULL;
01328        do {
01329         i++;
01330       if (fin) fclose(fin);
01331         sprintf(Name,"BUZZ%d.SAV",i);
01332         fin=sOpen(Name,"rb",1);
01333        } while (fin!=NULL);  // Find unique name
01334      fin=sOpen(Name,"wb",1);
01335       }
01336      else fin=sOpen(FList[i].Name,"wb",1);
01337        
01338       fwrite(SaveHdr,sizeof (SaveFileHdr),1,fin);
01339      fout=sOpen("ENDTURN.TMP","rb",1);
01340      size=16000L;
01341      fseek(fout,0x00,SEEK_SET);
01342      while (size==16000)
01343       {
01344        size=(long) fread(vhptr.vptr,1,size,fout);
01345        fwrite(vhptr.vptr,size,1,fin); // save Replay File
01346       }
01347      fclose(fout);
01348      fout=sOpen("REPLAY.DAT","rb",1);
01349      fread(vhptr.vptr,(sizeof(REPLAY))*MAX_REPLAY_ITEMS,1,fout);
01350      fclose(fout);
01351      fwrite(vhptr.vptr,(sizeof(REPLAY))*MAX_REPLAY_ITEMS,1,fin); // save Replay File
01352      fout=sOpen("EVENT.TMP","rb",1);  // Save Event File
01353      left=32000; // copy EVENT.TMP FILE
01354      while (left==32000)
01355       {
01356        left=fread(vhptr.vptr,1,32000,fout);
01357        fwrite(vhptr.vptr,left,1,fin);
01358       }
01359      fclose(fout); // close EVENT.TMP
01360       fclose(fin);
01361     }    
01362 }
01363 
01364 // Save Game related functions
01365 void EndOfTurnSave(char *inData, int dataLen)
01366 {
01367     FILE *fout = NULL;
01368     int compressedLen = 0;
01369     char buffer[dataLen * 2];
01370 
01371     // Remove old save data
01372     remove_savedat("ENDTURN.TMP");
01373 
01374     // Create new save data
01375     fout = sOpen("ENDTURN.TMP","wb",1);  
01376     compressedLen = RLEC(inData, buffer, dataLen);
01377 #ifdef OLD_DOS_ENCRYPT_SAVEDATA
01378     {
01379         int moo = 0;
01380         srand(compressedLen);       // Seed the random number generator with file length
01381         for(moo=0;moo<j;moo++) 
01382         {
01383             buffer[moo]^=random(256);   //
01384         }
01385         // Reseed the random number generator 
01386         // -- this may have been the source of created complaints about randomness
01387         randomize();
01388     }
01389 #endif
01390 
01391     fwrite(buffer, compressedLen, 1, fout);
01392     fclose(fout);
01393 }
01394 
01395 // EOF

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