diff --git a/UXAssist/CHANGELOG.md b/UXAssist/CHANGELOG.md index 4f8060e..051f08d 100644 --- a/UXAssist/CHANGELOG.md +++ b/UXAssist/CHANGELOG.md @@ -5,6 +5,7 @@ * 1.6.4 * `Hide battle-related techs in Peace mode`: Fix an array index error when opening the tech tree after switching from a Peace-mode save to a Combat-mode save in the same game process, including when disabling the option after loading another Peace-mode save. + * `Auto-cruise`: Fix the mecha diving back into the ground right after taking off from a moon that is close to its gas giant. * 1.6.3 * `Quick build Mining Machines`: * Add a Factory-tab button to arrange ordinary Mining Machines densely around the nearest solid vein group. Each miner covers at least 3 nodes from that group, without including nearby groups. Layouts are not limited by stock; missing miners remain as ghosts awaiting materials. Placement respects construction range and does not include belts or power facilities. Click again to cancel a search. @@ -448,6 +449,7 @@ * 1.6.4 * `在和平模式下隐藏战斗相关科技`:修复在同一次游戏运行中从和平模式存档切换到战斗模式存档后打开科技树时的数组越界,以及再次加载和平模式存档后关闭选项时的同类问题。 + * `自动巡航`:修复从紧邻气态巨星的卫星上起飞后,机甲又扎回地面的问题。 * 1.6.3 * `快速铺设采矿机`: * 在「工厂」页增加按钮,自动在最近的固体矿脉周围密集铺设普通采矿机。每台至少覆盖选中矿脉的 3 个矿点,不混入附近其他矿脉。布局数量不受库存限制,采矿机不足的位置保留待建造虚影。遵守建造范围,不自动铺设传送带和电力设施。计算期间再次点击可取消。 diff --git a/UXAssist/Patches/PlayerPatch.cs b/UXAssist/Patches/PlayerPatch.cs index 4a2246c..a584712 100644 --- a/UXAssist/Patches/PlayerPatch.cs +++ b/UXAssist/Patches/PlayerPatch.cs @@ -654,6 +654,14 @@ public class PlayerPatch : PatchImpl return default; 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; foreach (Obstacle obstacle in obstacles) { double pathRadius = GetReachablePathRadius(obstacle); @@ -662,10 +670,24 @@ public class PlayerPatch : PatchImpl VectorLF3 toObstacle = obstacle.Position - playerPos; double obstacleDistance = toObstacle.magnitude; - if (obstacleDistance < pathRadius) - return ComputeEscapeDirection(currentDirection, toObstacle, baseDir); + if (obstacleDistance >= pathRadius) + continue; + + inward += SafeNorm(toObstacle, baseDir) * (pathRadius - obstacleDistance); + insideObstacle = true; + } + + if (insideObstacle) + return ComputeEscapeDirection(currentDirection, inward, baseDir); + + foreach (Obstacle obstacle in obstacles) + { + double pathRadius = GetReachablePathRadius(obstacle); + if (pathRadius <= 0.0) + continue; + if (IsSegmentBlocked(playerPos, _targetUniversePosition, obstacle.Position, pathRadius)) - return ComputeTangentDirection(currentDirection, toObstacle, pathRadius, baseDir); + return ComputeTangentDirection(currentDirection, obstacle.Position - playerPos, pathRadius, baseDir); } return baseDir;