|
@@ -254,16 +254,6 @@ PathfinderConfig::PathfinderConfig(
|
|
|
{
|
|
|
}
|
|
|
|
|
|
-CPathfinder::CPathfinder(
|
|
|
- CPathsInfo & _out,
|
|
|
- CGameState * _gs,
|
|
|
- const CGHeroInstance * _hero)
|
|
|
- : CPathfinder(
|
|
|
- _gs,
|
|
|
- std::make_shared<SingleHeroPathfinderConfig>(_out, _gs, _hero))
|
|
|
-{
|
|
|
-}
|
|
|
-
|
|
|
std::vector<std::shared_ptr<IPathfindingRule>> SingleHeroPathfinderConfig::buildRuleSet()
|
|
|
{
|
|
|
return std::vector<std::shared_ptr<IPathfindingRule>>{
|
|
@@ -289,7 +279,7 @@ CPathfinderHelper * SingleHeroPathfinderConfig::getOrCreatePathfinderHelper(cons
|
|
|
CPathfinder::CPathfinder(
|
|
|
CGameState * _gs,
|
|
|
std::shared_ptr<PathfinderConfig> config)
|
|
|
- : CGameInfoCallback(_gs, boost::optional<PlayerColor>())
|
|
|
+ : gamestate(_gs)
|
|
|
, config(config)
|
|
|
, source()
|
|
|
, destination()
|
|
@@ -329,14 +319,14 @@ void CPathfinder::calculatePaths()
|
|
|
|
|
|
for(auto initialNode : initialNodes)
|
|
|
{
|
|
|
- if(!isInTheMap(initialNode->coord)/* || !gs->map->isInTheMap(dest)*/) //check input
|
|
|
+ if(!gamestate->isInTheMap(initialNode->coord)/* || !gs->map->isInTheMap(dest)*/) //check input
|
|
|
{
|
|
|
logGlobal->error("CGameState::calculatePaths: Hero outside the gs->map? How dare you...");
|
|
|
throw std::runtime_error("Wrong checksum");
|
|
|
}
|
|
|
|
|
|
- source.setNode(gs, initialNode);
|
|
|
- auto hlp = config->getOrCreatePathfinderHelper(source, gs);
|
|
|
+ source.setNode(gamestate, initialNode);
|
|
|
+ auto hlp = config->getOrCreatePathfinderHelper(source, gamestate);
|
|
|
|
|
|
if(hlp->isHeroPatrolLocked())
|
|
|
continue;
|
|
@@ -349,14 +339,14 @@ void CPathfinder::calculatePaths()
|
|
|
counter++;
|
|
|
auto node = topAndPop();
|
|
|
|
|
|
- source.setNode(gs, node);
|
|
|
+ source.setNode(gamestate, node);
|
|
|
source.node->locked = true;
|
|
|
|
|
|
int movement = source.node->moveRemains;
|
|
|
uint8_t turn = source.node->turns;
|
|
|
float cost = source.node->getCost();
|
|
|
|
|
|
- auto hlp = config->getOrCreatePathfinderHelper(source, gs);
|
|
|
+ auto hlp = config->getOrCreatePathfinderHelper(source, gamestate);
|
|
|
|
|
|
hlp->updateTurnInfo(turn);
|
|
|
if(!movement)
|
|
@@ -368,7 +358,7 @@ void CPathfinder::calculatePaths()
|
|
|
}
|
|
|
|
|
|
source.isInitialPosition = source.nodeHero == hlp->hero;
|
|
|
- source.updateInfo(hlp, gs);
|
|
|
+ source.updateInfo(hlp, gamestate);
|
|
|
|
|
|
//add accessible neighbouring nodes to the queue
|
|
|
auto neighbourNodes = config->nodeStorage->calculateNeighbours(source, config.get(), hlp);
|
|
@@ -380,8 +370,8 @@ void CPathfinder::calculatePaths()
|
|
|
if(!hlp->isLayerAvailable(neighbour->layer))
|
|
|
continue;
|
|
|
|
|
|
- destination.setNode(gs, neighbour);
|
|
|
- hlp = config->getOrCreatePathfinderHelper(destination, gs);
|
|
|
+ destination.setNode(gamestate, neighbour);
|
|
|
+ hlp = config->getOrCreatePathfinderHelper(destination, gamestate);
|
|
|
|
|
|
if(!hlp->isPatrolMovementAllowed(neighbour->coord))
|
|
|
continue;
|
|
@@ -393,7 +383,7 @@ void CPathfinder::calculatePaths()
|
|
|
destination.turn = turn;
|
|
|
destination.movementLeft = movement;
|
|
|
destination.cost = cost;
|
|
|
- destination.updateInfo(hlp, gs);
|
|
|
+ destination.updateInfo(hlp, gamestate);
|
|
|
destination.isGuardianTile = destination.guarded && isDestinationGuardian();
|
|
|
|
|
|
for(auto rule : config->rules)
|
|
@@ -410,7 +400,7 @@ void CPathfinder::calculatePaths()
|
|
|
} //neighbours loop
|
|
|
|
|
|
//just add all passable teleport exits
|
|
|
- hlp = config->getOrCreatePathfinderHelper(source, gs);
|
|
|
+ hlp = config->getOrCreatePathfinderHelper(source, gamestate);
|
|
|
|
|
|
/// For now we disable teleports usage for patrol movement
|
|
|
/// VCAI not aware about patrol and may stuck while attempt to use teleport
|
|
@@ -430,7 +420,7 @@ void CPathfinder::calculatePaths()
|
|
|
if(teleportNode->accessible == CGPathNode::BLOCKED)
|
|
|
continue;
|
|
|
|
|
|
- destination.setNode(gs, teleportNode);
|
|
|
+ destination.setNode(gamestate, teleportNode);
|
|
|
destination.turn = turn;
|
|
|
destination.movementLeft = movement;
|
|
|
destination.cost = cost;
|
|
@@ -903,7 +893,7 @@ CGPathNode::ENodeAction CPathfinder::getTeleportDestAction() const
|
|
|
|
|
|
bool CPathfinder::isDestinationGuardian() const
|
|
|
{
|
|
|
- return gs->guardingCreaturePosition(destination.node->coord) == destination.node->coord;
|
|
|
+ return gamestate->guardingCreaturePosition(destination.node->coord) == destination.node->coord;
|
|
|
}
|
|
|
|
|
|
void CPathfinderHelper::initializePatrol()
|
|
@@ -927,7 +917,7 @@ void CPathfinderHelper::initializePatrol()
|
|
|
void CPathfinder::initializeGraph()
|
|
|
{
|
|
|
INodeStorage * nodeStorage = config->nodeStorage.get();
|
|
|
- nodeStorage->initialize(config->options, gs);
|
|
|
+ nodeStorage->initialize(config->options, gamestate);
|
|
|
}
|
|
|
|
|
|
bool CPathfinderHelper::canMoveBetween(const int3 & a, const int3 & b) const
|