1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
/*
* GameSTatistics.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
#include "../GameConstants.h"
#include "../ResourceSet.h"
VCMI_LIB_NAMESPACE_BEGIN
class PlayerState;
class CGameState;
class CGHeroInstance;
class CGMine;
struct DLL_LINKAGE StatisticDataSetEntry
{
std::string map;
time_t timestamp;
int day;
PlayerColor player;
std::string playerName;
TeamID team;
bool isHuman;
EPlayerStatus status;
TResources resources;
int numberHeroes;
int numberTowns;
int numberArtifacts;
int numberDwellings;
si64 armyStrength;
si64 totalExperience;
int income;
float mapExploredRatio;
float obeliskVisitedRatio;
float townBuiltRatio;
bool hasGrail;
std::map<EGameResID, int> numMines;
int score;
int maxHeroLevel;
int numBattlesNeutral;
int numBattlesPlayer;
int numWinBattlesNeutral;
int numWinBattlesPlayer;
int numHeroSurrendered;
int numHeroEscaped;
TResources spentResourcesForArmy;
TResources spentResourcesForBuildings;
TResources tradeVolume;
bool eventCapturedTown;
bool eventDefeatedStrongestHero;
si64 movementPointsUsed;
template <typename Handler> void serialize(Handler &h)
{
h & map;
h & timestamp;
h & day;
h & player;
if(h.version >= Handler::Version::STATISTICS_SCREEN)
h & playerName;
h & team;
h & isHuman;
h & status;
h & resources;
h & numberHeroes;
h & numberTowns;
h & numberArtifacts;
h & numberDwellings;
h & armyStrength;
h & totalExperience;
h & income;
h & mapExploredRatio;
h & obeliskVisitedRatio;
h & townBuiltRatio;
h & hasGrail;
h & numMines;
h & score;
h & maxHeroLevel;
h & numBattlesNeutral;
h & numBattlesPlayer;
h & numWinBattlesNeutral;
h & numWinBattlesPlayer;
h & numHeroSurrendered;
h & numHeroEscaped;
h & spentResourcesForArmy;
h & spentResourcesForBuildings;
h & tradeVolume;
if(h.version >= Handler::Version::STATISTICS_SCREEN)
{
h & eventCapturedTown;
h & eventDefeatedStrongestHero;
}
h & movementPointsUsed;
}
};
class DLL_LINKAGE StatisticDataSet
{
public:
void add(StatisticDataSetEntry entry);
static StatisticDataSetEntry createEntry(const PlayerState * ps, const CGameState * gs);
std::string toCsv(std::string sep);
std::string writeCsv();
struct PlayerAccumulatedValueStorage // holds some actual values needed for stats
{
int numBattlesNeutral;
int numBattlesPlayer;
int numWinBattlesNeutral;
int numWinBattlesPlayer;
int numHeroSurrendered;
int numHeroEscaped;
TResources spentResourcesForArmy;
TResources spentResourcesForBuildings;
TResources tradeVolume;
si64 movementPointsUsed;
int lastCapturedTownDay;
int lastDefeatedStrongestHeroDay;
template <typename Handler> void serialize(Handler &h)
{
h & numBattlesNeutral;
h & numBattlesPlayer;
h & numWinBattlesNeutral;
h & numWinBattlesPlayer;
h & numHeroSurrendered;
h & numHeroEscaped;
h & spentResourcesForArmy;
h & spentResourcesForBuildings;
h & tradeVolume;
h & movementPointsUsed;
if(h.version >= Handler::Version::STATISTICS_SCREEN)
{
h & lastCapturedTownDay;
h & lastDefeatedStrongestHeroDay;
}
}
};
std::vector<StatisticDataSetEntry> data;
std::map<PlayerColor, PlayerAccumulatedValueStorage> accumulatedValues;
template <typename Handler> void serialize(Handler &h)
{
h & data;
h & accumulatedValues;
}
};
class DLL_LINKAGE Statistic
{
static std::vector<const CGMine *> getMines(const CGameState * gs, const PlayerState * ps);
public:
static int getNumberOfArts(const PlayerState * ps);
static int getNumberOfDwellings(const PlayerState * ps);
static si64 getArmyStrength(const PlayerState * ps, bool withTownGarrison = false);
static si64 getTotalExperience(const PlayerState * ps);
static int getIncome(const CGameState * gs, const PlayerState * ps);
static float getMapExploredRatio(const CGameState * gs, PlayerColor player);
static const CGHeroInstance * findBestHero(const CGameState * gs, const PlayerColor & color);
static std::vector<std::vector<PlayerColor>> getRank(std::vector<std::pair<PlayerColor, si64>> stats);
static int getObeliskVisited(const CGameState * gs, const TeamID & t);
static float getObeliskVisitedRatio(const CGameState * gs, const TeamID & t);
static std::map<EGameResID, int> getNumMines(const CGameState * gs, const PlayerState * ps);
static float getTownBuiltRatio(const PlayerState * ps);
};
VCMI_LIB_NAMESPACE_END
|