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

AI pathfinding: fix getPathsToTile for water tiles

This commit is contained in:
Andrii Danylchenko 2018-10-28 15:03:40 +02:00
parent bd0f8f840a
commit d5b26d9592
3 changed files with 12 additions and 4 deletions

View File

@ -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)
{

View File

@ -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)
{

View File

@ -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());
}