AIPathfinder.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * AIPathfinder.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 "AINodeStorage.h"
  12. #include "ObjectGraph.h"
  13. #include "GraphPaths.h"
  14. #include "../AIUtility.h"
  15. namespace NKAI
  16. {
  17. class Nullkiller;
  18. struct PathfinderSettings
  19. {
  20. bool useHeroChain;
  21. uint8_t scoutTurnDistanceLimit;
  22. uint8_t mainTurnDistanceLimit;
  23. bool allowBypassObjects;
  24. PathfinderSettings()
  25. :useHeroChain(false),
  26. scoutTurnDistanceLimit(255),
  27. mainTurnDistanceLimit(255),
  28. allowBypassObjects(true)
  29. { }
  30. };
  31. class AIPathfinder
  32. {
  33. private:
  34. std::shared_ptr<AINodeStorage> storage;
  35. CPlayerSpecificInfoCallback * cb;
  36. Nullkiller * ai;
  37. static std::map<ObjectInstanceID, std::unique_ptr<GraphPaths>> heroGraphs;
  38. public:
  39. AIPathfinder(CPlayerSpecificInfoCallback * cb, Nullkiller * ai);
  40. void calculatePathInfo(std::vector<AIPath> & paths, const int3 & tile, bool includeGraph = false) const;
  41. bool isTileAccessible(const HeroPtr & hero, const int3 & tile) const;
  42. void updatePaths(const std::map<const CGHeroInstance *, HeroRole> & heroes, PathfinderSettings pathfinderSettings);
  43. void updateGraphs(const std::map<const CGHeroInstance *, HeroRole> & heroes, uint8_t mainScanDepth, uint8_t scoutScanDepth);
  44. void calculateQuickPathsWithBlocker(std::vector<AIPath> & result, const std::vector<const CGHeroInstance *> & heroes, const int3 & tile);
  45. void init();
  46. std::shared_ptr<AINodeStorage>getStorage()
  47. {
  48. return storage;
  49. }
  50. std::vector<AIPath> getPathInfo(const int3 & tile, bool includeGraph = false)
  51. {
  52. std::vector<AIPath> result;
  53. calculatePathInfo(result, tile, includeGraph);
  54. return result;
  55. }
  56. };
  57. }