diff --git a/AI/VCAI/MapObjectsEvaluator.cpp b/AI/VCAI/MapObjectsEvaluator.cpp index 4568e0ed8..c82c890d8 100644 --- a/AI/VCAI/MapObjectsEvaluator.cpp +++ b/AI/VCAI/MapObjectsEvaluator.cpp @@ -12,7 +12,7 @@ MapObjectsEvaluator & MapObjectsEvaluator::getInstance() return *(singletonInstance.get()); } -MapObjectsEvaluator::MapObjectsEvaluator() : objectDatabase(std::map()) +MapObjectsEvaluator::MapObjectsEvaluator() : objectDatabase(std::map()) { for(auto primaryID : VLC->objtypeh->knownObjects()) { @@ -21,17 +21,17 @@ MapObjectsEvaluator::MapObjectsEvaluator() : objectDatabase(std::mapobjtypeh->getHandlerFor(primaryID, secondaryID); if(!handler->isStaticObject() && handler->getRMGInfo().value) { - AiMapObjectID newObjectType = AiMapObjectID(primaryID, secondaryID); - std::pair newObject = { newObjectType, handler->getRMGInfo().value }; + CompoundMapObjectID newObjectType = CompoundMapObjectID(primaryID, secondaryID); + std::pair newObject = { newObjectType, handler->getRMGInfo().value }; objectDatabase.insert(newObject); } } } } -boost::optional MapObjectsEvaluator::getObjectValue(int primaryID, int secondaryID) +boost::optional 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 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); } diff --git a/AI/VCAI/MapObjectsEvaluator.h b/AI/VCAI/MapObjectsEvaluator.h index 9c9a52ea8..a7d625244 100644 --- a/AI/VCAI/MapObjectsEvaluator.h +++ b/AI/VCAI/MapObjectsEvaluator.h @@ -13,12 +13,12 @@ class MapObjectsEvaluator { private: - std::map objectDatabase; //value for each object type + std::map objectDatabase; //value for each object type public: MapObjectsEvaluator(); static MapObjectsEvaluator & getInstance(); - boost::optional getObjectValue(int primaryID, int secondaryID); + boost::optional getObjectValue(int primaryID, int secondaryID) const; void addObjectData(int primaryID, int secondaryID, int value); void removeObjectData(int primaryID, int secondaryID, int value); }; diff --git a/lib/mapObjects/CObjectClassesHandler.cpp b/lib/mapObjects/CObjectClassesHandler.cpp index 6fc0d2c8b..d5edc4a1c 100644 --- a/lib/mapObjects/CObjectClassesHandler.cpp +++ b/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); } diff --git a/lib/mapObjects/CObjectClassesHandler.h b/lib/mapObjects/CObjectClassesHandler.h index 428259d18..82fa44cdb 100644 --- a/lib/mapObjects/CObjectClassesHandler.h +++ b/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;