From f883423875c0f8d01eb151127726b6cd36b612c5 Mon Sep 17 00:00:00 2001 From: Steve Date: Fri, 13 Nov 2015 16:55:49 +0000 Subject: [PATCH] Added function to adjust target value of objectives (such as requiring fewer civs to rescue if some are killed). --- src/battle/fighters.c | 10 +++++++++- src/battle/fighters.h | 1 + src/battle/objectives.c | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/battle/fighters.c b/src/battle/fighters.c index 26bd23d..932f674 100644 --- a/src/battle/fighters.c +++ b/src/battle/fighters.c @@ -270,12 +270,20 @@ void doFighter(void) if (!battle.epic) { - addHudMessage(colors.red, "Ally has been killed"); + if (self->flags & EF_CIVILIAN) + { + addHudMessage(colors.red, "Civilian has been killed"); + } + else + { + addHudMessage(colors.red, "Ally has been killed"); + } } } } updateObjective(self->name, TT_DESTROY); + adjustObjectiveTargetValue(self->name, TT_ESCAPED, -1); updateCondition(self->name, TT_DESTROY); diff --git a/src/battle/fighters.h b/src/battle/fighters.h index 62ac8fe..dcce3b4 100644 --- a/src/battle/fighters.h +++ b/src/battle/fighters.h @@ -41,6 +41,7 @@ extern void addHudMessage(SDL_Color c, char *format, ...); extern void checkTrigger(char *name, int type); extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore); extern Entity *spawnEntity(void); +extern void adjustObjectiveTargetValue(char *name, int type, int amount); extern App app; extern Battle battle; diff --git a/src/battle/objectives.c b/src/battle/objectives.c index 9b6302d..3b2b206 100644 --- a/src/battle/objectives.c +++ b/src/battle/objectives.c @@ -113,6 +113,26 @@ void updateObjective(char *name, int type) } } +void adjustObjectiveTargetValue(char *name, int type, int amount) +{ + Objective *o; + + for (o = battle.objectiveHead.next ; o != NULL ; o = o->next) + { + if (o->active && !o->isCondition && o->targetType == type && o->currentValue < o->targetValue && strcmp(o->targetName, name) == 0) + { + o->targetValue += amount; + o->currentValue = MIN(o->currentValue, o->targetValue); + + if (o->currentValue >= o->targetValue) + { + o->status = OS_COMPLETE; + addHudMessage(colors.green, "%s - Objective Complete!", o->description); + } + } + } +} + void updateCondition(char *name, int type) { Objective *o;