blobwarsAttrition/src/hub/postMission.c

178 lines
3.5 KiB
C
Raw Normal View History

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-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-21 23:04:01 +01:00
if (status == MS_COMPLETE || (!world.isReturnVisit && status != MS_INCOMPLETE))
2018-02-21 09:16:18 +01:00
{
app.restrictTrophyAlert = 0;
canContinue = 0;
missionCompleteY = SCREEN_HEIGHT;
playSound(SND_MISSION_COMPLETE, 0);
2018-02-21 23:04:01 +01:00
app.delegate.logic = logic;
app.delegate.draw = draw;
saveGame();
saveWorld();
2018-02-21 09:16:18 +01:00
endSectionTransition();
}
2018-02-21 23:04:01 +01:00
else
{
if (world.isReturnVisit)
{
saveWorld();
}
else
{
restoreGameState();
}
saveGame();
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-20 09:14:35 +01:00
t->value.i = status = getMissionStatus();
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-20 09:14:35 +01:00
t->value.i = status = getMissionStatus();
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);
drawText(SCREEN_WIDTH / 2, missionCompleteY, 45, TA_CENTER, colors.white, "Mission Complete!");
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;
status = _("Incomplete");
if (o->currentValue >= o->targetValue)
{
c = colors.green;
status = _("Complete");
}
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;
}
}
drawText(SCREEN_WIDTH / 2, SCREEN_HEIGHT - 80, 24, TA_CENTER, colors.white, _("Press Fire to Continue"));
canContinue = 1;
}
2018-02-20 09:14:35 +01:00
}