Fix Cut 5b Soul findings (Bastion hills, Desert spacing, OTS camera, Kestrel legs, scavenge target, spectator laser)

This commit is contained in:
Meta Vens 2026-12-05 07:06:49 +01:00
commit 6ca17fba44
9 changed files with 476 additions and 158 deletions

View file

@ -726,7 +726,8 @@ public partial class ArenaRenderer : Node3D
if (s.Stance != SpectatorStance.Neutral && s.HasTargetLos && target is { Alive: true })
{
Vector3 start = specPos + new Vector3(0f, s.Grid.Spec.HalfHeight * 0.7f, 0f);
Vector3 end = new Vector3(target.X, target.Y + target.Grid.Spec.HalfHeight * 0.3f, target.Z);
var (targetPos, _, _) = session.GetInterpolatedContenderPose(target.Id, alpha);
Vector3 end = new Vector3(targetPos.X, targetPos.Y + target.Grid.Spec.HalfHeight * 0.3f, targetPos.Z);
float dist = start.DistanceTo(end);
if (dist > 0.5f)
{

View file

@ -695,44 +695,33 @@ public partial class Main : Node3D
// Segment 1: sweep terrain + static Box3D (StableId < ContenderStableIdBase) from pivot along camRight * rightOffset
float effectiveRight = rightOffset;
if (Session.State.Terrain.Raycast(
pivot.X, pivot.Y, pivot.Z,
camRight.X, camRight.Y, camRight.Z,
rightOffset,
out _, out _, out _, out float rightTerrainDist))
if (CastStaticCameraRay(pivot, camRight, rightOffset, out float rightHitDist))
{
effectiveRight = MathF.Min(effectiveRight, MathF.Max(0f, rightTerrainDist - 0.45f));
}
var rightBoxHit = Session.World.CastRayClosest(
(pivot.X, pivot.Y, pivot.Z),
(camRight.X * effectiveRight, camRight.Y * effectiveRight, camRight.Z * effectiveRight));
if (rightBoxHit.Hit && rightBoxHit.StableId < ArenaSession.ContenderStableIdBase)
{
var pt = new Vector3(rightBoxHit.Point.X, rightBoxHit.Point.Y, rightBoxHit.Point.Z);
effectiveRight = MathF.Min(effectiveRight, MathF.Max(0f, pivot.DistanceTo(pt) - 0.45f));
effectiveRight = MathF.Min(effectiveRight, MathF.Max(0f, MathF.Min(rightHitDist - 0.35f, rightHitDist * 0.85f)));
}
Vector3 shoulderPos = pivot + camRight * effectiveRight;
// Segment 2: sweep terrain + static Box3D from shoulderPos along -lookDir * backDist
float effectiveBack = backDist;
if (Session.State.Terrain.Raycast(
shoulderPos.X, shoulderPos.Y, shoulderPos.Z,
-lookDir.X, -lookDir.Y, -lookDir.Z,
backDist,
out _, out _, out _, out float backTerrainDist))
if (CastStaticCameraRay(shoulderPos, -lookDir, backDist, out float backHitDist))
{
effectiveBack = MathF.Min(effectiveBack, MathF.Max(0.6f, backTerrainDist - 0.5f));
}
var backBoxHit = Session.World.CastRayClosest(
(shoulderPos.X, shoulderPos.Y, shoulderPos.Z),
(-lookDir.X * effectiveBack, -lookDir.Y * effectiveBack, -lookDir.Z * effectiveBack));
if (backBoxHit.Hit && backBoxHit.StableId < ArenaSession.ContenderStableIdBase)
{
var pt = new Vector3(backBoxHit.Point.X, backBoxHit.Point.Y, backBoxHit.Point.Z);
effectiveBack = MathF.Min(effectiveBack, MathF.Max(0.6f, shoulderPos.DistanceTo(pt) - 0.5f));
effectiveBack = MathF.Min(effectiveBack, SafeCameraPullbackDist(backHitDist));
}
Vector3 camPos = shoulderPos - lookDir * effectiveBack;
// Segment 3: verify direct pivot -> camPos LOS against static terrain/buildings so stepped wings cannot occlude player
Vector3 pivotToCam = camPos - pivot;
float pivotToCamDist = pivotToCam.Length();
if (pivotToCamDist > 0.05f)
{
Vector3 pivotToCamDir = pivotToCam / pivotToCamDist;
if (CastStaticCameraRay(pivot, pivotToCamDir, pivotToCamDist, out float wingHitDist))
{
camPos = pivot + pivotToCamDir * SafeCameraPullbackDist(wingHitDist);
}
}
float minTerrainY = Session.State.Terrain.SampleHeight(camPos.X, camPos.Z) + 1.2f;
if (camPos.Y < minTerrainY)
{
@ -743,6 +732,66 @@ public partial class Main : Node3D
_camera.LookAt(camPos + lookDir * 60f, Vector3.Up);
}
private static float SafeCameraPullbackDist(float rawDist) =>
MathF.Max(MathF.Min(0.05f, rawDist * 0.85f), MathF.Min(rawDist - 0.35f, rawDist * 0.85f));
private bool CastStaticCameraRay(Vector3 origin, Vector3 dir, float maxDist, out float hitDist)
{
hitDist = maxDist;
if (maxDist <= 0.01f)
{
return false;
}
bool hasHit = false;
if (Session.State.Terrain.Raycast(
origin.X, origin.Y, origin.Z,
dir.X, dir.Y, dir.Z,
maxDist,
out _, out _, out _, out float terrainDist))
{
hitDist = MathF.Min(hitDist, terrainDist);
hasHit = true;
}
Vector3 castOrigin = origin;
float skipped = 0f;
float remaining = hitDist;
for (int attempt = 0; attempt < 16 && remaining > 0.05f; attempt++)
{
var hit = Session.World.CastRayClosest(
(castOrigin.X, castOrigin.Y, castOrigin.Z),
(dir.X * remaining, dir.Y * remaining, dir.Z * remaining));
if (!hit.Hit)
{
break;
}
var pt = new Vector3(hit.Point.X, hit.Point.Y, hit.Point.Z);
float distFromOrigin = origin.DistanceTo(pt);
if (hit.StableId < ArenaSession.ContenderStableIdBase)
{
if (distFromOrigin < hitDist)
{
hitDist = distFromOrigin;
hasHit = true;
}
break;
}
float nextSkip = MathF.Max(distFromOrigin + 0.15f, skipped + 0.5f);
if (nextSkip >= hitDist)
{
break;
}
skipped = nextSkip;
castOrigin = origin + dir * skipped;
remaining = hitDist - skipped;
}
return hasHit;
}
private void OnEquipCargo(int cargoIndex, string hardpointId)
{
_session?.TryEquipCargo(cargoIndex, hardpointId);

View file

@ -604,11 +604,26 @@ namespace RustToDust.Core
return dropped;
}
private bool IsOccupiedByHardpoint(int x, int y)
{
for (int i = 0; i < Spec.Hardpoints.Length; i++)
{
var hp = Spec.Hardpoints[i];
if (x >= hp.X && x < hp.X + hp.Width && y >= hp.Y && y < hp.Y + hp.Height)
{
return true;
}
}
return false;
}
public void GetLegIntegrities(Span<float> outLegs)
{
if (Spec.Plane == GridPlane.Coronal)
{
int legStartY = Math.Max(0, Spec.Height - 2);
int legStartY = Spec.Height <= 5
? Math.Max(0, Spec.Height - 1)
: Math.Max(0, Spec.Height - 2);
int leftMaxX = Spec.Width / 2;
int rightMinX = (Spec.Width + 1) / 2;
float curL = 0f, maxL = 0f, curR = 0f, maxR = 0f;
@ -617,7 +632,7 @@ namespace RustToDust.Core
{
for (int x = 0; x < Spec.Width; x++)
{
if (!Spec.IsActive(x, y))
if (!Spec.IsActive(x, y) || IsOccupiedByHardpoint(x, y))
{
continue;
}
@ -708,36 +723,11 @@ namespace RustToDust.Core
return 1f;
}
if (Spec.Plane == GridPlane.Dorsal)
{
Span<float> legs = stackalloc float[4];
GetLegIntegrities(legs);
return (legs[0] + legs[1] + legs[2] + legs[3]) * 0.25f;
}
int legStartY = Math.Max(0, Spec.Height - 2);
float cur = 0f;
float max = 0f;
for (int y = legStartY; y < Spec.Height; y++)
{
for (int x = 0; x < Spec.Width; x++)
{
if (!Spec.IsActive(x, y))
{
continue;
}
cur += Armor[x, y];
max += MaxArmor[x, y];
}
}
if (max <= 0f)
{
return 1f;
}
float ratio = Math.Clamp(cur / max, 0f, 1f);
return 0.25f + 0.75f * ratio;
Span<float> legs = stackalloc float[4];
GetLegIntegrities(legs);
return Spec.Plane == GridPlane.Dorsal
? (legs[0] + legs[1] + legs[2] + legs[3]) * 0.25f
: (legs[0] + legs[1]) * 0.5f;
}
}

View file

@ -427,7 +427,7 @@ namespace RustToDust.Core
}
else if (bestDrop.Chassis is not null)
{
state.TrySwapNearbyChassis(ai.Id);
state.TrySwapNearbyChassis(ai.Id, bestDrop.Id);
}
ai.AiScavengeCooldown = MathF.Max(ai.AiScavengeCooldown, 2.5f);
}

View file

@ -469,7 +469,7 @@ namespace RustToDust.Core
return nearest is not null && ExecuteModuleDropPickup(contenderId, contender, nearest);
}
public bool TrySwapNearbyChassis(int contenderId = 0)
public bool TrySwapNearbyChassis(int contenderId = 0, int? preferredDropId = null)
{
if (contenderId < 0 || contenderId >= Contenders.Count)
{
@ -482,7 +482,7 @@ namespace RustToDust.Core
return false;
}
GroundDrop? nearest = null;
GroundDrop? chosen = null;
float bestDistSq = PickupRadius * PickupRadius;
for (int i = 0; i < GroundDrops.Count; i++)
@ -492,6 +492,10 @@ namespace RustToDust.Core
{
continue;
}
if (preferredDropId.HasValue && d.Id != preferredDropId.Value)
{
continue;
}
float dx = d.X - contender.X;
float dz = d.Z - contender.Z;
@ -499,11 +503,15 @@ namespace RustToDust.Core
if (d2 <= bestDistSq)
{
bestDistSq = d2;
nearest = d;
chosen = d;
if (preferredDropId.HasValue)
{
break;
}
}
}
return nearest is not null && ExecuteChassisDropSwap(contender, nearest);
return chosen is not null && ExecuteChassisDropSwap(contender, chosen);
}
private bool ExecuteModuleDropPickup(int contenderId, ContenderState contender, GroundDrop drop)
@ -611,105 +619,173 @@ namespace RustToDust.Core
private void SpawnContenders()
{
const float minSepSq = 220f * 220f;
const float minR = 210f;
const float maxR = 540f;
const float ringSpan = maxR - minR;
// Equal-start: all 12 contenders (player + 11 AI) spawn in stock Jackals with >= 220m pairwise separation
for (int i = 0; i < ContenderCount; i++)
static float MinDistSqTo(ReadOnlySpan<(float X, float Z)> placed, int count, float x, float z)
{
float x = 0f;
float z = 0f;
float bestX = 0f;
float bestZ = 0f;
float bestMinDistSq = -1f;
bool found = false;
float sectorAngle = (i / (float)ContenderCount) * MathF.Tau;
for (int attempt = 0; attempt < 48; attempt++)
float minSq = float.PositiveInfinity;
for (int k = 0; k < count; k++)
{
float angle = attempt < 8
? sectorAngle + (float)(Rng.NextDouble() - 0.5) * (attempt == 0 ? 0.16f : 0.45f)
: (float)(Rng.NextDouble() * MathF.Tau);
float baseR = attempt < 24
? (245f + (float)Rng.NextDouble() * 250f)
: (380f + (float)Rng.NextDouble() * 115f);
float cx = MathF.Cos(angle) * baseR;
float cz = MathF.Sin(angle) * baseR;
// Nudge radially inside [245, 495] if landing on a slope, dune wall, or cover box
for (int step = 0; step < 8; step++)
float dx = x - placed[k].X;
float dz = z - placed[k].Z;
float d2 = dx * dx + dz * dz;
if (d2 < minSq)
{
var (_, ny, _) = Terrain.SampleNormal(cx, cz);
bool flatPatch = ny >= 0.96f &&
Terrain.SampleNormal(cx + 10f, cz).Ny >= 0.93f &&
Terrain.SampleNormal(cx - 10f, cz).Ny >= 0.93f &&
Terrain.SampleNormal(cx, cz + 10f).Ny >= 0.93f &&
Terrain.SampleNormal(cx, cz - 10f).Ny >= 0.93f;
if (flatPatch && !IsNearCoverBox(cx, cz, 8f))
{
break;
}
float r = 245f + ((baseR - 245f + step * 31f) % 250f);
cx = MathF.Cos(angle) * r;
cz = MathF.Sin(angle) * r;
}
if (IsNearCoverBox(cx, cz, 4f))
{
continue;
}
float minDistSq = MinDistSqToPlacedContenders(cx, cz);
if (minDistSq > bestMinDistSq)
{
bestMinDistSq = minDistSq;
bestX = cx;
bestZ = cz;
}
if (minDistSq >= minSepSq)
{
x = cx;
z = cz;
found = true;
break;
minSq = d2;
}
}
return minSq;
}
if (!found)
Span<(float X, float Z)> coords = stackalloc (float X, float Z)[ContenderCount];
bool allSatisfied = false;
// Equal-start: all 12 contenders (player + 11 AI) spawn in stock Jackals with >= 220m pairwise separation.
// Retry up to 4 passes (increasing outer-ring bias) before falling back to deterministic outer dodecagon.
for (int retry = 0; retry < 4 && !allSatisfied; retry++)
{
allSatisfied = true;
float innerBiasR = retry == 0 ? 350f : 430f;
float innerSpanR = maxR - innerBiasR;
for (int i = 0; i < ContenderCount; i++)
{
for (int pass = 0; pass < 2 && !found; pass++)
float x = 0f;
float z = 0f;
float bestX = 0f;
float bestZ = 0f;
float bestMinDistSq = -1f;
bool found = false;
float sectorAngle = (i / (float)ContenderCount) * MathF.Tau;
for (int attempt = 0; attempt < 64; attempt++)
{
float minNy = pass == 0 ? 0.88f : 0f;
for (float r = 495f; r >= 245f && !found; r -= 15f)
float angle = attempt < 12
? sectorAngle + (float)(Rng.NextDouble() - 0.5) * (attempt == 0 ? 0.16f : 0.42f)
: (float)(Rng.NextDouble() * MathF.Tau);
float baseR = attempt < 32
? (innerBiasR + (float)Rng.NextDouble() * innerSpanR)
: (minR + (float)Rng.NextDouble() * ringSpan);
float cx = MathF.Cos(angle) * baseR;
float cz = MathF.Sin(angle) * baseR;
// Nudge radially inside [minR, maxR] if landing on a slope, dune wall, or cover box
for (int step = 0; step < 8; step++)
{
for (int a = 0; a < 72; a++)
var (_, ny, _) = Terrain.SampleNormal(cx, cz);
bool flatPatch = ny >= 0.96f &&
Terrain.SampleNormal(cx + 10f, cz).Ny >= 0.93f &&
Terrain.SampleNormal(cx - 10f, cz).Ny >= 0.93f &&
Terrain.SampleNormal(cx, cz + 10f).Ny >= 0.93f &&
Terrain.SampleNormal(cx, cz - 10f).Ny >= 0.93f;
if (flatPatch && !IsNearCoverBox(cx, cz, 8f))
{
float ang = sectorAngle + (a / 72f) * MathF.Tau;
float cx = MathF.Cos(ang) * r;
float cz = MathF.Sin(ang) * r;
if (minNy > 0f && Terrain.SampleNormal(cx, cz).Ny < minNy)
break;
}
float r = minR + ((baseR - minR + step * 37f) % ringSpan);
cx = MathF.Cos(angle) * r;
cz = MathF.Sin(angle) * r;
}
if (IsNearCoverBox(cx, cz, 4f))
{
continue;
}
float minDistSq = MinDistSqTo(coords, i, cx, cz);
if (minDistSq > bestMinDistSq)
{
bestMinDistSq = minDistSq;
bestX = cx;
bestZ = cz;
}
if (minDistSq >= minSepSq)
{
x = cx;
z = cz;
found = true;
break;
}
}
if (!found)
{
for (int pass = 0; pass < 2 && !found; pass++)
{
float minNy = pass == 0 ? 0.88f : 0f;
for (float r = maxR; r >= 180f && !found; r -= 12f)
{
for (int a = 0; a < 96; a++)
{
continue;
}
if (IsNearCoverBox(cx, cz, 4f))
{
continue;
}
if (MinDistSqToPlacedContenders(cx, cz) >= minSepSq)
{
x = cx;
z = cz;
found = true;
break;
float ang = sectorAngle + (a / 96f) * MathF.Tau;
float cx = MathF.Cos(ang) * r;
float cz = MathF.Sin(ang) * r;
if (minNy > 0f && Terrain.SampleNormal(cx, cz).Ny < minNy)
{
continue;
}
if (IsNearCoverBox(cx, cz, 4f))
{
continue;
}
if (MinDistSqTo(coords, i, cx, cz) >= minSepSq)
{
x = cx;
z = cz;
found = true;
break;
}
}
}
}
}
}
if (!found)
{
x = bestX;
z = bestZ;
if (!found)
{
allSatisfied = false;
x = bestX;
z = bestZ;
break;
}
coords[i] = (x, z);
}
}
if (!allSatisfied)
{
// Deterministic outer dodecagon fallback: chord at r=500m is 258.8m (> 220m)
for (int i = 0; i < ContenderCount; i++)
{
float sectorAngle = (i / (float)ContenderCount) * MathF.Tau;
float chosenX = MathF.Cos(sectorAngle) * 500f;
float chosenZ = MathF.Sin(sectorAngle) * 500f;
bool placed = false;
for (float r = 510f; r >= 460f && !placed; r -= 10f)
{
for (int da = 0; da < 5 && !placed; da++)
{
float ang = sectorAngle + (da - 2) * 0.02f;
float cx = MathF.Cos(ang) * r;
float cz = MathF.Sin(ang) * r;
if (!IsNearCoverBox(cx, cz, 4f) && MinDistSqTo(coords, i, cx, cz) >= minSepSq)
{
chosenX = cx;
chosenZ = cz;
placed = true;
}
}
}
coords[i] = (chosenX, chosenZ);
}
}
for (int i = 0; i < ContenderCount; i++)
{
float x = coords[i].X;
float z = coords[i].Z;
float yaw = MathF.Atan2(-x, -z);
string name = i == 0 ? "Contender 01 (You)" : $"Contender {i + 1:00}";

View file

@ -523,12 +523,15 @@ namespace RustToDust.Ymir
}
}
private static float GetPhysicsHalfHeight(ChassisSpec spec) =>
spec.IsWalker
? spec.HalfHeight * (spec.Plane == GridPlane.Dorsal ? 0.42f : 0.72f)
: spec.HalfHeight;
private void SpawnContenderBody(ContenderState c)
{
var spec = c.Grid.Spec;
float physHalfH = spec.IsWalker
? spec.HalfHeight * (spec.Plane == GridPlane.Dorsal ? 0.58f : 0.72f)
: spec.HalfHeight;
float physHalfH = GetPhysicsHalfHeight(spec);
float volume = 8f * spec.HalfWidth * physHalfH * spec.HalfLength;
float density = spec.MassKg / MathF.Max(0.1f, volume);
var q = Quaternion.CreateFromAxisAngle(Vector3.UnitY, c.Yaw);
@ -602,9 +605,7 @@ namespace RustToDust.Ymir
private void SpawnSpectatorBody(int index, SpectatorState s)
{
var spec = s.Grid.Spec;
float physHalfH = spec.IsWalker
? spec.HalfHeight * (spec.Plane == GridPlane.Dorsal ? 0.58f : 0.72f)
: spec.HalfHeight;
float physHalfH = GetPhysicsHalfHeight(spec);
float volume = 8f * spec.HalfWidth * physHalfH * spec.HalfLength;
float density = spec.MassKg / MathF.Max(0.1f, volume);
var q = Quaternion.CreateFromAxisAngle(Vector3.UnitY, s.Yaw);

View file

@ -842,36 +842,48 @@ namespace RustToDust.Ymir
float terrainRateY = Math.Clamp(rawTerrainRateY, -12f, 11f);
float plantedYSum = 0f;
int plantedYCount = 0;
float uphillFootGroundY = comGroundY;
for (int i = 0; i < n; i++)
{
if (ws.Planted[i])
{
plantedYSum += ws.FootSole[i].Y;
plantedYCount++;
Vector3 footNorm = WalkerState.SampleTerrainNormal(terrain, ws.FootSole[i].X, ws.FootSole[i].Z);
if (footNorm.Y >= 0.78f && ws.FootSole[i].Y > uphillFootGroundY)
{
uphillFootGroundY = ws.FootSole[i].Y;
}
}
}
float supportGroundY = plantedYCount > 0
? Math.Clamp(plantedYSum / plantedYCount, comGroundY - 0.03f * scale, comGroundY + 0.18f * scale)
: comGroundY;
// When sprinting uphill on traversable slopes (aheadNormal.Y >= 0.78), track rising terrain ahead so tall fast bipeds don't sink into steep dunes
// Track rising traversable slopes (aheadNormal.Y >= 0.78) from planted uphill feet and forward probe so wide/heavy hulls raise cleanly over hills
float effectiveGroundY = MathF.Max(supportGroundY, comGroundY);
if (horizSpeed > 2.0f)
float slopeGroundY = uphillFootGroundY;
Vector2 probeVec = horizSpeed > 1.0f
? new Vector2(vel.X / horizSpeed, vel.Z / horizSpeed)
: (desiredSpeed > 0.1f
? new Vector2(desiredHorizVel.X / desiredSpeed, desiredHorizVel.Z / desiredSpeed)
: new Vector2(fwd.X, fwd.Z));
float leadDist = Math.Clamp(MathF.Max(horizSpeed * 0.08f, view.Size2[lane] * 0.65f), 1.5f, 5.5f);
float ax = comPos.X + probeVec.X * leadDist;
float az = comPos.Z + probeVec.Y * leadDist;
Vector3 aheadNorm = WalkerState.SampleTerrainNormal(terrain, ax, az);
if (aheadNorm.Y >= 0.78f)
{
float vxDir = vel.X / horizSpeed;
float vzDir = vel.Z / horizSpeed;
float leadDist = MathF.Min(horizSpeed * 0.06f, 2.2f);
float ax = comPos.X + vxDir * leadDist;
float az = comPos.Z + vzDir * leadDist;
Vector3 aheadNorm = WalkerState.SampleTerrainNormal(terrain, ax, az);
if (aheadNorm.Y >= 0.78f)
float aheadH = terrain.SampleHeight(ax, az);
if (aheadH > slopeGroundY)
{
float aheadH = terrain.SampleHeight(ax, az);
if (aheadH > comGroundY)
{
effectiveGroundY = MathF.Max(effectiveGroundY, (comGroundY + aheadH) * 0.5f);
}
slopeGroundY = aheadH;
}
}
if (slopeGroundY > comGroundY)
{
float climbLift = MathF.Min(0.75f * scale, (slopeGroundY - comGroundY) * 0.45f);
effectiveGroundY = MathF.Max(effectiveGroundY, comGroundY + climbLift);
}
float targetY = effectiveGroundY + rideHeight;
float fyDes = MathF.Max(0f,
@ -880,7 +892,7 @@ namespace RustToDust.Ymir
mass * 10.5f * (terrainRateY - vel.Y));
float penThresh = MathF.Min(geom.ModelHalfHeight * scale, rideHeight) - 0.01f * scale;
float hullBottomPen = (comGroundY + penThresh) - comPos.Y;
if (!ws.IsAirborne && terrainNormal.Y < 0.975f && (vel.Y - terrainRateY) < 0.4f && comPos.Y <= comGroundY + geom.ModelHalfHeight * scale + 0.45f * scale)
if (!ws.IsAirborne && terrainNormal.Y < 0.975f && (vel.Y - terrainRateY) < 0.4f && comPos.Y <= targetY + 0.45f * scale)
{
fyDes = MathF.Max(fyDes, mass * Gravity);
}

View file

@ -710,5 +710,134 @@ namespace RustToDust.Tests
Assert.True(finalSlide < 0.18f, $"{spec.Id} Sion slope release: 1.0s slide={finalSlide:F4}m >= 0.18m");
}
}
[Fact]
public void HybridB_Bastion_SteepSionHills_15To22Deg_ClimbsWithoutBeaching()
{
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion);
for (int i = 1; i < session.State.Contenders.Count; i++)
{
session.SetContenderPose(i, 900f + i * 16f, 900f);
}
var sion = session.State.SionMap!;
var sites = new System.Collections.Generic.List<(float X, float Z, float Yaw, float Ny)>();
for (float r = 60f; r <= 720f && sites.Count < 3; r += 25f)
{
for (int a = 0; a < 48 && sites.Count < 3; a++)
{
float ang = a * (MathF.Tau / 48f);
float x = MathF.Cos(ang) * r;
float z = MathF.Sin(ang) * r;
if (sion.IsInsideAnyBuildingXz(x, z, 14f)) continue;
var (nx, ny, nz) = session.State.Terrain.SampleNormal(x, z);
if (ny < 0.925f || ny > 0.966f) continue;
float yaw = MathF.Atan2(-nx, -nz);
float fx = MathF.Sin(yaw);
float fz = MathF.Cos(yaw);
float rx = -fz;
float rz = fx;
bool clear = true;
foreach (float lat in new[] { -7.5f, 0f, 7.5f })
{
float sx = x + rx * lat;
float sz = z + rz * lat;
for (float d = 0f; d < 28f; d += 4f)
{
float ax = sx + fx * d;
float az = sz + fz * d;
float bx = sx + fx * (d + 4f);
float bz = sz + fz * (d + 4f);
if (sion.IsInsideAnyBuildingXz(ax, az, 4f) ||
session.State.Terrain.SampleNormal(ax, az).Ny < 0.88f)
{
clear = false;
break;
}
float gyA = session.State.Terrain.SampleHeight(ax, az);
float gyB = session.State.Terrain.SampleHeight(bx, bz);
if (!session.HasLineOfSight(ax, gyA + 2.5f, az, bx, gyB + 2.5f, bz))
{
clear = false;
break;
}
}
if (!clear) break;
}
if (clear && sites.TrueForAll(s => (s.X - x) * (s.X - x) + (s.Z - z) * (s.Z - z) > 60f * 60f))
{
sites.Add((x, z, yaw, ny));
}
}
}
Assert.NotEmpty(sites);
session.SetContenderPose(0, sites[0].X, sites[0].Z, sites[0].Yaw);
session.State.SpawnChassisDrop(sites[0].X, sites[0].Z, Catalog.Bastion);
Assert.True(session.TrySwapNearbyChassis(), "Failed swap to Bastion on Sion");
var player = session.State.Player;
foreach (var site in sites)
{
session.SetContenderPose(0, site.X, site.Z, site.Yaw);
Vector2 startPos = new(player.X, player.Z);
Vector2 fwdDir = new(MathF.Sin(site.Yaw), MathF.Cos(site.Yaw));
float gStart = session.State.Terrain.SampleHeight(player.X, player.Z);
for (int t = 0; t < 120; t++)
{
session.Step(new PlayerInput(
Throttle: 1f,
Steer: 0f,
AimWorldX: player.X + fwdDir.X * 50f,
AimWorldZ: player.Z + fwdDir.Y * 50f,
Fire: false,
InteractPickup: false,
Brake: false));
}
float disp2s = Vector2.Dot(new Vector2(player.X, player.Z) - startPos, fwdDir);
float endSpd = player.Speed;
float gEnd = session.State.Terrain.SampleHeight(player.X, player.Z);
var ws = session.GetWalkerState(true, player.Id)!;
_output.WriteLine(
$"Bastion Sion 15-22deg site ({site.X:F1},{site.Z:F1}) ny={site.Ny:F3}: " +
$"disp2s={disp2s:F2}m endSpd={endSpd:F2}m/s climb={(gEnd - gStart):F2}m force={ws.LastTotalForce}");
Assert.True(disp2s >= 10.0f, $"Bastion beached on Sion hill ny={site.Ny:F3}: disp2s={disp2s:F2}m < 10.0m");
Assert.True(endSpd >= 6.0f, $"Bastion stalled on Sion hill ny={site.Ny:F3}: endSpd={endSpd:F2}m/s < 6.0m/s");
}
}
[Fact]
public void Kestrel_5x5Coronal_ArmAndEngineDamage_DoesNotCrippleLegs()
{
var grid = new ChassisGrid(Catalog.Kestrel);
Span<float> legs = stackalloc float[4];
// Destroy right weapon arm (4,2),(4,3) and engine core (2,2),(2,3)
grid.Armor[4, 2] = 0f;
grid.Armor[4, 3] = 0f;
grid.Armor[2, 2] = 0f;
grid.Armor[2, 3] = 0f;
grid.GetLegIntegrities(legs);
Assert.Equal(1.0f, legs[0], precision: 3);
Assert.Equal(1.0f, legs[1], precision: 3);
Assert.Equal(1.0f, grid.LegIntegrity, precision: 3);
// Destroy left leg (1,4) -> only legs[0] drops
grid.Armor[1, 4] = 0f;
grid.GetLegIntegrities(legs);
Assert.True(legs[0] < 1.0f, $"Expected left leg integrity < 1.0 after (1,4) destroyed, got {legs[0]:F3}");
Assert.Equal(1.0f, legs[1], precision: 3);
Assert.True(grid.LegIntegrity < 1.0f);
// Destroy right leg (3,4) -> legs[1] also drops
grid.Armor[3, 4] = 0f;
grid.GetLegIntegrities(legs);
Assert.True(legs[1] < 1.0f, $"Expected right leg integrity < 1.0 after (3,4) destroyed, got {legs[1]:F3}");
}
}
}

