mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
add additional statistic
This commit is contained in:
parent
9ceb1c567d
commit
80dd97364a
@ -54,6 +54,11 @@ StatisticDataSetEntry StatisticDataSet::createEntry(const PlayerState * ps, cons
|
||||
data.mightMagicRatio = Statistic::getMightMagicRatio(ps);
|
||||
data.numMines = Statistic::getNumMines(gs, ps);
|
||||
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;
|
||||
}
|
||||
@ -77,7 +82,12 @@ std::string StatisticDataSet::toCsv()
|
||||
ss << "MapVisitedRatio" << ";";
|
||||
ss << "ObeliskVisited" << ";";
|
||||
ss << "MightMagicRatio" << ";";
|
||||
ss << "Score";
|
||||
ss << "Score" << ";";
|
||||
ss << "MaxHeroLevel" << ";";
|
||||
ss << "NumBattlesNeutral" << ";";
|
||||
ss << "NumBattlesPlayer" << ";";
|
||||
ss << "NumWinBattlesNeutral" << ";";
|
||||
ss << "NumWinBattlesPlayer";
|
||||
for(auto & resource : resources)
|
||||
ss << ";" << GameConstants::RESOURCE_NAMES[resource];
|
||||
for(auto & resource : resources)
|
||||
@ -99,7 +109,12 @@ std::string StatisticDataSet::toCsv()
|
||||
ss << entry.mapVisitedRatio << ";";
|
||||
ss << entry.obeliskVisited << ";";
|
||||
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)
|
||||
ss << ";" << entry.resources[resource];
|
||||
for(auto & resource : resources)
|
||||
@ -220,9 +235,9 @@ double Statistic::getMapVisitedRatio(const CGameState * gs, PlayerColor player)
|
||||
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())
|
||||
return nullptr;
|
||||
//best hero will be that with highest exp
|
||||
|
@ -37,6 +37,11 @@ struct DLL_LINKAGE StatisticDataSetEntry
|
||||
double mightMagicRatio;
|
||||
std::map<EGameResID, int> numMines;
|
||||
int score;
|
||||
int maxHeroLevel;
|
||||
int numBattlesNeutral;
|
||||
int numBattlesPlayer;
|
||||
int numWinBattlesNeutral;
|
||||
int numWinBattlesPlayer;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h)
|
||||
{
|
||||
@ -56,6 +61,11 @@ struct DLL_LINKAGE StatisticDataSetEntry
|
||||
h & mightMagicRatio;
|
||||
h & numMines;
|
||||
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);
|
||||
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)
|
||||
{
|
||||
h & data;
|
||||
h & values;
|
||||
}
|
||||
};
|
||||
|
||||
@ -84,7 +112,7 @@ public:
|
||||
static si64 getArmyStrength(const PlayerState * ps, bool withTownGarrison = false);
|
||||
static int getIncome(const CGameState * gs, const PlayerState * ps);
|
||||
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 int getObeliskVisited(const CGameState * gs, const TeamID & t);
|
||||
static double getMightMagicRatio(const PlayerState * ps);
|
||||
|
@ -497,6 +497,22 @@ void BattleResultProcessor::endBattleConfirm(const CBattleInfoCallback & battle)
|
||||
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;
|
||||
raccepted.battleID = battle.getBattle()->getBattleID();
|
||||
raccepted.heroResult[0].army = const_cast<CArmedInstance*>(battle.battleGetArmyObject(BattleSide::ATTACKER));
|
||||
|
Loading…
Reference in New Issue
Block a user