2026-12-04 13:47:43 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using RustToDust.Core;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace RustToDust.Tests
|
|
|
|
|
{
|
|
|
|
|
public sealed class GridHeatTests
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Conduction_SpreadsHeatFromHotHardpointToNeighbors()
|
|
|
|
|
{
|
|
|
|
|
var grid = Catalog.CreateStarterBuggy();
|
2026-12-04 19:11:33 +01:00
|
|
|
// hp.weapon.roof is at (1, 0) 1x2. Neighbors (0, 0) and (1, 2) start at ambient 20f.
|
|
|
|
|
grid.InjectHardpointHeat("hp.weapon.roof", 600f);
|
2026-12-04 13:47:43 +01:00
|
|
|
float hotBefore = grid.Temperature[1, 0];
|
|
|
|
|
Assert.True(hotBefore > ChassisGrid.AmbientTemp + 20f);
|
|
|
|
|
Assert.Equal(ChassisGrid.AmbientTemp, grid.Temperature[0, 0]);
|
2026-12-04 19:11:33 +01:00
|
|
|
Assert.Equal(ChassisGrid.AmbientTemp, grid.Temperature[1, 2]);
|
2026-12-04 13:47:43 +01:00
|
|
|
|
|
|
|
|
for (int i = 0; i < 30; i++)
|
|
|
|
|
{
|
|
|
|
|
grid.StepHeat(1f / 60f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Assert.True(grid.Temperature[0, 0] > ChassisGrid.AmbientTemp + 1f);
|
2026-12-04 19:11:33 +01:00
|
|
|
Assert.True(grid.Temperature[1, 2] > ChassisGrid.AmbientTemp + 1f);
|
2026-12-04 13:47:43 +01:00
|
|
|
Assert.True(grid.Temperature[1, 0] < hotBefore);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Radiation_CoolsBorderCellsWhileInteriorCellsDoNotRadiateDirectly()
|
|
|
|
|
{
|
|
|
|
|
var grid = new ChassisGrid(Catalog.Tank); // 4x5 full grid: interior cells exist at (1..2, 1..3)
|
|
|
|
|
for (int y = 0; y < grid.Spec.Height; y++)
|
|
|
|
|
{
|
|
|
|
|
for (int x = 0; x < grid.Spec.Width; x++)
|
|
|
|
|
{
|
|
|
|
|
grid.Temperature[x, y] = 120f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Single 60Hz substep: neighbors are all 120f so net conduction is 0.
|
|
|
|
|
// Only BorderCells lose heat to radiation; interior cell (1, 2) must stay at 120f.
|
|
|
|
|
grid.StepHeat(1f / 60f);
|
|
|
|
|
|
|
|
|
|
Assert.True(grid.BorderCells[0, 0]);
|
|
|
|
|
Assert.False(grid.BorderCells[1, 2]);
|
|
|
|
|
Assert.True(grid.Temperature[0, 0] < 120f);
|
|
|
|
|
Assert.Equal(120f, grid.Temperature[1, 2], precision: 5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ModulePerformance_MatchesTrapezoidalPlateauCurve()
|
|
|
|
|
{
|
|
|
|
|
var mod = Catalog.Mg762; // Min=0, Optimal=65, Plateau=70 => [30, 100], Max=155
|
|
|
|
|
|
|
|
|
|
Assert.Equal(0f, mod.Performance(-5f));
|
|
|
|
|
Assert.Equal(0f, mod.Performance(0f));
|
|
|
|
|
Assert.Equal(0.5f, mod.Performance(15f), precision: 4);
|
|
|
|
|
Assert.Equal(1f, mod.Performance(30f), precision: 4);
|
|
|
|
|
Assert.Equal(1f, mod.Performance(65f), precision: 4);
|
|
|
|
|
Assert.Equal(1f, mod.Performance(100f), precision: 4);
|
|
|
|
|
Assert.Equal(0.5f, mod.Performance(127.5f), precision: 4);
|
|
|
|
|
Assert.Equal(0f, mod.Performance(155f));
|
|
|
|
|
Assert.Equal(0f, mod.Performance(210f));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void DorsalHit_FrontStrikesFrontRowAndRearStrikesRearRow()
|
|
|
|
|
{
|
|
|
|
|
var grid = new ChassisGrid(Catalog.Tank);
|
|
|
|
|
|
|
|
|
|
var frontHit = grid.ApplyHit(localRight: 0f, localForward: 1f, localHeightNorm: 0.5f, damage: 15f, heatTransfer: 0f);
|
|
|
|
|
var rearHit = grid.ApplyHit(localRight: 0f, localForward: -1f, localHeightNorm: 0.5f, damage: 15f, heatTransfer: 0f);
|
|
|
|
|
var leftHit = grid.ApplyHit(localRight: -1f, localForward: 0f, localHeightNorm: 0.5f, damage: 15f, heatTransfer: 0f);
|
|
|
|
|
var rightHit = grid.ApplyHit(localRight: 1f, localForward: 0f, localHeightNorm: 0.5f, damage: 15f, heatTransfer: 0f);
|
|
|
|
|
|
|
|
|
|
Assert.Equal(0, frontHit.CellY);
|
|
|
|
|
Assert.Equal(grid.Spec.Height - 1, rearHit.CellY);
|
|
|
|
|
Assert.Equal(0, leftHit.CellX);
|
|
|
|
|
Assert.Equal(grid.Spec.Width - 1, rightHit.CellX);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void CoronalHit_HighVsLowElevationStrikesUpperVsLowerBipedCells()
|
|
|
|
|
{
|
|
|
|
|
var grid = new ChassisGrid(Catalog.Raptor);
|
|
|
|
|
float initialLegs = grid.LegIntegrity;
|
|
|
|
|
Assert.Equal(1f, initialLegs);
|
|
|
|
|
|
|
|
|
|
var highHit = grid.ApplyHit(localRight: 0f, localForward: 1f, localHeightNorm: 0.95f, damage: 20f, heatTransfer: 0f);
|
|
|
|
|
var lowHit = grid.ApplyHit(localRight: -0.4f, localForward: 1f, localHeightNorm: 0.05f, damage: 35f, heatTransfer: 0f);
|
|
|
|
|
|
|
|
|
|
Assert.True(highHit.CellY <= 1);
|
|
|
|
|
Assert.True(lowHit.CellY >= grid.Spec.Height - 2);
|
|
|
|
|
Assert.True(grid.LegIntegrity < initialLegs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void LooseFitAndSwapChassis_PreservesCompatibleGearAndStowsOverflow()
|
|
|
|
|
{
|
2026-12-04 19:11:33 +01:00
|
|
|
// Ironclad has 2x2 main turret hardpoint: smaller 1x1 weapon fits loosely; 2x2 weapon must NOT fit 1x2 Jackal roof.
|
|
|
|
|
var tankGrid = new ChassisGrid(Catalog.Ironclad);
|
|
|
|
|
Assert.True(tankGrid.TryMount(Catalog.Recoilless, "hp.weapon.main")); // 2x2 into 2x2
|
|
|
|
|
Assert.True(tankGrid.TryMount(Catalog.Mg762, "hp.weapon.coax")); // 1x1 into 1x1
|
|
|
|
|
Assert.True(tankGrid.TryMount(Catalog.TurboCore, "hp.engine.rear")); // 1x2 into 2x2
|
|
|
|
|
Assert.True(tankGrid.TryMount(Catalog.GoldRadiator, "hp.radiator.l")); // 1x1 into 1x2
|
|
|
|
|
Assert.True(tankGrid.TryMount(Catalog.WeldedPlate, "hp.armor.front")); // 1x1 into 4x1
|
|
|
|
|
Assert.True(tankGrid.TryMount(Catalog.GildedPlate, "hp.armor.skirts")); // 1x1 into 1x2
|
|
|
|
|
|
|
|
|
|
// Fill cargo so swapping down to Jackal (capacity 4) overflows 2 items to ground!
|
2026-12-04 13:47:43 +01:00
|
|
|
Assert.True(tankGrid.TryAddCargo(Catalog.Flak));
|
|
|
|
|
Assert.True(tankGrid.TryAddCargo(Catalog.CopperRad));
|
2026-12-04 19:11:33 +01:00
|
|
|
Assert.True(tankGrid.TryAddCargo(Catalog.DieselCore));
|
2026-12-04 13:47:43 +01:00
|
|
|
|
2026-12-04 19:11:33 +01:00
|
|
|
List<ModuleSpec> dropped = tankGrid.SwapChassis(Catalog.Jackal);
|
2026-12-04 13:47:43 +01:00
|
|
|
|
2026-12-04 19:11:33 +01:00
|
|
|
// 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("jackal", tankGrid.Spec.Id);
|
2026-12-04 13:47:43 +01:00
|
|
|
Assert.Contains(tankGrid.Mounted, m => m.Spec.Id == "mg_762");
|
2026-12-04 19:11:33 +01:00
|
|
|
Assert.Contains(tankGrid.Mounted, m => m.Spec.Id == "turbo_core");
|
2026-12-04 13:47:43 +01:00
|
|
|
Assert.Contains(tankGrid.Mounted, m => m.Spec.Id == "gold_radiator");
|
|
|
|
|
Assert.DoesNotContain(tankGrid.Mounted, m => m.Spec.Id == "recoilless");
|
|
|
|
|
|
2026-12-04 19:11:33 +01:00
|
|
|
// 6 mounted on Ironclad: 3 transferred, 3 leftover + 3 cargo = 6 items -> 4 in Jackal Cargo, 2 dropped!
|
|
|
|
|
Assert.Equal(Catalog.Jackal.CargoCapacity, tankGrid.Cargo.Count);
|
2026-12-04 13:47:43 +01:00
|
|
|
Assert.Equal(2, dropped.Count);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|