Mining 4: pin rock wear once per fused round, walk order, gone rule, lead, evasion, absorb height
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
bcf7d7195d
commit
67f5be1e78
2 changed files with 149 additions and 2 deletions
|
|
@ -229,6 +229,32 @@ public sealed partial class MiningCut3Tests
|
|||
Assert.Equal(s.Zone.AsteroidBelts[far.Field].UndamagedSize(far.Index, s.Zone.Settings), s.Zone.ChunkRadius(far));
|
||||
}
|
||||
|
||||
// The walk is fixed: (field ordinal, index), whatever order the targeting index yields. Two belts, rocks scattered
|
||||
// so the index's own order is not the sorted one; the absorbs come in sorted order.
|
||||
[Fact]
|
||||
public void RocksAreWornInFieldThenIndexOrder()
|
||||
{
|
||||
var kind = Kind("Asteroid", 4f);
|
||||
var s = BuildScene(new[] { kind },
|
||||
Belt(kind, Rock(200f, .7f, .5f), Rock(200f, .1f, .5f), Rock(200f, .4f, .5f)),
|
||||
Belt(kind, Rock(200f, .9f, .5f), Rock(200f, .2f, .5f)));
|
||||
var rocks = new[] { 0, 1, 2 }.Select(i => new ChunkId(s.Belts[0], i)).Concat(new[] { 0, 1 }.Select(i => new ChunkId(s.Belts[1], i))).ToList();
|
||||
var blast = float2.zero;
|
||||
var seen = new List<AbsorbEvent>();
|
||||
using var sub = s.Zone.ChunkCapabilities.Absorb.Subscribe(seen.Add);
|
||||
|
||||
FireControl.Detonate(s.Zone, blast, 400f, 1000f, DamageType.Kinetic);
|
||||
|
||||
Assert.Equal(rocks.Count, seen.Count);
|
||||
var expected = rocks.OrderBy(r => r.Field.Value, StringComparer.Ordinal).ThenBy(r => r.Index).ToList();
|
||||
for (var i = 0; i < expected.Count; i++)
|
||||
{
|
||||
var away = normalize(At(s, expected[i]) - blast);
|
||||
Assert.Equal(away.x, seen[i].Direction.x, 3);
|
||||
Assert.Equal(away.y, seen[i].Direction.z, 3);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AMineBlastWearsRocks()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -58,14 +58,14 @@ public sealed class MiningCut4bTests : IDisposable
|
|||
// `precision` 1 gives sigma 1 cell; accuracy 1 and a resolution that asks little of the info make PSensor 1.
|
||||
private Rig Build(bool sensor = true, bool launcher = false, float damage = 10f, float velocity = 0f, float spread = 0f,
|
||||
float precision = 1f, float effective = float.PositiveInfinity, WeaponFuse? fuse = null, float blastRadius = 0f,
|
||||
float rockSize = 0f, float crossSection = 20f, bool target = true)
|
||||
float rockSize = 0f, float crossSection = 20f, bool target = true, float tracking = 1000000f)
|
||||
{
|
||||
var kind = MiningCut3Tests.Kind("Asteroid", crossSection);
|
||||
var scene = _fixtures.BuildScene(new[] { kind }, MiningCut3Tests.Belt(kind, MiningCut3Tests.Rock(Distance, .25f, rockSize)));
|
||||
var gear = MiningCut3Tests.Gear("Targeting", new TargetingSystemData
|
||||
{
|
||||
Accuracy = MiningCut3Tests.Constant(1f), Resolution = MiningCut3Tests.Constant(1000f),
|
||||
Precision = MiningCut3Tests.Constant(precision), Tracking = MiningCut3Tests.Constant(1000000f)
|
||||
Precision = MiningCut3Tests.Constant(precision), Tracking = MiningCut3Tests.Constant(tracking)
|
||||
});
|
||||
scene.Cache.Upsert(gear);
|
||||
var gun = new WeaponItemData
|
||||
|
|
@ -334,4 +334,125 @@ public sealed class MiningCut4bTests : IDisposable
|
|||
Assert.True(length(velocity) > 1f);
|
||||
Assert.True(length(velocity * .5f - (ahead - now)) < .05f * length(ahead - now));
|
||||
}
|
||||
|
||||
// A rock is not a Ship: its evasion is 0, so Tracking (the metres of deviation a shooter forgives) never
|
||||
// discounts the price of a rock. The same rock priced by a tight and by a loose tracker reads one price.
|
||||
[Fact]
|
||||
public void ARockEvadesNothing()
|
||||
{
|
||||
var tight = Build(spread: 4f, precision: 1f, tracking: 10f);
|
||||
var loose = Build(spread: 4f, precision: 1f, tracking: 1000000f);
|
||||
var tightPrice = FireControl.HitProbability(tight.Gun, tight.Shooter, tight.Rock);
|
||||
var loosePrice = FireControl.HitProbability(loose.Gun, loose.Shooter, loose.Rock);
|
||||
Assert.InRange(loosePrice, .05f, .99f);
|
||||
Assert.Equal(loosePrice, tightPrice, 5);
|
||||
}
|
||||
|
||||
// The lead is the intercept of the rock's pose velocity: the point is where the rock will be when a round of the
|
||||
// gun's velocity gets there, derived here from the time of flight, not from the code under test.
|
||||
[Fact]
|
||||
public void AMovingRockIsLeadAtItsPoseVelocity()
|
||||
{
|
||||
var rig = Build(velocity: 50f);
|
||||
var velocity = rig.Zone.ChunkVelocity(rig.Rock);
|
||||
var now = rig.Zone.ChunkPose(rig.Rock.Field, rig.Rock.Index).xy;
|
||||
Assert.True(length(velocity) > 1f);
|
||||
|
||||
var point = FireControl.PredictedIntercept(rig.Gun, rig.Shooter, rig.Rock);
|
||||
|
||||
var flight = length(point.xz - rig.Shooter.Position.xz) / 50f;
|
||||
var there = now + velocity * flight;
|
||||
Assert.True(length(point.xz - now) > .5f, "the aim leads the rock");
|
||||
Assert.Equal(there.x, point.x, 2);
|
||||
Assert.Equal(there.y, point.z, 2);
|
||||
}
|
||||
|
||||
// A rock that breaks after its round committed a hit resolves as a miss through Step's gone rule: the frozen
|
||||
// outcome says Hit, so only that rule stops the round from absorbing on, and wearing, a rock that is gone.
|
||||
[Fact]
|
||||
public void ARockThatBreaksAfterCommitIsAMissNotAFrozenHit()
|
||||
{
|
||||
var rig = Build(velocity: 50f, precision: 1000f);
|
||||
var committed = new List<ShotOutcome>();
|
||||
rig.Zone.ShotCommitted.Subscribe(committed.Add);
|
||||
var absorbs = 0;
|
||||
rig.Zone.ChunkCapabilities.Absorb.Subscribe(_ => absorbs++);
|
||||
FireControl.Fire(rig.Gun, rig.GunItem, rig.Shooter);
|
||||
for (var waited = 0f; committed.Count == 0 && waited < 3f; waited += .01f) rig.Zone.Update(.01f);
|
||||
var frozen = Assert.Single(committed);
|
||||
Assert.True(frozen.Hit, "fixture: the commit rolled a hit");
|
||||
Assert.Empty(rig.Resolved);
|
||||
|
||||
Assert.True(rig.Zone.Wear(rig.Rock, 1e6f));
|
||||
Run(rig, 2.5f);
|
||||
|
||||
var outcome = Assert.Single(rig.Resolved);
|
||||
Assert.False(outcome.Hit);
|
||||
Assert.Equal(0, absorbs);
|
||||
}
|
||||
|
||||
private static void Wear(Rig rig, WeaponFuse fuse, int shots, out int hits, out List<AbsorbEvent> absorbs, out float worn)
|
||||
{
|
||||
var seen = new List<AbsorbEvent>();
|
||||
rig.Zone.ChunkCapabilities.Absorb.Subscribe(seen.Add);
|
||||
for (var shot = 0; shot < shots; shot++)
|
||||
{
|
||||
FireControl.Fire(rig.Gun, rig.GunItem, rig.Shooter);
|
||||
Run(rig, .02f);
|
||||
}
|
||||
hits = rig.Resolved.Count(o => o.Hit);
|
||||
absorbs = seen;
|
||||
worn = seen.Sum(e => e.Magnitude);
|
||||
}
|
||||
|
||||
// A contact round that hits a rock wears it exactly once, by the blast's share through Detonate: one absorb per hit,
|
||||
// and the rock's wear is the sum of those absorbs' magnitudes, with no Damage added on top.
|
||||
[Fact]
|
||||
public void AContactRoundWearsARockExactlyOnce()
|
||||
{
|
||||
var rig = Build(damage: 10f, fuse: WeaponFuse.Contact, blastRadius: 6f, precision: 1000f, rockSize: .5f);
|
||||
Wear(rig, WeaponFuse.Contact, 12, out var hits, out var absorbs, out var worn);
|
||||
|
||||
Assert.InRange(hits, 1, 12);
|
||||
Assert.Equal(hits, absorbs.Count);
|
||||
var belt = rig.Zone.AsteroidBelts[rig.Rock.Field];
|
||||
Assert.True(rig.Zone.ChunkExists(rig.Rock));
|
||||
Assert.Equal(belt.DamagedSize(rig.Rock.Index, worn, rig.Zone.Settings), rig.Zone.ChunkRadius(rig.Rock), 3);
|
||||
}
|
||||
|
||||
// The same for a proximity round, which detonates at its burst point hit or miss: one absorb per resolved round
|
||||
// that covers the rock, and no wear beyond them.
|
||||
[Fact]
|
||||
public void AProximityRoundWearsARockExactlyOnce()
|
||||
{
|
||||
var rig = Build(damage: 10f, fuse: WeaponFuse.Proximity, blastRadius: 6f, precision: 1000f, rockSize: .5f);
|
||||
Wear(rig, WeaponFuse.Proximity, 12, out _, out var absorbs, out var worn);
|
||||
|
||||
Assert.Equal(12, rig.Resolved.Count);
|
||||
Assert.NotEmpty(absorbs);
|
||||
var belt = rig.Zone.AsteroidBelts[rig.Rock.Field];
|
||||
Assert.True(rig.Zone.ChunkExists(rig.Rock));
|
||||
Assert.Equal(belt.DamagedSize(rig.Rock.Index, worn, rig.Zone.Settings), rig.Zone.ChunkRadius(rig.Rock), 3);
|
||||
}
|
||||
|
||||
// A rock's absorb has one height rule whoever reports it: a direct hit and a blast both publish at height 0, not at
|
||||
// the shooter's.
|
||||
[Fact]
|
||||
public void ARockAbsorbHasOneHeightRule()
|
||||
{
|
||||
var rig = Build(damage: 3f, rockSize: .5f, precision: 1000f);
|
||||
rig.Shooter.Position = float3(0, 7, 0);
|
||||
var heights = new List<float>();
|
||||
rig.Zone.ChunkCapabilities.Absorb.Subscribe(e => heights.Add(e.Position.y));
|
||||
for (var shot = 0; shot < 6; shot++)
|
||||
{
|
||||
FireControl.Fire(rig.Gun, rig.GunItem, rig.Shooter);
|
||||
Run(rig, .02f);
|
||||
}
|
||||
var direct = heights.Count;
|
||||
FireControl.Detonate(rig.Zone, rig.Zone.ChunkPose(rig.Rock.Field, rig.Rock.Index).xy, 5f, 3f, DamageType.Kinetic);
|
||||
|
||||
Assert.True(direct > 0 && heights.Count > direct);
|
||||
Assert.All(heights, h => Assert.Equal(0f, h));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue