Browse Source

CPathfinder: fix special movement boundary check

Forgot to fix it for water walking after fe12b8f664a6f38b71cf914a6326d6cb81dc1253
ArseniyShestakov 10 years ago
parent
commit
df4515901d
2 changed files with 17 additions and 9 deletions
  1. 14 9
      lib/CPathfinder.cpp
  2. 3 0
      lib/CPathfinder.h

+ 14 - 9
lib/CPathfinder.cpp

@@ -59,16 +59,21 @@ CPathfinder::CPathfinder(CPathsInfo & _out, CGameState * _gs, const CGHeroInstan
 
 void CPathfinder::calculatePaths()
 {
-	auto passOneTurnLimitCheck = [&](bool shouldCheck) -> bool
+	auto passOneTurnLimitCheck = [&]() -> bool
 	{
-		if(options.oneTurnSpecialLayersLimit && shouldCheck)
+		if(!options.oneTurnSpecialLayersLimit)
+			return true;
+
+		if(cp->layer == ELayer::WATER)
+			return false;
+		if(cp->layer == ELayer::AIR)
 		{
-			if((cp->layer == ELayer::AIR || cp->layer == ELayer::WATER)
-				&& cp->accessible != CGPathNode::ACCESSIBLE)
-			{
+			if(options.originalMovementRules && cp->accessible == CGPathNode::ACCESSIBLE)
+				return true;
+			else
 				return false;
-			}
 		}
+
 		return true;
 	};
 
@@ -104,7 +109,7 @@ void CPathfinder::calculatePaths()
 		{
 			hlp->updateTurnInfo(++turn);
 			movement = hlp->getMaxMovePoints(cp->layer);
-			if(!passOneTurnLimitCheck(true))
+			if(!passOneTurnLimitCheck())
 				continue;
 		}
 		ct = &gs->map->getTile(cp->coord);
@@ -155,8 +160,8 @@ void CPathfinder::calculatePaths()
 					remains = moveAtNextTile - cost;
 				}
 
-				if(isBetterWay(remains, turnAtNextTile)
-					&& passOneTurnLimitCheck(cp->turns != turnAtNextTile || !remains))
+				if(isBetterWay(remains, turnAtNextTile) &&
+					((cp->turns == turnAtNextTile && remains) || passOneTurnLimitCheck()))
 				{
 					assert(dp != cp->theNodeBefore); //two tiles can't point to each other
 					dp->moveRemains = remains;

+ 3 - 0
lib/CPathfinder.h

@@ -135,6 +135,9 @@ private:
 		///
 		/// Following imitation is default H3 mechanics, but someone may want to disable it in mods.
 		/// After all this limit should benefit performance on maps with tons of water or blocked tiles.
+		///
+		/// TODO:
+		/// - Behavior when option is disabled not implemented and will lead to crashes.
 		bool oneTurnSpecialLayersLimit;
 
 		/// VCMI have different movement rules to solve flaws original engine has.