From d5d516907890f006e870bf4586932dba0f254bef Mon Sep 17 00:00:00 2001 From: Steve Date: Thu, 3 Mar 2016 09:12:08 +0000 Subject: [PATCH] Accuracy for rockets and missiles, not just shots. --- data/challenges/04.json | 2 +- src/battle/battle.c | 2 ++ src/battle/battle.h | 1 + src/battle/missionInfo.c | 37 ++++++++++++++++++++----------------- src/challenges/challenges.c | 35 +++++++++++++++++++++++++++-------- src/challenges/challenges.h | 1 + src/defs.h | 7 ++++++- src/galaxy/stats.c | 31 ++++++++++++++++++++++++------- src/system/lookup.c | 7 ++++++- 9 files changed, 88 insertions(+), 35 deletions(-) diff --git a/data/challenges/04.json b/data/challenges/04.json index be4c3ba..81f74f0 100644 --- a/data/challenges/04.json +++ b/data/challenges/04.json @@ -25,7 +25,7 @@ "value" : 120 }, { - "type" : "CHALLENGE_ACCURACY", + "type" : "CHALLENGE_SHOT_ACCURACY", "value" : 80 } ] diff --git a/src/battle/battle.c b/src/battle/battle.c index f03b735..4bdec3e 100644 --- a/src/battle/battle.c +++ b/src/battle/battle.c @@ -367,6 +367,8 @@ static void postBattle(void) game.stats[i] += battle.stats[i]; } } + + updateAccuracyStats(game.stats); if (!game.currentMission->challengeData.isChallenge) { diff --git a/src/battle/battle.h b/src/battle/battle.h index b577b71..7a66e43 100644 --- a/src/battle/battle.h +++ b/src/battle/battle.h @@ -82,6 +82,7 @@ extern void destroyDebris(void); extern void destroyBullets(void); extern void destroyEffects(void); extern void initChallengeHome(void); +extern void updateAccuracyStats(unsigned int *stats); extern App app; extern Battle battle; diff --git a/src/battle/missionInfo.c b/src/battle/missionInfo.c index 9dccda2..6be8859 100644 --- a/src/battle/missionInfo.c +++ b/src/battle/missionInfo.c @@ -169,27 +169,30 @@ static void drawChallenges(void) { c = game.currentMission->challengeData.challenges[i]; - y += 50; - - color = colors.white; - - challengeStatus = _("Incomplete"); - - if (c->passed) + if (c) { - color = colors.green; + y += 50; - challengeStatus = _("Complete"); - } - else if (battle.status == MS_COMPLETE ||battle.status == MS_FAILED) - { - color = colors.red; + color = colors.white; - challengeStatus = _("Failed"); + challengeStatus = _("Incomplete"); + + if (c->passed) + { + color = colors.green; + + challengeStatus = _("Complete"); + } + else if (battle.status == MS_COMPLETE ||battle.status == MS_FAILED) + { + color = colors.red; + + challengeStatus = _("Failed"); + } + + drawText(SCREEN_WIDTH / 2 - 50, y, 22, TA_RIGHT, colors.white, "%s", getChallengeDescription(c)); + drawText(SCREEN_WIDTH / 2 + 50, y, 22, TA_LEFT, color, challengeStatus); } - - drawText(SCREEN_WIDTH / 2 - 50, y, 22, TA_RIGHT, colors.white, "%s", getChallengeDescription(c)); - drawText(SCREEN_WIDTH / 2 + 50, y, 22, TA_LEFT, color, challengeStatus); } } diff --git a/src/challenges/challenges.c b/src/challenges/challenges.c index 7f9d63c..9a5650e 100644 --- a/src/challenges/challenges.c +++ b/src/challenges/challenges.c @@ -45,7 +45,9 @@ void initChallenges(void) challengeDescription[CHALLENGE_ARMOUR] = _("Retain at least %d%% armour"); challengeDescription[CHALLENGE_TIME] = _("Complete challenge in %d seconds or less"); - challengeDescription[CHALLENGE_ACCURACY] = _("Attain a %d%% hit accuracy"); + challengeDescription[CHALLENGE_SHOT_ACCURACY] = _("Attain a %d%% shot hit accuracy"); + challengeDescription[CHALLENGE_ROCKET_ACCURACY] = _("Attain a %d%% rocket hit accuracy"); + challengeDescription[CHALLENGE_MISSILE_ACCURACY] = _("Attain a %d%% missile hit accuracy"); challengeDescription[CHALLENGE_NO_LOSSES] = _("Do not lose any team mates"); challengeDescription[CHALLENGE_1_LOSS] = _("Do not lose more than 1 team mate"); challengeDescription[CHALLENGE_LOSSES] = _("Do not lose more than %d team mates"); @@ -97,11 +99,13 @@ static void updateChallenges(void) int i; Challenge *c; + updateAccuracyStats(battle.stats); + for (i = 0 ; i < MAX_CHALLENGES ; i++) { c = game.currentMission->challengeData.challenges[i]; - if (!c->passed) + if (c && !c->passed) { switch (c->type) { @@ -110,7 +114,9 @@ static void updateChallenges(void) updateTimeChallenge(c); break; - case CHALLENGE_ACCURACY: + case CHALLENGE_SHOT_ACCURACY: + case CHALLENGE_ROCKET_ACCURACY: + case CHALLENGE_MISSILE_ACCURACY: updateAccuracyChallenge(c); break; @@ -159,8 +165,6 @@ 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) @@ -187,9 +191,24 @@ static void updateAccuracyChallenge(Challenge *c) { float percent; - percent = battle.stats[STAT_SHOTS_HIT]; - percent /= battle.stats[STAT_SHOTS_FIRED]; - percent *= 100; + switch (c->type) + { + case CHALLENGE_SHOT_ACCURACY: + percent = battle.stats[STAT_SHOT_ACCURACY]; + break; + + case CHALLENGE_ROCKET_ACCURACY: + percent = battle.stats[STAT_ROCKET_ACCURACY]; + break; + + case CHALLENGE_MISSILE_ACCURACY: + percent = battle.stats[STAT_MISSILE_ACCURACY]; + break; + + default: + percent = 0; + break; + } if (percent >= c->value) { diff --git a/src/challenges/challenges.h b/src/challenges/challenges.h index 92a1fb6..1299ddb 100644 --- a/src/challenges/challenges.h +++ b/src/challenges/challenges.h @@ -30,6 +30,7 @@ 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 void updateAccuracyStats(unsigned int *stats); extern Dev dev; extern Battle battle; diff --git a/src/defs.h b/src/defs.h index 685504c..d6de44d 100644 --- a/src/defs.h +++ b/src/defs.h @@ -257,7 +257,9 @@ enum { CHALLENGE_ARMOUR, CHALLENGE_TIME, - CHALLENGE_ACCURACY, + CHALLENGE_SHOT_ACCURACY, + CHALLENGE_ROCKET_ACCURACY, + CHALLENGE_MISSILE_ACCURACY, CHALLENGE_NO_LOSSES, CHALLENGE_1_LOSS, CHALLENGE_LOSSES, @@ -276,10 +278,13 @@ enum STAT_CHALLENGES_COMPLETED, STAT_SHOTS_FIRED, STAT_SHOTS_HIT, + STAT_SHOT_ACCURACY, STAT_ROCKETS_FIRED, STAT_ROCKETS_HIT, + STAT_ROCKET_ACCURACY, STAT_MISSILES_FIRED, STAT_MISSILES_HIT, + STAT_MISSILE_ACCURACY, STAT_ENEMIES_KILLED, STAT_ENEMIES_KILLED_PLAYER, STAT_ALLIES_KILLED, diff --git a/src/galaxy/stats.c b/src/galaxy/stats.c index 796d546..713fdd3 100644 --- a/src/galaxy/stats.c +++ b/src/galaxy/stats.c @@ -23,9 +23,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static void prevPage(void); static void nextPage(void); static void calculatePercentComplete(void); +void updateAccuracyStats(unsigned int *stats); static char *statDescription[STAT_MAX]; - static int page; static float maxPages; static Widget *prev; @@ -40,10 +40,13 @@ void initStats(void) statDescription[STAT_CHALLENGES_COMPLETED] = _("Challenges Completed"); statDescription[STAT_SHOTS_FIRED] = _("Shots Fired"); statDescription[STAT_SHOTS_HIT] = _("Shots Hit"); + statDescription[STAT_SHOT_ACCURACY] = _("Accuracy"); statDescription[STAT_ROCKETS_FIRED] = _("Rockets Fired"); statDescription[STAT_ROCKETS_HIT] = _("Rockets Hit"); + statDescription[STAT_ROCKET_ACCURACY] = _("Accuracy"); statDescription[STAT_MISSILES_FIRED] = _("Missiles Fired"); statDescription[STAT_MISSILES_HIT] = _("Missiles Hit"); + statDescription[STAT_MISSILE_ACCURACY] = _("Accuracy"); statDescription[STAT_ENEMIES_KILLED] = _("Enemies Killed"); statDescription[STAT_ENEMIES_KILLED_PLAYER] = _("Enemies Killed (Player)"); statDescription[STAT_ALLIES_KILLED] = _("Allies Killed"); @@ -82,6 +85,8 @@ void initStatsDisplay(void) next->action = nextPage; calculatePercentComplete(); + + updateAccuracyStats(game.stats); } static void calculatePercentComplete(void) @@ -144,13 +149,18 @@ void drawStats(void) { drawText(r.x + 20, y, 18, TA_LEFT, colors.white, statDescription[i]); - if (i == STAT_PERCENT_COMPLETE) + switch (i) { - drawText(r.x + r.w - 20, y, 18, TA_RIGHT, colors.white, "%d%%", game.stats[i]); - } - else - { - drawText(r.x + r.w - 20, y, 18, TA_RIGHT, colors.white, "%d", game.stats[i]); + case STAT_PERCENT_COMPLETE: + case STAT_SHOT_ACCURACY: + case STAT_ROCKET_ACCURACY: + case STAT_MISSILE_ACCURACY: + drawText(r.x + r.w - 20, y, 18, TA_RIGHT, colors.white, "%d%%", game.stats[i]); + break; + + default: + drawText(r.x + r.w - 20, y, 18, TA_RIGHT, colors.white, "%d", game.stats[i]); + break; } y += 40; @@ -178,3 +188,10 @@ static void prevPage(void) next->visible = 1; prev->visible = page > 0; } + +void updateAccuracyStats(unsigned int *stats) +{ + stats[STAT_SHOT_ACCURACY] = getPercent(stats[STAT_SHOTS_HIT], stats[STAT_SHOTS_FIRED]); + stats[STAT_ROCKET_ACCURACY] = getPercent(stats[STAT_ROCKETS_HIT], stats[STAT_ROCKETS_FIRED]); + stats[STAT_MISSILE_ACCURACY] = getPercent(stats[STAT_MISSILES_HIT], stats[STAT_MISSILES_FIRED]); +} diff --git a/src/system/lookup.c b/src/system/lookup.c index 66c6868..ffc09a8 100644 --- a/src/system/lookup.c +++ b/src/system/lookup.c @@ -108,7 +108,9 @@ void initLookups(void) addLookup("CHALLENGE_ARMOUR", CHALLENGE_ARMOUR); addLookup("CHALLENGE_TIME", CHALLENGE_TIME); - addLookup("CHALLENGE_ACCURACY", CHALLENGE_ACCURACY); + addLookup("CHALLENGE_SHOT_ACCURACY", CHALLENGE_SHOT_ACCURACY); + addLookup("CHALLENGE_ROCKET_ACCURACY", CHALLENGE_ROCKET_ACCURACY); + addLookup("CHALLENGE_MISSILE_ACCURACY", CHALLENGE_MISSILE_ACCURACY); addLookup("CHALLENGE_NO_LOSSES", CHALLENGE_NO_LOSSES); addLookup("CHALLENGE_1_LOSS", CHALLENGE_1_LOSS); addLookup("CHALLENGE_LOSSES", CHALLENGE_LOSSES); @@ -123,10 +125,13 @@ void initLookups(void) addLookup("STAT_CHALLENGES_COMPLETED", STAT_CHALLENGES_COMPLETED); addLookup("STAT_SHOTS_FIRED", STAT_SHOTS_FIRED); addLookup("STAT_SHOTS_HIT", STAT_SHOTS_HIT); + addLookup("STAT_SHOT_ACCURACY", STAT_SHOT_ACCURACY); addLookup("STAT_ROCKETS_FIRED", STAT_ROCKETS_FIRED); addLookup("STAT_ROCKETS_HIT", STAT_ROCKETS_HIT); + addLookup("STAT_ROCKET_ACCURACY", STAT_ROCKET_ACCURACY); addLookup("STAT_MISSILES_FIRED", STAT_MISSILES_FIRED); addLookup("STAT_MISSILES_HIT", STAT_MISSILES_HIT); + addLookup("STAT_MISSILE_ACCURACY", STAT_MISSILE_ACCURACY); addLookup("STAT_ENEMIES_KILLED", STAT_ENEMIES_KILLED); addLookup("STAT_ENEMIES_KILLED_PLAYER", STAT_ENEMIES_KILLED_PLAYER); addLookup("STAT_ALLIES_KILLED", STAT_ALLIES_KILLED);