View file

@ -452,5 +452,65 @@ namespace RustToDust.Tests
$"Ultra-close 2.2m muzzle overshot target Z! startZ={tracer.StartZ:F2}, targetZ={target.Z:F2}");
}
}
[Fact]
public void EqualStart_50Seeds_DesertAndSion_AllPairsAtLeast220m()
{
foreach (var map in new[] { ArenaMapKind.Desert, ArenaMapKind.Sion })
{
for (int seed = 1; seed <= 50; seed++)
{
var state = new MatchState(seed, map);
Assert.Equal(MatchState.ContenderCount, state.Contenders.Count);
float minDist = float.PositiveInfinity;
int minA = -1, minB = -1;
for (int i = 0; i < state.Contenders.Count; i++)
{
for (int j = i + 1; j < state.Contenders.Count; j++)
{
float dx = state.Contenders[i].X - state.Contenders[j].X;
float dz = state.Contenders[i].Z - state.Contenders[j].Z;
float d = MathF.Sqrt(dx * dx + dz * dz);
if (d < minDist)
{
minDist = d;
minA = i;
minB = j;
}
}
}
Assert.True(minDist >= 220.0f,
$"Map={map}, Seed={seed}: Contenders {minA} and {minB} pairwise separation {minDist:F2}m < 220.0m");
}
}
}
[Fact]
public void AiScavenge_PrefersBetterUpgradeInPickupRange_OverCloserInferiorWreck()
{
using var session = new ArenaSession(seed: 42, ArenaMapKind.Desert);
IsolateContenders(session, 0, 1);
var player = session.State.Player;
var ai = session.State.Contenders[1];
foreach (var d in session.State.GroundDrops)
{
d.PickedUp = true;
}
session.SetContenderPose(player.Id, -450f, -450f, yaw: 0f);
session.SetContenderPose(ai.Id, 0f, 0f, yaw: 0f);
ai.AiScavengeCooldown = 0f;
// Closer abandoned Jackal wreck at 1.5m vs superior Hornet at 5.5m (both within PickupRadius = 7.0m)
session.State.SpawnChassisDrop(0f, 1.5f, Catalog.Jackal);
session.State.SpawnChassisDrop(0f, 5.5f, Catalog.Hornet);
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
Assert.Equal(Catalog.Hornet.Id, ai.Grid.Spec.Id);
}
}
}