From 025e72822bf990d7e5dc59761143907c5e2580cc Mon Sep 17 00:00:00 2001 From: Steve Date: Tue, 10 May 2016 14:56:10 +0100 Subject: [PATCH] Use battle.hasThreats to determine if all enemies have been defeated. --- src/battle/entities.c | 7 ++++++- src/battle/objectives.c | 2 +- src/battle/script.c | 2 +- src/challenges/challenges.c | 10 +++++++--- src/structs.h | 4 +++- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/battle/entities.c b/src/battle/entities.c index 3fb3f70..2c45a53 100644 --- a/src/battle/entities.c +++ b/src/battle/entities.c @@ -67,7 +67,7 @@ void doEntities(void) prev = &battle.entityHead; - numAllies = numEnemies = numActiveAllies = numActiveEnemies = numSpawnedEnemies = 0; + battle.hasThreats = numAllies = numEnemies = numActiveAllies = numActiveEnemies = numSpawnedEnemies = 0; if (dev.playerImmortal) { @@ -218,6 +218,11 @@ void doEntities(void) numSpawnedEnemies++; } } + + if (e->health > 0 && !(e->flags & EF_DISABLED)) + { + battle.hasThreats = 1; + } } } diff --git a/src/battle/objectives.c b/src/battle/objectives.c index e041427..94f8371 100644 --- a/src/battle/objectives.c +++ b/src/battle/objectives.c @@ -120,7 +120,7 @@ void updateObjective(char *name, int type) } } - if (o->isEliminateAll && o->status != OS_COMPLETE && (battle.stats[STAT_ENEMIES_KILLED] + battle.stats[STAT_CAPITAL_SHIPS_DESTROYED]) == battle.numInitialEnemies) + if (o->isEliminateAll && o->status != OS_COMPLETE && !battle.hasThreats) { addHudMessage(colors.green, _("%s - Objective Complete!"), o->description); diff --git a/src/battle/script.c b/src/battle/script.c index 7d3380e..a3d57b8 100644 --- a/src/battle/script.c +++ b/src/battle/script.c @@ -262,7 +262,7 @@ static void executeNextLine(ScriptRunner *runner) } else if (strcmp(command, "END_CHALLENGE") == 0) { - game.currentMission->challengeData.scriptedEnd = 1; + battle.scriptedEnd = 1; } else if (strcmp(command, "RETREAT_ALLIES") == 0) { diff --git a/src/challenges/challenges.c b/src/challenges/challenges.c index 462ccf0..6d7cde0 100644 --- a/src/challenges/challenges.c +++ b/src/challenges/challenges.c @@ -89,8 +89,6 @@ void loadChallenge(Mission *mission, cJSON *node) int i; Challenge *challenge; - memset(&mission->challengeData, 0, sizeof(ChallengeData)); - mission->challengeData.isChallenge = 1; /* limits */ @@ -117,6 +115,7 @@ void loadChallenge(Mission *mission, cJSON *node) /* misc */ mission->challengeData.allowPlayerDeath = getJSONValue(node, "allowPlayerDeath", 0); mission->challengeData.clearWaypointEnemies = getJSONValue(node, "clearWaypointEnemies", 0); + mission->challengeData.eliminateThreats = getJSONValue(node, "eliminateThreats", 0); node = cJSON_GetObjectItem(node, "challenges"); @@ -208,7 +207,12 @@ static int challengeFinished(void) return 1; } - return (player->health <= 0 || player->alive == ALIVE_ESCAPED || game.currentMission->challengeData.scriptedEnd); + if (game.currentMission->challengeData.eliminateThreats && !battle.hasThreats) + { + return 1; + } + + return (player->health <= 0 || player->alive == ALIVE_ESCAPED || battle.scriptedEnd); } static int updateChallenges(void) diff --git a/src/structs.h b/src/structs.h index 7f36383..4b42513 100644 --- a/src/structs.h +++ b/src/structs.h @@ -262,9 +262,9 @@ typedef struct { int noBoost; int noECM; int noGuns; - int scriptedEnd; int allowPlayerDeath; int clearWaypointEnemies; + int eliminateThreats; Challenge *challenges[MAX_CHALLENGES]; } ChallengeData; @@ -345,6 +345,8 @@ typedef struct { int radarRange; int numPlayerGuns; int numObjectivesComplete, numObjectivesTotal, numConditions; + int scriptedEnd; + int hasThreats; Entity *missionTarget; Entity *jumpgate; Entity *messageSpeaker;