Wire client VTOL/arc HUD & inputs and add Cut 3a tests

This commit is contained in:
Meta Vens 2026-12-04 19:11:33 +01:00
commit eb579a6ede
10 changed files with 552 additions and 86 deletions

View file

@ -540,22 +540,36 @@ public partial class ArenaRenderer : Node3D
switch (chassisId) switch (chassisId)
{ {
case "buggy": case "buggy":
case "jackal":
BuildBuggyParts(root, aimPivot, bodyMat, accentMat, darkMat, heatMat); BuildBuggyParts(root, aimPivot, bodyMat, accentMat, darkMat, heatMat);
break; break;
case "technical": case "technical":
case "mule":
BuildTechnicalParts(root, aimPivot, bodyMat, accentMat, darkMat, heatMat); BuildTechnicalParts(root, aimPivot, bodyMat, accentMat, darkMat, heatMat);
break; break;
case "tank": case "tank":
case "anvil":
case "ironclad":
case "ferret":
case "mammoth":
BuildTankParts(root, aimPivot, bodyMat, accentMat, darkMat, heatMat); BuildTankParts(root, aimPivot, bodyMat, accentMat, darkMat, heatMat);
break; break;
case "hornet":
case "condor":
BuildVtolParts(root, aimPivot, bodyMat, accentMat, darkMat, heatMat, isHeavy: chassisId == "condor");
break;
case "manticore": case "manticore":
case "bastion":
BuildManticoreParts(root, aimPivot, bodyMat, accentMat, darkMat, heatMat); BuildManticoreParts(root, aimPivot, bodyMat, accentMat, darkMat, heatMat);
break; break;
case "raptor": case "raptor":
case "spectre":
case "kestrel":
case "exemplar_frame": case "exemplar_frame":
BuildRaptorParts(root, aimPivot, bodyMat, accentMat, darkMat, heatMat, isExemplar: chassisId == "exemplar_frame"); BuildRaptorParts(root, aimPivot, bodyMat, accentMat, darkMat, heatMat, isExemplar: chassisId == "exemplar_frame");
break; break;
case "paladin": case "paladin":
case "breaker":
BuildPaladinParts(root, aimPivot, bodyMat, accentMat, darkMat, heatMat, isTourist: isSpectator && tier == SpectatorTier.Tourist); BuildPaladinParts(root, aimPivot, bodyMat, accentMat, darkMat, heatMat, isTourist: isSpectator && tier == SpectatorTier.Tourist);
break; break;
default: default:
@ -728,6 +742,18 @@ public partial class ArenaRenderer : Node3D
AddBox(aimPivot, new Vector3(0.45f, 0.48f, 2.0f), new Vector3( 1.45f, 0f, 0.65f), accentMat); AddBox(aimPivot, new Vector3(0.45f, 0.48f, 2.0f), new Vector3( 1.45f, 0f, 0.65f), accentMat);
} }
private static void BuildVtolParts(Node3D root, Node3D aimPivot, Material bodyMat, Material accentMat, Material darkMat, Material heatMat, bool isHeavy)
{
float s = isHeavy ? 1.3f : 1.0f;
AddBox(root, new Vector3(1.1f * s, 0.7f * s, 3.4f * s), Vector3.Zero, bodyMat);
AddBox(root, new Vector3(3.1f * s, 0.16f * s, 0.9f * s), new Vector3(0f, 0.15f * s, -0.2f * s), accentMat);
AddBox(root, new Vector3(0.65f * s, 0.35f * s, 0.9f * s), new Vector3(-1.35f * s, 0.25f * s, -0.15f * s), darkMat);
AddBox(root, new Vector3(0.65f * s, 0.35f * s, 0.9f * s), new Vector3( 1.35f * s, 0.25f * s, -0.15f * s), darkMat);
AddBox(root, new Vector3(0.6f * s, 0.32f * s, 0.6f * s), new Vector3(0f, 0.25f * s, -1.4f * s), heatMat);
aimPivot.Position = new Vector3(0f, -0.25f * s, 1.3f * s);
AddBox(aimPivot, new Vector3(0.32f * s, 0.24f * s, 0.9f * s), new Vector3(0f, 0f, 0.35f * s), accentMat);
}
private static void AddBox(Node3D parent, Vector3 size, Vector3 pos, Material mat) private static void AddBox(Node3D parent, Vector3 size, Vector3 pos, Material mat)
{ {
parent.AddChild(new MeshInstance3D parent.AddChild(new MeshInstance3D

View file

@ -176,7 +176,17 @@ public partial class Hud : CanvasLayer
{ {
if (state.Contenders[i].Alive) aliveCount++; if (state.Contenders[i].Alive) aliveCount++;
} }
_statsLabel.Text = $"SPD {player.Speed:F1} m/s | ALIVE {aliveCount} / {state.Contenders.Count} | KILLS {player.Kills}"; if (player.Grid.Spec.IsVtol)
{
float agl = MathF.Max(0f, player.Y - player.Grid.Spec.HalfHeight - state.Terrain.SampleHeight(player.X, player.Z));
_statsLabel.Text = $"SPD {player.Speed:F1} m/s | ALT {agl:F1}m | ALIVE {aliveCount} / {state.Contenders.Count} | KILLS {player.Kills}";
_controlsHint.Text = "WASD Fly | Space/C Climb/Descend | Mouse Aim | LMB Fire | E Bolt/Swap | Tab Garage";
}
else
{
_statsLabel.Text = $"SPD {player.Speed:F1} m/s | ALIVE {aliveCount} / {state.Contenders.Count} | KILLS {player.Kills}";
_controlsHint.Text = "WASD Drive | Mouse Aim | LMB Fire | E Bolt/Swap | Tab Garage | T Conduits | Wheel Zoom";
}
float distCenter = MathF.Sqrt(player.X * player.X + player.Z * player.Z); float distCenter = MathF.Sqrt(player.X * player.X + player.Z * player.Z);
float outside = distCenter - state.Spectators.SafeRadius; float outside = distCenter - state.Spectators.SafeRadius;
@ -553,7 +563,7 @@ public partial class Hud : CanvasLayer
private void SyncCargoButtons(ChassisGrid grid) private void SyncCargoButtons(ChassisGrid grid)
{ {
int hash = grid.Cargo.Count * 97 + (_selectedCargoIndex + 10); int hash = HashCode.Combine(grid.Cargo.Count, grid.Spec.CargoCapacity, _selectedCargoIndex);
for (int i = 0; i < grid.Cargo.Count; i++) for (int i = 0; i < grid.Cargo.Count; i++)
{ {
hash = HashCode.Combine(hash, grid.Cargo[i].Id); hash = HashCode.Combine(hash, grid.Cargo[i].Id);
@ -691,7 +701,10 @@ public partial class Hud : CanvasLayer
if (nearest is null) return ""; if (nearest is null) return "";
if (nearest.Module is { } mod) if (nearest.Module is { } mod)
{ {
return $"[E] Loot {(mod.IsImperial ? "IMPERIAL " : "")}{mod.Name}"; var freeHp = player.Grid.FindFirstEmptyCompatibleHardpoint(mod);
return freeHp is not null
? $"[E] Bolt {(mod.IsImperial ? "IMPERIAL " : "")}{mod.Name} -> {freeHp.Id}"
: $"[E] Loot {(mod.IsImperial ? "IMPERIAL " : "")}{mod.Name}";
} }
if (nearest.Chassis is { } ch) if (nearest.Chassis is { } ch)
{ {
@ -784,7 +797,10 @@ public partial class Hud : CanvasLayer
Vector2 center = Size * 0.5f; Vector2 center = Size * 0.5f;
float gap = 6f; float gap = 6f;
float tick = 10f; float tick = 10f;
Color retCol = new Color(TextLight.R, TextLight.G, TextLight.B, 0.88f); bool outOfArc = _player is not null && _player.Alive && _player.AllWeaponsOutOfArc;
Color retCol = outOfArc
? new Color(RedCol.R, RedCol.G, RedCol.B, 0.95f)
: new Color(TextLight.R, TextLight.G, TextLight.B, 0.88f);
// Clean 4-tick center crosshair + center pip // Clean 4-tick center crosshair + center pip
DrawCircle(center, 1.8f, retCol); DrawCircle(center, 1.8f, retCol);
@ -793,6 +809,18 @@ public partial class Hud : CanvasLayer
DrawLine(center + new Vector2(0f, -gap - tick), center + new Vector2(0f, -gap), retCol, 1.6f); DrawLine(center + new Vector2(0f, -gap - tick), center + new Vector2(0f, -gap), retCol, 1.6f);
DrawLine(center + new Vector2(0f, gap), center + new Vector2(0f, gap + tick), retCol, 1.6f); DrawLine(center + new Vector2(0f, gap), center + new Vector2(0f, gap + tick), retCol, 1.6f);
if (outOfArc)
{
DrawString(
ThemeDB.FallbackFont,
center + new Vector2(-34f, 36f),
"OUT OF ARC",
HorizontalAlignment.Left,
-1,
11,
RedCol);
}
if (_player is null || !_player.Alive) if (_player is null || !_player.Alive)
{ {
return; return;

View file

@ -108,8 +108,8 @@ public partial class Main : Node3D
_cameraYaw -= mm.Relative.X * 0.0028f; _cameraYaw -= mm.Relative.X * 0.0028f;
_cameraPitch = Math.Clamp( _cameraPitch = Math.Clamp(
_cameraPitch + mm.Relative.Y * 0.0024f, _cameraPitch + mm.Relative.Y * 0.0024f,
Mathf.DegToRad(-18f), Mathf.DegToRad(-78f),
Mathf.DegToRad(38f)); Mathf.DegToRad(45f));
return; return;
} }
@ -211,7 +211,12 @@ public partial class Main : Node3D
if (Input.IsKeyPressed(Key.D) || Input.IsKeyPressed(Key.Right)) steer += 1f; if (Input.IsKeyPressed(Key.D) || Input.IsKeyPressed(Key.Right)) steer += 1f;
if (Input.IsKeyPressed(Key.A) || Input.IsKeyPressed(Key.Left)) steer -= 1f; if (Input.IsKeyPressed(Key.A) || Input.IsKeyPressed(Key.Left)) steer -= 1f;
bool brake = Input.IsKeyPressed(Key.Space); bool isVtol = Session.State.Player.Grid.Spec.IsVtol;
float verticalThrottle = 0f;
if (Input.IsKeyPressed(Key.Space)) verticalThrottle += 1f;
if (Input.IsKeyPressed(Key.C) || Input.IsKeyPressed(Key.Ctrl)) verticalThrottle -= 1f;
bool brake = isVtol ? Input.IsKeyPressed(Key.Shift) : Input.IsKeyPressed(Key.Space);
bool pointerOnHud = Input.MouseMode != Input.MouseModeEnum.Captured && bool pointerOnHud = Input.MouseMode != Input.MouseModeEnum.Captured &&
_hud.IsPointerOverInteractiveHud(GetViewport().GetMousePosition()); _hud.IsPointerOverInteractiveHud(GetViewport().GetMousePosition());
bool fire = !pointerOnHud && Input.IsMouseButtonPressed(MouseButton.Left); bool fire = !pointerOnHud && Input.IsMouseButtonPressed(MouseButton.Left);
@ -225,7 +230,8 @@ public partial class Main : Node3D
Fire: fire, Fire: fire,
InteractPickup: _interactQueued, InteractPickup: _interactQueued,
Brake: brake, Brake: brake,
AimWorldY: aimY); AimWorldY: aimY,
VerticalThrottle: verticalThrottle);
} }
private (float AimX, float AimY, float AimZ) ComputeCenterScreenAim() private (float AimX, float AimY, float AimZ) ComputeCenterScreenAim()

View file

@ -220,15 +220,15 @@ public partial class Smoke : Node
} }
Check(chromeCount == 5, $"Expected 5 ChromePanel materials on HUD, got {chromeCount}"); Check(chromeCount == 5, $"Expected 5 ChromePanel materials on HUD, got {chromeCount}");
// Pack a real Tank chassis with mounted modules, thermal gradient, stripped cell, and active hit-pulse // Pack a real Ironclad chassis with mounted modules, thermal gradient, stripped cell, and active hit-pulse
var testGrid = new ChassisGrid(Catalog.Tank); var testGrid = new ChassisGrid(Catalog.Ironclad);
Check(testGrid.TryMount(Catalog.Recoilless, "wpn_turret"), "Expected Recoilless to mount on wpn_turret"); Check(testGrid.TryMount(Catalog.Recoilless, "hp.weapon.main"), "Expected Recoilless to mount on hp.weapon.main");
Check(testGrid.TryMount(Catalog.Mg762, "wpn_coax"), "Expected Mg762 to mount on wpn_coax"); Check(testGrid.TryMount(Catalog.Mg762, "hp.weapon.coax"), "Expected Mg762 to mount on hp.weapon.coax");
Check(testGrid.TryMount(Catalog.TurboCore, "eng_rear"), "Expected TurboCore to mount on eng_rear"); Check(testGrid.TryMount(Catalog.TurboCore, "hp.engine.rear"), "Expected TurboCore to mount on hp.engine.rear");
Check(testGrid.TryMount(Catalog.CopperRad, "rad_deck"), "Expected CopperRad to mount on rad_deck"); Check(testGrid.TryMount(Catalog.CopperRad, "hp.radiator.l"), "Expected CopperRad to mount on hp.radiator.l");
Check(testGrid.TryMount(Catalog.WeldedPlate, "arm_glacis"), "Expected WeldedPlate to mount on arm_glacis"); Check(testGrid.TryMount(Catalog.WeldedPlate, "hp.armor.front"), "Expected WeldedPlate to mount on hp.armor.front");
testGrid.InjectHardpointHeat("eng_rear", 1800f); testGrid.InjectHardpointHeat("hp.engine.rear", 1800f);
testGrid.InjectHardpointHeat("wpn_turret", 900f); testGrid.InjectHardpointHeat("hp.weapon.main", 900f);
testGrid.StepHeat(0.25f); testGrid.StepHeat(0.25f);
testGrid.Armor[0, 0] = 0f; // stripped armor cell testGrid.Armor[0, 0] = 0f; // stripped armor cell
@ -236,7 +236,7 @@ public partial class Smoke : Node
schematic.SetGrid(testGrid); schematic.SetGrid(testGrid);
schematic.TriggerHitPulse(1, 1, 1f); schematic.TriggerHitPulse(1, 1, 1f);
// Hit-testing verification: center of cell (1, 1) must map to (1, 1) and hardpoint "wpn_turret" // Hit-testing verification: center of cell (1, 1) must map to (1, 1) and hardpoint "hp.weapon.main"
schematic.ComputeCellLayout(out float cellSize, out Vector2 origin); schematic.ComputeCellLayout(out float cellSize, out Vector2 origin);
Check(cellSize > 10f, $"Expected InventoryGridControl cellSize > 10px, got {cellSize:F2}"); Check(cellSize > 10f, $"Expected InventoryGridControl cellSize > 10px, got {cellSize:F2}");
Vector2 probePos = origin + new Vector2(1.5f * cellSize, 1.5f * cellSize); Vector2 probePos = origin + new Vector2(1.5f * cellSize, 1.5f * cellSize);
@ -244,8 +244,8 @@ public partial class Smoke : Node
Check(hitCell && mappedCell == new Vector2I(1, 1), Check(hitCell && mappedCell == new Vector2I(1, 1),
$"Expected TryGetCellAt to map center of (1,1) to (1,1), got hit={hitCell} cell={mappedCell}"); $"Expected TryGetCellAt to map center of (1,1) to (1,1), got hit={hitCell} cell={mappedCell}");
var mappedHp = schematic.GetHardpointAt(1, 1); var mappedHp = schematic.GetHardpointAt(1, 1);
Check(mappedHp is { Id: "wpn_turret" }, Check(mappedHp is { Id: "hp.weapon.main" },
$"Expected GetHardpointAt(1,1) to return wpn_turret, got {mappedHp?.Id ?? "null"}"); $"Expected GetHardpointAt(1,1) to return hp.weapon.main, got {mappedHp?.Id ?? "null"}");
// Toggle thermal mode off -> on -> off // Toggle thermal mode off -> on -> off
_main.Hud.SetThermalMode(true, instant: true); _main.Hud.SetThermalMode(true, instant: true);
@ -257,8 +257,8 @@ public partial class Smoke : Node
// Regression check (Finding 3): same-dimension SwapChassis updates _hardpointLookup and clears hover state // Regression check (Finding 3): same-dimension SwapChassis updates _hardpointLookup and clears hover state
schematic._GuiInput(new InputEventMouseMotion { Position = probePos }); schematic._GuiInput(new InputEventMouseMotion { Position = probePos });
Check(schematic.HoveredCell == new Vector2I(1, 1) && schematic.HoveredHardpoint is { Id: "wpn_turret" }, Check(schematic.HoveredCell == new Vector2I(1, 1) && schematic.HoveredHardpoint is { Id: "hp.weapon.main" },
$"Expected hover on (1,1)/wpn_turret before SwapChassis, got cell={schematic.HoveredCell} hp={schematic.HoveredHardpoint?.Id ?? "null"}"); $"Expected hover on (1,1)/hp.weapon.main before SwapChassis, got cell={schematic.HoveredCell} hp={schematic.HoveredHardpoint?.Id ?? "null"}");
bool hoverResetEmitted = false; bool hoverResetEmitted = false;
void OnSwapHoverChanged(Vector2I? cell, HardpointSpec? hp) void OnSwapHoverChanged(Vector2I? cell, HardpointSpec? hp)
@ -269,9 +269,9 @@ public partial class Smoke : Node
} }
} }
schematic.HoverChanged += OnSwapHoverChanged; schematic.HoverChanged += OnSwapHoverChanged;
var altTankSpec = Catalog.Tank with var altTankSpec = Catalog.Ironclad with
{ {
Id = "tank_alt", Id = "ironclad_alt",
Hardpoints = new[] Hardpoints = new[]
{ {
new HardpointSpec("wpn_swapped", HardpointKind.Weapon, 1, 1, 2, 2, 18f) new HardpointSpec("wpn_swapped", HardpointKind.Weapon, 1, 1, 2, 2, 18f)
@ -284,19 +284,19 @@ public partial class Smoke : Node
Check(schematic.GetHardpointAt(1, 1) is { Id: "wpn_swapped" }, Check(schematic.GetHardpointAt(1, 1) is { Id: "wpn_swapped" },
$"Expected GetHardpointAt(1,1) to update to wpn_swapped after same-dimension SwapChassis, got {schematic.GetHardpointAt(1, 1)?.Id ?? "null"}"); $"Expected GetHardpointAt(1,1) to update to wpn_swapped after same-dimension SwapChassis, got {schematic.GetHardpointAt(1, 1)?.Id ?? "null"}");
Check(schematic.GetHardpointAt(0, 1) is null, Check(schematic.GetHardpointAt(0, 1) is null,
$"Expected old hardpoint wpn_coax at (0,1) to clear after SwapChassis, got {schematic.GetHardpointAt(0, 1)?.Id ?? "null"}"); $"Expected old hardpoint hp.weapon.coax at (0,1) to clear after SwapChassis, got {schematic.GetHardpointAt(0, 1)?.Id ?? "null"}");
Check(schematic.HoveredCell is null && schematic.HoveredHardpoint is null && hoverResetEmitted, Check(schematic.HoveredCell is null && schematic.HoveredHardpoint is null && hoverResetEmitted,
$"Expected SwapChassis to clear hover and emit HoverChanged(null, null), cell={schematic.HoveredCell} emitted={hoverResetEmitted}"); $"Expected SwapChassis to clear hover and emit HoverChanged(null, null), cell={schematic.HoveredCell} emitted={hoverResetEmitted}");
// Re-seed Tank grid for GPU tests below // Re-seed Ironclad grid for GPU tests below
testGrid = new ChassisGrid(Catalog.Tank); testGrid = new ChassisGrid(Catalog.Ironclad);
Check(testGrid.TryMount(Catalog.Recoilless, "wpn_turret"), "Expected Recoilless to remount on wpn_turret"); Check(testGrid.TryMount(Catalog.Recoilless, "hp.weapon.main"), "Expected Recoilless to remount on hp.weapon.main");
Check(testGrid.TryMount(Catalog.Mg762, "wpn_coax"), "Expected Mg762 to remount on wpn_coax"); Check(testGrid.TryMount(Catalog.Mg762, "hp.weapon.coax"), "Expected Mg762 to remount on hp.weapon.coax");
Check(testGrid.TryMount(Catalog.TurboCore, "eng_rear"), "Expected TurboCore to remount on eng_rear"); Check(testGrid.TryMount(Catalog.TurboCore, "hp.engine.rear"), "Expected TurboCore to remount on hp.engine.rear");
Check(testGrid.TryMount(Catalog.CopperRad, "rad_deck"), "Expected CopperRad to remount on rad_deck"); Check(testGrid.TryMount(Catalog.CopperRad, "hp.radiator.l"), "Expected CopperRad to remount on hp.radiator.l");
Check(testGrid.TryMount(Catalog.WeldedPlate, "arm_glacis"), "Expected WeldedPlate to remount on arm_glacis"); Check(testGrid.TryMount(Catalog.WeldedPlate, "hp.armor.front"), "Expected WeldedPlate to remount on hp.armor.front");
testGrid.InjectHardpointHeat("eng_rear", 1800f); testGrid.InjectHardpointHeat("hp.engine.rear", 1800f);
testGrid.InjectHardpointHeat("wpn_turret", 900f); testGrid.InjectHardpointHeat("hp.weapon.main", 900f);
testGrid.StepHeat(0.25f); testGrid.StepHeat(0.25f);
testGrid.Armor[0, 0] = 0f; testGrid.Armor[0, 0] = 0f;
@ -354,8 +354,8 @@ public partial class Smoke : Node
Check(modeDiff > 500, $"Expected thermal conduit toggle to visibly change > 500 pixels, got {modeDiff}"); Check(modeDiff > 500, $"Expected thermal conduit toggle to visibly change > 500 pixels, got {modeDiff}");
// Finding 2 GPU check: overheated (350C+, thermal_mode = 1.0f) must obey blend_premul_alpha (out_rgb <= out_a) // Finding 2 GPU check: overheated (350C+, thermal_mode = 1.0f) must obey blend_premul_alpha (out_rgb <= out_a)
testGrid.InjectHardpointHeat("eng_rear", 45000f); testGrid.InjectHardpointHeat("hp.engine.rear", 45000f);
testGrid.InjectHardpointHeat("wpn_turret", 25000f); testGrid.InjectHardpointHeat("hp.weapon.main", 25000f);
testGrid.StepHeat(0.05f); testGrid.StepHeat(0.05f);
float hotTemp = testGrid.Temperature[1, 3]; float hotTemp = testGrid.Temperature[1, 3];
Check(hotTemp >= 350f, $"Expected overheated cell >= 350C for premul test, got {hotTemp:F1}C"); Check(hotTemp >= 350f, $"Expected overheated cell >= 350C for premul test, got {hotTemp:F1}C");
@ -371,12 +371,12 @@ public partial class Smoke : Node
// Finding 1 GPU check: asymmetric Raptor chassis with thermal_mode = 1.0f must leave 0 lit pixels in inactive cell holes // Finding 1 GPU check: asymmetric Raptor chassis with thermal_mode = 1.0f must leave 0 lit pixels in inactive cell holes
var raptorGrid = new ChassisGrid(Catalog.Raptor); var raptorGrid = new ChassisGrid(Catalog.Raptor);
Check(raptorGrid.TryMount(Catalog.CopperRad, "rad_lsh"), "Expected CopperRad on Raptor rad_lsh"); Check(raptorGrid.TryMount(Catalog.CopperRad, "hp.radiator.sh_l"), "Expected CopperRad on Raptor hp.radiator.sh_l");
Check(raptorGrid.TryMount(Catalog.CopperRad, "rad_rsh"), "Expected CopperRad on Raptor rad_rsh"); Check(raptorGrid.TryMount(Catalog.CopperRad, "hp.radiator.sh_r"), "Expected CopperRad on Raptor hp.radiator.sh_r");
Check(raptorGrid.TryMount(Catalog.Autocannon, "wpn_larm"), "Expected Autocannon on Raptor wpn_larm"); Check(raptorGrid.TryMount(Catalog.Autocannon, "hp.weapon.arm_l"), "Expected Autocannon on Raptor hp.weapon.arm_l");
Check(raptorGrid.TryMount(Catalog.TurboCore, "eng_chest"), "Expected TurboCore on Raptor eng_chest"); Check(raptorGrid.TryMount(Catalog.TurboCore, "hp.engine.chest"), "Expected TurboCore on Raptor hp.engine.chest");
Check(raptorGrid.TryMount(Catalog.Autocannon, "wpn_rarm"), "Expected Autocannon on Raptor wpn_rarm"); Check(raptorGrid.TryMount(Catalog.Autocannon, "hp.weapon.arm_r"), "Expected Autocannon on Raptor hp.weapon.arm_r");
raptorGrid.InjectHardpointHeat("eng_chest", 1800f); raptorGrid.InjectHardpointHeat("hp.engine.chest", 1800f);
raptorGrid.StepHeat(0.25f); raptorGrid.StepHeat(0.25f);
vpGrid.SetGrid(raptorGrid); vpGrid.SetGrid(raptorGrid);
@ -478,8 +478,8 @@ public partial class Smoke : Node
var grid = _main.Session.State.Player.Grid; var grid = _main.Session.State.Player.Grid;
grid.TryAddCargo(Catalog.TouringPlasma); grid.TryAddCargo(Catalog.TouringPlasma);
grid.TryAddCargo(Catalog.GoldRadiator); grid.TryAddCargo(Catalog.GoldRadiator);
grid.InjectHardpointHeat("eng_mid", 1100f); grid.InjectHardpointHeat("hp.engine.rear", 1100f);
grid.InjectHardpointHeat("wpn_roof", 750f); grid.InjectHardpointHeat("hp.weapon.roof", 750f);
grid.StepHeat(0.15f); grid.StepHeat(0.15f);
grid.Armor[0, 0] = 0f; grid.Armor[0, 0] = 0f;
_main.Hud.Sync(_main.Session); _main.Hud.Sync(_main.Session);
@ -499,15 +499,15 @@ public partial class Smoke : Node
{ {
var grid = _main.Session.State.Player.Grid; var grid = _main.Session.State.Player.Grid;
grid.SwapChassis(Catalog.Paladin); grid.SwapChassis(Catalog.Paladin);
Check(grid.TryMount(Catalog.TouringPlasma, "wpn_lsh"), "Expected TouringPlasma on Paladin wpn_lsh"); Check(grid.TryMount(Catalog.TouringPlasma, "hp.weapon.sh_l"), "Expected TouringPlasma on Paladin hp.weapon.sh_l");
Check(grid.TryMount(Catalog.WeldedPlate, "arm_collar"), "Expected WeldedPlate on Paladin arm_collar"); Check(grid.TryMount(Catalog.WeldedPlate, "hp.armor.torso"), "Expected WeldedPlate on Paladin hp.armor.torso");
Check(grid.TryMount(Catalog.TouringPlasma, "wpn_rsh"), "Expected TouringPlasma on Paladin wpn_rsh"); Check(grid.TryMount(Catalog.TouringPlasma, "hp.weapon.sh_r"), "Expected TouringPlasma on Paladin hp.weapon.sh_r");
Check(grid.TryMount(Catalog.GildedLance, "wpn_larm"), "Expected GildedLance on Paladin wpn_larm"); Check(grid.TryMount(Catalog.GildedLance, "hp.weapon.arm_l"), "Expected GildedLance on Paladin hp.weapon.arm_l");
Check(grid.TryMount(Catalog.NobleCore, "eng_core"), "Expected NobleCore on Paladin eng_core"); Check(grid.TryMount(Catalog.NobleCore, "hp.engine.chest"), "Expected NobleCore on Paladin hp.engine.chest");
Check(grid.TryMount(Catalog.GildedLance, "wpn_rarm"), "Expected GildedLance on Paladin wpn_rarm"); Check(grid.TryMount(Catalog.GildedLance, "hp.weapon.arm_r"), "Expected GildedLance on Paladin hp.weapon.arm_r");
Check(grid.TryMount(Catalog.GoldRadiator, "rad_l"), "Expected GoldRadiator on Paladin rad_l"); Check(grid.TryMount(Catalog.GoldRadiator, "hp.radiator.back_l"), "Expected GoldRadiator on Paladin hp.radiator.back_l");
Check(grid.TryMount(Catalog.WeldedPlate, "arm_waist"), "Expected WeldedPlate on Paladin arm_waist"); Check(grid.TryMount(Catalog.WeldedPlate, "hp.armor.legs"), "Expected WeldedPlate on Paladin hp.armor.legs");
Check(grid.TryMount(Catalog.GoldRadiator, "rad_r"), "Expected GoldRadiator on Paladin rad_r"); Check(grid.TryMount(Catalog.GoldRadiator, "hp.radiator.back_r"), "Expected GoldRadiator on Paladin hp.radiator.back_r");
grid.Cargo.Clear(); grid.Cargo.Clear();
var cargoSpecs = new[] var cargoSpecs = new[]

View file

@ -42,7 +42,7 @@ namespace RustToDust.Tests
Assert.True(displacement > 10f, $"Expected >10m displacement, got {displacement:F2}m"); 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"); Assert.True(yawDelta > 0.2f, $"Expected yaw change >0.2 rad, got {yawDelta:F2} rad");
var weapon = player.Grid.GetMountedOn("wpn_roof"); var weapon = player.Grid.GetMountedOn("hp.weapon.roof");
Assert.NotNull(weapon); Assert.NotNull(weapon);
Assert.True(weapon!.CurrentTemp > ChassisGrid.AmbientTemp + 5f); Assert.True(weapon!.CurrentTemp > ChassisGrid.AmbientTemp + 5f);
Assert.True(tracerTicks > 0); Assert.True(tracerTicks > 0);
@ -103,10 +103,10 @@ namespace RustToDust.Tests
using var session = new ArenaSession(seed: 19); using var session = new ArenaSession(seed: 19);
var player = session.State.Player; var player = session.State.Player;
// Swap to Tank (HalfWidth = 1.65m, HalfLength = 2.65m) where broadside vs forward differs by 1.0m. // Swap to Tank / Anvil (HalfWidth = 1.93m, HalfLength = 2.83m) where broadside vs forward differs by ~0.9m.
session.State.SpawnChassisDrop(player.X + 0.5f, player.Z + 0.5f, Catalog.Tank); session.State.SpawnChassisDrop(player.X + 0.5f, player.Z + 0.5f, Catalog.Tank);
Assert.True(session.TrySwapNearbyChassis()); Assert.True(session.TrySwapNearbyChassis());
Assert.Equal("tank", player.Grid.Spec.Id); Assert.Equal(Catalog.Tank.Id, player.Grid.Spec.Id);
// Step once to settle body, then aim strictly perpendicular (broadside) to player's Yaw. // 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)); session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, false));

View file

@ -131,6 +131,14 @@ namespace RustToDust.Tests
var player = session.State.Player; var player = session.State.Player;
var rival = session.State.Contenders[1]; var rival = session.State.Contenders[1];
// Ensure rival is a low-profile ground vehicle shorter than the 4m ruin cover wall
if (rival.Grid.Spec.IsVtol || rival.Grid.Spec.HalfHeight * 2f >= box.HalfY * 2f)
{
session.SetContenderPose(rival.Id, box.X, box.Z + box.HalfZ + 4f);
session.State.SpawnChassisDrop(box.X, box.Z + box.HalfZ + 4f, Catalog.Jackal);
Assert.True(session.State.TrySwapNearbyChassis(rival.Id));
}
session.SetContenderPose(player.Id, box.X, box.Z - box.HalfZ - 4f); session.SetContenderPose(player.Id, box.X, box.Z - box.HalfZ - 4f);
session.SetContenderPose(rival.Id, box.X, box.Z + box.HalfZ + 4f); session.SetContenderPose(rival.Id, box.X, box.Z + box.HalfZ + 4f);
@ -227,7 +235,14 @@ namespace RustToDust.Tests
var provokedSpec = tourists[0]; var provokedSpec = tourists[0];
var clearedSpec = tourists[1]; var clearedSpec = tourists[1];
// Keep AI contenders safely inside the safe circle and other spectators far away so they don't kill player or steal clearance // Place player on the side of the mesa further from center (strictly outside SafeRadius)
float xNeg = mesa.X - mesa.RadiusX - 18f;
float xPos = mesa.X + mesa.RadiusX + 18f;
bool negIsFurther = (xNeg * xNeg + mesa.Z * mesa.Z) >= (xPos * xPos + mesa.Z * mesa.Z);
float occludedX = negIsFurther ? xNeg : xPos;
float specSideX = negIsFurther ? (mesa.X + mesa.RadiusX + 45f) : (mesa.X - mesa.RadiusX - 45f);
// Keep AI contenders safely inside the safe circle and other spectators behind the mesa shadow so they don't peek around the flank
for (int i = 1; i < session.State.Contenders.Count; i++) for (int i = 1; i < session.State.Contenders.Count; i++)
{ {
session.SetContenderPose(session.State.Contenders[i].Id, (i - 6) * 12f, 0f); session.SetContenderPose(session.State.Contenders[i].Id, (i - 6) * 12f, 0f);
@ -237,17 +252,12 @@ namespace RustToDust.Tests
var other = session.State.Spectators.Spectators[i]; var other = session.State.Spectators.Spectators[i];
if (other.Id != provokedSpec.Id && other.Id != clearedSpec.Id) if (other.Id != provokedSpec.Id && other.Id != clearedSpec.Id)
{ {
session.SetSpectatorPose(other.Id, -mesa.X, -mesa.Z); float farX = (mesa.X >= 0f ? -1f : 1f) * 680f;
float farZ = (mesa.Z >= 0f ? -1f : 1f) * 680f;
session.SetSpectatorPose(other.Id, farX, farZ);
} }
} }
// Place player on the side of the mesa further from center (strictly outside SafeRadius)
float xNeg = mesa.X - mesa.RadiusX - 18f;
float xPos = mesa.X + mesa.RadiusX + 18f;
bool negIsFurther = (xNeg * xNeg + mesa.Z * mesa.Z) >= (xPos * xPos + mesa.Z * mesa.Z);
float occludedX = negIsFurther ? xNeg : xPos;
float specSideX = negIsFurther ? (mesa.X + mesa.RadiusX + 45f) : (mesa.X - mesa.RadiusX - 45f);
// Briefly establish visual contact for provokedSpec at initial spot, then move player behind the mesa // Briefly establish visual contact for provokedSpec at initial spot, then move player behind the mesa
session.SetContenderPose(player.Id, specSideX - (negIsFurther ? 12f : -12f), mesa.Z); session.SetContenderPose(player.Id, specSideX - (negIsFurther ? 12f : -12f), mesa.Z);
session.SetSpectatorPose(provokedSpec.Id, specSideX, mesa.Z); session.SetSpectatorPose(provokedSpec.Id, specSideX, mesa.Z);

View file

@ -10,12 +10,12 @@ namespace RustToDust.Tests
public void Conduction_SpreadsHeatFromHotHardpointToNeighbors() public void Conduction_SpreadsHeatFromHotHardpointToNeighbors()
{ {
var grid = Catalog.CreateStarterBuggy(); var grid = Catalog.CreateStarterBuggy();
// wpn_roof is at (1, 0). Neighbor (0, 0) and (1, 1) start at ambient 20f. // hp.weapon.roof is at (1, 0) 1x2. Neighbors (0, 0) and (1, 2) start at ambient 20f.
grid.InjectHardpointHeat("wpn_roof", 600f); grid.InjectHardpointHeat("hp.weapon.roof", 600f);
float hotBefore = grid.Temperature[1, 0]; float hotBefore = grid.Temperature[1, 0];
Assert.True(hotBefore > ChassisGrid.AmbientTemp + 20f); Assert.True(hotBefore > ChassisGrid.AmbientTemp + 20f);
Assert.Equal(ChassisGrid.AmbientTemp, grid.Temperature[0, 0]); Assert.Equal(ChassisGrid.AmbientTemp, grid.Temperature[0, 0]);
Assert.Equal(ChassisGrid.AmbientTemp, grid.Temperature[1, 1]); Assert.Equal(ChassisGrid.AmbientTemp, grid.Temperature[1, 2]);
for (int i = 0; i < 30; i++) for (int i = 0; i < 30; i++)
{ {
@ -23,7 +23,7 @@ namespace RustToDust.Tests
} }
Assert.True(grid.Temperature[0, 0] > ChassisGrid.AmbientTemp + 1f); Assert.True(grid.Temperature[0, 0] > ChassisGrid.AmbientTemp + 1f);
Assert.True(grid.Temperature[1, 1] > ChassisGrid.AmbientTemp + 1f); Assert.True(grid.Temperature[1, 2] > ChassisGrid.AmbientTemp + 1f);
Assert.True(grid.Temperature[1, 0] < hotBefore); Assert.True(grid.Temperature[1, 0] < hotBefore);
} }
@ -99,29 +99,31 @@ namespace RustToDust.Tests
[Fact] [Fact]
public void LooseFitAndSwapChassis_PreservesCompatibleGearAndStowsOverflow() public void LooseFitAndSwapChassis_PreservesCompatibleGearAndStowsOverflow()
{ {
// Tank has 2x2 turret hardpoint: smaller 1x1 weapon fits loosely; 2x2 weapon must NOT fit 1x1 buggy roof. // Ironclad has 2x2 main turret hardpoint: smaller 1x1 weapon fits loosely; 2x2 weapon must NOT fit 1x2 Jackal roof.
var tankGrid = new ChassisGrid(Catalog.Tank); var tankGrid = new ChassisGrid(Catalog.Ironclad);
Assert.True(tankGrid.TryMount(Catalog.Recoilless, "wpn_turret")); // 2x2 into 2x2 Assert.True(tankGrid.TryMount(Catalog.Recoilless, "hp.weapon.main")); // 2x2 into 2x2
Assert.True(tankGrid.TryMount(Catalog.Mg762, "wpn_coax")); // 1x1 into 1x1 Assert.True(tankGrid.TryMount(Catalog.Mg762, "hp.weapon.coax")); // 1x1 into 1x1
Assert.True(tankGrid.TryMount(Catalog.TurboCore, "eng_rear")); // 1x2 into 2x2 Assert.True(tankGrid.TryMount(Catalog.TurboCore, "hp.engine.rear")); // 1x2 into 2x2
Assert.True(tankGrid.TryMount(Catalog.GoldRadiator, "rad_deck")); // 1x1 into 1x1 Assert.True(tankGrid.TryMount(Catalog.GoldRadiator, "hp.radiator.l")); // 1x1 into 1x2
Assert.True(tankGrid.TryMount(Catalog.WeldedPlate, "arm_glacis")); // 1x1 into 2x1 Assert.True(tankGrid.TryMount(Catalog.WeldedPlate, "hp.armor.front")); // 1x1 into 4x1
Assert.True(tankGrid.TryMount(Catalog.GildedPlate, "arm_skirt")); // 1x1 into 1x1 Assert.True(tankGrid.TryMount(Catalog.GildedPlate, "hp.armor.skirts")); // 1x1 into 1x2
// Fill cargo near buggy capacity (4) so swapping down to Buggy overflows to ground! // Fill cargo so swapping down to Jackal (capacity 4) overflows 2 items to ground!
Assert.True(tankGrid.TryAddCargo(Catalog.Flak)); Assert.True(tankGrid.TryAddCargo(Catalog.Flak));
Assert.True(tankGrid.TryAddCargo(Catalog.CopperRad)); Assert.True(tankGrid.TryAddCargo(Catalog.CopperRad));
Assert.True(tankGrid.TryAddCargo(Catalog.DieselCore));
List<ModuleSpec> dropped = tankGrid.SwapChassis(Catalog.Buggy); List<ModuleSpec> dropped = tankGrid.SwapChassis(Catalog.Jackal);
// Buggy has 1x1 Weapon (mg_762 fits, recoilless 2x2 does not!), 1x1 Engine (turbo_core 1x2 does not fit!), 1x1 Radiator (gold_radiator fits!), 0 Armor hardpoints. // Jackal has 1x2 Weapon (mg_762 fits, recoilless 2x2 does not!), 1x2 Engine (turbo_core fits), 1x1 Radiator (gold_radiator fits), 0 Armor hardpoints.
Assert.Equal("buggy", tankGrid.Spec.Id); Assert.Equal("jackal", tankGrid.Spec.Id);
Assert.Contains(tankGrid.Mounted, m => m.Spec.Id == "mg_762"); Assert.Contains(tankGrid.Mounted, m => m.Spec.Id == "mg_762");
Assert.Contains(tankGrid.Mounted, m => m.Spec.Id == "turbo_core");
Assert.Contains(tankGrid.Mounted, m => m.Spec.Id == "gold_radiator"); Assert.Contains(tankGrid.Mounted, m => m.Spec.Id == "gold_radiator");
Assert.DoesNotContain(tankGrid.Mounted, m => m.Spec.Id == "recoilless"); Assert.DoesNotContain(tankGrid.Mounted, m => m.Spec.Id == "recoilless");
// 6 mounted on Tank: 2 transferred (mg_762, gold_radiator), 4 leftover + 2 cargo = 6 items -> 4 in Buggy Cargo, 2 dropped! // 6 mounted on Ironclad: 3 transferred, 3 leftover + 3 cargo = 6 items -> 4 in Jackal Cargo, 2 dropped!
Assert.Equal(Catalog.Buggy.CargoCapacity, tankGrid.Cargo.Count); Assert.Equal(Catalog.Jackal.CargoCapacity, tankGrid.Cargo.Count);
Assert.Equal(2, dropped.Count); Assert.Equal(2, dropped.Count);
} }
} }

View file

@ -382,13 +382,15 @@ namespace RustToDust.Tests
float climbProgress = maxGroundY - startGroundY; float climbProgress = maxGroundY - startGroundY;
float minRequiredClimb = testDune ? 4.0f : 2.0f; float minRequiredClimb = testDune ? 4.0f : 2.0f;
float minAllowedUpDot = chassis.IsWalker ? 0.927f : 0.50f; float minAllowedUpDot = chassis.IsWalker ? 0.927f : 0.50f;
// VTOLs naturally hover at ~3m AGL and briefly exceed 5m AGL when crossing sharp dune crests at speed
float maxAllowedAirGap = chassis.IsVtol ? 10.5f : 5.0f;
Assert.True(climbProgress >= minRequiredClimb, Assert.True(climbProgress >= minRequiredClimb,
$"Insufficient uphill climb progress (seed={seed}, chassis={chassis.Id}, dune={testDune}): climb={climbProgress:F2}m start=({startX:F1},{startZ:F1},h={startGroundY:F2}) end=({player.X:F1},{player.Z:F1},maxH={maxGroundY:F2}) brush=({targetBrush.X:F1},{targetBrush.Z:F1},rx={targetBrush.RadiusX:F1},rz={targetBrush.RadiusZ:F1},rot={targetBrush.RotationRad:F2},dh={targetBrush.HeightDelta:F1})"); $"Insufficient uphill climb progress (seed={seed}, chassis={chassis.Id}, dune={testDune}): climb={climbProgress:F2}m start=({startX:F1},{startZ:F1},h={startGroundY:F2}) end=({player.X:F1},{player.Z:F1},maxH={maxGroundY:F2}) brush=({targetBrush.X:F1},{targetBrush.Z:F1},rx={targetBrush.RadiusX:F1},rz={targetBrush.RadiusZ:F1},rot={targetBrush.RotationRad:F2},dh={targetBrush.HeightDelta:F1})");
Assert.True(minBottomRel >= -0.35f, Assert.True(minBottomRel >= -0.35f,
$"Terrain tunneling detected (seed={seed}, chassis={chassis.Id}, dune={testDune}): minBottomRel={minBottomRel:F2}m"); $"Terrain tunneling detected (seed={seed}, chassis={chassis.Id}, dune={testDune}): minBottomRel={minBottomRel:F2}m");
Assert.True(maxAirGap <= 5.0f, Assert.True(maxAirGap <= maxAllowedAirGap,
$"Excessive sky launch detected (seed={seed}, chassis={chassis.Id}, dune={testDune}): maxAirGap={maxAirGap:F2}m"); $"Excessive sky launch detected (seed={seed}, chassis={chassis.Id}, dune={testDune}): maxAirGap={maxAirGap:F2}m (max={maxAllowedAirGap:F1}m)");
Assert.True(minUpDot >= minAllowedUpDot, Assert.True(minUpDot >= minAllowedUpDot,
$"Excessive chassis tilt (seed={seed}, chassis={chassis.Id}, dune={testDune}): minUpDot={minUpDot:F3} (req>={minAllowedUpDot:F3})"); $"Excessive chassis tilt (seed={seed}, chassis={chassis.Id}, dune={testDune}): minUpDot={minUpDot:F3} (req>={minAllowedUpDot:F3})");
} }

View file

@ -0,0 +1,134 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
using RustToDust.Core;
using Xunit;
namespace RustToDust.Tests
{
public sealed class VehiclePackageTests
{
private static readonly string[] Expected15Ids =
{
"jackal", "mule", "ferret", "hornet", "mammoth",
"ironclad", "anvil", "condor", "breaker", "paladin",
"raptor", "manticore", "bastion", "spectre", "kestrel"
};
[Fact]
public void All15VehicleArchives_LoadFromCultCacheAndMatchManifests()
{
Assert.Equal(15, Catalog.AllChassis.Count);
Assert.Equal(15, Catalog.PackagesById.Count);
string vehiclesRoot = VehicleCatalogLoader.LocateVehiclesDirectory();
foreach (string id in Expected15Ids)
{
string ccPath = Path.Combine(vehiclesRoot, id, "vehicle.cc");
string manifestPath = Path.Combine(vehiclesRoot, id, "manifest.json");
Assert.True(File.Exists(ccPath), $"Missing vehicle.cc for {id}");
Assert.True(File.Exists(manifestPath), $"Missing manifest.json for {id}");
VehiclePackage pkg = VehiclePackageStore.Read(ccPath);
Assert.Equal(id, pkg.Id);
Assert.True(File.Exists(Path.Combine(vehiclesRoot, id, pkg.ModelAsset)), $"Missing GLB {pkg.ModelAsset}");
using var doc = JsonDocument.Parse(File.ReadAllText(manifestPath));
var root = doc.RootElement;
Assert.Equal(root.GetProperty("gridWidth").GetInt32(), pkg.GridWidth);
Assert.Equal(root.GetProperty("gridHeight").GetInt32(), pkg.GridHeight);
var manifestHps = root.GetProperty("hardpoints").EnumerateArray().ToArray();
Assert.Equal(manifestHps.Length, pkg.Hardpoints.Count);
for (int i = 0; i < manifestHps.Length; i++)
{
string expectedId = manifestHps[i].GetProperty("id").GetString()!;
string expectedAnchor = manifestHps[i].GetProperty("modelNodeId").GetString()!;
Assert.Equal(expectedId, pkg.Hardpoints[i].Id);
Assert.Equal(expectedAnchor, pkg.Hardpoints[i].AnchorId);
}
var manifestJoints = root.GetProperty("joints").EnumerateArray().ToArray();
Assert.Equal(manifestJoints.Length, pkg.Joints.Count);
for (int i = 0; i < manifestJoints.Length; i++)
{
Assert.Equal(manifestJoints[i].GetProperty("id").GetString(), pkg.Joints[i].Id);
}
var boundsSize = root.GetProperty("bounds").GetProperty("size").EnumerateArray().Select(e => e.GetSingle()).ToArray();
Assert.Equal(boundsSize[0] * 0.5f, pkg.HalfWidth, precision: 3);
Assert.Equal(boundsSize[1] * 0.5f, pkg.HalfHeight, precision: 3);
Assert.Equal(boundsSize[2] * 0.5f, pkg.HalfLength, precision: 3);
Assert.NotEmpty(pkg.PartCells);
var spec = pkg.ToChassisSpec();
Assert.All(pkg.PartCells, pc =>
{
Assert.False(string.IsNullOrWhiteSpace(pc.NodeName));
Assert.True(spec.IsActive(pc.CellX, pc.CellY), $"{id}: PartCell '{pc.NodeName}' mapped to inactive ({pc.CellX},{pc.CellY})");
});
}
}
[Fact]
public void BreakerArchive_RoundTripsFullMechanismHierarchy()
{
string vehiclesRoot = VehicleCatalogLoader.LocateVehiclesDirectory();
string manifestPath = Path.Combine(vehiclesRoot, "breaker", "manifest.json");
using var doc = JsonDocument.Parse(File.ReadAllText(manifestPath));
var mechJson = doc.RootElement.GetProperty("mechanisms");
var breaker = Catalog.PackagesById["breaker"];
Assert.NotNull(breaker.Mechanisms);
Assert.Equal(mechJson.GetProperty("dofs").GetArrayLength(), breaker.Mechanisms!.Dofs.Count);
Assert.Equal(35, breaker.Mechanisms.Dofs.Count);
Assert.Equal(mechJson.GetProperty("rams").GetArrayLength(), breaker.Mechanisms.Rams.Count);
Assert.Equal(2, breaker.Mechanisms.Scissors.Count);
Assert.Equal(2, breaker.Mechanisms.Struts.Count);
Assert.Equal("LegL.Hip", breaker.Mechanisms.Dofs[0].Name);
Assert.Equal("LegL.Torque", breaker.Mechanisms.Scissors[0].Name);
Assert.Equal("LegL.Oleo", breaker.Mechanisms.Struts[0].Name);
Assert.Equal(0.2f, breaker.Mechanisms.Struts[0].Travel, precision: 4);
}
[Fact]
public void AliasesAndVtolBalance_MatchSpecification()
{
Assert.Same(Catalog.Jackal, Catalog.Buggy);
Assert.Same(Catalog.Mule, Catalog.Technical);
Assert.Same(Catalog.Anvil, Catalog.Tank);
// VTOL glass-cannon balance vs ground equivalents
Assert.Equal(MobilityKind.Vtol, Catalog.Hornet.Mobility);
Assert.Equal(MobilityKind.Vtol, Catalog.Condor.Mobility);
Assert.Equal(42f, Catalog.Hornet.HoverMaxAltitudeM);
Assert.Equal(36f, Catalog.Condor.HoverMaxAltitudeM);
Assert.Equal(0f, Catalog.Jackal.HoverMaxAltitudeM);
Assert.Equal(0f, Catalog.Anvil.HoverMaxAltitudeM);
Assert.True(Catalog.Hornet.BaseCellArmor < Catalog.Jackal.BaseCellArmor,
$"Hornet armor ({Catalog.Hornet.BaseCellArmor}) must be lighter than Jackal ({Catalog.Jackal.BaseCellArmor})");
Assert.True(Catalog.Hornet.BaseCellArmor < Catalog.Ferret.BaseCellArmor,
$"Hornet armor ({Catalog.Hornet.BaseCellArmor}) must be lighter than Ferret ({Catalog.Ferret.BaseCellArmor})");
Assert.True(Catalog.Condor.BaseCellArmor < Catalog.Ironclad.BaseCellArmor,
$"Condor armor ({Catalog.Condor.BaseCellArmor}) must be lighter than Ironclad ({Catalog.Ironclad.BaseCellArmor})");
Assert.True(Catalog.Condor.BaseCellArmor < Catalog.Anvil.BaseCellArmor,
$"Condor armor ({Catalog.Condor.BaseCellArmor}) must be lighter than Anvil ({Catalog.Anvil.BaseCellArmor})");
// All 14 non-starter chassis spawn as salvageable drops in MatchState
var state = new MatchState(seed: 42);
var droppedChassisIds = state.GroundDrops
.Where(d => d.Chassis is not null)
.Select(d => d.Chassis!.Id)
.ToHashSet(StringComparer.Ordinal);
foreach (string id in Expected15Ids.Where(x => x != "jackal"))
{
Assert.Contains(id, droppedChassisIds);
}
}
}
}

View file

@ -0,0 +1,258 @@
using System;
using System.Linq;
using RustToDust.Core;
using RustToDust.Ymir;
using Xunit;
namespace RustToDust.Tests
{
public sealed class VtolAndArcTests
{
private static void IsolateContenders(ArenaSession session, params int[] keepIds)
{
var keep = keepIds.ToHashSet();
for (int i = 0; i < session.State.Contenders.Count; i++)
{
var c = session.State.Contenders[i];
if (!keep.Contains(c.Id))
{
session.SetContenderPose(c.Id, -650f + i * 10f, -650f);
}
}
for (int i = 0; i < session.State.Spectators.Spectators.Count; i++)
{
var s = session.State.Spectators.Spectators[i];
session.SetSpectatorPose(s.Id, 650f, -650f + i * 4f);
}
}
[Fact]
public void Vtol_HornetAndCondor_ClimbHoverAndDescendViaVerticalThrottle()
{
foreach (var vtolSpec in new[] { Catalog.Hornet, Catalog.Condor })
{
using var session = new ArenaSession(seed: 42);
IsolateContenders(session, 0);
var player = session.State.Player;
session.SetContenderPose(player.Id, 0f, 0f, 0f);
session.State.SpawnChassisDrop(player.X, player.Z, vtolSpec);
Assert.True(session.TrySwapNearbyChassis());
Assert.Equal(vtolSpec.Id, player.Grid.Spec.Id);
Assert.True(player.Grid.Spec.IsVtol);
float gh0 = session.State.Terrain.SampleHeight(player.X, player.Z);
float initialAgl = player.Y - vtolSpec.HalfHeight - gh0;
// Climb with VerticalThrottle = +1 for 2.5s (150 ticks)
for (int t = 0; t < 150; t++)
{
session.Step(new PlayerInput(0.4f, 0.1f, player.X, player.Z + 30f, false, false, false, VerticalThrottle: 1f));
}
float ghClimbed = session.State.Terrain.SampleHeight(player.X, player.Z);
float climbedAgl = player.Y - vtolSpec.HalfHeight - ghClimbed;
Assert.True(climbedAgl > initialAgl + 12f,
$"{vtolSpec.Id}: expected climb > 12m, got initial={initialAgl:F2}m -> climbed={climbedAgl:F2}m");
Assert.True(climbedAgl <= vtolSpec.HoverMaxAltitudeM + 2.0f,
$"{vtolSpec.Id}: exceeded HoverMaxAltitudeM {vtolSpec.HoverMaxAltitudeM}m (got {climbedAgl:F2}m)");
// Hold hover with VerticalThrottle = 0 for 2.0s (120 ticks) -> settles to TargetHoverAltAgl and holds steady
for (int t = 0; t < 60; t++)
{
session.Step(new PlayerInput(0f, 0f, player.X, player.Z + 30f, false, false, false, VerticalThrottle: 0f));
}
float ghSettled = session.State.Terrain.SampleHeight(player.X, player.Z);
float settledAgl = player.Y - vtolSpec.HalfHeight - ghSettled;
for (int t = 0; t < 60; t++)
{
session.Step(new PlayerInput(0f, 0f, player.X, player.Z + 30f, false, false, false, VerticalThrottle: 0f));
}
float ghHeld = session.State.Terrain.SampleHeight(player.X, player.Z);
float heldAgl = player.Y - vtolSpec.HalfHeight - ghHeld;
Assert.InRange(heldAgl, player.TargetHoverAltAgl - 1.5f, player.TargetHoverAltAgl + 1.5f);
Assert.InRange(heldAgl, settledAgl - 1.0f, settledAgl + 1.0f);
// Descend with VerticalThrottle = -1 for 3s (180 ticks) - should settle smoothly near 2.5m clearance
for (int t = 0; t < 180; t++)
{
session.Step(new PlayerInput(0f, 0f, player.X, player.Z + 30f, false, false, false, VerticalThrottle: -1f));
}
float ghDesc = session.State.Terrain.SampleHeight(player.X, player.Z);
float descAgl = player.Y - vtolSpec.HalfHeight - ghDesc;
Assert.True(descAgl < heldAgl - 8f, $"{vtolSpec.Id}: expected descent from {heldAgl:F2}m, got {descAgl:F2}m");
Assert.InRange(descAgl, 1.5f, 4.5f);
}
}
[Fact]
public void MwllTriangle_ZenithBlindSpot_MainCannonBlocked_WideArcPdAndDistantGroundRigHit()
{
using var session = new ArenaSession(seed: 42);
var player = session.State.Player;
var overheadVtol = session.State.Contenders[1];
var distantGroundRig = session.State.Contenders[2];
IsolateContenders(session, player.Id, overheadVtol.Id);
// Swap player to Anvil (heavy tracked tank, weapons capped at +30 deg pitch)
session.SetContenderPose(player.Id, 0f, 0f, 0f);
session.State.SpawnChassisDrop(0f, 0f, Catalog.Anvil);
Assert.True(session.TrySwapNearbyChassis());
Assert.Equal("anvil", player.Grid.Spec.Id);
// Swap contender 1 to Hornet and position it high overhead (~14m horizontal, ~38m above player => ~+69 deg pitch!)
session.SetContenderPose(overheadVtol.Id, 0f, 14f, 0f);
session.State.SpawnChassisDrop(0f, 14f, Catalog.Hornet);
Assert.True(session.State.TrySwapNearbyChassis(overheadVtol.Id));
Assert.Equal("hornet", overheadVtol.Grid.Spec.Id);
overheadVtol.AiScavengeCooldown = 999f;
overheadVtol.TargetHoverAltAgl = 38f;
session.SetContenderPose(overheadVtol.Id, 0f, 14f, 0f);
// Step once to seat bodies cleanly
session.Step(new PlayerInput(0f, 0f, overheadVtol.X, overheadVtol.Z, false, false, true, AimWorldY: overheadVtol.Y));
float vtolArmorBefore = overheadVtol.Grid.TotalArmorRatio();
// 1. Anvil's main cannons (-10..+30 deg) CANNOT fire at +69 deg overhead VTOL
for (int t = 0; t < 20; t++)
{
overheadVtol.TargetHoverAltAgl = 38f;
session.SetContenderPose(overheadVtol.Id, 0f, 14f, 0f);
session.Step(new PlayerInput(
0f, 0f,
overheadVtol.X, overheadVtol.Z,
Fire: true,
InteractPickup: false,
Brake: true,
AimWorldY: overheadVtol.Y));
}
Assert.True(player.AllWeaponsOutOfArc,
$"Expected Anvil main cannons to report AllWeaponsOutOfArc (in={player.InArcWeaponCount}, out={player.OutOfArcWeaponCount}, pY={player.Y:F1}, vY={overheadVtol.Y:F1}, vSpec={overheadVtol.Grid.Spec.Id}, vAlt={overheadVtol.TargetHoverAltAgl:F1}, vAlive={overheadVtol.Alive}, vPos=({overheadVtol.X:F1},{overheadVtol.Z:F1}))");
Assert.All(player.Grid.Mounted.Where(m => m.Spec.Kind == HardpointKind.Weapon), w => Assert.Equal(0f, w.Cooldown));
Assert.Equal(vtolArmorBefore, overheadVtol.Grid.TotalArmorRatio());
// 2. Mount a 1x1 Wide-Arc PointDefenseFlak (-10..+85 deg) onto Anvil's hp.weapon.sponson_r -> CAN hit overhead VTOL!
Assert.True(player.Grid.TryMount(Catalog.PointDefenseFlak, "hp.weapon.sponson_r"));
int pdTracers = 0;
for (int t = 0; t < 25; t++)
{
overheadVtol.TargetHoverAltAgl = 38f;
session.SetContenderPose(overheadVtol.Id, 0f, 14f, 0f);
session.Step(new PlayerInput(
0f, 0f,
overheadVtol.X, overheadVtol.Z,
Fire: true,
InteractPickup: false,
Brake: true,
AimWorldY: overheadVtol.Y));
pdTracers += session.State.Tracers.Count;
}
Assert.False(player.AllWeaponsOutOfArc, "Expected Wide-Arc PD module to clear overhead out-of-arc block");
Assert.True(pdTracers > 0, "Expected Wide-Arc PD to fire at overhead VTOL");
Assert.True(overheadVtol.Grid.TotalArmorRatio() < vtolArmorBefore,
"Expected Wide-Arc PD burst to damage overhead VTOL");
// 3. Second ground rig (Anvil, MaxPitchDeg = 30 deg) placed 140m away (~+15 deg pitch) CAN hit the overhead VTOL!
session.SetContenderPose(distantGroundRig.Id, 0f, 154f, MathF.PI);
session.State.SpawnChassisDrop(0f, 154f, Catalog.Anvil);
Assert.True(session.State.TrySwapNearbyChassis(distantGroundRig.Id));
session.SetContenderPose(distantGroundRig.Id, 0f, 154f, MathF.PI);
// Unmount player's PD so only distant rig shoots now
player.Grid.TryMount(Catalog.Mg762, "hp.weapon.sponson_r");
float vtolArmorBeforeDistant = overheadVtol.Grid.TotalArmorRatio();
for (int t = 0; t < 90; t++)
{
session.Step(new PlayerInput(0f, 0f, 0f, -20f, false, false, true));
}
Assert.True(overheadVtol.Grid.TotalArmorRatio() < vtolArmorBeforeDistant,
"Expected distant ground rig 140m away (~15 deg pitch) to hit the hovering Hornet inside its 30 deg cannon arc");
}
[Fact]
public void GroundRigWithWideArcPd_AutoTracksNearbyAirborneVtolWithoutManualFire()
{
using var session = new ArenaSession(seed: 42);
var player = session.State.Player;
var overheadVtol = session.State.Contenders[1];
IsolateContenders(session, player.Id, overheadVtol.Id);
// Swap player to Jackal, mount Wide-Arc PD, leave Fire = false and aim elsewhere!
session.SetContenderPose(player.Id, 0f, 0f, 0f);
Assert.True(player.Grid.TryMount(Catalog.PointDefenseFlak, "hp.weapon.roof"));
session.SetContenderPose(overheadVtol.Id, 20f, 25f, 0f);
session.State.SpawnChassisDrop(20f, 25f, Catalog.Hornet);
Assert.True(session.State.TrySwapNearbyChassis(overheadVtol.Id));
Assert.Equal("hornet", overheadVtol.Grid.Spec.Id);
overheadVtol.AiScavengeCooldown = 999f;
overheadVtol.TargetHoverAltAgl = 28f;
session.SetContenderPose(overheadVtol.Id, 20f, 25f, 0f);
float vtolArmorBefore = overheadVtol.Grid.TotalArmorRatio();
bool sawAutoTracer = false;
for (int t = 0; t < 45; t++)
{
overheadVtol.TargetHoverAltAgl = 28f;
session.SetContenderPose(overheadVtol.Id, 20f, 25f, 0f);
session.Step(new PlayerInput(
Throttle: 0f,
Steer: 0f,
AimWorldX: 0f,
AimWorldZ: -50f,
Fire: false,
InteractPickup: false,
Brake: true));
if (session.State.Tracers.Count > 0)
{
sawAutoTracer = true;
}
}
Assert.True(sawAutoTracer, "Expected auto-PD to fire tracers at airborne VTOL within 140m even while Fire=false");
Assert.True(overheadVtol.Grid.TotalArmorRatio() < vtolArmorBefore,
$"Expected auto-PD tracking to hit airborne VTOL (before={vtolArmorBefore:F3}, after={overheadVtol.Grid.TotalArmorRatio():F3}, vY={overheadVtol.Y:F1}, vSpec={overheadVtol.Grid.Spec.Id}, tracers={session.State.Tracers.Count}, lastTracer={(session.State.Tracers.Count > 0 ? $"{session.State.Tracers[^1].EndX:F1},{session.State.Tracers[^1].EndY:F1},{session.State.Tracers[^1].EndZ:F1}" : "none")})");
}
[Fact]
public void QuickBolt_MountsScavengedModuleIntoEmptyMatchingHardpointBeforeCargo()
{
var state = new MatchState(seed: 42);
var player = state.Player;
// Swap to Anvil (starter Jackal transfers 1 weapon into hp.weapon.sponson_l, leaving hp.weapon.siege_l, hp.weapon.siege_r, hp.weapon.sponson_r empty!)
state.SpawnChassisDrop(player.X, player.Z, Catalog.Anvil);
Assert.True(state.TrySwapNearbyChassis());
Assert.Null(player.Grid.GetMountedOn("hp.weapon.siege_l"));
int cargoBefore = player.Grid.Cargo.Count;
// Drop 1x1 PointDefenseFlak right at player and press [E]
state.SpawnModuleDrop(player.X + 0.5f, player.Z, Catalog.PointDefenseFlak);
MatchRules.ApplyPlayerInput(state, new PlayerInput(
0f, 0f, player.X, player.Z + 10f,
Fire: false,
InteractPickup: true,
Brake: false));
// Must bolt straight onto empty hp.weapon.siege_l, NOT Cargo!
var mountedSiege = player.Grid.GetMountedOn("hp.weapon.siege_l");
Assert.NotNull(mountedSiege);
Assert.Equal(Catalog.PointDefenseFlak.Id, mountedSiege!.Spec.Id);
Assert.Equal(cargoBefore, player.Grid.Cargo.Count);
Assert.Equal(BroadcastKind.QuickBolt, state.Broadcast.Latest?.Kind);
// Now fill remaining weapon slots; next weapon pickup must fall back to Cargo!
Assert.True(player.Grid.TryMount(Catalog.Autocannon, "hp.weapon.siege_r"));
Assert.True(player.Grid.TryMount(Catalog.Mg762, "hp.weapon.sponson_r"));
state.SpawnModuleDrop(player.X + 0.5f, player.Z, Catalog.Flak);
MatchRules.ApplyPlayerInput(state, new PlayerInput(
0f, 0f, player.X, player.Z + 10f,
Fire: false,
InteractPickup: true,
Brake: false));
Assert.Equal(cargoBefore + 1, player.Grid.Cargo.Count);
Assert.Equal(Catalog.Flak.Id, player.Grid.Cargo[^1].Id);
}
}
}