Centralize completeMission and failMission logic.

This commit is contained in:
Steve 2015-11-02 19:18:26 +00:00
parent cd1068b2a7
commit 1cd8b42664
4 changed files with 24 additions and 18 deletions

View File

@ -134,18 +134,6 @@ static void doBattle(void)
if (battle.status != MS_IN_PROGRESS)
{
battle.missionFinishedTimer--;
if (battle.missionFinishedTimer == 0)
{
if (battle.status == MS_COMPLETE)
{
selectWidget("continue", "battleWon");
}
else
{
selectWidget("retry", "battleLost");
}
}
}
battle.stats[STAT_TIME]++;
@ -247,6 +235,14 @@ static void handleKeyboard(void)
{
battle.status = MS_PAUSED;
}
#if DEBUG
if (app.keyboard[SDL_SCANCODE_F10])
{
completeMission();
battle.missionFinishedTimer = -FPS;
}
#endif
}
static void start(void)

View File

@ -65,6 +65,7 @@ extern void checkTrigger(char *name, int type);
extern void resetWaypoints(void);
extern void doPlayerSelect(void);
extern void destroyGrid(void);
extern void completeMission(void);
extern App app;
extern Battle battle;

View File

@ -98,16 +98,24 @@ void loadMission(char *filename)
void completeMission(void)
{
battle.status = MS_COMPLETE;
battle.missionFinishedTimer = FPS;
game.stats[STAT_MISSIONS_COMPLETED]++;
if (battle.status == MS_IN_PROGRESS)
{
battle.status = MS_COMPLETE;
battle.missionFinishedTimer = FPS;
selectWidget("continue", "battleWon");
game.stats[STAT_MISSIONS_COMPLETED]++;
}
}
void failMission(void)
{
battle.status = MS_FAILED;
battle.missionFinishedTimer = FPS;
if (battle.status == MS_IN_PROGRESS)
{
battle.status = MS_FAILED;
battle.missionFinishedTimer = FPS;
selectWidget("retry", "battleLost");
}
}
static void loadObjectives(cJSON *node)

View File

@ -37,6 +37,7 @@ extern void initPlayer(void);
extern long flagsToLong(char *flags);
extern Entity *spawnWaypoint(void);
extern void activateNextWaypoint(void);
extern void selectWidget(const char *name, const char *group);
extern Battle battle;
extern Entity *player;