From 22b02ecc784e3ffd92690310abce5a0704d31116 Mon Sep 17 00:00:00 2001 From: Dydzio Date: Mon, 30 Jul 2018 15:32:55 +0200 Subject: [PATCH] Use boost::optional "better way" --- AI/VCAI/Fuzzy.cpp | 4 ++-- AI/VCAI/MapObjectsEvaluator.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/AI/VCAI/Fuzzy.cpp b/AI/VCAI/Fuzzy.cpp index 4d60d7e5c..3db117451 100644 --- a/AI/VCAI/Fuzzy.cpp +++ b/AI/VCAI/Fuzzy.cpp @@ -295,9 +295,9 @@ float FuzzyHelper::getWanderTargetObjectValue(const CGHeroInstance & h, const Ob boost::optional 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 { diff --git a/AI/VCAI/MapObjectsEvaluator.cpp b/AI/VCAI/MapObjectsEvaluator.cpp index e214e097c..7783f68dd 100644 --- a/AI/VCAI/MapObjectsEvaluator.cpp +++ b/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 {