AIPreviousNodeRule.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 AIPathfinding
  13. {
  14. AIPreviousNodeRule::AIPreviousNodeRule(std::shared_ptr<AINodeStorage> nodeStorage)
  15. : nodeStorage(nodeStorage)
  16. {
  17. }
  18. void AIPreviousNodeRule::process(
  19. const PathNodeInfo & source,
  20. CDestinationNodeInfo & destination,
  21. const PathfinderConfig * pathfinderConfig,
  22. CPathfinderHelper * pathfinderHelper) const
  23. {
  24. if(source.node->action == CGPathNode::ENodeAction::BLOCKING_VISIT || source.node->action == CGPathNode::ENodeAction::VISIT)
  25. {
  26. // we can not directly bypass objects, we need to interact with them first
  27. destination.node->theNodeBefore = source.node;
  28. #ifdef VCMI_TRACE_PATHFINDER
  29. logAi->trace(
  30. "Link src node %s to destination node %s while bypassing visitable obj",
  31. source.coord.toString(),
  32. destination.coord.toString());
  33. #endif
  34. return;
  35. }
  36. auto aiSourceNode = nodeStorage->getAINode(source.node);
  37. if(aiSourceNode->specialAction)
  38. {
  39. // there is some action on source tile which should be performed before we can bypass it
  40. destination.node->theNodeBefore = source.node;
  41. }
  42. }
  43. }