AIPathfinderConfig.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * AIPathfinderConfig.cpp, 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. #include "StdInc.h"
  11. #include "AIPathfinderConfig.h"
  12. #include "Rules/AILayerTransitionRule.h"
  13. #include "Rules/AIMovementAfterDestinationRule.h"
  14. #include "Rules/AIMovementToDestinationRule.h"
  15. #include "Rules/AIPreviousNodeRule.h"
  16. #include "../../../lib/pathfinder/CPathfinder.h"
  17. namespace AIPathfinding
  18. {
  19. std::vector<std::shared_ptr<IPathfindingRule>> makeRuleset(
  20. CPlayerSpecificInfoCallback * cb,
  21. VCAI * ai,
  22. std::shared_ptr<AINodeStorage> nodeStorage)
  23. {
  24. std::vector<std::shared_ptr<IPathfindingRule>> rules = {
  25. std::make_shared<AILayerTransitionRule>(cb, ai, nodeStorage),
  26. std::make_shared<DestinationActionRule>(),
  27. std::make_shared<AIMovementToDestinationRule>(nodeStorage),
  28. std::make_shared<MovementCostRule>(),
  29. std::make_shared<AIPreviousNodeRule>(nodeStorage),
  30. std::make_shared<AIMovementAfterDestinationRule>(cb, nodeStorage)
  31. };
  32. return rules;
  33. }
  34. AIPathfinderConfig::AIPathfinderConfig(
  35. CPlayerSpecificInfoCallback * cb,
  36. VCAI * ai,
  37. std::shared_ptr<AINodeStorage> nodeStorage)
  38. :PathfinderConfig(nodeStorage, makeRuleset(cb, ai, nodeStorage)), hero(nodeStorage->getHero())
  39. {
  40. }
  41. AIPathfinderConfig::~AIPathfinderConfig() = default;
  42. CPathfinderHelper * AIPathfinderConfig::getOrCreatePathfinderHelper(const PathNodeInfo & source, CGameState * gs)
  43. {
  44. if(!helper)
  45. {
  46. helper.reset(new CPathfinderHelper(gs, hero, options));
  47. }
  48. return helper.get();
  49. }
  50. }