AIPathfinderConfig.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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, *cb, makeRuleset(cb, ai, nodeStorage)), hero(nodeStorage->getHero())
  39. {
  40. options.ignoreGuards = false;
  41. options.useEmbarkAndDisembark = true;
  42. options.useTeleportTwoWay = true;
  43. options.useTeleportOneWay = true;
  44. options.useTeleportOneWayRandom = true;
  45. options.useTeleportWhirlpool = true;
  46. }
  47. AIPathfinderConfig::~AIPathfinderConfig() = default;
  48. CPathfinderHelper * AIPathfinderConfig::getOrCreatePathfinderHelper(const PathNodeInfo & source, const IGameInfoCallback & gameInfo)
  49. {
  50. if(!helper)
  51. {
  52. helper.reset(new CPathfinderHelper(gameInfo, hero, options));
  53. }
  54. return helper.get();
  55. }
  56. }