Added item collection challenges.

This commit is contained in:
Steve 2016-03-07 12:29:23 +00:00
parent f6239903f7
commit 4a52bb1fce
7 changed files with 40 additions and 3 deletions

View File

@ -392,12 +392,12 @@ static void drawNumFighters(void)
/* Allies */
SDL_SetTextureColorMod(smallFighter, 150, 200, 255);
blit(smallFighter, 400, 15, 0);
drawText(425, 11, 14, TA_LEFT, colors.white, "(%d)", battle.numAllies);
drawText(425, 11, 14, TA_LEFT, colors.white, battle.numAllies < 1000 ? "(%d)" : "(999+)", battle.numAllies);
/* Enemies */
SDL_SetTextureColorMod(smallFighter, 255, 100, 100);
blit(smallFighter, SCREEN_WIDTH - 410, 15, 0);
drawText(SCREEN_WIDTH - 420, 11, 14, TA_RIGHT, colors.white, "(%d)", battle.numEnemies);
drawText(SCREEN_WIDTH - 420, 11, 14, TA_RIGHT, colors.white, battle.numEnemies < 1000 ? "(%d)" : "(999+)", battle.numEnemies);
}
static void drawObjectives(void)
@ -411,6 +411,11 @@ static void drawObjectives(void)
if (game.currentMission->challengeData.timeLimit)
{
drawText(SCREEN_WIDTH / 2, 10, 16, TA_CENTER, colors.white, timeToString(game.currentMission->challengeData.timeLimit - battle.stats[STAT_TIME], 0));
if (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
{

View File

@ -114,6 +114,10 @@ static void action(void)
if (e == player)
{
addHudMessage(colors.white, _("Picked up %s"), self->name);
battle.stats[STAT_ITEMS_COLLECTED_PLAYER]++;
}
else
{
battle.stats[STAT_ITEMS_COLLECTED]++;
}

View File

@ -26,6 +26,7 @@ static void updateArmourChallenge(Challenge *c);
static void updateLossesChallenge(Challenge *c);
static void updatePlayerKillsChallenge(Challenge *c);
static void updateDisabledChallenge(Challenge *c);
static void updateItemsChallenge(Challenge *c);
static void completeChallenge(void);
static void failChallenge(void);
static void updateChallenges(void);
@ -55,6 +56,7 @@ void initChallenges(void)
challengeDescription[CHALLENGE_LOSSES] = _("Do not lose more than %d team mates");
challengeDescription[CHALLENGE_PLAYER_KILLS] = _("Take down %d enemy targets");
challengeDescription[CHALLENGE_DISABLE] = _("Disable %d or more enemy fighters");
challengeDescription[CHALLENGE_ITEMS] = _("Collect %d packages");
tail = &game.challengeMissionHead;
@ -117,7 +119,12 @@ static int challengeFinished(void)
return 1;
}
if (game.currentMission->challengeData.itemLimit > 0 && battle.stats[STAT_ITEMS_COLLECTED] >= game.currentMission->challengeData.itemLimit)
if (game.currentMission->challengeData.itemLimit > 0 && battle.stats[STAT_ITEMS_COLLECTED] + battle.stats[STAT_ITEMS_COLLECTED_PLAYER] >= game.currentMission->challengeData.itemLimit)
{
return 1;
}
if (game.currentMission->challengeData.scriptedEnd)
{
return 1;
}
@ -167,6 +174,10 @@ static void updateChallenges(void)
case CHALLENGE_DISABLE:
updateDisabledChallenge(c);
break;
case CHALLENGE_ITEMS:
updateItemsChallenge(c);
break;
}
}
}
@ -272,6 +283,14 @@ static void updateDisabledChallenge(Challenge *c)
}
}
static void updateItemsChallenge(Challenge *c)
{
if (!c->passed)
{
c->passed = battle.stats[STAT_ITEMS_COLLECTED] + battle.stats[STAT_ITEMS_COLLECTED_PLAYER] >= c->value;
}
}
char *getChallengeDescription(Challenge *c)
{
return getFormattedChallengeDescription(challengeDescription[c->type], c->value);

View File

@ -288,6 +288,7 @@ enum
CHALLENGE_LOSSES,
CHALLENGE_PLAYER_KILLS,
CHALLENGE_DISABLE,
CHALLENGE_ITEMS,
CHALLENGE_MAX
};
@ -323,6 +324,7 @@ enum
STAT_SHUTTLE,
STAT_NUM_TOWED,
STAT_ITEMS_COLLECTED,
STAT_ITEMS_COLLECTED_PLAYER,
STAT_WAYPOINTS_VISITED,
STAT_EPIC_KILL_STREAK,
STAT_CAPITAL_SHIPS_DESTROYED,

View File

@ -77,10 +77,14 @@ Mission *loadMissionMeta(char *filename)
{
mission->challengeData.isChallenge = 1;
/* limits */
mission->challengeData.timeLimit = getJSONValue(node, "timeLimit", 0) * FPS;
mission->challengeData.killLimit = getJSONValue(node, "killLimit", 0);
mission->challengeData.escapeLimit = getJSONValue(node, "escapeLimit", 0);
mission->challengeData.waypointLimit = getJSONValue(node, "waypointLimit", 0);
mission->challengeData.itemLimit = getJSONValue(node, "itemLimit", 0);
/* restrictions */
mission->challengeData.noMissiles = getJSONValue(node, "noMissiles", 0);
mission->challengeData.noECM = getJSONValue(node, "noECM", 0);
mission->challengeData.noBoost = getJSONValue(node, "noBoost", 0);

View File

@ -63,6 +63,7 @@ void initStats(void)
statDescription[STAT_SHUTTLE] = _("Times used Shuttle");
statDescription[STAT_NUM_TOWED] = _("Craft Towed");
statDescription[STAT_ITEMS_COLLECTED] = _("Items Collected");
statDescription[STAT_ITEMS_COLLECTED_PLAYER] = _("Items Collected (Player)");
statDescription[STAT_EPIC_KILL_STREAK] = _("Longest Epic Kill Streak");
statDescription[STAT_WAYPOINTS_VISITED] = _("Waypoints Visited");
statDescription[STAT_CAPITAL_SHIPS_DESTROYED] = _("Capital Ships Destroyed");

View File

@ -130,6 +130,7 @@ void initLookups(void)
addLookup("CHALLENGE_LOSSES", CHALLENGE_LOSSES);
addLookup("CHALLENGE_PLAYER_KILLS", CHALLENGE_PLAYER_KILLS);
addLookup("CHALLENGE_DISABLE", CHALLENGE_DISABLE);
addLookup("CHALLENGE_ITEMS", CHALLENGE_ITEMS);
addLookup("STAT_PERCENT_COMPLETE", STAT_PERCENT_COMPLETE);
addLookup("STAT_MISSIONS_STARTED", STAT_MISSIONS_STARTED);
@ -161,6 +162,7 @@ void initLookups(void)
addLookup("STAT_SHUTTLE", STAT_SHUTTLE);
addLookup("STAT_NUM_TOWED", STAT_NUM_TOWED);
addLookup("STAT_ITEMS_COLLECTED", STAT_ITEMS_COLLECTED);
addLookup("STAT_ITEMS_COLLECTED_PLAYER", STAT_ITEMS_COLLECTED_PLAYER);
addLookup("STAT_WAYPOINTS_VISITED", STAT_WAYPOINTS_VISITED);
addLookup("STAT_EPIC_KILL_STREAK", STAT_EPIC_KILL_STREAK);
addLookup("STAT_CAPITAL_SHIPS_DESTROYED", STAT_CAPITAL_SHIPS_DESTROYED);