浏览代码

Improve dwelling value evaluation

Dydzio 7 年之前
父节点
当前提交
e197d22e68
共有 3 个文件被更改,包括 23 次插入20 次删除
  1. 1 1
      AI/VCAI/FuzzyEngines.cpp
  2. 21 19
      AI/VCAI/MapObjectsEvaluator.cpp
  3. 1 0
      AI/VCAI/MapObjectsEvaluator.h

+ 1 - 1
AI/VCAI/FuzzyEngines.cpp

@@ -375,7 +375,7 @@ float VisitObjEngine::evaluate(Goals::VisitObj & goal)
 	auto obj = ai->myCb->getObj(ObjectInstanceID(goal.objid));
 
 
-	boost::optional<int> objValueKnownByAI = MapObjectsEvaluator::getInstance().getObjectValue(obj->ID, obj->subID);
+	boost::optional<int> objValueKnownByAI = MapObjectsEvaluator::getInstance().getObjectValue(obj);
 	int objValue = 0;
 
 	if(objValueKnownByAI != boost::none) //consider adding value manipulation based on object instances on map

+ 21 - 19
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<int> MapObjectsEvaluator::getObjectValue(int primaryID, int seco
 	return boost::optional<int>();
 }
 
+boost::optional<int> MapObjectsEvaluator::getObjectValue(const CGObjectInstance * obj) const
+{
+	if(obj->ID == Obj::CREATURE_GENERATOR1 || obj->ID == Obj::CREATURE_GENERATOR4)
+	{
+		auto dwelling = dynamic_cast<const CGDwelling *>(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);

+ 1 - 0
AI/VCAI/MapObjectsEvaluator.h

@@ -19,6 +19,7 @@ public:
 	MapObjectsEvaluator();
 	static MapObjectsEvaluator & getInstance();
 	boost::optional<int> getObjectValue(int primaryID, int secondaryID) const;
+	boost::optional<int> getObjectValue(const CGObjectInstance * obj) const;
 	void addObjectData(int primaryID, int secondaryID, int value);
 	void removeObjectData(int primaryID, int secondaryID);
 };