PathfindingManager.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * PathfindingManager.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "PathfindingManager.h"
  12. #include "AIPathfinder.h"
  13. #include "AIPathfinderConfig.h"
  14. #include "../Goals/Goals.h"
  15. #include "../../../lib/CGameInfoCallback.h"
  16. #include "../../../lib/mapping/CMap.h"
  17. PathfindingManager::PathfindingManager(CPlayerSpecificInfoCallback * CB, VCAI * AI)
  18. : ai(AI), cb(CB)
  19. {
  20. }
  21. void PathfindingManager::init(CPlayerSpecificInfoCallback * CB)
  22. {
  23. cb = CB;
  24. pathfinder.reset(new AIPathfinder(cb, ai));
  25. pathfinder->init();
  26. }
  27. void PathfindingManager::setAI(VCAI * AI)
  28. {
  29. ai = AI;
  30. }
  31. std::vector<AIPath> PathfindingManager::getPathsToTile(const HeroPtr & hero, const int3 & tile) const
  32. {
  33. auto paths = pathfinder->getPathInfo(tile);
  34. vstd::erase_if(paths, [&](AIPath & path) -> bool{
  35. return path.targetHero != hero.h;
  36. });
  37. return paths;
  38. }
  39. std::vector<AIPath> PathfindingManager::getPathsToTile(const int3 & tile) const
  40. {
  41. return pathfinder->getPathInfo(tile);
  42. }
  43. void PathfindingManager::updatePaths(std::vector<HeroPtr> heroes, bool useHeroChain)
  44. {
  45. logAi->debug("AIPathfinder has been reseted.");
  46. pathfinder->updatePaths(heroes, useHeroChain);
  47. }