Added rescue challenges

This commit is contained in:
Steve 2016-03-11 23:45:47 +00:00
parent 3bd78dbd20
commit 4f27b40d97
7 changed files with 15 additions and 35 deletions

View File

@ -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); 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 else
{ {

View File

@ -57,6 +57,7 @@ void initChallenges(void)
challengeDescription[CHALLENGE_PLAYER_KILLS] = _("Take down %d enemy targets"); challengeDescription[CHALLENGE_PLAYER_KILLS] = _("Take down %d enemy targets");
challengeDescription[CHALLENGE_DISABLE] = _("Disable %d or more enemy fighters"); challengeDescription[CHALLENGE_DISABLE] = _("Disable %d or more enemy fighters");
challengeDescription[CHALLENGE_ITEMS] = _("Collect %d packages"); challengeDescription[CHALLENGE_ITEMS] = _("Collect %d packages");
challengeDescription[CHALLENGE_RESCUE] = _("Rescue %d civilians");
tail = &game.challengeMissionHead; tail = &game.challengeMissionHead;
@ -128,6 +129,11 @@ static int challengeFinished(void)
return 1; 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) if (game.currentMission->challengeData.scriptedEnd)
{ {
return 1; return 1;

View File

@ -292,6 +292,7 @@ enum
CHALLENGE_PLAYER_KILLS, CHALLENGE_PLAYER_KILLS,
CHALLENGE_DISABLE, CHALLENGE_DISABLE,
CHALLENGE_ITEMS, CHALLENGE_ITEMS,
CHALLENGE_RESCUE,
CHALLENGE_MAX CHALLENGE_MAX
}; };

View File

@ -28,7 +28,6 @@ static void loadEntities(cJSON *node);
static void loadItems(cJSON *node); static void loadItems(cJSON *node);
static void loadLocations(cJSON *node); static void loadLocations(cJSON *node);
static unsigned long hashcode(const char *str); static unsigned long hashcode(const char *str);
static char **toTypeArray(char *types, int *numTypes);
static void loadEpicData(cJSON *node); static void loadEpicData(cJSON *node);
static char *getAutoBackground(char *filename); static char *getAutoBackground(char *filename);
static char *getAutoPlanet(char *filename); static char *getAutoPlanet(char *filename);
@ -87,6 +86,7 @@ Mission *loadMissionMeta(char *filename)
mission->challengeData.escapeLimit = getJSONValue(node, "escapeLimit", 0); mission->challengeData.escapeLimit = getJSONValue(node, "escapeLimit", 0);
mission->challengeData.waypointLimit = getJSONValue(node, "waypointLimit", 0); mission->challengeData.waypointLimit = getJSONValue(node, "waypointLimit", 0);
mission->challengeData.itemLimit = getJSONValue(node, "itemLimit", 0); mission->challengeData.itemLimit = getJSONValue(node, "itemLimit", 0);
mission->challengeData.rescueLimit = getJSONValue(node, "rescueLimit", 0);
/* restrictions */ /* restrictions */
mission->challengeData.noMissiles = getJSONValue(node, "noMissiles", 0); mission->challengeData.noMissiles = getJSONValue(node, "noMissiles", 0);
@ -198,8 +198,6 @@ void loadMission(char *filename)
srand(time(NULL)); srand(time(NULL));
cJSON_Delete(root);
free(text); free(text);
endSectionTransition(); endSectionTransition();
@ -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) static void loadEpicData(cJSON *node)
{ {
Entity *e; Entity *e;

View File

@ -55,6 +55,7 @@ extern char *getMusicFilename(int n);
extern int getJSONValue(cJSON *node, char *name, int defValue); extern int getJSONValue(cJSON *node, char *name, int defValue);
extern char *getJSONValueStr(cJSON *node, char *name, char *defValue); extern char *getJSONValueStr(cJSON *node, char *name, char *defValue);
extern void addAllEntsToQuadtree(void); extern void addAllEntsToQuadtree(void);
extern char **toTypeArray(char *types, int *numTypes);
extern Battle battle; extern Battle battle;
extern Entity *player; extern Entity *player;

View File

@ -251,6 +251,7 @@ typedef struct {
int itemLimit; int itemLimit;
int escapeLimit; int escapeLimit;
int waypointLimit; int waypointLimit;
int rescueLimit;
int noMissiles; int noMissiles;
int noBoost; int noBoost;
int noECM; int noECM;

View File

@ -132,6 +132,7 @@ void initLookups(void)
addLookup("CHALLENGE_PLAYER_KILLS", CHALLENGE_PLAYER_KILLS); addLookup("CHALLENGE_PLAYER_KILLS", CHALLENGE_PLAYER_KILLS);
addLookup("CHALLENGE_DISABLE", CHALLENGE_DISABLE); addLookup("CHALLENGE_DISABLE", CHALLENGE_DISABLE);
addLookup("CHALLENGE_ITEMS", CHALLENGE_ITEMS); addLookup("CHALLENGE_ITEMS", CHALLENGE_ITEMS);
addLookup("CHALLENGE_RESCUE", CHALLENGE_RESCUE);
addLookup("STAT_PERCENT_COMPLETE", STAT_PERCENT_COMPLETE); addLookup("STAT_PERCENT_COMPLETE", STAT_PERCENT_COMPLETE);
addLookup("STAT_MISSIONS_STARTED", STAT_MISSIONS_STARTED); addLookup("STAT_MISSIONS_STARTED", STAT_MISSIONS_STARTED);