# Changeset View

Changeset View

# Standalone View

Standalone View

# ps/trunk/source/simulation2/components/CCmpUnitMotion.cpp

Show First 20 Lines • Show All 1,395 Lines • ▼ Show 20 Lines | else if (maxRange >= entity_pos_t::Zero() && distance > maxRange) | ||||

goal.type = PathGoal::CIRCLE; | goal.type = PathGoal::CIRCLE; | ||||

goal.hw = maxRange; | goal.hw = maxRange; | ||||

// If maxRange was abnormally small, | // If maxRange was abnormally small, | ||||

// collapse the circle into a point | // collapse the circle into a point | ||||

if (goal.hw <= entity_pos_t::Zero()) | if (goal.hw <= entity_pos_t::Zero()) | ||||

goal.type = PathGoal::POINT; | goal.type = PathGoal::POINT; | ||||

} | } | ||||

else | |||||

{ | |||||

// We're already in range - no need to move anywhere | |||||

if (m_FacePointAfterMove) | |||||

FaceTowardsPointFromPos(pos, x, z); | |||||

return true; | |||||

} | |||||

} | } | ||||

m_State = STATE_INDIVIDUAL_PATH; | m_State = STATE_INDIVIDUAL_PATH; | ||||

m_MoveRequest = MoveRequest(CFixedVector2D(x, z), minRange, maxRange); | m_MoveRequest = MoveRequest(CFixedVector2D(x, z), minRange, maxRange); | ||||

m_FinalGoal = goal; | m_FinalGoal = goal; | ||||

m_Tries = 0; | m_Tries = 0; | ||||

BeginPathing(pos, goal); | BeginPathing(pos, goal); | ||||

▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | if ((distance < minRange && previousDistance < minRange) || inside) | ||||

{ | { | ||||

goal.type = PathGoal::INVERTED_SQUARE; | goal.type = PathGoal::INVERTED_SQUARE; | ||||

goal.u = obstruction.u; | goal.u = obstruction.u; | ||||

goal.v = obstruction.v; | goal.v = obstruction.v; | ||||

goal.hw = obstruction.hw + goalDistance; | goal.hw = obstruction.hw + goalDistance; | ||||

goal.hh = obstruction.hh + goalDistance; | goal.hh = obstruction.hh + goalDistance; | ||||

} | } | ||||

} | } | ||||

else if (maxRange < entity_pos_t::Zero() || distance < maxRange || previousDistance < maxRange) | |||||

{ | |||||

// We're already in range - no need to move anywhere | |||||

FaceTowardsPointFromPos(pos, goal.x, goal.z); | |||||

return true; | |||||

} | |||||

else | else | ||||

{ | { | ||||

// We might need to move closer: | // We might need to move closer: | ||||

// Circumscribe the square | // Circumscribe the square | ||||

entity_pos_t circleRadius = halfSize.Length(); | entity_pos_t circleRadius = halfSize.Length(); | ||||

if (ShouldTreatTargetAsCircle(maxRange, circleRadius)) | if (ShouldTreatTargetAsCircle(maxRange, circleRadius)) | ||||

{ | { | ||||

// The target is small relative to our range, so pretend it's a circle | // The target is small relative to our range, so pretend it's a circle | ||||

// Note that the distance to the circle will always be less than | // Note that the distance to the circle will always be less than | ||||

// the distance to the square, so the previous "distance < maxRange" | // the distance to the square, so the previous "distance < maxRange" | ||||

// check is still valid (though not sufficient) | // check is still valid (though not sufficient) | ||||

entity_pos_t circleDistance = (pos - CFixedVector2D(obstruction.x, obstruction.z)).Length() - circleRadius; | entity_pos_t circleDistance = (pos - CFixedVector2D(obstruction.x, obstruction.z)).Length() - circleRadius; | ||||

entity_pos_t previousCircleDistance = (pos - CFixedVector2D(previousObstruction.x, previousObstruction.z)).Length() - circleRadius; | entity_pos_t previousCircleDistance = (pos - CFixedVector2D(previousObstruction.x, previousObstruction.z)).Length() - circleRadius; | ||||

if (circleDistance < maxRange || previousCircleDistance < maxRange) | |||||

{ | |||||

// We're already in range - no need to move anywhere | |||||

if (m_FacePointAfterMove) | |||||

FaceTowardsPointFromPos(pos, goal.x, goal.z); | |||||

return true; | |||||

} | |||||

entity_pos_t goalDistance = maxRange; | entity_pos_t goalDistance = maxRange; | ||||

goal.type = PathGoal::CIRCLE; | goal.type = PathGoal::CIRCLE; | ||||

goal.hw = circleRadius + goalDistance; | goal.hw = circleRadius + goalDistance; | ||||

} | } | ||||

else | else | ||||

{ | { | ||||

// The target is large relative to our range, so treat it as a square and | // The target is large relative to our range, so treat it as a square and | ||||

▲ Show 20 Lines • Show All 91 Lines • Show Last 20 Lines |

Wildfire Games · Phabricator