Core/Ymir: fix Raptor engine mount, Cleared provocation, cover clearance, road loop, and broadside muzzle

This commit is contained in:
Meta Vens 2026-12-04 14:16:05 +01:00
commit 6507a71c23
8 changed files with 198 additions and 23 deletions

View file

@ -168,7 +168,7 @@ namespace RustToDust.Core
new HardpointSpec("rad_lsh", HardpointKind.Radiator, 1, 1, 1, 1, 4f),
new HardpointSpec("rad_rsh", HardpointKind.Radiator, 3, 1, 1, 1, 4f),
new HardpointSpec("wpn_larm", HardpointKind.Weapon, 0, 2, 1, 2, 8f),
new HardpointSpec("eng_chest", HardpointKind.Engine, 2, 2, 1, 1, 12f),
new HardpointSpec("eng_chest", HardpointKind.Engine, 2, 2, 1, 2, 12f),
new HardpointSpec("wpn_rarm", HardpointKind.Weapon, 4, 2, 1, 2, 8f)
},
HullConductivity: 10.5f,

View file

@ -372,8 +372,12 @@ namespace RustToDust.Core
for (int i = 0; i < raw.Count; i++)
{
var b = raw[i];
float groundY = terrain.SampleHeight(b.X, b.Z);
seated[i] = b with { Y = groundY + b.HalfY };
float minY = terrain.SampleHeight(b.X, b.Z);
minY = MathF.Min(minY, terrain.SampleHeight(b.X - b.HalfX, b.Z - b.HalfZ));
minY = MathF.Min(minY, terrain.SampleHeight(b.X + b.HalfX, b.Z - b.HalfZ));
minY = MathF.Min(minY, terrain.SampleHeight(b.X - b.HalfX, b.Z + b.HalfZ));
minY = MathF.Min(minY, terrain.SampleHeight(b.X + b.HalfX, b.Z + b.HalfZ));
seated[i] = b with { Y = minY + b.HalfY };
}
return seated;
}

View file

