From 0a5d2d8cfb920d11f6ad41b7c7f392ed38db9898 Mon Sep 17 00:00:00 2001 From: Steve Date: Fri, 2 Mar 2018 08:09:04 +0000 Subject: [PATCH] Show additional stats. --- src/defs.h | 3 +++ src/game/stats.c | 22 +++++++++++++++++++++- src/game/stats.h | 1 + src/hub/hub.c | 21 ++++++++++----------- src/hub/hub.h | 1 + src/structs.h | 1 + src/system/lookup.c | 3 +++ src/test/atlasTest.c | 4 ++-- src/world/world.c | 1 + src/world/world.h | 1 + 10 files changed, 44 insertions(+), 14 deletions(-) diff --git a/src/defs.h b/src/defs.h index 849b907..a2de553 100644 --- a/src/defs.h +++ b/src/defs.h @@ -339,6 +339,7 @@ enum enum { + STAT_MISSIONS_COMPLETE, STAT_KEYS_FOUND, STAT_CELLS_FOUND, STAT_HEARTS_FOUND, @@ -347,6 +348,7 @@ enum STAT_DEATHS, STAT_SHOTS_FIRED, STAT_SHOTS_HIT, + STAT_SHOT_ACCURACY, STAT_EYE_DROID_EXPLOSION_KILLS, STAT_FLY_TIME, STAT_SWIM_TIME, @@ -355,6 +357,7 @@ enum STAT_WEAPONS_PICKED_UP, STAT_ENEMIES_KILLED, STAT_MISSIONS_PLAYED, + STAT_PERCENT_COMPLETE, STAT_TIME_PLAYED, STAT_MAX }; diff --git a/src/game/stats.c b/src/game/stats.c index b7344e6..4a491c6 100644 --- a/src/game/stats.c +++ b/src/game/stats.c @@ -35,6 +35,7 @@ void initStats(void) maxPages /= STATS_PER_PAGE; maxPages = ceil(maxPages); + statDescription[STAT_MISSIONS_COMPLETE] = _("Missions complete"); statDescription[STAT_KEYS_FOUND] = _("Keys found"); statDescription[STAT_CELLS_FOUND] = _("Power cells found"); statDescription[STAT_HEARTS_FOUND] = _("Hearts found"); @@ -43,7 +44,8 @@ void initStats(void) statDescription[STAT_DEATHS] = _("Deaths"); statDescription[STAT_SHOTS_FIRED] = _("Shots fired"); statDescription[STAT_SHOTS_HIT] = _("Shots hit"); - statDescription[STAT_EYE_DROID_EXPLOSION_KILLS] = _("Eyedroid Explosion kills"); + statDescription[STAT_SHOT_ACCURACY] = _("Accuracy"); + statDescription[STAT_EYE_DROID_EXPLOSION_KILLS] = _("EyeDroid explosion kills"); statDescription[STAT_FLY_TIME] = _("Time spent flying"); statDescription[STAT_SWIM_TIME] = _("Time spent swimming"); statDescription[STAT_CHERRIES_PICKED_UP] = _("Cherries picked up"); @@ -51,6 +53,7 @@ void initStats(void) statDescription[STAT_WEAPONS_PICKED_UP] = _("Weapons picked up"); statDescription[STAT_ENEMIES_KILLED] = _("Enemies killed"); statDescription[STAT_MISSIONS_PLAYED] = _("Missions played"); + statDescription[STAT_PERCENT_COMPLETE] = _("Percent complete"); statDescription[STAT_TIME_PLAYED] = _("Time played"); atlasTexture = getTexture("gfx/atlas/atlas.png"); @@ -58,6 +61,18 @@ void initStats(void) right = getImageFromAtlas("gfx/ui/right.png"); } +void initStatsDisplay(void) +{ + int gameDone, gameTotal; + + gameDone = game.stats[STAT_MISSIONS_COMPLETE] + game.stats[STAT_MIAS_RESCUED] + game.stats[STAT_TARGETS_DEFEATED] + game.stats[STAT_KEYS_FOUND] + game.stats[STAT_HEARTS_FOUND] + game.stats[STAT_CELLS_FOUND]; + + gameTotal = game.totalMissions + game.totalMIAs + game.totalTargets + game.totalKeys + game.totalHearts + game.totalCells; + + game.stats[STAT_SHOT_ACCURACY] = getPercent(STAT_SHOTS_HIT, STAT_SHOTS_FIRED); + game.stats[STAT_PERCENT_COMPLETE] = getPercent(gameDone, gameTotal); +} + void doStats(void) { if (isControl(CONTROL_LEFT) || app.keyboard[SDL_SCANCODE_LEFT]) @@ -124,6 +139,11 @@ void drawStats(void) switch (i) { + case STAT_SHOT_ACCURACY: + case STAT_PERCENT_COMPLETE: + drawText(r.x + r.w - 20, y, 18, TA_RIGHT, colors.white, "%d%%", game.stats[i]); + break; + case STAT_SWIM_TIME: case STAT_FLY_TIME: drawText(r.x + r.w - 20, y, 18, TA_RIGHT, colors.white, "%s", timeToString(game.stats[i] / FPS, 0)); diff --git a/src/game/stats.h b/src/game/stats.h index 317dc6a..07021ab 100644 --- a/src/game/stats.h +++ b/src/game/stats.h @@ -34,6 +34,7 @@ extern Texture *getTexture(const char *filename); extern int isControl(int type); extern float limit(float i, float low, float high); extern void playSound(int snd, int ch); +extern int getPercent(float current, float total); extern char *timeToString(int seconds, int showHours); extern App app; diff --git a/src/hub/hub.c b/src/hub/hub.c index 87fe1cd..74e84c1 100644 --- a/src/hub/hub.c +++ b/src/hub/hub.c @@ -55,8 +55,6 @@ static Atlas *clouds; static Sprite *cursorSpr; static Sprite *keySprites[MAX_KEY_TYPES]; static Texture *atlasTexture; -static int completedMissions; -static int numMissions; static int unlockedMissions; static PointF cursor; static float blipSize; @@ -115,11 +113,11 @@ void initHub(void) unlockAllLevels(); } - numMissions = 0; + game.totalMissions = 0; unlockedMissions = 0; - completedMissions = 0; + game.stats[STAT_MISSIONS_COMPLETE] = 0; unlockTeeka = 1; @@ -140,7 +138,7 @@ void initHub(void) if (t->value.i == MS_COMPLETE) { - completedMissions++; + game.stats[STAT_MISSIONS_COMPLETE]++; } } @@ -162,7 +160,7 @@ void initHub(void) unlockTeeka = 0; } - numMissions++; + game.totalMissions++; } for (mission = hubMissionHead.next ; mission != NULL ; mission = mission->next) @@ -411,7 +409,7 @@ static void drawInfoBar(void) { drawRect(0, 0, SCREEN_WIDTH, 32, 0, 0, 0, 192); - drawText(10, 5, 18, TA_LEFT, colors.white, "Missions : %d / %d", completedMissions, unlockedMissions); + drawText(10, 5, 18, TA_LEFT, colors.white, "Missions : %d / %d", game.stats[STAT_MISSIONS_COMPLETE], unlockedMissions); drawText(210, 5, 18, TA_LEFT, colors.white, "MIAs : %d / %d", game.stats[STAT_MIAS_RESCUED], game.totalMIAs); @@ -526,11 +524,11 @@ static void unlockAllLevels(void) static void unlockNeighbouringMission(HubMission *sourceMission) { - HubMission *mission, *missions[numMissions]; + HubMission *mission, *missions[game.totalMissions]; int i; i = 0; - memset(missions, 0, sizeof(HubMission*) * numMissions); + memset(missions, 0, sizeof(HubMission*) * game.totalMissions); for (mission = hubMissionHead.next ; mission != NULL ; mission = mission->next) { @@ -626,6 +624,7 @@ static void options(void) static void stats(void) { showing = SHOW_STATS; + initStatsDisplay(); showWidgetGroup("stats"); } @@ -743,13 +742,13 @@ static void awardMissionTrophies(void) } /* ignore training mission */ - if (completedMissions == 2) + if (game.stats[STAT_MISSIONS_COMPLETE] == 2) { awardTrophy("CLEAN"); } /* ignore Teeka's */ - if (numMissions - completedMissions == 1) + if (game.totalMissions - game.stats[STAT_MISSIONS_COMPLETE] == 1) { awardTrophy("FULLY_CLEAN"); } diff --git a/src/hub/hub.h b/src/hub/hub.h index dcf60db..f8405a8 100644 --- a/src/hub/hub.h +++ b/src/hub/hub.h @@ -71,6 +71,7 @@ extern Widget *selectWidgetAt(int x, int y); extern void showWidgetGroup(char *group); extern void startSectionTransition(void); extern void stopMusic(void); +extern void initStatsDisplay(void); extern App app; extern Colors colors; diff --git a/src/structs.h b/src/structs.h index 914b37d..0422eb8 100644 --- a/src/structs.h +++ b/src/structs.h @@ -367,6 +367,7 @@ typedef struct { int totalCells; int totalHearts; int totalKeys; + int totalMissions; unsigned int stats[STAT_MAX]; char worldId[MAX_NAME_LENGTH]; int isComplete; diff --git a/src/system/lookup.c b/src/system/lookup.c index 4424451..030ffda 100644 --- a/src/system/lookup.c +++ b/src/system/lookup.c @@ -68,6 +68,7 @@ void initLookups(void) addLookup("TROPHY_GOLD", TROPHY_GOLD); addLookup("TROPHY_PLATINUM", TROPHY_PLATINUM); + addLookup("STAT_MISSIONS_COMPLETE", STAT_MISSIONS_COMPLETE); addLookup("STAT_KEYS_FOUND", STAT_KEYS_FOUND); addLookup("STAT_CELLS_FOUND", STAT_CELLS_FOUND); addLookup("STAT_HEARTS_FOUND", STAT_HEARTS_FOUND); @@ -84,6 +85,8 @@ void initLookups(void) addLookup("STAT_WEAPONS_PICKED_UP", STAT_WEAPONS_PICKED_UP); addLookup("STAT_ENEMIES_KILLED", STAT_ENEMIES_KILLED); addLookup("STAT_MISSIONS_PLAYED", STAT_MISSIONS_PLAYED); + addLookup("STAT_SHOT_ACCURACY", STAT_SHOT_ACCURACY); + addLookup("STAT_PERCENT_COMPLETE", STAT_PERCENT_COMPLETE); addLookup("STAT_TIME_PLAYED", STAT_TIME_PLAYED); } diff --git a/src/test/atlasTest.c b/src/test/atlasTest.c index 963710b..2b670e5 100644 --- a/src/test/atlasTest.c +++ b/src/test/atlasTest.c @@ -24,12 +24,12 @@ void initAtlasTest(void) { int test; - dev.debug = 1; + dev.debug = 0; dev.cheatStatic = 0; dev.cheatBlind = 1; dev.cheatNoEnemies = 0; dev.cheatKeys = 0; - dev.cheatPower = 1; + dev.cheatPower = 0; dev.cheatHealth = 0; dev.cheatLevels = 0; dev.takeScreenshots = 0; diff --git a/src/world/world.c b/src/world/world.c index b25c062..2aa0ba3 100644 --- a/src/world/world.c +++ b/src/world/world.c @@ -802,6 +802,7 @@ static void options(void) static void stats(void) { showing = SHOW_STATS; + initStatsDisplay(); showWidgetGroup("stats"); } diff --git a/src/world/world.h b/src/world/world.h index 61de445..2d9c654 100644 --- a/src/world/world.h +++ b/src/world/world.h @@ -113,6 +113,7 @@ extern int rrnd(int low, int high); extern void showWidgetGroup(char *group); extern void startSectionTransition(void); extern void stopMusic(void); +extern void initStatsDisplay(void); extern App app; extern Colors colors;