mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
AI pathfinding: rename and add const to functions
This commit is contained in:
parent
cf213a5acf
commit
f327c46fa3
@ -17,8 +17,7 @@ AIhelper::AIhelper()
|
||||
{
|
||||
resourceManager.reset(new ResourceManager());
|
||||
buildingManager.reset(new BuildingManager());
|
||||
pathfindingManager.reset(new CPathfindingManager());
|
||||
//TODO: push to vector
|
||||
pathfindingManager.reset(new PathfindingManager());
|
||||
}
|
||||
|
||||
AIhelper::~AIhelper()
|
||||
@ -32,7 +31,6 @@ bool AIhelper::notifyGoalCompleted(Goals::TSubgoal goal)
|
||||
|
||||
void AIhelper::setCB(CPlayerSpecificInfoCallback * CB)
|
||||
{
|
||||
//TODO: for
|
||||
resourceManager->setCB(CB);
|
||||
buildingManager->setCB(CB);
|
||||
pathfindingManager->setCB(CB);
|
||||
@ -40,7 +38,6 @@ void AIhelper::setCB(CPlayerSpecificInfoCallback * CB)
|
||||
|
||||
void AIhelper::setAI(VCAI * AI)
|
||||
{
|
||||
//TODO: for loop
|
||||
resourceManager->setAI(AI);
|
||||
buildingManager->setAI(AI);
|
||||
pathfindingManager->setAI(AI);
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
#include "ResourceManager.h"
|
||||
#include "BuildingManager.h"
|
||||
#include "Pathfinding/CPathfindingManager.h"
|
||||
#include "Pathfinding/PathfindingManager.h"
|
||||
|
||||
class ResourceManager;
|
||||
class BuildingManager;
|
||||
@ -30,7 +30,7 @@ class DLL_EXPORT AIhelper : public IResourceManager, public IBuildingManager, pu
|
||||
|
||||
std::shared_ptr<ResourceManager> resourceManager;
|
||||
std::shared_ptr<BuildingManager> buildingManager;
|
||||
std::shared_ptr<CPathfindingManager> pathfindingManager;
|
||||
std::shared_ptr<PathfindingManager> pathfindingManager;
|
||||
//TODO: vector<IAbstractManager>
|
||||
public:
|
||||
AIhelper();
|
||||
|
@ -11,7 +11,7 @@ set(VCAI_SRCS
|
||||
Pathfinding/AIPathfinderConfig.cpp
|
||||
Pathfinding/AIPathfinder.cpp
|
||||
Pathfinding/AINodeStorage.cpp
|
||||
Pathfinding/CPathfindingManager.cpp
|
||||
Pathfinding/PathfindingManager.cpp
|
||||
AIUtility.cpp
|
||||
AIhelper.cpp
|
||||
ResourceManager.cpp
|
||||
@ -32,7 +32,7 @@ set(VCAI_HEADERS
|
||||
Pathfinding/AIPathfinderConfig.h
|
||||
Pathfinding/AIPathfinder.h
|
||||
Pathfinding/AINodeStorage.h
|
||||
Pathfinding/CPathfindingManager.h
|
||||
Pathfinding/PathfindingManager.h
|
||||
AIUtility.h
|
||||
AIhelper.h
|
||||
ResourceManager.h
|
||||
|
@ -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;
|
||||
}
|
||||
@ -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);
|
||||
auto srcNode = getAINode(source);
|
||||
const AIPathNode * srcNode = getAINode(source.node);
|
||||
|
||||
updateAINode(destination.node, [&](AIPathNode * dstNode) {
|
||||
dstNode->moveRemains = destination.movementLeft;
|
||||
dstNode->turns = destination.turn;
|
||||
dstNode->danger = srcNode->danger;
|
||||
dstNode->action = destination.action;
|
||||
dstNode->theNodeBefore = srcNode->theNodeBefore;
|
||||
});
|
||||
}
|
||||
|
||||
std::vector<CGPathNode *> AINodeStorage::calculateNeighbours(
|
||||
CPathNodeInfo & source,
|
||||
CPathfinderConfig * pathfinderConfig,
|
||||
CPathfinderHelper * pathfinderHelper)
|
||||
const PathNodeInfo & source,
|
||||
const PathfinderConfig * pathfinderConfig,
|
||||
const CPathfinderHelper * pathfinderHelper)
|
||||
{
|
||||
std::vector<CGPathNode *> neighbours;
|
||||
auto srcNode = getAINode(source);
|
||||
const AIPathNode * srcNode = getAINode(source.node);
|
||||
auto accessibleNeighbourTiles = pathfinderHelper->getNeighbourTiles(source);
|
||||
|
||||
for(auto & neighbour : accessibleNeighbourTiles)
|
||||
@ -102,13 +105,13 @@ std::vector<CGPathNode *> AINodeStorage::calculateNeighbours(
|
||||
}
|
||||
|
||||
std::vector<CGPathNode *> AINodeStorage::calculateTeleportations(
|
||||
CPathNodeInfo & source,
|
||||
CPathfinderConfig * pathfinderConfig,
|
||||
CPathfinderHelper * pathfinderHelper)
|
||||
const PathNodeInfo & source,
|
||||
const PathfinderConfig * pathfinderConfig,
|
||||
const CPathfinderHelper * pathfinderHelper)
|
||||
{
|
||||
std::vector<CGPathNode *> neighbours;
|
||||
auto accessibleExits = pathfinderHelper->getTeleportExits(source);
|
||||
auto srcNode = getAINode(source);
|
||||
auto srcNode = getAINode(source.node);
|
||||
|
||||
for(auto & neighbour : accessibleExits)
|
||||
{
|
||||
@ -120,11 +123,11 @@ std::vector<CGPathNode *> AINodeStorage::calculateTeleportations(
|
||||
return neighbours;
|
||||
}
|
||||
|
||||
bool AINodeStorage::hasBetterChain(CPathNodeInfo & source, CDestinationNodeInfo & destination) const
|
||||
bool AINodeStorage::hasBetterChain(const PathNodeInfo & source, CDestinationNodeInfo & destination) const
|
||||
{
|
||||
auto pos = destination.coord;
|
||||
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)
|
||||
{
|
||||
@ -154,7 +157,7 @@ bool AINodeStorage::hasBetterChain(CPathNodeInfo & source, CDestinationNodeInfo
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<AIPath> AINodeStorage::getChainInfo(int3 pos)
|
||||
std::vector<AIPath> AINodeStorage::getChainInfo(int3 pos) const
|
||||
{
|
||||
std::vector<AIPath> paths;
|
||||
auto chains = nodes[pos.x][pos.y][pos.z][EPathfindingLayer::LAND];
|
||||
|
@ -74,23 +74,24 @@ public:
|
||||
virtual void resetTile(const int3 & tile, EPathfindingLayer layer, CGPathNode::EAccessibility accessibility) override;
|
||||
|
||||
virtual std::vector<CGPathNode *> calculateNeighbours(
|
||||
CPathNodeInfo & source,
|
||||
CPathfinderConfig * pathfinderConfig,
|
||||
CPathfinderHelper * pathfinderHelper) override;
|
||||
const PathNodeInfo & source,
|
||||
const PathfinderConfig * pathfinderConfig,
|
||||
const CPathfinderHelper * pathfinderHelper) override;
|
||||
|
||||
virtual std::vector<CGPathNode *> calculateTeleportations(
|
||||
CPathNodeInfo & source,
|
||||
CPathfinderConfig * pathfinderConfig,
|
||||
CPathfinderHelper * pathfinderHelper) override;
|
||||
const PathNodeInfo & source,
|
||||
const PathfinderConfig * pathfinderConfig,
|
||||
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;
|
||||
AIPathNode * getAINode(CGPathNode * node) const;
|
||||
bool isBattleNode(CGPathNode * node) const;
|
||||
bool hasBetterChain(CPathNodeInfo & source, CDestinationNodeInfo & destination) const;
|
||||
const AIPathNode * getAINode(const CGPathNode * node) const;
|
||||
void updateAINode(CGPathNode * node, std::function<void (AIPathNode *)> updater);
|
||||
|
||||
bool isBattleNode(const CGPathNode * node) const;
|
||||
bool hasBetterChain(const PathNodeInfo & source, CDestinationNodeInfo & destination) const;
|
||||
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)
|
||||
{
|
||||
|
@ -11,30 +11,7 @@
|
||||
#include "AIPathfinderConfig.h"
|
||||
#include "../../../CCallback.h"
|
||||
|
||||
class AILayerTransitionRule : public CLayerTransitionRule
|
||||
{
|
||||
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
|
||||
class AIMovementAfterDestinationRule : public MovementAfterDestinationRule
|
||||
{
|
||||
private:
|
||||
CPlayerSpecificInfoCallback * cb;
|
||||
@ -47,9 +24,9 @@ public:
|
||||
}
|
||||
|
||||
virtual void process(
|
||||
CPathNodeInfo & source,
|
||||
const PathNodeInfo & source,
|
||||
CDestinationNodeInfo & destination,
|
||||
CPathfinderConfig * pathfinderConfig,
|
||||
const PathfinderConfig * pathfinderConfig,
|
||||
CPathfinderHelper * pathfinderHelper) const override
|
||||
{
|
||||
if(nodeStorage->hasBetterChain(source, destination))
|
||||
@ -64,7 +41,7 @@ public:
|
||||
if(blocker == BlockingReason::NONE)
|
||||
return;
|
||||
|
||||
auto srcNode = nodeStorage->getAINode(source);
|
||||
auto srcNode = nodeStorage->getAINode(source.node);
|
||||
|
||||
if(blocker == BlockingReason::DESTINATION_BLOCKVIS && destination.nodeObject)
|
||||
{
|
||||
@ -113,7 +90,7 @@ public:
|
||||
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);
|
||||
|
||||
if(battleNode->locked)
|
||||
@ -152,7 +129,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class AIMovementToDestinationRule : public CMovementToDestinationRule
|
||||
class AIMovementToDestinationRule : public MovementToDestinationRule
|
||||
{
|
||||
private:
|
||||
CPlayerSpecificInfoCallback * cb;
|
||||
@ -165,9 +142,9 @@ public:
|
||||
}
|
||||
|
||||
virtual void process(
|
||||
CPathNodeInfo & source,
|
||||
const PathNodeInfo & source,
|
||||
CDestinationNodeInfo & destination,
|
||||
CPathfinderConfig * pathfinderConfig,
|
||||
const PathfinderConfig * pathfinderConfig,
|
||||
CPathfinderHelper * pathfinderHelper) const override
|
||||
{
|
||||
auto blocker = getBlockingReason(source, destination, pathfinderConfig, pathfinderHelper);
|
||||
@ -207,7 +184,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class AIPreviousNodeRule : public CMovementToDestinationRule
|
||||
class AIPreviousNodeRule : public MovementToDestinationRule
|
||||
{
|
||||
private:
|
||||
CPlayerSpecificInfoCallback * cb;
|
||||
@ -220,9 +197,9 @@ public:
|
||||
}
|
||||
|
||||
virtual void process(
|
||||
CPathNodeInfo & source,
|
||||
const PathNodeInfo & source,
|
||||
CDestinationNodeInfo & destination,
|
||||
CPathfinderConfig * pathfinderConfig,
|
||||
const PathfinderConfig * pathfinderConfig,
|
||||
CPathfinderHelper * pathfinderHelper) const override
|
||||
{
|
||||
auto blocker = getBlockingReason(source, destination, pathfinderConfig, pathfinderHelper);
|
||||
@ -261,10 +238,10 @@ std::vector<std::shared_ptr<IPathfindingRule>> makeRuleset(
|
||||
std::shared_ptr<AINodeStorage> nodeStorage)
|
||||
{
|
||||
std::vector<std::shared_ptr<IPathfindingRule>> rules = {
|
||||
std::make_shared<AILayerTransitionRule>(),
|
||||
std::make_shared<CDestinationActionRule>(),
|
||||
std::make_shared<LayerTransitionRule>(),
|
||||
std::make_shared<DestinationActionRule>(),
|
||||
std::make_shared<AIMovementToDestinationRule>(cb, nodeStorage),
|
||||
std::make_shared<CMovementCostRule>(),
|
||||
std::make_shared<MovementCostRule>(),
|
||||
std::make_shared<AIPreviousNodeRule>(cb, nodeStorage),
|
||||
std::make_shared<AIMovementAfterDestinationRule>(cb, nodeStorage)
|
||||
};
|
||||
@ -275,6 +252,6 @@ std::vector<std::shared_ptr<IPathfindingRule>> makeRuleset(
|
||||
AIPathfinderConfig::AIPathfinderConfig(
|
||||
CPlayerSpecificInfoCallback * cb,
|
||||
std::shared_ptr<AINodeStorage> nodeStorage)
|
||||
:CPathfinderConfig(nodeStorage, makeRuleset(cb, nodeStorage))
|
||||
:PathfinderConfig(nodeStorage, makeRuleset(cb, nodeStorage))
|
||||
{
|
||||
}
|
@ -12,7 +12,7 @@
|
||||
|
||||
#include "AINodeStorage.h"
|
||||
|
||||
class AIPathfinderConfig : public CPathfinderConfig
|
||||
class AIPathfinderConfig : public PathfinderConfig
|
||||
{
|
||||
public:
|
||||
AIPathfinderConfig(CPlayerSpecificInfoCallback * cb, std::shared_ptr<AINodeStorage> nodeStorage);
|
||||
|
@ -8,29 +8,29 @@
|
||||
*
|
||||
*/
|
||||
#include "StdInc.h"
|
||||
#include "CPathfindingManager.h"
|
||||
#include "PathfindingManager.h"
|
||||
#include "AIPathfinder.h"
|
||||
#include "AIPathfinderConfig.h"
|
||||
#include "../../../lib/CGameInfoCallback.h"
|
||||
#include "../../../lib/mapping/CMap.h"
|
||||
|
||||
CPathfindingManager::CPathfindingManager(CPlayerSpecificInfoCallback * CB, VCAI * AI)
|
||||
PathfindingManager::PathfindingManager(CPlayerSpecificInfoCallback * CB, VCAI * AI)
|
||||
: ai(AI), cb(CB)
|
||||
{
|
||||
}
|
||||
|
||||
void CPathfindingManager::setCB(CPlayerSpecificInfoCallback * CB)
|
||||
void PathfindingManager::setCB(CPlayerSpecificInfoCallback * CB)
|
||||
{
|
||||
cb = CB;
|
||||
pathfinder.reset(new AIPathfinder(cb));
|
||||
}
|
||||
|
||||
void CPathfindingManager::setAI(VCAI * AI)
|
||||
void PathfindingManager::setAI(VCAI * AI)
|
||||
{
|
||||
ai = AI;
|
||||
}
|
||||
|
||||
Goals::TGoalVec CPathfindingManager::howToVisitTile(int3 tile)
|
||||
Goals::TGoalVec PathfindingManager::howToVisitTile(int3 tile)
|
||||
{
|
||||
Goals::TGoalVec result;
|
||||
|
||||
@ -44,7 +44,7 @@ Goals::TGoalVec CPathfindingManager::howToVisitTile(int3 tile)
|
||||
return result;
|
||||
}
|
||||
|
||||
Goals::TGoalVec CPathfindingManager::howToVisitObj(ObjectIdRef obj)
|
||||
Goals::TGoalVec PathfindingManager::howToVisitObj(ObjectIdRef obj)
|
||||
{
|
||||
Goals::TGoalVec result;
|
||||
|
||||
@ -58,7 +58,7 @@ Goals::TGoalVec CPathfindingManager::howToVisitObj(ObjectIdRef obj)
|
||||
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
|
||||
{
|
||||
@ -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)
|
||||
{
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Goals::TGoalVec CPathfindingManager::findPath(
|
||||
Goals::TGoalVec PathfindingManager::findPath(
|
||||
HeroPtr hero,
|
||||
crint3 dest,
|
||||
bool allowGatherArmy,
|
||||
@ -141,7 +141,7 @@ Goals::TGoalVec CPathfindingManager::findPath(
|
||||
return result;
|
||||
}
|
||||
|
||||
Goals::TSubgoal CPathfindingManager::selectVisitingGoal(HeroPtr hero, ObjectIdRef obj) const
|
||||
Goals::TSubgoal PathfindingManager::selectVisitingGoal(HeroPtr hero, ObjectIdRef obj) const
|
||||
{
|
||||
int3 dest = obj->visitablePos();
|
||||
|
||||
@ -161,7 +161,7 @@ Goals::TSubgoal CPathfindingManager::selectVisitingGoal(HeroPtr hero, ObjectIdRe
|
||||
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))
|
||||
{
|
||||
@ -207,7 +207,7 @@ Goals::TSubgoal CPathfindingManager::clearWayTo(HeroPtr hero, int3 firstTileToGe
|
||||
return sptr(Goals::VisitTile(firstTileToGet).sethero(hero).setisAbstract(true));
|
||||
}
|
||||
|
||||
void CPathfindingManager::resetPaths()
|
||||
void PathfindingManager::resetPaths()
|
||||
{
|
||||
logAi->debug("AIPathfinder has been reseted.");
|
||||
pathfinder->clear();
|
@ -13,7 +13,7 @@
|
||||
#include "VCAI.h"
|
||||
#include "AINodeStorage.h"
|
||||
|
||||
class IPathfindingManager // : pulbic IAbstractManager
|
||||
class IPathfindingManager
|
||||
{
|
||||
public:
|
||||
virtual ~IPathfindingManager() = default;
|
||||
@ -28,7 +28,7 @@ public:
|
||||
virtual std::vector<AIPath> getPathsToTile(HeroPtr hero, int3 tile) = 0;
|
||||
};
|
||||
|
||||
class CPathfindingManager : public IPathfindingManager
|
||||
class PathfindingManager : public IPathfindingManager
|
||||
{
|
||||
friend class AIhelper;
|
||||
|
||||
@ -38,8 +38,8 @@ private:
|
||||
std::unique_ptr<AIPathfinder> pathfinder;
|
||||
|
||||
public:
|
||||
CPathfindingManager() = default;
|
||||
CPathfindingManager(CPlayerSpecificInfoCallback * CB, VCAI * AI = nullptr); //for tests only
|
||||
PathfindingManager() = default;
|
||||
PathfindingManager(CPlayerSpecificInfoCallback * CB, VCAI * AI = nullptr); //for tests only
|
||||
|
||||
Goals::TGoalVec howToVisitTile(HeroPtr hero, int3 tile, bool allowGatherArmy = true) override;
|
||||
Goals::TGoalVec howToVisitObj(HeroPtr hero, ObjectIdRef obj, bool allowGatherArmy = true) override;
|
@ -25,7 +25,7 @@ class IShipyard;
|
||||
struct CGPathNode;
|
||||
struct CGPath;
|
||||
struct CPathsInfo;
|
||||
class CPathfinderConfig;
|
||||
class PathfinderConfig;
|
||||
struct CPack;
|
||||
class IBattleEventsReceiver;
|
||||
class IGameEventsReceiver;
|
||||
|
@ -919,7 +919,7 @@ void CGameInfoCallback::getVisibleTilesInRange(std::unordered_set<int3, ShashInt
|
||||
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);
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ struct TeamState;
|
||||
struct QuestInfo;
|
||||
struct ShashInt3;
|
||||
class CGameState;
|
||||
class CPathfinderConfig;
|
||||
class PathfinderConfig;
|
||||
|
||||
|
||||
class DLL_LINKAGE CGameInfoCallback : public virtual CCallbackBase
|
||||
@ -99,7 +99,7 @@ public:
|
||||
virtual std::shared_ptr<boost::multi_array<TerrainTile*, 3>> getAllVisibleTiles() 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 calculatePaths(std::shared_ptr<CPathfinderConfig> config, const CGHeroInstance * hero);
|
||||
virtual void calculatePaths(std::shared_ptr<PathfinderConfig> config, const CGHeroInstance * hero);
|
||||
|
||||
//town
|
||||
virtual const CGTownInstance* getTown(ObjectInstanceID objid) const;
|
||||
|
@ -1979,7 +1979,7 @@ void CGameState::calculatePaths(const CGHeroInstance *hero, CPathsInfo &out)
|
||||
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);
|
||||
pathfinder.calculatePaths();
|
||||
|
@ -178,7 +178,7 @@ public:
|
||||
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
|
||||
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;
|
||||
std::vector<CGObjectInstance*> guardingCreatures (int3 pos) const;
|
||||
void updateRumor();
|
||||
|
@ -25,10 +25,10 @@ bool canSeeObj(const CGObjectInstance * obj)
|
||||
return obj != nullptr && obj->ID != Obj::EVENT;
|
||||
}
|
||||
|
||||
std::vector<CGPathNode *> CNodeStorage::calculateNeighbours(
|
||||
CPathNodeInfo & source,
|
||||
CPathfinderConfig * pathfinderConfig,
|
||||
CPathfinderHelper * pathfinderHelper)
|
||||
std::vector<CGPathNode *> NodeStorage::calculateNeighbours(
|
||||
const PathNodeInfo & source,
|
||||
const PathfinderConfig * pathfinderConfig,
|
||||
const CPathfinderHelper * pathfinderHelper)
|
||||
{
|
||||
std::vector<CGPathNode *> neighbours;
|
||||
auto accessibleNeighbourTiles = pathfinderHelper->getNeighbourTiles(source);
|
||||
@ -49,10 +49,10 @@ std::vector<CGPathNode *> CNodeStorage::calculateNeighbours(
|
||||
return neighbours;
|
||||
}
|
||||
|
||||
std::vector<CGPathNode *> CNodeStorage::calculateTeleportations(
|
||||
CPathNodeInfo & source,
|
||||
CPathfinderConfig * pathfinderConfig,
|
||||
CPathfinderHelper * pathfinderHelper)
|
||||
std::vector<CGPathNode *> NodeStorage::calculateTeleportations(
|
||||
const PathNodeInfo & source,
|
||||
const PathfinderConfig * pathfinderConfig,
|
||||
const CPathfinderHelper * pathfinderHelper)
|
||||
{
|
||||
std::vector<CGPathNode *> neighbours;
|
||||
auto accessibleExits = pathfinderHelper->getTeleportExits(source);
|
||||
@ -67,7 +67,7 @@ std::vector<CGPathNode *> CNodeStorage::calculateTeleportations(
|
||||
return neighbours;
|
||||
}
|
||||
|
||||
std::vector<int3> CPathfinderHelper::getNeighbourTiles(CPathNodeInfo & source) const
|
||||
std::vector<int3> CPathfinderHelper::getNeighbourTiles(const PathNodeInfo & source) const
|
||||
{
|
||||
std::vector<int3> neighbourTiles;
|
||||
|
||||
@ -89,19 +89,19 @@ std::vector<int3> CPathfinderHelper::getNeighbourTiles(CPathNodeInfo & source) c
|
||||
return neighbourTiles;
|
||||
}
|
||||
|
||||
CNodeStorage::CNodeStorage(CPathsInfo & pathsInfo, const CGHeroInstance * hero)
|
||||
NodeStorage::NodeStorage(CPathsInfo & pathsInfo, const CGHeroInstance * hero)
|
||||
:out(pathsInfo)
|
||||
{
|
||||
out.hero = hero;
|
||||
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);
|
||||
}
|
||||
|
||||
void CNodeStorage::resetTile(
|
||||
void NodeStorage::resetTile(
|
||||
const int3 & tile,
|
||||
EPathfindingLayer layer,
|
||||
CGPathNode::EAccessibility accessibility)
|
||||
@ -109,7 +109,7 @@ void CNodeStorage::resetTile(
|
||||
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);
|
||||
|
||||
@ -119,7 +119,7 @@ CGPathNode * CNodeStorage::getInitialNode()
|
||||
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
|
||||
destination.node->moveRemains = destination.movementLeft;
|
||||
@ -145,10 +145,10 @@ PathfinderOptions::PathfinderOptions()
|
||||
originalMovementRules = settings["pathfinder"]["originalMovementRules"].Bool();
|
||||
}
|
||||
|
||||
void CMovementCostRule::process(
|
||||
CPathNodeInfo & source,
|
||||
void MovementCostRule::process(
|
||||
const PathNodeInfo & source,
|
||||
CDestinationNodeInfo & destination,
|
||||
CPathfinderConfig * pathfinderConfig,
|
||||
const PathfinderConfig * pathfinderConfig,
|
||||
CPathfinderHelper * pathfinderHelper) const
|
||||
{
|
||||
int turnAtNextTile = destination.turn, moveAtNextTile = destination.movementLeft;
|
||||
@ -183,7 +183,7 @@ void CMovementCostRule::process(
|
||||
destination.blocked = true;
|
||||
}
|
||||
|
||||
CPathfinderConfig::CPathfinderConfig(
|
||||
PathfinderConfig::PathfinderConfig(
|
||||
std::shared_ptr<INodeStorage> nodeStorage,
|
||||
std::vector<std::shared_ptr<IPathfindingRule>> rules)
|
||||
: nodeStorage(nodeStorage), rules(rules), options()
|
||||
@ -197,14 +197,14 @@ CPathfinder::CPathfinder(
|
||||
: CPathfinder(
|
||||
_gs,
|
||||
_hero,
|
||||
std::make_shared<CPathfinderConfig>(
|
||||
std::make_shared<CNodeStorage>(_out, _hero),
|
||||
std::make_shared<PathfinderConfig>(
|
||||
std::make_shared<NodeStorage>(_out, _hero),
|
||||
std::vector<std::shared_ptr<IPathfindingRule>>{
|
||||
std::make_shared<CLayerTransitionRule>(),
|
||||
std::make_shared<CDestinationActionRule>(),
|
||||
std::make_shared<CMovementToDestinationRule>(),
|
||||
std::make_shared<CMovementCostRule>(),
|
||||
std::make_shared<CMovementAfterDestinationRule>()
|
||||
std::make_shared<LayerTransitionRule>(),
|
||||
std::make_shared<DestinationActionRule>(),
|
||||
std::make_shared<MovementToDestinationRule>(),
|
||||
std::make_shared<MovementCostRule>(),
|
||||
std::make_shared<MovementAfterDestinationRule>()
|
||||
}))
|
||||
{
|
||||
}
|
||||
@ -212,7 +212,7 @@ CPathfinder::CPathfinder(
|
||||
CPathfinder::CPathfinder(
|
||||
CGameState * _gs,
|
||||
const CGHeroInstance * _hero,
|
||||
std::shared_ptr<CPathfinderConfig> config)
|
||||
std::shared_ptr<PathfinderConfig> config)
|
||||
: CGameInfoCallback(_gs, boost::optional<PlayerColor>())
|
||||
, hero(_hero)
|
||||
, FoW(getPlayerTeam(hero->tempOwner)->fogOfWarMap), patrolTiles({})
|
||||
@ -368,7 +368,7 @@ std::vector<int3> CPathfinderHelper::getAllowedTeleportChannelExits(TeleportChan
|
||||
return allowedExits;
|
||||
}
|
||||
|
||||
std::vector<int3> CPathfinderHelper::getCastleGates(CPathNodeInfo & source) const
|
||||
std::vector<int3> CPathfinderHelper::getCastleGates(const PathNodeInfo & source) const
|
||||
{
|
||||
std::vector<int3> allowedExits;
|
||||
|
||||
@ -385,7 +385,7 @@ std::vector<int3> CPathfinderHelper::getCastleGates(CPathNodeInfo & source) cons
|
||||
return allowedExits;
|
||||
}
|
||||
|
||||
std::vector<int3> CPathfinderHelper::getTeleportExits(CPathNodeInfo & source) const
|
||||
std::vector<int3> CPathfinderHelper::getTeleportExits(const PathNodeInfo & source) const
|
||||
{
|
||||
std::vector<int3> teleportationExits;
|
||||
|
||||
@ -474,10 +474,10 @@ bool CPathfinder::isLayerTransitionPossible(const ELayer destLayer) const
|
||||
return false;
|
||||
}
|
||||
|
||||
void CLayerTransitionRule::process(
|
||||
CPathNodeInfo & source,
|
||||
void LayerTransitionRule::process(
|
||||
const PathNodeInfo & source,
|
||||
CDestinationNodeInfo & destination,
|
||||
CPathfinderConfig * pathfinderConfig,
|
||||
const PathfinderConfig * pathfinderConfig,
|
||||
CPathfinderHelper * pathfinderHelper) const
|
||||
{
|
||||
if(source.node->layer == destination.node->layer)
|
||||
@ -536,11 +536,11 @@ void CLayerTransitionRule::process(
|
||||
}
|
||||
}
|
||||
|
||||
CPathfinderBlockingRule::BlockingReason CMovementToDestinationRule::getBlockingReason(
|
||||
CPathNodeInfo & source,
|
||||
CDestinationNodeInfo & destination,
|
||||
CPathfinderConfig * pathfinderConfig,
|
||||
CPathfinderHelper * pathfinderHelper) const
|
||||
PathfinderBlockingRule::BlockingReason MovementToDestinationRule::getBlockingReason(
|
||||
const PathNodeInfo & source,
|
||||
const CDestinationNodeInfo & destination,
|
||||
const PathfinderConfig * pathfinderConfig,
|
||||
const CPathfinderHelper * pathfinderHelper) const
|
||||
{
|
||||
|
||||
if(destination.node->accessible == CGPathNode::BLOCKED)
|
||||
@ -607,10 +607,10 @@ CPathfinderBlockingRule::BlockingReason CMovementToDestinationRule::getBlockingR
|
||||
}
|
||||
|
||||
|
||||
void CMovementAfterDestinationRule::process(
|
||||
CPathNodeInfo & source,
|
||||
void MovementAfterDestinationRule::process(
|
||||
const PathNodeInfo & source,
|
||||
CDestinationNodeInfo & destination,
|
||||
CPathfinderConfig * config,
|
||||
const PathfinderConfig * config,
|
||||
CPathfinderHelper * pathfinderHelper) const
|
||||
{
|
||||
auto blocker = getBlockingReason(source, destination, config, pathfinderHelper);
|
||||
@ -623,11 +623,11 @@ void CMovementAfterDestinationRule::process(
|
||||
destination.blocked = blocker != BlockingReason::NONE;
|
||||
}
|
||||
|
||||
CPathfinderBlockingRule::BlockingReason CMovementAfterDestinationRule::getBlockingReason(
|
||||
CPathNodeInfo & source,
|
||||
CDestinationNodeInfo & destination,
|
||||
CPathfinderConfig * config,
|
||||
CPathfinderHelper * pathfinderHelper) const
|
||||
PathfinderBlockingRule::BlockingReason MovementAfterDestinationRule::getBlockingReason(
|
||||
const PathNodeInfo & source,
|
||||
const CDestinationNodeInfo & destination,
|
||||
const PathfinderConfig * config,
|
||||
const CPathfinderHelper * pathfinderHelper) const
|
||||
{
|
||||
switch(destination.action)
|
||||
{
|
||||
@ -686,10 +686,10 @@ CPathfinderBlockingRule::BlockingReason CMovementAfterDestinationRule::getBlocki
|
||||
return BlockingReason::DESTINATION_BLOCKED;
|
||||
}
|
||||
|
||||
void CDestinationActionRule::process(
|
||||
CPathNodeInfo & source,
|
||||
void DestinationActionRule::process(
|
||||
const PathNodeInfo & source,
|
||||
CDestinationNodeInfo & destination,
|
||||
CPathfinderConfig * pathfinderConfig,
|
||||
const PathfinderConfig * pathfinderConfig,
|
||||
CPathfinderHelper * pathfinderHelper) const
|
||||
{
|
||||
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());
|
||||
}
|
||||
|
||||
bool CPathfinderHelper::passOneTurnLimitCheck(CPathNodeInfo & source) const
|
||||
bool CPathfinderHelper::passOneTurnLimitCheck(const PathNodeInfo & source) const
|
||||
{
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
CPathNodeInfo::CPathNodeInfo()
|
||||
PathNodeInfo::PathNodeInfo()
|
||||
: 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;
|
||||
|
||||
@ -1441,13 +1441,13 @@ void CPathNodeInfo::setNode(CGameState * gs, CGPathNode * n, bool excludeTopObje
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
CPathNodeInfo::setNode(gs, n, excludeTopObject);
|
||||
PathNodeInfo::setNode(gs, n, excludeTopObject);
|
||||
|
||||
blocked = false;
|
||||
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
|
||||
return canSeeObj(nodeObject) && (node->layer == EPathfindingLayer::LAND || node->layer == EPathfindingLayer::SAIL);
|
||||
|
@ -24,7 +24,7 @@ class CMap;
|
||||
class CGWhirlpool;
|
||||
class CPathfinderHelper;
|
||||
class CPathfinder;
|
||||
class CPathfinderConfig;
|
||||
class PathfinderConfig;
|
||||
|
||||
struct DLL_LINKAGE CGPathNode
|
||||
{
|
||||
@ -99,7 +99,7 @@ struct DLL_LINKAGE CPathsInfo
|
||||
CGPathNode * getNode(const int3 & coord, const ELayer layer);
|
||||
};
|
||||
|
||||
struct DLL_LINKAGE CPathNodeInfo
|
||||
struct DLL_LINKAGE PathNodeInfo
|
||||
{
|
||||
CGPathNode * node;
|
||||
const CGObjectInstance * nodeObject;
|
||||
@ -108,14 +108,14 @@ struct DLL_LINKAGE CPathNodeInfo
|
||||
bool guarded;
|
||||
PlayerRelations::PlayerRelations objectRelations;
|
||||
|
||||
CPathNodeInfo();
|
||||
PathNodeInfo();
|
||||
|
||||
virtual void setNode(CGameState * gs, CGPathNode * n, bool excludeTopObject = false);
|
||||
|
||||
bool isNodeObjectVisitable() const;
|
||||
};
|
||||
|
||||
struct DLL_LINKAGE CDestinationNodeInfo : public CPathNodeInfo
|
||||
struct DLL_LINKAGE CDestinationNodeInfo : public PathNodeInfo
|
||||
{
|
||||
CGPathNode::ENodeAction action;
|
||||
int turn;
|
||||
@ -134,49 +134,49 @@ class IPathfindingRule
|
||||
{
|
||||
public:
|
||||
virtual void process(
|
||||
CPathNodeInfo & source,
|
||||
const PathNodeInfo & source,
|
||||
CDestinationNodeInfo & destination,
|
||||
CPathfinderConfig * pathfinderConfig,
|
||||
const PathfinderConfig * pathfinderConfig,
|
||||
CPathfinderHelper * pathfinderHelper) const = 0;
|
||||
};
|
||||
|
||||
class DLL_LINKAGE CMovementCostRule : public IPathfindingRule
|
||||
class DLL_LINKAGE MovementCostRule : public IPathfindingRule
|
||||
{
|
||||
public:
|
||||
virtual void process(
|
||||
CPathNodeInfo & source,
|
||||
const PathNodeInfo & source,
|
||||
CDestinationNodeInfo & destination,
|
||||
CPathfinderConfig * pathfinderConfig,
|
||||
const PathfinderConfig * pathfinderConfig,
|
||||
CPathfinderHelper * pathfinderHelper) const override;
|
||||
};
|
||||
|
||||
class DLL_LINKAGE CLayerTransitionRule : public IPathfindingRule
|
||||
class DLL_LINKAGE LayerTransitionRule : public IPathfindingRule
|
||||
{
|
||||
public:
|
||||
virtual void process(
|
||||
CPathNodeInfo & source,
|
||||
const PathNodeInfo & source,
|
||||
CDestinationNodeInfo & destination,
|
||||
CPathfinderConfig * pathfinderConfig,
|
||||
const PathfinderConfig * pathfinderConfig,
|
||||
CPathfinderHelper * pathfinderHelper) const override;
|
||||
};
|
||||
|
||||
class DLL_LINKAGE CDestinationActionRule : public IPathfindingRule
|
||||
class DLL_LINKAGE DestinationActionRule : public IPathfindingRule
|
||||
{
|
||||
public:
|
||||
virtual void process(
|
||||
CPathNodeInfo & source,
|
||||
const PathNodeInfo & source,
|
||||
CDestinationNodeInfo & destination,
|
||||
CPathfinderConfig * pathfinderConfig,
|
||||
const PathfinderConfig * pathfinderConfig,
|
||||
CPathfinderHelper * pathfinderHelper) const override;
|
||||
};
|
||||
|
||||
class DLL_LINKAGE CPathfinderBlockingRule : public IPathfindingRule
|
||||
class DLL_LINKAGE PathfinderBlockingRule : public IPathfindingRule
|
||||
{
|
||||
public:
|
||||
virtual void process(
|
||||
CPathNodeInfo & source,
|
||||
const PathNodeInfo & source,
|
||||
CDestinationNodeInfo & destination,
|
||||
CPathfinderConfig * pathfinderConfig,
|
||||
const PathfinderConfig * pathfinderConfig,
|
||||
CPathfinderHelper * pathfinderHelper) const override
|
||||
{
|
||||
auto blockingReason = getBlockingReason(source, destination, pathfinderConfig, pathfinderHelper);
|
||||
@ -197,37 +197,37 @@ protected:
|
||||
};
|
||||
|
||||
virtual BlockingReason getBlockingReason(
|
||||
CPathNodeInfo & source,
|
||||
CDestinationNodeInfo & destination,
|
||||
CPathfinderConfig * pathfinderConfig,
|
||||
CPathfinderHelper * pathfinderHelper) const = 0;
|
||||
const PathNodeInfo & source,
|
||||
const CDestinationNodeInfo & destination,
|
||||
const PathfinderConfig * pathfinderConfig,
|
||||
const CPathfinderHelper * pathfinderHelper) const = 0;
|
||||
};
|
||||
|
||||
class DLL_LINKAGE CMovementAfterDestinationRule : public CPathfinderBlockingRule
|
||||
class DLL_LINKAGE MovementAfterDestinationRule : public PathfinderBlockingRule
|
||||
{
|
||||
public:
|
||||
virtual void process(
|
||||
CPathNodeInfo & source,
|
||||
const PathNodeInfo & source,
|
||||
CDestinationNodeInfo & destination,
|
||||
CPathfinderConfig * pathfinderConfig,
|
||||
const PathfinderConfig * pathfinderConfig,
|
||||
CPathfinderHelper * pathfinderHelper) const override;
|
||||
|
||||
protected:
|
||||
virtual BlockingReason getBlockingReason(
|
||||
CPathNodeInfo & source,
|
||||
CDestinationNodeInfo & destination,
|
||||
CPathfinderConfig * pathfinderConfig,
|
||||
CPathfinderHelper * pathfinderHelper) const override;
|
||||
const PathNodeInfo & source,
|
||||
const CDestinationNodeInfo & destination,
|
||||
const PathfinderConfig * pathfinderConfig,
|
||||
const CPathfinderHelper * pathfinderHelper) const override;
|
||||
};
|
||||
|
||||
class DLL_LINKAGE CMovementToDestinationRule : public CPathfinderBlockingRule
|
||||
class DLL_LINKAGE MovementToDestinationRule : public PathfinderBlockingRule
|
||||
{
|
||||
protected:
|
||||
virtual BlockingReason getBlockingReason(
|
||||
CPathNodeInfo & source,
|
||||
CDestinationNodeInfo & destination,
|
||||
CPathfinderConfig * pathfinderConfig,
|
||||
CPathfinderHelper * pathfinderHelper) const override;
|
||||
const PathNodeInfo & source,
|
||||
const CDestinationNodeInfo & destination,
|
||||
const PathfinderConfig * pathfinderConfig,
|
||||
const CPathfinderHelper * pathfinderHelper) const override;
|
||||
};
|
||||
|
||||
|
||||
@ -238,45 +238,45 @@ public:
|
||||
virtual void resetTile(const int3 & tile, EPathfindingLayer layer, CGPathNode::EAccessibility accessibility) = 0;
|
||||
|
||||
virtual std::vector<CGPathNode *> calculateNeighbours(
|
||||
CPathNodeInfo & source,
|
||||
CPathfinderConfig * pathfinderConfig,
|
||||
CPathfinderHelper * pathfinderHelper) = 0;
|
||||
const PathNodeInfo & source,
|
||||
const PathfinderConfig * pathfinderConfig,
|
||||
const CPathfinderHelper * pathfinderHelper) = 0;
|
||||
|
||||
virtual std::vector<CGPathNode *> calculateTeleportations(
|
||||
CPathNodeInfo & source,
|
||||
CPathfinderConfig * pathfinderConfig,
|
||||
CPathfinderHelper * pathfinderHelper) = 0;
|
||||
const PathNodeInfo & source,
|
||||
const PathfinderConfig * pathfinderConfig,
|
||||
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:
|
||||
CPathsInfo & out;
|
||||
|
||||
public:
|
||||
CNodeStorage(CPathsInfo & pathsInfo, const CGHeroInstance * hero);
|
||||
NodeStorage(CPathsInfo & pathsInfo, const CGHeroInstance * hero);
|
||||
|
||||
CGPathNode * getNode(const int3 & coord, const EPathfindingLayer layer);
|
||||
virtual CGPathNode * getInitialNode() override;
|
||||
|
||||
virtual std::vector<CGPathNode *> calculateNeighbours(
|
||||
CPathNodeInfo & source,
|
||||
CPathfinderConfig * pathfinderConfig,
|
||||
CPathfinderHelper * pathfinderHelper) override;
|
||||
const PathNodeInfo & source,
|
||||
const PathfinderConfig * pathfinderConfig,
|
||||
const CPathfinderHelper * pathfinderHelper) override;
|
||||
|
||||
virtual std::vector<CGPathNode *> calculateTeleportations(
|
||||
CPathNodeInfo & source,
|
||||
CPathfinderConfig * pathfinderConfig,
|
||||
CPathfinderHelper * pathfinderHelper) override;
|
||||
const PathNodeInfo & source,
|
||||
const PathfinderConfig * pathfinderConfig,
|
||||
const CPathfinderHelper * pathfinderHelper) override;
|
||||
|
||||
virtual void resetTile(
|
||||
const int3 & tile,
|
||||
EPathfindingLayer layer,
|
||||
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
|
||||
@ -330,14 +330,14 @@ struct DLL_LINKAGE PathfinderOptions
|
||||
PathfinderOptions();
|
||||
};
|
||||
|
||||
class DLL_LINKAGE CPathfinderConfig
|
||||
class DLL_LINKAGE PathfinderConfig
|
||||
{
|
||||
public:
|
||||
std::shared_ptr<INodeStorage> nodeStorage;
|
||||
std::vector<std::shared_ptr<IPathfindingRule>> rules;
|
||||
PathfinderOptions options;
|
||||
|
||||
CPathfinderConfig(
|
||||
PathfinderConfig(
|
||||
std::shared_ptr<INodeStorage> nodeStorage,
|
||||
std::vector<std::shared_ptr<IPathfindingRule>> rules);
|
||||
};
|
||||
@ -351,7 +351,7 @@ public:
|
||||
CPathfinder(
|
||||
CGameState * _gs,
|
||||
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
|
||||
|
||||
@ -361,7 +361,7 @@ private:
|
||||
const CGHeroInstance * hero;
|
||||
const std::vector<std::vector<std::vector<ui8> > > &FoW;
|
||||
std::unique_ptr<CPathfinderHelper> hlp;
|
||||
std::shared_ptr<CPathfinderConfig> config;
|
||||
std::shared_ptr<PathfinderConfig> config;
|
||||
|
||||
enum EPatrolState {
|
||||
PATROL_NONE = 0,
|
||||
@ -384,7 +384,7 @@ private:
|
||||
};
|
||||
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
|
||||
|
||||
bool isHeroPatrolLocked() const;
|
||||
@ -449,7 +449,7 @@ public:
|
||||
bool hasBonusOfType(const Bonus::BonusType type, const int subtype = -1) 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;
|
||||
std::vector<int3> getAllowedTeleportChannelExits(TeleportChannelID channelID) const;
|
||||
bool addTeleportTwoWay(const CGTeleport * obj) const;
|
||||
@ -458,8 +458,8 @@ public:
|
||||
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)
|
||||
|
||||
std::vector<int3> getNeighbourTiles(CPathNodeInfo & source) const;
|
||||
std::vector<int3> getTeleportExits(CPathNodeInfo & source) const;
|
||||
std::vector<int3> getNeighbourTiles(const PathNodeInfo & source) const;
|
||||
std::vector<int3> getTeleportExits(const PathNodeInfo & source) const;
|
||||
|
||||
void getNeighbours(
|
||||
const TerrainTile & srct,
|
||||
@ -477,8 +477,8 @@ public:
|
||||
const bool checkLast = true) const;
|
||||
|
||||
int getMovementCost(
|
||||
const CPathNodeInfo & src,
|
||||
const CPathNodeInfo & dst,
|
||||
const PathNodeInfo & src,
|
||||
const PathNodeInfo & dst,
|
||||
const int remainingMovePoints = -1,
|
||||
const bool checkLast = true) const
|
||||
{
|
||||
@ -494,5 +494,5 @@ public:
|
||||
|
||||
int getHeroMaxMovementPoints(EPathfindingLayer layer) const;
|
||||
int movementPointsAfterEmbark(int movement, int cost, int action) const;
|
||||
bool passOneTurnLimitCheck(CPathNodeInfo & source) const;
|
||||
bool passOneTurnLimitCheck(const PathNodeInfo & source) const;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user