Browse Source

add val; stat at end turn; events

Laserlicht 1 year ago
parent
commit
ec2163b974

+ 1 - 0
Mods/vcmi/config/vcmi/english.json

@@ -187,6 +187,7 @@
 	"vcmi.statisticWindow.param.battleWinRatioNeutral" : "Win ratio (neutral)",
 	"vcmi.statisticWindow.param.battlesHero" : "Battles (hero)",
 	"vcmi.statisticWindow.param.battlesNeutral" : "Battles (neutral)",
+	"vcmi.statisticWindow.param.maxArmyStrength" : "Max army strength",
 	"vcmi.statisticWindow.param.tradeVolume" : "Trade volume",
 	"vcmi.statisticWindow.param.obeliskVisited" : "Obelisk visited",
 

+ 1 - 0
Mods/vcmi/config/vcmi/german.json

@@ -187,6 +187,7 @@
 	"vcmi.statisticWindow.param.battleWinRatioNeutral" : "Sieg Verh. (Neutral)",
 	"vcmi.statisticWindow.param.battlesHero" : "Kämpfe (Helden)",
 	"vcmi.statisticWindow.param.battlesNeutral" : "Kämpfe (Neutral)",
+	"vcmi.statisticWindow.param.maxArmyStrength" : "Max Armeestärke",
 	"vcmi.statisticWindow.param.tradeVolume" : "Handelsvolumen",
 	"vcmi.statisticWindow.param.obeliskVisited" : "Obelisk besucht",
 

+ 10 - 0
client/mainmenu/CStatisticScreen.cpp

@@ -29,6 +29,7 @@
 
 #include "../../lib/gameState/GameStatistics.h"
 #include "../../lib/texts/CGeneralTextHandler.h"
+#include "../../lib/texts/TextOperations.h"
 
 #include <vstd/DateUtils.h>
 
@@ -267,6 +268,15 @@ OverviewPanel::OverviewPanel(Rect position, std::string title, StatisticDataSet
 				return std::to_string((int)(val.obeliskVisitedRatio * 100)) + " %";
 			}
 		},
