diff --git a/Assets/Scripts/ServerShared/RunStart.cs b/Assets/Scripts/ServerShared/RunStart.cs index 6278c0cbc..754c61a89 100644 --- a/Assets/Scripts/ServerShared/RunStart.cs +++ b/Assets/Scripts/ServerShared/RunStart.cs @@ -27,7 +27,7 @@ public static class RunStart { SeedItems(itemManager, galaxy, ArenaStep); return galaxy.Entrance.PackedContents = ZoneGenerator.GenerateZone( - itemManager, zoneSettings, planetSettings, galaxy, galaxy.Entrance, scenario.EntranceStation, scenario.Ambient); + itemManager, zoneSettings, planetSettings, galaxy, galaxy.Entrance, scenario.EntranceStations, scenario.Ambient); } // Runs a start and answers whether it produced a run: null, with the reason in `failures`, when `start` throws or diff --git a/Assets/Scripts/ServerShared/Scenario.cs b/Assets/Scripts/ServerShared/Scenario.cs index 4d0806597..1e970d9da 100644 --- a/Assets/Scripts/ServerShared/Scenario.cs +++ b/Assets/Scripts/ServerShared/Scenario.cs @@ -1,3 +1,6 @@ +using System; +using System.Collections.Generic; + // A scenario is one way to set up a new run (docs/scenarios-cut.md, R): a script, compiled with the game, that says // which galaxy to generate and what the run starts with. New Game lists them (Scenarios). RunStart runs one: it // generates the galaxy through GalaxyStage, the arena under Ambient, and admits what Stage placed through a @@ -27,9 +30,9 @@ public abstract class Scenario // declaration: nothing tests a scenario's type to decide saving. public virtual bool Saved => true; - // True: the arena's zone always gets a generated faction station with a docking bay, whatever its seed rolls - // (ZoneGenerator). False: its stations are rolled like any other zone's. - public virtual bool EntranceStation => true; + // The stations the arena's zone always gets, in slot order after its story stations, whatever its seed rolls + // (ZoneGenerator). Empty: its stations are rolled like any other zone's. + public virtual IReadOnlyList EntranceStations => EntranceStationOrder.Any; // Which galaxy the run is in: stage.Main() or stage.Cast(cast). public abstract Galaxy Generate(GalaxyStage stage); @@ -45,3 +48,17 @@ public enum ScenarioStance Neutral, Hostile } + +// One station a scenario's entrance zone must hold. Faction is a cast name Galaxy.ResolveFaction resolves (null: the zone's +// structure faction); Kind is a station-kind id, StationKindData.KeyOf (null: StationKinds.Choose picks one). +public sealed class EntranceStationOrder +{ + public string Faction { get; } + public string Kind { get; } + + public EntranceStationOrder(string faction, string kind) { Faction = faction; Kind = kind; } + + // One default order: the zone's structure faction, a chosen kind. + public static readonly IReadOnlyList Any = new[] { new EntranceStationOrder(null, null) }; + public static readonly IReadOnlyList None = Array.Empty(); +} diff --git a/Assets/Scripts/ServerShared/Scenarios/DemoTerminus.cs b/Assets/Scripts/ServerShared/Scenarios/DemoTerminus.cs index 7d8fbe330..beb86a59e 100644 --- a/Assets/Scripts/ServerShared/Scenarios/DemoTerminus.cs +++ b/Assets/Scripts/ServerShared/Scenarios/DemoTerminus.cs @@ -1,8 +1,10 @@ +using System.Collections.Generic; 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. +// 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. public sealed class DemoTerminus : Scenario { public static readonly GalaxyCast Cast = new GalaxyCast @@ -17,6 +19,14 @@ public sealed class DemoTerminus : Scenario InfluenceScale = .5f }; + // Zenith (ruling demo-zenith-ore-depot) and the Pirates' processing station (ruling demo-processing-station-buys-ore), + // named from the cast so the cast and the orders cannot drift. + public override IReadOnlyList EntranceStations { get; } = new[] + { + new EntranceStationOrder(Cast.NeutralFactions[0], "trade-hub"), + new EntranceStationOrder(Cast.ProtagonistFaction, "processing") + }; + public override string Name => "Terminus (Demo)"; public override string Id => "demo-terminus"; public override string Brief => "One gate, one region, one boss. Allied: the Pirates. Opposed: Zhestokost. " + diff --git a/Assets/Scripts/ServerShared/Scenarios/MainGalaxy.cs b/Assets/Scripts/ServerShared/Scenarios/MainGalaxy.cs index d8a484b7b..3f7e4b1df 100644 --- a/Assets/Scripts/ServerShared/Scenarios/MainGalaxy.cs +++ b/Assets/Scripts/ServerShared/Scenarios/MainGalaxy.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using float2 = CultMath.float2; // The full galaxy: factions drawn from the catalog, bosses on the road to the exit, entered in the starting hull. @@ -7,7 +8,7 @@ public sealed class MainGalaxy : Scenario public override string Id => "main-galaxy"; public override string Brief => "The full galaxy: factions drawn at random, bosses guarding the road to the exit."; - public override bool EntranceStation => false; + public override IReadOnlyList EntranceStations => EntranceStationOrder.None; public override Galaxy Generate(GalaxyStage stage) => stage.Main(); diff --git a/Assets/Scripts/ServerShared/ZoneGenerator.cs b/Assets/Scripts/ServerShared/ZoneGenerator.cs index ada967f1d..7d34e48ef 100644 --- a/Assets/Scripts/ServerShared/ZoneGenerator.cs +++ b/Assets/Scripts/ServerShared/ZoneGenerator.cs @@ -7,6 +7,7 @@ using System.Collections; using System.Collections.Generic; using System.Globalization; using System.Linq; +using GameCult.Caching; using MessagePack; using UniRx; using CultMath; @@ -35,6 +36,8 @@ public static class ZoneGenerator private const int MaximumPlacementSamples = 32; + // entranceStations: the stations the scenario's arena must hold (Scenario.EntranceStations); the orders apply only + // when galaxyZone == galaxy.Entrance, null or empty rolls the zone's stations like any other's. // ambient: false keeps the planets, orbits and stations but generates no ship and no turret, so nothing wanders // into a scenario's authored conditions (docs/scenarios-cut.md, 2.1). The rule is applied here, not by pruning. public static ZonePack GenerateZone( @@ -43,7 +46,7 @@ public static class ZoneGenerator PlanetSettings planetSettings, Galaxy galaxy, GalaxyZone galaxyZone, - bool entranceStation = false, + IReadOnlyList entranceStations = null, bool ambient = true) { var pack = new ZonePack(); @@ -303,12 +306,30 @@ public static class ZoneGenerator // Enemy count below is based on this pre-override value, so the entrance station zone doesn't gain an enemy // just because its station got forced. var baseStationCount = stationCount; - // Operator ruling, 2026-09-25 (docs/locomotion-cut.md): a scenario that declares an entrance station - // (Scenario.EntranceStation) gets a generated faction station with a docking bay in its entrance zone, - // deterministically. A cast galaxy's halved influence and its lowest-influence unowned Entrance otherwise roll + // Operator ruling, 2026-09-25 (docs/locomotion-cut.md): a scenario that declares entrance stations + // (Scenario.EntranceStations) gets them in its entrance zone, deterministically, one per order after the story + // stations. A cast galaxy's halved influence and its lowest-influence unowned Entrance otherwise roll // stationCount 0 on every seed. galaxy.Entrance is reference-identity, not a name comparison. - var isEntranceStation = entranceStation && galaxyZone == galaxy.Entrance; - if (isEntranceStation && stationCount < 1) stationCount = 1; + var orders = galaxyZone == galaxy.Entrance && entranceStations != null ? entranceStations : Array.Empty(); + var orderFactions = new Faction[orders.Count]; + var orderKinds = new CultRecordRef[orders.Count]; + for (var o = 0; o < orders.Count; o++) + { + if (orders[o].Faction != null) + { + orderFactions[o] = galaxy.ResolveFaction(orders[o].Faction); + if (orderFactions[o] == null || !galaxy.Factions.Contains(orderFactions[o])) + throw new InvalidOperationException($"Entrance station order faction {orders[o].Faction} is not in the galaxy."); + } + if (orders[o].Kind != null) + { + orderKinds[o] = new CultRecordRef(StationKindData.KeyOf(orders[o].Kind)); + if (cache.Get(orderKinds[o]) == null) + throw new InvalidOperationException($"Entrance station order kind {orders[o].Kind} is not in the catalog."); + } + } + var required = storyStations.Length + orders.Count; + if (orders.Count > 0 && stationCount < required) stationCount = required; // A station's source is a well-bearing body alone on its ring whose rail clears every massive sibling's extent (the // sibling's support, or its Roche margin if more) and the largest reach of any station or turret hull: whatever hull // is built there, its Lagrange orbit then sits clear of any other body. @@ -324,21 +345,29 @@ public static class ZoneGenerator // (the rail, how far a body on it keeps others out, whether it is a station's own orbit rather than a base's) var sources = candidates.Skip(candidates.Length / 2).Take(stationCount) .Select(p => (orbit: orbitMap[p], extent: Extent(p), direct: false)).ToArray(); - if (isEntranceStation && candidates.Length == 0) + if (orders.Count > 0 && sources.Length < required) { - // The entrance gets a station whatever its bodies: it orbits a root node beyond its ring group (or, for a body, its - // whole family), never at a ring member's distance, and sits there, not at a Lagrange point. + // An order the rails cannot seat orbits a root node beyond its ring group (or, for a body, its whole family), never at + // a ring member's distance, and sits there, not at a Lagrange point. The shortfall shares the first one's phase + // (drawn once) spread evenly round the turn. var roots = planets.Where(p => p.Parent == null).ToList(); var rootNode = roots.FirstOrDefault(p => p.Children.Count > 0) ?? (roots.Count > 1 ? roots.OrderByDescending(p => p.Mass).First() : null); if (rootNode == null) throw new InvalidOperationException( - "The entrance station zone must always get a station, but it has no candidate orbit at all -- every planet in the zone is a parentless root."); + "The entrance station zone must always get its stations, but it has no candidate orbit at all -- every planet in the zone is a parentless root."); var distance = rootNode.Empty ? (1 + GravityField.RingReach) * GravityField.Beta * rootNode.Children.Where(Massive).Min(c => c.Distance) : Extent(rootNode); - var direct = new OrbitData { Parent = cache.RefOf(orbitMap[rootNode]), Distance = distance, Phase = random.NextFloat() }; - pack.Orbits.Add(cache.Upsert(direct)); - sources = new[] { (orbit: direct, extent: float.NegativeInfinity, direct: true) }; + var shortfall = required - sources.Length; + var phase = random.NextFloat(); + var withDirect = sources.ToList(); + for (var k = 0; k < shortfall; k++) + { + var direct = new OrbitData { Parent = cache.RefOf(orbitMap[rootNode]), Distance = distance, Phase = phase + (float) k / shortfall }; + pack.Orbits.Add(cache.Upsert(direct)); + withDirect.Add((orbit: direct, extent: float.NegativeInfinity, direct: true)); + } + sources = withDirect.ToArray(); } var selectedStationOrbits = sources.Select(x => x.orbit).ToArray(); var extentOf = sources.ToDictionary(x => x.orbit, x => x.extent); @@ -446,14 +475,19 @@ public static class ZoneGenerator var orbit = selectedStationOrbits[i]; var security = (SecurityLevel) ((int) ((1f - pow(random.NextFloat(), factionPresence / 2f)) * 3f)); + var slot = i - storyStations.Length; + var isOrder = slot < orders.Count; + var slotFaction = isOrder && orderFactions[slot] != null ? orderFactions[slot] : structureFaction; + var slotKind = isOrder && orders[slot].Kind != null + ? orderKinds[slot] + : StationKinds.Choose(cache, slotFaction, $"{seed}:station:{i}", itemManager.Log); var lagrangeOrbit = CreateLagrangeOrbit(orbit); - var station = GetLoadoutGenerator(structureFaction).GenerateStationLoadout( - StationKinds.Choose(cache, structureFaction, $"{seed}:station:{i}", itemManager.Log)); + var station = GetLoadoutGenerator(slotFaction).GenerateStationLoadout(slotKind); if (station == null) { - if (isEntranceStation) + if (isOrder) throw new InvalidOperationException( - $"The entrance station zone must always get a station, but {structureFaction?.Name} has no station loadout to generate."); + $"The entrance station order for {slotFaction?.Name} ({slotKind.Key}) must always get a station, but it has no station loadout to generate."); continue; } station.Orbit = cache.RefOf(lagrangeOrbit); @@ -461,7 +495,7 @@ public static class ZoneGenerator station.SecurityRadius = pack.Radius; pack.Entities.Add(station); - if (ambient) PlaceTurrets(lagrangeOrbit, GetLoadoutGenerator(structureFaction), 2, StationReach(station), orbit); + if (ambient) PlaceTurrets(lagrangeOrbit, GetLoadoutGenerator(slotFaction), 2, StationReach(station), orbit); } // A boss zone gets its faction's boss whether or not the zone is ambient: the boss is the run's goal, not diff --git a/docs/aetheria-release-map.md b/docs/aetheria-release-map.md index 8ffe59163..b02dbd624 100644 --- a/docs/aetheria-release-map.md +++ b/docs/aetheria-release-map.md @@ -865,7 +865,7 @@ deletes the flag with no behaviour change except where named. to its owner: - influence halving -> the cast's own `InfluenceScale` (the demo's cast sets .5, so its galaxy is unchanged), carried by the Galaxy and the save (key 15) because later zones read it (PR2); -- the entrance station -> `Scenario.EntranceStation`, a declaration beside `Ambient`, default true, +- the entrance station -> `Scenario.EntranceStations`, a declaration beside `Ambient`, a list of `EntranceStationOrder` (default one), false for MainGalaxy, so every scenario's arena is unchanged; RunStart.GenerateArena applies it; - availability -> the general rule of gear-without-presence; - the save flag -> deleted (key 11 retired; ruling `no-save-compatibility-before-players`). @@ -899,7 +899,7 @@ name. Per ruling `no-save-compatibility-before-players` nothing reads key 11. | EmojiOne sample | none | Deleted by `emoji-font` | none | | Galaxy cast (replaces `TutorialGenerationSettings`) | A scenario's code constant (`DemoTerminus.Cast`) | Compiled with the game; no authored settings copy | The scenario | | `Galaxy.InfluenceScale` | Its galaxy | Set by the constructor (the cast's value, 1 for main), saved as `SavedGame` key 15 | The cast | -| `Scenario.EntranceStation` | Its scenario | Compiled | The scenario; `RunStart` applies it | +| `Scenario.EntranceStations` | Its scenario | Compiled | The scenario; `RunStart` applies it | | `SavedGame` key 11 (`IsTutorial`) | Retired | Not read, not written | none | | `Galaxy.IsPrelude`, `TutorialGalaxy`, `TutorialGenerationSettings`, `GameSettings.TutorialGenerationSettings` | Deleted by `retire-prelude` | | none | diff --git a/docs/merge-to-master-checklist.md b/docs/merge-to-master-checklist.md index 664f464b2..5d8e5ad33 100644 --- a/docs/merge-to-master-checklist.md +++ b/docs/merge-to-master-checklist.md @@ -33,7 +33,7 @@ Compiled 2026-09-29 by Eyes from the maps on the branch. Pointers are `doc:line` ### 2b. Fresh launch (no `run.cc`, no `player.cc`) 3. **Launch to main menu.** Expect no Addressables errors, and the Groups window shows `Assets/Content` under `Default Local Group` (`addressables-cut.md:301`). `player.cc` appears and Continue is disabled (`cultcache-migration-cut.md:2746`). Proves: Addressables Cut 1, CultCache cutover. The 09-17 smoke covered the last two on the old tree; this is a cheap recheck on the new schema. -4. **New Game, then a scenario.** New Game opens the scenario picker (`MainMenu.ShowScenarios`); a development build lists modes (Terminus (Demo)), development (Main Galaxy) and test arenas, a release build lists only the modes. Pick Terminus (Demo). Expect the galaxy generates and the start ship is the Longinus (`settings-globals-cut.md:498`, an expectation, not a recorded check for this stack). Expect a Zenith station with a docking bay in the entrance zone every time, because the scenario declares `EntranceStation` (`locomotion-cut.md:375`). Proves: locomotion Cut 1 station rule. +4. **New Game, then a scenario.** New Game opens the scenario picker (`MainMenu.ShowScenarios`); a development build lists modes (Terminus (Demo)), development (Main Galaxy) and test arenas, a release build lists only the modes. Pick Terminus (Demo). Expect the galaxy generates and the start ship is the Longinus (`settings-globals-cut.md:498`, an expectation, not a recorded check for this stack). Expect Zenith (Aeronautics Unlimited trade hub) and the Pirates refinery in the entrance zone every time, because the scenario declares `EntranceStations` (`locomotion-cut.md:375`). Proves: locomotion Cut 1 station rule. 5. **Addressables, "Use Asset Database".** Ships, turret and Zenith spawn; thruster and aether-drive particles show; fire an instant weapon (Autocannon) and a charged one (ChargeBlast SG); action bar icons show (`addressables-cut.md:362-366`). Proves: Addressables Cut 2. ### 2c. Flight, power and economy diff --git a/tests/Aetheria.Shared.Tests/ChildrenWithinReachTests.cs b/tests/Aetheria.Shared.Tests/ChildrenWithinReachTests.cs index 0d5c39c21..17255e703 100644 --- a/tests/Aetheria.Shared.Tests/ChildrenWithinReachTests.cs +++ b/tests/Aetheria.Shared.Tests/ChildrenWithinReachTests.cs @@ -50,7 +50,7 @@ public sealed class ChildrenWithinReachTests : IClassFixture("ZoneSettings"); tune?.Invoke(Settings); var pack = ZoneGenerator.GenerateZone(items, Settings, planetSettings, galaxy, galaxyZone, - true, false); + EntranceStationOrder.Any, false); foreach (var belt in pack.Planets.Select(cache.Get).OfType()) { Belts++; diff --git a/tests/Aetheria.Shared.Tests/DemoLoopTests.cs b/tests/Aetheria.Shared.Tests/DemoLoopTests.cs index 64da07c56..460c58483 100644 --- a/tests/Aetheria.Shared.Tests/DemoLoopTests.cs +++ b/tests/Aetheria.Shared.Tests/DemoLoopTests.cs @@ -10,7 +10,7 @@ using UniRx; using Xunit; // The demo loop on the shipped catalog (aetheria-release, mining 5a): the player's own gun breaks a rock -// through the trigger, the ore lands in the hold, the Pirates' one station (a depot stand-in, so the Arsenal Depot hull) buys it, repairs the hull and sells a unit back. +// through the trigger, the ore lands in the hold, the Pirates' refinery buys it and repairs the hull, and Zenith, Aeronautics Unlimited's trade hub, sells a unit back. public sealed partial class RunStartTests { [Fact] @@ -56,12 +56,13 @@ public sealed partial class RunStartTests Assert.All(gains, gain => Assert.Equal((GainKind.Mined, 0), (gain.Kind, gain.Adrift))); Assert.Equal(held.Sum(h => h.stack.Quantity), gains.Sum(gain => gain.Stored)); - var zenith = arena.Entities.Single(entity => entity.HullData.HullType == HullType.Station); + var refinery = StationOfKind(arena, "processing"); + var zenith = StationOfKind(arena, "trade-hub"); var credits = 0; - // Every mined stack goes in one sale: the market takes it all, whatever the full hold of Zenith has room for. + // Every mined stack goes in one sale: the market takes it all, whatever the full hold of the refinery has room for. var value = StationServices.OreValue(_items, player.CargoBays); Assert.True(value > 0); - Assert.Equal(gains.Sum(gain => gain.Stored), StationServices.TrySellOre(player.CargoBays, zenith, ref credits)); + Assert.Equal(gains.Sum(gain => gain.Stored), StationServices.TrySellOre(player.CargoBays, refinery, ref credits)); Assert.Equal(value, credits); Assert.DoesNotContain(player.CargoBays.SelectMany(bay => bay.Cargo.Keys.OfType()), c => ores.Contains(_items.GetData(c).Name)); @@ -76,11 +77,11 @@ public sealed partial class RunStartTests Assert.Equal(paid, credits); Assert.Equal(player.MaxArmor[cell.x, cell.y], player.Armor[cell.x, cell.y]); - // Zenith's whole stock is one 16-cell reactor, which fits only an empty 4x4: the player jettisons what the hold - // still carries, then buys it. + // Zenith's smallest piece may need an empty hold: the player jettisons what the hold still carries, then buys it. var hold = player.CargoBays[0]; foreach (var leftover in hold.Cargo.Keys.ToArray()) hold.Remove(leftover); - var stock = zenith.CargoBays.SelectMany(bay => bay.Cargo.Keys.OfType().Select(piece => (bay, piece))).Single(); + var stock = zenith.CargoBays.SelectMany(bay => bay.Cargo.Keys.OfType().Select(piece => (bay, piece))) + .MinBy(held => _items.GetData(held.piece).Shape.Cells.Cast().Count(occupied => occupied)); credits = StationServices.BuyPrice(_items, stock.piece); Assert.Equal(BuyResult.Bought, StationServices.TryBuy(_items, stock.piece, 1, ref credits, () => stock.bay.TryTransferItem(hold, stock.piece, 1))); @@ -98,6 +99,10 @@ public sealed partial class RunStartTests // design-bills (V 282.149, repair 55404, cheapest authored price 15500), and the band is 1/sqrt(10) to sqrt(10) of each, the // geometric midpoint between the shipped reading and the least mutant this test claims to catch (a divisor of ten on either side, a // ratio of 10 or 0.1): the shipped reading and that mutant each sit 3.16x from a bound. + // The one station of a kind in the arena: the demo's two stations are told apart by what they are for, never by hull. + private static OrbitalEntity StationOfKind(Zone arena, string kind) => + arena.Entities.OfType().Single(entity => entity.Kind.Key.Equals(StationKindData.KeyOf(kind))); + private const double BaseRepairRatio = 0.0050925, BaseBuyRatio = 0.018203; private static readonly double Margin = Math.Sqrt(10); @@ -116,7 +121,7 @@ public sealed partial class RunStartTests for (var y = 0; y < player.MaxArmor.GetLength(1); y++) player.Armor[x, y] = 0; var repair = StationServices.RepairCost(_items, player); - var zenith = arena.Entities.Single(entity => entity.HullData.HullType == HullType.Station); + var zenith = StationOfKind(arena, "trade-hub"); var cheapest = zenith.CargoBays.SelectMany(bay => bay.Cargo.Keys.OfType()).Min(piece => _items.GetData(piece).Price); Assert.True(repair > 0 && cheapest > 0); diff --git a/tests/Aetheria.Shared.Tests/DemoPressureTests.cs b/tests/Aetheria.Shared.Tests/DemoPressureTests.cs index 00a7def34..0c6ea5245 100644 --- a/tests/Aetheria.Shared.Tests/DemoPressureTests.cs +++ b/tests/Aetheria.Shared.Tests/DemoPressureTests.cs @@ -17,7 +17,7 @@ public sealed partial class RunStartTests private sealed record ZoneRow(int Index, int Jumps, double Depth, DemoPressure.Pressure Asked, int Hostiles, int Friendly, string[] HostileHulls, int[] HostilePrices); // The demo's own declaration, as RunStart.GenerateArena passes it: the entrance zone gets its station. - private static bool DemoEntranceStation => new DemoTerminus().EntranceStation; + private static IReadOnlyList DemoEntranceStations => new DemoTerminus().EntranceStations; // Every zone of the demo galaxy as the generator builds it. Hostile means the antagonist's ships, the one cast faction // the player is Hated by. @@ -28,7 +28,7 @@ public sealed partial class RunStartTests var antagonist = galaxy.Antagonist; return galaxy.Zones.Select((zone, index) => { - var pack = ZoneGenerator.GenerateZone(_items, _zoneSettings, _planetSettings, galaxy, zone, DemoEntranceStation); + var pack = ZoneGenerator.GenerateZone(_items, _zoneSettings, _planetSettings, galaxy, zone, DemoEntranceStations); var ships = pack.Entities.OfType().ToArray(); // The boss is the run's goal, placed apart from the pressure. var hostile = ships.Where(ship => _cache.Get(ship.Faction) == antagonist && !ship.Boss).ToArray(); @@ -154,11 +154,11 @@ public sealed partial class RunStartTests var (galaxy, _, _, _) = Launch(new DemoTerminus(), Inputs(() => seed)); foreach (var zone in Ring(galaxy)) { - var pack = ZoneGenerator.GenerateZone(_items, _zoneSettings, _planetSettings, galaxy, zone, DemoEntranceStation); + var pack = ZoneGenerator.GenerateZone(_items, _zoneSettings, _planetSettings, galaxy, zone, DemoEntranceStations); var hostile = pack.Entities.Where(entity => IsHated(galaxy, entity.Faction)).Select(entity => entity.GetType().Name + ":" + _items.GetData(entity.Hull).Name).ToArray(); Assert.True(hostile.Length == 0, $"seed {seed} zone {Array.IndexOf(galaxy.Zones, zone)} (jump {galaxy.Entrance.Distance[zone]}): {string.Join(", ", hostile)}"); } - var entrance = ZoneGenerator.GenerateZone(_items, _zoneSettings, _planetSettings, galaxy, galaxy.Entrance, DemoEntranceStation); + var entrance = ZoneGenerator.GenerateZone(_items, _zoneSettings, _planetSettings, galaxy, galaxy.Entrance, DemoEntranceStations); Assert.Contains(entrance.Entities.OfType(), entity => entity.Kind.IsSet()); } } @@ -180,7 +180,7 @@ public sealed partial class RunStartTests // The depth term itself: where no hostile would be drawn anyway (the curve's own ramp is 0 there), grace is // what moves the antagonist's stations and turrets away, so it is asserted, not left to the generated zone. Assert.True(DemoPressure.InGrace(galaxy, zone), $"seed {seed} zone {Array.IndexOf(galaxy.Zones, zone)} (jump {e}, depth {e / (e + x):0.00}) is not in grace"); - var pack = ZoneGenerator.GenerateZone(_items, _zoneSettings, _planetSettings, galaxy, zone, DemoEntranceStation); + var pack = ZoneGenerator.GenerateZone(_items, _zoneSettings, _planetSettings, galaxy, zone, DemoEntranceStations); var hostile = pack.Entities.Where(entity => IsHated(galaxy, entity.Faction)).Select(entity => entity.GetType().Name + ":" + _items.GetData(entity.Hull).Name).ToArray(); Assert.True(hostile.Length == 0, $"seed {seed} zone {Array.IndexOf(galaxy.Zones, zone)} (jump {e}, depth {e / (e + x):0.00}): {string.Join(", ", hostile)}"); } @@ -222,10 +222,10 @@ public sealed partial class RunStartTests var mid = galaxy.Zones.Where(zone => zone != near && zone != galaxy.Exit && DemoPressure.Of(galaxy, zone).Hostiles > 0) .MinBy(zone => Math.Abs(DemoPressure.Depth(galaxy, zone) - .5f)); Assert.NotNull(mid); - var raiders = ZoneGenerator.GenerateZone(_items, _zoneSettings, _planetSettings, galaxy, mid, DemoEntranceStation) + var raiders = ZoneGenerator.GenerateZone(_items, _zoneSettings, _planetSettings, galaxy, mid, DemoEntranceStations) .Entities.OfType().Where(ship => !ship.Boss && _cache.Get(ship.Faction) == zhestokost).ToArray(); Assert.Equal(DemoPressure.Of(galaxy, mid).Hostiles, raiders.Length); - ZoneGenerator.GenerateZone(_items, _zoneSettings, _planetSettings, galaxy, galaxy.Exit, DemoEntranceStation); + ZoneGenerator.GenerateZone(_items, _zoneSettings, _planetSettings, galaxy, galaxy.Exit, DemoEntranceStations); } // A galaxy with no gate antagonist keeps the nearest faction's patrol even where BossZones is filled (Main Galaxy's bosses): @@ -263,7 +263,7 @@ public sealed partial class RunStartTests var restored = new Galaxy(_cache, _cache.GetGlobal(), _ => { }); Assert.Null(restored.Antagonist); - string[] Hulls(Galaxy g, int index) => ZoneGenerator.GenerateZone(_items, _zoneSettings, _planetSettings, g, g.Zones[index], DemoEntranceStation) + string[] Hulls(Galaxy g, int index) => ZoneGenerator.GenerateZone(_items, _zoneSettings, _planetSettings, g, g.Zones[index], DemoEntranceStations) .Entities.OfType().Select(ship => _items.GetData(ship.Hull).Name).ToArray(); var deep = DemoZones(1).Where(row => row.Asked.Hostiles >= 3).ToArray(); Assert.NotEmpty(deep); @@ -274,7 +274,7 @@ public sealed partial class RunStartTests // adjust edits the generated pack before the arena is built. private (Zone arena, Ship player) EnterZone(Galaxy galaxy, GalaxyZone zone, Action adjust = null) { - var pack = ZoneGenerator.GenerateZone(_items, _zoneSettings, _planetSettings, galaxy, zone, DemoEntranceStation); + var pack = ZoneGenerator.GenerateZone(_items, _zoneSettings, _planetSettings, galaxy, zone, DemoEntranceStations); adjust?.Invoke(pack); var arena = new Zone(_items, _planetSettings, pack, zone, galaxy); var failures = new List(); @@ -353,7 +353,7 @@ public sealed partial class RunStartTests RunSave.Commit(_cache, game, zones, _items.Lots); var restored = new Galaxy(_cache, _cache.GetGlobal(), _ => { }); - string[] Hulls(Galaxy g, int index) => ZoneGenerator.GenerateZone(_items, _zoneSettings, _planetSettings, g, g.Zones[index], DemoEntranceStation) + string[] Hulls(Galaxy g, int index) => ZoneGenerator.GenerateZone(_items, _zoneSettings, _planetSettings, g, g.Zones[index], DemoEntranceStations) .Entities.OfType().Select(ship => _items.GetData(ship.Hull).Name).ToArray(); var deep = DemoZones(1).Where(row => row.Hostiles >= 3).ToArray(); Assert.NotEmpty(deep); diff --git a/tests/Aetheria.Shared.Tests/DemoTerminusTests.cs b/tests/Aetheria.Shared.Tests/DemoTerminusTests.cs index 21a761fdd..ec36ebb68 100644 --- a/tests/Aetheria.Shared.Tests/DemoTerminusTests.cs +++ b/tests/Aetheria.Shared.Tests/DemoTerminusTests.cs @@ -24,6 +24,30 @@ public sealed partial class RunStartTests DemoGalaxy(seed).Factions.Select(faction => faction.Name)); } + // The entrance declares its stations as orders (ruling demo-zenith-ore-depot, demo-processing-station-buys-ore): on every seed, + // Aeronautics Unlimited's trade hub on Zenith and the Pirates' processing station with its Refinery, apart by at least their reaches. + [Fact] + public void DemoEntranceHoldsZenithAndTheRefinery() + { + var cellSize = _items.GameplaySettings.SchematicCellSize; + foreach (var seed in Enumerable.Range(1, 40).Select(s => (uint) s).Concat(new uint[] { 69, 97 })) + { + var (_, arena, _, failures) = Launch(new DemoTerminus(), Inputs(() => seed)); + Assert.True(failures.Count == 0, $"seed {seed}: " + string.Join("; ", failures)); + arena.Update(.02f); // the stations take their places on their orbits + var stations = arena.Entities.OfType().Where(entity => entity.HullData.HullType == HullType.Station).ToArray(); + Assert.True(stations.Length == 2, $"seed {seed}: {stations.Length} stations"); + var hub = stations.Single(station => station.Kind.Key.Equals(StationKindData.KeyOf("trade-hub"))); + var refinery = stations.Single(station => station.Kind.Key.Equals(StationKindData.KeyOf("processing"))); + Assert.Equal("Aeronautics Unlimited", hub.Faction.Name); + Assert.Equal("Pirates", refinery.Faction.Name); + Assert.Contains(refinery.Equipment, equipped => equipped.Behaviors.OfType().Any() && _items.GetData(equipped.EquippableItem).Name == "Refinery"); + var apart = math.length(hub.Position.xz - refinery.Position.xz); + var reaches = hub.HullData.Reach(cellSize) + refinery.HullData.Reach(cellSize); + Assert.True(apart >= reaches, $"seed {seed}: stations {apart} apart against a reach sum of {reaches}"); + } + } + [Fact] public void DemoTerminus_gate_at_antagonist_home() { diff --git a/tests/Aetheria.Shared.Tests/MiningCut3Tests.cs b/tests/Aetheria.Shared.Tests/MiningCut3Tests.cs index 77c19deab..fdaeaceb6 100644 --- a/tests/Aetheria.Shared.Tests/MiningCut3Tests.cs +++ b/tests/Aetheria.Shared.Tests/MiningCut3Tests.cs @@ -863,7 +863,7 @@ public sealed partial class MiningCut3Tests : IDisposable var items = new ItemManager(1u, cache, new ProvenanceLedger(), GameSettings(), _ => { }); foreach (var zone in galaxy.Zones.Take(4)) { - var pack = ZoneGenerator.GenerateZone(items, RestoredHullsTests.TutorialZoneSettings(), RestoredHullsTests.AuthoredPlanetSettings(), galaxy, zone, entranceStation: zone == galaxy.Entrance); + var pack = ZoneGenerator.GenerateZone(items, RestoredHullsTests.TutorialZoneSettings(), RestoredHullsTests.AuthoredPlanetSettings(), galaxy, zone, entranceStations: EntranceStationOrder.Any); foreach (var body in pack.Planets) { if (!(cache.Get(body) is AsteroidBeltData belt)) continue; @@ -906,7 +906,7 @@ public sealed partial class MiningCut3Tests : IDisposable catch (Exception) { return null; } var items = new ItemManager(1u, cache, new ProvenanceLedger(), GameSettings(), _ => { }); return galaxy.Zones.Take(6).SelectMany(zone => - ZoneGenerator.GenerateZone(items, RestoredHullsTests.TutorialZoneSettings(), RestoredHullsTests.AuthoredPlanetSettings(), galaxy, zone, entranceStation: zone == galaxy.Entrance) + ZoneGenerator.GenerateZone(items, RestoredHullsTests.TutorialZoneSettings(), RestoredHullsTests.AuthoredPlanetSettings(), galaxy, zone, entranceStations: EntranceStationOrder.Any) .Planets.Select(body => cache.Get(body)).OfType().Select(belt => cache.Get(belt.Kind).Name)) .ToArray(); } diff --git a/tests/Aetheria.Shared.Tests/OrbitsFromFieldTests.cs b/tests/Aetheria.Shared.Tests/OrbitsFromFieldTests.cs index ffe29bbc1..9ed9a32cd 100644 --- a/tests/Aetheria.Shared.Tests/OrbitsFromFieldTests.cs +++ b/tests/Aetheria.Shared.Tests/OrbitsFromFieldTests.cs @@ -256,7 +256,7 @@ public sealed class OrbitsFromFieldTests : IDisposable cache, _ => { }, null, seed); var items = new ItemManager(1u, cache, new ProvenanceLedger(), authored.Read("GameplaySettings"), _ => { }); var pack = ZoneGenerator.GenerateZone(items, authored.Read("ZoneSettings"), authored.Read("PlanetSettings"), galaxy, galaxy.Entrance, - true, false); + EntranceStationOrder.Any, false); var zone = new Zone(items, authored.Read("PlanetSettings"), pack, galaxy.Entrance, galaxy); var hosting = zone.Planets.Values.Select(body => body.Orbit.Key).ToHashSet(); diff --git a/tests/Aetheria.Shared.Tests/OreGeographyTests.cs b/tests/Aetheria.Shared.Tests/OreGeographyTests.cs index d354f1904..dadd29448 100644 --- a/tests/Aetheria.Shared.Tests/OreGeographyTests.cs +++ b/tests/Aetheria.Shared.Tests/OreGeographyTests.cs @@ -932,7 +932,7 @@ public sealed class OreGeographyTests : IDisposable { foreach (var zone in galaxy.Zones.Take(zones)) { - var pack = ZoneGenerator.GenerateZone(items, RestoredHullsTests.TutorialZoneSettings(), RestoredHullsTests.AuthoredPlanetSettings(), galaxy, zone, entranceStation: zone == galaxy.Entrance); + var pack = ZoneGenerator.GenerateZone(items, RestoredHullsTests.TutorialZoneSettings(), RestoredHullsTests.AuthoredPlanetSettings(), galaxy, zone, entranceStations: EntranceStationOrder.Any); foreach (var belt in pack.Planets.Select(body => cache.Get(body)).OfType()) yield return (belt, zone, pack); } diff --git a/tests/Aetheria.Shared.Tests/RestoredHullsTests.cs b/tests/Aetheria.Shared.Tests/RestoredHullsTests.cs index f33e11a46..f1251b606 100644 --- a/tests/Aetheria.Shared.Tests/RestoredHullsTests.cs +++ b/tests/Aetheria.Shared.Tests/RestoredHullsTests.cs @@ -150,7 +150,7 @@ public sealed class RestoredHullsTests var galaxy = new Galaxy(TestCasts.Wide, TestCasts.Background, cache, _ => { }, null, seed); foreach (var zone in galaxy.Zones.Where(z => !ReferenceEquals(z, galaxy.Entrance))) { - var orbits = ParentedPlanetOrbits(cache, ZoneGenerator.GenerateZone(items, TutorialZoneSettings(), AuthoredPlanetSettings(), galaxy, zone, entranceStation: false, ambient: false)); + var orbits = ParentedPlanetOrbits(cache, ZoneGenerator.GenerateZone(items, TutorialZoneSettings(), AuthoredPlanetSettings(), galaxy, zone, entranceStations: EntranceStationOrder.None, ambient: false)); if (orbits.Length > 0 && !HasGenuineLagrangeCandidate(orbits)) return (seed, zone.Name); } } @@ -381,7 +381,7 @@ public sealed class RestoredHullsTests var galaxy = new Galaxy(tutorialSettings, background, cache, _ => { }, null, seed); var items = new ItemManager(1u, cache, new ProvenanceLedger(), Settings(), _ => { }); - var pack = ZoneGenerator.GenerateZone(items, zoneSettings, AuthoredPlanetSettings(), galaxy, galaxy.Entrance, entranceStation: true); + var pack = ZoneGenerator.GenerateZone(items, zoneSettings, AuthoredPlanetSettings(), galaxy, galaxy.Entrance, entranceStations: EntranceStationOrder.Any); var dockedStation = pack.Entities.OfType() .FirstOrDefault(e => (cache.Get(e.Hull.Data) as HullData)?.HullType == HullType.Station && e.DockingBays.Length > 0); @@ -421,7 +421,7 @@ public sealed class RestoredHullsTests var galaxy = new Galaxy(tutorialSettings, background, cache, _ => { }, null, seed); var items = new ItemManager(1u, cache, new ProvenanceLedger(), Settings(), _ => { }); - var pack = ZoneGenerator.GenerateZone(items, zoneSettings, AuthoredPlanetSettings(), galaxy, galaxy.Entrance, entranceStation: true); + var pack = ZoneGenerator.GenerateZone(items, zoneSettings, AuthoredPlanetSettings(), galaxy, galaxy.Entrance, entranceStations: EntranceStationOrder.Any); var planetOrbits = pack.Planets.Select(p => cache.Get(cache.Get(p).Orbit)).Where(o => o.Parent.IsSet()).ToArray(); var hasGenuineCandidate = planetOrbits.Any(o => planetOrbits.Count(c => c.Parent.Key.Equals(o.Parent.Key) && abs(c.Distance - o.Distance) < .1f) == 1); @@ -466,7 +466,7 @@ public sealed class RestoredHullsTests zoneSettings.SubZoneCount = new ExponentialLerp { Exponent = 1, Minimum = 0, Maximum = 0 }; Assert.Throws(() => - ZoneGenerator.GenerateZone(items, zoneSettings, AuthoredPlanetSettings(), galaxy, galaxy.Entrance, entranceStation: true)); + ZoneGenerator.GenerateZone(items, zoneSettings, AuthoredPlanetSettings(), galaxy, galaxy.Entrance, entranceStations: EntranceStationOrder.Any)); } finally { @@ -500,7 +500,7 @@ public sealed class RestoredHullsTests zoneSettings.SatelliteCreationProbability = 0; zoneSettings.BinaryCreationProbability = 0; - var pack = ZoneGenerator.GenerateZone(items, zoneSettings, AuthoredPlanetSettings(), galaxy, galaxy.Entrance, entranceStation: true); + var pack = ZoneGenerator.GenerateZone(items, zoneSettings, AuthoredPlanetSettings(), galaxy, galaxy.Entrance, entranceStations: EntranceStationOrder.Any); var roots = pack.Planets.Select(p => cache.Get(cache.Get(p).Orbit)).Count(o => !o.Parent.IsSet()); Assert.True(roots > 1, $"this fixture no longer produces a multi-root entrance (only {roots} root); it no longer tests the fragmented-topology case."); @@ -544,7 +544,7 @@ public sealed class RestoredHullsTests var galaxy = new Galaxy(tutorialSettings, background, cache, _ => { }, null, seed); var items = new ItemManager(1u, cache, new ProvenanceLedger(), Settings(), _ => { }); - var pack = ZoneGenerator.GenerateZone(items, zoneSettings, AuthoredPlanetSettings(), galaxy, galaxy.Entrance, entranceStation: true); + var pack = ZoneGenerator.GenerateZone(items, zoneSettings, AuthoredPlanetSettings(), galaxy, galaxy.Entrance, entranceStations: EntranceStationOrder.Any); var dockedStation = pack.Entities.OfType() .FirstOrDefault(e => (cache.Get(e.Hull.Data) as HullData)?.HullType == HullType.Station && e.DockingBays.Length > 0); @@ -738,7 +738,7 @@ public sealed class RestoredHullsTests var galaxy = BuildGalaxyWithForcedEntrance(cache, seed, zoneName); var items = new ItemManager(1u, cache, new ProvenanceLedger(), Settings(), _ => { }); - var pack = ZoneGenerator.GenerateZone(items, TutorialZoneSettings(), AuthoredPlanetSettings(), galaxy, galaxy.Entrance, entranceStation: true); + var pack = ZoneGenerator.GenerateZone(items, TutorialZoneSettings(), AuthoredPlanetSettings(), galaxy, galaxy.Entrance, entranceStations: EntranceStationOrder.Any); var station = pack.Entities.OfType() .FirstOrDefault(e => (cache.Get(e.Hull.Data) as HullData)?.HullType == HullType.Station && e.DockingBays.Length > 0); @@ -790,21 +790,21 @@ public sealed class RestoredHullsTests var galaxy = new Galaxy(TestCasts.Wide, TestCasts.Background, cache, _ => { }, null, seed: 1u); var items = new ItemManager(1u, cache, new ProvenanceLedger(), Settings(), _ => { }); - int StationCount(GalaxyZone zone, bool entranceStation) => - ZoneGenerator.GenerateZone(items, TutorialZoneSettings(), AuthoredPlanetSettings(), galaxy, zone, entranceStation) + int StationCount(GalaxyZone zone, IReadOnlyList entranceStations) => + ZoneGenerator.GenerateZone(items, TutorialZoneSettings(), AuthoredPlanetSettings(), galaxy, zone, entranceStations) .Entities.OfType() .Count(e => (cache.Get(e.Hull.Data) as HullData)?.HullType == HullType.Station); // (a) A non-entrance tutorial zone that naturally rolls zero stations keeps that roll under - // entranceStation: true -- the floor must not leak past the galaxy.Entrance reference check. - // The zone is chosen by its natural roll: zero stations without the tutorial floor (entranceStation: false). - var otherZone = galaxy.Zones.First(z => !ReferenceEquals(z, galaxy.Entrance) && StationCount(z, entranceStation: false) == 0); + // a default order -- the floor must not leak past the galaxy.Entrance reference check. + // The zone is chosen by its natural roll: zero stations without the tutorial floor (no orders). + var otherZone = galaxy.Zones.First(z => !ReferenceEquals(z, galaxy.Entrance) && StationCount(z, entranceStations: EntranceStationOrder.None) == 0); Assert.NotSame(galaxy.Entrance, otherZone); - Assert.Equal(0, StationCount(otherZone, entranceStation: true)); + Assert.Equal(0, StationCount(otherZone, entranceStations: EntranceStationOrder.Any)); - // (b) The entrance zone itself, generated for a non-tutorial game (entranceStation: false), keeps its - // natural roll too -- the floor must not leak past the entranceStation flag either. - Assert.Equal(0, StationCount(galaxy.Entrance, entranceStation: false)); + // (b) The entrance zone itself, generated for a non-tutorial game (no orders), keeps its + // natural roll too -- the floor must not leak past the declaration either. + Assert.Equal(0, StationCount(galaxy.Entrance, entranceStations: EntranceStationOrder.None)); } finally { @@ -815,7 +815,7 @@ public sealed class RestoredHullsTests // Cut 1 fix batch 2 (Soul's finding #2, baseStationCount): the entrance override raises stationCount (the // orbit-selection floor) but must not also raise the enemyCount roll, which is keyed to baseStationCount // (the pre-override value) precisely so the forced station doesn't buy the zone an extra enemy. Seed 1's - // entrance zone rolls baseStationCount 0 (confirmed via the entranceStation: false StationCount == 0 above) and + // entrance zone rolls baseStationCount 0 (confirmed via the entranceStations: EntranceStationOrder.None StationCount == 0 above) and // the override raises stationCount to 1; this pins the resulting ship count at the value baseStationCount // produces. It must fail if the enemy-count formula is changed to add stationCount instead (it would add a // ship instead of zero). @@ -830,7 +830,7 @@ public sealed class RestoredHullsTests var galaxy = new Galaxy(TestCasts.Wide, TestCasts.Background, cache, _ => { }, null, seed: 1u); var items = new ItemManager(1u, cache, new ProvenanceLedger(), Settings(), _ => { }); - var pack = ZoneGenerator.GenerateZone(items, TutorialZoneSettings(), AuthoredPlanetSettings(), galaxy, galaxy.Entrance, entranceStation: true); + var pack = ZoneGenerator.GenerateZone(items, TutorialZoneSettings(), AuthoredPlanetSettings(), galaxy, galaxy.Entrance, entranceStations: EntranceStationOrder.Any); var stationCount = pack.Entities.OfType().Count(e => (cache.Get(e.Hull.Data) as HullData)?.HullType == HullType.Station); // Soul's finding (this cut's fix batch 3): pack.Entities.OfType().Count() also counts the // zone's neutral wanderers (ZoneGenerator.cs's own EligibleWandererFactions spawn, keyed to @@ -913,7 +913,7 @@ public sealed class RestoredHullsTests Assert.NotSame(galaxy.Entrance, zone); var items = new ItemManager(1u, cache, new ProvenanceLedger(), Settings(), _ => { }); - var pack = ZoneGenerator.GenerateZone(items, TutorialZoneSettings(), AuthoredPlanetSettings(), galaxy, zone, entranceStation: true); + var pack = ZoneGenerator.GenerateZone(items, TutorialZoneSettings(), AuthoredPlanetSettings(), galaxy, zone, entranceStations: EntranceStationOrder.Any); // Confirms this fixture still has no genuine (non-rosette) Lagrange candidate -- a regression here // would mean the fixture no longer probes what this test claims to probe. diff --git a/tests/Aetheria.Shared.Tests/RunGoalTests.cs b/tests/Aetheria.Shared.Tests/RunGoalTests.cs index 6d4646284..c23ffef59 100644 --- a/tests/Aetheria.Shared.Tests/RunGoalTests.cs +++ b/tests/Aetheria.Shared.Tests/RunGoalTests.cs @@ -21,7 +21,7 @@ public sealed partial class RunStartTests private ZonePack BossZonePack(Galaxy galaxy, ItemManager items, GalaxyZone zone, bool ambient = true, uint seed = 7) { items.Random = new CultMath.Random(seed); - return ZoneGenerator.GenerateZone(items, _zoneSettings, _planetSettings, galaxy, zone, entranceStation: zone == galaxy.Entrance, ambient); + return ZoneGenerator.GenerateZone(items, _zoneSettings, _planetSettings, galaxy, zone, entranceStations: EntranceStationOrder.Any, ambient); } private Zone ZoneOf(Galaxy galaxy, GalaxyZone zone) => diff --git a/tests/Aetheria.Shared.Tests/ScenarioTests.cs b/tests/Aetheria.Shared.Tests/ScenarioTests.cs index 1a8516bc5..866b8d729 100644 --- a/tests/Aetheria.Shared.Tests/ScenarioTests.cs +++ b/tests/Aetheria.Shared.Tests/ScenarioTests.cs @@ -782,17 +782,26 @@ public sealed partial class RunStartTests [Fact] public void EntranceStationIsTheScenariosDeclaration() { - Assert.True(new DemoTerminus().EntranceStation); - Assert.False(new MainGalaxy().EntranceStation); + Assert.Equal(new[] { ("Aero", "trade-hub"), ("Pirates", "processing") }, + new DemoTerminus().EntranceStations.Select(order => (order.Faction, order.Kind))); + Assert.Empty(new MainGalaxy().EntranceStations); - var natural = ZoneGenerator.GenerateZone(_items, _zoneSettings, _planetSettings, _galaxy, _galaxy.Entrance, entranceStation: false, ambient: false); - var forced = ZoneGenerator.GenerateZone(_items, _zoneSettings, _planetSettings, _galaxy, _galaxy.Entrance, entranceStation: true, ambient: false); + var natural = ZoneGenerator.GenerateZone(_items, _zoneSettings, _planetSettings, _galaxy, _galaxy.Entrance, entranceStations: EntranceStationOrder.None, ambient: false); + var forced = ZoneGenerator.GenerateZone(_items, _zoneSettings, _planetSettings, _galaxy, _galaxy.Entrance, entranceStations: EntranceStationOrder.Any, ambient: false); Assert.Equal(0, StationsOf(natural)); Assert.True(StationsOf(forced) >= 1); // Through RunStart, the scenario's declaration is what reaches the generator. - Assert.True(StationsOf(RunStart.GenerateArena(_items, _zoneSettings, _planetSettings, _galaxy, new DemoTerminus())) >= 1); + Assert.Equal(2, StationsOf(RunStart.GenerateArena(_items, _zoneSettings, _planetSettings, _galaxy, new DemoTerminus()))); Assert.Equal(0, StationsOf(RunStart.GenerateArena(_items, _zoneSettings, _planetSettings, _galaxy, new MainGalaxy()))); + + // An order the galaxy or the catalog cannot meet is refused by name, never placed as something else. + var badFaction = Assert.Throws(() => ZoneGenerator.GenerateZone(_items, _zoneSettings, _planetSettings, _galaxy, + _galaxy.Entrance, new[] { new EntranceStationOrder("Nonesuch", null) }, ambient: false)); + Assert.Contains("Nonesuch", badFaction.Message); + var badKind = Assert.Throws(() => ZoneGenerator.GenerateZone(_items, _zoneSettings, _planetSettings, _galaxy, + _galaxy.Entrance, new[] { new EntranceStationOrder(null, "nowhere") }, ambient: false)); + Assert.Contains("nowhere", badKind.Message); } private int StationsOf(ZonePack pack) => diff --git a/tests/Aetheria.Shared.Tests/StationKindTests.cs b/tests/Aetheria.Shared.Tests/StationKindTests.cs index 6f18b1391..2f306cf61 100644 --- a/tests/Aetheria.Shared.Tests/StationKindTests.cs +++ b/tests/Aetheria.Shared.Tests/StationKindTests.cs @@ -412,7 +412,7 @@ public sealed class StationKindTests : IDisposable var galaxy = new Galaxy(TestCasts.Wide, authored.Read("CastBackgroundSettings"), w.Cache, _ => { }, null, 3); var pack = ZoneGenerator.GenerateZone(w.Items, authored.Read("ZoneSettings"), - authored.Read("PlanetSettings"), galaxy, galaxy.Entrance, true, true); + authored.Read("PlanetSettings"), galaxy, galaxy.Entrance, EntranceStationOrder.Any, true); Assert.NotEmpty(pack.Entities.OfType()); return pack.Orbits.Select(orbit => w.Cache.Get(orbit)).Select(orbit => (orbit.Distance, orbit.Phase)).ToArray(); } @@ -435,7 +435,7 @@ public sealed class StationKindTests : IDisposable var galaxy = new Galaxy(TestCasts.Wide, authored.Read("CastBackgroundSettings"), w.Cache, _ => { }, null, 3); return galaxy.Zones.Take(8).SelectMany(zone => ZoneGenerator.GenerateZone(w.Items, authored.Read("ZoneSettings"), - authored.Read("PlanetSettings"), galaxy, zone, true, true) + authored.Read("PlanetSettings"), galaxy, zone, EntranceStationOrder.Any, true) .Entities.OfType().Where(e => e.Kind.IsSet()).Select(e => e.Kind.Key.Value)).ToArray(); } var first = Kinds(); @@ -459,7 +459,7 @@ public sealed class StationKindTests : IDisposable foreach (var galaxyZone in galaxy.Zones.Take(8)) { var pack = ZoneGenerator.GenerateZone(w.Items, authored.Read("ZoneSettings"), - authored.Read("PlanetSettings"), galaxy, galaxyZone, true, true); + authored.Read("PlanetSettings"), galaxy, galaxyZone, EntranceStationOrder.Any, true); foreach (var station in pack.Entities.OfType().Where(e => w.HullOf(e).HullType == HullType.Station)) { stations++; @@ -530,7 +530,7 @@ public sealed class StationKindTests : IDisposable var galaxy = new Galaxy(TestCasts.Wide, authored.Read("CastBackgroundSettings"), world.Cache, _ => { }, null, 5); var entrance = ZoneGenerator.GenerateZone(world.Items, authored.Read("ZoneSettings"), - authored.Read("PlanetSettings"), galaxy, galaxy.Entrance, true, true); + authored.Read("PlanetSettings"), galaxy, galaxy.Entrance, EntranceStationOrder.Any, true); Assert.Contains(entrance.Entities.OfType(), e => world.HullOf(e).HullType == HullType.Station); } diff --git a/tests/Aetheria.Shared.Tests/StationPlacementTests.cs b/tests/Aetheria.Shared.Tests/StationPlacementTests.cs index 33441e369..8eced01ec 100644 --- a/tests/Aetheria.Shared.Tests/StationPlacementTests.cs +++ b/tests/Aetheria.Shared.Tests/StationPlacementTests.cs @@ -64,7 +64,7 @@ public sealed class StationPlacementTests : IDisposable var zoneSettings = authored.Read("ZoneSettings"); tune?.Invoke(zoneSettings); var pack = ZoneGenerator.GenerateZone(items, zoneSettings, authored.Read("PlanetSettings"), galaxy, galaxyZone, - true, true); + EntranceStationOrder.Any, true); var zone = new Zone(items, authored.Read("PlanetSettings"), pack, galaxyZone, galaxy); zone.Update(.02f); yield return new Built(seed, zone, items); diff --git a/tests/Aetheria.Shared.Tests/SunsNeverGreenTests.cs b/tests/Aetheria.Shared.Tests/SunsNeverGreenTests.cs index d1f9f73de..b17248ff4 100644 --- a/tests/Aetheria.Shared.Tests/SunsNeverGreenTests.cs +++ b/tests/Aetheria.Shared.Tests/SunsNeverGreenTests.cs @@ -190,7 +190,7 @@ public sealed class SunsNeverGreenTests : IDisposable foreach (var zone in galaxy.Zones) { zones++; - var pack = ZoneGenerator.GenerateZone(items, zoneSettings, RestoredHullsTests.AuthoredPlanetSettings(), galaxy, zone, false, false); + var pack = ZoneGenerator.GenerateZone(items, zoneSettings, RestoredHullsTests.AuthoredPlanetSettings(), galaxy, zone, EntranceStationOrder.None, false); suns.AddRange(pack.Planets.Select(p => cache.Get(p)).OfType()); } }