浏览代码

Move CompoundMapObjectID to separate file

Tomasz Zieliński 1 年之前
父节点
当前提交
9591ce1ab4

+ 1 - 0
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"

+ 1 - 0
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
 

+ 1 - 22
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<AObjectTypeHandler>;

+ 37 - 0
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

+ 5 - 0
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();

+ 3 - 1
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);

+ 1 - 1
lib/rmg/ObjectConfig.h

@@ -10,7 +10,7 @@
 
 #pragma once
 
-#include "../constants/EntityIdentifiers.h"
+#include "../mapObjects/CompoundMapObjectID.h"
 
 VCMI_LIB_NAMESPACE_BEGIN
 

+ 1 - 1
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
 

+ 0 - 1
lib/rmg/modificators/TreasurePlacer.h

@@ -21,7 +21,6 @@ class ObjectManager;
 class RmgMap;
 class CMapGenerator;
 class ObjectConfig;
-struct CompoundMapObjectID;
 
 class TreasurePlacer: public Modificator
 {