1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00

Use boost::optional "better way"

This commit is contained in:
Dydzio 2018-07-30 15:32:55 +02:00
parent 0786bd915a
commit 22b02ecc78
2 changed files with 6 additions and 6 deletions

View File

@ -295,9 +295,9 @@ float FuzzyHelper::getWanderTargetObjectValue(const CGHeroInstance & h, const Ob
boost::optional<int> objValueKnownByAI = MapObjectsEvaluator::getInstance().getObjectValue(obj->ID, obj->subID); boost::optional<int> objValueKnownByAI = MapObjectsEvaluator::getInstance().getObjectValue(obj->ID, obj->subID);
int objValue = 0; 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 else
{ {

View File

@ -21,13 +21,13 @@ MapObjectsEvaluator::MapObjectsEvaluator()
auto handler = VLC->objtypeh->getHandlerFor(primaryID, secondaryID); auto handler = VLC->objtypeh->getHandlerFor(primaryID, secondaryID);
if(!handler->isStaticObject()) 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 else
{ {