From 82486837e6fc09667578cf611de419478acd914b Mon Sep 17 00:00:00 2001 From: soul Date: Sat, 28 Nov 2026 03:20:27 +0100 Subject: [PATCH] Catalog: six facility designs, every kind's Facilities, every recipe's Facility, Zenith's Fa.1 economy author Facilities (apply) gives the six station kinds recipes run on a 2x2 facility design (Extraction Rig, Volatiles Skimmer, Algae Vats, Refinery, Fabrication Line, Munitions Line) with a NotOffered branded product each, lists it on the kind and names it on each recipe. station-kinds facilities "Zenith" 9,7:##/## gives Zenith its Facility row. catalog resave leaves nothing stale. The economy report keeps its 139 faults and adds no L-facility fault. Two tests that counted products now count the offered ones, since a NotOffered facility product is on no market. Co-Authored-By: Claude Sonnet 5.5 --- GameData/Aetheria.cc | 4 +- .../FacilitiesBatchTests.cs | 107 ++++++++++++++++++ .../Aetheria.Shared.Tests/MinorPowersTests.cs | 2 +- tests/Aetheria.Shared.Tests/RunStartTests.cs | 3 +- .../Aetheria.Shared.Tests/StationKindTests.cs | 16 +++ tools/AetherDb/Economy/Facilities.cs | 17 ++- 6 files changed, 139 insertions(+), 10 deletions(-) create mode 100644 tests/Aetheria.Shared.Tests/FacilitiesBatchTests.cs diff --git a/GameData/Aetheria.cc b/GameData/Aetheria.cc index d8d927a6a..435097c45 100644 --- a/GameData/Aetheria.cc +++ b/GameData/Aetheria.cc @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1521215b420c538dfd117c6855912a20889ca83fba932f9c422aae2ff2e9132a -size 282124 +oid sha256:ee7e166125413bda61562e4b0d38ff040f6a731c38ee11e28780c2b856cef064 +size 289402 diff --git a/tests/Aetheria.Shared.Tests/FacilitiesBatchTests.cs b/tests/Aetheria.Shared.Tests/FacilitiesBatchTests.cs new file mode 100644 index 000000000..07b102423 --- /dev/null +++ b/tests/Aetheria.Shared.Tests/FacilitiesBatchTests.cs @@ -0,0 +1,107 @@ +using System; +using System.IO; +using System.Linq; +using GameCult.Caching; +using Xunit; + +// The Facilities economy batch (aetheria-living-world, cut recipe-facilities): over a copy of the shipped catalog stripped of its +// facilities, it gives every kind a recipe names one facility design, and every recipe its kind's. +public sealed class FacilitiesBatchTests : IDisposable +{ + private readonly string _root = Path.Combine(Path.GetTempPath(), "aetheria-facilities-" + Guid.NewGuid().ToString("N")); + + public FacilitiesBatchTests() => Directory.CreateDirectory(_root); + public void Dispose() => Directory.Delete(_root, true); + + // The shipped Aetheria.cc on its own (the batch's catalog: no packages), as it stood before the batch: no facility design, no + // kind's Facilities, no recipe's Facility. + private CultCache Stripped() + { + var path = Path.Combine(_root, Guid.NewGuid().ToString("N") + ".cc"); + File.Copy(Path.Combine(RunStartTests.FindRepoRoot(), "GameData", "Aetheria.cc"), path); + var cache = AetheriaStores.Open(path, catalogWritable: true, registry: TestCatalog.Registry()); + foreach (var recipe in cache.GetAll().ToArray()) + { + recipe.Facility = default; + cache.Upsert(typeof(RecipeData), recipe, cache.RefOf(recipe).Key); + } + foreach (var kind in cache.GetAll().ToArray()) + { + kind.Facilities.Clear(); + cache.Upsert(typeof(StationKindData), kind, cache.RefOf(kind).Key); + } + foreach (var key in cache.GetAll().Where(StationKinds.IsRecipeFacility).Select(gear => cache.RefOf(gear).Key).ToArray()) cache.Remove(key); + foreach (var product in cache.GetAll().Where(p => cache.Get(p.Design) == null).ToArray()) cache.Remove(cache.RefOf(product).Key); + Assert.Empty(cache.GetAll().SelectMany(kind => kind.Facilities)); + return cache; + } + + [Fact] + public void EveryRecipeNamesItsKindsFacility() + { + using var cache = Stripped(); + new Facilities().Author(new EconomyAuthor(cache)); + var recipes = cache.GetAll().ToArray(); + Assert.NotEmpty(recipes); + foreach (var recipe in recipes) + { + var kind = cache.Get(recipe.StationKind); + var facility = Assert.Single(kind.Facilities); + Assert.Equal(facility.Key.Value, recipe.Facility.Key.Value); + Assert.True(StationKinds.IsRecipeFacility(cache.Get(facility))); + } + Assert.Equal(recipes.Select(r => r.StationKind.Key.Value).Distinct().Count(), recipes.Select(r => r.Facility.Key.Value).Distinct().Count()); + Assert.DoesNotContain(EconomyChecks.Recipe(cache), fault => fault.Invariant == EconomyChecks.LFacility && fault.Record != "station-facilities"); + } + + [Fact] + public void RerunConverges() + { + using var cache = Stripped(); + new Facilities().Author(new EconomyAuthor(cache)); + var again = new EconomyAuthor(cache); + new Facilities().Author(again); + Assert.Empty(again.Touched); + } + + [Fact] + public void EachFacilityHasOneUnofferedProduct() + { + using var cache = Stripped(); + new Facilities().Author(new EconomyAuthor(cache)); + var facilities = cache.GetAll().SelectMany(kind => kind.Facilities).Select(facility => facility.Key).ToArray(); + Assert.NotEmpty(facilities); + foreach (var facility in facilities) + { + var product = Assert.Single(cache.GetAll(), p => p.Design.Key.Equals(facility)); + Assert.True(product.NotOffered); + Assert.False(LoadoutGenerator.IsOffered(cache, product)); + Assert.True(cache.Get(product.Manufacturer) != null); + } + } + + [Fact] + public void AKindWithoutARowThrows() + { + using var cache = Stripped(); + var recipe = cache.GetAll().First(); + recipe.StationKind = new CultRecordRef(StationKindData.KeyOf("shipyard")); + cache.Upsert(typeof(RecipeData), recipe, cache.RefOf(recipe).Key); + var refusal = Assert.Throws(() => new Facilities().Author(new EconomyAuthor(cache))); + Assert.Contains("station-kind:shipyard", refusal.Message); + } + + // The munitions batch rewrites its kind whole; the facilities the catalog already holds for it survive, and so does every recipe's. + [Fact] + public void MunitionsRewriteKeepsAKindsFacilities() + { + var path = Path.Combine(_root, "munitions.cc"); + File.Copy(Path.Combine(RunStartTests.FindRepoRoot(), "GameData", "Aetheria.cc"), path); + using var cache = AetheriaStores.Open(path, catalogWritable: true, registry: TestCatalog.Registry()); + var works = StationKindData.KeyOf("munitions-works"); + var held = Assert.Single(cache.Get(works).Facilities).Key.Value; + new Munitions().Author(new EconomyAuthor(cache)); + Assert.Equal(held, Assert.Single(cache.Get(works).Facilities).Key.Value); + Assert.DoesNotContain(EconomyChecks.Recipe(cache), fault => fault.Invariant == EconomyChecks.LFacility); + } +} diff --git a/tests/Aetheria.Shared.Tests/MinorPowersTests.cs b/tests/Aetheria.Shared.Tests/MinorPowersTests.cs index 334dad2ee..cf133ecb8 100644 --- a/tests/Aetheria.Shared.Tests/MinorPowersTests.cs +++ b/tests/Aetheria.Shared.Tests/MinorPowersTests.cs @@ -140,7 +140,7 @@ public sealed partial class RunStartTests Assert.Contains(Enumerable.Range(1, 64), seed => For("AU", unchecked((uint) seed * 2654435761u)).ChooseProduct(autocannon)?.Name == pattern30.Name); var terri = For("Miss Terri's", 1); - var theirs = _cache.GetAll().Where(p => new[] { "Aya", "Megiddo", "Forge" }.Contains(_cache.Get(p.Manufacturer).ShortName)).ToArray(); + var theirs = _cache.GetAll().Where(p => LoadoutGenerator.IsOffered(_cache, p) && new[] { "Aya", "Megiddo", "Forge" }.Contains(_cache.Get(p.Manufacturer).ShortName)).ToArray(); // 10 until the shield projectors: Awning (Aya) and Migdal (Megiddo) join their makers' lines. Assert.Equal(12, theirs.Length); Assert.All(theirs, product => Assert.False(terri.IsAvailable(product), product.Name)); diff --git a/tests/Aetheria.Shared.Tests/RunStartTests.cs b/tests/Aetheria.Shared.Tests/RunStartTests.cs index 3ea2f2fdc..ded69be9c 100644 --- a/tests/Aetheria.Shared.Tests/RunStartTests.cs +++ b/tests/Aetheria.Shared.Tests/RunStartTests.cs @@ -381,7 +381,8 @@ public sealed partial class RunStartTests : IDisposable public void GenerationOffersExactlyTheSoldGearSomeHullCanFit() { var hulls = LoadoutGenerator.SoldHulls(_cache); - var sold = _cache.GetAll().Where(p => p.Manufacturer.IsSet()).Select(p => p.Design.Key).ToHashSet(); + // Sold means on the market: a facility design's product is NotOffered, which no generation draws. + var sold = _cache.GetAll().Where(p => p.Manufacturer.IsSet() && LoadoutGenerator.IsOffered(_cache, p)).Select(p => p.Design.Key).ToHashSet(); var generator = PreludeGenerator(); var wrong = _cache.GetAll() .Where(design => sold.Contains(_cache.RefOf(design).Key) && design.Price > 0) diff --git a/tests/Aetheria.Shared.Tests/StationKindTests.cs b/tests/Aetheria.Shared.Tests/StationKindTests.cs index 05ea64da3..6f18b1391 100644 --- a/tests/Aetheria.Shared.Tests/StationKindTests.cs +++ b/tests/Aetheria.Shared.Tests/StationKindTests.cs @@ -197,6 +197,22 @@ public sealed class StationKindTests : IDisposable Assert.Contains(opened.GetAll(), hull => hull.Hardpoints.Any(row => row.Type == HardpointType.Facility)); } + // The random fill never decides a Facility row (a kind's Facilities fill it, follow-up station-buys-by-installed-gear): Zenith + // generates with no gear of a Facility design and no "No compatible item" log for its row, whatever seed draws it. + [Fact] + public void AStationGeneratesWithItsFacilityRowUnfilledAndUnlogged() + { + var world = World.Make(this, zenithOffered: true); + Assert.Single(world.Zenith.Hardpoints, row => row.Type == HardpointType.Facility); + for (uint seed = 1; seed <= 8; seed++) + { + var pack = world.Generator(world.Au, seed).GenerateStationLoadout(Kind("trade-hub")); + Assert.Equal("Zenith", world.HullName(pack)); + Assert.DoesNotContain(pack.Equipment, entry => entry.item != null && ((EquippableItemData) world.Items.GetData(entry.item)).HardpointType == HardpointType.Facility); + } + Assert.DoesNotContain(world.Log, line => line.Contains("Facility hardpoint")); + } + [Fact] public void OpenRefusesBadStandIn() { diff --git a/tools/AetherDb/Economy/Facilities.cs b/tools/AetherDb/Economy/Facilities.cs index 429e0ba90..50726e33f 100644 --- a/tools/AetherDb/Economy/Facilities.cs +++ b/tools/AetherDb/Economy/Facilities.cs @@ -50,17 +50,22 @@ public sealed class Facilities : EconomyBatch var designKey = new CultRecordKey("facility:" + id); var shape = new Shape(2, 2); foreach (var cell in shape.AllCoordinates) shape[cell] = true; - Put(new GearData - { - Name = name, Description = description, Hardpoint = HardpointType.Facility, Shape = shape, - Durability = 100, Mass = 250, Price = 1000, Behaviors = { new FacilityData() } - }, designKey); + // A stored behavior carries a cache-minted element id, so a design is compared by its fields, never by bytes. + if (!(catalog.Get(designKey) is GearData held && held.Name == name && held.Description == description && held.Hardpoint == HardpointType.Facility + && held.Durability == 100 && held.Mass == 250 && held.Price == 1000 && held.Shape.Width == 2 && held.Shape.Height == 2 && held.Shape.Coordinates.Length == 4 + && held.Behaviors.Count == 1 && held.Behaviors[0] is FacilityData)) + author.Put(new GearData + { + Name = name, Description = description, Hardpoint = HardpointType.Facility, Shape = shape, + Durability = 100, Mass = 250, Price = 1000, Behaviors = { new FacilityData() } + }, designKey); var factions = catalog.GetAll().Select(faction => (Key: catalog.RefOf(faction).Key, Faction: faction)).OrderBy(pair => pair.Key.Value, StringComparer.Ordinal).ToArray(); var maker = factions.FirstOrDefault(pair => StationKinds.KindsOf(catalog, pair.Faction).Any(kind => kind.Key.Value == kindKey)); if (maker.Faction == null) maker = factions.First(); + // The brand lives in the product (ruling designs-are-tech-nodes): the maker's name before the design's. Put(new FactionProductData { - Name = name, Description = description, Design = new CultRecordRef(designKey), + Name = $"{maker.Faction.Name} {name}", Description = description, Design = new CultRecordRef(designKey), Manufacturer = new CultRecordRef(maker.Key), NotOffered = true }, new CultRecordKey("product:facility:" + id));