Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/helpers/VertexPathfinder.cpp
Show First 20 Lines • Show All 519 Lines • ▼ Show 20 Lines | WaypointPath VertexPathfinder::ComputeShortPath(const ShortPathRequest& request, CmpPtr<ICmpObstructionManager> cmpObstructionManager) const | ||||
// Create impassable edges at the max-range boundary, so we can't escape the region | // Create impassable edges at the max-range boundary, so we can't escape the region | ||||
// where we're meant to be searching | // where we're meant to be searching | ||||
fixed rangeXMin = request.x0 - request.range; | fixed rangeXMin = request.x0 - request.range; | ||||
fixed rangeXMax = request.x0 + request.range; | fixed rangeXMax = request.x0 + request.range; | ||||
fixed rangeZMin = request.z0 - request.range; | fixed rangeZMin = request.z0 - request.range; | ||||
fixed rangeZMax = request.z0 + request.range; | fixed rangeZMax = request.z0 + request.range; | ||||
// If useful, move the center of the search-space so that it's slightly towards the goal, | // If the goal is outside the bounds, move the center of the search-space towards it slightly, | ||||
// as the vertex pathfinder tends to be used to get around entities in front of us. | // as the vertex pathfinder tends to be used to get around entities in front of us | ||||
// (this makes it possible to use smaller search ranges, but still find good paths). | |||||
// Don't do this for the largest ranges: it makes it harder to backtrack, and large search domains | |||||
// indicate a rather stuck unit, which means having to backtrack is probable. | |||||
// (keep this in sync with unitMotion's max-search range). | |||||
// (this also ensures symmetrical behaviour for goals inside/outside the max search range). | |||||
CFixedVector2D toGoal = CFixedVector2D(request.goal.x, request.goal.z) - CFixedVector2D(request.x0, request.z0); | CFixedVector2D toGoal = CFixedVector2D(request.goal.x, request.goal.z) - CFixedVector2D(request.x0, request.z0); | ||||
if (toGoal.CompareLength(request.range) >= 0) | if (toGoal.CompareLength(request.range) >= 0 && request.range < fixed::FromInt(TERRAIN_TILE_SIZE) * 10) | ||||
{ | { | ||||
fixed toGoalLength = toGoal.Length(); | fixed toGoalLength = toGoal.Length(); | ||||
fixed inv = fixed::FromInt(1) / toGoalLength; | fixed inv = fixed::FromInt(1) / toGoalLength; | ||||
rangeXMin += (toGoal.Multiply(std::min(toGoalLength / 2, request.range * 3 / 5)).Multiply(inv)).X; | rangeXMin += (toGoal.Multiply(std::min(toGoalLength / 2, request.range * 3 / 5)).Multiply(inv)).X; | ||||
rangeXMax += (toGoal.Multiply(std::min(toGoalLength / 2, request.range * 3 / 5)).Multiply(inv)).X; | rangeXMax += (toGoal.Multiply(std::min(toGoalLength / 2, request.range * 3 / 5)).Multiply(inv)).X; | ||||
rangeZMin += (toGoal.Multiply(std::min(toGoalLength / 2, request.range * 3 / 5)).Multiply(inv)).Y; | rangeZMin += (toGoal.Multiply(std::min(toGoalLength / 2, request.range * 3 / 5)).Multiply(inv)).Y; | ||||
rangeZMax += (toGoal.Multiply(std::min(toGoalLength / 2, request.range * 3 / 5)).Multiply(inv)).Y; | rangeZMax += (toGoal.Multiply(std::min(toGoalLength / 2, request.range * 3 / 5)).Multiply(inv)).Y; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 449 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator