Przeglądaj źródła

Removed pointer to army from StackInstance

Ivan Savenko 7 miesięcy temu
rodzic
commit
63d00b080e
80 zmienionych plików z 260 dodań i 280 usunięć
  1. 2 0
      AI/BattleAI/AttackPossibility.cpp
  2. 1 0
      AI/BattleAI/BattleEvaluator.cpp
  3. 3 1
      AI/BattleAI/BattleExchangeVariant.cpp
  4. 1 1
      AI/Nullkiller/AIGateway.cpp
  5. 3 3
      AI/Nullkiller/Helpers/ArmyFormation.cpp
  6. 1 1
      AI/VCAI/VCAI.cpp
  7. 6 5
      client/ArtifactsUIController.cpp
  8. 1 1
      client/NetPacksClient.cpp
  9. 1 0
      client/adventureMap/CInfoBar.cpp
  10. 1 0
      client/adventureMap/CList.cpp
  11. 1 0
      client/battle/BattleActionsController.cpp
  12. 4 2
      client/battle/BattleEffectsController.cpp
  13. 7 5
      client/battle/BattleInterface.cpp
  14. 1 0
      client/battle/BattleInterfaceClasses.cpp
  15. 6 4
      client/battle/BattleStacksController.cpp
  16. 9 7
      client/battle/BattleWindow.cpp
  17. 6 7
      client/lobby/CBonusSelection.cpp
  18. 6 8
      client/mainmenu/CCampaignScreen.cpp
  19. 5 3
      client/widgets/CComponentHolder.cpp
  20. 1 0
      client/widgets/CGarrisonInt.cpp
  21. 1 0
      client/widgets/MiscWidgets.cpp
  22. 1 0
      client/widgets/markets/CAltarArtifacts.cpp
  23. 1 0
      client/widgets/markets/CAltarCreatures.cpp
  24. 1 0
      client/widgets/markets/CArtifactsBuying.cpp
  25. 1 0
      client/widgets/markets/CArtifactsSelling.cpp
  26. 2 1
      client/widgets/markets/CFreelancerGuild.cpp
  27. 2 1
      client/widgets/markets/CMarketBase.cpp
  28. 1 0
      client/widgets/markets/TradePanels.cpp
  29. 2 1
      client/windows/CCastleInterface.cpp
  30. 19 14
      client/windows/CCreatureWindow.cpp
  31. 2 1
      client/windows/CCreatureWindow.h
  32. 1 0
      client/windows/CExchangeWindow.cpp
  33. 1 0
      client/windows/CHeroBackpackWindow.cpp
  34. 3 2
      client/windows/CHeroWindow.cpp
  35. 4 3
      client/windows/CKingdomInterface.cpp
  36. 4 3
      client/windows/CMarketWindow.cpp
  37. 3 1
      client/windows/CQuestLog.cpp
  38. 3 2
      client/windows/CSpellWindow.cpp
  39. 3 2
      client/windows/CWindowWithArtifacts.cpp
  40. 1 0
      client/windows/GUIClasses.cpp
  41. 1 1
      lib/ArtifactUtils.cpp
  42. 50 38
      lib/CCreatureSet.cpp
  43. 19 19
      lib/CCreatureSet.h
  44. 4 3
      lib/CStack.cpp
  45. 15 15
      lib/CStack.h
  46. 2 1
      lib/battle/BattleInfo.cpp
  47. 1 0
      lib/battle/CBattleInfoCallback.cpp
  48. 4 4
      lib/gameState/CGameState.cpp
  49. 1 0
      lib/gameState/InfoAboutArmy.cpp
  50. 1 0
      lib/mapObjectConstructors/CRewardableConstructor.cpp
  51. 2 2
      lib/mapObjectConstructors/DwellingInstanceConstructor.cpp
  52. 1 0
      lib/mapObjectConstructors/HillFortInstanceConstructor.cpp
  53. 1 0
      lib/mapObjectConstructors/ShipyardInstanceConstructor.cpp
  54. 2 1
      lib/mapObjects/CArmedInstance.cpp
  55. 2 0
      lib/mapObjects/CArmedInstance.h
  56. 1 1
      lib/mapObjects/CGCreature.cpp
  57. 2 2
      lib/mapObjects/CGHeroInstance.cpp
  58. 1 1
      lib/mapObjects/CGTownInstance.cpp
  59. 1 1
      lib/mapObjects/CRewardableObject.cpp
  60. 1 1
      lib/mapObjects/MiscObjects.cpp
  61. 1 0
      lib/mapping/CMapInfo.cpp
  62. 2 2
      lib/mapping/MapFormatH3M.cpp
  63. 1 1
      lib/networkPacks/NetPacksLib.cpp
  64. 1 0
      lib/rewardable/Info.cpp
  65. 1 1
      lib/rewardable/Interface.cpp
  66. 1 1
      lib/rmg/modificators/ObjectManager.cpp
  67. 0 46
      lib/serializer/BinaryDeserializer.h
  68. 0 35
      lib/serializer/BinarySerializer.h
  69. 0 1
      lib/serializer/CSerializer.h
  70. 0 15
      lib/serializer/Connection.cpp
  71. 0 2
      lib/serializer/Connection.h
  72. 1 0
      lib/spells/CSpellHandler.cpp
  73. 2 1
      mapeditor/inspector/armywidget.cpp
  74. 2 0
      mapeditor/inspector/artifactwidget.cpp
  75. 4 2
      mapeditor/inspector/heroskillswidget.cpp
  76. 2 0
      mapeditor/inspector/herospellwidget.cpp
  77. 1 1
      mapeditor/inspector/inspector.cpp
  78. 2 0
      mapeditor/inspector/portraitwidget.cpp
  79. 2 0
      mapeditor/inspector/townspellswidget.cpp
  80. 3 3
      server/CGameHandler.cpp

+ 2 - 0
AI/BattleAI/AttackPossibility.cpp

@@ -17,6 +17,8 @@
 #include "../../lib/spells/ObstacleCasterProxy.h"
 #include "../../lib/battle/CObstacleInstance.h"
 
