Add Surrender challenge type.

This commit is contained in:
Steve 2016-05-25 12:25:13 +01:00
parent 274697caa5
commit 197e630fee
5 changed files with 27 additions and 0 deletions

View File

@ -472,6 +472,10 @@ static void drawObjectives(void)
{
drawText(SCREEN_WIDTH / 2, 35, 14, TA_CENTER, colors.white, "%d / %d", battle.stats[STAT_ENEMIES_DISABLED], game.currentMission->challengeData.disableLimit);
}
else if (game.currentMission->challengeData.surrenderLimit)
{
drawText(SCREEN_WIDTH / 2, 35, 14, TA_CENTER, colors.white, "%d / %d", battle.stats[STAT_ENEMIES_SURRENDERED], game.currentMission->challengeData.surrenderLimit);
}
else if (player->flags & EF_MUST_DISABLE)
{
drawText(SCREEN_WIDTH / 2, 35, 14, TA_CENTER, colors.white, _("System Power : %d%%"), player->systemPower);

View File

@ -28,6 +28,7 @@ static void updateLossesChallenge(Challenge *c);
static void updatePlayerKillsChallenge(Challenge *c);
static void updateDisabledChallenge(Challenge *c);
static void updateItemsChallenge(Challenge *c);
static void updateSurrenderChallenge(Challenge *c);
static void completeChallenge(void);
static void failChallenge(void);
static int updateChallenges(void);
@ -61,6 +62,7 @@ void initChallenges(void)
challengeDescription[CHALLENGE_ITEMS] = _("Collect %d packages");
challengeDescription[CHALLENGE_PLAYER_ITEMS] = _("Collect %d packages");
challengeDescription[CHALLENGE_RESCUE] = _("Rescue %d civilians");
challengeDescription[CHALLENGE_SURRENDER] = _("Cause %d enemies to surrender");
tail = &game.challengeMissionHead;
@ -100,6 +102,7 @@ void loadChallenge(Mission *mission, cJSON *node)
mission->challengeData.playerItemLimit = getJSONValue(node, "playerItemLimit", 0);
mission->challengeData.rescueLimit = getJSONValue(node, "rescueLimit", 0);
mission->challengeData.disableLimit = getJSONValue(node, "disableLimit", 0);
mission->challengeData.surrenderLimit = getJSONValue(node, "surrenderLimit", 0);
/* restrictions */
mission->challengeData.noMissiles = getJSONValue(node, "noMissiles", 0);
@ -208,6 +211,11 @@ static int challengeFinished(void)
return 1;
}
if (game.currentMission->challengeData.surrenderLimit > 0 && (battle.stats[STAT_ENEMIES_KILLED_PLAYER] + battle.stats[STAT_ENEMIES_SURRENDERED] + battle.stats[STAT_ENEMIES_DISABLED]) >= game.currentMission->challengeData.surrenderLimit)
{
return 1;
}
if (game.currentMission->challengeData.eliminateThreats && !battle.hasThreats)
{
return 1;
@ -271,6 +279,10 @@ static int updateChallenges(void)
case CHALLENGE_PLAYER_ITEMS:
updateItemsChallenge(c);
break;
case CHALLENGE_SURRENDER:
updateSurrenderChallenge(c);
break;
}
}
@ -407,6 +419,14 @@ static void updateItemsChallenge(Challenge *c)
}
}
static void updateSurrenderChallenge(Challenge *c)
{
if (!c->passed)
{
c->passed = battle.stats[STAT_ENEMIES_SURRENDERED] >= c->value;
}
}
char *getChallengeDescription(Challenge *c)
{
if (c->type == CHALLENGE_TIME)

View File

@ -338,6 +338,7 @@ enum
CHALLENGE_PLAYER_ITEMS,
CHALLENGE_RESCUE,
CHALLENGE_SURVIVE,
CHALLENGE_SURRENDER,
CHALLENGE_MAX
};

View File

@ -259,6 +259,7 @@ typedef struct {
int waypointLimit;
int rescueLimit;
int disableLimit;
int surrenderLimit;
int noMissiles;
int noBoost;
int noECM;

View File

@ -157,6 +157,7 @@ void initLookups(void)
addLookup("CHALLENGE_ITEMS", CHALLENGE_ITEMS);
addLookup("CHALLENGE_PLAYER_ITEMS", CHALLENGE_PLAYER_ITEMS);
addLookup("CHALLENGE_RESCUE", CHALLENGE_RESCUE);
addLookup("CHALLENGE_SURRENDER", CHALLENGE_SURRENDER);
addLookup("STAT_PERCENT_COMPLETE", STAT_PERCENT_COMPLETE);
addLookup("STAT_MISSIONS_STARTED", STAT_MISSIONS_STARTED);