From 1cd8b42664f9b5bcabfe860f8f9a3c398a926d37 Mon Sep 17 00:00:00 2001 From: Steve Date: Mon, 2 Nov 2015 19:18:26 +0000 Subject: [PATCH] Centralize completeMission and failMission logic. --- src/battle/battle.c | 20 ++++++++------------ src/battle/battle.h | 1 + src/galaxy/mission.c | 20 ++++++++++++++------ src/galaxy/mission.h | 1 + 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/battle/battle.c b/src/battle/battle.c index 0e17021..8b05646 100644 --- a/src/battle/battle.c +++ b/src/battle/battle.c @@ -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) diff --git a/src/battle/battle.h b/src/battle/battle.h index 216acaa..0a8f9cd 100644 --- a/src/battle/battle.h +++ b/src/battle/battle.h @@ -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; diff --git a/src/galaxy/mission.c b/src/galaxy/mission.c index e8883fb..9cdb32f 100644 --- a/src/galaxy/mission.c +++ b/src/galaxy/mission.c @@ -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) diff --git a/src/galaxy/mission.h b/src/galaxy/mission.h index 8131e52..848aefb 100644 --- a/src/galaxy/mission.h +++ b/src/galaxy/mission.h @@ -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;