PathfindingManager.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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) = 0;
  20. virtual Goals::TGoalVec howToVisitTile(const HeroPtr & hero, const int3 & tile, bool allowGatherArmy = true) const = 0;
  21. virtual Goals::TGoalVec howToVisitObj(const HeroPtr & hero, ObjectIdRef obj, bool allowGatherArmy = true) const = 0;
  22. virtual Goals::TGoalVec howToVisitTile(const int3 & tile) const = 0;
  23. virtual Goals::TGoalVec howToVisitObj(ObjectIdRef obj) const = 0;
  24. virtual std::vector<AIPath> getPathsToTile(const HeroPtr & hero, const int3 & tile) const = 0;
  25. };
  26. class DLL_EXPORT PathfindingManager : public IPathfindingManager
  27. {
  28. friend class AIhelper;
  29. private:
  30. CPlayerSpecificInfoCallback * cb; //this is enough, but we downcast from CCallback
  31. VCAI * ai;
  32. std::unique_ptr<AIPathfinder> pathfinder;
  33. public:
  34. PathfindingManager() = default;
  35. PathfindingManager(CPlayerSpecificInfoCallback * CB, VCAI * AI = nullptr); //for tests only
  36. Goals::TGoalVec howToVisitTile(const HeroPtr & hero, const int3 & tile, bool allowGatherArmy = true) const override;
  37. Goals::TGoalVec howToVisitObj(const HeroPtr & hero, ObjectIdRef obj, bool allowGatherArmy = true) const override;
  38. Goals::TGoalVec howToVisitTile(const int3 & tile) const override;
  39. Goals::TGoalVec howToVisitObj(ObjectIdRef obj) const override;
  40. std::vector<AIPath> getPathsToTile(const HeroPtr & hero, const int3 & tile) const override;
  41. void updatePaths(std::vector<HeroPtr> heroes) override;
  42. STRONG_INLINE
  43. bool isTileAccessible(const HeroPtr & hero, const int3 & tile) const
  44. {
  45. return pathfinder->isTileAccessible(hero, tile);
  46. }
  47. private:
  48. void init(CPlayerSpecificInfoCallback * CB) override;
  49. void setAI(VCAI * AI) override;
  50. Goals::TGoalVec findPath(
  51. HeroPtr hero,
  52. crint3 dest,
  53. bool allowGatherArmy,
  54. const std::function<Goals::TSubgoal(int3)> goalFactory) const;
  55. Goals::TSubgoal clearWayTo(HeroPtr hero, int3 firstTileToGet) const;
  56. };