Kaynağa Gözat

Moved CGameState files into a separate directory

Ivan Savenko 2 yıl önce
ebeveyn
işleme
85262cf4f5
79 değiştirilmiş dosya ile 527 ekleme ve 706 silme
  1. 1 1
      AI/Nullkiller/AIGateway.cpp
  2. 1 1
      AI/Nullkiller/AIUtility.cpp
  3. 0 1
      AI/Nullkiller/Analyzers/HeroManager.cpp
  4. 0 1
      AI/Nullkiller/Engine/PriorityEvaluator.cpp
  5. 1 1
      AI/Nullkiller/Goals/CompleteQuest.h
  6. 0 1
      AI/Nullkiller/Pathfinding/Actions/BattleAction.h
  7. 0 1
      AI/Nullkiller/Pathfinding/Actions/BuyArmyAction.h
  8. 1 1
      AI/Nullkiller/Pathfinding/Actions/QuestAction.h
  9. 1 0
      AI/VCAI/FuzzyHelper.cpp
  10. 1 0
      AI/VCAI/Goals/CompleteQuest.h
  11. 1 1
      AI/VCAI/VCAI.cpp
  12. 1 1
      CCallback.cpp
  13. 1 0
      client/CMT.cpp
  14. 1 1
      client/CPlayerInterface.cpp
  15. 1 1
      client/Client.cpp
  16. 1 1
      client/ClientCommandManager.cpp
  17. 1 1
      client/NetPacksClient.cpp
  18. 1 0
      client/battle/BattleInterface.cpp
  19. 1 1
      client/battle/BattleInterfaceClasses.cpp
  20. 0 1
      client/battle/BattleStacksController.cpp
  21. 1 0
      client/battle/BattleWindow.cpp
  22. 0 1
      client/render/Graphics.cpp
  23. 1 2
      client/widgets/CGarrisonInt.cpp
  24. 1 1
      client/widgets/MiscWidgets.cpp
  25. 1 1
      client/windows/CCreatureWindow.cpp
  26. 1 1
      client/windows/CQuestLog.cpp
  27. 0 1
      client/windows/CTradeWindow.cpp
  28. 2 1
      client/windows/GUIClasses.cpp
  29. 1 1
      client/windows/InfoWindows.cpp
  30. 10 3
      cmake_modules/VCMI_lib.cmake
  31. 0 1
      lib/CCreatureHandler.cpp
  32. 0 1
      lib/CCreatureSet.cpp
  33. 2 1
      lib/CGameInfoCallback.cpp
  34. 0 1
      lib/CGameInterface.h
  35. 0 215
      lib/CGameStateFwd.h
  36. 1 1
      lib/CPlayerState.cpp
  37. 1 1
      lib/IGameCallback.cpp
  38. 8 7
      lib/NetPacks.h
  39. 1 1
      lib/NetPacksLib.cpp
  40. 1 0
      lib/battle/CBattleInfoEssentials.cpp
  41. 1 1
      lib/battle/CPlayerBattleCallback.cpp
  42. 32 379
      lib/gameState/CGameState.cpp
  43. 7 37
      lib/gameState/CGameState.h
  44. 83 0
      lib/gameState/EVictoryLossCheckResult.h
  45. 183 0
      lib/gameState/InfoAboutArmy.cpp
  46. 99 0
      lib/gameState/InfoAboutArmy.h
  47. 55 0
      lib/gameState/QuestInfo.h
  48. 1 1
      lib/mapObjects/CArmedInstance.cpp
  49. 1 1
      lib/mapObjects/CBank.cpp
  50. 1 1
      lib/mapObjects/CGDwelling.cpp
  51. 1 1
      lib/mapObjects/CGHeroInstance.cpp
  52. 0 1
      lib/mapObjects/CGMarket.cpp
  53. 1 1
      lib/mapObjects/CGObjectInstance.cpp
  54. 1 1
      lib/mapObjects/CGTownBuilding.cpp
  55. 1 1
      lib/mapObjects/CGTownInstance.cpp
  56. 0 1
      lib/mapObjects/CQuest.cpp
  57. 1 1
      lib/mapObjects/CRewardableObject.cpp
  58. 1 1
      lib/mapObjects/MiscObjects.cpp
  59. 1 1
      lib/pathfinder/CGPathNode.cpp
  60. 1 1
      lib/pathfinder/CPathfinder.cpp
  61. 1 1
      lib/pathfinder/PathfinderUtil.h
  62. 0 1
      lib/registerTypes/RegisterTypes.cpp
  63. 0 1
      lib/registerTypes/TypesClientPacks1.cpp
  64. 0 1
      lib/registerTypes/TypesClientPacks2.cpp
  65. 1 1
      lib/registerTypes/TypesLobbyPacks.cpp
  66. 0 1
      lib/registerTypes/TypesMapObjects1.cpp
  67. 0 1
      lib/registerTypes/TypesMapObjects2.cpp
  68. 0 1
      lib/registerTypes/TypesMapObjects3.cpp
  69. 0 1
      lib/registerTypes/TypesServerPacks.cpp
  70. 0 1
      lib/rewardable/Limiter.cpp
  71. 1 1
      lib/serializer/CSerializer.cpp
  72. 0 1
      lib/serializer/Connection.cpp
  73. 0 1
      mapeditor/graphics.cpp
  74. 1 1
      server/CGameHandler.cpp
  75. 1 1
      server/CVCMIServer.cpp
  76. 1 1
      server/NetPacksServer.cpp
  77. 1 1
      server/ServerSpellCastEnvironment.cpp
  78. 1 1
      test/game/CGameStateTest.cpp
  79. 1 1
      test/netpacks/NetPackFixture.h

+ 1 - 1
AI/Nullkiller/AIGateway.cpp

@@ -15,7 +15,7 @@
 #include "../../lib/CConfigHandler.h"
 #include "../../lib/CHeroHandler.h"
 #include "../../lib/GameSettings.h"
-#include "../../lib/CGameState.h"
+#include "../../lib/gameState/CGameState.h"
 #include "../../lib/NetPacks.h"
 #include "../../lib/serializer/CTypeList.h"
 #include "../../lib/serializer/BinarySerializer.h"

+ 1 - 1
AI/Nullkiller/AIUtility.cpp

@@ -17,7 +17,7 @@
 #include "../../lib/CHeroHandler.h"
 #include "../../lib/mapObjects/MapObjects.h"
 #include "../../lib/mapping/CMapDefines.h"
-
+#include "../../lib/gameState/QuestInfo.h"
 #include "../../lib/GameSettings.h"
 
 #include <vcmi/CreatureService.h>

+ 0 - 1
AI/Nullkiller/Analyzers/HeroManager.cpp

@@ -13,7 +13,6 @@
 #include "../../../lib/mapObjects/MapObjects.h"
 #include "../../../lib/CHeroHandler.h"
 #include "../../../lib/GameSettings.h"
