diff --git a/data/brief1.txt b/data/brief1.txt index 59c1983..8449448 100644 --- a/data/brief1.txt +++ b/data/brief1.txt @@ -1,5 +1,4 @@ Krass Tyler -8 FACE_KRASS Hey, boy! You still owe me money for the Firefly I stole for you! But instead, I want you to go to the WEAPCO training ground and destroy all the craft there. FACE_CHRIS diff --git a/data/brief10.txt b/data/brief10.txt index 0598cf2..61de4cc 100644 --- a/data/brief10.txt +++ b/data/brief10.txt @@ -1,5 +1,4 @@ Phoebe Lexx -6 FACE_CHRIS A WEAPCO scientist just fled in an escape pod, I'm going after them. FACE_PHOEBE diff --git a/data/brief11.txt b/data/brief11.txt index 0de9f07..cb28eba 100644 --- a/data/brief11.txt +++ b/data/brief11.txt @@ -1,5 +1,4 @@ Phoebe Lexx -10 FACE_CHRIS I've received word that a rebellion is underway thanks to the slave being rescued. FACE_PHOEBE diff --git a/data/brief12.txt b/data/brief12.txt index 4a00efb..0aea37b 100644 --- a/data/brief12.txt +++ b/data/brief12.txt @@ -1,5 +1,4 @@ Sid Wilson -8 FACE_CHRIS What have you managed to find out about that experimental fighter? FACE_SID diff --git a/data/brief13.txt b/data/brief13.txt index c235a60..c958747 100644 --- a/data/brief13.txt +++ b/data/brief13.txt @@ -1,5 +1,4 @@ Phoebe Lexx -10 FACE_PHOEBE I've located my sister's ship currently in orbit around Odeon. She's ignoring my hails though. FACE_CHRIS diff --git a/data/brief14.txt b/data/brief14.txt index edb0021..615e5cc 100644 --- a/data/brief14.txt +++ b/data/brief14.txt @@ -1,5 +1,4 @@ Sid Wilson -4 FACE_SID A rebel group in this sector has organised a counter strike. If we can help them secure a victory it will be a real boost to morale. FACE_CHRIS diff --git a/data/brief15.txt b/data/brief15.txt index 95f66d1..182413f 100644 --- a/data/brief15.txt +++ b/data/brief15.txt @@ -1,5 +1,4 @@ Sid Wilson -6 FACE_SID Seems like taking out that WEAPCO mining ship wasn't such a good idea. The Ore it collected from those asteroids is needed in weapon production. FACE_CHRIS diff --git a/data/brief16.txt b/data/brief16.txt index a8ffd4e..6a0cb22 100644 --- a/data/brief16.txt +++ b/data/brief16.txt @@ -1,5 +1,4 @@ Krass Tyler -8 FACE_CHRIS I need you to help us out with something. In order to give the rebellion here a chance we're taking out key WEAPCO plants. FACE_KRASS diff --git a/data/brief17.txt b/data/brief17.txt index 7d80ee9..87afc24 100644 --- a/data/brief17.txt +++ b/data/brief17.txt @@ -1,5 +1,4 @@ Ursula Lexx -8 FACE_URSULA I've remembered something. WEAPCO are transporting some high level personnel to Poswic. FACE_CHRIS diff --git a/data/brief18.txt b/data/brief18.txt index 5c2523a..2bb0d19 100644 --- a/data/brief18.txt +++ b/data/brief18.txt @@ -1,5 +1,4 @@ Phoebe Lexx -6 FACE_CHRIS Phoebe, I need you to keep an eye on things here! I'm going after that ship! FACE_PHOEBE diff --git a/data/brief19.txt b/data/brief19.txt index 3946b5f..7623ac2 100644 --- a/data/brief19.txt +++ b/data/brief19.txt @@ -1,5 +1,4 @@ Sid Wilson -8 FACE_CHRIS We've got to start from the outside and work our way in. That will give us less chance of being flanked during the final operation. FACE_PHOEBE diff --git a/data/brief2.txt b/data/brief2.txt index c8fe76e..1f5aaca 100644 --- a/data/brief2.txt +++ b/data/brief2.txt @@ -1,5 +1,4 @@ Sid Wilson -8 FACE_CHRIS Hey, Sid, what's up? FACE_SID diff --git a/data/brief20.txt b/data/brief20.txt index 3946b5f..7623ac2 100644 --- a/data/brief20.txt +++ b/data/brief20.txt @@ -1,5 +1,4 @@ Sid Wilson -8 FACE_CHRIS We've got to start from the outside and work our way in. That will give us less chance of being flanked during the final operation. FACE_PHOEBE diff --git a/data/brief21.txt b/data/brief21.txt index 3946b5f..7623ac2 100644 --- a/data/brief21.txt +++ b/data/brief21.txt @@ -1,5 +1,4 @@ Sid Wilson -8 FACE_CHRIS We've got to start from the outside and work our way in. That will give us less chance of being flanked during the final operation. FACE_PHOEBE diff --git a/data/brief22.txt b/data/brief22.txt index e9cf1a2..e8dcf00 100644 --- a/data/brief22.txt +++ b/data/brief22.txt @@ -1,5 +1,4 @@ Phoebe and Ursula -8 FACE_CHRIS WEAPCO have set up a highly dangerous defense line between Saturn and Uranus. I'll need your help to take it out. FACE_PHOEBE diff --git a/data/brief23.txt b/data/brief23.txt index e48ff6a..5bf0e97 100644 --- a/data/brief23.txt +++ b/data/brief23.txt @@ -1,5 +1,4 @@ Sid Wilson -8 FACE_SID Whilst you were gone I picked up a distress call coming from around Jupiter. FACE_URSULA diff --git a/data/brief24.txt b/data/brief24.txt index 399c6ec..100ab4b 100644 --- a/data/brief24.txt +++ b/data/brief24.txt @@ -1,5 +1,4 @@ Sid Wilson -4 FACE_SID Chris, we've got a small problem. WEAPCO have mined the asteroid belt in the system. We'll need to clear a way through! FACE_CHRIS diff --git a/data/brief25.txt b/data/brief25.txt index 73750cc..4b8a0a6 100644 --- a/data/brief25.txt +++ b/data/brief25.txt @@ -1,5 +1,4 @@ Everyone -8 FACE_CHRIS Okay people, this is the big one. We go in fast and we go in hard. Don't hold back and hit them with everything we've got! FACE_SID diff --git a/data/brief26.txt b/data/brief26.txt index e88b473..eb5ba66 100644 --- a/data/brief26.txt +++ b/data/brief26.txt @@ -1,5 +1,4 @@ Kline Kethlan -4 FACE_CHRIS I'm going to give you one last warning, Kethlan - Surrender now! FACE_KLINE diff --git a/data/brief3.txt b/data/brief3.txt index 1ef5686..5bc0549 100644 --- a/data/brief3.txt +++ b/data/brief3.txt @@ -1,5 +1,4 @@ Sid Wilson -8 FACE_CHRIS Missile boats?!! FACE_SID diff --git a/data/brief4.txt b/data/brief4.txt index 61a55eb..e69fb09 100644 --- a/data/brief4.txt +++ b/data/brief4.txt @@ -1,5 +1,4 @@ Sid Wilson -6 FACE_SID We're going to have to clear the mine field that's been building up here recently. I have a feeling that WEAPCO have deployed some miners in the area and are testing the effectiveness of the field. Removing the mines will help interplanetary traffic to start up again. FACE_CHRIS diff --git a/data/brief5.txt b/data/brief5.txt index 5b106ed..2bd8d51 100644 --- a/data/brief5.txt +++ b/data/brief5.txt @@ -1,5 +1,4 @@ Sid Wilson -6 FACE_SID CHRIS!!!! We've got a major problem here!!! WEAPCO have decided to retaliate!! But they've decided it'll take too long to hunt you down so instead they're going to destroy Spirit! The explosion will destroy everything in the system!! You've only got about 3 minutes to destroy the frigate before it's in range! FACE_CHRIS diff --git a/data/brief6.txt b/data/brief6.txt index 8438ddf..e6fe953 100644 --- a/data/brief6.txt +++ b/data/brief6.txt @@ -1,5 +1,4 @@ Sid Wilson -6 FACE_CHRIS WEAPCO has many slaves in this system. If we free a large number of them, it might help to spark a rebellion movement. FACE_SID diff --git a/data/brief7.txt b/data/brief7.txt index c48f7f1..32dd961 100644 --- a/data/brief7.txt +++ b/data/brief7.txt @@ -1,5 +1,4 @@ (unknown) -10 FACE_PHOEBE Help!! This is an SOS!! Can anyone hear me??! I was intercepted by a large WEAPCO force near Nerod! I'm in need of assistance!! FACE_CHRIS diff --git a/data/brief8.txt b/data/brief8.txt index 433334f..3270644 100644 --- a/data/brief8.txt +++ b/data/brief8.txt @@ -1,5 +1,4 @@ Sid Wilson -8 FACE_SID I've just received another SOS. This one is coming from a supply craft that is under attack. FACE_CHRIS diff --git a/data/brief9.txt b/data/brief9.txt index 672cebb..ab7cd6e 100644 --- a/data/brief9.txt +++ b/data/brief9.txt @@ -1,5 +1,4 @@ Sid Wilson -10 FACE_SID I need some resources before we leave, it'll make life a lot easier in Mordor. Problem is that the parts are proprietry of WEAPCO. FACE_PHOEBE diff --git a/data/credits.txt b/data/credits.txt index 9645f6a..9ae90cf 100644 --- a/data/credits.txt +++ b/data/credits.txt @@ -1,8 +1,3 @@ -And so it was that in the year 2579 the galactic weapons corporation -WEAPCO was defeated thanks to the valiant efforts of a few determined -individuals; A cause that would be remembered throughout the rest of -human history as Project: Starfighter. -66 000 +++ CAST +++ 030 Chris Bainfield 020 Krass Tylar diff --git a/data/extro.txt b/data/extro.txt new file mode 100644 index 0000000..f423c83 --- /dev/null +++ b/data/extro.txt @@ -0,0 +1,4 @@ +And so it was that in the year 2579 the galactic weapons corporation +WEAPCO was defeated thanks to the valiant efforts of a few determined +individuals; A cause that would be remembered throughout the rest of +human history as Project: Starfighter. \ No newline at end of file diff --git a/data/intro.txt b/data/intro.txt index 233d202..0be315d 100644 --- a/data/intro.txt +++ b/data/intro.txt @@ -7,4 +7,3 @@ 40 The people cried out for a saviour... for someone to come and 20 light this dark hour... 80 ... and someone did. --1 diff --git a/src/aliens.cpp b/src/aliens.cpp index b0c5123..15d569f 100644 --- a/src/aliens.cpp +++ b/src/aliens.cpp @@ -294,14 +294,10 @@ static void getPreDefinedAliens() if (fp == NULL) return; - fscanf(fp, "%d ", &index); - - while (index != -1) + while (fscanf(fp, "%d %d ", &index, &alienType) == 2) { placeAttempt = 0; - fscanf(fp, "%d ", &alienType); - enemy[index] = defEnemy[alienType]; enemy[index].owner = &enemy[index]; enemy[index].target = &enemy[index]; @@ -311,7 +307,7 @@ static void getPreDefinedAliens() /* we make 1000 attempts to place this enemy since it is required. If after 1000 attempts we still have managed to place the alien, then it simple isn't going to happen and we - will just exit the same. The chances of this happening are very very low! + will just exit the game. The chances of this happening are very very low! */ while (true) { @@ -376,8 +372,6 @@ static void getPreDefinedAliens() if (index == WC_BOSS) enemy[index].chance[1] = 5; } - - fscanf(fp, "%d ", &index); } fclose(fp); diff --git a/src/comms.cpp b/src/comms.cpp index e5a6bf3..d169b35 100644 --- a/src/comms.cpp +++ b/src/comms.cpp @@ -86,15 +86,16 @@ static void createMissionDetailSurface(SDL_Surface *comms, int missionSlot) fp = fopen(string, "rb"); - fscanf(fp, "%[^\n]%*c", name); + if (fscanf(fp, "%[^\n]%*c", name) < 1) + { + printf("Warning: Failed to retrieve name from \"%s\"\n", string); + strcpy(name, "Error"); + } sprintf(string, "+++ Communication with %s +++", name); drawString(string, -1, 20, FONT_GREEN, comms); - fscanf(fp, "%d%*c", &lines); - - for (int i = 0 ; i < lines ; i++) + while (fscanf(fp, "%[^\n]%*c", string) == 1) { - fscanf(fp, "%[^\n]%*c", string); faceNumber = getFace(string); if (faceNumber > -1) { diff --git a/src/game.cpp b/src/game.cpp index bc19980..f4e0763 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -318,7 +318,7 @@ int mainGameLoop() doCutscene(6); break; case 26: - doCredits(); + doCredits(true); break; } diff --git a/src/init.cpp b/src/init.cpp index 1cb7e70..b63dfca 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -173,7 +173,8 @@ void initSystem() if (fp != NULL) { - fscanf(fp, "%d %d %d", &fullScreen, &useSound, &useMusic); + if (fscanf(fp, "%d %d %d", &fullScreen, &useSound, &useMusic) < 3) + printf("Warning: Config file \"%s\" is not correctly formatted\n", filename); fclose(fp); } diff --git a/src/intermission.cpp b/src/intermission.cpp index 1bb9efb..eddcf37 100644 --- a/src/intermission.cpp +++ b/src/intermission.cpp @@ -204,7 +204,7 @@ static void setSystemPlanets() { if (fscanf(fp, "%d %s %d", &distance, name, &image) < 3) { - printf("Warning: Data file \"%s\" is not correctly formatted\n", string); + printf("Warning: Data for planet %i in \"%s\" is not correctly formatted\n", i, string); break; } @@ -225,7 +225,7 @@ static void setSystemPlanets() (fscanf(fp, "%[^\n]%*c", from) < 1) || (fscanf(fp, "%[^\n]%*c", subject) < 1)) { - printf("Warning: Data file \"%s\" is not correctly formatted\n", string); + printf("Warning: Mission data for planet %i in \"%s\" is not correctly formatted\n", i, string); break; } diff --git a/src/resources.cpp b/src/resources.cpp index 6a9931a..bb7f6ef 100644 --- a/src/resources.cpp +++ b/src/resources.cpp @@ -61,11 +61,9 @@ void loadGameGraphics() if (fp == NULL) exit(1); - fscanf(fp, "%d %s", &index, string); - while (index != -1) + while (fscanf(fp, "%d %s", &index, string) == 2) { shipShape[index] = loadImage(string); - fscanf(fp, "%d %s", &index, string); } fclose(fp); @@ -113,11 +111,9 @@ void loadGameGraphics() fp = fopen(string, "rb"); - fscanf(fp, "%d %s", &index, string); - while (index != -1) + while (fscanf(fp, "%d %s", &index, string) == 2) { shape[index] = loadImage(string); - fscanf(fp, "%d %s", &index, string); } fclose(fp); diff --git a/src/script.cpp b/src/script.cpp index 247f377..b2c7f2d 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -62,12 +62,10 @@ void loadScriptEvents() if (fp == NULL) return; - fscanf(fp, "%d ", &time); - - while (time != 0) + while (fscanf(fp, "%d %s %d %d ", &time, face, &entity, &flags) == 4) { - fscanf(fp, "%s %d %d ", face, &entity, &flags); - fscanf(fp, "%[^\n]%*c", message); + if (fscanf(fp, "%[^\n]%*c", message) < 1) + strcpy(message, "Error: Text missing"); gameEvent[i].time = time; gameEvent[i].face = getFace(face); @@ -76,8 +74,6 @@ void loadScriptEvents() strcpy(gameEvent[i].message, message); i++; - - fscanf(fp, "%d ", &time); } fclose(fp); @@ -136,19 +132,22 @@ static void setScene(int scene) fp = fopen(string, "rb"); // Load in the specified background - fscanf(fp, "%s", string); + if (fscanf(fp, "%s", string) < 1) + { + printf("Warning: didn't find a background definition for \"%s\"\n", string); + strcpy(string, "gfx/spirit.jpg"); + } loadBackground(string); // Set the star speed - fscanf(fp, "%f %f", &sx, &sy); + if (fscanf(fp, "%f %f", &sx, &sy) < 2) + printf("Warning: failed to read star speed data for cutscene"); engine.ssx = sx; engine.ssy = sy; // Read in the specs for each ship - for (int i = 0 ; i < 15 ; i++) + while (fscanf(fp, "%d %d %f %f %f", &index, &shape, &x, &y, &speed) == 5) { - fscanf(fp, "%d %d %f %f %f", &index, &shape, &x, &y, &speed); - if (x < 0) x = (rand() % abs((int)x)); if (y < 0) y = (rand() % abs((int)y)); if (speed <= -1) speed = 1 + (rand() % abs((int)speed)); @@ -164,16 +163,16 @@ static void setScene(int scene) } // And finally read in the messages - for (int i = 0 ; i < 10 ; i++) + index = 0; + while (fscanf(fp, "%s%*c %[^\n]", face, string) == 2) { - fscanf(fp, "%s%*c", face); - fscanf(fp, "%[^\n]", string); - if (strcmp(string, "@none@") == 0) break; - cutMessage[i].face = getFace(face); - strcpy(cutMessage[i].message, string); + cutMessage[index].face = getFace(face); + strcpy(cutMessage[index].message, string); + + index++; } fclose(fp); diff --git a/src/title.cpp b/src/title.cpp index c1bdc37..7c751e2 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -373,7 +373,7 @@ int doTitle() // if someone has invoked the credits cheat if (engine.cheatCredits) { - doCredits(); + doCredits(false); engine.cheatCredits = false; } @@ -534,18 +534,12 @@ void showStory() int nextPos = -1; char string[255]; - fscanf(fp, "%d ", &nextPos); - - while (nextPos != -1) + while (fscanf(fp, "%d %[^\n]%*c", &nextPos, string) == 2) { - fscanf(fp, "%[^\n]%*c", string); - y += nextPos; textSurface(i, string, -1, y, FONT_WHITE); i++; - - fscanf(fp, "%d ", &nextPos); } fclose(fp); @@ -645,7 +639,7 @@ void gameover() flushBuffer(); } -void doCredits() +void doCredits(bool show_extro) { loadBackground("gfx/credits.jpg"); flushBuffer(); @@ -655,12 +649,12 @@ void doCredits() loadMusic("music/rise_of_spirit.ogg"); FILE *fp; - int numberOfCredits = 0; - int lastCredit = 0; + int lastCredit = -1; int yPos = 0; int yPos2 = screen->h; char text[255]; + int i; textObject *credit; @@ -670,43 +664,49 @@ void doCredits() drawBackGround(); - fp = fopen("data/credits.txt", "rb"); - - for (int i = 0 ; i < 4 ; i++) - { - fscanf(fp, "%[^\n]%*c", text); - drawString(text, -1, 240 + (i * 20), FONT_WHITE); - } - - fscanf(fp, "%d%*c", &numberOfCredits); - - credit = (textObject*) malloc(sizeof(textObject) * numberOfCredits); - - for (int i = 0 ; i < numberOfCredits ; i++) - { - fscanf(fp, "%d %[^\n]%*c", &yPos, text); - credit[i].image = textSurface(text, FONT_WHITE); - credit[i].x = (screen->w - credit[i].image->w) / 2; - yPos2 += yPos; - credit[i].y = yPos2; - } - - fclose(fp); - if ((engine.useMusic) && (engine.useAudio)) { Mix_VolumeMusic(100); Mix_PlayMusic(engine.music, 1); } - updateScreen(); - SDL_Delay(20000); - drawBackGround(); + if (show_extro) + { + fp = fopen("data/extro.txt", "rb"); + + i = 0; + while (fscanf(fp, "%[^\n]%*c", text) == 1) + { + drawString(text, -1, 240 + (i * 20), FONT_WHITE); + i++; + } + + fclose(fp); + + updateScreen(); + SDL_Delay(20000); + drawBackGround(); + } + + fp = fopen("data/credits.txt", "rb"); + // FIXME: It would be nice for the size of this array to be determined + // by the number of lines in the text file. I'm not sure how to do + // that at the moment, so just giving it a very large number for now. + credit = (textObject*) malloc(sizeof(textObject) * 300); + + while (fscanf(fp, "%d %[^\n]%*c", &yPos, text) == 2) + { + lastCredit++; + credit[lastCredit].image = textSurface(text, FONT_WHITE); + credit[lastCredit].x = (screen->w - credit[lastCredit].image->w) / 2; + yPos2 += yPos; + credit[lastCredit].y = yPos2; + } + + fclose(fp); engine.done = 0; - lastCredit = numberOfCredits - 1; - engine.keyState[KEY_ESCAPE] = 0; flushInput(); @@ -725,7 +725,7 @@ void doCredits() else if(engine.keyState[KEY_UP]) speed = -2; - for (int i = 0 ; i < numberOfCredits ; i++) + for (i = 0 ; i <= lastCredit ; i++) { if ((credit[i].y > -10) && (credit[i].y < (screen->h + 10))) blit(credit[i].image, (int)credit[i].x, (int)credit[i].y); @@ -738,7 +738,7 @@ void doCredits() delayFrame(); } - for (int i = 0 ; i < numberOfCredits ; i++) + for (i = 0 ; i <= lastCredit ; i++) { SDL_FreeSurface(credit[i].image); } diff --git a/src/title.h b/src/title.h index 685f3cb..3ad23fc 100644 --- a/src/title.h +++ b/src/title.h @@ -18,4 +18,4 @@ along with this program. If not, see . extern int doTitle(); extern void showStory(); extern void gameover(); -extern void doCredits(); +extern void doCredits(bool show_extro);