mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
Pathfinding: move getNode into CPathsInfo
This commit is contained in:
parent
4b64bec711
commit
9c1c7d0caf
@ -79,7 +79,7 @@ void CPathfinder::calculatePaths()
|
||||
//logGlobal->infoStream() << boost::format("Calculating paths for hero %s (adress %d) of player %d") % hero->name % hero % hero->tempOwner;
|
||||
|
||||
//initial tile - set cost on 0 and add to the queue
|
||||
CGPathNode &initialNode = *getNode(out.hpos, hero->boat ? EPathfindingLayer::SAIL : EPathfindingLayer::LAND);
|
||||
CGPathNode &initialNode = *out.getNode(out.hpos, hero->boat ? EPathfindingLayer::SAIL : EPathfindingLayer::LAND);
|
||||
initialNode.turns = 0;
|
||||
initialNode.moveRemains = hero->movement;
|
||||
mq.push_back(&initialNode);
|
||||
@ -100,7 +100,7 @@ void CPathfinder::calculatePaths()
|
||||
addNeighbours(cp->coord);
|
||||
for(auto & neighbour : neighbours)
|
||||
{
|
||||
dp = getNode(neighbour, EPathfindingLayer::LAND);
|
||||
dp = out.getNode(neighbour, EPathfindingLayer::LAND);
|
||||
dt = &gs->map->getTile(neighbour);
|
||||
useEmbarkCost = 0; //0 - usual movement; 1 - embark; 2 - disembark
|
||||
|
||||
@ -143,7 +143,7 @@ void CPathfinder::calculatePaths()
|
||||
addTeleportExits();
|
||||
for(auto & neighbour : neighbours)
|
||||
{
|
||||
dp = getNode(neighbour, EPathfindingLayer::LAND);
|
||||
dp = out.getNode(neighbour, EPathfindingLayer::LAND);
|
||||
if(isBetterWay(movement, turn))
|
||||
{
|
||||
dp->moveRemains = movement;
|
||||
@ -360,11 +360,6 @@ void CPathfinder::initializeGraph()
|
||||
}
|
||||
}
|
||||
|
||||
CGPathNode *CPathfinder::getNode(const int3 &coord, const EPathfindingLayer &layer)
|
||||
{
|
||||
return &out.nodes[coord.x][coord.y][coord.z][layer];
|
||||
}
|
||||
|
||||
CGPathNode::EAccessibility CPathfinder::evaluateAccessibility(const int3 &pos, const TerrainTile *tinfo) const
|
||||
{
|
||||
CGPathNode::EAccessibility ret = (tinfo->blocked ? CGPathNode::BLOCKED : CGPathNode::ACCESSIBLE);
|
||||
@ -530,7 +525,7 @@ const CGPathNode * CPathsInfo::getPathInfo(const int3 &tile, const EPathfindingL
|
||||
|
||||
if(tile.x >= sizes.x || tile.y >= sizes.y || tile.z >= sizes.z || layer >= EPathfindingLayer::NUM_LAYERS)
|
||||
return nullptr;
|
||||
return &nodes[tile.x][tile.y][tile.z][layer];
|
||||
return getNode(tile, layer);
|
||||
}
|
||||
|
||||
bool CPathsInfo::getPath(CGPath &out, const int3 &dst, const EPathfindingLayer &layer) const
|
||||
@ -538,7 +533,7 @@ bool CPathsInfo::getPath(CGPath &out, const int3 &dst, const EPathfindingLayer &
|
||||
boost::unique_lock<boost::mutex> pathLock(pathMx);
|
||||
|
||||
out.nodes.clear();
|
||||
const CGPathNode *curnode = &nodes[dst.x][dst.y][dst.z][layer];
|
||||
const CGPathNode *curnode = getNode(dst, layer);
|
||||
if(!curnode->theNodeBefore)
|
||||
return false;
|
||||
|
||||
@ -562,3 +557,15 @@ int CPathsInfo::getDistance(const int3 &tile, const EPathfindingLayer &layer) co
|
||||
else
|
||||
return 255;
|
||||
}
|
||||
|
||||
CGPathNode *CPathsInfo::getNode(const int3 &coord, const EPathfindingLayer &layer) const
|
||||
{
|
||||
if(layer != EPathfindingLayer::AUTO)
|
||||
return &nodes[coord.x][coord.y][coord.z][layer];
|
||||
|
||||
auto landNode = &nodes[coord.x][coord.y][coord.z][EPathfindingLayer::LAND];
|
||||
if(landNode->theNodeBefore)
|
||||
return landNode;
|
||||
else
|
||||
return &nodes[coord.x][coord.y][coord.z][EPathfindingLayer::SAIL];
|
||||
}
|
||||
|
@ -65,6 +65,7 @@ struct DLL_LINKAGE CPathsInfo
|
||||
const CGPathNode * getPathInfo(const int3 &tile, const EPathfindingLayer &layer = EPathfindingLayer::AUTO) const;
|
||||
bool getPath(CGPath &out, const int3 &dst, const EPathfindingLayer &layer = EPathfindingLayer::AUTO) const;
|
||||
int getDistance(const int3 &tile, const EPathfindingLayer &layer = EPathfindingLayer::AUTO) const;
|
||||
CGPathNode *getNode(const int3 &coord, const EPathfindingLayer &layer) const;
|
||||
};
|
||||
|
||||
class CPathfinder : private CGameInfoCallback
|
||||
@ -114,7 +115,6 @@ private:
|
||||
|
||||
void initializeGraph();
|
||||
|
||||
CGPathNode *getNode(const int3 &coord, const EPathfindingLayer &layer);
|
||||
CGPathNode::EAccessibility evaluateAccessibility(const int3 &pos, const TerrainTile *tinfo) 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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user