2024-07-27 02:11:26 +02:00
|
|
|
/*
|
|
|
|
* 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"
|
2024-08-01 21:30:53 +02:00
|
|
|
#include "../ResourceSet.h"
|
2024-07-27 02:11:26 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2024-08-01 21:30:53 +02:00
|
|
|
struct PlayerState;
|
|
|
|
class CGameState;
|
2024-08-02 00:04:41 +02:00
|
|
|
class CGHeroInstance;
|
2024-08-02 01:18:39 +02:00
|
|
|
class CGMine;
|
2024-08-01 21:30:53 +02:00
|
|
|
|
2024-07-27 02:11:26 +02:00
|
|
|
struct DLL_LINKAGE StatisticDataSetEntry
|
|
|
|
{
|
2024-08-02 20:40:24 +02:00
|
|
|
std::string map;
|
|
|
|
time_t timestamp;
|
2024-07-27 02:11:26 +02:00
|
|
|
int day;
|
|
|
|
PlayerColor player;
|
2024-08-14 02:49:54 +02:00
|
|
|
std::string playerName;
|
2024-08-01 21:30:53 +02:00
|
|
|
TeamID team;
|
2024-08-01 23:21:41 +02:00
|
|
|
bool isHuman;
|
|
|
|
EPlayerStatus status;
|
2024-08-01 21:30:53 +02:00
|
|
|
TResources resources;
|
2024-08-01 22:36:32 +02:00
|
|
|
int numberHeroes;
|
|
|
|
int numberTowns;
|
|
|
|
int numberArtifacts;
|
2024-08-03 18:48:45 +02:00
|
|
|
int numberDwellings;
|
2024-08-01 22:36:32 +02:00
|
|
|
si64 armyStrength;
|
2024-08-03 18:48:45 +02:00
|
|
|
si64 totalExperience;
|
2024-08-01 22:36:32 +02:00
|
|
|
int income;
|
2024-08-03 17:55:43 +02:00
|
|
|
float mapExploredRatio;
|
|
|
|
float obeliskVisitedRatio;
|
2024-08-03 19:53:05 +02:00
|
|
|
float townBuiltRatio;
|
|
|
|
bool hasGrail;
|
2024-08-02 01:18:39 +02:00
|
|
|
std::map<EGameResID, int> numMines;
|
2024-08-02 19:37:46 +02:00
|
|
|
int score;
|
2024-08-02 19:38:33 +02:00
|
|
|
int maxHeroLevel;
|
|
|
|
int numBattlesNeutral;
|
|
|
|
int numBattlesPlayer;
|
|
|
|
int numWinBattlesNeutral;
|
|
|
|
int numWinBattlesPlayer;
|
2024-08-02 20:40:24 +02:00
|
|
|
int numHeroSurrendered;
|
|
|
|
int numHeroEscaped;
|
2024-08-03 19:53:05 +02:00
|
|
|
TResources spentResourcesForArmy;
|
|
|
|
TResources spentResourcesForBuildings;
|
|
|
|
TResources tradeVolume;
|
2024-08-03 20:47:20 +02:00
|
|
|
si64 movementPointsUsed;
|
2024-07-27 02:11:26 +02:00
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h)
|
|
|
|
{
|
2024-08-02 20:40:24 +02:00
|
|
|
h & map;
|
|
|
|
h & timestamp;
|
2024-07-27 02:11:26 +02:00
|
|
|
h & day;
|
|
|
|
h & player;
|
2024-08-14 02:49:54 +02:00
|
|
|
h & playerName;
|
2024-08-01 21:30:53 +02:00
|
|
|
h & team;
|
2024-08-01 23:21:41 +02:00
|
|
|
h & isHuman;
|
|
|
|
h & status;
|
2024-08-01 21:30:53 +02:00
|
|
|
h & resources;
|
2024-08-01 22:36:32 +02:00
|
|
|
h & numberHeroes;
|
|
|
|
h & numberTowns;
|
|
|
|
h & numberArtifacts;
|
2024-08-03 18:48:45 +02:00
|
|
|
h & numberDwellings;
|
2024-08-01 22:36:32 +02:00
|
|
|
h & armyStrength;
|
2024-08-03 18:48:45 +02:00
|
|
|
h & totalExperience;
|
2024-08-01 22:36:32 +02:00
|
|
|
h & income;
|
2024-08-03 17:55:43 +02:00
|
|
|
h & mapExploredRatio;
|
|
|
|
h & obeliskVisitedRatio;
|
2024-08-03 19:53:05 +02:00
|
|
|
h & townBuiltRatio;
|
|
|
|
h & hasGrail;
|
2024-08-02 01:18:39 +02:00
|
|
|
h & numMines;
|
2024-08-02 19:37:46 +02:00
|
|
|
h & score;
|
2024-08-02 19:38:33 +02:00
|
|
|
h & maxHeroLevel;
|
|
|
|
h & numBattlesNeutral;
|
|
|
|
h & numBattlesPlayer;
|
|
|
|
h & numWinBattlesNeutral;
|
|
|
|
h & numWinBattlesPlayer;
|
2024-08-02 20:40:24 +02:00
|
|
|
h & numHeroSurrendered;
|
|
|
|
h & numHeroEscaped;
|
2024-08-03 19:53:05 +02:00
|
|
|
h & spentResourcesForArmy;
|
|
|
|
h & spentResourcesForBuildings;
|
|
|
|
h & tradeVolume;
|
2024-08-03 20:47:20 +02:00
|
|
|
h & movementPointsUsed;
|
2024-07-27 02:11:26 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_LINKAGE StatisticDataSet
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void add(StatisticDataSetEntry entry);
|
2024-08-01 21:30:53 +02:00
|
|
|
static StatisticDataSetEntry createEntry(const PlayerState * ps, const CGameState * gs);
|
2024-07-27 02:11:26 +02:00
|
|
|
std::string toCsv();
|
2024-08-12 20:14:36 +02:00
|
|
|
std::string writeCsv();
|
2024-07-27 02:11:26 +02:00
|
|
|
|
2024-08-07 21:26:22 +02:00
|
|
|
struct PlayerAccumulatedValueStorage // holds some actual values needed for stats
|
2024-08-02 19:38:33 +02:00
|
|
|
{
|
2024-08-07 21:26:22 +02:00
|
|
|
int numBattlesNeutral;
|
|
|
|
int numBattlesPlayer;
|
|
|
|
int numWinBattlesNeutral;
|
|
|
|
int numWinBattlesPlayer;
|
|
|
|
int numHeroSurrendered;
|
|
|
|
int numHeroEscaped;
|
|
|
|
TResources spentResourcesForArmy;
|
|
|
|
TResources spentResourcesForBuildings;
|
|
|
|
TResources tradeVolume;
|
|
|
|
si64 movementPointsUsed;
|
2024-08-02 19:38:33 +02:00
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h)
|
|
|
|
{
|
|
|
|
h & numBattlesNeutral;
|
|
|
|
h & numBattlesPlayer;
|
|
|
|
h & numWinBattlesNeutral;
|
|
|
|
h & numWinBattlesPlayer;
|
2024-08-02 20:40:24 +02:00
|
|
|
h & numHeroSurrendered;
|
|
|
|
h & numHeroEscaped;
|
2024-08-03 20:47:20 +02:00
|
|
|
h & spentResourcesForArmy;
|
|
|
|
h & spentResourcesForBuildings;
|
|
|
|
h & tradeVolume;
|
|
|
|
h & movementPointsUsed;
|
2024-08-02 19:38:33 +02:00
|
|
|
}
|
|
|
|
};
|
2024-08-13 00:50:10 +02:00
|
|
|
std::vector<StatisticDataSetEntry> data;
|
2024-08-07 21:26:22 +02:00
|
|
|
std::map<PlayerColor, PlayerAccumulatedValueStorage> accumulatedValues;
|
2024-08-02 19:38:33 +02:00
|
|
|
|
2024-07-27 02:11:26 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h)
|
|
|
|
{
|
|
|
|
h & data;
|
2024-08-07 21:26:22 +02:00
|
|
|
h & accumulatedValues;
|
2024-07-27 02:11:26 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-08-01 22:36:32 +02:00
|
|
|
class DLL_LINKAGE Statistic
|
|
|
|
{
|
2024-08-02 01:18:39 +02:00
|
|
|
static std::vector<const CGMine *> getMines(const CGameState * gs, const PlayerState * ps);
|
2024-08-01 22:36:32 +02:00
|
|
|
public:
|
2024-08-02 01:18:39 +02:00
|
|
|
static int getNumberOfArts(const PlayerState * ps);
|
|
|
|
static si64 getArmyStrength(const PlayerState * ps, bool withTownGarrison = false);
|
2024-08-03 18:48:45 +02:00
|
|
|
static si64 getTotalExperience(const PlayerState * ps);
|
2024-08-01 23:56:06 +02:00
|
|
|
static int getIncome(const CGameState * gs, const PlayerState * ps);
|
2024-08-03 17:55:43 +02:00
|
|
|
static float getMapExploredRatio(const CGameState * gs, PlayerColor player);
|
2024-08-02 19:38:33 +02:00
|
|
|
static const CGHeroInstance * findBestHero(const CGameState * gs, const PlayerColor & color);
|
2024-08-03 17:55:43 +02:00
|
|
|
static std::vector<std::vector<PlayerColor>> getRank(std::vector<std::pair<PlayerColor, si64>> stats);
|
2024-08-02 01:18:39 +02:00
|
|
|
static int getObeliskVisited(const CGameState * gs, const TeamID & t);
|
2024-08-03 17:55:43 +02:00
|
|
|
static float getObeliskVisitedRatio(const CGameState * gs, const TeamID & t);
|
2024-08-02 01:18:39 +02:00
|
|
|
static std::map<EGameResID, int> getNumMines(const CGameState * gs, const PlayerState * ps);
|
2024-08-03 19:53:05 +02:00
|
|
|
static float getTownBuiltRatio(const PlayerState * ps);
|
2024-08-01 22:36:32 +02:00
|
|
|
};
|
|
|
|
|
2024-07-27 02:11:26 +02:00
|
|
|
VCMI_LIB_NAMESPACE_END
|