From bffa16e0c75ad69b5cc1ce312f5f3752accfd04d Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 5 Dec 2026 12:50:13 +0100 Subject: [PATCH] Fix Cut 6 orbital drop L-shaped 3D building wall guard (sion_0005) --- src/RustToDust.Core/MatchState.cs | 10 +- src/RustToDust.Core/OrbitalDropSystem.cs | 17 ++- src/RustToDust.Ymir/ArenaSession.cs | 124 +++++++++-------- tests/RustToDust.Tests/OrbitalDropTests.cs | 148 ++++++++++++++++++++- 4 files changed, 233 insertions(+), 66 deletions(-) diff --git a/src/RustToDust.Core/MatchState.cs b/src/RustToDust.Core/MatchState.cs index dead16f..3551af1 100644 --- a/src/RustToDust.Core/MatchState.cs +++ b/src/RustToDust.Core/MatchState.cs @@ -1304,15 +1304,21 @@ namespace RustToDust.Core Vector3.UnitY, IsBuildingRoof: true, IsFlatRoofValid: flat, - IsInsideBuildingFootprint: true); + IsInsideBuildingFootprint: true, + IsInsideSolidBuilding: centerBldg.RoofY > referenceMaxY - 0.5f); } + bool isInsideSolid = centerOverBuilding + && centerBldg.RoofY > terrainY + 0.25f + && centerBldg.RoofY > referenceMaxY - 0.5f; + return new DropSurfaceSample( terrainY, normal, IsBuildingRoof: false, IsFlatRoofValid: false, - IsInsideBuildingFootprint: lateralWallOverlap); + IsInsideBuildingFootprint: lateralWallOverlap, + IsInsideSolidBuilding: isInsideSolid); } if (ArenaCoverBoxes.Count > 0) diff --git a/src/RustToDust.Core/OrbitalDropSystem.cs b/src/RustToDust.Core/OrbitalDropSystem.cs index 9fac090..eb54964 100644 --- a/src/RustToDust.Core/OrbitalDropSystem.cs +++ b/src/RustToDust.Core/OrbitalDropSystem.cs @@ -31,7 +31,8 @@ namespace RustToDust.Core Vector3 Normal, bool IsBuildingRoof, bool IsFlatRoofValid, - bool IsInsideBuildingFootprint); + bool IsInsideBuildingFootprint, + bool IsInsideSolidBuilding = false); public delegate DropSurfaceSample DropSurfaceQuery(float x, float z, float footRadius, float referenceMaxY); @@ -408,8 +409,8 @@ namespace RustToDust.Core { // Guarantee 0 building-interior / invalid-roof touchdowns bool touchInvalidBuilding = - (sampleNext.IsInsideBuildingFootprint || sampleNext.IsBuildingRoof) && - !(pod.AllowFlatRoofLanding && sampleNext.IsFlatRoofValid); + sampleNext.IsInsideSolidBuilding || + (sampleNext.IsBuildingRoof && !(pod.AllowFlatRoofLanding && sampleNext.IsFlatRoofValid)); if (touchInvalidBuilding) { var (clearX, clearZ) = findClearPoint(pod.X, pod.Z, preset.PodFootRadius + 1.5f); @@ -417,7 +418,7 @@ namespace RustToDust.Core pod.Z = Math.Clamp(clearZ, -maxBound, maxBound); sampleNext = surfaceQuery(pod.X, pod.Z, preset.PodFootRadius, pod.Y + 60f); terrainNext = terrain.SampleHeight(pod.X, pod.Z); - if (!sampleNext.IsBuildingRoof && !sampleNext.IsInsideBuildingFootprint) + if (!sampleNext.IsBuildingRoof && !sampleNext.IsInsideSolidBuilding) { surfaceNext = terrainNext; } @@ -433,7 +434,8 @@ namespace RustToDust.Core ToNormalVec(terrain.SampleNormal(pod.X, pod.Z)), IsBuildingRoof: false, IsFlatRoofValid: false, - IsInsideBuildingFootprint: false); + IsInsideBuildingFootprint: false, + IsInsideSolidBuilding: false); } } @@ -476,6 +478,11 @@ namespace RustToDust.Core return true; } + if (!sampleNow.IsInsideSolidBuilding && sampleNext.IsInsideSolidBuilding) + { + return true; + } + if (!sampleNow.IsInsideBuildingFootprint && sampleNext.IsInsideBuildingFootprint && (!sampleNext.IsBuildingRoof || !pod.AllowFlatRoofLanding)) diff --git a/src/RustToDust.Ymir/ArenaSession.cs b/src/RustToDust.Ymir/ArenaSession.cs index 850573e..6304d33 100644 --- a/src/RustToDust.Ymir/ArenaSession.cs +++ b/src/RustToDust.Ymir/ArenaSession.cs @@ -854,82 +854,91 @@ namespace RustToDust.Ymir if (state.MapKind == ArenaMapKind.Sion && state.SionMap is { } sionMap) { bool centerOverBuilding = sionMap.TryGetBuildingAt(x, z, 0f, out var centerBldg); - bool lateralWallOverlap = centerOverBuilding || sionMap.TryGetBuildingAt(x, z, footRadius, out _); + SionBuildingAabb nearBldg = default; + bool lateralWallOverlap = centerOverBuilding || sionMap.TryGetBuildingAt(x, z, footRadius, out nearBldg); + var queryBldg = centerOverBuilding ? centerBldg : nearBldg; - if (!centerOverBuilding) + if (!lateralWallOverlap) { return new DropSurfaceSample( terrainY, terrainNorm, IsBuildingRoof: false, IsFlatRoofValid: false, - IsInsideBuildingFootprint: lateralWallOverlap); + IsInsideBuildingFootprint: false, + IsInsideSolidBuilding: false); } if (world is not null) { - float castStartY = MathF.Max(referenceMaxY, centerBldg.RoofY + 6f); - float castSpan = MathF.Max(20f, castStartY - (terrainY - 12f)); - var centerHit = world.CastRayClosest((x, castStartY, z), (0f, -castSpan, 0f)); - if (centerHit.Hit && - centerHit.StableId >= StaticMeshStableIdBase && - centerHit.StableId < ContenderStableIdBase) + if (centerOverBuilding || referenceMaxY < queryBldg.RoofY + 2.0f) { - float roofY = centerHit.Point.Y; - if (roofY > referenceMaxY || roofY <= terrainY + 0.1f) + float castStartY = MathF.Max(referenceMaxY, queryBldg.RoofY + 6f); + float castSpan = MathF.Max(20f, castStartY - (terrainY - 12f)); + var centerHit = world.CastRayClosest((x, castStartY, z), (0f, -castSpan, 0f)); + if (centerHit.Hit && + centerHit.StableId >= StaticMeshStableIdBase && + centerHit.StableId < ContenderStableIdBase) { - return new DropSurfaceSample( - terrainY, - terrainNorm, - IsBuildingRoof: false, - IsFlatRoofValid: false, - IsInsideBuildingFootprint: true); - } - - Vector3 roofNorm = new(centerHit.Normal.X, centerHit.Normal.Y, centerHit.Normal.Z); - if (roofNorm.LengthSquared() < 1e-4f) roofNorm = Vector3.UnitY; - else roofNorm = Vector3.Normalize(roofNorm); - - bool flatValid = false; - if (roofNorm.Y >= 0.90f) - { - flatValid = true; - float r = MathF.Max(0.8f, footRadius); - ReadOnlySpan<(float Ox, float Oz)> offsets = stackalloc (float, float)[] + float roofY = centerHit.Point.Y; + bool isInsideSolid = roofY > terrainY + 0.1f && roofY > referenceMaxY - 0.5f; + if (roofY > referenceMaxY || roofY <= terrainY + 0.1f) { - (-r, -r), (r, -r), (-r, r), (r, r) - }; - for (int k = 0; k < 4; k++) + return new DropSurfaceSample( + terrainY, + terrainNorm, + IsBuildingRoof: false, + IsFlatRoofValid: false, + IsInsideBuildingFootprint: true, + IsInsideSolidBuilding: isInsideSolid); + } + + Vector3 roofNorm = new(centerHit.Normal.X, centerHit.Normal.Y, centerHit.Normal.Z); + if (roofNorm.LengthSquared() < 1e-4f) roofNorm = Vector3.UnitY; + else roofNorm = Vector3.Normalize(roofNorm); + + bool flatValid = false; + if (roofNorm.Y >= 0.90f) { - float cx = x + offsets[k].Ox; - float cz = z + offsets[k].Oz; - var cornerHit = world.CastRayClosest((cx, roofY + 2.5f, cz), (0f, -5.0f, 0f)); - if (!cornerHit.Hit || - cornerHit.StableId < StaticMeshStableIdBase || - cornerHit.StableId >= ContenderStableIdBase || - MathF.Abs(cornerHit.Point.Y - roofY) > 0.45f) + flatValid = true; + float r = MathF.Max(0.8f, footRadius); + ReadOnlySpan<(float Ox, float Oz)> offsets = stackalloc (float, float)[] { - flatValid = false; - break; - } - var aboveHit = world.CastRayClosest((cx, roofY + 60f, cz), (0f, -58f, 0f)); - if (aboveHit.Hit && - aboveHit.StableId >= StaticMeshStableIdBase && - aboveHit.StableId < ContenderStableIdBase && - aboveHit.Point.Y > roofY + 0.6f) + (-r, -r), (r, -r), (-r, r), (r, r) + }; + for (int k = 0; k < 4; k++) { - flatValid = false; - break; + float cx = x + offsets[k].Ox; + float cz = z + offsets[k].Oz; + var cornerHit = world.CastRayClosest((cx, roofY + 2.5f, cz), (0f, -5.0f, 0f)); + if (!cornerHit.Hit || + cornerHit.StableId < StaticMeshStableIdBase || + cornerHit.StableId >= ContenderStableIdBase || + MathF.Abs(cornerHit.Point.Y - roofY) > 0.45f) + { + flatValid = false; + break; + } + var aboveHit = world.CastRayClosest((cx, roofY + 60f, cz), (0f, -58f, 0f)); + if (aboveHit.Hit && + aboveHit.StableId >= StaticMeshStableIdBase && + aboveHit.StableId < ContenderStableIdBase && + aboveHit.Point.Y > roofY + 0.6f) + { + flatValid = false; + break; + } } } - } - return new DropSurfaceSample( - MathF.Max(terrainY, roofY), - roofNorm, - IsBuildingRoof: true, - IsFlatRoofValid: flatValid, - IsInsideBuildingFootprint: true); + return new DropSurfaceSample( + MathF.Max(terrainY, roofY), + roofNorm, + IsBuildingRoof: true, + IsFlatRoofValid: flatValid, + IsInsideBuildingFootprint: true, + IsInsideSolidBuilding: isInsideSolid); + } } return new DropSurfaceSample( @@ -937,7 +946,8 @@ namespace RustToDust.Ymir terrainNorm, IsBuildingRoof: false, IsFlatRoofValid: false, - IsInsideBuildingFootprint: lateralWallOverlap); + IsInsideBuildingFootprint: lateralWallOverlap, + IsInsideSolidBuilding: false); } } diff --git a/tests/RustToDust.Tests/OrbitalDropTests.cs b/tests/RustToDust.Tests/OrbitalDropTests.cs index 012f15b..c017051 100644 --- a/tests/RustToDust.Tests/OrbitalDropTests.cs +++ b/tests/RustToDust.Tests/OrbitalDropTests.cs @@ -261,8 +261,11 @@ namespace RustToDust.Tests landed = true; worstTouchTime = MathF.Max(worstTouchTime, pod.FlightTime); worstImpactSpeed = MathF.Max(worstImpactSpeed, pod.TouchdownSpeed); - Assert.False(sion.IsInsideAnyBuildingXz(pod.X, pod.Z, 0f), - $"Target #{i} ({tx:F1},{tz:F1}) landed inside Sion building at ({pod.X:F1},{pod.Z:F1})!"); + var skyCheck = session.QueryDropSurface(pod.X, pod.Z, 0f, 500f); + Assert.False(skyCheck.IsBuildingRoof, + $"Target #{i} ({tx:F1},{tz:F1}) landed inside solid Sion building at ({pod.X:F1},{pod.Z:F1})!"); + Assert.False(touchSample.IsInsideSolidBuilding, + $"Target #{i} ({tx:F1},{tz:F1}) landed with IsInsideSolidBuilding=true at ({pod.X:F1},{pod.Z:F1})!"); Assert.False(touchSample.IsBuildingRoof); Assert.InRange(pod.TouchdownSpeed, 0.5f, 2.99f); break; @@ -1131,6 +1134,147 @@ namespace RustToDust.Tests p => p.PodKind == OrbitalPodKind.Contender && p.ContenderId == rivalId); } + [Fact] + public void Sion0005_LShapedCornerAndWallSteering_ZeroWallBreachesAndZeroTouchdownWarps() + { + using var session = new ArenaSession(seed: 42, ArenaMapKind.Sion, slot0Human: true); + var sion = session.State.SionMap!; + var b = sion.Buildings.First(x => x.Id == "sion_0005"); + + // Find an open-sky AABB corner inside sion_0005 (IsInsideAnyBuildingXz == true, no solid roof overhead) + // and a solid-roof interior target inside sion_0005 to steer toward. + float? openCornerX = null, openCornerZ = null; + float? solidTargetX = null, solidTargetZ = null; + float solidTargetRoofY = b.RoofY; + for (float z = b.CenterZ - b.HalfZ + 1.5f; z <= b.CenterZ + b.HalfZ - 1.5f; z += 2.0f) + { + for (float x = b.CenterX - b.HalfX + 1.5f; x <= b.CenterX + b.HalfX - 1.5f; x += 2.0f) + { + var sky = session.QueryDropSurface(x, z, 0f, b.RoofY + 50f); + if (!sky.IsBuildingRoof) + { + openCornerX ??= x; + openCornerZ ??= z; + } + else if (solidTargetX is null && sky.SurfaceY > session.State.Terrain.SampleHeight(x, z) + 2f) + { + solidTargetX = x; + solidTargetZ = z; + solidTargetRoofY = sky.SurfaceY; + } + } + } + + Assert.True(solidTargetX.HasValue, "Expected solid roof interior point on sion_0005"); + float tx = solidTargetX!.Value; + float tz = solidTargetZ!.Value; + + var startPoints = new List<(string Label, float X, float Z)>(); + if (openCornerX.HasValue) + { + startPoints.Add(("L-corner", openCornerX.Value, openCornerZ!.Value)); + } + foreach (float offset in new[] { 1.2f, 5.0f, 18.0f, 35.0f }) + { + startPoints.Add(($"+{offset:F1}m_W", b.CenterX - b.HalfX - offset, tx != b.CenterX ? tz : b.CenterZ)); + startPoints.Add(($"+{offset:F1}m_S", tx, b.CenterZ - b.HalfZ - offset)); + } + + int totalCases = 0; + int wallBreachFrames = 0; + int touchdownWarps = 0; + float maxHorizStep = 0f; + float maxTouchdownStep = 0f; + float maxTouchSpeed = 0f; + + foreach (bool allowFlat in new[] { false, true }) + { + foreach (float startAgl in new[] { 410f, 80f }) + { + foreach (var (label, sx, sz) in startPoints) + { + float terrain0 = session.State.Terrain.SampleHeight(sx, sz); + float dx = tx - sx; + float dz = tz - sz; + float len = MathF.Max(0.001f, MathF.Sqrt(dx * dx + dz * dz)); + float dirX = dx / len; + float dirZ = dz / len; + + var pod = new OrbitalPod + { + PodId = 9800 + totalCases, + PodKind = OrbitalPodKind.Contender, + Phase = OrbitalPodPhase.Freefall, + AllowFlatRoofLanding = allowFlat, + X = sx, + Y = terrain0 + startAgl, + Z = sz, + VelY = startAgl > 200f ? OrbitalPodPreset.Contender.InitialVelY : -28f, + LookForwardX = dirX, + LookForwardZ = dirZ, + SteerForwardCmd = 1f, + Yaw = MathF.Atan2(dirX, dirZ) + }; + + bool landed = false; + for (int t = 0; t < 720; t++) + { + float prevX = pod.X; + float prevY = pod.Y; + float prevZ = pod.Z; + + bool touched = OrbitalDropKinematics.StepPod( + pod, + ArenaSession.FixedDt, + session.State.Terrain, + session.QueryDropSurface, + session.State.FindClearDropPoint, + out _, + out _); + + float horizStep = MathF.Sqrt((pod.X - prevX) * (pod.X - prevX) + (pod.Z - prevZ) * (pod.Z - prevZ)); + maxHorizStep = MathF.Max(maxHorizStep, horizStep); + + var skyProbe = session.QueryDropSurface(pod.X, pod.Z, 0f, solidTargetRoofY + 60f); + if (skyProbe.IsBuildingRoof && pod.Y < skyProbe.SurfaceY - 0.1f) + { + wallBreachFrames++; + } + + if (touched) + { + float tdStep3D = MathF.Sqrt( + (pod.X - prevX) * (pod.X - prevX) + + (pod.Y - prevY) * (pod.Y - prevY) + + (pod.Z - prevZ) * (pod.Z - prevZ)); + maxTouchdownStep = MathF.Max(maxTouchdownStep, tdStep3D); + if (tdStep3D > 1.0f || horizStep > 1.0f) + { + touchdownWarps++; + } + maxTouchSpeed = MathF.Max(maxTouchSpeed, pod.TouchdownSpeed); + landed = true; + break; + } + } + + Assert.True(landed, $"sion_0005 case {label} (agl={startAgl}, flat={allowFlat}) failed to land"); + totalCases++; + } + } + } + + _output.WriteLine( + $"sion_0005 sweep: cases={totalCases}, hasLCorner={openCornerX.HasValue}, " + + $"wallBreachFrames={wallBreachFrames}, touchdownWarps={touchdownWarps}, " + + $"maxHorizStep={maxHorizStep:F3}m, maxTouchdownStep={maxTouchdownStep:F3}m, maxTouchSpeed={maxTouchSpeed:F2} m/s"); + + Assert.Equal(0, wallBreachFrames); + Assert.Equal(0, touchdownWarps); + Assert.True(maxHorizStep <= 1.0f, $"Horizontal warp {maxHorizStep:F3}m > 1.0m/tick"); + Assert.True(maxTouchSpeed < 3.0f, $"Touchdown speed {maxTouchSpeed:F2} m/s >= 3.0 m/s"); + } + private static void AssertZeroChassisPenetration(MatchState state, ContenderState c) { var spec = c.Grid.Spec;