PathfindingManager.h 1.9 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 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. };
  26. class 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(HeroPtr hero, int3 tile, bool allowGatherArmy = true) override;
  37. Goals::TGoalVec howToVisitObj(HeroPtr hero, ObjectIdRef obj, bool allowGatherArmy = true) override;
  38. Goals::TGoalVec howToVisitTile(int3 tile) override;
  39. Goals::TGoalVec howToVisitObj(ObjectIdRef obj) override;
  40. std::vector<AIPath> getPathsToTile(HeroPtr hero, int3 tile) override;
  41. void resetPaths() override;
  42. private:
  43. void init(CPlayerSpecificInfoCallback * CB) override;
  44. void setAI(VCAI * AI) override;
  45. Goals::TGoalVec findPath(
  46. HeroPtr hero,
  47. crint3 dest,
  48. bool allowGatherArmy,
  49. const std::function<Goals::TSubgoal(int3)> goalFactory);
  50. Goals::TSubgoal clearWayTo(HeroPtr hero, int3 firstTileToGet);
  51. };