RustToDust Phase 1: Core simulation, Ymir Box3D arena, and behavioral tests
This commit is contained in:
parent
ea63ae8f03
commit
1e6efd7b55
15 changed files with 3870 additions and 0 deletions
91
tests/RustToDust.Tests/ArenaSessionTests.cs
Normal file
91
tests/RustToDust.Tests/ArenaSessionTests.cs
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
using System;
|
||||
using RustToDust.Core;
|
||||
using RustToDust.Ymir;
|
||||
using Xunit;
|
||||
|
||||
namespace RustToDust.Tests
|
||||
{
|
||||
public sealed class ArenaSessionTests
|
||||
{
|
||||
[Fact]
|
||||
public void DrivingAndFiring_MovesBuggyInYmirAndBuildsWeaponHeat()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 42);
|
||||
var player = session.State.Player;
|
||||
float startX = player.X;
|
||||
float startZ = player.Z;
|
||||
float startYaw = player.Yaw;
|
||||
|
||||
for (int tick = 0; tick < 120; tick++)
|
||||
{
|
||||
session.Step(new PlayerInput(
|
||||
Throttle: 1f,
|
||||
Steer: 0.45f,
|
||||
AimWorldX: player.X + 40f,
|
||||
AimWorldZ: player.Z + 10f,
|
||||
Fire: true,
|
||||
InteractPickup: false,
|
||||
Brake: false));
|
||||
}
|
||||
|
||||
float dx = player.X - startX;
|
||||
float dz = player.Z - startZ;
|
||||
float displacement = MathF.Sqrt(dx * dx + dz * dz);
|
||||
float yawDelta = MathF.Abs(MatchRules.NormalizeAngle(player.Yaw - startYaw));
|
||||
|
||||
Assert.True(displacement > 10f, $"Expected >10m displacement, got {displacement:F2}m");
|
||||
Assert.True(yawDelta > 0.2f, $"Expected yaw change >0.2 rad, got {yawDelta:F2} rad");
|
||||
|
||||
var weapon = player.Grid.GetMountedOn("wpn_roof");
|
||||
Assert.NotNull(weapon);
|
||||
Assert.True(weapon!.CurrentTemp > ChassisGrid.AmbientTemp + 5f);
|
||||
Assert.NotEmpty(session.State.Tracers);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ChassisSwap_ToManticoreAndRaptor_ReplacesBodyWithoutLeakingYmirLanes()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 77);
|
||||
var player = session.State.Player;
|
||||
int initialFreeSlots = session.World.FreeBodySlots;
|
||||
|
||||
// Step once to settle world
|
||||
session.Step(new PlayerInput(0f, 0f, 0f, 0f, false, false, false));
|
||||
|
||||
// Spawn Manticore (Dorsal) right beside player and swap
|
||||
session.State.SpawnChassisDrop(player.X + 1f, player.Z + 1f, Catalog.Manticore);
|
||||
Assert.True(session.TrySwapNearbyChassis());
|
||||
Assert.Equal("manticore", player.Grid.Spec.Id);
|
||||
Assert.Equal(GridPlane.Dorsal, player.Grid.Spec.Plane);
|
||||
|
||||
// Step so Ymir reclaims old tombstone lane
|
||||
session.Step(new PlayerInput(0f, 0f, 0f, 0f, false, false, false));
|
||||
Assert.Equal(initialFreeSlots, session.World.FreeBodySlots);
|
||||
|
||||
// Now spawn Raptor (Coronal) beside player and swap
|
||||
session.State.SpawnChassisDrop(player.X + 1f, player.Z + 1f, Catalog.Raptor);
|
||||
Assert.True(session.TrySwapNearbyChassis());
|
||||
Assert.Equal("raptor", player.Grid.Spec.Id);
|
||||
Assert.Equal(GridPlane.Coronal, player.Grid.Spec.Plane);
|
||||
|
||||
session.Step(new PlayerInput(0f, 0f, 0f, 0f, false, false, false));
|
||||
Assert.Equal(initialFreeSlots, session.World.FreeBodySlots);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Raycast_RespectsStaticCoverWalls()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 12);
|
||||
// Cover block #0 sits at (28, 1.8, 16) with half-extents (4.5, 1.8, 1.4).
|
||||
// A ray from one side (28, 1.0, 10) to the other side (28, 1.0, 22) must hit the static cover wall!
|
||||
var blockedHit = session.World.CastRayClosest((28f, 1.0f, 10f), (0f, 0f, 15f));
|
||||
Assert.True(blockedHit.Hit);
|
||||
Assert.True(blockedHit.Point.Z < 16f, $"Expected cover hit before z=16, got z={blockedHit.Point.Z:F2}");
|
||||
Assert.InRange(blockedHit.StableId, 10UL, 99UL); // Static cover StableId range
|
||||
|
||||
// Ray high above the cover block (y = 5.0 > 3.6 top) passes unobstructed
|
||||
var clearHit = session.World.CastRayClosest((28f, 5.0f, 10f), (0f, 0f, 15f));
|
||||
Assert.False(clearHit.Hit);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue