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

Converted pathfinder enum's to enum class

This commit is contained in:
Ivan Savenko
2023-06-21 15:38:57 +03:00
parent f78470a301
commit ebc7a82c2e
24 changed files with 162 additions and 161 deletions

View File

@@ -1196,11 +1196,11 @@ bool AIGateway::moveHeroToTile(int3 dst, HeroPtr h)
//return cb->getTile(coord,false)->topVisitableObj(ignoreHero);
};
auto isTeleportAction = [&](CGPathNode::ENodeAction action) -> bool
auto isTeleportAction = [&](EPathNodeAction action) -> bool
{
if(action != CGPathNode::TELEPORT_NORMAL && action != CGPathNode::TELEPORT_BLOCKING_VISIT)
if(action != EPathNodeAction::TELEPORT_NORMAL && action != EPathNodeAction::TELEPORT_BLOCKING_VISIT)
{
if(action != CGPathNode::TELEPORT_BATTLE)
if(action != EPathNodeAction::TELEPORT_BATTLE)
{
return false;
}
@@ -1311,7 +1311,7 @@ bool AIGateway::moveHeroToTile(int3 dst, HeroPtr h)
doChannelProbing();
}
if(path.nodes[0].action == CGPathNode::BLOCKING_VISIT || path.nodes[0].action == CGPathNode::BATTLE)
if(path.nodes[0].action == EPathNodeAction::BLOCKING_VISIT || path.nodes[0].action == EPathNodeAction::BATTLE)
{
// when we take resource we do not reach its position. We even might not move
// also guarded town is not get visited automatically after capturing

View File

@@ -103,9 +103,9 @@ void ExecuteHeroChain::accept(AIGateway * ai)
{
auto targetNode = cb->getPathsInfo(hero)->getPathInfo(node.coord);
if(targetNode->accessible == CGPathNode::EAccessibility::NOT_SET
|| targetNode->accessible == CGPathNode::EAccessibility::BLOCKED
|| targetNode->accessible == CGPathNode::EAccessibility::FLYABLE
if(targetNode->accessible == EPathAccessibility::NOT_SET
|| targetNode->accessible == EPathAccessibility::BLOCKED
|| targetNode->accessible == EPathAccessibility::FLYABLE
|| targetNode->turns != 0)
{
logAi->error(

View File

@@ -206,7 +206,7 @@ std::vector<CGPathNode *> AINodeStorage::getInitialNodes()
initialNode->moveRemains = actor->initialMovement;
initialNode->danger = 0;
initialNode->setCost(actor->initialTurn);
initialNode->action = CGPathNode::ENodeAction::NORMAL;
initialNode->action = EPathNodeAction::NORMAL;
if(actor->isMovable)
{
@@ -224,7 +224,7 @@ std::vector<CGPathNode *> AINodeStorage::getInitialNodes()
return initialNodes;
}
void AINodeStorage::resetTile(const int3 & coord, EPathfindingLayer layer, CGPathNode::EAccessibility accessibility)
void AINodeStorage::resetTile(const int3 & coord, EPathfindingLayer layer, EPathAccessibility accessibility)
{
for(AIPathNode & heroNode : nodes.get(coord, layer))
{
@@ -262,7 +262,7 @@ void AINodeStorage::commit(CDestinationNodeInfo & destination, const PathNodeInf
void AINodeStorage::commit(
AIPathNode * destination,
const AIPathNode * source,
CGPathNode::ENodeAction action,
EPathNodeAction action,
int turn,
int movementLeft,
float cost) const
@@ -312,7 +312,7 @@ std::vector<CGPathNode *> AINodeStorage::calculateNeighbours(
{
auto nextNode = getOrCreateNode(neighbour, i, srcNode->actor);
if(!nextNode || nextNode.value()->accessible == CGPathNode::NOT_SET)
if(!nextNode || nextNode.value()->accessible == EPathAccessibility::NOT_SET)
continue;
neighbours.push_back(nextNode.value());
@@ -342,7 +342,7 @@ bool AINodeStorage::increaseHeroChainTurnLimit()
{
for(AIPathNode & node : chains)
{
if(node.turns <= heroChainTurn && node.action != CGPathNode::ENodeAction::UNKNOWN)
if(node.turns <= heroChainTurn && node.action != EPathNodeAction::UNKNOWN)
{
commitedTiles.insert(pos);
break;
@@ -372,7 +372,7 @@ bool AINodeStorage::calculateHeroChainFinal()
{
if(node.turns > heroChainTurn
&& !node.locked
&& node.action != CGPathNode::ENodeAction::UNKNOWN
&& node.action != EPathNodeAction::UNKNOWN
&& node.actor->actorExchangeCount > 1
&& !hasBetterChain(&node, &node, chains))
{
@@ -444,7 +444,7 @@ public:
for(AIPathNode & node : chains)
{
if(node.turns <= heroChainTurn && node.action != CGPathNode::ENodeAction::UNKNOWN)
if(node.turns <= heroChainTurn && node.action != EPathNodeAction::UNKNOWN)
existingChains.push_back(&node);
}
@@ -644,16 +644,16 @@ void HeroChainCalculationTask::calculateHeroChain(
if(node->actor->actorExchangeCount + srcNode->actor->actorExchangeCount > CHAIN_MAX_DEPTH)
continue;
if(node->action == CGPathNode::ENodeAction::BATTLE
|| node->action == CGPathNode::ENodeAction::TELEPORT_BATTLE
|| node->action == CGPathNode::ENodeAction::TELEPORT_NORMAL
|| node->action == CGPathNode::ENodeAction::TELEPORT_BLOCKING_VISIT)
if(node->action == EPathNodeAction::BATTLE
|| node->action == EPathNodeAction::TELEPORT_BATTLE
|| node->action == EPathNodeAction::TELEPORT_NORMAL
|| node->action == EPathNodeAction::TELEPORT_BLOCKING_VISIT)
{
continue;
}
if(node->turns > heroChainTurn
|| (node->action == CGPathNode::ENodeAction::UNKNOWN && node->actor->hero)
|| (node->action == EPathNodeAction::UNKNOWN && node->actor->hero)
|| (node->actor->chainMask & srcNode->actor->chainMask) != 0)
{
#if NKAI_PATHFINDER_TRACE_LEVEL >= 2
@@ -666,7 +666,7 @@ void HeroChainCalculationTask::calculateHeroChain(
srcNode->coord.toString(),
(node->turns > heroChainTurn
? "turn limit"
: (node->action == CGPathNode::ENodeAction::UNKNOWN && node->actor->hero)
: (node->action == EPathNodeAction::UNKNOWN && node->actor->hero)
? "action unknown"
: "chain mask"));
#endif
@@ -693,8 +693,8 @@ void HeroChainCalculationTask::calculateHeroChain(
std::vector<ExchangeCandidate> & result)
{
if(carrier->armyLoss < carrier->actor->armyValue
&& (carrier->action != CGPathNode::BATTLE || (carrier->actor->allowBattle && carrier->specialAction))
&& carrier->action != CGPathNode::BLOCKING_VISIT
&& (carrier->action != EPathNodeAction::BATTLE || (carrier->actor->allowBattle && carrier->specialAction))
&& carrier->action != EPathNodeAction::BLOCKING_VISIT
&& (other->armyLoss == 0 || other->armyLoss < other->actor->armyValue))
{
#if NKAI_PATHFINDER_TRACE_LEVEL >= 2
@@ -747,7 +747,7 @@ void HeroChainCalculationTask::addHeroChain(const std::vector<ExchangeCandidate>
auto exchangeNode = chainNodeOptional.value();
if(exchangeNode->action != CGPathNode::ENodeAction::UNKNOWN)
if(exchangeNode->action != EPathNodeAction::UNKNOWN)
{
#if NKAI_PATHFINDER_TRACE_LEVEL >= 2
logAi->trace(
@@ -1057,12 +1057,12 @@ struct TowmPortalFinder
movementCost += bestNode->getCost();
if(node->action == CGPathNode::UNKNOWN || node->getCost() > movementCost)
if(node->action == EPathNodeAction::UNKNOWN || node->getCost() > movementCost)
{
nodeStorage->commit(
node,
nodeStorage->getAINode(bestNode),
CGPathNode::TELEPORT_NORMAL,
EPathNodeAction::TELEPORT_NORMAL,
bestNode->turns,
bestNode->moveRemains - movementNeeded,
movementCost);
@@ -1190,7 +1190,7 @@ bool AINodeStorage::hasBetterChain(
{
auto sameNode = node.actor == candidateNode->actor;
if(sameNode || node.action == CGPathNode::ENodeAction::UNKNOWN || !node.actor || !node.actor->hero)
if(sameNode || node.action == EPathNodeAction::UNKNOWN || !node.actor || !node.actor->hero)
{
continue;
}
@@ -1273,7 +1273,7 @@ bool AINodeStorage::isTileAccessible(const HeroPtr & hero, const int3 & pos, con
for(const AIPathNode & node : chains)
{
if(node.action != CGPathNode::ENodeAction::UNKNOWN
if(node.action != EPathNodeAction::UNKNOWN
&& node.actor && node.actor->hero == hero.h)
{
return true;
@@ -1293,7 +1293,7 @@ std::vector<AIPath> AINodeStorage::getChainInfo(const int3 & pos, bool isOnLand)
for(const AIPathNode & node : chains)
{
if(node.action == CGPathNode::ENodeAction::UNKNOWN || !node.actor || !node.actor->hero)
if(node.action == EPathNodeAction::UNKNOWN || !node.actor || !node.actor->hero)
{
continue;
}

View File

@@ -53,8 +53,8 @@ struct AIPathNode : public CGPathNode
STRONG_INLINE
bool blocked() const
{
return accessible == CGPathNode::EAccessibility::NOT_SET
|| accessible == CGPathNode::EAccessibility::BLOCKED;
return accessible == EPathAccessibility::NOT_SET
|| accessible == EPathAccessibility::BLOCKED;
}
void addSpecialAction(std::shared_ptr<const SpecialAction> action);
@@ -196,7 +196,7 @@ public:
void commit(
AIPathNode * destination,
const AIPathNode * source,
CGPathNode::ENodeAction action,
EPathNodeAction action,
int turn,
int movementLeft,
float cost) const;
@@ -262,7 +262,7 @@ public:
}
STRONG_INLINE
void resetTile(const int3 & tile, EPathfindingLayer layer, CGPathNode::EAccessibility accessibility);
void resetTile(const int3 & tile, EPathfindingLayer layer, EPathAccessibility accessibility);
STRONG_INLINE int getBucket(const ChainActor * actor) const
{

View File

@@ -131,11 +131,11 @@ namespace AIPathfinding
{
AIPathNode * boatNode = boatNodeOptional.value();
if(boatNode->action == CGPathNode::UNKNOWN)
if(boatNode->action == EPathNodeAction::UNKNOWN)
{
boatNode->addSpecialAction(virtualBoat);
destination.blocked = false;
destination.action = CGPathNode::ENodeAction::EMBARK;
destination.action = EPathNodeAction::EMBARK;
destination.node = boatNode;
result = true;
}

View File

@@ -31,7 +31,7 @@ namespace AIPathfinding
return;
if(blocker == BlockingReason::DESTINATION_BLOCKED
&& destination.action == CGPathNode::EMBARK
&& destination.action == EPathNodeAction::EMBARK
&& nodeStorage->getAINode(destination.node)->specialAction)
{
return;

View File

@@ -27,8 +27,8 @@ namespace AIPathfinding
const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) const
{
if(source.node->action == CGPathNode::ENodeAction::BLOCKING_VISIT
|| source.node->action == CGPathNode::ENodeAction::VISIT)
if(source.node->action == EPathNodeAction::BLOCKING_VISIT
|| source.node->action == EPathNodeAction::VISIT)
{
if(source.nodeObject
&& isObjectPassable(source.nodeObject, pathfinderHelper->hero->tempOwner, source.objectRelations))

View File

@@ -120,7 +120,7 @@ std::vector<CGPathNode *> AINodeStorage::getInitialNodes()
return {initialNode};
}
void AINodeStorage::resetTile(const int3 & coord, EPathfindingLayer layer, CGPathNode::EAccessibility accessibility)
void AINodeStorage::resetTile(const int3 & coord, EPathfindingLayer layer, EPathAccessibility accessibility)
{
for(int i = 0; i < NUM_CHAINS; i++)
{
@@ -171,7 +171,7 @@ std::vector<CGPathNode *> AINodeStorage::calculateNeighbours(
{
auto nextNode = getOrCreateNode(neighbour, i, srcNode->chainMask);
if(!nextNode || nextNode.value()->accessible == CGPathNode::NOT_SET)
if(!nextNode || nextNode.value()->accessible == EPathAccessibility::NOT_SET)
continue;
neighbours.push_back(nextNode.value());
@@ -294,7 +294,7 @@ bool AINodeStorage::hasBetterChain(const PathNodeInfo & source, CDestinationNode
for(const AIPathNode & node : chains)
{
auto sameNode = node.chainMask == destinationNode->chainMask;
if(sameNode || node.action == CGPathNode::ENodeAction::UNKNOWN)
if(sameNode || node.action == EPathNodeAction::UNKNOWN)
{
continue;
}
@@ -323,7 +323,7 @@ bool AINodeStorage::isTileAccessible(const int3 & pos, const EPathfindingLayer l
{
const AIPathNode & node = nodes[layer][pos.z][pos.x][pos.y][0];
return node.action != CGPathNode::ENodeAction::UNKNOWN;
return node.action != EPathNodeAction::UNKNOWN;
}
std::vector<AIPath> AINodeStorage::getChainInfo(const int3 & pos, bool isOnLand) const
@@ -334,7 +334,7 @@ std::vector<AIPath> AINodeStorage::getChainInfo(const int3 & pos, bool isOnLand)
for(const AIPathNode & node : chains)
{
if(node.action == CGPathNode::ENodeAction::UNKNOWN)
if(node.action == EPathNodeAction::UNKNOWN)
{
continue;
}

View File

@@ -70,7 +70,7 @@ private:
std::unique_ptr<FuzzyHelper> dangerEvaluator;
STRONG_INLINE
void resetTile(const int3 & tile, EPathfindingLayer layer, CGPathNode::EAccessibility accessibility);
void resetTile(const int3 & tile, EPathfindingLayer layer, EPathAccessibility accessibility);
public:
/// more than 1 chain layer allows us to have more than 1 path to each tile so we can chose more optimal one.

View File

@@ -122,11 +122,11 @@ namespace AIPathfinding
{
AIPathNode * boatNode = boatNodeOptional.value();
if(boatNode->action == CGPathNode::UNKNOWN)
if(boatNode->action == EPathNodeAction::UNKNOWN)
{
boatNode->specialAction = virtualBoat;
destination.blocked = false;
destination.action = CGPathNode::ENodeAction::EMBARK;
destination.action = EPathNodeAction::EMBARK;
destination.node = boatNode;
result = true;
}

View File

@@ -29,7 +29,7 @@ namespace AIPathfinding
return;
if(blocker == BlockingReason::DESTINATION_BLOCKED
&& destination.action == CGPathNode::EMBARK
&& destination.action == EPathNodeAction::EMBARK
&& nodeStorage->getAINode(destination.node)->specialAction)
{
return;

View File

@@ -23,7 +23,7 @@ namespace AIPathfinding
const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) const
{
if(source.node->action == CGPathNode::ENodeAction::BLOCKING_VISIT || source.node->action == CGPathNode::ENodeAction::VISIT)
if(source.node->action == EPathNodeAction::BLOCKING_VISIT || source.node->action == EPathNodeAction::VISIT)
{
// we can not directly bypass objects, we need to interact with them first
destination.node->theNodeBefore = source.node;

View File

@@ -1849,11 +1849,11 @@ bool VCAI::moveHeroToTile(int3 dst, HeroPtr h)
//return cb->getTile(coord,false)->topVisitableObj(ignoreHero);
};
auto isTeleportAction = [&](CGPathNode::ENodeAction action) -> bool
auto isTeleportAction = [&](EPathNodeAction action) -> bool
{
if(action != CGPathNode::TELEPORT_NORMAL && action != CGPathNode::TELEPORT_BLOCKING_VISIT)
if(action != EPathNodeAction::TELEPORT_NORMAL && action != EPathNodeAction::TELEPORT_BLOCKING_VISIT)
{
if(action != CGPathNode::TELEPORT_BATTLE)
if(action != EPathNodeAction::TELEPORT_BATTLE)
{
return false;
}
@@ -1964,7 +1964,7 @@ bool VCAI::moveHeroToTile(int3 dst, HeroPtr h)
doChannelProbing();
}
if(path.nodes[0].action == CGPathNode::BLOCKING_VISIT)
if(path.nodes[0].action == EPathNodeAction::BLOCKING_VISIT)
{
ret = h && i == 0; // when we take resource we do not reach its position. We even might not move
}