PathfindingManager.h 2.1 KB

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