AIMovementToDestinationRule.cpp 1.3 KB

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