diff --git a/AI/VCAI/FuzzyEngines.cpp b/AI/VCAI/FuzzyEngines.cpp index 421a6900f..2aae0cef8 100644 --- a/AI/VCAI/FuzzyEngines.cpp +++ b/AI/VCAI/FuzzyEngines.cpp @@ -375,7 +375,7 @@ float VisitObjEngine::evaluate(Goals::VisitObj & goal) auto obj = ai->myCb->getObj(ObjectInstanceID(goal.objid)); - boost::optional objValueKnownByAI = MapObjectsEvaluator::getInstance().getObjectValue(obj->ID, obj->subID); + boost::optional objValueKnownByAI = MapObjectsEvaluator::getInstance().getObjectValue(obj); int objValue = 0; if(objValueKnownByAI != boost::none) //consider adding value manipulation based on object instances on map diff --git a/AI/VCAI/MapObjectsEvaluator.cpp b/AI/VCAI/MapObjectsEvaluator.cpp index b6525e72e..7059e16d9 100644 --- a/AI/VCAI/MapObjectsEvaluator.cpp +++ b/AI/VCAI/MapObjectsEvaluator.cpp @@ -34,25 +34,7 @@ MapObjectsEvaluator::MapObjectsEvaluator() } else //some default handling when aiValue not found { - if(primaryID == Obj::CREATURE_GENERATOR1 || primaryID == Obj::CREATURE_GENERATOR4) - { - int aiValue = 0; - CGDwelling dwellingMock; - CRandomGenerator rngMock; - handler->configureObject(&dwellingMock, rngMock); - - for(auto & creLevel : dwellingMock.creatures) - { - for(auto & creatureID : creLevel.second) - { - auto creature = VLC->creh->creatures[creatureID]; - aiValue += (creature->AIValue * creature->growth); - } - } - objectDatabase[CompoundMapObjectID(primaryID, secondaryID)] = aiValue; - } - else - objectDatabase[CompoundMapObjectID(primaryID, secondaryID)] = 0; + objectDatabase[CompoundMapObjectID(primaryID, secondaryID)] = 0; } } } @@ -70,6 +52,26 @@ boost::optional MapObjectsEvaluator::getObjectValue(int primaryID, int seco return boost::optional(); } +boost::optional MapObjectsEvaluator::getObjectValue(const CGObjectInstance * obj) const +{ + if(obj->ID == Obj::CREATURE_GENERATOR1 || obj->ID == Obj::CREATURE_GENERATOR4) + { + auto dwelling = dynamic_cast(obj); + int aiValue = 0; + for(auto & creLevel : dwelling->creatures) + { + for(auto & creatureID : creLevel.second) + { + auto creature = VLC->creh->creatures[creatureID]; + aiValue += (creature->AIValue * creature->growth); + } + } + return aiValue; + } + else + return getObjectValue(obj->ID, obj->subID); +} + void MapObjectsEvaluator::addObjectData(int primaryID, int secondaryID, int value) //by current design it updates value if already in AI database { CompoundMapObjectID internalIdentifier = CompoundMapObjectID(primaryID, secondaryID); diff --git a/AI/VCAI/MapObjectsEvaluator.h b/AI/VCAI/MapObjectsEvaluator.h index bdee725b6..35a76d304 100644 --- a/AI/VCAI/MapObjectsEvaluator.h +++ b/AI/VCAI/MapObjectsEvaluator.h @@ -19,6 +19,7 @@ public: MapObjectsEvaluator(); static MapObjectsEvaluator & getInstance(); boost::optional getObjectValue(int primaryID, int secondaryID) const; + boost::optional getObjectValue(const CGObjectInstance * obj) const; void addObjectData(int primaryID, int secondaryID, int value); void removeObjectData(int primaryID, int secondaryID); };