diff --git a/src/battle/missionInfo.c b/src/battle/missionInfo.c index 36e4043..9dccda2 100644 --- a/src/battle/missionInfo.c +++ b/src/battle/missionInfo.c @@ -167,7 +167,7 @@ static void drawChallenges(void) for (i = 0 ; i < MAX_CHALLENGES ; i++) { - c = mission->challengeData.challenges[i]; + c = game.currentMission->challengeData.challenges[i]; y += 50; diff --git a/src/challenges/challengeHome.c b/src/challenges/challengeHome.c index 18f7b70..6f8fab1 100644 --- a/src/challenges/challengeHome.c +++ b/src/challenges/challengeHome.c @@ -327,7 +327,7 @@ static void drawChallenges(void) r.y -= 50; 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_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; 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]; 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)); } } } diff --git a/src/challenges/challenges.c b/src/challenges/challenges.c index 8f79fdf..7f9d63c 100644 --- a/src/challenges/challenges.c +++ b/src/challenges/challenges.c @@ -99,7 +99,7 @@ static void updateChallenges(void) for (i = 0 ; i < MAX_CHALLENGES ; i++) { - c = mission->challengeData.challenges[i]; + c = game.currentMission->challengeData.challenges[i]; 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) @@ -281,13 +283,16 @@ void updateChallengeMissions(void) for (i = 0 ; i < MAX_CHALLENGES ; i++) { - c = mission->challengeData.challenges[i]; + c = m->challengeData.challenges[i]; - m->totalChallenges++; - - if (c->passed) + if (c) { - m->completedChallenges++; + m->totalChallenges++; + + if (c->passed) + { + m->completedChallenges++; + } } } } diff --git a/src/challenges/challenges.h b/src/challenges/challenges.h index 5211c9d..92a1fb6 100644 --- a/src/challenges/challenges.h +++ b/src/challenges/challenges.h @@ -29,6 +29,7 @@ extern char *getTranslatedString(char *string); extern char *getFileLocation(char *filename); extern char *getLookupName(char *prefix, long num); extern char *timeToString(long millis, int showHours); +extern int getPercent(float current, float total); extern Dev dev; extern Battle battle; diff --git a/src/system/save.c b/src/system/save.c index 46afb55..626a6ca 100644 --- a/src/system/save.c +++ b/src/system/save.c @@ -114,12 +114,15 @@ static void saveChallenges(cJSON *gameJSON) { c = mission->challengeData.challenges[i]; - challengeJSON = cJSON_CreateObject(); - cJSON_AddStringToObject(challengeJSON, "type", getLookupName("CHALLENGE_", c->type)); - cJSON_AddNumberToObject(challengeJSON, "value", c->value); - cJSON_AddNumberToObject(challengeJSON, "passed", c->passed); - - cJSON_AddItemToArray(challengesJSON, challengeJSON); + if (c) + { + challengeJSON = cJSON_CreateObject(); + cJSON_AddStringToObject(challengeJSON, "type", getLookupName("CHALLENGE_", c->type)); + cJSON_AddNumberToObject(challengeJSON, "value", c->value); + cJSON_AddNumberToObject(challengeJSON, "passed", c->passed); + + cJSON_AddItemToArray(challengesJSON, challengeJSON); + } } cJSON_AddItemToObject(missionJSON, "challenges", challengesJSON);