AIPreviousNodeRule.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * AIPreviousNodeRule.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 "AIPreviousNodeRule.h"
  12. namespace NKAI
  13. {
  14. namespace AIPathfinding
  15. {
  16. AIPreviousNodeRule::AIPreviousNodeRule(std::shared_ptr<AINodeStorage> nodeStorage)
  17. : nodeStorage(nodeStorage)
  18. {
  19. }
  20. void AIPreviousNodeRule::process(
  21. const PathNodeInfo & source,
  22. CDestinationNodeInfo & destination,
  23. const PathfinderConfig * pathfinderConfig,
  24. CPathfinderHelper * pathfinderHelper) const
  25. {
  26. if(source.node->action == CGPathNode::ENodeAction::BLOCKING_VISIT
  27. || source.node->action == CGPathNode::ENodeAction::VISIT)
  28. {
  29. if(source.nodeObject
  30. && isObjectPassable(source.nodeObject, pathfinderHelper->hero->tempOwner, source.objectRelations))
  31. {
  32. return;
  33. }
  34. // we can not directly bypass objects, we need to interact with them first
  35. destination.node->theNodeBefore = source.node;
  36. #if NKAI_PATHFINDER_TRACE_LEVEL >= 1
  37. logAi->trace(
  38. "Link src node %s to destination node %s while bypassing visitable obj",
  39. source.coord.toString(),
  40. destination.coord.toString());
  41. #endif
  42. return;
  43. }
  44. }
  45. }
  46. }