AIPathfinderConfig.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. }
  44. AIPathfinderConfig::~AIPathfinderConfig() = default;
  45. CPathfinderHelper * AIPathfinderConfig::getOrCreatePathfinderHelper(const PathNodeInfo & source, CGameState * gs)
  46. {
  47. auto hero = aiNodeStorage->getHero(source.node);
  48. auto & helper = pathfindingHelpers[hero];
  49. if(!helper)
  50. {
  51. helper.reset(new CPathfinderHelper(gs, hero, options));
  52. }
  53. return helper.get();
  54. }
  55. }
  56. }