Merge eureka/aetheria-living-world-economy-content-b1: economy batch 1 (Zhestokost munitions) applied; one owner of drawable station hulls
Operator approved the batch (aetheria-living-world:ruling:batch-1-munitions-approved). Soul s2 holds; suite 2836/0 at the merged head; catalog LFS oid 68b37cb5 on GitHub and the Yggdrasil cache. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
c6a49e5568
6 changed files with 452 additions and 45 deletions
|
|
@ -200,11 +200,8 @@ public class LoadoutGenerator
|
|||
var candidates = ItemManager.ItemData.GetAll<FactionProductData>()
|
||||
.Select(product => (product, design: ItemManager.ItemData.Get(product.Design) as T))
|
||||
.Where(entry =>
|
||||
entry.design != null &&
|
||||
entry.design.Price > 0 &&
|
||||
entry.product.Manufacturer.IsSet() &&
|
||||
// A not-offered product is never a candidate, so the any-manufacturer fallback below cannot reach it either.
|
||||
IsOffered(ItemManager.ItemData, entry.product) &&
|
||||
IsDrawable(ItemManager.ItemData, entry.product, entry.design) &&
|
||||
(!(entry.design is EquippableItemData equippable) || HasHome(equippable, hulls)) &&
|
||||
(filter?.Invoke(entry.design) ?? true))
|
||||
.ToArray();
|
||||
|
|
@ -246,6 +243,12 @@ public class LoadoutGenerator
|
|||
Galaxy == null || Faction == null ||
|
||||
ItemManager.ItemData.Get(product.Manufacturer) == Faction || Faction.Allegiance.ContainsKey(product.Manufacturer));
|
||||
|
||||
// Whether a product can be drawn for its design at all: the design resolves, has a price, the product names a maker and is
|
||||
// offered. The one definition of 'a maker offers this design'; AvailableProducts selects by it and StationKinds decides which
|
||||
// station kinds a hull can be drawn for by it, so a kind is kept exactly when a hull of it can be drawn.
|
||||
public static bool IsDrawable(CultCache items, FactionProductData product, CraftedItemData design) =>
|
||||
design != null && design.Price > 0 && product.Manufacturer.IsSet() && IsOffered(items, product);
|
||||
|
||||
// Whether a product is on the market at all (ruling off-market-is-unoffered-product). The one reader of NotOffered. A bin is
|
||||
// offered only if both it and its line are (ruling bin-inherits-line-offered); the catalog read guarantees a bin's line exists.
|
||||
public static bool IsOffered(CultCache items, FactionProductData product) =>
|
||||
|
|
|
|||
|
|
@ -52,35 +52,47 @@ public static class StationKinds
|
|||
return Ordered(kinds);
|
||||
}
|
||||
|
||||
// A station's kind: a stable pick among the faction's kinds by the station's site, which generation names by the zone's
|
||||
// seed and the station's place in its orbit order (never by a key the cache mints). It draws nothing from any random
|
||||
// stream, so adding the kind to generation moves no other roll. A faction with no kinds falls back to any kind some
|
||||
// offered station hull carries, logged, and the hull draw then falls back to any maker. Unset when the catalog has none.
|
||||
// The kinds this faction places that a station can be drawn for: those whose hull kind (its own model, else its stand-in's) some
|
||||
// maker offers. A stand-in whose model has not landed leaves its kind out.
|
||||
public static CultRecordRef<StationKindData>[] FieldableKindsOf(CultCache catalog, Faction faction) =>
|
||||
KindsOf(catalog, faction).Where(kind => HasModel(catalog, faction, kind) || LiveStandIn(catalog, faction, kind).IsSet()).ToArray();
|
||||
|
||||
// A station's kind: a stable pick among the faction's kinds it can field, by the station's site, which generation names by the
|
||||
// zone's seed and the station's place in its orbit order (never by a key the cache mints). It draws nothing from any random
|
||||
// stream, so adding the kind to generation moves no other roll. A kind the faction places but cannot field (neither its own
|
||||
// model nor a stand-in's hull kind is carried by any offered station hull) is not in the pool; a faction left with no kind to
|
||||
// field falls back to any kind some offered station hull carries, logged, and the hull draw then falls back to any maker.
|
||||
// Unset when the catalog has none.
|
||||
public static CultRecordRef<StationKindData> Choose(CultCache catalog, Faction faction, string site, Action<string> log = null)
|
||||
{
|
||||
var pool = KindsOf(catalog, faction);
|
||||
var pool = FieldableKindsOf(catalog, faction);
|
||||
if (pool.Length == 0)
|
||||
{
|
||||
pool = Ordered(new HashSet<string>(
|
||||
catalog.GetAll<FactionProductData>().Where(product => LoadoutGenerator.IsOffered(catalog, product))
|
||||
.Select(product => catalog.Get(product.Design) as HullData)
|
||||
.Where(hull => hull != null && hull.HullType == HullType.Station && hull.Kind.IsSet())
|
||||
.Select(hull => hull.Kind.Key.Value), StringComparer.Ordinal));
|
||||
pool = Ordered(OfferedKinds(catalog));
|
||||
if (pool.Length == 0) return default;
|
||||
log?.Invoke($"{faction?.Name ?? "This galaxy"} builds no station kind; placing a station of any kind some maker offers.");
|
||||
log?.Invoke($"{faction?.Name ?? "This galaxy"} builds no station kind it can field; placing a station of any kind some maker offers.");
|
||||
}
|
||||
return pool[(int) (site.StableHash() % (uint) pool.Length)];
|
||||
}
|
||||
|
||||
// The kind of hull a faction builds for a station kind: the kind itself when the faction offers a model of it (a model
|
||||
// wins over a stale stand-in), else the kind its stand-in names, else the kind itself (the hull draw then falls back to
|
||||
// any maker).
|
||||
// wins over a stale stand-in), else the kind its stand-in names when some maker offers that, else the kind itself (the hull
|
||||
// draw then falls back to any maker).
|
||||
public static CultRecordRef<StationKindData> HullKindFor(CultCache catalog, Faction faction, CultRecordRef<StationKindData> kind)
|
||||
{
|
||||
if (!kind.IsSet()) return kind;
|
||||
if (OfferedStationHulls(catalog, faction).Any(hull => hull.Kind.Key.Equals(kind.Key))) return kind;
|
||||
if (!kind.IsSet() || HasModel(catalog, faction, kind)) return kind;
|
||||
var standIn = LiveStandIn(catalog, faction, kind);
|
||||
return standIn.IsSet() ? standIn : kind;
|
||||
}
|
||||
|
||||
private static bool HasModel(CultCache catalog, Faction faction, CultRecordRef<StationKindData> kind) =>
|
||||
OfferedStationHulls(catalog, faction).Any(hull => hull.Kind.Key.Equals(kind.Key));
|
||||
|
||||
// The kind the faction's stand-in names for this kind, when some maker offers a hull of it; else unset.
|
||||
private static CultRecordRef<StationKindData> LiveStandIn(CultCache catalog, Faction faction, CultRecordRef<StationKindData> kind)
|
||||
{
|
||||
var standIn = catalog.Get(kind)?.StandIns.FirstOrDefault(entry => catalog.Get(entry.Faction) == faction);
|
||||
return standIn != null && standIn.Kind.IsSet() ? standIn.Kind : kind;
|
||||
return standIn != null && standIn.Kind.IsSet() && OfferedKinds(catalog).Contains(standIn.Kind.Key.Value) ? standIn.Kind : default;
|
||||
}
|
||||
|
||||
// What is wrong with a hull's kind, or null: a Station hull names a kind the catalog holds, and no other hull names one.
|
||||
|
|
@ -130,11 +142,19 @@ public static class StationKinds
|
|||
}
|
||||
}
|
||||
|
||||
// The hull kinds some maker offers: the pool a station can always be drawn from.
|
||||
private static HashSet<string> OfferedKinds(CultCache catalog) =>
|
||||
new HashSet<string>(DrawableStationProducts(catalog).Select(entry => entry.hull.Kind.Key.Value), StringComparer.Ordinal);
|
||||
|
||||
private static IEnumerable<HullData> OfferedStationHulls(CultCache catalog, Faction faction) =>
|
||||
DrawableStationProducts(catalog).Where(entry => catalog.Get(entry.product.Manufacturer) == faction).Select(entry => entry.hull);
|
||||
|
||||
// The station hulls a hull draw can reach (LoadoutGenerator.IsDrawable, the one definition), with the product that sells each.
|
||||
private static IEnumerable<(FactionProductData product, HullData hull)> DrawableStationProducts(CultCache catalog) =>
|
||||
catalog.GetAll<FactionProductData>()
|
||||
.Where(product => LoadoutGenerator.IsOffered(catalog, product) && catalog.Get(product.Manufacturer) == faction)
|
||||
.Select(product => catalog.Get(product.Design) as HullData)
|
||||
.Where(hull => hull != null && hull.HullType == HullType.Station && hull.Kind.IsSet());
|
||||
.Select(product => (product, hull: catalog.Get(product.Design) as HullData))
|
||||
.Where(entry => entry.hull != null && entry.hull.HullType == HullType.Station && entry.hull.Kind.IsSet() &&
|
||||
LoadoutGenerator.IsDrawable(catalog, entry.product, entry.hull));
|
||||
|
||||
private static CultRecordRef<StationKindData>[] Ordered(IEnumerable<string> keys) =>
|
||||
keys.OrderBy(key => key, StringComparer.Ordinal).Select(key => new CultRecordRef<StationKindData>(new CultRecordKey(key))).ToArray();
|
||||
|
|
|
|||
BIN
GameData/Aetheria.cc
(Stored with Git LFS)
BIN
GameData/Aetheria.cc
(Stored with Git LFS)
Binary file not shown.
|
|
@ -13,8 +13,8 @@ public sealed class CommodityRecordsTests
|
|||
public void ShippedCatalogOpensWithTheRetiredKeysGone()
|
||||
{
|
||||
using var cache = RestoredHullsTests.OpenCatalog();
|
||||
Assert.Equal(13, cache.GetAll<SimpleCommodityData>().Count());
|
||||
Assert.Equal(51, cache.GetAll<CompoundCommodityData>().Count());
|
||||
Assert.Equal(22, cache.GetAll<SimpleCommodityData>().Count());
|
||||
Assert.Equal(63, cache.GetAll<CompoundCommodityData>().Count());
|
||||
Assert.Contains(cache.GetAll<SimpleCommodityData>(), c => c.Name == "Ammo");
|
||||
Assert.All(cache.GetAll<CompoundCommodityData>(), c => Assert.False(string.IsNullOrEmpty(c.Name)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,6 +86,14 @@ public sealed class StationKindTests : IDisposable
|
|||
return hull;
|
||||
}
|
||||
|
||||
// Takes a sold hull's price to zero, or its product's maker away: the hull is still on a product but no hull draw can reach it.
|
||||
public void Unsellable(HullData hull, bool unsetMaker)
|
||||
{
|
||||
var product = Cache.GetAll<FactionProductData>().Single(p => Cache.Get(p.Design) == hull);
|
||||
if (unsetMaker) { product.Manufacturer = default; Cache.Upsert(product); }
|
||||
else { hull.Price = 0; Cache.Upsert(hull); }
|
||||
}
|
||||
|
||||
public void StandIn(string kindId, Faction faction, string asKindId)
|
||||
{
|
||||
var kind = Cache.Get(Kind(kindId));
|
||||
|
|
@ -273,6 +281,34 @@ public sealed class StationKindTests : IDisposable
|
|||
}
|
||||
}
|
||||
|
||||
// A faction that places a kind through a stand-in no maker offers cannot field it: the kind is out of its pool and it falls back
|
||||
// exactly as a faction with no kinds does. Once any maker offers the stand-in's hull kind, the faction keeps its kind.
|
||||
[Fact]
|
||||
public void FactionWhoseStandInNoMakerOffersFallsBackToAnyMaker()
|
||||
{
|
||||
var world = World.Make(this, zenithOffered: false);
|
||||
world.Sell(world.Au, "shipyard");
|
||||
world.StandIn("mining", world.Lucent, "depot");
|
||||
Assert.Equal(new[] { Kind("mining").Key }, StationKinds.KindsOf(world.Cache, world.Lucent).Select(kind => kind.Key));
|
||||
|
||||
var logged = new List<string>();
|
||||
var kind = StationKinds.Choose(world.Cache, world.Lucent, "site", logged.Add);
|
||||
Assert.Equal(Kind("shipyard").Key, kind.Key);
|
||||
Assert.Contains(world.Lucent.Name, Assert.Single(logged));
|
||||
var pack = world.Generator(world.Lucent).GenerateStationLoadout(kind);
|
||||
Assert.NotNull(pack);
|
||||
Assert.Equal(Kind("shipyard").Key, world.HullOf(pack).Kind.Key);
|
||||
|
||||
world.Sell(world.Au, "depot");
|
||||
var kept = new List<string>();
|
||||
var placed = StationKinds.Choose(world.Cache, world.Lucent, "site", kept.Add);
|
||||
Assert.Equal(Kind("mining").Key, placed.Key);
|
||||
Assert.Empty(kept);
|
||||
var depotStation = world.Generator(world.Lucent).GenerateStationLoadout(placed);
|
||||
Assert.NotNull(depotStation);
|
||||
Assert.Equal(Kind("depot").Key, world.HullOf(depotStation).Kind.Key);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FactionWithoutModelsFallsBack()
|
||||
{
|
||||
|
|
@ -358,11 +394,14 @@ public sealed class StationKindTests : IDisposable
|
|||
var w = World.Make(this, zenithOffered: true);
|
||||
w.Sell(w.Au, "mining");
|
||||
w.Sell(w.Au, "shipyard");
|
||||
w.StandIn("depot", w.Lucent, "power");
|
||||
w.StandIn("depot", w.Zh, "power");
|
||||
var authored = AuthoredSettings.Load(RunStartTests.FindRepoRoot());
|
||||
var galaxy = new Galaxy(authored.Read<TutorialGenerationSettings>("TutorialGenerationSettings"),
|
||||
authored.Read<SectorBackgroundSettings>("TutorialBackgroundSettings"), w.Cache, new PlayerSettings(),
|
||||
Directory.CreateDirectory(Path.Combine(_root, "zones", "Narrative")), _ => { }, null, 5);
|
||||
var stations = 0;
|
||||
var fallbacks = 0;
|
||||
foreach (var galaxyZone in galaxy.Zones.Take(8))
|
||||
{
|
||||
var pack = ZoneGenerator.GenerateZone(w.Items, authored.Read<ZoneGenerationSettings>("ZoneSettings"),
|
||||
|
|
@ -373,13 +412,104 @@ public sealed class StationKindTests : IDisposable
|
|||
Assert.True(station.Kind.IsSet(), "a placed station has a kind");
|
||||
Assert.Equal(station.Kind.Key, w.HullOf(station).Kind.Key);
|
||||
var faction = w.Cache.Get(station.Faction);
|
||||
var kinds = StationKinds.KindsOf(w.Cache, faction);
|
||||
if (kinds.Length > 0) Assert.Contains(station.Kind.Key.Value, kinds.Select(kind => kind.Key.Value));
|
||||
var fieldable = OracleFieldableKinds(w.Cache, faction);
|
||||
if (fieldable.Count > 0) Assert.Contains(station.Kind.Key.Value, fieldable);
|
||||
else
|
||||
{
|
||||
fallbacks++;
|
||||
Assert.Contains(station.Kind.Key.Value, OracleOfferedKinds(w.Cache));
|
||||
}
|
||||
}
|
||||
}
|
||||
Assert.True(fallbacks > 0, "the sample seated a faction that could field none of its kinds, by the fallback");
|
||||
Assert.True(stations > 0, "the sample generated stations");
|
||||
}
|
||||
|
||||
// An oracle for what a hull draw can reach, read straight off the records and independent of StationKinds and LoadoutGenerator:
|
||||
// a station hull with a kind and a price, sold by an unbinned product that names a maker and is not off the market.
|
||||
private static IEnumerable<(CultRecordKey maker, string kind)> OracleSoldStationKinds(CultCache cache) =>
|
||||
cache.GetAll<FactionProductData>()
|
||||
.Where(p => !p.NotOffered && p.Bin == null && p.Manufacturer.IsSet())
|
||||
.Select(p => (p, hull: cache.Get(p.Design) as HullData))
|
||||
.Where(e => e.hull != null && e.hull.HullType == HullType.Station && e.hull.Kind.IsSet() && e.hull.Price > 0)
|
||||
.Select(e => (e.p.Manufacturer.Key, e.hull.Kind.Key.Value));
|
||||
|
||||
private static HashSet<string> OracleOfferedKinds(CultCache cache) => OracleSoldStationKinds(cache).Select(e => e.kind).ToHashSet();
|
||||
|
||||
// The kinds a faction can field: those it has its own model of, and those it stands in on whose stand-in kind some maker sells.
|
||||
private static HashSet<string> OracleFieldableKinds(CultCache cache, Faction faction)
|
||||
{
|
||||
var offered = OracleOfferedKinds(cache);
|
||||
var own = OracleSoldStationKinds(cache).Where(e => e.maker.Equals(cache.RefOf(faction).Key)).Select(e => e.kind).ToHashSet();
|
||||
foreach (var kind in cache.GetAll<StationKindData>())
|
||||
foreach (var standIn in kind.StandIns.Where(entry => cache.Get(entry.Faction) == faction))
|
||||
if (offered.Contains(standIn.Kind.Key.Value)) own.Add(cache.RefOf(kind).Key.Value);
|
||||
return own;
|
||||
}
|
||||
|
||||
// Choose keeps a kind exactly when GenerateStationLoadout can draw a hull of it: a hull sold at Price 0, or by a product with no
|
||||
// maker, is no hull a draw reaches, so a faction standing in on its kind is not seated on it. The tutorial entrance still gets a station.
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public void AKindIsKeptExactlyWhenAHullOfItCanBeDrawn(bool unsetMaker)
|
||||
{
|
||||
var world = World.Make(this, zenithOffered: false);
|
||||
world.Sell(world.Au, "mining");
|
||||
var unsold = world.Sell(world.Au, "shipyard");
|
||||
world.Unsellable(unsold, unsetMaker);
|
||||
// No hull draw reaches it: a station of its kind cannot be generated for anyone.
|
||||
Assert.Null(world.Generator(world.Au).GenerateStationLoadout(Kind("shipyard")));
|
||||
Assert.Null(world.Generator(world.Lucent).GenerateStationLoadout(Kind("shipyard")));
|
||||
world.StandIn("mining", world.Lucent, "shipyard");
|
||||
world.StandIn("mining", world.Zh, "shipyard");
|
||||
|
||||
foreach (var faction in new[] { world.Au, world.Lucent, world.Zh })
|
||||
for (var site = 0; site < 12; site++)
|
||||
{
|
||||
var kind = StationKinds.Choose(world.Cache, faction, "site-" + site);
|
||||
Assert.Equal(Kind("mining").Key, kind.Key);
|
||||
Assert.NotNull(world.Generator(faction).GenerateStationLoadout(kind));
|
||||
}
|
||||
|
||||
var authored = AuthoredSettings.Load(RunStartTests.FindRepoRoot());
|
||||
var galaxy = new Galaxy(authored.Read<TutorialGenerationSettings>("TutorialGenerationSettings"),
|
||||
authored.Read<SectorBackgroundSettings>("TutorialBackgroundSettings"), world.Cache, new PlayerSettings(),
|
||||
Directory.CreateDirectory(Path.Combine(_root, "galaxy" + _worlds++, "Narrative")), _ => { }, null, 5);
|
||||
var entrance = ZoneGenerator.GenerateZone(world.Items, authored.Read<ZoneGenerationSettings>("ZoneSettings"),
|
||||
authored.Read<PlanetSettings>("PlanetSettings"), galaxy, galaxy.Entrance, galaxy.IsPrelude, true);
|
||||
Assert.Contains(entrance.Entities.OfType<OrbitalEntityPack>(), e => world.HullOf(e).HullType == HullType.Station);
|
||||
}
|
||||
|
||||
// A faction with one kind it can field and one it cannot places only the one it can, and never takes the fallback.
|
||||
[Fact]
|
||||
public void AFactionWithSomeKindsFieldablePlacesOnlyThose()
|
||||
{
|
||||
var world = World.Make(this, zenithOffered: false);
|
||||
world.Sell(world.Au, "shipyard");
|
||||
world.StandIn("mining", world.Lucent, "shipyard");
|
||||
world.StandIn("depot", world.Lucent, "power");
|
||||
Assert.Equal(2, StationKinds.KindsOf(world.Cache, world.Lucent).Length);
|
||||
|
||||
var logged = new List<string>();
|
||||
for (var site = 0; site < 40; site++)
|
||||
Assert.Equal(Kind("mining").Key, StationKinds.Choose(world.Cache, world.Lucent, "site-" + site, logged.Add).Key);
|
||||
Assert.Empty(logged);
|
||||
}
|
||||
|
||||
// The fallback pool is every kind some maker offers, spread over sites, not the first of them.
|
||||
[Fact]
|
||||
public void TheFallbackSpreadsSitesOverEveryOfferedKind()
|
||||
{
|
||||
var world = World.Make(this, zenithOffered: false);
|
||||
world.Sell(world.Au, "mining");
|
||||
world.Sell(world.Au, "shipyard");
|
||||
world.Sell(world.Au, "depot");
|
||||
var chosen = Enumerable.Range(0, 40).Select(site => StationKinds.Choose(world.Cache, world.Lucent, "site-" + site).Key.Value).ToHashSet();
|
||||
Assert.Equal(new[] { Kind("depot"), Kind("mining"), Kind("shipyard") }.Select(kind => kind.Key.Value).OrderBy(k => k, StringComparer.Ordinal),
|
||||
chosen.OrderBy(k => k, StringComparer.Ordinal));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void KindSurvivesSave()
|
||||
{
|
||||
|
|
@ -405,26 +535,41 @@ public sealed class StationKindTests : IDisposable
|
|||
var ids = new[]
|
||||
{
|
||||
"mining", "volatiles", "agriculture", "processing", "fabrication", "shipyard", "depot", "trade-hub", "residential",
|
||||
"habitat-support", "urban", "administrative", "power", "research", "salvage", "black-market", "waystation"
|
||||
"habitat-support", "urban", "administrative", "power", "research", "salvage", "black-market", "waystation", "munitions-works"
|
||||
};
|
||||
Assert.Equal(ids.Select(id => StationKindData.KeyOf(id).Value).OrderBy(key => key, StringComparer.Ordinal),
|
||||
cache.GetAll<StationKindData>().Select(kind => cache.RefOf(kind).Key.Value).OrderBy(key => key, StringComparer.Ordinal));
|
||||
Assert.Equal(StationKindData.KeyOf("trade-hub").Value, cache.GetAll<HullData>().Single(h => h.Name == "Zenith").Kind.Key.Value);
|
||||
}
|
||||
|
||||
private static void AssertStandInsLive(CultCache cache)
|
||||
// Every stand-in is judged from the catalog: its target is a real kind; the faction owns no model of the kind it stands in for; and
|
||||
// the stand-in is live (the faction can field the kind) exactly when some maker sells a hull of the target kind. A stand-in
|
||||
// no maker can field is not a defect: the generator drops the kind from the faction's pool and seats it by the any-maker
|
||||
// fallback, logged (StationKinds.Choose). Returns how many stand-ins were live, so a caller can see the catalog's state.
|
||||
private static int AssertStandInsLive(CultCache cache)
|
||||
{
|
||||
var live = 0;
|
||||
foreach (var kind in cache.GetAll<StationKindData>())
|
||||
foreach (var standIn in kind.StandIns)
|
||||
{
|
||||
var faction = cache.Get(standIn.Faction);
|
||||
var models = StationKinds.KindsOf(cache, faction);
|
||||
var own = cache.GetAll<FactionProductData>().Where(p => cache.Get(p.Manufacturer) == faction && LoadoutGenerator.IsOffered(cache, p))
|
||||
.Select(p => cache.Get(p.Design) as HullData).Where(h => h != null && h.HullType == HullType.Station).Select(h => h.Kind.Key).ToArray();
|
||||
Assert.DoesNotContain(cache.RefOf(kind).Key, own);
|
||||
Assert.Contains(standIn.Kind.Key, own);
|
||||
Assert.NotEmpty(models);
|
||||
var owning = cache.RefOf(kind).Key.Value;
|
||||
Assert.NotNull(cache.Get(standIn.Kind));
|
||||
Assert.DoesNotContain(owning, OracleSoldStationKinds(cache).Where(e => e.maker.Equals(cache.RefOf(faction).Key)).Select(e => e.kind));
|
||||
var carried = OracleOfferedKinds(cache).Contains(standIn.Kind.Key.Value);
|
||||
var fieldable = StationKinds.FieldableKindsOf(cache, faction).Select(k => k.Key.Value).Contains(owning);
|
||||
Assert.Equal(carried, fieldable);
|
||||
if (carried) { live++; continue; }
|
||||
if (StationKinds.FieldableKindsOf(cache, faction).Length > 0) continue;
|
||||
var logged = new List<string>();
|
||||
var seated = StationKinds.Choose(cache, faction, "site", logged.Add);
|
||||
if (OracleOfferedKinds(cache).Count > 0)
|
||||
{
|
||||
Assert.Single(logged);
|
||||
Assert.Contains(seated.Key.Value, OracleOfferedKinds(cache));
|
||||
}
|
||||
}
|
||||
return live;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -434,16 +579,17 @@ public sealed class StationKindTests : IDisposable
|
|||
AssertStandInsLive(cache);
|
||||
}
|
||||
|
||||
// The retirement check is not vacuous: given a stand-in it passes when the faction offers the kind it stands in with and
|
||||
// not the owning kind, and fails when the faction has gained its own model of the owning kind or has no model to use.
|
||||
// The stand-in check is not vacuous: a stand-in passes live when the faction can field the kind it stands in with and has no model
|
||||
// of the owning kind; fails when the faction has gained its own model of the owning kind; is dead, with the fallback observed,
|
||||
// when no maker sells the target kind (a retarget to a kind no hull carries included); and is caught if its target is no kind.
|
||||
[Fact]
|
||||
public void StandInRetirementCheckCanFail()
|
||||
public void StandInCheckCanFail()
|
||||
{
|
||||
var live = World.Make(this, zenithOffered: false);
|
||||
live.Sell(live.Au, "mining");
|
||||
live.StandIn("shipyard", live.Au, "mining");
|
||||
Assert.Single(live.Cache.GetAll<StationKindData>().SelectMany(kind => kind.StandIns));
|
||||
AssertStandInsLive(live.Cache);
|
||||
Assert.Single(live.Cache.GetAll<StationKindData>().SelectMany(kind => kind.StandIns), standIn => live.Cache.Get(standIn.Faction) == live.Au);
|
||||
Assert.Equal(1, AssertStandInsLive(live.Cache));
|
||||
|
||||
var retired = World.Make(this, zenithOffered: false);
|
||||
retired.Sell(retired.Au, "mining");
|
||||
|
|
@ -451,8 +597,19 @@ public sealed class StationKindTests : IDisposable
|
|||
retired.StandIn("shipyard", retired.Au, "mining");
|
||||
Assert.ThrowsAny<Exception>(() => AssertStandInsLive(retired.Cache));
|
||||
|
||||
var hollow = World.Make(this, zenithOffered: false);
|
||||
hollow.StandIn("shipyard", hollow.Au, "mining");
|
||||
Assert.ThrowsAny<Exception>(() => AssertStandInsLive(hollow.Cache));
|
||||
var nowhere = World.Make(this, zenithOffered: false);
|
||||
nowhere.Sell(nowhere.Au, "mining");
|
||||
nowhere.StandIn("shipyard", nowhere.Lucent, "power");
|
||||
Assert.Equal(0, AssertStandInsLive(nowhere.Cache));
|
||||
var logged = new List<string>();
|
||||
Assert.Equal(Kind("mining").Key, StationKinds.Choose(nowhere.Cache, nowhere.Lucent, "site", logged.Add).Key);
|
||||
Assert.Single(logged);
|
||||
|
||||
var missing = World.Make(this, zenithOffered: false);
|
||||
missing.Sell(missing.Au, "mining");
|
||||
missing.StandIn("shipyard", missing.Zh, "mining");
|
||||
var kind = missing.Cache.Get(Kind("shipyard"));
|
||||
kind.StandIns[0].Kind = Kind("no-such-kind");
|
||||
Assert.ThrowsAny<Exception>(() => AssertStandInsLive(missing.Cache));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
227
tools/AetherDb/Economy/Munitions.cs
Normal file
227
tools/AetherDb/Economy/Munitions.cs
Normal file
|
|
@ -0,0 +1,227 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameCult.Caching;
|
||||
|
||||
// Economy content, batch 1: the munitions chain. Rounds (the Ammo commodity ballistic weapons draw), the energetics behind them,
|
||||
// and the parts that fill the roles of ballistic guns, missile racks and the mine launcher: barrel, feed mechanism, warhead,
|
||||
// thruster and dispenser. Zhestokost is the faction this chain is written around (its arsenal commissions plan foundry output,
|
||||
// ammunition and transport together), so it is the faction that places the chain's station kinds until other factions' batches
|
||||
// place them too.
|
||||
//
|
||||
// Goods owned by other chains are named here only as interface goods: written when no record holds the key yet, never
|
||||
// overwritten, and given no recipe. Their own batch writes them unconditionally and owns their recipe, so the batch order
|
||||
// does not decide their content.
|
||||
public sealed class Munitions : EconomyBatch
|
||||
{
|
||||
private EconomyAuthor _a;
|
||||
|
||||
public override void Author(EconomyAuthor author)
|
||||
{
|
||||
_a = author;
|
||||
|
||||
// The kind this chain adds. Energetics and loading are sited apart from other industry because a loading accident must not
|
||||
// take a yard with it; that separation is the reason it is its own kind rather than a line in a fabrication station.
|
||||
_a.Put(new StationKindData
|
||||
{
|
||||
Name = "Munitions Works",
|
||||
Description = "Makes energetics (nitrocellulose, propellant, high explosive), loads rounds, primers, fuzes, warheads and rocket motors; sited apart from other industry so an accident takes only itself.",
|
||||
StandIns = new List<StationKindStandIn>()
|
||||
}, StationKindData.KeyOf("munitions-works"));
|
||||
|
||||
// Zhestokost has no station model of any kind yet. Its first planned model is the supply depot (ruling faction-station-models),
|
||||
// so its industrial kinds stand in on the depot until their own models land. One hop: depot itself has no Zhestokost stand-in.
|
||||
var zhestokost = FactionRef("Zhestokost");
|
||||
foreach (var kind in new[] { "processing", "fabrication", "munitions-works" })
|
||||
StandIn(kind, zhestokost, "depot");
|
||||
|
||||
// Interface goods: named by this chain, owned by another.
|
||||
var steel = Interface("steel", "Steel", "Rolled and drawn structural steel: bar, sheet and billet.", 1f, 30, simple: true);
|
||||
var ammonia = Interface("ammonia", "Ammonia", "Ammonia ice and gas skimmed from cold bodies; the nitrogen in fertiliser and in every explosive.", 0.6f, 15, simple: true);
|
||||
var oxygen = Interface("oxygen", "Oxygen", "Liquid oxygen, cracked from water ice or recovered from life support.", 1.1f, 8, simple: true);
|
||||
var pulp = Interface("cellulose-pulp", "Cellulose Pulp", "Washed cellulose from algae and bacterial vats: the stock for paper, packaging, fibre and guncotton.", 0.8f, 20, simple: true);
|
||||
var actuator = Interface("actuator", "Actuator", "A sealed motor and gear train that moves a load on command; the same unit opens a hatch, feeds a gun or folds laundry.", 2f, 400, simple: false);
|
||||
var diamond = Existing("Diamond");
|
||||
var board = Existing("Circuit Board");
|
||||
var potassium = Existing("Potassium");
|
||||
var methane = Existing("Methane");
|
||||
var water = Existing("Water");
|
||||
|
||||
// Chemistry: processing stations, the same acid plants that feed agriculture.
|
||||
var nitric = Simple("nitric-acid", "Nitric Acid", "Concentrated nitric acid from ammonia burned over a catalyst and absorbed in water.", 1.5f, 40);
|
||||
Recipe(nitric, "processing", 300, 12, 2,
|
||||
"The towers that burn ammonia into acid make fertiliser for the farms and nitrate for the arsenal. In Zhestokost the arsenal commission sets each season's split, so a hold of acid bound for a munitions works instead of an agriculture station tells you which plan won this year.",
|
||||
new[] { "fertiliser" }, (ammonia, 1), (oxygen, 2), (water, 1));
|
||||
|
||||
var saltpetre = Simple("potassium-nitrate", "Potassium Nitrate", "Saltpetre: potassium neutralised with nitric acid and crystallised.", 2.1f, 60);
|
||||
Recipe(saltpetre, "processing", 240, 8, 2,
|
||||
"Saltpetre is fertiliser, curing salt for ration meat, and the oxidiser in powder and primers. A Zhestokost ration tin carries it twice: once in the meat and once in the gun that guards the convoy.",
|
||||
new[] { "fertiliser", "preservative" }, (potassium, 1), (nitric, 1));
|
||||
|
||||
var hexamine = Simple("hexamine", "Hexamine", "White crystalline hexamine from ammonia and methane-derived formaldehyde.", 1.3f, 50);
|
||||
Recipe(hexamine, "processing", 300, 10, 2,
|
||||
"Pressed into tablets, hexamine heats a ration tin in a cold corridor; nitrated, it is the explosive in every warhead. A crate of it is either somebody's winter or somebody's siege.",
|
||||
new[] { "solid fuel", "preservative" }, (ammonia, 2), (methane, 3));
|
||||
|
||||
// Energetics: the munitions works.
|
||||
var guncotton = Simple("nitrocellulose", "Nitrocellulose", "Guncotton: cellulose nitrated in mixed acid, washed and kept damp.", 1.2f, 90);
|
||||
Recipe(guncotton, "munitions-works", 600, 20, 2,
|
||||
"Guncotton comes from the same cellulose vats as paper and packaging, and it also makes the lacquer for stencils and decals: a Zhestokost hull's cream serial numbers and the charge behind its guns came out of the same nitrator.",
|
||||
new[] { "lacquer" }, (pulp, 2), (nitric, 2));
|
||||
|
||||
var powder = Existing("Ballistic Powder");
|
||||
_a.Edit<CompoundCommodityData>("Ballistic Powder", p =>
|
||||
{
|
||||
p.Description = "Single-base propellant: nitrocellulose grains with a saltpetre flash reducer. The charge in every ballistic round and the grain in every rocket motor.";
|
||||
p.Price = 160;
|
||||
});
|
||||
Recipe(powder, "munitions-works", 600, 24, 3,
|
||||
"A ballistic gun fires on the energy this powder holds, not on its ship's reactor, so a heavy formation's reach is set by the powder in its tenders. Watch the powder trains and you know how long a siege is planned to last.",
|
||||
new string[0], (guncotton, 3), (saltpetre, 1));
|
||||
|
||||
var fill = Simple("explosive-fill", "Explosive Fill", "Cast high explosive: hexamine nitrated to RDX and melt-cast with a binder.", 1.8f, 220);
|
||||
Recipe(fill, "munitions-works", 900, 30, 2,
|
||||
"Nothing peaceful is worth the risk of storing cast explosive, so a shipment of it in peacetime is news in itself: someone is filling warheads.",
|
||||
new string[0], (hexamine, 1), (nitric, 3));
|
||||
|
||||
var primer = Compound("primer", "Primer", "Electric percussion primers in a steel cup, packed by the hundred.", 0.2f, 30);
|
||||
Recipe(primer, "munitions-works", 300, 16, 10,
|
||||
"Primers are small, sensitive and made in a hall of their own; a primer-line accident is how a new munitions works learns why its halls stand apart.",
|
||||
new string[0], (saltpetre, 1), (steel, 1));
|
||||
|
||||
// Metal parts: fabrication and the state foundry.
|
||||
var casing = Compound("shell-casing", "Shell Casing", "Deep-drawn steel cartridge cases, lacquered against corrosion.", 0.5f, 40);
|
||||
Recipe(casing, "fabrication", 240, 12, 4,
|
||||
"Zhestokost draws its cases from lacquered steel, not brass: brass is scarce and the arsenal plans for volume, not for reloading. A spent case in a wreck field tells you whose guns fired.",
|
||||
new string[0], (steel, 1));
|
||||
|
||||
var slug = Compound("projectile", "Projectile", "Turned steel slugs with a driving band, sized by calibre.", 0.8f, 60);
|
||||
Recipe(slug, "fabrication", 240, 12, 4,
|
||||
"Each slug carries the tolerance stamp of the foundry that cast its bar, so a quartermaster can trace a bad lot back to a named shift.",
|
||||
new string[0], (steel, 2));
|
||||
|
||||
var ammo = Existing("Ammo");
|
||||
_a.Edit<SimpleCommodityData>("Ammo", a => a.Description = "Crated ballistic rounds: lacquered steel case, steel slug, propellant charge and primer. The round, not the reactor, carries the energy a ballistic gun fires.");
|
||||
Recipe(ammo, "munitions-works", 600, 30, 2,
|
||||
"A tender's hold of crated rounds is a battle's energy budget in transit. Zhestokost heavy formations fight as long as their tenders reach them, and cutting that line is how a faster enemy makes them go quiet.",
|
||||
new string[0], (casing, 2), (slug, 2), (powder, 1), (primer, 2));
|
||||
|
||||
var forging = Compound("gun-forging", "Gun Forging", "Rotary-forged barrel blanks, stamped with the pour number.", 40f, 900);
|
||||
Recipe(forging, "processing", 1800, 40, 1,
|
||||
"Barrel blanks come from the same state foundries that pour hull plate. A foundry shipping forgings is one not shipping plate this quarter, and the arsenal commission's quarterly split is a secret worth stealing.",
|
||||
new string[0], (steel, 4));
|
||||
|
||||
var barrel = Compound("gun-barrel", "Gun Barrel", "A forged blank bored, rifled and diamond-lined.", 35f, 2400);
|
||||
Recipe(barrel, "fabrication", 1200, 30, 1,
|
||||
"The diamond lining decides how many rounds a barrel takes before its crew swaps it. Zhestokost barrels are built to be swapped in the field, under fire, by crews trained on one pattern for twenty years.",
|
||||
new[] { "barrel" }, (forging, 1), (diamond, 1));
|
||||
|
||||
var autoloader = Compound("autoloader", "Autoloader Mechanism", "Rammer, feed tray and cycling actuators that take rounds from a magazine into the breech.", 30f, 2600);
|
||||
Recipe(autoloader, "fabrication", 1200, 30, 1,
|
||||
"The feed is the largest moving part of a Zhestokost gun and the first thing its maintainers learn to strip. The Nakovalnya's feed collar exists so a tender can couple straight into these mechanisms.",
|
||||
new[] { "feed mechanism" }, (steel, 2), (actuator, 2));
|
||||
|
||||
var fragCase = Compound("fragmentation-case", "Fragmentation Case", "A notched steel warhead body that breaks in a set pattern.", 6f, 120);
|
||||
Recipe(fragCase, "fabrication", 600, 14, 2,
|
||||
"The notch pattern is a maker's signature; salvage crews read it in the debris to tell whose warhead it was.",
|
||||
new string[0], (steel, 2));
|
||||
|
||||
var fuze = Compound("fuze", "Fuze", "A proximity and impact fuze: a circuit board, a safe-arm switch and a booster pellet.", 0.6f, 300);
|
||||
Recipe(fuze, "munitions-works", 600, 18, 4,
|
||||
"Fuzes are where munitions meet electronics. When a region runs short of boards, it shows first as warheads without fuzes stacked in a depot.",
|
||||
new string[0], (board, 1), (fill, 1));
|
||||
|
||||
var warhead = Compound("he-warhead", "High-Explosive Warhead", "Explosive fill cast into a fragmentation case, fuzed.", 12f, 1800);
|
||||
Recipe(warhead, "munitions-works", 900, 24, 1,
|
||||
"Death Monkey Explosives and the Zhestokost arsenal fill the same warhead from the same chemistry; only the stencils differ, and a recovered warhead's stencil is evidence in a claim.",
|
||||
new[] { "warhead" }, (fill, 2), (fragCase, 1), (fuze, 1));
|
||||
|
||||
var motor = Compound("rocket-motor", "Rocket Motor", "Propellant cast into a steel case with a nozzle.", 10f, 1500);
|
||||
Recipe(motor, "munitions-works", 900, 20, 1,
|
||||
"The same powder as a gun charge, shaped to burn for seconds instead of milliseconds: missile stocks and gun stocks compete for one powder train.",
|
||||
new[] { "thruster" }, (powder, 2), (steel, 1));
|
||||
|
||||
var dispenser = Compound("mine-dispenser", "Mine Dispenser", "A rack and ejector that lays mines in a pattern.", 20f, 1600);
|
||||
Recipe(dispenser, "fabrication", 900, 20, 1,
|
||||
"Little more than steel and actuators, which is why every convoy navy can build one and every blockade starts with one.",
|
||||
new[] { "dispenser" }, (steel, 2), (actuator, 1));
|
||||
|
||||
// The designs whose every role this chain fills. Missile racks and rocket pods also need a guidance system, which the
|
||||
// electronics chain fills; their recipes wait for it.
|
||||
foreach (var gun in new[] { "Light Machine Gun", "Autocannon", "Long Slug Rifle", "Charged Scattergun", "Slug Rifle", "Flak Gun", "Cluster Cannon", "Point Defense Gun" })
|
||||
Design(gun, 1800, 30, "A ballistic gun is a barrel and a feed; the round brings the energy.");
|
||||
Design("Mine Launcher", 1800, 24, "A dispenser and the warheads it lays.");
|
||||
}
|
||||
|
||||
private CultRecordRef<Faction> FactionRef(string name)
|
||||
{
|
||||
var faction = _a.Catalog.GetAll<Faction>().Single(f => f.Name == name);
|
||||
return new CultRecordRef<Faction>(_a.Catalog.RefOf(faction).Key);
|
||||
}
|
||||
|
||||
// Sets this faction's stand-in on a kind, replacing any it had, so a rerun converges.
|
||||
private void StandIn(string kindId, CultRecordRef<Faction> faction, string standInKindId)
|
||||
{
|
||||
var key = StationKindData.KeyOf(kindId);
|
||||
var kind = _a.Catalog.Get<StationKindData>(key) ?? throw new InvalidOperationException($"The catalog holds no station kind '{kindId}'.");
|
||||
kind.StandIns = kind.StandIns.Where(s => !s.Faction.Key.Equals(faction.Key)).ToList();
|
||||
kind.StandIns.Add(new StationKindStandIn { Faction = faction, Kind = new CultRecordRef<StationKindData>(StationKindData.KeyOf(standInKindId)) });
|
||||
_a.Put(kind, key);
|
||||
}
|
||||
|
||||
private static CultRecordKey CommodityKey(string id) => new CultRecordKey("commodity:" + id);
|
||||
|
||||
private CultRecordRef<ItemData> Interface(string id, string name, string description, float mass, int price, bool simple)
|
||||
{
|
||||
var key = CommodityKey(id);
|
||||
if (_a.Catalog.Get(key) == null)
|
||||
{
|
||||
if (simple) _a.Put(new SimpleCommodityData { Name = name, Description = description, Mass = mass, Price = price }, key);
|
||||
else _a.Put(new CompoundCommodityData { Name = name, Description = description, Mass = mass, Price = price }, key);
|
||||
}
|
||||
return new CultRecordRef<ItemData>(key);
|
||||
}
|
||||
|
||||
private CultRecordRef<ItemData> Simple(string id, string name, string description, float mass, int price)
|
||||
{
|
||||
var key = CommodityKey(id);
|
||||
_a.Put(new SimpleCommodityData { Name = name, Description = description, Mass = mass, Price = price }, key);
|
||||
return new CultRecordRef<ItemData>(key);
|
||||
}
|
||||
|
||||
private CultRecordRef<ItemData> Compound(string id, string name, string description, float mass, int price)
|
||||
{
|
||||
var key = CommodityKey(id);
|
||||
_a.Put(new CompoundCommodityData { Name = name, Description = description, Mass = mass, Price = price }, key);
|
||||
return new CultRecordRef<ItemData>(key);
|
||||
}
|
||||
|
||||
// An item the catalog already holds, by its unique name.
|
||||
private CultRecordRef<ItemData> Existing(string name)
|
||||
{
|
||||
var named = _a.Catalog.GetAll<ItemData>().Where(i => i.Name == name).ToArray();
|
||||
if (named.Length != 1) throw new InvalidOperationException($"{named.Length} items are named '{name}'; the munitions batch needs exactly one.");
|
||||
return new CultRecordRef<ItemData>(_a.Catalog.RefOf(named[0]).Key);
|
||||
}
|
||||
|
||||
private void Recipe(CultRecordRef<ItemData> output, string kind, float cycle, int workforce, int outputCount, string lore, string[] fills,
|
||||
params (CultRecordRef<ItemData> Commodity, int Count)[] inputs)
|
||||
{
|
||||
_a.Put(new RecipeData
|
||||
{
|
||||
Output = output,
|
||||
OutputCount = outputCount,
|
||||
Inputs = inputs.Select(i => new CommodityCount { Commodity = i.Commodity, Count = i.Count }).ToList(),
|
||||
Cycle = cycle,
|
||||
Workforce = workforce,
|
||||
Upkeep = new List<CommodityCount>(),
|
||||
StationKind = new CultRecordRef<StationKindData>(StationKindData.KeyOf(kind)),
|
||||
LoreHook = lore,
|
||||
Fills = fills.ToList()
|
||||
}, RecipeData.KeyOf(output.Key));
|
||||
}
|
||||
|
||||
// A role recipe: its inputs are the design's roles, so it names none.
|
||||
private void Design(string name, float cycle, int workforce, string lore) =>
|
||||
Recipe(Existing(name), "fabrication", cycle, workforce, 1, lore, new string[0]);
|
||||
}
|
||||
Loading…
Reference in a new issue