Mining cut 4: rocks take blasts and shots through the one fire path (#18)
This commit is contained in:
parent
c47a34115c
commit
2b3278ba3d
6 changed files with 999 additions and 92 deletions
|
|
@ -32,7 +32,7 @@ public sealed partial class MiningCut3Tests : IDisposable
|
|||
Directory.Delete(_root, true);
|
||||
}
|
||||
|
||||
private static PerformanceStat Constant(float v) => new PerformanceStat { Min = v, Max = v };
|
||||
internal static PerformanceStat Constant(float v) => new PerformanceStat { Min = v, Max = v };
|
||||
|
||||
private static GameplaySettings GameSettings() => new GameplaySettings
|
||||
{
|
||||
|
|
@ -49,7 +49,7 @@ public sealed partial class MiningCut3Tests : IDisposable
|
|||
|
||||
// Every sun carries a well (the belts circle in it, c = 9), one sun whose light reaches 1000 units, and the chunk
|
||||
// curves MiningCut2Tests uses, so sizes and wear vary over the fixture's range.
|
||||
private static PlanetSettings PlanetSettings(float lightRadius = 1000f) => new PlanetSettings
|
||||
internal static PlanetSettings PlanetSettings(float lightRadius = 1000f) => new PlanetSettings
|
||||
{
|
||||
WellStrength = new ExponentialCurve { Constant = 9f },
|
||||
RocheLimit = new ExponentialCurve { Constant = 1f },
|
||||
|
|
@ -66,7 +66,7 @@ public sealed partial class MiningCut3Tests : IDisposable
|
|||
Keys = new[] { new float4(0, 1, 0, 0), new float4(1, .3f, 0, 0) }
|
||||
};
|
||||
|
||||
private sealed class Scene
|
||||
internal sealed class Scene
|
||||
{
|
||||
public CultCache Cache;
|
||||
public ItemManager Items;
|
||||
|
|
@ -81,16 +81,16 @@ public sealed partial class MiningCut3Tests : IDisposable
|
|||
|
||||
// A belt around the sun: its chunks orbit the origin at their own distances, so at zone time 0 a chunk of
|
||||
// phase p sits at distance × (cos 2πp, sin 2πp). `kind` null leaves the belt kindless, for the zone to assign.
|
||||
private sealed class BeltSpec
|
||||
internal sealed class BeltSpec
|
||||
{
|
||||
public Asteroid[] Asteroids;
|
||||
public FieldKindData Kind;
|
||||
}
|
||||
|
||||
private static Asteroid Rock(float distance, float phase = 0f, float size = .5f) =>
|
||||
internal static Asteroid Rock(float distance, float phase = 0f, float size = .5f) =>
|
||||
new Asteroid { Distance = distance, Phase = phase, Size = size, RotationSpeed = .1f };
|
||||
|
||||
private Scene BuildScene(FieldKindData[] kinds = null, params BeltSpec[] belts) => BuildSceneAt(float2.zero, kinds, belts);
|
||||
internal Scene BuildScene(FieldKindData[] kinds = null, params BeltSpec[] belts) => BuildSceneAt(float2.zero, kinds, belts);
|
||||
|
||||
// The same scene with its sun, and so every belt centre, at `sunAt`.
|
||||
private Scene BuildSceneAt(float2 sunAt, FieldKindData[] kinds, params BeltSpec[] belts) =>
|
||||
|
|
@ -165,10 +165,10 @@ public sealed partial class MiningCut3Tests : IDisposable
|
|||
return scene;
|
||||
}
|
||||
|
||||
private static FieldKindData Kind(string name, float crossSection, float weight = 1f) =>
|
||||
internal static FieldKindData Kind(string name, float crossSection, float weight = 1f) =>
|
||||
new FieldKindData { Name = name, CrossSection = crossSection, GenerationWeight = weight };
|
||||
|
||||
private static BeltSpec Belt(FieldKindData kind, params Asteroid[] asteroids) => new BeltSpec { Kind = kind, Asteroids = asteroids };
|
||||
internal static BeltSpec Belt(FieldKindData kind, params Asteroid[] asteroids) => new BeltSpec { Kind = kind, Asteroids = asteroids };
|
||||
|
||||
// A chunk's planar position now (zone time never advances in these tests).
|
||||
private static float2 At(Scene s, ChunkId chunk) => s.Zone.ChunkPose(chunk.Field, chunk.Index).xy;
|
||||
|
|
@ -180,14 +180,14 @@ public sealed partial class MiningCut3Tests : IDisposable
|
|||
return kind.CrossSection * PI * cells * cells * s.Zone.GetLight(At(s, chunk));
|
||||
}
|
||||
|
||||
private static GearData Gear(string name, BehaviorData behavior) => new GearData
|
||||
internal static GearData Gear(string name, BehaviorData behavior) => new GearData
|
||||
{
|
||||
Name = name, Hardpoint = HardpointType.Tool, Shape = new Shape(), Durability = 1,
|
||||
MinimumTemperature = -1000, MaximumTemperature = 1000, OptimalTemperature = 0, PlateauWidth = 2000,
|
||||
Behaviors = { behavior }
|
||||
};
|
||||
|
||||
private static EquippableItem Mint(Scene s, ItemData design) => new EquippableItem
|
||||
internal static EquippableItem Mint(Scene s, ItemData design) => new EquippableItem
|
||||
{
|
||||
Data = s.Cache.RefOf<ItemData>(design),
|
||||
Durability = design is EquippableItemData equippable ? equippable.Durability : 0,
|
||||
|
|
|
|||
279
tests/Aetheria.Shared.Tests/MiningCut4aTests.cs
Normal file
279
tests/Aetheria.Shared.Tests/MiningCut4aTests.cs
Normal file
|
|
@ -0,0 +1,279 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CultMath;
|
||||
using UniRx;
|
||||
using Xunit;
|
||||
using static CultMath.math;
|
||||
using float2 = CultMath.float2;
|
||||
using float3 = CultMath.float3;
|
||||
|
||||
// Mining cut 4a (docs/mining-cut-refresh.md, Q10 = A): a blast's disc is shared by area over whatever it covers, hull
|
||||
// cells or rocks, through FireControl.Detonate; each worn rock publishes one absorb on Zone.ChunkCapabilities. Reuses
|
||||
// MiningCut3Tests' belt fixture (a partial of that class), so a filter on these tests names the methods below.
|
||||
public sealed partial class MiningCut3Tests
|
||||
{
|
||||
// A one-rock belt: the rock at phase 0 sits on +x of the belt centre, `size` its authored size.
|
||||
private (Scene scene, ChunkId rock) OneRock(float size = .5f, float distance = 200f)
|
||||
{
|
||||
var kind = Kind("Asteroid", 4f);
|
||||
var s = BuildScene(new[] { kind }, Belt(kind, Rock(distance, 0f, size)));
|
||||
return (s, new ChunkId(s.Belts[0], 0));
|
||||
}
|
||||
|
||||
private static List<AbsorbEvent> Absorbs(Scene s, List<IDisposable> subs)
|
||||
{
|
||||
var list = new List<AbsorbEvent>();
|
||||
subs.Add(s.Zone.ChunkCapabilities.Absorb.Subscribe(list.Add));
|
||||
return list;
|
||||
}
|
||||
|
||||
// The area of a disc at the origin of radius r1 and a disc at (d, 0) of radius r2, by midpoint integration of the
|
||||
// chord overlap -- no formula of the code under test.
|
||||
private static double NumericLens(double d, double r1, double r2)
|
||||
{
|
||||
var lo = Math.Max(-r1, d - r2);
|
||||
var hi = Math.Min(r1, d + r2);
|
||||
if (hi <= lo) return 0;
|
||||
const int n = 400000;
|
||||
var h = (hi - lo) / n;
|
||||
var area = 0.0;
|
||||
for (var i = 0; i < n; i++)
|
||||
{
|
||||
var x = lo + (i + .5) * h;
|
||||
var a = Math.Sqrt(Math.Max(0, r1 * r1 - x * x));
|
||||
var b = Math.Sqrt(Math.Max(0, r2 * r2 - (x - d) * (x - d)));
|
||||
area += 2 * Math.Min(a, b) * h;
|
||||
}
|
||||
return area;
|
||||
}
|
||||
|
||||
// The area of a disc centred (cx, cy) of radius r inside the axis-aligned rectangle, by the same integration.
|
||||
private static double NumericDiscInRect(double cx, double cy, double r, double x0, double x1, double y0, double y1)
|
||||
{
|
||||
var lo = Math.Max(cx - r, x0);
|
||||
var hi = Math.Min(cx + r, x1);
|
||||
if (hi <= lo) return 0;
|
||||
const int n = 400000;
|
||||
var h = (hi - lo) / n;
|
||||
var area = 0.0;
|
||||
for (var i = 0; i < n; i++)
|
||||
{
|
||||
var x = lo + (i + .5) * h;
|
||||
var half = Math.Sqrt(Math.Max(0, r * r - (x - cx) * (x - cx)));
|
||||
area += Math.Max(0, Math.Min(cy + half, y1) - Math.Max(cy - half, y0)) * h;
|
||||
}
|
||||
return area;
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(5f, 3f, 4f)]
|
||||
[InlineData(1f, 3f, 4f)]
|
||||
[InlineData(6.5f, 3f, 4f)]
|
||||
[InlineData(2.5f, 2f, 5f)]
|
||||
[InlineData(3f, 3f, 3f)]
|
||||
public void CircleCircleOverlapIsTheLens(float d, float r1, float r2)
|
||||
{
|
||||
var expected = NumericLens(d, r1, r2);
|
||||
Assert.Equal(expected, FireControl.CircleCircleOverlap(d, r1, r2), 3);
|
||||
Assert.Equal(expected, FireControl.CircleCircleOverlap(d, r2, r1), 3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CircleCircleOverlapIsExactAtTheLimits()
|
||||
{
|
||||
Assert.Equal(0f, FireControl.CircleCircleOverlap(7f, 3f, 4f)); // tangent
|
||||
Assert.Equal(0f, FireControl.CircleCircleOverlap(8f, 3f, 4f)); // disjoint
|
||||
Assert.Equal(PI * 9f, FireControl.CircleCircleOverlap(1f, 3f, 4f), 3); // contained: the smaller disc
|
||||
Assert.Equal(PI * 9f, FireControl.CircleCircleOverlap(0f, 4f, 3f), 3); // concentric
|
||||
Assert.Equal(PI * 9f, FireControl.CircleCircleOverlap(1f, 3f, 4f), 3);
|
||||
Assert.Equal(0f, FireControl.CircleCircleOverlap(0f, 0f, 3f));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ABlastBesideAnUntargetedRockWearsIt()
|
||||
{
|
||||
var (s, rock) = OneRock();
|
||||
var at = At(s, rock);
|
||||
var radius = 5f;
|
||||
var offset = 3f;
|
||||
var undamaged = s.Zone.ChunkRadius(rock);
|
||||
FireControl.Detonate(s.Zone, at + float2(offset, 0), radius, 10f, DamageType.Kinetic);
|
||||
|
||||
var share = (float) (10.0 * NumericLens(offset, radius, undamaged) / (Math.PI * radius * radius));
|
||||
Assert.True(share > 0f);
|
||||
Assert.Equal(s.Zone.AsteroidBelts[rock.Field].DamagedSize(rock.Index, share, s.Zone.Settings), s.Zone.ChunkRadius(rock), 3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ABlastSharesItsDiscOverCellsAndRocksByArea()
|
||||
{
|
||||
var (s, rock) = OneRock();
|
||||
var rockAt = At(s, rock);
|
||||
var rockRadius = s.Zone.ChunkRadius(rock);
|
||||
var ship = SpawnShip(s, rockAt + float2(-12f, 0f));
|
||||
var radius = 6f;
|
||||
var blast = rockAt + float2(-5.5f, 0f);
|
||||
var damage = 1f;
|
||||
var subs = new List<IDisposable>();
|
||||
var hullAbsorbs = new List<AbsorbEvent>();
|
||||
subs.Add(ship.Capabilities.Absorb.Subscribe(hullAbsorbs.Add));
|
||||
var rockAbsorbs = Absorbs(s, subs);
|
||||
|
||||
FireControl.Detonate(s.Zone, blast, radius, damage, DamageType.Kinetic);
|
||||
foreach (var sub in subs) sub.Dispose();
|
||||
|
||||
// The hull is a 5 x 5 block of 2-unit cells about its position; the rock a disc; the two do not overlap.
|
||||
var p = ship.Position.xz;
|
||||
var area = Math.PI * radius * radius;
|
||||
var hullArea = NumericDiscInRect(blast.x, blast.y, radius, p.x - 5, p.x + 5, p.y - 5, p.y + 5);
|
||||
var rockArea = NumericLens(length(rockAt - blast), radius, rockRadius);
|
||||
Assert.True(hullArea > 0 && rockArea > 0 && hullArea + rockArea < area, "fixture: both covered, some of the disc lost");
|
||||
var hull = Assert.Single(hullAbsorbs);
|
||||
var worn = Assert.Single(rockAbsorbs);
|
||||
Assert.Equal(damage * hullArea / area, hull.Magnitude, 4);
|
||||
Assert.Equal(damage * rockArea / area, worn.Magnitude, 4);
|
||||
var lost = damage * (area - hullArea - rockArea) / area;
|
||||
Assert.Equal(damage, hull.Magnitude + worn.Magnitude + lost, 4);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ARockWhoseCentreIsOutsideTheBlastIsStillWorn()
|
||||
{
|
||||
// The widest rock (size 1, radius 9) and a small blast: the blast radius 3 plus the rock's 9 exceeds the
|
||||
// 8 between them, yet the centre is far outside the blast disc.
|
||||
var (s, rock) = OneRock(size: 1f);
|
||||
var at = At(s, rock);
|
||||
var radius = 3f;
|
||||
Assert.Equal(9f, s.Zone.ChunkRadius(rock), 3);
|
||||
var subs = new List<IDisposable>();
|
||||
var absorbs = Absorbs(s, subs);
|
||||
FireControl.Detonate(s.Zone, at + float2(8f, 0f), radius, 10f, DamageType.Kinetic);
|
||||
subs.ForEach(x => x.Dispose());
|
||||
|
||||
var worn = Assert.Single(absorbs);
|
||||
Assert.Equal(10.0 * NumericLens(8, radius, 9) / (Math.PI * radius * radius), worn.Magnitude, 4);
|
||||
Assert.True(s.Zone.ChunkRadius(rock) < 9f);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ATangentOrDistantBlastWearsNothing()
|
||||
{
|
||||
var (s, rock) = OneRock();
|
||||
var at = At(s, rock);
|
||||
var radius = s.Zone.ChunkRadius(rock);
|
||||
var subs = new List<IDisposable>();
|
||||
var absorbs = Absorbs(s, subs);
|
||||
FireControl.Detonate(s.Zone, at + float2(2f * radius, 0f), radius, 10f, DamageType.Kinetic);
|
||||
FireControl.Detonate(s.Zone, at + float2(60f, 0f), 5f, 10f, DamageType.Kinetic);
|
||||
subs.ForEach(x => x.Dispose());
|
||||
|
||||
Assert.Empty(absorbs);
|
||||
Assert.Equal(radius, s.Zone.ChunkRadius(rock));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ABrokenRockTakesNothingAndPublishesNothing()
|
||||
{
|
||||
var (s, rock) = OneRock();
|
||||
var at = At(s, rock);
|
||||
Assert.True(s.Zone.Wear(rock, 1e6f));
|
||||
var subs = new List<IDisposable>();
|
||||
var absorbs = Absorbs(s, subs);
|
||||
FireControl.Detonate(s.Zone, at, 8f, 10f, DamageType.Kinetic);
|
||||
subs.ForEach(x => x.Dispose());
|
||||
|
||||
Assert.Empty(absorbs);
|
||||
Assert.False(s.Zone.ChunkExists(rock));
|
||||
Assert.Equal(0f, s.Zone.ChunkRadius(rock));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EachWornRockPublishesOneAbsorb()
|
||||
{
|
||||
var kind = Kind("Asteroid", 4f);
|
||||
// Two rocks side by side and a third out of reach, listed out of order of their distance.
|
||||
var s = BuildScene(new[] { kind }, Belt(kind, Rock(200f, 0f, .5f), Rock(300f, 0f, .5f), Rock(205f, 0f, .5f)));
|
||||
var a = new ChunkId(s.Belts[0], 0);
|
||||
var b = new ChunkId(s.Belts[0], 2);
|
||||
var far = new ChunkId(s.Belts[0], 1);
|
||||
var blast = (At(s, a) + At(s, b)) / 2f;
|
||||
var radius = 8f;
|
||||
var damage = 10f;
|
||||
var seen = new List<(AbsorbEvent e, float aRadius, float bRadius)>();
|
||||
using var sub = s.Zone.ChunkCapabilities.Absorb.Subscribe(e => seen.Add((e, s.Zone.ChunkRadius(a), s.Zone.ChunkRadius(b))));
|
||||
var undamagedA = s.Zone.ChunkRadius(a);
|
||||
var undamagedB = s.Zone.ChunkRadius(b);
|
||||
|
||||
FireControl.Detonate(s.Zone, blast, radius, damage, DamageType.Kinetic);
|
||||
|
||||
Assert.Equal(2, seen.Count);
|
||||
Assert.All(seen, x => Assert.Equal(AbsorbLayer.Hull, x.e.Layer));
|
||||
Assert.All(seen, x => Assert.Equal(0f, x.e.Position.y));
|
||||
// Walked in index order; each absorb lands before its own rock's wear, and the first rock's wear is already
|
||||
// done when the second is published.
|
||||
Assert.Equal(undamagedA, seen[0].aRadius);
|
||||
Assert.Equal(undamagedB, seen[0].bRadius);
|
||||
Assert.True(seen[1].aRadius < undamagedA);
|
||||
Assert.Equal(undamagedB, seen[1].bRadius);
|
||||
Assert.Equal(damage * NumericLens(length(At(s, a) - blast), radius, undamagedA) / (Math.PI * radius * radius), seen[0].e.Magnitude, 4);
|
||||
Assert.Equal(damage * NumericLens(length(At(s, b) - blast), radius, undamagedB) / (Math.PI * radius * radius), seen[1].e.Magnitude, 4);
|
||||
// The direction runs from the blast out through the rock.
|
||||
var away = normalize(At(s, a) - blast);
|
||||
Assert.Equal(away.x, seen[0].e.Direction.x, 4);
|
||||
Assert.Equal(away.y, seen[0].e.Direction.z, 4);
|
||||
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()
|
||||
{
|
||||
var (s, rock) = OneRock();
|
||||
var at = At(s, rock);
|
||||
var undamaged = s.Zone.ChunkRadius(rock);
|
||||
var absorbs = new List<AbsorbEvent>();
|
||||
using var sub = s.Zone.ChunkCapabilities.Absorb.Subscribe(absorbs.Add);
|
||||
s.Zone.Lay(new Mine
|
||||
{
|
||||
Id = s.Zone.NextBodyId(), Body = new KinematicBody { Position = at + float2(2f, 0f), Velocity = float2.zero },
|
||||
ArmingDelay = 0f, FuseDelay = 100f, Lifetime = 0f, BlastRadius = 6f, Damage = 10f,
|
||||
DamageType = DamageType.Kinetic, Layer = null, LayerFaction = null
|
||||
});
|
||||
|
||||
s.Zone.Update(.001f);
|
||||
|
||||
Assert.Empty(s.Zone.Mines);
|
||||
Assert.Single(absorbs);
|
||||
Assert.True(s.Zone.ChunkRadius(rock) < undamaged);
|
||||
}
|
||||
}
|
||||
458
tests/Aetheria.Shared.Tests/MiningCut4bTests.cs
Normal file
458
tests/Aetheria.Shared.Tests/MiningCut4bTests.cs
Normal file
|
|
@ -0,0 +1,458 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CultMath;
|
||||
using UniRx;
|
||||
using Xunit;
|
||||
using static CultMath.math;
|
||||
using float2 = CultMath.float2;
|
||||
using float3 = CultMath.float3;
|
||||
|
||||
// Mining Cut 4b (docs/mining-cut-refresh.md, Q12 = A): a shot at a rock goes through FireControl's one fire path
|
||||
// and wears it; the rock is a disc. The fixture is MiningCut3Tests' belt scene: a shooter at the origin, one rock
|
||||
// straight ahead (+z, phase .25) at `Distance`, a gun and a targeting system fitted on the shooter.
|
||||
public sealed class MiningCut4bTests : IDisposable
|
||||
{
|
||||
private const float Distance = 100f;
|
||||
private readonly MiningCut3Tests _fixtures = new MiningCut3Tests();
|
||||
|
||||
public void Dispose() => _fixtures.Dispose();
|
||||
|
||||
private sealed class Rig
|
||||
{
|
||||
public MiningCut3Tests.Scene Scene;
|
||||
public Zone Zone => Scene.Zone;
|
||||
public Ship Shooter;
|
||||
public EquippedItem GunItem;
|
||||
public Weapon Gun;
|
||||
public ChunkId Rock;
|
||||
public List<ShotOutcome> Resolved = new List<ShotOutcome>();
|
||||
}
|
||||
|
||||
private static InstantWeaponData Behavior(bool launcher, float damage, float velocity, float spread, float effective = float.PositiveInfinity)
|
||||
{
|
||||
InstantWeaponData data = launcher ? new LockWeaponData
|
||||
{
|
||||
LockSpeed = MiningCut3Tests.Constant(1000), SensorImpact = MiningCut3Tests.Constant(1), LockAngle = MiningCut3Tests.Constant(180),
|
||||
DirectionImpact = MiningCut3Tests.Constant(1), Decay = MiningCut3Tests.Constant(1)
|
||||
} : new InstantWeaponData();
|
||||
data.Damage = MiningCut3Tests.Constant(damage);
|
||||
data.Range = MiningCut3Tests.Constant(500f);
|
||||
data.MinRange = MiningCut3Tests.Constant(0);
|
||||
data.EffectiveRange = MiningCut3Tests.Constant(effective);
|
||||
data.DamageAtMaxRange = 0f;
|
||||
data.Velocity = MiningCut3Tests.Constant(velocity);
|
||||
data.Spread = MiningCut3Tests.Constant(spread);
|
||||
data.DamageSpread = MiningCut3Tests.Constant(0);
|
||||
data.Penetration = MiningCut3Tests.Constant(0);
|
||||
data.Count = MiningCut3Tests.Constant(1);
|
||||
data.BurstTime = MiningCut3Tests.Constant(0);
|
||||
data.Cooldown = MiningCut3Tests.Constant(1000);
|
||||
return data;
|
||||
}
|
||||
|
||||
// `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 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(tracking)
|
||||
});
|
||||
scene.Cache.Upsert(gear);
|
||||
var gun = new WeaponItemData
|
||||
{
|
||||
Name = "Gun", Hardpoint = HardpointType.Sensors, Shape = new Shape(), Durability = 1,
|
||||
MinimumTemperature = -1000, MaximumTemperature = 1000, OptimalTemperature = 0, PlateauWidth = 2000,
|
||||
Fuse = fuse, BlastRadius = blastRadius,
|
||||
Behaviors = { Behavior(launcher, damage, velocity, spread, effective) }
|
||||
};
|
||||
scene.Cache.Upsert(gun);
|
||||
|
||||
var shape = new Shape(5, 5);
|
||||
foreach (var cell in shape.AllCoordinates) shape[cell] = true;
|
||||
var hull = new HullData
|
||||
{
|
||||
Name = "Gunship", HullType = HullType.Ship, Shape = shape, Durability = 10, Mass = 1000,
|
||||
Hardpoints = { new HardpointData { Type = HardpointType.Sensors, Position = new int2(0, 0), Shape = new Shape() } }
|
||||
};
|
||||
scene.Cache.Upsert(hull);
|
||||
var shooter = new Ship(scene.Items, scene.Zone, MiningCut3Tests.Mint(scene, hull), new EntitySettings());
|
||||
if (sensor) Assert.True(shooter.TryEquip(MiningCut3Tests.Mint(scene, scene.Eye)), "eye");
|
||||
Assert.True(shooter.TryEquip(MiningCut3Tests.Mint(scene, gear)), "targeting");
|
||||
var minted = MiningCut3Tests.Mint(scene, gun);
|
||||
Assert.True(shooter.TryEquip(minted, new int2(0, 0)), "gun");
|
||||
scene.Zone.Admit(shooter, piloted: false);
|
||||
shooter.Position = float3.zero;
|
||||
shooter.Direction = float2(0, 1);
|
||||
shooter.Aim = float3(0, 0, 1);
|
||||
|
||||
shooter.Update(.05f); // the fitted sensor becomes active on its first tick; zone time does not advance
|
||||
shooter.Position = float3.zero;
|
||||
shooter.Velocity = float2.zero;
|
||||
var item = shooter.Equipment.Single(x => x.EquippableItem == minted);
|
||||
var rig = new Rig
|
||||
{
|
||||
Scene = scene, Shooter = shooter, GunItem = item, Gun = (Weapon) item.Behaviors.Single(b => b is Weapon),
|
||||
Rock = new ChunkId(scene.Belts[0], 0)
|
||||
};
|
||||
scene.Zone.ShotResolved.Subscribe(outcome => rig.Resolved.Add(outcome));
|
||||
if (target && sensor) Assert.True(shooter.SetTarget(rig.Rock), "target");
|
||||
return rig;
|
||||
}
|
||||
|
||||
private static float Phi(double z) => (float) (.5 * (1 + erf((float) (z / Math.Sqrt(2)))));
|
||||
|
||||
// The rock's radius in cells is the one the zone reports, sigma the targeting system's (floored at half a cell).
|
||||
private static float Disc(Rig rig)
|
||||
{
|
||||
var sigma = max(1f / FireControl.Precision(rig.Shooter), .5f);
|
||||
var radius = rig.Zone.ChunkCells(rig.Rock);
|
||||
return Phi(radius / sigma) - Phi(-radius / sigma);
|
||||
}
|
||||
|
||||
// PSensor as the rule states it, for a gear that wants only the detection threshold plus a thousandth of the rest.
|
||||
private static float Sensor(Rig rig, float info)
|
||||
{
|
||||
var th = rig.Scene.Items.GameplaySettings.TargetDetectionInfoThreshold;
|
||||
return saturate(unlerp(th, th + (1f - th) / 1000f, info));
|
||||
}
|
||||
|
||||
// ==== one fire path ====
|
||||
|
||||
// Accuracy, PSensor, PSpread, Sigma and PMount price a rock exactly as a ship at equal range, precision and info:
|
||||
// a two-cell ship (span 2, centre-aimed) and a rock one cell in radius (span 2) are the same disc to the gun, and
|
||||
// an unauthored gun follows anything, so the mount is 1 for both.
|
||||
[Fact]
|
||||
public void ARockShotUsesTheSameFactors()
|
||||
{
|
||||
var rig = Build(spread: 4f, precision: 1f, crossSection: 1f);
|
||||
var s = rig.Scene;
|
||||
Assert.Equal(1f, rig.Zone.ChunkCells(rig.Rock), 4);
|
||||
var info = rig.Shooter.ChunkInfo(rig.Rock);
|
||||
Assert.True(info > .11f && info < 1f, $"the rock's info {info} should be visible and unsaturated");
|
||||
|
||||
var hull = new HullData { Name = "Pair", HullType = HullType.Ship, Shape = new Shape(2, 2), Durability = 10, Mass = 1000 };
|
||||
foreach (var cell in hull.Shape.AllCoordinates) hull.Shape[cell] = true;
|
||||
s.Cache.Upsert(hull);
|
||||
var at = rig.Zone.ChunkPose(rig.Rock.Field, rig.Rock.Index).xy;
|
||||
var ship = new Ship(s.Items, rig.Zone, MiningCut3Tests.Mint(s, hull), new EntitySettings());
|
||||
rig.Zone.Admit(ship, piloted: false);
|
||||
ship.Position = float3(at.x, 0, at.y);
|
||||
ship.Direction = float2(0, 1);
|
||||
rig.Shooter.EntityInfoGathered[ship] = info;
|
||||
rig.Shooter.VisibleEntities.Add(ship);
|
||||
|
||||
var rock = FireControl.HitProbability(rig.Gun, rig.Shooter, rig.Rock);
|
||||
var vessel = FireControl.HitProbability(rig.Gun, rig.Shooter, ship);
|
||||
Assert.InRange(rock, .05f, .99f);
|
||||
Assert.Equal(vessel, rock, 4);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AnUnseenRockCannotBeFiredOn()
|
||||
{
|
||||
var blind = Build(sensor: false);
|
||||
Assert.False(FireControl.Designated(blind.Gun, blind.Shooter, blind.Rock, out var range));
|
||||
Assert.Equal(Distance, range, 2);
|
||||
Assert.Equal(0f, FireControl.HitProbability(blind.Gun, blind.Shooter, blind.Rock));
|
||||
Assert.False(FireControl.Solve(blind.Gun, blind.GunItem, blind.Shooter, blind.Rock).Designated);
|
||||
|
||||
var sighted = Build();
|
||||
Assert.True(FireControl.Designated(sighted.Gun, sighted.Shooter, sighted.Rock, out _));
|
||||
Assert.True(FireControl.HitProbability(sighted.Gun, sighted.Shooter, sighted.Rock) > 0f);
|
||||
}
|
||||
|
||||
// Q12 = A: a launcher (a LockWeapon) is never designated on a rock, locked or not.
|
||||
[Fact]
|
||||
public void LaunchersCannotFireOnARock()
|
||||
{
|
||||
var launcher = Build(launcher: true);
|
||||
Assert.False(FireControl.Designated(launcher.Gun, launcher.Shooter, launcher.Rock, out _));
|
||||
Assert.Equal(0f, FireControl.HitProbability(launcher.Gun, launcher.Shooter, launcher.Rock));
|
||||
var plain = Build();
|
||||
Assert.True(FireControl.Designated(plain.Gun, plain.Shooter, plain.Rock, out _));
|
||||
}
|
||||
|
||||
// POnHull is the closed form Phi(R/sigma) - Phi(-R/sigma): a zero-spread gun with a full sensor reading is priced by the
|
||||
// disc alone.
|
||||
[Fact]
|
||||
public void DiscMassIsTheClosedForm()
|
||||
{
|
||||
var rig = Build(spread: 0f, precision: 1f, rockSize: .5f);
|
||||
var info = rig.Shooter.ChunkInfo(rig.Rock);
|
||||
var expected = Sensor(rig, info) * Disc(rig);
|
||||
Assert.InRange(Disc(rig), .5f, .99f);
|
||||
Assert.Equal(expected, FireControl.HitProbability(rig.Gun, rig.Shooter, rig.Rock), 4);
|
||||
}
|
||||
|
||||
// Commit's price at fire time is the forecast: for a rock still at the instant it is fired at, one price.
|
||||
[Fact]
|
||||
public void TheForecastIsTheCommitPriceForARock()
|
||||
{
|
||||
var rig = Build(spread: 4f, precision: 1f, velocity: 50f);
|
||||
var forecast = FireControl.HitProbability(rig.Gun, rig.Shooter, rig.Rock);
|
||||
var id = FireControl.Fire(rig.Gun, rig.GunItem, rig.Shooter);
|
||||
Assert.True(rig.Zone.TryGetShot(id, out var shot));
|
||||
Assert.Equal(rig.Rock, shot.Chunk);
|
||||
Assert.Null(shot.Target);
|
||||
Assert.Equal(forecast, FireControl.CommitProbability(shot, shot.FireTime, out _), 4);
|
||||
}
|
||||
|
||||
// ==== resolution ====
|
||||
|
||||
private static void Run(Rig rig, float seconds)
|
||||
{
|
||||
for (var elapsed = 0f; elapsed < seconds; elapsed += .01f) rig.Zone.Update(.01f);
|
||||
}
|
||||
|
||||
// A rock hit has no lane and no shield. Hits wear the rock by the shot's Damage after the falloff, and each
|
||||
// publishes one absorb on the zone's ChunkCapabilities at the rock's surface facing the shot.
|
||||
[Fact]
|
||||
public void DirectHitsWearTheRock()
|
||||
{
|
||||
var rig = Build(damage: 3f, rockSize: .5f, precision: 1000f, effective: 50f);
|
||||
var absorbs = new List<AbsorbEvent>();
|
||||
var surface = new List<float>();
|
||||
rig.Zone.ChunkCapabilities.Absorb.Subscribe(e =>
|
||||
{
|
||||
absorbs.Add(e);
|
||||
var centre = rig.Zone.ChunkPose(rig.Rock.Field, rig.Rock.Index).xy;
|
||||
surface.Add(length(float2(e.Position.x, e.Position.z) - centre) - rig.Zone.ChunkRadius(rig.Rock));
|
||||
});
|
||||
var before = rig.Zone.ChunkRadius(rig.Rock);
|
||||
var factor = WeaponData.RangeFactor(0f, 50f, 500f, 0f, Distance);
|
||||
Assert.InRange(factor, .01f, .99f);
|
||||
|
||||
for (var shot = 0; shot < 12; shot++)
|
||||
{
|
||||
FireControl.Fire(rig.Gun, rig.GunItem, rig.Shooter);
|
||||
Run(rig, .02f);
|
||||
}
|
||||
|
||||
var hits = rig.Resolved.Count(o => o.Hit);
|
||||
Assert.InRange(hits, 1, 12);
|
||||
Assert.Equal(hits, absorbs.Count);
|
||||
Assert.All(rig.Resolved.Where(o => o.Hit), o => { Assert.Equal(0, o.Cell.x); Assert.Equal(0, o.Cell.y); Assert.False(o.Shielded); });
|
||||
Assert.All(absorbs, e => Assert.Equal(3f * factor, e.Magnitude, 2));
|
||||
Assert.All(surface, d => Assert.True(abs(d) < 1e-3f, $"absorb was {d} off the rock's surface"));
|
||||
Assert.All(absorbs, e => Assert.Equal(AbsorbLayer.Hull, e.Layer));
|
||||
var hp = MiningCut3Tests.PlanetSettings().AsteroidHitpoints.Evaluate(.5f);
|
||||
var expected = MiningCut3Tests.PlanetSettings().AsteroidSize.Evaluate((hp - hits * 3f * factor) / hp * .5f);
|
||||
Assert.Equal(expected, rig.Zone.ChunkRadius(rig.Rock), 3);
|
||||
Assert.True(rig.Zone.ChunkRadius(rig.Rock) < before);
|
||||
}
|
||||
|
||||
// A contact round that hits a rock detonates at its centre as it arrives, through Detonate: a bystander beside it
|
||||
// takes the blast from the rock's centre, not from the muzzle or from a lane.
|
||||
[Fact]
|
||||
public void AContactRoundAtARockDetonatesAtItsCentre()
|
||||
{
|
||||
var rig = Build(damage: 10f, fuse: WeaponFuse.Contact, blastRadius: 6f, precision: 1000f, rockSize: .5f);
|
||||
var s = rig.Scene;
|
||||
var at = rig.Zone.ChunkPose(rig.Rock.Field, rig.Rock.Index).xy;
|
||||
var bystander = new Ship(s.Items, rig.Zone, MiningCut3Tests.Mint(s, s.Hull), new EntitySettings());
|
||||
rig.Zone.Admit(bystander, piloted: false);
|
||||
bystander.Position = float3(at.x + 3f, 0, at.y);
|
||||
var burstAt = new List<float>();
|
||||
bystander.Capabilities.Absorb.Subscribe(e =>
|
||||
{
|
||||
var centre = rig.Zone.ChunkPose(rig.Rock.Field, rig.Rock.Index).xy;
|
||||
burstAt.Add(length(float2(e.Position.x, e.Position.z) - centre));
|
||||
});
|
||||
|
||||
for (var shot = 0; shot < 12; shot++)
|
||||
{
|
||||
FireControl.Fire(rig.Gun, rig.GunItem, rig.Shooter);
|
||||
Run(rig, .02f);
|
||||
}
|
||||
|
||||
Assert.InRange(rig.Resolved.Count(o => o.Hit), 1, 12);
|
||||
Assert.NotEmpty(burstAt);
|
||||
Assert.All(burstAt, d => Assert.True(d < 1e-2f, $"blast was {d} from the rock's centre"));
|
||||
}
|
||||
|
||||
// A rock that no longer exists when its round arrives, broken in flight, resolves as a miss, like a target that
|
||||
// left the zone: nothing is worn and nothing absorbs.
|
||||
[Fact]
|
||||
public void ARockThatBreaksMidFlightIsAMiss()
|
||||
{
|
||||
var rig = Build(velocity: 50f, precision: 1000f);
|
||||
var absorbs = 0;
|
||||
rig.Zone.ChunkCapabilities.Absorb.Subscribe(_ => absorbs++);
|
||||
FireControl.Fire(rig.Gun, rig.GunItem, rig.Shooter);
|
||||
Assert.Empty(rig.Resolved);
|
||||
|
||||
Assert.True(rig.Zone.Wear(rig.Rock, 1e6f));
|
||||
Run(rig, 2.5f);
|
||||
|
||||
var outcome = Assert.Single(rig.Resolved);
|
||||
Assert.Equal(ShotResult.Miss, outcome.Result);
|
||||
Assert.Equal(0, absorbs);
|
||||
Assert.False(rig.Zone.ChunkExists(rig.Rock));
|
||||
}
|
||||
|
||||
// The shot's own dice: two zones built alike roll the same sequence of outcomes for the same shot ids.
|
||||
[Fact]
|
||||
public void RockDiceAreTheShotsOwn()
|
||||
{
|
||||
List<ShotResult> Roll()
|
||||
{
|
||||
var rig = Build(precision: 1f);
|
||||
for (var shot = 0; shot < 20; shot++)
|
||||
{
|
||||
FireControl.Fire(rig.Gun, rig.GunItem, rig.Shooter);
|
||||
Run(rig, .02f);
|
||||
}
|
||||
return rig.Resolved.Select(o => o.Result).ToList();
|
||||
}
|
||||
|
||||
var first = Roll();
|
||||
var second = Roll();
|
||||
Assert.Equal(20, first.Count);
|
||||
Assert.Contains(ShotResult.Hit, first);
|
||||
Assert.Contains(ShotResult.Miss, first);
|
||||
Assert.Equal(first, second);
|
||||
}
|
||||
|
||||
// A rock's velocity is the pose function's derivative, derived on every read.
|
||||
[Fact]
|
||||
public void ARockMovesAtItsPoseVelocity()
|
||||
{
|
||||
var rig = Build();
|
||||
var velocity = rig.Zone.ChunkVelocity(rig.Rock);
|
||||
var ahead = rig.Zone.ChunkPose(rig.Rock.Field, rig.Rock.Index, rig.Zone.Time + .5).xy;
|
||||
var now = rig.Zone.ChunkPose(rig.Rock.Field, rig.Rock.Index).xy;
|
||||
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