AetherDb: MunitionsFeed gives the munitions chain real sources; Mines; every round-firing gun names its round
MunitionsFeed (run after Munitions) authors the chain's leaf recipes: extraction at mining (Rock, New Metals, Gold, Potassium, Diamond) and volatiles (Water, Methane, Ammonia), Algae at agriculture, Oxygen/Steel/Cellulose Pulp at processing, Circuit Board/Actuator at fabrication. Munitions adds the Mines commodity and recipe, AmmoType=Ammo on Slug Rifle, Long Slug Rifle and Light Machine Gun, AmmoType=Mines on the Mine Launcher, a real Light Machine Gun magazine (0 -> 100 rounds, reload 3 s), and Zhestokost depot stand-ins for mining, volatiles and agriculture so the new recipes' station kinds are placed. Tests read the shipped catalog (pending the blob commit). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
1a8ced9ab6
commit
1f93e22239
3 changed files with 191 additions and 1 deletions
79
tests/Aetheria.Shared.Tests/MunitionsSourcingCatalogTests.cs
Normal file
79
tests/Aetheria.Shared.Tests/MunitionsSourcingCatalogTests.cs
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameCult.Caching;
|
||||
using Xunit;
|
||||
|
||||
// Ruling ballistics-real-ammo, read from the shipped catalog: every gun that fires a round names the commodity it draws, and every
|
||||
// such commodity (and the chain behind it) is produced from extraction, not from nothing. A round with no source is a magazine
|
||||
// nobody can ever refill.
|
||||
public sealed class MunitionsSourcingCatalogTests
|
||||
{
|
||||
// The guns that fire real rounds: ballistic and launcher hardpoints, and the mine layer (a launcher in all but hardpoint).
|
||||
private static bool FiresRounds(WeaponItemData item, WeaponData data) =>
|
||||
item.HardpointType == HardpointType.Ballistic || item.HardpointType == HardpointType.Launcher || data is MineLayerData;
|
||||
|
||||
// Kills: a ballistic gun (or the Light Machine Gun's free hose) authored with AmmoType unset, which reloads for nothing; a
|
||||
// drawn commodity that is not a commodity record; a magazine too small for a reload to mean anything.
|
||||
[Fact]
|
||||
public void EveryRoundFiringGunNamesAnAmmunitionCommodityAndHoldsARealMagazine()
|
||||
{
|
||||
using var db = AetherDb.Open();
|
||||
var guns = db.Cache.GetAll<WeaponItemData>()
|
||||
.SelectMany(i => i.Behaviors.OfType<WeaponData>().Where(d => FiresRounds(i, d)).Select(d => (i.Name, d))).ToArray();
|
||||
Assert.True(guns.Length >= 14, $"fixture: the catalog holds its round-firing guns ({guns.Length})");
|
||||
foreach (var (name, data) in guns)
|
||||
{
|
||||
Assert.True(data.AmmoType.IsSet(), $"{name} draws no ammunition");
|
||||
Assert.NotNull(db.Cache.Get<SimpleCommodityData>(data.AmmoType.Key));
|
||||
Assert.True(data.MagazineSize >= 1, $"{name} has no magazine");
|
||||
}
|
||||
Assert.Equal(new[] { "Ammo", "Mines", "Missiles" }, guns.Select(g => db.Cache.Get<SimpleCommodityData>(g.d.AmmoType.Key).Name).Distinct().OrderBy(n => n).ToArray());
|
||||
}
|
||||
|
||||
// Kills: an ammunition commodity no chain of recipes reaches raw goods for (the Ammo, Missiles and Mines leaves had no recipe at all).
|
||||
[Fact]
|
||||
public void EveryDrawnAmmunitionHasAFiniteProductionDepth()
|
||||
{
|
||||
using var db = AetherDb.Open();
|
||||
var depth = EconomyChecks.Deep(db.Cache);
|
||||
var drawn = db.Cache.GetAll<WeaponItemData>().SelectMany(i => i.Behaviors.OfType<WeaponData>()).Where(d => d.AmmoType.IsSet())
|
||||
.Select(d => d.AmmoType.Key.Value).Distinct().ToArray();
|
||||
Assert.Equal(3, drawn.Length);
|
||||
foreach (var key in drawn)
|
||||
Assert.True(depth[key] != null, $"{db.Cache.Get<ItemData>(new CultRecordKey(key)).Name} has no finite production depth");
|
||||
}
|
||||
|
||||
// Kills: a leaf of the munitions chain left without a source or a sink (the 19 L-source-sink faults this chain shipped with).
|
||||
[Fact]
|
||||
public void TheMunitionsChainHasNoSourceSinkFault()
|
||||
{
|
||||
using var db = AetherDb.Open();
|
||||
var chain = new HashSet<string>(ChainOf(db.Cache), System.StringComparer.Ordinal);
|
||||
Assert.True(chain.Count >= 25, $"fixture: the chain is walked ({chain.Count} goods)");
|
||||
var faults = EconomyChecks.SourceSink(db.Cache).Where(f => chain.Contains(KeyOfRecipe(f.Record))).ToArray();
|
||||
Assert.True(faults.Length == 0, string.Join("\n", faults.Select(f => f.Message)));
|
||||
}
|
||||
|
||||
private static string KeyOfRecipe(string recipeKey) => recipeKey.StartsWith("recipe:") ? recipeKey.Substring("recipe:".Length) : recipeKey;
|
||||
|
||||
// Every good that feeds a drawn round, or fills a role of a round-firing gun, through the recipe graph; the rounds included.
|
||||
private static IEnumerable<string> ChainOf(CultCache catalog)
|
||||
{
|
||||
var recipes = catalog.GetAll<RecipeData>().ToDictionary(r => r.Output.Key.Value);
|
||||
var open = new Stack<string>(catalog.GetAll<WeaponItemData>().SelectMany(i => i.Behaviors.OfType<WeaponData>())
|
||||
.Where(d => d.AmmoType.IsSet()).Select(d => d.AmmoType.Key.Value).Distinct());
|
||||
foreach (var item in catalog.GetAll<WeaponItemData>().Where(i => i.Behaviors.OfType<WeaponData>().Any(d => FiresRounds(i, d))))
|
||||
{
|
||||
var recipe = Recipes.RecipeOf(catalog, item);
|
||||
if (recipe == null) continue;
|
||||
foreach (var role in Recipes.RoleInputsOf(catalog, recipe))
|
||||
foreach (var filler in Recipes.Fillers(catalog, role.Name)) open.Push(filler.Value);
|
||||
}
|
||||
var seen = new HashSet<string>(open);
|
||||
while (open.Count > 0)
|
||||
if (recipes.TryGetValue(open.Pop(), out var recipe))
|
||||
foreach (var input in recipe.Inputs.Select(c => c.Commodity.Key.Value))
|
||||
if (seen.Add(input)) open.Push(input);
|
||||
return seen;
|
||||
}
|
||||
}
|
||||
|
|
@ -32,7 +32,9 @@ public sealed class Munitions : EconomyBatch
|
|||
// 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" })
|
||||
// The feed stock for the chain (MunitionsFeed) is extracted and grown where the arsenal's planners can reach it, so the mining,
|
||||
// volatiles and agriculture kinds stand in on the depot too until the factions that own those industries place them.
|
||||
foreach (var kind in new[] { "processing", "fabrication", "munitions-works", "mining", "volatiles", "agriculture" })
|
||||
StandIn(kind, zhestokost, "depot");
|
||||
|
||||
// Interface goods: named by this chain, owned by another.
|
||||
|
|
@ -153,6 +155,15 @@ public sealed class Munitions : EconomyBatch
|
|||
"A missile crate is a warhead and a motor in one box, and the box is the arsenal's most counted object: Zhestokost ties each launcher crew's allowance to a serial range, so a cache of loose crates is either a deserter's or a quartermaster's crime.",
|
||||
new string[0], (warhead, 1), (motor, 1));
|
||||
|
||||
// Mines: the crate the mine launcher reloads from, a warhead per mine laid. Shape and stack as Missiles.
|
||||
var mines = new SimpleCommodityData { Name = "Mines", Shape = new Shape(), MaxStack = 5, Mass = 7f, Price = 1400,
|
||||
Description = "Crated proximity mines: a high-explosive warhead in a steel drum with a fuzed trigger. The crate a mine launcher reloads from." };
|
||||
_a.Put(mines, CommodityKey("mines"));
|
||||
var minesRef = new CultRecordRef<ItemData>(CommodityKey("mines"));
|
||||
Recipe(minesRef, "munitions-works", 900, 20, 2,
|
||||
"A mine is a warhead with patience. Every blockade that holds a lane for a season is paid for in crates of these, and a convoy captain who finds a lane suddenly quiet counts the hours since the last tender came through.",
|
||||
new string[0], (warhead, 1), (steel, 2));
|
||||
|
||||
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.",
|
||||
|
|
@ -171,6 +182,22 @@ public sealed class Munitions : EconomyBatch
|
|||
{
|
||||
foreach (var data in w.Behaviors.OfType<WeaponData>()) data.AmmoType = new CultRecordRef<SimpleCommodityData>(CommodityKey("missiles"));
|
||||
});
|
||||
|
||||
// Every ballistic gun draws a round (ruling ballistics-real-ammo). The Light Machine Gun had no magazine, a free hose; it gets a
|
||||
// real one so a single Ammo crate reloads it like the other guns. The mine launcher draws a Mines crate.
|
||||
foreach (var gun in new[] { "Slug Rifle", "Long Slug Rifle", "Light Machine Gun" })
|
||||
_a.Edit<WeaponItemData>(gun, w =>
|
||||
{
|
||||
foreach (var data in w.Behaviors.OfType<WeaponData>())
|
||||
{
|
||||
data.AmmoType = new CultRecordRef<SimpleCommodityData>(ammo.Key);
|
||||
if (gun == "Light Machine Gun") { data.MagazineSize = 100; data.ReloadTime = 3f; }
|
||||
}
|
||||
});
|
||||
_a.Edit<WeaponItemData>("Mine Launcher", w =>
|
||||
{
|
||||
foreach (var data in w.Behaviors.OfType<WeaponData>()) data.AmmoType = new CultRecordRef<SimpleCommodityData>(CommodityKey("mines"));
|
||||
});
|
||||
}
|
||||
|
||||
private CultRecordRef<Faction> FactionRef(string name)
|
||||
|
|
|
|||
84
tools/AetherDb/Economy/MunitionsFeed.cs
Normal file
84
tools/AetherDb/Economy/MunitionsFeed.cs
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameCult.Caching;
|
||||
|
||||
// Economy content, batch 1b: where the munitions chain's raw materials come from. Munitions writes the chain and names its leaves
|
||||
// (Water, Methane, Ammonia, Oxygen, Potassium, Diamond, Steel, Cellulose Pulp, Actuator, Circuit Board) without recipes; this batch
|
||||
// gives each a source at a station kind whose description already says it does that work: input-free extraction at mining (ore,
|
||||
// Gold, Potassium, Diamond) and volatiles (Water, Methane, Ammonia), and processing or fabrication from those goods for the rest.
|
||||
// Run after Munitions: it edits nothing the other batch writes and every output it names must exist.
|
||||
public sealed class MunitionsFeed : EconomyBatch
|
||||
{
|
||||
private EconomyAuthor _a;
|
||||
|
||||
public override void Author(EconomyAuthor author)
|
||||
{
|
||||
_a = author;
|
||||
|
||||
// Extraction: no inputs, so these are the chain's raw goods.
|
||||
var rock = Make("Rock", "mining", 300, 10, 8,
|
||||
"Nobody on a mining station calls it rock; it is the overburden, the slag, the thing the real cargo was buried in. It is also what every smelter, board shop and cement yard starts from, so the cheapest hold in the verse is the one that decides who can build.");
|
||||
var metals = Make("New Metals", "mining", 300, 12, 6,
|
||||
"The ore that built the cities: whoever holds the claim feeds every foundry downstream, which is why mining rights are the one commodity the garrisons will not leave unguarded.");
|
||||
var gold = Make("Gold", "mining", 600, 8, 2,
|
||||
"Gold has a use besides vanity: it does not corrode in a contact. Boards bound for a hull in a cold or wet corridor are gold-plated, and a prospector who finds a seam sells it to the board shops before the jewellers.");
|
||||
var potassium = Make("Potassium", "mining", 300, 8, 4,
|
||||
"Potash and saltpetre salts turn up in the same evaporite beds that mark old water. Farms want it for fertiliser and the arsenal wants it for powder; the survey crews tag the beds by which buyer reached them first.");
|
||||
var diamond = Make("Diamond", "mining", 1200, 12, 1,
|
||||
"Industrial stones from the deep kimberlite cores: grit for lining barrels and cutting tools rather than jewellery. A miner who sells one for a ring has wasted a barrel.");
|
||||
var water = Make("Water", "volatiles", 300, 8, 6,
|
||||
"Every station buys water first and everything else second. The ice haulers run on the knowledge that a station's water reserve is the one stock it cannot be talked out of counting.");
|
||||
var methane = Make("Methane", "volatiles", 300, 8, 4,
|
||||
"Skimmed from the cold ice where it keeps for ever. Hauled home it is cooking gas, a feedstock for the formaldehyde plants, and the first thing that burns when a tank is struck.");
|
||||
var ammonia = Make("Ammonia", "volatiles", 300, 8, 4,
|
||||
"Ammonia ice is the nitrogen the whole verse eats and shoots: the farms spread it and the arsenals nitrate it. The skimmers who work cold bodies know exactly which of the two their hold is bound for by the hauler waiting at the dock.");
|
||||
|
||||
// Processing from those goods.
|
||||
var oxygen = Make("Oxygen", "processing", 240, 10, 3,
|
||||
"Cracking water ice pays twice: the oxygen goes to lungs and acid towers, and the hydrogen is fuel. A station that sells its oxygen cheap is either swimming in ice or hiding a shortage.",
|
||||
(water, 3));
|
||||
|
||||
var steel = Make("Steel", "processing", 600, 20, 4,
|
||||
"Foundries on the ore belts pour bar, sheet and billet from alloy ore and slag flux. A pour is cheap; the rolling mills that finish it are the part a blockade starves, and every gun, hull plate and nail in the verse is waiting behind them.",
|
||||
(metals, 3), (rock, 1));
|
||||
|
||||
// Algae is a catalog commodity the agriculture station description says grows from Water and Potassium.
|
||||
var algae = Make("Algae", "agriculture", 600, 12, 6,
|
||||
"Vats of green water under lamp-light: the first thing a new habitat grows, because it eats ash and sunlight and gives back food, fibre and air. A farm that loses its algae loses its station within the season.",
|
||||
(water, 2), (potassium, 1));
|
||||
|
||||
var pulp = Make("Cellulose Pulp", "processing", 300, 10, 2,
|
||||
"Algae from the farm vats is washed, digested and pressed into pulp. The same vats make paper for a Zhestokost order book and guncotton stock for its arsenal, and the split is seen in how many hands the washing hall hires.",
|
||||
(algae, 3));
|
||||
|
||||
var board = Make("Circuit Board", "fabrication", 600, 14, 2,
|
||||
"Gold-plated contacts on a silicate board: the oldest reliable electronics. A region that cannot make its own boards imports a shortage in every device that has a fuze, a sensor or a lock.",
|
||||
(gold, 1), (rock, 2));
|
||||
|
||||
Make("Actuator", "fabrication", 600, 16, 1,
|
||||
"A steel housing, a motor and a controller board. It opens hatches and feeds guns, and a repair crew keeps a drawer of them because everything on a ship eventually needs to move on command.",
|
||||
(steel, 2), (board, 1));
|
||||
}
|
||||
|
||||
private CultRecordRef<ItemData> Make(string name, string kind, float cycle, int workforce, int count, string lore,
|
||||
params (CultRecordRef<ItemData> Commodity, int Count)[] inputs)
|
||||
{
|
||||
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 feed needs exactly one.");
|
||||
var output = new CultRecordRef<ItemData>(_a.Catalog.RefOf(named[0]).Key);
|
||||
_a.Put(new RecipeData
|
||||
{
|
||||
Output = output,
|
||||
OutputCount = count,
|
||||
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 = new List<string>()
|
||||
}, RecipeData.KeyOf(output.Key));
|
||||
return output;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue