From e258921987bd6b68a5a42861f1473602cb66a86e Mon Sep 17 00:00:00 2001 From: onpon4 Date: Sat, 2 Jan 2016 22:37:44 -0500 Subject: [PATCH] Moved all "script" files to C code. I'm going to do this for all of the stuff in the "data" directory. It was obviously an attempt to make Starfighter more flexible somehow, but it fails at that entirely. More importantly, these things are both unreadable and easy to make mistakes on. Simple C code is much easier to read. The only disadvantage is that recompiling is now needed to change the "scripts", but considering that they had hidden limits and no one was making custom missions to begin with, I don't consider this to be a real loss. --- Makefile | 2 +- data/script11.txt | 61 -------- data/script13.txt | 17 --- data/script16.txt | 61 -------- data/script17.txt | 8 - data/script22.txt | 37 ----- data/script23.txt | 55 ------- data/script25.txt | 13 -- data/script26.txt | 11 -- data/script5.txt | 37 ----- data/script7.txt | 7 - data/script8.txt | 61 -------- src/Starfighter.h | 1 + src/event.cpp | 374 ++++++++++++++++++++++++++++++++++++++++++++++ src/event.h | 37 +++++ src/game.cpp | 8 +- src/missions.cpp | 4 +- src/script.cpp | 105 ------------- src/script.h | 3 - src/structs.h | 10 -- 20 files changed, 418 insertions(+), 494 deletions(-) delete mode 100644 data/script11.txt delete mode 100644 data/script13.txt delete mode 100644 data/script16.txt delete mode 100644 data/script17.txt delete mode 100644 data/script22.txt delete mode 100644 data/script23.txt delete mode 100644 data/script25.txt delete mode 100644 data/script26.txt delete mode 100644 data/script5.txt delete mode 100644 data/script7.txt delete mode 100644 data/script8.txt create mode 100644 src/event.cpp create mode 100644 src/event.h diff --git a/Makefile b/Makefile index 508c200..427d97f 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CXXFLAGS ?= -O2 -Wall -g CXXFLAGS += `pkg-config --cflags sdl2 SDL2_image SDL2_mixer` LIBS = `pkg-config --libs sdl2 SDL2_image SDL2_mixer` -OBJS = alien.o audio.o bullet.o cargo.o collectable.o colors.o engine.o explosion.o game.o gfx.o intermission.o loadSave.o messages.o misc.o missions.o player.o renderer.o resources.o screen.o script.o ship.o shop.o Starfighter.o title.o weapons.o window.o +OBJS = alien.o audio.o bullet.o cargo.o collectable.o colors.o engine.o event.o explosion.o game.o gfx.o intermission.o loadSave.o messages.o misc.o missions.o player.o renderer.o resources.o screen.o script.o ship.o shop.o Starfighter.o title.o weapons.o window.o VERSION = 1.4.1-dev PROG = starfighter diff --git a/data/script11.txt b/data/script11.txt deleted file mode 100644 index 8f8ffdb..0000000 --- a/data/script11.txt +++ /dev/null @@ -1,61 +0,0 @@ -5 -FACE_PHOEBE --1 -0 -Ummm... something about this doesn't look right! They should be offering more resistance than this! - --8 -FACE_PHOEBE --1 -0 -DAMMIT! It's a trap! Come on, Chris, we have to leave NOW!! - --9 --1 -16 -128 -@none@ - --13 -FACE_SID --1 -0 -Chris, wh... - --15 -FACE_KLINE --1 -0 -So finally I meet the man who has been causing us so much trouble! - --20 -FACE_CHRIS --1 -0 -I see you've jammed up my warp drive. Who are you? - --25 -FACE_KLINE --1 -0 -I am Kline Kethlan. And I am here to put to a stop to your worthless little crusade! - --31 -FACE_CHRIS --1 -0 -Kline Kethlan, huh? You sure sound confident. - --36 -FACE_KLINE --1 -0 -Nowhere to run, nowhere to hide, and no one to help you! This will certainly be interesting... - --42 --1 -15 --20 -@none@ - -0 diff --git a/data/script13.txt b/data/script13.txt deleted file mode 100644 index 192584c..0000000 --- a/data/script13.txt +++ /dev/null @@ -1,17 +0,0 @@ -2 -FACE_URSULA --1 -0 -Unidentified craft sighted. Will proceed to destroy all targets. - -8 -FACE_CHRIS --1 -0 -Looks like she's got one of those homing missile launchers too! Any advice, Phoebe? - -14 -FACE_PHOEBE --1 -0 -Just try and dodge them! diff --git a/data/script16.txt b/data/script16.txt deleted file mode 100644 index 6861e25..0000000 --- a/data/script16.txt +++ /dev/null @@ -1,61 +0,0 @@ -1 -FACE_CHRIS --1 -0 -Nice ship! - -7 -FACE_KRASS --1 -0 -Thanks, boy. Made it myself! - -60 -FACE_KRASS --1 -0 -Hey, boy, we've got company! Looks like your friends didn't do a very good job after all! - -60 --1 -10 --1048576 -@none@ - -90 --1 -11 --1048576 -@none@ - -93 -FACE_KRASS --1 -0 -Keep those things off my back or it'll cost you extra!!! - -120 --1 -12 --1048576 -@none@ - -140 -FACE_PHOEBE -16 --1048576 -Hey!! Did we miss anything exciting? - -140 --1 -17 --1048576 -@none@ - -150 -FACE_KRASS -19 -128 -I've earned my fee. I'll see you around, boy! - -0 diff --git a/data/script17.txt b/data/script17.txt deleted file mode 100644 index 812e242..0000000 --- a/data/script17.txt +++ /dev/null @@ -1,8 +0,0 @@ -90 -FACE_SID -14 -128 -DAMMIT! It's getting away! We've got to stop it! - - -0 diff --git a/data/script22.txt b/data/script22.txt deleted file mode 100644 index be940a2..0000000 --- a/data/script22.txt +++ /dev/null @@ -1,37 +0,0 @@ -45 -FACE_SID --1 -0 -Chris! Another two of those ray cannons just arrived in your sector! - -45 --1 -11 --1048576 -@none@ - -45 --1 -12 --1048576 -@none@ - -90 -FACE_SID --1 -0 -Two more! - -90 --1 -13 --1048576 -@none@ - -90 --1 -14 --1048576 -@none@ - -0 diff --git a/data/script23.txt b/data/script23.txt deleted file mode 100644 index ef85896..0000000 --- a/data/script23.txt +++ /dev/null @@ -1,55 +0,0 @@ -1 --1 -10 --1048576 -@none@ - -2 -FACE_URSULA --1 -0 -It's a trap! My God! It's Tyler! - -8 -FACE_KRASS --1 -0 -I'm a mercenary, what do you expect?! WEAPCO hired me to do a job, just like you have been doing. - -14 -FACE_CHRIS --1 -0 -Good point. It would be foolish to expect anything else. - -15 --1 -11 --1048576 -@none@ - -20 -FACE_KRASS --1 -0 -Now if you'll assist me in dying quickly, I have a cheque to earn, boy... - -25 -FACE_CHRIS --1 -0 -I have a name, you know. Do you remember it? - -45 --1 -12 --1048576 -@none@ - -45 --1 -13 --1048576 -@none@ - -0 diff --git a/data/script25.txt b/data/script25.txt deleted file mode 100644 index 0604dc7..0000000 --- a/data/script25.txt +++ /dev/null @@ -1,13 +0,0 @@ -2 -FACE_KLINE --1 -0 -That's far enough, Bainfield. You've been lucky so far, but your luck is about to run out! - -8 -FACE_CHRIS --1 -0 -Yeah, right! Like I'd lose to you after coming this far! - -0 diff --git a/data/script26.txt b/data/script26.txt deleted file mode 100644 index 96374ee..0000000 --- a/data/script26.txt +++ /dev/null @@ -1,11 +0,0 @@ -2 -FACE_CHRIS --1 -0 -WEAPCO is finished, Kethlan! You have nowhere to run, nowhere to hide, and no one to help you. - -8 -FACE_KLINE --1 -0 -You underestimate me, Bainfield. diff --git a/data/script5.txt b/data/script5.txt deleted file mode 100644 index 66d43e5..0000000 --- a/data/script5.txt +++ /dev/null @@ -1,37 +0,0 @@ -2 -FACE_SID --1 -0 -You should try and destroy some of the frigate's weaponary, it'll help! - -120 -FACE_SID --1 -0 -Chris, get a move on! The frigate is almost in range! - -150 -FACE_SID --1 -0 -The frigate is charging its cannon! - -170 -FACE_SID --1 -0 -Chris, HURRY!!! - -180 --1 -14 -132 -@none@ - -180 -FACE_SID --1 -0 -oh my god... - -0 diff --git a/data/script7.txt b/data/script7.txt deleted file mode 100644 index 9c15b97..0000000 --- a/data/script7.txt +++ /dev/null @@ -1,7 +0,0 @@ -2 -FACE_PHOEBE --1 -0 -Hey, over here! Destroy this tug so I can break free! - -0 diff --git a/data/script8.txt b/data/script8.txt deleted file mode 100644 index df7e490..0000000 --- a/data/script8.txt +++ /dev/null @@ -1,61 +0,0 @@ -2 -FACE_CREW --1 -0 -Thank God! Please, help us! If they destroy this ship... - -6 -FACE_CHRIS --1 -0 -How long do you need? - -10 -FACE_CREW --1 -0 -Just a few minutes! - -60 -FACE_CREW -19 --16 -Alright! We've got the weapons working again! Now to look at the engines... - -80 -FACE_CREW -19 -16 -DAMN! The guns are offline again! What you guys doing back there?! - -100 -FACE_CREW -19 -2048 -Chris, HELP!! We've lost all system power! We're a sitting duck out here! - -120 -FACE_CREW --1 -0 -Just a little longer... - -140 -FACE_CREW -19 --2048 -Okay! We've fixed that one. We think we've found the problem with the engines too... - -177 -FACE_CREW --1 -0 -Engines fixed! Let's move! - -180 --1 -19 -132 -@none@ - -0 diff --git a/src/Starfighter.h b/src/Starfighter.h index a5e6b5d..7ce1d8b 100644 --- a/src/Starfighter.h +++ b/src/Starfighter.h @@ -42,6 +42,7 @@ along with this program. If not, see . #include "collectable.h" #include "colors.h" #include "engine.h" +#include "event.h" #include "explosion.h" #include "game.h" #include "gfx.h" diff --git a/src/event.cpp b/src/event.cpp new file mode 100644 index 0000000..815e2fb --- /dev/null +++ b/src/event.cpp @@ -0,0 +1,374 @@ +/* +Copyright (C) 2003 Parallel Realities +Copyright (C) 2011, 2012, 2013 Guus Sliepen +Copyright (C) 2012, 2015, 2016 onpon4 + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 3 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include "Starfighter.h" + +static Event gameEvent[20]; +static const char *klineGreeting[] = { + "How nice to see you again, Bainfield!", + "It all ends here, rebel!", + "I hope you won't disappoint me this time...", + "Do you really think you can defeat us?!" +}; + +void event_set() +{ + for (int i = 0 ; i < 20 ; i++) + { + gameEvent[i].time = 0; + gameEvent[i].face = -1; + strcpy(gameEvent[i].message, ""); + gameEvent[i].entity = -1; + gameEvent[i].flag = 0; + } + + switch (game.area) + { + case MISN_INTERCEPTION: + if ((aliens[ALIEN_KLINE].classDef == CD_KLINE) && + (aliens[ALIEN_KLINE].active)) + gameEvent[0].time = 2; + gameEvent[0].face = FACE_KLINE; + strcpy(gameEvent[0].message, klineGreeting[rand() % 4]); + + break; + + case MISN_MOEBO: + gameEvent[0].time = 2; + gameEvent[0].face = FACE_SID; + strcpy(gameEvent[0].message, "You should try and destroy some of the frigate's weaponary, it'll help!"); + + gameEvent[1].time = 120; + gameEvent[1].face = FACE_SID; + strcpy(gameEvent[1].message, "Chris, get a move on! The frigate is almost in range!"); + + gameEvent[2].time = 150; + gameEvent[2].face = FACE_SID; + strcpy(gameEvent[2].message, "The frigate is charging its cannon!"); + + gameEvent[3].time = 170; + gameEvent[3].face = FACE_SID; + strcpy(gameEvent[3].message, "Chris, HURRY!!!"); + + gameEvent[4].time = 180; + gameEvent[4].face = FACE_SID; + strcpy(gameEvent[4].message, "Oh my god..."); + gameEvent[4].entity = ALIEN_BOSS; + gameEvent[4].flag = FL_LEAVESECTOR | FL_IMMORTAL; + + break; + + case MISN_NEROD: + gameEvent[0].time = 2; + gameEvent[0].face = FACE_PHOEBE; + strcpy(gameEvent[0].message, "Hey, over here! Destroy this tug so I can break free!"); + + break; + + case MISN_ALLEZ: + gameEvent[0].time = 2; + gameEvent[0].face = FACE_CREW; + strcpy(gameEvent[0].message, "Thank God! Please, help us! If they destroy this ship..."); + + gameEvent[1].time = 6; + gameEvent[1].face = FACE_CHRIS; + strcpy(gameEvent[1].message, "How long do you need?"); + + gameEvent[2].time = 10; + gameEvent[2].face = FACE_CREW; + strcpy(gameEvent[2].message, "Just a few minutes!"); + + gameEvent[3].time = 60; + gameEvent[3].face = FACE_CREW; + strcpy(gameEvent[3].message, "Alright! We've got the weapons working again! Now to look at the engines..."); + gameEvent[3].entity = ALIEN_GOODTRANSPORT; + gameEvent[3].flag = -FL_NOFIRE; + + gameEvent[4].time = 80; + gameEvent[4].face = FACE_CREW; + strcpy(gameEvent[4].message, "DAMN! The guns are offline again! What you guys doing back there?!"); + gameEvent[4].entity = ALIEN_GOODTRANSPORT; + gameEvent[4].flag = FL_NOFIRE; + + gameEvent[5].time = 100; + gameEvent[5].face = FACE_CREW; + strcpy(gameEvent[5].message, "Chris, HELP!! We've lost all system power! We're a sitting duck out here!"); + gameEvent[5].entity = ALIEN_GOODTRANSPORT; + gameEvent[5].flag = FL_DISABLED; + + gameEvent[6].time = 120; + gameEvent[6].face = FACE_CREW; + strcpy(gameEvent[6].message, "Just a little longer..."); + + gameEvent[7].time = 140; + gameEvent[7].face = FACE_CREW; + strcpy(gameEvent[7].message, "Okay! We've fixed that one. We think we've found the problem with the engines too..."); + gameEvent[7].entity = ALIEN_GOODTRANSPORT; + gameEvent[7].flag = -FL_DISABLED; + + gameEvent[8].time = 177; + gameEvent[8].face = FACE_CREW; + strcpy(gameEvent[8].message, "Engines fixed! Let's move!"); + + gameEvent[9].time = 180; + gameEvent[9].entity = ALIEN_GOODTRANSPORT; + gameEvent[9].flag = FL_LEAVESECTOR | FL_IMMORTAL; + + break; + + case MISN_ELAMALE: + gameEvent[0].time = 5; + gameEvent[0].face = FACE_PHOEBE; + strcpy(gameEvent[0].message, "Ummm... something about this doesn't look right! They should be offering more resistance than this!"); + + gameEvent[1].time = -8; + gameEvent[1].face = FACE_PHOEBE; + strcpy(gameEvent[1].message, "DAMMIT! It's a trap! Come on, Chris, we have to leave NOW!!"); + + gameEvent[2].time = -9; + gameEvent[2].entity = ALIEN_PHOEBE; + gameEvent[2].flag = FL_LEAVESECTOR; + + gameEvent[3].time = -13; + gameEvent[3].face = FACE_SID; + strcpy(gameEvent[3].message, "Chris, wh..."); + + gameEvent[4].time = -15; + gameEvent[4].face = FACE_KLINE; + strcpy(gameEvent[4].message, "So finally I meet the man who has been causing us so much trouble!"); + + gameEvent[5].time = -20; + gameEvent[5].face = FACE_CHRIS; + strcpy(gameEvent[5].message, "I see you've jammed up my warp drive. Who are you?"); + + gameEvent[6].time = -25; + gameEvent[6].face = FACE_KLINE; + strcpy(gameEvent[6].message, "I am Kline Kethlan. And I am here to put to a stop to your worthless little crusade!"); + + gameEvent[7].time = -31; + gameEvent[7].face = FACE_CHRIS; + strcpy(gameEvent[7].message, "Kline Kethlan, huh? You sure sound confident."); + + gameEvent[8].time = -36; + gameEvent[8].face = FACE_KLINE; + strcpy(gameEvent[8].message, "Nowhere to run, nowhere to hide, and no one to help you! This will certainly be interesting..."); + + gameEvent[9].time = -42; + gameEvent[9].entity = ALIEN_KLINE; + gameEvent[9].flag = -(FL_IMMORTAL | FL_NOFIRE); + + break; + + case MISN_ODEON: + gameEvent[0].time = 2; + gameEvent[0].face = FACE_URSULA; + strcpy(gameEvent[0].message, "Unidentified craft sighted. Will proceed to destroy all targets."); + + gameEvent[1].time = 8; + gameEvent[1].face = FACE_CHRIS; + strcpy(gameEvent[1].message, "Looks like she's got one of those homing missile launchers too! Any advice, Phoebe?"); + + gameEvent[2].time = 14; + gameEvent[2].face = FACE_PHOEBE; + strcpy(gameEvent[2].message, "Just try and dodge them!"); + + break; + + case MISN_ALMARTHA: + gameEvent[0].time = 1; + gameEvent[0].face = FACE_CHRIS; + strcpy(gameEvent[0].message, "Nice ship!"); + + gameEvent[1].time = 7; + gameEvent[1].face = FACE_KRASS; + strcpy(gameEvent[1].message, "Thanks, boy. Made it myself!"); + + gameEvent[2].time = 60; + gameEvent[2].face = FACE_KRASS; + strcpy(gameEvent[2].message, "Hey, boy, we've got company! Looks like your friends didn't do a very good job after all!"); + gameEvent[2].entity = 10; + gameEvent[2].flag = -FL_ACTIVATE; + + gameEvent[3].time = 90; + gameEvent[3].entity = 11; + gameEvent[3].flag = -FL_ACTIVATE; + + gameEvent[4].time = 93; + gameEvent[4].face = FACE_KRASS; + strcpy(gameEvent[4].message, "Keep those things off my back or it'll cost you extra!!!"); + + gameEvent[5].time = 120; + gameEvent[5].entity = 12; + gameEvent[5].flag = -FL_ACTIVATE; + + gameEvent[6].time = 140; + gameEvent[6].face = FACE_PHOEBE; + strcpy(gameEvent[6].message, "Hey! Did we miss anything exciting?"); + gameEvent[6].entity = ALIEN_PHOEBE; + gameEvent[6].flag = -FL_ACTIVATE; + + gameEvent[7].time = 140; + gameEvent[7].entity = ALIEN_URSULA; + gameEvent[7].flag = -FL_ACTIVATE; + + gameEvent[8].time = 150; + gameEvent[8].face = FACE_KRASS; + strcpy(gameEvent[8].message, "I've earned my fee. I'll see you around, boy!"); + gameEvent[8].entity = ALIEN_GOODTRANSPORT; + gameEvent[8].flag = FL_LEAVESECTOR; + + break; + + case MISN_POSWIC: + gameEvent[0].time = 90; + gameEvent[0].face = FACE_SID; + strcpy(gameEvent[0].message, "DAMMIT! It's getting away! We've got to stop it!"); + gameEvent[0].entity = ALIEN_BOSS; + gameEvent[0].flag = FL_LEAVESECTOR; + + break; + + case MISN_SATURN: + gameEvent[0].time = 45; + gameEvent[0].face = FACE_SID; + strcpy(gameEvent[0].message, "Chris! Another two of those ray cannons just arrived in your sector!"); + gameEvent[0].entity = 11; + gameEvent[0].flag = -FL_ACTIVATE; + + gameEvent[1].time = 45; + gameEvent[1].entity = 12; + gameEvent[1].flag = -FL_ACTIVATE; + + gameEvent[2].time = 90; + gameEvent[2].face = FACE_SID; + strcpy(gameEvent[2].message, "Two more!"); + gameEvent[2].entity = 13; + gameEvent[2].flag = -FL_ACTIVATE; + + gameEvent[3].time = 90; + gameEvent[3].entity = 14; + gameEvent[3].flag = -FL_ACTIVATE; + + break; + + case MISN_JUPITER: + gameEvent[0].time = 1; + gameEvent[0].entity = 10; + gameEvent[0].flag = -FL_ACTIVATE; + + gameEvent[1].time = 2; + gameEvent[1].face = FACE_URSULA; + strcpy(gameEvent[1].message, "It's a trap! My God! It's Tyler!"); + + gameEvent[2].time = 8; + gameEvent[2].face = FACE_KRASS; + strcpy(gameEvent[2].message, "I'm a mercenary, what do you expect?! WEAPCO hired me to do a job, just like you have been doing."); + + gameEvent[3].time = 14; + gameEvent[3].face = FACE_CHRIS; + strcpy(gameEvent[3].message, "Good point. It would be foolish to expect anything else."); + + gameEvent[4].time = 15; + gameEvent[4].entity = 11; + gameEvent[4].flag = -FL_ACTIVATE; + + gameEvent[5].time = 20; + gameEvent[5].face = FACE_KRASS; + strcpy(gameEvent[5].message, "Now if you'll assist me in dying quickly, I have a cheque to earn, boy..."); + + gameEvent[6].time = 25; + gameEvent[6].face = FACE_CHRIS; + strcpy(gameEvent[6].message, "I have a name, you know. Do you remember it?"); + + gameEvent[4].time = 45; + gameEvent[4].entity = 12; + gameEvent[4].flag = -FL_ACTIVATE; + + gameEvent[4].time = 45; + gameEvent[4].entity = 13; + gameEvent[4].flag = -FL_ACTIVATE; + + break; + + case MISN_EARTH: + gameEvent[0].time = 2; + gameEvent[0].face = FACE_KLINE; + strcpy(gameEvent[0].message, "That's far enough, Bainfield. You've been lucky so far, but your luck is about to run out!"); + + gameEvent[1].time = 8; + gameEvent[1].face = FACE_CHRIS; + strcpy(gameEvent[1].message, "Yeah, right! Like I'd lose to you after coming this far!"); + + break; + + case MISN_VENUS: + gameEvent[0].time = 2; + gameEvent[0].face = FACE_CHRIS; + strcpy(gameEvent[0].message, "WEAPCO is finished, Kethlan! You have nowhere to run, nowhere to hide, and no one to help you."); + + gameEvent[1].time = 8; + gameEvent[1].face = FACE_KLINE; + strcpy(gameEvent[1].message, "You underestimate me, Bainfield."); + + break; + } +} + +void event_check() +{ + for (int i = 0 ; i < 20 ; i++) + { + if (engine.timeTaken == gameEvent[i].time) + { + if (strcmp(gameEvent[i].message, "@none@") != 0) + { + setRadioMessage(gameEvent[i].face, gameEvent[i].message, 1); + } + + if (gameEvent[i].entity > -1) + { + if (gameEvent[i].flag != -FL_ACTIVATE) + { + aliens[gameEvent[i].entity].flags += gameEvent[i].flag; + } + else + { + aliens[gameEvent[i].entity].active = true; + aliens[gameEvent[i].entity].x = ((int)player.x + + RANDRANGE(400, 800)); + aliens[gameEvent[i].entity].y = ((int)player.y + + RANDRANGE(-400, 800)); + } + } + + gameEvent[i].time = 0; + } + } +} + +void event_sync() +{ + for (int i = 0 ; i < 20 ; i++) + { + if (gameEvent[i].time < 0) + { + gameEvent[i].time = engine.timeTaken + abs(gameEvent[i].time); + } + } +} diff --git a/src/event.h b/src/event.h new file mode 100644 index 0000000..6996bd0 --- /dev/null +++ b/src/event.h @@ -0,0 +1,37 @@ +/* +Copyright (C) 2003 Parallel Realities +Copyright (C) 2011 Guus Sliepen +Copyright (C) 2015, 2016 onpon4 + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 3 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#ifndef EVENT_H +#define EVENT_H + +typedef struct Event_ { + + int time; + int face; + char message[255]; + int entity; + int flag; + +} Event; + +void event_set(); +void event_check(); +void event_sync(); + +#endif diff --git a/src/game.cpp b/src/game.cpp index f96782a..7108604 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1718,7 +1718,7 @@ static void game_doHud() engine.timeTaken++; engine.counter2 = SDL_GetTicks() + 1000; if (engine.missionCompleteTimer == 0) - checkScriptEvents(); + event_check(); } if ((engine.timeMission) && (!engine.cheatTime) && (player.shield > 0)) @@ -1748,7 +1748,7 @@ static void game_doHud() currentMission.timeLimit2[i]--; } checkTimer(); - checkScriptEvents(); + event_check(); } if ((engine.seconds == 0) && (engine.minutes == 0)) @@ -1761,7 +1761,7 @@ static void game_doHud() currentMission.timeLimit2[i]--; } checkTimer(); - checkScriptEvents(); + event_check(); engine.counter = (SDL_GetTicks() + 1000); } } @@ -2099,7 +2099,7 @@ int game_mainLoop() clearInfoLines(); - loadScriptEvents(); + event_set(); engine.ssx = 0; engine.ssy = 0; diff --git a/src/missions.cpp b/src/missions.cpp index 2dd8c59..faf7b3d 100644 --- a/src/missions.cpp +++ b/src/missions.cpp @@ -19,8 +19,6 @@ along with this program. If not, see . #include "Starfighter.h" -// God, I hate this file! :(( - Planet systemPlanet[10]; mission currentMission; static mission missions[MISN_MAX]; @@ -529,7 +527,7 @@ static char revealHiddenObjectives() if (game.area == MISN_ELAMALE) { mission_killAllEnemies(); - syncScriptEvents(); + event_sync(); aliens[ALIEN_KLINE].active = true; aliens[ALIEN_KLINE].x = player.x + 1000; aliens[ALIEN_KLINE].y = player.y; diff --git a/src/script.cpp b/src/script.cpp index 88dd6de..bfa823a 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -20,111 +20,6 @@ along with this program. If not, see . #include "Starfighter.h" static cutMsg cutMessage[10]; -static event gameEvent[20]; - -static void setKlineGreeting() -{ - static const char *greet[] = { - "How nice to see you again, Bainfield!", - "It all ends here, rebel!", - "I hope you won't disappoint me this time...", - "Do you really think you can defeat us?!" - }; - - gameEvent[0].time = 2; - gameEvent[0].face = FACE_KLINE; - strcpy(gameEvent[0].message, greet[rand() % 4]); - gameEvent[0].entity = -1; - gameEvent[0].flag = 0; -} - -void loadScriptEvents() -{ - for (int i = 0 ; i < 20 ; i++) - { - gameEvent[i].time = 0; - strcpy(gameEvent[i].message, ""); - gameEvent[i].entity = -1; - gameEvent[i].flag = 0; - } - - if ((game.area == MISN_INTERCEPTION) && - (aliens[ALIEN_KLINE].classDef == CD_KLINE) && - (aliens[ALIEN_KLINE].active)) - setKlineGreeting(); - - char filename[255]; - sprintf(filename, "data/script%d.txt", game.area); - - FILE *fp; - int i = 0; - - int time, entity, flags; - char face[255], message[255]; - - fp = fopen(filename, "rb"); - if (fp == NULL) - return; - - while (fscanf(fp, "%d %s %d %d ", &time, face, &entity, &flags) == 4) - { - if (fscanf(fp, "%[^\n]%*c", message) < 1) - strcpy(message, "Error: Text missing"); - - gameEvent[i].time = time; - gameEvent[i].face = getFace(face); - gameEvent[i].entity = entity; - gameEvent[i].flag = flags; - strcpy(gameEvent[i].message, message); - - i++; - } - - fclose(fp); -} - -void checkScriptEvents() -{ - for (int i = 0 ; i < 20 ; i++) - { - if (engine.timeTaken == gameEvent[i].time) - { - if (strcmp(gameEvent[i].message, "@none@") != 0) - { - setRadioMessage(gameEvent[i].face, gameEvent[i].message, 1); - } - - if (gameEvent[i].entity > -1) - { - if (gameEvent[i].flag != -FL_ACTIVATE) - { - aliens[gameEvent[i].entity].flags += gameEvent[i].flag; - } - else - { - aliens[gameEvent[i].entity].active = true; - aliens[gameEvent[i].entity].x = ((int)player.x + - RANDRANGE(400, 800)); - aliens[gameEvent[i].entity].y = ((int)player.y + - RANDRANGE(-400, 800)); - } - } - - gameEvent[i].time = 0; - } - } -} - -void syncScriptEvents() -{ - for (int i = 0 ; i < 20 ; i++) - { - if (gameEvent[i].time < 0) - { - gameEvent[i].time = engine.timeTaken + abs(gameEvent[i].time); - } - } -} static void setScene(int scene) { diff --git a/src/script.h b/src/script.h index 8bba7d8..a883e5a 100644 --- a/src/script.h +++ b/src/script.h @@ -20,9 +20,6 @@ along with this program. If not, see . #ifndef SCRIPT_H #define SCRIPT_H -extern void loadScriptEvents(); -extern void checkScriptEvents(); -extern void syncScriptEvents(); extern void doCutscene(int scene); #endif diff --git a/src/structs.h b/src/structs.h index 49a6ec2..f2071e3 100644 --- a/src/structs.h +++ b/src/structs.h @@ -227,16 +227,6 @@ typedef struct Planet_ { } Planet; -typedef struct event_ { - - int time; - char message[255]; - int face; - int entity; - int flag; - -} event; - typedef struct cutMsg_ { int face;