mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	AI pathfinding: fix getPathsToTile for water tiles
This commit is contained in:
		| @@ -181,10 +181,10 @@ bool AINodeStorage::hasBetterChain(const PathNodeInfo & source, CDestinationNode | ||||
| 	return false; | ||||
| } | ||||
|  | ||||
| std::vector<AIPath> AINodeStorage::getChainInfo(int3 pos) const | ||||
| std::vector<AIPath> AINodeStorage::getChainInfo(int3 pos, bool isOnLand) const | ||||
| { | ||||
| 	std::vector<AIPath> paths; | ||||
| 	auto chains = nodes[pos.x][pos.y][pos.z][EPathfindingLayer::LAND]; | ||||
| 	auto chains = nodes[pos.x][pos.y][pos.z][isOnLand ? EPathfindingLayer::LAND : EPathfindingLayer::SAIL]; | ||||
|  | ||||
| 	for(const AIPathNode & node : chains) | ||||
| 	{ | ||||
|   | ||||
| @@ -98,7 +98,7 @@ public: | ||||
| 	bool isBattleNode(const CGPathNode * node) const; | ||||
| 	bool hasBetterChain(const PathNodeInfo & source, CDestinationNodeInfo & destination) const; | ||||
| 	boost::optional<AIPathNode *> getOrCreateNode(const int3 & coord, const EPathfindingLayer layer, int chainNumber); | ||||
| 	std::vector<AIPath> getChainInfo(int3 pos) const; | ||||
| 	std::vector<AIPath> getChainInfo(int3 pos, bool isOnLand) const; | ||||
|  | ||||
| 	void setHero(HeroPtr heroPtr) | ||||
| 	{ | ||||
|   | ||||
| @@ -11,6 +11,7 @@ | ||||
| #include "AIPathfinder.h" | ||||
| #include "AIPathfinderConfig.h" | ||||
| #include "../../../CCallback.h" | ||||
| #include "../../../lib/mapping/CMap.h" | ||||
|  | ||||
| std::vector<std::shared_ptr<AINodeStorage>> AIPathfinder::storagePool; | ||||
| std::map<HeroPtr, std::shared_ptr<AINodeStorage>> AIPathfinder::storageMap; | ||||
| @@ -58,5 +59,12 @@ std::vector<AIPath> AIPathfinder::getPathInfo(HeroPtr hero, int3 tile) | ||||
| 		nodeStorage = storageMap.at(hero); | ||||
| 	} | ||||
|  | ||||
| 	return nodeStorage->getChainInfo(tile); | ||||
| 	const TerrainTile * tileInfo = cb->getTile(tile, false); | ||||
|  | ||||
| 	if(!tileInfo) | ||||
| 	{ | ||||
| 		return std::vector<AIPath>(); | ||||
| 	} | ||||
|  | ||||
| 	return nodeStorage->getChainInfo(tile, !tileInfo->isWater()); | ||||
| } | ||||
		Reference in New Issue
	
	Block a user