diff --git a/src/battle/hud.c b/src/battle/hud.c index a551d9f..40371cc 100644 --- a/src/battle/hud.c +++ b/src/battle/hud.c @@ -45,7 +45,7 @@ static SDL_Texture *ecm; static SDL_Texture *boost; static SDL_Texture *nextGun; static int numMessages; -static char *gunName[BT_MAX]; +static const char *gunName[BT_MAX]; void initHud(void) { diff --git a/src/challenges/challenges.c b/src/challenges/challenges.c index d400534..93a2238 100644 --- a/src/challenges/challenges.c +++ b/src/challenges/challenges.c @@ -33,18 +33,7 @@ static char *getFormattedChallengeDescription(const char *format, ...); char *getChallengeDescription(Challenge *c); static char descriptionBuffer[MAX_DESCRIPTION_LENGTH]; - -static char *challengeDescription[] = { - "Retain at least %d%% armour", - "Complete challenge in %d seconds or less", - "Attain a %d%% hit accuracy", - "Do not lose any team mates", - "Do not lose more than 1 team mate", - "Do not lose more than %d team mates", - "Take down %d enemy targets", - "Disable %d or more enemy fighters", - "Complete challenge in %d minutes or less" -}; +static const char *challengeDescription[CHALLENGE_MAX]; void initChallenges(void) { @@ -53,6 +42,16 @@ void initChallenges(void) char path[MAX_FILENAME_LENGTH]; int count, i; + 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_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"); + challengeDescription[CHALLENGE_PLAYER_KILLS] = _("Take down %d enemy targets"); + challengeDescription[CHALLENGE_DISABLE] = _("Disable %d or more enemy fighters"); + challengeDescription[CHALLENGE_TIME_MINS] = _("Complete challenge in %d minutes or less"); + tail = &game.challengeMissionHead; filenames = getFileList("data/challenges", &count); @@ -238,6 +237,27 @@ static char *getFormattedChallengeDescription(const char *format, ...) return descriptionBuffer; } +void updateChallengeMissions(void) +{ + Mission *m; + Challenge *c; + + for (m = game.challengeMissionHead.next ; m != NULL ; m = m->next) + { + m->totalChallenges = m->completedChallenges = 0; + + for (c = m->challengeHead.next ; c != NULL ; c = c->next) + { + m->totalChallenges++; + + if (c->passed) + { + m->completedChallenges++; + } + } + } +} + static void completeChallenge(void) { if (battle.status == MS_IN_PROGRESS) diff --git a/src/challenges/challenges.h b/src/challenges/challenges.h index 4a10d67..5e46595 100644 --- a/src/challenges/challenges.h +++ b/src/challenges/challenges.h @@ -25,6 +25,7 @@ extern char **getFileList(char *dir, int *count); extern void selectWidget(const char *name, const char *group); extern void retreatAllies(void); extern void retreatEnemies(void); +extern char *getTranslatedString(char *string); extern Battle battle; extern Entity *player; diff --git a/src/galaxy/stats.c b/src/galaxy/stats.c index b864ad4..a3deb71 100644 --- a/src/galaxy/stats.c +++ b/src/galaxy/stats.c @@ -22,43 +22,50 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static void prevPage(void); static void nextPage(void); +static void calculatePercentComplete(void); -static char *statDescription[] = { - "Missions Started", - "Missons Completed", - "Shots Fired", - "Shots Hit", - "Rockets Fired", - "Rockets Hit", - "Missiles Fired", - "Missiles Hit", - "Enemies Killed", - "Enemies Killed (Player)", - "Allies Killed", - "Times Killed", - "Enemies Disabled", - "Enemies Escaped", - "ECM Used", - "Boost Used", - "Missiles Evaded", - "Missiles Struck Player", - "Civilians Rescued", - "Civilians Killed", - "Times used Tug", - "Times used Shuttle", - "Craft Towed", - "Items Collected", - "Longest Epic Kill Streak", - "Capital Ships Destroyed", - "Capital Ships Lost", - "STAT_TIME" -}; +static char *statDescription[STAT_MAX]; static int page; static int maxPages; static Widget *prev; static Widget *next; +void initStats(void) +{ + statDescription[STAT_PERCENT_COMPLETE] = _("Percent Complete"); + statDescription[STAT_MISSIONS_STARTED] = _("Missions Started"); + statDescription[STAT_MISSIONS_COMPLETED] = _("Missons Completed"); + statDescription[STAT_CHALLENGES_STARTED] = _("Challenges Started"); + statDescription[STAT_CHALLENGES_COMPLETED] = _("Challenges Completed"); + statDescription[STAT_SHOTS_FIRED] = _("Shots Fired"); + statDescription[STAT_SHOTS_HIT] = _("Shots Hit"); + statDescription[STAT_ROCKETS_FIRED] = _("Rockets Fired"); + statDescription[STAT_ROCKETS_HIT] = _("Rockets Hit"); + statDescription[STAT_MISSILES_FIRED] = _("Missiles Fired"); + statDescription[STAT_MISSILES_HIT] = _("Missiles Hit"); + statDescription[STAT_ENEMIES_KILLED] = _("Enemies Killed"); + statDescription[STAT_ENEMIES_KILLED_PLAYER] = _("Enemies Killed (Player)"); + statDescription[STAT_ALLIES_KILLED] = _("Allies Killed"); + statDescription[STAT_PLAYER_KILLED] = _("Times Killed"); + statDescription[STAT_ENEMIES_DISABLED] = _("Enemies Disabled"); + statDescription[STAT_ENEMIES_ESCAPED] = _("Enemies Escaped"); + statDescription[STAT_ECM] = _("ECM Used"); + statDescription[STAT_BOOST] = _("Boost Used"); + statDescription[STAT_MISSILES_EVADED] = _("Missiles Evaded"); + statDescription[STAT_MISSILES_STRUCK] = _("Missiles Struck Player"); + statDescription[STAT_CIVILIANS_RESCUED] = _("Civilians Rescued"); + statDescription[STAT_CIVILIANS_KILLED] = _("Civilians Killed"); + statDescription[STAT_TUG] = _("Times used Tug"); + statDescription[STAT_SHUTTLE] = _("Times used Shuttle"); + statDescription[STAT_NUM_TOWED] = _("Craft Towed"); + statDescription[STAT_ITEMS_COLLECTED] = _("Items Collected"); + statDescription[STAT_EPIC_KILL_STREAK] = _("Longest Epic Kill Streak"); + statDescription[STAT_CAPITAL_SHIPS_DESTROYED] = _("Capital Ships Destroyed"); + statDescription[STAT_CAPITAL_SHIPS_LOST] = _("Capital Ships Lost"); + statDescription[STAT_TIME] = _("Time Played"); +} + void initStatsDisplay(void) { page = 0; @@ -70,6 +77,34 @@ void initStatsDisplay(void) next = getWidget("next", "stats"); next->action = nextPage; + + calculatePercentComplete(); +} + +static void calculatePercentComplete(void) +{ + StarSystem *starSystem; + Mission *mission; + int completed, total; + + completed = total = 0; + + for (starSystem = game.starSystemHead.next ; starSystem != NULL ; starSystem = starSystem->next) + { + if (strcmp(starSystem->name, "Sol")) + { + completed += starSystem->completedMissions; + total += starSystem->totalMissions; + } + } + + for (mission = game.challengeMissionHead.next ; mission != NULL ; mission = mission->next) + { + completed += mission->completedChallenges; + total += mission->totalChallenges; + } + + game.stats[STAT_PERCENT_COMPLETE] = getPercent(completed, total); } void drawStats(void) @@ -105,12 +140,21 @@ void drawStats(void) if (i < STAT_TIME) { drawText(r.x + 20, y, 18, TA_LEFT, colors.white, statDescription[i]); - drawText(r.x + r.w - 20, y, 18, TA_RIGHT, colors.white, "%d", game.stats[i]); + + if (i == STAT_PERCENT_COMPLETE) + { + 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]); + } + y += 40; } } - drawText(r.x + 20, 565, 18, TA_LEFT, colors.white, _("Time Played")); + drawText(r.x + 20, 565, 18, TA_LEFT, colors.white, statDescription[STAT_TIME]); drawText(r.x + r.w - 20, 565, 18, TA_RIGHT, colors.white, timeToString(game.stats[STAT_TIME], 1)); drawWidgets("stats"); diff --git a/src/galaxy/stats.h b/src/galaxy/stats.h index 21013fb..4a06f77 100644 --- a/src/galaxy/stats.h +++ b/src/galaxy/stats.h @@ -27,6 +27,7 @@ extern void drawText(int x, int y, int size, int align, SDL_Color c, const char extern Widget *getWidget(const char *name, const char *group); extern char *getTranslatedString(char *string); extern char *timeToString(long millis, int showHours); +extern int getPercent(float current, float total); extern App app; extern Colors colors; diff --git a/src/system/init.c b/src/system/init.c index 822613b..c1bf5c9 100644 --- a/src/system/init.c +++ b/src/system/init.c @@ -117,7 +117,7 @@ void initSDL(void) void initGameSystem(void) { int step = 0; - int STEPS = 14; + int STEPS = 16; initColor(&colors.red, 255, 0, 0); initColor(&colors.orange, 255, 128, 0); @@ -181,6 +181,10 @@ void initGameSystem(void) showLoadingStep(step++, STEPS); + initStats(); + + showLoadingStep(step++, STEPS); + initBattle(); showLoadingStep(step++, STEPS); diff --git a/src/system/init.h b/src/system/init.h index d793fdd..fe79f25 100644 --- a/src/system/init.h +++ b/src/system/init.h @@ -43,6 +43,7 @@ extern void initBulletDefs(void); extern void initLookups(void); extern void initBattle(void); extern void initGame(void); +extern void initStats(void); extern void initStarSystems(void); extern void initChallenges(void); extern void initWidgets(void);