1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Pathfinding: change argument order for getPath and AUTO layer as default

This still need investigation, but likely most of external code shouldn't be aware of layers in order to work properly because only LAND and SAIL can be targeted and single tile can't have both of these layers.
This commit is contained in:
ArseniyShestakov 2015-11-02 11:14:32 +03:00
parent b8253206c7
commit 2b6e1498d2
6 changed files with 12 additions and 12 deletions

View File

@ -372,7 +372,7 @@ int3 whereToExplore(HeroPtr h)
{
int3 op = obj->visitablePos();
CGPath p;
ai->myCb->getPathsInfo(h.get())->getPath(op, p);
ai->myCb->getPathsInfo(h.get())->getPath(p, ops);
if (p.nodes.size() && p.endPos() == op && p.nodes.size() <= DIST_LIMIT)
if (ai->isGoodForVisit(obj, h, sm))
nearbyVisitableObjs.push_back(obj);

View File

@ -1840,7 +1840,7 @@ bool VCAI::moveHeroToTile(int3 dst, HeroPtr h)
else
{
CGPath path;
cb->getPathsInfo(h.get())->getPath(dst, path);
cb->getPathsInfo(h.get())->getPath(path, dst);
if(path.nodes.empty())
{
logAi->errorStream() << "Hero " << h->name << " cannot reach " << dst;
@ -2519,7 +2519,7 @@ int3 VCAI::explorationNewPoint(HeroPtr h)
continue;
CGPath path;
cb->getPathsInfo(hero)->getPath(tile, path);
cb->getPathsInfo(hero)->getPath(path, tile);
float ourValue = (float)howManyTilesWillBeDiscovered(tile, radius, cbp) / (path.nodes.size() + 1); //+1 prevents erratic jumps
if (ourValue > bestValue) //avoid costly checks of tiles that don't reveal much

View File

@ -1288,7 +1288,7 @@ template <typename Handler> void CPlayerInterface::serializeTempl( Handler &h, c
for(auto &p : pathsMap)
{
CGPath path;
cb->getPathsInfo(p.first)->getPath(p.second, path);
cb->getPathsInfo(p.first)->getPath(path, p.second);
paths[p.first] = path;
logGlobal->traceStream() << boost::format("Restored path for hero %s leading to %s with %d nodes")
% p.first->nodeName() % p.second % path.nodes.size();
@ -2226,7 +2226,7 @@ CGPath * CPlayerInterface::getAndVerifyPath(const CGHeroInstance * h)
{
assert(h->getPosition(false) == path.startPos());
//update the hero path in case of something has changed on map
if(LOCPLINT->cb->getPathsInfo(h)->getPath(path.endPos(), path))
if(LOCPLINT->cb->getPathsInfo(h)->getPath(path, path.endPos()))
return &path;
else
paths.erase(h);

View File

@ -1190,7 +1190,7 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
CGPath &path = LOCPLINT->paths[h];
terrain.currentPath = &path;
int3 dst = h->getPosition(false) + dir;
if(dst != verifyPos(dst) || !LOCPLINT->cb->getPathsInfo(h)->getPath(dst, path))
if(dst != verifyPos(dst) || !LOCPLINT->cb->getPathsInfo(h)->getPath(path, dst))
{
terrain.currentPath = nullptr;
return;
@ -1445,7 +1445,7 @@ void CAdvMapInt::tileLClicked(const int3 &mapPos)
{
CGPath &path = LOCPLINT->paths[currentHero];
terrain.currentPath = &path;
bool gotPath = LOCPLINT->cb->getPathsInfo(currentHero)->getPath(mapPos, path); //try getting path, erase if failed
bool gotPath = LOCPLINT->cb->getPathsInfo(currentHero)->getPath(path, mapPos); //try getting path, erase if failed
updateMoveHero(currentHero);
if (!gotPath)
LOCPLINT->eraseCurrentPathOf(currentHero);

View File

@ -532,7 +532,7 @@ const CGPathNode * CPathsInfo::getPathInfo(const int3 &tile, const EPathfindingL
return &nodes[tile.x][tile.y][tile.z][layer];
}
bool CPathsInfo::getPath(const int3 &dst, const EPathfindingLayer &layer, CGPath &out) const
bool CPathsInfo::getPath(CGPath &out, const int3 &dst, const EPathfindingLayer &layer) const
{
boost::unique_lock<boost::mutex> pathLock(pathMx);
@ -556,7 +556,7 @@ int CPathsInfo::getDistance(const int3 &tile, const EPathfindingLayer &layer) co
boost::unique_lock<boost::mutex> pathLock(pathMx);
CGPath ret;
if(getPath(tile, layer, ret))
if(getPath(ret, tile, layer))
return ret.nodes.size();
else
return 255;

View File

@ -62,9 +62,9 @@ struct DLL_LINKAGE CPathsInfo
CPathsInfo(const int3 &Sizes);
~CPathsInfo();
const CGPathNode * getPathInfo(const int3 &tile, const EPathfindingLayer &layer) const;
bool getPath(const int3 &dst, const EPathfindingLayer &layer, CGPath &out) const;
int getDistance(const int3 &tile, const EPathfindingLayer &layer) const;
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;
};
class CPathfinder : private CGameInfoCallback