diff --git a/tests/Aetheria.Shared.Tests/MunitionsBillsTests.cs b/tests/Aetheria.Shared.Tests/MunitionsBillsTests.cs index d24803d1e..a3bd6c027 100644 --- a/tests/Aetheria.Shared.Tests/MunitionsBillsTests.cs +++ b/tests/Aetheria.Shared.Tests/MunitionsBillsTests.cs @@ -105,4 +105,36 @@ public sealed class MunitionsBillsTests : IDisposable var gun = Assert.Single(cache.GetAll(), w => w.Name == "Autocannon"); Assert.Equal(99, cache.Get(RecipeData.KeyOf(cache.RefOf(gun).Key)).Workforce); } + + // What the shipped catalog holds of the bills: every part and design with its price, role counts and recipe, as text. + private static string[] Bills(CultCache cache) + { + var keys = new[] { "rifled-barrel", "lined-barrel", "coil-barrel", "tracking-feed" }.Select(id => new CultRecordKey("commodity:" + id)).ToList(); + var designs = new[] { "Light Machine Gun", "Point Defense Gun", "Slug Rifle", "Long Slug Rifle", "Flak Gun", "Autocannon", "Cluster Cannon", "Charged Scattergun", "Mine Launcher" }; + keys.AddRange(designs.Select(name => cache.RefOf(Assert.Single(cache.GetAll(), w => w.Name == name)).Key)); + return keys.Select(key => + { + var item = cache.Get(key); + var recipe = cache.Get(RecipeData.KeyOf(key)); + var roles = string.Join(",", Recipes.RolesOf(item).OrderBy(r => r.Name, StringComparer.Ordinal).Select(r => r.Name + "x" + r.Count)); + var inputs = string.Join(",", recipe.Inputs.OrderBy(i => i.Commodity.Key.Value, StringComparer.Ordinal).Select(i => i.Commodity.Key.Value + "x" + i.Count)); + return $"{item.Name}|price {item.Price}|roles {roles}|inputs {inputs}|fills {string.Join(",", recipe.Fills)}|cycle {recipe.Cycle} wf {recipe.Workforce} out {recipe.OutputCount}"; + }).ToArray(); + } + + // Kills: an edit to the batch (a bill count, a part input, a workforce) that the shipped catalog does not carry, or a catalog edit the + // batch would silently undo on its next apply. Byte equality is out of reach (element ids are minted on every write), so the batch is + // applied to a copy and the records it owns are compared as text, prices included. + [Fact] + public void TheBatchWritesWhatTheShippedCatalogHolds() + { + var path = ShippedCopy("Bills.cc"); + using (var shipped = AetheriaStores.Open(TestCatalog.Repo, registry: TestCatalog.Registry())) + { + var output = new StringWriter(); + Assert.True(EconomyCommand.Author(path, new EconomyBatch[] { new MunitionsBills() }, true, output, TestCatalog.Registry(), _root) == 0, output.ToString()); + using var applied = AetheriaStores.Open(path, registry: TestCatalog.Registry()); + Assert.Equal(Bills(shipped), Bills(applied)); + } + } } diff --git a/tools/AetherDb/Economy/MunitionsBills.cs b/tools/AetherDb/Economy/MunitionsBills.cs index e026bf8c0..0db457006 100644 --- a/tools/AetherDb/Economy/MunitionsBills.cs +++ b/tools/AetherDb/Economy/MunitionsBills.cs @@ -13,7 +13,7 @@ using GameCult.Caching; // // Owner of the munitions chain's design recipes, their role counts and tier role names, and the four tier parts. Munitions writes // the parts the starter fills and the rounds; it writes no design recipe, so a Munitions rerun cannot undo a bill. Renames run -// before bills, and a design that already holds the new role name is left alone, so a rerun writes nothing. +// before bills, and a design that already holds the new role name is left alone, so a rerun changes no price, role or count (it does rewrite the four part recipes as new bytes: CommodityCount carries a cache-minted element id). public sealed class MunitionsBills : EconomyBatch { private EconomyAuthor _a; @@ -91,7 +91,7 @@ public sealed class MunitionsBills : EconomyBatch } // Renames a role of a design everywhere it is read: the design's roles, every stat term of every behaviour, and every non-bin - // seller's profile. A design that holds the new name and not the old is left alone, so a rerun writes nothing. + // seller's profile. A design that holds the new name and not the old is left alone, so a rerun renames nothing. public static void RenameRole(EconomyAuthor author, string design, string from, string to) { CultRecordKey key = default; diff --git a/tools/AetherDb/EconomyCommand.cs b/tools/AetherDb/EconomyCommand.cs index 4195a9a0b..7c7a2a849 100644 --- a/tools/AetherDb/EconomyCommand.cs +++ b/tools/AetherDb/EconomyCommand.cs @@ -8,7 +8,7 @@ using MessagePack; // One batch of economy content: commodities, recipes, station kinds with stand-ins, outside-market rows and edits to existing // items, written through EconomyAuthor. A batch is a class under tools/AetherDb/Economy/, named on the command line by its class -// name. It writes what it names and nothing else, so a revised batch converges and a rerun writes nothing. +// name. It writes what it names and nothing else, so a revised batch converges to the same records; a rerun rewrites any recipe that has inputs as new bytes (their elements carry cache-minted ids), and only `author` with no batch is certain to print Nothing to write. public abstract class EconomyBatch { public abstract void Author(EconomyAuthor author); @@ -170,12 +170,13 @@ public static class EconomyCommand output.WriteLine(string.Format(inv, " {0} {11}/{12} | {1} | {2} | {13} | {3} | {4:0.#} | {5} | {6} | {7} | {8} | {9} | {10:0.#}", s.Seed, s.BeltKind, s.Weapons, s.Rocks, s.SimSeconds, s.HoldFullAt.HasValue ? s.HoldFullAt.Value.ToString("0.#", inv) + " s" : "never", s.Units, s.SellValue, s.AmmoSpent, s.Repair, s.RatePerMinute, s.Belt + 1, s.Belts, s.Outcome)); output.WriteLine(string.Format(inv, " median {0:0.#} per minute, best {1:0.#} per minute over the {3} sorties that mined to a full hold or the cap; purse {2}", loop.Median, loop.Best, loop.Purse, loop.Samples.Count(s => s.Measured))); + output.WriteLine(string.Format(inv, " median net per sortie {0:0.#} (the afford band counts sorties of this net, resting on {1} measured sorties)", loop.MedianNet, loop.MeasuredSorties)); string Minutes(double? m) => m.HasValue ? m.Value.ToString("0.#", inv) : "-"; string Width(double? w) => w.HasValue ? w.Value.ToString("0.##", inv) + "x" : "-"; output.WriteLine("\nLadders (category: width; each design: price | priced from | minutes at median | minutes at best | purse covers)"); foreach (var ladder in loop.Ladders) { - output.WriteLine($" {ladder.Category}: {Width(ladder.Width)}"); + output.WriteLine($" {ladder.Category}: {Width(ladder.Width)}{(ladder.TopSorties.HasValue ? $", top {ladder.TopSorties.Value.ToString("0.#", inv)} sorties" : "")}"); foreach (var d in ladder.Designs) output.WriteLine(string.Format(inv, " {0} ({1}) | {2} | {3} | {4} | {5} | {6}", d.Name, d.Key, d.Price, d.Chained ? "chain" : "authored", Minutes(d.MinutesAtMedian), Minutes(d.MinutesAtBest), d.Covered ? "yes" : "no"));