AIPathfinderConfig.cpp 2.2 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 "AI/Nullkiller2/Engine/Nullkiller.h"
  12. #include "AIPathfinderConfig.h"
  13. #include "Rules/AILayerTransitionRule.h"
  14. #include "Rules/AIMovementAfterDestinationRule.h"
  15. #include "Rules/AIMovementToDestinationRule.h"
  16. #include "Rules/AIPreviousNodeRule.h"
  17. #include "../../../lib/pathfinder/CPathfinder.h"
  18. namespace NK2AI
  19. {
  20. namespace AIPathfinding
  21. {
  22. std::vector<std::shared_ptr<IPathfindingRule>>
  23. makeRuleset(CPlayerSpecificInfoCallback * cpsic, Nullkiller * aiNk, std::shared_ptr<AINodeStorage> nodeStorage, bool allowBypassObjects)
  24. {
  25. std::vector<std::shared_ptr<IPathfindingRule>> rules = {
  26. std::make_shared<AILayerTransitionRule>(aiNk, nodeStorage),
  27. std::make_shared<DestinationActionRule>(),
  28. std::make_shared<AIMovementToDestinationRule>(nodeStorage, allowBypassObjects, *aiNk->cc),
  29. std::make_shared<MovementCostRule>(),
  30. std::make_shared<AIPreviousNodeRule>(nodeStorage),
  31. std::make_shared<AIMovementAfterDestinationRule>(aiNk, nodeStorage, allowBypassObjects)
  32. };
  33. return rules;
  34. }
  35. AIPathfinderConfig::AIPathfinderConfig(Nullkiller * aiNk, std::shared_ptr<AINodeStorage> nodeStorage, bool allowBypassObjects)
  36. : PathfinderConfig(nodeStorage, *aiNk->cc, makeRuleset(aiNk->cc.get(), aiNk, nodeStorage, allowBypassObjects)), aiNodeStorage(nodeStorage)
  37. {
  38. options.canUseCast = true;
  39. options.allowLayerTransitioningAfterBattle = true;
  40. options.useTeleportWhirlpool = true;
  41. options.forceUseTeleportWhirlpool = true;
  42. options.useTeleportOneWay = aiNk->settings->isOneWayMonolithUsageAllowed();
  43. options.useTeleportOneWayRandom = aiNk->settings->isOneWayMonolithUsageAllowed();
  44. }
  45. AIPathfinderConfig::~AIPathfinderConfig() = default;
  46. CPathfinderHelper * AIPathfinderConfig::getOrCreatePathfinderHelper(const PathNodeInfo & source, const IGameInfoCallback & gameInfo)
  47. {
  48. auto hero = aiNodeStorage->getHero(source.node);
  49. auto & helper = pathfindingHelpers[hero];
  50. if(!helper)
  51. {
  52. helper.reset(new CPathfinderHelper(gameInfo, hero, options));
  53. }
  54. return helper.get();
  55. }
  56. }
  57. }