Browse Source

Removed most of non-const static fields in lib. Reduced header includes.

Ivan Savenko 1 year ago
parent
commit
e67e4430ba
49 changed files with 139 additions and 116 deletions
  1. 1 0
      CCallback.cpp
  2. 1 0
      client/NetPacksClient.cpp
  3. 1 0
      client/mapView/MapRendererContext.cpp
  4. 2 2
      lib/CArtHandler.cpp
  5. 0 2
      lib/CCreatureHandler.h
  6. 6 4
      lib/CGameInfoCallback.cpp
  7. 5 5
      lib/CTownHandler.cpp
  8. 3 3
      lib/CTownHandler.h
  9. 3 0
      lib/IGameCallback.cpp
  10. 0 10
      lib/IHandlerBase.h
  11. 2 3
      lib/JsonNode.cpp
  12. 2 3
      lib/battle/CBattleInfoEssentials.cpp
  13. 12 12
      lib/bonuses/BonusSelector.cpp
  14. 6 6
      lib/bonuses/BonusSelector.h
  15. 1 0
      lib/campaign/CampaignState.cpp
  16. 12 10
      lib/gameState/CGameState.cpp
  17. 1 0
      lib/gameState/CGameStateCampaign.cpp
  18. 1 0
      lib/mapObjects/CGDwelling.cpp
  19. 1 0
      lib/mapObjects/CGHeroInstance.cpp
  20. 2 12
      lib/mapObjects/CGTownInstance.cpp
  21. 0 4
      lib/mapObjects/CGTownInstance.h
  22. 5 14
      lib/mapObjects/MiscObjects.cpp
  23. 0 4
      lib/mapObjects/MiscObjects.h
  24. 1 0
      lib/mapping/CDrawRoadsOperation.cpp
  25. 6 2
      lib/mapping/CMap.cpp
  26. 14 8
      lib/mapping/CMap.h
  27. 5 4
      lib/mapping/CMapOperation.cpp
  28. 1 0
      lib/mapping/MapFormatJson.cpp
  29. 1 0
      lib/mapping/ObstacleProxy.cpp
  30. 4 1
      lib/networkPacks/NetPacksLib.cpp
  31. 2 0
      lib/pathfinder/CPathfinder.cpp
  32. 1 0
      lib/pathfinder/NodeStorage.cpp
  33. 1 0
      lib/rmg/CMapGenerator.cpp
  34. 3 2
      lib/rmg/CZonePlacer.cpp
  35. 1 0
      lib/rmg/RmgMap.h
  36. 1 0
      lib/rmg/RmgObject.cpp
  37. 1 0
      lib/rmg/modificators/MinePlacer.cpp
  38. 1 0
      lib/rmg/modificators/ObstaclePlacer.cpp
  39. 1 0
      lib/rmg/modificators/RoadPlacer.cpp
  40. 1 0
      lib/rmg/modificators/TerrainPainter.cpp
  41. 1 0
      lib/rmg/modificators/TownPlacer.cpp
  42. 6 4
      lib/rmg/modificators/TreasurePlacer.cpp
  43. 1 0
      lib/rmg/modificators/WaterProxy.cpp
  44. 7 0
      lib/serializer/CSerializer.cpp
  45. 5 0
      lib/serializer/CSerializer.h
  46. 2 0
      lib/spells/AdventureSpellMechanics.cpp
  47. 1 0
      mapeditor/maphandler.cpp
  48. 1 0
      mapeditor/mapsettings/translations.cpp
  49. 3 1
      server/CGameHandler.cpp

+ 1 - 0
CCallback.cpp

@@ -16,6 +16,7 @@
 #include "client/Client.h"
 #include "lib/mapping/CMap.h"
 #include "lib/mapObjects/CGHeroInstance.h"
+#include "lib/mapObjects/CGTownInstance.h"
 #include "lib/CBuildingHandler.h"
 #include "lib/CGeneralTextHandler.h"
 #include "lib/CHeroHandler.h"

+ 1 - 0
client/NetPacksClient.cpp

@@ -39,6 +39,7 @@
 #include "../lib/StartInfo.h"
 #include "../lib/CConfigHandler.h"
 #include "../lib/mapObjects/CGMarket.h"
+#include "../lib/mapObjects/CGTownInstance.h"
 #include "../lib/gameState/CGameState.h"
 #include "../lib/CStack.h"
 #include "../lib/battle/BattleInfo.h"

+ 1 - 0
client/mapView/MapRendererContext.cpp

@@ -21,6 +21,7 @@
 
 #include "../../lib/Point.h"
 #include "../../lib/mapObjects/CGHeroInstance.h"
+#include "../../lib/mapObjects/MiscObjects.h"
 #include "../../lib/spells/CSpellHandler.h"
 #include "../../lib/mapping/CMap.h"
 #include "../../lib/pathfinder/CGPathNode.h"

+ 2 - 2
lib/CArtHandler.cpp

@@ -328,7 +328,7 @@ std::vector<JsonNode> CArtHandler::loadLegacyData()
 	const std::vector<std::string> artSlots = { ART_POS_LIST };
 	#undef ART_POS
 
-	static std::map<char, std::string> classes =
+	static const std::map<char, std::string> classes =
 		{{'S',"SPECIAL"}, {'T',"TREASURE"},{'N',"MINOR"},{'J',"MAJOR"},{'R',"RELIC"},};
 
 	CLegacyConfigParser parser(TextPath::builtin("DATA/ARTRAITS.TXT"));
@@ -353,7 +353,7 @@ std::vector<JsonNode> CArtHandler::loadLegacyData()
 				artData["slot"].Vector().back().String() = artSlot;
 			}
 		}
-		artData["class"].String() = classes[parser.readString()[0]];
+		artData["class"].String() = classes.at(parser.readString()[0]);
 		artData["text"]["description"].String() = parser.readString();
 
 		parser.endLine();

+ 0 - 2
lib/CCreatureHandler.h

@@ -222,8 +222,6 @@ public:
 	std::vector< std::vector <ui8> > skillLevels; //how much of a bonus will be given to commander with every level. SPELL_POWER also gives CASTS and RESISTANCE
 	std::vector <std::pair <std::shared_ptr<Bonus>, std::pair <ui8, ui8> > > skillRequirements; // first - Bonus, second - which two skills are needed to use it
 
