diff --git a/src/AcDream.Core/Physics/TransitionTypes.cs b/src/AcDream.Core/Physics/TransitionTypes.cs index eb93665..f947a67 100644 --- a/src/AcDream.Core/Physics/TransitionTypes.cs +++ b/src/AcDream.Core/Physics/TransitionTypes.cs @@ -698,8 +698,14 @@ public sealed class Transition offsetPerStep = Vector3.Zero; } - // Retail safety cap (30 steps). Sight objects bypass this. - if (numSteps > PhysicsGlobals.MaxTransitionSteps) + // Retail safety cap (30 steps). Viewer/sight objects bypass it, matching + // retail: CTransition::find_transitional_position (acclient_2013_pseudo_c.txt + // :273613) has no cap, and calc_num_steps (:272149) has a dedicated viewer + // branch `if ((state & 4) != 0)` at :272181. The A8.F camera spring-arm + // (IsViewer) sweeps the eye far past 30 steps; the zoom clamp (≤40 m / 0.3 m + // radius ≈ 134 steps) bounds it. Non-viewers keep the safety net (players + // never exceed it: 30 × 0.48 m ≈ 14 m/tick). + if (numSteps > PhysicsGlobals.MaxTransitionSteps && !ObjectInfo.IsViewer) return false; // Apply free rotation if requested. diff --git a/tests/AcDream.Core.Tests/Physics/TransitionTests.cs b/tests/AcDream.Core.Tests/Physics/TransitionTests.cs index 307def0..7feb991 100644 --- a/tests/AcDream.Core.Tests/Physics/TransitionTests.cs +++ b/tests/AcDream.Core.Tests/Physics/TransitionTests.cs @@ -283,6 +283,34 @@ public class TransitionTests $"Sphere bottom {bottom:F4} should be >= terrain {groundZ}"); } + [Fact] + public void FindTransitionalPosition_LongSweep_ViewerBypassesStepCap() + { + // A8.F: the 30-step safety cap bailed long sweeps. Retail's + // find_transitional_position has no cap and handles viewers specially + // (calc_num_steps `state & 4` branch, acclient :272181). The camera + // spring arm (IsViewer) must not bail. radius 0.3, dist 12 → 40 steps > 30. + const float groundZ = 10f; + var engine = MakeEngine(FlatTerrain(groundZ)); + + Vector3 from = new(50f, 50f, groundZ); + Vector3 to = new(62f, 50f, groundZ); // 12 units → 40 steps at r=0.3 (>30 cap) + + // Normal mover: hits the 30-step cap, bails without moving. + var normal = MakeTransition(from, to, sphereRadius: 0.3f); + bool normalOk = normal.FindTransitionalPosition(engine); + Assert.False(normalOk); + + // Viewer: cap bypassed → sweep proceeds the full distance over flat ground. + var viewer = MakeTransition(from, to, sphereRadius: 0.3f); + viewer.ObjectInfo.State |= ObjectInfoState.IsViewer; + bool viewerOk = viewer.FindTransitionalPosition(engine); + Assert.True(viewerOk); + // Position must have advanced toward `to` (key invariant: viewer proceeds). + Assert.True(viewer.SpherePath.CurPos.X > from.X, + "Viewer sphere should have advanced in +X past the step cap"); + } + [Fact] public void SampleTerrainZ_FindsCorrectLandblock() {