From c622e192ae181856b6d9414436e9c8ddfd3968c1 Mon Sep 17 00:00:00 2001 From: soul Date: Sat, 28 Nov 2026 16:58:32 +0100 Subject: [PATCH] The demo starter is an authored Longinus fit: Light Lasers on its Energy mounts, the same on every seed demo-start-hull-longinus's default fit is the authored fit (economy-is-never-faked: a random loadout draw is interim). The generated draw rolled Cell Blasters, ammunition-fed on an Energy mount, on seeds 2 3 69 97 and they ended AmmoOut in 12 s; Light Laser is the mining gun. DemoTerminus.Starter stages it at StarterQuality; DemoPressureTests.EnterZone stages the same. The generator-replay test becomes the authored-starter test; the AmmoOut sortie test flies a test-local Cell Blaster scenario through EconomyLoop.Sortie's new scenario parameter. Co-Authored-By: Claude Sonnet 5.5 --- .../ServerShared/Scenarios/DemoTerminus.cs | 35 +++++++++++-- .../DemoPressureTests.cs | 2 +- .../DemoTerminusTests.cs | 36 ++++++++----- .../Aetheria.Shared.Tests/EconomyLoopTests.cs | 51 ++++++++++++++++++- tools/AetherDb/EconomyLoop.cs | 16 +++--- 5 files changed, 115 insertions(+), 25 deletions(-) diff --git a/Assets/Scripts/ServerShared/Scenarios/DemoTerminus.cs b/Assets/Scripts/ServerShared/Scenarios/DemoTerminus.cs index 91a00019c..d78fb3a70 100644 --- a/Assets/Scripts/ServerShared/Scenarios/DemoTerminus.cs +++ b/Assets/Scripts/ServerShared/Scenarios/DemoTerminus.cs @@ -1,12 +1,14 @@ using System.Collections.Generic; using System.Linq; using GameCult.Caching; +using static CultMath.math; +using static ItemRotation; using float2 = CultMath.float2; // The demo: one gate, one region and one boss, with a fixed cast. The Pirates are the protagonist's ostensible // employer, Zhestokost the antagonist whose home is the boss zone and the exit, Lucent Media and Aeronautics Unlimited -// the neutrals. A galaxy of that cast at half influence; the player, who is not a Pirate, flies the base Longinus. Its -// entrance holds two stations on every seed: Aeronautics Unlimited's Zenith trade hub and the Pirates' refinery. +// the neutrals. A galaxy of that cast at half influence; the player, who is not a Pirate, flies the authored Longinus of +// Starter, the same fit on every seed (ruling demo-start-hull-longinus). Its entrance holds two stations on every seed: Aeronautics Unlimited's Zenith trade hub and the Pirates' refinery. public sealed class DemoTerminus : Scenario { public static readonly GalaxyCast Cast = new GalaxyCast @@ -34,6 +36,31 @@ public sealed class DemoTerminus : Scenario public override string Brief => "One gate, one region, one boss. Allied: the Pirates. Opposed: Zhestokost. " + "Neutral: Lucent Media and Aeronautics Unlimited."; + // The quality of every lot of the starter: a sim-tuned knob (economy-numbers-are-sim-tuned-knobs), repair scales with it. + public const float StarterQuality = .5f; + + // The demo player's ship (ruling demo-start-hull-longinus, read by economy-is-never-faked: an authored fit, no random draw): + // the Longinus with its Light Lasers on the two Energy mounts, since a Cell Blaster there is ammunition-fed and the starter + // mines with its lasers. Everything else is the design the generator gives every seed, by product, at the generator's cells. + public static ScenarioFit Starter(ScenarioStage stage) => stage.Fit("Longinus", StarterQuality, + ("Wheelhouse", int2(2, 6), None), // Cockpit 2x2 + ("True North", int2(1, 0), Reversed), // Large Drive + ("True North", int2(3, 0), Reversed), // Large Drive + ("Hestia", int2(2, 4), None), // Compact Reactor + ("Homer", int2(0, 5), None), // Guided Missile Launcher + ("Homer", int2(5, 5), None), // Guided Missile Launcher + ("Stagecoach", int2(2, 14), CounterClockwise), // Medium Drive + ("Stagecoach", int2(3, 14), Clockwise), // Medium Drive + ("Spotlight", int2(1, 8), None), // Light Laser + ("Spotlight", int2(4, 8), None), // Light Laser + ("Iapyx", int2(2, 2), CounterClockwise), // Radiator + ("Iapyx", int2(3, 2), Clockwise), // Radiator + ("not if i see you first", int2(3, 10), None), // Compact Sensor + ("PotaT+-", int2(1, 5), None), // Capacitor + ("👀🎯", int2(1, 6), None), // Targeting Computer + ("Space Tractor", int2(1, 7), None), // Tractor Beam + ("Pithos", int2(2, 8), None)); // Cargo Bay + public override Galaxy Generate(GalaxyStage stage) { var galaxy = stage.Cast(Cast); @@ -50,7 +77,7 @@ public sealed class DemoTerminus : Scenario galaxy.FactionRelationships[galaxy.ResolveFaction(Cast.BufferFaction)] = FactionRelationship.Neutral; foreach (var neutral in Cast.NeutralFactions) galaxy.FactionRelationships[galaxy.ResolveFaction(neutral)] = FactionRelationship.Neutral; - stage.Player(stage.Generated("Longinus"), float2.zero); + stage.Player(Starter(stage), float2.zero); // Zenith's silo buys the ores the refinery's gear draws (ruling demo-zenith-ore-depot), by a standing order to the // refinery, and a hauler of Zenith's faction carries it (ore-haul-run). @@ -61,6 +88,8 @@ public sealed class DemoTerminus : Scenario var ores = StationWants.Of(refinery).Where(good => FieldKinds.IsOre(items.ItemData, items.ItemData.Get(new CultRecordRef(good)))) .OrderBy(good => good.Value, System.StringComparer.Ordinal).Select(good => new CultRecordRef(good)); stage.HaulOrder("demo-terminus-ore", zenith, refinery, ores, "scenario:demo-terminus"); + // Interim scaffolding (economy-is-never-faked): the hauler's draw is deleted when an Aeronautics Unlimited shipyard in the + // region's chain (demo-chain-spans-the-region) builds it. stage.Hauler(stage.Generated(null, zenith.Faction), "demo-terminus-ore", stage.Arena.GetOrbitPosition(zenith.OrbitData)); } } diff --git a/tests/Aetheria.Shared.Tests/DemoPressureTests.cs b/tests/Aetheria.Shared.Tests/DemoPressureTests.cs index 850e19b36..9a8f1a9f0 100644 --- a/tests/Aetheria.Shared.Tests/DemoPressureTests.cs +++ b/tests/Aetheria.Shared.Tests/DemoPressureTests.cs @@ -286,7 +286,7 @@ public sealed partial class RunStartTests stage.Galaxy.FactionRelationships[stage.Galaxy.ResolveFaction(DemoTerminus.Cast.BufferFaction)] = FactionRelationship.Neutral; foreach (var neutral in DemoTerminus.Cast.NeutralFactions) stage.Galaxy.FactionRelationships[stage.Galaxy.ResolveFaction(neutral)] = FactionRelationship.Neutral; - stage.Player(stage.Generated("Longinus"), float2.zero); + stage.Player(DemoTerminus.Starter(stage), float2.zero); }), _startingHull, failures); Assert.True(failures.Count == 0, string.Join("; ", failures)); arena.Update(0); diff --git a/tests/Aetheria.Shared.Tests/DemoTerminusTests.cs b/tests/Aetheria.Shared.Tests/DemoTerminusTests.cs index ec36ebb68..b0df8cd0d 100644 --- a/tests/Aetheria.Shared.Tests/DemoTerminusTests.cs +++ b/tests/Aetheria.Shared.Tests/DemoTerminusTests.cs @@ -139,24 +139,34 @@ public sealed partial class RunStartTests } } - // The ruling says the Longinus with its default fit: the fit the game generates for that hull from the run's item - // draws, which Stage seeds from the galaxy's seed. The expected fit is that same generation replayed from the same - // seed, so no item list is spelled here; a bare hull, a preset, or one item swapped for another differs from it. + // The ruling's default fit is the authored one (economy-is-never-faked): the Longinus with Light Lasers on its Energy mounts, the same + // products at the same cells on every seed, every lot at StarterQuality. The Cell Blaster is ammunition-fed on an Energy mount and spends its + // crates in seconds, so no Energy-mount weapon may draw ammunition. Kills: a Generated player (the brands and the Energy pair roll per seed), + // Spotlight swapped for Strobe (Cell Blaster), a different quality. [Fact] - public void DemoTerminus_player_carries_the_longinus_default_fit() + public void DemoTerminus_player_carries_the_authored_starter() { - string Fit(Entity ship) => string.Join(";", ship.Equipment - .Select(item => $"{item.Data.Name}@{item.Position}/{item.EquippableItem.Rotation}") - .OrderBy(entry => entry, StringComparer.Ordinal)); + var expected = new[] + { + "Wheelhouse@2,6/None", "True North@1,0/Reversed", "True North@3,0/Reversed", "Hestia@2,4/None", "Homer@0,5/None", "Homer@5,5/None", + "Stagecoach@2,14/CounterClockwise", "Stagecoach@3,14/Clockwise", "Spotlight@1,8/None", "Spotlight@4,8/None", + "Iapyx@2,2/CounterClockwise", "Iapyx@3,2/Clockwise", "not if i see you first@3,10/None", "PotaT+-@1,5/None", + "👀🎯@1,6/None", "Space Tractor@1,7/None", "Pithos@2,8/None" + }.OrderBy(entry => entry, StringComparer.Ordinal).ToArray(); foreach (var seed in DemoSeeds) { - var (galaxy, arena, staged, failures) = Launch(new DemoTerminus(), Inputs(() => seed)); + var (_, _, staged, failures) = Launch(new DemoTerminus(), Inputs(() => seed)); Assert.True(failures.Count == 0, string.Join("; ", failures)); - _items.Random = new CultMath.Random(galaxy.Seed * 0x9E3779B1u + 2); - var generator = new LoadoutGenerator(ref _items.Random, _items, galaxy, arena.GalaxyZone, null, 2); - var expected = EntitySerializer.Unpack(_items, null, generator.GenerateShipLoadout(hull => hull.Name == "Longinus")); - Assert.NotEmpty(expected.Equipment); - Assert.Equal(Fit(expected), Fit(staged.Player)); + var player = staged.Player; + var slots = player.Equipment.Concat(player.CargoBays).Where(item => item != player.EquippedHull).Distinct().ToArray(); + var got = string.Join(" | ", slots.Select(item => + $"{_cache.Get(_items.GetLot(item.EquippableItem).Product).Name}@{item.Position.x},{item.Position.y}/{item.EquippableItem.Rotation}") + .OrderBy(entry => entry, StringComparer.Ordinal).ToArray()); + Assert.True(got == string.Join(" | ", expected), "seed " + seed + ": " + got); + Assert.All(slots, item => Assert.Equal(DemoTerminus.StarterQuality, _items.GetLot(item.EquippableItem).Quality, 3)); + var energy = player.Weapons.Where(weapon => player.Hardpoints[weapon.Item.Position.x, weapon.Item.Position.y]?.Type == HardpointType.Energy).ToArray(); + Assert.Equal(2, energy.Length); + Assert.All(energy, weapon => Assert.False(weapon.WeaponData.AmmoType.IsSet(), $"seed {seed}: {weapon.Item.Data.Name} on an Energy mount draws ammunition")); } } diff --git a/tests/Aetheria.Shared.Tests/EconomyLoopTests.cs b/tests/Aetheria.Shared.Tests/EconomyLoopTests.cs index 8ade9b7f4..cc0c9d32b 100644 --- a/tests/Aetheria.Shared.Tests/EconomyLoopTests.cs +++ b/tests/Aetheria.Shared.Tests/EconomyLoopTests.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using static CultMath.math; using Xunit; // The player-loop section of `economy balance --loop` (EconomyLoop): rates from hand samples, minutes to afford, the ladder band and @@ -269,12 +270,44 @@ public sealed class EconomyLoopTests Assert.Equal(0, sample.AmmoSpent); } + // The demo's galaxy and entrance stations with the starter's fit, Cell Blasters in place of its Light Lasers, as the player: an ammunition-fed fit on the Energy + // mounts, which no shipped scenario flies any more (the demo starter carries Light Lasers). Test-local, so no shipped scenario has a seam. + private sealed class CellBlasterDemo : Scenario + { + private readonly DemoTerminus _demo = new DemoTerminus(); + public override string Name => "Cell Blaster demo"; + public override string Id => "test-cell-blaster-demo"; + public override string Brief => "The demo's zone, flown in an ammunition-fed fit."; + public override IReadOnlyList EntranceStations => _demo.EntranceStations; + public override Galaxy Generate(GalaxyStage stage) => _demo.Generate(stage); + + public override void Stage(ScenarioStage stage) => stage.Player(stage.Fit("Longinus", DemoTerminus.StarterQuality, + ("Wheelhouse", int2(2, 6), ItemRotation.None), + ("True North", int2(1, 0), ItemRotation.Reversed), + ("True North", int2(3, 0), ItemRotation.Reversed), + ("Hestia", int2(2, 4), ItemRotation.None), + ("Homer", int2(0, 5), ItemRotation.None), + ("Homer", int2(5, 5), ItemRotation.None), + ("Stagecoach", int2(2, 14), ItemRotation.CounterClockwise), + ("Stagecoach", int2(3, 14), ItemRotation.Clockwise), + ("FastBlast+-", int2(1, 8), ItemRotation.None), // Cell Blaster, ammunition-fed on an Energy mount + ("FastBlast+-", int2(4, 8), ItemRotation.None), + ("Iapyx", int2(2, 2), ItemRotation.CounterClockwise), + ("Iapyx", int2(3, 2), ItemRotation.Clockwise), + ("not if i see you first", int2(3, 10), ItemRotation.None), + ("PotaT+-", int2(1, 5), ItemRotation.None), + ("👀🎯", int2(1, 6), ItemRotation.None), + ("Space Tractor", int2(1, 7), ItemRotation.None), + ("Pithos", int2(2, 8), ItemRotation.None)), float2(0, 0)); + } + [Fact] public void ASortieThatSpendsItsStarterAmmunitionEndsAmmoOutAndPaysForIt() { var ammoLeft = -1; var sample = EconomyLoop.Sortie(Root, 2, 0, 150, (ship, items, _) => - ammoLeft = ship.CargoBays.SelectMany(bay => bay.Cargo.Keys.OfType()).Where(c => items.GetData(c).Name == "Ammo").Sum(c => c.Quantity)); + ammoLeft = ship.CargoBays.SelectMany(bay => bay.Cargo.Keys.OfType()).Where(c => items.GetData(c).Name == "Ammo").Sum(c => c.Quantity), + new CellBlasterDemo()); Assert.Equal(LoopOutcome.AmmoOut, sample.Outcome); Assert.Equal(0, ammoLeft); // The Cell Blaster fit starts with 3 Ammo, bought back at the catalog's price. @@ -282,6 +315,22 @@ public sealed class EconomyLoopTests Assert.True(sample.SimSeconds < 150); } + // The demo's own starter, flown on the seeds a player meets first (1 2 3 69 97), mines with its lasers and never runs dry. Seed 2's second belt + // is unlit (a zone cause, follow_up demo-entrance-holds-no-lit-belt), a RigFault. Kills: the base Generated starter, whose Cell Blasters + // spent their 3 crates in 11-13 s on seeds 2 3 69 97 (AmmoOut). + [Fact] + public void EveryDemoSeedStarterCompletesASortie() + { + foreach (var seed in new uint[] { 1, 2, 3, 69, 97 }) + { + var samples = EconomyLoop.Sorties(Root, seed, 150); + Assert.DoesNotContain(samples, x => x.Outcome == LoopOutcome.AmmoOut); + Assert.Contains(samples, x => x.Outcome == LoopOutcome.Full || x.Outcome == LoopOutcome.Capped); + Assert.All(samples, x => Assert.True(x.Outcome != LoopOutcome.RigFault || seed == 2 && x.Belt == 1, $"seed {seed} belt {x.Belt}: {x.Outcome} {x.Note}")); + Assert.All(samples.Where(x => x.Outcome != LoopOutcome.RigFault), x => Assert.Equal(0, x.AmmoSpent)); + } + } + [Fact] public void EveryBeltOfTheZoneIsItsOwnSampleAndAnUnlitOneIsARigFault() { diff --git a/tools/AetherDb/EconomyLoop.cs b/tools/AetherDb/EconomyLoop.cs index 4d4ee1dd8..7c2cb134a 100644 --- a/tools/AetherDb/EconomyLoop.cs +++ b/tools/AetherDb/EconomyLoop.cs @@ -115,8 +115,9 @@ public static class EconomyLoop // The demo run of one seed booted in a scratch of its own, with the two stations found by what they are for. Everything it // touches is its own: a scratch copy of the catalog, its own run store and its own ItemManager (a shared one advances its - // Random and gave the same seed different results). Dispose closes the store and deletes the scratch. - public static DemoArena Boot(string root, uint seed) + // Random and gave the same seed different results). Dispose closes the store and deletes the scratch. scenario defaults to the demo; a test + // passes its own to fly another fit through the same zone. + public static DemoArena Boot(string root, uint seed, Scenario scenario = null) { var scratch = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "aetherdb-loop-" + Guid.NewGuid().ToString("N"))).FullName; var demo = new DemoArena(scratch); @@ -132,15 +133,16 @@ public static class EconomyLoop var startingHull = File.ReadLines(Path.Combine(root, "Assets", "Resources", "Settings.asset")) .Select(line => Regex.Match(line, @"^ StartingHullName: (.+)$")).First(match => match.Success).Groups[1].Value.Trim(); - var scenario = new DemoTerminus(); + scenario ??= new DemoTerminus(); var stage = new GalaxyStage(authored.Read("SectorGenerationSettings"), authored.Read("SectorBackgroundSettings"), authored.Read("CastBackgroundSettings"), cache, _ => { }, null, () => seed); var galaxy = RunStart.Generate(scenario, stage); var arena = demo.Arena = new Zone(items, planetSettings, RunStart.GenerateArena(items, zoneSettings, planetSettings, galaxy, scenario), galaxy.Entrance, galaxy); var failures = new List(); - demo.Player = RunStart.Stage(items, arena, scenario, startingHull, failures).Player; - if (failures.Count > 0) throw new InvalidOperationException($"seed {seed}: staging failed: {string.Join("; ", failures)}"); + var staged = RunStart.Stage(items, arena, scenario, startingHull, failures); + if (failures.Count > 0 || staged == null) throw new InvalidOperationException($"seed {seed}: staging failed: {string.Join("; ", failures)}"); + demo.Player = staged.Player; // The station that buys a sortie's ore and the one that holds it for onward haul, found by what they are for. OrbitalEntity OfKind(string kind) => arena.Entities.OfType().Single(entity => entity.Kind.Key.Equals(StationKindData.KeyOf(kind))); demo.Processing = OfKind("processing"); @@ -159,10 +161,10 @@ public static class EconomyLoop // at the cap. Everything it touches is its own: a scratch copy of the catalog, its own run store and its own ItemManager (a // shared one advances its Random and gave the same seed different results). atEnd, if given, sees the ship, items and the processing station as the // sample is taken, so a test can read the same state the sample was priced from. - public static LoopSample Sortie(string root, uint seed, int beltIndex, float capSeconds, Action atEnd = null) + public static LoopSample Sortie(string root, uint seed, int beltIndex, float capSeconds, Action atEnd = null, Scenario scenario = null) { if (!float.IsFinite(capSeconds) || capSeconds <= 0) throw new ArgumentOutOfRangeException(nameof(capSeconds), "the cap must be a positive, finite number of sim seconds"); - using var demo = Boot(root, seed); + using var demo = Boot(root, seed, scenario); var (cache, items, arena, player, processing) = (demo.Cache, demo.Items, demo.Arena, demo.Player, demo.Processing); var belts = arena.Planets.Where(body => body.Value is AsteroidBeltData).ToList();