2018-02-18 10:29:26 +01:00
|
|
|
/*
|
|
|
|
Copyright (C) 2018 Parallel Realities
|
|
|
|
|
|
|
|
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 2
|
|
|
|
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, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "postMission.h"
|
|
|
|
|
|
|
|
static void logic(void);
|
|
|
|
static void draw(void);
|
|
|
|
static void updateMissionStatus(void);
|
2018-02-22 08:45:57 +01:00
|
|
|
static int getPostMissionStatus(void);
|
2018-04-24 09:27:42 +02:00
|
|
|
static void saveGameAndWorld(void);
|
2018-02-21 09:16:18 +01:00
|
|
|
|
2018-02-20 09:14:35 +01:00
|
|
|
static int status;
|
2018-02-21 09:16:18 +01:00
|
|
|
static float missionCompleteY;
|
|
|
|
static Atlas *background;
|
|
|
|
static Texture *atlasTexture;
|
|
|
|
static float oNum;
|
|
|
|
static int canContinue;
|
2018-02-18 10:29:26 +01:00
|
|
|
|
|
|
|
void initPostMission(void)
|
|
|
|
{
|
|
|
|
startSectionTransition();
|
|
|
|
|
2018-02-21 09:16:18 +01:00
|
|
|
atlasTexture = getTexture("gfx/atlas/atlas.png");
|
|
|
|
background = getImageFromAtlas("gfx/radar/background.png");
|
2018-02-18 10:29:26 +01:00
|
|
|
|
2018-02-21 09:16:18 +01:00
|
|
|
updateMissionStatus();
|
2018-02-20 13:31:41 +01:00
|
|
|
|
2018-03-20 20:26:14 +01:00
|
|
|
if (world.state == WS_GAME_COMPLETE)
|
|
|
|
{
|
2018-04-24 09:27:42 +02:00
|
|
|
saveGameAndWorld();
|
2018-03-20 20:26:14 +01:00
|
|
|
|
|
|
|
destroyWorld();
|
|
|
|
|
|
|
|
initEnding();
|
|
|
|
}
|
|
|
|
else if (world.state != WS_QUIT)
|
2018-02-21 09:16:18 +01:00
|
|
|
{
|
|
|
|
app.restrictTrophyAlert = 0;
|
|
|
|
|
|
|
|
canContinue = 0;
|
|
|
|
|
2018-02-22 08:45:57 +01:00
|
|
|
oNum = 0;
|
|
|
|
|
2018-02-21 09:16:18 +01:00
|
|
|
missionCompleteY = SCREEN_HEIGHT;
|
|
|
|
|
|
|
|
playSound(SND_MISSION_COMPLETE, 0);
|
|
|
|
|
2018-03-15 09:01:04 +01:00
|
|
|
app.delegate.logic = &logic;
|
|
|
|
app.delegate.draw = &draw;
|
2018-02-21 23:04:01 +01:00
|
|
|
|
2018-04-24 09:27:42 +02:00
|
|
|
saveGameAndWorld();
|
2018-02-21 23:04:01 +01:00
|
|
|
|
2018-02-21 09:16:18 +01:00
|
|
|
endSectionTransition();
|
|
|
|
}
|
2018-02-21 23:04:01 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (world.isReturnVisit)
|
|
|
|
{
|
2018-04-24 09:27:42 +02:00
|
|
|
saveGameAndWorld();
|
2018-02-21 23:04:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
restoreGameState();
|
2018-04-24 09:27:42 +02:00
|
|
|
|
|
|
|
saveGame(0);
|
2018-02-21 23:04:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
destroyWorld();
|
|
|
|
|
|
|
|
initHub();
|
|
|
|
}
|
2018-02-18 10:29:26 +01:00
|
|
|
}
|
|
|
|
|
2018-04-24 09:27:42 +02:00
|
|
|
static void saveGameAndWorld(void)
|
|
|
|
{
|
|
|
|
char *src, *dest;
|
|
|
|
|
|
|
|
saveGame(1);
|
|
|
|
|
|
|
|
saveWorld();
|
|
|
|
|
|
|
|
src = buildFormattedString("%s/%d/%s.json.tmp", app.saveDir, game.saveSlot, world.id);
|
|
|
|
dest = buildFormattedString("%s/%d/%s.json", app.saveDir, game.saveSlot, world.id);
|
|
|
|
renameFile(src, dest);
|
|
|
|
|
|
|
|
src = buildFormattedString("%s/%d/game.json.tmp", app.saveDir, game.saveSlot);
|
|
|
|
dest = buildFormattedString("%s/%d/game.json", app.saveDir, game.saveSlot, world.id);
|
|
|
|
renameFile(src, dest);
|
|
|
|
|
|
|
|
free(src);
|
|
|
|
free(dest);
|
|
|
|
}
|
|
|
|
|
2018-02-25 13:12:31 +01:00
|
|
|
void retryMission(void)
|
|
|
|
{
|
|
|
|
restoreGameState();
|
|
|
|
|
2018-04-24 09:27:42 +02:00
|
|
|
saveGame(0);
|
2018-02-25 13:12:31 +01:00
|
|
|
|
|
|
|
initWorld();
|
|
|
|
}
|
|
|
|
|
|
|
|
void returnToHub(void)
|
|
|
|
{
|
|
|
|
restoreGameState();
|
|
|
|
|
2018-04-24 09:27:42 +02:00
|
|
|
saveGame(0);
|
2018-02-25 13:12:31 +01:00
|
|
|
|
|
|
|
destroyWorld();
|
|
|
|
|
|
|
|
initHub();
|
|
|
|
}
|
|
|
|
|
2018-02-18 10:29:26 +01:00
|
|
|
static void updateMissionStatus(void)
|
|
|
|
{
|
|
|
|
Tuple *t;
|
|
|
|
|
|
|
|
for (t = game.missionStatusHead.next ; t != NULL ; t = t->next)
|
|
|
|
{
|
|
|
|
if (strcmp(t->key, world.id) == 0)
|
|
|
|
{
|
2018-02-22 08:45:57 +01:00
|
|
|
t->value.i = status = getPostMissionStatus();
|
2018-02-18 10:29:26 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
t = malloc(sizeof(Tuple));
|
|
|
|
memset(t, 0, sizeof(Tuple));
|
|
|
|
game.missionStatusTail->next = t;
|
|
|
|
game.missionStatusTail = t;
|
|
|
|
|
|
|
|
STRNCPY(t->key, world.id, MAX_NAME_LENGTH);
|
2018-02-22 08:45:57 +01:00
|
|
|
t->value.i = status = getPostMissionStatus();
|
2018-02-18 10:29:26 +01:00
|
|
|
}
|
|
|
|
|
2018-02-20 09:14:35 +01:00
|
|
|
static void logic(void)
|
2018-02-18 10:29:26 +01:00
|
|
|
{
|
2018-02-21 09:16:18 +01:00
|
|
|
int done;
|
|
|
|
|
|
|
|
done = (status == MS_INCOMPLETE);
|
|
|
|
|
|
|
|
missionCompleteY = limit(missionCompleteY - 10, 50, SCREEN_HEIGHT);
|
|
|
|
|
|
|
|
if (missionCompleteY == 50)
|
|
|
|
{
|
|
|
|
oNum += 0.1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (canContinue && isAcceptControl())
|
|
|
|
{
|
|
|
|
done = 1;
|
|
|
|
|
|
|
|
clearControls();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (done)
|
|
|
|
{
|
|
|
|
destroyWorld();
|
2018-02-18 10:29:26 +01:00
|
|
|
|
2018-02-21 09:16:18 +01:00
|
|
|
initHub();
|
|
|
|
}
|
2018-02-18 10:29:26 +01:00
|
|
|
}
|
2018-02-20 09:14:35 +01:00
|
|
|
|
|
|
|
static void draw(void)
|
|
|
|
{
|
2018-02-21 09:16:18 +01:00
|
|
|
Objective *o;
|
|
|
|
SDL_Color c;
|
|
|
|
char *status;
|
|
|
|
int x, y, w, i;
|
|
|
|
|
|
|
|
blitRectScaled(atlasTexture->texture, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, &background->rect, 0);
|
|
|
|
|
2018-04-01 18:41:45 +02:00
|
|
|
drawText(SCREEN_WIDTH / 2, missionCompleteY, 45, TA_CENTER, colors.white, app.strings[ST_MISSION_COMPLETE]);
|
2018-02-21 09:16:18 +01:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
if (missionCompleteY == 50)
|
|
|
|
{
|
|
|
|
w = 800;
|
|
|
|
x = (SCREEN_WIDTH - w) / 2;
|
|
|
|
y = 150;
|
|
|
|
|
|
|
|
for (o = world.objectiveHead.next ; o != NULL ; o = o->next)
|
|
|
|
{
|
|
|
|
c = o->required ? colors.red : colors.white;
|
2018-04-01 18:41:45 +02:00
|
|
|
status = app.strings[ST_INCOMPLETE];
|
2018-02-21 09:16:18 +01:00
|
|
|
|
|
|
|
if (o->currentValue >= o->targetValue)
|
|
|
|
{
|
|
|
|
c = colors.green;
|
2018-04-01 18:41:45 +02:00
|
|
|
status = app.strings[ST_COMPLETE];
|
2018-02-21 09:16:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
drawText(x + 20, y, 24, TA_LEFT, c, o->description);
|
|
|
|
drawText(SCREEN_WIDTH / 2 + 100, y, 24, TA_LEFT, c, "%d / %d", MIN(o->currentValue, o->targetValue), o->targetValue);
|
|
|
|
drawText(x + w - 20, y, 24, TA_RIGHT, c, status);
|
|
|
|
|
|
|
|
y += 55;
|
|
|
|
|
|
|
|
if (oNum < ++i)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-01 18:41:45 +02:00
|
|
|
drawText(SCREEN_WIDTH / 2, SCREEN_HEIGHT - 80, 24, TA_CENTER, colors.white, app.strings[ST_PRESS_FIRE]);
|
2018-02-21 09:16:18 +01:00
|
|
|
|
|
|
|
canContinue = 1;
|
|
|
|
}
|
2018-02-20 09:14:35 +01:00
|
|
|
}
|
2018-02-22 08:45:57 +01:00
|
|
|
|
|
|
|
static int getPostMissionStatus(void)
|
|
|
|
{
|
|
|
|
Objective *o;
|
|
|
|
Entity *e;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
status = MS_COMPLETE;
|
|
|
|
|
|
|
|
for (o = world.objectiveHead.next ; o != NULL ; o = o->next)
|
|
|
|
{
|
|
|
|
if (o->required && o->currentValue < o->targetValue)
|
|
|
|
{
|
|
|
|
return MS_INCOMPLETE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (o->currentValue < o->totalValue)
|
|
|
|
{
|
|
|
|
status = MS_PARTIAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status == MS_COMPLETE)
|
|
|
|
{
|
|
|
|
for (e = world.entityHead.next ; e != NULL ; e = e->next)
|
|
|
|
{
|
2018-03-01 23:30:33 +01:00
|
|
|
if (e->type == ET_HEART || e->type == ET_CELL)
|
2018-02-22 08:45:57 +01:00
|
|
|
{
|
|
|
|
return MS_MISSING_HEART_CELL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|