1
0
forked from mirrors/0ad

revert e0771b98dd which was based on misunderstanding of the algo, and fix the inverted_circle case, refs #3577

This was SVN commit r17184.
This commit is contained in:
mimo
2015-11-05 19:22:04 +00:00
parent 05547bf36f
commit 83bba7bdfc
@@ -1495,15 +1495,11 @@ bool CCmpUnitMotion::ShouldTreatTargetAsCircle(entity_pos_t range, entity_pos_t
// is a round-cornered square which we can approximate as either a circle or as a square.
// Choose the shape that will minimise the worst-case error:
entity_pos_t rSquare = std::min(hw, hh);
if (range < rSquare)
return false;
// For a square, error is (sqrt(2)-1) * (range-rSquare) at the corners
entity_pos_t errSquare = (entity_pos_t::FromInt(4142)/10000).Multiply(range-rSquare);
entity_pos_t errSquare = (entity_pos_t::FromInt(4142)/10000).Multiply(range);
// For a circle, error is radius-hw at the sides and radius-hh at the top/bottom
entity_pos_t errCircle = circleRadius - rSquare;
entity_pos_t errCircle = circleRadius - std::min(hw, hh);
return (errCircle < errSquare);
}
@@ -1586,14 +1582,12 @@ bool CCmpUnitMotion::MoveToTargetRange(entity_id_t target, entity_pos_t minRange
entity_pos_t circleRadius = halfSize.Length();
entity_pos_t goalDistance = minRange + Pathfinding::GOAL_DELTA;
// ensure it's far enough to not intersect the building itself (TODO is it really needed for inverted move ?)
goalDistance = std::max(goalDistance, m_Clearance + entity_pos_t::FromInt(TERRAIN_TILE_SIZE)/16);
if (ShouldTreatTargetAsCircle(minRange, obstruction.hw, obstruction.hh, circleRadius))
{
// The target is small relative to our range, so pretend it's a circle
goal.type = PathGoal::INVERTED_CIRCLE;
goal.hw = goalDistance;
goal.hw = circleRadius + goalDistance;
}
else
{