Index: source/simulation2/components/CCmpUnitMotion.cpp =================================================================== --- source/simulation2/components/CCmpUnitMotion.cpp +++ source/simulation2/components/CCmpUnitMotion.cpp @@ -634,9 +634,10 @@ /** * React if our move was obstructed. * @param moved - true if the unit still managed to move. + * @param notify - true if we possibly should increment movement fails and notify * @returns true if the obstruction required handling, false otherwise. */ - bool HandleObstructedMove(bool moved); + bool HandleObstructedMove(bool moved, bool notify); /** * Returns true if the target position is valid. False otherwise. @@ -887,9 +888,19 @@ UpdateMovementState(offset.Length() / dt); } - if (wasObstructed && HandleObstructedMove(pos != initialPos)) + bool willBeObstructed = false; + + if (!wasObstructed && m_ShortPath.m_Waypoints.empty() && !m_LongPath.m_Waypoints.empty()) + { + CFixedVector2D target = CFixedVector2D(m_LongPath.m_Waypoints.back().x, m_LongPath.m_Waypoints.back().z); + CmpPtr cmpPathfinder(GetSystemEntity()); + if (cmpPathfinder) + willBeObstructed = !cmpPathfinder->CheckMovement(GetObstructionFilter(), pos.X, pos.Y, target.X, target.Y, m_Clearance, m_PassClass); + } + + if ((wasObstructed || willBeObstructed) && HandleObstructedMove(pos != initialPos || angle != initialAngle, wasObstructed)) return; - else if (!wasObstructed && pos != initialPos) + else if (!wasObstructed && (pos != initialPos || angle != initialAngle)) m_FailedMovements = 0; // We may need to recompute our path sometimes (e.g. if our target moves). @@ -1077,7 +1088,7 @@ m_CurSpeed = speed; } -bool CCmpUnitMotion::HandleObstructedMove(bool moved) +bool CCmpUnitMotion::HandleObstructedMove(bool moved, bool notify) { CmpPtr cmpPosition(GetEntityHandle()); if (!cmpPosition || !cmpPosition->IsInWorld()) @@ -1086,7 +1097,7 @@ // We failed to move, inform other components as they might handle it. // (don't send messages on the first failure, as that would be too noisy). // Also don't increment above the initial MoveObstructed message if we actually manage to move a little. - if (!moved || m_FailedMovements < 2) + if (notify && (!moved || m_FailedMovements < 2)) { if (!IncrementFailedMovementsAndMaybeNotify() && m_FailedMovements >= 2) MoveObstructed();