2015-10-20 13:51:49 +02:00
|
|
|
/*
|
2016-02-21 16:50:27 +01:00
|
|
|
Copyright (C) 2015-2016 Parallel Realities
|
2015-10-20 13:51:49 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stats.h"
|
|
|
|
|
2015-11-26 09:16:29 +01:00
|
|
|
static void prevPage(void);
|
|
|
|
static void nextPage(void);
|
2016-02-29 11:47:41 +01:00
|
|
|
static void calculatePercentComplete(void);
|
2016-03-03 10:12:08 +01:00
|
|
|
void updateAccuracyStats(unsigned int *stats);
|
2015-11-26 09:16:29 +01:00
|
|
|
|
2016-02-29 11:47:41 +01:00
|
|
|
static char *statDescription[STAT_MAX];
|
2015-10-25 01:01:46 +02:00
|
|
|
static int page;
|
2016-02-29 16:55:21 +01:00
|
|
|
static float maxPages;
|
2015-11-26 09:16:29 +01:00
|
|
|
static Widget *prev;
|
|
|
|
static Widget *next;
|
2015-10-25 01:01:46 +02:00
|
|
|
|
2016-02-29 11:47:41 +01:00
|
|
|
void initStats(void)
|
|
|
|
{
|
|
|
|
statDescription[STAT_PERCENT_COMPLETE] = _("Percent Complete");
|
|
|
|
statDescription[STAT_MISSIONS_STARTED] = _("Missions Started");
|
2016-06-06 00:04:57 +02:00
|
|
|
statDescription[STAT_MISSIONS_COMPLETED] = _("Missions Completed");
|
2016-05-15 14:53:19 +02:00
|
|
|
statDescription[STAT_OPTIONAL_COMPLETED] = _("Optional Missions Completed");
|
2016-02-29 11:47:41 +01:00
|
|
|
statDescription[STAT_CHALLENGES_STARTED] = _("Challenges Started");
|
|
|
|
statDescription[STAT_CHALLENGES_COMPLETED] = _("Challenges Completed");
|
|
|
|
statDescription[STAT_SHOTS_FIRED] = _("Shots Fired");
|
|
|
|
statDescription[STAT_SHOTS_HIT] = _("Shots Hit");
|
2016-03-03 10:12:08 +01:00
|
|
|
statDescription[STAT_SHOT_ACCURACY] = _("Accuracy");
|
2016-02-29 11:47:41 +01:00
|
|
|
statDescription[STAT_ROCKETS_FIRED] = _("Rockets Fired");
|
|
|
|
statDescription[STAT_ROCKETS_HIT] = _("Rockets Hit");
|
2016-03-03 10:12:08 +01:00
|
|
|
statDescription[STAT_ROCKET_ACCURACY] = _("Accuracy");
|
2016-02-29 11:47:41 +01:00
|
|
|
statDescription[STAT_MISSILES_FIRED] = _("Missiles Fired");
|
|
|
|
statDescription[STAT_MISSILES_HIT] = _("Missiles Hit");
|
2016-03-03 10:12:08 +01:00
|
|
|
statDescription[STAT_MISSILE_ACCURACY] = _("Accuracy");
|
2016-02-29 11:47:41 +01:00
|
|
|
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");
|
2016-03-07 13:29:23 +01:00
|
|
|
statDescription[STAT_ITEMS_COLLECTED_PLAYER] = _("Items Collected (Player)");
|
2016-02-29 11:47:41 +01:00
|
|
|
statDescription[STAT_EPIC_KILL_STREAK] = _("Longest Epic Kill Streak");
|
2016-03-04 23:59:16 +01:00
|
|
|
statDescription[STAT_WAYPOINTS_VISITED] = _("Waypoints Visited");
|
2016-02-29 11:47:41 +01:00
|
|
|
statDescription[STAT_CAPITAL_SHIPS_DESTROYED] = _("Capital Ships Destroyed");
|
|
|
|
statDescription[STAT_CAPITAL_SHIPS_LOST] = _("Capital Ships Lost");
|
2016-04-03 09:37:09 +02:00
|
|
|
statDescription[STAT_MINES_DESTROYED] = _("Mines Destroyed");
|
2016-05-22 13:08:19 +02:00
|
|
|
statDescription[STAT_ENEMIES_SURRENDERED] = _("Enemies Surrendered");
|
2016-02-29 11:47:41 +01:00
|
|
|
statDescription[STAT_TIME] = _("Time Played");
|
|
|
|
}
|
|
|
|
|
2015-10-25 01:01:46 +02:00
|
|
|
void initStatsDisplay(void)
|
|
|
|
{
|
|
|
|
page = 0;
|
2016-02-29 16:55:21 +01:00
|
|
|
|
|
|
|
maxPages = STAT_TIME;
|
|
|
|
maxPages /= STATS_PER_PAGE;
|
|
|
|
maxPages = ceil(maxPages);
|
2015-10-25 01:01:46 +02:00
|
|
|
|
2015-11-26 09:16:29 +01:00
|
|
|
prev = getWidget("prev", "stats");
|
|
|
|
prev->action = prevPage;
|
2015-12-23 20:22:31 +01:00
|
|
|
prev->visible = 0;
|
2015-11-24 23:33:25 +01:00
|
|
|
|
2015-11-26 09:16:29 +01:00
|
|
|
next = getWidget("next", "stats");
|
|
|
|
next->action = nextPage;
|
2016-05-15 09:19:26 +02:00
|
|
|
next->visible = 1;
|
2016-02-29 11:47:41 +01:00
|
|
|
|
|
|
|
calculatePercentComplete();
|
2016-03-03 10:12:08 +01:00
|
|
|
|
|
|
|
updateAccuracyStats(game.stats);
|
2016-02-29 11:47:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void calculatePercentComplete(void)
|
|
|
|
{
|
|
|
|
StarSystem *starSystem;
|
|
|
|
Mission *mission;
|
|
|
|
int completed, total;
|
|
|
|
|
|
|
|
completed = total = 0;
|
|
|
|
|
|
|
|
for (starSystem = game.starSystemHead.next ; starSystem != NULL ; starSystem = starSystem->next)
|
|
|
|
{
|
2016-05-15 11:50:09 +02:00
|
|
|
if (starSystem->type == SS_NORMAL)
|
2016-02-29 11:47:41 +01:00
|
|
|
{
|
|
|
|
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);
|
2015-10-25 01:01:46 +02:00
|
|
|
}
|
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
void drawStats(void)
|
|
|
|
{
|
2016-02-28 14:02:57 +01:00
|
|
|
int i, y, startIndex;
|
2015-10-20 13:51:49 +02:00
|
|
|
SDL_Rect r;
|
|
|
|
|
|
|
|
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
|
|
|
|
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128);
|
|
|
|
SDL_RenderFillRect(app.renderer, NULL);
|
|
|
|
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
|
|
|
|
|
|
|
|
r.w = 500;
|
|
|
|
r.h = 600;
|
|
|
|
r.x = (SCREEN_WIDTH / 2) - r.w / 2;
|
|
|
|
r.y = (SCREEN_HEIGHT / 2) - r.h / 2;
|
|
|
|
|
|
|
|
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 0);
|
|
|
|
SDL_RenderFillRect(app.renderer, &r);
|
|
|
|
SDL_SetRenderDrawColor(app.renderer, 200, 200, 200, 255);
|
|
|
|
SDL_RenderDrawRect(app.renderer, &r);
|
|
|
|
|
2016-02-27 20:16:17 +01:00
|
|
|
drawText(SCREEN_WIDTH / 2, 70, 28, TA_CENTER, colors.white, _("Stats"));
|
2015-10-20 13:51:49 +02:00
|
|
|
|
2016-02-29 16:55:21 +01:00
|
|
|
drawText(SCREEN_WIDTH / 2, 110, 16, TA_CENTER, colors.lightGrey, _("Page %d / %d"), page + 1, (int)maxPages);
|
2015-10-20 13:51:49 +02:00
|
|
|
|
2016-03-05 14:49:07 +01:00
|
|
|
SDL_SetRenderDrawColor(app.renderer, 128, 128, 128, 255);
|
|
|
|
SDL_RenderDrawLine(app.renderer, r.x, 150, r.x + r.w, 150);
|
|
|
|
|
2015-10-25 01:01:46 +02:00
|
|
|
y = 170;
|
2015-10-20 13:51:49 +02:00
|
|
|
|
2016-02-29 16:55:21 +01:00
|
|
|
startIndex = (page * STATS_PER_PAGE);
|
2015-10-20 13:51:49 +02:00
|
|
|
|
2016-02-29 16:55:21 +01:00
|
|
|
for (i = startIndex ; i < startIndex + STATS_PER_PAGE ; i++)
|
2015-10-25 01:01:46 +02:00
|
|
|
{
|
|
|
|
if (i < STAT_TIME)
|
|
|
|
{
|
|
|
|
drawText(r.x + 20, y, 18, TA_LEFT, colors.white, statDescription[i]);
|
2016-02-29 11:47:41 +01:00
|
|
|
|
2016-03-03 10:12:08 +01:00
|
|
|
switch (i)
|
2016-02-29 11:47:41 +01:00
|
|
|
{
|
2016-03-03 10:12:08 +01:00
|
|
|
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;
|
2016-02-29 11:47:41 +01:00
|
|
|
}
|
|
|
|
|
2015-10-25 01:01:46 +02:00
|
|
|
y += 40;
|
|
|
|
}
|
|
|
|
}
|
2015-10-20 13:51:49 +02:00
|
|
|
|
2016-02-29 11:47:41 +01:00
|
|
|
drawText(r.x + 20, 565, 18, TA_LEFT, colors.white, statDescription[STAT_TIME]);
|
2016-02-28 14:02:57 +01:00
|
|
|
drawText(r.x + r.w - 20, 565, 18, TA_RIGHT, colors.white, timeToString(game.stats[STAT_TIME], 1));
|
2015-10-20 13:51:49 +02:00
|
|
|
|
2016-03-05 14:49:07 +01:00
|
|
|
drawWidgets("stats");
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
2015-11-26 09:16:29 +01:00
|
|
|
|
|
|
|
static void nextPage(void)
|
|
|
|
{
|
2015-12-23 20:22:31 +01:00
|
|
|
page = MIN(page + 1, maxPages - 1);
|
|
|
|
|
|
|
|
next->visible = page < maxPages - 1;
|
|
|
|
prev->visible = 1;
|
2015-11-26 09:16:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void prevPage(void)
|
|
|
|
{
|
|
|
|
page = MAX(0, page - 1);
|
2015-12-23 20:22:31 +01:00
|
|
|
|
|
|
|
next->visible = 1;
|
|
|
|
prev->visible = page > 0;
|
2015-11-26 09:16:29 +01:00
|
|
|
}
|
2016-03-03 10:12:08 +01:00
|
|
|
|
|
|
|
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]);
|
|
|
|
}
|