mis_c.c

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2005 Michael K. McCarty & Fritz Bronner
00003 
00004     This program is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or
00007     (at your option) any later version.
00008 
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software
00016     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 */
00018 // Interplay's BUZZ ALDRIN's RACE into SPACE
00019 //
00020 // Formerly -=> LiftOff : Race to the Moon :: IBM version MCGA
00021 // Copyright 1991 by Strategic Visions, Inc.
00022 // Designed by Fritz Bronner
00023 // Programmed by Michael K McCarty
00024 //
00025 
00026 #include "gamedata.h"
00027 #include "Buzz_inc.h"
00028 #include "externs.h"
00029 #include "mis.h"
00030 #include "av.h"
00031 #include "mmfile.h"
00032 #include "utils.h"
00033 #include "logging.h"
00034 
00035 #include <assert.h>
00036 
00037 #define FRM_Delay 22
00038 
00039 #define NORM_TABLE 397
00040 #define CLIF_TABLE 240
00041 #define ANIM_PARTS 297
00042 #define SCND_TABLE 486
00043 
00044 LOG_DEFAULT_CATEGORY(mission);
00045 
00046  struct NTable {
00047   char ID[8];
00048  };
00049 
00050  struct Infin {
00051   char Code[9],Qty;
00052   i16 List[10];
00053  };
00054 
00055  struct OF {
00056   char Name[8];
00057   i16 idx;
00058  };
00059 
00060 struct Infin *Mob;
00061 struct OF *Mob2;
00062 int tFrames,cFrame;
00063 char SHTS[4];
00064 long aLoc;
00065 GXHEADER dply;
00066 struct AnimType AHead;
00067 struct BlockHead BHead;
00068 
00069 char STEPnum,loc[4];
00070 extern struct MisAst MA[2][4];
00071 extern struct MisEval Mev[60];
00072 extern char MANNED[2],STEP,pal2[768],AI[2],fEarly,LM[2],EVA[2];
00073 extern char BIG;
00074 
00075 void Tick(char plr);
00076 void Clock(char plr,char clck,char mode,char tm);
00077 // void Plop(char plr,char mode);
00078 
00079 // Who and What the hell are "Shining Happy People?"
00080 
00081 #if 0
00082 void RLEE (char *dest, char *src, unsigned int src_size)
00083 {
00084     asm push es;          // preserve ES
00085     asm push ds;          // preserve DS
00086     asm les di,dest;      // move dest into ES:DI
00087     asm lds si,src;       // move src into DS:SI
00088     asm mov cx,0;         // clear CX
00089     asm mov bx,src_size;  // move counter into BX
00090 loa:
00091     asm lodsb;            // move byte into AL
00092     asm dec bx;           // decrement CX
00093     asm cmp al,0;         // compare AL to 0
00094     asm jl repeat;        // if al < 0 jump to repeat
00095                   // copy bytes
00096     asm mov ah,0;         // clear AH
00097     asm inc al;           // increment AL
00098     asm mov cl,al;        // put value of AL into CL
00099     asm rep movsb;        // move CX bytes from DS:SI to ES:DI
00100     asm sub bx,ax;        // increment BX by approp value
00101     asm cmp bx,0;         // see if finished
00102     asm jg loa;           // if not then loop
00103     asm jmp bot;          // else jump to bottom
00104 
00105 repeat:
00106     asm neg al;           // negate AL
00107     asm inc al;           // increment AL by 1
00108     asm mov cl,al;        // move counter value to CX
00109     asm lodsb;            // load value to copy
00110 lob:
00111     asm stosb;            // copy AL into ES:DI
00112     asm loop lob;         // do while CX >0
00113     asm dec bx;           // decrement bx;
00114 
00115   asm cmp bx,100h;
00116   asm jg  sk;
00117   asm int   03h;
00118 
00119 sk:
00120     asm cmp bx,0;         // see if finished
00121     asm jg loa;           // if not then loop
00122 
00123 bot:                          // bottom of routine
00124     asm pop ds;           // restore ds
00125     asm pop es;           // restore es
00126 
00127   return;
00128 }
00129 #endif
00130 
00131 /**
00132  * 
00133  * \param mode Female or other (2 = female)
00134  * \param Seq Sequence-Code for the movies (?)
00135  */
00136 void PlaySequence(char plr,int step,char *Seq,char mode)
00137 {
00138     DEBUG4("->PlaySequence(plr, step %d, Seq %c, mode %s)", step, Seq, mode);
00139     int keep_going;
00140     int wlen,i,j;
00141     unsigned int fres,max;
00142     char lnch=0,AEPT,BABY,Tst2,Tst3;
00143     unsigned char sts=0,fem=0;
00144     FILE *fin,*fout,*ffin,*nfin;
00145     long offset;
00146     struct oGROUP *bSeq,aSeq;
00147     struct oFGROUP *dSeq,cSeq;
00148     struct Table *F;
00149     char sName[20],err=0;
00150     char *SEQ_DAT="SEQ.DAT";
00151     char *FSEQ_DAT="FSEQ.DAT";
00152     mm_file vidfile;
00153     FILE *mmfp;
00154     float fps;
00155     int hold_count;
00156 
00157     F = NULL; /* XXX check uninitialized */
00158     dSeq = NULL; /* XXX check uninitialized */
00159     bSeq = NULL; /* XXX check uninitialized */
00160     i = j = 0; /* XXX check uninitialized */
00161 
00162     memset(buffer,0x00,BUFFER_SIZE);
00163     SHTS[0]=random(10);SHTS[1]=random(10);SHTS[2]=random(10);SHTS[3]=random(10);
00164 
00165     if (fEarly && step!=0) return; //Specs: unmanned mission cut short
00166 
00167     //Specs: female'snaut klugge
00168     if (mode==2) {
00169         fem=1;  //Spec: additional search param.
00170         mode=0;
00171     } else fem=0;
00172 
00173     //Specs: Lem Activities Klugge
00174     if (Seq[0]=='h') {
00175         if (Mev[STEP-1].Name[0]=='S'){
00176           Seq[0]='Q';
00177         } else {
00178           Seq[0]='i';
00179           strncpy(Mev[step].FName,"F034",4);
00180         }
00181     };
00182 
00183     if (Seq[0]=='Q') {
00184         if (Mev[STEP-1].Name[0]!='S') {
00185             if (mode==0){ 
00186                 Seq[0]='i';
00187             } else if (mode==1) {
00188                 Seq[0]='i';
00189                 strncpy(Mev[step].FName,"F034",4);
00190             }
00191         }
00192         if ((Seq[1]=='U' || Seq[1]=='S') && Seq[2]=='C') {
00193             if (Seq[3]=='5'){ 
00194                 Seq[3]='6';
00195             } else if (Seq[3]=='6'){ 
00196                 Seq[3]='5';
00197             }
00198         }
00199     };
00200 
00201     //Specs: lm act lunar liftoff failure klugge and failed landing LPL
00202     if (mode==1) {
00203         if (Seq[0]=='T') {
00204             if (Seq[3]=='6' || Seq[3]=='5')
00205                 strncpy(Mev[STEP].FName,"F019",4);
00206         };
00207         if (Seq[0]=='Q') {
00208             if (Seq[3]=='6' || Seq[3]=='5')
00209                 strncpy(Mev[STEP].FName,"F216",4);
00210         };
00211         if (Seq[0]=='S') {
00212             if (Seq[2]=='P') strncpy(Mev[STEP].FName,"F118",4);
00213         };
00214         if (Seq[0]=='P') {
00215             //TC changero klugge
00216             if (Seq[5]=='6') {
00217                 Tst2 = Seq[4];
00218                 Tst3 = Seq[5];
00219                 Seq[4] = Seq[2];
00220                 Seq[5] = Seq[3];
00221                 Seq[2] = (char)Tst2;
00222                 Seq[3] = (char)Tst3;
00223                 strncpy(Mev[STEP].FName,"F115",4);
00224             }
00225         }
00226     }
00227 
00228     //Specs: launch sync
00229     if (Seq[0]=='#') lnch=1;
00230     else lnch=0;
00231 
00232     if (Seq[0]=='A' || Seq[0]=='E' || Seq[0]=='P' || Seq[0]=='T' || Seq[0]=='#')
00233         AEPT=1; else AEPT=0;
00234 
00235     if (mode==0) bSeq=(struct oGROUP *)&vhptr.vptr[35000];
00236     else dSeq=(struct oFGROUP *)&vhptr.vptr[35000];
00237 
00238     if (mode==0) {
00239         fin=open_gamedat(SEQ_DAT);
00240         offset=fread(&vhptr.vptr[35000],1,vhptr.h*vhptr.w-35000,fin);
00241     } else {
00242         fin = open_gamedat(FSEQ_DAT);
00243         F=(struct Table *)&vhptr.vptr[0];
00244         fread_Table(F,50,fin);
00245 
00246         err=0;  //Specs: reset error
00247 
00248         for (i=0;i<50;i++) {
00249             if (strncmp(F[i].fname,Mev[step].FName,4)==0)
00250                 break;
00251         }
00252 
00253         if (i==50) err=1;
00254 
00255         if (err==0) {
00256             fseek(fin, F[i].foffset, SEEK_SET);
00257             fread_oFGROUP(dSeq, F[i].size / sizeof_oFGROUP, fin);
00258         }
00259     };
00260 
00261     fclose(fin);
00262 
00263     if (mode==0) {
00264         j=0;
00265         while (strncmp(bSeq[j].ID,"XXXX",4)!=0 && strncmp(&bSeq[j].ID[3],Seq,strlen(&bSeq[j].ID[3]))!=0)
00266             j++;
00267 
00268         if (bSeq[j].ID[2]-0x30 == 1)
00269             if (fem==0) j++; 
00270     } else if (err==0) {
00271         j=0;
00272         memset(sName,0x00,sizeof sName);
00273         strncpy(sName,&dSeq[j].ID[3+strlen(&dSeq[j].ID[3])-2],2);
00274         while (strncmp(dSeq[j].ID,"XXXX",4) !=0 && strncmp(&dSeq[j].ID[3],Seq,strlen(&dSeq[j].ID[3])-2) !=0)
00275             j++;
00276         while(strncmp(sName,&Seq[strlen(Seq)-2],2) !=0) {
00277             j++;
00278             strncpy(sName,&dSeq[j].ID[3+strlen(&dSeq[j].ID[3])-2],2);
00279             if (j>=F[i].size/sizeof_oFGROUP) {err=1;break;} 
00280         }
00281     };
00282 
00283     if ((strncmp((mode==0) ? bSeq[j].ID : dSeq[j].ID,"XXXX",4)==0) || (mode==1 && err==1)) {
00284         //Specs: Search Error Play Static
00285         if (mode==0) {
00286             j=0;
00287         } else {
00288             fin=open_gamedat(FSEQ_DAT);
00289             fseek(fin,F[0].foffset,SEEK_SET);
00290             fread_oFGROUP(dSeq,F[0].size/sizeof_oFGROUP,fin);
00291             fclose(fin);
00292         }
00293     }
00294     if (mode==1 && err==1) j=0;
00295 
00296     //::::::::::::::::::::::::::::::::::::
00297     // Specs  Success Sequence Variation :
00298     //::::::::::::::::::::::::::::::::::::
00299     if (mode==0 && (bSeq[j].ID[0]-0x30 !=1)) {
00300         fres=0;
00301         fres=(unsigned)(bSeq[j].ID[0]-0x30);
00302         max=(unsigned)fres;
00303         fres=fres-1;
00304         wlen=0;
00305         while(1) {
00306             fres=random(10000);
00307             fres%=10;
00308             if (fres<max) break;
00309             wlen++;
00310             if (wlen>100) {fres=0;break;}
00311         };
00312         j+=fres;
00313     };
00314 
00315     //::::::::::::::::::::::::::::::::::::
00316     // Specs: Failure Sequence Variation :
00317     //::::::::::::::::::::::::::::::::::::
00318     if (mode==1 && (dSeq[j].ID[0]-0x30 !=1)) {
00319         fres=0;
00320         fres=(unsigned)(dSeq[j].ID[0]-0x30);
00321         max=(unsigned)fres;
00322         fres=fres-1;
00323         wlen=0;
00324         while(1) {
00325             fres=random(10000);
00326             fres%=10;
00327             if (fres<max) break;
00328             wlen++;
00329             if (wlen>100) {fres=0;break;}
00330         };
00331         j+=fres;
00332     };
00333 
00334     BABY=0;
00335     if (mode==0) {
00336         if (j>=1 && j<=22)
00337             BABY=1;
00338     }
00339 
00340     if (mode==0) memcpy(&aSeq,&bSeq[j],sizeof aSeq);
00341     else memcpy(&cSeq,&dSeq[j],sizeof cSeq);
00342 
00343     fout=sOpen("REPLAY.TMP","at",1);
00344     if (mode==0) fprintf(fout,"%d\n",(unsigned int)j);
00345     else {i+=1;fprintf(fout,"%d\n",(unsigned int)(i*1000+j));}
00346     // Specs: mode==1 save out fail seq (i*1000)+j 
00347     fclose(fout);
00348 
00349     if (AI[plr]==1) return;
00350 
00351     ffin=open_gamedat("BABYPICX.CDR");
00352 
00353     Mob=(struct Infin *) buffer;
00354 
00355     if (AEPT && !mode) {
00356         if ((nfin=open_gamedat("BABYCLIF.CDR"))==NULL) return;
00357         fread(Mob,CLIF_TABLE*(sizeof (struct Infin)),1,nfin); //Specs: First Table
00358 
00359 #ifdef __BIG_ENDIAN__
00360         for (i=0;i<CLIF_TABLE;i++)  {
00361             int ii;
00362             for (ii=0;ii<10;ii++)
00363                 Swap16bit(Mob[i].List[ii]);
00364         }
00365 #endif
00366         Mob2=(struct OF *)&buffer[15000];
00367         fseek(nfin,7200,SEEK_SET);
00368         fread(Mob2,SCND_TABLE*(sizeof (struct OF)),1,nfin);   //Specs: Second Table
00369         fclose(nfin);
00370 
00371 #ifdef __BIG_ENDIAN__
00372         for (i=0;i<SCND_TABLE;i++) 
00373             Swap16bit(Mob2[i].idx);
00374 #endif
00375 
00376         for (i=0;i<SCND_TABLE;i++) Mob2[i].Name[strlen(Mob2[i].Name)-3]='_'; // patch
00377     } else {
00378         nfin=open_gamedat("BABYNORM.CDR");
00379         fread(Mob,NORM_TABLE*(sizeof (struct Infin)),1,nfin);
00380         fclose(nfin);
00381 #ifdef __BIG_ENDIAN__
00382         for (i = 0; i< NORM_TABLE; i++)
00383         {
00384             int j;
00385             for (j=0;j<10;j++)
00386                 Swap16bit(Mob[i].List[j]);
00387         }
00388 #endif
00389     }
00390 
00391     // Plop(plr,1); //Specs: random single frame for sound buffering
00392 
00393     i=0;
00394 
00395     if (mode==0) max=aSeq.ID[1]-'0';
00396     else max=cSeq.ID[1]-'0';
00397 
00398     keep_going = 1;
00399     while (keep_going && i<(int)max) {
00400         int aidx, sidx;
00401         char *seq_name = NULL;
00402         char name[20]; /** \todo assumption about seq_filename len */
00403 
00404         if (mode==0) {
00405             aidx = aSeq.oLIST[i].aIdx;
00406             sidx = aSeq.oLIST[i].sIdx;
00407         } else {
00408             aidx = cSeq.oLIST[i].aIdx;
00409             sidx = cSeq.oLIST[i].sIdx;
00410         }
00411 
00412         Swap16bit(aidx);
00413         Swap16bit(sidx);
00414 
00415         if (sidx)
00416             play_audio (sidx, mode);
00417 
00418         if ((seq_name = seq_filename(aidx, mode)) == NULL)
00419             seq_name = "(unknown)";
00420 
00421         snprintf(name, sizeof(name), "%s.ogg", seq_name);
00422         mmfp = sOpen(name, "rb", FT_VIDEO);
00423 
00424         INFO2("opening video file `%s'", name);
00425         if (mm_open_fp(&vidfile, mmfp) <= 0)
00426             break;
00427 
00428         /** \todo do not ignore width/height */
00429         if (mm_video_info(&vidfile, NULL, NULL, &fps) <= 0)
00430             break;
00431 
00432         j=0;
00433 
00434         hold_count = 0;
00435         while (keep_going) {
00436             av_step ();
00437 
00438             if (BABY==0 && BIG==0) Tick(plr);
00439 
00440             if (hold_count == 0) {
00441 
00442                 /** \todo track decoding time and adjust delays */
00443                 if (mm_decode_video(&vidfile, video_overlay) <= 0)
00444                     break;
00445 
00446                 screen_dirty = 1;
00447 
00448             /* XXX I don't get the fancy "hold thing so I left it out */
00449 
00450             } else if (hold_count < 8) {
00451                 //Specs: single frame hold
00452                 idle_loop (FRM_Delay);
00453                 if (!BABY && BIG==0) Tick(plr);
00454                 idle_loop (FRM_Delay);
00455                 if (!BABY && BIG==0) Tick(plr);
00456                 idle_loop (FRM_Delay);
00457                 if (!BABY && BIG==0) Tick(plr);
00458                 idle_loop (FRM_Delay);
00459                 hold_count++;
00460             } else {
00461                 DEBUG1("need to come out of hold");
00462             }
00463 
00464             video_rect.w = 160;
00465             video_rect.h = 100;
00466             if (BIG==0)
00467             {
00468                 video_rect.x = 80;
00469                 video_rect.y = 3+plr*10;
00470             }
00471             else
00472             {
00473                 memset(screen, 0, MAX_X*MAX_Y);
00474                 video_rect.x = MAX_X / 4;
00475                 video_rect.y = MAX_Y / 4;
00476                 video_rect.h = MAX_Y / 2;
00477                 video_rect.w = MAX_X / 2;
00478             }
00479 
00480             /** \todo idle_loop is too inaccurate for this */
00481             idle_loop_secs(1.0 / fps);
00482             if (sts<23) {
00483                 if (BABY==0 && BIG==0) DoPack(plr,ffin,(AEPT && !mode) ? 1 : 0,Seq,seq_name);
00484                 ++sts;
00485                 if (sts==23) sts=0;
00486 
00487                 if (bioskey(0) || grGetMouseButtons())
00488                 {
00489                     av_silence (AV_SOUND_CHANNEL);
00490                     keep_going = 0;
00491                 }
00492                 if (Data->Def.Anim) {
00493                     idle_loop (FRM_Delay * 3);
00494                 };
00495                 j++;
00496             }
00497         }
00498 
00499         mm_close(&vidfile);
00500 
00501         i++;
00502     }
00503 
00504     if (!IsChannelMute(AV_SOUND_CHANNEL)) {
00505         if (lnch == 0)
00506             PlayAudio("wh.ogg",0);
00507         keep_going = 1;
00508         while (keep_going) {
00509             if (AnimSoundCheck())
00510                 keep_going = 0;
00511 
00512             if (bioskey(0) || grGetMouseButtons())
00513             {
00514                 av_silence (AV_SOUND_CHANNEL);
00515                 keep_going = 0;
00516             }
00517 
00518             av_block ();
00519             if (Data->Def.Sound==1) UpdateAudio();
00520             if (!BABY && BIG==0) {
00521                 Tick(plr);
00522                 gr_maybe_sync ();
00523             }
00524         }
00525     }
00526 
00527     fclose(ffin);  // Specs: babypicx.cdr
00528     mm_close(&vidfile);
00529     video_rect.h = 0;
00530     video_rect.w = 0;
00531     DEBUG1("<-PlaySequence()");
00532 }
00533 
00534 void Tick(char plr)
00535 {
00536  static int Sec=1,Min=0,Hour=5,Day=5;
00537  int g,change=0;
00538  double now;
00539  static double last;
00540 
00541  //: Specs: reset clocks
00542  if (plr==2) {
00543   Sec=1;
00544   Min=0;
00545   Hour=5;
00546   Day=5;
00547   return;
00548  }
00549 
00550  now = get_time ();
00551  if (now - last < .1)
00552      return;
00553  last = now;
00554 
00555  for (g=3;g>-1;g--)
00556   {
00557    change=0;
00558    if (g==3 && Hour==7) change=1;
00559     else if (g==2 && Min==7) change=1;
00560      else if (g==1 && Sec==7) change=1;
00561       else if (g==0) change=1;
00562    if (change==1)
00563     {
00564      switch(g)
00565       {
00566        case 3:Clock(plr,3,0,Day);if (Day==7) Day=0; else Day++;Clock(plr,3,1,Day);
00567        case 2:Clock(plr,2,0,Hour);if (Hour==7) Hour=0; else Hour++;Clock(plr,2,1,Hour);
00568        case 1:Clock(plr,1,0,Min);if (Min==7) Min=0; else Min++;Clock(plr,1,1,Min);
00569        default:Clock(plr,0,0,Sec);if (Sec==7) Sec=0; else Sec++;Clock(plr,0,1,Sec);break;
00570       };
00571     };
00572  };
00573  return;
00574 }
00575 
00576 void Clock(char plr,char clck,char mode,char tm)
00577 {
00578  unsigned sx,sy;
00579 
00580  sx = 0; /* XXX check uninitialized */
00581 
00582  //: Specs: clock y value
00583  if (plr==0) sy=108;
00584   else sy=121;
00585  //: Specs: color 
00586  if (mode==0) mode=3;
00587   else mode=4;
00588  //: Specs: clock x_value
00589  if (clck==0) sx=147;
00590   else if (clck==1) sx=157;
00591    else if (clck==2) sx=168;
00592     else if (clck==3) sx=178;
00593 
00594  switch(tm)
00595   {
00596    case 0:grPutPixel(sx,sy-1,mode);grPutPixel(sx,sy-2,mode);break;
00597    case 1:grPutPixel(sx+1,sy-1,mode);break;
00598    case 2:grPutPixel(sx+1,sy,mode);grPutPixel(sx+2,sy,mode);break;
00599    case 3:grPutPixel(sx+1,sy+1,mode);break;
00600    case 4:grPutPixel(sx,sy+1,mode);grPutPixel(sx,sy+2,mode);break;
00601    case 5:grPutPixel(sx-1,sy+1,mode);break;
00602    case 6:grPutPixel(sx-1,sy,mode);grPutPixel(sx-2,sy,mode);break;
00603    case 7:grPutPixel(sx-1,sy-1,mode);break;
00604    default:break;
00605   };
00606  av_need_update_xy(sx - 2, sy - 2, sx + 2, sy - 2);
00607  return;
00608 }
00609 
00610 void DoPack(char plr,FILE *ffin,char mode,char *cde,char *fName)
00611 {
00612  int i,x,y,try,which,mx2,mx1;
00613  GXHEADER boob;
00614  ui16 *bot,off=0;
00615  long locl;
00616  static char kk=0,bub=0;
00617  char Val1[12],Val2[12],loc;
00618 
00619   memset(Val1,0x00,sizeof Val1);memset(Val2,0x00,sizeof Val2);
00620   strcpy(Val1,cde);
00621   if (Val1[0]=='W') Val1[2]='P';  // for planetary steps
00622 
00623   if (bub<2) //4
00624    {
00625     mode=3;
00626     loc=kk;
00627    }
00628   else if (bub==2) {   //4
00629    ++bub;
00630    loc=kk;
00631   }
00632   else {
00633    bub=0;
00634    SHTS[0]++;SHTS[1]++;
00635    SHTS[2]++;SHTS[3]++;
00636    mx1=maxx(SHTS[0],SHTS[2]);mx2=maxx(SHTS[1],SHTS[3]);
00637    if (mx1>mx2) loc=(SHTS[0]>SHTS[2]) ? 0 : 2 ;
00638     else loc=(SHTS[1]>SHTS[3]) ? 1 : 3 ;
00639    SHTS[loc]=random(3);
00640    kk=loc;
00641    return;
00642   };
00643 
00644    x=(loc==0 || loc==1) ? 6 : 246;
00645    y=(loc==0 || loc==2) ? 5+2*plr: 57+plr*9;
00646    off=64+loc*16;
00647    GV(&boob,68,46);
00648    bot=(ui16 *) boob.vptr;
00649 
00650   //:::::::::::::::::::::::::::::::
00651   //Specs: which holds baby frame :
00652   //:::::::::::::::::::::::::::::::
00653   if (mode==3) {
00654    which=580+bub; //Specs: static frames
00655    ++bub;
00656   }
00657   else if (mode==1) {
00658    try=0;which=0;
00659    while (try<SCND_TABLE)
00660     {
00661      if (xstrncasecmp(fName,Mob2[try].Name,strlen(Mob2[try].Name))==0) break;
00662       else try++;
00663     };
00664    if (try>=SCND_TABLE) which=415+random(25);
00665     else
00666      {
00667       if (Val1[0]!='#')
00668        switch(Mob2[try].idx)
00669         {
00670          case 0:strcat(Val1,"0\0");break;
00671          case 1:strcat(Val1,"1\0");break;
00672          case 2:strcat(Val1,"2\0");break;
00673          case 3:strcat(Val1,"3\0");break;
00674          case 4:strcat(Val1,"0\0");break;
00675          case 5:strcat(Val1,"1\0");break;
00676          case 6:strcat(Val1,"2\0");break;
00677          case 7:strcat(Val1,"0\0");break;
00678          case 8:strcat(Val1,"1\0");break;
00679          case 9:strcat(Val1,"2\0");break;
00680          case 10:strcat(Val1,"0\0");break;
00681          case 11:strcat(Val1,"1\0");break;
00682          default:which=415+random(25);
00683         }
00684       if (which==0) {
00685        try=0;
00686        while (try<CLIF_TABLE)
00687         {
00688          strcpy(Val2,&Mob[try].Code[0]);
00689          if (xstrncasecmp(Val1,Val2,strlen(Val1))==0) break;
00690           else try++;
00691         };
00692         if (try>=CLIF_TABLE) which=415+random(25);
00693          else
00694           {  
00695            which=random(Mob[try].Qty);
00696            if (which>=10)
00697             {
00698              locl=((which-(which%10))/10)-1;
00699              which=Mob[try].List[which%10];
00700             }
00701            else which=Mob[try].List[which];
00702           }
00703        }
00704      }
00705   }
00706   else {
00707    try=0;
00708    while (try<NORM_TABLE)
00709     {
00710      strcpy(Val2,&Mob[try].Code[0]);
00711      if (strncmp(Val1,Val2,strlen(Val2))==0) break;
00712       else try++;
00713     };
00714    if (try>=NORM_TABLE) which=415+random(25);
00715     else
00716      {  
00717       which=random(Mob[try].Qty);
00718       if (which>=10)
00719        {
00720         locl=((which-(which%10))/10)-1;
00721         which=Mob[try].List[which%10];
00722        }
00723       else which=Mob[try].List[which];
00724     }
00725   };
00726 
00727   //Specs: which holds baby num
00728   locl=(long) 1612*which; 
00729   if (which<580) memset(&pal[off*3],0x00,48);
00730   if(loc!=0 && which<580) {VBlank();gxSetDisplayPalette(pal);}
00731   fseek(ffin,(long)locl,SEEK_SET);
00732   fread(&pal[off*3],48,1,ffin);
00733   fread(boob.vptr,1564,1,ffin);
00734   for (i=0;i<782;i++) {
00735    bot[i+782]=((bot[i]&0xF0F0)>>4);
00736    bot[i]=(bot[i]&0x0F0F);
00737   };
00738   for (i=0;i<1564;i++) {
00739    boob.vptr[i]+=off;
00740    boob.vptr[1564+i]+=off;
00741   };
00742   VBlank();
00743   gxPutImage(&boob,gxSET,x,y,0);
00744   VBlank();
00745   gxSetDisplayPalette(pal);
00746   DV(&boob);
00747 }
00748 
00749 
00750 
00751 void InRFBox(int a, int b, int c, int d, int col)
00752 {
00753    InBox(a,b,c,d);RectFill(a+1,b+1,c-1,d-1,col);
00754    return;
00755 }
00756 
00757 void GuyDisp(int xa,int ya,struct Astros *Guy)
00758 {
00759    grSetColor(1);
00760    assert(Guy != NULL);
00761    PrintAt(xa,ya,Guy->Name);
00762    switch(Guy->Status) {
00763       case 1: grSetColor(9);PrintAt(0,0," : DEAD");break;
00764       case 2: grSetColor(12);PrintAt(0,0," : INJ");break;
00765       case 3: grSetColor(12);PrintAt(0,0," : INJ");break;
00766       default: grSetColor(13);PrintAt(0,0," : OK");break;
00767       }
00768   return;
00769 }
00770 
00771 
00772 char FailureMode(char plr,int prelim,char *text)
00773 {
00774   int i,j,k;
00775   FILE *fin;
00776   double last_secs;
00777   char save_screen[64000], save_pal[768];
00778 
00779   FadeOut(2,pal,10,0,0);
00780  
00781   // this destroy's what's in the current page frames
00782   memcpy (save_screen, screen, 64000);
00783   memcpy (save_pal, pal, 768);
00784 
00785   gxClearDisplay(0,0);
00786   ShBox(0,0,319,22);IOBox(243,3,316,19);InBox(3,3,30,19);FlagSm(plr,4,4);
00787   grSetColor(1);PrintAt(258,13,"CONTINUE");
00788 
00789   ShBox(0,24,319,199);
00790 
00791   InRFBox(4,27,153,58,0);
00792 
00793   grSetColor(1);
00794   MisStep(9,34,Mev[STEP].loc);
00795   PrintAt(9,41,"MISSION STEP: ");DispNum(0,0,STEP);
00796   PrintAt(9,48,Mev[STEP].E->Name);
00797   PrintAt(0,0," CHECK");
00798 
00799    if (strncmp(Mev[STEP].E->Name,"DO",2)==0) {
00800       if (Mev[STEP].loc==1 || Mev[STEP].loc==2)
00801          DispNum(9,55,Mev[STEP].E->MSF);
00802       else DispNum(9,55,Mev[STEP].E->MisSaf);
00803       }
00804    else DispNum(9,55,Mev[STEP].E->MisSaf);
00805 
00806 
00807   PrintAt(0,0," VS ");DispNum(0,0,Mev[STEP].dice);
00808 
00809   DispBig(40,5,"STEP FAILURE",0,-1);
00810 
00811 //  InRFBox(4,61,153,109,0); // Image, Small Left Side
00812 
00813   // Status/Scrub
00814   InRFBox(4,112,153,128,0);
00815   // Display Result of Mission
00816   if (prelim==3) {
00817     ShBox(6,114,151,126);
00818     grSetColor(1); PrintAt(8,122,"RECOMMEND MISSION SCRUB");
00819   } else {
00820     grSetColor(9);
00821     switch(prelim) {
00822       case 0: grSetColor(15);PrintAt(8,122,"ALL SYSTEMS ARE GO");break;
00823       case 1: PrintAt(8,122,"FAILURE: USE ALTERNATE");break;
00824       case 2: PrintAt(8,122,"FURTHER PROBLEMS: RECHECK");break;
00825       case 4: PrintAt(8,122,"CREW STRANDED IN SPACE");break;
00826       case 5: PrintAt(8,122,"MISSION FAILURE");break;
00827       case 6: grSetColor(15);PrintAt(8,122,"MISSION SUCCESS");break;
00828       case 7: PrintAt(8,122,"STEP FAILURE");break;
00829       case 8: PrintAt(8,122,"CATASTROPHIC FAILURE");break;
00830       case 9: PrintAt(8,122,"CREW INJURIES");break;
00831       default: break;
00832     };
00833   };
00834 
00835 
00836   // Flight Crew Info
00837   InRFBox(4,131,315,151,0);// Astro List/Crew
00838   grSetColor(12);PrintAt(14,139,"CREW");PrintAt(9,146,"STATUS");
00839 
00840 
00841    if (MANNED[Mev[STEP].pad]>0) GuyDisp(49,138,MA[Mev[STEP].pad][0].A);
00842    if (MANNED[Mev[STEP].pad]>1) GuyDisp(49,146,MA[Mev[STEP].pad][1].A);
00843    if (MANNED[Mev[STEP].pad]>2) GuyDisp(182,138,MA[Mev[STEP].pad][2].A);
00844    if (MANNED[Mev[STEP].pad]>3) GuyDisp(182,146,MA[Mev[STEP].pad][3].A);
00845 
00846    if (MANNED[Mev[STEP].pad]==0) {
00847      if (((Mev[STEP].E->ID[1]==0x35 || Mev[STEP].E->ID[1]==0x36) && STEP>5)) {  // if LEMS
00848         GuyDisp(49,138,MA[1][LM[1]].A);
00849         if (EVA[1]!=LM[1]) GuyDisp(49,146,MA[1][EVA[1]].A);
00850      }
00851      else if (strncmp(Mev[STEP].E->ID,"M2",2)==0) {
00852        GuyDisp(49,138,MA[other(Mev[STEP].pad)][0].A);
00853        GuyDisp(49,146,MA[other(Mev[STEP].pad)][1].A);
00854        GuyDisp(182,138,MA[other(Mev[STEP].pad)][2].A);
00855      }
00856      else if (strncmp(Mev[STEP].E->ID,"M3",2)==0) {  // EVA
00857         GuyDisp(49,138,MA[1][EVA[1]].A);
00858      }
00859      else {grSetColor(1);PrintAt(49,138,"UNMANNED");}
00860    };
00861 
00862    grSetColor(11);  // Specialist
00863    if (MANNED[Mev[STEP].pad]>0) {
00864       switch (Mev[STEP].ast) {
00865           case 0: grDrawLine(49,140,172,140);break;
00866           case 1: grDrawLine(49,148,172,148);break;
00867           case 2: grDrawLine(182,140,305,140);break;
00868           case 3: grDrawLine(182,148,305,148);break;
00869           default: break;
00870      };
00871       };
00872 
00873   // Display Failure Text
00874   InRFBox(4,154,315,196,0);
00875   grSetColor(11);j=0;k=163;grMoveTo(12,k);
00876   for (i=0;i<200;i++) {
00877     if (j>40 && text[i]==' ') {k+=7;j=0;grMoveTo(12,k);}
00878     else DispChr(text[i]);
00879     j++;if (text[i]=='\0') break;
00880   };
00881 
00882 
00883   // Failure Diagram
00884   InRFBox(162,28,312,42,10);
00885   grSetColor(11);PrintAt(181,37," EQUIPMENT DETAIL");
00886 
00887   InRFBox(162,46,312,127,0); // Image is 188,49
00888 
00889   // Place Image Here
00890   // Build Name
00891   memset(Name,0x00,sizeof Name);
00892 
00893   VerifyData();
00894   if (plr==0) strcat(Name,"US");
00895   else strcat(Name,"SV");
00896   strncat(Name,Mev[STEP].E->ID,2);
00897 
00898    if(Mev[STEP].Class==6) {
00899       strcpy(&Name[0],"XCAM\0");
00900       }
00901 
00902    strcat(Name,".BZ\0");
00903 
00904   fin=OpenAnim(Name);
00905   StepAnim(188,47,fin);
00906 
00907   last_secs = get_time ();
00908 
00909   FadeIn(2,pal,10,0,0);
00910   
00911 
00912     WaitForMouseUp();
00913     key = 0;
00914   while(bioskey(1)) bioskey(0);
00915 
00916   while (1)
00917   {
00918     if (get_time () - last_secs > .55) {
00919         last_secs = get_time ();
00920         StepAnim(188,47,fin);
00921     }
00922 
00923     GetMouse();
00924     if ((x>=245 && y>=5 && x<=314 && y<=17 && mousebuttons>0) || key==K_ENTER)
00925     {
00926        InBox(245,5,314,17);
00927        WaitForMouseUp();
00928        OutBox(245,5,314,17);delay(10);
00929        FadeOut(2,pal2,10,0,0);
00930      //  DrawControl(plr);
00931        CloseAnim(fin);
00932 
00933        memcpy (screen, save_screen, 64000);
00934        memcpy (pal, save_pal, 768);
00935        screen_dirty = 1;
00936 
00937        FadeIn(2,pal,10,0,0);
00938        key=0;
00939        return 0;  /* Continue */
00940     };
00941     if ((x>=6 && y>=114 && x<=151 && y<=126 && prelim==3 && mousebuttons>0) || (prelim==7 && key=='S'))
00942     {
00943        InBox(6,114,151,126);
00944        WaitForMouseUp();
00945        OutBox(6,114,151,126);delay(10);
00946        FadeOut(2,pal2,10,0,0);
00947     //   DrawControl(plr);
00948        CloseAnim(fin);
00949 
00950        memcpy (screen, save_screen, 64000);
00951        memcpy (pal, save_pal, 768);
00952        screen_dirty = 1;
00953        FadeIn(2,pal,10,0,0); key=0;
00954        return 1;  /* Scrub */
00955     };
00956   };
00957 }
00958 
00959 FILE *OpenAnim(char *fname)
00960 {
00961    FILE  *fin;
00962    struct TM {
00963       char ID[4];
00964       long offset;
00965       long size;
00966       } AIndex;
00967 
00968     fin=open_gamedat("LIFTOFF.ABZ");
00969     if (!fin)
00970     {                                  
00971         WARNING1("can't access file LIFTOFF.ABZ");
00972         return fin;
00973     }
00974    fread(&AIndex,sizeof AIndex,1,fin);
00975    while (strncmp(AIndex.ID,fname,4)!=0) {
00976       fread(&AIndex,sizeof AIndex,1,fin);
00977       }
00978             Swap32bit(AIndex.offset);
00979             Swap32bit(AIndex.size);
00980    fseek(fin,AIndex.offset,SEEK_SET);
00981 
00982       fread(&AHead,sizeof AHead,1,fin);
00983             Swap16bit(AHead.w);
00984             Swap16bit(AHead.h);
00985       fread(&pal[AHead.cOff*3],AHead.cNum*3,1,fin);
00986       aLoc=ftell(fin);
00987       tFrames=AHead.fNum;
00988       cFrame=0;
00989 
00990    GV(&dply,AHead.w,AHead.h);
00991    return fin;
00992 }
00993 
00994 int CloseAnim(FILE *fin)
00995 {
00996    DV(&dply);
00997    tFrames=cFrame=0;
00998    aLoc=0;
00999    fclose(fin);
01000    return 0;
01001 }
01002 
01003 int StepAnim(int x,int y,FILE *fin)
01004 {
01005    int mode;
01006 
01007    mode = 0; /* XXX check uninitialized */
01008 
01009    if (cFrame==tFrames) {
01010       fseek(fin,aLoc,SEEK_SET);
01011       cFrame=0;
01012       }
01013    if (cFrame<tFrames) {
01014        fread(&BHead,sizeof BHead,1,fin);
01015          Swap32bit(BHead.fSize);
01016        fread(vhptr.vptr,BHead.fSize,1,fin);
01017        switch(BHead.cType) {
01018            case 0: memcpy(dply.vptr,vhptr.vptr,BHead.fSize); mode=gxSET;break;
01019        case 1: RLED_img(vhptr.vptr,dply.vptr,BHead.fSize,dply.w,dply.h); mode=gxSET; break;
01020        case 2: RLED_img(vhptr.vptr,dply.vptr,BHead.fSize,dply.w,dply.h); mode=gxXOR; break;
01021            default: break;
01022            }
01023       
01024       dply.vptr[AHead.w*AHead.h-1]=dply.vptr[AHead.w*AHead.h-2];
01025         gxPutImage(&dply,mode,x,y,0);
01026       
01027       cFrame++;
01028    }
01029    return (tFrames-cFrame);  //remaining frames
01030 }
01031 
01032 
01033 

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