PathfindingManager.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * PathfindingManager.h, 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. #pragma once
  11. #include "../VCAI.h"
  12. #include "AINodeStorage.h"
  13. class DLL_EXPORT IPathfindingManager
  14. {
  15. public:
  16. virtual ~IPathfindingManager() = default;
  17. virtual void init(CPlayerSpecificInfoCallback * CB) = 0;
  18. virtual void setAI(VCAI * AI) = 0;
  19. virtual void updatePaths(std::vector<HeroPtr> heroes, bool useHeroChain = false) = 0;
  20. virtual std::vector<AIPath> getPathsToTile(const HeroPtr & hero, const int3 & tile) const = 0;
  21. virtual std::vector<AIPath> getPathsToTile(const int3 & tile) const = 0;
  22. };
  23. class DLL_EXPORT PathfindingManager : public IPathfindingManager
  24. {
  25. friend class AIhelper;
  26. private:
  27. CPlayerSpecificInfoCallback * cb; //this is enough, but we downcast from CCallback
  28. VCAI * ai;
  29. std::unique_ptr<AIPathfinder> pathfinder;
  30. public:
  31. PathfindingManager() = default;
  32. PathfindingManager(CPlayerSpecificInfoCallback * CB, VCAI * AI = nullptr); //for tests only
  33. std::vector<AIPath> getPathsToTile(const HeroPtr & hero, const int3 & tile) const override;
  34. std::vector<AIPath> getPathsToTile(const int3 & tile) const override;
  35. void updatePaths(std::vector<HeroPtr> heroes, bool useHeroChain = false) override;
  36. STRONG_INLINE
  37. bool isTileAccessible(const HeroPtr & hero, const int3 & tile) const
  38. {
  39. return pathfinder->isTileAccessible(hero, tile);
  40. }
  41. private:
  42. void init(CPlayerSpecificInfoCallback * CB) override;
  43. void setAI(VCAI * AI) override;
  44. Goals::TGoalVec findPaths(
  45. crint3 dest,
  46. bool allowGatherArmy,
  47. HeroPtr hero,
  48. const std::function<Goals::TSubgoal(int3)> goalFactory) const;
  49. Goals::TSubgoal clearWayTo(HeroPtr hero, int3 firstTileToGet) const;
  50. };