瀏覽代碼

Move object ID struct to lib

Dydzio 7 年之前
父節點
當前提交
2c1d91e2ff

+ 0 - 1
AI/VCAI/MapObjectsEvaluator.cpp

@@ -2,7 +2,6 @@
 #include "MapObjectsEvaluator.h"
 #include "../../lib/GameConstants.h"
 #include "../../lib/VCMI_Lib.h"
-#include "../../lib/mapObjects/CObjectClassesHandler.h"
 
 MapObjectsEvaluator & MapObjectsEvaluator::getInstance()
 {

+ 1 - 24
AI/VCAI/MapObjectsEvaluator.h

@@ -8,30 +8,7 @@
 *
 */
 #pragma once
-
-struct AiMapObjectID
-{
-	int primaryID;
-	int secondaryID;
-
-	AiMapObjectID(int primID, int secID) : primaryID(primID), secondaryID(secID) {};
-};
-
-inline bool operator<(const AiMapObjectID& obj1, const AiMapObjectID& obj2)
-{
-	if(obj1.primaryID != obj2.primaryID)
-		return obj1.primaryID < obj2.primaryID;
-	else
-		return obj1.secondaryID < obj2.secondaryID;
-}
-
-inline bool operator==(const AiMapObjectID& obj1, const AiMapObjectID& obj2)
-{
-	if(obj1.primaryID == obj2.primaryID)
-		return obj1.secondaryID == obj2.secondaryID;
-
-	return false;
-}
+#include "../../lib/mapObjects/CObjectClassesHandler.h"
 
 class MapObjectsEvaluator
 {

+ 5 - 0
lib/mapObjects/CObjectClassesHandler.cpp

@@ -285,6 +285,11 @@ TObjectTypeHandler CObjectClassesHandler::getHandlerFor(std::string type, std::s
 	throw std::runtime_error("Object type handler not found");
 }
 
+TObjectTypeHandler CObjectClassesHandler::getHandlerFor(AiMapObjectID compoundIdentifier) const
+{
+	return getHandlerFor(compoundIdentifier.primaryID, compoundIdentifier.secondaryID);
+}
+
 std::set<si32> CObjectClassesHandler::knownObjects() const
 {
 	std::set<si32> ret;

+ 25 - 0
lib/mapObjects/CObjectClassesHandler.h

@@ -65,6 +65,30 @@ struct DLL_LINKAGE RandomMapInfo
 	}
 };
 
+struct DLL_LINKAGE AiMapObjectID
+{
+	si32 primaryID;
+	si32 secondaryID;
+
+	AiMapObjectID(si32 primID, si32 secID) : primaryID(primID), secondaryID(secID) {};
+
+	bool operator<(const AiMapObjectID& other)
+	{
+		if(this->primaryID != other.primaryID)
+			return this->primaryID < other.primaryID;
+		else
+			return this->secondaryID < other.secondaryID;
+	}
+
+	bool operator==(const AiMapObjectID& other)
+	{
+		if(this->primaryID == other.primaryID)
+			return this->secondaryID == other.secondaryID;
+
+		return false;
+	}
+};
+
 class DLL_LINKAGE IObjectInfo
 {
 public:
@@ -274,6 +298,7 @@ public:
 	/// returns handler for specified object (ID-based). ObjectHandler keeps ownership
 	TObjectTypeHandler getHandlerFor(si32 type, si32 subtype) const;
 	TObjectTypeHandler getHandlerFor(std::string type, std::string subtype) const;
+	TObjectTypeHandler getHandlerFor(AiMapObjectID compoundIdentifier) const;
 
 	std::string getObjectName(si32 type) const;
 	std::string getObjectName(si32 type, si32 subtype) const;