1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

add some stats

This commit is contained in:
Laserlicht 2024-08-02 20:40:24 +02:00
parent b3b7729a6c
commit 58bfd27aad
3 changed files with 33 additions and 3 deletions

View File

@ -38,6 +38,8 @@ StatisticDataSetEntry StatisticDataSet::createEntry(const PlayerState * ps, cons
scenarioHighScores.parameters.push_back(param); scenarioHighScores.parameters.push_back(param);
scenarioHighScores.isCampaign = false; scenarioHighScores.isCampaign = false;
data.map = gs->map->name.toString();
data.timestamp = std::time(0);
data.day = gs->getDate(Date::DAY); data.day = gs->getDate(Date::DAY);
data.player = ps->color; data.player = ps->color;
data.team = ps->team; data.team = ps->team;
@ -54,11 +56,13 @@ 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.maxHeroLevel = Statistic::findBestHero(gs, ps->color) ? Statistic::findBestHero(gs, ps->color)->level : 0;
data.numBattlesNeutral = gs->statistic.values.numBattlesNeutral.count(ps->color) ? gs->statistic.values.numBattlesNeutral.at(ps->color) : 0; data.numBattlesNeutral = gs->statistic.values.numBattlesNeutral.count(ps->color) ? gs->statistic.values.numBattlesNeutral.at(ps->color) : 0;
data.numBattlesPlayer = gs->statistic.values.numBattlesPlayer.count(ps->color) ? gs->statistic.values.numBattlesPlayer.at(ps->color) : 0; data.numBattlesPlayer = gs->statistic.values.numBattlesPlayer.count(ps->color) ? gs->statistic.values.numBattlesPlayer.at(ps->color) : 0;
data.numWinBattlesNeutral = gs->statistic.values.numWinBattlesNeutral.count(ps->color) ? gs->statistic.values.numWinBattlesNeutral.at(ps->color) : 0; data.numWinBattlesNeutral = gs->statistic.values.numWinBattlesNeutral.count(ps->color) ? gs->statistic.values.numWinBattlesNeutral.at(ps->color) : 0;
data.numWinBattlesPlayer = gs->statistic.values.numWinBattlesPlayer.count(ps->color) ? gs->statistic.values.numWinBattlesPlayer.at(ps->color) : 0; data.numWinBattlesPlayer = gs->statistic.values.numWinBattlesPlayer.count(ps->color) ? gs->statistic.values.numWinBattlesPlayer.at(ps->color) : 0;
data.numHeroSurrendered = gs->statistic.values.numHeroSurrendered.count(ps->color) ? gs->statistic.values.numHeroSurrendered.at(ps->color) : 0;
data.numHeroEscaped = gs->statistic.values.numHeroEscaped.count(ps->color) ? gs->statistic.values.numHeroEscaped.at(ps->color) : 0;
return data; return data;
} }
@ -69,6 +73,8 @@ std::string StatisticDataSet::toCsv()
auto resources = std::vector<EGameResID>{EGameResID::GOLD, EGameResID::WOOD, EGameResID::MERCURY, EGameResID::ORE, EGameResID::SULFUR, EGameResID::CRYSTAL, EGameResID::GEMS}; auto resources = std::vector<EGameResID>{EGameResID::GOLD, EGameResID::WOOD, EGameResID::MERCURY, EGameResID::ORE, EGameResID::SULFUR, EGameResID::CRYSTAL, EGameResID::GEMS};
ss << "Map" << ";";
ss << "Timestamp" << ";";
ss << "Day" << ";"; ss << "Day" << ";";
ss << "Player" << ";"; ss << "Player" << ";";
ss << "Team" << ";"; ss << "Team" << ";";
@ -87,7 +93,9 @@ std::string StatisticDataSet::toCsv()
ss << "NumBattlesNeutral" << ";"; ss << "NumBattlesNeutral" << ";";
ss << "NumBattlesPlayer" << ";"; ss << "NumBattlesPlayer" << ";";
ss << "NumWinBattlesNeutral" << ";"; ss << "NumWinBattlesNeutral" << ";";
ss << "NumWinBattlesPlayer"; ss << "NumWinBattlesPlayer" << ";";
ss << "NumHeroSurrendered" << ";";
ss << "NumHeroEscaped";
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)
@ -96,6 +104,8 @@ std::string StatisticDataSet::toCsv()
for(auto & entry : data) for(auto & entry : data)
{ {
ss << entry.map << ";";
ss << vstd::getFormattedDateTime(entry.timestamp, "%Y-%m-%dT%H-%M-%S") << ";";
ss << entry.day << ";"; ss << entry.day << ";";
ss << GameConstants::PLAYER_COLOR_NAMES[entry.player] << ";"; ss << GameConstants::PLAYER_COLOR_NAMES[entry.player] << ";";
ss << entry.team.getNum() << ";"; ss << entry.team.getNum() << ";";
@ -114,7 +124,9 @@ std::string StatisticDataSet::toCsv()
ss << entry.numBattlesNeutral << ";"; ss << entry.numBattlesNeutral << ";";
ss << entry.numBattlesPlayer << ";"; ss << entry.numBattlesPlayer << ";";
ss << entry.numWinBattlesNeutral << ";"; ss << entry.numWinBattlesNeutral << ";";
ss << entry.numWinBattlesPlayer; ss << entry.numWinBattlesPlayer << ";";
ss << entry.numHeroSurrendered << ";";
ss << entry.numHeroEscaped;
for(auto & resource : resources) for(auto & resource : resources)
ss << ";" << entry.resources[resource]; ss << ";" << entry.resources[resource];
for(auto & resource : resources) for(auto & resource : resources)

View File

@ -21,6 +21,8 @@ class CGMine;
struct DLL_LINKAGE StatisticDataSetEntry struct DLL_LINKAGE StatisticDataSetEntry
{ {
std::string map;
time_t timestamp;
int day; int day;
PlayerColor player; PlayerColor player;
TeamID team; TeamID team;
@ -42,9 +44,13 @@ struct DLL_LINKAGE StatisticDataSetEntry
int numBattlesPlayer; int numBattlesPlayer;
int numWinBattlesNeutral; int numWinBattlesNeutral;
int numWinBattlesPlayer; int numWinBattlesPlayer;
int numHeroSurrendered;
int numHeroEscaped;
template <typename Handler> void serialize(Handler &h) template <typename Handler> void serialize(Handler &h)
{ {
h & map;
h & timestamp;
h & day; h & day;
h & player; h & player;
h & team; h & team;
@ -66,6 +72,8 @@ struct DLL_LINKAGE StatisticDataSetEntry
h & numBattlesPlayer; h & numBattlesPlayer;
h & numWinBattlesNeutral; h & numWinBattlesNeutral;
h & numWinBattlesPlayer; h & numWinBattlesPlayer;
h & numHeroSurrendered;
h & numHeroEscaped;
} }
}; };
@ -84,6 +92,8 @@ public:
std::map<PlayerColor, int> numBattlesPlayer; std::map<PlayerColor, int> numBattlesPlayer;
std::map<PlayerColor, int> numWinBattlesNeutral; std::map<PlayerColor, int> numWinBattlesNeutral;
std::map<PlayerColor, int> numWinBattlesPlayer; std::map<PlayerColor, int> numWinBattlesPlayer;
std::map<PlayerColor, int> numHeroSurrendered;
std::map<PlayerColor, int> numHeroEscaped;
template <typename Handler> void serialize(Handler &h) template <typename Handler> void serialize(Handler &h)
{ {
@ -91,6 +101,8 @@ public:
h & numBattlesPlayer; h & numBattlesPlayer;
h & numWinBattlesNeutral; h & numWinBattlesNeutral;
h & numWinBattlesPlayer; h & numWinBattlesPlayer;
h & numHeroSurrendered;
h & numHeroEscaped;
} }
}; };
ValueStorage values; ValueStorage values;

