AIMovementToDestinationRule.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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(
  17. std::shared_ptr<AINodeStorage> nodeStorage,
  18. bool allowBypassObjects)
  19. : nodeStorage(nodeStorage), allowBypassObjects(allowBypassObjects)
  20. {
  21. }
  22. void AIMovementToDestinationRule::process(
  23. const PathNodeInfo & source,
  24. CDestinationNodeInfo & destination,
  25. const PathfinderConfig * pathfinderConfig,
  26. CPathfinderHelper * pathfinderHelper) const
  27. {
  28. auto blocker = getBlockingReason(source, destination, pathfinderConfig, pathfinderHelper);
  29. if(blocker == BlockingReason::NONE)
  30. return;
  31. if(blocker == BlockingReason::DESTINATION_BLOCKED
  32. && destination.action == EPathNodeAction::EMBARK
  33. && nodeStorage->getAINode(destination.node)->specialAction)
  34. {
  35. return;
  36. }
  37. if(blocker == BlockingReason::SOURCE_GUARDED)
  38. {
  39. auto actor = nodeStorage->getAINode(source.node)->actor;
  40. if(!allowBypassObjects)
  41. {
  42. if (source.node->getCost() < 0.0001f)
  43. return;
  44. // when actor represents moster graph node, we need to let him escape monster
  45. if(cb->getGuardingCreaturePosition(source.coord) == actor->initialPosition)
  46. return;
  47. }
  48. if(actor->allowBattle)
  49. {
  50. #if NKAI_PATHFINDER_TRACE_LEVEL >= 1
  51. logAi->trace(
  52. "Bypass src guard while moving from %s to %s",
  53. source.coord.toString(),
  54. destination.coord.toString());
  55. #endif
  56. return;
  57. }
  58. }
  59. destination.blocked = true;
  60. }
  61. }
  62. }