From 9591ce1ab4879484050f73c907d2fadb7c40a38a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zieli=C5=84ski?= Date: Sat, 14 Sep 2024 08:55:28 +0200 Subject: [PATCH] Move CompoundMapObjectID to separate file --- AI/VCAI/MapObjectsEvaluator.cpp | 1 + lib/CMakeLists.txt | 1 + .../CObjectClassesHandler.h | 23 +----------- lib/mapObjects/CompoundMapObjectID.h | 37 +++++++++++++++++++ lib/mapObjects/ObjectTemplate.cpp | 5 +++ lib/mapObjects/ObjectTemplate.h | 4 +- lib/rmg/ObjectConfig.h | 2 +- lib/rmg/ObjectInfo.h | 2 +- lib/rmg/modificators/TreasurePlacer.h | 1 - 9 files changed, 50 insertions(+), 26 deletions(-) create mode 100644 lib/mapObjects/CompoundMapObjectID.h diff --git a/AI/VCAI/MapObjectsEvaluator.cpp b/AI/VCAI/MapObjectsEvaluator.cpp index 3d6382559..5536d8fd9 100644 --- a/AI/VCAI/MapObjectsEvaluator.cpp +++ b/AI/VCAI/MapObjectsEvaluator.cpp @@ -13,6 +13,7 @@ #include "../../lib/VCMI_Lib.h" #include "../../lib/CCreatureHandler.h" #include "../../lib/CHeroHandler.h" +#include "../../lib/mapObjects/CompoundMapObjectID.h" #include "../../lib/mapObjectConstructors/AObjectTypeHandler.h" #include "../../lib/mapObjects/CGHeroInstance.h" #include "../../lib/mapObjects/CGTownInstance.h" diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 28b1e0d3f..1893c7977 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -502,6 +502,7 @@ set(lib_MAIN_HEADERS mapObjects/IObjectInterface.h mapObjects/MapObjects.h mapObjects/MiscObjects.h + mapObjects/CompoundMapObjectID.h mapObjects/ObjectTemplate.h mapObjects/ObstacleSetHandler.h diff --git a/lib/mapObjectConstructors/CObjectClassesHandler.h b/lib/mapObjectConstructors/CObjectClassesHandler.h index ce94f67ae..8651f08f5 100644 --- a/lib/mapObjectConstructors/CObjectClassesHandler.h +++ b/lib/mapObjectConstructors/CObjectClassesHandler.h @@ -9,7 +9,7 @@ */ #pragma once -#include "../constants/EntityIdentifiers.h" +#include "../mapObjects/CompoundMapObjectID.h" #include "../IHandlerBase.h" #include "../json/JsonNode.h" @@ -19,27 +19,6 @@ 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; diff --git a/lib/mapObjects/CompoundMapObjectID.h b/lib/mapObjects/CompoundMapObjectID.h new file mode 100644 index 000000000..4c067548b --- /dev/null +++ b/lib/mapObjects/CompoundMapObjectID.h @@ -0,0 +1,37 @@ +/* + * CompoundMapObjectID.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 "../constants/EntityIdentifiers.h" + +VCMI_LIB_NAMESPACE_BEGIN + +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); + } +}; + +VCMI_LIB_NAMESPACE_END \ No newline at end of file diff --git a/lib/mapObjects/ObjectTemplate.cpp b/lib/mapObjects/ObjectTemplate.cpp index 9c32a7566..68c6a6178 100644 --- a/lib/mapObjects/ObjectTemplate.cpp +++ b/lib/mapObjects/ObjectTemplate.cpp @@ -508,6 +508,11 @@ bool ObjectTemplate::canBePlacedAt(TerrainId terrainID) const return vstd::contains(allowedTerrains, terrainID); } +CompoundMapObjectID ObjectTemplate::getCompoundID() const +{ + return CompoundMapObjectID(id, subid); +} + void ObjectTemplate::recalculate() { calculateWidth(); diff --git a/lib/mapObjects/ObjectTemplate.h b/lib/mapObjects/ObjectTemplate.h index a9a5daf63..584750f48 100644 --- a/lib/mapObjects/ObjectTemplate.h +++ b/lib/mapObjects/ObjectTemplate.h @@ -13,6 +13,7 @@ #include "../int3.h" #include "../filesystem/ResourcePath.h" #include "../serializer/Serializeable.h" +#include "../mapObjects/CompoundMapObjectID.h" VCMI_LIB_NAMESPACE_BEGIN @@ -47,7 +48,6 @@ public: MapObjectID id; MapObjectSubID subid; - // TODO: get compound id /// print priority, objects with higher priority will be print first, below everything else si32 printPriority; /// animation file that should be used to display object @@ -124,6 +124,8 @@ public: // Checks if object can be placed on specific terrain bool canBePlacedAt(TerrainId terrain) const; + CompoundMapObjectID getCompoundID() const; + ObjectTemplate(); void readTxt(CLegacyConfigParser & parser); diff --git a/lib/rmg/ObjectConfig.h b/lib/rmg/ObjectConfig.h index d4534ce47..998052944 100644 --- a/lib/rmg/ObjectConfig.h +++ b/lib/rmg/ObjectConfig.h @@ -10,7 +10,7 @@ #pragma once -#include "../constants/EntityIdentifiers.h" +#include "../mapObjects/CompoundMapObjectID.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/rmg/ObjectInfo.h b/lib/rmg/ObjectInfo.h index 409b768f9..843c7c9ed 100644 --- a/lib/rmg/ObjectInfo.h +++ b/lib/rmg/ObjectInfo.h @@ -11,7 +11,7 @@ #pragma once #include "../mapObjects/ObjectTemplate.h" -#include "../constants/EntityIdentifiers.h" +#include "../mapObjects/CompoundMapObjectID.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/rmg/modificators/TreasurePlacer.h b/lib/rmg/modificators/TreasurePlacer.h index c9cde768e..f82873cd1 100644 --- a/lib/rmg/modificators/TreasurePlacer.h +++ b/lib/rmg/modificators/TreasurePlacer.h @@ -21,7 +21,6 @@ class ObjectManager; class RmgMap; class CMapGenerator; class ObjectConfig; -struct CompoundMapObjectID; class TreasurePlacer: public Modificator {