mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-27 22:49:25 +02:00
show statistics ingame
This commit is contained in:
@@ -1582,6 +1582,30 @@ void CGameHandler::throwAndComplain(GameConnectionID connectionID, const std::st
|
||||
throwNotAllowedAction(connectionID);
|
||||
}
|
||||
|
||||
bool CGameHandler::responseStatistic(PlayerColor player)
|
||||
{
|
||||
ResponseStatistic rs;
|
||||
rs.statistic = *statistics;
|
||||
rs.player = player;
|
||||
|
||||
// Keep only team statistics, no enemy
|
||||
const TeamState * team = gameState().getPlayerTeam(player);
|
||||
|
||||
for(auto it = rs.statistic.accumulatedValues.begin(); it != rs.statistic.accumulatedValues.end();) {
|
||||
if (std::find(team->players.begin(), team->players.end(), it->first) == team->players.end())
|
||||
it = rs.statistic.accumulatedValues.erase(it);
|
||||
else
|
||||
++it;
|
||||
}
|
||||
rs.statistic.data.erase(std::remove_if(rs.statistic.data.begin(), rs.statistic.data.end(), [&team](const StatisticDataSetEntry& entry) {
|
||||
return std::find(team->players.begin(), team->players.end(), entry.player) == team->players.end();
|
||||
}), rs.statistic.data.end());
|
||||
|
||||
sendAndApply(rs);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CGameHandler::save(const std::string & filename)
|
||||
{
|
||||
logGlobal->info("Saving to %s", filename);
|
||||
|
||||
@@ -237,6 +237,7 @@ public:
|
||||
bool bulkSplitStack(SlotID src, ObjectInstanceID srcOwner, si32 howMany);
|
||||
bool bulkMergeStacks(SlotID slotSrc, ObjectInstanceID srcOwner);
|
||||
bool bulkSplitAndRebalanceStack(SlotID slotSrc, ObjectInstanceID srcOwner);
|
||||
bool responseStatistic(PlayerColor player);
|
||||
void save(const std::string &fname);
|
||||
void load(const StartInfo &info);
|
||||
|
||||
|
||||
@@ -441,6 +441,13 @@ void ApplyGhNetPackVisitor::visitCastAdvSpell(CastAdvSpell & pack)
|
||||
result = s->adventureCast(gh.spellEnv.get(), p);
|
||||
}
|
||||
|
||||
void ApplyGhNetPackVisitor::visitRequestStatistic(RequestStatistic & pack)
|
||||
{
|
||||
gh.throwIfPlayerNotActive(connection, &pack);
|
||||
|
||||
result = gh.responseStatistic(pack.player);
|
||||
}
|
||||
|
||||
void ApplyGhNetPackVisitor::visitPlayerMessage(PlayerMessage & pack)
|
||||
{
|
||||
if(!pack.player.isSpectator()) // TODO: clearly not a great way to verify permissions
|
||||
|
||||
@@ -65,6 +65,7 @@ public:
|
||||
void visitMakeAction(MakeAction & pack) override;
|
||||
void visitDigWithHero(DigWithHero & pack) override;
|
||||
void visitCastAdvSpell(CastAdvSpell & pack) override;
|
||||
void visitRequestStatistic(RequestStatistic & pack) override;
|
||||
void visitPlayerMessage(PlayerMessage & pack) override;
|
||||
void visitSaveLocalState(SaveLocalState & pack) override;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user