AIPathfinderConfig.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 "../Engine//Nullkiller.h"
  17. #include "../../../lib/pathfinder/CPathfinder.h"
  18. namespace NKAI
  19. {
  20. namespace AIPathfinding
  21. {
  22. std::vector<std::shared_ptr<IPathfindingRule>> makeRuleset(
  23. CPlayerSpecificInfoCallback * cb,
  24. Nullkiller * ai,
  25. std::shared_ptr<AINodeStorage> nodeStorage)
  26. {
  27. std::vector<std::shared_ptr<IPathfindingRule>> rules = {
  28. std::make_shared<AILayerTransitionRule>(cb, ai, nodeStorage),
  29. std::make_shared<DestinationActionRule>(),
  30. std::make_shared<AIMovementToDestinationRule>(nodeStorage),
  31. std::make_shared<MovementCostRule>(),
  32. std::make_shared<AIPreviousNodeRule>(nodeStorage),
  33. std::make_shared<AIMovementAfterDestinationRule>(cb, nodeStorage)
  34. };
  35. return rules;
  36. }
  37. AIPathfinderConfig::AIPathfinderConfig(
  38. CPlayerSpecificInfoCallback * cb,
  39. Nullkiller * ai,
  40. std::shared_ptr<AINodeStorage> nodeStorage)
  41. :PathfinderConfig(nodeStorage, makeRuleset(cb, ai, nodeStorage)), aiNodeStorage(nodeStorage)
  42. {
  43. options.canUseCast = true;
  44. }
  45. AIPathfinderConfig::~AIPathfinderConfig() = default;
  46. CPathfinderHelper * AIPathfinderConfig::getOrCreatePathfinderHelper(const PathNodeInfo & source, CGameState * gs)
  47. {
  48. auto hero = aiNodeStorage->getHero(source.node);
  49. auto & helper = pathfindingHelpers[hero];
  50. if(!helper)
  51. {
  52. helper.reset(new CPathfinderHelper(gs, hero, options));
  53. }
  54. return helper.get();
  55. }
  56. }
  57. }