瀏覽代碼

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.
ArseniyShestakov 10 年之前
父節點
當前提交
2b6e1498d2
共有 6 個文件被更改,包括 12 次插入12 次删除
  1. 1 1
      AI/VCAI/AIUtility.cpp
  2. 2 2
      AI/VCAI/VCAI.cpp
  3. 2 2
      client/CPlayerInterface.cpp
  4. 2 2
      client/windows/CAdvmapInterface.cpp
  5. 2 2
      lib/CPathfinder.cpp
  6. 3 3
      lib/CPathfinder.h

+ 1 - 1
AI/VCAI/AIUtility.cpp

@@ -372,7 +372,7 @@ int3 whereToExplore(HeroPtr h)
 			{
 			{
 				int3 op = obj->visitablePos();
 				int3 op = obj->visitablePos();
 				CGPath p;
 				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 (p.nodes.size() && p.endPos() == op && p.nodes.size() <= DIST_LIMIT)
 					if (ai->isGoodForVisit(obj, h, sm))
 					if (ai->isGoodForVisit(obj, h, sm))
 						nearbyVisitableObjs.push_back(obj);
 						nearbyVisitableObjs.push_back(obj);

+ 2 - 2
AI/VCAI/VCAI.cpp

@@ -1840,7 +1840,7 @@ bool VCAI::moveHeroToTile(int3 dst, HeroPtr h)
 	else
 	else
 	{
 	{
 		CGPath path;
 		CGPath path;
-		cb->getPathsInfo(h.get())->getPath(dst, path);
+		cb->getPathsInfo(h.get())->getPath(path, dst);
 		if(path.nodes.empty())
 		if(path.nodes.empty())
 		{
 		{
             logAi->errorStream() << "Hero " << h->name << " cannot reach " << dst;
             logAi->errorStream() << "Hero " << h->name << " cannot reach " << dst;
@@ -2519,7 +2519,7 @@ int3 VCAI::explorationNewPoint(HeroPtr h)
 				continue;
 				continue;
 
 
 			CGPath path;
 			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
 			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
 			if (ourValue > bestValue) //avoid costly checks of tiles that don't reveal much

+ 2 - 2
client/CPlayerInterface.cpp

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

+ 2 - 2
client/windows/CAdvmapInterface.cpp

@@ -1190,7 +1190,7 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
 			CGPath &path = LOCPLINT->paths[h];
 			CGPath &path = LOCPLINT->paths[h];
 			terrain.currentPath = &path;
 			terrain.currentPath = &path;
 			int3 dst = h->getPosition(false) + dir;
 			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;
 				terrain.currentPath = nullptr;
 				return;
 				return;
@@ -1445,7 +1445,7 @@ void CAdvMapInt::tileLClicked(const int3 &mapPos)
 			{
 			{
 				CGPath &path = LOCPLINT->paths[currentHero];
 				CGPath &path = LOCPLINT->paths[currentHero];
 				terrain.currentPath = &path;
 				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);
 				updateMoveHero(currentHero);
 				if (!gotPath)
 				if (!gotPath)
 					LOCPLINT->eraseCurrentPathOf(currentHero);
 					LOCPLINT->eraseCurrentPathOf(currentHero);

+ 2 - 2
lib/CPathfinder.cpp

@@ -532,7 +532,7 @@ const CGPathNode * CPathsInfo::getPathInfo(const int3 &tile, const EPathfindingL
 	return &nodes[tile.x][tile.y][tile.z][layer];
 	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);
 	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);
 	boost::unique_lock<boost::mutex> pathLock(pathMx);
 
 
 	CGPath ret;
 	CGPath ret;
-	if(getPath(tile, layer, ret))
+	if(getPath(ret, tile, layer))
 		return ret.nodes.size();
 		return ret.nodes.size();
 	else
 	else
 		return 255;
 		return 255;

+ 3 - 3
lib/CPathfinder.h

@@ -62,9 +62,9 @@ struct DLL_LINKAGE CPathsInfo
 
 
 	CPathsInfo(const int3 &Sizes);
 	CPathsInfo(const int3 &Sizes);
 	~CPathsInfo();
 	~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
 class CPathfinder : private CGameInfoCallback