news.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 // NewsCaster Main Files
00026 
00027 #include "gamedata.h"
00028 #include "Buzz_inc.h"
00029 #include "externs.h"
00030 #include "macros.h"
00031 #include "av.h"
00032 #include "mmfile.h"
00033 #include "logging.h"
00034 
00035 /* LOG_DEFAULT_CATEGORY(LOG_ROOT_CAT); */
00036 
00037 static char *news_shots[] = { "angle", "opening", "closing" };
00038 
00039 double load_news_anim_start;
00040 
00041 #define PHYS_PAGE_OFFSET  0x4000
00042 #define BUFFR_FRAMES 1
00043 #define FIRST_FRAME 0
00044 #define TOMS_BUGFIX 69
00045 
00046 int evflag;
00047 static int bufsize, LOAD_US = 0, LOAD_SV = 0;
00048 static int Frame, MaxFrame, AnimIndex = 255;
00049 #ifdef DEAD_CODE
00050 ui16 handle0, handle1, handle2, handle3, handle4, handle5;
00051 #endif
00052 extern char Option;
00053 
00054 SimpleHdr table[99];
00055 
00056 enum news_type {
00057     NEWS_ANGLE,
00058     NEWS_OPENING,
00059     NEWS_CLOSING
00060 };
00061 
00062 /* country, color, type */
00063 static int news_index[2][2][3] = {
00064     { /* usa */
00065         { 9, 1, 3 }, /* color */
00066         { 8, 0, 2 }, /* b&w */
00067     },
00068     { /* soviet */
00069         { 10, 4, 6 }, /* color */
00070         { 11, 5, 7 }, /* b&w */
00071     },
00072 };
00073 
00074 struct rNews
00075 {
00076     i16 offset;
00077     char chrs;
00078 };
00079 
00080 void
00081 NFrame(int x1, int y1, int x2, int y2)
00082 {
00083     grSetColor(0);
00084     Box(x1, y1, x2, y2 + 1);
00085     OutBox(x1, y1, x2, y2);
00086     grSetColor(3);
00087     Box(x1 + 1, y1 + 1, x2 - 1, y2 - 1);
00088     Box(x1 + 2, y1 + 2, x2 - 2, y2 - 2);
00089     InBox(x1 + 3, y1 + 3, x2 - 3, y2 - 3);
00090 }
00091 
00092 void
00093 GoNews(char plr)
00094 {
00095     int i, j;
00096     struct rNews *list;
00097 
00098     memset(Name, 0x00, sizeof Name);
00099     memset(buffer, 0x00, 20480);   // clear buffer
00100     grSetColor(1);
00101 
00102     j = ResolveEvent(plr);
00103     if (j > 0)
00104         Data->Events[Data->Count] = j + 99;
00105     OpenNews(plr, buffer + 6000, (int) Data->Events[Data->Count]);
00106 
00107     Data->P[plr].eCount++;
00108 
00109     DispNews(plr, buffer + 6000, buffer);
00110 
00111     j = 0;
00112     memset(buffer + 6000, 0x00, 8000);  //clear memory
00113     list = (struct rNews *) (buffer + 6000);
00114     for (i = 0; i < (int) strlen(buffer); i++)
00115     {
00116         if (buffer[i] == 'x')
00117         {
00118             list[i].chrs = j;
00119             list[i].offset = i;
00120         }
00121         else
00122             j++;
00123     }
00124 }
00125 
00126 // Open News Constructs a complete event array.
00127 void
00128 OpenNews(char plr, char *buf, int bud)
00129 {
00130     int j, size;
00131     FILE *fp, *gork;
00132     char old[120];
00133     int i, len[5];
00134 
00135     size = (plr == 0) ? 232 : 177;
00136     i = (long) 500 *bud + (long) plr *250;
00137 
00138     //if (plr==1 && bud==22) i=11250L;
00139     // Event Card Info
00140     if (plr == 0)
00141         strcpy(&buf[0], "IN THE NEWS TODAY...x");
00142     else
00143         strcpy(&buf[0], "DEVELOPMENTS IN THE WORLD...x");
00144 
00145     fp = sOpen("EVENT.DAT", "rb", 0);
00146     fseek(fp, i, SEEK_SET);
00147     bufsize = strlen(buf);
00148     fread(&buf[bufsize], 249, 1, fp);
00149     fclose(fp);
00150     bufsize = strlen(buf);
00151     buf[bufsize] = 'x';
00152     //Astronaut info
00153 
00154     fp = sOpen("NEWS.DAT", "rb", 0);
00155     fread(&len[0], sizeof(len), 1, fp);
00156 
00157     for (i = 0; i < 5; i++)
00158     {
00159         Swap32bit(len[i]);
00160     }
00161 
00162     i = 0;
00163 
00164     for (j = 0; j < Data->P[plr].AstroCount; j++)
00165         if (Data->P[plr].Pool[j].Special > 0)
00166             i++;
00167 
00168     bufsize = strlen(buf);
00169     if (i > 0)
00170     {
00171         if (plr == 0)
00172             strcpy(&buf[bufsize], "xASTRONAUTS IN THE NEWS...x");
00173         else
00174             strcpy(&buf[bufsize], "xIN COSMONAUT NEWS...x");
00175     }
00176 
00177     for (j = 0; j < Data->P[plr].AstroCount; j++)
00178     {
00179         if (Data->P[plr].Pool[j].Special > 0)
00180         {                          // 12 ideas
00181             bufsize = strlen(buf);
00182             strcpy(&buf[bufsize], Data->P[plr].Pool[j].Name);
00183             i = len[0] + len[1] + (sizeof len) + 50 * (Data->P[plr].Pool[j].Special - 1);
00184             fseek(fp, i, SEEK_SET);
00185             bufsize = strlen(buf);
00186             fread(&buf[bufsize], 50, 1, fp);
00187         }
00188         if (Data->P[plr].Pool[j].Special == 1
00189             || (Data->P[plr].Pool[j].Special > 0 && Data->P[plr].Pool[j].RetReas == 8))
00190         {                          //13 other things
00191             i = len[0] + len[1] + len[2] + (sizeof len) + 50 * (Data->P[plr].Pool[j].RetReas - 1);
00192             if (plr == 1)
00193                 i += len[3];
00194             fseek(fp, i, SEEK_SET);
00195             bufsize = strlen(buf);
00196             fread(&buf[bufsize], 50, 1, fp);
00197         }
00198         Data->P[plr].Pool[j].Special = 0;
00199     }
00200 
00201     if (Data->Year >= 58)
00202     {
00203         if (Data->Season == 1 && plr == 0)
00204             strcpy(&buf[strlen(buf)], "xCHECK INTELLIGENCE, THE CIA REPORTS NEW INFORMATION.x\0");
00205         else if (Data->Season == 1 && plr == 1)
00206             strcpy(&buf[strlen(buf)], "xCHECK INTELLIGENCE, THE KGB REPORTS NEW INFORMATION.x\0");
00207     }
00208 
00209     //-----------------------------------------------------
00210     //Specs: check tracking station for directors message |
00211     //-----------------------------------------------------
00212 #if 1
00213     if (Option != -1)
00214     {
00215         if ((gork = sOpen((Option == 0) ? "SENDR.MSG" : "SENDH.MSG", "rb", 0)) != NULL)
00216         {
00217             fread(&old, sizeof(old), 1, gork);
00218             if (old[0] != 0x00)
00219             {
00220                 if (Option == 0)
00221                 {
00222                     strcpy(&buf[strlen(buf)], "xCHECK THE TRACKING STATION, THE SOVIETx");
00223                     strcpy(&buf[strlen(buf)], "DIRECTOR HAS SENT A NEW MESSAGE.x\0");
00224                 }
00225                 else if (Option == 1)
00226                 {
00227                     strcpy(&buf[strlen(buf)], "xCHECK THE TRACKING STATION, THE UNITEDx");
00228                     strcpy(&buf[strlen(buf)], "STATES DIRECTOR HAS SENT A NEW MESSAGE.x\0");
00229                 }
00230             }
00231             fclose(gork);
00232         }
00233     };
00234 #endif
00235 
00236     bufsize = strlen(buf);
00237     if (Data->P[plr].Plans && 0xff)
00238         strcpy(&buf[bufsize], "xPLANETARY MISSION UPDATES...x");
00239 
00240     // Past Mission Info
00241     if (Data->P[plr].Plans & 0x0f)
00242     {                              // Failures
00243         if (Data->P[plr].Plans & 0x01)
00244             strcpy(&buf[strlen(buf)], "MARS FLYBY FAILS!x");
00245         if (Data->P[plr].Plans & 0x02)
00246             strcpy(&buf[strlen(buf)], "JUPITER FLYBY FAILS!x");
00247         if (Data->P[plr].Plans & 0x04)
00248             strcpy(&buf[strlen(buf)], "SATURN FLYBY FAILS!x");
00249     }
00250     if (Data->P[plr].Plans & 0xf0)
00251     {
00252         if (Data->P[plr].Plans & 0x10)
00253             strcpy(&buf[strlen(buf)], "MARS FLYBY SUCCESS!x");
00254         if (Data->P[plr].Plans & 0x20)
00255             strcpy(&buf[strlen(buf)], "JUPITER FLYBY SUCCESS!x");
00256         if (Data->P[plr].Plans & 0x40)
00257             strcpy(&buf[strlen(buf)], "SATURN FLYBY SUCCESS!x");
00258     }
00259     Data->P[plr].Plans = 0;
00260 
00261     // History info
00262     fseek(fp, sizeof(len), SEEK_SET);
00263     bufsize = strlen(buf);
00264     if (plr == 0)
00265         strcpy(&buf[bufsize], "xALSO IN THE NEWS...x");
00266     else
00267         strcpy(&buf[bufsize], "xOTHER EVENTS IN THE NEWS...x");
00268     bufsize = strlen(buf);
00269 
00270     if (plr == 1)
00271         fseek(fp, len[0], SEEK_CUR);    // go to start of Soviet news
00272     if (plr == 0)
00273         i = ((Data->Year - 57) * 6 + Data->Season * 3 + random(3)) * size;
00274     else
00275         i = ((Data->Year - 57) * 4 + Data->Season * 2 + random(2)) * size;
00276     fseek(fp, i, SEEK_CUR);
00277 
00278     fread(&buf[bufsize], size, 1, fp);
00279     fclose(fp);
00280     strcat(buf, "x");
00281     bufsize = strlen(buf);
00282     if (plr == 0)
00283         strcpy(&buf[bufsize], "xAND THAT'S THE NEWS, I'M CARTER WALCRITE.x");
00284     else
00285         strcpy(&buf[bufsize], "xTHIS CONCLUDES OUR NEWS, I'M SVETLANA IZVESTIA.x");
00286 }
00287 
00288 void
00289 DispNews(char plr, char *src, char *dest)
00290 {
00291     int i = 0, j = 0, k = 0;
00292 
00293     for (i = 0; i < (int) strlen(src); i++)
00294     {
00295         dest[j] = src[i];
00296         switch (dest[j])
00297         {
00298             case 'a':
00299             case 'd':
00300             case 'f':
00301             case 'j':
00302             case 'i':
00303                 sprintf(&Name[0], "%d", evflag);
00304                 strncpy(&dest[j], &Name[0], strlen(Name));
00305                 j += strlen(Name) - 1;
00306                 break;
00307             case 'b':
00308                 switch (evflag)
00309                 {
00310                     case 0:
00311                         strcpy(&Name[0], "FIRST");
00312                         break;
00313                     case 1:
00314                         strcpy(&Name[0], "SECOND");
00315                         break;
00316                     case 2:
00317                         strcpy(&Name[0], "THIRD");
00318                         break;
00319                 };
00320                 strncpy(&dest[j], &Name[0], strlen(Name));
00321                 j += strlen(Name) - 1;
00322                 break;
00323             case 'c':
00324                 strncpy(&dest[j], &Name[0], strlen(Name));
00325                 j += strlen(Name) - 1;
00326                 break;
00327             case 'e':
00328                 strncpy(&dest[j], &Name[0], strlen(Name));
00329                 j += strlen(Name) - 1;
00330                 break;
00331             case 'h':
00332                 switch (evflag)
00333                 {
00334                     case 0:
00335                         strcpy(&Name[0], "PRIMARY");
00336                         break;
00337                     case 1:
00338                         strcpy(&Name[0], "SECONDARY");
00339                         break;
00340                     case 2:
00341                         strcpy(&Name[0], "THIRD");
00342                         break;
00343                     default:
00344                         break;
00345                 }
00346                 break;
00347             case 'g':
00348                 if (plr == 0)
00349                 {
00350                     if (Data->Year <= 59)
00351                         strcpy(&Name[0], "EISENHOWER");
00352                     if (Data->Year >= 60 && Data->Year <= 63)
00353                         strcpy(&Name[0], "KENNEDY");
00354                     if (Data->Year >= 64 && Data->Year <= 67)
00355                         strcpy(&Name[0], "JOHNSON");
00356                     if (Data->Year >= 68 && Data->Year <= 73)
00357                         strcpy(&Name[0], "NIXON");
00358                     if (Data->Year >= 74 && Data->Year <= 75)
00359                         strcpy(&Name[0], "FORD");
00360                     if (Data->Year >= 76 && Data->Year <= 79)
00361                         strcpy(&Name[0], "CARTER");
00362                 };
00363                 if (plr == 1)
00364                 {
00365                     if (Data->Year < 64)
00366                         strcpy(&Name[0], "KHRUSHCHEV");
00367                     if (Data->Year == 64 && Data->Season == 0)
00368                         strcpy(&Name[0], "KHRUSHCHEV");
00369                     if (Data->Year == 64 && Data->Season == 1)
00370                         strcpy(&Name[0], "BREZHNEV");
00371                     if (Data->Year > 65)
00372                         strcpy(&Name[0], "BREZHNEV");
00373                 };
00374                 strncpy(&dest[j], &Name[0], strlen(Name));
00375                 j += strlen(Name) - 1;
00376                 break;
00377             case 'm':
00378                 strncpy(&dest[j], Data->P[plr].Name, strlen(Data->P[plr].Name));
00379                 j += strlen(Data->P[plr].Name) - 1;
00380                 break;
00381             case 'x':
00382                 k = 0;
00383                 break;
00384             case ' ':
00385                 if (k > 34)
00386                 {
00387                     dest[j] = 'x';
00388                     k = 0;
00389                     if (src[i + 1] == ' ')
00390                         i++;
00391                 };
00392             default:
00393                 break;
00394         };
00395         j++;
00396         k++;
00397     };
00398 }
00399 
00400 #ifdef DEAD_CODE
00401 FILE *
00402 PreLoadAnim(char plr, char bw)
00403 {
00404     FILE *fp = NULL;
00405 
00406     gxClearDisplay(0, 0);
00407     ShBox(49, 54, 262, 122);
00408     InBox(53, 57, 258, 105);
00409     InBox(53, 108, 258, 119);
00410     RectFill(54, 109, 257, 118, 11);
00411     InBox(56, 60, 255, 72);
00412     RectFill(57, 61, 254, 71, 7);
00413     grSetColor(11);
00414     PrintAt(73, 68, "UPDATING NEWSCASTER ANIMATION");
00415     grSetColor(11);
00416     PrintAt(64, 81, "INSTALLING YOUR NEW");
00417     if (bw)
00418         PrintAt(64, 90, "BLACK AND WHITE TV SET.");
00419     else
00420         PrintAt(64, 90, "COLOR TV SET.");
00421     grSetColor(9);
00422     if (plr == 0)
00423     {
00424         PrintAt(64, 99, "TYPE: ");
00425         grSetColor(1);
00426         PrintAt(0, 0, "U.S. NEWSCASTER");
00427     }
00428     else
00429     {
00430         PrintAt(64, 99, "TYPE: ");
00431         grSetColor(1);
00432         PrintAt(0, 0, "SOVIET NEWSCASTER");
00433     }
00434     FadeIn(2, pal, 10, 0, 0);
00435     bw = !!bw;
00436     fp = LoadNewsAnim(plr, bw, NEWS_ANGLE, BUFFR_FRAMES, NULL);
00437     LoadNewsAnim(plr, bw, NEWS_CLOSING, BUFFR_FRAMES, fp);
00438     LoadNewsAnim(plr, bw, NEWS_OPENING, BUFFR_FRAMES, fp);
00439     FadeOut(2, pal, 10, 0, 0);
00440 
00441     return fp;
00442 }
00443 #endif
00444 
00445 void
00446 DrawNews(char plr)
00447 {
00448 
00449     gxClearDisplay(0, 0);
00450     memset(screen, 0xff, 320 * 113);
00451     pal[767] = pal[766] = pal[765] = 0x00;
00452     OutBox(0, 0, 319, 113);
00453     grSetColor(3);
00454     Box(1, 1, 318, 112);
00455     Box(2, 2, 317, 111);
00456     InBox(3, 3, 316, 110);
00457     ShBox(240, 3, 316, 22);
00458     RectFill(315, 20, 317, 21, 3);
00459     RectFill(241, 2, 242, 4, 3);
00460     IOBox(243, 3, 316, 19);
00461     grSetColor(1);
00462     PrintAt(258, 13, "CONTINUE");
00463     ShBox(0, 115, 319, 199);
00464     InBox(4, 118, 297, 196);
00465     RectFill(5, 119, 296, 195, 7 + 3 * plr);
00466     InBox(301, 118, 315, 196);
00467     RectFill(302, 119, 314, 195, 0);
00468     ShBox(303, 120, 313, 156);
00469     ShBox(303, 158, 313, 194);
00470     UPArrow(305, 126);
00471     DNArrow(305, 163);
00472 
00473 }
00474 
00475 void
00476 DrawNText(char plr, char got)
00477 {
00478     int xx = 12, yy = 128, i;
00479     char *buf;
00480 
00481     buf = buffer;
00482     grSetColor(1);
00483     for (i = 0; i < got; i++)
00484     {
00485         while (*buf != 'x')
00486             buf++;
00487         buf++;
00488         if (strncmp(&buf[0], "ASTRONAUTS IN THE NEWS", 22) == 0)
00489             grSetColor(11);
00490         if (strncmp(&buf[0], "ALSO IN THE NEWS", 16) == 0)
00491             grSetColor(12);
00492         if (strncmp(&buf[0], "IN COSMONAUT NEWS", 17) == 0)
00493             grSetColor(11);
00494         if (strncmp(&buf[0], "OTHER EVENTS IN THE NEWS", 24) == 0)
00495             grSetColor(12);
00496         if (strncmp(&buf[0], "PLANETARY", 9) == 0)
00497             grSetColor(11);
00498         if (strncmp(&buf[0], "CHECK INTEL", 11) == 0)
00499             grSetColor(11);
00500         if (strncmp(&buf[0], "CHECK THE TRACKING STATION", 26) == 0)
00501             grSetColor((plr == 0) ? 9 : 7);
00502     }
00503 
00504     for (i = 0; i < 8; i++)
00505     {
00506         RectFill(5, yy - 7, 296, yy + 1, 7 + 3 * plr);
00507         grMoveTo(xx, yy);
00508         if (strncmp(&buf[0], "ASTRONAUTS IN THE NEWS", 22) == 0)
00509             grSetColor(11);
00510         if (strncmp(&buf[0], "ALSO IN THE NEWS", 16) == 0)
00511             grSetColor(12);
00512         if (strncmp(&buf[0], "IN COSMONAUT NEWS", 17) == 0)
00513             grSetColor(11);
00514         if (strncmp(&buf[0], "OTHER EVENTS IN THE NEWS", 24) == 0)
00515             grSetColor(12);
00516         if (strncmp(&buf[0], "PLANETARY", 9) == 0)
00517             grSetColor(11);
00518         if (strncmp(&buf[0], "AND THAT'S THE NEWS", 19) == 0)
00519             grSetColor(11);
00520         if (strncmp(&buf[0], "THIS CONCLUDES OUR NEWS", 23) == 0)
00521             grSetColor(11);
00522         if (strncmp(&buf[0], "CHECK INTEL", 11) == 0)
00523             grSetColor(11);
00524         if (strncmp(&buf[0], "CHECK THE TRACKING STATION", 26) == 0)
00525             grSetColor((plr == 0) ? 9 : 7);
00526 
00527         while (buf[0] != 'x' && buf[0] != '\0')
00528         {
00529             DispChr(buf[0]);
00530             buf++;
00531         };
00532         yy += 9;
00533         buf++;
00534         if (*buf == '\0')
00535             i = 9;
00536     }
00537 
00538 }
00539 
00540 
00541 void
00542 News(char plr)
00543 {
00544     double last_secs;
00545     int bline = 0, ctop = 0, i;
00546     char cYr[5];
00547     ONEWS oNews;
00548     char loc = 0;
00549     ui8 Status = 0, BW = 0;
00550     mm_file video_file, *fp = &video_file;
00551     FILE *fout = NULL;
00552 
00553     BW = (Data->Year <= 63);
00554 
00555     memset(fp, 0, sizeof(*fp));
00556 
00557 #ifdef DEAD_CODE
00558     /* no need to preload anims */
00559     //: LOAD_US & LOAD_SV  0 None 1 B/W 2 Color
00560     if (Data->Year <= 63)
00561     {
00562         BW = 1;
00563         if (plr == 0 && LOAD_US == 2)
00564         {
00565             LOAD_US = 0;
00566         };
00567         if (plr == 1 && LOAD_SV == 2)
00568         {
00569             LOAD_SV = 0;
00570         };
00571     }
00572     else
00573     {
00574         BW = 0;
00575         if (plr == 0 && LOAD_US == 1)
00576         {
00577             LOAD_US = 0;
00578         };
00579         if (plr == 1 && LOAD_SV == 1)
00580         {
00581             LOAD_SV = 0;
00582         };
00583     };
00584 
00585     ///Specs: preload anims
00586     if (plr == 0 && LOAD_US == 0)
00587     {
00588         fp = PreLoadAnim(plr, BW);
00589         if (BW == 1)
00590             LOAD_US = 1;
00591         else
00592             LOAD_US = 2;
00593     }
00594     else if (plr == 1 && LOAD_SV == 0)
00595     {
00596         fp = PreLoadAnim(plr, BW);
00597         if (BW == 1)
00598             LOAD_SV = 1;
00599         else
00600             LOAD_SV = 2;
00601     }
00602 #endif
00603 //  DrawNews(plr);
00604     GoNews(plr);
00605 
00606     if ((plr == 0 && LOAD_US == 0) || (plr == 1 && LOAD_SV == 0))
00607     {
00608 
00609         sprintf(cYr, "%d", 1900 + Data->Year);
00610         if (Data->Season == 1)
00611             DispBig(42 + (BW * 200), 40 - (plr * 4), "FALL", 0, -1);
00612         else
00613             DispBig(37 + (BW * 200), 40 - (plr * 4), "SPRING", 0, -1);
00614         DispBig(48 + (BW * 200), 63 - (4 * plr), &cYr[0], 0, -1);
00615 
00616     };
00617 
00618     for (i = 0; i < (int) strlen(buffer); i++)
00619         if (buffer[i] == 'x')
00620             bline++;
00621     bline -= 8;
00622 
00623     // File Structure is 84 longs 42 per side
00624 
00625     fout = sOpen("EVENT.TMP", "r+b", 1);
00626     fseek(fout, 0, SEEK_END);
00627     oNews.offset = ftell(fout);
00628     oNews.size = (strlen(buffer));
00629     fwrite(buffer, strlen(buffer), 1, fout);
00630     fseek(fout, (plr * 42 + Data->P[plr].eCount - 1) * (sizeof(struct oldNews)), SEEK_SET);
00631     fwrite(&oNews, sizeof(struct oldNews), 1, fout);
00632     fclose(fout);
00633 
00634     /* XXX there is also M_NEW1950, why it is unused? */
00635     music_start(M_NEW1970);
00636 
00637     /* Tom's News kludge, also open and load first anim */
00638     fp = LoadNewsAnim(plr, BW, NEWS_ANGLE, TOMS_BUGFIX, fp);
00639     loc = 1;
00640     Status = 0;
00641 
00642     strcpy(IDT, "i002\0");
00643     WaitForMouseUp();
00644     while (1)
00645     {
00646         key = 0;
00647         GetMouse_fast();
00648         last_secs = get_time();
00649         if (!(loc == 0 && Status == 1))
00650             NUpdateVoice();
00651         i = AnimSoundCheck();
00652         if (Status == 1 || (loc == 3 && i == 1))
00653             switch (loc)
00654             {
00655                 case 0:        //: Angle In
00656                     AnimIndex = 255;
00657                     LoadNewsAnim(plr, BW, NEWS_ANGLE, FIRST_FRAME, fp);
00658     /* TODO this is skipped as it will be overlaid by movie frame anyway */
00659 #if 0
00660                     sprintf(cYr, "%d", 1900 + Data->Year);
00661                     if (Data->Season == 1)
00662                         DispBig(42 + (BW * 200), 40 - (plr * 4), "FALL", 0, -1);
00663                     else
00664                         DispBig(37 + (BW * 200), 40 - (plr * 4), "SPRING", 0, -1);
00665                     DispBig(48 + (BW * 200), 63 - (4 * plr), &cYr[0], 0, -1);
00666                     VBlank();
00667 #endif
00668                     Status = 0;
00669                     loc++;
00670                     break;
00671                 case 1:        //: Intro
00672                     LoadNewsAnim(plr, BW, NEWS_OPENING, FIRST_FRAME, fp);
00673                     Status = 0;
00674                     if (AnimIndex == 5)
00675                     {
00676 
00677                         RectFill(227, 108, 228, 108, grGetPixel(227, 108));
00678 
00679                     }
00680                     NGetVoice(plr, 0);
00681                     PlayNewsAnim(fp);
00682                     PlayNewsAnim(fp);
00683                     PlayNewsAnim(fp);
00684                     PlayNewsAnim(fp);
00685                     PlayVoice();
00686                     loc++;
00687                     break;
00688                 case 2:        //: Event (sound)
00689                     loc++;
00690                     if (IsChannelMute(AV_SOUND_CHANNEL))
00691                     {
00692                         /* if no sound then just skip event picture */
00693                         Status = 1;
00694                         break;
00695                     }
00696                     NGetVoice(plr, Data->Events[Data->Count] + 2);
00697                     PlayVoice();
00698                     Status = 0;
00699                     i = bline;
00700                     ShowEvt(plr, Data->Events[Data->Count]);
00701                     bline = i;
00702                     break;
00703                 case 3:        //: Close
00704                     LoadNewsAnim(plr, BW, NEWS_CLOSING, FIRST_FRAME, fp);
00705                     Status = 0;
00706                     NGetVoice(plr, 1);
00707                     if (plr == 0)
00708                     {              // This is done to sync with audio
00709                         PlayNewsAnim(fp);
00710                         PlayNewsAnim(fp);
00711                         PlayNewsAnim(fp);
00712                         PlayNewsAnim(fp);
00713                         PlayNewsAnim(fp);
00714                     }
00715                     PlayVoice();
00716                     /* the "mysterious" delay of soviet newscaster.
00717                      * she is out of sync anyway... */
00718 #ifdef DEAD_CODE
00719                     if (plr == 1)
00720                     {
00721                         bzdelay(170);
00722                     };
00723 #endif
00724                     loc++;
00725                     break;
00726                 case 4:        //: Angle Out
00727                     LoadNewsAnim(plr, BW, NEWS_ANGLE, FIRST_FRAME, fp);
00728 /* TODO this is skipped as it will be overlaid by movie frame anyway */
00729 #if 0
00730 
00731                     sprintf(cYr, "%d", 1900 + Data->Year);
00732                     if (Data->Season == 1)
00733                         DispBig(42 + (BW * 200), 40 - (plr * 4), "FALL", 0, -1);
00734                     else
00735                         DispBig(37 + (BW * 200), 40 - (plr * 4), "SPRING", 0, -1);
00736                     DispBig(48 + (BW * 200), 63 - (4 * plr), &cYr[0], 0, -1);
00737 
00738 #endif
00739                     Status = 0;
00740                     loc++;
00741                     break;
00742                 case 5:        //: Event (no sound)
00743                     Status = 0;
00744                     loc++;
00745                     if (AnimIndex == 9)
00746                     {
00747 
00748                         ShBox(240, 3, 316, 22);
00749                         RectFill(315, 20, 317, 21, 3);
00750                         RectFill(241, 2, 242, 4, 3);
00751                         IOBox(243, 3, 316, 19);
00752                         grSetColor(1);
00753                         PrintAt(258, 13, "CONTINUE");
00754 
00755                     };
00756                     i = bline;
00757                     ShowEvt(plr, Data->Events[Data->Count]);
00758                     bline = i;
00759                     break;
00760                 default:
00761                     break;
00762             };
00763 
00764         if (loc != 3 && loc != 6 && !Status)
00765             Status = PlayNewsAnim(fp);
00766         else
00767             idle_loop_secs(.05); /* was: .125 */
00768 
00769         //: Repeat News Sequence
00770         if (key == 'R' && loc == 6)
00771         {
00772             KillVoice();
00773             loc = 0;
00774             Status = 1;
00775         }
00776         if (ctop > 0 && key == 0x4900)
00777         {                          // Page Up Key
00778             ctop -= 9;
00779             if (ctop < 0)
00780                 ctop = 0;
00781             DrawNText(plr, ctop);
00782         }
00783         else if (ctop < bline && key == 0x5100)
00784         {                          // Page Down Key
00785             ctop += 9;
00786             if (ctop > bline)
00787                 ctop = bline;
00788             DrawNText(plr, ctop);
00789         }
00790         else if (ctop > 0 && ((x >= 303 && y > 120 && x <= 313 && y <= 156
00791                     && mousebuttons > 0) || (key >> 8) == 72))
00792         {                          // Up Arrow
00793             InBox(303, 120, 313, 156);
00794             ctop--;
00795             DrawNText(plr, ctop);
00796             OutBox(303, 120, 313, 156);
00797         }
00798         else if ((x >= 245 && y >= 5 && x <= 314 && y <= 17
00799                 && mousebuttons > 0) || (key == K_ENTER))
00800         {                          // Continue
00801             InBox(245, 5, 314, 17);
00802             WaitForMouseUp();
00803             key = 0;
00804             i = 0;
00805             music_stop();
00806             KillVoice();
00807             break;
00808         }
00809         else if (ctop < bline && ((x >= 303 && y > 158 && x <= 313
00810                     && y <= 194 && mousebuttons > 0) || (key >> 8) == 80))
00811         {                          // Down Arrow
00812             InBox(303, 158, 313, 194);
00813             ctop++;
00814             DrawNText(plr, ctop);
00815             OutBox(303, 158, 313, 194);
00816         }
00817 //   gr_sync ();
00818     };
00819     mm_close(fp);
00820     news_rect.w = news_rect.h = 0;
00821 }
00822 
00823 void
00824 AIEvent(char plr)
00825 {
00826     ResolveEvent(plr);
00827 }
00828 
00829 // ResolveEvent seems to set a flag in the BadCard array
00830 // and return the index into that array
00831 char
00832 ResolveEvent(char plr)
00833 {
00834     int bad, ctr = 0;
00835 
00836     bad = REvent(plr);
00837     if (bad)
00838     {
00839         // News event was bad, find an open slot to record the bad event
00840         do
00841         {
00842             ctr++;
00843             bad = random(14);
00844             if (ctr > 30)
00845             {
00846                 // After 30 good faith random attemptes to find an open slot
00847                 // reset the BadCard array
00848                 memset(&Data->P[plr].BadCard[0], 0x00, sizeof(Data->P[plr].BadCard));
00849                 ctr = 0;
00850             }
00851         } while (Data->P[plr].BadCard[bad] != 0);
00852 
00853         Data->P[plr].BadCard[bad] = 1;
00854         bad++;
00855     }
00856     return bad;                    // zero if card is good
00857 }
00858 
00859 void
00860 Breakgrp(char plr)
00861 {
00862     int i, j, k, l, temp;
00863 
00864     j = plr;
00865     if (plr == 4)
00866         for (k = 0; k < 6; k++)
00867         {
00868             for (l = 0; l < 8; l++)
00869             {
00870                 temp = 0;
00871                 if (Data->P[j].Gcnt[k][l] > 0)
00872                 {
00873                     for (i = 0; i < Data->P[j].Gcnt[k][l]; i++)
00874                     {
00875                         if (Data->P[j].Pool[Data->P[j].Crew[k][l][i] - 1].Status == 1
00876                             || Data->P[j].Pool[Data->P[j].Crew[k][l][i] - 1].Status == 2
00877                             || Data->P[j].Pool[Data->P[j].Crew[k][l][i] - 1].Status == 3)
00878                             temp++;
00879                     };             /* for i */
00880                     if (temp > 0)
00881                     {
00882                         for (i = 0; i < Data->P[j].Gcnt[k][l]; i++)
00883                         {
00884                             Data->P[j].Pool[Data->P[j].Crew[k][l][i] - 1].oldAssign =
00885                               Data->P[j].Pool[Data->P[j].Crew[k][l][i] - 1].Assign;
00886                             Data->P[j].Pool[Data->P[j].Crew[k][l][i] - 1].Assign = 0;
00887                             Data->P[j].Pool[Data->P[j].Crew[k][l][i] - 1].Crew = 0;
00888                             Data->P[j].Pool[Data->P[j].Crew[k][l][i] - 1].Prime = 0;
00889                             Data->P[j].Pool[Data->P[j].Crew[k][l][i] - 1].Task = 0;
00890                             Data->P[j].Pool[Data->P[j].Crew[k][l][i] - 1].Moved = 0;
00891                             if (Data->P[j].Pool[Data->P[j].Crew[k][l][i] - 1].Special == 0)
00892                                 Data->P[j].Pool[Data->P[j].Crew[k][l][i] - 1].Special = 6;
00893                             Data->P[j].Crew[k][l][i] = 0;
00894                         };         /* for i */
00895                         Data->P[j].Gcnt[k][l] = 0;
00896                     };             /* it temp */
00897                 };                 /* if Gcnt */
00898             };                     /* for l */
00899         };                         /* for k */
00900 }
00901 
00902 /* modified to return true if end of anim */
00903 int
00904 PlayNewsAnim(mm_file * fp)
00905 {
00906     double delta;
00907     double fps = 15;            /* TODO hardcoded fps here! */
00908     int skip_frame = 0;
00909 
00910     if (Frame == MaxFrame)
00911         return 1;
00912 
00913     delta = get_time() - load_news_anim_start;
00914     if (Frame < (int) (delta * fps))
00915         skip_frame = 1;
00916 
00917     if (mm_decode_video(fp, news_overlay) <= 0)
00918     {
00919         MaxFrame = Frame;
00920         return 1;
00921     }
00922     screen_dirty = 1;
00923 
00924     /* TODO skipping frames should not use decode_video */
00925     if (!skip_frame)
00926     {
00927         static double diff = 0;
00928         double t1 = get_time(), to_sleep;
00929 
00930         to_sleep = (Frame - delta * fps) / fps - diff;
00931         idle_loop_secs(to_sleep);
00932         diff = get_time() - t1 - to_sleep;
00933         CTRACE4(video, "sleep % 4.3f, drift % 4.3f", to_sleep, diff);
00934     }
00935     Frame += 1;
00936 
00937     return 0;
00938 }
00939 
00940 static void
00941 DrawTopNewsBox(int player)
00942 {
00943     OutBox(0, 0, 319, 113);
00944     grSetColor(3);
00945     Box(1, 1, 318, 112);
00946     Box(2, 2, 317, 111);
00947     InBox(3, 3, 316, 110);
00948     ShBox(240, 3, 316, 22);
00949     RectFill(315, 20, 317, 21, 3);
00950     RectFill(241, 2, 242, 4, 3);
00951     IOBox(243, 3, 316, 19);
00952     grSetColor(1);
00953     PrintAt(258, 13, "CONTINUE");
00954     av_need_update_xy(0, 0, 319, 113);
00955 }
00956 
00957 static void
00958 DrawBottomNewsBox(int player)
00959 {
00960     ShBox(0, 115, 319, 199);
00961     InBox(4, 118, 297, 196);
00962     RectFill(5, 119, 296, 195, 7 + 3 * player);
00963     InBox(301, 118, 315, 196);
00964     RectFill(302, 119, 314, 195, 0);
00965     ShBox(303, 120, 313, 156);
00966     ShBox(303, 158, 313, 194);
00967     UPArrow(305, 126);
00968     DNArrow(305, 163);
00969     DrawNText(player, 0);
00970 }
00971 
00972 mm_file *
00973 LoadNewsAnim(int plr, int bw, int type, int Mode, mm_file * fp)
00974 {
00975     int Index = news_index[plr][bw][type];
00976 #ifdef DEAD_CODE
00977     unsigned MAX = 0, TOT = 0;
00978     int aframe;
00979 #endif
00980 
00981 #ifdef DEAD_CODE
00982     if (Mode == 1)
00983     {
00984         switch (Index)
00985         {
00986             case 0:
00987                 TOT = 118;
00988                 MAX = 170;
00989                 break;
00990             case 1:
00991                 TOT = 135;
00992                 MAX = 181;
00993                 break;
00994             case 2:
00995                 TOT = 58;
00996                 MAX = 170;
00997                 break;
00998             case 3:
00999                 TOT = 75;
01000                 MAX = 181;
01001                 break;
01002             case 4:
01003                 TOT = 151;
01004                 MAX = 211;
01005                 break;
01006             case 5:
01007                 TOT = 167;
01008                 MAX = 227;
01009                 break;
01010             case 6:
01011                 TOT = 66;
01012                 MAX = 211;
01013                 break;
01014             case 7:
01015                 TOT = 68;
01016                 MAX = 227;
01017                 break;
01018             case 8:
01019                 TOT = 0;
01020                 MAX = 170;
01021                 break;
01022             case 9:
01023                 TOT = 0;
01024                 MAX = 181;
01025                 break;
01026             case 10:
01027                 TOT = 0;
01028                 MAX = 211;
01029                 break;
01030             case 11:
01031                 TOT = 0;
01032                 MAX = 227;
01033                 break;
01034             default:
01035                 break;
01036         }
01037     };
01038 #endif
01039 
01040     if (AnimIndex != Index)
01041     {
01042         char fname[100];
01043         unsigned h, w;
01044 
01045         mm_close(fp);
01046         news_rect.w = news_rect.h = 0;
01047 
01048         sprintf(fname, "%s_%s_%s.ogg",
01049                 plr ? "sov" : "usa",
01050                 bw  ? "bw"  : "col",
01051                 news_shots[type]);
01052 
01053         /* XXX error checking */
01054         mm_open_fp(fp, sOpen(fname, "rb", FT_VIDEO));
01055 
01056         /* XXX we know fps anyway */
01057         mm_video_info(fp, &w, &h, NULL);
01058         news_rect.h = h;
01059         news_rect.w = w;
01060         news_rect.x = 4;
01061         news_rect.y = 4;
01062     }
01063     Frame = 1;
01064     AnimIndex = Index;
01065     MaxFrame = 0;
01066 
01067     // Specs: Display Single Frame
01068     if (Mode == FIRST_FRAME)
01069     {
01070         /* XXX: error checking */
01071         mm_decode_video(fp, news_overlay);
01072         screen_dirty = 1;
01073     };
01074 
01075     // *************** TCS001 my kludge (tom) 3/15/94
01076     if (Mode == TOMS_BUGFIX)
01077     {
01078         FadeOut(2, pal, 1, 0, 0);
01079 
01080         gxClearDisplay(0, 0);
01081         DrawTopNewsBox(plr);
01082         DrawBottomNewsBox(plr);
01083 
01084         /* XXX: error checking */
01085         mm_decode_video(fp, news_overlay);
01086         screen_dirty = 1;
01087 
01088         /* This fade was too long given current fades impl. */
01089         FadeIn(2, pal, 10, 0, 0); /* was: 50 */
01090     }
01091 
01092     load_news_anim_start = get_time();
01093 
01094     return fp;
01095 }
01096 
01097 void
01098 ShowEvt(char plr, char crd)
01099 {
01100     FILE *ffin;
01101     uint32_t offset;
01102     uint32_t length;
01103 
01104     memset(&pal[96], 0, 672);
01105     if (plr == 0)
01106     {
01107         switch (crd)
01108         {
01109             case 41:
01110                 crd = 45;
01111                 break;
01112             case 50:
01113                 crd = 67;
01114                 break;
01115             case 8:
01116                 crd = 98;
01117                 break;
01118             case 105:
01119                 crd = 112;
01120                 break;
01121             case 33:
01122                 crd = 111;
01123                 break;
01124             case 109:
01125                 crd = 108;
01126                 break;
01127             default:
01128                 break;
01129         }
01130     }
01131     ffin = sOpen("NEWS.CDR", "rb", 0);
01132     if (!ffin)
01133         return;
01134     fseek(ffin, (plr * 115 + crd) * 2 * sizeof(uint32_t), SEEK_SET);
01135     fread_uint32_t(&offset, 1, ffin);
01136     fread_uint32_t(&length, 1, ffin);
01137 
01138     /*
01139      * This loop overwrites newscaster video frame, so we use hardcoded values for
01140      * update rectangle offsets.
01141      */
01142     if (offset && length)
01143     {
01144         fseek(ffin, offset, SEEK_SET);
01145         fread(&pal[384], 384, 1, ffin);
01146         fread(screen, (size_t) min(length, MAX_X * 110), 1, ffin);
01147         DrawTopNewsBox(plr);
01148     }
01149     news_rect.w = news_rect.h = 0;
01150 
01151     fclose(ffin);
01152 }
01153 
01154 // EOF
01155 
01156 

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