1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-06 09:09:40 +02:00

vcmi: use std::optional

This commit is contained in:
Konstantin
2023-04-16 20:42:56 +03:00
parent 0d35606a44
commit 7a5775a9f9
135 changed files with 552 additions and 585 deletions

View File

@@ -83,7 +83,7 @@ bool AINodeStorage::isBattleNode(const CGPathNode * node) const
return (getAINode(node)->chainMask & BATTLE_CHAIN) > 0;
}
boost::optional<AIPathNode *> AINodeStorage::getOrCreateNode(const int3 & pos, const EPathfindingLayer layer, int chainNumber)
std::optional<AIPathNode *> AINodeStorage::getOrCreateNode(const int3 & pos, const EPathfindingLayer layer, int chainNumber)
{
auto chains = nodes[layer][pos.z][pos.x][pos.y];
@@ -102,15 +102,13 @@ boost::optional<AIPathNode *> AINodeStorage::getOrCreateNode(const int3 & pos, c
}
}
return boost::none;
return std::nullopt;
}
std::vector<CGPathNode *> AINodeStorage::getInitialNodes()
{
auto hpos = hero->visitablePos();
auto initialNode =
getOrCreateNode(hpos, hero->boat ? EPathfindingLayer::SAIL : EPathfindingLayer::LAND, NORMAL_CHAIN)
.get();
auto initialNode = getOrCreateNode(hpos, hero->boat ? EPathfindingLayer::SAIL : EPathfindingLayer::LAND, NORMAL_CHAIN).value();
initialNode->turns = 0;
initialNode->moveRemains = hero->movement;
@@ -171,10 +169,10 @@ std::vector<CGPathNode *> AINodeStorage::calculateNeighbours(
{
auto nextNode = getOrCreateNode(neighbour, i, srcNode->chainMask);
if(!nextNode || nextNode.get()->accessible == CGPathNode::NOT_SET)
if(!nextNode || nextNode.value()->accessible == CGPathNode::NOT_SET)
continue;
neighbours.push_back(nextNode.get());
neighbours.push_back(nextNode.value());
}
}
@@ -207,7 +205,7 @@ std::vector<CGPathNode *> AINodeStorage::calculateTeleportations(
if(!node)
continue;
neighbours.push_back(node.get());
neighbours.push_back(node.value());
}
}
@@ -273,7 +271,7 @@ void AINodeStorage::calculateTownPortalTeleportations(
logAi->trace("Adding town portal node at %s", targetTown->name);
#endif
AIPathNode * node = nodeOptional.get();
AIPathNode * node = nodeOptional.value();
node->theNodeBefore = source.node;
node->specialAction.reset(new AIPathfinding::TownPortalAction(targetTown));

View File

@@ -107,7 +107,7 @@ public:
bool isBattleNode(const CGPathNode * node) const;
bool hasBetterChain(const PathNodeInfo & source, CDestinationNodeInfo & destination) const;
boost::optional<AIPathNode *> getOrCreateNode(const int3 & coord, const EPathfindingLayer layer, int chainNumber);
std::optional<AIPathNode *> getOrCreateNode(const int3 & coord, const EPathfindingLayer layer, int chainNumber);
std::vector<AIPath> getChainInfo(const int3 & pos, bool isOnLand) const;
bool isTileAccessible(const int3 & pos, const EPathfindingLayer layer) const;

View File

@@ -114,7 +114,7 @@ Goals::TGoalVec PathfindingManager::findPath(
const std::function<Goals::TSubgoal(int3)> doVisitTile) const
{
Goals::TGoalVec result;
boost::optional<uint64_t> armyValueRequired;
std::optional<uint64_t> armyValueRequired;
uint64_t danger;
std::vector<AIPath> chainInfo = pathfinder->getPathInfo(hero, dest);
@@ -165,12 +165,12 @@ Goals::TGoalVec PathfindingManager::findPath(
if(!armyValueRequired || armyValueRequired > danger)
{
armyValueRequired = boost::make_optional(danger);
armyValueRequired = std::make_optional(danger);
}
}
}
danger = armyValueRequired.get_value_or(0);
danger = armyValueRequired.value_or(0);
if(allowGatherArmy && danger > 0)
{

View File

@@ -120,7 +120,7 @@ namespace AIPathfinding
if(boatNodeOptional)
{
AIPathNode * boatNode = boatNodeOptional.get();
AIPathNode * boatNode = boatNodeOptional.value();
if(boatNode->action == CGPathNode::UNKNOWN)
{

View File

@@ -106,7 +106,7 @@ namespace AIPathfinding
return;
}
AIPathNode * battleNode = battleNodeOptional.get();
auto * battleNode = battleNodeOptional.value();
if(battleNode->locked)
{