EconomyLoop.Boot builds the arena through RunStart and can materialize the region; DemoArena gains Galaxy and ParkHaulers

Galaxy.Entrance.Contents is now the arena (it was a Zone built beside the galaxy). region: true calls RunStart.Materialize after staging. Sortie and drain readings are unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-11-28 22:56:19 +01:00
commit 33bdf92a2f
2 changed files with 22 additions and 9 deletions

View file

@ -117,13 +117,10 @@ public static class EconomyDrain
if (!double.IsFinite(horizonHours) || horizonHours <= 0) throw new ArgumentOutOfRangeException(nameof(horizonHours), "the horizon must be a positive, finite number of sim hours");
using var demo = EconomyLoop.Boot(root, seed);
var catalog = demo.Cache;
// The demo's hauler flies orders on screen and has no span-side model (follow-up drain-haul-throughput; off-screen hauling is
// region-haul-legs), so it is parked in both paths: taken out of the arena before the fill, the window and the spans.
var haulers = demo.Arena.Entities.OfType<Ship>().Where(ship => ship.Haul.Key.IsSet()).ToList();
foreach (var hauler in haulers)
if (demo.Arena.Remove(hauler)) hauler.Deactivate();
// Parked in both paths: taken out of the arena before the fill, the window and the spans (DemoArena.ParkHaulers).
var parked = demo.ParkHaulers();
var usable = sorties.Where(s => s.Measured && s.Mined.Count > 0).ToList();
var sample = new DrainSample { Seed = seed, Parked = haulers.Count, Usable = usable.Count, Excluded = sorties.Except(usable).ToList(), WindowSeconds = windowSeconds, HorizonHours = horizonHours, Supplied = supplied };
var sample = new DrainSample { Seed = seed, Parked = parked, Usable = usable.Count, Excluded = sorties.Except(usable).ToList(), WindowSeconds = windowSeconds, HorizonHours = horizonHours, Supplied = supplied };
var stations = new[] { ("processing", demo.Processing), ("trade-hub", demo.Zenith) };
var runs = new List<StationRun>();
foreach (var (role, station) in stations)

View file

@ -116,8 +116,8 @@ 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. 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)
// passes its own to fly another fit through the same zone. region also materializes every other zone of the galaxy, as a run does after staging.
public static DemoArena Boot(string root, uint seed, Scenario scenario = null, bool region = false)
{
var scratch = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "aetherdb-loop-" + Guid.NewGuid().ToString("N"))).FullName;
var demo = new DemoArena(scratch);
@ -138,11 +138,15 @@ public static class EconomyLoop
authored.Read<SectorBackgroundSettings>("SectorBackgroundSettings"), authored.Read<SectorBackgroundSettings>("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);
RunStart.GenerateArena(items, zoneSettings, planetSettings, galaxy, scenario);
var arena = demo.Arena = RunStart.BuildArena(items, planetSettings, galaxy);
demo.Galaxy = galaxy;
var failures = new List<string>();
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;
// A region boot stages as RunStart.Begin does, then has every other zone of the galaxy generated and live.
if (region) RunStart.Materialize(items, zoneSettings, planetSettings, galaxy);
// 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<OrbitalEntity>().Single(entity => entity.Kind.Key.Equals(StationKindData.KeyOf(kind)));
demo.Processing = OfKind("processing");
@ -352,9 +356,21 @@ public sealed class DemoArena : IDisposable
public ItemManager Items;
public Zone Arena;
public Ship Player;
// The run's galaxy: Galaxy.Entrance.Contents is Arena, and a region boot has every other zone live (RunStart.Materialize).
public Galaxy Galaxy;
// The refinery that buys a sortie's ore, and the trade hub that holds ore for onward haul.
public OrbitalEntity Processing, Zenith;
// The demo's hauler flies orders on screen and has no span-side model (follow-up drain-haul-throughput; off-screen hauling is
// region-haul-legs): the harnesses that measure facilities take it out of the arena before anything else. Returns how many.
public int ParkHaulers()
{
var haulers = Arena.Entities.OfType<Ship>().Where(ship => ship.Haul.Key.IsSet()).ToList();
foreach (var hauler in haulers)
if (Arena.Remove(hauler)) hauler.Deactivate();
return haulers.Count;
}
public void Dispose()
{
(Cache as IDisposable)?.Dispose();