Challenge processing fixes.

This commit is contained in:
Steve 2016-03-03 07:44:04 +00:00
parent cb34b3b9b6
commit 11d5ed635f
5 changed files with 24 additions and 15 deletions

View File

@ -167,7 +167,7 @@ static void drawChallenges(void)
for (i = 0 ; i < MAX_CHALLENGES ; i++) for (i = 0 ; i < MAX_CHALLENGES ; i++)
{ {
c = mission->challengeData.challenges[i]; c = game.currentMission->challengeData.challenges[i];
y += 50; y += 50;

View File

@ -327,7 +327,7 @@ static void drawChallenges(void)
r.y -= 50; r.y -= 50;
c = game.currentMission->challengeData.challenges[0]; c = game.currentMission->challengeData.challenges[0];
drawText((SCREEN_WIDTH / 2) - 25, SCREEN_HEIGHT - r.y, 18, TA_RIGHT, colors.white, _("Craft: %s"), game.currentMission->craft); drawText((SCREEN_WIDTH / 2) - 25, SCREEN_HEIGHT - r.y, 18, TA_RIGHT, colors.white, _("Craft: %s"), game.currentMission->craft);
drawText((SCREEN_WIDTH / 2) + 25, SCREEN_HEIGHT - r.y, 18, TA_LEFT, c ? colors.green : colors.white, "1. %s", getChallengeDescription(c)); drawText((SCREEN_WIDTH / 2) + 25, SCREEN_HEIGHT - r.y, 18, TA_LEFT, (c->passed) ? colors.green : colors.white, "1. %s", getChallengeDescription(c));
r.y -= 30; r.y -= 30;
drawText((SCREEN_WIDTH / 2) - 25, SCREEN_HEIGHT - r.y, 18, TA_RIGHT, colors.white, _("Time Limit: %s"), timeLimit); drawText((SCREEN_WIDTH / 2) - 25, SCREEN_HEIGHT - r.y, 18, TA_RIGHT, colors.white, _("Time Limit: %s"), timeLimit);
@ -344,7 +344,7 @@ static void drawChallenges(void)
c = game.currentMission->challengeData.challenges[2]; c = game.currentMission->challengeData.challenges[2];
if (c) if (c)
{ {
drawText((SCREEN_WIDTH / 2) + 25, SCREEN_HEIGHT - r.y, 18, TA_LEFT, (c) ? colors.green : colors.white, "3. %s", getChallengeDescription(c)); drawText((SCREEN_WIDTH / 2) + 25, SCREEN_HEIGHT - r.y, 18, TA_LEFT, (c->passed) ? colors.green : colors.white, "3. %s", getChallengeDescription(c));
} }
} }
} }

View File

@ -99,7 +99,7 @@ static void updateChallenges(void)
for (i = 0 ; i < MAX_CHALLENGES ; i++) for (i = 0 ; i < MAX_CHALLENGES ; i++)
{ {
c = mission->challengeData.challenges[i]; c = game.currentMission->challengeData.challenges[i];
if (!c->passed) if (!c->passed)
{ {
@ -159,6 +159,8 @@ static void printStats(void)
} }
} }
} }
printf("DEBUG: Accuracy=%d\n", getPercent(battle.stats[STAT_SHOTS_FIRED], battle.stats[STAT_SHOTS_HIT]));
} }
static void updateTimeChallenge(Challenge *c) static void updateTimeChallenge(Challenge *c)
@ -281,8 +283,10 @@ void updateChallengeMissions(void)
for (i = 0 ; i < MAX_CHALLENGES ; i++) for (i = 0 ; i < MAX_CHALLENGES ; i++)
{ {
c = mission->challengeData.challenges[i]; c = m->challengeData.challenges[i];
if (c)
{
m->totalChallenges++; m->totalChallenges++;
if (c->passed) if (c->passed)
@ -291,6 +295,7 @@ void updateChallengeMissions(void)
} }
} }
} }
}
} }
static void completeChallenge(void) static void completeChallenge(void)

View File

@ -29,6 +29,7 @@ extern char *getTranslatedString(char *string);
extern char *getFileLocation(char *filename); extern char *getFileLocation(char *filename);
extern char *getLookupName(char *prefix, long num); extern char *getLookupName(char *prefix, long num);
extern char *timeToString(long millis, int showHours); extern char *timeToString(long millis, int showHours);
extern int getPercent(float current, float total);
extern Dev dev; extern Dev dev;
extern Battle battle; extern Battle battle;

View File

@ -114,6 +114,8 @@ static void saveChallenges(cJSON *gameJSON)
{ {
c = mission->challengeData.challenges[i]; c = mission->challengeData.challenges[i];
if (c)
{
challengeJSON = cJSON_CreateObject(); challengeJSON = cJSON_CreateObject();
cJSON_AddStringToObject(challengeJSON, "type", getLookupName("CHALLENGE_", c->type)); cJSON_AddStringToObject(challengeJSON, "type", getLookupName("CHALLENGE_", c->type));
cJSON_AddNumberToObject(challengeJSON, "value", c->value); cJSON_AddNumberToObject(challengeJSON, "value", c->value);
@ -121,6 +123,7 @@ static void saveChallenges(cJSON *gameJSON)
cJSON_AddItemToArray(challengesJSON, challengeJSON); cJSON_AddItemToArray(challengesJSON, challengeJSON);
} }
}
cJSON_AddItemToObject(missionJSON, "challenges", challengesJSON); cJSON_AddItemToObject(missionJSON, "challenges", challengesJSON);