Challenge completion bug fix.

This commit is contained in:
Steve 2016-04-03 14:04:31 +01:00
parent f6504fc7a1
commit 16a1e1b20a
1 changed files with 50 additions and 36 deletions

View File

@ -29,7 +29,7 @@ static void updateDisabledChallenge(Challenge *c);
static void updateItemsChallenge(Challenge *c); static void updateItemsChallenge(Challenge *c);
static void completeChallenge(void); static void completeChallenge(void);
static void failChallenge(void); static void failChallenge(void);
static void updateChallenges(void); static int updateChallenges(void);
static char *getFormattedChallengeDescription(const char *format, ...); static char *getFormattedChallengeDescription(const char *format, ...);
char *getChallengeDescription(Challenge *c); char *getChallengeDescription(Challenge *c);
static int challengeFinished(void); static int challengeFinished(void);
@ -83,19 +83,21 @@ void initChallenges(void)
void doChallenges(void) void doChallenges(void)
{ {
int passed;
if (game.currentMission->challengeData.isChallenge && battle.status == MS_IN_PROGRESS) if (game.currentMission->challengeData.isChallenge && battle.status == MS_IN_PROGRESS)
{ {
if (challengeFinished()) if (challengeFinished())
{ {
if (game.currentMission->challengeData.timeLimit && battle.stats[STAT_TIME] >= game.currentMission->challengeData.timeLimit) passed = updateChallenges();
if (passed)
{ {
failChallenge(); completeChallenge();
} }
else else
{ {
updateChallenges(); failChallenge();
completeChallenge();
} }
} }
} }
@ -147,52 +149,62 @@ static int challengeFinished(void)
return 0; return 0;
} }
static void updateChallenges(void) static int updateChallenges(void)
{ {
int i; int i, numPassed;
Challenge *c; Challenge *c;
updateAccuracyStats(battle.stats); updateAccuracyStats(battle.stats);
numPassed = 0;
for (i = 0 ; i < MAX_CHALLENGES ; i++) for (i = 0 ; i < MAX_CHALLENGES ; i++)
{ {
c = game.currentMission->challengeData.challenges[i]; c = game.currentMission->challengeData.challenges[i];
if (c && !c->passed) if (c)
{ {
switch (c->type) if (!c->passed)
{ {
case CHALLENGE_TIME: switch (c->type)
updateTimeChallenge(c); {
break; case CHALLENGE_TIME:
updateTimeChallenge(c);
break;
case CHALLENGE_SHOT_ACCURACY: case CHALLENGE_SHOT_ACCURACY:
case CHALLENGE_ROCKET_ACCURACY: case CHALLENGE_ROCKET_ACCURACY:
case CHALLENGE_MISSILE_ACCURACY: case CHALLENGE_MISSILE_ACCURACY:
updateAccuracyChallenge(c); updateAccuracyChallenge(c);
break; break;
case CHALLENGE_ARMOUR: case CHALLENGE_ARMOUR:
updateArmourChallenge(c); updateArmourChallenge(c);
break; break;
case CHALLENGE_NO_LOSSES: case CHALLENGE_NO_LOSSES:
case CHALLENGE_1_LOSS: case CHALLENGE_1_LOSS:
case CHALLENGE_LOSSES: case CHALLENGE_LOSSES:
updateLossesChallenge(c); updateLossesChallenge(c);
break; break;
case CHALLENGE_PLAYER_KILLS: case CHALLENGE_PLAYER_KILLS:
updatePlayerKillsChallenge(c); updatePlayerKillsChallenge(c);
break; break;
case CHALLENGE_DISABLE: case CHALLENGE_DISABLE:
updateDisabledChallenge(c); updateDisabledChallenge(c);
break; break;
case CHALLENGE_ITEMS: case CHALLENGE_ITEMS:
updateItemsChallenge(c); updateItemsChallenge(c);
break; break;
}
}
if (c->passed)
{
numPassed++;
} }
} }
} }
@ -201,6 +213,8 @@ static void updateChallenges(void)
{ {
printStats(); printStats();
} }
return numPassed;
} }
static void printStats(void) static void printStats(void)