AIPreviousNodeRule.cpp 1.3 KB

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