From e59af4bfbc4b0466cbe8541d30dc71cffbd6a869 Mon Sep 17 00:00:00 2001 From: Steve Date: Sun, 28 Aug 2016 18:48:55 +0100 Subject: [PATCH] Allow for a kill threshold to be specified in epic missions (for use with unwinnable missions). --- src/battle/fighters.c | 5 +++++ src/battle/objectives.c | 20 ++++++++++++++++++++ src/battle/player.c | 11 ++++++++--- src/galaxy/mission.c | 6 ++++++ src/galaxy/mission.h | 1 + src/structs.h | 1 + 6 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/battle/fighters.c b/src/battle/fighters.c index 8fbf110..e4c2687 100644 --- a/src/battle/fighters.c +++ b/src/battle/fighters.c @@ -363,6 +363,11 @@ void doFighter(void) updateObjective(self->name, TT_DESTROY); updateObjective(self->groupName, TT_DESTROY); + + if (battle.isEpic && self->killedBy == player) + { + updateObjective("EPIC_PLAYER_KILLS", TT_DESTROY); + } adjustObjectiveTargetValue(self->name, TT_ESCAPED, -1); diff --git a/src/battle/objectives.c b/src/battle/objectives.c index 9b04662..181eca3 100644 --- a/src/battle/objectives.c +++ b/src/battle/objectives.c @@ -346,3 +346,23 @@ void addEpicLivesObjective(void) o->active = 1; o->isCondition = 1; } + +void addEpicKillsObjective(void) +{ + Objective *o; + char id[MAX_DESCRIPTION_LENGTH]; + + o = malloc(sizeof(Objective)); + memset(o, 0, sizeof(Objective)); + battle.objectiveTail->next = o; + battle.objectiveTail = o; + + sprintf(id, _("Destroy at least %d enemy fighters"), battle.epicKills); + + STRNCPY(o->id, id, MAX_DESCRIPTION_LENGTH); + STRNCPY(o->description, id, MAX_DESCRIPTION_LENGTH); + STRNCPY(o->targetName, "EPIC_PLAYER_KILLS", MAX_NAME_LENGTH); + o->targetValue = battle.epicKills; + o->targetType = TT_DESTROY; + o->active = 1; +} diff --git a/src/battle/player.c b/src/battle/player.c index 6771c32..3a3f29e 100644 --- a/src/battle/player.c +++ b/src/battle/player.c @@ -432,15 +432,15 @@ static void preFireMissile(void) } } -void initPlayerSelect(void) +static void initPlayerSelect(void) { Entity *e; memset(&availablePlayerUnits, 0, sizeof(Entity*) * MAX_SELECTABLE_PLAYERS); selectedPlayerIndex = 0; - - if (battle.epicLives > 0 && --battle.epicLives > 0) + + if (battle.epicLives == 0 || (battle.epicLives > 0 && --battle.epicLives > 0)) { for (e = battle.entityHead.next ; e != NULL ; e = e->next) { @@ -460,6 +460,11 @@ void initPlayerSelect(void) else { battle.isEpic = 0; + + if (battle.epicKills > 0 && battle.stats[STAT_ENEMIES_KILLED_PLAYER] < battle.epicKills) + { + battle.unwinnable = 0; + } failMission(); } diff --git a/src/galaxy/mission.c b/src/galaxy/mission.c index 6b4a67d..3e1ba21 100644 --- a/src/galaxy/mission.c +++ b/src/galaxy/mission.c @@ -421,11 +421,17 @@ static void loadEpicData(cJSON *node) battle.epicFighterLimit = cJSON_GetObjectItem(node, "fighterLimit")->valueint; battle.unlimitedEnemies = getJSONValue(node, "unlimitedEnemies", 0); battle.epicLives = getJSONValue(node, "lives", 0); + battle.epicKills = getJSONValue(node, "kills", 0); if (battle.epicLives > 0) { addEpicLivesObjective(); } + + if (battle.epicKills != 0) + { + addEpicKillsObjective(); + } for (e = battle.entityHead.next ; e != NULL ; e = e->next) { diff --git a/src/galaxy/mission.h b/src/galaxy/mission.h index 47b0df4..ed56305 100644 --- a/src/galaxy/mission.h +++ b/src/galaxy/mission.h @@ -65,6 +65,7 @@ extern void awardPostMissionTrophies(void); extern void awardCraftTrophy(void); extern void setInitialPlayerAngle(void); extern void addEpicLivesObjective(void); +extern void addEpicKillsObjective(void); extern Battle battle; extern Dev dev; diff --git a/src/structs.h b/src/structs.h index b31ca53..6c2dfc9 100644 --- a/src/structs.h +++ b/src/structs.h @@ -345,6 +345,7 @@ typedef struct { int unlimitedEnemies; int epicFighterLimit; int epicLives; + int epicKills; int playerSelect; int manualComplete; int unwinnable;