+#include "../../lib/GameLibrary.h"
+
 uint64_t averageDmg(const DamageRange & range)
 {
 	return (range.min + range.max) / 2;

+ 1 - 0
AI/BattleAI/BattleEvaluator.cpp

@@ -24,6 +24,7 @@
 #include "../../lib/battle/CObstacleInstance.h"
 #include "../../lib/battle/BattleAction.h"
 #include "../../lib/CRandomGenerator.h"
+#include "../../lib/GameLibrary.h"
 
 
 // TODO: remove

+ 3 - 1
AI/BattleAI/BattleExchangeVariant.cpp

@@ -11,7 +11,9 @@
 #include "BattleExchangeVariant.h"
 #include "BattleEvaluator.h"
 #include "../../lib/CStack.h"
-#include "tbb/parallel_for.h"
+#include "../../lib/GameLibrary.h"
+
+#include <tbb/parallel_for.h>
 
 AttackerValue::AttackerValue()
 	: value(0),

+ 1 - 1
AI/Nullkiller/AIGateway.cpp

@@ -628,7 +628,7 @@ void AIGateway::commanderGotLevel(const CCommanderInstance * commander, std::vec
 {
 	LOG_TRACE_PARAMS(logAi, "queryID '%i'", queryID);
 	NET_EVENT_HANDLER;
-	status.addQuery(queryID, boost::str(boost::format("Commander %s of %s got level %d") % commander->name % commander->armyObj->nodeName() % (int)commander->level));
+	status.addQuery(queryID, boost::str(boost::format("Commander %s of %s got level %d") % commander->name % commander->getArmy()->nodeName() % (int)commander->level));
 	executeActionAsync("commanderGotLevel", [this, queryID](){ answerQuery(queryID, 0); });
 }
 

+ 3 - 3
AI/Nullkiller/Helpers/ArmyFormation.cpp

@@ -48,14 +48,14 @@ void ArmyFormation::rearrangeArmyForSiege(const CGTownInstance * town, const CGH
 
 	if(town->fortLevel() > CGTownInstance::FORT)
 	{
-		std::vector<CStackInstance *> stacks;
+		std::vector<const CStackInstance *> stacks;
 
 		for(const auto & slot : attacker->Slots())
 			stacks.push_back(slot.second.get());
 
 		boost::sort(
 			stacks,
-			[](CStackInstance * slot1, CStackInstance * slot2) -> bool
+			[](const CStackInstance * slot1, const CStackInstance * slot2) -> bool
 			{
 				auto cre1 = slot1->getCreatureID().toCreature();
 				auto cre2 = slot2->getCreatureID().toCreature();
@@ -67,7 +67,7 @@ void ArmyFormation::rearrangeArmyForSiege(const CGTownInstance * town, const CGH
 
 		for(int i = 0; i < stacks.size(); i++)
 		{
-			auto pos = stacks[i]->armyObj->findStack(stacks[i]);
+			auto pos = stacks[i]->getArmy()->findStack(stacks[i]);
 
 			if(pos.getNum() != i)
 				cb->swapCreatures(attacker, attacker, static_cast<SlotID>(i), pos);

+ 1 - 1
AI/VCAI/VCAI.cpp

@@ -673,7 +673,7 @@ void VCAI::commanderGotLevel(const CCommanderInstance * commander, std::vector<u
 {
 	LOG_TRACE_PARAMS(logAi, "queryID '%i'", queryID);
 	NET_EVENT_HANDLER;
-	status.addQuery(queryID, boost::str(boost::format("Commander %s of %s got level %d") % commander->name % commander->armyObj->nodeName() % (int)commander->level));
+	status.addQuery(queryID, boost::str(boost::format("Commander %s of %s got level %d") % commander->name % commander->getArmy()->nodeName() % (int)commander->level));
 	executeActionAsync("commanderGotLevel", [this, queryID](){ answerQuery(queryID, 0); });
 }
 

+ 6 - 5
client/ArtifactsUIController.cpp

@@ -12,17 +12,18 @@
 #include "ArtifactsUIController.h"
 #include "CPlayerInterface.h"
 
-#include "../CCallback.h"
-#include "../lib/ArtifactUtils.h"
-#include "../lib/texts/CGeneralTextHandler.h"
-#include "../lib/mapObjects/CGHeroInstance.h"
-
 #include "GameEngine.h"
 #include "GameInstance.h"
 #include "gui/WindowHandler.h"
 #include "widgets/CComponent.h"
 #include "windows/CWindowWithArtifacts.h"
 
+#include "../CCallback.h"
+#include "../lib/ArtifactUtils.h"
+#include "../lib/GameLibrary.h"
+#include "../lib/mapObjects/CGHeroInstance.h"
+#include "../lib/texts/CGeneralTextHandler.h"
+
 ArtifactsUIController::ArtifactsUIController()
 {
 	numOfMovedArts = 0;

+ 1 - 1
client/NetPacksClient.cpp

@@ -705,7 +705,7 @@ void ApplyClientNetPackVisitor::visitCommanderLevelUp(CommanderLevelUp & pack)
 	assert(hero);
 	const auto & commander = hero->getCommander();
 	assert(commander);
-	assert(commander->armyObj); //is it possible for Commander to exist beyond armed instance?
+	assert(commander->getArmy()); //is it possible for Commander to exist beyond armed instance?
 	callOnlyThatInterface(cl, pack.player, &CGameInterface::commanderGotLevel, commander, pack.skills, pack.queryID);
 }
 

+ 1 - 0
client/adventureMap/CInfoBar.cpp

@@ -29,6 +29,7 @@
 
 #include "../../CCallback.h"
 #include "../../lib/CConfigHandler.h"
+#include "../../lib/GameLibrary.h"
 #include "../../lib/texts/CGeneralTextHandler.h"
 #include "../../lib/mapObjects/CGHeroInstance.h"
 #include "../../lib/mapObjects/CGTownInstance.h"

+ 1 - 0
client/adventureMap/CList.cpp

@@ -30,6 +30,7 @@
 
 #include "../../lib/texts/CGeneralTextHandler.h"
 #include "../../lib/IGameSettings.h"
+#include "../../lib/GameLibrary.h"
 #include "../../lib/mapObjects/CGHeroInstance.h"
 #include "../../lib/mapObjects/CGTownInstance.h"
 

+ 1 - 0
client/battle/BattleActionsController.cpp

@@ -28,6 +28,7 @@
 
 #include "../../CCallback.h"
 #include "../../lib/CConfigHandler.h"
+#include "../../lib/GameLibrary.h"
 #include "../../lib/texts/CGeneralTextHandler.h"
 #include "../../lib/CRandomGenerator.h"
 #include "../../lib/CStack.h"

+ 4 - 2
client/battle/BattleEffectsController.cpp

@@ -26,11 +26,13 @@
 #include "../render/Graphics.h"
 
 #include "../../CCallback.h"
+
+#include "../../lib/CStack.h"
+#include "../../lib/GameLibrary.h"
+#include "../../lib/IGameEventsReceiver.h"
 #include "../../lib/battle/BattleAction.h"
 #include "../../lib/filesystem/ResourcePath.h"
 #include "../../lib/networkPacks/PacksForClientBattle.h"
-#include "../../lib/CStack.h"
-#include "../../lib/IGameEventsReceiver.h"
 #include "../../lib/texts/CGeneralTextHandler.h"
 
 BattleEffectsController::BattleEffectsController(BattleInterface & owner):

+ 7 - 5
client/battle/BattleInterface.cpp

@@ -35,16 +35,18 @@
 #include "../adventureMap/AdventureMapInterface.h"
 
 #include "../../CCallback.h"
+
 #include "../../lib/BattleFieldHandler.h"
-#include "../../lib/CStack.h"
 #include "../../lib/CConfigHandler.h"
-#include "../../lib/texts/CGeneralTextHandler.h"
+#include "../../lib/CStack.h"
+#include "../../lib/CThreadHelper.h"
+#include "../../lib/GameLibrary.h"
+#include "../../lib/TerrainHandler.h"
+#include "../../lib/UnlockGuard.h"
 #include "../../lib/gameState/InfoAboutArmy.h"
 #include "../../lib/mapObjects/CGTownInstance.h"
 #include "../../lib/networkPacks/PacksForClientBattle.h"
-#include "../../lib/UnlockGuard.h"
-#include "../../lib/TerrainHandler.h"
-#include "../../lib/CThreadHelper.h"
+#include "../../lib/texts/CGeneralTextHandler.h"
 
 BattleInterface::BattleInterface(const BattleID & battleID, const CCreatureSet *army1, const CCreatureSet *army2,
 		const CGHeroInstance *hero1, const CGHeroInstance *hero2,

+ 1 - 0
client/battle/BattleInterfaceClasses.cpp

@@ -52,6 +52,7 @@
 #include "../../lib/CCreatureHandler.h"
 #include "../../lib/entities/hero/CHeroClass.h"
 #include "../../lib/entities/hero/CHero.h"
+#include "../../lib/GameLibrary.h"
 #include "../../lib/gameState/InfoAboutArmy.h"
 #include "../../lib/texts/CGeneralTextHandler.h"
 #include "../../lib/texts/TextOperations.h"

+ 6 - 4
client/battle/BattleStacksController.cpp

@@ -33,13 +33,15 @@
 #include "../render/IFont.h"
 
 #include "../../CCallback.h"
-#include "../../lib/spells/ISpellMechanics.h"
-#include "../../lib/battle/BattleAction.h"
-#include "../../lib/battle/BattleHex.h"
-#include "../../lib/texts/TextOperations.h"
+
 #include "../../lib/CConfigHandler.h"
 #include "../../lib/CRandomGenerator.h"
 #include "../../lib/CStack.h"
+#include "../../lib/GameLibrary.h"
+#include "../../lib/battle/BattleAction.h"
+#include "../../lib/battle/BattleHex.h"
+#include "../../lib/spells/ISpellMechanics.h"
+#include "../../lib/texts/TextOperations.h"
 
 static void onAnimationFinished(const CStack *stack, std::weak_ptr<CreatureAnimation> anim)
 {

+ 9 - 7
client/battle/BattleWindow.cpp

@@ -32,18 +32,20 @@
 #include "../render/IRenderHandler.h"
 #include "../adventureMap/CInGameConsole.h"
 #include "../adventureMap/TurnTimerWidget.h"
+#include "../windows/settings/SettingsMainWindow.h"
 
 #include "../../CCallback.h"
-#include "../../lib/texts/CGeneralTextHandler.h"
-#include "../../lib/gameState/InfoAboutArmy.h"
-#include "../../lib/mapObjects/CGHeroInstance.h"
-#include "../../lib/CStack.h"
+
 #include "../../lib/CConfigHandler.h"
-#include "../../lib/filesystem/ResourcePath.h"
+#include "../../lib/CPlayerState.h"
+#include "../../lib/CStack.h"
+#include "../../lib/GameLibrary.h"
 #include "../../lib/StartInfo.h"
 #include "../../lib/battle/BattleInfo.h"
-#include "../../lib/CPlayerState.h"
-#include "../windows/settings/SettingsMainWindow.h"
+#include "../../lib/filesystem/ResourcePath.h"
+#include "../../lib/gameState/InfoAboutArmy.h"
+#include "../../lib/mapObjects/CGHeroInstance.h"
+#include "../../lib/texts/CGeneralTextHandler.h"
 
 BattleWindow::BattleWindow(BattleInterface & Owner):
 	owner(Owner),

+ 6 - 7
client/lobby/CBonusSelection.cpp

@@ -43,7 +43,9 @@
 #include "../../lib/CConfigHandler.h"
 #include "../../lib/CCreatureHandler.h"
 #include "../../lib/CSkillHandler.h"
+#include "../../lib/GameLibrary.h"
 #include "../../lib/StartInfo.h"
+#include "../../lib/campaign/CampaignState.h"
 #include "../../lib/entities/building/CBuilding.h"
 #include "../../lib/entities/building/CBuildingHandler.h"
 #include "../../lib/entities/faction/CFaction.h"
@@ -51,14 +53,11 @@
 #include "../../lib/entities/faction/CTownHandler.h"
 #include "../../lib/entities/hero/CHeroHandler.h"
 #include "../../lib/filesystem/Filesystem.h"
-#include "../../lib/texts/CGeneralTextHandler.h"
-
-#include "../../lib/campaign/CampaignState.h"
-#include "../../lib/mapping/CMapService.h"
-#include "../../lib/mapping/CMapInfo.h"
-#include "../../lib/mapping/CMapHeader.h"
-
 #include "../../lib/mapObjects/CGHeroInstance.h"
+#include "../../lib/mapping/CMapHeader.h"
+#include "../../lib/mapping/CMapInfo.h"
+#include "../../lib/mapping/CMapService.h"
+#include "../../lib/texts/CGeneralTextHandler.h"
 
 std::shared_ptr<CampaignState> CBonusSelection::getCampaign()
 {

+ 6 - 8
client/mainmenu/CCampaignScreen.cpp

@@ -29,19 +29,17 @@
 #include "../windows/InfoWindows.h"
 #include "../windows/CWindowObject.h"
 
-#include "../../lib/filesystem/Filesystem.h"
-#include "../../lib/texts/CGeneralTextHandler.h"
-
 #include "../../lib/CArtHandler.h"
-#include "../../lib/spells/CSpellHandler.h"
 #include "../../lib/CConfigHandler.h"
-#include "../../lib/CSkillHandler.h"
 #include "../../lib/CCreatureHandler.h"
-
+#include "../../lib/CSkillHandler.h"
+#include "../../lib/GameLibrary.h"
 #include "../../lib/campaign/CampaignHandler.h"
-#include "../../lib/mapping/CMapService.h"
-
+#include "../../lib/filesystem/Filesystem.h"
 #include "../../lib/mapObjects/CGHeroInstance.h"
+#include "../../lib/mapping/CMapService.h"
+#include "../../lib/spells/CSpellHandler.h"
+#include "../../lib/texts/CGeneralTextHandler.h"
 
 CCampaignScreen::CCampaignScreen(const JsonNode & config, std::string name)
 	: CWindowObject(BORDERED), campaignSet(name)

+ 5 - 3
client/widgets/CComponentHolder.cpp

@@ -23,12 +23,14 @@
 #include "../CPlayerInterface.h"
 
 #include "../../CCallback.h"
-#include "../../lib/texts/CGeneralTextHandler.h"
+
 #include "../../lib/ArtifactUtils.h"
-#include "../../lib/mapObjects/CGHeroInstance.h"
-#include "../../lib/networkPacks/ArtifactLocation.h"
 #include "../../lib/CConfigHandler.h"
 #include "../../lib/CSkillHandler.h"
+#include "../../lib/GameLibrary.h"
+#include "../../lib/mapObjects/CGHeroInstance.h"
+#include "../../lib/networkPacks/ArtifactLocation.h"
+#include "../../lib/texts/CGeneralTextHandler.h"
 
 CComponentHolder::CComponentHolder(const Rect & area, const Point & selectionOversize)
 	: SelectableSlot(area, selectionOversize)

+ 1 - 0
client/widgets/CGarrisonInt.cpp

@@ -30,6 +30,7 @@
 #include "../../lib/texts/TextOperations.h"
 #include "../../lib/CCreatureHandler.h"
 #include "../../lib/CConfigHandler.h"
+#include "../../lib/GameLibrary.h"
 #include "../../lib/mapObjects/CGHeroInstance.h"
 #include "../../lib/networkPacks/ArtifactLocation.h"
 #include "../../lib/gameState/CGameState.h"

+ 1 - 0
client/widgets/MiscWidgets.cpp

@@ -33,6 +33,7 @@
 
 #include "../../lib/CConfigHandler.h"
 #include "../../lib/IGameSettings.h"
+#include "../../lib/GameLibrary.h"
 #include "../../lib/entities/faction/CTownHandler.h"
 #include "../../lib/gameState/InfoAboutArmy.h"
 #include "../../lib/mapObjects/CGCreature.h"

+ 1 - 0
client/widgets/markets/CAltarArtifacts.cpp

@@ -21,6 +21,7 @@
 
 #include "../../../CCallback.h"
 
+#include "../../../lib/GameLibrary.h"
 #include "../../../lib/networkPacks/ArtifactLocation.h"
 #include "../../../lib/texts/CGeneralTextHandler.h"
 #include "../../../lib/mapObjects/CGHeroInstance.h"

+ 1 - 0
client/widgets/markets/CAltarCreatures.cpp

@@ -21,6 +21,7 @@
 
 #include "../../../CCallback.h"
 
+#include "../../../lib/GameLibrary.h"
 #include "../../../lib/texts/CGeneralTextHandler.h"
 #include "../../../lib/mapObjects/CGHeroInstance.h"
 #include "../../../lib/mapObjects/IMarket.h"

+ 1 - 0
client/widgets/markets/CArtifactsBuying.cpp

@@ -20,6 +20,7 @@
 
 #include "../../../CCallback.h"
 
+#include "../../../lib/GameLibrary.h"
 #include "../../../lib/mapObjects/CGHeroInstance.h"
 #include "../../../lib/mapObjects/IMarket.h"
 #include "../../../lib/texts/CGeneralTextHandler.h"

+ 1 - 0
client/widgets/markets/CArtifactsSelling.cpp

@@ -22,6 +22,7 @@
 #include "../../../CCallback.h"
 
 #include "../../../lib/CArtifactInstance.h"
+#include "../../../lib/GameLibrary.h"
 #include "../../../lib/mapObjects/CGHeroInstance.h"
 #include "../../../lib/mapObjects/IMarket.h"
 #include "../../../lib/texts/CGeneralTextHandler.h"

+ 2 - 1
client/widgets/markets/CFreelancerGuild.cpp

@@ -21,9 +21,10 @@
 
 #include "../../../CCallback.h"
 
-#include "../../../lib/texts/CGeneralTextHandler.h"
+#include "../../../lib/GameLibrary.h"
 #include "../../../lib/mapObjects/CGHeroInstance.h"
 #include "../../../lib/mapObjects/IMarket.h"
+#include "../../../lib/texts/CGeneralTextHandler.h"
 
 CFreelancerGuild::CFreelancerGuild(const IMarket * market, const CGHeroInstance * hero)
 	: CMarketBase(market, hero)

+ 2 - 1
client/widgets/markets/CMarketBase.cpp

@@ -23,10 +23,11 @@
 
 #include "../../../CCallback.h"
 
+#include "../../../lib/GameLibrary.h"
 #include "../../../lib/entities/hero/CHeroHandler.h"
-#include "../../../lib/texts/CGeneralTextHandler.h"
 #include "../../../lib/mapObjects/CGHeroInstance.h"
 #include "../../../lib/mapObjects/CGMarket.h"
+#include "../../../lib/texts/CGeneralTextHandler.h"
 
 CMarketBase::CMarketBase(const IMarket * market, const CGHeroInstance * hero)
 	: market(market)

+ 1 - 0
client/widgets/markets/TradePanels.cpp

@@ -20,6 +20,7 @@
 
 #include "../../../CCallback.h"
 
+#include "../../../lib/GameLibrary.h"
 #include "../../../lib/texts/CGeneralTextHandler.h"
 #include "../../../lib/mapObjects/CGHeroInstance.h"
 

+ 2 - 1
client/windows/CCastleInterface.cpp

@@ -49,6 +49,7 @@
 #include "../../lib/CConfigHandler.h"
 #include "../../lib/CSoundBase.h"
 #include "../../lib/CCreatureHandler.h"
+#include "../../lib/GameLibrary.h"
 #include "../../lib/texts/CGeneralTextHandler.h"
 #include "../../lib/IGameSettings.h"
 #include "../../lib/spells/CSpellHandler.h"
@@ -348,7 +349,7 @@ auto CHeroGSlot::getUpgradableSlots(const CArmedInstance *obj) const
 	for(const auto & slot : obj->Slots())
 	{
 		auto upgradeInfo = std::make_pair(slot.first, UpgradeInfo(slot.second->getCreatureID()));
-		GAME->interface()->cb->fillUpgradeInfo(slot.second->armyObj, slot.first, upgradeInfo.second);
+		GAME->interface()->cb->fillUpgradeInfo(slot.second->getArmy(), slot.first, upgradeInfo.second);
 		bool canUpgrade = obj->tempOwner == GAME->interface()->playerID && upgradeInfo.second.canUpgrade();
 		if(canUpgrade)
 			upgradeInfos.push_back(upgradeInfo);

+ 19 - 14
client/windows/CCreatureWindow.cpp

@@ -29,17 +29,19 @@
 #include "../battle/BattleInterface.h"
 
 #include "../../CCallback.h"
+
 #include "../../lib/ArtifactUtils.h"
-#include "../../lib/CStack.h"
 #include "../../lib/CBonusTypeHandler.h"
+#include "../../lib/CStack.h"
+#include "../../lib/GameLibrary.h"
 #include "../../lib/IGameSettings.h"
+#include "../../lib/bonuses/Propagators.h"
 #include "../../lib/entities/hero/CHeroHandler.h"
 #include "../../lib/gameState/CGameState.h"
 #include "../../lib/gameState/UpgradeInfo.h"
 #include "../../lib/networkPacks/ArtifactLocation.h"
 #include "../../lib/texts/CGeneralTextHandler.h"
 #include "../../lib/texts/TextOperations.h"
-#include "../../lib/bonuses/Propagators.h"
 
 class CCreatureArtifactInstance;
 class CSelectableSkill;
@@ -736,7 +738,7 @@ void CStackWindow::MainSection::addStatLabel(EStat index, int64_t value)
 
 CStackWindow::CStackWindow(const CStack * stack, bool popup)
 	: CWindowObject(BORDERED | (popup ? RCLICK_POPUP : 0)),
-	info(new UnitView())
+	info(std::make_unique<UnitView>())
 {
 	info->stack = stack;
 	info->stackNode = stack->base;
@@ -749,7 +751,7 @@ CStackWindow::CStackWindow(const CStack * stack, bool popup)
 
 CStackWindow::CStackWindow(const CCreature * creature, bool popup)
 	: CWindowObject(BORDERED | (popup ? RCLICK_POPUP : 0)),
-	info(new UnitView())
+	info(std::make_unique<UnitView>())
 {
 	info->creature = creature;
 	info->popupWindow = popup;
@@ -758,19 +760,19 @@ CStackWindow::CStackWindow(const CCreature * creature, bool popup)
 
 CStackWindow::CStackWindow(const CStackInstance * stack, bool popup)
 	: CWindowObject(BORDERED | (popup ? RCLICK_POPUP : 0)),
-	info(new UnitView())
+	info(std::make_unique<UnitView>())
 {
 	info->stackNode = stack;
 	info->creature = stack->getCreature();
 	info->creatureCount = stack->count;
 	info->popupWindow = popup;
-	info->owner = dynamic_cast<const CGHeroInstance *> (stack->armyObj);
+	info->owner = dynamic_cast<const CGHeroInstance *> (stack->getArmy());
 	init();
 }
 
 CStackWindow::CStackWindow(const CStackInstance * stack, std::function<void()> dismiss, const UpgradeInfo & upgradeInfo, std::function<void(CreatureID)> callback)
 	: CWindowObject(BORDERED),
-	info(new UnitView())
+	info(std::make_unique<UnitView>())
 {
 	info->stackNode = stack;
 	info->creature = stack->getCreature();
@@ -784,26 +786,26 @@ CStackWindow::CStackWindow(const CStackInstance * stack, std::function<void()> d
 	
 	info->dismissInfo = std::make_optional(UnitView::StackDismissInfo());
 	info->dismissInfo->callback = dismiss;
-	info->owner = dynamic_cast<const CGHeroInstance *> (stack->armyObj);
+	info->owner = dynamic_cast<const CGHeroInstance *> (stack->getArmy());
 	init();
 }
 
 CStackWindow::CStackWindow(const CCommanderInstance * commander, bool popup)
 	: CWindowObject(BORDERED | (popup ? RCLICK_POPUP : 0)),
-	info(new UnitView())
+	info(std::make_unique<UnitView>())
 {
 	info->stackNode = commander;
 	info->creature = commander->getCreature();
 	info->commander = commander;
 	info->creatureCount = 1;
 	info->popupWindow = popup;
-	info->owner = dynamic_cast<const CGHeroInstance *> (commander->armyObj);
+	info->owner = dynamic_cast<const CGHeroInstance *> (commander->getArmy());
 	init();
 }
 
 CStackWindow::CStackWindow(const CCommanderInstance * commander, std::vector<ui32> &skills, std::function<void(ui32)> callback)
 	: CWindowObject(BORDERED),
-	info(new UnitView())
+	info(std::make_unique<UnitView>())
 {
 	info->stackNode = commander;
 	info->creature = commander->getCreature();
@@ -812,7 +814,7 @@ CStackWindow::CStackWindow(const CCommanderInstance * commander, std::vector<ui3
 	info->levelupInfo = std::make_optional(UnitView::CommanderLevelInfo());
 	info->levelupInfo->skills = skills;
 	info->levelupInfo->callback = callback;
-	info->owner = dynamic_cast<const CGHeroInstance *> (commander->armyObj);
+	info->owner = dynamic_cast<const CGHeroInstance *> (commander->getArmy());
 	init();
 }
 
@@ -827,7 +829,10 @@ void CStackWindow::init()
 	OBJECT_CONSTRUCTION;
 
 	if(!info->stackNode)
-		info->stackNode = new CStackInstance(info->creature, 1, true);// FIXME: free data
+	{
+		fakeNode = std::make_unique<CStackInstance>(nullptr, info->creature->getId(), 1, true);
+		info->stackNode = fakeNode.get();
+	}
 
 	selectedIcon = nullptr;
 	selectedSkill = -1;
@@ -1087,7 +1092,7 @@ void CStackWindow::removeStackArtifact(ArtifactPosition pos)
 	if(slot != ArtifactPosition::PRE_FIRST)
 	{
 		auto artLoc = ArtifactLocation(info->owner->id, pos);
-		artLoc.creature = info->stackNode->armyObj->findStack(info->stackNode);
+		artLoc.creature = info->stackNode->getArmy()->findStack(info->stackNode);
 		GAME->interface()->cb->swapArtifacts(artLoc, ArtifactLocation(info->owner->id, slot));
 		stackArtifactButton.reset();
 		stackArtifact.reset();

+ 2 - 1
client/windows/CCreatureWindow.h

@@ -165,7 +165,8 @@ class CStackWindow : public CWindowObject
 	std::shared_ptr<CButton> stackArtifactButton;
 
 
-	std::shared_ptr<UnitView> info;
+	std::unique_ptr<UnitView> info;
+	std::unique_ptr<CStackInstance> fakeNode;
 	std::vector<BonusInfo> activeBonuses;
 	size_t activeTab;
 	std::shared_ptr<CTabbedInt> commanderTab;

+ 1 - 0
client/windows/CExchangeWindow.cpp

@@ -30,6 +30,7 @@
 #include "../../CCallback.h"
 
 #include "../lib/CSkillHandler.h"
+#include "../lib/GameLibrary.h"
 #include "../lib/entities/hero/CHeroHandler.h"
 #include "../lib/filesystem/Filesystem.h"
 #include "../lib/mapObjects/CGHeroInstance.h"

+ 1 - 0
client/windows/CHeroBackpackWindow.cpp

@@ -23,6 +23,7 @@
 
 #include "../../CCallback.h"
 
+#include "../../lib/GameLibrary.h"
 #include "../../lib/mapObjects/CGHeroInstance.h"
 #include "../../lib/networkPacks/ArtifactLocation.h"
 #include "../../lib/texts/CGeneralTextHandler.h"

+ 3 - 2
client/windows/CHeroWindow.cpp

@@ -35,11 +35,12 @@
 #include "../lib/ArtifactUtils.h"
 #include "../lib/CArtHandler.h"
 #include "../lib/CConfigHandler.h"
-#include "../lib/entities/hero/CHeroHandler.h"
-#include "../lib/texts/CGeneralTextHandler.h"
 #include "../lib/CSkillHandler.h"
+#include "../lib/GameLibrary.h"
+#include "../lib/entities/hero/CHeroHandler.h"
 #include "../lib/mapObjects/CGHeroInstance.h"
 #include "../lib/networkPacks/ArtifactLocation.h"
+#include "../lib/texts/CGeneralTextHandler.h"
 
 void CHeroSwitcher::clickPressed(const Point & cursorPosition)
 {

+ 4 - 3
client/windows/CKingdomInterface.cpp

@@ -33,14 +33,15 @@
 
 #include "../../lib/CConfigHandler.h"
 #include "../../lib/CCreatureHandler.h"
-#include "../../lib/entities/hero/CHeroHandler.h"
-#include "../../lib/texts/CGeneralTextHandler.h"
-#include "../../lib/IGameSettings.h"
 #include "../../lib/CSkillHandler.h"
+#include "../../lib/GameLibrary.h"
+#include "../../lib/IGameSettings.h"
 #include "../../lib/StartInfo.h"
+#include "../../lib/entities/hero/CHeroHandler.h"
 #include "../../lib/mapObjects/CGHeroInstance.h"
 #include "../../lib/mapObjects/CGTownInstance.h"
 #include "../../lib/mapObjects/MiscObjects.h"
+#include "../../lib/texts/CGeneralTextHandler.h"
 
 static const std::string OVERVIEW_BACKGROUND = "OvCast.pcx";
 static const size_t OVERVIEW_SIZE = 4;

+ 4 - 3
client/windows/CMarketWindow.cpp

@@ -27,11 +27,12 @@
 
 #include "../CPlayerInterface.h"
 
+#include "../../lib/GameLibrary.h"
 #include "../../lib/entities/building/CBuilding.h"
-#include "../../lib/texts/CGeneralTextHandler.h"
-#include "../../lib/mapObjects/CGTownInstance.h"
-#include "../../lib/mapObjects/CGMarket.h"
 #include "../../lib/mapObjects/CGHeroInstance.h"
+#include "../../lib/mapObjects/CGMarket.h"
+#include "../../lib/mapObjects/CGTownInstance.h"
+#include "../../lib/texts/CGeneralTextHandler.h"
 
 #include "../../CCallback.h"
 

+ 3 - 1
client/windows/CQuestLog.cpp

@@ -24,11 +24,13 @@
 #include "../render/Canvas.h"
 
 #include "../../CCallback.h"
+
 #include "../../lib/CArtHandler.h"
 #include "../../lib/CConfigHandler.h"
+#include "../../lib/GameLibrary.h"
 #include "../../lib/gameState/QuestInfo.h"
-#include "../../lib/texts/CGeneralTextHandler.h"
 #include "../../lib/mapObjects/CQuest.h"
+#include "../../lib/texts/CGeneralTextHandler.h"
 
 VCMI_LIB_NAMESPACE_BEGIN
 

+ 3 - 2
client/windows/CSpellWindow.cpp

@@ -36,12 +36,13 @@
 #include "../../CCallback.h"
 
 #include "../../lib/CConfigHandler.h"
-#include "../../lib/texts/CGeneralTextHandler.h"
+#include "../../lib/GameConstants.h"
+#include "../../lib/GameLibrary.h"
 #include "../../lib/spells/CSpellHandler.h"
 #include "../../lib/spells/ISpellMechanics.h"
 #include "../../lib/spells/Problem.h"
+#include "../../lib/texts/CGeneralTextHandler.h"
 #include "../../lib/texts/TextOperations.h"
-#include "../../lib/GameConstants.h"
 
 #include "../../lib/mapObjects/CGHeroInstance.h"
 

+ 3 - 2
client/windows/CWindowWithArtifacts.cpp

@@ -28,10 +28,11 @@
 #include "../CPlayerInterface.h"
 
 #include "../../lib/ArtifactUtils.h"
-#include "../../lib/texts/CGeneralTextHandler.h"
+#include "../../lib/CConfigHandler.h"
+#include "../../lib/GameLibrary.h"
 #include "../../lib/mapObjects/CGHeroInstance.h"
 #include "../../lib/networkPacks/ArtifactLocation.h"
-#include "../../lib/CConfigHandler.h"
+#include "../../lib/texts/CGeneralTextHandler.h"
 
 #include "../../CCallback.h"
 

+ 1 - 0
client/windows/GUIClasses.cpp

@@ -43,6 +43,7 @@
 
 #include "../../CCallback.h"
 
+#include "../lib/GameLibrary.h"
 #include "../lib/entities/building/CBuilding.h"
 #include "../lib/entities/faction/CTownHandler.h"
 #include "../lib/entities/hero/CHeroHandler.h"

+ 1 - 1
lib/ArtifactUtils.cpp

@@ -13,7 +13,7 @@
 #include "CArtHandler.h"
 #include "IGameSettings.h"
 #include "spells/CSpellHandler.h"
-
+#include "GameLibrary.h"
 #include "mapObjects/CGHeroInstance.h"
 
 VCMI_LIB_NAMESPACE_BEGIN

+ 50 - 38
lib/CCreatureSet.cpp

@@ -23,6 +23,7 @@
 #include "spells/CSpellHandler.h"
 #include "IBonusTypeHandler.h"
 #include "serializer/JsonSerializeFormat.h"
+#include "gameState/CGameState.h"
 
 #include <vcmi/FactionService.h>
 #include <vcmi/Faction.h>
@@ -70,10 +71,10 @@ bool CCreatureSet::setCreature(SlotID slot, CreatureID type, TQuantity quantity)
 	if(hasStackAtSlot(slot)) //remove old creature
 		eraseStack(slot);
 
-	auto * armyObj = castToArmyObj();
+	auto * armyObj = getArmy();
 	bool isHypotheticArmy = armyObj ? armyObj->isHypothetic() : false;
 
-	putStack(slot, std::make_unique<CStackInstance>(type, quantity, isHypotheticArmy));
+	putStack(slot, std::make_unique<CStackInstance>(armyObj ? armyObj->cb : nullptr, type, quantity, isHypotheticArmy));
 	return true;
 }
 
@@ -511,17 +512,12 @@ SlotID CCreatureSet::findStack(const CStackInstance *stack) const
 	return SlotID();
 }
 
-CArmedInstance * CCreatureSet::castToArmyObj()
-{
-	return dynamic_cast<CArmedInstance *>(this);
-}
-
 void CCreatureSet::putStack(const SlotID & slot, std::unique_ptr<CStackInstance> stack)
 {
 	assert(slot.getNum() < GameConstants::ARMY_SIZE);
 	assert(!hasStackAtSlot(slot));
 	stacks[slot] = std::move(stack);
-	stack->setArmyObj(castToArmyObj());
+	stack->setArmy(getArmy());
 	armyChanged();
 }
 
@@ -552,7 +548,7 @@ void CCreatureSet::setToArmy(CSimpleArmy &src)
 	{
 		auto i = src.army.begin();
 
-		putStack(i->first, std::make_unique<CStackInstance>(i->second.first, i->second.second));
+		putStack(i->first, std::make_unique<CStackInstance>(getArmy()->cb, i->second.first, i->second.second));
 		src.army.erase(i);
 	}
 }
@@ -565,8 +561,8 @@ std::unique_ptr<CStackInstance> CCreatureSet::detachStack(const SlotID & slot)
 	//if(CArmedInstance *armedObj = castToArmyObj())
 	if(ret)
 	{
-		ret->setArmyObj(nullptr); //detaches from current armyobj
-		assert(!ret->armyObj); //we failed detaching?
+		ret->setArmy(nullptr); //detaches from current armyobj
+		assert(!ret->getArmy()); //we failed detaching?
 	}
 
 	stacks.erase(slot);
@@ -671,41 +667,33 @@ void CCreatureSet::serializeJson(JsonSerializeFormat & handler, const std::strin
 
 			if(amount > 0)
 			{
-				auto new_stack = std::make_unique<CStackInstance>();
-				new_stack->serializeJson(handler);
-				putStack(SlotID(static_cast<si32>(idx)), std::move(new_stack));
+				auto newStack = std::make_unique<CStackInstance>(getArmy()->cb);
+				newStack->serializeJson(handler);
+				putStack(SlotID(static_cast<si32>(idx)), std::move(newStack));
 			}
 		}
 	}
 }
 
-CStackInstance::CStackInstance(bool isHypothetic)
+CStackInstance::CStackInstance(IGameCallback *cb, bool isHypothetic)
 	: CBonusSystemNode(isHypothetic)
+	, GameCallbackHolder(cb)
 	, nativeTerrain(this, Selector::type()(BonusType::TERRAIN_NATIVE))
 	, initiative(this, Selector::type()(BonusType::STACKS_SPEED))
-	, armyObj(_armyObj)
 {
 	experience = 0;
 	count = 0;
 	setType(nullptr);
-	_armyObj = nullptr;
 	setNodeType(STACK_INSTANCE);
 }
 
-CStackInstance::CStackInstance(const CreatureID & id, TQuantity Count, bool isHypothetic)
-	: CStackInstance(false)
+CStackInstance::CStackInstance(IGameCallback *cb, const CreatureID & id, TQuantity Count, bool isHypothetic)
+	: CStackInstance(cb, false)
 {
 	setType(id);
 	count = Count;
 }
 
-CStackInstance::CStackInstance(const CCreature *cre, TQuantity Count, bool isHypothetic)
-	: CStackInstance(false)
-{
-	setType(cre);
-	count = Count;
-}
-
 CCreature::CreatureQuantityId CStackInstance::getQuantityID() const
 {
 	return CCreature::getQuantityID(count);
@@ -786,15 +774,35 @@ ImagePath CStackInstance::bonusToGraphics(const std::shared_ptr<Bonus> & bonus)
 	return LIBRARY->getBth()->bonusToGraphics(bonus);
 }
 
-void CStackInstance::setArmyObj(const CArmedInstance * ArmyObj)
+CArmedInstance * CStackInstance::getArmy()
 {
-	if(_armyObj)
-		detachFrom(const_cast<CArmedInstance&>(*_armyObj));
+	if (armyInstanceID.hasValue())
+		return dynamic_cast<CArmedInstance*>(cb->gameState()->getObjInstance(armyInstanceID));
+	return nullptr;
+}
 
-	_armyObj = ArmyObj;
+const CArmedInstance * CStackInstance::getArmy() const
+{
+	if (armyInstanceID.hasValue())
+		return dynamic_cast<const CArmedInstance*>(cb->getObjInstance(armyInstanceID));
+	return nullptr;
+}
+
+void CStackInstance::setArmy(const CArmedInstance * ArmyObj)
+{
+	auto oldArmy = getArmy();
+
+	if(oldArmy)
+	{
+		detachFrom(*oldArmy);
+		armyInstanceID = {};
+	}
 
 	if(ArmyObj)
-		attachTo(const_cast<CArmedInstance&>(*_armyObj));
+	{
+		attachTo(const_cast<CArmedInstance&>(*ArmyObj));
+		armyInstanceID = ArmyObj->id;
+	}
 }
 
 std::string CStackInstance::getQuantityTXT(bool capitalized) const
@@ -836,7 +844,8 @@ std::string CStackInstance::nodeName() const
 
 PlayerColor CStackInstance::getOwner() const
 {
-	return _armyObj ? _armyObj->getOwner() : PlayerColor::NEUTRAL;
+	auto army = getArmy();
+	return army ? army->getOwner() : PlayerColor::NEUTRAL;
 }
 
 int32_t CStackInstance::getInitiative(int turn) const
@@ -862,9 +871,9 @@ TerrainId CStackInstance::getCurrentTerrain() const
 
 void CStackInstance::deserializationFix()
 {
-	const CArmedInstance *armyBackup = _armyObj;
-	_armyObj = nullptr;
-	setArmyObj(armyBackup);
+	const CArmedInstance *armyBackup = getArmy();
+	armyInstanceID = {};
+	setArmy(armyBackup);
 	artDeserializationFix(this);
 }
 
@@ -960,16 +969,19 @@ const IBonusBearer* CStackInstance::getBonusBearer() const
 	return this;
 }
 
-CCommanderInstance::CCommanderInstance() = default;
+CCommanderInstance::CCommanderInstance(IGameCallback *cb)
+	:CStackInstance(cb)
+{}
 
-CCommanderInstance::CCommanderInstance(const CreatureID & id): name("Commando")
+CCommanderInstance::CCommanderInstance(IGameCallback *cb, const CreatureID & id)
+	: CStackInstance(cb)
+	, name("Commando")
 {
 	alive = true;
 	experience = 0;
 	level = 1;
 	count = 1;
 	setType(nullptr);
-	_armyObj = nullptr;
 	setNodeType (CBonusSystemNode::COMMANDER);
 	secondarySkills.resize (ECommander::SPELL_POWER + 1);
 	setType(id);

+ 19 - 19
lib/CCreatureSet.h

@@ -9,15 +9,15 @@
  */
 #pragma once
 
+#include "CArtHandler.h"
+#include "CArtifactInstance.h"
+#include "CCreatureHandler.h"
+#include "GameCallbackHolder.h"
+#include "GameConstants.h"
 #include "bonuses/Bonus.h"
 #include "bonuses/BonusCache.h"
 #include "bonuses/CBonusSystemNode.h"
 #include "serializer/Serializeable.h"
-#include "GameConstants.h"
-#include "CArtHandler.h"
-#include "CArtifactInstance.h"
-#include "CCreatureHandler.h"
-#include "GameLibrary.h"
 
 #include <vcmi/Entity.h>
 
@@ -70,13 +70,12 @@ public:
 	void serializeJson(JsonSerializeFormat & handler);
 };
 
-class DLL_LINKAGE CStackInstance : public CBonusSystemNode, public CStackBasicDescriptor, public CArtifactSet, public ACreature
+class DLL_LINKAGE CStackInstance : public CBonusSystemNode, public CStackBasicDescriptor, public CArtifactSet, public ACreature, public GameCallbackHolder
 {
 	BonusValueCache nativeTerrain;
 	BonusValueCache initiative;
 
-protected:
-	const CArmedInstance *_armyObj; //stack must be part of some army, army must be part of some object
+	ObjectInstanceID armyInstanceID; //stack must be part of some army, army must be part of some object
 
 public:
 	struct RandomStackInfo
@@ -87,7 +86,10 @@ public:
 	// helper variable used during loading map, when object (hero or town) have creatures that must have same alignment.
 	std::optional<RandomStackInfo> randomStack;
 
-	const CArmedInstance * const & armyObj; //stack must be part of some army, army must be part of some object
+	CArmedInstance * getArmy();
+	const CArmedInstance * getArmy() const; //stack must be part of some army, army must be part of some object
+	void setArmy(const CArmedInstance *ArmyObj);
+
 	TExpType experience;//commander needs same amount of exp as hero
 
 	template <typename Handler> void serialize(Handler &h)
@@ -95,7 +97,7 @@ public:
 		h & static_cast<CBonusSystemNode&>(*this);
 		h & static_cast<CStackBasicDescriptor&>(*this);
 		h & static_cast<CArtifactSet&>(*this);
-		h & _armyObj;
+		h & armyInstanceID;
 		h & experience;
 
 		if(!h.saving)
@@ -122,14 +124,12 @@ public:
 	virtual int getLevel() const; //different for regular stack and commander
 	CreatureID getCreatureID() const; //-1 if not available
 	std::string getName() const; //plural or singular
-	CStackInstance(bool isHypothetic = false);
-	CStackInstance(const CreatureID & id, TQuantity count, bool isHypothetic = false);
-	CStackInstance(const CCreature *cre, TQuantity count, bool isHypothetic = false);
+	CStackInstance(IGameCallback *cb, bool isHypothetic	= false);
+	CStackInstance(IGameCallback *cb, const CreatureID & id, TQuantity count, bool isHypothetic = false);
 	virtual ~CStackInstance() = default;
 
 	void setType(const CreatureID & creID);
 	void setType(const CCreature * c) final;
-	void setArmyObj(const CArmedInstance *ArmyObj);
 	virtual void giveStackExp(TExpType exp);
 	bool valid(bool allowUnrandomized) const;
 	ArtPlacementMap putArtifact(const ArtifactPosition & pos, const CArtifactInstance * art) override;//from CArtifactSet
@@ -156,8 +156,8 @@ public:
 	std::vector <ui8> secondarySkills; //ID -> level
 	std::set <ui8> specialSkills;
 	//std::vector <CArtifactInstance *> arts;
-	CCommanderInstance();
-	CCommanderInstance(const CreatureID & id);
+	CCommanderInstance(IGameCallback *cb);
+	CCommanderInstance(IGameCallback *cb, const CreatureID & id);
 	void setAlive (bool alive);
 	void giveStackExp (TExpType exp) override;
 	void levelUp ();
@@ -223,9 +223,8 @@ class DLL_LINKAGE CCreatureSet : public IArmyDescriptor, public virtual Serializ
 {
 	CCreatureSet(const CCreatureSet &) = delete;
 	CCreatureSet &operator=(const CCreatureSet&);
-public:
-
 
+public:
 	TSlots stacks; //slots[slot_id]->> pair(creature_id,creature_quantity)
 	EArmyFormation formation = EArmyFormation::LOOSE; //0 - wide, 1 - tight
 
@@ -241,7 +240,8 @@ public:
 	void addToSlot(const SlotID & slot, std::unique_ptr<CStackInstance> stack, bool allowMerging = true); //Adds stack to slot. Slot must be empty or with same type creature
 	void clearSlots() override;
 	void setFormation(EArmyFormation tight);
-	CArmedInstance *castToArmyObj();
+	virtual CArmedInstance * getArmy() { return nullptr; }
+	virtual const CArmedInstance * getArmy() const { return nullptr; }
 
 	//basic operations
 	void putStack(const SlotID & slot, std::unique_ptr<CStackInstance> stack); //adds new stack to the army, slot must be empty

+ 4 - 3
lib/CStack.cpp

@@ -17,6 +17,7 @@
 
 #include "texts/CGeneralTextHandler.h"
 #include "battle/BattleInfo.h"
+#include "GameLibrary.h"
 #include "spells/CSpellHandler.h"
 #include "networkPacks/PacksForClientBattle.h"
 
@@ -151,7 +152,7 @@ CStack::~CStack()
 const CGHeroInstance * CStack::getMyHero() const
 {
 	if(base)
-		return dynamic_cast<const CGHeroInstance *>(base->armyObj);
+		return dynamic_cast<const CGHeroInstance *>(base->getArmy());
 	else //we are attached directly?
 		for(const CBonusSystemNode * n : getParentNodes())
 			if(n->getNodeType() == HERO)
@@ -171,8 +172,8 @@ std::string CStack::nodeName() const
 		oss << "[UNDEFINED TYPE]";
 
 	oss << " from slot " << slot;
-	if(base && base->armyObj)
-		oss << " of armyobj=" << base->armyObj->id.getNum();
+	if(base && base->getArmy())
+		oss << " of armyobj=" << base->getArmy()->id.getNum();
 	return oss.str();
 }
 

+ 15 - 15
lib/CStack.h

@@ -109,21 +109,21 @@ public:
 		h & side;
 		h & initialPosition;
 
-		const CArmedInstance * army = (base ? base->armyObj : nullptr);
-		SlotID extSlot = (base ? base->armyObj->findStack(base) : SlotID());
-
-		if(h.saving)
-		{
-			h & army;
-			h & extSlot;
-		}
-		else
-		{
-			h & army;
-			h & extSlot;
-
-			postDeserialize(army, extSlot);
-		}
+//		const CArmedInstance * army = (base ? base->armyObj : nullptr);
+//		SlotID extSlot = (base ? base->armyObj->findStack(base) : SlotID());
+//
+//		if(h.saving)
+//		{
+//			h & army;
+//			h & extSlot;
+//		}
+//		else
+//		{
+//			h & army;
+//			h & extSlot;
+//
+//			postDeserialize(army, extSlot);
+//		}
 	}
 
 private:

+ 2 - 1
lib/battle/BattleInfo.cpp

@@ -17,6 +17,7 @@
 #include "../CStack.h"
 #include "../entities/building/TownFortifications.h"
 #include "../filesystem/Filesystem.h"
+#include "../GameLibrary.h"
 #include "../mapObjects/CGTownInstance.h"
 #include "../texts/CGeneralTextHandler.h"
 #include "../BattleFieldHandler.h"
@@ -43,7 +44,7 @@ SideInBattle & BattleInfo::getSide(BattleSide side)
 void BattleInfo::generateNewStack(uint32_t id, const CStackInstance & base, BattleSide side, const SlotID & slot, const BattleHex & position)
 {
 	PlayerColor owner = getSide(side).color;
-	assert(!owner.isValidPlayer() || (base.armyObj && base.armyObj->tempOwner == owner));
+	assert(!owner.isValidPlayer() || (base.getArmy() && base.getArmy()->tempOwner == owner));
 
 	auto ret = std::make_unique<CStack>(&base, owner, id, side, slot);
 	ret->initialPosition = getAvailableHex(base.getCreatureID(), side, position.toInt()); //TODO: what if no free tile on battlefield was found?

+ 1 - 0
lib/battle/CBattleInfoCallback.cpp

@@ -20,6 +20,7 @@
 #include "IGameSettings.h"
 #include "PossiblePlayerBattleAction.h"
 #include "../entities/building/TownFortifications.h"
+#include "../GameLibrary.h"
 #include "../spells/ObstacleCasterProxy.h"
 #include "../spells/ISpellMechanics.h"
 #include "../spells/Problem.h"

+ 4 - 4
lib/gameState/CGameState.cpp

@@ -1071,9 +1071,9 @@ UpgradeInfo CGameState::fillUpgradeInfo(const CStackInstance & stack) const
 	
 	UpgradeInfo ret(base->getId());
 
-	if (stack.armyObj->ID == Obj::HERO)
+	if (stack.getArmy()->ID == Obj::HERO)
 	{
-		auto hero = dynamic_cast<const CGHeroInstance *>(stack.armyObj);
+		auto hero = dynamic_cast<const CGHeroInstance *>(stack.getArmy());
 		hero->fillUpgradeInfo(ret, stack);
 
 		if (hero->getVisitedTown())
@@ -1089,9 +1089,9 @@ UpgradeInfo CGameState::fillUpgradeInfo(const CStackInstance & stack) const
 		}
 	}
 
-	if (stack.armyObj->ID == Obj::TOWN)
+	if (stack.getArmy()->ID == Obj::TOWN)
 	{
-		auto town = dynamic_cast<const CGTownInstance *>(stack.armyObj);
+		auto town = dynamic_cast<const CGTownInstance *>(stack.getArmy());
 		town->fillUpgradeInfo(ret, stack);
 	}
 

+ 1 - 0
lib/gameState/InfoAboutArmy.cpp

@@ -12,6 +12,7 @@
 
 #include "../mapObjects/CGHeroInstance.h"
 #include "../mapObjects/CGTownInstance.h"
+#include "../GameLibrary.h"
 
 #include <vcmi/HeroTypeService.h>
 #include <vcmi/HeroType.h>

+ 1 - 0
lib/mapObjectConstructors/CRewardableConstructor.cpp

@@ -16,6 +16,7 @@
 #include "../texts/CGeneralTextHandler.h"
 #include "../IGameCallback.h"
 #include "../CConfigHandler.h"
+#include "../GameLibrary.h"
 
 VCMI_LIB_NAMESPACE_BEGIN
 

+ 2 - 2
lib/mapObjectConstructors/DwellingInstanceConstructor.cpp

@@ -104,7 +104,7 @@ void DwellingInstanceConstructor::randomizeObject(CGDwelling * dwelling, vstd::R
 		JsonRandom::Variables emptyVariables;
 		for(auto & stack : randomizer.loadCreatures(guards, rng, emptyVariables))
 		{
-			dwelling->putStack(SlotID(dwelling->stacksCount()), std::make_unique<CStackInstance>(stack.getId(), stack.count));
+			dwelling->putStack(SlotID(dwelling->stacksCount()), std::make_unique<CStackInstance>(dwelling->cb, stack.getId(), stack.count));
 		}
 	}
 	else if (dwelling->ID == Obj::CREATURE_GENERATOR1 || dwelling->ID == Obj::CREATURE_GENERATOR4)
@@ -125,7 +125,7 @@ void DwellingInstanceConstructor::randomizeObject(CGDwelling * dwelling, vstd::R
 		for(auto creatureEntry : availableCreatures)
 		{
 			const CCreature * crea = creatureEntry.at(0);
-			dwelling->putStack(SlotID(dwelling->stacksCount()), std::make_unique<CStackInstance>(crea->getId(), crea->getGrowth() * 3));
+			dwelling->putStack(SlotID(dwelling->stacksCount()), std::make_unique<CStackInstance>(dwelling->cb, crea->getId(), crea->getGrowth() * 3));
 		}
 	}
 }

+ 1 - 0
lib/mapObjectConstructors/HillFortInstanceConstructor.cpp

@@ -10,6 +10,7 @@
 #include "StdInc.h"
 #include "HillFortInstanceConstructor.h"
 
+#include "../GameLibrary.h"
 #include "../mapObjects/MiscObjects.h"
 #include "../texts/CGeneralTextHandler.h"
 

+ 1 - 0
lib/mapObjectConstructors/ShipyardInstanceConstructor.cpp

@@ -10,6 +10,7 @@
 #include "StdInc.h"
 #include "ShipyardInstanceConstructor.h"
 
+#include "../GameLibrary.h"
 #include "../mapObjects/MiscObjects.h"
 #include "../modding/IdentifierStorage.h"
 

+ 2 - 1
lib/mapObjects/CArmedInstance.cpp

@@ -16,6 +16,7 @@
 #include "../entities/faction/CFaction.h"
 #include "../entities/faction/CTown.h"
 #include "../entities/faction/CTownHandler.h"
+#include "../GameLibrary.h"
 #include "../gameState/CGameState.h"
 #include "../mapping/CMapDefines.h"
 #include "../texts/CGeneralTextHandler.h"
@@ -35,7 +36,7 @@ void CArmedInstance::randomizeArmy(FactionID type)
 			elem.second->randomStack = std::nullopt;
 		}
 		assert(elem.second->valid(false));
-		assert(elem.second->armyObj == this);
+		assert(elem.second->getArmy() == this);
 	}
 }
 

+ 2 - 0
lib/mapObjects/CArmedInstance.h

@@ -32,6 +32,8 @@ public:
 	virtual void updateMoraleBonusFromArmy();
 
 	void armyChanged() override;
+	CArmedInstance * getArmy() final { return this; }
+	const CArmedInstance * getArmy() const final { return this; }
 
 	//////////////////////////////////////////////////////////////////////////
 	//IConstBonusProvider

+ 1 - 1
lib/mapObjects/CGCreature.cpp

@@ -672,7 +672,7 @@ void CGCreature::serializeJsonOptions(JsonSerializeFormat & handler)
 	{
 		si32 amount = 0;
 		handler.serializeInt("amount", amount);
-		auto hlp = std::make_unique<CStackInstance>();
+		auto hlp = std::make_unique<CStackInstance>(cb);
 		hlp->count = amount;
 		//type will be set during initialization
 		putStack(SlotID(0), std::move(hlp));

+ 2 - 2
lib/mapObjects/CGHeroInstance.cpp

@@ -464,8 +464,8 @@ void CGHeroInstance::initHero(vstd::RNG & rand)
 
 	if (cb->getSettings().getBoolean(EGameSettings::MODULE_COMMANDERS) && !commander && getHeroClass()->commander.hasValue())
 	{
-		commander = std::make_unique<CCommanderInstance>(getHeroClass()->commander);
-		commander->setArmyObj (castToArmyObj()); //TODO: separate function for setting commanders
+		commander = std::make_unique<CCommanderInstance>(cb, getHeroClass()->commander);
+		commander->setArmy(getArmy()); //TODO: separate function for setting commanders
 		commander->giveStackExp (exp); //after our exp is set
 	}
 

+ 1 - 1
lib/mapObjects/CGTownInstance.cpp

@@ -533,7 +533,7 @@ void CGTownInstance::initializeNeutralTownGarrison(vstd::RNG & rand)
 		CreatureID guardID = getTown()->creatures[guard.tier].at(0);
 		int guardSize = rand.nextInt(guard.min, guard.max);
 
-		putStack(getFreeSlot(), std::make_unique<CStackInstance>(guardID, guardSize));
+		putStack(getFreeSlot(), std::make_unique<CStackInstance>(cb, guardID, guardSize));
 	}
 }
 

+ 1 - 1
lib/mapObjects/CRewardableObject.cpp

@@ -361,7 +361,7 @@ void CRewardableObject::initializeGuards()
 			if (!slotID.validSlot())
 				return;
 
-			putStack(slotID, std::make_unique<CStackInstance>(guard.getId(), guard.getCount()));
+			putStack(slotID, std::make_unique<CStackInstance>(cb, guard.getId(), guard.getCount()));
 		}
 	}
 }

+ 1 - 1
lib/mapObjects/MiscObjects.cpp

@@ -102,7 +102,7 @@ void CGMine::initObj(vstd::RNG & rand)
 	{
 		//set guardians
 		int howManyTroglodytes = rand.nextInt(100, 199);
-		auto troglodytes = std::make_unique<CStackInstance>(CreatureID::TROGLODYTES, howManyTroglodytes);
+		auto troglodytes = std::make_unique<CStackInstance>(cb, CreatureID::TROGLODYTES, howManyTroglodytes);
 		putStack(SlotID(0), std::move(troglodytes));
 
 		assert(!abandonedMineResources.empty());

+ 1 - 0
lib/mapping/CMapInfo.cpp

@@ -19,6 +19,7 @@
 
 #include "../campaign/CampaignHandler.h"
 #include "../filesystem/Filesystem.h"
+#include "../GameLibrary.h"
 #include "../rmg/CMapGenOptions.h"
 #include "../serializer/CLoadFile.h"
 #include "../texts/CGeneralTextHandler.h"

+ 2 - 2
lib/mapping/MapFormatH3M.cpp

@@ -1189,7 +1189,7 @@ std::shared_ptr<CGObjectInstance> CMapLoaderH3M::readMonster(const int3 & mapPos
 		questIdentifierToId[object->identifier] = objectInstanceID;
 	}
 
-	auto hlp = std::make_unique<CStackInstance>();
+	auto hlp = std::make_unique<CStackInstance>(map->cb);
 	hlp->count = reader->readUInt16();
 
 	//type will be set during initialization
@@ -1978,7 +1978,7 @@ void CMapLoaderH3M::readCreatureSet(CCreatureSet * out, int number)
 		if(creatureID == CreatureID::NONE)
 			continue;
 
-		auto result = std::make_unique<CStackInstance>();
+		auto result = std::make_unique<CStackInstance>(map->cb);
 		result->count = count;
 
 		if(creatureID < CreatureID::NONE)

+ 1 - 1
lib/networkPacks/NetPacksLib.cpp

@@ -1553,7 +1553,7 @@ void SwapStacks::applyGs(CGameState *gs)
 void InsertNewStack::applyGs(CGameState *gs)
 {
 	if(auto * obj = gs->getArmyInstance(army))
-		obj->putStack(slot, std::make_unique<CStackInstance>(type, count));
+		obj->putStack(slot, std::make_unique<CStackInstance>(gs->callback, type, count));
 	else
 		throw std::runtime_error("InsertNewStack: invalid army object " + std::to_string(army.getNum()) + ", possible game state corruption.");
 }

+ 1 - 0
lib/rewardable/Info.cpp

@@ -18,6 +18,7 @@
 #include "../texts/CGeneralTextHandler.h"
 #include "../IGameCallback.h"
 #include "../json/JsonRandom.h"
+#include "../GameLibrary.h"
 #include "../mapObjects/IObjectInterface.h"
 #include "../modding/IdentifierStorage.h"
 

+ 1 - 1
lib/rewardable/Interface.cpp

@@ -197,7 +197,7 @@ void Rewardable::Interface::grantRewardAfterLevelup(const Rewardable::VisitInfo
 	{
 		CCreatureSet creatures;
 		for(const auto & crea : info.reward.creatures)
-			creatures.addToSlot(creatures.getFreeSlot(), std::make_unique<CStackInstance>(crea.getCreature(), crea.count));
+			creatures.addToSlot(creatures.getFreeSlot(), std::make_unique<CStackInstance>(cb, crea.getId(), crea.count));
 
 		if(auto * army = dynamic_cast<const CArmedInstance*>(this)) //TODO: to fix that, CArmedInstance must be split on map instance part and interface part
 			cb->giveCreatures(army, hero, creatures, false);

+ 1 - 1
lib/rmg/modificators/ObjectManager.cpp

@@ -777,7 +777,7 @@ std::shared_ptr<CGCreature> ObjectManager::chooseGuard(si32 strength, bool zoneG
 
 	auto guard = std::dynamic_pointer_cast<CGCreature>(guardFactory->create(map.mapInstance->cb, nullptr));
 	guard->character = CGCreature::HOSTILE;
-	auto hlp = std::make_unique<CStackInstance>(creId, amount);
+	auto hlp = std::make_unique<CStackInstance>(map.mapInstance->cb, creId, amount);
 	//will be set during initialization
 	guard->putStack(SlotID(0), std::move(hlp));
 	return guard;

+ 0 - 46
lib/serializer/BinaryDeserializer.h

@@ -37,45 +37,6 @@ public:
 /// Effectively revesed version of BinarySerializer
 class BinaryDeserializer : public CLoaderBase
 {
-	template<typename Fake, typename T>
-	static bool loadIfStackInstance(T &data)
-	{
-		return false;
-	}
-
-	template<typename Fake>
-	bool loadIfStackInstance(const CStackInstance* &data)
-	{
-		CArmedInstance * armyPtr = nullptr;
-		ObjectInstanceID armyID;
-		SlotID slot;
-		load(armyID);
-		load(slot);
-
-		if (armyID == ObjectInstanceID::NONE)
-			return false;
-
-		if(reader->smartVectorMembersSerialization)
-		{
-			if(const auto *info = reader->getVectorizedTypeInfo<CArmedInstance, ObjectInstanceID>())
-				armyPtr = reader->getVectorItemFromId<CArmedInstance, ObjectInstanceID>(*info, armyID);
-		}
-
-		if(slot != SlotID::COMMANDER_SLOT_PLACEHOLDER)
-		{
-			assert(armyPtr->hasStackAtSlot(slot));
-			data = armyPtr->stacks[slot];
-		}
-		else
-		{
-			auto * hero = dynamic_cast<CGHeroInstance *>(armyPtr);
-			assert(hero);
-			assert(hero->getCommander());
-			data = hero->getCommander();
-		}
-		return true;
-	}
-
 	STRONG_INLINE uint32_t readAndCheckLength()
 	{
 		uint32_t length;
@@ -258,13 +219,6 @@ public:
 			}
 		}
 
-		if(reader->sendStackInstanceByIds)
-		{
-			bool gotLoaded = loadIfStackInstance<void>(data);
-			if(gotLoaded)
-				return;
-		}
-
 		uint32_t pid = 0xffffffff; //pointer id (or maybe rather pointee id)
 		if(trackSerializedPointers)
 		{

+ 0 - 35
lib/serializer/BinarySerializer.h

@@ -53,34 +53,6 @@ class BinarySerializer : public CSaverBase
 		}
 	};
 
-	template<typename Fake, typename T>
-	bool saveIfStackInstance(const T &data)
-	{
-		return false;
-	}
-
-	template<typename Fake>
-	bool saveIfStackInstance(const CStackInstance* const &data)
-	{
-		assert(data->armyObj);
-
-		SlotID slot;
-
-		if(data->getNodeType() == CBonusSystemNode::COMMANDER)
-			slot = SlotID::COMMANDER_SLOT_PLACEHOLDER;
-		else
-			slot = data->armyObj->findStack(data);
-
-		assert(slot != SlotID());
-		save(data->armyObj->id);
-		save(slot);
-
-		if (data->armyObj->id != ObjectInstanceID::NONE)
-			return true;
-		else
-			return false;
-	}
-
 public:
 	using Version = ESerializationVersion;
 
@@ -199,13 +171,6 @@ public:
 			}
 		}
 
-		if(writer->sendStackInstanceByIds)
-		{
-			const bool gotSaved = saveIfStackInstance<void>(data);
-			if(gotSaved)
-				return;
-		}
-
 		if(trackSerializedPointers)
 		{
 			// We might have an object that has multiple inheritance and store it via the non-first base pointer.

+ 0 - 1
lib/serializer/CSerializer.h

@@ -78,7 +78,6 @@ class DLL_LINKAGE CSerializer : boost::noncopyable
 
 public:
 	bool smartVectorMembersSerialization = false;
-	bool sendStackInstanceByIds = false;
 
 	~CSerializer();
 

+ 0 - 15
lib/serializer/Connection.cpp

@@ -119,24 +119,11 @@ std::shared_ptr<INetworkConnection> CConnection::getConnection()
 	return networkConnection.lock();
 }
 
-void CConnection::disableStackSendingByID()
-{
-	packReader->sendStackInstanceByIds = false;
-	packWriter->sendStackInstanceByIds = false;
-}
-
-void CConnection::enableStackSendingByID()
-{
-	packReader->sendStackInstanceByIds = true;
-	packWriter->sendStackInstanceByIds = true;
-}
-
 void CConnection::enterLobbyConnectionMode()
 {
 	deserializer->loadedPointers.clear();
 	serializer->savedPointers.clear();
 	disableSmartVectorMemberSerialization();
-	disableStackSendingByID();
 }
 
 void CConnection::setCallback(IGameCallback * cb)
@@ -146,8 +133,6 @@ void CConnection::setCallback(IGameCallback * cb)
 
 void CConnection::enterGameplayConnectionMode(CGameState * gs)
 {
-	enableStackSendingByID();
-
 	setCallback(gs->callback);
 	enableSmartVectorMemberSerializatoin(gs);
 }

+ 0 - 2
lib/serializer/Connection.h

@@ -36,8 +36,6 @@ class DLL_LINKAGE CConnection : boost::noncopyable
 
 	std::mutex writeMutex;
 
-	void disableStackSendingByID();
-	void enableStackSendingByID();
 	void disableSmartVectorMemberSerialization();
 	void enableSmartVectorMemberSerializatoin(CGameState * gs);
 

+ 1 - 0
lib/spells/CSpellHandler.cpp

@@ -26,6 +26,7 @@
 #include "../battle/Unit.h"
 #include "../json/JsonBonus.h"
 #include "../json/JsonUtils.h"
+#include "../GameLibrary.h"
 #include "../mapObjects/CGHeroInstance.h" //todo: remove
 #include "../modding/IdentifierStorage.h"
 #include "../modding/ModUtility.h"

+ 2 - 1
mapeditor/inspector/armywidget.cpp

@@ -13,6 +13,7 @@
 #include "ui_armywidget.h"
 #include "CCreatureHandler.h"
 
+#include "../../lib/GameLibrary.h"
 
 ArmyWidget::ArmyWidget(CArmedInstance & a, QWidget *parent) :
 	QDialog(parent),
@@ -99,7 +100,7 @@ bool ArmyWidget::commitChanges()
 			{
 				if(army.hasStackAtSlot(SlotID(i)))
 					army.eraseStack(SlotID(i));
-				army.putStack(SlotID(i), std::make_unique<CStackInstance>(creId, amount, false));
+				army.putStack(SlotID(i), std::make_unique<CStackInstance>(army.cb, creId, amount, false));
 			}
 		}
 	}

+ 2 - 0
mapeditor/inspector/artifactwidget.cpp

@@ -11,7 +11,9 @@
 #include "artifactwidget.h"
 #include "ui_artifactwidget.h"
 #include "inspector.h"
+
 #include "../../lib/ArtifactUtils.h"
+#include "../../lib/GameLibrary.h"
 #include "../../lib/constants/StringConstants.h"
 
 ArtifactWidget::ArtifactWidget(CArtifactFittingSet & fittingSet, QWidget * parent) :

+ 4 - 2
mapeditor/inspector/heroskillswidget.cpp

@@ -10,10 +10,12 @@
 #include "StdInc.h"
 #include "heroskillswidget.h"
 #include "ui_heroskillswidget.h"
+#include "inspector.h"
+
+#include "../../lib/CSkillHandler.h"
+#include "../../lib/GameLibrary.h"
 #include "../../lib/constants/StringConstants.h"
 #include "../../lib/entities/hero/CHeroHandler.h"
-#include "../../lib/CSkillHandler.h"
-#include "inspector.h"
 
 static const QList<std::pair<QString, QVariant>> LevelIdentifiers
 {

+ 2 - 0
mapeditor/inspector/herospellwidget.cpp

@@ -11,6 +11,8 @@
 #include "herospellwidget.h"
 #include "ui_herospellwidget.h"
 #include "inspector.h"
+
+#include "../../lib/GameLibrary.h"
 #include "../../lib/constants/StringConstants.h"
 #include "../../lib/spells/CSpellHandler.h"
 

+ 1 - 1
mapeditor/inspector/inspector.cpp

@@ -79,7 +79,7 @@ void Initializer::initialize(CGCreature * o)
 	
 	o->character = CGCreature::Character::HOSTILE;
 	if(!o->hasStackAtSlot(SlotID(0)))
-		o->putStack(SlotID(0), std::make_unique<CStackInstance>(CreatureID(o->subID), 0, false));
+		o->putStack(SlotID(0), std::make_unique<CStackInstance>(o->cb, CreatureID(o->subID), 0, false));
 }
 
 void Initializer::initialize(CGDwelling * o)

+ 2 - 0
mapeditor/inspector/portraitwidget.cpp

@@ -11,6 +11,8 @@
 #include "portraitwidget.h"
 #include "ui_portraitwidget.h"
 #include "../Animation.h"
+
+#include "../lib/GameLibrary.h"
 #include "../lib/entities/hero/CHeroHandler.h"
 
 PortraitWidget::PortraitWidget(CGHeroInstance & h, QWidget *parent):

+ 2 - 0
mapeditor/inspector/townspellswidget.cpp

@@ -12,6 +12,8 @@
 #include "ui_townspellswidget.h"
 #include "inspector.h"
 #include "mapeditorroles.h"
+
+#include "../../lib/GameLibrary.h"
 #include "../../lib/constants/StringConstants.h"
 #include "../../lib/spells/CSpellHandler.h"
 

+ 3 - 3
server/CGameHandler.cpp

@@ -191,7 +191,7 @@ void CGameHandler::levelUpCommander (const CCommanderInstance * c, int skill)
 {
 	SetCommanderProperty scp;
 
-	auto hero = dynamic_cast<const CGHeroInstance *>(c->armyObj);
+	auto hero = dynamic_cast<const CGHeroInstance *>(c->getArmy());
 	if (hero)
 		scp.heroid = hero->id;
 	else
@@ -281,7 +281,7 @@ void CGameHandler::levelUpCommander(const CCommanderInstance * c)
 	}
 	CommanderLevelUp clu;
 
-	auto hero = dynamic_cast<const CGHeroInstance *>(c->armyObj);
+	auto hero = dynamic_cast<const CGHeroInstance *>(c->getArmy());
 	if(hero)
 	{
 		clu.heroId = hero->id;
@@ -4287,7 +4287,7 @@ void CGameHandler::createWanderingMonster(const int3 & visitablePosition, Creatu
 	cre->character = 2;
 	cre->gainedArtifact = ArtifactID::NONE;
 	cre->identifier = -1;
-	cre->addToSlot(SlotID(0), std::make_unique<CStackInstance>(creature, -1)); //add placeholder stack
+	cre->addToSlot(SlotID(0), std::make_unique<CStackInstance>(gs->callback, creature, -1)); //add placeholder stack
 
 	newObject(createdObject, PlayerColor::NEUTRAL);
 }