-#include "../../../lib/CGameState.h"
 
 namespace NKAI
 {

+ 0 - 1
AI/Nullkiller/Engine/PriorityEvaluator.cpp

@@ -16,7 +16,6 @@
 #include "../../../lib/mapObjectConstructors/CBankInstanceConstructor.h"
 #include "../../../lib/mapObjects/MapObjects.h"
 #include "../../../lib/CCreatureHandler.h"
-#include "../../../lib/CGameStateFwd.h"
 #include "../../../lib/VCMI_Lib.h"
 #include "../../../lib/StartInfo.h"
 #include "../../../CCallback.h"

+ 1 - 1
AI/Nullkiller/Goals/CompleteQuest.h

@@ -12,7 +12,7 @@
 #include "../AIUtility.h"
 #include "../../../CCallback.h"
 #include "../Goals/CGoal.h"
-#include "../../../lib/CGameState.h"
+#include "../../../lib/gameState/QuestInfo.h"
 
 namespace NKAI
 {

+ 0 - 1
AI/Nullkiller/Pathfinding/Actions/BattleAction.h

@@ -11,7 +11,6 @@
 #pragma once
 
 #include "SpecialAction.h"
-#include "../../../../lib/CGameState.h"
 
 namespace NKAI
 {

+ 0 - 1
AI/Nullkiller/Pathfinding/Actions/BuyArmyAction.h

@@ -11,7 +11,6 @@
 #pragma once
 
 #include "SpecialAction.h"
-#include "../../../../lib/CGameState.h"
 
 namespace NKAI
 {

+ 1 - 1
AI/Nullkiller/Pathfinding/Actions/QuestAction.h

@@ -11,7 +11,7 @@
 #pragma once
 
 #include "SpecialAction.h"
-#include "../../../../lib/CGameState.h"
+#include "../../../../lib/gameState/QuestInfo.h"
 
 namespace NKAI
 {

+ 1 - 0
AI/VCAI/FuzzyHelper.cpp

@@ -19,6 +19,7 @@
 #include "../../lib/mapObjects/CBank.h"
 #include "../../lib/mapObjects/CGCreature.h"
 #include "../../lib/mapObjects/CGDwelling.h"
+#include "../../lib/gameState/InfoAboutArmy.h"
 
 FuzzyHelper * fh;
 

+ 1 - 0
AI/VCAI/Goals/CompleteQuest.h

@@ -11,6 +11,7 @@
 
 #include "CGoal.h"
 #include "../../../lib/VCMI_Lib.h"
+#include "../../../lib/gameState/QuestInfo.h"
 
 namespace Goals
 {

+ 1 - 1
AI/VCAI/VCAI.cpp

@@ -20,7 +20,7 @@
 #include "../../lib/CConfigHandler.h"
 #include "../../lib/CHeroHandler.h"
 #include "../../lib/GameSettings.h"
-#include "../../lib/CGameState.h"
+#include "../../lib/gameState/CGameState.h"
 #include "../../lib/NetPacksBase.h"
 #include "../../lib/NetPacks.h"
 #include "../../lib/bonuses/CBonusSystemNode.h"

+ 1 - 1
CCallback.cpp

@@ -11,7 +11,7 @@
 #include "CCallback.h"
 
 #include "lib/CCreatureHandler.h"
-#include "lib/CGameState.h"
+#include "lib/gameState/CGameState.h"
 #include "client/CPlayerInterface.h"
 #include "client/Client.h"
 #include "lib/mapping/CMap.h"

+ 1 - 0
client/CMT.cpp

@@ -29,6 +29,7 @@
 #include "../lib/filesystem/Filesystem.h"
 #include "../lib/CGeneralTextHandler.h"
 #include "../lib/VCMIDirs.h"
+#include "../lib/VCMI_Lib.h"
 #include "../lib/CConfigHandler.h"
 
 #include "../lib/logging/CBasicLogConfigurator.h"

+ 1 - 1
client/CPlayerInterface.cpp

@@ -75,7 +75,7 @@
 #include "../lib/TerrainHandler.h"
 #include "CServerHandler.h"
 // FIXME: only needed for CGameState::mutex
-#include "../lib/CGameState.h"
+#include "../lib/gameState/CGameState.h"
 #include "eventsSDL/NotificationHandler.h"
 #include "adventureMap/CInGameConsole.h"
 

+ 1 - 1
client/Client.cpp

@@ -23,7 +23,7 @@
 
 #include "../CCallback.h"
 #include "../lib/CConfigHandler.h"
-#include "../lib/CGameState.h"
+#include "../lib/gameState/CGameState.h"
 #include "../lib/CThreadHelper.h"
 #include "../lib/VCMIDirs.h"
 #include "../lib/battle/BattleInfo.h"

+ 1 - 1
client/ClientCommandManager.cpp

@@ -20,7 +20,7 @@
 #include "../lib/NetPacks.h"
 #include "ClientNetPackVisitors.h"
 #include "../lib/CConfigHandler.h"
-#include "../lib/CGameState.h"
+#include "../lib/gameState/CGameState.h"
 #include "../lib/CPlayerState.h"
 #include "../lib/StringConstants.h"
 #include "../lib/mapping/CMapService.h"

+ 1 - 1
client/NetPacksClient.cpp

@@ -38,7 +38,7 @@
 #include "../lib/CConfigHandler.h"
 #include "../lib/mapObjects/CGMarket.h"
 #include "../lib/mapping/CCampaignHandler.h"
-#include "../lib/CGameState.h"
+#include "../lib/gameState/CGameState.h"
 #include "../lib/CStack.h"
 #include "../lib/battle/BattleInfo.h"
 #include "../lib/GameConstants.h"

+ 1 - 0
client/battle/BattleInterface.cpp

@@ -38,6 +38,7 @@
 #include "../../lib/CGeneralTextHandler.h"
 #include "../../lib/CHeroHandler.h"
 #include "../../lib/CondSh.h"
+#include "../../lib/gameState/InfoAboutArmy.h"
 #include "../../lib/mapObjects/CGTownInstance.h"
 #include "../../lib/NetPacks.h"
 #include "../../lib/UnlockGuard.h"

+ 1 - 1
client/battle/BattleInterfaceClasses.cpp

@@ -41,7 +41,7 @@
 #include "../../lib/CStack.h"
 #include "../../lib/CConfigHandler.h"
 #include "../../lib/CCreatureHandler.h"
-#include "../../lib/CGameState.h"
+#include "../../lib/gameState/InfoAboutArmy.h"
 #include "../../lib/CGeneralTextHandler.h"
 #include "../../lib/CTownHandler.h"
 #include "../../lib/CHeroHandler.h"

+ 0 - 1
client/battle/BattleStacksController.cpp

@@ -32,7 +32,6 @@
 #include "../../CCallback.h"
 #include "../../lib/spells/ISpellMechanics.h"
 #include "../../lib/battle/BattleHex.h"
-#include "../../lib/CGameState.h"
 #include "../../lib/CStack.h"
 #include "../../lib/CondSh.h"
 #include "../../lib/TextOperations.h"

+ 1 - 0
client/battle/BattleWindow.cpp

@@ -33,6 +33,7 @@
 
 #include "../../CCallback.h"
 #include "../../lib/CGeneralTextHandler.h"
+#include "../../lib/gameState/InfoAboutArmy.h"
 #include "../../lib/mapObjects/CGHeroInstance.h"
 #include "../../lib/CStack.h"
 #include "../../lib/CConfigHandler.h"

+ 0 - 1
client/render/Graphics.cpp

@@ -32,7 +32,6 @@
 #include "../lib/VCMI_Lib.h"
 #include "../CCallback.h"
 #include "../lib/CGeneralTextHandler.h"
-#include "../lib/CGameState.h"
 #include "../lib/JsonNode.h"
 #include "../lib/vcmi_endian.h"
 #include "../lib/CStopWatch.h"

+ 1 - 2
client/widgets/CGarrisonInt.cpp

@@ -27,8 +27,7 @@
 #include "../../lib/CCreatureHandler.h"
 #include "../../lib/mapObjects/CGHeroInstance.h"
 #include "../../lib/TextOperations.h"
-
-#include "../../lib/CGameState.h"
+#include "../../lib/gameState/CGameState.h"
 
 void CGarrisonSlot::setHighlight(bool on)
 {

+ 1 - 1
client/widgets/MiscWidgets.cpp

@@ -25,7 +25,7 @@
 #include "../../CCallback.h"
 
 #include "../../lib/CConfigHandler.h"
-#include "../../lib/CGameState.h"
+#include "../../lib/gameState/InfoAboutArmy.h"
 #include "../../lib/CGeneralTextHandler.h"
 #include "../../lib/CModHandler.h"
 #include "../../lib/GameSettings.h"

+ 1 - 1
client/windows/CCreatureWindow.cpp

@@ -32,7 +32,7 @@
 #include "../../lib/CModHandler.h"
 #include "../../lib/GameSettings.h"
 #include "../../lib/CHeroHandler.h"
-#include "../../lib/CGameState.h"
+#include "../../lib/gameState/CGameState.h"
 #include "../../lib/TextOperations.h"
 
 class CCreatureArtifactInstance;

+ 1 - 1
client/windows/CQuestLog.cpp

@@ -26,7 +26,7 @@
 #include "../../CCallback.h"
 #include "../../lib/CArtHandler.h"
 #include "../../lib/CConfigHandler.h"
-#include "../../lib/CGameState.h"
+#include "../../lib/gameState/QuestInfo.h"
 #include "../../lib/CGeneralTextHandler.h"
 #include "../../lib/MetaString.h"
 #include "../../lib/mapObjects/CQuest.h"

+ 0 - 1
client/windows/CTradeWindow.cpp

@@ -32,7 +32,6 @@
 #include "../../lib/CCreatureHandler.h"
 #include "../../lib/CGeneralTextHandler.h"
 #include "../../lib/CHeroHandler.h"
-#include "../../lib/CGameState.h"
 #include "../../lib/mapObjects/CGHeroInstance.h"
 #include "../../lib/mapObjects/CGTownInstance.h"
 #include "../../lib/mapObjects/CGMarket.h"

+ 2 - 1
client/windows/GUIClasses.cpp

@@ -53,11 +53,12 @@
 #include "../lib/ArtifactUtils.h"
 #include "../lib/mapObjects/CGTownInstance.h"
 #include "../lib/mapObjects/ObjectTemplate.h"
+#include "../lib/gameState/CGameState.h"
+#include "../lib/gameState/InfoAboutArmy.h"
 #include "../lib/CArtHandler.h"
 #include "../lib/CBuildingHandler.h"
 #include "../lib/CConfigHandler.h"
 #include "../lib/CCreatureHandler.h"
-#include "../lib/CGameState.h"
 #include "../lib/CGeneralTextHandler.h"
 #include "../lib/CHeroHandler.h"
 #include "../lib/CModHandler.h"

+ 1 - 1
client/windows/InfoWindows.cpp

@@ -32,13 +32,13 @@
 
 #include "../../CCallback.h"
 
-#include "../../lib/CGameState.h"
 #include "../../lib/CConfigHandler.h"
 #include "../../lib/CondSh.h"
 #include "../../lib/CGeneralTextHandler.h" //for Unicode related stuff
 #include "../../lib/mapObjects/CGHeroInstance.h"
 #include "../../lib/mapObjects/CGTownInstance.h"
 #include "../../lib/mapObjects/MiscObjects.h"
+#include "../../lib/gameState/InfoAboutArmy.h"
 
 #include <SDL_surface.h>
 

+ 10 - 3
cmake_modules/VCMI_lib.cmake

@@ -62,6 +62,10 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE)
 		${MAIN_LIB_DIR}/filesystem/MinizipExtensions.cpp
 		${MAIN_LIB_DIR}/filesystem/ResourceID.cpp
 
+		${MAIN_LIB_DIR}/gameState/CGameState.cpp
+		${MAIN_LIB_DIR}/gameState/CGameStateCampaign.cpp
+		${MAIN_LIB_DIR}/gameState/InfoAboutArmy.cpp
+
 		${MAIN_LIB_DIR}/logging/CBasicLogConfigurator.cpp
 		${MAIN_LIB_DIR}/logging/CLogger.cpp
 
@@ -222,7 +226,6 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE)
 		${MAIN_LIB_DIR}/CCreatureSet.cpp
 		${MAIN_LIB_DIR}/CGameInfoCallback.cpp
 		${MAIN_LIB_DIR}/CGameInterface.cpp
-		${MAIN_LIB_DIR}/CGameState.cpp
 		${MAIN_LIB_DIR}/CGeneralTextHandler.cpp
 		${MAIN_LIB_DIR}/CHeroHandler.cpp
 		${MAIN_LIB_DIR}/CModHandler.cpp
@@ -378,6 +381,12 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE)
 		${MAIN_LIB_DIR}/filesystem/MinizipExtensions.h
 		${MAIN_LIB_DIR}/filesystem/ResourceID.h
 
+		${MAIN_LIB_DIR}/gameState/CGameState.h
+		${MAIN_LIB_DIR}/gameState/CGameStateCampaign.h
+		${MAIN_LIB_DIR}/gameState/EVictoryLossCheckResult.h
+		${MAIN_LIB_DIR}/gameState/InfoAboutArmy.h
+		${MAIN_LIB_DIR}/gameState/QuestInfo.h
+
 		${MAIN_LIB_DIR}/logging/CBasicLogConfigurator.h
 		${MAIN_LIB_DIR}/logging/CLogger.h
 
@@ -542,8 +551,6 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE)
 		${MAIN_LIB_DIR}/CCreatureSet.h
 		${MAIN_LIB_DIR}/CGameInfoCallback.h
 		${MAIN_LIB_DIR}/CGameInterface.h
-		${MAIN_LIB_DIR}/CGameStateFwd.h
-		${MAIN_LIB_DIR}/CGameState.h
 		${MAIN_LIB_DIR}/CGeneralTextHandler.h
 		${MAIN_LIB_DIR}/CHeroHandler.h
 		${MAIN_LIB_DIR}/CModHandler.h

+ 0 - 1
lib/CCreatureHandler.cpp

@@ -14,7 +14,6 @@
 #include "ResourceSet.h"
 #include "filesystem/Filesystem.h"
 #include "VCMI_Lib.h"
-#include "CGameState.h"
 #include "CTownHandler.h"
 #include "CModHandler.h"
 #include "GameSettings.h"

+ 0 - 1
lib/CCreatureSet.cpp

@@ -18,7 +18,6 @@
 #include "GameSettings.h"
 #include "mapObjects/CGHeroInstance.h"
 #include "IGameCallback.h"
-#include "CGameState.h"
 #include "CGeneralTextHandler.h"
 #include "spells/CSpellHandler.h"
 #include "CHeroHandler.h"

+ 2 - 1
lib/CGameInfoCallback.cpp

@@ -10,7 +10,8 @@
 #include "StdInc.h"
 #include "CGameInfoCallback.h"
 
-#include "CGameState.h" // PlayerState
+#include "gameState/CGameState.h"
+#include "gameState/InfoAboutArmy.h"
 #include "CGeneralTextHandler.h"
 #include "StartInfo.h" // for StartInfo
 #include "battle/BattleInfo.h" // for BattleInfo

+ 0 - 1
lib/CGameInterface.h

@@ -11,7 +11,6 @@
 
 #include "battle/BattleAction.h"
 #include "IGameEventsReceiver.h"
-#include "CGameStateFwd.h"
 
 #include "spells/ViewSpellInt.h"
 

+ 0 - 215
lib/CGameStateFwd.h

@@ -1,215 +0,0 @@
-/*
- * CGameStateFwd.h, part of VCMI engine
- *
- * Authors: listed in file AUTHORS in main folder
- *
- * License: GNU General Public License v2.0 or later
- * Full text of license available in license.txt file, in main folder
- *
- */
-#pragma once
-
-#include "CCreatureSet.h"
-#include "MetaString.h"
-#include "int3.h"
-
-VCMI_LIB_NAMESPACE_BEGIN
-
-class CQuest;
-class CGObjectInstance;
-class CHeroClass;
-class CTown;
-
-//numbers of creatures are exact numbers if detailed else they are quantity ids (1 - a few, 2 - several and so on; additionally 0 - unknown)
-struct ArmyDescriptor : public std::map<SlotID, CStackBasicDescriptor>
-{
-	bool isDetailed;
-	DLL_LINKAGE ArmyDescriptor(const CArmedInstance *army, bool detailed); //not detailed -> quantity ids as count
-	DLL_LINKAGE ArmyDescriptor();
-
-	DLL_LINKAGE int getStrength() const;
-};
-
-struct DLL_LINKAGE InfoAboutArmy
-{
-	PlayerColor owner;
-	std::string name;
-
-	ArmyDescriptor army;
-
-	InfoAboutArmy();
-	InfoAboutArmy(const CArmedInstance *Army, bool detailed);
-
-	void initFromArmy(const CArmedInstance *Army, bool detailed);
-};
-
-struct DLL_LINKAGE InfoAboutHero : public InfoAboutArmy
-{
-private:
-	void assign(const InfoAboutHero & iah);
-
-public:
-	struct DLL_LINKAGE Details
-	{
-		std::vector<si32> primskills;
-		si32 mana, manaLimit, luck, morale;
-	};
-
-	Details * details = nullptr;
-
-	const CHeroClass *hclass;
-	int portrait;
-
-	enum EInfoLevel
-	{
-		BASIC,
-		DETAILED,
-		INBATTLE
-	};
-
-	InfoAboutHero();
-	InfoAboutHero(const InfoAboutHero & iah);
-	InfoAboutHero(const CGHeroInstance *h, EInfoLevel infoLevel);
-	~InfoAboutHero();
-
-	InfoAboutHero & operator=(const InfoAboutHero & iah);
-
-	void initFromHero(const CGHeroInstance *h, EInfoLevel infoLevel);
-};
-
-/// Struct which holds a int information about a town
-struct DLL_LINKAGE InfoAboutTown : public InfoAboutArmy
-{
-	struct DLL_LINKAGE Details
-	{
-		si32 hallLevel, goldIncome;
-		bool customRes;
-		bool garrisonedHero;
-
-	} *details;
-
-	const CTown *tType;
-
-	si32 built;
-	si32 fortLevel; //0 - none
-
-	InfoAboutTown();
-	InfoAboutTown(const CGTownInstance *t, bool detailed);
-	~InfoAboutTown();
-	void initFromTown(const CGTownInstance *t, bool detailed);
-};
-
-class DLL_LINKAGE EVictoryLossCheckResult
-{
-public:
-	static EVictoryLossCheckResult victory(MetaString toSelf, MetaString toOthers)
-	{
-		return EVictoryLossCheckResult(VICTORY, toSelf, toOthers);
-	}
-
-	static EVictoryLossCheckResult defeat(MetaString toSelf, MetaString toOthers)
-	{
-		return EVictoryLossCheckResult(DEFEAT, toSelf, toOthers);
-	}
-
-	EVictoryLossCheckResult():
-	intValue(0)
-	{
-	}
-
-	bool operator==(EVictoryLossCheckResult const & other) const
-	{
-		return intValue == other.intValue;
-	}
-
-	bool operator!=(EVictoryLossCheckResult const & other) const
-	{
-		return intValue != other.intValue;
-	}
-
-	bool victory() const
-	{
-		return intValue == VICTORY;
-	}
-	bool loss() const
-	{
-		return intValue == DEFEAT;
-	}
-
-	EVictoryLossCheckResult invert()
-	{
-		return EVictoryLossCheckResult(-intValue, messageToOthers, messageToSelf);
-	}
-
-	MetaString messageToSelf;
-	MetaString messageToOthers;
-
-	template <typename Handler> void serialize(Handler &h, const int version)
-	{
-		h & intValue;
-		h & messageToSelf;
-		h & messageToOthers;
-	}
-private:
-	enum EResult
-	{
-		DEFEAT = -1,
-		INGAME =  0,
-		VICTORY= +1
-	};
-
-	EVictoryLossCheckResult(si32 intValue, MetaString toSelf, MetaString toOthers):
-		messageToSelf(toSelf),
-		messageToOthers(toOthers),
-		intValue(intValue)
-	{
-	}
-
-	si32 intValue; // uses EResultult
-};
-
-/*static std::ostream & operator<<(std::ostream & os, const EVictoryLossCheckResult & victoryLossCheckResult)
-{
-	os << victoryLossCheckResult.messageToSelf;
-	return os;
-}*/
-
-struct DLL_LINKAGE QuestInfo //universal interface for human and AI
-{
-	const CQuest * quest;
-	const CGObjectInstance * obj; //related object, most likely Seer Hut
-	int3 tile;
-
-	QuestInfo()
-		: quest(nullptr), obj(nullptr), tile(-1,-1,-1)
-	{};
-	QuestInfo (const CQuest * Quest, const CGObjectInstance * Obj, int3 Tile) :
-		quest (Quest), obj (Obj), tile (Tile){};
-
-	QuestInfo (const QuestInfo &qi) : quest(qi.quest), obj(qi.obj), tile(qi.tile)
-	{};
-
-	const QuestInfo& operator= (const QuestInfo &qi)
-	{
-		quest = qi.quest;
-		obj = qi.obj;
-		tile = qi.tile;
-		return *this;
-	}
-
-	bool operator== (const QuestInfo & qi) const
-	{
-		return (quest == qi.quest && obj == qi.obj);
-	}
-
-	//std::vector<std::string> > texts //allow additional info for quest log?
-
-	template <typename Handler> void serialize(Handler &h, const int version)
-	{
-		h & quest;
-		h & obj;
-		h & tile;
-	}
-};
-
-VCMI_LIB_NAMESPACE_END

+ 1 - 1
lib/CPlayerState.cpp

@@ -10,7 +10,7 @@
 #include "StdInc.h"
 
 #include "CPlayerState.h"
-#include "CGameStateFwd.h"
+#include "gameState/QuestInfo.h"
 
 VCMI_LIB_NAMESPACE_BEGIN
 

+ 1 - 1
lib/IGameCallback.cpp

@@ -34,7 +34,7 @@
 #include "mapObjects/ObjectTemplate.h"
 #include "mapping/CCampaignHandler.h"
 #include "StartInfo.h"
-#include "CGameState.h"
+#include "gameState/CGameState.h"
 #include "mapping/CMap.h"
 #include "CPlayerState.h"
 #include "GameSettings.h"

+ 8 - 7
lib/NetPacks.h

@@ -11,16 +11,17 @@
 
 #include "NetPacksBase.h"
 
-#include "battle/BattleAction.h"
-#include "mapObjects/CGHeroInstance.h"
 #include "ConstTransitivePtr.h"
-#include "int3.h"
-#include "ResourceSet.h"
-#include "CGameStateFwd.h"
-#include "mapping/CMapDefines.h"
-#include "battle/CObstacleInstance.h"
 #include "MetaString.h"
+#include "ResourceSet.h"
+#include "int3.h"
 
+#include "battle/BattleAction.h"
+#include "battle/CObstacleInstance.h"
+#include "gameState/EVictoryLossCheckResult.h"
+#include "gameState/QuestInfo.h"
+#include "mapObjects/CGHeroInstance.h"
+#include "mapping/CMapDefines.h"
 #include "spells/ViewSpellInt.h"
 
 class CClient;

+ 1 - 1
lib/NetPacksLib.cpp

@@ -19,7 +19,7 @@
 #include "mapping/CMap.h"
 #include "spells/CSpellHandler.h"
 #include "CCreatureHandler.h"
-#include "CGameState.h"
+#include "gameState/CGameState.h"
 #include "CStack.h"
 #include "battle/BattleInfo.h"
 #include "CTownHandler.h"

+ 1 - 0
lib/battle/CBattleInfoEssentials.cpp

@@ -13,6 +13,7 @@
 #include "BattleInfo.h"
 #include "../NetPacks.h"
 #include "../mapObjects/CGTownInstance.h"
+#include "../gameState/InfoAboutArmy.h"
 
 VCMI_LIB_NAMESPACE_BEGIN
 

+ 1 - 1
lib/battle/CPlayerBattleCallback.cpp

@@ -10,7 +10,7 @@
 #include "StdInc.h"
 #include "CPlayerBattleCallback.h"
 #include "../CStack.h"
-#include "../CGameState.h"
+#include "../gameState/InfoAboutArmy.h"
 
 VCMI_LIB_NAMESPACE_BEGIN
 

+ 32 - 379
lib/CGameState.cpp → lib/gameState/CGameState.cpp

@@ -10,36 +10,38 @@
 #include "StdInc.h"
 #include "CGameState.h"
 
-#include "mapping/CCampaignHandler.h"
-#include "ArtifactUtils.h"
-#include "CArtHandler.h"
-#include "CBuildingHandler.h"
-#include "CGeneralTextHandler.h"
-#include "CTownHandler.h"
-#include "spells/CSpellHandler.h"
-#include "CHeroHandler.h"
-#include "CModHandler.h"
-#include "GameSettings.h"
-#include "TerrainHandler.h"
-#include "CSkillHandler.h"
-#include "mapping/CMap.h"
-#include "mapping/CMapService.h"
-#include "mapObjectConstructors/CObjectClassesHandler.h"
-#include "StartInfo.h"
-#include "NetPacks.h"
-#include "pathfinder/CPathfinder.h"
-#include "pathfinder/PathfinderOptions.h"
-#include "registerTypes/RegisterTypes.h"
-#include "battle/BattleInfo.h"
-#include "JsonNode.h"
-#include "filesystem/Filesystem.h"
-#include "GameConstants.h"
-#include "rmg/CMapGenerator.h"
-#include "CStopWatch.h"
-#include "mapping/CMapEditManager.h"
-#include "serializer/CTypeList.h"
-#include "serializer/CMemorySerializer.h"
-#include "VCMIDirs.h"
+#include "EVictoryLossCheckResult.h"
+#include "InfoAboutArmy.h"
+
+#include "../ArtifactUtils.h"
+#include "../CBuildingHandler.h"
+#include "../CGeneralTextHandler.h"
+#include "../CHeroHandler.h"
+#include "../CPlayerState.h"
+#include "../CStopWatch.h"
+#include "../GameSettings.h"
+#include "../StartInfo.h"
+#include "../TerrainHandler.h"
+#include "../VCMIDirs.h"
+#include "../VCMI_Lib.h"
+#include "../battle/BattleInfo.h"
+#include "../filesystem/ResourceID.h"
+#include "../mapObjectConstructors/AObjectTypeHandler.h"
+#include "../mapObjectConstructors/CObjectClassesHandler.h"
+#include "../mapObjectConstructors/DwellingInstanceConstructor.h"
+#include "../mapObjects/CGHeroInstance.h"
+#include "../mapObjects/CGTownInstance.h"
+#include "../mapping/CCampaignHandler.h"
+#include "../mapping/CMap.h"
+#include "../mapping/CMapEditManager.h"
+#include "../mapping/CMapService.h"
+#include "../pathfinder/CPathfinder.h"
+#include "../pathfinder/PathfinderOptions.h"
+#include "../registerTypes/RegisterTypes.h"
+#include "../rmg/CMapGenerator.h"
+#include "../serializer/CMemorySerializer.h"
+#include "../serializer/CTypeList.h"
+#include "../spells/CSpellHandler.h"
 
 VCMI_LIB_NAMESPACE_BEGIN
 
@@ -952,191 +954,6 @@ void CGameState::placeStartingHero(const PlayerColor & playerColor, const HeroTy
 	map->getEditManager()->insertObject(hero);
 }
 
-CGameState::CrossoverHeroesList CGameState::getCrossoverHeroesFromPreviousScenarios() const
-{
-	CrossoverHeroesList crossoverHeroes;
-
-	auto campaignState = scenarioOps->campState;
-	auto bonus = campaignState->getBonusForCurrentMap();
-	if(bonus && bonus->type == CScenarioTravel::STravelBonus::HEROES_FROM_PREVIOUS_SCENARIO)
-	{
-		std::vector<CGHeroInstance *> heroes;
-		for(auto & node : campaignState->camp->scenarios[bonus->info2].crossoverHeroes)
-		{
-			auto * h = CCampaignState::crossoverDeserialize(node);
-			heroes.push_back(h);
-		}
-		crossoverHeroes.heroesFromAnyPreviousScenarios = crossoverHeroes.heroesFromPreviousScenario = heroes;
-	}
-	else
-	{
-		if(!campaignState->mapsConquered.empty())
-		{
-			std::vector<CGHeroInstance *> heroes = {};
-
-			crossoverHeroes.heroesFromAnyPreviousScenarios = crossoverHeroes.heroesFromPreviousScenario = heroes;
-			crossoverHeroes.heroesFromPreviousScenario = heroes;
-
-			for(auto mapNr : campaignState->mapsConquered)
-			{
-				// create a list of deleted heroes
-				auto & scenario = campaignState->camp->scenarios[mapNr];
-				auto lostCrossoverHeroes = scenario.getLostCrossoverHeroes();
-
-				// remove heroes which didn't reached the end of the scenario, but were available at the start
-				for(auto * hero : lostCrossoverHeroes)
-				{
-					//					auto hero = CCampaignState::crossoverDeserialize(node);
-					vstd::erase_if(crossoverHeroes.heroesFromAnyPreviousScenarios, [hero](CGHeroInstance * h)
-					{
-						return hero->subID == h->subID;
-					});
-				}
-
-				// now add heroes which completed the scenario
-				for(auto node : scenario.crossoverHeroes)
-				{
-					auto * hero = CCampaignState::crossoverDeserialize(node);
-					// add new heroes and replace old heroes with newer ones
-					auto it = range::find_if(crossoverHeroes.heroesFromAnyPreviousScenarios, [hero](CGHeroInstance * h)
-					{
-						return hero->subID == h->subID;
-					});
-
-					if(it != crossoverHeroes.heroesFromAnyPreviousScenarios.end())
-					{
-						// replace old hero with newer one
-						crossoverHeroes.heroesFromAnyPreviousScenarios[it - crossoverHeroes.heroesFromAnyPreviousScenarios.begin()] = hero;
-					}
-					else
-					{
-						// add new hero
-						crossoverHeroes.heroesFromAnyPreviousScenarios.push_back(hero);
-					}
-
-					if(mapNr == campaignState->mapsConquered.back())
-					{
-						crossoverHeroes.heroesFromPreviousScenario.push_back(hero);
-					}
-				}
-			}
-		}
-	}
-
-	return crossoverHeroes;
-}
-
-void CGameState::prepareCrossoverHeroes(std::vector<CGameState::CampaignHeroReplacement> & campaignHeroReplacements, const CScenarioTravel & travelOptions)
-{
-	// create heroes list for convenience iterating
-	std::vector<CGHeroInstance *> crossoverHeroes;
-	crossoverHeroes.reserve(campaignHeroReplacements.size());
-	for(auto & campaignHeroReplacement : campaignHeroReplacements)
-	{
-		crossoverHeroes.push_back(campaignHeroReplacement.hero);
-	}
-
-	// TODO replace magic numbers with named constants
-	// TODO this logic (what should be kept) should be part of CScenarioTravel and be exposed via some clean set of methods
-	if(!travelOptions.whatHeroKeeps.experience)
-	{
-		//trimming experience
-		for(CGHeroInstance * cgh : crossoverHeroes)
-		{
-			cgh->initExp(getRandomGenerator());
-		}
-	}
-
-	if(!travelOptions.whatHeroKeeps.primarySkills)
-	{
-		//trimming prim skills
-		for(CGHeroInstance * cgh : crossoverHeroes)
-		{
-			for(int g=0; g<GameConstants::PRIMARY_SKILLS; ++g)
-			{
-				auto sel = Selector::type()(BonusType::PRIMARY_SKILL)
-					.And(Selector::subtype()(g))
-					.And(Selector::sourceType()(BonusSource::HERO_BASE_SKILL));
-
-				cgh->getBonusLocalFirst(sel)->val = cgh->type->heroClass->primarySkillInitial[g];
-			}
-		}
-	}
-
-	if(!travelOptions.whatHeroKeeps.secondarySkills)
-	{
-		//trimming sec skills
-		for(CGHeroInstance * cgh : crossoverHeroes)
-		{
-			cgh->secSkills = cgh->type->secSkillsInit;
-			cgh->recreateSecondarySkillsBonuses();
-		}
-	}
-
-	if(!travelOptions.whatHeroKeeps.spells)
-	{
-		for(CGHeroInstance * cgh : crossoverHeroes)
-		{
-			cgh->removeSpellbook();
-		}
-	}
-
-	if(!travelOptions.whatHeroKeeps.artifacts)
-	{
-		//trimming artifacts
-		for(CGHeroInstance * hero : crossoverHeroes)
-		{
-			size_t totalArts = GameConstants::BACKPACK_START + hero->artifactsInBackpack.size();
-			for (size_t i = 0; i < totalArts; i++ )
-			{
-				auto artifactPosition = ArtifactPosition((si32)i);
-				if(artifactPosition == ArtifactPosition::SPELLBOOK) continue; // do not handle spellbook this way
-
-				const ArtSlotInfo *info = hero->getSlot(artifactPosition);
-				if(!info)
-					continue;
-
-				// TODO: why would there be nullptr artifacts?
-				const CArtifactInstance *art = info->artifact;
-				if(!art)
-					continue;
-
-				bool takeable = travelOptions.artifactsKeptByHero.count(art->artType->getId());
-
-				ArtifactLocation al(hero, artifactPosition);
-				if(!takeable  &&  !al.getSlot()->locked)  //don't try removing locked artifacts -> it crashes #1719
-					al.removeArtifact();
-			}
-		}
-	}
-
-	//trimming creatures
-	for(CGHeroInstance * cgh : crossoverHeroes)
-	{
-		auto shouldSlotBeErased = [&](const std::pair<SlotID, CStackInstance *> & j) -> bool
-		{
-			CreatureID::ECreatureID crid = j.second->getCreatureID().toEnum();
-			return !travelOptions.monstersKeptByHero.count(crid);
-		};
-
-		auto stacksCopy = cgh->stacks; //copy of the map, so we can iterate iover it and remove stacks
-		for(auto &slotPair : stacksCopy)
-			if(shouldSlotBeErased(slotPair))
-				cgh->eraseStack(slotPair.first);
-	}
-
-	// Removing short-term bonuses
-	for(CGHeroInstance * cgh : crossoverHeroes)
-	{
-		cgh->removeBonusesRecursive(CSelector(Bonus::OneDay)
-			.Or(CSelector(Bonus::OneWeek))
-			.Or(CSelector(Bonus::NTurns))
-			.Or(CSelector(Bonus::NDays))
-			.Or(CSelector(Bonus::OneBattle)));
-	}
-
-}
-
 void CGameState::placeStartingHeroes()
 {
 	logGlobal->debug("\tGiving starting hero");
@@ -2801,170 +2618,6 @@ bool RumorState::update(int id, int extra)
 	return true;
 }
 
-InfoAboutArmy::InfoAboutArmy():
-	owner(PlayerColor::NEUTRAL)
-{}
-
-InfoAboutArmy::InfoAboutArmy(const CArmedInstance *Army, bool detailed)
-{
-	initFromArmy(Army, detailed);
-}
-
-void InfoAboutArmy::initFromArmy(const CArmedInstance *Army, bool detailed)
-{
-	army = ArmyDescriptor(Army, detailed);
-	owner = Army->tempOwner;
-	name = Army->getObjectName();
-}
-
-void InfoAboutHero::assign(const InfoAboutHero & iah)
-{
-	vstd::clear_pointer(details);
-	InfoAboutArmy::operator = (iah);
-
-	details = (iah.details ? new Details(*iah.details) : nullptr);
-	hclass = iah.hclass;
-	portrait = iah.portrait;
-}
-
-InfoAboutHero::InfoAboutHero(): portrait(-1) {}
-
-InfoAboutHero::InfoAboutHero(const InfoAboutHero & iah): InfoAboutArmy(iah)
-{
-	assign(iah);
-}
-
-InfoAboutHero::InfoAboutHero(const CGHeroInstance * h, InfoAboutHero::EInfoLevel infoLevel):
-	portrait(-1)
-{
-	initFromHero(h, infoLevel);
-}
-
-InfoAboutHero::~InfoAboutHero()
-{
-	vstd::clear_pointer(details);
-}
-
-InfoAboutHero & InfoAboutHero::operator=(const InfoAboutHero & iah)
-{
-	assign(iah);
-	return *this;
-}
-
-void InfoAboutHero::initFromHero(const CGHeroInstance *h, InfoAboutHero::EInfoLevel infoLevel)
-{
-	vstd::clear_pointer(details);
-	if(!h)
-		return;
-
-	bool detailed = ( (infoLevel == EInfoLevel::DETAILED) || (infoLevel == EInfoLevel::INBATTLE) );
-
-	initFromArmy(h, detailed);
-
-	hclass = h->type->heroClass;
-	name = h->getNameTranslated();
-	portrait = h->portrait;
-
-	if(detailed)
-	{
-		//include details about hero
-		details = new Details();
-		details->luck = h->luckVal();
-		details->morale = h->moraleVal();
-		details->mana = h->mana;
-		details->primskills.resize(GameConstants::PRIMARY_SKILLS);
-
-		for (int i = 0; i < GameConstants::PRIMARY_SKILLS ; i++)
-		{
-			details->primskills[i] = h->getPrimSkillLevel(static_cast<PrimarySkill::PrimarySkill>(i));
-		}
-		if (infoLevel == EInfoLevel::INBATTLE)
-			details->manaLimit = h->manaLimit();
-		else
-			details->manaLimit = -1; //we do not want to leak max mana info outside battle so set to meaningless value
-	}
-}
-
-InfoAboutTown::InfoAboutTown():
-	details(nullptr),
-	tType(nullptr),
-	built(0),
-	fortLevel(0)
-{
-
-}
-
-InfoAboutTown::InfoAboutTown(const CGTownInstance *t, bool detailed):
-	details(nullptr),
-	tType(nullptr),
-	built(0),
-	fortLevel(0)
-{
-	initFromTown(t, detailed);
-}
-
-InfoAboutTown::~InfoAboutTown()
-{
-	vstd::clear_pointer(details);
-}
-
-void InfoAboutTown::initFromTown(const CGTownInstance *t, bool detailed)
-{
-	initFromArmy(t, detailed);
-	army = ArmyDescriptor(t->getUpperArmy(), detailed);
-	built = t->builded;
-	fortLevel = t->fortLevel();
-	name = t->getNameTranslated();
-	tType = t->getTown();
-
-	vstd::clear_pointer(details);
-
-	if(detailed)
-	{
-		//include details about hero
-		details = new Details();
-		TResources income = t->dailyIncome();
-		details->goldIncome = income[EGameResID::GOLD];
-		details->customRes = t->hasBuilt(BuildingID::RESOURCE_SILO);
-		details->hallLevel = t->hallLevel();
-		details->garrisonedHero = t->garrisonHero;
-	}
-}
-
-ArmyDescriptor::ArmyDescriptor(const CArmedInstance *army, bool detailed)
-	: isDetailed(detailed)
-{
-	for(const auto & elem : army->Slots())
-	{
-		if(detailed)
-			(*this)[elem.first] = *elem.second;
-		else
-			(*this)[elem.first] = CStackBasicDescriptor(elem.second->type, (int)elem.second->getQuantityID());
-	}
-}
-
-ArmyDescriptor::ArmyDescriptor()
-	: isDetailed(false)
-{
-
-}
-
-int ArmyDescriptor::getStrength() const
-{
-	ui64 ret = 0;
-	if(isDetailed)
-	{
-		for(const auto & elem : *this)
-			ret += elem.second.type->getAIValue() * elem.second.count;
-	}
-	else
-	{
-		for(const auto & elem : *this)
-			ret += elem.second.type->getAIValue() * CCreature::estimateCreatureCount(elem.second.count);
-	}
-	return static_cast<int>(ret);
-}
-
 TeamState::TeamState()
 {
 	setNodeType(TEAM);

+ 7 - 37
lib/CGameState.h → lib/gameState/CGameState.h

@@ -9,17 +9,8 @@
  */
 #pragma once
 
-#include "CCreatureHandler.h"
-#include "VCMI_Lib.h"
-
-#include "bonuses/Bonus.h"
-#include "CCreatureSet.h"
-#include "ConstTransitivePtr.h"
+#include "bonuses/CBonusSystemNode.h"
 #include "IGameCallback.h"
-#include "ResourceSet.h"
-#include "int3.h"
-#include "CRandomGenerator.h"
-#include "CGameStateFwd.h"
 
 namespace boost
 {
@@ -28,36 +19,15 @@ class shared_mutex;
 
 VCMI_LIB_NAMESPACE_BEGIN
 
-class CTown;
-class IGameCallback;
-class CCreatureSet;
-class CQuest;
-class CGHeroInstance;
-class CGTownInstance;
-class CArmedInstance;
-class CGDwelling;
-class CObjectScript;
-class CGObjectInstance;
-class CCreature;
+class EVictoryLossCheckResult;
+class Services;
+class IMapService;
 class CMap;
-struct StartInfo;
-struct SetObjectProperty;
-class MetaString;
 struct CPack;
-class CSpell;
-struct TerrainTile;
 class CHeroClass;
-class CCampaign;
-class CCampaignState;
-class IModableArt;
-class CGGarrison;
-struct QuestInfo;
-class CQuest;
-class CCampaignScenario;
 struct EventCondition;
 class CScenarioTravel;
-class IMapService;
-
+class CStackInstance;
 
 template<typename T> class CApplier;
 class CBaseForGSApply;
@@ -125,7 +95,7 @@ struct UpgradeInfo
 {
 	CreatureID oldID; //creature to be upgraded
 	std::vector<CreatureID> newID; //possible upgrades
-	std::vector<TResources> cost; // cost[upgrade_serial] -> set of pairs<resource_ID,resource_amount>; cost is for single unit (not entire stack)
+	std::vector<ResourceSet> cost; // cost[upgrade_serial] -> set of pairs<resource_ID,resource_amount>; cost is for single unit (not entire stack)
 	UpgradeInfo(){oldID = CreatureID::NONE;};
 };
 
@@ -261,7 +231,7 @@ private:
 	void randomizeObject(CGObjectInstance *cur);
 	void initPlayerStates();
 	void placeCampaignHeroes();
-	CrossoverHeroesList getCrossoverHeroesFromPreviousScenarios() const;
+
 
 	/// returns heroes and placeholders in where heroes will be put
 	std::vector<CampaignHeroReplacement> generateCampaignHeroesToReplace(CrossoverHeroesList & crossoverHeroes);

+ 83 - 0
lib/gameState/EVictoryLossCheckResult.h

@@ -0,0 +1,83 @@
+/*
+ * EVictoryLossCheckResult.h, part of VCMI engine
+ *
+ * Authors: listed in file AUTHORS in main folder
+ *
+ * License: GNU General Public License v2.0 or later
+ * Full text of license available in license.txt file, in main folder
+ *
+ */
+#pragma once
+
+#include "MetaString.h"
+
+VCMI_LIB_NAMESPACE_BEGIN
+
+class DLL_LINKAGE EVictoryLossCheckResult
+{
+public:
+	static EVictoryLossCheckResult victory(MetaString toSelf, MetaString toOthers)
+	{
+		return EVictoryLossCheckResult(VICTORY, toSelf, toOthers);
+	}
+
+	static EVictoryLossCheckResult defeat(MetaString toSelf, MetaString toOthers)
+	{
+		return EVictoryLossCheckResult(DEFEAT, toSelf, toOthers);
+	}
+
+	EVictoryLossCheckResult():
+	intValue(0)
+	{
+	}
+
+	bool operator==(EVictoryLossCheckResult const & other) const
+	{
+		return intValue == other.intValue;
+	}
+
+	bool operator!=(EVictoryLossCheckResult const & other) const
+	{
+		return intValue != other.intValue;
+	}
+
+	bool victory() const
+	{
+		return intValue == VICTORY;
+	}
+	bool loss() const
+	{
+		return intValue == DEFEAT;
+	}
+
+	EVictoryLossCheckResult invert()
+	{
+		return EVictoryLossCheckResult(-intValue, messageToOthers, messageToSelf);
+	}
+
+	MetaString messageToSelf;
+	MetaString messageToOthers;
+
+	template <typename Handler> void serialize(Handler &h, const int version)
+	{
+		h & intValue;
+		h & messageToSelf;
+		h & messageToOthers;
+	}
+private:
+	enum EResult
+	{
+		DEFEAT = -1,
+		INGAME =  0,
+		VICTORY= +1
+	};
+
+	EVictoryLossCheckResult(si32 intValue, MetaString toSelf, MetaString toOthers):
+		messageToSelf(toSelf),
+		messageToOthers(toOthers),
+		intValue(intValue)
+	{
+	}
+
+	si32 intValue; // uses EResultult
+};

+ 183 - 0
lib/gameState/InfoAboutArmy.cpp

@@ -0,0 +1,183 @@
+/*
+ * InfoAboutArmy.cpp, part of VCMI engine
+ *
+ * Authors: listed in file AUTHORS in main folder
+ *
+ * License: GNU General Public License v2.0 or later
+ * Full text of license available in license.txt file, in main folder
+ *
+ */
+#include "StdInc.h"
+#include "InfoAboutArmy.h"
+
+#include "../mapObjects/CGHeroInstance.h"
+#include "../mapObjects/CGTownInstance.h"
+#include "../CHeroHandler.h"
+
+VCMI_LIB_NAMESPACE_BEGIN
+
+ArmyDescriptor::ArmyDescriptor(const CArmedInstance *army, bool detailed)
+	: isDetailed(detailed)
+{
+	for(const auto & elem : army->Slots())
+	{
+		if(detailed)
+			(*this)[elem.first] = *elem.second;
+		else
+			(*this)[elem.first] = CStackBasicDescriptor(elem.second->type, (int)elem.second->getQuantityID());
+	}
+}
+
+ArmyDescriptor::ArmyDescriptor()
+	: isDetailed(false)
+{
+
+}
+
+int ArmyDescriptor::getStrength() const
+{
+	ui64 ret = 0;
+	if(isDetailed)
+	{
+		for(const auto & elem : *this)
+			ret += elem.second.type->getAIValue() * elem.second.count;
+	}
+	else
+	{
+		for(const auto & elem : *this)
+			ret += elem.second.type->getAIValue() * CCreature::estimateCreatureCount(elem.second.count);
+	}
+	return static_cast<int>(ret);
+}
+
+InfoAboutArmy::InfoAboutArmy():
+	owner(PlayerColor::NEUTRAL)
+{}
+
+InfoAboutArmy::InfoAboutArmy(const CArmedInstance *Army, bool detailed)
+{
+	initFromArmy(Army, detailed);
+}
+
+void InfoAboutArmy::initFromArmy(const CArmedInstance *Army, bool detailed)
+{
+	army = ArmyDescriptor(Army, detailed);
+	owner = Army->tempOwner;
+	name = Army->getObjectName();
+}
+
+void InfoAboutHero::assign(const InfoAboutHero & iah)
+{
+	vstd::clear_pointer(details);
+	InfoAboutArmy::operator = (iah);
+
+	details = (iah.details ? new Details(*iah.details) : nullptr);
+	hclass = iah.hclass;
+	portrait = iah.portrait;
+}
+
+InfoAboutHero::InfoAboutHero(): portrait(-1) {}
+
+InfoAboutHero::InfoAboutHero(const InfoAboutHero & iah): InfoAboutArmy(iah)
+{
+	assign(iah);
+}
+
+InfoAboutHero::InfoAboutHero(const CGHeroInstance * h, InfoAboutHero::EInfoLevel infoLevel):
+	portrait(-1)
+{
+	initFromHero(h, infoLevel);
+}
+
+InfoAboutHero::~InfoAboutHero()
+{
+	vstd::clear_pointer(details);
+}
+
+InfoAboutHero & InfoAboutHero::operator=(const InfoAboutHero & iah)
+{
+	assign(iah);
+	return *this;
+}
+
+void InfoAboutHero::initFromHero(const CGHeroInstance *h, InfoAboutHero::EInfoLevel infoLevel)
+{
+	vstd::clear_pointer(details);
+	if(!h)
+		return;
+
+	bool detailed = ( (infoLevel == EInfoLevel::DETAILED) || (infoLevel == EInfoLevel::INBATTLE) );
+
+	initFromArmy(h, detailed);
+
+	hclass = h->type->heroClass;
+	name = h->getNameTranslated();
+	portrait = h->portrait;
+
+	if(detailed)
+	{
+		//include details about hero
+		details = new Details();
+		details->luck = h->luckVal();
+		details->morale = h->moraleVal();
+		details->mana = h->mana;
+		details->primskills.resize(GameConstants::PRIMARY_SKILLS);
+
+		for (int i = 0; i < GameConstants::PRIMARY_SKILLS ; i++)
+		{
+			details->primskills[i] = h->getPrimSkillLevel(static_cast<PrimarySkill::PrimarySkill>(i));
+		}
+		if (infoLevel == EInfoLevel::INBATTLE)
+			details->manaLimit = h->manaLimit();
+		else
+			details->manaLimit = -1; //we do not want to leak max mana info outside battle so set to meaningless value
+	}
+}
+
+InfoAboutTown::InfoAboutTown():
+	details(nullptr),
+	tType(nullptr),
+	built(0),
+	fortLevel(0)
+{
+
+}
+
+InfoAboutTown::InfoAboutTown(const CGTownInstance *t, bool detailed):
+	details(nullptr),
+	tType(nullptr),
+	built(0),
+	fortLevel(0)
+{
+	initFromTown(t, detailed);
+}
+
+InfoAboutTown::~InfoAboutTown()
+{
+	vstd::clear_pointer(details);
+}
+
+void InfoAboutTown::initFromTown(const CGTownInstance *t, bool detailed)
+{
+	initFromArmy(t, detailed);
+	army = ArmyDescriptor(t->getUpperArmy(), detailed);
+	built = t->builded;
+	fortLevel = t->fortLevel();
+	name = t->getNameTranslated();
+	tType = t->getTown();
+
+	vstd::clear_pointer(details);
+
+	if(detailed)
+	{
+		//include details about hero
+		details = new Details();
+		TResources income = t->dailyIncome();
+		details->goldIncome = income[EGameResID::GOLD];
+		details->customRes = t->hasBuilt(BuildingID::RESOURCE_SILO);
+		details->hallLevel = t->hallLevel();
+		details->garrisonedHero = t->garrisonHero;
+	}
+}
+
+VCMI_LIB_NAMESPACE_END

+ 99 - 0
lib/gameState/InfoAboutArmy.h

@@ -0,0 +1,99 @@
+/*
+ * InfoAboutArmy.h, part of VCMI engine
+ *
+ * Authors: listed in file AUTHORS in main folder
+ *
+ * License: GNU General Public License v2.0 or later
+ * Full text of license available in license.txt file, in main folder
+ *
+ */
+#pragma once
+
+#include "CCreatureSet.h"
+
+VCMI_LIB_NAMESPACE_BEGIN
+
+class CGTownInstance;
+class CHeroClass;
+class CTown;
+
+//numbers of creatures are exact numbers if detailed else they are quantity ids (1 - a few, 2 - several and so on; additionally 0 - unknown)
+struct ArmyDescriptor : public std::map<SlotID, CStackBasicDescriptor>
+{
+	bool isDetailed;
+	DLL_LINKAGE ArmyDescriptor(const CArmedInstance *army, bool detailed); //not detailed -> quantity ids as count
+	DLL_LINKAGE ArmyDescriptor();
+
+	DLL_LINKAGE int getStrength() const;
+};
+
+struct DLL_LINKAGE InfoAboutArmy
+{
+	PlayerColor owner;
+	std::string name;
+
+	ArmyDescriptor army;
+
+	InfoAboutArmy();
+	InfoAboutArmy(const CArmedInstance *Army, bool detailed);
+
+	void initFromArmy(const CArmedInstance *Army, bool detailed);
+};
+
+struct DLL_LINKAGE InfoAboutHero : public InfoAboutArmy
+{
+private:
+	void assign(const InfoAboutHero & iah);
+
+public:
+	struct DLL_LINKAGE Details
+	{
+		std::vector<si32> primskills;
+		si32 mana, manaLimit, luck, morale;
+	};
+
+	Details * details = nullptr;
+
+	const CHeroClass *hclass;
+	int portrait;
+
+	enum EInfoLevel
+	{
+		BASIC,
+		DETAILED,
+		INBATTLE
+	};
+
+	InfoAboutHero();
+	InfoAboutHero(const InfoAboutHero & iah);
+	InfoAboutHero(const CGHeroInstance *h, EInfoLevel infoLevel);
+	~InfoAboutHero();
+
+	InfoAboutHero & operator=(const InfoAboutHero & iah);
+
+	void initFromHero(const CGHeroInstance *h, EInfoLevel infoLevel);
+};
+
+/// Struct which holds a int information about a town
+struct DLL_LINKAGE InfoAboutTown : public InfoAboutArmy
+{
+	struct DLL_LINKAGE Details
+	{
+		si32 hallLevel, goldIncome;
+		bool customRes;
+		bool garrisonedHero;
+
+	} *details;
+
+	const CTown *tType;
+
+	si32 built;
+	si32 fortLevel; //0 - none
+
+	InfoAboutTown();
+	InfoAboutTown(const CGTownInstance *t, bool detailed);
+	~InfoAboutTown();
+	void initFromTown(const CGTownInstance *t, bool detailed);
+};
+
+VCMI_LIB_NAMESPACE_END

+ 55 - 0
lib/gameState/QuestInfo.h

@@ -0,0 +1,55 @@
+/*
+ * QuestInfo.h, part of VCMI engine
+ *
+ * Authors: listed in file AUTHORS in main folder
+ *
+ * License: GNU General Public License v2.0 or later
+ * Full text of license available in license.txt file, in main folder
+ *
+ */
+#pragma once
+
+#include "int3.h"
+
+VCMI_LIB_NAMESPACE_BEGIN
+
+class CQuest;
+class CGObjectInstance;
+
+struct DLL_LINKAGE QuestInfo //universal interface for human and AI
+{
+	const CQuest * quest;
+	const CGObjectInstance * obj; //related object, most likely Seer Hut
+	int3 tile;
+
+	QuestInfo()
+		: quest(nullptr), obj(nullptr), tile(-1,-1,-1)
+	{};
+	QuestInfo (const CQuest * Quest, const CGObjectInstance * Obj, int3 Tile) :
+		quest (Quest), obj (Obj), tile (Tile){};
+
+	QuestInfo (const QuestInfo &qi) : quest(qi.quest), obj(qi.obj), tile(qi.tile)
+	{};
+
+	const QuestInfo& operator= (const QuestInfo &qi)
+	{
+		quest = qi.quest;
+		obj = qi.obj;
+		tile = qi.tile;
+		return *this;
+	}
+
+	bool operator== (const QuestInfo & qi) const
+	{
+		return (quest == qi.quest && obj == qi.obj);
+	}
+
+	template <typename Handler> void serialize(Handler &h, const int version)
+	{
+		h & quest;
+		h & obj;
+		h & tile;
+	}
+};
+
+VCMI_LIB_NAMESPACE_END

+ 1 - 1
lib/mapObjects/CArmedInstance.cpp

@@ -14,7 +14,7 @@
 #include "../CTownHandler.h"
 #include "../CCreatureHandler.h"
 #include "../CGeneralTextHandler.h"
-#include "../CGameState.h"
+#include "../gameState/CGameState.h"
 #include "../CPlayerState.h"
 
 VCMI_LIB_NAMESPACE_BEGIN

+ 1 - 1
lib/mapObjects/CBank.cpp

@@ -20,7 +20,7 @@
 #include "../mapObjectConstructors/CObjectClassesHandler.h"
 #include "../mapObjectConstructors/CBankInstanceConstructor.h"
 #include "../IGameCallback.h"
-#include "../CGameState.h"
+#include "../gameState/CGameState.h"
 
 VCMI_LIB_NAMESPACE_BEGIN
 

+ 1 - 1
lib/mapObjects/CGDwelling.cpp

@@ -15,7 +15,7 @@
 #include "../mapObjectConstructors/CObjectClassesHandler.h"
 #include "../CTownHandler.h"
 #include "../IGameCallback.h"
-#include "../CGameState.h"
+#include "../gameState/CGameState.h"
 #include "../CPlayerState.h"
 #include "../NetPacks.h"
 #include "../GameSettings.h"

+ 1 - 1
lib/mapObjects/CGHeroInstance.cpp

@@ -26,7 +26,7 @@
 #include "../spells/CSpellHandler.h"
 #include "../CSkillHandler.h"
 #include "../IGameCallback.h"
-#include "../CGameState.h"
+#include "../gameState/CGameState.h"
 #include "../CCreatureHandler.h"
 #include "../CTownHandler.h"
 #include "../mapping/CMap.h"

+ 0 - 1
lib/mapObjects/CGMarket.cpp

@@ -15,7 +15,6 @@
 #include "../CGeneralTextHandler.h"
 #include "../IGameCallback.h"
 #include "../CCreatureHandler.h"
-#include "../CGameState.h"
 #include "CGTownInstance.h"
 #include "../GameSettings.h"
 #include "../CSkillHandler.h"

+ 1 - 1
lib/mapObjects/CGObjectInstance.cpp

@@ -14,7 +14,7 @@
 #include "CGHeroInstance.h"
 #include "ObjectTemplate.h"
 
-#include "../CGameState.h"
+#include "../gameState/CGameState.h"
 #include "../CGeneralTextHandler.h"
 #include "../IGameCallback.h"
 #include "../NetPacks.h"

+ 1 - 1
lib/mapObjects/CGTownBuilding.cpp

@@ -14,7 +14,7 @@
 #include "../CGeneralTextHandler.h"
 #include "../NetPacks.h"
 #include "../IGameCallback.h"
-#include "../CGameState.h"
+#include "../gameState/CGameState.h"
 
 VCMI_LIB_NAMESPACE_BEGIN
 

+ 1 - 1
lib/mapObjects/CGTownInstance.cpp

@@ -19,7 +19,7 @@
 #include "../CGeneralTextHandler.h"
 #include "../CModHandler.h"
 #include "../IGameCallback.h"
-#include "../CGameState.h"
+#include "../gameState/CGameState.h"
 #include "../mapping/CMap.h"
 #include "../CPlayerState.h"
 #include "../TerrainHandler.h"

+ 0 - 1
lib/mapObjects/CQuest.cpp

@@ -20,7 +20,6 @@
 #include "../CHeroHandler.h"
 #include "CGCreature.h"
 #include "../IGameCallback.h"
-#include "../CGameState.h"
 #include "../mapObjectConstructors/CObjectClassesHandler.h"
 #include "../serializer/JsonSerializeFormat.h"
 #include "../CModHandler.h"

+ 1 - 1
lib/mapObjects/CRewardableObject.cpp

@@ -10,7 +10,7 @@
 
 #include "StdInc.h"
 #include "CRewardableObject.h"
-#include "../CGameState.h"
+#include "../gameState/CGameState.h"
 #include "../CGeneralTextHandler.h"
 #include "../CPlayerState.h"
 #include "../IGameCallback.h"

+ 1 - 1
lib/mapObjects/MiscObjects.cpp

@@ -19,7 +19,7 @@
 #include "../CSkillHandler.h"
 #include "../spells/CSpellHandler.h"
 #include "../IGameCallback.h"
-#include "../CGameState.h"
+#include "../gameState/CGameState.h"
 #include "../mapping/CMap.h"
 #include "../CPlayerState.h"
 #include "../serializer/JsonSerializeFormat.h"

+ 1 - 1
lib/pathfinder/CGPathNode.cpp

@@ -12,7 +12,7 @@
 
 #include "CPathfinder.h"
 
-#include "../CGameState.h"
+#include "../gameState/CGameState.h"
 #include "../mapObjects/CGHeroInstance.h"
 #include "../mapping/CMapDefines.h"
 

+ 1 - 1
lib/pathfinder/CPathfinder.cpp

@@ -15,7 +15,7 @@
 #include "PathfindingRules.h"
 #include "TurnInfo.h"
 
-#include "../CGameState.h"
+#include "../gameState/CGameState.h"
 #include "../CPlayerState.h"
 #include "../TerrainHandler.h"
 #include "../mapObjects/CGHeroInstance.h"

+ 1 - 1
lib/pathfinder/PathfinderUtil.h

@@ -12,7 +12,7 @@
 #include "../TerrainHandler.h"
 #include "../mapObjects/CGObjectInstance.h"
 #include "../mapping/CMapDefines.h"
-#include "../CGameState.h"
+#include "../gameState/CGameState.h"
 #include "CGPathNode.h"
 
 VCMI_LIB_NAMESPACE_BEGIN

+ 0 - 1
lib/registerTypes/RegisterTypes.cpp

@@ -13,7 +13,6 @@
 
 #include "../mapping/CMapInfo.h"
 #include "../StartInfo.h"
-#include "../CGameState.h"
 #include "../mapObjects/CObjectHandler.h"
 #include "../CCreatureHandler.h"
 #include "../spells/CSpellHandler.h"

+ 0 - 1
lib/registerTypes/TypesClientPacks1.cpp

@@ -11,7 +11,6 @@
 #include "RegisterTypes.h"
 
 #include "../StartInfo.h"
-#include "../CGameState.h"
 #include "../CModHandler.h"
 #include "../mapObjects/CObjectHandler.h"
 #include "../CCreatureHandler.h"

+ 0 - 1
lib/registerTypes/TypesClientPacks2.cpp

@@ -13,7 +13,6 @@
 #include "../StartInfo.h"
 #include "../CStack.h"
 #include "../battle/BattleInfo.h"
-#include "../CGameState.h"
 #include "../CModHandler.h"
 #include "../mapObjects/CObjectHandler.h"
 #include "../CCreatureHandler.h"

+ 1 - 1
lib/registerTypes/TypesLobbyPacks.cpp

@@ -12,7 +12,7 @@
 
 #include "../mapping/CMapInfo.h"
 #include "../StartInfo.h"
-#include "../CGameState.h"
+#include "../gameState/CGameState.h"
 #include "../mapping/CMap.h"
 #include "../CModHandler.h"
 #include "../mapObjects/CObjectHandler.h"

+ 0 - 1
lib/registerTypes/TypesMapObjects1.cpp

@@ -11,7 +11,6 @@
 #include "RegisterTypes.h"
 
 #include "../StartInfo.h"
-#include "../CGameState.h"
 #include "../CModHandler.h"
 #include "../mapObjects/CObjectHandler.h"
 #include "../CCreatureHandler.h"

+ 0 - 1
lib/registerTypes/TypesMapObjects2.cpp

@@ -13,7 +13,6 @@
 #include "../StartInfo.h"
 #include "../CStack.h"
 #include "../battle/BattleInfo.h"
-#include "../CGameState.h"
 #include "../CModHandler.h"
 #include "../mapObjects/CObjectHandler.h"
 #include "../CCreatureHandler.h"

+ 0 - 1
lib/registerTypes/TypesMapObjects3.cpp

@@ -11,7 +11,6 @@
 #include "RegisterTypes.h"
 
 #include "../StartInfo.h"
-#include "../CGameState.h"
 #include "../CModHandler.h"
 #include "../mapObjects/CObjectHandler.h"
 #include "../CCreatureHandler.h"

+ 0 - 1
lib/registerTypes/TypesServerPacks.cpp

@@ -11,7 +11,6 @@
 #include "RegisterTypes.h"
 
 #include "../StartInfo.h"
-#include "../CGameState.h"
 #include "../CModHandler.h"
 #include "../mapObjects/CObjectHandler.h"
 #include "../CCreatureHandler.h"

+ 0 - 1
lib/rewardable/Limiter.cpp

@@ -12,7 +12,6 @@
 #include "Limiter.h"
 
 #include "../IGameCallback.h"
-#include "../CGameStateFwd.h"
 #include "../CPlayerState.h"
 #include "../mapObjects/CGHeroInstance.h"
 

+ 1 - 1
lib/serializer/CSerializer.cpp

@@ -10,7 +10,7 @@
 #include "StdInc.h"
 #include "CSerializer.h"
 
-#include "../CGameState.h"
+#include "../gameState/CGameState.h"
 #include "../mapping/CMap.h"
 #include "../CHeroHandler.h"
 #include "../mapObjects/CGHeroInstance.h"

+ 0 - 1
lib/serializer/Connection.cpp

@@ -12,7 +12,6 @@
 
 #include "../registerTypes/RegisterTypes.h"
 #include "../mapping/CMapHeader.h"
-#include "../CGameState.h"
 
 #include <boost/asio.hpp>
 

+ 0 - 1
mapeditor/graphics.cpp

@@ -29,7 +29,6 @@
 #include "../CCallback.h"
 #include "../lib/CGeneralTextHandler.h"
 #include "BitmapHandler.h"
-#include "../lib/CGameState.h"
 #include "../lib/JsonNode.h"
 #include "../lib/CStopWatch.h"
 #include "../lib/mapObjectConstructors/AObjectTypeHandler.h"

+ 1 - 1
server/CGameHandler.cpp

@@ -31,7 +31,7 @@
 #include "../lib/CGeneralTextHandler.h"
 #include "../lib/CTownHandler.h"
 #include "../lib/CCreatureHandler.h"
-#include "../lib/CGameState.h"
+#include "../lib/gameState/CGameState.h"
 #include "../lib/CStack.h"
 #include "../lib/GameSettings.h"
 #include "../lib/battle/BattleInfo.h"

+ 1 - 1
server/CVCMIServer.cpp

@@ -57,7 +57,7 @@
 #include <boost/uuid/uuid_io.hpp>
 #include <boost/uuid/uuid_generators.hpp>
 
-#include "../lib/CGameState.h"
+#include "../lib/gameState/CGameState.h"
 
 template<typename T> class CApplyOnServer;
 

+ 1 - 1
server/NetPacksServer.cpp

@@ -13,7 +13,7 @@
 #include "CGameHandler.h"
 #include "../lib/IGameCallback.h"
 #include "../lib/mapObjects/CGTownInstance.h"
-#include "../lib/CGameState.h"
+#include "../lib/gameState/CGameState.h"
 #include "../lib/battle/BattleInfo.h"
 #include "../lib/battle/BattleAction.h"
 #include "../lib/battle/Unit.h"

+ 1 - 1
server/ServerSpellCastEnvironment.cpp

@@ -8,7 +8,7 @@
  *
  */
 #include "StdInc.h"
-#include "../lib/CGameState.h"
+#include "../lib/gameState/CGameState.h"
 #include "CGameHandler.h"
 #include "ServerSpellCastEnvironment.h"
 

+ 1 - 1
test/game/CGameStateTest.cpp

@@ -15,7 +15,7 @@
 #include "mock/mock_spells_Problem.h"
 
 #include "../../lib/VCMIDirs.h"
-#include "../../lib/CGameState.h"
+#include "../../lib/gameState/CGameState.h"
 #include "../../lib/NetPacks.h"
 #include "../../lib/StartInfo.h"
 #include "../../lib/TerrainHandler.h"

+ 1 - 1
test/netpacks/NetPackFixture.h

@@ -11,7 +11,7 @@
 #pragma once
 
 #include "../../lib/NetPacks.h"
-#include "../../lib/CGameState.h"
+#include "../../lib/gameState/CGameState.h"
 
 namespace test
 {