Browse Source

#2689 - fix approaching guards when closest tile is double-guarded

Andrii Danylchenko 2 years ago
parent
commit
903be33bf3

+ 5 - 0
lib/pathfinder/CPathfinder.cpp

@@ -455,6 +455,11 @@ bool CPathfinderHelper::passOneTurnLimitCheck(const PathNodeInfo & source) const
 	return true;
 }
 
+int CPathfinderHelper::getGuardiansCount(int3 tile) const
+{
+	return getGuardingCreatures(tile).size();
+}
+
 CPathfinderHelper::CPathfinderHelper(CGameState * gs, const CGHeroInstance * Hero, const PathfinderOptions & Options):
 	CGameInfoCallback(gs),
 	turn(-1),

+ 2 - 0
lib/pathfinder/CPathfinder.h

@@ -121,6 +121,8 @@ public:
 
 	int movementPointsAfterEmbark(int movement, int basicCost, bool disembark) const;
 	bool passOneTurnLimitCheck(const PathNodeInfo & source) const;
+
+	int getGuardiansCount(int3 tile) const;
 };
 
 VCMI_LIB_NAMESPACE_END

+ 2 - 2
lib/pathfinder/PathfindingRules.cpp

@@ -298,8 +298,8 @@ PathfinderBlockingRule::BlockingReason MovementToDestinationRule::getBlockingRea
 
 		if(source.guarded)
 		{
-			if(!(pathfinderConfig->options.originalMovementRules && source.node->layer == EPathfindingLayer::AIR) &&
-				!destination.isGuardianTile) // Can step into tile of guard
+			if(!(pathfinderConfig->options.originalMovementRules && source.node->layer == EPathfindingLayer::AIR) 
+				&&	(!destination.isGuardianTile || pathfinderHelper->getGuardiansCount(source.coord) > 1)) // Can step into tile of guard
 			{
 				return BlockingReason::SOURCE_GUARDED;
 			}