mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2026-11-19 17:05:20 +08:00
fix(uxassist): preserve satellite targeting near gas giants
Only avoid an orbiting parent when the direct target segment intersects it. Constrain its avoidance radius to stay outside the target and follow a heading-selected tangent before resuming direct approach.
This commit is contained in:
1 parent
04a2fbb85a
commit
7f9f0b62ae
2 files changed
+74
-73
No files matched your search
@@ -160,7 +160,7 @@ The sync is implemented as an inline PowerShell `Exec` step inside the `ZipMod`
|
||||
- **Auto-construct planner:** `AutoConstructPatch` keeps a construction-site plan while drones work, chooses among a fixed candidate set using the native 120-target construction capacity, total drone travel cost, and player travel cost, then refines the strongest candidates to an actual ghost nearest the target-group center. Candidate scoring uses the planned flight altitude when evaluating build-range coverage. It replans before the current site is empty when the remaining local workload no longer covers the next flight. Candidate evaluation has fixed limits and uses allocation-free arrays; local construction checks scan actual hash entries instead of trusting stale module counters and include ghosts whose materials can be delivered from the mecha package.
|
||||
- **Auto-construct final pass:** When at most eight eligible construction ghosts remain, the planner bypasses site-hold hysteresis and routes directly to the nearest remaining ghost. The final-pass count is capped at nine during the existing prebuild scan, so large construction queues do not incur an additional unbounded performance cost.
|
||||
- **Auto-construct maintenance:** Planner scan reset, final-pass nearest-ghost routing, and route-arrival/recovery transitions use shared state helpers; no-op UI lifecycle forwarding is removed.
|
||||
- **Auto-navigation:** UXAssist now exposes one auto-cruise implementation through `PlayerPatch.AutoNavigation`; the former legacy cruise path and algorithm-selection branch are removed. The shared `ToggleAutoCruise` key and in-game button control the session state. The configuration entry is presented as `Enable auto-cruise`, and its navigation options are grouped beneath it as indented 13-point sub-options. Steering follows the original `PlayerMove_Sail.GameTick` interpolation cap of 1.6 degrees per tick and explicitly chooses a stable turn plane for antiparallel velocity and target directions. Target resolution is validated once and applied atomically for both the UI and tick path; moving-target velocity is converted to universal coordinates; obstacle escape and symmetric-obstacle bias are continuous per-tick calculations; direct sail steering only runs while the player is sailing. Target state and reusable obstacle data are reset through one navigation lifecycle path.
|
||||
- **Auto-navigation:** UXAssist now exposes one auto-cruise implementation through `PlayerPatch.AutoNavigation`; the former legacy cruise path and algorithm-selection branch are removed. The shared `ToggleAutoCruise` key and in-game button control the session state. The configuration entry is presented as `Enable auto-cruise`, and its navigation options are grouped beneath it as indented 13-point sub-options. Steering follows the original `PlayerMove_Sail.GameTick` interpolation cap of 1.6 degrees per tick and explicitly chooses a stable turn plane for antiparallel velocity and target directions. Target resolution is validated once and applied atomically for both the UI and tick path; moving-target velocity is converted to universal coordinates; direct sail steering only runs while the player is sailing. Target state and reusable obstacle data are reset through one navigation lifecycle path. Satellite targets use a target corridor: an orbiting parent is ignored when the direct player-to-target segment is clear, shrinks its avoidance radius so it cannot contain the target, and otherwise follows a current-heading-selected tangent around the parent before returning to the satellite.
|
||||
- **Auto-cruise flight input:** In the original `PlayerMove_Fly.GameTick`, `PlayerController.input0.y = 1` matches manual forward movement and `input1.y = 1` matches manual upward thrust. The auto-cruise `Fly` handler must preserve these signs so the mecha leaves a planet with the same orientation and motion as manual control.
|
||||
- **Shortcut input timing:** UXAssist dispatches mod shortcuts from a postfix of the original `VFInput.OnUpdate`, after DSP has refreshed its current modifier and UI input state. Do not move shortcut polling back to an independent plugin `Update()` or a logic-tick callback: CommonAPI `PressKeyBind.keyValue` combines Unity's current-frame `Input.GetKeyDown()` with `CombineKey` modifier caches refreshed by `VFInput.OnUpdate`. Polling before that refresh can miss a shortcut when a modifier changes in the same frame, which is easier to encounter at low frame rates. Keep the typing/menu guards and per-frame registry guards.
|
||||
- **UI clone initialization and text measurement:** UXAssist UI factories and dependent mods' direct UI clones treat runtime DSP objects as style sources only; after `Instantiate`, they explicitly reset stateful `UIButton`, `Text`, `Image`, `InputField`, `Slider`, and `UIComboBox` fields that can otherwise carry source state. Use `UXAssist.UI.Util.GetPreferredWidth` for dynamic text width because it invalidates DSP's custom text-generator cache before reading `preferredWidth`; do not replace it with a generic `TextGenerator` or canvas-wide rebuild without validating the rendered result.
|
||||
|
||||
@@ -355,13 +355,10 @@ public class PlayerPatch : PatchImpl<PlayerPatch>
|
||||
private const double StarSafeRedis = 2000;
|
||||
private const double PlanetSafeRedis = 2000;
|
||||
private const double HiveSafeRedis = GalaxyData.AU * 0.5;
|
||||
|
||||
private const double FollowModeUseWarpDistance = GalaxyData.AU * 1.5;
|
||||
private const double ResidualCompensationMaxDistance = GalaxyData.AU * 0.5;
|
||||
private const double ResidualCompensationSpeedRatio = 0.5;
|
||||
private const double ResidualCompensationMinSpeed = 100;
|
||||
private const double ObstacleLookAheadDistance = GalaxyData.AU;
|
||||
private const double ObstacleEscapeAltitude = 200;
|
||||
|
||||
private static bool _enabled;
|
||||
private static Text _uiTipText;
|
||||
@@ -664,8 +661,9 @@ public class PlayerPatch : PatchImpl<PlayerPatch>
|
||||
|
||||
Player player = controller.player;
|
||||
double currentSpeed = player.uVelocity.magnitude;
|
||||
VectorLF3 targetDir = ComputeDirection(player.uPosition, Obstacles);
|
||||
VectorLF3 currentDir = SafeNorm(player.uVelocity, targetDir);
|
||||
VectorLF3 preliminaryDir = SafeNorm(_targetUniversePosition - player.uPosition, default);
|
||||
VectorLF3 currentDir = SafeNorm(player.uVelocity, preliminaryDir);
|
||||
VectorLF3 targetDir = ComputeDirection(player.uPosition, currentDir, Obstacles);
|
||||
if (player.warping)
|
||||
UpdateSailVelocityAndRotation(controller, currentDir, currentSpeed, targetDir, currentSpeed);
|
||||
else
|
||||
@@ -731,85 +729,88 @@ public class PlayerPatch : PatchImpl<PlayerPatch>
|
||||
/// <param name="playerPos">Player position.</param>
|
||||
/// <param name="obstacles">Nearby obstacles.</param>
|
||||
/// <returns></returns>
|
||||
private static VectorLF3 ComputeDirection(VectorLF3 playerPos, List<Obstacle> obstacles)
|
||||
private static VectorLF3 ComputeDirection(VectorLF3 playerPos, VectorLF3 currentDirection, List<Obstacle> obstacles)
|
||||
{
|
||||
VectorLF3 toTarget = _targetUniversePosition - playerPos;
|
||||
VectorLF3 toTarget = _targetUniversePosition - playerPos;
|
||||
double toTargetSqr = toTarget.sqrMagnitude;
|
||||
if (toTargetSqr < Epsilon)
|
||||
return default;
|
||||
VectorLF3 baseDir = toTarget.normalized;
|
||||
if (obstacles.Count == 0)
|
||||
return baseDir;
|
||||
|
||||
VectorLF3 avoid = default;
|
||||
double sumWeight = 0;
|
||||
VectorLF3 baseDir = toTarget.normalized;
|
||||
foreach (Obstacle obstacle in obstacles)
|
||||
{
|
||||
double safeR = obstacle.SafeRadius;
|
||||
if (safeR <= 0.0)
|
||||
continue;
|
||||
VectorLF3 toObject = obstacle.Position - playerPos;
|
||||
double toObjectSqr = toObject.sqrMagnitude;
|
||||
if (toObjectSqr > toTargetSqr)
|
||||
double pathRadius = GetReachablePathRadius(obstacle);
|
||||
if (pathRadius <= 0.0)
|
||||
continue;
|
||||
|
||||
double toObjectMagnitude = Math.Sqrt(toObjectSqr);
|
||||
if (toObjectMagnitude > ObstacleLookAheadDistance)
|
||||
continue;
|
||||
|
||||
double toObjectAltitude = toObjectMagnitude - obstacle.Radius;
|
||||
double forward = VectorLF3.Dot(toObject, baseDir);
|
||||
VectorLF3 pushVector = baseDir * forward - toObject;
|
||||
|
||||
double escapeExitAltitude = Math.Max(ObstacleEscapeAltitude * 3, obstacle.Radius * 1.5);
|
||||
if (toObjectAltitude < escapeExitAltitude && (forward > 0 || toObjectAltitude < 0))
|
||||
{
|
||||
VectorLF3 outward = SafeNorm(-toObject, -baseDir);
|
||||
VectorLF3 tangent = baseDir - outward * VectorLF3.Dot(baseDir, outward);
|
||||
tangent = SafeNorm(tangent, GetPerpendicularDirection(baseDir, VectorLF3.unit_y));
|
||||
double escapeWeight = Clamp(
|
||||
(escapeExitAltitude - toObjectAltitude) / (escapeExitAltitude - ObstacleEscapeAltitude),
|
||||
0,
|
||||
1);
|
||||
return SafeNorm(outward * escapeWeight + tangent * (1 - escapeWeight), outward);
|
||||
}
|
||||
|
||||
// Only consider obstacles in front of the player.
|
||||
if (forward <= 0.0)
|
||||
continue;
|
||||
double pushSqr = pushVector.sqrMagnitude;
|
||||
double pushMagnitude = Math.Sqrt(pushSqr);
|
||||
if (pushSqr < Epsilon)
|
||||
continue;
|
||||
if (pushMagnitude >= safeR)
|
||||
continue;
|
||||
|
||||
// Weight and combine avoidance forces by distance.
|
||||
double pushW = (safeR - pushMagnitude) / safeR;
|
||||
pushW = Clamp(pushW, 0, 1);
|
||||
double forwardRange = Math.Max(ObstacleLookAheadDistance - safeR, Epsilon);
|
||||
double forwardW = 1 - (forward - safeR) / forwardRange;
|
||||
forwardW = Clamp(forwardW, 0, 1);
|
||||
double weight = pushW * pushW * (3.0 - 2.0 * pushW) * forwardW * forwardW;
|
||||
VectorLF3 pushDir = pushVector / pushMagnitude;
|
||||
avoid += pushDir * weight;
|
||||
sumWeight += weight;
|
||||
VectorLF3 toObstacle = obstacle.Position - playerPos;
|
||||
double obstacleDistance = toObstacle.magnitude;
|
||||
if (obstacleDistance < pathRadius)
|
||||
return ComputeEscapeDirection(currentDirection, toObstacle, baseDir);
|
||||
if (IsSegmentBlocked(playerPos, _targetUniversePosition, obstacle.Position, pathRadius))
|
||||
return ComputeTangentDirection(currentDirection, toObstacle, pathRadius, baseDir);
|
||||
}
|
||||
|
||||
double avoidSqr = avoid.sqrMagnitude;
|
||||
if (sumWeight < Epsilon)
|
||||
return baseDir;
|
||||
return baseDir;
|
||||
}
|
||||
|
||||
VectorLF3 mixed = baseDir + avoid;
|
||||
double avoidStrength = Math.Sqrt(avoidSqr);
|
||||
if (avoidStrength < sumWeight * 0.6)
|
||||
{
|
||||
VectorLF3 lift = GetPerpendicularDirection(baseDir, VectorLF3.unit_y);
|
||||
mixed += lift.normalized * (Clamp(1 - avoidStrength / sumWeight, 0, 1) * 0.25);
|
||||
}
|
||||
private static double GetReachablePathRadius(Obstacle obstacle)
|
||||
{
|
||||
double targetClearance = (obstacle.Position - _targetUniversePosition).magnitude - _targetArriveThresholdRadius;
|
||||
return Math.Min(obstacle.PathRadius, targetClearance);
|
||||
}
|
||||
|
||||
double mixedSqr = mixed.sqrMagnitude;
|
||||
return mixedSqr < Epsilon ? baseDir : mixed.normalized;
|
||||
private static bool IsSegmentBlocked(
|
||||
VectorLF3 start,
|
||||
VectorLF3 end,
|
||||
VectorLF3 center,
|
||||
double pathRadius)
|
||||
{
|
||||
VectorLF3 segment = end - start;
|
||||
double segmentLength = segment.magnitude;
|
||||
if (segmentLength < Epsilon)
|
||||
return false;
|
||||
|
||||
VectorLF3 toCenter = center - start;
|
||||
double projection = VectorLF3.Dot(toCenter, segment) / segmentLength;
|
||||
double closestDistance = projection <= 0.0
|
||||
? toCenter.magnitude
|
||||
: projection >= segmentLength
|
||||
? (center - end).magnitude
|
||||
: Math.Sqrt(Math.Max(0.0, toCenter.sqrMagnitude - projection * projection));
|
||||
return closestDistance < pathRadius;
|
||||
}
|
||||
|
||||
private static VectorLF3 ComputeEscapeDirection(VectorLF3 currentDirection, VectorLF3 toObstacle, VectorLF3 fallback)
|
||||
{
|
||||
VectorLF3 outward = SafeNorm(-toObstacle, -fallback);
|
||||
VectorLF3 tangent = currentDirection - outward * VectorLF3.Dot(currentDirection, outward);
|
||||
tangent = SafeNorm(tangent, GetPerpendicularDirection(outward, VectorLF3.unit_y));
|
||||
return SafeNorm(outward + tangent * 0.5, outward);
|
||||
}
|
||||
|
||||
private static VectorLF3 ComputeTangentDirection(
|
||||
VectorLF3 currentDirection,
|
||||
VectorLF3 toObstacle,
|
||||
double pathRadius,
|
||||
VectorLF3 fallback)
|
||||
{
|
||||
double obstacleDistance = toObstacle.magnitude;
|
||||
if (obstacleDistance < Epsilon)
|
||||
return ComputeEscapeDirection(currentDirection, toObstacle, fallback);
|
||||
|
||||
VectorLF3 radial = toObstacle / obstacleDistance;
|
||||
double cosAngle = Clamp(pathRadius / obstacleDistance, 0.0, 1.0);
|
||||
double sinAngle = Math.Sqrt(Math.Max(0.0, 1.0 - cosAngle * cosAngle));
|
||||
VectorLF3 side = currentDirection - radial * VectorLF3.Dot(currentDirection, radial);
|
||||
if (side.sqrMagnitude < Epsilon)
|
||||
side = _targetUniverseVelocity - radial * VectorLF3.Dot(_targetUniverseVelocity, radial);
|
||||
if (side.sqrMagnitude < Epsilon)
|
||||
side = fallback - radial * VectorLF3.Dot(fallback, radial);
|
||||
if (side.sqrMagnitude < Epsilon)
|
||||
side = GetPerpendicularDirection(radial, VectorLF3.unit_y);
|
||||
|
||||
return SafeNorm(radial * cosAngle + side.normalized * sinAngle, fallback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1164,7 +1165,7 @@ public class PlayerPatch : PatchImpl<PlayerPatch>
|
||||
{
|
||||
public VectorLF3 Position { get; } = position;
|
||||
public double Radius { get; } = radius;
|
||||
public double SafeRadius { get; } = radius + safetyMargin;
|
||||
public double PathRadius { get; } = radius + safetyMargin;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in new issue
Block a user