View File

@ -572,10 +572,16 @@ void BattleResultProcessor::battleAfterLevelUp(const BattleID & battleID, const
gameHandler->checkVictoryLossConditions(playerColors); gameHandler->checkVictoryLossConditions(playerColors);
if (result.result == EBattleResult::SURRENDER) if (result.result == EBattleResult::SURRENDER)
{
gameHandler->gameState()->statistic.values.numHeroSurrendered[finishingBattle->loser]++;
gameHandler->heroPool->onHeroSurrendered(finishingBattle->loser, finishingBattle->loserHero); gameHandler->heroPool->onHeroSurrendered(finishingBattle->loser, finishingBattle->loserHero);
}
if (result.result == EBattleResult::ESCAPE) if (result.result == EBattleResult::ESCAPE)
{
gameHandler->gameState()->statistic.values.numHeroEscaped[finishingBattle->loser]++;
gameHandler->heroPool->onHeroEscaped(finishingBattle->loser, finishingBattle->loserHero); gameHandler->heroPool->onHeroEscaped(finishingBattle->loser, finishingBattle->loserHero);
}
if (result.winner != 2 && finishingBattle->winnerHero && finishingBattle->winnerHero->stacks.empty() if (result.winner != 2 && finishingBattle->winnerHero && finishingBattle->winnerHero->stacks.empty()
&& (!finishingBattle->winnerHero->commander || !finishingBattle->winnerHero->commander->alive)) && (!finishingBattle->winnerHero->commander || !finishingBattle->winnerHero->commander->alive))