mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Improve dwelling value evaluation
This commit is contained in:
		| @@ -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 | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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); | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user