Tests: EB-1 structure damage/death, fortress targeting, persistence v3

10 new EditMode tests (312 total, all green): HealthApplyDamage destroys a Destructible at 0 + a wounded structure survives clamped; PickWeightedNearest x5 (player-only, structure-preferred-by-weight, player-in-the-way wins, raze undefended base, no targets); persistence (StructureSave.HP round-trip + writes v3, v2 in the load floor, SaveApply.ToPending maps the wounded HP - the staging-copy bug the pre-code review caught); + the StructureAggroWeight default pin. See DR-032.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-11 23:53:50 -07:00
parent 73cfe2943d
commit 66edbdec69
4 changed files with 139 additions and 0 deletions
@@ -1,6 +1,7 @@
using NUnit.Framework;
using ProjectM.Simulation;
using Unity.Mathematics;
using Unity.Collections;
namespace ProjectM.Tests
{
@@ -111,5 +112,63 @@ namespace ProjectM.Tests
Assert.AreEqual(v.x, slid.x, Eps);
Assert.AreEqual(v.z, slid.z, Eps);
}
// ---- EB-1 fortress aggro: PickWeightedNearest ----
[Test]
public void PickWeightedNearest_NoStructures_PicksNearestPlayer()
{
using var players = new NativeList<float3>(Allocator.Temp);
using var structs = new NativeList<float3>(Allocator.Temp);
players.Add(new float3(10, 0, 0));
players.Add(new float3(3, 0, 0));
EnemyAIMath.PickWeightedNearest(float3.zero, players, structs, 0.7f, out bool isStruct, out int idx);
Assert.IsFalse(isStruct);
Assert.AreEqual(1, idx, "nearest player is index 1 (dist 3)");
}
[Test]
public void PickWeightedNearest_PrefersStructure_WhenWeightShrinksItsDistance()
{
using var players = new NativeList<float3>(Allocator.Temp);
using var structs = new NativeList<float3>(Allocator.Temp);
players.Add(new float3(8, 0, 0)); // effective 8
structs.Add(new float3(10, 0, 0)); // 10 * weight 0.5 = effective 5 < 8
EnemyAIMath.PickWeightedNearest(float3.zero, players, structs, 0.5f, out bool isStruct, out int idx);
Assert.IsTrue(isStruct, "a weighted structure (10*0.5=5) beats a player at 8 -> Husks push for structures");
Assert.AreEqual(0, idx);
}
[Test]
public void PickWeightedNearest_PlayerInTheWay_WinsOverWeightedStructure()
{
using var players = new NativeList<float3>(Allocator.Temp);
using var structs = new NativeList<float3>(Allocator.Temp);
players.Add(new float3(2, 0, 0)); // a player right in the way (dist 2)
structs.Add(new float3(10, 0, 0)); // 10 * 0.7 = effective 7 > 2
EnemyAIMath.PickWeightedNearest(float3.zero, players, structs, 0.7f, out bool isStruct, out int idx);
Assert.IsFalse(isStruct, "a player closer than the weighted structure distance wins (attack the one in the way)");
Assert.AreEqual(0, idx);
}
[Test]
public void PickWeightedNearest_OnlyStructures_RazesTheUndefendedBase()
{
using var players = new NativeList<float3>(Allocator.Temp);
using var structs = new NativeList<float3>(Allocator.Temp);
structs.Add(new float3(0, 0, 12));
EnemyAIMath.PickWeightedNearest(float3.zero, players, structs, 0.7f, out bool isStruct, out int idx);
Assert.IsTrue(isStruct, "with no players, a Husk targets a structure (razes the undefended base)");
Assert.AreEqual(0, idx);
}
[Test]
public void PickWeightedNearest_NoTargets_ReturnsMinusOne()
{
using var players = new NativeList<float3>(Allocator.Temp);
using var structs = new NativeList<float3>(Allocator.Temp);
EnemyAIMath.PickWeightedNearest(float3.zero, players, structs, 0.7f, out bool isStruct, out int idx);
Assert.AreEqual(-1, idx);
}
}
}