+		{
+			CGI->generaltexth->translate("vcmi.statisticWindow.param.maxArmyStrength"), [this](PlayerColor color){
+				int maxArmyStrength = 0;
+				for(auto val : playerDataFilter(color))
+					if(maxArmyStrength < val.armyStrength)
+						maxArmyStrength = val.armyStrength;
+				return TextOperations::formatMetric(maxArmyStrength, 6);
+			}
+		},
 		{
 			CGI->generaltexth->translate("vcmi.statisticWindow.param.tradeVolume") + " - " + CGI->generaltexth->translate(TextIdentifier("core.restypes", EGameResID::GOLD).get()), [this](PlayerColor color){
 				auto val = playerDataFilter(color).back();

+ 9 - 0
lib/gameState/GameStatistics.cpp

@@ -73,6 +73,9 @@ StatisticDataSetEntry StatisticDataSet::createEntry(const PlayerState * ps, cons
 	data.spentResourcesForArmy = gs->statistic.accumulatedValues.count(ps->color) ? gs->statistic.accumulatedValues.at(ps->color).spentResourcesForArmy : TResources();
 	data.spentResourcesForBuildings = gs->statistic.accumulatedValues.count(ps->color) ? gs->statistic.accumulatedValues.at(ps->color).spentResourcesForBuildings : TResources();
 	data.tradeVolume = gs->statistic.accumulatedValues.count(ps->color) ? gs->statistic.accumulatedValues.at(ps->color).tradeVolume : TResources();
+	data.eventCapturedTown = gs->statistic.accumulatedValues.count(ps->color) ? gs->statistic.accumulatedValues.at(ps->color).lastCapturedTownDay == gs->getDate(Date::DAY) : false;
+	data.eventDefeatedStrongestHero = gs->statistic.accumulatedValues.count(ps->color) ? gs->statistic.accumulatedValues.at(ps->color).lastDefeatedStrongestHeroDay == gs->getDate(Date::DAY) : false;
+	data.eventRansackingDragonUtopia = gs->statistic.accumulatedValues.count(ps->color) ? gs->statistic.accumulatedValues.at(ps->color).lastRansackingDragonUtopiaDay == gs->getDate(Date::DAY) : false;
 	data.movementPointsUsed = gs->statistic.accumulatedValues.count(ps->color) ? gs->statistic.accumulatedValues.at(ps->color).movementPointsUsed : 0;
 
 	return data;
@@ -111,6 +114,9 @@ std::string StatisticDataSet::toCsv()
 	ss << "NumWinBattlesPlayer" << ";";
 	ss << "NumHeroSurrendered" << ";";
 	ss << "NumHeroEscaped" << ";";
+	ss << "EventCapturedTown" << ";";
+	ss << "EventDefeatedStrongestHero" << ";";
+	ss << "EventRansackingDragonUtopia" << ";";
 	ss << "MovementPointsUsed";
 	for(auto & resource : resources)
 		ss << ";" << GameConstants::RESOURCE_NAMES[resource];
@@ -153,6 +159,9 @@ std::string StatisticDataSet::toCsv()
 		ss << entry.numWinBattlesPlayer << ";";
 		ss << entry.numHeroSurrendered << ";";
 		ss << entry.numHeroEscaped << ";";
+		ss << entry.eventCapturedTown << ";";
+		ss << entry.eventDefeatedStrongestHero << ";";
+		ss << entry.eventRansackingDragonUtopia << ";";
 		ss << entry.movementPointsUsed;
 		for(auto & resource : resources)
 			ss << ";" << entry.resources[resource];

+ 12 - 0
lib/gameState/GameStatistics.h

@@ -53,6 +53,9 @@ struct DLL_LINKAGE StatisticDataSetEntry
 	TResources spentResourcesForArmy;
 	TResources spentResourcesForBuildings;
 	TResources tradeVolume;
+	bool eventCapturedTown;
+	bool eventDefeatedStrongestHero;
+	bool eventRansackingDragonUtopia;
 	si64 movementPointsUsed;
 
 	template <typename Handler> void serialize(Handler &h)
@@ -89,6 +92,9 @@ struct DLL_LINKAGE StatisticDataSetEntry
 		h & spentResourcesForArmy;
 		h & spentResourcesForBuildings;
 		h & tradeVolume;
+		h & eventCapturedTown;
+		h & eventDefeatedStrongestHero;
+		h & eventRansackingDragonUtopia;
 		h & movementPointsUsed;
 	}
 };
@@ -113,6 +119,9 @@ public:
 		TResources spentResourcesForBuildings;
 		TResources tradeVolume;
 		si64 movementPointsUsed;
+		int lastCapturedTownDay;
+		int lastDefeatedStrongestHeroDay;
+		int lastRansackingDragonUtopiaDay;
 
 		template <typename Handler> void serialize(Handler &h)
 		{
@@ -126,6 +135,9 @@ public:
 			h & spentResourcesForBuildings;
 			h & tradeVolume;
 			h & movementPointsUsed;
+			h & lastCapturedTownDay;
+			h & lastDefeatedStrongestHeroDay;
+			h & lastRansackingDragonUtopiaDay;
 		}
 	};
 	std::vector<StatisticDataSetEntry> data;

+ 7 - 0
lib/mapObjects/CBank.cpp

@@ -383,6 +383,13 @@ void CBank::doVisit(const CGHeroInstance * hero) const
 		}
 		cb->setObjPropertyValue(id, ObjProperty::BANK_CLEAR); //bc = nullptr
 	}
+
+	// add statistics
+	if(bankConfig)
+	{
+		if(ID.toEnum() == Obj::DRAGON_UTOPIA)
+			cb->gameState()->statistic.accumulatedValues[hero->getOwner()].lastRansackingDragonUtopiaDay = cb->gameState()->getDate(Date::DAY);
+	}
 }
 
 void CBank::battleFinished(const CGHeroInstance *hero, const BattleResult &result) const

+ 10 - 5
server/CGameHandler.cpp

