From d5b26d9592cd7a298351d818078e742b7e805913 Mon Sep 17 00:00:00 2001 From: Andrii Danylchenko Date: Sun, 28 Oct 2018 15:03:40 +0200 Subject: [PATCH] AI pathfinding: fix getPathsToTile for water tiles --- AI/VCAI/Pathfinding/AINodeStorage.cpp | 4 ++-- AI/VCAI/Pathfinding/AINodeStorage.h | 2 +- AI/VCAI/Pathfinding/AIPathfinder.cpp | 10 +++++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/AI/VCAI/Pathfinding/AINodeStorage.cpp b/AI/VCAI/Pathfinding/AINodeStorage.cpp index 638658064..6a77dd14d 100644 --- a/AI/VCAI/Pathfinding/AINodeStorage.cpp +++ b/AI/VCAI/Pathfinding/AINodeStorage.cpp @@ -181,10 +181,10 @@ bool AINodeStorage::hasBetterChain(const PathNodeInfo & source, CDestinationNode return false; } -std::vector AINodeStorage::getChainInfo(int3 pos) const +std::vector AINodeStorage::getChainInfo(int3 pos, bool isOnLand) const { std::vector 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) { diff --git a/AI/VCAI/Pathfinding/AINodeStorage.h b/AI/VCAI/Pathfinding/AINodeStorage.h index da657a105..2405abc9a 100644 --- a/AI/VCAI/Pathfinding/AINodeStorage.h +++ b/AI/VCAI/Pathfinding/AINodeStorage.h @@ -98,7 +98,7 @@ public: bool isBattleNode(const CGPathNode * node) const; bool hasBetterChain(const PathNodeInfo & source, CDestinationNodeInfo & destination) const; boost::optional getOrCreateNode(const int3 & coord, const EPathfindingLayer layer, int chainNumber); - std::vector getChainInfo(int3 pos) const; + std::vector getChainInfo(int3 pos, bool isOnLand) const; void setHero(HeroPtr heroPtr) { diff --git a/AI/VCAI/Pathfinding/AIPathfinder.cpp b/AI/VCAI/Pathfinding/AIPathfinder.cpp index f9f42371b..35bf0040f 100644 --- a/AI/VCAI/Pathfinding/AIPathfinder.cpp +++ b/AI/VCAI/Pathfinding/AIPathfinder.cpp @@ -11,6 +11,7 @@ #include "AIPathfinder.h" #include "AIPathfinderConfig.h" #include "../../../CCallback.h" +#include "../../../lib/mapping/CMap.h" std::vector> AIPathfinder::storagePool; std::map> AIPathfinder::storageMap; @@ -58,5 +59,12 @@ std::vector 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(); + } + + return nodeStorage->getChainInfo(tile, !tileInfo->isWater()); } \ No newline at end of file