AIPreviousNodeRule.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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
  25. || source.node->action == CGPathNode::ENodeAction::VISIT)
  26. {
  27. if(source.nodeObject)
  28. {
  29. if((source.nodeObject->ID == Obj::GARRISON || source.nodeObject->ID == Obj::GARRISON2)
  30. && source.heroRelations != PlayerRelations::ENEMIES)
  31. return;
  32. if(source.nodeObject->ID == Obj::BORDER_GATE)
  33. {
  34. auto quest = dynamic_cast<const CGBorderGate *>(source.nodeObject);
  35. if(quest->wasMyColorVisited(pathfinderHelper->hero->tempOwner))
  36. return;
  37. }
  38. }
  39. // we can not directly bypass objects, we need to interact with them first
  40. destination.node->theNodeBefore = source.node;
  41. #if PATHFINDER_TRACE_LEVEL >= 1
  42. logAi->trace(
  43. "Link src node %s to destination node %s while bypassing visitable obj",
  44. source.coord.toString(),
  45. destination.coord.toString());
  46. #endif
  47. return;
  48. }
  49. }
  50. }