@@ -669,7 +669,7 @@ void CGameHandler::onPlayerTurnEnded(PlayerColor which)
 		heroPool->onNewWeek(which);
 }
 
-void CGameHandler::addStatistics()
+void CGameHandler::addStatistics(StatisticDataSet &stat)
 {
 	for (auto & elem : gs->players)
 	{
@@ -678,7 +678,7 @@ void CGameHandler::addStatistics()
 
 		auto data = StatisticDataSet::createEntry(&elem.second, gs);
 
-		gameState()->statistic.add(data);
+		stat.add(data);
 	}
 }
 
@@ -706,6 +706,10 @@ void CGameHandler::onNewTurn()
 			}
 		}
 	}
+	else
+	{
+		addStatistics(gameState()->statistic); // write at end of turn
+	}
 
 	for (auto & player : gs->players)
 	{
@@ -1026,8 +1030,6 @@ void CGameHandler::onNewTurn()
 	}
 
 	synchronizeArtifactHandlerLists(); //new day events may have changed them. TODO better of managing that
-
-	addStatistics();
 }
 
 void CGameHandler::start(bool resume)
@@ -1404,6 +1406,8 @@ void CGameHandler::setOwner(const CGObjectInstance * obj, const PlayerColor owne
 	const CGTownInstance * town = dynamic_cast<const CGTownInstance *>(obj);
 	if (town) //town captured
 	{
+		gs->statistic.accumulatedValues[owner].lastCapturedTownDay = gs->getDate(Date::DAY);
+
 		if (owner.isValidPlayer()) //new owner is real player
 		{
 			if (town->hasBuilt(BuildingSubID::PORTAL_OF_SUMMONING))
@@ -3793,7 +3797,8 @@ void CGameHandler::checkVictoryLossConditionsForPlayer(PlayerColor player)
 		PlayerEndsGame peg;
 		peg.player = player;
 		peg.victoryLossCheckResult = victoryLossCheckResult;
-		peg.statistic = gameState()->statistic;
+		peg.statistic = StatisticDataSet(gameState()->statistic);
+		addStatistics(peg.statistic); // add last turn befor win / loss
 		sendAndApply(&peg);
 
 		turnOrder->onPlayerEndsGame(player);

+ 2 - 1
server/CGameHandler.h

@@ -14,6 +14,7 @@
 #include "../lib/IGameCallback.h"
 #include "../lib/LoadProgress.h"
 #include "../lib/ScriptHandler.h"
+#include "../lib/gameState/GameStatistics.h"
 
 VCMI_LIB_NAMESPACE_BEGIN
 
@@ -227,7 +228,7 @@ public:
 	void onPlayerTurnStarted(PlayerColor which);
 	void onPlayerTurnEnded(PlayerColor which);
 	void onNewTurn();
-	void addStatistics();
+	void addStatistics(StatisticDataSet &stat);
 
 	void handleTimeEvents();
 	void handleTownEvents(CGTownInstance *town, NewTurn &n);

+ 10 - 0
server/battles/BattleResultProcessor.cpp

@@ -487,6 +487,16 @@ void BattleResultProcessor::endBattleConfirm(const CBattleInfoCallback & battle)
 	// Remove beaten hero
 	if(finishingBattle->loserHero)
 	{
+		if(!finishingBattle->isDraw())
+		{
+			ConstTransitivePtr<CGHeroInstance> strongestHero = nullptr;
+			for(auto & hero : gameHandler->gameState()->getPlayerState(finishingBattle->loser)->heroes)
+				if(!strongestHero || hero->exp > strongestHero->exp)
+					strongestHero = hero;
+			if(strongestHero->id == finishingBattle->loserHero->id)
+				gameHandler->gameState()->statistic.accumulatedValues[finishingBattle->victor].lastDefeatedStrongestHeroDay = gameHandler->gameState()->getDate(Date::DAY);
+		}
+
 		RemoveObject ro(finishingBattle->loserHero->id, finishingBattle->victor);
 		gameHandler->sendAndApply(&ro);
 	}