Dydzio 7 年之前
父節點
當前提交
21c1f47a78

+ 7 - 7
AI/VCAI/MapObjectsEvaluator.cpp

@@ -12,7 +12,7 @@ MapObjectsEvaluator & MapObjectsEvaluator::getInstance()
 	return *(singletonInstance.get());
 }
 
-MapObjectsEvaluator::MapObjectsEvaluator() : objectDatabase(std::map<AiMapObjectID, int>())
+MapObjectsEvaluator::MapObjectsEvaluator() : objectDatabase(std::map<CompoundMapObjectID, int>())
 {
 	for(auto primaryID : VLC->objtypeh->knownObjects())
 	{
@@ -21,17 +21,17 @@ MapObjectsEvaluator::MapObjectsEvaluator() : objectDatabase(std::map<AiMapObject
 			auto handler = VLC->objtypeh->getHandlerFor(primaryID, secondaryID);
 			if(!handler->isStaticObject() && handler->getRMGInfo().value)
 			{
-				AiMapObjectID newObjectType = AiMapObjectID(primaryID, secondaryID);
-				std::pair<AiMapObjectID, int> newObject = { newObjectType, handler->getRMGInfo().value };
+				CompoundMapObjectID newObjectType = CompoundMapObjectID(primaryID, secondaryID);
+				std::pair<CompoundMapObjectID, int> newObject = { newObjectType, handler->getRMGInfo().value };
 				objectDatabase.insert(newObject);
 			}
 		}	
 	}
 }
 
-boost::optional<int> MapObjectsEvaluator::getObjectValue(int primaryID, int secondaryID)
+boost::optional<int> MapObjectsEvaluator::getObjectValue(int primaryID, int secondaryID) const
 {
-	AiMapObjectID internalIdentifier = AiMapObjectID(primaryID, secondaryID);
+	CompoundMapObjectID internalIdentifier = CompoundMapObjectID(primaryID, secondaryID);
 	auto object = objectDatabase.find(internalIdentifier);
 	if(object != objectDatabase.end())
 		return object->second;
@@ -42,13 +42,13 @@ boost::optional<int> MapObjectsEvaluator::getObjectValue(int primaryID, int seco
 
 void MapObjectsEvaluator::addObjectData(int primaryID, int secondaryID, int value) //by current design it updates value if already in AI database
 {
-	AiMapObjectID internalIdentifier = AiMapObjectID(primaryID, secondaryID);
+	CompoundMapObjectID internalIdentifier = CompoundMapObjectID(primaryID, secondaryID);
 	objectDatabase.insert_or_assign(internalIdentifier, value);
 }
 
 void MapObjectsEvaluator::removeObjectData(int primaryID, int secondaryID, int value)
 {
-	AiMapObjectID internalIdentifier = AiMapObjectID(primaryID, secondaryID);
+	CompoundMapObjectID internalIdentifier = CompoundMapObjectID(primaryID, secondaryID);
 	vstd::erase_if_present(objectDatabase, internalIdentifier);
 }
 

+ 2 - 2
AI/VCAI/MapObjectsEvaluator.h

@@ -13,12 +13,12 @@
 class MapObjectsEvaluator
 {
 private:
-	std::map<AiMapObjectID, int> objectDatabase; //value for each object type
+	std::map<CompoundMapObjectID, int> objectDatabase; //value for each object type
 
 public:
 	MapObjectsEvaluator();
 	static MapObjectsEvaluator & getInstance();
-	boost::optional<int> getObjectValue(int primaryID, int secondaryID);
+	boost::optional<int> getObjectValue(int primaryID, int secondaryID) const;
 	void addObjectData(int primaryID, int secondaryID, int value);
 	void removeObjectData(int primaryID, int secondaryID, int value);
 };

+ 1 - 1
lib/mapObjects/CObjectClassesHandler.cpp

@@ -285,7 +285,7 @@ TObjectTypeHandler CObjectClassesHandler::getHandlerFor(std::string type, std::s
 	throw std::runtime_error("Object type handler not found");
 }
 
-TObjectTypeHandler CObjectClassesHandler::getHandlerFor(AiMapObjectID compoundIdentifier) const
+TObjectTypeHandler CObjectClassesHandler::getHandlerFor(CompoundMapObjectID compoundIdentifier) const
 {
 	return getHandlerFor(compoundIdentifier.primaryID, compoundIdentifier.secondaryID);
 }

+ 6 - 9
lib/mapObjects/CObjectClassesHandler.h

@@ -65,22 +65,19 @@ struct DLL_LINKAGE RandomMapInfo
 	}
 };
 
-struct DLL_LINKAGE AiMapObjectID
+struct DLL_LINKAGE CompoundMapObjectID
 {
 	si32 primaryID;
 	si32 secondaryID;
 
-	AiMapObjectID(si32 primID, si32 secID) : primaryID(primID), secondaryID(secID) {};
+	CompoundMapObjectID(si32 primID, si32 secID) : primaryID(primID), secondaryID(secID) {};
 
-	bool operator<(const AiMapObjectID& other)
+	bool operator<(const CompoundMapObjectID& other) const
 	{
-		if(this->primaryID != other.primaryID)
-			return this->primaryID < other.primaryID;
-		else
-			return this->secondaryID < other.secondaryID;
+		return (this->primaryID == other.primaryID) && (this->secondaryID == other.secondaryID);
 	}
 
-	bool operator==(const AiMapObjectID& other)
+	bool operator==(const CompoundMapObjectID& other) const
 	{
 		if(this->primaryID == other.primaryID)
 			return this->secondaryID == other.secondaryID;
@@ -298,7 +295,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;
+	TObjectTypeHandler getHandlerFor(CompoundMapObjectID compoundIdentifier) const;
 
 	std::string getObjectName(si32 type) const;
 	std::string getObjectName(si32 type, si32 subtype) const;