From 5a134f2250d5e3ea9c694039117220c826f3905e Mon Sep 17 00:00:00 2001 From: Steve Date: Wed, 21 Feb 2018 22:04:01 +0000 Subject: [PATCH] Handle mission result correctly. --- src/hub/postMission.c | 39 +++++++++++++++++++++++-------------- src/world/objectives.c | 10 +++++----- src/world/world.c | 44 +++++++++++++++++++++++++++++++++++++----- 3 files changed, 69 insertions(+), 24 deletions(-) diff --git a/src/hub/postMission.c b/src/hub/postMission.c index 83451ad..2b72a58 100644 --- a/src/hub/postMission.c +++ b/src/hub/postMission.c @@ -40,11 +40,8 @@ void initPostMission(void) updateMissionStatus(); - if (status != MS_INCOMPLETE) + if (status == MS_COMPLETE || (!world.isReturnVisit && status != MS_INCOMPLETE)) { - app.delegate.logic = logic; - app.delegate.draw = draw; - app.restrictTrophyAlert = 0; canContinue = 0; @@ -53,8 +50,32 @@ void initPostMission(void) playSound(SND_MISSION_COMPLETE, 0); + app.delegate.logic = logic; + app.delegate.draw = draw; + + saveGame(); + + saveWorld(); + endSectionTransition(); } + else + { + if (world.isReturnVisit) + { + saveWorld(); + } + else + { + restoreGameState(); + } + + saveGame(); + + destroyWorld(); + + initHub(); + } } static void updateMissionStatus(void) @@ -77,16 +98,6 @@ static void updateMissionStatus(void) STRNCPY(t->key, world.id, MAX_NAME_LENGTH); t->value.i = status = getMissionStatus(); - - if (status != MS_INCOMPLETE) - { - saveGame(); - saveWorld(); - } - else - { - restoreGameState(); - } } static void logic(void) diff --git a/src/world/objectives.c b/src/world/objectives.c index 6fb3e5d..5d3852e 100644 --- a/src/world/objectives.c +++ b/src/world/objectives.c @@ -24,7 +24,6 @@ static int isMissingHeartCell(char *targetName); static int countTargetsInWorld(char *targetName); static int missingHeartCell; -static int isReturnVisit; static int isEliminateAllEnemies; void initObjectives(void) @@ -32,10 +31,11 @@ void initObjectives(void) int totalTargets; Objective *o; - isReturnVisit = world.currentStatus == MS_PARTIAL || world.currentStatus == MS_MISSING_HEART_CELL; + world.isReturnVisit = world.currentStatus == MS_PARTIAL || world.currentStatus == MS_MISSING_HEART_CELL; + missingHeartCell = world.currentStatus == MS_MISSING_HEART_CELL; - SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "isReturnVisit = %d", isReturnVisit); + SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "world.isReturnVisit = %d", world.isReturnVisit); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "missingHeartCell = %d", missingHeartCell); for (o = world.objectiveHead.next ; o != NULL ; o = o->next) @@ -64,7 +64,7 @@ void initObjectives(void) } } - if (o->required && isReturnVisit) + if (o->required && world.isReturnVisit) { o->targetValue = o->totalValue; o->required = 0; @@ -150,7 +150,7 @@ void updateObjective(char *targetName) { if (o->currentValue < o->targetValue) { - if (o->required || isReturnVisit) + if (o->required || world.isReturnVisit) { world.allObjectivesComplete = 0; } diff --git a/src/world/world.c b/src/world/world.c index 2bf3c5a..a4fa8fd 100644 --- a/src/world/world.c +++ b/src/world/world.c @@ -47,6 +47,7 @@ static void drawQuit(void); static void quitMission(void); static void returnFromOptions(void); int getMissionStatus(void); +static void completeTrainingMission(void); static Texture *background; static int observationIndex; @@ -663,11 +664,6 @@ int getMissionStatus(void) Objective *o; Entity *e; int status; - - if (world.missionType == MT_TRAINING) - { - return MS_COMPLETE; - } status = MS_COMPLETE; @@ -808,6 +804,11 @@ static void quitMission(void) stopMusic(); world.state = WS_COMPLETE; world.missionCompleteTimer = (FPS * 1.5) + 1; + + if (world.missionType == MT_TRAINING) + { + completeTrainingMission(); + } } static void returnFromOptions(void) @@ -818,6 +819,39 @@ static void returnFromOptions(void) returnFromTrophyStats(); } +static void completeTrainingMission(void) +{ + Objective *o; + Entity *e; + + for (o = world.objectiveHead.next ; o != NULL ; o = o->next) + { + o->currentValue = o->targetValue; + } + + for (e = world.entityHead.next ; e != NULL ; e = e->next) + { + switch (e->type) + { + case ET_MIA: + e->alive = ALIVE_DEAD; + game.stats[STAT_MIAS_RESCUED]++; + break; + + case ET_KEY: + if (!(e->flags & EF_GONE)) + { + e->alive = ALIVE_DEAD; + game.stats[STAT_KEYS_FOUND]++; + } + break; + + default: + break; + } + } +} + void destroyWorld(void) { int i;