Переглянути джерело

Use boost::optional "better way"

Dydzio 7 роки тому
батько
коміт
22b02ecc78
2 змінених файлів з 6 додано та 6 видалено
  1. 2 2
      AI/VCAI/Fuzzy.cpp
  2. 4 4
      AI/VCAI/MapObjectsEvaluator.cpp

+ 2 - 2
AI/VCAI/Fuzzy.cpp

@@ -295,9 +295,9 @@ float FuzzyHelper::getWanderTargetObjectValue(const CGHeroInstance & h, const Ob
 	boost::optional<int> objValueKnownByAI = MapObjectsEvaluator::getInstance().getObjectValue(obj->ID, obj->subID);
 	int objValue = 0;
 
-	if(objValueKnownByAI.is_initialized()) //consider adding value manipulation based on object instances on map
+	if(objValueKnownByAI != boost::none) //consider adding value manipulation based on object instances on map
 	{
-		objValue = std::min(std::max(objValueKnownByAI.value(), 0), 20000);
+		objValue = std::min(std::max(objValueKnownByAI.get(), 0), 20000);
 	}
 	else
 	{

+ 4 - 4
AI/VCAI/MapObjectsEvaluator.cpp

@@ -21,13 +21,13 @@ MapObjectsEvaluator::MapObjectsEvaluator()
 			auto handler = VLC->objtypeh->getHandlerFor(primaryID, secondaryID);
 			if(!handler->isStaticObject())
 			{
-				if(handler->getAiValue().is_initialized())
+				if(handler->getAiValue() != boost::none)
 				{
-					objectDatabase[CompoundMapObjectID(primaryID, secondaryID)] = handler->getAiValue().value();
+					objectDatabase[CompoundMapObjectID(primaryID, secondaryID)] = handler->getAiValue().get();
 				}
-				else if(VLC->objtypeh->getObjGroupAiValue(primaryID).is_initialized()) //if value is not initialized - fallback to default value for this object family if it exists
+				else if(VLC->objtypeh->getObjGroupAiValue(primaryID) != boost::none) //if value is not initialized - fallback to default value for this object family if it exists
 				{
-					objectDatabase[CompoundMapObjectID(primaryID, secondaryID)] = VLC->objtypeh->getObjGroupAiValue(primaryID).value();
+					objectDatabase[CompoundMapObjectID(primaryID, secondaryID)] = VLC->objtypeh->getObjGroupAiValue(primaryID).get();
 				}
 				else
 				{