mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2026-11-19 17:05:20 +08:00
fix(uxassist): route construction through nearby ghosts
Select the closest eligible ghost in the approach corridor before flying to a selected site, and use spherical cross-track checks to avoid bypassing nearer construction work.
This commit is contained in:
1 parent
27c6a959ad
commit
b7564903d0
2 files changed
+96
-9
No files matched your search
@@ -142,7 +142,7 @@ The sync is implemented as an inline PowerShell `Exec` step inside the `ZipMod`
|
||||
|
||||
## Key Architectural Patterns
|
||||
|
||||
- Auto-construct motion recovery treats only actual movement keys as manual override, yields to active auto-navigation, clears stale move orders before flight ascent, returns before issuing a same-frame route after switching from walking to flying, and performs one stop-equivalent recovery when a route circles without radial progress. Planner candidates use fixed angular fan sectors with near and far representatives instead of retaining only globally nearest ghosts. Arrival follows the game's surface-direction order semantics. Site selection follows a nearest-cluster route: it prefers the best local candidate within a build-area-scaled horizon and falls back to the nearest candidate, rather than selecting a distant high-density cluster and forcing return flights. A site is held only until its first construction-drone wave is dispatched when coverage exceeds that wave; it must not wait merely to exhaust every ghost in range, because waiting extends drone round trips and mecha power use. Normal route changes still brake and wait for tangential flight speed to settle, but recovery detours, their continuation points, and the resumed final route bypass flight settling so they can take over before the mecha stops. Refinement destinations are selected from the scanned ghost positions. Obstacle probing is only allowed to initiate a detour after stuck or orbit evidence; it detects overlapping colliders, derives a horizontal footprint radius from the collider bounds, tests tangent candidates at several radii and sides, chooses the least-blocked horizontal fallback when no fully clear tangent exists, and a completed detour resumes the final construction route instead of resetting the plan.
|
||||
- Auto-construct motion recovery treats only actual movement keys as manual override, yields to active auto-navigation, clears stale move orders before flight ascent, returns before issuing a same-frame route after switching from walking to flying, and performs one stop-equivalent recovery when a route circles without radial progress. Planner candidates use fixed angular fan sectors with near and far representatives instead of retaining only globally nearest ghosts. Arrival follows the game's surface-direction order semantics. Site selection follows a nearest-cluster route: it prefers the best local candidate within a build-area-scaled horizon and falls back to the nearest candidate, rather than selecting a distant high-density cluster and forcing return flights. A site is held only while its first construction-drone wave remains below capacity and its current throughput is not meaningfully beaten by a nearby candidate; it must not wait merely to exhaust every ghost in range, because waiting extends drone round trips and mecha power use. Normal route changes still brake and wait for tangential flight speed to settle, but recovery detours, their continuation points, and the resumed final route bypass flight settling so they can take over before the mecha stops. Refinement destinations are selected from the scanned ghost positions. After a destination is chosen, eligible ghosts in its approach corridor are reduced to the closest route-prefix ghost so travel cannot bypass nearer construction work. Obstacle probing is only allowed to initiate a detour after stuck or orbit evidence; it detects overlapping colliders, derives a horizontal footprint radius from the collider bounds, tests tangent candidates at several radii and sides, chooses the least-blocked horizontal fallback when no fully clear tangent exists, and a completed detour resumes the final construction route instead of resetting the plan.
|
||||
|
||||
- **Shared library:** `UXAssist` acts as a common library. `CheatEnabler` and `UniverseGenTweaks` reference `UXAssist.csproj` directly to reuse `Common/`, `UI/`, and config panel infrastructure.
|
||||
- **Centralized mod-feature lifecycle:** `UXAssist.Common.ModFeatures.ModFeatureRegistry` holds shared static lists of mod features discovered across all mods. **Only UXAssist drives the shared deferred lifecycle** (`StartAll`/`UninitAll`/`OnInputUpdateAll`/`OnUpdateAll`); these dispatchers are `internal` so dependent mods (separate assemblies, no `InternalsVisibleTo`) cannot call them and re-trigger other mods' features. A feature's `Init` runs **eagerly** when it is registered (via `Discover`/`Register`), preserving the original `Awake`-phase timing that keybind registration and other early setup rely on — the game's `UIOptionWindow._OnCreate` copies registered keybinds only after all plugins have finished loading. Dependent mods only call `ModFeatureRegistry.Discover(Assembly.GetExecutingAssembly())` (and optionally `Register<T>()`) in their `Awake`. UXAssist begins the deferred lifecycle from its own `Start`; if a dependent feature is discovered after that transition, the registry starts it immediately after initialization so it cannot miss `Start`. The registry also guards start idempotency per feature (start at most once; uninit resets) and per-frame re-entrancy (`Time.frameCount`) for the update dispatchers, as defense-in-depth.
|
||||
|
||||
@@ -24,6 +24,7 @@ internal static class FactoryBuildPatches
|
||||
private const float PlanArrivalDistance = 5f;
|
||||
private const float MinimumSiteMoveDistance = 8f;
|
||||
private const float ConstructionFlightAltitude = 15f;
|
||||
private const float SiteSwitchGain = 1.15f;
|
||||
private const float DroneBuildSecondsPerTarget = 2f;
|
||||
private const int MinimumConstructionSiteHoldTicks = 45;
|
||||
private const int FlightSettleDurationTicks = 45;
|
||||
@@ -39,6 +40,7 @@ internal static class FactoryBuildPatches
|
||||
private const int OrbitTickThreshold = 45;
|
||||
private const int MaxDetourAttempts = 8;
|
||||
private const float LocalRouteRadiusMultiplier = 3f;
|
||||
private const float RouteCorridorWidthFactor = 0.8f;
|
||||
private static readonly float[] DetourRadiusScales = { 1f, 1.5f, 2f, 3f };
|
||||
private static readonly int[] DetourSideSigns = { -1, 1 };
|
||||
private static readonly Collider[] ObstacleOverlapColliders = new Collider[8];
|
||||
@@ -83,6 +85,8 @@ internal static class FactoryBuildPatches
|
||||
private static Vector3 _plannerTargetDirectionSum;
|
||||
private static int _currentSiteTargetCount;
|
||||
private static int _currentSiteLaunchedTargetCount;
|
||||
private static float _currentSiteScore;
|
||||
private static float _nextSiteScore;
|
||||
private static readonly int[] ItemAvailabilityProtoIds = new int[ItemAvailabilityCacheSize];
|
||||
private static readonly int[] ItemAvailabilityCounts = new int[ItemAvailabilityCacheSize];
|
||||
private static Vector3 _plannerFanForward;
|
||||
@@ -313,6 +317,8 @@ internal static class FactoryBuildPatches
|
||||
_plannerTargetDirectionSum = Vector3.zero;
|
||||
_currentSiteTargetCount = 0;
|
||||
_currentSiteLaunchedTargetCount = 0;
|
||||
_currentSiteScore = 0f;
|
||||
_nextSiteScore = 0f;
|
||||
_itemAvailabilityCount = 0;
|
||||
for (var i = 0; i < MaxPlannerCandidates; i++)
|
||||
{
|
||||
@@ -356,7 +362,7 @@ internal static class FactoryBuildPatches
|
||||
if (buildArea < PlanArrivalDistance) return false;
|
||||
|
||||
var buildAreaSquared = buildArea * buildArea;
|
||||
EvaluatePlannerCandidate(
|
||||
_currentSiteScore = EvaluatePlannerCandidate(
|
||||
factory, player, player.position, buildAreaSquared, out _currentSiteTargetCount, out _, true);
|
||||
_currentSiteLaunchedTargetCount = _plannerLaunchedTargetCount;
|
||||
CollectPlannerCandidates(factory, player);
|
||||
@@ -379,6 +385,9 @@ internal static class FactoryBuildPatches
|
||||
var localBestCandidate = Vector3.zero;
|
||||
var nearestCandidate = Vector3.zero;
|
||||
var nearestCandidateDistanceSquared = float.MaxValue;
|
||||
var nearestCandidateScore = float.MinValue;
|
||||
Vector3 prefixDestination;
|
||||
float prefixScore;
|
||||
for (var i = 0; i < MaxPlannerCandidates; i++)
|
||||
{
|
||||
if (PlannerCandidateDistanceSquared[i] < 0f) continue;
|
||||
@@ -392,8 +401,8 @@ internal static class FactoryBuildPatches
|
||||
ref localBestScore, ref localBestCoverageCount, ref localBestCandidate);
|
||||
}
|
||||
ConsiderNearestDestination(
|
||||
candidate, coverageCount, PlannerCandidateDistanceSquared[i],
|
||||
ref nearestCandidateDistanceSquared, ref nearestCandidate);
|
||||
candidate, coverageCount, PlannerCandidateDistanceSquared[i], score,
|
||||
ref nearestCandidateDistanceSquared, ref nearestCandidate, ref nearestCandidateScore);
|
||||
AddPlannerRefinementCandidate(candidate, refinedCandidate, score, coverageCount);
|
||||
}
|
||||
|
||||
@@ -416,33 +425,109 @@ internal static class FactoryBuildPatches
|
||||
ref localBestScore, ref localBestCoverageCount, ref localBestCandidate);
|
||||
}
|
||||
ConsiderNearestDestination(
|
||||
refinedCandidate, coverageCount, refinementDistanceSquared,
|
||||
ref nearestCandidateDistanceSquared, ref nearestCandidate);
|
||||
refinedCandidate, coverageCount, refinementDistanceSquared, score,
|
||||
ref nearestCandidateDistanceSquared, ref nearestCandidate, ref nearestCandidateScore);
|
||||
}
|
||||
|
||||
if (localBestCoverageCount > 0)
|
||||
{
|
||||
destination = localBestCandidate;
|
||||
_nextSiteScore = localBestScore;
|
||||
if (TryFindRoutePrefixDestination(
|
||||
factory, player, destination, buildArea, out prefixDestination, out prefixScore))
|
||||
{
|
||||
destination = prefixDestination;
|
||||
_nextSiteScore = prefixScore;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (nearestCandidateDistanceSquared >= float.MaxValue) return false;
|
||||
if (nearestCandidateDistanceSquared >= float.MaxValue || nearestCandidateScore <= float.MinValue) return false;
|
||||
|
||||
destination = nearestCandidate;
|
||||
_nextSiteScore = nearestCandidateScore;
|
||||
if (TryFindRoutePrefixDestination(
|
||||
factory, player, destination, buildArea, out prefixDestination, out prefixScore))
|
||||
{
|
||||
destination = prefixDestination;
|
||||
_nextSiteScore = prefixScore;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool TryFindRoutePrefixDestination(
|
||||
PlanetFactory factory,
|
||||
Player player,
|
||||
Vector3 destination,
|
||||
float buildArea,
|
||||
out Vector3 prefixDestination,
|
||||
out float prefixScore)
|
||||
{
|
||||
prefixDestination = default;
|
||||
prefixScore = float.MinValue;
|
||||
var realRadius = factory.planet.realRadius;
|
||||
var originDirection = player.position.normalized;
|
||||
var targetDirection = destination.normalized;
|
||||
var routeNormal = Vector3.Cross(originDirection, targetDirection);
|
||||
if (routeNormal.sqrMagnitude < 0.000001f) return false;
|
||||
|
||||
routeNormal.Normalize();
|
||||
var routeCos = Vector3.Dot(originDirection, targetDirection);
|
||||
var routeAngle = Mathf.Acos(Mathf.Clamp(routeCos, -1f, 1f));
|
||||
var routeDistance = routeAngle * realRadius;
|
||||
if (routeDistance <= MinimumSiteMoveDistance) return false;
|
||||
var minimumDistanceCos = Mathf.Cos(Mathf.Min(Mathf.PI, MinimumSiteMoveDistance / realRadius));
|
||||
|
||||
var corridorWidth = Mathf.Max(16f, buildArea * RouteCorridorWidthFactor);
|
||||
var maximumCrossTrackNormal = Mathf.Sin(
|
||||
Mathf.Min(Mathf.PI, corridorWidth / realRadius));
|
||||
var prebuilds = factory.prebuildPool;
|
||||
var bestCandidateCos = -2f;
|
||||
var found = false;
|
||||
for (var i = 1; i < factory.prebuildCursor; i++)
|
||||
{
|
||||
ref var prebuild = ref prebuilds[i];
|
||||
if (prebuild.id != i || prebuild.isDestroyed || prebuild.builderLaunched) continue;
|
||||
if (!HasRequiredItems(player, prebuild.protoId, prebuild.itemRequired)) continue;
|
||||
|
||||
var candidateDirection = prebuild.pos.normalized;
|
||||
var candidateCos = Vector3.Dot(originDirection, candidateDirection);
|
||||
if (candidateCos >= minimumDistanceCos || candidateCos <= routeCos) continue;
|
||||
if (Vector3.Dot(candidateDirection, targetDirection) <= routeCos) continue;
|
||||
|
||||
var crossTrackAngle = Mathf.Asin(
|
||||
Mathf.Clamp(Vector3.Dot(routeNormal, candidateDirection), -1f, 1f));
|
||||
if (Mathf.Abs(crossTrackAngle) > maximumCrossTrackNormal) continue;
|
||||
if (candidateCos <= bestCandidateCos) continue;
|
||||
|
||||
bestCandidateCos = candidateCos;
|
||||
prefixDestination = prebuild.pos;
|
||||
found = true;
|
||||
}
|
||||
|
||||
if (!found) return false;
|
||||
|
||||
prefixScore = EvaluatePlannerCandidate(
|
||||
factory, player, prefixDestination, buildArea * buildArea, out _, out _);
|
||||
return prefixScore > float.MinValue;
|
||||
}
|
||||
|
||||
private static void ConsiderNearestDestination(
|
||||
Vector3 candidate,
|
||||
int coverageCount,
|
||||
float distanceSquared,
|
||||
float score,
|
||||
ref float nearestDistanceSquared,
|
||||
ref Vector3 nearestCandidate)
|
||||
ref Vector3 nearestCandidate,
|
||||
ref float nearestScore)
|
||||
{
|
||||
if (coverageCount <= 0 || distanceSquared >= nearestDistanceSquared) return;
|
||||
|
||||
nearestDistanceSquared = distanceSquared;
|
||||
nearestCandidate = candidate;
|
||||
nearestScore = score;
|
||||
}
|
||||
|
||||
private static void ConsiderPlannerDestination(
|
||||
@@ -859,7 +944,9 @@ internal static class FactoryBuildPatches
|
||||
|
||||
if (_currentSiteTargetCount <= 0) return false;
|
||||
|
||||
return _currentSiteLaunchedTargetCount < GetConstructionWaveCapacity(player);
|
||||
if (_currentSiteLaunchedTargetCount >= GetConstructionWaveCapacity(player)) return false;
|
||||
|
||||
return _nextSiteScore < _currentSiteScore * SiteSwitchGain;
|
||||
}
|
||||
|
||||
private static int GetConstructionWaveCapacity(Player player)
|
||||
|
||||
Reference in new issue
Block a user