diff --git a/tests/Aetheria.Shared.Tests/ConsumableAiTests.cs b/tests/Aetheria.Shared.Tests/ConsumableAiTests.cs index 6ad889fda..2f5863958 100644 --- a/tests/Aetheria.Shared.Tests/ConsumableAiTests.cs +++ b/tests/Aetheria.Shared.Tests/ConsumableAiTests.cs @@ -50,6 +50,7 @@ public sealed class ConsumableAiTests : IDisposable public GearData HeavyGun; public CultRecordRef Maker; public float Optimum; + public CultRecordKey[] Circuit; public void Store(ConsumableItemData design) => Assert.True(Hold.TryStore((ItemInstance) Items.CreateInstance(Items.CreateLot(design, Maker, .5f)))); @@ -97,7 +98,7 @@ public sealed class ConsumableAiTests : IDisposable } }; - private Scene Build(bool carryVent = false, bool carryOverdrive = false, bool carryDecoy = false, int stackableVents = 0, float effective = 500f) + private Scene Build(bool carryVent = false, bool carryOverdrive = false, bool carryDecoy = false, int stackableVents = 0, float effective = 500f, uint? runSeed = null, int orbits = 1) { var cache = AetheriaStores.Open(Path.Combine(_root, Guid.NewGuid().ToString("N") + ".cc"), catalogWritable: true); _caches.Add(cache); @@ -150,7 +151,10 @@ public sealed class ConsumableAiTests : IDisposable var maker = cache.RefOf(cache.GetByName("Maker")); EquippableItem Make(string name) where T : CraftedItemData => (EquippableItem) items.CreateInstance(items.CreateLot(cache.GetByName(name), maker, .5f)); - var zone = new Zone(items, new PlanetSettings(), new ZonePack(), new GalaxyZone { Name = "Test Zone", Owner = null }, null); + var galaxy = runSeed.HasValue ? RunSeedFixture.Continue(cache, "Test Zone", runSeed.Value) : null; + var zone = galaxy != null + ? new Zone(items, new PlanetSettings(), new ZonePack(), galaxy.Zones[0], galaxy) + : new Zone(items, new PlanetSettings(), new ZonePack(), new GalaxyZone { Name = "Test Zone", Owner = null }, null); Ship NewShip(string gear) { var ship = new Ship(items, zone, Make("Skiff"), new EntitySettings()) @@ -174,8 +178,10 @@ public sealed class ConsumableAiTests : IDisposable // The agent joins as the zone admits a piloted ship (its Minion and CombatState come from production); the // locker is a gun ship nobody pilots. // One fixed orbit far from the fight, before the agent joins: a pilot that is not engaged patrols it, as production's would. - zone.Orbits.Add(new CultRecordKey("test-orbit"), new Orbit(new OrbitData { FixedPosition = float2(0, 5000) })); + for (var i = 0; i < orbits; i++) + zone.Orbits.Add(new CultRecordKey(orbits == 1 ? "test-orbit" : "test-orbit-" + i), new Orbit(new OrbitData { FixedPosition = float2(0, 5000) })); zone.Admit(scene.Agent, piloted: true); + scene.Circuit = ((PatrolOrbitsTask) zone.Agents.Single().Task).Circuit; zone.Admit(scene.Prey, piloted: false); zone.Admit(scene.Locker, piloted: false); // The flight is the only writer of the agent's Target: the agent senses the prey and holds a grudge on it, so the @@ -356,6 +362,25 @@ public sealed class ConsumableAiTests : IDisposable // The production path for the optimum: a ship the zone admits as piloted derives it from its gun's live stats // before it needs it, and re-derives it when its loadout changes. The gun's effective range is 500 and the // heavy gun's is 800, so the optimum moves with the weapons it has now. + // The run seed feeds drops and mines only (ruling run-seed-drops-only): the same pilot in the same zone samples its + // range with the same offset and draws the same patrol circuit at every run seed. Kills: the combat-sample dice or + // the patrol dice read DropSeed. + [Theory] + [InlineData(1u, 2u)] + [InlineData(0xC0FFEE42u, 0x2468ACE1u)] + public void ThePilotsDiceDoNotMoveWithTheRunSeed(uint first, uint second) + { + var a = Build(runSeed: first, orbits: 8); + var b = Build(runSeed: second, orbits: 8); + a.AssertInCombat(); + b.AssertInCombat(); + Assert.NotEqual(a.Zone.DropSeed, b.Zone.DropSeed); + Assert.Equal(a.Zone.CombatSeed, b.Zone.CombatSeed); + Assert.Equal(a.Optimum, b.Optimum); + Assert.Equal(4, a.Circuit.Length); + Assert.Equal(a.Circuit, b.Circuit); + } + [Fact] public void ASpawnedShipsOptimumFollowsItsWeaponsAndNeverReadsZero() { diff --git a/tests/Aetheria.Shared.Tests/RunSaveTests.cs b/tests/Aetheria.Shared.Tests/RunSaveTests.cs index 7e32c9928..456561d76 100644 --- a/tests/Aetheria.Shared.Tests/RunSaveTests.cs +++ b/tests/Aetheria.Shared.Tests/RunSaveTests.cs @@ -178,25 +178,25 @@ public sealed class RunSaveTests : IDisposable using (var cache = Open()) { var game = Game(cache); - game.Seed = 0xC0FFEEu; + game.Seed = 0xC0FFEE42u; RunSave.Commit(cache, game, Zones(2, StageZoneContents(cache), 0), new ProvenanceLedger()); } using (var cache = Open()) { var galaxy = new Galaxy(cache, cache.GetGlobal(), _ => { }); - Assert.Equal(0xC0FFEEu, galaxy.Seed); + Assert.Equal(0xC0FFEE42u, galaxy.Seed); var itemManager = new ItemManager(cache, new ProvenanceLedger(), TestSettings(), _ => { }); galaxy.Zones[0].Contents = new Zone(itemManager, new PlanetSettings(), new ZonePack(), galaxy.Zones[0], galaxy); // The zone's drop dice are its name's seed mixed with the run's. - Assert.Equal("Zone 0".StableHash() ^ SimulationDice.Mix(0xC0FFEEu), galaxy.Zones[0].Contents.DropSeed); + Assert.Equal("Zone 0".StableHash() ^ SimulationDice.Mix(0xC0FFEE42u), galaxy.Zones[0].Contents.DropSeed); var (game, zones) = RunSave.Capture(cache, galaxy, galaxy.Zones[0].Contents, null, new SavedActionBarBinding[0], 0); - Assert.Equal(0xC0FFEEu, game.Seed); + Assert.Equal(0xC0FFEE42u, game.Seed); RunSave.Commit(cache, game, zones, RunSave.Lots(cache)); } using (var cache = Open()) - Assert.Equal(0xC0FFEEu, cache.GetGlobal().Seed); + Assert.Equal(0xC0FFEE42u, cache.GetGlobal().Seed); // A save written before run-seed holds no seed, and continues on name-only drops. using (var cache = Open()) diff --git a/tests/Aetheria.Shared.Tests/RunStartTests.cs b/tests/Aetheria.Shared.Tests/RunStartTests.cs index 7c22bb911..4b181f67e 100644 --- a/tests/Aetheria.Shared.Tests/RunStartTests.cs +++ b/tests/Aetheria.Shared.Tests/RunStartTests.cs @@ -115,14 +115,26 @@ public sealed partial class RunStartTests : IDisposable private const float Freezing = 273.15f; - // One minter: a generated galaxy never reads the clock, so seed 0 is refused by both generation constructors. + // One minter: a generated galaxy never reads the clock, so seed 0 is refused by both generation constructors, naming + // the field and echoing no input (no ActualValue). The settings are the authored ones: a galaxy that stops refusing must be able to + // finish generating, so the test fails by assertion rather than wedging in the generator. [Fact] public void AGeneratedGalaxyRefusesSeedZero() { - Assert.Throws(() => - new Galaxy(new SectorGenerationSettings(), new SectorBackgroundSettings(), _cache, _ => { }, null, 0)); - Assert.Throws(() => - new Galaxy(new TutorialGenerationSettings(), new SectorBackgroundSettings(), _cache, new PlayerSettings(), new DirectoryInfo(_root), _ => { }, null, 0)); + var authored = AuthoredSettings.Load(FindRepoRoot()); + var background = authored.Read("SectorBackgroundSettings"); + var sector = authored.Read("SectorGenerationSettings"); + sector.ZoneCount = 8; + var tutorial = authored.Read("TutorialGenerationSettings"); + + var main = Assert.Throws(() => new Galaxy(sector, background, _cache, _ => { }, null, 0)); + var prelude = Assert.Throws(() => + new Galaxy(tutorial, background, _cache, new PlayerSettings(), new DirectoryInfo(_root), _ => { }, null, 0)); + foreach (var refusal in new[] { main, prelude }) + { + Assert.Equal("seed", refusal.ParamName); + Assert.Null(refusal.ActualValue); + } } // A main-sector galaxy: each station's gear must come from manufacturers its faction can reach, the makers its