Browse Source

vcmi: really correct BFS

AFAIK, all is working as H3.
Konstantin 2 years ago
parent
commit
88a7b3141d
2 changed files with 7 additions and 1 deletions
  1. 6 1
      lib/battle/CBattleInfoCallback.cpp
  2. 1 0
      lib/battle/ReachabilityInfo.h

+ 6 - 1
lib/battle/CBattleInfoCallback.cpp

@@ -932,6 +932,8 @@ ReachabilityInfo CBattleInfoCallback::makeBFS(const AccessibilityInfo &accessibi
 		return ret;
 
 	const std::set<BattleHex> obstacles = getStoppers(params.perspective);
+	auto checkParams = params;
+	checkParams.ignoreKnownAccessible = true; //Ignore starting hexes obstacles
 
 	std::queue<BattleHex> hexq; //bfs queue
 
@@ -949,7 +951,7 @@ ReachabilityInfo CBattleInfoCallback::makeBFS(const AccessibilityInfo &accessibi
 		hexq.pop();
 
 		//walking stack can't step past the obstacles
-		if(curHex != params.startPosition && isInObstacle(curHex, obstacles, params))
+		if(isInObstacle(curHex, obstacles, checkParams))
 			continue;
 
 		const int costToNeighbour = ret.distances[curHex.hex] + 1;
@@ -982,6 +984,9 @@ bool CBattleInfoCallback::isInObstacle(
 
 	for(auto occupiedHex : occupiedHexes)
 	{
+		if(params.ignoreKnownAccessible && vstd::contains(params.knownAccessible, occupiedHex))
+			continue;
+
 		if(vstd::contains(obstacles, occupiedHex))
 		{
 			if(occupiedHex == ESiegeHex::GATE_BRIDGE)

+ 1 - 0
lib/battle/ReachabilityInfo.h

@@ -28,6 +28,7 @@ struct DLL_LINKAGE ReachabilityInfo
 		ui8 side = 0;
 		bool doubleWide = false;
 		bool flying = false;
+		bool ignoreKnownAccessible = false; //Ignore obstacles if it is in accessible hexes
 		std::vector<BattleHex> knownAccessible; //hexes that will be treated as accessible, even if they're occupied by stack (by default - tiles occupied by stack we do reachability for, so it doesn't block itself)
 
 		BattleHex startPosition; //assumed position of stack