@ -191,7 +191,7 @@ namespace RustToDust.Core
return false;
}
if (spectator.Stance == SpectatorStance.Neutral)
if (spectator.Stance == SpectatorStance.Neutral || spectator.Stance == SpectatorStance.Cleared)
{
spectator.Stance = SpectatorStance.Provoked;
spectator.TargetContenderId = attackerContenderId;
@ -328,6 +328,15 @@ namespace RustToDust.Core
}
}
private static void MountRequired(ChassisGrid grid, ModuleSpec mod, string hardpointId)
{
if (!grid.TryMount(mod, hardpointId))
{
throw new InvalidOperationException(
$"Failed to mount '{mod.Id}' onto '{grid.Spec.Id}.{hardpointId}'.");
}
}
private static SpectatorState CreateSpectator(int id, SpectatorTier tier, float angle, float ringOffset)
{
switch (tier)
@ -335,11 +344,11 @@ namespace RustToDust.Core
case SpectatorTier.Tourist:
{
var grid = new ChassisGrid(Catalog.Paladin);
grid.TryMount(Catalog.GildedLance, "wpn_larm");
grid.TryMount(Catalog.TouringPlasma, "wpn_lsh");
grid.TryMount(Catalog.NobleCore, "eng_core");
grid.TryMount(Catalog.GoldRadiator, "rad_l");
grid.TryMount(Catalog.GildedPlate, "arm_collar");
MountRequired(grid, Catalog.GildedLance, "wpn_larm");
MountRequired(grid, Catalog.TouringPlasma, "wpn_lsh");
MountRequired(grid, Catalog.NobleCore, "eng_core");
MountRequired(grid, Catalog.GoldRadiator, "rad_l");
MountRequired(grid, Catalog.GildedPlate, "arm_collar");
return new SpectatorState(
id, tier, grid, angle, ringOffset,
radarSignature: 1.0f,
@ -350,10 +359,10 @@ namespace RustToDust.Core
case SpectatorTier.Patron:
{
var grid = new ChassisGrid(Catalog.Raptor);
grid.TryMount(Catalog.Autocannon, "wpn_larm");
grid.TryMount(Catalog.Flak, "wpn_rarm");
grid.TryMount(Catalog.TurboCore, "eng_chest");
grid.TryMount(Catalog.CopperRad, "rad_lsh");
MountRequired(grid, Catalog.Autocannon, "wpn_larm");
MountRequired(grid, Catalog.Flak, "wpn_rarm");
MountRequired(grid, Catalog.TurboCore, "eng_chest");
MountRequired(grid, Catalog.CopperRad, "rad_lsh");
return new SpectatorState(
id, tier, grid, angle, ringOffset,
radarSignature: 0.6f,
@ -378,11 +387,11 @@ namespace RustToDust.Core
HalfLength = 0.8f
};
var grid = new ChassisGrid(exemplarSpec);
grid.TryMount(Catalog.GildedLance, "wpn_rarm");
grid.TryMount(Catalog.TouringPlasma, "wpn_larm");
grid.TryMount(Catalog.NobleCore, "eng_chest");
grid.TryMount(Catalog.GoldRadiator, "rad_lsh");
grid.TryMount(Catalog.GoldRadiator, "rad_rsh");
MountRequired(grid, Catalog.GildedLance, "wpn_rarm");
MountRequired(grid, Catalog.TouringPlasma, "wpn_larm");
MountRequired(grid, Catalog.NobleCore, "eng_chest");
MountRequired(grid, Catalog.GoldRadiator, "rad_lsh");
MountRequired(grid, Catalog.GoldRadiator, "rad_rsh");
return new SpectatorState(
id, tier, grid, angle, ringOffset,
radarSignature: 0.22f,

View file

@ -125,8 +125,8 @@ namespace RustToDust.Core
X: rx,
Z: rz,
RotationRad: tangentRot,
RadiusX: 9f,
RadiusZ: 34f,
RadiusX: 34f,
RadiusZ: 9f,
HeightDelta: -0.18f,
Roughness: 0.94f,
Metallic: 0.02f,
@ -529,7 +529,8 @@ namespace RustToDust.Core
private static void GetBrushTileBounds(in TerrainBrush brush, out int minTx, out int maxTx, out int minTz, out int maxTz)
{
float extent = MathF.Sqrt(brush.RadiusX * brush.RadiusX + brush.RadiusZ * brush.RadiusZ);
const float gutterPaddingMeters = 1.0f;
float extent = MathF.Sqrt(brush.RadiusX * brush.RadiusX + brush.RadiusZ * brush.RadiusZ) + gutterPaddingMeters;
float minX = brush.X - extent;
float maxX = brush.X + extent;
float minZ = brush.Z - extent;
@ -554,10 +555,18 @@ namespace RustToDust.Core
return false;
}
const float margin = 1.5f;
for (int i = 0; i < coverBoxes.Count; i++)
{
var c = coverBoxes[i];
if (MathF.Abs(EvaluateBrushHeight(in candidate, c.X, c.Z)) > 0.35f)
float hx = c.HalfX + margin;
float hz = c.HalfZ + margin;
if (MathF.Abs(EvaluateBrushHeight(in candidate, c.X, c.Z)) > 0.35f ||
MathF.Abs(EvaluateBrushHeight(in candidate, c.X - hx, c.Z - hz)) > 0.35f ||
MathF.Abs(EvaluateBrushHeight(in candidate, c.X + hx, c.Z - hz)) > 0.35f ||
MathF.Abs(EvaluateBrushHeight(in candidate, c.X - hx, c.Z + hz)) > 0.35f ||
MathF.Abs(EvaluateBrushHeight(in candidate, c.X + hx, c.Z + hz)) > 0.35f)
{
return false;
}

View file

@ -568,6 +568,7 @@ namespace RustToDust.Ymir
isSpectatorShooter: false,
shooterGrid: c.Grid,
shooterPos: new Vector3(c.X, c.Y, c.Z),
shooterYaw: c.Yaw,
aimX: c.AimX,
aimZ: c.AimZ,
extraSpread: 0f,
@ -596,6 +597,7 @@ namespace RustToDust.Ymir
isSpectatorShooter: true,
shooterGrid: s.Grid,
shooterPos: new Vector3(s.X, s.Y, s.Z),
shooterYaw: s.Yaw,
aimX: aimX,
aimZ: aimZ,
extraSpread: s.AimSpreadRad,
@ -610,6 +612,7 @@ namespace RustToDust.Ymir
bool isSpectatorShooter,
ChassisGrid shooterGrid,
Vector3 shooterPos,
float shooterYaw,
float aimX,
float aimZ,
float extraSpread,
@ -635,7 +638,14 @@ namespace RustToDust.Ymir
horizDir = Vector3.Normalize(horizDir);
}
float clearance = MathF.Max(shooterGrid.Spec.HalfWidth, shooterGrid.Spec.HalfLength) + 0.55f;
float cosYaw = MathF.Cos(shooterYaw);
float sinYaw = MathF.Sin(shooterYaw);
float localDirX = horizDir.X * cosYaw - horizDir.Z * sinYaw;
float localDirZ = horizDir.X * sinYaw + horizDir.Z * cosYaw;
float clearance =
MathF.Abs(localDirX) * shooterGrid.Spec.HalfWidth +
MathF.Abs(localDirZ) * shooterGrid.Spec.HalfLength +
0.35f;
Vector3 muzzle = new Vector3(
shooterPos.X + horizDir.X * clearance,
shooterPos.Y + shooterGrid.Spec.HalfHeight * 0.25f,

View file

@ -93,5 +93,40 @@ namespace RustToDust.Tests
var clearHit = session.World.CastRayClosest((28f, 5.0f, 10f), (0f, 0f, 15f));
Assert.False(clearHit.Hit);
}
[Fact]
public void BroadsideFire_UsesDirectionalSupportRadiusNotMaxExtent()
{
using var session = new ArenaSession(seed: 19);
var player = session.State.Player;
// Swap to Tank (HalfWidth = 1.65m, HalfLength = 2.65m) where broadside vs forward differs by 1.0m.
session.State.SpawnChassisDrop(player.X + 0.5f, player.Z + 0.5f, Catalog.Tank);
Assert.True(session.TrySwapNearbyChassis());
Assert.Equal("tank", player.Grid.Spec.Id);
// Step once to settle body, then aim strictly perpendicular (broadside) to player's Yaw.
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, false));
float broadsideX = MathF.Cos(player.Yaw);
float broadsideZ = -MathF.Sin(player.Yaw);
session.Step(new PlayerInput(
Throttle: 0f,
Steer: 0f,
AimWorldX: player.X + broadsideX * 30f,
AimWorldZ: player.Z + broadsideZ * 30f,
Fire: true,
InteractPickup: false,
Brake: true));
Assert.NotEmpty(session.State.Tracers);
var tracer = session.State.Tracers[^1];
float dx = tracer.StartX - player.X;
float dz = tracer.StartZ - player.Z;
float muzzleHorizDist = MathF.Sqrt(dx * dx + dz * dz);
// Expected broadside clearance = HalfWidth (1.65) + 0.35 = 2.00m (well below HalfLength + 0.55 = 3.20m)
Assert.InRange(muzzleHorizDist, player.Grid.Spec.HalfWidth + 0.25f, player.Grid.Spec.HalfWidth + 0.50f);
}
}
}

View file

@ -90,5 +90,44 @@ namespace RustToDust.Tests
Assert.DoesNotContain(drops, d => d.IsImperial);
}
}
[Fact]
public void SpawnedSpectators_EveryTierMountsEngineAndWeapon()
{
var ring = new SpectatorRing(seed: 42);
Assert.Contains(ring.Spectators, s => s.Tier == SpectatorTier.Tourist);
Assert.Contains(ring.Spectators, s => s.Tier == SpectatorTier.Patron);
Assert.Contains(ring.Spectators, s => s.Tier == SpectatorTier.Exemplar);
foreach (var spec in ring.Spectators)
{
Assert.Contains(spec.Grid.Mounted, m => m.Spec.Kind == HardpointKind.Engine);
Assert.Contains(spec.Grid.Mounted, m => m.Spec.Kind == HardpointKind.Weapon);
}
}
[Fact]
public void Provocation_AttackingClearedSpectatorSwitchesToProvokedAndPersistsInsideSafeCircle()
{
var ring = new SpectatorRing(seed: 505);
float outsideR = ring.SafeRadius + 15f;
// Contender 0 steps outside safe circle -> clears at least 1 spectator
ring.UpdateClearance(new[] { new RingContact(0, outsideR, 0f, true) });
var clearedSpec = ring.Spectators.FirstOrDefault(s => s.Stance == SpectatorStance.Cleared);
Assert.NotNull(clearedSpec);
// Contender 0 fights back against the Cleared spectator
bool provoked = ring.OnSpectatorDamaged(clearedSpec!, attackerContenderId: 0);
Assert.True(provoked);
Assert.Equal(SpectatorStance.Provoked, clearedSpec!.Stance);
Assert.Equal(0, clearedSpec.TargetContenderId);
// Returning inside the safe circle must NOT clear the Provoked lock
ring.UpdateClearance(new[] { new RingContact(0, 0f, 0f, true) });
Assert.Equal(SpectatorStance.Provoked, clearedSpec.Stance);
Assert.Equal(1, ring.CountProvokedFor(0));
}
}
}