-	//const CCreature * getCreature(const std::string & scope, const std::string & identifier) const;
-
 	CreatureID pickRandomMonster(CRandomGenerator & rand, int tier = -1) const; //tier <1 - CREATURES_PER_TOWN> or -1 for any
 
 	CCreatureHandler();

+ 6 - 4
lib/CGameInfoCallback.cpp

@@ -16,6 +16,8 @@
 #include "gameState/TavernHeroesPool.h"
 #include "gameState/QuestInfo.h"
 #include "mapObjects/CGHeroInstance.h"
+#include "mapObjects/CGTownInstance.h"
+#include "mapObjects/MiscObjects.h"
 #include "networkPacks/ArtifactLocation.h"
 #include "CGeneralTextHandler.h"
 #include "StartInfo.h" // for StartInfo
@@ -791,7 +793,7 @@ int CPlayerSpecificInfoCallback::getHeroSerial(const CGHeroInstance * hero, bool
 
 int3 CPlayerSpecificInfoCallback::getGrailPos( double *outKnownRatio )
 {
-	if (!getPlayerID() || CGObelisk::obeliskCount == 0)
+	if (!getPlayerID() || gs->map->obeliskCount == 0)
 	{
 		*outKnownRatio = 0.0;
 	}
@@ -799,10 +801,10 @@ int3 CPlayerSpecificInfoCallback::getGrailPos( double *outKnownRatio )
 	{
 		TeamID t = gs->getPlayerTeam(*getPlayerID())->id;
 		double visited = 0.0;
-		if(CGObelisk::visited.count(t))
-			visited = static_cast<double>(CGObelisk::visited[t]);
+		if(gs->map->obelisksVisited.count(t))
+			visited = static_cast<double>(gs->map->obelisksVisited[t]);
 
-		*outKnownRatio = visited / CGObelisk::obeliskCount;
+		*outKnownRatio = visited / gs->map->obeliskCount;
 	}
 	return gs->map->grailPos;
 }

+ 5 - 5
lib/CTownHandler.cpp

@@ -336,9 +336,9 @@ JsonNode readBuilding(CLegacyConfigParser & parser)
 	return ret;
 }
 
-TPropagatorPtr & CTownHandler::emptyPropagator()
+const TPropagatorPtr & CTownHandler::emptyPropagator()
 {
-	static TPropagatorPtr emptyProp(nullptr);
+	static const TPropagatorPtr emptyProp(nullptr);
 	return emptyProp;
 }
 
