diff --git a/GameData/Aetheria.cc b/GameData/Aetheria.cc index 3a467909f..6c3965b19 100644 --- a/GameData/Aetheria.cc +++ b/GameData/Aetheria.cc @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a44ecdd4d4b470cc67534dd21234da41096ed2d246927be486d45c240164d790 -size 12728634 +oid sha256:b60cefa2308d9794ae481232c427c9149427f950c17a09e4a13e5381ce8e0623 +size 12728590 diff --git a/tests/Aetheria.Shared.Tests/SmokeRoundsCommandTests.cs b/tests/Aetheria.Shared.Tests/SmokeRoundsCommandTests.cs index 716a41c39..7dd04c2f1 100644 --- a/tests/Aetheria.Shared.Tests/SmokeRoundsCommandTests.cs +++ b/tests/Aetheria.Shared.Tests/SmokeRoundsCommandTests.cs @@ -1,8 +1,10 @@ using System; using System.IO; +using System.Collections.Generic; using System.Linq; using GameCult.Caching; using GameCult.Caching.MessagePack; +using MessagePack; using Xunit; // AetherDb's smoke-rounds command (aetheria-release, cut scenarios-smoke-rounds), run on a scratch copy of the shipped catalog @@ -14,6 +16,13 @@ public sealed class SmokeRoundsCommandTests : IDisposable private readonly string _root = Path.Combine(Path.GetTempPath(), "smoke-rounds-command-" + Guid.NewGuid().ToString("N")); private string CatalogPath => Path.Combine(_root, "GameData", "Aetheria.cc"); + // The five designs as the shipped catalog holds them, taken before they are removed from the scratch copy: apply must write + // exactly these, so the command stays the replay of what ships. + private readonly Dictionary _shipped = new Dictionary(); + + private static byte[] Pack(WeaponItemData design) => + MessagePackSerializer.Serialize(design, CultDocumentMessagePackSerialization.OptionsFor(typeof(WeaponItemData).Assembly)); + public SmokeRoundsCommandTests() { Directory.CreateDirectory(Path.Combine(_root, "GameData")); @@ -23,7 +32,12 @@ public sealed class SmokeRoundsCommandTests : IDisposable File.Copy(Path.Combine(shipped, "Assets", "Resources", "Settings.asset"), Path.Combine(_root, "Assets", "Resources", "Settings.asset")); using var cache = new CultCache(TestCatalog.Registry()); cache.AddBackingStore(new SingleFileMessagePackBackingStore(CatalogPath), AetheriaStores.CatalogTypes); - foreach (var weapon in cache.GetAll().Where(w => Names.Contains(w.Name)).ToArray()) Assert.True(cache.Remove(cache.RefOf(weapon).Key)); + foreach (var weapon in cache.GetAll().Where(w => Names.Contains(w.Name)).ToArray()) + { + _shipped[weapon.Name] = Pack(weapon); + Assert.True(cache.Remove(cache.RefOf(weapon).Key)); + } + Assert.Equal(Names.OrderBy(n => n), _shipped.Keys.OrderBy(n => n)); cache.FlushAsync().Wait(); } @@ -59,6 +73,10 @@ public sealed class SmokeRoundsCommandTests : IDisposable Assert.Equal(Names.OrderBy(n => n), smoke.Select(w => w.Name).OrderBy(n => n)); Assert.Equal(0, products); + // Replaying the command on the catalog without them writes the records the shipped catalog holds (the record keys are + // CultCache's to mint and differ run to run; the designs do not). + foreach (var design in smoke) Assert.True(_shipped[design.Name].AsSpan().SequenceEqual(Pack(design)), $"{design.Name} differs from the shipped catalog's record"); + WeaponItemData Design(string name) => smoke.Single(w => w.Name == name); WeaponData Data(string name) => Design(name).Behaviors.OfType().Single(); diff --git a/tests/Aetheria.Shared.Tests/SmokeRoundsScenarioTests.cs b/tests/Aetheria.Shared.Tests/SmokeRoundsScenarioTests.cs index eaf07de29..bfd412452 100644 --- a/tests/Aetheria.Shared.Tests/SmokeRoundsScenarioTests.cs +++ b/tests/Aetheria.Shared.Tests/SmokeRoundsScenarioTests.cs @@ -159,4 +159,15 @@ public sealed partial class RunStartTests } Assert.True(carried > 100, "the generated ships carried no gear to check"); } + + // New Game lists the three arenas. The census (EveryScenario) is built from the same listing, so only a read of the listing + // itself notices an arena dropped from it. + [Fact] + public void NewGameListsTheThreeSmokeRoundsArenas() + { + var listed = Scenarios.Tests.Select(scenario => scenario.Name).ToArray(); + Assert.Contains(new FusedRounds().Name, listed); + Assert.Contains(new RefusedRounds().Name, listed); + Assert.Contains(new AiFusedDiscipline().Name, listed); + } } diff --git a/tests/Aetheria.Shared.Tests/SmokeRoundsSteppedTests.cs b/tests/Aetheria.Shared.Tests/SmokeRoundsSteppedTests.cs new file mode 100644 index 000000000..56ba8a169 --- /dev/null +++ b/tests/Aetheria.Shared.Tests/SmokeRoundsSteppedTests.cs @@ -0,0 +1,129 @@ +using System.Collections.Generic; +using System.Linq; +using UniRx; +using Xunit; +using static CultMath.math; + +// aetheria-release, cut scenarios-smoke-rounds: the Fused Rounds and AI Fused Discipline arenas flown, stepped through +// Zone.Update with the production fire path (Activate, the weapons' Execute, FireControl.Step), each against a control that +// shows the harness fires when the rule allows it. SmokeRoundsScenarioTests reads what the arenas stage; this reads what they do. +public sealed partial class RunStartTests +{ + private const float SteppedDt = .05f; + + private (Zone Arena, RunStart.Staged Staged) LaunchStepped(Scenario scenario) + { + var (_, arena, staged, failures) = Launch(scenario, Inputs(() => GalaxySeed)); + Assert.True(failures.Count == 0, string.Join("; ", failures)); + staged.Player.GenerateWeaponGroups(); + EvSettle(staged.Player); + return (arena, staged); + } + + // Fused Rounds, nothing selected, the player aiming down the bare hull ahead. The DeathCluster is the control: it fires + // in this arena, so a fused weapon that does not is not a harness that cannot fire. A fused round flies slowly enough + // to be in the air when the direct weapon kills the fragile hull (check A.3) and bursts on the first hull on the aim line. + [Theory] + [InlineData("DeathCluster")] + [InlineData("Smoke Proximity")] + [InlineData("Smoke Delayed")] + public void EveryWeaponAboardFiresInTheSteppedFusedRoundsArena(string design) + { + var (arena, staged) = LaunchStepped(new FusedRounds()); + var player = staged.Player; + var weapon = (InstantWeapon) WeaponOf(Carried(player, design)); + player.Aim = float3(0, 0, 1); + var fired = new List(); + var committed = new List<(float At, ShotOutcome Outcome)>(); + weapon.OnFire += _ => fired.Add(arena.Time); + using var subscription = arena.ShotCommitted.Subscribe(outcome => committed.Add((arena.Time, outcome))); + + weapon.Activate(); + for (var i = 0; i < 60; i++) arena.Update(SteppedDt); + + Assert.True(fired.Count > 0, $"{design} fired nothing in 3 s; the ship's reactor is {(player.PowerBus.TotalGeneration > 0f ? "running" : "down")}"); + if (design == "DeathCluster") return; + var (at, burst) = committed.First(); + Assert.Equal(ShotResult.Burst, burst.Result); + Assert.True(burst.HasBurstPoint); + var reach = length(burst.BurstPoint - player.Position.xz); + Assert.InRange(reach, FusedRounds.Ahead.y - 30f, FusedRounds.Ahead.y); // on the first hull in the way, not at max range + Assert.InRange(at + burst.ArrivalIn - fired[0], 1f, 5f); // in the air for seconds: not resolved in its firing tick, not minutes of flight + } + + // Check A.3 flown: the fragile hull is selected, a Smoke Proximity round is fired at it and the DeathCluster kills it + // before the round lands, so the round never bursts. + [Fact] + public void TheDirectWeaponKillsTheFragileHullWhileASmokeRoundIsStillInTheAir() + { + var (arena, staged) = LaunchStepped(new FusedRounds()); + var player = staged.Player; + var fragile = staged.Entities[2]; + Assert.Equal(FusedRounds.Fragile, fragile.Position.xz); + player.SetTarget(fragile); + player.SetIff(fragile, true); + player.EntityInfoGathered[fragile] = 1f; + var proximity = Carried(player, "Smoke Proximity"); + (float At, ShotResult Result)? landed = null; + using var subscription = arena.ShotResolved.Subscribe(outcome => + { + if (landed == null && outcome.Weapon == proximity) landed = (arena.Time, outcome.Result); + }); + + WeaponOf(proximity).Activate(); + WeaponOf(Carried(player, "DeathCluster")).Activate(); + float? deadAt = null; + for (var i = 0; i < 120 && landed == null; i++) + { + arena.Update(SteppedDt); + if (deadAt == null && !arena.Entities.Contains(fragile)) deadAt = arena.Time; + } + + Assert.NotNull(deadAt); + Assert.NotNull(landed); + Assert.True(deadAt <= landed.Value.At, $"the round landed at {landed.Value.At:F2} s, before the fragile hull died at {deadAt:F2} s"); + Assert.NotEqual(ShotResult.Burst, landed.Value.Result); + } + + // AI Fused Discipline, run for two minutes, against its two controls. The hostile closes on the player and never fires its + // refused weapon; the neutral never fires its fused one. Each silence is discipline, not inability: the same hostile + // fires once its weapon's Range reaches its blast radius, and the same neutral fires once it is hostile to the player. + [Fact] + public void TheAiHoldsARefusedWeaponAndANeutralHoldsItsFusedOne() + { + (int Hostile, int Neutral, float Closest) Fly(System.Action alter = null) + { + var (arena, staged) = LaunchStepped(new AiFusedDiscipline()); + var (hostile, neutral) = (staged.Entities[0], staged.Entities[1]); + alter?.Invoke(hostile, neutral, staged.Player); + int hostileShots = 0, neutralShots = 0; + using var subscription = arena.ShotCommitted.Subscribe(outcome => + { + if (outcome.Source == hostile) hostileShots++; + else if (outcome.Source == neutral) neutralShots++; + }); + var closest = float.MaxValue; + for (var i = 0; i < 1200; i++) + { + arena.Update(.1f); + closest = min(closest, length((hostile.Position - staged.Player.Position).xz)); + } + return (hostileShots, neutralShots, closest); + } + + var shipped = Fly(); + Assert.Equal((0, 0), (shipped.Hostile, shipped.Neutral)); + Assert.True(shipped.Closest < 100f, $"the hostile never closed on the player (nearest {shipped.Closest:F0} m)"); + + // Control: the hostile's weapon given the reach to arm. The design's data is shared, so it is put back. + var refused = _cache.GetAll().Single(design => design.Name == "Smoke Refused").Behaviors.OfType().Single(); + var range = refused.Range; + refused.Range = new PerformanceStat { Min = 2000f, Max = 2000f }; + try { Assert.True(Fly().Hostile > 0, "the hostile fires nothing even when its weapon can arm: the arena cannot show it holding fire"); } + finally { refused.Range = range; } + + // Control: the neutral made hostile to the player, both ways. + Assert.True(Fly((hostile, neutral, player) => { neutral.SetIff(player, true); player.SetIff(neutral, true); }).Neutral > 0, + "the neutral fires nothing even when hostile: the arena cannot show it holding fire"); + } +}