diff --git a/src/battle/hud.c b/src/battle/hud.c index 9fbdc0b..b98ffac 100644 --- a/src/battle/hud.c +++ b/src/battle/hud.c @@ -422,6 +422,10 @@ static void drawObjectives(void) { drawText(SCREEN_WIDTH / 2, 35, 14, TA_CENTER, colors.white, "%d / %d", battle.stats[STAT_ITEMS_COLLECTED] + battle.stats[STAT_ITEMS_COLLECTED_PLAYER], game.currentMission->challengeData.itemLimit); } + else if (game.currentMission->challengeData.rescueLimit) + { + drawText(SCREEN_WIDTH / 2, 35, 14, TA_CENTER, colors.white, "%d / %d", battle.stats[STAT_CIVILIANS_RESCUED], game.currentMission->challengeData.rescueLimit); + } } else { diff --git a/src/challenges/challenges.c b/src/challenges/challenges.c index 61180ee..27082ad 100644 --- a/src/challenges/challenges.c +++ b/src/challenges/challenges.c @@ -57,6 +57,7 @@ void initChallenges(void) challengeDescription[CHALLENGE_PLAYER_KILLS] = _("Take down %d enemy targets"); challengeDescription[CHALLENGE_DISABLE] = _("Disable %d or more enemy fighters"); challengeDescription[CHALLENGE_ITEMS] = _("Collect %d packages"); + challengeDescription[CHALLENGE_RESCUE] = _("Rescue %d civilians"); tail = &game.challengeMissionHead; @@ -128,6 +129,11 @@ static int challengeFinished(void) return 1; } + if (game.currentMission->challengeData.rescueLimit > 0 && (battle.stats[STAT_CIVILIANS_RESCUED] + battle.stats[STAT_CIVILIANS_KILLED]) >= game.currentMission->challengeData.rescueLimit) + { + return 1; + } + if (game.currentMission->challengeData.scriptedEnd) { return 1; diff --git a/src/defs.h b/src/defs.h index c92d365..eed8c23 100644 --- a/src/defs.h +++ b/src/defs.h @@ -292,6 +292,7 @@ enum CHALLENGE_PLAYER_KILLS, CHALLENGE_DISABLE, CHALLENGE_ITEMS, + CHALLENGE_RESCUE, CHALLENGE_MAX }; diff --git a/src/galaxy/mission.c b/src/galaxy/mission.c index b4789ee..ee89fb9 100644 --- a/src/galaxy/mission.c +++ b/src/galaxy/mission.c @@ -28,7 +28,6 @@ static void loadEntities(cJSON *node); static void loadItems(cJSON *node); static void loadLocations(cJSON *node); static unsigned long hashcode(const char *str); -static char **toTypeArray(char *types, int *numTypes); static void loadEpicData(cJSON *node); static char *getAutoBackground(char *filename); static char *getAutoPlanet(char *filename); @@ -87,6 +86,7 @@ Mission *loadMissionMeta(char *filename) mission->challengeData.escapeLimit = getJSONValue(node, "escapeLimit", 0); mission->challengeData.waypointLimit = getJSONValue(node, "waypointLimit", 0); mission->challengeData.itemLimit = getJSONValue(node, "itemLimit", 0); + mission->challengeData.rescueLimit = getJSONValue(node, "rescueLimit", 0); /* restrictions */ mission->challengeData.noMissiles = getJSONValue(node, "noMissiles", 0); @@ -197,8 +197,6 @@ void loadMission(char *filename) battle.planetHeight *= planetScale; srand(time(NULL)); - - cJSON_Delete(root); free(text); @@ -761,38 +759,6 @@ static void loadLocations(cJSON *node) } } -static char **toTypeArray(char *types, int *numTypes) -{ - int i; - char **typeArray, *type; - - *numTypes = 1; - - for (i = 0 ; i < strlen(types) ; i++) - { - if (types[i] == ';') - { - *numTypes = *numTypes + 1; - } - } - - typeArray = malloc(*numTypes * sizeof(char*)); - - i = 0; - type = strtok(types, ";"); - while (type) - { - typeArray[i] = malloc(strlen(type) + 1); - strcpy(typeArray[i], type); - - type = strtok(NULL, ";"); - - i++; - } - - return typeArray; -} - static void loadEpicData(cJSON *node) { Entity *e; diff --git a/src/galaxy/mission.h b/src/galaxy/mission.h index af2a4d9..998712e 100644 --- a/src/galaxy/mission.h +++ b/src/galaxy/mission.h @@ -55,6 +55,7 @@ extern char *getMusicFilename(int n); extern int getJSONValue(cJSON *node, char *name, int defValue); extern char *getJSONValueStr(cJSON *node, char *name, char *defValue); extern void addAllEntsToQuadtree(void); +extern char **toTypeArray(char *types, int *numTypes); extern Battle battle; extern Entity *player; diff --git a/src/structs.h b/src/structs.h index 2473231..334d792 100644 --- a/src/structs.h +++ b/src/structs.h @@ -251,6 +251,7 @@ typedef struct { int itemLimit; int escapeLimit; int waypointLimit; + int rescueLimit; int noMissiles; int noBoost; int noECM; diff --git a/src/system/lookup.c b/src/system/lookup.c index 3edf355..b2810b9 100644 --- a/src/system/lookup.c +++ b/src/system/lookup.c @@ -132,6 +132,7 @@ void initLookups(void) addLookup("CHALLENGE_PLAYER_KILLS", CHALLENGE_PLAYER_KILLS); addLookup("CHALLENGE_DISABLE", CHALLENGE_DISABLE); addLookup("CHALLENGE_ITEMS", CHALLENGE_ITEMS); + addLookup("CHALLENGE_RESCUE", CHALLENGE_RESCUE); addLookup("STAT_PERCENT_COMPLETE", STAT_PERCENT_COMPLETE); addLookup("STAT_MISSIONS_STARTED", STAT_MISSIONS_STARTED);