AIMovementToDestinationRule.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * AIMovementToDestinationRule.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 "AIMovementToDestinationRule.h"
  12. namespace NKAI
  13. {
  14. namespace AIPathfinding
  15. {
  16. AIMovementToDestinationRule::AIMovementToDestinationRule(std::shared_ptr<AINodeStorage> nodeStorage)
  17. : nodeStorage(nodeStorage)
  18. {
  19. }
  20. void AIMovementToDestinationRule::process(
  21. const PathNodeInfo & source,
  22. CDestinationNodeInfo & destination,
  23. const PathfinderConfig * pathfinderConfig,
  24. CPathfinderHelper * pathfinderHelper) const
  25. {
  26. auto blocker = getBlockingReason(source, destination, pathfinderConfig, pathfinderHelper);
  27. if(blocker == BlockingReason::NONE)
  28. return;
  29. if(blocker == BlockingReason::DESTINATION_BLOCKED
  30. && destination.action == EPathNodeAction::EMBARK
  31. && nodeStorage->getAINode(destination.node)->specialAction)
  32. {
  33. return;
  34. }
  35. if(blocker == BlockingReason::SOURCE_GUARDED && nodeStorage->getAINode(source.node)->actor->allowBattle)
  36. {
  37. #if NKAI_PATHFINDER_TRACE_LEVEL >= 1
  38. logAi->trace(
  39. "Bypass src guard while moving from %s to %s",
  40. source.coord.toString(),
  41. destination.coord.toString());
  42. #endif
  43. return;
  44. }
  45. destination.blocked = true;
  46. }
  47. }
  48. }