2011-08-24 14:14:44 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2003 Parallel Realities
|
2015-03-01 21:37:32 +01:00
|
|
|
Copyright (C) 2011, 2012, 2013 Guus Sliepen
|
|
|
|
Copyright (C) 2012, 2015 Julian Marchant
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
2015-02-26 17:20:36 +01:00
|
|
|
as published by the Free Software Foundation; either version 3
|
2011-08-24 14:14:44 +02:00
|
|
|
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
|
2015-02-26 17:20:36 +01:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2015-02-26 17:20:36 +01:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-08-24 14:14:44 +02:00
|
|
|
*/
|
|
|
|
|
2011-08-26 21:29:04 +02:00
|
|
|
#include "Starfighter.h"
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2011-08-26 21:29:04 +02:00
|
|
|
static cutMsg cutMessage[10];
|
2015-03-08 21:19:41 +01:00
|
|
|
static event gameEvent[20];
|
2011-08-26 21:29:04 +02:00
|
|
|
|
|
|
|
static void setKlineGreeting()
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2012-03-11 15:23:12 +01:00
|
|
|
static const char *greet[] = {
|
2011-08-24 14:14:44 +02:00
|
|
|
"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()
|
|
|
|
{
|
2015-03-08 21:19:41 +01:00
|
|
|
for (int i = 0 ; i < 20 ; i++)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
|
|
|
gameEvent[i].time = 0;
|
|
|
|
strcpy(gameEvent[i].message, "");
|
|
|
|
gameEvent[i].entity = -1;
|
|
|
|
gameEvent[i].flag = 0;
|
|
|
|
}
|
|
|
|
|
2015-05-21 01:41:43 +02:00
|
|
|
if ((game.area == MISN_INTERCEPTION) &&
|
2015-03-09 01:59:33 +01:00
|
|
|
(aliens[ALIEN_KLINE].classDef == CD_KLINE) &&
|
|
|
|
(aliens[ALIEN_KLINE].active))
|
2011-08-24 14:14:44 +02:00
|
|
|
setKlineGreeting();
|
|
|
|
|
|
|
|
char filename[255];
|
2015-05-21 01:41:43 +02:00
|
|
|
sprintf(filename, "data/script%d.txt", game.area);
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
FILE *fp;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
int time, entity, flags;
|
|
|
|
char face[255], message[255];
|
|
|
|
|
|
|
|
fp = fopen(filename, "rb");
|
|
|
|
if (fp == NULL)
|
|
|
|
return;
|
|
|
|
|
2015-02-27 23:59:25 +01:00
|
|
|
while (fscanf(fp, "%d %s %d %d ", &time, face, &entity, &flags) == 4)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2015-02-27 23:59:25 +01:00
|
|
|
if (fscanf(fp, "%[^\n]%*c", message) < 1)
|
|
|
|
strcpy(message, "Error: Text missing");
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2015-03-08 21:19:41 +01:00
|
|
|
for (int i = 0 ; i < 20 ; i++)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2015-03-07 15:42:24 +01:00
|
|
|
aliens[gameEvent[i].entity].flags += gameEvent[i].flag;
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-03-07 15:42:24 +01:00
|
|
|
aliens[gameEvent[i].entity].active = true;
|
2015-03-29 16:19:53 +02:00
|
|
|
aliens[gameEvent[i].entity].x = ((int)player.x +
|
|
|
|
RANDRANGE(400, 800));
|
|
|
|
aliens[gameEvent[i].entity].y = ((int)player.y +
|
|
|
|
RANDRANGE(-400, 800));
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gameEvent[i].time = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void syncScriptEvents()
|
|
|
|
{
|
2015-03-08 21:19:41 +01:00
|
|
|
for (int i = 0 ; i < 20 ; i++)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
|
|
|
if (gameEvent[i].time < 0)
|
|
|
|
{
|
|
|
|
gameEvent[i].time = engine.timeTaken + abs(gameEvent[i].time);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-26 21:29:04 +02:00
|
|
|
static void setScene(int scene)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
char string[255], face[255];
|
|
|
|
float sx, sy, x, y, speed;
|
|
|
|
int index, shape;
|
|
|
|
|
|
|
|
sprintf(string, "data/cutscene%d.dat", scene);
|
|
|
|
|
|
|
|
fp = fopen(string, "rb");
|
|
|
|
|
|
|
|
// Load in the specified background
|
2015-02-27 23:59:25 +01:00
|
|
|
if (fscanf(fp, "%s", string) < 1)
|
|
|
|
{
|
|
|
|
printf("Warning: didn't find a background definition for \"%s\"\n", string);
|
|
|
|
strcpy(string, "gfx/spirit.jpg");
|
|
|
|
}
|
2011-08-24 14:14:44 +02:00
|
|
|
loadBackground(string);
|
|
|
|
|
|
|
|
// Set the star speed
|
2015-02-27 23:59:25 +01:00
|
|
|
if (fscanf(fp, "%f %f", &sx, &sy) < 2)
|
|
|
|
printf("Warning: failed to read star speed data for cutscene");
|
2011-08-24 14:14:44 +02:00
|
|
|
engine.ssx = sx;
|
|
|
|
engine.ssy = sy;
|
|
|
|
|
|
|
|
// Read in the specs for each ship
|
2015-02-27 23:59:25 +01:00
|
|
|
while (fscanf(fp, "%d %d %f %f %f", &index, &shape, &x, &y, &speed) == 5)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
|
|
|
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));
|
|
|
|
|
|
|
|
if (shape > -1)
|
|
|
|
{
|
2015-03-07 15:42:24 +01:00
|
|
|
aliens[index].image[0] = shipShape[shape];
|
|
|
|
aliens[index].x = x;
|
|
|
|
aliens[index].y = y;
|
|
|
|
aliens[index].dx = speed;
|
|
|
|
aliens[index].active = true;
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// And finally read in the messages
|
2015-02-27 23:59:25 +01:00
|
|
|
index = 0;
|
|
|
|
while (fscanf(fp, "%s%*c %[^\n]", face, string) == 2)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
|
|
|
if (strcmp(string, "@none@") == 0)
|
|
|
|
break;
|
|
|
|
|
2015-02-27 23:59:25 +01:00
|
|
|
cutMessage[index].face = getFace(face);
|
|
|
|
strcpy(cutMessage[index].message, string);
|
|
|
|
|
|
|
|
index++;
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void doCutscene(int scene)
|
|
|
|
{
|
2011-08-26 23:53:46 +02:00
|
|
|
clearScreen(black);
|
2015-10-27 01:07:31 +01:00
|
|
|
renderer_update();
|
2011-08-26 23:53:46 +02:00
|
|
|
clearScreen(black);
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2015-03-04 01:28:15 +01:00
|
|
|
engine.keyState[KEY_FIRE] = 0;
|
|
|
|
engine.keyState[KEY_ALTFIRE] = 0;
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
engine.ssx = -0.5;
|
|
|
|
engine.ssy = 0;
|
2015-02-27 05:23:08 +01:00
|
|
|
engine.smx = 0;
|
|
|
|
engine.smy = 0;
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2015-11-02 23:53:05 +01:00
|
|
|
screen_flushBuffer();
|
2011-08-26 23:53:46 +02:00
|
|
|
freeGraphics();
|
2011-08-24 14:14:44 +02:00
|
|
|
resetLists();
|
|
|
|
loadGameGraphics();
|
|
|
|
|
|
|
|
for (int i = 0 ; i < 15 ; i++)
|
|
|
|
{
|
2015-03-07 15:42:24 +01:00
|
|
|
aliens[i] = alien_defs[0];
|
|
|
|
aliens[i].face = 0;
|
|
|
|
aliens[i].active = false;
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0 ; i < 10 ; i++)
|
|
|
|
{
|
|
|
|
strcpy(cutMessage[i].message, "");
|
|
|
|
cutMessage[i].face = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
setScene(scene);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Because we can fiddle with the images, we need to set the engines to
|
|
|
|
the correct places on the craft. Otherwise it will look wrong
|
|
|
|
*/
|
|
|
|
for (int i = 0 ; i < 15 ; i++)
|
|
|
|
{
|
2015-03-07 15:42:24 +01:00
|
|
|
aliens[i].engineX = aliens[i].image[0]->w;
|
|
|
|
aliens[i].engineY = (aliens[i].image[0]->h / 2);
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
|
2011-08-26 16:55:46 +02:00
|
|
|
bool showMessage = false;
|
2011-08-24 14:14:44 +02:00
|
|
|
signed char currentMessage = -1;
|
|
|
|
int timer = 60 * 4;
|
|
|
|
|
2011-08-26 23:53:46 +02:00
|
|
|
drawBackGround();
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
SDL_Surface *face;
|
|
|
|
|
|
|
|
flushInput();
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
2015-10-27 01:07:31 +01:00
|
|
|
renderer_update();
|
2015-11-02 23:53:05 +01:00
|
|
|
screen_unBuffer();
|
2011-08-24 14:14:44 +02:00
|
|
|
getPlayerInput();
|
2015-06-20 17:58:37 +02:00
|
|
|
game_doStars();
|
2015-05-01 00:51:26 +02:00
|
|
|
game_doExplosions();
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
for (int i = 0 ; i < 15 ; i++)
|
|
|
|
{
|
2015-03-07 15:42:24 +01:00
|
|
|
if (aliens[i].active)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2015-05-01 00:51:26 +02:00
|
|
|
explosion_addEngine(&aliens[i]);
|
2012-02-29 14:49:12 +01:00
|
|
|
if (scene == 0 && i > 0 && (timer % 15) == i) {
|
2015-03-07 15:42:24 +01:00
|
|
|
aliens[i].dx += (drand48() - 0.5) * 0.1;
|
|
|
|
aliens[i].dy += (drand48() - 0.5) * 0.1;
|
|
|
|
if (aliens[i].x > 500 - timer)
|
|
|
|
aliens[i].dx -= 0.2;
|
|
|
|
if (aliens[i].x < 0)
|
|
|
|
aliens[i].dx += 0.2;
|
2012-02-29 14:49:12 +01:00
|
|
|
}
|
2015-03-07 15:42:24 +01:00
|
|
|
aliens[i].x += aliens[i].dx;
|
|
|
|
aliens[i].y += aliens[i].dy;
|
|
|
|
aliens[i].x += engine.ssx + engine.smx;
|
2015-09-26 14:49:21 +02:00
|
|
|
screen_blit(aliens[i].image[0], (int)aliens[i].x, (int)aliens[i].y);
|
2015-03-07 15:42:24 +01:00
|
|
|
if (aliens[i].x > (screen->w + 50))
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2015-03-07 15:42:24 +01:00
|
|
|
aliens[i].x = -50;
|
|
|
|
aliens[i].y = rand() % (screen->h - 40);
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
2015-03-07 15:42:24 +01:00
|
|
|
if (aliens[i].y < -50)
|
|
|
|
aliens[i].y = (screen->h + 50);
|
|
|
|
if (aliens[i].y > (screen->h + 50))
|
|
|
|
aliens[i].y = -50;
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
timer--;
|
|
|
|
if (timer == 0)
|
|
|
|
{
|
2011-08-26 16:55:46 +02:00
|
|
|
showMessage = !showMessage;
|
2011-08-24 14:14:44 +02:00
|
|
|
timer = 120;
|
|
|
|
if (showMessage)
|
|
|
|
{
|
|
|
|
timer = 60 * 7;
|
|
|
|
currentMessage++;
|
|
|
|
|
|
|
|
if (currentMessage == 10)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (strcmp(cutMessage[currentMessage].message, "") == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
face = NULL;
|
|
|
|
if (cutMessage[currentMessage].face != -1)
|
2011-08-26 23:53:46 +02:00
|
|
|
face = shape[cutMessage[currentMessage].face];
|
|
|
|
createMessageBox(face, cutMessage[currentMessage].message, 0);
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-26 23:53:46 +02:00
|
|
|
if ((showMessage) && (messageBox != NULL))
|
2015-09-26 14:49:21 +02:00
|
|
|
screen_blit(messageBox, (screen->w - messageBox->w) / 2, screen->h - 100);
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2015-11-07 01:36:20 +01:00
|
|
|
screen_renderString("Press [Escape] to skip", -1, 580, FONT_WHITE);
|
2013-07-10 21:16:31 +02:00
|
|
|
|
2011-08-26 23:53:46 +02:00
|
|
|
delayFrame();
|
2011-08-24 20:02:35 +02:00
|
|
|
|
2015-03-04 01:28:15 +01:00
|
|
|
if ((engine.keyState[KEY_ESCAPE]) || (engine.keyState[KEY_FIRE]) ||
|
|
|
|
(engine.keyState[KEY_ALTFIRE]))
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-11-02 23:53:05 +01:00
|
|
|
screen_flushBuffer();
|
2011-08-26 23:53:46 +02:00
|
|
|
freeGraphics();
|
|
|
|
clearScreen(black);
|
2015-10-27 01:07:31 +01:00
|
|
|
renderer_update();
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|