fix(uxassist): keep stars and planets ahead of hives in auto-cruise escape

Weighting every containing obstacle by depth let a hive's 0.5 AU range
outweigh the planet right below the mecha, so a take-off under a hive
steered back into the ground.

Stars and planets keep their priority over hives, as before this branch:
while the mecha is inside any star or planet range, hives take no part.
Overlapping star and planet ranges are still left together, weighted by
depth; their safety margins are equal, so the nearest surface dominates.
Inside hive ranges only, the first containing hive is left, as before.

Add tools/tests/Test-AutoCruiseAvoidance.ps1: an offline check of the
avoidance heading for a plain take-off, a take-off under an overlapping
hive range, a take-off from a moon inside its gas giant's range, and a
hive on its own.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Jiesi LuoandClaude Fable 5.2 authored and Soar Qin committed 2026-11-16 09:05:47 +08:00
1 parent 5e6cfe7fa5
commit 4c0ad9c27f
3 files changed
+195 -11

No files matched your search

+27 -11
View File
@@ -655,13 +655,18 @@ public class PlayerPatch : PatchImpl<PlayerPatch>
VectorLF3 baseDir = toTarget.normalized;
// The mecha can be inside several path radii at once: a moon close to its gas giant puts a mecha
// on the moon inside both, and the giant comes first in the list. Leaving only the first one
// sends a mecha that takes off from the moon's giant-facing side back into the ground, because
// "away from the giant" points down there. Leave all of them together, each weighted by how deep
// the mecha is inside it, so the body right below dominates.
VectorLF3 inward = default;
bool insideObstacle = false;
// The mecha can be inside several path radii at once. Stars and planets keep priority over
// hives: a hive's range is wide enough to cover a whole planet, and leaving the hive first
// can steer a mecha that has just taken off back into the ground.
// Among stars and planets, a moon close to its gas giant puts a mecha on the moon inside both
// ranges, and the giant comes first in the list. Leaving only the giant sends a mecha that
// takes off from the moon's giant-facing side back into the ground, because "away from the
// giant" points down there. Leave all of them together, each weighted by how deep the mecha
// is inside its range: their safety margins are equal, so the nearest surface dominates.
VectorLF3 bodiesInward = default;
VectorLF3 hiveInward = default;
bool insideBody = false;
bool insideHive = false;
foreach (Obstacle obstacle in obstacles)
{
double pathRadius = GetReachablePathRadius(obstacle);
@@ -673,12 +678,22 @@ public class PlayerPatch : PatchImpl<PlayerPatch>
if (obstacleDistance >= pathRadius)
continue;
inward += SafeNorm(toObstacle, baseDir) * (pathRadius - obstacleDistance);
insideObstacle = true;
if (obstacle.HasSurface)
{
bodiesInward += SafeNorm(toObstacle, baseDir) * (pathRadius - obstacleDistance);
insideBody = true;
}
else if (!insideHive)
{
hiveInward = toObstacle;
insideHive = true;
}
}
if (insideObstacle)
return ComputeEscapeDirection(currentDirection, inward, baseDir);
if (insideBody)
return ComputeEscapeDirection(currentDirection, bodiesInward, baseDir);
if (insideHive)
return ComputeEscapeDirection(currentDirection, hiveInward, baseDir);
foreach (Obstacle obstacle in obstacles)
{
@@ -1147,6 +1162,7 @@ public class PlayerPatch : PatchImpl<PlayerPatch>
{
public VectorLF3 Position { get; } = position;
public double PathRadius { get; } = radius + safetyMargin;
public bool HasSurface { get; } = radius > 0.0;
}
#endregion