From b1a78ce285a7dc8264bd9cb392175b4d09736678 Mon Sep 17 00:00:00 2001 From: Angen Date: Thu, 26 Dec 2019 21:03:15 +0000 Subject: [PATCH] Treat min range in the same manner as max range when computing goal Problem description: When unit gets command to move to the range exactly X units from some point/entity, what means minRange == maxRange, that triggers computing goal when distance < minRange with result distance(goal, target) > maxRange, because minRange computation uses clearance even when is treating target as circle. Solution: Do not use clearance when treating target as circle, so computation when distance < minimum range is done in same way as computation when distance > maximum range and so computed goal has correct position. Reported on forum: https://wildfiregames.com/forum/index.php?/topic/27384-strange-landing-on-the-island-and-unable-to-attack/ Differential Revision: https://code.wildfiregames.com/D2512 Tested by: gameboy This was SVN commit r23283. --- source/simulation2/components/CCmpUnitMotion.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/source/simulation2/components/CCmpUnitMotion.cpp b/source/simulation2/components/CCmpUnitMotion.cpp index 43baeac0d3..c1a0688dd4 100644 --- a/source/simulation2/components/CCmpUnitMotion.cpp +++ b/source/simulation2/components/CCmpUnitMotion.cpp @@ -1320,18 +1320,17 @@ bool CCmpUnitMotion::ComputeGoal(PathGoal& out, const MoveRequest& moveRequest) // min-range is not 0 and max-range is not infinity. if (distance < moveRequest.m_MinRange) { - // Distance checks are nearest edge to nearest edge, so we need to account for our clearance - // and we must make sure diagonals also fit so multiply by slightly more than sqrt(2) - entity_pos_t goalDistance = moveRequest.m_MinRange + m_Clearance * 3 / 2; - if (ShouldTreatTargetAsCircle(moveRequest.m_MinRange, circleRadius)) { // We are safely away from the obstruction itself if we are away from the circumscribing circle out.type = PathGoal::INVERTED_CIRCLE; - out.hw = circleRadius + goalDistance; + out.hw = circleRadius + moveRequest.m_MinRange; } else { + // Distance checks are nearest edge to nearest edge, so we need to account for our clearance + // and we must make sure diagonals also fit so multiply by slightly more than sqrt(2) + entity_pos_t goalDistance = moveRequest.m_MinRange + m_Clearance * 3 / 2; out.type = PathGoal::INVERTED_SQUARE; out.hw = targetObstruction.hw + goalDistance; out.hh = targetObstruction.hh + goalDistance;