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 <noreply@anthropic.com>
This commit is contained in:
soul 2026-11-28 03:20:27 +01:00
commit 82486837e6
6 changed files with 139 additions and 10 deletions

BIN
GameData/Aetheria.cc (Stored with Git LFS)

Binary file not shown.

View file

@ -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<RecipeData>().ToArray())
{
recipe.Facility = default;
cache.Upsert(typeof(RecipeData), recipe, cache.RefOf(recipe).Key);
}
foreach (var kind in cache.GetAll<StationKindData>().ToArray())
{
kind.Facilities.Clear();
cache.Upsert(typeof(StationKindData), kind, cache.RefOf(kind).Key);
}
foreach (var key in cache.GetAll<GearData>().Where(StationKinds.IsRecipeFacility).Select(gear => cache.RefOf(gear).Key).ToArray()) cache.Remove(key);
foreach (var product in cache.GetAll<FactionProductData>().Where(p => cache.Get(p.Design) == null).ToArray()) cache.Remove(cache.RefOf(product).Key);
Assert.Empty(cache.GetAll<StationKindData>().SelectMany(kind => kind.Facilities));
return cache;
}
[Fact]
public void EveryRecipeNamesItsKindsFacility()
{
using var cache = Stripped();
new Facilities().Author(new EconomyAuthor(cache));
var recipes = cache.GetAll<RecipeData>().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<StationKindData>().SelectMany(kind => kind.Facilities).Select(facility => facility.Key).ToArray();
Assert.NotEmpty(facilities);
foreach (var facility in facilities)
{
var product = Assert.Single(cache.GetAll<FactionProductData>(), 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<RecipeData>().First();
recipe.StationKind = new CultRecordRef<StationKindData>(StationKindData.KeyOf("shipyard"));
cache.Upsert(typeof(RecipeData), recipe, cache.RefOf(recipe).Key);
var refusal = Assert.Throws<InvalidOperationException>(() => 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<StationKindData>(works).Facilities).Key.Value;
new Munitions().Author(new EconomyAuthor(cache));
Assert.Equal(held, Assert.Single(cache.Get<StationKindData>(works).Facilities).Key.Value);
Assert.DoesNotContain(EconomyChecks.Recipe(cache), fault => fault.Invariant == EconomyChecks.LFacility);
}
}

View file

@ -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<FactionProductData>().Where(p => new[] { "Aya", "Megiddo", "Forge" }.Contains(_cache.Get(p.Manufacturer).ShortName)).ToArray();
var theirs = _cache.GetAll<FactionProductData>().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));

View file

@ -381,7 +381,8 @@ public sealed partial class RunStartTests : IDisposable
public void GenerationOffersExactlyTheSoldGearSomeHullCanFit()
{
var hulls = LoadoutGenerator.SoldHulls(_cache);
var sold = _cache.GetAll<FactionProductData>().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<FactionProductData>().Where(p => p.Manufacturer.IsSet() && LoadoutGenerator.IsOffered(_cache, p)).Select(p => p.Design.Key).ToHashSet();
var generator = PreludeGenerator();
var wrong = _cache.GetAll<EquippableItemData>()
.Where(design => sold.Contains(_cache.RefOf(design).Key) && design.Price > 0)

View file

@ -197,6 +197,22 @@ public sealed class StationKindTests : IDisposable
Assert.Contains(opened.GetAll<HullData>(), 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()
{

View file

@ -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<Faction>().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<CraftedItemData>(designKey),
Name = $"{maker.Faction.Name} {name}", Description = description, Design = new CultRecordRef<CraftedItemData>(designKey),
Manufacturer = new CultRecordRef<Faction>(maker.Key), NotOffered = true
}, new CultRecordKey("product:facility:" + id));