main.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 
00019 //****************************************************************
00020 //*Interplay's BUZZ ALDRIN's RACE into SPACE                     *
00021 //*                                                              *
00022 //*Formerly -=> LiftOff : Race to the Moon :: IBM version MCGA   *
00023 //*Copyright 1991 by Strategic Visions, Inc.                     *
00024 //*Designed by Fritz Bronner                                     *
00025 //*Programmed by Michael K McCarty                               *
00026 //*                                                              *
00027 //****************************************************************
00028 
00029 #include "Buzz_inc.h"
00030 #include "options.h"
00031 #include "utils.h"
00032 #include "logging.h"
00033 #include "externs.h"
00034 #include <ctype.h>
00035 
00036 #ifdef CONFIG_MACOSX
00037 // SDL.h needs to be included here to replace the original main() with
00038 // what it needs for the Mac
00039 #include <SDL.h>
00040 #endif
00041 
00042   int cdROM,hDISK;
00043 
00044   char Name[20];
00045   struct Players *Data;
00046   int x,y,mousebuttons,key,oldx,oldy;
00047   unsigned char LOAD,QUIT,HARD1,UNIT1,BUTLOAD,FADE,AL_CALL,XMAS;
00048   char plr[NUM_PLAYERS],IDT[5],IKEY[5],df,IDLE[2];
00049   char *buffer;
00050   GXHEADER vhptr,vhptr2;
00051   char * oldpal,pNeg[NUM_PLAYERS][MAX_MISSIONS];
00052   long xMODE;
00053   HTIMER server;
00054   char Option=-1,MAIL=-1;
00055   int SEG=15,FadeVal,fOFF=-1;
00056   extern struct mStr Mis;
00057   extern struct Prest_Upd MP[3];
00058   struct cdtable *cdt;
00059   long PalOff;
00060   ui16 LetHand;
00061   char BIG;         /**< 1 for fullscreen mission playback, 0 otherwise */
00062 
00063 char *S_Name[] = {
00064    "LAUNCH",
00065    "ORBITAL INS. BURN",
00066    "HARDWARE POWER-ON",
00067    "RE-ENTRY",
00068    "RECOVERY/LANDING",
00069    "EARTH ORBITAL ACTIVITIES",
00070    "EARTH DE-ORBIT BURN",
00071    "ORBITAL EVA",
00072    "DOCKING",
00073    "TRANS-LUNAR INJECTION",
00074    "TRANS-EARTH INJECTION",
00075    "LUNAR ORBITAL INS. BURN",
00076    "LUNAR ORBITAL ACTIVITIES",
00077    "EARTH MID-COURSE ACT.",
00078    "LUNAR MID-COURSE ACT.",
00079    "LUNAR EVA",
00080    "LEM ACTIVITIES",
00081    "LUNAR DE-ORBIT BURN",
00082    "LUNAR LANDING",
00083    "LUNAR LIFTOFF",
00084    "PHOTO RECONNAISSANCE",
00085    "PLANET ORBIT BURN",
00086    "PLANETARY ACTIVITIES",
00087    "EARTH RENDEZVOUS",
00088    "LUNAR RENDEZVOUS",
00089    "TRANS-PLANETARY INJ.",
00090    "LEM THRUST TEST",
00091    "DURATION",
00092    "JOINT DURATION",
00093    "\0",
00094    "MID-COURSE CORR. BURN",
00095    "MID-COURSE CORR. BURN",
00096    "EARTH ORBITAL INS. BURN"
00097    };
00098 
00099 #define BSOUND 1
00100 #define HOST 0
00101 #define SLAVE 1
00102 #define MODEM_ERROR 4
00103 
00104 extern struct order Order[6];
00105 extern struct ManPool *Men;
00106 char AI[2]={0,0};
00107 
00108 #ifdef DEAD_CODE
00109 static char BUZZ_DIR[32];
00110 
00111 void Plop(char plr,char mode);
00112 #endif
00113 
00114 LOG_DEFAULT_CATEGORY(LOG_ROOT_CAT);
00115 
00116 int main(int argc, char *argv[])
00117 {
00118   int i;
00119   FILE *fin;
00120   const char * see_readme = "look for further instructions in the README file";
00121 
00122   char AName[6][22]={"NEW GAME","OLD GAME","MODEM","PLAY BY MAIL","CREDITS","EXIT TO DOS"};
00123   char ex;
00124 
00125   argc = setup_options(argc, argv);
00126   /* hacking... */
00127   log_setThreshold(&_LOGV(LOG_ROOT_CAT), max(0, LP_NOTICE-options.want_debug));
00128 
00129   fin = open_gamedat("USA_PORT.DAT");
00130   if (fin == NULL)
00131   {
00132       CRITICAL1("can't find game data files");
00133       NOTICE1("set environment variable BARIS_DATA or edit config file");
00134       NOTICE2("%s", see_readme);
00135       exit(EXIT_FAILURE);
00136   }
00137   fclose(fin);
00138 
00139   if (create_save_dir() != 0)
00140   {
00141       CRITICAL3("can't create save directory `%s': %s",
00142               options.dir_savegame, strerror(errno));
00143       NOTICE1("set environment variable BARIS_SAVE to a writable directory");
00144       NOTICE2("%s", see_readme);
00145       exit(EXIT_FAILURE);
00146   }
00147 
00148   av_setup();
00149 
00150   strcpy(IDT,"i000\0");  strcpy(IKEY,"k000\0");
00151 
00152   LOAD=QUIT=0;
00153 
00154   xMODE=0;
00155 
00156   xMODE|=xMODE_NOCOPRO;
00157 
00158   Data = xmalloc(sizeof (struct Players) + 1);
00159   buffer = xmalloc(BUFFER_SIZE);
00160 
00161   DEBUG3("main buffer %p (%d)", buffer, BUFFER_SIZE);
00162 
00163   memset(buffer,0x00,BUFFER_SIZE);
00164 
00165   OpenEmUp();                   // OPEN SCREEN AND SETUP GOODIES
00166   if (options.want_intro)
00167       Introd();
00168 
00169   ex=0;
00170   while(ex==0) {
00171 
00172     MakeRecords();
00173 
00174     // ReadInitialGameData((HIST)?"HIST.DAT":"RAST.DAT");
00175     if (HIST) fin=sOpen("HIST.DAT","rb",0);
00176     else fin=sOpen("RAST.DAT","rb",0);
00177     i=fread(buffer,1,BUFFER_SIZE,fin); 
00178     fclose(fin);
00179 
00180     DEBUG2("reading Players: size = %d", (int)sizeof (struct Players));
00181     RLED(buffer,(char *)Data,i);
00182 #ifdef __BIG_ENDIAN__
00183         SwapGameDat();  // Take care of endian read
00184 #endif
00185     if (Data->Checksum!=(sizeof (struct Players))) {
00186         /* XXX: too drastic */
00187       CRITICAL1("wrong version of data file");
00188       exit(EXIT_FAILURE);
00189     }
00190 
00191     gxClearDisplay(0,0);
00192     PortPal(0);
00193     key=0;strcpy(IDT,"i000\0");strcpy(IKEY,"i000\0");
00194     df=1;
00195 
00196 tommy:
00197         music_start(M_LIFTOFF);
00198             
00199     i=99;
00200     while (i == 99)
00201      {
00202       i=MChoice(6,(char *)AName);
00203       if (i==98) goto tommy;
00204       IDLE[0]=IDLE[1]=0;
00205       if (i==99) {Introd();PortPal(0);}
00206      }
00207 
00208     switch(i) {
00209       case 1:  // New Game
00210           LOAD=QUIT=0,BUTLOAD=0;
00211           HARD1=UNIT1=1;
00212          MAIL=-1;Option=-1;
00213          strcpy(IDT,"i013");
00214           Prefs(0);                     // GET INITIAL PREFS FROM PLAYER
00215           plr[0]=Data->Def.Plr1;         // SET GLOBAL PLAYER VALUES
00216           plr[1]=Data->Def.Plr2;
00217           Data->plr[0]=Data->Def.Plr1;    // SET STRUCTURE PLAYER VALUES
00218           Data->plr[1]=Data->Def.Plr2;
00219           if (plr[0]==2 || plr[0]==3) AI[0]=1;
00220           else AI[0]=0;
00221           if (plr[1]==2 || plr[1]==3) AI[1]=1;
00222           else AI[1]=0;
00223           InitData();                   // PICK EVENT CARDS N STUFF
00224           MainLoop();                   // PLAY GAME
00225             gxClearDisplay(0,0);
00226           break;
00227       case 2: // Play Old Game
00228            LOAD=QUIT=BUTLOAD=0;
00229            HARD1=UNIT1=1;
00230           MAIL=-1;Option=-1;
00231            FileAccess(1);
00232 
00233            if (LOAD==1)
00234           {
00235            if (Option==-1 && MAIL==-1) MainLoop(); //Regular game
00236             else { //Modem game
00237             WARNING1("can't do modem games");
00238             break;
00239         }
00240           }
00241          else if (!QUIT) FadeOut(2,pal,10,0,0);
00242          QUIT=0;
00243         gxClearDisplay(0,0);
00244           break;
00245       case 3:
00246          break;
00247       case 4:
00248           break;
00249       case 5:
00250          df=0;
00251          Credits();
00252          df=1;
00253           break;
00254       case 6:
00255          //KillMusic();
00256           ex=1;
00257          FadeOut(2,pal,10,0,0);
00258          break;
00259     }
00260   }
00261 
00262   CloseEmUp(0,0);  // Normal Exit
00263   exit(EXIT_SUCCESS);
00264 }
00265 
00266 /** utility fn for AI to see if it should scrub the mission
00267  * 
00268  * Rules are:
00269  * - always do unmanned missions
00270  * - Safety must be within 15 of R&D-Safety
00271  * 
00272  * \param plr Playerdata
00273  * \param launchIdx ID of the launch
00274  */
00275 int CheckIfMissionGo(char plr,char launchIdx)
00276 {
00277   char idx,mcode;
00278   struct MissionType *pMission;
00279   Equipment *E = NULL;  /* Pointer to Equipment we're looking at */
00280 
00281     // Grab the Mission Code from the current Launch Index
00282   mcode=Data->P[plr].Mission[launchIdx].MissionCode;
00283   pMission=&Data->P[plr].Mission[launchIdx];
00284 
00285     // Always a go for Unmanned missions
00286   /** \todo introduce mission attribute "manned vs. unmanned" */
00287   if (mcode==1 || mcode==3 || mcode==5 || (mcode>=7 && mcode<=13) || mcode==15)
00288      return 1;
00289 
00290     // Spin through mission hardware checking safety
00291     for (idx = Mission_Capsule; idx <= Mission_PrimaryBooster; idx++) {
00292         switch(idx) {
00293             case Mission_Capsule:
00294                 E=&Data->P[plr].Manned[pMission->Hard[idx]];
00295                 E->MisSaf=E->Safety;
00296                 break;
00297             case Mission_Kicker:
00298                 E=&Data->P[plr].Misc[pMission->Hard[idx]];
00299                 E->MisSaf=E->Safety;
00300                 break;
00301             case Mission_LM:
00302                 E=&Data->P[plr].Manned[pMission->Hard[idx]];
00303                 E->MisSaf=E->Safety;
00304                 break;
00305             case Mission_PrimaryBooster:
00306                 E=&Data->P[plr].Manned[pMission->Hard[idx%4]];  // YYY No idea why this is using this value
00307 
00308                 // YYY  Safety check for this is never reached
00309                 if (idx>Mission_PrimaryBooster)     // implies
00310                     E->MisSaf = (int) (E->Safety+Data->P[plr].Manned[pMission->Hard[Mission_PrimaryBooster]].Safety) >> 1;
00311                 break;
00312         }
00313 
00314         if (E && idx != Mission_Probe_DM && pMission->Hard[idx]>=0)
00315         {
00316             // If mission Safety is not within 15 points of the MaxRD then NO Go
00317             if (E->MisSaf < (E->MaxRD-15))
00318                 return 0;
00319         }
00320     }
00321   return 1;
00322 }
00323 
00324 void InitData(void)
00325 {
00326   int i,j;
00327 
00328   SetEvents();                  // RESET EVENT CARDS
00329   Data->Count=0;                 // SET EVENT COUNTER TO ZERO
00330   for(j=0;j<NUM_PLAYERS;j++)
00331     for(i=0;i<5;i++)
00332       Data->P[j].PresRev[i]=8;
00333   return;
00334 }
00335 
00336 void MainLoop(void)
00337 {
00338 int i,j,t1,t2,t3,prest,sign,kik;
00339 
00340   if (LOAD!=1) {
00341     Data->P[0].Cash=Data->P[0].Budget;   // INCREMENT BY BUDGET
00342     Data->P[1].Cash=Data->P[1].Budget;
00343   }
00344 
00345 restart:                              // ON A LOAD PROG JUMPS TO HERE
00346 
00347   LOAD=0;                             // CLEAR LOAD FLAG
00348 
00349   while (Data->Year < 78)              // WHILE THE YEAR IS NOT 1977
00350   {
00351         EndOfTurnSave((char *) Data, sizeof ( struct Players));
00352 
00353    Data->P[0].RDMods=0;           // CLEAR ALL TURN RD MODS
00354    Data->P[1].RDMods=0;
00355 
00356    Data->P[0].BudgetHistory[Data->Year-53]=Data->P[0].Budget; // RECORD BUDGET
00357    Data->P[1].BudgetHistory[Data->Year-53]=Data->P[1].Budget;
00358 
00359    Data->P[0].BudgetHistoryF[Data->Year-53]=     // MAKE ESTIMATE OF BUDGETS
00360       (Data->P[0].Budget*(random(40)+80))/100;
00361    Data->P[1].BudgetHistoryF[Data->Year-53]=
00362       (Data->P[1].Budget*(random(40)+80))/100;
00363 
00364   for(t1=0;t1<NUM_PLAYERS;t1++)                   // Move Expenditures down one
00365   {
00366     for(t2=4;t2>=0;t2--)
00367      for(t3=0;t3<4;t3++)
00368     Data->P[t1].Spend[t2][t3]=Data->P[t1].Spend[t2-1][t3];
00369     for(t3=0;t3<4;t3++)
00370      Data->P[t1].Spend[0][t3]=0;
00371   };
00372    if(Data->Season==0) CalcPresRev();
00373 
00374    for (i=0;i<NUM_PLAYERS;i++) {
00375      xMODE&= ~xMODE_CLOUDS;  // reset clouds for spaceport
00376      if (Data->Season==1) {
00377        IntelPhase(plr[i]-2*AI[i],0);
00378       }
00379    // computer vs. human
00380 
00381    if ((IDLE[0]>12 || IDLE[1]>12) || ((AI[i] && plr[other(i)]<NUM_PLAYERS && ((Data->Def.Lev1!=0 && other(i)==0) || (Data->Def.Lev2!=0 && other(i)==1)))))
00382     {
00383      if (IDLE[0]>12 || IDLE[1]>12 || Data->P[abs(i-1)].PresRev[0]>=16)
00384       {
00385        strncpy(IDT,"i136",4);
00386        Data->P[abs(i-1)].PresRev[0]=0x7F;
00387        strncpy(IDT,"i000",4);
00388        if (IDLE[0]>12 || IDLE[1]>12) SpecialEnd();
00389        else {
00390          Review(abs(i-1));
00391          FakeWin(plr[i]-2);
00392        }
00393        FadeOut(2,pal,10,0,0);
00394        QUIT=1;
00395        return;
00396       }
00397     };
00398      if (!AI[i]) {
00399        NextTurn(plr[i]);
00400        VerifySF(plr[i]);
00401        News(plr[i]);                  // EVENT FOR PLAYER
00402        if ((Data->P[plr[i] % 2].Mission[0].MissionCode>6 ||
00403            Data->P[plr[i] % 2].Mission[1].MissionCode>6 ||
00404            Data->P[plr[i] % 2].Mission[2].MissionCode>6) &&
00405            (NOCOPRO && !PUSSY ))
00406           xMODE &= ~xMODE_NOCOPRO;
00407        VerifyCrews(plr[i]);
00408        VerifySF(plr[i]);
00409        strncpy(IDT,"i000",4);strncpy(IKEY,"k000",4);
00410        FixPrograms(plr[i]);
00411 
00412        //soften sound
00413 //       SetVoiceVolume(80);            // 80% seems good MWR
00414        Master(plr[i]);                // PLAY TURN
00415        //restore sound
00416 //       SetVoiceVolume(115);
00417         gxClearDisplay(0,0);
00418        IDLE[plr[i]]++;
00419        if (LOAD==1) goto restart;     // TEST FOR LOAD
00420      } else {
00421       AI_Begin(plr[i]-2);  // Turns off Mouse for AI
00422       GetMouse();
00423       VerifySF(plr[i]-2);
00424         AIEvent(plr[i]-2);VerifySF(plr[i]-2);
00425         AIMaster(plr[i]-2);
00426       AI_Done(); // Fade Out AI Thinking Screen and Restores Mouse
00427      };
00428      Data->Count++;
00429      if (QUIT) return;
00430    };
00431 
00432    DockingKludge();  // fixup for both sides
00433 
00434    // Do Missions Here
00435    kik=OrderMissions();
00436 
00437 for (i = 0; i < kik; i++)
00438     if (Data->P[Order[i].plr].Mission[Order[i].loc].MissionCode != 0)
00439     {
00440         if (AI[Order[i].plr] == 1)
00441         {
00442             if (!CheckIfMissionGo(Order[i].plr, Order[i].loc))
00443                 ClrMiss(Order[i].plr, Order[i].loc);
00444         }
00445         if (Data->P[Order[i].plr].Mission[Order[i].loc].MissionCode != 0)
00446         {
00447             if (!AI[Order[i].plr])
00448                 IDLE[0] = IDLE[1] = 0;
00449             if (!(Data->P[Order[i].plr].Mission[Order[i].loc].part == 1
00450                     || Data->P[Order[i].plr].Mission[Order[i].loc].Hard[4] ==
00451                     0))
00452             {
00453                 prest = Launch(Order[i].plr, Order[i].loc);
00454                 // check for prestige firsts
00455                 if (AI[Order[i].plr] == 1 && Data->Prestige[22].Place == -1)    // supposed to be 1
00456                     for (j = 0; j < 28; j++)
00457                     {
00458                         if (j != 4 && j != 5 && j != 6)
00459                             if (Data->Prestige[j].Place == Order[i].plr
00460                                 && Data->PD[Order[i].plr][j] != 1)
00461                             {
00462                                 PlayFirst(Order[i].plr, j);
00463                             }
00464                     }
00465                 if (Data->Prestige[22].Place != -1)
00466                 {
00467                     UpdateRecords(1);
00468                     NewEnd(Data->Prestige[22].Place, Order[i].loc);
00469                     FadeOut(2, pal, 10, 0, 0);
00470                     return;
00471                 }
00472                 if (!AI[Order[i].plr] && prest != -20)  // -20 means scrubbed
00473                     MisRev(Order[i].plr, prest);
00474             }
00475         }
00476 
00477     };                             //for(i=0...
00478    Update();  /* Moves Future launches to Missions + More */
00479 
00480    // Update M array to speed AI code
00481    for (j=0;j<NUM_PLAYERS;j++) {
00482       for (i=0;i<Data->P[j].PastMis;i++) {
00483      if (Data->P[j].History[i].result>=100)
00484         Data->P[j].M[Data->P[j].History[i].MissionCode]=1;
00485      }
00486       }
00487 
00488    if (Data->Year==77 && Data->Season==1 && Data->Prestige[22].Place==-1)
00489      {  // nobody wins .....
00490       SpecialEnd();
00491       FadeOut(2,pal,10,0,0);
00492       return;
00493      }
00494 
00495    Data->P[0].Budget+=Data->P[0].Prestige;
00496    Data->P[1].Budget+=Data->P[1].Prestige;
00497    if (Data->P[0].Budget>180) Data->P[0].Budget=180;
00498    if (Data->P[1].Budget>180) Data->P[1].Budget=180;
00499   // move prestige history down one;
00500   for(t3=0;t3<2;t3++) // t3 is the index to the real and random hists
00501   {
00502     for(t1=0;t1<NUM_PLAYERS;t1++) // t1 is the player index
00503     {
00504       for(t2=4;t2>0;t2--) // t2 is the time index
00505     Data->P[t1].PrestHist[t2][t3]=Data->P[t1].PrestHist[t2-1][t3];
00506       sign = (Data->P[t1].Prestige < 0) ? -1 : 1;
00507 
00508       Data->P[t1].PrestHist[0][t3] = (t3 == 0) ? Data->P[t1].Prestige
00509       : (Data->P[t1].Prestige*4)/5+sign*random(Data->P[t1].Prestige*2/5)+1;
00510       if(t3==0) Data->P[t1].tempPrestige[Data->Season] += Data->P[t1].Prestige;
00511     }
00512   };
00513    Data->P[0].Prestige=Data->P[1].Prestige=0;
00514 
00515     if (Data->Season==1) {
00516       for (i=0;i<NUM_PLAYERS;i++) {
00517     Data->P[plr[i] % 2].Cash+=Data->P[plr[i]-AI[i] % 2].Budget;
00518     if (Data->P[plr[i] % 2].Cash > 999) Data->P[plr[i]-AI[i] % 2].Cash=900;
00519       }
00520     Data->Season=0;
00521     Data->Year++;
00522     } else Data->Season++;
00523   };
00524   FadeOut(2,pal,10,0,0);
00525   Museum(0);
00526   Museum(1);
00527   return;
00528 }
00529 
00530 void DockingKludge(void)
00531 {
00532   int j;
00533   for (j=0;j<NUM_PLAYERS;j++) {
00534     Data->P[j].Misc[4].MSF=
00535        maxx( maxx(Data->P[j].Probe[0].Safety,Data->P[j].Probe[1].Safety),
00536         Data->P[j].Probe[2].Safety);
00537   }
00538   return;
00539 }
00540 
00541 // Reset Crews on a particular Mission
00542 void FreePadMen(char plr,struct MissionType *XMis)
00543 {
00544    int i,c;
00545    if (XMis->PCrew>0) {    // Remove Primary Crew
00546       for (i=0;i<Data->P[plr].Gcnt[XMis->Prog][XMis->PCrew-1];i++) {
00547          c=Data->P[plr].Crew[XMis->Prog][XMis->PCrew-1][i]-1;
00548          Data->P[plr].Pool[c].Prime=0;
00549          }
00550       }
00551    if (XMis->BCrew>0) {    // Remove Backup Crew
00552       for (i=0;i<Data->P[plr].Gcnt[XMis->Prog][XMis->BCrew-1];i++) {
00553          c=Data->P[plr].Crew[XMis->Prog][XMis->BCrew-1][i]-1;
00554          Data->P[plr].Pool[c].Prime=0;
00555          }
00556       }
00557    return;
00558 }
00559 
00560 
00561 /** Destroy Pad and Reset any Crews affected
00562  * 
00563  * \param cost amount of MB to pay for repairs
00564  * \param pad number of the launch facility destroyed
00565  * \param plr Player data
00566  * \param mode 0 if future mission, 1 is current mission
00567  */
00568 void DestroyPad(char plr,char pad,int cost,char mode)
00569 {
00570    struct MissionType *BMis=NULL,*AMis=NULL;
00571 
00572    Data->P[plr].LaunchFacility[pad]=cost;  // Destroys pad
00573 
00574    AMis=(mode==0) ? &Data->P[plr].Future[pad] : &Data->P[plr].Mission[pad];
00575    if (AMis->Joint==1) {
00576       if (AMis->part==0) BMis=&AMis[1];
00577       if (AMis->part==1) BMis=&AMis[-1];
00578       }
00579 
00580    if (AMis!=NULL) {
00581       if (AMis->Men!=0) FreePadMen(plr,AMis);
00582       memset(AMis,0x00,sizeof (struct MissionType));
00583       }
00584    if (BMis!=NULL) {
00585       if (BMis->Men!=0) FreePadMen(plr,BMis);
00586       memset(BMis,0x00,sizeof (struct MissionType));
00587       }
00588 
00589    return;
00590 }
00591 
00592 void GV(GXHEADER *obj,int w,int h)
00593 {
00594   gxCreateVirtual(gxCMM,obj,gxVGA_13,w,h);
00595 }
00596 
00597 void DV(GXHEADER *obj)
00598 {
00599   gxDestroyVirtual(obj);
00600   return;
00601 }
00602 
00603 void
00604 GetMouse (void)
00605 {
00606     av_block ();
00607     GetMouse_fast ();
00608 }
00609 
00610 
00611 /* get mouse of keyboard input, non-blocking */
00612 void GetMouse_fast(void)
00613 {
00614   mousebuttons=0;
00615   oldx=x;oldy=y;
00616   
00617   gr_maybe_sync ();
00618   av_step ();
00619 
00620   if (XMAS!=0) {
00621       if (grGetMouseButtons()) {
00622           mousebuttons=1;
00623           grGetMousePressedPos(&x,&y);
00624       } else {
00625           mousebuttons=0;
00626           grGetMouseCurPos (&x, &y);
00627       }
00628   }
00629   while (bioskey(1)) {
00630     key=bioskey(0);
00631     if((key&0x00ff)>0) key=toupper(key & 0xff);
00632     mousebuttons=0;
00633     //grSetMousePos(319,199);
00634     }
00635 
00636    if (mousebuttons>0) key=0;
00637 
00638   if (key>>8==15) CloseEmUp(0,0);
00639   else if (XMAS && AL_CALL==0 && (key>>8==0x3B)) {
00640     if (mousebuttons!=1) Help(IDT);
00641     }
00642   else if (AL_CALL==0 && ((key>>8)==0x3C)) Help(IKEY);
00643   else if (AL_CALL==0 && ((key>>8)==0x3D)) Help("i123");
00644 }
00645 
00646 void WaitForMouseUp(void) 
00647 {
00648     // Wait for mouse and key to be up
00649     while (mousebuttons)
00650         GetMouse();
00651 }
00652 
00653 void WaitForKeyOrMouseDown(void) 
00654 {
00655     // Wait for mouse and key to be up
00656     while (mousebuttons==0 && key==0) 
00657         GetMouse();
00658 }
00659 
00660 
00661 void PauseMouse(void)
00662 {
00663     /* wait until mouse button is released */
00664     while(1)  {
00665         GetMouse(); /* blocks briefly */
00666         if (mousebuttons==0) break;
00667     }
00668 
00669     GetMouse ();
00670 }
00671 
00672 void PrintAt(int x,int y,char *s)
00673 {
00674   short i;
00675   if (x!=0 && y!=0) grMoveTo(x,y);
00676   if (strlen(s) > 100) return;
00677   for(i=0;i<(int)strlen(s);i++)
00678     DispChr(s[i]);
00679   av_need_update_xy(x, y-7, x+i*7, y);
00680   return;
00681 }
00682 
00683 void PrintAtKey(int x,int y,char *s,char val)
00684 {
00685   PrintAt(x, y, s);
00686   grMoveTo(x,y);grSetColor(9);
00687   DispChr(s[val]);
00688   return;
00689 }
00690 
00691 
00692 void DrawLED(int x,int y,char st)
00693 {
00694   int i,j;
00695   unsigned char Dots[2][5][5] ={
00696       {{0,9,9,10,0},{9,8,9,9,10},{9,9,9,9,10},{10,9,9,9,10},{0,10,10,10,0}}, // Red
00697       {{0,15,15,16,0},{15,14,15,15,16},{15,15,15,15,16},{16,15,15,15,16},{0,16,16,16,0}}}; // Grn
00698 
00699   for (i=0;i<5;i++) for (j=0;j<5;j++) if (Dots[st][i][j]!=0)
00700     grPutPixel(x+i,y+j,Dots[st][i][j]);
00701   return;
00702 }
00703 
00704 void DispBig(int x,int y,char *txt,char mode,char te)
00705 {
00706   int i,k,l,px;
00707   struct LET {char width,img[15][21];} letter;
00708   int c;
00709   int x0 = x;
00710 
00711   y--;
00712   if(mode)EMPTY_BODY;
00713 
00714   for (i=0;i<(int)strlen(txt);i++) {
00715     if (txt[i]==0x20) {x+=6;i++;};
00716     c=toupper(txt[i] & 0xff);
00717     if (c>=0x30 && c<=0x39) px=c-32;
00718     else px=c-33;
00719     if (c=='-') px++;
00720 
00721     memcpy(&letter,letter_dat + (sizeof letter*px),sizeof letter);  // copy letter over
00722     for (k=0;k<15;k++)
00723       for (l=0;l<letter.width;l++) {
00724         if (letter.img[k][l]!=0x03) {
00725          if ((letter.img[k][l]==0x01 || letter.img[k][l]==0x02) && i==te)
00726           grPutPixel(x+l,y+k,letter.img[k][l]+7);
00727         else grPutPixel(x+l,y+k,letter.img[k][l]);
00728         }
00729       }
00730     x+=letter.width-1;
00731   };
00732   av_need_update_xy(x0, y, x, y+15);
00733 }
00734 
00735 void DispNum(int xx,int yy,int num)
00736 {
00737   short n0,n1,n2,n3,t;
00738   if (xx!=0 && yy!=0) grMoveTo(xx,yy);
00739   t=num;
00740   num=abs(t);
00741   if (t<0) PrintAt(0,0,"-");
00742   n0=num/1000;
00743   n1=num/100-n0*10;
00744   n2=num/10-n0*100-n1*10;
00745   n3=num-n0*1000-n1*100-n2*10;
00746   if (n0!=0) {
00747     DispChr(n0+0x30);
00748     DispChr(n1+0x30);
00749     DispChr(n2+0x30);
00750     DispChr(n3+0x30);
00751   };
00752   if (n0==0 && n1!=0) {
00753     DispChr(n1+0x30);
00754     DispChr(n2+0x30);
00755     DispChr(n3+0x30);
00756   };
00757   if (n0==0 && n1==0 && n2!=0) {
00758     DispChr(n2+0x30);
00759     DispChr(n3+0x30);
00760   };
00761   if (n0==0 && n1==0 && n2==0)
00762     DispChr(n3+0x30);
00763   return;
00764 }
00765 
00766 
00767 void DispMB(int x,int y,int val)
00768 {
00769   DispNum(x,y,val);
00770   PrintAt(0,0," MB");
00771   return;
00772 }
00773 
00774 // Place a glimmer on a box
00775 void Gl(int x1,int x2,int y,char t)
00776 {
00777   int i,nx;
00778   char Glim[13]={31,30,29,28,27,1,1,1,27,28,29,30,31};
00779   if ((x2-x1)<30) return;
00780   nx=(x2-x1)/2;
00781   if (t==0) nx=nx-(nx/3);
00782   else nx=nx+(nx/3);
00783   for (i=0;i<13;i++) grPutPixel(x1+nx+i,y,Glim[i]);
00784   return;
00785 }
00786 
00787 void ShBox(int x1,int y1,int x2,int y2)
00788 {
00789   RectFill(x1,y1,x2,y2,3);
00790   OutBox(x1,y1,x2,y2);
00791   return;
00792 }
00793 
00794 void UPArrow(int x1,int y1)
00795 {
00796   grSetColor(4);grDrawLine(x1,y1,x1,25+y1);grDrawLine(3+x1,11+y1,5+x1,11+y1);
00797   grSetColor(2);grDrawLine(1+x1,y1,6+x1,11+y1);grDrawLine(3+x1,12+y1,3+x1,25+y1);
00798   return;
00799 };
00800 
00801 void RTArrow(int x1,int y1)
00802 {
00803  grSetColor(4);grDrawLine(x1,y1,x1+31,y1);grDrawLine(x1+20,y1+3,x1+20,y1+5);
00804  grSetColor(2);grDrawLine(x1,y1+3,x1+19,y1+3);grDrawLine(x1+31,y1+1,x1+20,y1+6);
00805  return;
00806 }
00807 
00808 void LTArrow(int x1,int y1)
00809 {
00810  grSetColor(4);grDrawLine(x1,y1,x1+31,y1);grDrawLine(x1+11,y1+3,x1+11,y1+5);
00811  grSetColor(2);grDrawLine(x1,y1+1,x1+11,y1+6);grDrawLine(x1+12,y1+3,x1+31,y1+3);
00812  return;
00813 }
00814 
00815 void DNArrow(int x1,int y1)
00816 {
00817   grSetColor(4);grDrawLine(x1,y1,x1,25+y1);grDrawLine(3+x1,14+y1,5+x1,14+y1);
00818   grSetColor(2);grDrawLine(3+x1,y1,3+x1,13+y1);grDrawLine(6+x1,14+y1,1+x1,25+y1);
00819   return;
00820 };
00821 
00822 void InBox(int x1,int y1,int x2,int y2)
00823 {
00824   grSetColor(2);  grMoveTo(x1,y2);  grLineTo(x2,y2);  grLineTo(x2,y1);
00825   grSetColor(4);  grLineTo(x1,y1);  grLineTo(x1,y2);
00826   av_need_update_xy(x1, y1, x2, y2);
00827 }
00828 
00829 void OutBox(int x1,int y1,int x2,int y2)
00830 {
00831   grSetColor(4);  grMoveTo(x1,y2); grLineTo(x2,y2);  grLineTo(x2,y1);
00832   grSetColor(2);  grMoveTo(x2-1,y1); grLineTo(x1,y1);  grLineTo(x1,y2-1);
00833   av_need_update_xy(x1, y1, x2, y2);
00834 }
00835 
00836 void IOBox(int x1, int y1, int x2, int y2)
00837 {
00838   InBox(x1,y1,x2,y2);
00839   grSetColor(0);Box(x1+1,y1+1,x2-1,y2-1);
00840   OutBox(x1+2,y1+2,x2-2,y2-2);
00841 }
00842 
00843 void RectFill(int x1,int y1,int x2,int y2,char col)
00844 {
00845   grSetBkColor(col);
00846   grClearArea(x1,y1,x2,y2);
00847   return;
00848 }
00849 
00850 void Box(int x1,int y1,int x2,int y2)
00851 {
00852   grDrawRect(x1,y1,x2,y2,grOUTLINE);
00853   return;
00854 }
00855 
00856 void GradRect(int x1,int y1,int x2,int y2,char plr)
00857 {
00858   //register int i,j,val;
00859   //val=3*plr+6;
00860 
00861   RectFill(x1,y1,x2,y2,7+3*plr);
00862   //for (j=x1;j<=x2;j+=4)
00863   //  for (i=y1;i<=y2;i+=4)
00864   //    screen[j+320*i]=val;
00865    return;
00866 }
00867 
00868 void FlagSm(char plr,int xm,int ym)
00869 {
00870   int i;
00871   if (plr==0) {
00872     RectFill(xm,ym,xm+25,ym+14,1);
00873     grSetColor(8);
00874     for (i=0;i<15;i++) {
00875       grMoveTo(xm,ym+i);
00876       grLineTo(xm+25,ym+i);
00877       i++;
00878     };
00879     RectFill(xm,ym,xm+12,ym+7,5);
00880     xm++;
00881     for (i=0;i<11;i++) {
00882       grPutPixel(xm+i,ym+1,2);
00883       grPutPixel(xm+i,ym+3,2);
00884       grPutPixel(xm+i,ym+5,2);
00885        i++;
00886     };
00887     for (i=1;i<10;i++) {
00888       grPutPixel(xm+i,ym+2,2);
00889       grPutPixel(xm+i,ym+4,2);
00890       grPutPixel(xm+i,ym+6,2);
00891       i++;
00892     };
00893   } else {
00894     RectFill(xm,ym,xm+25,ym+14,8);
00895     grSetColor(11); grMoveTo(xm+2,ym+6); grLineTo(xm+4,ym+6); grLineTo(xm+4,ym+5);
00896     grLineTo(xm+5,ym+5); grLineTo(xm+5,ym+3);
00897     grPutPixel(xm+3,ym+4,11);grPutPixel(xm+4,ym+2,11);grPutPixel(xm+5,ym+1,11);
00898     grPutPixel(xm+6,ym+2,11);
00899   }
00900   return;
00901 }
00902 
00903 void Flag(int x,int y,char plr)
00904 {
00905   int i,j;
00906   if (plr==0) {
00907     for (i=0;i<7;i++) RectFill(x,y+i*6,x+69,y+2+i*6,8);
00908     for (i=0;i<6;i++) RectFill(x,y+3+i*6,x+69,y+5+i*6,1);
00909     RectFill(x,y,x+33,y+20,6);
00910     RectFill(x,y,x+32,y+20,5);
00911     for (j=0;j<5;j++) for (i=0;i<8;i++) PP(x+2+i*4,y+2+4*j,2);
00912     for (j=0;j<4;j++) for (i=0;i<7;i++) PP(x+4+i*4,y+4+4*j,2);
00913   } else {
00914     RectFill(x,y,x+69,38+y,8);
00915     PP(10+x,2+y,11);
00916     PP(8+x,3+y,11); PP(9+x,3+y,11);PP(11+x,3+y,11); PP(12+x,3+y,11);
00917     PP(9+x,5+y,11); PP(11+x,5+y,11);
00918     PP(12+x,6+y,11);
00919     PP(10+x,7+y,11);PP(13+x,7+y,11);
00920     PP(9+x,8+y,11);PP(10+x,8+y,11);PP(11+x,8+y,11);PP(14+x,8+y,11);
00921     PP(8+x,9+y,11);PP(9+x,9+y,11);PP(10+x,9+y,11);PP(14+x,9+y,11);PP(15+x,9+y,11);
00922     PP(7+x,10+y,11);PP(8+x,10+y,11);PP(9+x,10+y,11);PP(10+x,10+y,11);PP(14+x,10+y,11);PP(15+x,10+y,11);
00923     PP(11+x,11+y,11);PP(14+x,11+y,11);
00924     PP(12+x,12+y,11);PP(13+x,12+y,11);PP(14+x,12+y,11);
00925     PP(7+x,13+y,11);PP(8+x,13+y,11);PP(12+x,13+y,11);PP(13+x,13+y,11);
00926     PP(6+x,14+y,11);PP(9+x,14+y,11);PP(10+x,14+y,11);PP(11+x,14+y,11);
00927     PP(12+x,14+y,11);PP(13+x,14+y,11);PP(14+x,15+y,11);
00928     PP(9+x,4+y,12);PP(10+x,4+y,12);PP(11+x,4+y,12);
00929     PP(14+x,7+y,12); PP(8+x,11+y,12); PP(10+x,11+y,12); PP(15+x,11+y,12);
00930     PP(11+x,12+y,12); PP(14+x,13+y,12); PP(7+x,14+y,12); PP(5+x,15+y,12);
00931     PP(15+x,15+y,12);
00932   };
00933   return;
00934 }
00935 
00936 
00937 void DispChr(char chr)
00938 {
00939   switch(toupper(chr))
00940   {
00941     case 'A': LR(0,-3);LR(1,-1);LR(2,0);LR(1,1);LR(0,3);LR(-1,-1);
00942           LR(-2,0);MR(5,1);break;
00943     case 'B': LR(0,-4);LR(3,0);LR(1,1);LR(-1,1);LR(1,1);
00944           LR(-1,1);LR(-2,0);MR(0,-2);LR(1,0);MR(4,2);
00945           break;
00946     case 'C': MR(4,-4);LR(-3,0);LR(-1,1);LR(0,2);LR(1,1);LR(3,0);MR(2,0);
00947           break;
00948     case 'D': LR(0,-4);LR(3,0);LR(1,1);LR(0,2);LR(-1,1);LR(-2,0);MR(5,0);
00949           break;
00950     case 'E': LR(0,-4);LR(4,0);MR(0,4);LR(-3,0);MR(0,-2);LR(1,0);MR(4,2);
00951           break;
00952     case 'F': LR(0,-4);LR(4,0);MR(-2,2);LR(-1,0);MR(5,2);break;
00953     case 'G': MR(4,-4);LR(-3,0);LR(-1,1);LR(0,2);LR(1,1);LR(3,0);
00954           LR(0,-2);LR(-1,0);MR(3,2);break;
00955     case 'H': LR(0,-4);MR(1,2);LR(2,0);MR(1,-2);LR(0,4);MR(2,0);
00956           break;
00957     case 'I': LR(2,0);LR(-1,-1);LR(0,-2);LR(-1,-1);LR(2,0);MR(2,4);break;
00958     case 'J': MR(0,-1);LR(1,1);LR(2,0);LR(1,-1);LR(0,-3);MR(2,4);break;
00959     case 'K': LR(0,-4);MR(4,0);LR(-2,2);LR(-1,0);MR(1,0);LR(2,2);MR(2,0);
00960           break;
00961     case 'L': MR(0,-4);LR(0,4);LR(4,0);
00962           MR(2,0);break;
00963     case 'M': LR(0,-4);LR(2,2);LR(2,-2);LR(0,4);MR(2,0);break;
00964     case 'N': LR(0,-4);LR(4,4);LR(0,-4);MR(2,4);break;
00965     case 'O': case '0': MR(0,-1);LR(0,-2);LR(1,-1);LR(2,0);LR(1,1);
00966           LR(0,2);LR(-1,1);LR(-2,0);MR(5,0);break;
00967     case 'P': LR(0,-4);LR(3,0);LR(1,1);LR(-1,1);LR(-2,0);MR(5,2);break;
00968     case 'Q': MR(0,-1);LR(0,-2);LR(1,-1);LR(2,0);LR(1,1);
00969           LR(0,2);LR(-1,1);LR(-2,0);MR(2,-1);LR(1,1);MR(2,0);break;
00970     case 'R': LR(0,-4);LR(3,0);LR(1,1);LR(-1,1);LR(-2,0);MR(3,1);LR(0,1);
00971           MR(2,0);break;
00972     case 'S': LR(3,0);LR(1,-1);LR(-1,-1);LR(-2,0);LR(-1,-1);
00973           LR(1,-1);LR(3,0);MR(2,4);break;
00974     case 'T': MR(2,0);LR(0,-4);LR(-2,0);LR(4,0);MR(2,4);break;
00975     case 'U': MR(0,-4);LR(0,3);LR(1,1);LR(2,0);LR(1,-1);LR(0,-3);MR(2,4);break;
00976     case 'V': MR(0,-4);LR(0,2);LR(2,2);LR(2,-2);LR(0,-2);MR(2,4);break;
00977     case 'W': MR(0,-4);LR(0,4);LR(2,-2);LR(2,2);LR(0,-4);MR(2,4);break;
00978     case 'X': MR(0,-4);LR(4,4);MR(0,-4);LR(-4,4);MR(6,0);break;
00979     case 'Y': MR(2,0);LR(0,-1);LR(-2,-2);LR(0,-1);MR(4,0);LR(0,1);
00980           LR(-2,2);MR(4,1);break;
00981     case 'Z': MR(0,-4);LR(4,0);LR(-4,4);LR(4,0);MR(2,0);break;
00982     case '1': LR(2,0);LR(-1,-1);LR(0,-3);LR(-1,1);MR(4,3);break;
00983     case '2': MR(0,-4);LR(3,0);LR(1,1);LR(-1,1);LR(-1,0);LR(-2,2);
00984           LR(4,0);MR(2,0);break;
00985     case '3': LR(3,0);LR(1,-1);LR(-1,-1);LR(-1,0);LR(1,0);LR(1,-1);
00986           LR(-1,-1);LR(-3,0);MR(6,4);break;
00987     case '4': MR(4,-1);LR(-4,0);LR(0,-1);LR(2,-2);LR(1,0);LR(0,4);MR(3,0);
00988           break;
00989     case '5': LR(3,0);LR(1,-1);LR(-1,-1);LR(-2,0);LR(-1,-1);LR(0,-1);
00990           LR(4,0);MR(2,4);break;
00991     case '6': MR(1,-2);LR(2,0);LR(1,1);LR(-1,1);LR(-2,0);LR(-1,-1);
00992           LR(0,-2);LR(1,-1);LR(2,0);MR(3,4);break;
00993     case '7': MR(0,-4);LR(4,0);LR(0,1);LR(-2,2);LR(0,1);MR(4,0);break;
00994     case '8': MR(1,0);LR(2,0);LR(1,-1);LR(-1,-1);LR(-2,0);LR(-1,-1);
00995           LR(1,-1);LR(2,0);LR(1,1);MR(-4,2);LR(0,0);MR(6,1);break;
00996     case '9': MR(1,0);LR(2,0);LR(1,-1);LR(0,-2);LR(-1,-1);LR(-2,0);
00997           LR(-1,1);LR(1,1);LR(2,0);MR(3,2);break;
00998     case '-': MR(0,-2),LR(3,0);MR(2,2);break;
00999     case '.': LR(0,0);MR(2,0);break;
01000     case ',': MR(0,1);LR(1,-1);MR(2,0);break;
01001     case ':': MR(0,-1);LR(0,0);MR(0,-2);LR(0,0);MR(2,3);break;
01002     case '&': MR(0,-1);LR(1,1);LR(1,0);LR(1,-1);LR(1,1);LR(-2,-2);
01003           LR(-1,0);LR(0,-1);LR(1,-1);LR(1,1);MR(3,3);break;
01004     case ' ': MR(3,0); break;
01005     case '!': LR(0,0);MR(0,-2);LR(0,-2);MR(2,4);break;
01006     case '@':
01007     case '#': MR(1,0);LR(0,-4);MR(-1,1);LR(4,0);MR(-1,-1);LR(0,4);
01008           MR(1,-1);LR(-4,0);MR(6,1);break;
01009     case '%': LR(4,-4);MR(-3,0);LR(-1,1);LR(0,-1);LR(4,4);LR(-1,0);LR(1,-1);
01010           MR(2,1);break;
01011     case '(': MR(1,0);LR(-1,-1);LR(0,-2);LR(1,-1);MR(2,4);break;
01012     case ')': LR(1,-1);LR(0,-2);LR(-1,-1);MR(3,4);break;
01013     case '/': LR(4,-4);MR(2,4);break;
01014     case '<': MR(4,-4);LR(-2,2);LR(2,2);MR(2,0);break;
01015     case '>': MR(0,-4);LR(2,2);LR(-2,2);MR(4,0);break;
01016     case 0x27: MR(0,-4);LR(0,1);MR(2,3);break;
01017     case '*': MR(1,0);LR(0,-4);MR(-1,1);LR(4,0);MR(-1,-1);LR(0,4);
01018           MR(1,-1);LR(-4,0);MR(6,1);break;
01019     case '^': MR(0,-3);LR(1,-1);LR(1,0);LR(1,1);MR(0,3);break;
01020     case '?': MR(0,-3);LR(1,-1);LR(2,0);LR(1,1);LR(-1,1);
01021          MR(0,2);LR(0,0);MR(3,0);break;
01022     case 0x14: LR(0,-4);MR(2,4);
01023            break;
01024     default:  break;
01025   }
01026 }
01027 
01028 void VerifySF(char plr)
01029 {
01030   int i;
01031   Equipment *px;
01032 
01033   for (i=0;i<28;i++) {
01034     px=(Equipment *) &Data->P[plr].Probe[i];
01035     if (px->Safety>px->MaxSafety) px->Safety=px->MaxSafety;
01036     if (px->Safety<px->Base) px->Safety=px->Base;
01037   }
01038 }
01039 
01040 void VerifyCrews(char plr)
01041 {
01042   int i,t,k;
01043 
01044   for (i=0;i<3;i++) {
01045      if (Data->P[plr].Mission[i].MissionCode==18 && Data->P[plr].Mission[i].part==0) {
01046         Data->P[plr].Mission[i].Joint=1;
01047         Data->P[plr].Mission[i+1].Joint=1;
01048         Data->P[plr].Mission[i].part=0;
01049         Data->P[plr].Mission[i+1].part=1;
01050      }
01051      if (Data->P[plr].Mission[i].PCrew>0) {  // primary verify
01052         t=Data->P[plr].Mission[i].Prog;
01053         k=Data->P[plr].Mission[i].PCrew-1;
01054         if (Data->P[plr].Gcnt[t][k]==0) Data->P[plr].Mission[i].PCrew=0;
01055 
01056         t=Data->P[plr].Mission[i].Prog;  // backup verify
01057         k=Data->P[plr].Mission[i].BCrew-1;
01058         if (Data->P[plr].Gcnt[t][k]==0) Data->P[plr].Mission[i].BCrew=0;
01059 
01060      }
01061   }
01062 }
01063 
01064 /** Opens "MISSION.DAT" to find mission data
01065  * 
01066  * \param mcode Code of the mission - works as index for the file
01067  * 
01068  * \todo This is highly coupled to game logic 
01069  * and size of internal structures.
01070  */
01071 void GetMisType(char mcode)
01072 {
01073   FILE *fin;
01074     /** \todo Missing assert for opening file? */
01075   fin=sOpen("MISSION.DAT","rb",0);
01076   fseek(fin,mcode*(sizeof Mis),SEEK_SET); // Find Mission Type
01077   fread(&Mis,sizeof Mis,1,fin);            // Get new Mission Info
01078   fclose(fin);
01079 }
01080 
01081 
01082 int MisRandom(void)
01083 {
01084   int i,nval;
01085   do {
01086     nval=107;
01087     for (i=0;i<250;i++) nval+=(random(7)-3);
01088   } while (nval<50 || nval>150);
01089 
01090   return nval-50;
01091 }
01092 
01093 #ifdef DEAD_CODE
01094 #   ifdef CONFIG_THEORA_VIDEO
01095 #      include "av.h"
01096 #      include "mmfile.h"
01097 #   endif
01098 
01099 void
01100 Plop(char plr, char mode)
01101 {
01102     char sName[20];
01103 
01104 #   ifndef CONFIG_THEORA_VIDEO
01105     int wlen;
01106     FILE *fin;
01107     char *ext = "frm";
01108 #   else
01109     char *ext = "ogg";
01110     mm_file vidfile;
01111     char fname[1000];
01112 #   endif
01113 
01114     if (mode == 0)
01115         sprintf(sName, "%s%d.%s", (plr == 0) ? "us" : "sviet",
01116             random(5) + 1, ext);
01117     else if (mode == 1)
01118         sprintf(sName, "passt%02d.%s", random(11) + 1, ext);
01119     else
01120         sprintf(sName, "static.%s", ext);
01121 
01122 #   ifndef CONFIG_THEORA_VIDEO
01123     fin = sOpen(sName, "rb", 0);
01124     if (!fin)
01125         return;
01126     wlen = 8;
01127     fread(&vhptr.vptr[40000], 1, wlen * 2048, fin);
01128     vhptr.vptr[40000] = vhptr.vptr[40001] = vhptr.vptr[40002] =
01129         vhptr.vptr[40005];
01130     vhptr.vptr[55999] = vhptr.vptr[55995];
01131     vhptr.vptr[55998] = vhptr.vptr[55994];
01132     memcpy(&pal[384], &vhptr.vptr[56000], 384);
01133     /* SetPal(pal); FIXME */
01134     if (BIG == 0)
01135         SMove(&vhptr.vptr[40000], 80, 3 + plr * 10);
01136     else
01137         LMove(&vhptr.vptr[40000]);
01138     fclose(fin);
01139     return;
01140 #   else
01141     sprintf(fname, "%s/%s", movies_dir, sName);
01142     if (mm_open(&vidfile, fname) <= 0)
01143         return;
01144     if (mm_video_info(&vidfile, NULL, NULL, NULL) <= 0)
01145         goto end;
01146     if (mm_decode_video(&vidfile, video_overlay) <= 0)
01147         goto end;
01148     if (BIG == 0)
01149     {
01150         video_rect.w = 160;
01151         video_rect.h = 100;
01152         video_rect.x = 80;
01153         video_rect.y = 3 + plr * 10;
01154     }
01155     else
01156     {
01157         video_rect.x = MAX_X / 4;
01158         video_rect.y = MAX_Y / 4;
01159         video_rect.w = MAX_X / 2;
01160         video_rect.h = MAX_Y / 2;
01161     }
01162   end:
01163     mm_close(&vidfile);
01164 #   endif
01165 }
01166 
01167 #endif
01168 // EOF

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