From 61dd0ceb401f9320a90b92a23bc95d0b5361f127 Mon Sep 17 00:00:00 2001 From: Steve Date: Fri, 9 Mar 2018 07:32:23 +0000 Subject: [PATCH] Autocomplete mission when Cell and Heart have been found, and we're in MS_MISSING_HEART_CELL. --- src/entities/items/cell.c | 2 +- src/entities/items/cell.h | 2 +- src/entities/items/heart.c | 2 +- src/entities/items/heart.h | 2 +- src/world/objectives.c | 80 +++++++++++++++++--------------------- 5 files changed, 40 insertions(+), 48 deletions(-) diff --git a/src/entities/items/cell.c b/src/entities/items/cell.c index 5ac2213..ddc46e8 100644 --- a/src/entities/items/cell.c +++ b/src/entities/items/cell.c @@ -60,6 +60,6 @@ static void touch(Entity *other) self->alive = ALIVE_DEAD; - updateObjective("HEART_CELL"); + updateHeartCellObjective(); } } diff --git a/src/entities/items/cell.h b/src/entities/items/cell.h index 5c3ddba..3ce7d19 100644 --- a/src/entities/items/cell.h +++ b/src/entities/items/cell.h @@ -24,7 +24,7 @@ extern Entity *createItem(void); extern Sprite *getSprite(char *name); extern void playSound(int snd, int ch); extern void setGameplayMessage(int type, char *format, ...); -extern void updateObjective(char *targetName); +extern void updateHeartCellObjective(void); extern Entity *self; extern Game game; diff --git a/src/entities/items/heart.c b/src/entities/items/heart.c index b36eb9b..690ffe4 100644 --- a/src/entities/items/heart.c +++ b/src/entities/items/heart.c @@ -72,6 +72,6 @@ static void touch(Entity *other) self->alive = ALIVE_DEAD; - updateObjective("HEART_CELL"); + updateHeartCellObjective(); } } diff --git a/src/entities/items/heart.h b/src/entities/items/heart.h index 3d0eb41..729931c 100644 --- a/src/entities/items/heart.h +++ b/src/entities/items/heart.h @@ -25,7 +25,7 @@ extern Sprite *getSprite(char *name); extern void playSound(int snd, int ch); extern int rrnd(int low, int high); extern void setGameplayMessage(int type, char *format, ...); -extern void updateObjective(char *targetName); +extern void updateHeartCellObjective(void); extern Entity *self; extern Game game; diff --git a/src/world/objectives.c b/src/world/objectives.c index 49a4238..fad183b 100644 --- a/src/world/objectives.c +++ b/src/world/objectives.c @@ -20,11 +20,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "objectives.h" -static int isMissingHeartCell(char *targetName); static int countTargetsInWorld(char *targetName); -static int missingHeartCell; - void initObjectives(void) { int totalTargets; @@ -32,10 +29,7 @@ void initObjectives(void) 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, "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) { @@ -111,78 +105,76 @@ void updateObjective(char *targetName) { Objective *o; - if (missingHeartCell && !isMissingHeartCell(targetName)) + if (world.currentStatus != MS_MISSING_HEART_CELL) { - return; - } - - for (o = world.objectiveHead.next ; o != NULL ; o = o->next) - { - if (strcmp(o->targetName, targetName) == 0) + for (o = world.objectiveHead.next ; o != NULL ; o = o->next) { - o->currentValue++; - - if (strcmp(o->targetName, "KEY") != 0) + if (strcmp(o->targetName, targetName) == 0) { - if (o->currentValue == o->targetValue) + o->currentValue++; + + if (strcmp(o->targetName, "KEY") != 0) { - setGameplayMessage(MSG_OBJECTIVE, _("%s - Objective Complete!"), o->description); - } - else if (o->currentValue < o->targetValue) - { - if (strcmp(o->targetName, "ENEMY") != 0) + if (o->currentValue == o->targetValue) { - setGameplayMessage(MSG_PROGRESS, "%s - (%d / %d)", o->description, o->currentValue, o->targetValue); + setGameplayMessage(MSG_OBJECTIVE, _("%s - Objective Complete!"), o->description); } - else if (o->targetValue - o->currentValue < 10 || o->currentValue % 5 == 0) + else if (o->currentValue < o->targetValue) { - setGameplayMessage(MSG_PROGRESS, "%s - (%d / %d)", o->description, o->currentValue, o->targetValue); + if (strcmp(o->targetName, "ENEMY") != 0) + { + setGameplayMessage(MSG_PROGRESS, "%s - (%d / %d)", o->description, o->currentValue, o->targetValue); + } + else if (o->targetValue - o->currentValue < 10 || o->currentValue % 5 == 0) + { + setGameplayMessage(MSG_PROGRESS, "%s - (%d / %d)", o->description, o->currentValue, o->targetValue); + } } } } } - } - world.allObjectivesComplete = 1; + world.allObjectivesComplete = 1; - for (o = world.objectiveHead.next ; o != NULL ; o = o->next) - { - if (o->currentValue < o->targetValue) + for (o = world.objectiveHead.next ; o != NULL ; o = o->next) { - if (o->required || world.isReturnVisit) + if (o->currentValue < o->targetValue) { - world.allObjectivesComplete = 0; + if (o->required || world.isReturnVisit) + { + world.allObjectivesComplete = 0; + } } } - } - if (world.allObjectivesComplete) - { - setGameplayMessage(MSG_OBJECTIVE, _("Mission Complete!")); + if (world.allObjectivesComplete) + { + setGameplayMessage(MSG_OBJECTIVE, _("Mission Complete!")); + } } } -static int isMissingHeartCell(char *targetName) +void updateHeartCellObjective(void) { Entity *e; - if (targetName == NULL || strcmp(targetName, "HEART_CELL") == 0) - { - return 0; - } - for (e = world.entityHead.next ; e != NULL ; e = e->next) { if (e->alive == ALIVE_ALIVE) { if (e->type == ET_HEART || e->type == ET_CELL) { - return 0; + return; } } } - return 1; + if (world.currentStatus == MS_MISSING_HEART_CELL) + { + world.allObjectivesComplete = 1; + + setGameplayMessage(MSG_OBJECTIVE, _("Mission Complete!")); + } } void destroyObjectives(void)