View file

@ -138,5 +138,74 @@ namespace RustToDust.Tests
Assert.True(maxGround - minGround > 0.25f,
$"Expected buggy to traverse non-flat terrain (span {maxGround - minGround:F2}m)");
}
[Theory]
[InlineData(42)]
[InlineData(101)]
[InlineData(999)]
public void CoverBoxes_HaveFlatFootprintWithinHalfMeterAcrossAllCorners(int seed)
{
var state = new MatchState(seed);
float maxCoverCornerDelta = 0f;
foreach (var box in state.ArenaCoverBoxes)
{
float[] heights =
{
state.Terrain.SampleHeight(box.X, box.Z),
state.Terrain.SampleHeight(box.X - box.HalfX, box.Z - box.HalfZ),
state.Terrain.SampleHeight(box.X + box.HalfX, box.Z - box.HalfZ),
state.Terrain.SampleHeight(box.X - box.HalfX, box.Z + box.HalfZ),
state.Terrain.SampleHeight(box.X + box.HalfX, box.Z + box.HalfZ)
};
float minH = float.PositiveInfinity;
float maxH = float.NegativeInfinity;
for (int i = 0; i < heights.Length; i++)
{
minH = MathF.Min(minH, heights[i]);
maxH = MathF.Max(maxH, heights[i]);
}
maxCoverCornerDelta = MathF.Max(maxCoverCornerDelta, maxH - minH);
float boxBottom = box.Y - box.HalfY;
Assert.True(boxBottom <= minH + 0.01f,
$"Cover box at ({box.X}, {box.Z}) bottom {boxBottom:F2}m floats above corner height {minH:F2}m");
}
Assert.True(maxCoverCornerDelta <= 0.5f,
$"Expected MaxCoverCornerDelta <= 0.5m for seed {seed}, got {maxCoverCornerDelta:F3}m");
}
[Fact]
public void RoadBrushes_MajorAxisRunsTangentiallyToFormRingLoop()
{
var terrain = TerrainField.Generate(42UL, Array.Empty<ArenaBoxSpec>());
var roads = new List<TerrainBrush>();
for (int i = 0; i < terrain.Brushes.Count; i++)
{
if (terrain.Brushes[i].Kind == TerrainBrushKind.Road)
{
roads.Add(terrain.Brushes[i]);
}
}
Assert.Equal(8, roads.Count);
foreach (var road in roads)
{
Assert.True(road.RadiusX > road.RadiusZ,
$"Expected Road RadiusX ({road.RadiusX}) > RadiusZ ({road.RadiusZ}) so major axis follows tangential u");
float rLen = MathF.Sqrt(road.X * road.X + road.Z * road.Z);
float radX = road.X / rLen;
float radZ = road.Z / rLen;
float axisX = MathF.Cos(road.RotationRad);
float axisZ = MathF.Sin(road.RotationRad);
float radialDot = MathF.Abs(radX * axisX + radZ * axisZ);
Assert.True(radialDot < 1e-4f,
$"Expected Road major axis to be tangential (dot ~ 0), got {radialDot:F4}");
}
}
}
}