AIPathfinder.h 1.7 KB

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