AIPathfinderConfig.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. options.useEmbarkAndDisembark = true;
  41. options.useTeleportTwoWay = true;
  42. options.useTeleportOneWay = true;
  43. options.useTeleportOneWayRandom = true;
  44. options.useTeleportWhirlpool = true;
  45. }
  46. AIPathfinderConfig::~AIPathfinderConfig() = default;
  47. CPathfinderHelper * AIPathfinderConfig::getOrCreatePathfinderHelper(const PathNodeInfo & source, CGameState * gs)
  48. {
  49. if(!helper)
  50. {
  51. helper.reset(new CPathfinderHelper(gs, hero, options));
  52. }
  53. return helper.get();
  54. }
  55. }