AIPathfinderConfig.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. bool allowBypassObjects)
  27. {
  28. std::vector<std::shared_ptr<IPathfindingRule>> rules = {
  29. std::make_shared<AILayerTransitionRule>(cb, ai, nodeStorage),
  30. std::make_shared<DestinationActionRule>(),
  31. std::make_shared<AIMovementToDestinationRule>(nodeStorage, allowBypassObjects),
  32. std::make_shared<MovementCostRule>(),
  33. std::make_shared<AIPreviousNodeRule>(nodeStorage),
  34. std::make_shared<AIMovementAfterDestinationRule>(ai, cb, nodeStorage, allowBypassObjects)
  35. };
  36. return rules;
  37. }
  38. AIPathfinderConfig::AIPathfinderConfig(
  39. CPlayerSpecificInfoCallback * cb,
  40. Nullkiller * ai,
  41. std::shared_ptr<AINodeStorage> nodeStorage,
  42. bool allowBypassObjects)
  43. :PathfinderConfig(nodeStorage, cb, makeRuleset(cb, ai, nodeStorage, allowBypassObjects)), aiNodeStorage(nodeStorage)
  44. {
  45. options.canUseCast = true;
  46. options.allowLayerTransitioningAfterBattle = true;
  47. options.useTeleportWhirlpool = true;
  48. options.forceUseTeleportWhirlpool = true;
  49. options.useTeleportOneWay = ai->settings->isOneWayMonolithUsageAllowed();
  50. options.useTeleportOneWayRandom = ai->settings->isOneWayMonolithUsageAllowed();
  51. }
  52. AIPathfinderConfig::~AIPathfinderConfig() = default;
  53. CPathfinderHelper * AIPathfinderConfig::getOrCreatePathfinderHelper(const PathNodeInfo & source, CGameState * gs)
  54. {
  55. auto hero = aiNodeStorage->getHero(source.node);
  56. auto & helper = pathfindingHelpers[hero];
  57. if(!helper)
  58. {
  59. helper.reset(new CPathfinderHelper(gs, hero, options));
  60. }
  61. return helper.get();
  62. }
  63. }
  64. }