/* * AIPathfinder.cpp, part of VCMI engine * * Authors: listed in file AUTHORS in main folder * * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * */ #include "StdInc.h" #include "AIPathfinder.h" #include "AIPathfinderConfig.h" #include "../../../CCallback.h" #include "../../../lib/mapping/CMap.h" std::shared_ptr AIPathfinder::storage; AIPathfinder::AIPathfinder(CPlayerSpecificInfoCallback * cb, VCAI * ai) :cb(cb), ai(ai) { } void AIPathfinder::init() { storage.reset(); } bool AIPathfinder::isTileAccessible(const HeroPtr & hero, const int3 & tile) const { return storage->isTileAccessible(hero, tile, EPathfindingLayer::LAND) || storage->isTileAccessible(hero, tile, EPathfindingLayer::SAIL); } std::vector AIPathfinder::getPathInfo(const HeroPtr & hero, const int3 & tile) const { const TerrainTile * tileInfo = cb->getTile(tile, false); if(!tileInfo) { return std::vector(); } return storage->getChainInfo(tile, !tileInfo->isWater()); } void AIPathfinder::updatePaths(std::vector heroes) { if(!storage) { storage = std::make_shared(cb->getMapSize()); } logAi->debug("Recalculate all paths"); storage.reset(); storage->setHeroes(heroes, ai); auto config = std::make_shared(cb, ai, storage); cb->calculatePaths(config); } void AIPathfinder::updatePaths(const HeroPtr & hero) { updatePaths(std::vector{hero}); }