From d6a357fd1723bb5fb59f925b55ec2cf49dadaa7c Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Fri, 2 Jun 2023 21:47:37 +0300 Subject: [PATCH] Split some map object files into smaller files. Reduced includes usage. --- AI/Nullkiller/AIGateway.cpp | 1 + AI/Nullkiller/AIUtility.h | 1 - AI/Nullkiller/Engine/FuzzyHelper.cpp | 5 +- AI/Nullkiller/Engine/PriorityEvaluator.cpp | 4 +- AI/VCAI/AIUtility.h | 1 - AI/VCAI/FuzzyHelper.cpp | 9 +- AI/VCAI/MapObjectsEvaluator.cpp | 1 + AI/VCAI/VCAI.cpp | 1 + CCallback.cpp | 1 - client/CPlayerInterface.cpp | 2 +- client/NetPacksClient.cpp | 1 + client/mapView/MapRenderer.cpp | 1 + client/mapView/MapViewCache.cpp | 1 + client/mapView/mapHandler.cpp | 3 +- client/render/Graphics.cpp | 2 - client/windows/GUIClasses.cpp | 2 + cmake_modules/VCMI_lib.cmake | 25 +- lib/CArtHandler.cpp | 3 +- lib/CCreatureHandler.cpp | 3 +- lib/CGameInfoCallback.cpp | 1 - lib/CGameInterface.h | 3 +- lib/CGameState.cpp | 3 +- lib/CHeroHandler.cpp | 4 +- lib/CModHandler.cpp | 3 +- lib/CTownHandler.cpp | 4 +- lib/CTownHandler.h | 2 +- lib/GameConstants.cpp | 1 - lib/IGameCallback.cpp | 5 +- lib/JsonRandom.cpp | 2 +- lib/NetPacks.h | 4 + lib/NetPacksLib.cpp | 5 +- lib/PathfinderUtil.h | 3 +- lib/ResourceSet.cpp | 2 +- lib/VCMI_Lib.cpp | 4 +- .../AObjectTypeHandler.cpp | 225 ++++++++ .../AObjectTypeHandler.h | 127 +++++ .../CObjectClassesHandler.cpp | 211 +------- .../CObjectClassesHandler.h | 138 +++++ .../CRewardableConstructor.cpp | 3 +- .../CRewardableConstructor.h | 2 +- .../CommonConstructors.cpp | 17 +- .../CommonConstructors.h | 13 +- lib/mapObjectConstructors/IObjectInfo.h | 58 ++ lib/mapObjectConstructors/RandomMapInfo.h | 46 ++ lib/mapObjectConstructors/SObjectSounds.h | 28 + lib/mapObjects/CArmedInstance.h | 2 +- lib/mapObjects/CBank.cpp | 3 +- lib/mapObjects/CBank.h | 1 - lib/mapObjects/CGDwelling.cpp | 3 +- lib/mapObjects/CGHeroInstance.cpp | 3 +- lib/mapObjects/CGHeroInstance.h | 2 - lib/mapObjects/CGMarket.cpp | 159 +----- lib/mapObjects/CGMarket.h | 20 +- lib/mapObjects/CGObjectInstance.cpp | 344 ++++++++++++ lib/mapObjects/CGObjectInstance.h | 143 +++++ lib/mapObjects/CGPandoraBox.h | 1 - lib/mapObjects/CGTownBuilding.h | 2 +- lib/mapObjects/CGTownInstance.cpp | 3 +- lib/mapObjects/CGTownInstance.h | 4 +- lib/mapObjects/CObjectClassesHandler.h | 337 ------------ lib/mapObjects/CObjectHandler.cpp | 497 +----------------- lib/mapObjects/CObjectHandler.h | 228 +------- lib/mapObjects/CQuest.cpp | 2 +- lib/mapObjects/CQuest.h | 5 - lib/mapObjects/CRewardableObject.cpp | 3 +- lib/mapObjects/IMarket.cpp | 175 ++++++ lib/mapObjects/IMarket.h | 35 ++ lib/mapObjects/IObjectInterface.cpp | 188 +++++++ lib/mapObjects/IObjectInterface.h | 107 ++++ lib/mapObjects/MiscObjects.cpp | 1 - lib/mapObjects/MiscObjects.h | 5 +- lib/mapObjects/ObjectTemplate.cpp | 5 +- lib/mapping/CMap.cpp | 2 +- lib/mapping/CMapEditManager.cpp | 2 - lib/mapping/MapFormatH3M.cpp | 4 +- lib/mapping/MapFormatJson.cpp | 4 +- lib/mapping/MapIdentifiersH3M.cpp | 4 +- lib/mapping/ObstacleProxy.cpp | 7 +- lib/registerTypes/RegisterTypes.h | 7 +- lib/registerTypes/TypesClientPacks1.cpp | 1 - lib/registerTypes/TypesClientPacks2.cpp | 1 - lib/registerTypes/TypesLobbyPacks.cpp | 1 - lib/registerTypes/TypesMapObjects1.cpp | 1 - lib/registerTypes/TypesMapObjects2.cpp | 1 - lib/registerTypes/TypesMapObjects3.cpp | 1 - lib/registerTypes/TypesServerPacks.cpp | 1 - lib/rewardable/Configuration.h | 1 + lib/rewardable/Info.cpp | 3 + lib/rewardable/Info.h | 2 +- lib/rewardable/Interface.h | 3 +- lib/rewardable/Limiter.cpp | 15 + lib/rewardable/Limiter.h | 17 +- lib/rewardable/Reward.cpp | 17 + lib/rewardable/Reward.h | 20 +- lib/rmg/CMapGenerator.cpp | 3 +- lib/rmg/Functions.cpp | 4 +- lib/rmg/RmgObject.cpp | 6 +- lib/rmg/modificators/ConnectionsPlacer.cpp | 3 +- lib/rmg/modificators/MinePlacer.cpp | 3 +- lib/rmg/modificators/ObjectDistributor.cpp | 5 +- lib/rmg/modificators/ObjectManager.cpp | 4 +- lib/rmg/modificators/QuestArtifactPlacer.cpp | 4 +- lib/rmg/modificators/RiverPlacer.cpp | 4 +- lib/rmg/modificators/TownPlacer.cpp | 3 +- lib/rmg/modificators/TreasurePlacer.cpp | 6 +- lib/rmg/modificators/WaterAdopter.cpp | 1 - lib/rmg/modificators/WaterProxy.cpp | 3 +- lib/rmg/modificators/WaterRoutes.cpp | 1 - lib/spells/ViewSpellInt.cpp | 3 +- mapeditor/graphics.cpp | 6 +- mapeditor/inspector/inspector.cpp | 4 +- mapeditor/mainwindow.cpp | 4 +- mapeditor/mapcontroller.cpp | 4 +- mapeditor/maphandler.cpp | 2 +- mapeditor/mapview.cpp | 4 +- mapeditor/objectbrowser.cpp | 6 +- 116 files changed, 1864 insertions(+), 1593 deletions(-) create mode 100644 lib/mapObjectConstructors/AObjectTypeHandler.cpp create mode 100644 lib/mapObjectConstructors/AObjectTypeHandler.h rename lib/{mapObjects => mapObjectConstructors}/CObjectClassesHandler.cpp (73%) create mode 100644 lib/mapObjectConstructors/CObjectClassesHandler.h rename lib/{mapObjects => mapObjectConstructors}/CRewardableConstructor.cpp (97%) rename lib/{mapObjects => mapObjectConstructors}/CRewardableConstructor.h (95%) rename lib/{mapObjects => mapObjectConstructors}/CommonConstructors.cpp (99%) rename lib/{mapObjects => mapObjectConstructors}/CommonConstructors.h (96%) create mode 100644 lib/mapObjectConstructors/IObjectInfo.h create mode 100644 lib/mapObjectConstructors/RandomMapInfo.h create mode 100644 lib/mapObjectConstructors/SObjectSounds.h create mode 100644 lib/mapObjects/CGObjectInstance.cpp create mode 100644 lib/mapObjects/CGObjectInstance.h delete mode 100644 lib/mapObjects/CObjectClassesHandler.h create mode 100644 lib/mapObjects/IMarket.cpp create mode 100644 lib/mapObjects/IMarket.h create mode 100644 lib/mapObjects/IObjectInterface.cpp create mode 100644 lib/mapObjects/IObjectInterface.h diff --git a/AI/Nullkiller/AIGateway.cpp b/AI/Nullkiller/AIGateway.cpp index 580e98cb3..cf142f177 100644 --- a/AI/Nullkiller/AIGateway.cpp +++ b/AI/Nullkiller/AIGateway.cpp @@ -11,6 +11,7 @@ #include "../../lib/UnlockGuard.h" #include "../../lib/mapObjects/MapObjects.h" +#include "../../lib/mapObjects/ObjectTemplate.h" #include "../../lib/CConfigHandler.h" #include "../../lib/CHeroHandler.h" #include "../../lib/GameSettings.h" diff --git a/AI/Nullkiller/AIUtility.h b/AI/Nullkiller/AIUtility.h index 06dd99dc2..9f193c285 100644 --- a/AI/Nullkiller/AIUtility.h +++ b/AI/Nullkiller/AIUtility.h @@ -45,7 +45,6 @@ #include "../../lib/CTownHandler.h" #include "../../lib/spells/CSpellHandler.h" #include "../../lib/CStopWatch.h" -#include "../../lib/mapObjects/CObjectHandler.h" #include "../../lib/mapObjects/CGHeroInstance.h" #include "../../lib/CPathfinder.h" #include "../../CCallback.h" diff --git a/AI/Nullkiller/Engine/FuzzyHelper.cpp b/AI/Nullkiller/Engine/FuzzyHelper.cpp index 850f69897..0815f4767 100644 --- a/AI/Nullkiller/Engine/FuzzyHelper.cpp +++ b/AI/Nullkiller/Engine/FuzzyHelper.cpp @@ -10,10 +10,13 @@ #include "../StdInc.h" #include "FuzzyHelper.h" -#include "../../../lib/mapObjects/CommonConstructors.h" #include "../Goals/Goals.h" #include "Nullkiller.h" +#include "../../../lib/mapObjectConstructors/AObjectTypeHandler.h" +#include "../../../lib/mapObjectConstructors/CObjectClassesHandler.h" +#include "../../../lib/mapObjectConstructors/CommonConstructors.h" + namespace NKAI { diff --git a/AI/Nullkiller/Engine/PriorityEvaluator.cpp b/AI/Nullkiller/Engine/PriorityEvaluator.cpp index f058b32e3..902470d97 100644 --- a/AI/Nullkiller/Engine/PriorityEvaluator.cpp +++ b/AI/Nullkiller/Engine/PriorityEvaluator.cpp @@ -11,8 +11,10 @@ #include #include "Nullkiller.h" +#include "../../../lib/mapObjectConstructors/AObjectTypeHandler.h" +#include "../../../lib/mapObjectConstructors/CObjectClassesHandler.h" +#include "../../../lib/mapObjectConstructors/CommonConstructors.h" #include "../../../lib/mapObjects/MapObjects.h" -#include "../../../lib/mapObjects/CommonConstructors.h" #include "../../../lib/CCreatureHandler.h" #include "../../../lib/CPathfinder.h" #include "../../../lib/CGameStateFwd.h" diff --git a/AI/VCAI/AIUtility.h b/AI/VCAI/AIUtility.h index 656bb39ab..cbe0a43c0 100644 --- a/AI/VCAI/AIUtility.h +++ b/AI/VCAI/AIUtility.h @@ -15,7 +15,6 @@ #include "../../lib/CTownHandler.h" #include "../../lib/spells/CSpellHandler.h" #include "../../lib/CStopWatch.h" -#include "../../lib/mapObjects/CObjectHandler.h" #include "../../lib/mapObjects/CGHeroInstance.h" #include "../../lib/CPathfinder.h" #include "../../CCallback.h" diff --git a/AI/VCAI/FuzzyHelper.cpp b/AI/VCAI/FuzzyHelper.cpp index ed5ae9c52..ae1941eb8 100644 --- a/AI/VCAI/FuzzyHelper.cpp +++ b/AI/VCAI/FuzzyHelper.cpp @@ -10,10 +10,15 @@ #include "StdInc.h" #include "FuzzyHelper.h" -#include "../../lib/mapObjects/CommonConstructors.h" #include "Goals/Goals.h" #include "VCAI.h" +#include "../../../lib/mapObjectConstructors/AObjectTypeHandler.h" +#include "../../../lib/mapObjectConstructors/CObjectClassesHandler.h" +#include "../../../lib/mapObjectConstructors/CommonConstructors.h" +#include "../../../lib/mapObjects/CBank.h" +#include "../../../lib/mapObjects/CGDwelling.h" + FuzzyHelper * fh; extern boost::thread_specific_ptr ai; @@ -332,4 +337,4 @@ ui64 FuzzyHelper::evaluateDanger(const CGObjectInstance * obj, const VCAI * ai) default: return 0; } -} \ No newline at end of file +} diff --git a/AI/VCAI/MapObjectsEvaluator.cpp b/AI/VCAI/MapObjectsEvaluator.cpp index 764e1008b..fc7c575c2 100644 --- a/AI/VCAI/MapObjectsEvaluator.cpp +++ b/AI/VCAI/MapObjectsEvaluator.cpp @@ -4,6 +4,7 @@ #include "../../lib/VCMI_Lib.h" #include "../../lib/CCreatureHandler.h" #include "../../lib/CHeroHandler.h" +#include "../../lib/mapObjectConstructors/AObjectTypeHandler.h" #include "../../lib/mapObjects/CGHeroInstance.h" #include "../../lib/mapObjects/CGTownInstance.h" #include "../../lib/mapObjects/MiscObjects.h" diff --git a/AI/VCAI/VCAI.cpp b/AI/VCAI/VCAI.cpp index 9ed4411d0..1cbf02287 100644 --- a/AI/VCAI/VCAI.cpp +++ b/AI/VCAI/VCAI.cpp @@ -16,6 +16,7 @@ #include "../../lib/UnlockGuard.h" #include "../../lib/mapObjects/MapObjects.h" +#include "../../lib/mapObjects/ObjectTemplate.h" #include "../../lib/CConfigHandler.h" #include "../../lib/CHeroHandler.h" #include "../../lib/GameSettings.h" diff --git a/CCallback.cpp b/CCallback.cpp index c7bd94fcf..948ca259f 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -16,7 +16,6 @@ #include "client/Client.h" #include "lib/mapping/CMap.h" #include "lib/CBuildingHandler.h" -#include "lib/mapObjects/CObjectClassesHandler.h" #include "lib/CGeneralTextHandler.h" #include "lib/CHeroHandler.h" #include "lib/NetPacks.h" diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 413e80593..ddaec2fb4 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -52,9 +52,9 @@ #include "../lib/serializer/BinarySerializer.h" #include "../lib/spells/CSpellHandler.h" #include "../lib/CTownHandler.h" -#include "../lib/mapObjects/CObjectClassesHandler.h" // For displaying correct UI when interacting with objects #include "../lib/mapObjects/CGTownInstance.h" #include "../lib/mapObjects/MiscObjects.h" +#include "../lib/mapObjects/ObjectTemplate.h" #include "../lib/CStack.h" #include "../lib/JsonNode.h" #include "CMusicHandler.h" diff --git a/client/NetPacksClient.cpp b/client/NetPacksClient.cpp index df5e7152b..5cf74ae57 100644 --- a/client/NetPacksClient.cpp +++ b/client/NetPacksClient.cpp @@ -36,6 +36,7 @@ #include "../lib/CSoundBase.h" #include "../lib/StartInfo.h" #include "../lib/CConfigHandler.h" +#include "../lib/mapObjects/CGMarket.h" #include "../lib/mapping/CCampaignHandler.h" #include "../lib/CGameState.h" #include "../lib/CStack.h" diff --git a/client/mapView/MapRenderer.cpp b/client/mapView/MapRenderer.cpp index 80057ea7d..2a28cc8be 100644 --- a/client/mapView/MapRenderer.cpp +++ b/client/mapView/MapRenderer.cpp @@ -27,6 +27,7 @@ #include "../../lib/TerrainHandler.h" #include "../../lib/mapObjects/CGHeroInstance.h" #include "../../lib/mapObjects/MiscObjects.h" +#include "../../lib/mapObjects/ObjectTemplate.h" #include "../../lib/mapping/CMapDefines.h" struct NeighborTilesInfo diff --git a/client/mapView/MapViewCache.cpp b/client/mapView/MapViewCache.cpp index 4ffb3ee07..18ed65208 100644 --- a/client/mapView/MapViewCache.cpp +++ b/client/mapView/MapViewCache.cpp @@ -20,6 +20,7 @@ #include "../render/IImage.h" #include "../../lib/mapObjects/CObjectHandler.h" +#include "../../lib/int3.h" MapViewCache::~MapViewCache() = default; diff --git a/client/mapView/mapHandler.cpp b/client/mapView/mapHandler.cpp index 8fbf66c67..fda8cb883 100644 --- a/client/mapView/mapHandler.cpp +++ b/client/mapView/mapHandler.cpp @@ -19,8 +19,9 @@ #include "../../lib/CGeneralTextHandler.h" #include "../../lib/TerrainHandler.h" #include "../../lib/UnlockGuard.h" +#include "../../lib/mapObjectConstructors/CObjectClassesHandler.h" #include "../../lib/mapObjects/CGHeroInstance.h" -#include "../../lib/mapObjects/CObjectClassesHandler.h" +#include "../../lib/mapObjects/ObjectTemplate.h" #include "../../lib/mapping/CMap.h" bool CMapHandler::hasOngoingAnimations() diff --git a/client/render/Graphics.cpp b/client/render/Graphics.cpp index 991e39d16..891208206 100644 --- a/client/render/Graphics.cpp +++ b/client/render/Graphics.cpp @@ -36,8 +36,6 @@ #include "../lib/JsonNode.h" #include "../lib/vcmi_endian.h" #include "../lib/CStopWatch.h" -#include "../lib/mapObjects/CObjectClassesHandler.h" -#include "../lib/mapObjects/CObjectHandler.h" #include "../lib/CHeroHandler.h" #include diff --git a/client/windows/GUIClasses.cpp b/client/windows/GUIClasses.cpp index 1ab9d3d26..ec73254bb 100644 --- a/client/windows/GUIClasses.cpp +++ b/client/windows/GUIClasses.cpp @@ -46,7 +46,9 @@ #include "../../CCallback.h" #include "../lib/mapObjects/CGHeroInstance.h" +#include "../lib/mapObjects/CGMarket.h" #include "../lib/mapObjects/CGTownInstance.h" +#include "../lib/mapObjects/ObjectTemplate.h" #include "../lib/CArtHandler.h" #include "../lib/CBuildingHandler.h" #include "../lib/CConfigHandler.h" diff --git a/cmake_modules/VCMI_lib.cmake b/cmake_modules/VCMI_lib.cmake index 640e264aa..5a354d3e3 100644 --- a/cmake_modules/VCMI_lib.cmake +++ b/cmake_modules/VCMI_lib.cmake @@ -65,20 +65,25 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE) ${MAIN_LIB_DIR}/logging/CBasicLogConfigurator.cpp ${MAIN_LIB_DIR}/logging/CLogger.cpp + ${MAIN_LIB_DIR}/mapObjectConstructors/AObjectTypeHandler.cpp + ${MAIN_LIB_DIR}/mapObjectConstructors/CObjectClassesHandler.cpp + ${MAIN_LIB_DIR}/mapObjectConstructors/CommonConstructors.cpp + ${MAIN_LIB_DIR}/mapObjectConstructors/CRewardableConstructor.cpp + ${MAIN_LIB_DIR}/mapObjects/CArmedInstance.cpp ${MAIN_LIB_DIR}/mapObjects/CBank.cpp ${MAIN_LIB_DIR}/mapObjects/CGDwelling.cpp ${MAIN_LIB_DIR}/mapObjects/CGHeroInstance.cpp ${MAIN_LIB_DIR}/mapObjects/CGMarket.cpp + ${MAIN_LIB_DIR}/mapObjects/CGObjectInstance.cpp ${MAIN_LIB_DIR}/mapObjects/CGPandoraBox.cpp ${MAIN_LIB_DIR}/mapObjects/CGTownBuilding.cpp ${MAIN_LIB_DIR}/mapObjects/CGTownInstance.cpp - ${MAIN_LIB_DIR}/mapObjects/CObjectClassesHandler.cpp ${MAIN_LIB_DIR}/mapObjects/CObjectHandler.cpp - ${MAIN_LIB_DIR}/mapObjects/CommonConstructors.cpp ${MAIN_LIB_DIR}/mapObjects/CQuest.cpp - ${MAIN_LIB_DIR}/mapObjects/CRewardableConstructor.cpp ${MAIN_LIB_DIR}/mapObjects/CRewardableObject.cpp + ${MAIN_LIB_DIR}/mapObjects/IMarket.cpp + ${MAIN_LIB_DIR}/mapObjects/IObjectInterface.cpp ${MAIN_LIB_DIR}/mapObjects/MiscObjects.cpp ${MAIN_LIB_DIR}/mapObjects/ObjectTemplate.cpp @@ -362,20 +367,28 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE) ${MAIN_LIB_DIR}/logging/CBasicLogConfigurator.h ${MAIN_LIB_DIR}/logging/CLogger.h + ${MAIN_LIB_DIR}/mapObjectConstructors/AObjectTypeHandler.h + ${MAIN_LIB_DIR}/mapObjectConstructors/CObjectClassesHandler.h + ${MAIN_LIB_DIR}/mapObjectConstructors/CommonConstructors.h + ${MAIN_LIB_DIR}/mapObjectConstructors/CRewardableConstructor.h + ${MAIN_LIB_DIR}/mapObjectConstructors/IObjectInfo.h + ${MAIN_LIB_DIR}/mapObjectConstructors/RandomMapInfo.h + ${MAIN_LIB_DIR}/mapObjectConstructors/SObjectSounds.h + ${MAIN_LIB_DIR}/mapObjects/CArmedInstance.h ${MAIN_LIB_DIR}/mapObjects/CBank.h ${MAIN_LIB_DIR}/mapObjects/CGDwelling.h ${MAIN_LIB_DIR}/mapObjects/CGHeroInstance.h ${MAIN_LIB_DIR}/mapObjects/CGMarket.h + ${MAIN_LIB_DIR}/mapObjects/CGObjectInstance.h ${MAIN_LIB_DIR}/mapObjects/CGPandoraBox.h ${MAIN_LIB_DIR}/mapObjects/CGTownBuilding.h ${MAIN_LIB_DIR}/mapObjects/CGTownInstance.h - ${MAIN_LIB_DIR}/mapObjects/CObjectClassesHandler.h ${MAIN_LIB_DIR}/mapObjects/CObjectHandler.h - ${MAIN_LIB_DIR}/mapObjects/CommonConstructors.h ${MAIN_LIB_DIR}/mapObjects/CQuest.h - ${MAIN_LIB_DIR}/mapObjects/CRewardableConstructor.h ${MAIN_LIB_DIR}/mapObjects/CRewardableObject.h + ${MAIN_LIB_DIR}/mapObjects/IMarket.h + ${MAIN_LIB_DIR}/mapObjects/IObjectInterface.h ${MAIN_LIB_DIR}/mapObjects/MapObjects.h ${MAIN_LIB_DIR}/mapObjects/MiscObjects.h ${MAIN_LIB_DIR}/mapObjects/ObjectTemplate.h diff --git a/lib/CArtHandler.cpp b/lib/CArtHandler.cpp index 245caee27..00fabea51 100644 --- a/lib/CArtHandler.cpp +++ b/lib/CArtHandler.cpp @@ -23,7 +23,8 @@ #include "StringConstants.h" #include "CRandomGenerator.h" -#include "mapObjects/CObjectClassesHandler.h" +#include "mapObjectConstructors/AObjectTypeHandler.h" +#include "mapObjectConstructors/CObjectClassesHandler.h" #include "mapping/CMap.h" #include "serializer/JsonSerializeFormat.h" diff --git a/lib/CCreatureHandler.cpp b/lib/CCreatureHandler.cpp index 4d6ccbe94..a379627cd 100644 --- a/lib/CCreatureHandler.cpp +++ b/lib/CCreatureHandler.cpp @@ -23,7 +23,8 @@ #include "bonuses/Updaters.h" #include "serializer/JsonDeserializer.h" #include "serializer/JsonUpdater.h" -#include "mapObjects/CObjectClassesHandler.h" +#include "mapObjectConstructors/AObjectTypeHandler.h" +#include "mapObjectConstructors/CObjectClassesHandler.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/CGameInfoCallback.cpp b/lib/CGameInfoCallback.cpp index 370f67a7a..18ea4f40e 100644 --- a/lib/CGameInfoCallback.cpp +++ b/lib/CGameInfoCallback.cpp @@ -12,7 +12,6 @@ #include "CGameState.h" // PlayerState #include "CGeneralTextHandler.h" -#include "mapObjects/CObjectHandler.h" // for CGObjectInstance #include "StartInfo.h" // for StartInfo #include "battle/BattleInfo.h" // for BattleInfo #include "NetPacks.h" // for InfoWindow diff --git a/lib/CGameInterface.h b/lib/CGameInterface.h index da736d90e..54057059e 100644 --- a/lib/CGameInterface.h +++ b/lib/CGameInterface.h @@ -15,8 +15,6 @@ #include "spells/ViewSpellInt.h" -#include "mapObjects/CObjectHandler.h" - class CBattleCallback; class CCallback; @@ -68,6 +66,7 @@ namespace scripting } #endif +using TTeleportExitsList = std::vector>; class DLL_LINKAGE CBattleGameInterface : public IBattleEventsReceiver { diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index d06934524..f1fa33822 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -11,20 +11,19 @@ #include "CGameState.h" #include "mapping/CCampaignHandler.h" -#include "mapObjects/CObjectClassesHandler.h" #include "CArtHandler.h" #include "CBuildingHandler.h" #include "CGeneralTextHandler.h" #include "CTownHandler.h" #include "spells/CSpellHandler.h" #include "CHeroHandler.h" -#include "mapObjects/CObjectHandler.h" #include "CModHandler.h" #include "GameSettings.h" #include "TerrainHandler.h" #include "CSkillHandler.h" #include "mapping/CMap.h" #include "mapping/CMapService.h" +#include "mapObjectConstructors/CObjectClassesHandler.h" #include "StartInfo.h" #include "NetPacks.h" #include "registerTypes/RegisterTypes.h" diff --git a/lib/CHeroHandler.cpp b/lib/CHeroHandler.cpp index 216f8264c..9623a3b77 100644 --- a/lib/CHeroHandler.cpp +++ b/lib/CHeroHandler.cpp @@ -20,12 +20,12 @@ #include "GameSettings.h" #include "CModHandler.h" #include "CTownHandler.h" -#include "mapObjects/CObjectHandler.h" //for hero specialty #include "CSkillHandler.h" -#include "mapObjects/CObjectClassesHandler.h" #include "BattleFieldHandler.h" #include "bonuses/Limiters.h" #include "bonuses/Updaters.h" +#include "mapObjectConstructors/AObjectTypeHandler.h" +#include "mapObjectConstructors/CObjectClassesHandler.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/CModHandler.cpp b/lib/CModHandler.cpp index 4e2837d60..1a78d708f 100644 --- a/lib/CModHandler.cpp +++ b/lib/CModHandler.cpp @@ -9,7 +9,6 @@ */ #include "StdInc.h" #include "CModHandler.h" -#include "mapObjects/CObjectClassesHandler.h" #include "rmg/CRmgTemplateStorage.h" #include "filesystem/FileStream.h" #include "filesystem/AdapterLoaders.h" @@ -20,7 +19,6 @@ #include "CArtHandler.h" #include "CTownHandler.h" #include "CHeroHandler.h" -#include "mapObjects/CObjectHandler.h" #include "StringConstants.h" #include "CStopWatch.h" #include "IHandlerBase.h" @@ -35,6 +33,7 @@ #include "TerrainHandler.h" #include "BattleFieldHandler.h" #include "ObstacleHandler.h" +#include "mapObjectConstructors/CObjectClassesHandler.h" #include diff --git a/lib/CTownHandler.cpp b/lib/CTownHandler.cpp index 0af0779f9..a2ce90c94 100644 --- a/lib/CTownHandler.cpp +++ b/lib/CTownHandler.cpp @@ -22,11 +22,11 @@ #include "TerrainHandler.h" #include "spells/CSpellHandler.h" #include "filesystem/Filesystem.h" -#include "mapObjects/CObjectClassesHandler.h" -#include "mapObjects/CObjectHandler.h" #include "bonuses/Bonus.h" #include "bonuses/Propagators.h" #include "ResourceSet.h" +#include "mapObjectConstructors/AObjectTypeHandler.h" +#include "mapObjectConstructors/CObjectClassesHandler.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/CTownHandler.h b/lib/CTownHandler.h index 484844752..983611d0c 100644 --- a/lib/CTownHandler.h +++ b/lib/CTownHandler.h @@ -22,7 +22,7 @@ #include "bonuses/Bonus.h" #include "bonuses/BonusList.h" #include "Point.h" -#include "mapObjects/CRewardableConstructor.h" +#include "rewardable/Info.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/GameConstants.cpp b/lib/GameConstants.cpp index 5997c4574..026b88aa4 100644 --- a/lib/GameConstants.cpp +++ b/lib/GameConstants.cpp @@ -26,7 +26,6 @@ #include #include "VCMI_Lib.h" -#include "mapObjects/CObjectClassesHandler.h"//todo: remove #include "CArtHandler.h"//todo: remove #include "CCreatureHandler.h"//todo: remove #include "spells/CSpellHandler.h" //todo: remove diff --git a/lib/IGameCallback.cpp b/lib/IGameCallback.cpp index b89a577af..c05494e4f 100644 --- a/lib/IGameCallback.cpp +++ b/lib/IGameCallback.cpp @@ -28,8 +28,11 @@ #include "serializer/BinarySerializer.h" #include "serializer/CLoadIntegrityValidator.h" #include "rmg/CMapGenOptions.h" +#include "mapObjectConstructors/AObjectTypeHandler.h" +#include "mapObjectConstructors/CObjectClassesHandler.h" +#include "mapObjects/CObjectHandler.h" +#include "mapObjects/ObjectTemplate.h" #include "mapping/CCampaignHandler.h" -#include "mapObjects/CObjectClassesHandler.h" #include "StartInfo.h" #include "CGameState.h" #include "mapping/CMap.h" diff --git a/lib/JsonRandom.cpp b/lib/JsonRandom.cpp index 211c7234d..de1433f67 100644 --- a/lib/JsonRandom.cpp +++ b/lib/JsonRandom.cpp @@ -23,8 +23,8 @@ #include "CCreatureSet.h" #include "spells/CSpellHandler.h" #include "CSkillHandler.h" -#include "mapObjects/CObjectHandler.h" #include "IGameCallback.h" +#include "mapObjects/IObjectInterface.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/NetPacks.h b/lib/NetPacks.h index 892047280..5861b44b6 100644 --- a/lib/NetPacks.h +++ b/lib/NetPacks.h @@ -36,6 +36,10 @@ struct ArtSlotInfo; struct QuestInfo; class IBattleState; +// This one teleport-specific, but has to be available everywhere in callbacks and netpacks +// For now it's will be there till teleports code refactored and moved into own file +using TTeleportExitsList = std::vector>; + struct DLL_LINKAGE Query : public CPackForClient { QueryID queryID; // equals to -1 if it is not an actual query (and should not be answered) diff --git a/lib/NetPacksLib.cpp b/lib/NetPacksLib.cpp index 64b1b8b49..1019887e3 100644 --- a/lib/NetPacksLib.cpp +++ b/lib/NetPacksLib.cpp @@ -11,10 +11,8 @@ #include "NetPacks.h" #include "NetPackVisitor.h" #include "CGeneralTextHandler.h" -#include "mapObjects/CObjectClassesHandler.h" #include "CArtHandler.h" #include "CHeroHandler.h" -#include "mapObjects/CObjectHandler.h" #include "CModHandler.h" #include "VCMI_Lib.h" #include "mapping/CMap.h" @@ -28,6 +26,9 @@ #include "StartInfo.h" #include "CPlayerState.h" #include "TerrainHandler.h" +#include "mapObjects/CGMarket.h" +#include "mapObjectConstructors/AObjectTypeHandler.h" +#include "mapObjectConstructors/CObjectClassesHandler.h" #include "mapping/CCampaignHandler.h" #include "GameSettings.h" diff --git a/lib/PathfinderUtil.h b/lib/PathfinderUtil.h index 81123807c..dcb40306b 100644 --- a/lib/PathfinderUtil.h +++ b/lib/PathfinderUtil.h @@ -10,7 +10,8 @@ #pragma once #include "TerrainHandler.h" -#include "mapObjects/CObjectHandler.h" +#include "mapObjects/CGObjectInstance.h" +#include "mapping/CMapDefines.h" #include "CGameState.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/ResourceSet.cpp b/lib/ResourceSet.cpp index d571d4ea8..50f2c48b6 100644 --- a/lib/ResourceSet.cpp +++ b/lib/ResourceSet.cpp @@ -14,8 +14,8 @@ #include "StringConstants.h" #include "JsonNode.h" #include "serializer/JsonSerializeFormat.h" -#include "VCMI_Lib.h" #include "mapObjects/CObjectHandler.h" +#include "VCMI_Lib.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/VCMI_Lib.cpp b/lib/VCMI_Lib.cpp index a108b8dd3..01a8c18d1 100644 --- a/lib/VCMI_Lib.cpp +++ b/lib/VCMI_Lib.cpp @@ -14,9 +14,7 @@ #include "CArtHandler.h" #include "CBonusTypeHandler.h" #include "CCreatureHandler.h" -#include "mapObjects/CObjectClassesHandler.h" #include "CHeroHandler.h" -#include "mapObjects/CObjectHandler.h" #include "CTownHandler.h" #include "CConfigHandler.h" #include "RoadHandler.h" @@ -34,6 +32,8 @@ #include "filesystem/Filesystem.h" #include "CConsoleHandler.h" #include "rmg/CRmgTemplateStorage.h" +#include "mapObjectConstructors/CObjectClassesHandler.h" +#include "mapObjects/CObjectHandler.h" #include "mapping/CMapEditManager.h" #include "ScriptHandler.h" #include "BattleFieldHandler.h" diff --git a/lib/mapObjectConstructors/AObjectTypeHandler.cpp b/lib/mapObjectConstructors/AObjectTypeHandler.cpp new file mode 100644 index 000000000..2273415c9 --- /dev/null +++ b/lib/mapObjectConstructors/AObjectTypeHandler.cpp @@ -0,0 +1,225 @@ +/* + * AObjectTypeHandler.cpp, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +#include "StdInc.h" +#include "AObjectTypeHandler.h" + +#include "../CGeneralTextHandler.h" +#include "../VCMI_Lib.h" +#include "../mapObjects/CGObjectInstance.h" +#include "../mapObjects/ObjectTemplate.h" + +VCMI_LIB_NAMESPACE_BEGIN + +std::string AObjectTypeHandler::getJsonKey() const +{ + return modScope + ':' + subTypeName; +} + +si32 AObjectTypeHandler::getIndex() const +{ + return type; +} + +si32 AObjectTypeHandler::getSubIndex() const +{ + return subtype; +} + +std::string AObjectTypeHandler::getTypeName() const +{ + return typeName; +} + +std::string AObjectTypeHandler::getSubTypeName() const +{ + return subTypeName; +} + +static ui32 loadJsonOrMax(const JsonNode & input) +{ + if (input.isNull()) + return std::numeric_limits::max(); + else + return static_cast(input.Float()); +} + +void AObjectTypeHandler::init(const JsonNode & input) +{ + base = input["base"]; + + if (!input["rmg"].isNull()) + { + rmgInfo.value = static_cast(input["rmg"]["value"].Float()); + + const JsonNode & mapLimit = input["rmg"]["mapLimit"]; + if (!mapLimit.isNull()) + rmgInfo.mapLimit = static_cast(mapLimit.Float()); + + rmgInfo.zoneLimit = loadJsonOrMax(input["rmg"]["zoneLimit"]); + rmgInfo.rarity = static_cast(input["rmg"]["rarity"].Float()); + } // else block is not needed - set in constructor + + for (auto entry : input["templates"].Struct()) + { + entry.second.setType(JsonNode::JsonType::DATA_STRUCT); + JsonUtils::inherit(entry.second, base); + + auto * tmpl = new ObjectTemplate; + tmpl->id = Obj(type); + tmpl->subid = subtype; + tmpl->stringID = entry.first; // FIXME: create "fullID" - type.object.template? + try + { + tmpl->readJson(entry.second); + templates.push_back(std::shared_ptr(tmpl)); + } + catch (const std::exception & e) + { + logGlobal->warn("Failed to load terrains for object %s: %s", entry.first, e.what()); + } + } + + for(const JsonNode & node : input["sounds"]["ambient"].Vector()) + sounds.ambient.push_back(node.String()); + + for(const JsonNode & node : input["sounds"]["visit"].Vector()) + sounds.visit.push_back(node.String()); + + for(const JsonNode & node : input["sounds"]["removal"].Vector()) + sounds.removal.push_back(node.String()); + + if(input["aiValue"].isNull()) + aiValue = std::nullopt; + else + aiValue = static_cast>(input["aiValue"].Integer()); + + if(input["battleground"].getType() == JsonNode::JsonType::DATA_STRING) + battlefield = input["battleground"].String(); + else + battlefield = std::nullopt; + + initTypeData(input); +} + +bool AObjectTypeHandler::objectFilter(const CGObjectInstance * obj, std::shared_ptr tmpl) const +{ + return false; // by default there are no overrides +} + +void AObjectTypeHandler::preInitObject(CGObjectInstance * obj) const +{ + obj->ID = Obj(type); + obj->subID = subtype; + obj->typeName = typeName; + obj->subTypeName = subTypeName; +} + +void AObjectTypeHandler::initTypeData(const JsonNode & input) +{ + // empty implementation for overrides +} + +bool AObjectTypeHandler::hasNameTextID() const +{ + return false; +} + +std::string AObjectTypeHandler::getNameTextID() const +{ + return TextIdentifier("mapObject", modScope, typeName, subTypeName, "name").get(); +} + +std::string AObjectTypeHandler::getNameTranslated() const +{ + return VLC->generaltexth->translate(getNameTextID()); +} + +SObjectSounds AObjectTypeHandler::getSounds() const +{ + return sounds; +} + +void AObjectTypeHandler::addTemplate(const std::shared_ptr & templ) +{ + templates.push_back(templ); +} + +void AObjectTypeHandler::addTemplate(JsonNode config) +{ + config.setType(JsonNode::JsonType::DATA_STRUCT); // ensure that input is not null + JsonUtils::inherit(config, base); + auto * tmpl = new ObjectTemplate; + tmpl->id = Obj(type); + tmpl->subid = subtype; + tmpl->stringID.clear(); // TODO? + tmpl->readJson(config); + templates.emplace_back(tmpl); +} + +std::vector> AObjectTypeHandler::getTemplates() const +{ + return templates; +} + +BattleField AObjectTypeHandler::getBattlefield() const +{ + return battlefield ? BattleField::fromString(battlefield.value()) : BattleField::NONE; +} + +std::vector>AObjectTypeHandler::getTemplates(TerrainId terrainType) const +{ + std::vector> templates = getTemplates(); + std::vector> filtered; + const auto cfun = [&](const std::shared_ptr & obj) + { + return obj->canBePlacedAt(terrainType); + }; + std::copy_if(templates.begin(), templates.end(), std::back_inserter(filtered), cfun); + // H3 defines allowed terrains in a weird way - artifacts, monsters and resources have faulty masks here + // Perhaps we should re-define faulty templates and remove this workaround (already done for resources) + if (type == Obj::ARTIFACT || type == Obj::MONSTER) + return templates; + else + return filtered; +} + +std::shared_ptr AObjectTypeHandler::getOverride(TerrainId terrainType, const CGObjectInstance * object) const +{ + std::vector> ret = getTemplates(terrainType); + for (const auto & tmpl: ret) + { + if (objectFilter(object, tmpl)) + return tmpl; + } + return std::shared_ptr(); //empty +} + +const RandomMapInfo & AObjectTypeHandler::getRMGInfo() +{ + return rmgInfo; +} + +std::optional AObjectTypeHandler::getAiValue() const +{ + return aiValue; +} + +bool AObjectTypeHandler::isStaticObject() +{ + return false; // most of classes are not static +} + +void AObjectTypeHandler::afterLoadFinalization() +{ +} + + +VCMI_LIB_NAMESPACE_END diff --git a/lib/mapObjectConstructors/AObjectTypeHandler.h b/lib/mapObjectConstructors/AObjectTypeHandler.h new file mode 100644 index 000000000..56dcec4de --- /dev/null +++ b/lib/mapObjectConstructors/AObjectTypeHandler.h @@ -0,0 +1,127 @@ +/* + * AObjectTypeHandler.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#pragma once + +#include "RandomMapInfo.h" +#include "SObjectSounds.h" +#include "../JsonNode.h" + +VCMI_LIB_NAMESPACE_BEGIN + +class ObjectTemplate; +class CGObjectInstance; +class CRandomGenerator; +class IObjectInfo; + +/// Class responsible for creation of objects of specific type & subtype +class DLL_LINKAGE AObjectTypeHandler : public boost::noncopyable +{ + friend class CObjectClassesHandler; + + RandomMapInfo rmgInfo; + + JsonNode base; /// describes base template + + std::vector> templates; + + SObjectSounds sounds; + + std::optional aiValue; + std::optional battlefield; + + std::string modScope; + std::string typeName; + std::string subTypeName; + + si32 type; + si32 subtype; + +protected: + void preInitObject(CGObjectInstance * obj) const; + virtual bool objectFilter(const CGObjectInstance * obj, std::shared_ptr tmpl) const; + + /// initialization for classes that inherit this one + virtual void initTypeData(const JsonNode & input); +public: + + virtual ~AObjectTypeHandler() = default; + + si32 getIndex() const; + si32 getSubIndex() const; + + std::string getTypeName() const; + std::string getSubTypeName() const; + + /// loads generic data from Json structure and passes it towards type-specific constructors + void init(const JsonNode & input); + + /// returns full form of identifier of this object in form of modName:objectName + std::string getJsonKey() const; + + /// Returns object-specific name, if set + SObjectSounds getSounds() const; + + void addTemplate(const std::shared_ptr & templ); + void addTemplate(JsonNode config); + + /// returns all templates matching parameters + std::vector> getTemplates() const; + std::vector> getTemplates(const TerrainId terrainType) const; + + /// returns preferred template for this object, if present (e.g. one of 3 possible templates for town - village, fort and castle) + /// note that appearance will not be changed - this must be done separately (either by assignment or via pack from server) + std::shared_ptr getOverride(TerrainId terrainType, const CGObjectInstance * object) const; + + BattleField getBattlefield() const; + + const RandomMapInfo & getRMGInfo(); + + std::optional getAiValue() const; + + /// returns true if this class provides custom text ID's instead of generic per-object name + virtual bool hasNameTextID() const; + + /// returns object's name in form of translatable text ID + virtual std::string getNameTextID() const; + + /// returns object's name in form of human-readable text + std::string getNameTranslated() const; + + virtual bool isStaticObject(); + + virtual void afterLoadFinalization(); + + /// Creates object and set up core properties (like ID/subID). Object is NOT initialized + /// to allow creating objects before game start (e.g. map loading) + virtual CGObjectInstance * create(std::shared_ptr tmpl = nullptr) const = 0; + + /// Configures object properties. Should be re-entrable, resetting state of the object if necessarily + /// This should set remaining properties, including randomized or depending on map + virtual void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const = 0; + + /// Returns object configuration, if available. Otherwise returns NULL + virtual std::unique_ptr getObjectInfo(std::shared_ptr tmpl) const = 0; + + template void serialize(Handler &h, const int version) + { + h & type; + h & subtype; + h & templates; + h & rmgInfo; + h & modScope; + h & typeName; + h & subTypeName; + h & sounds; + h & aiValue; + h & battlefield; + } +}; + +VCMI_LIB_NAMESPACE_END diff --git a/lib/mapObjects/CObjectClassesHandler.cpp b/lib/mapObjectConstructors/CObjectClassesHandler.cpp similarity index 73% rename from lib/mapObjects/CObjectClassesHandler.cpp rename to lib/mapObjectConstructors/CObjectClassesHandler.cpp index 2d4f662ed..063f6b173 100644 --- a/lib/mapObjects/CObjectClassesHandler.cpp +++ b/lib/mapObjectConstructors/CObjectClassesHandler.cpp @@ -21,9 +21,11 @@ #include "../JsonNode.h" #include "../CSoundBase.h" -#include "CRewardableConstructor.h" -#include "CommonConstructors.h" -#include "MapObjects.h" +#include "../mapObjectConstructors/CRewardableConstructor.h" +#include "../mapObjectConstructors/CommonConstructors.h" +#include "../mapObjects/CQuest.h" +#include "../mapObjects/CGPandoraBox.h" +#include "../mapObjects/ObjectTemplate.h" VCMI_LIB_NAMESPACE_BEGIN @@ -470,207 +472,4 @@ std::string CObjectClassesHandler::getObjectHandlerName(si32 type) const return objects.at(type)->handlerName; } -std::string AObjectTypeHandler::getJsonKey() const -{ - return modScope + ':' + subTypeName; -} - -si32 AObjectTypeHandler::getIndex() const -{ - return type; -} - -si32 AObjectTypeHandler::getSubIndex() const -{ - return subtype; -} - -std::string AObjectTypeHandler::getTypeName() const -{ - return typeName; -} - -std::string AObjectTypeHandler::getSubTypeName() const -{ - return subTypeName; -} - -static ui32 loadJsonOrMax(const JsonNode & input) -{ - if (input.isNull()) - return std::numeric_limits::max(); - else - return static_cast(input.Float()); -} - -void AObjectTypeHandler::init(const JsonNode & input) -{ - base = input["base"]; - - if (!input["rmg"].isNull()) - { - rmgInfo.value = static_cast(input["rmg"]["value"].Float()); - - const JsonNode & mapLimit = input["rmg"]["mapLimit"]; - if (!mapLimit.isNull()) - rmgInfo.mapLimit = static_cast(mapLimit.Float()); - - rmgInfo.zoneLimit = loadJsonOrMax(input["rmg"]["zoneLimit"]); - rmgInfo.rarity = static_cast(input["rmg"]["rarity"].Float()); - } // else block is not needed - set in constructor - - for (auto entry : input["templates"].Struct()) - { - entry.second.setType(JsonNode::JsonType::DATA_STRUCT); - JsonUtils::inherit(entry.second, base); - - auto * tmpl = new ObjectTemplate; - tmpl->id = Obj(type); - tmpl->subid = subtype; - tmpl->stringID = entry.first; // FIXME: create "fullID" - type.object.template? - try - { - tmpl->readJson(entry.second); - templates.push_back(std::shared_ptr(tmpl)); - } - catch (const std::exception & e) - { - logGlobal->warn("Failed to load terrains for object %s: %s", entry.first, e.what()); - } - } - - for(const JsonNode & node : input["sounds"]["ambient"].Vector()) - sounds.ambient.push_back(node.String()); - - for(const JsonNode & node : input["sounds"]["visit"].Vector()) - sounds.visit.push_back(node.String()); - - for(const JsonNode & node : input["sounds"]["removal"].Vector()) - sounds.removal.push_back(node.String()); - - if(input["aiValue"].isNull()) - aiValue = std::nullopt; - else - aiValue = static_cast>(input["aiValue"].Integer()); - - if(input["battleground"].getType() == JsonNode::JsonType::DATA_STRING) - battlefield = input["battleground"].String(); - else - battlefield = std::nullopt; - - initTypeData(input); -} - -bool AObjectTypeHandler::objectFilter(const CGObjectInstance * obj, std::shared_ptr tmpl) const -{ - return false; // by default there are no overrides -} - -void AObjectTypeHandler::preInitObject(CGObjectInstance * obj) const -{ - obj->ID = Obj(type); - obj->subID = subtype; - obj->typeName = typeName; - obj->subTypeName = subTypeName; -} - -void AObjectTypeHandler::initTypeData(const JsonNode & input) -{ - // empty implementation for overrides -} - -bool AObjectTypeHandler::hasNameTextID() const -{ - return false; -} - -std::string AObjectTypeHandler::getNameTextID() const -{ - return TextIdentifier("mapObject", modScope, typeName, subTypeName, "name").get(); -} - -std::string AObjectTypeHandler::getNameTranslated() const -{ - return VLC->generaltexth->translate(getNameTextID()); -} - -SObjectSounds AObjectTypeHandler::getSounds() const -{ - return sounds; -} - -void AObjectTypeHandler::addTemplate(const std::shared_ptr & templ) -{ - templates.push_back(templ); -} - -void AObjectTypeHandler::addTemplate(JsonNode config) -{ - config.setType(JsonNode::JsonType::DATA_STRUCT); // ensure that input is not null - JsonUtils::inherit(config, base); - auto * tmpl = new ObjectTemplate; - tmpl->id = Obj(type); - tmpl->subid = subtype; - tmpl->stringID.clear(); // TODO? - tmpl->readJson(config); - templates.emplace_back(tmpl); -} - -std::vector> AObjectTypeHandler::getTemplates() const -{ - return templates; -} - -BattleField AObjectTypeHandler::getBattlefield() const -{ - return battlefield ? BattleField::fromString(battlefield.value()) : BattleField::NONE; -} - -std::vector>AObjectTypeHandler::getTemplates(TerrainId terrainType) const -{ - std::vector> templates = getTemplates(); - std::vector> filtered; - const auto cfun = [&](const std::shared_ptr & obj) - { - return obj->canBePlacedAt(terrainType); - }; - std::copy_if(templates.begin(), templates.end(), std::back_inserter(filtered), cfun); - // H3 defines allowed terrains in a weird way - artifacts, monsters and resources have faulty masks here - // Perhaps we should re-define faulty templates and remove this workaround (already done for resources) - if (type == Obj::ARTIFACT || type == Obj::MONSTER) - return templates; - else - return filtered; -} - -std::shared_ptr AObjectTypeHandler::getOverride(TerrainId terrainType, const CGObjectInstance * object) const -{ - std::vector> ret = getTemplates(terrainType); - for (const auto & tmpl: ret) - { - if (objectFilter(object, tmpl)) - return tmpl; - } - return std::shared_ptr(); //empty -} - -const RandomMapInfo & AObjectTypeHandler::getRMGInfo() -{ - return rmgInfo; -} - -std::optional AObjectTypeHandler::getAiValue() const -{ - return aiValue; -} - -bool AObjectTypeHandler::isStaticObject() -{ - return false; // most of classes are not static -} - -void AObjectTypeHandler::afterLoadFinalization() -{ -} - VCMI_LIB_NAMESPACE_END diff --git a/lib/mapObjectConstructors/CObjectClassesHandler.h b/lib/mapObjectConstructors/CObjectClassesHandler.h new file mode 100644 index 000000000..16817063d --- /dev/null +++ b/lib/mapObjectConstructors/CObjectClassesHandler.h @@ -0,0 +1,138 @@ +/* + * CObjectClassesHandler.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#pragma once + +#include "../IHandlerBase.h" +#include "../JsonNode.h" + +VCMI_LIB_NAMESPACE_BEGIN + +class CRandomGenerator; +class AObjectTypeHandler; +class ObjectTemplate; +struct SObjectSounds; + +struct DLL_LINKAGE CompoundMapObjectID +{ + si32 primaryID; + si32 secondaryID; + + CompoundMapObjectID(si32 primID, si32 secID) : primaryID(primID), secondaryID(secID) {}; + + bool operator<(const CompoundMapObjectID& other) const + { + if(this->primaryID != other.primaryID) + return this->primaryID < other.primaryID; + else + return this->secondaryID < other.secondaryID; + } + + bool operator==(const CompoundMapObjectID& other) const + { + return (this->primaryID == other.primaryID) && (this->secondaryID == other.secondaryID); + } +}; + +class CGObjectInstance; + +using TObjectTypeHandler = std::shared_ptr; + +/// Class responsible for creation of adventure map objects of specific type +class DLL_LINKAGE ObjectClass +{ +public: + std::string modScope; + std::string identifier; + + si32 id; + std::string handlerName; // ID of handler that controls this object, should be determined using handlerConstructor map + + JsonNode base; + std::vector objects; + + ObjectClass() = default; + + std::string getJsonKey() const; + std::string getNameTextID() const; + std::string getNameTranslated() const; + + template void serialize(Handler &h, const int version) + { + h & id; + h & handlerName; + h & base; + h & objects; + h & identifier; + h & modScope; + } +}; + +/// Main class responsible for creation of all adventure map objects +class DLL_LINKAGE CObjectClassesHandler : public IHandlerBase +{ + /// list of object handlers, each of them handles only one type + std::vector objects; + + /// map that is filled during contruction with all known handlers. Not serializeable due to usage of std::function + std::map > handlerConstructors; + + /// container with H3 templates, used only during loading, no need to serialize it + using TTemplatesContainer = std::multimap, std::shared_ptr>; + TTemplatesContainer legacyTemplates; + + TObjectTypeHandler loadSubObjectFromJson(const std::string & scope, const std::string & identifier, const JsonNode & entry, ObjectClass * obj, size_t index); + + void loadSubObject(const std::string & scope, const std::string & identifier, const JsonNode & entry, ObjectClass * obj); + void loadSubObject(const std::string & scope, const std::string & identifier, const JsonNode & entry, ObjectClass * obj, size_t index); + + ObjectClass * loadFromJson(const std::string & scope, const JsonNode & json, const std::string & name, size_t index); + + void generateExtraMonolithsForRMG(); + +public: + CObjectClassesHandler(); + ~CObjectClassesHandler(); + + std::vector loadLegacyData() override; + + void loadObject(std::string scope, std::string name, const JsonNode & data) override; + void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override; + + void loadSubObject(const std::string & identifier, JsonNode config, si32 ID, si32 subID); + void removeSubObject(si32 ID, si32 subID); + + void beforeValidate(JsonNode & object) override; + void afterLoadFinalization() override; + + std::vector getDefaultAllowed() const override; + + /// Queries to detect loaded objects + std::set knownObjects() const; + std::set knownSubObjects(si32 primaryID) const; + + /// returns handler for specified object (ID-based). ObjectHandler keeps ownership + TObjectTypeHandler getHandlerFor(si32 type, si32 subtype) const; + TObjectTypeHandler getHandlerFor(const std::string & scope, const std::string & type, const std::string & subtype) const; + TObjectTypeHandler getHandlerFor(CompoundMapObjectID compoundIdentifier) const; + + std::string getObjectName(si32 type, si32 subtype) const; + + SObjectSounds getObjectSounds(si32 type, si32 subtype) const; + + /// Returns handler string describing the handler (for use in client) + std::string getObjectHandlerName(si32 type) const; + + template void serialize(Handler &h, const int version) + { + h & objects; + } +}; + +VCMI_LIB_NAMESPACE_END diff --git a/lib/mapObjects/CRewardableConstructor.cpp b/lib/mapObjectConstructors/CRewardableConstructor.cpp similarity index 97% rename from lib/mapObjects/CRewardableConstructor.cpp rename to lib/mapObjectConstructors/CRewardableConstructor.cpp index ad01e9874..d0fe29ada 100644 --- a/lib/mapObjects/CRewardableConstructor.cpp +++ b/lib/mapObjectConstructors/CRewardableConstructor.cpp @@ -9,7 +9,8 @@ */ #include "StdInc.h" #include "CRewardableConstructor.h" -#include "CRewardableObject.h" + +#include "../mapObjects/CRewardableObject.h" #include "../CGeneralTextHandler.h" #include "../IGameCallback.h" diff --git a/lib/mapObjects/CRewardableConstructor.h b/lib/mapObjectConstructors/CRewardableConstructor.h similarity index 95% rename from lib/mapObjects/CRewardableConstructor.h rename to lib/mapObjectConstructors/CRewardableConstructor.h index 3738c8a0a..aeb8d6b62 100644 --- a/lib/mapObjects/CRewardableConstructor.h +++ b/lib/mapObjectConstructors/CRewardableConstructor.h @@ -9,7 +9,7 @@ */ #pragma once -#include "../mapObjects/CObjectClassesHandler.h" +#include "AObjectTypeHandler.h" #include "../rewardable/Info.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/mapObjects/CommonConstructors.cpp b/lib/mapObjectConstructors/CommonConstructors.cpp similarity index 99% rename from lib/mapObjects/CommonConstructors.cpp rename to lib/mapObjectConstructors/CommonConstructors.cpp index 651a586d1..1876575a7 100644 --- a/lib/mapObjects/CommonConstructors.cpp +++ b/lib/mapObjectConstructors/CommonConstructors.cpp @@ -10,18 +10,19 @@ #include "StdInc.h" #include "CommonConstructors.h" -#include "CGTownInstance.h" -#include "CGHeroInstance.h" -#include "CBank.h" -#include "../TerrainHandler.h" -#include "../mapping/CMapDefines.h" -#include "../CHeroHandler.h" -#include "../CGeneralTextHandler.h" #include "../CCreatureHandler.h" -#include "JsonRandom.h" +#include "../CGeneralTextHandler.h" +#include "../CHeroHandler.h" #include "../CModHandler.h" #include "../IGameCallback.h" #include "../StringConstants.h" +#include "../TerrainHandler.h" +#include "../mapObjects/CBank.h" +#include "../mapObjects/CGHeroInstance.h" +#include "../mapObjects/CGTownInstance.h" +#include "../mapObjects/ObjectTemplate.h" +#include "../mapping/CMapDefines.h" +#include "JsonRandom.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/mapObjects/CommonConstructors.h b/lib/mapObjectConstructors/CommonConstructors.h similarity index 96% rename from lib/mapObjects/CommonConstructors.h rename to lib/mapObjectConstructors/CommonConstructors.h index b0f764386..12745afe0 100644 --- a/lib/mapObjects/CommonConstructors.h +++ b/lib/mapObjectConstructors/CommonConstructors.h @@ -9,9 +9,15 @@ */ #pragma once -#include "CObjectClassesHandler.h" -#include "../CTownHandler.h" // for building ID-based filters -#include "MapObjects.h" +#include "AObjectTypeHandler.h" + +#include "../mapObjects/CGMarket.h" +#include "../mapObjects/MiscObjects.h" +#include "../mapObjects/CGHeroInstance.h" +#include "../mapObjects/CGTownInstance.h" +#include "../mapObjects/CBank.h" +#include "../LogicalExpression.h" +#include "IObjectInfo.h" VCMI_LIB_NAMESPACE_BEGIN @@ -21,6 +27,7 @@ class CGHeroInstance; class CGDwelling; class CHeroClass; class CBank; +class CFaction; class CStackBasicDescriptor; /// Class that is used for objects that do not have dedicated handler diff --git a/lib/mapObjectConstructors/IObjectInfo.h b/lib/mapObjectConstructors/IObjectInfo.h new file mode 100644 index 000000000..17219fbfd --- /dev/null +++ b/lib/mapObjectConstructors/IObjectInfo.h @@ -0,0 +1,58 @@ +/* + * IObjectInfo.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#pragma once + +VCMI_LIB_NAMESPACE_BEGIN + +class DLL_LINKAGE IObjectInfo +{ +public: + struct CArmyStructure + { + ui32 totalStrength; + ui32 shootersStrength; + ui32 flyersStrength; + ui32 walkersStrength; + + CArmyStructure() : + totalStrength(0), + shootersStrength(0), + flyersStrength(0), + walkersStrength(0) + {} + + bool operator <(const CArmyStructure & other) const + { + return this->totalStrength < other.totalStrength; + } + }; + + /// Returns possible composition of guards. Actual guards would be + /// somewhere between these two values + virtual CArmyStructure minGuards() const { return CArmyStructure(); } + virtual CArmyStructure maxGuards() const { return CArmyStructure(); } + + virtual bool givesResources() const { return false; } + + virtual bool givesExperience() const { return false; } + virtual bool givesMana() const { return false; } + virtual bool givesMovement() const { return false; } + + virtual bool givesPrimarySkills() const { return false; } + virtual bool givesSecondarySkills() const { return false; } + + virtual bool givesArtifacts() const { return false; } + virtual bool givesCreatures() const { return false; } + virtual bool givesSpells() const { return false; } + + virtual bool givesBonuses() const { return false; } + + virtual ~IObjectInfo() = default; +}; diff --git a/lib/mapObjectConstructors/RandomMapInfo.h b/lib/mapObjectConstructors/RandomMapInfo.h new file mode 100644 index 000000000..5bb98daf6 --- /dev/null +++ b/lib/mapObjectConstructors/RandomMapInfo.h @@ -0,0 +1,46 @@ +/* + * RandomMapInfo.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#pragma once + +VCMI_LIB_NAMESPACE_BEGIN + +/// Structure that describes placement rules for this object in random map +struct DLL_LINKAGE RandomMapInfo +{ + /// How valuable this object is, 1k = worthless, 10k = Utopia-level + ui32 value; + + /// How many of such objects can be placed on map, 0 = object can not be placed by RMG + std::optional mapLimit; + + /// How many of such objects can be placed in one zone, 0 = unplaceable + ui32 zoneLimit; + + /// Rarity of object, 5 = extremely rare, 100 = common + ui32 rarity; + + RandomMapInfo(): + value(0), + zoneLimit(0), + rarity(0) + {} + + void setMapLimit(ui32 val) { mapLimit = val; } + + template void serialize(Handler &h, const int version) + { + h & value; + h & mapLimit; + h & zoneLimit; + h & rarity; + } +}; + +VCMI_LIB_NAMESPACE_END diff --git a/lib/mapObjectConstructors/SObjectSounds.h b/lib/mapObjectConstructors/SObjectSounds.h new file mode 100644 index 000000000..ca1b8fef9 --- /dev/null +++ b/lib/mapObjectConstructors/SObjectSounds.h @@ -0,0 +1,28 @@ +/* + * SObjectSounds.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#pragma once + +VCMI_LIB_NAMESPACE_BEGIN + +struct SObjectSounds +{ + std::vector ambient; + std::vector visit; + std::vector removal; + + template void serialize(Handler &h, const int version) + { + h & ambient; + h & visit; + h & removal; + } +}; + +VCMI_LIB_NAMESPACE_END diff --git a/lib/mapObjects/CArmedInstance.h b/lib/mapObjects/CArmedInstance.h index 817d5f4e4..e14447c55 100644 --- a/lib/mapObjects/CArmedInstance.h +++ b/lib/mapObjects/CArmedInstance.h @@ -9,7 +9,7 @@ */ #pragma once -#include "CObjectHandler.h" +#include "CGObjectInstance.h" #include "../CCreatureSet.h" #include "../bonuses/CBonusProxy.h" #include "../bonuses/CBonusSystemNode.h" diff --git a/lib/mapObjects/CBank.cpp b/lib/mapObjects/CBank.cpp index 11d4127c3..a5b090bf4 100644 --- a/lib/mapObjects/CBank.cpp +++ b/lib/mapObjects/CBank.cpp @@ -17,7 +17,8 @@ #include "../NetPacks.h" #include "../CGeneralTextHandler.h" #include "../CSoundBase.h" -#include "CommonConstructors.h" +#include "../mapObjectConstructors/CObjectClassesHandler.h" +#include "../mapObjectConstructors/CommonConstructors.h" #include "../IGameCallback.h" #include "../CGameState.h" diff --git a/lib/mapObjects/CBank.h b/lib/mapObjects/CBank.h index f723dc04b..6723e9bac 100644 --- a/lib/mapObjects/CBank.h +++ b/lib/mapObjects/CBank.h @@ -9,7 +9,6 @@ */ #pragma once -#include "CObjectHandler.h" #include "CArmedInstance.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/mapObjects/CGDwelling.cpp b/lib/mapObjects/CGDwelling.cpp index c83482345..d3566b81a 100644 --- a/lib/mapObjects/CGDwelling.cpp +++ b/lib/mapObjects/CGDwelling.cpp @@ -10,8 +10,9 @@ #include "StdInc.h" #include "CGDwelling.h" -#include "CObjectClassesHandler.h" #include "../serializer/JsonSerializeFormat.h" +#include "../mapObjectConstructors/AObjectTypeHandler.h" +#include "../mapObjectConstructors/CObjectClassesHandler.h" #include "../CTownHandler.h" #include "../IGameCallback.h" #include "../CGameState.h" diff --git a/lib/mapObjects/CGHeroInstance.cpp b/lib/mapObjects/CGHeroInstance.cpp index 55c967fff..3df8e2f88 100644 --- a/lib/mapObjects/CGHeroInstance.cpp +++ b/lib/mapObjects/CGHeroInstance.cpp @@ -24,7 +24,6 @@ #include "../CSoundBase.h" #include "../spells/CSpellHandler.h" #include "../CSkillHandler.h" -#include "CObjectClassesHandler.h" #include "../IGameCallback.h" #include "../CGameState.h" #include "../CCreatureHandler.h" @@ -32,6 +31,8 @@ #include "../mapping/CMap.h" #include "CGTownInstance.h" #include "../serializer/JsonSerializeFormat.h" +#include "../mapObjectConstructors/AObjectTypeHandler.h" +#include "../mapObjectConstructors/CObjectClassesHandler.h" #include "../StringConstants.h" #include "../battle/Unit.h" diff --git a/lib/mapObjects/CGHeroInstance.h b/lib/mapObjects/CGHeroInstance.h index 007adc0ed..1397237da 100644 --- a/lib/mapObjects/CGHeroInstance.h +++ b/lib/mapObjects/CGHeroInstance.h @@ -11,11 +11,9 @@ #include -#include "CObjectHandler.h" #include "CArmedInstance.h" #include "../CArtHandler.h" // For CArtifactSet -#include "../CRandomGenerator.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/mapObjects/CGMarket.cpp b/lib/mapObjects/CGMarket.cpp index f3f7a7789..b05de13ca 100644 --- a/lib/mapObjects/CGMarket.cpp +++ b/lib/mapObjects/CGMarket.cpp @@ -19,166 +19,11 @@ #include "CGTownInstance.h" #include "../GameSettings.h" #include "../CSkillHandler.h" -#include "CObjectClassesHandler.h" +#include "../mapObjectConstructors/AObjectTypeHandler.h" +#include "../mapObjectConstructors/CObjectClassesHandler.h" VCMI_LIB_NAMESPACE_BEGIN -bool IMarket::getOffer(int id1, int id2, int &val1, int &val2, EMarketMode::EMarketMode mode) const -{ - switch(mode) - { - case EMarketMode::RESOURCE_RESOURCE: - { - double effectiveness = std::min((getMarketEfficiency() + 1.0) / 20.0, 0.5); - - double r = VLC->objh->resVals[id1]; //value of given resource - double g = VLC->objh->resVals[id2] / effectiveness; //value of wanted resource - - if(r>g) //if given resource is more expensive than wanted - { - val2 = static_cast(ceil(r / g)); - val1 = 1; - } - else //if wanted resource is more expensive - { - val1 = static_cast((g / r) + 0.5); - val2 = 1; - } - } - break; - case EMarketMode::CREATURE_RESOURCE: - { - const double effectivenessArray[] = {0.0, 0.3, 0.45, 0.50, 0.65, 0.7, 0.85, 0.9, 1.0}; - double effectiveness = effectivenessArray[std::min(getMarketEfficiency(), 8)]; - - double r = VLC->creatures()->getByIndex(id1)->getRecruitCost(EGameResID::GOLD); //value of given creature in gold - double g = VLC->objh->resVals[id2] / effectiveness; //value of wanted resource - - if(r>g) //if given resource is more expensive than wanted - { - val2 = static_cast(ceil(r / g)); - val1 = 1; - } - else //if wanted resource is more expensive - { - val1 = static_cast((g / r) + 0.5); - val2 = 1; - } - } - break; - case EMarketMode::RESOURCE_PLAYER: - val1 = 1; - val2 = 1; - break; - case EMarketMode::RESOURCE_ARTIFACT: - { - double effectiveness = std::min((getMarketEfficiency() + 3.0) / 20.0, 0.6); - double r = VLC->objh->resVals[id1]; //value of offered resource - double g = VLC->artifacts()->getByIndex(id2)->getPrice() / effectiveness; //value of bought artifact in gold - - if(id1 != 6) //non-gold prices are doubled - r /= 2; - - val1 = std::max(1, static_cast((g / r) + 0.5)); //don't sell arts for less than 1 resource - val2 = 1; - } - break; - case EMarketMode::ARTIFACT_RESOURCE: - { - double effectiveness = std::min((getMarketEfficiency() + 3.0) / 20.0, 0.6); - double r = VLC->artifacts()->getByIndex(id1)->getPrice() * effectiveness; - double g = VLC->objh->resVals[id2]; - -// if(id2 != 6) //non-gold prices are doubled -// r /= 2; - - val1 = 1; - val2 = std::max(1, static_cast((r / g) + 0.5)); //at least one resource is given in return - } - break; - case EMarketMode::CREATURE_EXP: - { - val1 = 1; - val2 = (VLC->creh->objects[id1]->getAIValue() / 40) * 5; - } - break; - case EMarketMode::ARTIFACT_EXP: - { - val1 = 1; - - int givenClass = VLC->arth->objects[id1]->getArtClassSerial(); - if(givenClass < 0 || givenClass > 3) - { - val2 = 0; - return false; - } - - static constexpr int expPerClass[] = {1000, 1500, 3000, 6000}; - val2 = expPerClass[givenClass]; - } - break; - default: - assert(0); - return false; - } - - return true; -} - -bool IMarket::allowsTrade(EMarketMode::EMarketMode mode) const -{ - return false; -} - -int IMarket::availableUnits(EMarketMode::EMarketMode mode, int marketItemSerial) const -{ - switch(mode) - { - case EMarketMode::RESOURCE_RESOURCE: - case EMarketMode::ARTIFACT_RESOURCE: - case EMarketMode::CREATURE_RESOURCE: - return -1; - default: - return 1; - } -} - -std::vector IMarket::availableItemsIds(EMarketMode::EMarketMode mode) const -{ - std::vector ret; - switch(mode) - { - case EMarketMode::RESOURCE_RESOURCE: - case EMarketMode::ARTIFACT_RESOURCE: - case EMarketMode::CREATURE_RESOURCE: - for (int i = 0; i < 7; i++) - ret.push_back(i); - } - return ret; -} - -const IMarket * IMarket::castFrom(const CGObjectInstance *obj, bool verbose) -{ - auto * imarket = dynamic_cast(obj); - if(verbose && !imarket) - logGlobal->error("Cannot cast to IMarket object type %s", obj->typeName); - return imarket; -} - -IMarket::IMarket() -{ -} - -std::vector IMarket::availableModes() const -{ - std::vector ret; - for (int i = 0; i < EMarketMode::MARTKET_AFTER_LAST_PLACEHOLDER; i++) - if(allowsTrade(static_cast(i))) - ret.push_back(static_cast(i)); - - return ret; -} - void CGMarket::initObj(CRandomGenerator & rand) { VLC->objtypeh->getHandlerFor(ID, subID)->configureObject(this, rand); diff --git a/lib/mapObjects/CGMarket.h b/lib/mapObjects/CGMarket.h index 721d4bd40..d9e98f975 100644 --- a/lib/mapObjects/CGMarket.h +++ b/lib/mapObjects/CGMarket.h @@ -9,27 +9,11 @@ */ #pragma once -#include "CObjectHandler.h" +#include "CGObjectInstance.h" +#include "IMarket.h" VCMI_LIB_NAMESPACE_BEGIN -class DLL_LINKAGE IMarket -{ -public: - IMarket(); - virtual ~IMarket() {} - - virtual int getMarketEfficiency() const = 0; - virtual bool allowsTrade(EMarketMode::EMarketMode mode) const; - virtual int availableUnits(EMarketMode::EMarketMode mode, int marketItemSerial) const; //-1 if unlimited - virtual std::vector availableItemsIds(EMarketMode::EMarketMode mode) const; - - bool getOffer(int id1, int id2, int &val1, int &val2, EMarketMode::EMarketMode mode) const; //val1 - how many units of id1 player has to give to receive val2 units - std::vector availableModes() const; - - static const IMarket *castFrom(const CGObjectInstance *obj, bool verbose = true); -}; - class DLL_LINKAGE CGMarket : public CGObjectInstance, public IMarket { public: diff --git a/lib/mapObjects/CGObjectInstance.cpp b/lib/mapObjects/CGObjectInstance.cpp new file mode 100644 index 000000000..ef139b4b6 --- /dev/null +++ b/lib/mapObjects/CGObjectInstance.cpp @@ -0,0 +1,344 @@ +/* + * CObjectHandler.cpp, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +#include "StdInc.h" +#include "CGObjectInstance.h" + +#include "CGHeroInstance.h" +#include "ObjectTemplate.h" + +#include "../CGameState.h" +#include "../CGeneralTextHandler.h" +#include "../IGameCallback.h" +#include "../NetPacks.h" +#include "../StringConstants.h" +#include "../TerrainHandler.h" +#include "../mapObjectConstructors/AObjectTypeHandler.h" +#include "../mapObjectConstructors/CObjectClassesHandler.h" +#include "../mapping/CMap.h" +#include "../serializer/JsonSerializeFormat.h" + +//TODO: remove constructor +CGObjectInstance::CGObjectInstance(): + pos(-1,-1,-1), + ID(Obj::NO_OBJ), + subID(-1), + tempOwner(PlayerColor::UNFLAGGABLE), + blockVisit(false) +{ +} + +//must be instantiated in .cpp file for access to complete types of all member fields +CGObjectInstance::~CGObjectInstance() = default; + +int32_t CGObjectInstance::getObjGroupIndex() const +{ + return ID.num; +} + +int32_t CGObjectInstance::getObjTypeIndex() const +{ + return subID; +} + +int3 CGObjectInstance::getPosition() const +{ + return pos; +} + +int3 CGObjectInstance::getTopVisiblePos() const +{ + return pos - appearance->getTopVisibleOffset(); +} + +void CGObjectInstance::setOwner(const PlayerColor & ow) +{ + tempOwner = ow; +} +int CGObjectInstance::getWidth() const//returns width of object graphic in tiles +{ + return appearance->getWidth(); +} +int CGObjectInstance::getHeight() const //returns height of object graphic in tiles +{ + return appearance->getHeight(); +} +bool CGObjectInstance::visitableAt(int x, int y) const //returns true if object is visitable at location (x, y) form left top tile of image (x, y in tiles) +{ + return appearance->isVisitableAt(pos.x - x, pos.y - y); +} +bool CGObjectInstance::blockingAt(int x, int y) const +{ + return appearance->isBlockedAt(pos.x - x, pos.y - y); +} + +bool CGObjectInstance::coveringAt(int x, int y) const +{ + return appearance->isVisibleAt(pos.x - x, pos.y - y); +} + +std::set CGObjectInstance::getBlockedPos() const +{ + std::set ret; + for(int w=0; wisBlockedAt(w, h)) + ret.insert(int3(pos.x - w, pos.y - h, pos.z)); + } + } + return ret; +} + +std::set CGObjectInstance::getBlockedOffsets() const +{ + return appearance->getBlockedOffsets(); +} + +void CGObjectInstance::setType(si32 ID, si32 subID) +{ + auto position = visitablePos(); + auto oldOffset = getVisitableOffset(); + auto &tile = cb->gameState()->map->getTile(position); + + //recalculate blockvis tiles - new appearance might have different blockmap than before + cb->gameState()->map->removeBlockVisTiles(this, true); + auto handler = VLC->objtypeh->getHandlerFor(ID, subID); + if(!handler) + { + logGlobal->error("Unknown object type %d:%d at %s", ID, subID, visitablePos().toString()); + return; + } + if(!handler->getTemplates(tile.terType->getId()).empty()) + { + appearance = handler->getTemplates(tile.terType->getId())[0]; + } + else + { + logGlobal->warn("Object %d:%d at %s has no templates suitable for terrain %s", ID, subID, visitablePos().toString(), tile.terType->getNameTranslated()); + appearance = handler->getTemplates()[0]; // get at least some appearance since alternative is crash + } + + if(this->ID == Obj::PRISON && ID == Obj::HERO) + { + auto newOffset = getVisitableOffset(); + // FIXME: potentially unused code - setType is NOT called when releasing hero from prison + // instead, appearance update & pos adjustment occurs in GiveHero::applyGs + + // adjust position since hero and prison may have different visitable offset + pos = pos - oldOffset + newOffset; + } + + this->ID = Obj(ID); + this->subID = subID; + + cb->gameState()->map->addBlockVisTiles(this); +} + +void CGObjectInstance::initObj(CRandomGenerator & rand) +{ + switch(ID) + { + case Obj::TAVERN: + blockVisit = true; + break; + } +} + +void CGObjectInstance::setProperty( ui8 what, ui32 val ) +{ + setPropertyDer(what, val); // call this before any actual changes (needed at least for dwellings) + + switch(what) + { + case ObjProperty::OWNER: + tempOwner = PlayerColor(val); + break; + case ObjProperty::BLOCKVIS: + blockVisit = val; + break; + case ObjProperty::ID: + ID = Obj(val); + break; + case ObjProperty::SUBID: + subID = val; + break; + } +} + +void CGObjectInstance::setPropertyDer( ui8 what, ui32 val ) +{} + +int3 CGObjectInstance::getSightCenter() const +{ + return visitablePos(); +} + +int CGObjectInstance::getSightRadius() const +{ + return 3; +} + +int3 CGObjectInstance::getVisitableOffset() const +{ + return appearance->getVisitableOffset(); +} + +void CGObjectInstance::giveDummyBonus(const ObjectInstanceID & heroID, BonusDuration::Type duration) const +{ + GiveBonus gbonus; + gbonus.bonus.type = BonusType::NONE; + gbonus.id = heroID.getNum(); + gbonus.bonus.duration = duration; + gbonus.bonus.source = BonusSource::OBJECT; + gbonus.bonus.sid = ID; + cb->giveHeroBonus(&gbonus); +} + +std::string CGObjectInstance::getObjectName() const +{ + return VLC->objtypeh->getObjectName(ID, subID); +} + +std::optional CGObjectInstance::getAmbientSound() const +{ + const auto & sounds = VLC->objtypeh->getObjectSounds(ID, subID).ambient; + if(!sounds.empty()) + return sounds.front(); // TODO: Support randomization of ambient sounds + + return std::nullopt; +} + +std::optional CGObjectInstance::getVisitSound() const +{ + const auto & sounds = VLC->objtypeh->getObjectSounds(ID, subID).visit; + if(!sounds.empty()) + return *RandomGeneratorUtil::nextItem(sounds, CRandomGenerator::getDefault()); + + return std::nullopt; +} + +std::optional CGObjectInstance::getRemovalSound() const +{ + const auto & sounds = VLC->objtypeh->getObjectSounds(ID, subID).removal; + if(!sounds.empty()) + return *RandomGeneratorUtil::nextItem(sounds, CRandomGenerator::getDefault()); + + return std::nullopt; +} + +std::string CGObjectInstance::getHoverText(PlayerColor player) const +{ + auto text = getObjectName(); + if (tempOwner.isValidPlayer()) + text += "\n" + VLC->generaltexth->arraytxt[23 + tempOwner.getNum()]; + return text; +} + +std::string CGObjectInstance::getHoverText(const CGHeroInstance * hero) const +{ + return getHoverText(hero->tempOwner); +} + +void CGObjectInstance::onHeroVisit( const CGHeroInstance * h ) const +{ + switch(ID) + { + case Obj::HILL_FORT: + { + openWindow(EOpenWindowMode::HILL_FORT_WINDOW,id.getNum(),h->id.getNum()); + } + break; + case Obj::SANCTUARY: + { + //You enter the sanctuary and immediately feel as if a great weight has been lifted off your shoulders. You feel safe here. + h->showInfoDialog(114); + } + break; + case Obj::TAVERN: + { + openWindow(EOpenWindowMode::TAVERN_WINDOW,h->id.getNum(),id.getNum()); + } + break; + } +} + +int3 CGObjectInstance::visitablePos() const +{ + return pos - getVisitableOffset(); +} + +bool CGObjectInstance::isVisitable() const +{ + return appearance->isVisitable(); +} + +bool CGObjectInstance::passableFor(PlayerColor color) const +{ + return false; +} + +void CGObjectInstance::updateFrom(const JsonNode & data) +{ + +} + +void CGObjectInstance::serializeJson(JsonSerializeFormat & handler) +{ + //only save here, loading is handled by map loader + if(handler.saving) + { + handler.serializeString("type", typeName); + handler.serializeString("subtype", subTypeName); + + handler.serializeInt("x", pos.x); + handler.serializeInt("y", pos.y); + handler.serializeInt("l", pos.z); + JsonNode app; + appearance->writeJson(app, false); + handler.serializeRaw("template", app, std::nullopt); + } + + { + auto options = handler.enterStruct("options"); + serializeJsonOptions(handler); + } +} + +void CGObjectInstance::afterAddToMap(CMap * map) +{ + //nothing here +} + +void CGObjectInstance::afterRemoveFromMap(CMap * map) +{ + //nothing here +} + +void CGObjectInstance::serializeJsonOptions(JsonSerializeFormat & handler) +{ + //nothing here +} + +void CGObjectInstance::serializeJsonOwner(JsonSerializeFormat & handler) +{ + ui8 temp = tempOwner.getNum(); + + handler.serializeEnum("owner", temp, PlayerColor::NEUTRAL.getNum(), GameConstants::PLAYER_COLOR_NAMES); + + if(!handler.saving) + tempOwner = PlayerColor(temp); +} + +BattleField CGObjectInstance::getBattlefield() const +{ + return VLC->objtypeh->getHandlerFor(ID, subID)->getBattlefield(); +} diff --git a/lib/mapObjects/CGObjectInstance.h b/lib/mapObjects/CGObjectInstance.h new file mode 100644 index 000000000..8563858a5 --- /dev/null +++ b/lib/mapObjects/CGObjectInstance.h @@ -0,0 +1,143 @@ +/* + * CGObjectInstance.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#pragma once + +#include "IObjectInterface.h" +#include "../int3.h" +#include "../bonuses/BonusEnum.h" + +VCMI_LIB_NAMESPACE_BEGIN + +class JsonSerializeFormat; +class ObjectTemplate; +class CMap; + +class DLL_LINKAGE CGObjectInstance : public IObjectInterface +{ +public: + /// Position of bottom-right corner of object on map + int3 pos; + /// Type of object, e.g. town, hero, creature. + Obj ID; + /// Subtype of object, depends on type + si32 subID; + /// Current owner of an object (when below PLAYER_LIMIT) + PlayerColor tempOwner; + /// Index of object in map's list of objects + ObjectInstanceID id; + /// Defines appearance of object on map (animation, blocked tiles, blit order, etc) + std::shared_ptr appearance; + /// If true hero can visit this object only from neighbouring tiles and can't stand on this object + bool blockVisit; + + std::string instanceName; + std::string typeName; + std::string subTypeName; + + CGObjectInstance(); //TODO: remove constructor + ~CGObjectInstance() override; + + int32_t getObjGroupIndex() const override; + int32_t getObjTypeIndex() const override; + + /// "center" tile from which the sight distance is calculated + int3 getSightCenter() const; + + PlayerColor getOwner() const override + { + return this->tempOwner; + } + void setOwner(const PlayerColor & ow); + + /** APPEARANCE ACCESSORS **/ + + int getWidth() const; //returns width of object graphic in tiles + int getHeight() const; //returns height of object graphic in tiles + bool visitableAt(int x, int y) const; //returns true if object is visitable at location (x, y) (h3m pos) + int3 visitablePos() const override; + int3 getPosition() const override; + int3 getTopVisiblePos() const; + bool blockingAt(int x, int y) const; //returns true if object is blocking location (x, y) (h3m pos) + bool coveringAt(int x, int y) const; //returns true if object covers with picture location (x, y) (h3m pos) + std::set getBlockedPos() const; //returns set of positions blocked by this object + std::set getBlockedOffsets() const; //returns set of relative positions blocked by this object + bool isVisitable() const; //returns true if object is visitable + + virtual BattleField getBattlefield() const; + + virtual bool isTile2Terrain() const { return false; } + + std::optional getAmbientSound() const; + std::optional getVisitSound() const; + std::optional getRemovalSound() const; + + /** VIRTUAL METHODS **/ + + /// Returns true if player can pass through visitable tiles of this object + virtual bool passableFor(PlayerColor color) const; + /// Range of revealed map around this object, counting from getSightCenter() + virtual int getSightRadius() const; + /// returns (x,y,0) offset to a visitable tile of object + virtual int3 getVisitableOffset() const; + /// Called mostly during map randomization to turn random object into a regular one (e.g. "Random Monster" into "Pikeman") + virtual void setType(si32 ID, si32 subID); + + /// returns text visible in status bar with specific hero/player active. + + /// Returns generic name of object, without any player-specific info + virtual std::string getObjectName() const; + + /// Returns hover name for situation when there are no selected heroes. Default = object name + virtual std::string getHoverText(PlayerColor player) const; + /// Returns hero-specific hover name, including visited/not visited info. Default = player-specific name + virtual std::string getHoverText(const CGHeroInstance * hero) const; + + /** OVERRIDES OF IObjectInterface **/ + + void initObj(CRandomGenerator & rand) override; + void onHeroVisit(const CGHeroInstance * h) const override; + /// method for synchronous update. Note: For new properties classes should override setPropertyDer instead + void setProperty(ui8 what, ui32 val) final; + + virtual void afterAddToMap(CMap * map); + virtual void afterRemoveFromMap(CMap * map); + + ///Entry point of binary (de-)serialization + template void serialize(Handler &h, const int version) + { + h & instanceName; + h & typeName; + h & subTypeName; + h & pos; + h & ID; + h & subID; + h & id; + h & tempOwner; + h & blockVisit; + h & appearance; + //definfo is handled by map serializer + } + + ///Entry point of Json (de-)serialization + void serializeJson(JsonSerializeFormat & handler); + virtual void updateFrom(const JsonNode & data); + +protected: + /// virtual method that allows synchronously update object state on server and all clients + virtual void setPropertyDer(ui8 what, ui32 val); + + /// Gives dummy bonus from this object to hero. Can be used to track visited state + void giveDummyBonus(const ObjectInstanceID & heroID, BonusDuration::Type duration = BonusDuration::ONE_DAY) const; + + ///Serialize object-type specific options + virtual void serializeJsonOptions(JsonSerializeFormat & handler); + + void serializeJsonOwner(JsonSerializeFormat & handler); +}; diff --git a/lib/mapObjects/CGPandoraBox.h b/lib/mapObjects/CGPandoraBox.h index 46c89baf3..b6c94a7bd 100644 --- a/lib/mapObjects/CGPandoraBox.h +++ b/lib/mapObjects/CGPandoraBox.h @@ -9,7 +9,6 @@ */ #pragma once -#include "CObjectHandler.h" #include "CArmedInstance.h" #include "../ResourceSet.h" diff --git a/lib/mapObjects/CGTownBuilding.h b/lib/mapObjects/CGTownBuilding.h index 998a52794..1fffb3710 100644 --- a/lib/mapObjects/CGTownBuilding.h +++ b/lib/mapObjects/CGTownBuilding.h @@ -10,7 +10,7 @@ #pragma once -#include "CObjectHandler.h" +#include "IObjectInterface.h" #include "../rewardable/Interface.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/mapObjects/CGTownInstance.cpp b/lib/mapObjects/CGTownInstance.cpp index 444d1398d..e704e3b49 100644 --- a/lib/mapObjects/CGTownInstance.cpp +++ b/lib/mapObjects/CGTownInstance.cpp @@ -11,7 +11,6 @@ #include "StdInc.h" #include "CGTownInstance.h" #include "CGTownBuilding.h" -#include "CObjectClassesHandler.h" #include "../spells/CSpellHandler.h" #include "../bonuses/Bonus.h" #include "../battle/IBattleInfoCallback.h" @@ -24,6 +23,8 @@ #include "../mapping/CMap.h" #include "../CPlayerState.h" #include "../TerrainHandler.h" +#include "../mapObjectConstructors/AObjectTypeHandler.h" +#include "../mapObjectConstructors/CObjectClassesHandler.h" #include "../serializer/JsonSerializeFormat.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/mapObjects/CGTownInstance.h b/lib/mapObjects/CGTownInstance.h index f41c64870..aaffde1ce 100644 --- a/lib/mapObjects/CGTownInstance.h +++ b/lib/mapObjects/CGTownInstance.h @@ -9,9 +9,7 @@ */ #pragma once -#include "CObjectHandler.h" -#include "CGMarket.h" // For IMarket interface -#include "CArmedInstance.h" +#include "IMarket.h" #include "CGDwelling.h" #include "CGTownBuilding.h" diff --git a/lib/mapObjects/CObjectClassesHandler.h b/lib/mapObjects/CObjectClassesHandler.h deleted file mode 100644 index 36e234108..000000000 --- a/lib/mapObjects/CObjectClassesHandler.h +++ /dev/null @@ -1,337 +0,0 @@ -/* - * CObjectClassesHandler.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ -#pragma once - -#include "ObjectTemplate.h" - -#include "../GameConstants.h" -#include "../ConstTransitivePtr.h" -#include "../IHandlerBase.h" -#include "../JsonNode.h" - -VCMI_LIB_NAMESPACE_BEGIN - -class JsonNode; -class CRandomGenerator; - - -struct SObjectSounds -{ - std::vector ambient; - std::vector visit; - std::vector removal; - - template void serialize(Handler &h, const int version) - { - h & ambient; - h & visit; - h & removal; - } -}; - -/// Structure that describes placement rules for this object in random map -struct DLL_LINKAGE RandomMapInfo -{ - /// How valuable this object is, 1k = worthless, 10k = Utopia-level - ui32 value; - - /// How many of such objects can be placed on map, 0 = object can not be placed by RMG - std::optional mapLimit; - - /// How many of such objects can be placed in one zone, 0 = unplaceable - ui32 zoneLimit; - - /// Rarity of object, 5 = extremely rare, 100 = common - ui32 rarity; - - RandomMapInfo(): - value(0), - zoneLimit(0), - rarity(0) - {} - - void setMapLimit(ui32 val) { mapLimit = val; } - - template void serialize(Handler &h, const int version) - { - h & value; - h & mapLimit; - h & zoneLimit; - h & rarity; - } -}; - -struct DLL_LINKAGE CompoundMapObjectID -{ - si32 primaryID; - si32 secondaryID; - - CompoundMapObjectID(si32 primID, si32 secID) : primaryID(primID), secondaryID(secID) {}; - - bool operator<(const CompoundMapObjectID& other) const - { - if(this->primaryID != other.primaryID) - return this->primaryID < other.primaryID; - else - return this->secondaryID < other.secondaryID; - } - - bool operator==(const CompoundMapObjectID& other) const - { - return (this->primaryID == other.primaryID) && (this->secondaryID == other.secondaryID); - } -}; - -class DLL_LINKAGE IObjectInfo -{ -public: - struct CArmyStructure - { - ui32 totalStrength; - ui32 shootersStrength; - ui32 flyersStrength; - ui32 walkersStrength; - - CArmyStructure() : - totalStrength(0), - shootersStrength(0), - flyersStrength(0), - walkersStrength(0) - {} - - bool operator <(const CArmyStructure & other) const - { - return this->totalStrength < other.totalStrength; - } - }; - - /// Returns possible composition of guards. Actual guards would be - /// somewhere between these two values - virtual CArmyStructure minGuards() const { return CArmyStructure(); } - virtual CArmyStructure maxGuards() const { return CArmyStructure(); } - - virtual bool givesResources() const { return false; } - - virtual bool givesExperience() const { return false; } - virtual bool givesMana() const { return false; } - virtual bool givesMovement() const { return false; } - - virtual bool givesPrimarySkills() const { return false; } - virtual bool givesSecondarySkills() const { return false; } - - virtual bool givesArtifacts() const { return false; } - virtual bool givesCreatures() const { return false; } - virtual bool givesSpells() const { return false; } - - virtual bool givesBonuses() const { return false; } - - virtual ~IObjectInfo() = default; -}; - -class CGObjectInstance; - -/// Class responsible for creation of objects of specific type & subtype -class DLL_LINKAGE AObjectTypeHandler : public boost::noncopyable -{ - friend class CObjectClassesHandler; - - RandomMapInfo rmgInfo; - - JsonNode base; /// describes base template - - std::vector> templates; - - SObjectSounds sounds; - - std::optional aiValue; - std::optional battlefield; - - std::string modScope; - std::string typeName; - std::string subTypeName; - - si32 type; - si32 subtype; - -protected: - void preInitObject(CGObjectInstance * obj) const; - virtual bool objectFilter(const CGObjectInstance * obj, std::shared_ptr tmpl) const; - - /// initialization for classes that inherit this one - virtual void initTypeData(const JsonNode & input); -public: - - virtual ~AObjectTypeHandler() = default; - - si32 getIndex() const; - si32 getSubIndex() const; - - std::string getTypeName() const; - std::string getSubTypeName() const; - - /// loads generic data from Json structure and passes it towards type-specific constructors - void init(const JsonNode & input); - - /// returns full form of identifier of this object in form of modName:objectName - std::string getJsonKey() const; - - /// Returns object-specific name, if set - SObjectSounds getSounds() const; - - void addTemplate(const std::shared_ptr & templ); - void addTemplate(JsonNode config); - - /// returns all templates matching parameters - std::vector> getTemplates() const; - std::vector> getTemplates(const TerrainId terrainType) const; - - /// returns preferred template for this object, if present (e.g. one of 3 possible templates for town - village, fort and castle) - /// note that appearance will not be changed - this must be done separately (either by assignment or via pack from server) - std::shared_ptr getOverride(TerrainId terrainType, const CGObjectInstance * object) const; - - BattleField getBattlefield() const; - - const RandomMapInfo & getRMGInfo(); - - std::optional getAiValue() const; - - /// returns true if this class provides custom text ID's instead of generic per-object name - virtual bool hasNameTextID() const; - - /// returns object's name in form of translatable text ID - virtual std::string getNameTextID() const; - - /// returns object's name in form of human-readable text - std::string getNameTranslated() const; - - virtual bool isStaticObject(); - - virtual void afterLoadFinalization(); - - /// Creates object and set up core properties (like ID/subID). Object is NOT initialized - /// to allow creating objects before game start (e.g. map loading) - virtual CGObjectInstance * create(std::shared_ptr tmpl = nullptr) const = 0; - - /// Configures object properties. Should be re-entrable, resetting state of the object if necessarily - /// This should set remaining properties, including randomized or depending on map - virtual void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const = 0; - - /// Returns object configuration, if available. Otherwise returns NULL - virtual std::unique_ptr getObjectInfo(std::shared_ptr tmpl) const = 0; - - template void serialize(Handler &h, const int version) - { - h & type; - h & subtype; - h & templates; - h & rmgInfo; - h & modScope; - h & typeName; - h & subTypeName; - h & sounds; - h & aiValue; - h & battlefield; - } -}; - -using TObjectTypeHandler = std::shared_ptr; - -/// Class responsible for creation of adventure map objects of specific type -class DLL_LINKAGE ObjectClass -{ -public: - std::string modScope; - std::string identifier; - - si32 id; - std::string handlerName; // ID of handler that controls this object, should be determined using handlerConstructor map - - JsonNode base; - std::vector objects; - - ObjectClass() = default; - - std::string getJsonKey() const; - std::string getNameTextID() const; - std::string getNameTranslated() const; - - template void serialize(Handler &h, const int version) - { - h & id; - h & handlerName; - h & base; - h & objects; - h & identifier; - h & modScope; - } -}; - -/// Main class responsible for creation of all adventure map objects -class DLL_LINKAGE CObjectClassesHandler : public IHandlerBase -{ - /// list of object handlers, each of them handles only one type - std::vector objects; - - /// map that is filled during contruction with all known handlers. Not serializeable due to usage of std::function - std::map > handlerConstructors; - - /// container with H3 templates, used only during loading, no need to serialize it - using TTemplatesContainer = std::multimap, std::shared_ptr>; - TTemplatesContainer legacyTemplates; - - TObjectTypeHandler loadSubObjectFromJson(const std::string & scope, const std::string & identifier, const JsonNode & entry, ObjectClass * obj, size_t index); - - void loadSubObject(const std::string & scope, const std::string & identifier, const JsonNode & entry, ObjectClass * obj); - void loadSubObject(const std::string & scope, const std::string & identifier, const JsonNode & entry, ObjectClass * obj, size_t index); - - ObjectClass * loadFromJson(const std::string & scope, const JsonNode & json, const std::string & name, size_t index); - - void generateExtraMonolithsForRMG(); - -public: - CObjectClassesHandler(); - ~CObjectClassesHandler(); - - std::vector loadLegacyData() override; - - void loadObject(std::string scope, std::string name, const JsonNode & data) override; - void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override; - - void loadSubObject(const std::string & identifier, JsonNode config, si32 ID, si32 subID); - void removeSubObject(si32 ID, si32 subID); - - void beforeValidate(JsonNode & object) override; - void afterLoadFinalization() override; - - std::vector getDefaultAllowed() const override; - - /// Queries to detect loaded objects - std::set knownObjects() const; - std::set knownSubObjects(si32 primaryID) const; - - /// returns handler for specified object (ID-based). ObjectHandler keeps ownership - TObjectTypeHandler getHandlerFor(si32 type, si32 subtype) const; - TObjectTypeHandler getHandlerFor(const std::string & scope, const std::string & type, const std::string & subtype) const; - TObjectTypeHandler getHandlerFor(CompoundMapObjectID compoundIdentifier) const; - - std::string getObjectName(si32 type, si32 subtype) const; - - SObjectSounds getObjectSounds(si32 type, si32 subtype) const; - - /// Returns handler string describing the handler (for use in client) - std::string getObjectHandlerName(si32 type) const; - - template void serialize(Handler &h, const int version) - { - h & objects; - } -}; - -VCMI_LIB_NAMESPACE_END diff --git a/lib/mapObjects/CObjectHandler.cpp b/lib/mapObjects/CObjectHandler.cpp index 7771ffa01..dccbb6610 100644 --- a/lib/mapObjects/CObjectHandler.cpp +++ b/lib/mapObjects/CObjectHandler.cpp @@ -11,89 +11,11 @@ #include "StdInc.h" #include "CObjectHandler.h" -#include "../NetPacks.h" -#include "../CGeneralTextHandler.h" -#include "../CHeroHandler.h" -#include "../CSoundBase.h" +#include "CGObjectInstance.h" #include "../filesystem/ResourceID.h" -#include "../IGameCallback.h" -#include "../CGameState.h" -#include "../StringConstants.h" -#include "../mapping/CMap.h" -#include "../TerrainHandler.h" - -#include "CObjectClassesHandler.h" -#include "CGTownInstance.h" - -#include "../serializer/JsonSerializeFormat.h" VCMI_LIB_NAMESPACE_BEGIN -IGameCallback * IObjectInterface::cb = nullptr; - -///helpers -void IObjectInterface::openWindow(const EOpenWindowMode type, const int id1, const int id2) -{ - OpenWindow ow; - ow.window = type; - ow.id1 = id1; - ow.id2 = id2; - IObjectInterface::cb->sendAndApply(&ow); -} - -void IObjectInterface::showInfoDialog(const ui32 txtID, const ui16 soundID, EInfoWindowMode mode) const -{ - InfoWindow iw; - iw.soundID = soundID; - iw.player = getOwner(); - iw.type = mode; - iw.text.addTxt(MetaString::ADVOB_TXT,txtID); - IObjectInterface::cb->sendAndApply(&iw); -} - -///IObjectInterface -void IObjectInterface::onHeroVisit(const CGHeroInstance * h) const -{} - -void IObjectInterface::onHeroLeave(const CGHeroInstance * h) const -{} - -void IObjectInterface::newTurn(CRandomGenerator & rand) const -{} - -void IObjectInterface::initObj(CRandomGenerator & rand) -{} - -void IObjectInterface::setProperty( ui8 what, ui32 val ) -{} - -bool IObjectInterface::wasVisited (PlayerColor player) const -{ - return false; -} -bool IObjectInterface::wasVisited (const CGHeroInstance * h) const -{ - return false; -} - -void IObjectInterface::postInit() -{} - -void IObjectInterface::preInit() -{} - -void IObjectInterface::battleFinished(const CGHeroInstance *hero, const BattleResult &result) const -{} - -void IObjectInterface::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const -{} - -void IObjectInterface::garrisonDialogClosed(const CGHeroInstance *hero) const -{} - -void IObjectInterface::heroLevelUpDone(const CGHeroInstance *hero) const -{} - CObjectHandler::CObjectHandler() { logGlobal->trace("\t\tReading resources prices "); @@ -105,324 +27,6 @@ CObjectHandler::CObjectHandler() logGlobal->trace("\t\tDone loading resource prices!"); } -//TODO: remove constructor -CGObjectInstance::CGObjectInstance(): - pos(-1,-1,-1), - ID(Obj::NO_OBJ), - subID(-1), - tempOwner(PlayerColor::UNFLAGGABLE), - blockVisit(false) -{ -} - -//must be instantiated in .cpp file for access to complete types of all member fields -CGObjectInstance::~CGObjectInstance() = default; - -int32_t CGObjectInstance::getObjGroupIndex() const -{ - return ID.num; -} - -int32_t CGObjectInstance::getObjTypeIndex() const -{ - return subID; -} - -int3 CGObjectInstance::getPosition() const -{ - return pos; -} - -int3 CGObjectInstance::getTopVisiblePos() const -{ - return pos - appearance->getTopVisibleOffset(); -} - -void CGObjectInstance::setOwner(const PlayerColor & ow) -{ - tempOwner = ow; -} -int CGObjectInstance::getWidth() const//returns width of object graphic in tiles -{ - return appearance->getWidth(); -} -int CGObjectInstance::getHeight() const //returns height of object graphic in tiles -{ - return appearance->getHeight(); -} -bool CGObjectInstance::visitableAt(int x, int y) const //returns true if object is visitable at location (x, y) form left top tile of image (x, y in tiles) -{ - return appearance->isVisitableAt(pos.x - x, pos.y - y); -} -bool CGObjectInstance::blockingAt(int x, int y) const -{ - return appearance->isBlockedAt(pos.x - x, pos.y - y); -} - -bool CGObjectInstance::coveringAt(int x, int y) const -{ - return appearance->isVisibleAt(pos.x - x, pos.y - y); -} - -std::set CGObjectInstance::getBlockedPos() const -{ - std::set ret; - for(int w=0; wisBlockedAt(w, h)) - ret.insert(int3(pos.x - w, pos.y - h, pos.z)); - } - } - return ret; -} - -std::set CGObjectInstance::getBlockedOffsets() const -{ - return appearance->getBlockedOffsets(); -} - -void CGObjectInstance::setType(si32 ID, si32 subID) -{ - auto position = visitablePos(); - auto oldOffset = getVisitableOffset(); - auto &tile = cb->gameState()->map->getTile(position); - - //recalculate blockvis tiles - new appearance might have different blockmap than before - cb->gameState()->map->removeBlockVisTiles(this, true); - auto handler = VLC->objtypeh->getHandlerFor(ID, subID); - if(!handler) - { - logGlobal->error("Unknown object type %d:%d at %s", ID, subID, visitablePos().toString()); - return; - } - if(!handler->getTemplates(tile.terType->getId()).empty()) - { - appearance = handler->getTemplates(tile.terType->getId())[0]; - } - else - { - logGlobal->warn("Object %d:%d at %s has no templates suitable for terrain %s", ID, subID, visitablePos().toString(), tile.terType->getNameTranslated()); - appearance = handler->getTemplates()[0]; // get at least some appearance since alternative is crash - } - - if(this->ID == Obj::PRISON && ID == Obj::HERO) - { - auto newOffset = getVisitableOffset(); - // FIXME: potentially unused code - setType is NOT called when releasing hero from prison - // instead, appearance update & pos adjustment occurs in GiveHero::applyGs - - // adjust position since hero and prison may have different visitable offset - pos = pos - oldOffset + newOffset; - } - - this->ID = Obj(ID); - this->subID = subID; - - cb->gameState()->map->addBlockVisTiles(this); -} - -void CGObjectInstance::initObj(CRandomGenerator & rand) -{ - switch(ID) - { - case Obj::TAVERN: - blockVisit = true; - break; - } -} - -void CGObjectInstance::setProperty( ui8 what, ui32 val ) -{ - setPropertyDer(what, val); // call this before any actual changes (needed at least for dwellings) - - switch(what) - { - case ObjProperty::OWNER: - tempOwner = PlayerColor(val); - break; - case ObjProperty::BLOCKVIS: - blockVisit = val; - break; - case ObjProperty::ID: - ID = Obj(val); - break; - case ObjProperty::SUBID: - subID = val; - break; - } -} - -void CGObjectInstance::setPropertyDer( ui8 what, ui32 val ) -{} - -int3 CGObjectInstance::getSightCenter() const -{ - return visitablePos(); -} - -int CGObjectInstance::getSightRadius() const -{ - return 3; -} - -int3 CGObjectInstance::getVisitableOffset() const -{ - return appearance->getVisitableOffset(); -} - -void CGObjectInstance::giveDummyBonus(const ObjectInstanceID & heroID, BonusDuration::Type duration) const -{ - GiveBonus gbonus; - gbonus.bonus.type = BonusType::NONE; - gbonus.id = heroID.getNum(); - gbonus.bonus.duration = duration; - gbonus.bonus.source = BonusSource::OBJECT; - gbonus.bonus.sid = ID; - cb->giveHeroBonus(&gbonus); -} - -std::string CGObjectInstance::getObjectName() const -{ - return VLC->objtypeh->getObjectName(ID, subID); -} - -std::optional CGObjectInstance::getAmbientSound() const -{ - const auto & sounds = VLC->objtypeh->getObjectSounds(ID, subID).ambient; - if(!sounds.empty()) - return sounds.front(); // TODO: Support randomization of ambient sounds - - return std::nullopt; -} - -std::optional CGObjectInstance::getVisitSound() const -{ - const auto & sounds = VLC->objtypeh->getObjectSounds(ID, subID).visit; - if(!sounds.empty()) - return *RandomGeneratorUtil::nextItem(sounds, CRandomGenerator::getDefault()); - - return std::nullopt; -} - -std::optional CGObjectInstance::getRemovalSound() const -{ - const auto & sounds = VLC->objtypeh->getObjectSounds(ID, subID).removal; - if(!sounds.empty()) - return *RandomGeneratorUtil::nextItem(sounds, CRandomGenerator::getDefault()); - - return std::nullopt; -} - -std::string CGObjectInstance::getHoverText(PlayerColor player) const -{ - auto text = getObjectName(); - if (tempOwner.isValidPlayer()) - text += "\n" + VLC->generaltexth->arraytxt[23 + tempOwner.getNum()]; - return text; -} - -std::string CGObjectInstance::getHoverText(const CGHeroInstance * hero) const -{ - return getHoverText(hero->tempOwner); -} - -void CGObjectInstance::onHeroVisit( const CGHeroInstance * h ) const -{ - switch(ID) - { - case Obj::HILL_FORT: - { - openWindow(EOpenWindowMode::HILL_FORT_WINDOW,id.getNum(),h->id.getNum()); - } - break; - case Obj::SANCTUARY: - { - //You enter the sanctuary and immediately feel as if a great weight has been lifted off your shoulders. You feel safe here. - h->showInfoDialog(114); - } - break; - case Obj::TAVERN: - { - openWindow(EOpenWindowMode::TAVERN_WINDOW,h->id.getNum(),id.getNum()); - } - break; - } -} - -int3 CGObjectInstance::visitablePos() const -{ - return pos - getVisitableOffset(); -} - -bool CGObjectInstance::isVisitable() const -{ - return appearance->isVisitable(); -} - -bool CGObjectInstance::passableFor(PlayerColor color) const -{ - return false; -} - -void CGObjectInstance::updateFrom(const JsonNode & data) -{ - -} - -void CGObjectInstance::serializeJson(JsonSerializeFormat & handler) -{ - //only save here, loading is handled by map loader - if(handler.saving) - { - handler.serializeString("type", typeName); - handler.serializeString("subtype", subTypeName); - - handler.serializeInt("x", pos.x); - handler.serializeInt("y", pos.y); - handler.serializeInt("l", pos.z); - JsonNode app; - appearance->writeJson(app, false); - handler.serializeRaw("template", app, std::nullopt); - } - - { - auto options = handler.enterStruct("options"); - serializeJsonOptions(handler); - } -} - -void CGObjectInstance::afterAddToMap(CMap * map) -{ - //nothing here -} - -void CGObjectInstance::afterRemoveFromMap(CMap * map) -{ - //nothing here -} - -void CGObjectInstance::serializeJsonOptions(JsonSerializeFormat & handler) -{ - //nothing here -} - -void CGObjectInstance::serializeJsonOwner(JsonSerializeFormat & handler) -{ - ui8 temp = tempOwner.getNum(); - - handler.serializeEnum("owner", temp, PlayerColor::NEUTRAL.getNum(), GameConstants::PLAYER_COLOR_NAMES); - - if(!handler.saving) - tempOwner = PlayerColor(temp); -} - -BattleField CGObjectInstance::getBattlefield() const -{ - return VLC->objtypeh->getHandlerFor(ID, subID)->getBattlefield(); -} - CGObjectInstanceBySubIdFinder::CGObjectInstanceBySubIdFinder(CGObjectInstance * obj) : obj(obj) { @@ -433,103 +37,4 @@ bool CGObjectInstanceBySubIdFinder::operator()(CGObjectInstance * obj) const return this->obj->subID == obj->subID; } -int3 IBoatGenerator::bestLocation() const -{ - std::vector offsets; - getOutOffsets(offsets); - - for (auto & offset : offsets) - { - if(const TerrainTile *tile = IObjectInterface::cb->getTile(o->pos + offset, false)) //tile is in the map - { - if(tile->terType->isWater() && (!tile->blocked || tile->blockingObjects.front()->ID == Obj::BOAT)) //and is water and is not blocked or is blocked by boat - return o->pos + offset; - } - } - return int3 (-1,-1,-1); -} - -IBoatGenerator::EGeneratorState IBoatGenerator::shipyardStatus() const -{ - int3 tile = bestLocation(); - const TerrainTile *t = IObjectInterface::cb->getTile(tile); - if(!t) - return TILE_BLOCKED; //no available water - else if(t->blockingObjects.empty()) - return GOOD; //OK - else if(t->blockingObjects.front()->ID == Obj::BOAT) - return BOAT_ALREADY_BUILT; //blocked with boat - else - return TILE_BLOCKED; //blocked -} - -BoatId IBoatGenerator::getBoatType() const -{ - //We make good ships by default - return EBoatId::BOAT_GOOD; -} - - -IBoatGenerator::IBoatGenerator(const CGObjectInstance *O) -: o(O) -{ -} - -void IBoatGenerator::getProblemText(MetaString &out, const CGHeroInstance *visitor) const -{ - switch(shipyardStatus()) - { - case BOAT_ALREADY_BUILT: - out.addTxt(MetaString::GENERAL_TXT, 51); - break; - case TILE_BLOCKED: - if(visitor) - { - out.addTxt(MetaString::GENERAL_TXT, 134); - out.addReplacement(visitor->getNameTranslated()); - } - else - out.addTxt(MetaString::ADVOB_TXT, 189); - break; - case NO_WATER: - logGlobal->error("Shipyard without water! %s \t %d", o->pos.toString(), o->id.getNum()); - return; - } -} - -void IShipyard::getBoatCost(TResources & cost) const -{ - cost[EGameResID::WOOD] = 10; - cost[EGameResID::GOLD] = 1000; -} - -IShipyard::IShipyard(const CGObjectInstance *O) - : IBoatGenerator(O) -{ -} - -IShipyard * IShipyard::castFrom( CGObjectInstance *obj ) -{ - if(!obj) - return nullptr; - - if(obj->ID == Obj::TOWN) - { - return dynamic_cast(obj); - } - else if(obj->ID == Obj::SHIPYARD) - { - return dynamic_cast(obj); - } - else - { - return nullptr; - } -} - -const IShipyard * IShipyard::castFrom( const CGObjectInstance *obj ) -{ - return castFrom(const_cast(obj)); -} - VCMI_LIB_NAMESPACE_END diff --git a/lib/mapObjects/CObjectHandler.h b/lib/mapObjects/CObjectHandler.h index 5e537af21..128d579b4 100644 --- a/lib/mapObjects/CObjectHandler.h +++ b/lib/mapObjects/CObjectHandler.h @@ -9,236 +9,12 @@ */ #pragma once -#include "ObjectTemplate.h" - -#include "../int3.h" -#include "../NetPacksBase.h" -#include "../ResourceSet.h" - -#include "../bonuses/Bonus.h" +#include "../GameConstants.h" VCMI_LIB_NAMESPACE_BEGIN -class CGHeroInstance; -class IGameCallback; class CGObjectInstance; -struct MetaString; -struct BattleResult; -class JsonSerializeFormat; -class CRandomGenerator; -class CMap; -class JsonNode; - -// This one teleport-specific, but has to be available everywhere in callbacks and netpacks -// For now it's will be there till teleports code refactored and moved into own file -using TTeleportExitsList = std::vector>; - -class DLL_LINKAGE IObjectInterface -{ -public: - static IGameCallback *cb; - - virtual ~IObjectInterface() = default; - - virtual int32_t getObjGroupIndex() const = 0; - virtual int32_t getObjTypeIndex() const = 0; - - virtual PlayerColor getOwner() const = 0; - virtual int3 visitablePos() const = 0; - virtual int3 getPosition() const = 0; - - virtual void onHeroVisit(const CGHeroInstance * h) const; - virtual void onHeroLeave(const CGHeroInstance * h) const; - virtual void newTurn(CRandomGenerator & rand) const; - virtual void initObj(CRandomGenerator & rand); //synchr - virtual void setProperty(ui8 what, ui32 val);//synchr - - //Called when queries created DURING HERO VISIT are resolved - //First parameter is always hero that visited object and triggered the query - virtual void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const; - virtual void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const; - virtual void garrisonDialogClosed(const CGHeroInstance *hero) const; - virtual void heroLevelUpDone(const CGHeroInstance *hero) const; - - //unified helper to show info dialog for object owner - virtual void showInfoDialog(const ui32 txtID, const ui16 soundID = 0, EInfoWindowMode mode = EInfoWindowMode::AUTO) const; - - //unified helper to show a specific window - static void openWindow(const EOpenWindowMode type, const int id1, const int id2 = -1); - - //unified interface, AI helpers - virtual bool wasVisited (PlayerColor player) const; - virtual bool wasVisited (const CGHeroInstance * h) const; - - static void preInit(); //called before objs receive their initObj - static void postInit();//called after objs receive their initObj - - template void serialize(Handler &h, const int version) - { - logGlobal->error("IObjectInterface serialized, unexpected, should not happen!"); - } -}; - -class DLL_LINKAGE IBoatGenerator -{ -public: - const CGObjectInstance *o; - - IBoatGenerator(const CGObjectInstance *O); - virtual ~IBoatGenerator() = default; - - virtual BoatId getBoatType() const; //0 - evil (if a ship can be evil...?), 1 - good, 2 - neutral - virtual void getOutOffsets(std::vector &offsets) const =0; //offsets to obj pos when we boat can be placed - int3 bestLocation() const; //returns location when the boat should be placed - - enum EGeneratorState {GOOD, BOAT_ALREADY_BUILT, TILE_BLOCKED, NO_WATER}; - EGeneratorState shipyardStatus() const; //0 - can buid, 1 - there is already a boat at dest tile, 2 - dest tile is blocked, 3 - no water - void getProblemText(MetaString &out, const CGHeroInstance *visitor = nullptr) const; - - template void serialize(Handler &h, const int version) - { - h & o; - } -}; - -class DLL_LINKAGE IShipyard : public IBoatGenerator -{ -public: - IShipyard(const CGObjectInstance *O); - - virtual void getBoatCost(TResources & cost) const; - - static const IShipyard *castFrom(const CGObjectInstance *obj); - static IShipyard *castFrom(CGObjectInstance *obj); - - template void serialize(Handler &h, const int version) - { - h & static_cast(*this); - } -}; - -class DLL_LINKAGE CGObjectInstance : public IObjectInterface -{ -public: - /// Position of bottom-right corner of object on map - int3 pos; - /// Type of object, e.g. town, hero, creature. - Obj ID; - /// Subtype of object, depends on type - si32 subID; - /// Current owner of an object (when below PLAYER_LIMIT) - PlayerColor tempOwner; - /// Index of object in map's list of objects - ObjectInstanceID id; - /// Defines appearance of object on map (animation, blocked tiles, blit order, etc) - std::shared_ptr appearance; - /// If true hero can visit this object only from neighbouring tiles and can't stand on this object - bool blockVisit; - - std::string instanceName; - std::string typeName; - std::string subTypeName; - - CGObjectInstance(); //TODO: remove constructor - ~CGObjectInstance() override; - - int32_t getObjGroupIndex() const override; - int32_t getObjTypeIndex() const override; - - /// "center" tile from which the sight distance is calculated - int3 getSightCenter() const; - - PlayerColor getOwner() const override - { - return this->tempOwner; - } - void setOwner(const PlayerColor & ow); - - /** APPEARANCE ACCESSORS **/ - - int getWidth() const; //returns width of object graphic in tiles - int getHeight() const; //returns height of object graphic in tiles - bool visitableAt(int x, int y) const; //returns true if object is visitable at location (x, y) (h3m pos) - int3 visitablePos() const override; - int3 getPosition() const override; - int3 getTopVisiblePos() const; - bool blockingAt(int x, int y) const; //returns true if object is blocking location (x, y) (h3m pos) - bool coveringAt(int x, int y) const; //returns true if object covers with picture location (x, y) (h3m pos) - std::set getBlockedPos() const; //returns set of positions blocked by this object - std::set getBlockedOffsets() const; //returns set of relative positions blocked by this object - bool isVisitable() const; //returns true if object is visitable - - virtual BattleField getBattlefield() const; - - virtual bool isTile2Terrain() const { return false; } - - std::optional getAmbientSound() const; - std::optional getVisitSound() const; - std::optional getRemovalSound() const; - - /** VIRTUAL METHODS **/ - - /// Returns true if player can pass through visitable tiles of this object - virtual bool passableFor(PlayerColor color) const; - /// Range of revealed map around this object, counting from getSightCenter() - virtual int getSightRadius() const; - /// returns (x,y,0) offset to a visitable tile of object - virtual int3 getVisitableOffset() const; - /// Called mostly during map randomization to turn random object into a regular one (e.g. "Random Monster" into "Pikeman") - virtual void setType(si32 ID, si32 subID); - - /// returns text visible in status bar with specific hero/player active. - - /// Returns generic name of object, without any player-specific info - virtual std::string getObjectName() const; - - /// Returns hover name for situation when there are no selected heroes. Default = object name - virtual std::string getHoverText(PlayerColor player) const; - /// Returns hero-specific hover name, including visited/not visited info. Default = player-specific name - virtual std::string getHoverText(const CGHeroInstance * hero) const; - - /** OVERRIDES OF IObjectInterface **/ - - void initObj(CRandomGenerator & rand) override; - void onHeroVisit(const CGHeroInstance * h) const override; - /// method for synchronous update. Note: For new properties classes should override setPropertyDer instead - void setProperty(ui8 what, ui32 val) final; - - virtual void afterAddToMap(CMap * map); - virtual void afterRemoveFromMap(CMap * map); - - ///Entry point of binary (de-)serialization - template void serialize(Handler &h, const int version) - { - h & instanceName; - h & typeName; - h & subTypeName; - h & pos; - h & ID; - h & subID; - h & id; - h & tempOwner; - h & blockVisit; - h & appearance; - //definfo is handled by map serializer - } - - ///Entry point of Json (de-)serialization - void serializeJson(JsonSerializeFormat & handler); - virtual void updateFrom(const JsonNode & data); - -protected: - /// virtual method that allows synchronously update object state on server and all clients - virtual void setPropertyDer(ui8 what, ui32 val); - - /// Gives dummy bonus from this object to hero. Can be used to track visited state - void giveDummyBonus(const ObjectInstanceID & heroID, BonusDuration::Type duration = BonusDuration::ONE_DAY) const; - - ///Serialize object-type specific options - virtual void serializeJsonOptions(JsonSerializeFormat & handler); - - void serializeJsonOwner(JsonSerializeFormat & handler); -}; +class int3; /// function object which can be used to find an object with an specific sub ID class CGObjectInstanceBySubIdFinder diff --git a/lib/mapObjects/CQuest.cpp b/lib/mapObjects/CQuest.cpp index a39d116c3..2232cfd67 100644 --- a/lib/mapObjects/CQuest.cpp +++ b/lib/mapObjects/CQuest.cpp @@ -17,10 +17,10 @@ #include "../CSoundBase.h" #include "../CGeneralTextHandler.h" #include "../CHeroHandler.h" -#include "CObjectClassesHandler.h" #include "MiscObjects.h" #include "../IGameCallback.h" #include "../CGameState.h" +#include "../mapObjectConstructors/CObjectClassesHandler.h" #include "../serializer/JsonSerializeFormat.h" #include "../CModHandler.h" #include "../GameConstants.h" diff --git a/lib/mapObjects/CQuest.h b/lib/mapObjects/CQuest.h index f888d1a63..ee115d082 100644 --- a/lib/mapObjects/CQuest.h +++ b/lib/mapObjects/CQuest.h @@ -9,18 +9,13 @@ */ #pragma once -#include "CObjectHandler.h" #include "CArmedInstance.h" - #include "../ResourceSet.h" -#include "../CCreatureSet.h" -#include "../NetPacksBase.h" VCMI_LIB_NAMESPACE_BEGIN class CGCreature; - class DLL_LINKAGE CQuest final { mutable std::unordered_map artifactsRequirements; // artifact ID -> required count diff --git a/lib/mapObjects/CRewardableObject.cpp b/lib/mapObjects/CRewardableObject.cpp index 4f4b028ef..e5b008951 100644 --- a/lib/mapObjects/CRewardableObject.cpp +++ b/lib/mapObjects/CRewardableObject.cpp @@ -10,12 +10,13 @@ #include "StdInc.h" #include "CRewardableObject.h" -#include "../mapObjects/CObjectClassesHandler.h" #include "../CGameState.h" #include "../CGeneralTextHandler.h" #include "../CPlayerState.h" #include "../IGameCallback.h" #include "../NetPacks.h" +#include "../mapObjectConstructors/AObjectTypeHandler.h" +#include "../mapObjectConstructors/CObjectClassesHandler.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/mapObjects/IMarket.cpp b/lib/mapObjects/IMarket.cpp new file mode 100644 index 000000000..4832987fe --- /dev/null +++ b/lib/mapObjects/IMarket.cpp @@ -0,0 +1,175 @@ +/* + * IMarket.cpp, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +#include "StdInc.h" +#include "IMarket.h" + +#include "CArtHandler.h" +#include "CCreatureHandler.h" +#include "CGObjectInstance.h" +#include "CObjectHandler.h" + +#include "../VCMI_Lib.h" + +bool IMarket::getOffer(int id1, int id2, int &val1, int &val2, EMarketMode::EMarketMode mode) const +{ + switch(mode) + { + case EMarketMode::RESOURCE_RESOURCE: + { + double effectiveness = std::min((getMarketEfficiency() + 1.0) / 20.0, 0.5); + + double r = VLC->objh->resVals[id1]; //value of given resource + double g = VLC->objh->resVals[id2] / effectiveness; //value of wanted resource + + if(r>g) //if given resource is more expensive than wanted + { + val2 = static_cast(ceil(r / g)); + val1 = 1; + } + else //if wanted resource is more expensive + { + val1 = static_cast((g / r) + 0.5); + val2 = 1; + } + } + break; + case EMarketMode::CREATURE_RESOURCE: + { + const double effectivenessArray[] = {0.0, 0.3, 0.45, 0.50, 0.65, 0.7, 0.85, 0.9, 1.0}; + double effectiveness = effectivenessArray[std::min(getMarketEfficiency(), 8)]; + + double r = VLC->creatures()->getByIndex(id1)->getRecruitCost(EGameResID::GOLD); //value of given creature in gold + double g = VLC->objh->resVals[id2] / effectiveness; //value of wanted resource + + if(r>g) //if given resource is more expensive than wanted + { + val2 = static_cast(ceil(r / g)); + val1 = 1; + } + else //if wanted resource is more expensive + { + val1 = static_cast((g / r) + 0.5); + val2 = 1; + } + } + break; + case EMarketMode::RESOURCE_PLAYER: + val1 = 1; + val2 = 1; + break; + case EMarketMode::RESOURCE_ARTIFACT: + { + double effectiveness = std::min((getMarketEfficiency() + 3.0) / 20.0, 0.6); + double r = VLC->objh->resVals[id1]; //value of offered resource + double g = VLC->artifacts()->getByIndex(id2)->getPrice() / effectiveness; //value of bought artifact in gold + + if(id1 != 6) //non-gold prices are doubled + r /= 2; + + val1 = std::max(1, static_cast((g / r) + 0.5)); //don't sell arts for less than 1 resource + val2 = 1; + } + break; + case EMarketMode::ARTIFACT_RESOURCE: + { + double effectiveness = std::min((getMarketEfficiency() + 3.0) / 20.0, 0.6); + double r = VLC->artifacts()->getByIndex(id1)->getPrice() * effectiveness; + double g = VLC->objh->resVals[id2]; + +// if(id2 != 6) //non-gold prices are doubled +// r /= 2; + + val1 = 1; + val2 = std::max(1, static_cast((r / g) + 0.5)); //at least one resource is given in return + } + break; + case EMarketMode::CREATURE_EXP: + { + val1 = 1; + val2 = (VLC->creh->objects[id1]->getAIValue() / 40) * 5; + } + break; + case EMarketMode::ARTIFACT_EXP: + { + val1 = 1; + + int givenClass = VLC->arth->objects[id1]->getArtClassSerial(); + if(givenClass < 0 || givenClass > 3) + { + val2 = 0; + return false; + } + + static constexpr int expPerClass[] = {1000, 1500, 3000, 6000}; + val2 = expPerClass[givenClass]; + } + break; + default: + assert(0); + return false; + } + + return true; +} + +bool IMarket::allowsTrade(EMarketMode::EMarketMode mode) const +{ + return false; +} + +int IMarket::availableUnits(EMarketMode::EMarketMode mode, int marketItemSerial) const +{ + switch(mode) + { + case EMarketMode::RESOURCE_RESOURCE: + case EMarketMode::ARTIFACT_RESOURCE: + case EMarketMode::CREATURE_RESOURCE: + return -1; + default: + return 1; + } +} + +std::vector IMarket::availableItemsIds(EMarketMode::EMarketMode mode) const +{ + std::vector ret; + switch(mode) + { + case EMarketMode::RESOURCE_RESOURCE: + case EMarketMode::ARTIFACT_RESOURCE: + case EMarketMode::CREATURE_RESOURCE: + for (int i = 0; i < 7; i++) + ret.push_back(i); + } + return ret; +} + +const IMarket * IMarket::castFrom(const CGObjectInstance *obj, bool verbose) +{ + auto * imarket = dynamic_cast(obj); + if(verbose && !imarket) + logGlobal->error("Cannot cast to IMarket object type %s", obj->typeName); + return imarket; +} + +IMarket::IMarket() +{ +} + +std::vector IMarket::availableModes() const +{ + std::vector ret; + for (int i = 0; i < EMarketMode::MARTKET_AFTER_LAST_PLACEHOLDER; i++) + if(allowsTrade(static_cast(i))) + ret.push_back(static_cast(i)); + + return ret; +} diff --git a/lib/mapObjects/IMarket.h b/lib/mapObjects/IMarket.h new file mode 100644 index 000000000..7e9d79359 --- /dev/null +++ b/lib/mapObjects/IMarket.h @@ -0,0 +1,35 @@ +/* + * IMarket.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#pragma once + +#include "../GameConstants.h" + +VCMI_LIB_NAMESPACE_BEGIN + +class CGObjectInstance; + +class DLL_LINKAGE IMarket +{ +public: + IMarket(); + virtual ~IMarket() {} + + virtual int getMarketEfficiency() const = 0; + virtual bool allowsTrade(EMarketMode::EMarketMode mode) const; + virtual int availableUnits(EMarketMode::EMarketMode mode, int marketItemSerial) const; //-1 if unlimited + virtual std::vector availableItemsIds(EMarketMode::EMarketMode mode) const; + + bool getOffer(int id1, int id2, int &val1, int &val2, EMarketMode::EMarketMode mode) const; //val1 - how many units of id1 player has to give to receive val2 units + std::vector availableModes() const; + + static const IMarket *castFrom(const CGObjectInstance *obj, bool verbose = true); +}; + +VCMI_LIB_NAMESPACE_END diff --git a/lib/mapObjects/IObjectInterface.cpp b/lib/mapObjects/IObjectInterface.cpp new file mode 100644 index 000000000..5be5edf33 --- /dev/null +++ b/lib/mapObjects/IObjectInterface.cpp @@ -0,0 +1,188 @@ +/* + * IObjectInterface.cpp, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +#include "StdInc.h" +#include "IObjectInterface.h" + +#include "CGTownInstance.h" +#include "MiscObjects.h" + +#include "../NetPacks.h" +#include "../IGameCallback.h" +#include "../TerrainHandler.h" + +VCMI_LIB_NAMESPACE_BEGIN + +IGameCallback * IObjectInterface::cb = nullptr; + +///helpers +void IObjectInterface::openWindow(const EOpenWindowMode type, const int id1, const int id2) +{ + OpenWindow ow; + ow.window = type; + ow.id1 = id1; + ow.id2 = id2; + IObjectInterface::cb->sendAndApply(&ow); +} + +void IObjectInterface::showInfoDialog(const ui32 txtID, const ui16 soundID, EInfoWindowMode mode) const +{ + InfoWindow iw; + iw.soundID = soundID; + iw.player = getOwner(); + iw.type = mode; + iw.text.addTxt(MetaString::ADVOB_TXT,txtID); + IObjectInterface::cb->sendAndApply(&iw); +} + +///IObjectInterface +void IObjectInterface::onHeroVisit(const CGHeroInstance * h) const +{} + +void IObjectInterface::onHeroLeave(const CGHeroInstance * h) const +{} + +void IObjectInterface::newTurn(CRandomGenerator & rand) const +{} + +void IObjectInterface::initObj(CRandomGenerator & rand) +{} + +void IObjectInterface::setProperty( ui8 what, ui32 val ) +{} + +bool IObjectInterface::wasVisited (PlayerColor player) const +{ + return false; +} +bool IObjectInterface::wasVisited (const CGHeroInstance * h) const +{ + return false; +} + +void IObjectInterface::postInit() +{} + +void IObjectInterface::preInit() +{} + +void IObjectInterface::battleFinished(const CGHeroInstance *hero, const BattleResult &result) const +{} + +void IObjectInterface::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const +{} + +void IObjectInterface::garrisonDialogClosed(const CGHeroInstance *hero) const +{} + +void IObjectInterface::heroLevelUpDone(const CGHeroInstance *hero) const +{} + +int3 IBoatGenerator::bestLocation() const +{ + std::vector offsets; + getOutOffsets(offsets); + + for (auto & offset : offsets) + { + if(const TerrainTile *tile = IObjectInterface::cb->getTile(o->pos + offset, false)) //tile is in the map + { + if(tile->terType->isWater() && (!tile->blocked || tile->blockingObjects.front()->ID == Obj::BOAT)) //and is water and is not blocked or is blocked by boat + return o->pos + offset; + } + } + return int3 (-1,-1,-1); +} + +IBoatGenerator::EGeneratorState IBoatGenerator::shipyardStatus() const +{ + int3 tile = bestLocation(); + const TerrainTile *t = IObjectInterface::cb->getTile(tile); + if(!t) + return TILE_BLOCKED; //no available water + else if(t->blockingObjects.empty()) + return GOOD; //OK + else if(t->blockingObjects.front()->ID == Obj::BOAT) + return BOAT_ALREADY_BUILT; //blocked with boat + else + return TILE_BLOCKED; //blocked +} + +BoatId IBoatGenerator::getBoatType() const +{ + //We make good ships by default + return EBoatId::BOAT_GOOD; +} + + +IBoatGenerator::IBoatGenerator(const CGObjectInstance *O) +: o(O) +{ +} + +void IBoatGenerator::getProblemText(MetaString &out, const CGHeroInstance *visitor) const +{ + switch(shipyardStatus()) + { + case BOAT_ALREADY_BUILT: + out.addTxt(MetaString::GENERAL_TXT, 51); + break; + case TILE_BLOCKED: + if(visitor) + { + out.addTxt(MetaString::GENERAL_TXT, 134); + out.addReplacement(visitor->getNameTranslated()); + } + else + out.addTxt(MetaString::ADVOB_TXT, 189); + break; + case NO_WATER: + logGlobal->error("Shipyard without water! %s \t %d", o->pos.toString(), o->id.getNum()); + return; + } +} + +void IShipyard::getBoatCost(TResources & cost) const +{ + cost[EGameResID::WOOD] = 10; + cost[EGameResID::GOLD] = 1000; +} + +IShipyard::IShipyard(const CGObjectInstance *O) + : IBoatGenerator(O) +{ +} + +IShipyard * IShipyard::castFrom( CGObjectInstance *obj ) +{ + if(!obj) + return nullptr; + + if(obj->ID == Obj::TOWN) + { + return dynamic_cast(obj); + } + else if(obj->ID == Obj::SHIPYARD) + { + return dynamic_cast(obj); + } + else + { + return nullptr; + } +} + +const IShipyard * IShipyard::castFrom( const CGObjectInstance *obj ) +{ + return castFrom(const_cast(obj)); +} + + +VCMI_LIB_NAMESPACE_END diff --git a/lib/mapObjects/IObjectInterface.h b/lib/mapObjects/IObjectInterface.h new file mode 100644 index 000000000..05175761a --- /dev/null +++ b/lib/mapObjects/IObjectInterface.h @@ -0,0 +1,107 @@ +/* + * IObjectInterface.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#pragma once + +#include "../NetPacksBase.h" + +VCMI_LIB_NAMESPACE_BEGIN + +struct BattleResult; +class CGObjectInstance; +class CRandomGenerator; +class IGameCallback; +class ResourceSet; +class int3; + +class DLL_LINKAGE IObjectInterface +{ +public: + static IGameCallback *cb; + + virtual ~IObjectInterface() = default; + + virtual int32_t getObjGroupIndex() const = 0; + virtual int32_t getObjTypeIndex() const = 0; + + virtual PlayerColor getOwner() const = 0; + virtual int3 visitablePos() const = 0; + virtual int3 getPosition() const = 0; + + virtual void onHeroVisit(const CGHeroInstance * h) const; + virtual void onHeroLeave(const CGHeroInstance * h) const; + virtual void newTurn(CRandomGenerator & rand) const; + virtual void initObj(CRandomGenerator & rand); //synchr + virtual void setProperty(ui8 what, ui32 val);//synchr + + //Called when queries created DURING HERO VISIT are resolved + //First parameter is always hero that visited object and triggered the query + virtual void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const; + virtual void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const; + virtual void garrisonDialogClosed(const CGHeroInstance *hero) const; + virtual void heroLevelUpDone(const CGHeroInstance *hero) const; + + //unified helper to show info dialog for object owner + virtual void showInfoDialog(const ui32 txtID, const ui16 soundID = 0, EInfoWindowMode mode = EInfoWindowMode::AUTO) const; + + //unified helper to show a specific window + static void openWindow(const EOpenWindowMode type, const int id1, const int id2 = -1); + + //unified interface, AI helpers + virtual bool wasVisited (PlayerColor player) const; + virtual bool wasVisited (const CGHeroInstance * h) const; + + static void preInit(); //called before objs receive their initObj + static void postInit();//called after objs receive their initObj + + template void serialize(Handler &h, const int version) + { + logGlobal->error("IObjectInterface serialized, unexpected, should not happen!"); + } +}; + +class DLL_LINKAGE IBoatGenerator +{ +public: + const CGObjectInstance *o; + + IBoatGenerator(const CGObjectInstance *O); + virtual ~IBoatGenerator() = default; + + virtual BoatId getBoatType() const; //0 - evil (if a ship can be evil...?), 1 - good, 2 - neutral + virtual void getOutOffsets(std::vector &offsets) const =0; //offsets to obj pos when we boat can be placed + int3 bestLocation() const; //returns location when the boat should be placed + + enum EGeneratorState {GOOD, BOAT_ALREADY_BUILT, TILE_BLOCKED, NO_WATER}; + EGeneratorState shipyardStatus() const; //0 - can buid, 1 - there is already a boat at dest tile, 2 - dest tile is blocked, 3 - no water + void getProblemText(MetaString &out, const CGHeroInstance *visitor = nullptr) const; + + template void serialize(Handler &h, const int version) + { + h & o; + } +}; + +class DLL_LINKAGE IShipyard : public IBoatGenerator +{ +public: + IShipyard(const CGObjectInstance *O); + + virtual void getBoatCost(ResourceSet & cost) const; + + static const IShipyard *castFrom(const CGObjectInstance *obj); + static IShipyard *castFrom(CGObjectInstance *obj); + + template void serialize(Handler &h, const int version) + { + h & static_cast(*this); + } +}; + +VCMI_LIB_NAMESPACE_END diff --git a/lib/mapObjects/MiscObjects.cpp b/lib/mapObjects/MiscObjects.cpp index 95ed54364..f5572f364 100644 --- a/lib/mapObjects/MiscObjects.cpp +++ b/lib/mapObjects/MiscObjects.cpp @@ -19,7 +19,6 @@ #include "../CModHandler.h" #include "../CHeroHandler.h" #include "../CSkillHandler.h" -#include "CObjectClassesHandler.h" #include "../spells/CSpellHandler.h" #include "../IGameCallback.h" #include "../CGameState.h" diff --git a/lib/mapObjects/MiscObjects.h b/lib/mapObjects/MiscObjects.h index a9cac157a..4d20a7558 100644 --- a/lib/mapObjects/MiscObjects.h +++ b/lib/mapObjects/MiscObjects.h @@ -9,7 +9,6 @@ */ #pragma once -#include "CObjectHandler.h" #include "CArmedInstance.h" #include "../ResourceSet.h" @@ -17,6 +16,10 @@ VCMI_LIB_NAMESPACE_BEGIN class CMap; +// This one teleport-specific, but has to be available everywhere in callbacks and netpacks +// For now it's will be there till teleports code refactored and moved into own file +using TTeleportExitsList = std::vector>; + /// Legacy class, use CRewardableObject instead class DLL_LINKAGE CTeamVisited: public CGObjectInstance { diff --git a/lib/mapObjects/ObjectTemplate.cpp b/lib/mapObjects/ObjectTemplate.cpp index cf36e66a6..83bfd2b26 100644 --- a/lib/mapObjects/ObjectTemplate.cpp +++ b/lib/mapObjects/ObjectTemplate.cpp @@ -8,7 +8,7 @@ * */ #include "StdInc.h" -#include "CObjectClassesHandler.h" +#include "ObjectTemplate.h" #include "../filesystem/Filesystem.h" #include "../filesystem/CBinaryReader.h" @@ -16,12 +16,11 @@ #include "../GameConstants.h" #include "../StringConstants.h" #include "../CGeneralTextHandler.h" -#include "CObjectHandler.h" #include "../CModHandler.h" #include "../JsonNode.h" #include "../TerrainHandler.h" -#include "CRewardableConstructor.h" +#include "../mapObjectConstructors/CRewardableConstructor.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/mapping/CMap.cpp b/lib/mapping/CMap.cpp index b9554ebab..09eb206f0 100644 --- a/lib/mapping/CMap.cpp +++ b/lib/mapping/CMap.cpp @@ -18,8 +18,8 @@ #include "../RiverHandler.h" #include "../RoadHandler.h" #include "../TerrainHandler.h" -#include "../mapObjects/CObjectClassesHandler.h" #include "../mapObjects/CGHeroInstance.h" +#include "../mapObjects/ObjectTemplate.h" #include "../CGeneralTextHandler.h" #include "../spells/CSpellHandler.h" #include "../CSkillHandler.h" diff --git a/lib/mapping/CMapEditManager.cpp b/lib/mapping/CMapEditManager.cpp index 05a684881..fcc4cdaf9 100644 --- a/lib/mapping/CMapEditManager.cpp +++ b/lib/mapping/CMapEditManager.cpp @@ -10,8 +10,6 @@ #include "StdInc.h" #include "CMapEditManager.h" - -#include "../mapObjects/CObjectClassesHandler.h" #include "../mapObjects/CGHeroInstance.h" #include "../VCMI_Lib.h" #include "CDrawRoadsOperation.h" diff --git a/lib/mapping/MapFormatH3M.cpp b/lib/mapping/MapFormatH3M.cpp index d118ff945..f9710e3c2 100644 --- a/lib/mapping/MapFormatH3M.cpp +++ b/lib/mapping/MapFormatH3M.cpp @@ -29,8 +29,10 @@ #include "../VCMI_Lib.h" #include "../filesystem/CBinaryReader.h" #include "../filesystem/Filesystem.h" -#include "../mapObjects/CObjectClassesHandler.h" +#include "../mapObjectConstructors/AObjectTypeHandler.h" +#include "../mapObjectConstructors/CObjectClassesHandler.h" #include "../mapObjects/MapObjects.h" +#include "../mapObjects/ObjectTemplate.h" #include "../spells/CSpellHandler.h" #include diff --git a/lib/mapping/MapFormatJson.cpp b/lib/mapping/MapFormatJson.cpp index 67d3d6549..22b352862 100644 --- a/lib/mapping/MapFormatJson.cpp +++ b/lib/mapping/MapFormatJson.cpp @@ -23,9 +23,9 @@ #include "../RiverHandler.h" #include "../RoadHandler.h" #include "../TerrainHandler.h" +#include "../mapObjectConstructors/AObjectTypeHandler.h" +#include "../mapObjectConstructors/CObjectClassesHandler.h" #include "../mapObjects/ObjectTemplate.h" -#include "../mapObjects/CObjectHandler.h" -#include "../mapObjects/CObjectClassesHandler.h" #include "../mapObjects/CGHeroInstance.h" #include "../mapObjects/CGTownInstance.h" #include "../spells/CSpellHandler.h" diff --git a/lib/mapping/MapIdentifiersH3M.cpp b/lib/mapping/MapIdentifiersH3M.cpp index 6e6c1b6f0..7cc8aae84 100644 --- a/lib/mapping/MapIdentifiersH3M.cpp +++ b/lib/mapping/MapIdentifiersH3M.cpp @@ -15,8 +15,10 @@ #include "../VCMI_Lib.h" #include "../CModHandler.h" #include "../CTownHandler.h" -#include "../mapObjects/CObjectClassesHandler.h" #include "../filesystem/Filesystem.h" +#include "../mapObjectConstructors/AObjectTypeHandler.h" +#include "../mapObjectConstructors/CObjectClassesHandler.h" +#include "../mapObjects/ObjectTemplate.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/mapping/ObstacleProxy.cpp b/lib/mapping/ObstacleProxy.cpp index bf5e517f0..d6a30de33 100644 --- a/lib/mapping/ObstacleProxy.cpp +++ b/lib/mapping/ObstacleProxy.cpp @@ -10,9 +10,10 @@ #include "StdInc.h" #include "ObstacleProxy.h" -#include "../mapObjects/CObjectClassesHandler.h" -#include "../mapObjects/CObjectHandler.h" #include "../mapping/CMap.h" +#include "../mapObjectConstructors/AObjectTypeHandler.h" +#include "../mapObjectConstructors/CObjectClassesHandler.h" +#include "../mapObjects/ObjectTemplate.h" VCMI_LIB_NAMESPACE_BEGIN @@ -213,4 +214,4 @@ void EditorObstaclePlacer::placeObstacles(CRandomGenerator & rand) finalInsertion(map->getEditManager(), obstacles); } -VCMI_LIB_NAMESPACE_END \ No newline at end of file +VCMI_LIB_NAMESPACE_END diff --git a/lib/registerTypes/RegisterTypes.h b/lib/registerTypes/RegisterTypes.h index f1d1c50fb..741cb0b6f 100644 --- a/lib/registerTypes/RegisterTypes.h +++ b/lib/registerTypes/RegisterTypes.h @@ -13,15 +13,16 @@ #include "../NetPacksLobby.h" #include "../VCMI_Lib.h" #include "../CArtHandler.h" +#include "../CCreatureSet.h" #include "../CPlayerState.h" #include "../CHeroHandler.h" #include "../CTownHandler.h" #include "../CModHandler.h" //needed? -#include "../mapObjects/CObjectClassesHandler.h" -#include "../mapObjects/CRewardableConstructor.h" -#include "../mapObjects/CommonConstructors.h" +#include "../mapObjectConstructors/CRewardableConstructor.h" +#include "../mapObjectConstructors/CommonConstructors.h" #include "../mapObjects/MapObjects.h" #include "../mapObjects/CGTownBuilding.h" +#include "../mapObjects/ObjectTemplate.h" #include "../battle/CObstacleInstance.h" #include "../bonuses/CBonusSystemNode.h" #include "../bonuses/Limiters.h" diff --git a/lib/registerTypes/TypesClientPacks1.cpp b/lib/registerTypes/TypesClientPacks1.cpp index ff702295c..b2d85dd67 100644 --- a/lib/registerTypes/TypesClientPacks1.cpp +++ b/lib/registerTypes/TypesClientPacks1.cpp @@ -22,7 +22,6 @@ #include "../CTownHandler.h" #include "../mapping/CCampaignHandler.h" #include "../NetPacks.h" -#include "../mapObjects/CObjectClassesHandler.h" #include "../serializer/BinaryDeserializer.h" #include "../serializer/BinarySerializer.h" diff --git a/lib/registerTypes/TypesClientPacks2.cpp b/lib/registerTypes/TypesClientPacks2.cpp index a28f9f58d..c02569cc2 100644 --- a/lib/registerTypes/TypesClientPacks2.cpp +++ b/lib/registerTypes/TypesClientPacks2.cpp @@ -24,7 +24,6 @@ #include "../CTownHandler.h" #include "../mapping/CCampaignHandler.h" #include "../NetPacks.h" -#include "../mapObjects/CObjectClassesHandler.h" #include "../serializer/BinaryDeserializer.h" #include "../serializer/BinarySerializer.h" diff --git a/lib/registerTypes/TypesLobbyPacks.cpp b/lib/registerTypes/TypesLobbyPacks.cpp index 106529f37..27f05aa56 100644 --- a/lib/registerTypes/TypesLobbyPacks.cpp +++ b/lib/registerTypes/TypesLobbyPacks.cpp @@ -27,7 +27,6 @@ #include "../TerrainHandler.h" #include "../mapping/CCampaignHandler.h" #include "../NetPacks.h" -#include "../mapObjects/CObjectClassesHandler.h" #include "../rmg/CMapGenOptions.h" #include "../serializer/BinaryDeserializer.h" diff --git a/lib/registerTypes/TypesMapObjects1.cpp b/lib/registerTypes/TypesMapObjects1.cpp index 53e40ceaa..89250ef90 100644 --- a/lib/registerTypes/TypesMapObjects1.cpp +++ b/lib/registerTypes/TypesMapObjects1.cpp @@ -22,7 +22,6 @@ #include "../CTownHandler.h" #include "../mapping/CCampaignHandler.h" #include "../NetPacks.h" -#include "../mapObjects/CObjectClassesHandler.h" #include "../serializer/BinaryDeserializer.h" #include "../serializer/BinarySerializer.h" diff --git a/lib/registerTypes/TypesMapObjects2.cpp b/lib/registerTypes/TypesMapObjects2.cpp index 694790502..c3318a716 100644 --- a/lib/registerTypes/TypesMapObjects2.cpp +++ b/lib/registerTypes/TypesMapObjects2.cpp @@ -24,7 +24,6 @@ #include "../CTownHandler.h" #include "../mapping/CCampaignHandler.h" #include "../NetPacks.h" -#include "../mapObjects/CObjectClassesHandler.h" #include "../serializer/BinaryDeserializer.h" #include "../serializer/BinarySerializer.h" diff --git a/lib/registerTypes/TypesMapObjects3.cpp b/lib/registerTypes/TypesMapObjects3.cpp index bb94179d6..238cf75c7 100644 --- a/lib/registerTypes/TypesMapObjects3.cpp +++ b/lib/registerTypes/TypesMapObjects3.cpp @@ -22,7 +22,6 @@ #include "../CTownHandler.h" #include "../mapping/CCampaignHandler.h" #include "../NetPacks.h" -#include "../mapObjects/CObjectClassesHandler.h" #include "../serializer/BinaryDeserializer.h" #include "../serializer/BinarySerializer.h" diff --git a/lib/registerTypes/TypesServerPacks.cpp b/lib/registerTypes/TypesServerPacks.cpp index 86494f7d5..cdd06e2ce 100644 --- a/lib/registerTypes/TypesServerPacks.cpp +++ b/lib/registerTypes/TypesServerPacks.cpp @@ -22,7 +22,6 @@ #include "../CTownHandler.h" #include "../mapping/CCampaignHandler.h" #include "../NetPacks.h" -#include "../mapObjects/CObjectClassesHandler.h" #include "../serializer/BinaryDeserializer.h" #include "../serializer/BinarySerializer.h" diff --git a/lib/rewardable/Configuration.h b/lib/rewardable/Configuration.h index 5d00ad4ca..cc65dda42 100644 --- a/lib/rewardable/Configuration.h +++ b/lib/rewardable/Configuration.h @@ -12,6 +12,7 @@ #include "Limiter.h" #include "Reward.h" +#include "NetPacksBase.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/rewardable/Info.cpp b/lib/rewardable/Info.cpp index 798b2e012..68fced7d7 100644 --- a/lib/rewardable/Info.cpp +++ b/lib/rewardable/Info.cpp @@ -14,15 +14,18 @@ #include "Reward.h" #include "Configuration.h" +#include "../CCreatureSet.h" #include "../CRandomGenerator.h" #include "../StringConstants.h" #include "../CCreatureHandler.h" #include "../CModHandler.h" +#include "../NetPacksBase.h" #include "../JsonRandom.h" #include "../IGameCallback.h" #include "../CGeneralTextHandler.h" #include "../JsonNode.h" #include "../IGameCallback.h" +#include "../mapObjects/IObjectInterface.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/rewardable/Info.h b/lib/rewardable/Info.h index c9cca1ca7..ff0d7fea5 100644 --- a/lib/rewardable/Info.h +++ b/lib/rewardable/Info.h @@ -11,7 +11,7 @@ #pragma once #include "../JsonNode.h" -#include "../mapObjects/CObjectClassesHandler.h" +#include "../mapObjectConstructors/IObjectInfo.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/rewardable/Interface.h b/lib/rewardable/Interface.h index 2f8298699..74b798d69 100644 --- a/lib/rewardable/Interface.h +++ b/lib/rewardable/Interface.h @@ -10,7 +10,6 @@ #pragma once -#include "../mapObjects/CObjectHandler.h" #include "../CCreatureSet.h" #include "../ResourceSet.h" #include "../spells/ExternalCaster.h" @@ -18,6 +17,8 @@ VCMI_LIB_NAMESPACE_BEGIN +class IGameCallback; + namespace Rewardable { diff --git a/lib/rewardable/Limiter.cpp b/lib/rewardable/Limiter.cpp index cbc101efc..4f25e0cb6 100644 --- a/lib/rewardable/Limiter.cpp +++ b/lib/rewardable/Limiter.cpp @@ -10,12 +10,27 @@ #include "StdInc.h" #include "Limiter.h" + #include "../IGameCallback.h" #include "../CGameStateFwd.h" #include "../CPlayerState.h" +#include "../mapObjects/CGHeroInstance.h" VCMI_LIB_NAMESPACE_BEGIN +Rewardable::Limiter::Limiter() + : dayOfWeek(0) + , daysPassed(0) + , heroExperience(0) + , heroLevel(0) + , manaPercentage(0) + , manaPoints(0) + , primary(GameConstants::PRIMARY_SKILLS, 0) +{ +} + +Rewardable::Limiter::~Limiter() = default; + bool Rewardable::Limiter::heroAllowed(const CGHeroInstance * hero) const { if(dayOfWeek != 0) diff --git a/lib/rewardable/Limiter.h b/lib/rewardable/Limiter.h index 46d40a762..a443d1e2c 100644 --- a/lib/rewardable/Limiter.h +++ b/lib/rewardable/Limiter.h @@ -10,10 +10,14 @@ #pragma once -#include "../mapObjects/CGHeroInstance.h" +#include "../GameConstants.h" +#include "../ResourceSet.h" VCMI_LIB_NAMESPACE_BEGIN +class CGHeroInstance; +class CStackBasicDescriptor; + namespace Rewardable { struct Limiter; @@ -66,15 +70,8 @@ struct DLL_LINKAGE Limiter /// sub-limiters, none should pass for this limiter to pass LimitersList noneOf; - Limiter(): - dayOfWeek(0), - daysPassed(0), - heroExperience(0), - heroLevel(0), - manaPercentage(0), - manaPoints(0), - primary(GameConstants::PRIMARY_SKILLS, 0) - {} + Limiter(); + ~Limiter(); bool heroAllowed(const CGHeroInstance * hero) const; diff --git a/lib/rewardable/Reward.cpp b/lib/rewardable/Reward.cpp index e3b42153d..48caa35e5 100644 --- a/lib/rewardable/Reward.cpp +++ b/lib/rewardable/Reward.cpp @@ -11,8 +11,25 @@ #include "StdInc.h" #include "Reward.h" +#include "../mapObjects/CGHeroInstance.h" + VCMI_LIB_NAMESPACE_BEGIN +Rewardable::Reward::Reward() + : heroExperience(0) + , heroLevel(0) + , manaDiff(0) + , manaPercentage(-1) + , movePoints(0) + , movePercentage(-1) + , primary(4, 0) + , removeObject(false) + , spellCast(SpellID::NONE, SecSkillLevel::NONE) +{ +} + +Rewardable::Reward::~Reward() = default; + si32 Rewardable::Reward::calculateManaPoints(const CGHeroInstance * hero) const { si32 manaScaled = hero->mana; diff --git a/lib/rewardable/Reward.h b/lib/rewardable/Reward.h index b0923e022..ff9655342 100644 --- a/lib/rewardable/Reward.h +++ b/lib/rewardable/Reward.h @@ -10,10 +10,15 @@ #pragma once -#include "../mapObjects/CGHeroInstance.h" +#include "../ResourceSet.h" VCMI_LIB_NAMESPACE_BEGIN +struct Bonus; +struct Component; +class CStackBasicDescriptor; +class CGHeroInstance; + namespace Rewardable { @@ -78,17 +83,8 @@ struct DLL_LINKAGE Reward si32 calculateManaPoints(const CGHeroInstance * h) const; - Reward() : - heroExperience(0), - heroLevel(0), - manaDiff(0), - manaPercentage(-1), - movePoints(0), - movePercentage(-1), - primary(4, 0), - removeObject(false), - spellCast(SpellID::NONE, SecSkillLevel::NONE) - {} + Reward(); + ~Reward(); template void serialize(Handler &h, const int version) { diff --git a/lib/rmg/CMapGenerator.cpp b/lib/rmg/CMapGenerator.cpp index 2dafe736b..97134a9df 100644 --- a/lib/rmg/CMapGenerator.cpp +++ b/lib/rmg/CMapGenerator.cpp @@ -14,12 +14,13 @@ #include "../mapping/MapFormat.h" #include "../VCMI_Lib.h" #include "../CGeneralTextHandler.h" +#include "../mapObjectConstructors/AObjectTypeHandler.h" +#include "../mapObjectConstructors/CObjectClassesHandler.h" #include "../mapping/CMapEditManager.h" #include "../CTownHandler.h" #include "../StringConstants.h" #include "../filesystem/Filesystem.h" #include "CZonePlacer.h" -#include "../mapObjects/CObjectClassesHandler.h" #include "TileInfo.h" #include "Zone.h" #include "Functions.h" diff --git a/lib/rmg/Functions.cpp b/lib/rmg/Functions.cpp index 747337e3a..5c59c7e1e 100644 --- a/lib/rmg/Functions.cpp +++ b/lib/rmg/Functions.cpp @@ -17,8 +17,8 @@ #include "../TerrainHandler.h" #include "../CTownHandler.h" #include "../mapping/CMap.h" -#include "../mapObjects/CommonConstructors.h" -#include "../mapObjects/MapObjects.h" //needed to resolve templates for CommonConstructors.h +#include "../mapObjectConstructors/AObjectTypeHandler.h" +#include "../mapObjectConstructors/CObjectClassesHandler.h" #include "../VCMI_Lib.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/rmg/RmgObject.cpp b/lib/rmg/RmgObject.cpp index 39da55bae..bfe775f1c 100644 --- a/lib/rmg/RmgObject.cpp +++ b/lib/rmg/RmgObject.cpp @@ -11,12 +11,12 @@ #include "StdInc.h" #include "RmgObject.h" #include "RmgMap.h" -#include "../mapObjects/CObjectHandler.h" #include "../mapping/CMapEditManager.h" #include "../mapping/CMap.h" #include "../VCMI_Lib.h" -#include "../mapObjects/CommonConstructors.h" -#include "../mapObjects/MapObjects.h" //needed to resolve templates for CommonConstructors.h +#include "../mapObjectConstructors/AObjectTypeHandler.h" +#include "../mapObjectConstructors/CObjectClassesHandler.h" +#include "../mapObjects/ObjectTemplate.h" #include "Functions.h" #include "../TerrainHandler.h" diff --git a/lib/rmg/modificators/ConnectionsPlacer.cpp b/lib/rmg/modificators/ConnectionsPlacer.cpp index c18276bc0..5eef81976 100644 --- a/lib/rmg/modificators/ConnectionsPlacer.cpp +++ b/lib/rmg/modificators/ConnectionsPlacer.cpp @@ -13,8 +13,9 @@ #include "../CMapGenerator.h" #include "../RmgMap.h" #include "../../TerrainHandler.h" +#include "../../mapObjectConstructors/AObjectTypeHandler.h" +#include "../../mapObjectConstructors/CObjectClassesHandler.h" #include "../../mapping/CMapEditManager.h" -#include "../../mapObjects/CObjectClassesHandler.h" #include "../RmgObject.h" #include "ObjectManager.h" #include "../Functions.h" diff --git a/lib/rmg/modificators/MinePlacer.cpp b/lib/rmg/modificators/MinePlacer.cpp index dde5b9b46..758028f6c 100644 --- a/lib/rmg/modificators/MinePlacer.cpp +++ b/lib/rmg/modificators/MinePlacer.cpp @@ -10,8 +10,9 @@ #include "ConnectionsPlacer.h" #include "../CMapGenerator.h" #include "../RmgMap.h" +#include "../../mapObjectConstructors/AObjectTypeHandler.h" +#include "../../mapObjectConstructors/CObjectClassesHandler.h" #include "../../mapping/CMapEditManager.h" -#include "../../mapObjects/CObjectClassesHandler.h" #include "../RmgPath.h" #include "../RmgObject.h" #include "ObjectManager.h" diff --git a/lib/rmg/modificators/ObjectDistributor.cpp b/lib/rmg/modificators/ObjectDistributor.cpp index 7637007b1..0c3b0a356 100644 --- a/lib/rmg/modificators/ObjectDistributor.cpp +++ b/lib/rmg/modificators/ObjectDistributor.cpp @@ -18,7 +18,8 @@ #include "QuestArtifactPlacer.h" #include "TownPlacer.h" #include "TerrainPainter.h" -#include "../../mapObjects/CObjectClassesHandler.h" +#include "../../mapObjectConstructors/AObjectTypeHandler.h" +#include "../../mapObjectConstructors/CObjectClassesHandler.h" #include "../../mapObjects/MapObjects.h" #include "../Functions.h" #include "../RmgObject.h" @@ -168,4 +169,4 @@ void ObjectDistributor::distributePrisons() } } -VCMI_LIB_NAMESPACE_END \ No newline at end of file +VCMI_LIB_NAMESPACE_END diff --git a/lib/rmg/modificators/ObjectManager.cpp b/lib/rmg/modificators/ObjectManager.cpp index 87d2726ba..db2ffe5a4 100644 --- a/lib/rmg/modificators/ObjectManager.cpp +++ b/lib/rmg/modificators/ObjectManager.cpp @@ -21,8 +21,8 @@ #include "MinePlacer.h" #include "QuestArtifactPlacer.h" #include "../../CCreatureHandler.h" -#include "../../mapObjects/CommonConstructors.h" -#include "../../mapObjects/MapObjects.h" //needed to resolve templates for CommonConstructors.h +#include "../../mapObjectConstructors/AObjectTypeHandler.h" +#include "../../mapObjectConstructors/CObjectClassesHandler.h" #include "../../mapping/CMap.h" #include "../../mapping/CMapEditManager.h" #include "../Functions.h" diff --git a/lib/rmg/modificators/QuestArtifactPlacer.cpp b/lib/rmg/modificators/QuestArtifactPlacer.cpp index 4c654b1a5..7640474f3 100644 --- a/lib/rmg/modificators/QuestArtifactPlacer.cpp +++ b/lib/rmg/modificators/QuestArtifactPlacer.cpp @@ -15,8 +15,8 @@ #include "TreasurePlacer.h" #include "../CZonePlacer.h" #include "../../VCMI_Lib.h" -#include "../../mapObjects/CObjectHandler.h" -#include "../../mapObjects/CommonConstructors.h" +#include "../../mapObjectConstructors/AObjectTypeHandler.h" +#include "../../mapObjectConstructors/CObjectClassesHandler.h" #include "../../mapObjects/MapObjects.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/rmg/modificators/RiverPlacer.cpp b/lib/rmg/modificators/RiverPlacer.cpp index d845a4abc..901a5ec7e 100644 --- a/lib/rmg/modificators/RiverPlacer.cpp +++ b/lib/rmg/modificators/RiverPlacer.cpp @@ -15,9 +15,11 @@ #include "../RmgMap.h" #include "../../RiverHandler.h" #include "../../TerrainHandler.h" +#include "../../mapObjectConstructors/AObjectTypeHandler.h" +#include "../../mapObjectConstructors/CObjectClassesHandler.h" +#include "../../mapObjects/ObjectTemplate.h" #include "../../mapping/CMap.h" #include "../../mapping/CMapEditManager.h" -#include "../../mapObjects/CObjectClassesHandler.h" #include "../RmgPath.h" #include "ObjectManager.h" #include "ObstaclePlacer.h" diff --git a/lib/rmg/modificators/TownPlacer.cpp b/lib/rmg/modificators/TownPlacer.cpp index 646c874b0..f4e4f6895 100644 --- a/lib/rmg/modificators/TownPlacer.cpp +++ b/lib/rmg/modificators/TownPlacer.cpp @@ -12,9 +12,10 @@ #include "TownPlacer.h" #include "../CMapGenerator.h" #include "../RmgMap.h" +#include "../../mapObjectConstructors/AObjectTypeHandler.h" +#include "../../mapObjectConstructors/CObjectClassesHandler.h" #include "../../mapping/CMap.h" #include "../../mapping/CMapEditManager.h" -#include "../../mapObjects/CObjectClassesHandler.h" #include "../../spells/CSpellHandler.h" //for choosing random spells #include "../RmgPath.h" #include "../RmgObject.h" diff --git a/lib/rmg/modificators/TreasurePlacer.cpp b/lib/rmg/modificators/TreasurePlacer.cpp index 79d1094d7..7fe22fda6 100644 --- a/lib/rmg/modificators/TreasurePlacer.cpp +++ b/lib/rmg/modificators/TreasurePlacer.cpp @@ -19,8 +19,10 @@ #include "../TileInfo.h" #include "../CZonePlacer.h" #include "QuestArtifactPlacer.h" -#include "../../mapObjects/CommonConstructors.h" -#include "../../mapObjects/MapObjects.h" //needed to resolve templates for CommonConstructors.h +#include "../../mapObjectConstructors/AObjectTypeHandler.h" +#include "../../mapObjectConstructors/CObjectClassesHandler.h" +#include "../../mapObjectConstructors/CommonConstructors.h" +#include "../../mapObjects/CGPandoraBox.h" #include "../../CCreatureHandler.h" #include "../../spells/CSpellHandler.h" //for choosing random spells #include "../../mapping/CMap.h" diff --git a/lib/rmg/modificators/WaterAdopter.cpp b/lib/rmg/modificators/WaterAdopter.cpp index 732b2557d..326c3c266 100644 --- a/lib/rmg/modificators/WaterAdopter.cpp +++ b/lib/rmg/modificators/WaterAdopter.cpp @@ -13,7 +13,6 @@ #include "../CMapGenerator.h" #include "../RmgMap.h" #include "../../mapping/CMapEditManager.h" -#include "../../mapObjects/CObjectClassesHandler.h" #include "../RmgPath.h" #include "../RmgObject.h" #include "ObjectManager.h" diff --git a/lib/rmg/modificators/WaterProxy.cpp b/lib/rmg/modificators/WaterProxy.cpp index 08b15257f..a99489077 100644 --- a/lib/rmg/modificators/WaterProxy.cpp +++ b/lib/rmg/modificators/WaterProxy.cpp @@ -13,9 +13,10 @@ #include "../CMapGenerator.h" #include "../RmgMap.h" #include "../../TerrainHandler.h" +#include "../../mapObjectConstructors/AObjectTypeHandler.h" +#include "../../mapObjectConstructors/CObjectClassesHandler.h" #include "../../mapping/CMap.h" #include "../../mapping/CMapEditManager.h" -#include "../../mapObjects/CObjectClassesHandler.h" #include "../RmgPath.h" #include "../RmgObject.h" #include "ObjectManager.h" diff --git a/lib/rmg/modificators/WaterRoutes.cpp b/lib/rmg/modificators/WaterRoutes.cpp index 4a2f0e108..8d271d67a 100644 --- a/lib/rmg/modificators/WaterRoutes.cpp +++ b/lib/rmg/modificators/WaterRoutes.cpp @@ -14,7 +14,6 @@ #include "../CMapGenerator.h" #include "../RmgMap.h" #include "../../mapping/CMapEditManager.h" -#include "../../mapObjects/CObjectClassesHandler.h" #include "../RmgPath.h" #include "../RmgObject.h" #include "ObjectManager.h" diff --git a/lib/spells/ViewSpellInt.cpp b/lib/spells/ViewSpellInt.cpp index 50d79fccb..2b8e36ec7 100644 --- a/lib/spells/ViewSpellInt.cpp +++ b/lib/spells/ViewSpellInt.cpp @@ -11,8 +11,7 @@ #include "StdInc.h" #include "ViewSpellInt.h" - -#include "../mapObjects/CObjectHandler.h" +#include "../mapObjects/CGObjectInstance.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/mapeditor/graphics.cpp b/mapeditor/graphics.cpp index 77e5e289b..ac9d9ff16 100644 --- a/mapeditor/graphics.cpp +++ b/mapeditor/graphics.cpp @@ -32,8 +32,10 @@ #include "../lib/CGameState.h" #include "../lib/JsonNode.h" #include "../lib/CStopWatch.h" -#include "../lib/mapObjects/CObjectClassesHandler.h" -#include "../lib/mapObjects/CObjectHandler.h" +#include "../lib/mapObjectConstructors/AObjectTypeHandler.h" +#include "../lib/mapObjectConstructors/CObjectClassesHandler.h" +#include "../lib/mapObjects/CGObjectInstance.h" +#include "../lib/mapObjects/ObjectTemplate.h" #include "../lib/CHeroHandler.h" Graphics * graphics = nullptr; diff --git a/mapeditor/inspector/inspector.cpp b/mapeditor/inspector/inspector.cpp index ee9599a1b..ec0787f04 100644 --- a/mapeditor/inspector/inspector.cpp +++ b/mapeditor/inspector/inspector.cpp @@ -13,7 +13,9 @@ #include "../lib/spells/CSpellHandler.h" #include "../lib/CHeroHandler.h" #include "../lib/CRandomGenerator.h" -#include "../lib/mapObjects/CObjectClassesHandler.h" +#include "../lib/mapObjectConstructors/AObjectTypeHandler.h" +#include "../lib/mapObjectConstructors/CObjectClassesHandler.h" +#include "../lib/mapObjects/ObjectTemplate.h" #include "../lib/mapping/CMap.h" #include "townbulidingswidget.h" diff --git a/mapeditor/mainwindow.cpp b/mapeditor/mainwindow.cpp index b10c51fe7..f1c4f9f5b 100644 --- a/mapeditor/mainwindow.cpp +++ b/mapeditor/mainwindow.cpp @@ -24,6 +24,9 @@ #include "../lib/CModHandler.h" #include "../lib/filesystem/Filesystem.h" #include "../lib/GameConstants.h" +#include "../lib/mapObjectConstructors/AObjectTypeHandler.h" +#include "../lib/mapObjectConstructors/CObjectClassesHandler.h" +#include "../lib/mapObjects/ObjectTemplate.h" #include "../lib/mapping/CMapService.h" #include "../lib/mapping/CMap.h" #include "../lib/mapping/CMapEditManager.h" @@ -31,7 +34,6 @@ #include "../lib/RoadHandler.h" #include "../lib/RiverHandler.h" #include "../lib/TerrainHandler.h" -#include "../lib/mapObjects/CObjectClassesHandler.h" #include "../lib/filesystem/CFilesystemLoader.h" #include "maphandler.h" diff --git a/mapeditor/mapcontroller.cpp b/mapeditor/mapcontroller.cpp index aa62d7674..fee2c3850 100644 --- a/mapeditor/mapcontroller.cpp +++ b/mapeditor/mapcontroller.cpp @@ -11,12 +11,14 @@ #include "mapcontroller.h" #include "../lib/GameConstants.h" +#include "../lib/mapObjectConstructors/AObjectTypeHandler.h" +#include "../lib/mapObjectConstructors/CObjectClassesHandler.h" +#include "../lib/mapObjects/ObjectTemplate.h" #include "../lib/mapping/CMapService.h" #include "../lib/mapping/CMap.h" #include "../lib/mapping/CMapEditManager.h" #include "../lib/mapping/ObstacleProxy.h" #include "../lib/TerrainHandler.h" -#include "../lib/mapObjects/CObjectClassesHandler.h" #include "../lib/CSkillHandler.h" #include "../lib/spells/CSpellHandler.h" #include "../lib/CHeroHandler.h" diff --git a/mapeditor/maphandler.cpp b/mapeditor/maphandler.cpp index 9ee5f86d7..17a43e0d5 100644 --- a/mapeditor/maphandler.cpp +++ b/mapeditor/maphandler.cpp @@ -17,7 +17,7 @@ #include "../lib/TerrainHandler.h" #include "../lib/mapping/CMap.h" #include "../lib/mapObjects/CGHeroInstance.h" -#include "../lib/mapObjects/CObjectClassesHandler.h" +#include "../lib/mapObjects/ObjectTemplate.h" #include "../lib/CHeroHandler.h" #include "../lib/CTownHandler.h" #include "../lib/CModHandler.h" diff --git a/mapeditor/mapview.cpp b/mapeditor/mapview.cpp index cecbdd98d..af7bffe35 100644 --- a/mapeditor/mapview.cpp +++ b/mapeditor/mapview.cpp @@ -13,9 +13,11 @@ #include "mainwindow.h" #include #include "mapcontroller.h" -#include "../lib/mapObjects/CObjectClassesHandler.h" +#include "../lib/mapObjectConstructors/AObjectTypeHandler.h" +#include "../lib/mapObjectConstructors/CObjectClassesHandler.h" #include "../lib/mapping/CMap.h" + MinimapView::MinimapView(QWidget * parent): QGraphicsView(parent) { diff --git a/mapeditor/objectbrowser.cpp b/mapeditor/objectbrowser.cpp index 68d4addf1..c86b9aecc 100644 --- a/mapeditor/objectbrowser.cpp +++ b/mapeditor/objectbrowser.cpp @@ -10,7 +10,11 @@ #include "StdInc.h" #include "objectbrowser.h" -#include "../lib/mapObjects/CObjectClassesHandler.h" + +#include "../lib/mapObjectConstructors/AObjectTypeHandler.h" +#include "../lib/mapObjectConstructors/CObjectClassesHandler.h" +#include "../lib/mapObjects/ObjectTemplate.h" +#include "../lib/VCMI_Lib.h" ObjectBrowserProxyModel::ObjectBrowserProxyModel(QObject *parent) : QSortFilterProxyModel{parent}, terrain(ETerrainId::ANY_TERRAIN)