From a64b41f851d3302a62509edd56dad79b78fa47fc Mon Sep 17 00:00:00 2001 From: Steve Date: Sat, 2 Apr 2016 09:37:39 +0100 Subject: [PATCH] Allow challenges to be completed even if the player is killed. --- src/battle/fighters.c | 6 +----- src/battle/player.c | 11 ++++++++++- src/challenges/challenges.c | 7 ++++++- src/galaxy/mission.c | 3 +++ src/structs.h | 1 + 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/battle/fighters.c b/src/battle/fighters.c index b02f3ee..5035268 100644 --- a/src/battle/fighters.c +++ b/src/battle/fighters.c @@ -276,11 +276,7 @@ void doFighter(void) if (self->alive == ALIVE_DEAD) { - if (self == player) - { - battle.stats[STAT_PLAYER_KILLED]++; - } - else if (player != NULL) + if (player != NULL && self == player) { if (player->alive == ALIVE_ALIVE) { diff --git a/src/battle/player.c b/src/battle/player.c index 221326a..196fa32 100644 --- a/src/battle/player.c +++ b/src/battle/player.c @@ -119,7 +119,16 @@ void doPlayer(void) if (player->health <= 0 && battle.status == MS_IN_PROGRESS) { - if (!battle.isEpic) + battle.stats[STAT_PLAYER_KILLED]++; + + if (game.currentMission->challengeData.isChallenge) + { + if (!game.currentMission->challengeData.allowPlayerDeath) + { + failMission(); + } + } + else if (!battle.isEpic) { failMission(); } diff --git a/src/challenges/challenges.c b/src/challenges/challenges.c index fcedc30..b5c8ffb 100644 --- a/src/challenges/challenges.c +++ b/src/challenges/challenges.c @@ -87,7 +87,7 @@ void doChallenges(void) { if (challengeFinished()) { - if (battle.stats[STAT_TIME] >= game.currentMission->challengeData.timeLimit) + if (game.currentMission->challengeData.timeLimit && battle.stats[STAT_TIME] >= game.currentMission->challengeData.timeLimit) { failChallenge(); } @@ -139,6 +139,11 @@ static int challengeFinished(void) return 1; } + if (player->health <= 0) + { + return 1; + } + return 0; } diff --git a/src/galaxy/mission.c b/src/galaxy/mission.c index 5ba64e9..de77caf 100644 --- a/src/galaxy/mission.c +++ b/src/galaxy/mission.c @@ -87,6 +87,9 @@ Mission *loadMissionMeta(char *filename) mission->challengeData.noECM = getJSONValue(node, "noECM", 0); mission->challengeData.noBoost = getJSONValue(node, "noBoost", 0); mission->challengeData.noGuns = getJSONValue(node, "noGuns", 0); + + /* misc */ + mission->challengeData.allowPlayerDeath = getJSONValue(node, "allowPlayerDeath", 0); node = cJSON_GetObjectItem(node, "challenges"); diff --git a/src/structs.h b/src/structs.h index 7e462bc..0d44850 100644 --- a/src/structs.h +++ b/src/structs.h @@ -261,6 +261,7 @@ typedef struct { int noECM; int noGuns; int scriptedEnd; + int allowPlayerDeath; Challenge *challenges[MAX_CHALLENGES]; } ChallengeData;