mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-09 01:06:07 +02:00
add additional statistic
This commit is contained in:
@ -54,6 +54,11 @@ StatisticDataSetEntry StatisticDataSet::createEntry(const PlayerState * ps, cons
|
|||||||
data.mightMagicRatio = Statistic::getMightMagicRatio(ps);
|
data.mightMagicRatio = Statistic::getMightMagicRatio(ps);
|
||||||
data.numMines = Statistic::getNumMines(gs, ps);
|
data.numMines = Statistic::getNumMines(gs, ps);
|
||||||
data.score = scenarioHighScores.calculate().total;
|
data.score = scenarioHighScores.calculate().total;
|
||||||
|
data.maxHeroLevel = Statistic::findBestHero(gs, ps->color)->level;
|
||||||
|
data.numBattlesNeutral = gs->statistic.values.numBattlesNeutral.at(ps->color);
|
||||||
|
data.numBattlesPlayer = gs->statistic.values.numBattlesPlayer.at(ps->color);
|
||||||
|
data.numWinBattlesNeutral = gs->statistic.values.numWinBattlesNeutral.at(ps->color);
|
||||||
|
data.numWinBattlesPlayer = gs->statistic.values.numWinBattlesPlayer.at(ps->color);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@ -77,7 +82,12 @@ std::string StatisticDataSet::toCsv()
|
|||||||
ss << "MapVisitedRatio" << ";";
|
ss << "MapVisitedRatio" << ";";
|
||||||
ss << "ObeliskVisited" << ";";
|
ss << "ObeliskVisited" << ";";
|
||||||
ss << "MightMagicRatio" << ";";
|
ss << "MightMagicRatio" << ";";
|
||||||
ss << "Score";
|
ss << "Score" << ";";
|
||||||
|
ss << "MaxHeroLevel" << ";";
|
||||||
|
ss << "NumBattlesNeutral" << ";";
|
||||||
|
ss << "NumBattlesPlayer" << ";";
|
||||||
|
ss << "NumWinBattlesNeutral" << ";";
|
||||||
|
ss << "NumWinBattlesPlayer";
|
||||||
for(auto & resource : resources)
|
for(auto & resource : resources)
|
||||||
ss << ";" << GameConstants::RESOURCE_NAMES[resource];
|
ss << ";" << GameConstants::RESOURCE_NAMES[resource];
|
||||||
for(auto & resource : resources)
|
for(auto & resource : resources)
|
||||||
@ -99,7 +109,12 @@ std::string StatisticDataSet::toCsv()
|
|||||||
ss << entry.mapVisitedRatio << ";";
|
ss << entry.mapVisitedRatio << ";";
|
||||||
ss << entry.obeliskVisited << ";";
|
ss << entry.obeliskVisited << ";";
|
||||||
ss << entry.mightMagicRatio << ";";
|
ss << entry.mightMagicRatio << ";";
|
||||||
ss << entry.score;
|
ss << entry.score << ";";
|
||||||
|
ss << entry.maxHeroLevel << ";";
|
||||||
|
ss << entry.numBattlesNeutral << ";";
|
||||||
|
ss << entry.numBattlesPlayer << ";";
|
||||||
|
ss << entry.numWinBattlesNeutral << ";";
|
||||||
|
ss << entry.numWinBattlesPlayer;
|
||||||
for(auto & resource : resources)
|
for(auto & resource : resources)
|
||||||
ss << ";" << entry.resources[resource];
|
ss << ";" << entry.resources[resource];
|
||||||
for(auto & resource : resources)
|
for(auto & resource : resources)
|
||||||
@ -220,9 +235,9 @@ double Statistic::getMapVisitedRatio(const CGameState * gs, PlayerColor player)
|
|||||||
return visible / numTiles;
|
return visible / numTiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CGHeroInstance * Statistic::findBestHero(CGameState * gs, const PlayerColor & color)
|
const CGHeroInstance * Statistic::findBestHero(const CGameState * gs, const PlayerColor & color)
|
||||||
{
|
{
|
||||||
std::vector<ConstTransitivePtr<CGHeroInstance> > &h = gs->players[color].heroes;
|
auto &h = gs->players.at(color).heroes;
|
||||||
if(h.empty())
|
if(h.empty())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
//best hero will be that with highest exp
|
//best hero will be that with highest exp
|
||||||
|
@ -37,6 +37,11 @@ struct DLL_LINKAGE StatisticDataSetEntry
|
|||||||
double mightMagicRatio;
|
double mightMagicRatio;
|
||||||
std::map<EGameResID, int> numMines;
|
std::map<EGameResID, int> numMines;
|
||||||
int score;
|
int score;
|
||||||
|
int maxHeroLevel;
|
||||||
|
int numBattlesNeutral;
|
||||||
|
int numBattlesPlayer;
|
||||||
|
int numWinBattlesNeutral;
|
||||||
|
int numWinBattlesPlayer;
|
||||||
|
|
||||||
template <typename Handler> void serialize(Handler &h)
|
template <typename Handler> void serialize(Handler &h)
|
||||||
{
|
{
|
||||||
@ -56,6 +61,11 @@ struct DLL_LINKAGE StatisticDataSetEntry
|
|||||||
h & mightMagicRatio;
|
h & mightMagicRatio;
|
||||||
h & numMines;
|
h & numMines;
|
||||||
h & score;
|
h & score;
|
||||||
|
h & maxHeroLevel;
|
||||||
|
h & numBattlesNeutral;
|
||||||
|
h & numBattlesPlayer;
|
||||||
|
h & numWinBattlesNeutral;
|
||||||
|
h & numWinBattlesPlayer;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -68,9 +78,27 @@ public:
|
|||||||
static StatisticDataSetEntry createEntry(const PlayerState * ps, const CGameState * gs);
|
static StatisticDataSetEntry createEntry(const PlayerState * ps, const CGameState * gs);
|
||||||
std::string toCsv();
|
std::string toCsv();
|
||||||
|
|
||||||
|
struct ValueStorage
|
||||||
|
{
|
||||||
|
std::map<PlayerColor, int> numBattlesNeutral;
|
||||||
|
std::map<PlayerColor, int> numBattlesPlayer;
|
||||||
|
std::map<PlayerColor, int> numWinBattlesNeutral;
|
||||||
|
std::map<PlayerColor, int> numWinBattlesPlayer;
|
||||||
|
|
||||||
|
template <typename Handler> void serialize(Handler &h)
|
||||||
|
{
|
||||||
|
h & numBattlesNeutral;
|
||||||
|
h & numBattlesPlayer;
|
||||||
|
h & numWinBattlesNeutral;
|
||||||
|
h & numWinBattlesPlayer;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ValueStorage values;
|
||||||
|
|
||||||
template <typename Handler> void serialize(Handler &h)
|
template <typename Handler> void serialize(Handler &h)
|
||||||
{
|
{
|
||||||
h & data;
|
h & data;
|
||||||
|
h & values;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -84,7 +112,7 @@ public:
|
|||||||
static si64 getArmyStrength(const PlayerState * ps, bool withTownGarrison = false);
|
static si64 getArmyStrength(const PlayerState * ps, bool withTownGarrison = false);
|
||||||
static int getIncome(const CGameState * gs, const PlayerState * ps);
|
static int getIncome(const CGameState * gs, const PlayerState * ps);
|
||||||
static double getMapVisitedRatio(const CGameState * gs, PlayerColor player);
|
static double getMapVisitedRatio(const CGameState * gs, PlayerColor player);
|
||||||
static const CGHeroInstance * findBestHero(CGameState * gs, const PlayerColor & color);
|
static const CGHeroInstance * findBestHero(const CGameState * gs, const PlayerColor & color);
|
||||||
static std::vector<std::vector<PlayerColor>> getRank(std::vector<TStat> stats);
|
static std::vector<std::vector<PlayerColor>> getRank(std::vector<TStat> stats);
|
||||||
static int getObeliskVisited(const CGameState * gs, const TeamID & t);
|
static int getObeliskVisited(const CGameState * gs, const TeamID & t);
|
||||||
static double getMightMagicRatio(const PlayerState * ps);
|
static double getMightMagicRatio(const PlayerState * ps);
|
||||||
|
@ -497,6 +497,22 @@ void BattleResultProcessor::endBattleConfirm(const CBattleInfoCallback & battle)
|
|||||||
gameHandler->sendAndApply(&ro);
|
gameHandler->sendAndApply(&ro);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add statistic
|
||||||
|
if(battle.sideToPlayer(0) == PlayerColor::NEUTRAL || battle.sideToPlayer(1) == PlayerColor::NEUTRAL)
|
||||||
|
{
|
||||||
|
gameHandler->gameState()->statistic.values.numBattlesNeutral[battle.sideToPlayer(0)]++;
|
||||||
|
gameHandler->gameState()->statistic.values.numBattlesNeutral[battle.sideToPlayer(1)]++;
|
||||||
|
if(!finishingBattle->isDraw())
|
||||||
|
gameHandler->gameState()->statistic.values.numWinBattlesNeutral[battle.sideToPlayer(finishingBattle->winnerSide)]++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gameHandler->gameState()->statistic.values.numBattlesPlayer[battle.sideToPlayer(0)]++;
|
||||||
|
gameHandler->gameState()->statistic.values.numBattlesPlayer[battle.sideToPlayer(1)]++;
|
||||||
|
if(!finishingBattle->isDraw())
|
||||||
|
gameHandler->gameState()->statistic.values.numWinBattlesPlayer[battle.sideToPlayer(finishingBattle->winnerSide)]++;
|
||||||
|
}
|
||||||
|
|
||||||
BattleResultAccepted raccepted;
|
BattleResultAccepted raccepted;
|
||||||
raccepted.battleID = battle.getBattle()->getBattleID();
|
raccepted.battleID = battle.getBattle()->getBattleID();
|
||||||
raccepted.heroResult[0].army = const_cast<CArmedInstance*>(battle.battleGetArmyObject(BattleSide::ATTACKER));
|
raccepted.heroResult[0].army = const_cast<CArmedInstance*>(battle.battleGetArmyObject(BattleSide::ATTACKER));
|
||||||
|
Reference in New Issue
Block a user