1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-13 01:20:34 +02:00

AI pathfinding: rename and add const to functions

This commit is contained in:
Andrii Danylchenko
2018-10-07 14:51:27 +03:00
parent cf213a5acf
commit f327c46fa3
16 changed files with 198 additions and 220 deletions

View File

@ -17,8 +17,7 @@ AIhelper::AIhelper()
{ {
resourceManager.reset(new ResourceManager()); resourceManager.reset(new ResourceManager());
buildingManager.reset(new BuildingManager()); buildingManager.reset(new BuildingManager());
pathfindingManager.reset(new CPathfindingManager()); pathfindingManager.reset(new PathfindingManager());
//TODO: push to vector
} }
AIhelper::~AIhelper() AIhelper::~AIhelper()
@ -32,7 +31,6 @@ bool AIhelper::notifyGoalCompleted(Goals::TSubgoal goal)
void AIhelper::setCB(CPlayerSpecificInfoCallback * CB) void AIhelper::setCB(CPlayerSpecificInfoCallback * CB)
{ {
//TODO: for
resourceManager->setCB(CB); resourceManager->setCB(CB);
buildingManager->setCB(CB); buildingManager->setCB(CB);
pathfindingManager->setCB(CB); pathfindingManager->setCB(CB);
@ -40,7 +38,6 @@ void AIhelper::setCB(CPlayerSpecificInfoCallback * CB)
void AIhelper::setAI(VCAI * AI) void AIhelper::setAI(VCAI * AI)
{ {
//TODO: for loop
resourceManager->setAI(AI); resourceManager->setAI(AI);
buildingManager->setAI(AI); buildingManager->setAI(AI);
pathfindingManager->setAI(AI); pathfindingManager->setAI(AI);

View File

@ -16,7 +16,7 @@
#include "ResourceManager.h" #include "ResourceManager.h"
#include "BuildingManager.h" #include "BuildingManager.h"
#include "Pathfinding/CPathfindingManager.h" #include "Pathfinding/PathfindingManager.h"
class ResourceManager; class ResourceManager;
class BuildingManager; class BuildingManager;
@ -30,7 +30,7 @@ class DLL_EXPORT AIhelper : public IResourceManager, public IBuildingManager, pu
std::shared_ptr<ResourceManager> resourceManager; std::shared_ptr<ResourceManager> resourceManager;
std::shared_ptr<BuildingManager> buildingManager; std::shared_ptr<BuildingManager> buildingManager;
std::shared_ptr<CPathfindingManager> pathfindingManager; std::shared_ptr<PathfindingManager> pathfindingManager;
//TODO: vector<IAbstractManager> //TODO: vector<IAbstractManager>
public: public:
AIhelper(); AIhelper();

View File

@ -11,7 +11,7 @@ set(VCAI_SRCS
Pathfinding/AIPathfinderConfig.cpp Pathfinding/AIPathfinderConfig.cpp
Pathfinding/AIPathfinder.cpp Pathfinding/AIPathfinder.cpp
Pathfinding/AINodeStorage.cpp Pathfinding/AINodeStorage.cpp
Pathfinding/CPathfindingManager.cpp Pathfinding/PathfindingManager.cpp
AIUtility.cpp AIUtility.cpp
AIhelper.cpp AIhelper.cpp
ResourceManager.cpp ResourceManager.cpp
@ -32,7 +32,7 @@ set(VCAI_HEADERS
Pathfinding/AIPathfinderConfig.h Pathfinding/AIPathfinderConfig.h
Pathfinding/AIPathfinder.h Pathfinding/AIPathfinder.h
Pathfinding/AINodeStorage.h Pathfinding/AINodeStorage.h
Pathfinding/CPathfindingManager.h Pathfinding/PathfindingManager.h
AIUtility.h AIUtility.h
AIhelper.h AIhelper.h
ResourceManager.h ResourceManager.h

View File

@ -21,17 +21,19 @@ AINodeStorage::~AINodeStorage()
{ {
} }
AIPathNode * AINodeStorage::getAINode(CPathNodeInfo & nodeInfo) const const AIPathNode * AINodeStorage::getAINode(const CGPathNode * node) const
{ {
return static_cast<AIPathNode *>(nodeInfo.node); return static_cast<const AIPathNode *>(node);
} }
AIPathNode * AINodeStorage::getAINode(CGPathNode * node) const void AINodeStorage::updateAINode(CGPathNode * node, std::function<void(AIPathNode *)> updater)
{ {
return static_cast<AIPathNode *>(node); auto aiNode = static_cast<AIPathNode *>(node);
updater(aiNode);
} }
bool AINodeStorage::isBattleNode(CGPathNode * node) const bool AINodeStorage::isBattleNode(const CGPathNode * node) const
{ {
return getAINode(node)->chainMask & BATTLE_CHAIN > 0; return getAINode(node)->chainMask & BATTLE_CHAIN > 0;
} }
@ -64,25 +66,26 @@ void AINodeStorage::resetTile(const int3 & coord, EPathfindingLayer layer, CGPat
} }
} }
void AINodeStorage::commit(CDestinationNodeInfo & destination, CPathNodeInfo & source) void AINodeStorage::commit(CDestinationNodeInfo & destination, const PathNodeInfo & source)
{ {
auto dstNode = getAINode(destination); const AIPathNode * srcNode = getAINode(source.node);
auto srcNode = getAINode(source);
updateAINode(destination.node, [&](AIPathNode * dstNode) {
dstNode->moveRemains = destination.movementLeft; dstNode->moveRemains = destination.movementLeft;
dstNode->turns = destination.turn; dstNode->turns = destination.turn;
dstNode->danger = srcNode->danger; dstNode->danger = srcNode->danger;
dstNode->action = destination.action; dstNode->action = destination.action;
dstNode->theNodeBefore = srcNode->theNodeBefore; dstNode->theNodeBefore = srcNode->theNodeBefore;
});
} }
std::vector<CGPathNode *> AINodeStorage::calculateNeighbours( std::vector<CGPathNode *> AINodeStorage::calculateNeighbours(
CPathNodeInfo & source, const PathNodeInfo & source,
CPathfinderConfig * pathfinderConfig, const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) const CPathfinderHelper * pathfinderHelper)
{ {
std::vector<CGPathNode *> neighbours; std::vector<CGPathNode *> neighbours;
auto srcNode = getAINode(source); const AIPathNode * srcNode = getAINode(source.node);
auto accessibleNeighbourTiles = pathfinderHelper->getNeighbourTiles(source); auto accessibleNeighbourTiles = pathfinderHelper->getNeighbourTiles(source);
for(auto & neighbour : accessibleNeighbourTiles) for(auto & neighbour : accessibleNeighbourTiles)
@ -102,13 +105,13 @@ std::vector<CGPathNode *> AINodeStorage::calculateNeighbours(
} }
std::vector<CGPathNode *> AINodeStorage::calculateTeleportations( std::vector<CGPathNode *> AINodeStorage::calculateTeleportations(
CPathNodeInfo & source, const PathNodeInfo & source,
CPathfinderConfig * pathfinderConfig, const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) const CPathfinderHelper * pathfinderHelper)
{ {
std::vector<CGPathNode *> neighbours; std::vector<CGPathNode *> neighbours;
auto accessibleExits = pathfinderHelper->getTeleportExits(source); auto accessibleExits = pathfinderHelper->getTeleportExits(source);
auto srcNode = getAINode(source); auto srcNode = getAINode(source.node);
for(auto & neighbour : accessibleExits) for(auto & neighbour : accessibleExits)
{ {
@ -120,11 +123,11 @@ std::vector<CGPathNode *> AINodeStorage::calculateTeleportations(
return neighbours; return neighbours;
} }
bool AINodeStorage::hasBetterChain(CPathNodeInfo & source, CDestinationNodeInfo & destination) const bool AINodeStorage::hasBetterChain(const PathNodeInfo & source, CDestinationNodeInfo & destination) const
{ {
auto pos = destination.coord; auto pos = destination.coord;
auto chains = nodes[pos.x][pos.y][pos.z][EPathfindingLayer::LAND]; auto chains = nodes[pos.x][pos.y][pos.z][EPathfindingLayer::LAND];
auto destinationNode = getAINode(destination); auto destinationNode = getAINode(destination.node);
for(const AIPathNode & node : chains) for(const AIPathNode & node : chains)
{ {
@ -154,7 +157,7 @@ bool AINodeStorage::hasBetterChain(CPathNodeInfo & source, CDestinationNodeInfo
return false; return false;
} }
std::vector<AIPath> AINodeStorage::getChainInfo(int3 pos) std::vector<AIPath> AINodeStorage::getChainInfo(int3 pos) const
{ {
std::vector<AIPath> paths; std::vector<AIPath> paths;
auto chains = nodes[pos.x][pos.y][pos.z][EPathfindingLayer::LAND]; auto chains = nodes[pos.x][pos.y][pos.z][EPathfindingLayer::LAND];

View File

@ -74,23 +74,24 @@ public:
virtual void resetTile(const int3 & tile, EPathfindingLayer layer, CGPathNode::EAccessibility accessibility) override; virtual void resetTile(const int3 & tile, EPathfindingLayer layer, CGPathNode::EAccessibility accessibility) override;
virtual std::vector<CGPathNode *> calculateNeighbours( virtual std::vector<CGPathNode *> calculateNeighbours(
CPathNodeInfo & source, const PathNodeInfo & source,
CPathfinderConfig * pathfinderConfig, const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) override; const CPathfinderHelper * pathfinderHelper) override;
virtual std::vector<CGPathNode *> calculateTeleportations( virtual std::vector<CGPathNode *> calculateTeleportations(
CPathNodeInfo & source, const PathNodeInfo & source,
CPathfinderConfig * pathfinderConfig, const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) override; const CPathfinderHelper * pathfinderHelper) override;
virtual void commit(CDestinationNodeInfo & destination, CPathNodeInfo & source) override; virtual void commit(CDestinationNodeInfo & destination, const PathNodeInfo & source) override;
AIPathNode * getAINode(CPathNodeInfo & nodeInfo) const; const AIPathNode * getAINode(const CGPathNode * node) const;
AIPathNode * getAINode(CGPathNode * node) const; void updateAINode(CGPathNode * node, std::function<void (AIPathNode *)> updater);
bool isBattleNode(CGPathNode * node) const;
bool hasBetterChain(CPathNodeInfo & source, CDestinationNodeInfo & destination) const; bool isBattleNode(const CGPathNode * node) const;
bool hasBetterChain(const PathNodeInfo & source, CDestinationNodeInfo & destination) const;
AIPathNode * getNode(const int3 & coord, const EPathfindingLayer layer, int chainNumber); AIPathNode * getNode(const int3 & coord, const EPathfindingLayer layer, int chainNumber);
std::vector<AIPath> getChainInfo(int3 pos); std::vector<AIPath> getChainInfo(int3 pos) const;
void setHero(HeroPtr heroPtr) void setHero(HeroPtr heroPtr)
{ {

View File

@ -11,30 +11,7 @@
#include "AIPathfinderConfig.h" #include "AIPathfinderConfig.h"
#include "../../../CCallback.h" #include "../../../CCallback.h"
class AILayerTransitionRule : public CLayerTransitionRule class AIMovementAfterDestinationRule : public MovementAfterDestinationRule
{
public:
virtual void process(
CPathNodeInfo & source,
CDestinationNodeInfo & destination,
CPathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) const override
{
CLayerTransitionRule::process(source, destination, pathfinderConfig, pathfinderHelper);
if(!destination.blocked)
{
return;
}
if(source.node->layer == EPathfindingLayer::LAND && destination.node->layer == EPathfindingLayer::SAIL)
{
logAi->debug("Check virtual boat!");
}
}
};
class AIMovementAfterDestinationRule : public CMovementAfterDestinationRule
{ {
private: private:
CPlayerSpecificInfoCallback * cb; CPlayerSpecificInfoCallback * cb;
@ -47,9 +24,9 @@ public:
} }
virtual void process( virtual void process(
CPathNodeInfo & source, const PathNodeInfo & source,
CDestinationNodeInfo & destination, CDestinationNodeInfo & destination,
CPathfinderConfig * pathfinderConfig, const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) const override CPathfinderHelper * pathfinderHelper) const override
{ {
if(nodeStorage->hasBetterChain(source, destination)) if(nodeStorage->hasBetterChain(source, destination))
@ -64,7 +41,7 @@ public:
if(blocker == BlockingReason::NONE) if(blocker == BlockingReason::NONE)
return; return;
auto srcNode = nodeStorage->getAINode(source); auto srcNode = nodeStorage->getAINode(source.node);
if(blocker == BlockingReason::DESTINATION_BLOCKVIS && destination.nodeObject) if(blocker == BlockingReason::DESTINATION_BLOCKVIS && destination.nodeObject)
{ {
@ -113,7 +90,7 @@ public:
return; return;
} }
auto destNode = nodeStorage->getAINode(destination); auto destNode = nodeStorage->getAINode(destination.node);
auto battleNode = nodeStorage->getNode(destination.coord, destination.node->layer, destNode->chainMask | AINodeStorage::BATTLE_CHAIN); auto battleNode = nodeStorage->getNode(destination.coord, destination.node->layer, destNode->chainMask | AINodeStorage::BATTLE_CHAIN);
if(battleNode->locked) if(battleNode->locked)
@ -152,7 +129,7 @@ public:
} }
}; };
class AIMovementToDestinationRule : public CMovementToDestinationRule class AIMovementToDestinationRule : public MovementToDestinationRule
{ {
private: private:
CPlayerSpecificInfoCallback * cb; CPlayerSpecificInfoCallback * cb;
@ -165,9 +142,9 @@ public:
} }
virtual void process( virtual void process(
CPathNodeInfo & source, const PathNodeInfo & source,
CDestinationNodeInfo & destination, CDestinationNodeInfo & destination,
CPathfinderConfig * pathfinderConfig, const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) const override CPathfinderHelper * pathfinderHelper) const override
{ {
auto blocker = getBlockingReason(source, destination, pathfinderConfig, pathfinderHelper); auto blocker = getBlockingReason(source, destination, pathfinderConfig, pathfinderHelper);
@ -207,7 +184,7 @@ public:
} }
}; };
class AIPreviousNodeRule : public CMovementToDestinationRule class AIPreviousNodeRule : public MovementToDestinationRule
{ {
private: private:
CPlayerSpecificInfoCallback * cb; CPlayerSpecificInfoCallback * cb;
@ -220,9 +197,9 @@ public:
} }
virtual void process( virtual void process(
CPathNodeInfo & source, const PathNodeInfo & source,
CDestinationNodeInfo & destination, CDestinationNodeInfo & destination,
CPathfinderConfig * pathfinderConfig, const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) const override CPathfinderHelper * pathfinderHelper) const override
{ {
auto blocker = getBlockingReason(source, destination, pathfinderConfig, pathfinderHelper); auto blocker = getBlockingReason(source, destination, pathfinderConfig, pathfinderHelper);
@ -261,10 +238,10 @@ std::vector<std::shared_ptr<IPathfindingRule>> makeRuleset(
std::shared_ptr<AINodeStorage> nodeStorage) std::shared_ptr<AINodeStorage> nodeStorage)
{ {
std::vector<std::shared_ptr<IPathfindingRule>> rules = { std::vector<std::shared_ptr<IPathfindingRule>> rules = {
std::make_shared<AILayerTransitionRule>(), std::make_shared<LayerTransitionRule>(),
std::make_shared<CDestinationActionRule>(), std::make_shared<DestinationActionRule>(),
std::make_shared<AIMovementToDestinationRule>(cb, nodeStorage), std::make_shared<AIMovementToDestinationRule>(cb, nodeStorage),
std::make_shared<CMovementCostRule>(), std::make_shared<MovementCostRule>(),
std::make_shared<AIPreviousNodeRule>(cb, nodeStorage), std::make_shared<AIPreviousNodeRule>(cb, nodeStorage),
std::make_shared<AIMovementAfterDestinationRule>(cb, nodeStorage) std::make_shared<AIMovementAfterDestinationRule>(cb, nodeStorage)
}; };
@ -275,6 +252,6 @@ std::vector<std::shared_ptr<IPathfindingRule>> makeRuleset(
AIPathfinderConfig::AIPathfinderConfig( AIPathfinderConfig::AIPathfinderConfig(
CPlayerSpecificInfoCallback * cb, CPlayerSpecificInfoCallback * cb,
std::shared_ptr<AINodeStorage> nodeStorage) std::shared_ptr<AINodeStorage> nodeStorage)
:CPathfinderConfig(nodeStorage, makeRuleset(cb, nodeStorage)) :PathfinderConfig(nodeStorage, makeRuleset(cb, nodeStorage))
{ {
} }

View File

@ -12,7 +12,7 @@
#include "AINodeStorage.h" #include "AINodeStorage.h"
class AIPathfinderConfig : public CPathfinderConfig class AIPathfinderConfig : public PathfinderConfig
{ {
public: public:
AIPathfinderConfig(CPlayerSpecificInfoCallback * cb, std::shared_ptr<AINodeStorage> nodeStorage); AIPathfinderConfig(CPlayerSpecificInfoCallback * cb, std::shared_ptr<AINodeStorage> nodeStorage);

View File

@ -8,29 +8,29 @@
* *
*/ */
#include "StdInc.h" #include "StdInc.h"
#include "CPathfindingManager.h" #include "PathfindingManager.h"
#include "AIPathfinder.h" #include "AIPathfinder.h"
#include "AIPathfinderConfig.h" #include "AIPathfinderConfig.h"
#include "../../../lib/CGameInfoCallback.h" #include "../../../lib/CGameInfoCallback.h"
#include "../../../lib/mapping/CMap.h" #include "../../../lib/mapping/CMap.h"
CPathfindingManager::CPathfindingManager(CPlayerSpecificInfoCallback * CB, VCAI * AI) PathfindingManager::PathfindingManager(CPlayerSpecificInfoCallback * CB, VCAI * AI)
: ai(AI), cb(CB) : ai(AI), cb(CB)
{ {
} }
void CPathfindingManager::setCB(CPlayerSpecificInfoCallback * CB) void PathfindingManager::setCB(CPlayerSpecificInfoCallback * CB)
{ {
cb = CB; cb = CB;
pathfinder.reset(new AIPathfinder(cb)); pathfinder.reset(new AIPathfinder(cb));
} }
void CPathfindingManager::setAI(VCAI * AI) void PathfindingManager::setAI(VCAI * AI)
{ {
ai = AI; ai = AI;
} }
Goals::TGoalVec CPathfindingManager::howToVisitTile(int3 tile) Goals::TGoalVec PathfindingManager::howToVisitTile(int3 tile)
{ {
Goals::TGoalVec result; Goals::TGoalVec result;
@ -44,7 +44,7 @@ Goals::TGoalVec CPathfindingManager::howToVisitTile(int3 tile)
return result; return result;
} }
Goals::TGoalVec CPathfindingManager::howToVisitObj(ObjectIdRef obj) Goals::TGoalVec PathfindingManager::howToVisitObj(ObjectIdRef obj)
{ {
Goals::TGoalVec result; Goals::TGoalVec result;
@ -58,7 +58,7 @@ Goals::TGoalVec CPathfindingManager::howToVisitObj(ObjectIdRef obj)
return result; return result;
} }
Goals::TGoalVec CPathfindingManager::howToVisitTile(HeroPtr hero, int3 tile, bool allowGatherArmy) Goals::TGoalVec PathfindingManager::howToVisitTile(HeroPtr hero, int3 tile, bool allowGatherArmy)
{ {
return findPath(hero, tile, allowGatherArmy, [&](int3 firstTileToGet) -> Goals::TSubgoal return findPath(hero, tile, allowGatherArmy, [&](int3 firstTileToGet) -> Goals::TSubgoal
{ {
@ -66,7 +66,7 @@ Goals::TGoalVec CPathfindingManager::howToVisitTile(HeroPtr hero, int3 tile, boo
}); });
} }
Goals::TGoalVec CPathfindingManager::howToVisitObj(HeroPtr hero, ObjectIdRef obj, bool allowGatherArmy) Goals::TGoalVec PathfindingManager::howToVisitObj(HeroPtr hero, ObjectIdRef obj, bool allowGatherArmy)
{ {
if(!obj) if(!obj)
{ {
@ -81,12 +81,12 @@ Goals::TGoalVec CPathfindingManager::howToVisitObj(HeroPtr hero, ObjectIdRef obj
}); });
} }
std::vector<AIPath> CPathfindingManager::getPathsToTile(HeroPtr hero, int3 tile) std::vector<AIPath> PathfindingManager::getPathsToTile(HeroPtr hero, int3 tile)
{ {
return pathfinder->getPathInfo(hero, tile); return pathfinder->getPathInfo(hero, tile);
} }
Goals::TGoalVec CPathfindingManager::findPath( Goals::TGoalVec PathfindingManager::findPath(
HeroPtr hero, HeroPtr hero,
crint3 dest, crint3 dest,
bool allowGatherArmy, bool allowGatherArmy,
@ -141,7 +141,7 @@ Goals::TGoalVec CPathfindingManager::findPath(
return result; return result;
} }
Goals::TSubgoal CPathfindingManager::selectVisitingGoal(HeroPtr hero, ObjectIdRef obj) const Goals::TSubgoal PathfindingManager::selectVisitingGoal(HeroPtr hero, ObjectIdRef obj) const
{ {
int3 dest = obj->visitablePos(); int3 dest = obj->visitablePos();
@ -161,7 +161,7 @@ Goals::TSubgoal CPathfindingManager::selectVisitingGoal(HeroPtr hero, ObjectIdRe
return sptr(Goals::VisitTile(dest).sethero(hero).setisAbstract(true)); return sptr(Goals::VisitTile(dest).sethero(hero).setisAbstract(true));
} }
Goals::TSubgoal CPathfindingManager::clearWayTo(HeroPtr hero, int3 firstTileToGet) Goals::TSubgoal PathfindingManager::clearWayTo(HeroPtr hero, int3 firstTileToGet)
{ {
if(isBlockedBorderGate(firstTileToGet)) if(isBlockedBorderGate(firstTileToGet))
{ {
@ -207,7 +207,7 @@ Goals::TSubgoal CPathfindingManager::clearWayTo(HeroPtr hero, int3 firstTileToGe
return sptr(Goals::VisitTile(firstTileToGet).sethero(hero).setisAbstract(true)); return sptr(Goals::VisitTile(firstTileToGet).sethero(hero).setisAbstract(true));
} }
void CPathfindingManager::resetPaths() void PathfindingManager::resetPaths()
{ {
logAi->debug("AIPathfinder has been reseted."); logAi->debug("AIPathfinder has been reseted.");
pathfinder->clear(); pathfinder->clear();

View File

@ -13,7 +13,7 @@
#include "VCAI.h" #include "VCAI.h"
#include "AINodeStorage.h" #include "AINodeStorage.h"
class IPathfindingManager // : pulbic IAbstractManager class IPathfindingManager
{ {
public: public:
virtual ~IPathfindingManager() = default; virtual ~IPathfindingManager() = default;
@ -28,7 +28,7 @@ public:
virtual std::vector<AIPath> getPathsToTile(HeroPtr hero, int3 tile) = 0; virtual std::vector<AIPath> getPathsToTile(HeroPtr hero, int3 tile) = 0;
}; };
class CPathfindingManager : public IPathfindingManager class PathfindingManager : public IPathfindingManager
{ {
friend class AIhelper; friend class AIhelper;
@ -38,8 +38,8 @@ private:
std::unique_ptr<AIPathfinder> pathfinder; std::unique_ptr<AIPathfinder> pathfinder;
public: public:
CPathfindingManager() = default; PathfindingManager() = default;
CPathfindingManager(CPlayerSpecificInfoCallback * CB, VCAI * AI = nullptr); //for tests only PathfindingManager(CPlayerSpecificInfoCallback * CB, VCAI * AI = nullptr); //for tests only
Goals::TGoalVec howToVisitTile(HeroPtr hero, int3 tile, bool allowGatherArmy = true) override; Goals::TGoalVec howToVisitTile(HeroPtr hero, int3 tile, bool allowGatherArmy = true) override;
Goals::TGoalVec howToVisitObj(HeroPtr hero, ObjectIdRef obj, bool allowGatherArmy = true) override; Goals::TGoalVec howToVisitObj(HeroPtr hero, ObjectIdRef obj, bool allowGatherArmy = true) override;

View File

@ -25,7 +25,7 @@ class IShipyard;
struct CGPathNode; struct CGPathNode;
struct CGPath; struct CGPath;
struct CPathsInfo; struct CPathsInfo;
class CPathfinderConfig; class PathfinderConfig;
struct CPack; struct CPack;
class IBattleEventsReceiver; class IBattleEventsReceiver;
class IGameEventsReceiver; class IGameEventsReceiver;

View File

@ -919,7 +919,7 @@ void CGameInfoCallback::getVisibleTilesInRange(std::unordered_set<int3, ShashInt
gs->getTilesInRange(tiles, pos, radious, getLocalPlayer(), -1, distanceFormula); gs->getTilesInRange(tiles, pos, radious, getLocalPlayer(), -1, distanceFormula);
} }
void CGameInfoCallback::calculatePaths(std::shared_ptr<CPathfinderConfig> config, const CGHeroInstance * hero) void CGameInfoCallback::calculatePaths(std::shared_ptr<PathfinderConfig> config, const CGHeroInstance * hero)
{ {
gs->calculatePaths(config, hero); gs->calculatePaths(config, hero);
} }

View File

@ -31,7 +31,7 @@ struct TeamState;
struct QuestInfo; struct QuestInfo;
struct ShashInt3; struct ShashInt3;
class CGameState; class CGameState;
class CPathfinderConfig; class PathfinderConfig;
class DLL_LINKAGE CGameInfoCallback : public virtual CCallbackBase class DLL_LINKAGE CGameInfoCallback : public virtual CCallbackBase
@ -99,7 +99,7 @@ public:
virtual std::shared_ptr<boost::multi_array<TerrainTile*, 3>> getAllVisibleTiles() const; virtual std::shared_ptr<boost::multi_array<TerrainTile*, 3>> getAllVisibleTiles() const;
virtual bool isInTheMap(const int3 &pos) const; virtual bool isInTheMap(const int3 &pos) const;
virtual void getVisibleTilesInRange(std::unordered_set<int3, ShashInt3> &tiles, int3 pos, int radious, int3::EDistanceFormula distanceFormula = int3::DIST_2D) const; virtual void getVisibleTilesInRange(std::unordered_set<int3, ShashInt3> &tiles, int3 pos, int radious, int3::EDistanceFormula distanceFormula = int3::DIST_2D) const;
virtual void calculatePaths(std::shared_ptr<CPathfinderConfig> config, const CGHeroInstance * hero); virtual void calculatePaths(std::shared_ptr<PathfinderConfig> config, const CGHeroInstance * hero);
//town //town
virtual const CGTownInstance* getTown(ObjectInstanceID objid) const; virtual const CGTownInstance* getTown(ObjectInstanceID objid) const;

View File

@ -1979,7 +1979,7 @@ void CGameState::calculatePaths(const CGHeroInstance *hero, CPathsInfo &out)
pathfinder.calculatePaths(); pathfinder.calculatePaths();
} }
void CGameState::calculatePaths(std::shared_ptr<CPathfinderConfig> config, const CGHeroInstance * hero) void CGameState::calculatePaths(std::shared_ptr<PathfinderConfig> config, const CGHeroInstance * hero)
{ {
CPathfinder pathfinder(this, hero, config); CPathfinder pathfinder(this, hero, config);
pathfinder.calculatePaths(); pathfinder.calculatePaths();

View File

@ -178,7 +178,7 @@ public:
PlayerRelations::PlayerRelations getPlayerRelations(PlayerColor color1, PlayerColor color2); PlayerRelations::PlayerRelations getPlayerRelations(PlayerColor color1, PlayerColor color2);
bool checkForVisitableDir(const int3 & src, const int3 & dst) const; //check if src tile is visitable from dst tile bool checkForVisitableDir(const int3 & src, const int3 & dst) const; //check if src tile is visitable from dst tile
void calculatePaths(const CGHeroInstance *hero, CPathsInfo &out); //calculates possible paths for hero, by default uses current hero position and movement left; returns pointer to newly allocated CPath or nullptr if path does not exists void calculatePaths(const CGHeroInstance *hero, CPathsInfo &out); //calculates possible paths for hero, by default uses current hero position and movement left; returns pointer to newly allocated CPath or nullptr if path does not exists
void calculatePaths(std::shared_ptr<CPathfinderConfig> config, const CGHeroInstance * hero); void calculatePaths(std::shared_ptr<PathfinderConfig> config, const CGHeroInstance * hero);
int3 guardingCreaturePosition (int3 pos) const; int3 guardingCreaturePosition (int3 pos) const;
std::vector<CGObjectInstance*> guardingCreatures (int3 pos) const; std::vector<CGObjectInstance*> guardingCreatures (int3 pos) const;
void updateRumor(); void updateRumor();

View File

@ -25,10 +25,10 @@ bool canSeeObj(const CGObjectInstance * obj)
return obj != nullptr && obj->ID != Obj::EVENT; return obj != nullptr && obj->ID != Obj::EVENT;
} }
std::vector<CGPathNode *> CNodeStorage::calculateNeighbours( std::vector<CGPathNode *> NodeStorage::calculateNeighbours(
CPathNodeInfo & source, const PathNodeInfo & source,
CPathfinderConfig * pathfinderConfig, const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) const CPathfinderHelper * pathfinderHelper)
{ {
std::vector<CGPathNode *> neighbours; std::vector<CGPathNode *> neighbours;
auto accessibleNeighbourTiles = pathfinderHelper->getNeighbourTiles(source); auto accessibleNeighbourTiles = pathfinderHelper->getNeighbourTiles(source);
@ -49,10 +49,10 @@ std::vector<CGPathNode *> CNodeStorage::calculateNeighbours(
return neighbours; return neighbours;
} }
std::vector<CGPathNode *> CNodeStorage::calculateTeleportations( std::vector<CGPathNode *> NodeStorage::calculateTeleportations(
CPathNodeInfo & source, const PathNodeInfo & source,
CPathfinderConfig * pathfinderConfig, const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) const CPathfinderHelper * pathfinderHelper)
{ {
std::vector<CGPathNode *> neighbours; std::vector<CGPathNode *> neighbours;
auto accessibleExits = pathfinderHelper->getTeleportExits(source); auto accessibleExits = pathfinderHelper->getTeleportExits(source);
@ -67,7 +67,7 @@ std::vector<CGPathNode *> CNodeStorage::calculateTeleportations(
return neighbours; return neighbours;
} }
std::vector<int3> CPathfinderHelper::getNeighbourTiles(CPathNodeInfo & source) const std::vector<int3> CPathfinderHelper::getNeighbourTiles(const PathNodeInfo & source) const
{ {
std::vector<int3> neighbourTiles; std::vector<int3> neighbourTiles;
@ -89,19 +89,19 @@ std::vector<int3> CPathfinderHelper::getNeighbourTiles(CPathNodeInfo & source) c
return neighbourTiles; return neighbourTiles;
} }
CNodeStorage::CNodeStorage(CPathsInfo & pathsInfo, const CGHeroInstance * hero) NodeStorage::NodeStorage(CPathsInfo & pathsInfo, const CGHeroInstance * hero)
:out(pathsInfo) :out(pathsInfo)
{ {
out.hero = hero; out.hero = hero;
out.hpos = hero->getPosition(false); out.hpos = hero->getPosition(false);
} }
CGPathNode * CNodeStorage::getNode(const int3 & coord, const EPathfindingLayer layer) CGPathNode * NodeStorage::getNode(const int3 & coord, const EPathfindingLayer layer)
{ {
return out.getNode(coord, layer); return out.getNode(coord, layer);
} }
void CNodeStorage::resetTile( void NodeStorage::resetTile(
const int3 & tile, const int3 & tile,
EPathfindingLayer layer, EPathfindingLayer layer,
CGPathNode::EAccessibility accessibility) CGPathNode::EAccessibility accessibility)
@ -109,7 +109,7 @@ void CNodeStorage::resetTile(
getNode(tile, layer)->update(tile, layer, accessibility); getNode(tile, layer)->update(tile, layer, accessibility);
} }
CGPathNode * CNodeStorage::getInitialNode() CGPathNode * NodeStorage::getInitialNode()
{ {
auto initialNode = getNode(out.hpos, out.hero->boat ? EPathfindingLayer::SAIL : EPathfindingLayer::LAND); auto initialNode = getNode(out.hpos, out.hero->boat ? EPathfindingLayer::SAIL : EPathfindingLayer::LAND);
@ -119,7 +119,7 @@ CGPathNode * CNodeStorage::getInitialNode()
return initialNode; return initialNode;
} }
void CNodeStorage::commit(CDestinationNodeInfo & destination, CPathNodeInfo & source) void NodeStorage::commit(CDestinationNodeInfo & destination, const PathNodeInfo & source)
{ {
assert(destination.node != source.node->theNodeBefore); //two tiles can't point to each other assert(destination.node != source.node->theNodeBefore); //two tiles can't point to each other
destination.node->moveRemains = destination.movementLeft; destination.node->moveRemains = destination.movementLeft;
@ -145,10 +145,10 @@ PathfinderOptions::PathfinderOptions()
originalMovementRules = settings["pathfinder"]["originalMovementRules"].Bool(); originalMovementRules = settings["pathfinder"]["originalMovementRules"].Bool();
} }
void CMovementCostRule::process( void MovementCostRule::process(
CPathNodeInfo & source, const PathNodeInfo & source,
CDestinationNodeInfo & destination, CDestinationNodeInfo & destination,
CPathfinderConfig * pathfinderConfig, const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) const CPathfinderHelper * pathfinderHelper) const
{ {
int turnAtNextTile = destination.turn, moveAtNextTile = destination.movementLeft; int turnAtNextTile = destination.turn, moveAtNextTile = destination.movementLeft;
@ -183,7 +183,7 @@ void CMovementCostRule::process(
destination.blocked = true; destination.blocked = true;
} }
CPathfinderConfig::CPathfinderConfig( PathfinderConfig::PathfinderConfig(
std::shared_ptr<INodeStorage> nodeStorage, std::shared_ptr<INodeStorage> nodeStorage,
std::vector<std::shared_ptr<IPathfindingRule>> rules) std::vector<std::shared_ptr<IPathfindingRule>> rules)
: nodeStorage(nodeStorage), rules(rules), options() : nodeStorage(nodeStorage), rules(rules), options()
@ -197,14 +197,14 @@ CPathfinder::CPathfinder(
: CPathfinder( : CPathfinder(
_gs, _gs,
_hero, _hero,
std::make_shared<CPathfinderConfig>( std::make_shared<PathfinderConfig>(
std::make_shared<CNodeStorage>(_out, _hero), std::make_shared<NodeStorage>(_out, _hero),
std::vector<std::shared_ptr<IPathfindingRule>>{ std::vector<std::shared_ptr<IPathfindingRule>>{
std::make_shared<CLayerTransitionRule>(), std::make_shared<LayerTransitionRule>(),
std::make_shared<CDestinationActionRule>(), std::make_shared<DestinationActionRule>(),
std::make_shared<CMovementToDestinationRule>(), std::make_shared<MovementToDestinationRule>(),
std::make_shared<CMovementCostRule>(), std::make_shared<MovementCostRule>(),
std::make_shared<CMovementAfterDestinationRule>() std::make_shared<MovementAfterDestinationRule>()
})) }))
{ {
} }
@ -212,7 +212,7 @@ CPathfinder::CPathfinder(
CPathfinder::CPathfinder( CPathfinder::CPathfinder(
CGameState * _gs, CGameState * _gs,
const CGHeroInstance * _hero, const CGHeroInstance * _hero,
std::shared_ptr<CPathfinderConfig> config) std::shared_ptr<PathfinderConfig> config)
: CGameInfoCallback(_gs, boost::optional<PlayerColor>()) : CGameInfoCallback(_gs, boost::optional<PlayerColor>())
, hero(_hero) , hero(_hero)
, FoW(getPlayerTeam(hero->tempOwner)->fogOfWarMap), patrolTiles({}) , FoW(getPlayerTeam(hero->tempOwner)->fogOfWarMap), patrolTiles({})
@ -368,7 +368,7 @@ std::vector<int3> CPathfinderHelper::getAllowedTeleportChannelExits(TeleportChan
return allowedExits; return allowedExits;
} }
std::vector<int3> CPathfinderHelper::getCastleGates(CPathNodeInfo & source) const std::vector<int3> CPathfinderHelper::getCastleGates(const PathNodeInfo & source) const
{ {
std::vector<int3> allowedExits; std::vector<int3> allowedExits;
@ -385,7 +385,7 @@ std::vector<int3> CPathfinderHelper::getCastleGates(CPathNodeInfo & source) cons
return allowedExits; return allowedExits;
} }
std::vector<int3> CPathfinderHelper::getTeleportExits(CPathNodeInfo & source) const std::vector<int3> CPathfinderHelper::getTeleportExits(const PathNodeInfo & source) const
{ {
std::vector<int3> teleportationExits; std::vector<int3> teleportationExits;
@ -474,10 +474,10 @@ bool CPathfinder::isLayerTransitionPossible(const ELayer destLayer) const
return false; return false;
} }
void CLayerTransitionRule::process( void LayerTransitionRule::process(
CPathNodeInfo & source, const PathNodeInfo & source,
CDestinationNodeInfo & destination, CDestinationNodeInfo & destination,
CPathfinderConfig * pathfinderConfig, const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) const CPathfinderHelper * pathfinderHelper) const
{ {
if(source.node->layer == destination.node->layer) if(source.node->layer == destination.node->layer)
@ -536,11 +536,11 @@ void CLayerTransitionRule::process(
} }
} }
CPathfinderBlockingRule::BlockingReason CMovementToDestinationRule::getBlockingReason( PathfinderBlockingRule::BlockingReason MovementToDestinationRule::getBlockingReason(
CPathNodeInfo & source, const PathNodeInfo & source,
CDestinationNodeInfo & destination, const CDestinationNodeInfo & destination,
CPathfinderConfig * pathfinderConfig, const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) const const CPathfinderHelper * pathfinderHelper) const
{ {
if(destination.node->accessible == CGPathNode::BLOCKED) if(destination.node->accessible == CGPathNode::BLOCKED)
@ -607,10 +607,10 @@ CPathfinderBlockingRule::BlockingReason CMovementToDestinationRule::getBlockingR
} }
void CMovementAfterDestinationRule::process( void MovementAfterDestinationRule::process(
CPathNodeInfo & source, const PathNodeInfo & source,
CDestinationNodeInfo & destination, CDestinationNodeInfo & destination,
CPathfinderConfig * config, const PathfinderConfig * config,
CPathfinderHelper * pathfinderHelper) const CPathfinderHelper * pathfinderHelper) const
{ {
auto blocker = getBlockingReason(source, destination, config, pathfinderHelper); auto blocker = getBlockingReason(source, destination, config, pathfinderHelper);
@ -623,11 +623,11 @@ void CMovementAfterDestinationRule::process(
destination.blocked = blocker != BlockingReason::NONE; destination.blocked = blocker != BlockingReason::NONE;
} }
CPathfinderBlockingRule::BlockingReason CMovementAfterDestinationRule::getBlockingReason( PathfinderBlockingRule::BlockingReason MovementAfterDestinationRule::getBlockingReason(
CPathNodeInfo & source, const PathNodeInfo & source,
CDestinationNodeInfo & destination, const CDestinationNodeInfo & destination,
CPathfinderConfig * config, const PathfinderConfig * config,
CPathfinderHelper * pathfinderHelper) const const CPathfinderHelper * pathfinderHelper) const
{ {
switch(destination.action) switch(destination.action)
{ {
@ -686,10 +686,10 @@ CPathfinderBlockingRule::BlockingReason CMovementAfterDestinationRule::getBlocki
return BlockingReason::DESTINATION_BLOCKED; return BlockingReason::DESTINATION_BLOCKED;
} }
void CDestinationActionRule::process( void DestinationActionRule::process(
CPathNodeInfo & source, const PathNodeInfo & source,
CDestinationNodeInfo & destination, CDestinationNodeInfo & destination,
CPathfinderConfig * pathfinderConfig, const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) const CPathfinderHelper * pathfinderHelper) const
{ {
if(destination.action != CGPathNode::ENodeAction::UNKNOWN) if(destination.action != CGPathNode::ENodeAction::UNKNOWN)
@ -1008,7 +1008,7 @@ int CPathfinderHelper::movementPointsAfterEmbark(int movement, int turn, int act
return hero->movementPointsAfterEmbark(movement, turn, action, getTurnInfo()); return hero->movementPointsAfterEmbark(movement, turn, action, getTurnInfo());
} }
bool CPathfinderHelper::passOneTurnLimitCheck(CPathNodeInfo & source) const bool CPathfinderHelper::passOneTurnLimitCheck(const PathNodeInfo & source) const
{ {
if(!options.oneTurnSpecialLayersLimit) if(!options.oneTurnSpecialLayersLimit)
@ -1419,12 +1419,12 @@ CGPathNode * CPathsInfo::getNode(const int3 & coord, const ELayer layer)
return &nodes[coord.x][coord.y][coord.z][layer]; return &nodes[coord.x][coord.y][coord.z][layer];
} }
CPathNodeInfo::CPathNodeInfo() PathNodeInfo::PathNodeInfo()
: node(nullptr), nodeObject(nullptr), tile(nullptr), coord(-1, -1, -1), guarded(false) : node(nullptr), nodeObject(nullptr), tile(nullptr), coord(-1, -1, -1), guarded(false)
{ {
} }
void CPathNodeInfo::setNode(CGameState * gs, CGPathNode * n, bool excludeTopObject) void PathNodeInfo::setNode(CGameState * gs, CGPathNode * n, bool excludeTopObject)
{ {
node = n; node = n;
@ -1441,13 +1441,13 @@ void CPathNodeInfo::setNode(CGameState * gs, CGPathNode * n, bool excludeTopObje
} }
CDestinationNodeInfo::CDestinationNodeInfo() CDestinationNodeInfo::CDestinationNodeInfo()
: CPathNodeInfo(), blocked(false), action(CGPathNode::ENodeAction::UNKNOWN) : PathNodeInfo(), blocked(false), action(CGPathNode::ENodeAction::UNKNOWN)
{ {
} }
void CDestinationNodeInfo::setNode(CGameState * gs, CGPathNode * n, bool excludeTopObject) void CDestinationNodeInfo::setNode(CGameState * gs, CGPathNode * n, bool excludeTopObject)
{ {
CPathNodeInfo::setNode(gs, n, excludeTopObject); PathNodeInfo::setNode(gs, n, excludeTopObject);
blocked = false; blocked = false;
action = CGPathNode::ENodeAction::UNKNOWN; action = CGPathNode::ENodeAction::UNKNOWN;
@ -1466,7 +1466,7 @@ bool CDestinationNodeInfo::isBetterWay() const
} }
bool CPathNodeInfo::isNodeObjectVisitable() const bool PathNodeInfo::isNodeObjectVisitable() const
{ {
/// Hero can't visit objects while walking on water or flying /// Hero can't visit objects while walking on water or flying
return canSeeObj(nodeObject) && (node->layer == EPathfindingLayer::LAND || node->layer == EPathfindingLayer::SAIL); return canSeeObj(nodeObject) && (node->layer == EPathfindingLayer::LAND || node->layer == EPathfindingLayer::SAIL);

View File

@ -24,7 +24,7 @@ class CMap;
class CGWhirlpool; class CGWhirlpool;
class CPathfinderHelper; class CPathfinderHelper;
class CPathfinder; class CPathfinder;
class CPathfinderConfig; class PathfinderConfig;
struct DLL_LINKAGE CGPathNode struct DLL_LINKAGE CGPathNode
{ {
@ -99,7 +99,7 @@ struct DLL_LINKAGE CPathsInfo
CGPathNode * getNode(const int3 & coord, const ELayer layer); CGPathNode * getNode(const int3 & coord, const ELayer layer);
}; };
struct DLL_LINKAGE CPathNodeInfo struct DLL_LINKAGE PathNodeInfo
{ {
CGPathNode * node; CGPathNode * node;
const CGObjectInstance * nodeObject; const CGObjectInstance * nodeObject;
@ -108,14 +108,14 @@ struct DLL_LINKAGE CPathNodeInfo
bool guarded; bool guarded;
PlayerRelations::PlayerRelations objectRelations; PlayerRelations::PlayerRelations objectRelations;
CPathNodeInfo(); PathNodeInfo();
virtual void setNode(CGameState * gs, CGPathNode * n, bool excludeTopObject = false); virtual void setNode(CGameState * gs, CGPathNode * n, bool excludeTopObject = false);
bool isNodeObjectVisitable() const; bool isNodeObjectVisitable() const;
}; };
struct DLL_LINKAGE CDestinationNodeInfo : public CPathNodeInfo struct DLL_LINKAGE CDestinationNodeInfo : public PathNodeInfo
{ {
CGPathNode::ENodeAction action; CGPathNode::ENodeAction action;
int turn; int turn;
@ -134,49 +134,49 @@ class IPathfindingRule
{ {
public: public:
virtual void process( virtual void process(
CPathNodeInfo & source, const PathNodeInfo & source,
CDestinationNodeInfo & destination, CDestinationNodeInfo & destination,
CPathfinderConfig * pathfinderConfig, const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) const = 0; CPathfinderHelper * pathfinderHelper) const = 0;
}; };
class DLL_LINKAGE CMovementCostRule : public IPathfindingRule class DLL_LINKAGE MovementCostRule : public IPathfindingRule
{ {
public: public:
virtual void process( virtual void process(
CPathNodeInfo & source, const PathNodeInfo & source,
CDestinationNodeInfo & destination, CDestinationNodeInfo & destination,
CPathfinderConfig * pathfinderConfig, const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) const override; CPathfinderHelper * pathfinderHelper) const override;
}; };
class DLL_LINKAGE CLayerTransitionRule : public IPathfindingRule class DLL_LINKAGE LayerTransitionRule : public IPathfindingRule
{ {
public: public:
virtual void process( virtual void process(
CPathNodeInfo & source, const PathNodeInfo & source,
CDestinationNodeInfo & destination, CDestinationNodeInfo & destination,
CPathfinderConfig * pathfinderConfig, const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) const override; CPathfinderHelper * pathfinderHelper) const override;
}; };
class DLL_LINKAGE CDestinationActionRule : public IPathfindingRule class DLL_LINKAGE DestinationActionRule : public IPathfindingRule
{ {
public: public:
virtual void process( virtual void process(
CPathNodeInfo & source, const PathNodeInfo & source,
CDestinationNodeInfo & destination, CDestinationNodeInfo & destination,
CPathfinderConfig * pathfinderConfig, const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) const override; CPathfinderHelper * pathfinderHelper) const override;
}; };
class DLL_LINKAGE CPathfinderBlockingRule : public IPathfindingRule class DLL_LINKAGE PathfinderBlockingRule : public IPathfindingRule
{ {
public: public:
virtual void process( virtual void process(
CPathNodeInfo & source, const PathNodeInfo & source,
CDestinationNodeInfo & destination, CDestinationNodeInfo & destination,
CPathfinderConfig * pathfinderConfig, const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) const override CPathfinderHelper * pathfinderHelper) const override
{ {
auto blockingReason = getBlockingReason(source, destination, pathfinderConfig, pathfinderHelper); auto blockingReason = getBlockingReason(source, destination, pathfinderConfig, pathfinderHelper);
@ -197,37 +197,37 @@ protected:
}; };
virtual BlockingReason getBlockingReason( virtual BlockingReason getBlockingReason(
CPathNodeInfo & source, const PathNodeInfo & source,
CDestinationNodeInfo & destination, const CDestinationNodeInfo & destination,
CPathfinderConfig * pathfinderConfig, const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) const = 0; const CPathfinderHelper * pathfinderHelper) const = 0;
}; };
class DLL_LINKAGE CMovementAfterDestinationRule : public CPathfinderBlockingRule class DLL_LINKAGE MovementAfterDestinationRule : public PathfinderBlockingRule
{ {
public: public:
virtual void process( virtual void process(
CPathNodeInfo & source, const PathNodeInfo & source,
CDestinationNodeInfo & destination, CDestinationNodeInfo & destination,
CPathfinderConfig * pathfinderConfig, const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) const override; CPathfinderHelper * pathfinderHelper) const override;
protected: protected:
virtual BlockingReason getBlockingReason( virtual BlockingReason getBlockingReason(
CPathNodeInfo & source, const PathNodeInfo & source,
CDestinationNodeInfo & destination, const CDestinationNodeInfo & destination,
CPathfinderConfig * pathfinderConfig, const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) const override; const CPathfinderHelper * pathfinderHelper) const override;
}; };
class DLL_LINKAGE CMovementToDestinationRule : public CPathfinderBlockingRule class DLL_LINKAGE MovementToDestinationRule : public PathfinderBlockingRule
{ {
protected: protected:
virtual BlockingReason getBlockingReason( virtual BlockingReason getBlockingReason(
CPathNodeInfo & source, const PathNodeInfo & source,
CDestinationNodeInfo & destination, const CDestinationNodeInfo & destination,
CPathfinderConfig * pathfinderConfig, const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) const override; const CPathfinderHelper * pathfinderHelper) const override;
}; };
@ -238,45 +238,45 @@ public:
virtual void resetTile(const int3 & tile, EPathfindingLayer layer, CGPathNode::EAccessibility accessibility) = 0; virtual void resetTile(const int3 & tile, EPathfindingLayer layer, CGPathNode::EAccessibility accessibility) = 0;
virtual std::vector<CGPathNode *> calculateNeighbours( virtual std::vector<CGPathNode *> calculateNeighbours(
CPathNodeInfo & source, const PathNodeInfo & source,
CPathfinderConfig * pathfinderConfig, const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) = 0; const CPathfinderHelper * pathfinderHelper) = 0;
virtual std::vector<CGPathNode *> calculateTeleportations( virtual std::vector<CGPathNode *> calculateTeleportations(
CPathNodeInfo & source, const PathNodeInfo & source,
CPathfinderConfig * pathfinderConfig, const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) = 0; const CPathfinderHelper * pathfinderHelper) = 0;
virtual void commit(CDestinationNodeInfo & destination, CPathNodeInfo & source) = 0; virtual void commit(CDestinationNodeInfo & destination, const PathNodeInfo & source) = 0;
}; };
class DLL_LINKAGE CNodeStorage : public INodeStorage class DLL_LINKAGE NodeStorage : public INodeStorage
{ {
private: private:
CPathsInfo & out; CPathsInfo & out;
public: public:
CNodeStorage(CPathsInfo & pathsInfo, const CGHeroInstance * hero); NodeStorage(CPathsInfo & pathsInfo, const CGHeroInstance * hero);
CGPathNode * getNode(const int3 & coord, const EPathfindingLayer layer); CGPathNode * getNode(const int3 & coord, const EPathfindingLayer layer);
virtual CGPathNode * getInitialNode() override; virtual CGPathNode * getInitialNode() override;
virtual std::vector<CGPathNode *> calculateNeighbours( virtual std::vector<CGPathNode *> calculateNeighbours(
CPathNodeInfo & source, const PathNodeInfo & source,
CPathfinderConfig * pathfinderConfig, const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) override; const CPathfinderHelper * pathfinderHelper) override;
virtual std::vector<CGPathNode *> calculateTeleportations( virtual std::vector<CGPathNode *> calculateTeleportations(
CPathNodeInfo & source, const PathNodeInfo & source,
CPathfinderConfig * pathfinderConfig, const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) override; const CPathfinderHelper * pathfinderHelper) override;
virtual void resetTile( virtual void resetTile(
const int3 & tile, const int3 & tile,
EPathfindingLayer layer, EPathfindingLayer layer,
CGPathNode::EAccessibility accessibility) override; CGPathNode::EAccessibility accessibility) override;
virtual void commit(CDestinationNodeInfo & destination, CPathNodeInfo & source) override; virtual void commit(CDestinationNodeInfo & destination, const PathNodeInfo & source) override;
}; };
struct DLL_LINKAGE PathfinderOptions struct DLL_LINKAGE PathfinderOptions
@ -330,14 +330,14 @@ struct DLL_LINKAGE PathfinderOptions
PathfinderOptions(); PathfinderOptions();
}; };
class DLL_LINKAGE CPathfinderConfig class DLL_LINKAGE PathfinderConfig
{ {
public: public:
std::shared_ptr<INodeStorage> nodeStorage; std::shared_ptr<INodeStorage> nodeStorage;
std::vector<std::shared_ptr<IPathfindingRule>> rules; std::vector<std::shared_ptr<IPathfindingRule>> rules;
PathfinderOptions options; PathfinderOptions options;
CPathfinderConfig( PathfinderConfig(
std::shared_ptr<INodeStorage> nodeStorage, std::shared_ptr<INodeStorage> nodeStorage,
std::vector<std::shared_ptr<IPathfindingRule>> rules); std::vector<std::shared_ptr<IPathfindingRule>> rules);
}; };
@ -351,7 +351,7 @@ public:
CPathfinder( CPathfinder(
CGameState * _gs, CGameState * _gs,
const CGHeroInstance * _hero, const CGHeroInstance * _hero,
std::shared_ptr<CPathfinderConfig> config); std::shared_ptr<PathfinderConfig> config);
void calculatePaths(); //calculates possible paths for hero, uses current hero position and movement left; returns pointer to newly allocated CPath or nullptr if path does not exists void calculatePaths(); //calculates possible paths for hero, uses current hero position and movement left; returns pointer to newly allocated CPath or nullptr if path does not exists
@ -361,7 +361,7 @@ private:
const CGHeroInstance * hero; const CGHeroInstance * hero;
const std::vector<std::vector<std::vector<ui8> > > &FoW; const std::vector<std::vector<std::vector<ui8> > > &FoW;
std::unique_ptr<CPathfinderHelper> hlp; std::unique_ptr<CPathfinderHelper> hlp;
std::shared_ptr<CPathfinderConfig> config; std::shared_ptr<PathfinderConfig> config;
enum EPatrolState { enum EPatrolState {
PATROL_NONE = 0, PATROL_NONE = 0,
@ -384,7 +384,7 @@ private:
}; };
boost::heap::priority_queue<CGPathNode *, boost::heap::compare<NodeComparer> > pq; boost::heap::priority_queue<CGPathNode *, boost::heap::compare<NodeComparer> > pq;
CPathNodeInfo source; //current (source) path node -> we took it from the queue PathNodeInfo source; //current (source) path node -> we took it from the queue
CDestinationNodeInfo destination; //destination node -> it's a neighbour of source that we consider CDestinationNodeInfo destination; //destination node -> it's a neighbour of source that we consider
bool isHeroPatrolLocked() const; bool isHeroPatrolLocked() const;
@ -449,7 +449,7 @@ public:
bool hasBonusOfType(const Bonus::BonusType type, const int subtype = -1) const; bool hasBonusOfType(const Bonus::BonusType type, const int subtype = -1) const;
int getMaxMovePoints(const EPathfindingLayer layer) const; int getMaxMovePoints(const EPathfindingLayer layer) const;
std::vector<int3> getCastleGates(CPathNodeInfo & source) const; std::vector<int3> getCastleGates(const PathNodeInfo & source) const;
bool isAllowedTeleportEntrance(const CGTeleport * obj) const; bool isAllowedTeleportEntrance(const CGTeleport * obj) const;
std::vector<int3> getAllowedTeleportChannelExits(TeleportChannelID channelID) const; std::vector<int3> getAllowedTeleportChannelExits(TeleportChannelID channelID) const;
bool addTeleportTwoWay(const CGTeleport * obj) const; bool addTeleportTwoWay(const CGTeleport * obj) const;
@ -458,8 +458,8 @@ public:
bool addTeleportWhirlpool(const CGWhirlpool * obj) const; bool addTeleportWhirlpool(const CGWhirlpool * obj) const;
bool canMoveBetween(const int3 & a, const int3 & b) const; //checks only for visitable objects that may make moving between tiles impossible, not other conditions (like tiles itself accessibility) bool canMoveBetween(const int3 & a, const int3 & b) const; //checks only for visitable objects that may make moving between tiles impossible, not other conditions (like tiles itself accessibility)
std::vector<int3> getNeighbourTiles(CPathNodeInfo & source) const; std::vector<int3> getNeighbourTiles(const PathNodeInfo & source) const;
std::vector<int3> getTeleportExits(CPathNodeInfo & source) const; std::vector<int3> getTeleportExits(const PathNodeInfo & source) const;
void getNeighbours( void getNeighbours(
const TerrainTile & srct, const TerrainTile & srct,
@ -477,8 +477,8 @@ public:
const bool checkLast = true) const; const bool checkLast = true) const;
int getMovementCost( int getMovementCost(
const CPathNodeInfo & src, const PathNodeInfo & src,
const CPathNodeInfo & dst, const PathNodeInfo & dst,
const int remainingMovePoints = -1, const int remainingMovePoints = -1,
const bool checkLast = true) const const bool checkLast = true) const
{ {
@ -494,5 +494,5 @@ public:
int getHeroMaxMovementPoints(EPathfindingLayer layer) const; int getHeroMaxMovementPoints(EPathfindingLayer layer) const;
int movementPointsAfterEmbark(int movement, int cost, int action) const; int movementPointsAfterEmbark(int movement, int cost, int action) const;
bool passOneTurnLimitCheck(CPathNodeInfo & source) const; bool passOneTurnLimitCheck(const PathNodeInfo & source) const;
}; };