@@ -534,7 +534,7 @@ R CTownHandler::getMappedValue(const JsonNode & node, const R defval, const std:
 void CTownHandler::addBonusesForVanilaBuilding(CBuilding * building) const
 {
 	std::shared_ptr<Bonus> b;
-	static TPropagatorPtr playerPropagator = std::make_shared<CPropagatorNodeType>(CBonusSystemNode::ENodeTypes::PLAYER);
+	static const TPropagatorPtr playerPropagator = std::make_shared<CPropagatorNodeType>(CBonusSystemNode::ENodeTypes::PLAYER);
 
 	if(building->bid == BuildingID::TAVERN)
 	{
@@ -578,7 +578,7 @@ std::shared_ptr<Bonus> CTownHandler::createBonus(CBuilding * build, BonusType ty
 	return createBonus(build, type, val, subtype, emptyPropagator());
 }
 
-std::shared_ptr<Bonus> CTownHandler::createBonus(CBuilding * build, BonusType type, int val, BonusSubtypeID subtype, TPropagatorPtr & prop) const
+std::shared_ptr<Bonus> CTownHandler::createBonus(CBuilding * build, BonusType type, int val, BonusSubtypeID subtype, const TPropagatorPtr & prop) const
 {
 	std::ostringstream descr;
 	descr << build->getNameTranslated();
@@ -589,7 +589,7 @@ std::shared_ptr<Bonus> CTownHandler::createBonusImpl(const BuildingID & building
 													 const FactionID & faction,
 													 BonusType type,
 													 int val,
-													 TPropagatorPtr & prop,
+													 const TPropagatorPtr & prop,
 													 const std::string & description,
 													 BonusSubtypeID subtype) const
 {

+ 3 - 3
lib/CTownHandler.h

@@ -290,7 +290,7 @@ class DLL_LINKAGE CTownHandler : public CHandlerBase<FactionID, Faction, CFactio
 	std::vector<BuildingRequirementsHelper> requirementsToLoad;
 	std::vector<BuildingRequirementsHelper> overriddenBidsToLoad; //list of buildings, which bonuses should be overridden.
 
-	static TPropagatorPtr & emptyPropagator();
+	static const TPropagatorPtr & emptyPropagator();
 
 	void initializeRequirements();
 	void initializeOverridden();
@@ -303,12 +303,12 @@ class DLL_LINKAGE CTownHandler : public CHandlerBase<FactionID, Faction, CFactio
 
 	std::shared_ptr<Bonus> createBonus(CBuilding * build, BonusType type, int val) const;
 	std::shared_ptr<Bonus> createBonus(CBuilding * build, BonusType type, int val, BonusSubtypeID subtype) const;
-	std::shared_ptr<Bonus> createBonus(CBuilding * build, BonusType type, int val, BonusSubtypeID subtype, TPropagatorPtr & prop) const;
+	std::shared_ptr<Bonus> createBonus(CBuilding * build, BonusType type, int val, BonusSubtypeID subtype, const TPropagatorPtr & prop) const;
 	std::shared_ptr<Bonus> createBonusImpl(const BuildingID & building,
 										   const FactionID & faction,
 												  BonusType type,
 												  int val,
-												  TPropagatorPtr & prop,
+												  const TPropagatorPtr & prop,
 												  const std::string & description,
 												  BonusSubtypeID subtype) const;
 

+ 3 - 0
lib/IGameCallback.cpp

@@ -25,7 +25,10 @@
 #include "rmg/CMapGenOptions.h"
 #include "mapObjectConstructors/AObjectTypeHandler.h"
 #include "mapObjectConstructors/CObjectClassesHandler.h"
+#include "mapObjects/CGTownInstance.h"
 #include "mapObjects/CObjectHandler.h"
+#include "mapObjects/CQuest.h"
+#include "mapObjects/MiscObjects.h"
 #include "mapObjects/ObjectTemplate.h"
 #include "campaign/CampaignState.h"
 #include "StartInfo.h"

+ 0 - 10
lib/IHandlerBase.h

@@ -68,16 +68,6 @@ public:
 		}
 	}
 
-	_Object * getObjectWriteable(const int32_t index)
-	{
-		if(index < 0 || index >= objects.size())
-		{
-			logMod->error("%s id %d is invalid", getTypeNames()[0], index);
-			throw std::runtime_error("Attempt to access invalid index " + std::to_string(index) + " of type " + getTypeNames().front());
-		}
-		return objects[index].get();
-	}
-
 	const Entity * getBaseByIndex(const int32_t index) const override
 	{
 		return getObjectImpl(index);

+ 2 - 3
lib/JsonNode.cpp

@@ -690,7 +690,6 @@ std::shared_ptr<Bonus> JsonUtils::parseBonus(const JsonVector & ability_vec)
 template <typename T>
 const T parseByMap(const std::map<std::string, T> & map, const JsonNode * val, const std::string & err)
 {
-	static T defaultValue = T();
 	if (!val->isNull())
 	{
 		const std::string & type = val->String();
@@ -698,7 +697,7 @@ const T parseByMap(const std::map<std::string, T> & map, const JsonNode * val, c
 		if (it == map.end())
 		{
 			logMod->error("Error: invalid %s%s.", err, type);
-			return defaultValue;
+			return {};
 		}
 		else
 		{
@@ -706,7 +705,7 @@ const T parseByMap(const std::map<std::string, T> & map, const JsonNode * val, c
 		}
 	}
 	else
-		return defaultValue;
+		return {};
 }
 
 template <typename T>

+ 2 - 3
lib/battle/CBattleInfoEssentials.cpp

@@ -401,10 +401,9 @@ PlayerColor CBattleInfoEssentials::battleGetOwner(const battle::Unit * unit) con
 
 	PlayerColor initialOwner = getBattle()->getSidePlayer(unit->unitSide());
 
-	static CSelector selector = Selector::type()(BonusType::HYPNOTIZED);
-	static std::string cachingString = "type_103s-1";
+	static const CSelector selector = Selector::type()(BonusType::HYPNOTIZED);
 
-	if(unit->hasBonus(selector, cachingString))
+	if(unit->hasBonus(selector))
 		return otherPlayer(initialOwner);
 	else
 		return initialOwner;

+ 12 - 12
lib/bonuses/BonusSelector.cpp

@@ -15,39 +15,39 @@ VCMI_LIB_NAMESPACE_BEGIN
 
 namespace Selector
 {
-	DLL_LINKAGE CSelectFieldEqual<BonusType> & type()
+	DLL_LINKAGE const CSelectFieldEqual<BonusType> & type()
 	{
-		static CSelectFieldEqual<BonusType> stype(&Bonus::type);
+		static const CSelectFieldEqual<BonusType> stype(&Bonus::type);
 		return stype;
 	}
 
-	DLL_LINKAGE CSelectFieldEqual<BonusSubtypeID> & subtype()
+	DLL_LINKAGE const CSelectFieldEqual<BonusSubtypeID> & subtype()
 	{
-		static CSelectFieldEqual<BonusSubtypeID> ssubtype(&Bonus::subtype);
+		static const CSelectFieldEqual<BonusSubtypeID> ssubtype(&Bonus::subtype);
 		return ssubtype;
 	}
 
-	DLL_LINKAGE CSelectFieldEqual<CAddInfo> & info()
+	DLL_LINKAGE const CSelectFieldEqual<CAddInfo> & info()
 	{
-		static CSelectFieldEqual<CAddInfo> sinfo(&Bonus::additionalInfo);
+		static const CSelectFieldEqual<CAddInfo> sinfo(&Bonus::additionalInfo);
 		return sinfo;
 	}
 
-	DLL_LINKAGE CSelectFieldEqual<BonusSource> & sourceType()
+	DLL_LINKAGE const CSelectFieldEqual<BonusSource> & sourceType()
 	{
-		static CSelectFieldEqual<BonusSource> ssourceType(&Bonus::source);
+		static const CSelectFieldEqual<BonusSource> ssourceType(&Bonus::source);
 		return ssourceType;
 	}
 
-	DLL_LINKAGE CSelectFieldEqual<BonusSource> & targetSourceType()
+	DLL_LINKAGE const CSelectFieldEqual<BonusSource> & targetSourceType()
 	{
-		static CSelectFieldEqual<BonusSource> ssourceType(&Bonus::targetSourceType);
+		static const CSelectFieldEqual<BonusSource> ssourceType(&Bonus::targetSourceType);
 		return ssourceType;
 	}
 
-	DLL_LINKAGE CSelectFieldEqual<BonusLimitEffect> & effectRange()
+	DLL_LINKAGE const CSelectFieldEqual<BonusLimitEffect> & effectRange()
 	{
-		static CSelectFieldEqual<BonusLimitEffect> seffectRange(&Bonus::effectRange);
+		static const CSelectFieldEqual<BonusLimitEffect> seffectRange(&Bonus::effectRange);
 		return seffectRange;
 	}
 

+ 6 - 6
lib/bonuses/BonusSelector.h

@@ -125,12 +125,12 @@ public:
 
 namespace Selector
 {
-	extern DLL_LINKAGE CSelectFieldEqual<BonusType> & type();
-	extern DLL_LINKAGE CSelectFieldEqual<BonusSubtypeID> & subtype();
-	extern DLL_LINKAGE CSelectFieldEqual<CAddInfo> & info();
-	extern DLL_LINKAGE CSelectFieldEqual<BonusSource> & sourceType();
-	extern DLL_LINKAGE CSelectFieldEqual<BonusSource> & targetSourceType();
-	extern DLL_LINKAGE CSelectFieldEqual<BonusLimitEffect> & effectRange();
+	extern DLL_LINKAGE const CSelectFieldEqual<BonusType> & type();
+	extern DLL_LINKAGE const CSelectFieldEqual<BonusSubtypeID> & subtype();
+	extern DLL_LINKAGE const CSelectFieldEqual<CAddInfo> & info();
+	extern DLL_LINKAGE const CSelectFieldEqual<BonusSource> & sourceType();
+	extern DLL_LINKAGE const CSelectFieldEqual<BonusSource> & targetSourceType();
+	extern DLL_LINKAGE const CSelectFieldEqual<BonusLimitEffect> & effectRange();
 	extern DLL_LINKAGE CWillLastTurns turns;
 	extern DLL_LINKAGE CWillLastDays days;
 

+ 1 - 0
lib/campaign/CampaignState.cpp

@@ -11,6 +11,7 @@
 #include "CampaignState.h"
 
 #include "../JsonNode.h"
+#include "../Point.h"
 #include "../filesystem/ResourcePath.h"
 #include "../VCMI_Lib.h"
 #include "../CGeneralTextHandler.h"

+ 12 - 10
lib/gameState/CGameState.cpp

@@ -36,6 +36,8 @@
 #include "../mapObjectConstructors/DwellingInstanceConstructor.h"
 #include "../mapObjects/CGHeroInstance.h"
 #include "../mapObjects/CGTownInstance.h"
+#include "../mapObjects/CQuest.h"
+#include "../mapObjects/MiscObjects.h"
 #include "../mapping/CMap.h"
 #include "../mapping/CMapEditManager.h"
 #include "../mapping/CMapService.h"
@@ -226,7 +228,7 @@ void CGameState::init(const IMapService * mapService, StartInfo * si, Load::Prog
 
 	for(auto & elem : teams)
 	{
-		CGObelisk::visited[elem.first] = 0;
+		map->obelisksVisited[elem.first] = 0;
 	}
 
 	logGlobal->debug("\tChecking objectives");
@@ -766,11 +768,11 @@ void CGameState::initTowns()
 	if (campaign)
 		campaign->initTowns();
 
-	CGTownInstance::universitySkills.clear();
-	CGTownInstance::universitySkills.push_back(SecondarySkill(SecondarySkill::FIRE_MAGIC));
-	CGTownInstance::universitySkills.push_back(SecondarySkill(SecondarySkill::AIR_MAGIC));
-	CGTownInstance::universitySkills.push_back(SecondarySkill(SecondarySkill::WATER_MAGIC));
-	CGTownInstance::universitySkills.push_back(SecondarySkill(SecondarySkill::EARTH_MAGIC));
+	map->townUniversitySkills.clear();
+	map->townUniversitySkills.push_back(SecondarySkill(SecondarySkill::FIRE_MAGIC));
+	map->townUniversitySkills.push_back(SecondarySkill(SecondarySkill::AIR_MAGIC));
+	map->townUniversitySkills.push_back(SecondarySkill(SecondarySkill::WATER_MAGIC));
+	map->townUniversitySkills.push_back(SecondarySkill(SecondarySkill::EARTH_MAGIC));
 
 	for (auto & elem : map->towns)
 	{
@@ -1202,7 +1204,7 @@ int3 CGameState::guardingCreaturePosition (int3 pos) const
 
 void CGameState::updateRumor()
 {
-	static std::vector<RumorState::ERumorType> rumorTypes = {RumorState::TYPE_MAP, RumorState::TYPE_SPECIAL, RumorState::TYPE_RAND, RumorState::TYPE_RAND};
+	static const std::vector<RumorState::ERumorType> rumorTypes = {RumorState::TYPE_MAP, RumorState::TYPE_SPECIAL, RumorState::TYPE_RAND, RumorState::TYPE_RAND};
 	std::vector<RumorState::ERumorTypeSpecial> sRumorTypes = {
 		RumorState::RUMOR_OBELISKS, RumorState::RUMOR_ARTIFACTS, RumorState::RUMOR_ARMY, RumorState::RUMOR_INCOME};
 	if(map->grailPos.valid()) // Grail should always be on map, but I had related crash I didn't manage to reproduce
@@ -1716,10 +1718,10 @@ void CGameState::obtainPlayersStats(SThievesGuildInfo & tgi, int level)
 	}
 	if(level >= 3) //obelisks found
 	{
-		auto getObeliskVisited = [](const TeamID & t)
+		auto getObeliskVisited = [&](const TeamID & t)
 		{
-			if(CGObelisk::visited.count(t))
-				return CGObelisk::visited[t];
+			if(map->obelisksVisited.count(t))
+				return map->obelisksVisited[t];
 			else
 				return ui8(0);
 		};

+ 1 - 0
lib/gameState/CGameStateCampaign.cpp

@@ -16,6 +16,7 @@
 #include "../campaign/CampaignState.h"
 #include "../mapping/CMapEditManager.h"
 #include "../mapObjects/CGHeroInstance.h"
+#include "../mapObjects/CGTownInstance.h"
 #include "../networkPacks/ArtifactLocation.h"
 #include "../mapObjectConstructors/AObjectTypeHandler.h"
 #include "../mapObjectConstructors/CObjectClassesHandler.h"

+ 1 - 0
lib/mapObjects/CGDwelling.cpp

@@ -16,6 +16,7 @@
 #include "../mapObjectConstructors/CObjectClassesHandler.h"
 #include "../mapObjectConstructors/DwellingInstanceConstructor.h"
 #include "../mapObjects/CGHeroInstance.h"
+#include "../mapObjects/CGTownInstance.h"
 #include "../networkPacks/StackLocation.h"
 #include "../networkPacks/PacksForClient.h"
 #include "../networkPacks/PacksForClientBattle.h"

+ 1 - 0
lib/mapObjects/CGHeroInstance.cpp

@@ -33,6 +33,7 @@
 #include "../serializer/JsonSerializeFormat.h"
 #include "../mapObjectConstructors/AObjectTypeHandler.h"
 #include "../mapObjectConstructors/CObjectClassesHandler.h"
+#include "../mapObjects/MiscObjects.h"
 #include "../modding/ModScope.h"
 #include "../networkPacks/PacksForClient.h"
 #include "../networkPacks/PacksForClientBattle.h"

+ 2 - 12
lib/mapObjects/CGTownInstance.cpp

@@ -33,10 +33,6 @@
 
 VCMI_LIB_NAMESPACE_BEGIN
 
-std::vector<const CArtifact *> CGTownInstance::merchantArtifacts;
-std::vector<TradeItemBuy> CGTownInstance::universitySkills;
-
-
 int CGTownInstance::getSightRadius() const //returns sight distance
 {
 	auto ret = CBuilding::HEIGHT_NO_TOWER;
@@ -772,7 +768,7 @@ std::vector<TradeItemBuy> CGTownInstance::availableItemsIds(EMarketMode mode) co
 	if(mode == EMarketMode::RESOURCE_ARTIFACT)
 	{
 		std::vector<TradeItemBuy> ret;
-		for(const CArtifact *a : merchantArtifacts)
+		for(const CArtifact *a : cb->gameState()->map->townMerchantArtifacts)
 			if(a)
 				ret.push_back(a->getId());
 			else
@@ -781,7 +777,7 @@ std::vector<TradeItemBuy> CGTownInstance::availableItemsIds(EMarketMode mode) co
 	}
 	else if ( mode == EMarketMode::RESOURCE_SKILL )
 	{
-		return universitySkills;
+		return cb->gameState()->map->townUniversitySkills;
 	}
 	else
 		return IMarket::availableItemsIds(mode);
@@ -1115,12 +1111,6 @@ void CGTownInstance::afterRemoveFromMap(CMap * map)
 	vstd::erase_if_present(map->towns, this);
 }
 
-void CGTownInstance::reset()
-{
-	CGTownInstance::merchantArtifacts.clear();
-	CGTownInstance::universitySkills.clear();
-}
-
 void CGTownInstance::serializeJsonOptions(JsonSerializeFormat & handler)
 {
 	CGObjectInstance::serializeJsonOwner(handler);

+ 0 - 4
lib/mapObjects/CGTownInstance.h

@@ -67,9 +67,6 @@ public:
 	std::pair<si32, si32> bonusValue;//var to store town bonuses (rampart = resources from mystic pond);
 
 	//////////////////////////////////////////////////////////////////////////
-	static std::vector<const CArtifact *> merchantArtifacts; //vector of artifacts available at Artifact merchant, NULLs possible (for making empty space when artifact is bought)
-	static std::vector<TradeItemBuy> universitySkills;//skills for university of magic
-
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{
 		h & static_cast<CGDwelling&>(*this);
@@ -216,7 +213,6 @@ public:
 
 	void afterAddToMap(CMap * map) override;
 	void afterRemoveFromMap(CMap * map) override;
-	static void reset();
 
 	inline bool isBattleOutsideTown(const CGHeroInstance * defendingHero) const
 	{

+ 5 - 14
lib/mapObjects/MiscObjects.cpp

@@ -34,9 +34,6 @@
 
 VCMI_LIB_NAMESPACE_BEGIN
 
-ui8 CGObelisk::obeliskCount = 0; //how many obelisks are on map
-std::map<TeamID, ui8> CGObelisk::visited; //map: team_id => how many obelisks has been visited
-
 ///helpers
 static std::string visitedTxt(const bool visited)
 {
@@ -1243,13 +1240,7 @@ void CGObelisk::onHeroVisit( const CGHeroInstance * h ) const
 
 void CGObelisk::initObj(CRandomGenerator & rand)
 {
-	obeliskCount++;
-}
-
-void CGObelisk::reset()
-{
-	obeliskCount = 0;
-	visited.clear();
+	cb->gameState()->map->obeliskCount++;
 }
 
 std::string CGObelisk::getHoverText(PlayerColor player) const
@@ -1263,12 +1254,12 @@ void CGObelisk::setPropertyDer(ObjProperty what, ObjPropertyID identifier)
 	{
 		case ObjProperty::OBELISK_VISITED:
 			{
-				auto progress = ++visited[identifier.as<TeamID>()];
-				logGlobal->debug("Player %d: obelisk progress %d / %d", identifier.getNum(), static_cast<int>(progress) , static_cast<int>(obeliskCount));
+				auto progress = ++cb->gameState()->map->obelisksVisited[identifier.as<TeamID>()];
+				logGlobal->debug("Player %d: obelisk progress %d / %d", identifier.getNum(), static_cast<int>(progress) , static_cast<int>(cb->gameState()->map->obeliskCount));
 
-				if(progress > obeliskCount)
+				if(progress > cb->gameState()->map->obeliskCount)
 				{
-					logGlobal->error("Visited %d of %d", static_cast<int>(progress), obeliskCount);
+					logGlobal->error("Visited %d of %d", static_cast<int>(progress), cb->gameState()->map->obeliskCount);
 					throw std::runtime_error("Player visited more obelisks than present on map!");
 				}
 

+ 0 - 4
lib/mapObjects/MiscObjects.h

@@ -389,13 +389,9 @@ class DLL_LINKAGE CGObelisk : public CTeamVisited
 public:
 	using CTeamVisited::CTeamVisited;
 
-	static ui8 obeliskCount; //how many obelisks are on map
-	static std::map<TeamID, ui8> visited; //map: team_id => how many obelisks has been visited
-
 	void onHeroVisit(const CGHeroInstance * h) const override;
 	void initObj(CRandomGenerator & rand) override;
 	std::string getHoverText(PlayerColor player) const override;
-	static void reset();
 
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{

+ 1 - 0
lib/mapping/CDrawRoadsOperation.cpp

@@ -12,6 +12,7 @@
 #include "CDrawRoadsOperation.h"
 #include "CMap.h"
 
+#include "../CRandomGenerator.h"
 #include "../RoadHandler.h"
 #include "../RiverHandler.h"
 

+ 6 - 2
lib/mapping/CMap.cpp

@@ -19,6 +19,8 @@
 #include "../RoadHandler.h"
 #include "../TerrainHandler.h"
 #include "../mapObjects/CGHeroInstance.h"
+#include "../mapObjects/CGTownInstance.h"
+#include "../mapObjects/CQuest.h"
 #include "../mapObjects/ObjectTemplate.h"
 #include "../CGeneralTextHandler.h"
 #include "../spells/CSpellHandler.h"
@@ -676,8 +678,10 @@ CMapEditManager * CMap::getEditManager()
 
 void CMap::resetStaticData()
 {
-	CGObelisk::reset();
-	CGTownInstance::reset();
+	obeliskCount = 0;
+	obelisksVisited.clear();
+	townMerchantArtifacts.clear();
+	townUniversitySkills.clear();
 }
 
 VCMI_LIB_NAMESPACE_END

+ 14 - 8
lib/mapping/CMap.h

@@ -10,13 +10,13 @@
 
 #pragma once
 
+#include "CMapDefines.h"
 #include "CMapHeader.h"
+
+#include "../ConstTransitivePtr.h"
 #include "../GameCallbackHolder.h"
 #include "../MetaString.h"
-#include "../mapObjects/MiscObjects.h" // To serialize static props
-#include "../mapObjects/CQuest.h" // To serialize static props
-#include "../mapObjects/CGTownInstance.h" // To serialize static props
-#include "CMapDefines.h"
+#include "../networkPacks/TradeItem.h"
 
 VCMI_LIB_NAMESPACE_BEGIN
 
@@ -159,6 +159,12 @@ public:
 
 	bool waterMap;
 
+	ui8 obeliskCount = 0; //how many obelisks are on map
+	std::map<TeamID, ui8> obelisksVisited; //map: team_id => how many obelisks has been visited
+
+	std::vector<const CArtifact *> townMerchantArtifacts;
+	std::vector<TradeItemBuy> townUniversitySkills;
+
 private:
 	/// a 3-dimensional array of terrain tiles, access is as follows: x, y, level. where level=1 is underground
 	boost::multi_array<TerrainTile, 3> terrain;
@@ -193,10 +199,10 @@ public:
 		h & artInstances;
 
 		// static members
-		h & CGObelisk::obeliskCount;
-		h & CGObelisk::visited;
-		h & CGTownInstance::merchantArtifacts;
-		h & CGTownInstance::universitySkills;
+		h & obeliskCount;
+		h & obelisksVisited;
+		h & townMerchantArtifacts;
+		h & townUniversitySkills;
 
 		h & instanceNames;
 	}

+ 5 - 4
lib/mapping/CMapOperation.cpp

@@ -12,7 +12,9 @@
 #include "CMapOperation.h"
 
 #include "../VCMI_Lib.h"
+#include "../CRandomGenerator.h"
 #include "../TerrainHandler.h"
+#include "../mapObjects/CGObjectInstance.h"
 #include "CMap.h"
 #include "MapEditUtils.h"
 
@@ -510,9 +512,8 @@ CDrawTerrainOperation::InvalidTiles CDrawTerrainOperation::getInvalidTiles(const
 		{
 			if(map->isInTheMap(pos))
 			{
-				const auto & ptrConfig = VLC->terviewh;
 				const auto * terType = map->getTile(pos).terType;
-				auto valid = validateTerrainView(pos, ptrConfig->getTerrainTypePatternById("n1")).result;
+				auto valid = validateTerrainView(pos, VLC->terviewh->getTerrainTypePatternById("n1")).result;
 
 				// Special validity check for rock & water
 				if(valid && (terType->isWater() || !terType->isPassable()))
@@ -520,7 +521,7 @@ CDrawTerrainOperation::InvalidTiles CDrawTerrainOperation::getInvalidTiles(const
 					static const std::string patternIds[] = { "s1", "s2" };
 					for(const auto & patternId : patternIds)
 					{
-						valid = !validateTerrainView(pos, ptrConfig->getTerrainTypePatternById(patternId)).result;
+						valid = !validateTerrainView(pos, VLC->terviewh->getTerrainTypePatternById(patternId)).result;
 						if(!valid) break;
 					}
 				}
@@ -530,7 +531,7 @@ CDrawTerrainOperation::InvalidTiles CDrawTerrainOperation::getInvalidTiles(const
 					static const std::string patternIds[] = { "n2", "n3" };
 					for(const auto & patternId : patternIds)
 					{
-						valid = validateTerrainView(pos, ptrConfig->getTerrainTypePatternById(patternId)).result;
+						valid = validateTerrainView(pos, VLC->terviewh->getTerrainTypePatternById(patternId)).result;
 						if(valid) break;
 					}
 				}

+ 1 - 0
lib/mapping/MapFormatJson.cpp

@@ -28,6 +28,7 @@
 #include "../mapObjects/ObjectTemplate.h"
 #include "../mapObjects/CGHeroInstance.h"
 #include "../mapObjects/CGTownInstance.h"
+#include "../mapObjects/MiscObjects.h"
 #include "../modding/ModScope.h"
 #include "../modding/ModUtility.h"
 #include "../spells/CSpellHandler.h"

+ 1 - 0
lib/mapping/ObstacleProxy.cpp

@@ -13,6 +13,7 @@
 #include "../mapping/CMap.h"
 #include "../mapObjectConstructors/AObjectTypeHandler.h"
 #include "../mapObjectConstructors/CObjectClassesHandler.h"
+#include "../mapObjects/CGObjectInstance.h"
 #include "../mapObjects/ObjectTemplate.h"
 
 VCMI_LIB_NAMESPACE_BEGIN

+ 4 - 1
lib/networkPacks/NetPacksLib.cpp

@@ -34,6 +34,9 @@
 #include "TerrainHandler.h"
 #include "mapObjects/CGCreature.h"
 #include "mapObjects/CGMarket.h"
+#include "mapObjects/CGTownInstance.h"
+#include "mapObjects/CQuest.h"
+#include "mapObjects/MiscObjects.h"
 #include "mapObjectConstructors/AObjectTypeHandler.h"
 #include "mapObjectConstructors/CObjectClassesHandler.h"
 #include "campaign/CampaignState.h"
@@ -1990,7 +1993,7 @@ void SetAvailableArtifacts::applyGs(CGameState * gs) const
 	}
 	else
 	{
-		CGTownInstance::merchantArtifacts = arts;
+		gs->map->townMerchantArtifacts = arts;
 	}
 }
 

+ 2 - 0
lib/pathfinder/CPathfinder.cpp

@@ -19,6 +19,8 @@
 #include "../CPlayerState.h"
 #include "../TerrainHandler.h"
 #include "../mapObjects/CGHeroInstance.h"
+#include "../mapObjects/CGTownInstance.h"
+#include "../mapObjects/MiscObjects.h"
 #include "../mapping/CMap.h"
 #include "spells/CSpellHandler.h"
 

+ 1 - 0
lib/pathfinder/NodeStorage.cpp

@@ -16,6 +16,7 @@
 
 #include "../CPlayerState.h"
 #include "../mapObjects/CGHeroInstance.h"
+#include "../mapObjects/MiscObjects.h"
 #include "../mapping/CMap.h"
 
 VCMI_LIB_NAMESPACE_BEGIN

+ 1 - 0
lib/rmg/CMapGenerator.cpp

@@ -17,6 +17,7 @@
 #include "../mapObjectConstructors/AObjectTypeHandler.h"
 #include "../mapObjectConstructors/CObjectClassesHandler.h"
 #include "../mapping/CMapEditManager.h"
+#include "../CArtHandler.h"
 #include "../CTownHandler.h"
 #include "../CHeroHandler.h"
 #include "../constants/StringConstants.h"

+ 3 - 2
lib/rmg/CZonePlacer.cpp

@@ -9,9 +9,10 @@
  */
 
 #include "StdInc.h"
-#include <stack>
-#include "../CRandomGenerator.h"
 #include "CZonePlacer.h"
+
+#include "../CRandomGenerator.h"
+#include "../CTownHandler.h"
 #include "../TerrainHandler.h"
 #include "../mapping/CMap.h"
 #include "../mapping/CMapEditManager.h"

+ 1 - 0
lib/rmg/RmgMap.h

@@ -17,6 +17,7 @@ VCMI_LIB_NAMESPACE_BEGIN
 
 class CMap;
 class CMapEditManager;
+class CRandomGenerator;
 class TileInfo;
 class CMapGenOptions;
 class Zone;

+ 1 - 0
lib/rmg/RmgObject.cpp

@@ -17,6 +17,7 @@
 #include "../mapObjectConstructors/AObjectTypeHandler.h"
 #include "../mapObjectConstructors/CObjectClassesHandler.h"
 #include "../mapObjects/ObjectTemplate.h"
+#include "../mapObjects/CGObjectInstance.h"
 #include "Functions.h"
 #include "../TerrainHandler.h"
 

+ 1 - 0
lib/rmg/modificators/MinePlacer.cpp

@@ -12,6 +12,7 @@
 #include "../RmgMap.h"
 #include "../../mapObjectConstructors/AObjectTypeHandler.h"
 #include "../../mapObjectConstructors/CObjectClassesHandler.h"
+#include "../../mapObjects/MiscObjects.h"
 #include "../../mapping/CMapEditManager.h"
 #include "../RmgPath.h"
 #include "../RmgObject.h"

+ 1 - 0
lib/rmg/modificators/ObstaclePlacer.cpp

@@ -24,6 +24,7 @@
 #include "../../mapping/CMapEditManager.h"
 #include "../../mapping/CMap.h"
 #include "../../mapping/ObstacleProxy.h"
+#include "../../mapObjects/CGObjectInstance.h"
 
 VCMI_LIB_NAMESPACE_BEGIN
 

+ 1 - 0
lib/rmg/modificators/RoadPlacer.cpp

@@ -17,6 +17,7 @@
 #include "../CMapGenerator.h"
 #include "../threadpool/MapProxy.h"
 #include "../../mapping/CMapEditManager.h"
+#include "../../mapObjects/CGObjectInstance.h"
 #include "../../modding/IdentifierStorage.h"
 #include "../../modding/ModScope.h"
 #include "../../TerrainHandler.h"

+ 1 - 0
lib/rmg/modificators/TerrainPainter.cpp

@@ -20,6 +20,7 @@
 #include "../RmgMap.h"
 #include "../../VCMI_Lib.h"
 #include "../../TerrainHandler.h"
+#include "../../CTownHandler.h"
 
 VCMI_LIB_NAMESPACE_BEGIN
 

+ 1 - 0
lib/rmg/modificators/TownPlacer.cpp

@@ -14,6 +14,7 @@
 #include "../RmgMap.h"
 #include "../../mapObjectConstructors/AObjectTypeHandler.h"
 #include "../../mapObjectConstructors/CObjectClassesHandler.h"
+#include "../../mapObjects/CGTownInstance.h"
 #include "../../mapping/CMap.h"
 #include "../../mapping/CMapEditManager.h"
 #include "../../spells/CSpellHandler.h" //for choosing random spells

+ 6 - 4
lib/rmg/modificators/TreasurePlacer.cpp

@@ -26,6 +26,8 @@
 #include "../../mapObjectConstructors/DwellingInstanceConstructor.h"
 #include "../../mapObjects/CGHeroInstance.h"
 #include "../../mapObjects/CGPandoraBox.h"
+#include "../../mapObjects/CQuest.h"
+#include "../../mapObjects/MiscObjects.h"
 #include "../../CCreatureHandler.h"
 #include "../../spells/CSpellHandler.h" //for choosing random spells
 #include "../../mapping/CMap.h"
@@ -110,7 +112,7 @@ void TreasurePlacer::addAllPossibleObjects()
 
 		//prisons
 		//levels 1, 5, 10, 20, 30
-		static int prisonsLevels = std::min(generator.getConfig().prisonExperience.size(), generator.getConfig().prisonValues.size());
+		static const int prisonsLevels = std::min(generator.getConfig().prisonExperience.size(), generator.getConfig().prisonValues.size());
 
 		size_t prisonsLeft = getMaxPrisons();
 		for (int i = prisonsLevels - 1; i >= 0; i--)
@@ -178,7 +180,7 @@ void TreasurePlacer::addAllPossibleObjects()
 		if(dwellingType == Obj::CREATURE_GENERATOR1)
 		{
 			//don't spawn original "neutral" dwellings that got replaced by Conflux dwellings in AB
-			static MapObjectSubID elementalConfluxROE[] = {7, 13, 16, 47};
+			static const MapObjectSubID elementalConfluxROE[] = {7, 13, 16, 47};
 			for(auto const & i : elementalConfluxROE)
 				vstd::erase_if_present(subObjects, i);
 		}
@@ -516,7 +518,7 @@ void TreasurePlacer::addAllPossibleObjects()
 			}
 		}
 		
-		static int seerLevels = std::min(generator.getConfig().questValues.size(), generator.getConfig().questRewardValues.size());
+		static const int seerLevels = std::min(generator.getConfig().questValues.size(), generator.getConfig().questRewardValues.size());
 		for(int i = 0; i < seerLevels; i++) //seems that code for exp and gold reward is similiar
 		{
 			int randomAppearance = chooseRandomAppearance(zone.getRand(), Obj::SEER_HUT, zone.getTerrainType());
@@ -819,7 +821,7 @@ void TreasurePlacer::createTreasures(ObjectManager& manager)
 
 	int mapMonsterStrength = map.getMapGenOptions().getMonsterStrength();
 	int monsterStrength = (zone.monsterStrength == EMonsterStrength::ZONE_NONE ? 0 : zone.monsterStrength + mapMonsterStrength - 1); //array index from 0 to 4; pick any correct value for ZONE_NONE, minGuardedValue won't be used in this case anyway
-	static int minGuardedValues[] = { 6500, 4167, 3000, 1833, 1333 };
+	static const int minGuardedValues[] = { 6500, 4167, 3000, 1833, 1333 };
 	minGuardedValue = minGuardedValues[monsterStrength];
 
 	auto valueComparator = [](const CTreasureInfo& lhs, const CTreasureInfo& rhs) -> bool

+ 1 - 0
lib/rmg/modificators/WaterProxy.cpp

@@ -15,6 +15,7 @@
 #include "../../TerrainHandler.h"
 #include "../../mapObjectConstructors/AObjectTypeHandler.h"
 #include "../../mapObjectConstructors/CObjectClassesHandler.h"
+#include "../../mapObjects/MiscObjects.h"
 #include "../../mapping/CMap.h"
 #include "../../mapping/CMapEditManager.h"
 #include "../RmgPath.h"

+ 7 - 0
lib/serializer/CSerializer.cpp

@@ -14,6 +14,7 @@
 #include "../mapping/CMap.h"
 #include "../CHeroHandler.h"
 #include "../mapObjects/CGHeroInstance.h"
+#include "../mapObjects/CQuest.h"
 
 VCMI_LIB_NAMESPACE_BEGIN
 
@@ -24,8 +25,14 @@ void CSerializer::addStdVecItems(CGameState *gs, LibClasses *lib)
 {
 	registerVectoredType<CGObjectInstance, ObjectInstanceID>(&gs->map->objects,
 		[](const CGObjectInstance &obj){ return obj.id; });
+	registerVectoredType<CHero, HeroTypeID>(&lib->heroh->objects,
+		[](const CHero &h){ return h.getId(); });
 	registerVectoredType<CGHeroInstance, HeroTypeID>(&gs->map->allHeroes,
 		[](const CGHeroInstance &h){ return h.type->getId(); });
+	registerVectoredType<CCreature, CreatureID>(&lib->creh->objects,
+		[](const CCreature &cre){ return cre.getId(); });
+	registerVectoredType<CArtifact, ArtifactID>(&lib->arth->objects,
+		[](const CArtifact &art){ return art.getId(); });
 	registerVectoredType<CArtifactInstance, ArtifactInstanceID>(&gs->map->artInstances,
 		[](const CArtifactInstance &artInst){ return artInst.getId(); });
 	registerVectoredType<CQuest, si32>(&gs->map->quests,

+ 5 - 0
lib/serializer/CSerializer.h

@@ -65,6 +65,11 @@ class DLL_LINKAGE CSerializer
 		return t.getNum();
 	}
 
+	template <typename T, typename U>
+	void registerVectoredType(const std::vector<T*> *Vector, const std::function<U(const T&)> &idRetriever)
+	{
+		vectors[&typeid(T)] = VectorizedObjectInfo<T, U>(Vector, idRetriever);
+	}
 	template <typename T, typename U>
 	void registerVectoredType(const std::vector<ConstTransitivePtr<T> > *Vector, const std::function<U(const T&)> &idRetriever)
 	{

+ 2 - 0
lib/spells/AdventureSpellMechanics.cpp

@@ -18,6 +18,8 @@
 #include "../CPlayerState.h"
 #include "../CRandomGenerator.h"
 #include "../mapObjects/CGHeroInstance.h"
+#include "../mapObjects/CGTownInstance.h"
+#include "../mapObjects/MiscObjects.h"
 #include "../mapping/CMap.h"
 #include "../networkPacks/PacksForClient.h"
 

+ 1 - 0
mapeditor/maphandler.cpp

@@ -18,6 +18,7 @@
 #include "../lib/mapping/CMap.h"
 #include "../lib/mapObjects/CGHeroInstance.h"
 #include "../lib/mapObjects/ObjectTemplate.h"
+#include "../lib/mapObjects/MiscObjects.h"
 #include "../lib/CHeroHandler.h"
 #include "../lib/CTownHandler.h"
 #include "../lib/GameConstants.h"

+ 1 - 0
mapeditor/mapsettings/translations.cpp

@@ -13,6 +13,7 @@
 #include "ui_translations.h"
 #include "../../lib/Languages.h"
 #include "../../lib/CGeneralTextHandler.h"
+#include "../../lib/mapObjects/CGObjectInstance.h"
 #include "../../lib/VCMI_Lib.h"
 
 void Translations::cleanupRemovedItems(CMap & map)

+ 3 - 1
server/CGameHandler.cpp

@@ -49,6 +49,8 @@
 #include "../lib/mapping/CMap.h"
 #include "../lib/mapping/CMapService.h"
 #include "../lib/mapObjects/CGMarket.h"
+#include "../lib/mapObjects/CGTownInstance.h"
+#include "../lib/mapObjects/MiscObjects.h"
 #include "../lib/modding/ModIncompatibility.h"
 #include "../lib/networkPacks/StackLocation.h"
 #include "../lib/pathfinder/CPathfinder.h"
@@ -2999,7 +3001,7 @@ bool CGameHandler::buyArtifact(const IMarket *m, const CGHeroInstance *h, GameRe
 	if(dynamic_cast<const CGTownInstance *>(m))
 	{
 		saa.id = ObjectInstanceID::NONE;
-		saa.arts = CGTownInstance::merchantArtifacts;
+		saa.arts = gs->map->townMerchantArtifacts;
 	}
 	else if(const CGBlackMarket *bm = dynamic_cast<const CGBlackMarket *>(m)) //black market
 	{