From 7a2d9c30d4d61dd542f50fb411a32c9f251fcbaf Mon Sep 17 00:00:00 2001 From: soul Date: Fri, 27 Nov 2026 19:55:32 +0100 Subject: [PATCH] Prices covers every design with a recipe: L-price and the harness follow; one ladder width; economy author applied (nine designs repriced from their chains) Co-Authored-By: Claude Sonnet 5.5 --- .changeset/design-bills.md | 5 +++ Assets/Scripts/ServerShared/EconomyBalance.cs | 16 ++++---- Assets/Scripts/ServerShared/EconomyChecks.cs | 4 +- GameData/Aetheria.cc | 2 +- .../DerivedPriceTests.cs | 40 +++++++++++++++++-- tests/Aetheria.Shared.Tests/EconomyFixture.cs | 3 +- .../Aetheria.Shared.Tests/EconomyLoopTests.cs | 37 +++++------------ .../Golden/economy-balance-base.txt | 38 ++++++++---------- .../MunitionsBillsTests.cs | 3 ++ tools/AetherDb/EconomyCommand.cs | 11 ++--- tools/AetherDb/EconomyLoop.cs | 18 ++++----- 11 files changed, 98 insertions(+), 79 deletions(-) create mode 100644 .changeset/design-bills.md diff --git a/.changeset/design-bills.md b/.changeset/design-bills.md new file mode 100644 index 000000000..9dfd9da45 --- /dev/null +++ b/.changeset/design-bills.md @@ -0,0 +1,5 @@ +--- +default: patch +--- + +Ballistic guns and the mine launcher are priced from what they are built from, and the heavier guns need rarer metals: rifled barrels from titanium, lined barrels from tungsten, charged scatter barrels from niobium, rare earths and platinum; flak and point defence guns take a tracking feed. diff --git a/Assets/Scripts/ServerShared/EconomyBalance.cs b/Assets/Scripts/ServerShared/EconomyBalance.cs index 770806487..0b513dd04 100644 --- a/Assets/Scripts/ServerShared/EconomyBalance.cs +++ b/Assets/Scripts/ServerShared/EconomyBalance.cs @@ -42,7 +42,7 @@ public sealed class BalanceReport // The static economy balance: a steady-state input-output reading of the chain (Leontief 1936; Sraffa 1960 zero-profit prices under // one wage; Samuelson 1951: with labour the only primary factor the cheapest filler of a role is demand-independent; Lewis 1954: the // extraction sector sets the going wage). Pure: reads the catalog, writes nothing. ItemData.Price stays the one price the game charges; -// for a made commodity it is the price Prices derives, which economy author writes. Balance's faults are report-only. +// for a made good it is the price Prices derives, which economy author writes. Balance's faults are report-only. public static class EconomyBalance { public const string HMargin = "H-margin", HWage = "H-wage", HConverge = "H-converge"; @@ -136,18 +136,16 @@ public static class EconomyBalance return derived; } - // The price of every made commodity (a commodity whose recipe is not raw) at the going wage: its inputs, upkeep and cheapest - // role fillers at their prices, plus the wage times its labour, over its output count. Raw and recipeless goods keep their - // authored price; designs are not priced here unless asked. Unsettled names the goods still moving when the sweep gave up: a cycle of recipes - // whose requirements do not shrink has no price, so none of the values are a price. - // With designs, the derived price of every design output that has a recipe is returned too: a reading for the report, never a - // price anything writes. - public static Dictionary Prices(CultCache catalog, out List unsettled, bool designs = false) + // The price of every made good (an output whose recipe is not raw) at the going wage: its inputs, upkeep and cheapest + // role fillers at their prices, plus the wage times its labour, over its output count. A design with a recipe is a made good + // priced like a commodity; raw goods and designs with no recipe keep their authored price. Unsettled names the goods still moving + // when the sweep gave up: a cycle of recipes whose requirements do not shrink has no price, so none of the values are a price. + public static Dictionary Prices(CultCache catalog, out List unsettled) { var columns = EconomyChecks.Columns(catalog); var raw = new HashSet(columns.Where(c => Recipes.IsRaw(catalog, c.Recipe)).Select(c => c.Output), StringComparer.Ordinal); var derived = Sweep(catalog, columns, RawWage(catalog, columns, Links(catalog, columns)), raw, out unsettled); - return columns.Where(c => (c.IsCommodity || designs) && !raw.Contains(c.Output)).Select(c => c.Output).Distinct(StringComparer.Ordinal) + return columns.Where(c => !raw.Contains(c.Output)).Select(c => c.Output).Distinct(StringComparer.Ordinal) .ToDictionary(key => key, key => derived[key], StringComparer.Ordinal); } diff --git a/Assets/Scripts/ServerShared/EconomyChecks.cs b/Assets/Scripts/ServerShared/EconomyChecks.cs index cff5de88b..9a265f9fd 100644 --- a/Assets/Scripts/ServerShared/EconomyChecks.cs +++ b/Assets/Scripts/ServerShared/EconomyChecks.cs @@ -163,7 +163,7 @@ public static class EconomyChecks Commodities(catalog).Where(item => item.Shape?.Coordinates == null || item.Shape.Coordinates.Length == 0) .Select(item => new EconomyFault(LShape, catalog.RefOf(item).Key.Value, $"Commodity '{item.Name}' has no Shape cell: a cargo bay cannot hold it.")).ToList(); - // A made commodity's Price is the price EconomyBalance derives from its chain, rounded to whole credits (at least 1); economy author + // A made good's Price (a commodity, or a design with a recipe) is the price EconomyBalance derives from its chain, rounded to whole credits (at least 1); economy author // writes it, and a stored price off it is drift (an inspector edit) that the next author run repairs. public static List PriceCheck(CultCache catalog) { @@ -180,7 +180,7 @@ public static class EconomyChecks if (item == null) continue; var want = EconomyBalance.Rounded(derived); if (item.Price != want) - faults.Add(new EconomyFault(LPrice, key, $"Commodity '{item.Name}' is priced {item.Price}; its chain derives {want}.")); + faults.Add(new EconomyFault(LPrice, key, $"'{item.Name}' is priced {item.Price}; its chain derives {want}.")); } return faults; } diff --git a/GameData/Aetheria.cc b/GameData/Aetheria.cc index f4f340662..d8d927a6a 100644 --- a/GameData/Aetheria.cc +++ b/GameData/Aetheria.cc @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c46adb5c23658824a2c89f552cfdd74da0488777e878cecab9f9a34adfbeefe9 +oid sha256:1521215b420c538dfd117c6855912a20889ca83fba932f9c422aae2ff2e9132a size 282124 diff --git a/tests/Aetheria.Shared.Tests/DerivedPriceTests.cs b/tests/Aetheria.Shared.Tests/DerivedPriceTests.cs index 092474843..64a0564ea 100644 --- a/tests/Aetheria.Shared.Tests/DerivedPriceTests.cs +++ b/tests/Aetheria.Shared.Tests/DerivedPriceTests.cs @@ -5,7 +5,7 @@ using System.Linq; using GameCult.Caching; using Xunit; -// Made commodities are priced from their chain at the raw wage (EconomyBalance.Prices); economy author writes the price and L-price +// Made goods (commodities, and designs with a recipe) are priced from their chain at the raw wage (EconomyBalance.Prices); economy author writes the price and L-price // refuses drift. Fixture chains are hand-solved. public sealed class DerivedPriceTests { @@ -74,22 +74,56 @@ public sealed class DerivedPriceTests } [Fact] - public void RawRecipelessAndDesignPricesAreNotRepriced() + public void RawAndRecipelessPricesAreNotRepricedButADesignWithARecipeIs() { using var f = Chain(); f.Cache.Upsert(typeof(SimpleCommodityData), new SimpleCommodityData { Name = "tin", Price = 7 }, new CultRecordKey("commodity:tin")); var gear = f.Gear("laser", new[] { ("Plate", 1) }); f.Good("plate", inputs: new[] { ("bar", 1) }, fills: new[] { "Plate" }, workforce: 1, cycle: 1); f.EditItem(gear, g => g.Price = 12345); + var bare = f.Gear("bare", new (string, int)[0], recipe: false); + f.EditItem(bare, g => g.Price = 777); Assert.Equal(0, Author(f, true, out _)); using var after = Read(f); Assert.Equal(50, after.Get(new CultRecordKey("commodity:ore")).Price); Assert.Equal(100, after.Get(new CultRecordKey("commodity:salt")).Price); Assert.Equal(7, after.Get(new CultRecordKey("commodity:tin")).Price); - Assert.Equal(12345, after.Get(new CultRecordKey(gear)).Price); + Assert.Equal(777, after.Get(new CultRecordKey(bare)).Price); + // The laser takes one plate: a bar (106.25) and a worker-second of the 6.25 wage, 112.5 rounded half away from zero. + Assert.Equal(113, after.Get(new CultRecordKey(gear)).Price); Assert.Equal(106, after.Get(new CultRecordKey("commodity:bar")).Price); } + // Kills: PriceCheck skipping designs, so a chained design's drift passes unseen. + [Fact] + public void AStaleDesignPriceIsAnLPriceFault() + { + using var f = Chain(); + f.Good("plate", inputs: new[] { ("bar", 1) }, fills: new[] { "Plate" }, workforce: 1, cycle: 1); + var gear = f.Gear("laser", new[] { ("Plate", 1) }); + f.Settle(); + f.EditItem(gear, g => g.Price = 5); + var stale = Assert.Single(EconomyChecks.PriceCheck(f.Cache)); + Assert.Equal(gear, stale.Record); + Assert.Equal(0, Author(f, true, out _)); + using var after = Read(f); + Assert.Empty(EconomyChecks.PriceCheck(after)); + } + + // Kills: repricing every design, whether or not it has a chain. + [Fact] + public void ADesignWithoutARecipeKeepsItsAuthoredPrice() + { + using var f = Chain(); + var bare = f.Gear("bare", new (string, int)[0], recipe: false); + f.EditItem(bare, g => g.Price = 777); + f.Settle(); + Assert.DoesNotContain(EconomyChecks.PriceCheck(f.Cache), x => x.Record == bare); + Assert.Equal(0, Author(f, true, out _)); + using var after = Read(f); + Assert.Equal(777, after.Get(new CultRecordKey(bare)).Price); + } + [Fact] public void AuthorRepricesAfterTheBatchesAndConverges() { diff --git a/tests/Aetheria.Shared.Tests/EconomyFixture.cs b/tests/Aetheria.Shared.Tests/EconomyFixture.cs index b3ad8b1c3..127a79efe 100644 --- a/tests/Aetheria.Shared.Tests/EconomyFixture.cs +++ b/tests/Aetheria.Shared.Tests/EconomyFixture.cs @@ -135,7 +135,8 @@ public sealed class EconomyFixture : IDisposable Rows = rows.Select(r => new OutsideMarketRow { Commodity = Item(r.Commodity), Price = 10, Buys = r.Buys, Sells = r.Sells, RatePerHour = 5 }).ToList() }, OutsideMarketData.KeyOf("gate")); - // Every made commodity at the price its chain derives, as economy author leaves it. + // Every made good (a commodity, or a design with a recipe) at the price its chain derives, as economy author leaves it. A test that + // needs an off-chain design price sets it after Settle. public void Settle() { foreach (var (key, derived) in EconomyBalance.Prices(Cache, out _)) diff --git a/tests/Aetheria.Shared.Tests/EconomyLoopTests.cs b/tests/Aetheria.Shared.Tests/EconomyLoopTests.cs index d093f1e5e..5766630b9 100644 --- a/tests/Aetheria.Shared.Tests/EconomyLoopTests.cs +++ b/tests/Aetheria.Shared.Tests/EconomyLoopTests.cs @@ -64,21 +64,6 @@ public sealed class EconomyLoopTests Assert.DoesNotContain(EconomyLoop.Report(f.Cache, Settings(0, 200), samples).Faults, x => x.Record == "Gear/Reactor"); } - [Fact] - public void ADerivedWidthOutsideTheBandIsAFaultAlthoughTheAuthoredOneIsInIt() - { - using var f = EconomyFixture.Healthy(); - // Authored 2x; derived from one plate against ten, 10x. - f.EditItem("commodity:ore", o => o.Price = 10); - Offer(f, "thin", HardpointType.Reactor, 100, plates: 1); - Offer(f, "thick", HardpointType.Reactor, 200, plates: 10); - var report = EconomyLoop.Report(f.Cache, Settings(1, 5), new[] { Sample(1, 1000, 0, 0, 60) }); - Assert.Equal(2, Ladder(report, "Gear/Reactor").WidthAuthored.Value, 9); - Assert.Equal(10, Ladder(report, "Gear/Reactor").WidthDerived.Value, 9); - var fault = Assert.Single(report.Faults, x => x.Invariant == EconomyLoop.HLadder); - Assert.Contains("derived", fault.Message); - } - [Fact] public void UnsetLadderBandRaisesNoLadderFault() { @@ -87,7 +72,7 @@ public sealed class EconomyLoopTests Offer(f, "dear", HardpointType.Reactor, 1000); // A settings object nobody tuned: its band is what the field defaults to. var report = EconomyLoop.Report(f.Cache, new GameplaySettings(), new[] { Sample(1, 1000, 0, 0, 60) }); - Assert.Equal(100, Ladder(report, "Gear/Reactor").WidthAuthored.Value, 9); + Assert.Equal(100, Ladder(report, "Gear/Reactor").Width.Value, 9); Assert.DoesNotContain(report.Faults, x => x.Invariant == EconomyLoop.HLadder); } @@ -108,8 +93,8 @@ public sealed class EconomyLoopTests var report = EconomyLoop.Report(f.Cache, Settings(10, 30), new[] { Sample(1, 1000, 0, 0, 60) }); var faulted = report.Faults.Where(x => x.Invariant == EconomyLoop.HLadder).Select(x => x.Record).OrderBy(x => x, StringComparer.Ordinal).ToArray(); Assert.Equal(new[] { "Gear/Thruster", "Gear/Tool" }, faulted); - Assert.Null(Ladder(report, "Gear/Sensors").WidthAuthored); - Assert.Null(Ladder(report, "Gear/Energy").WidthAuthored); + Assert.Null(Ladder(report, "Gear/Sensors").Width); + Assert.Null(Ladder(report, "Gear/Energy").Width); } [Fact] @@ -159,18 +144,18 @@ public sealed class EconomyLoopTests Assert.All(report.Ladders.SelectMany(l => l.Designs), d => Assert.Null(d.MinutesAtMedian)); } + // Kills: Prices leaving out a design that has a recipe, or pricing one that has none. [Fact] - public void DesignPricesOnlyWhenAsked() + public void PricesCoverEveryDesignWithARecipe() { using var f = EconomyFixture.Healthy(); - var plain = EconomyBalance.Prices(f.Cache, out _); - Assert.Equal(new[] { "commodity:plate" }, plain.Keys.OrderBy(k => k, StringComparer.Ordinal).ToArray()); - var withDesigns = EconomyBalance.Prices(f.Cache, out _, designs: true); - Assert.Equal(new[] { "commodity:plate", "gear:laser", "hull:skiff" }, withDesigns.Keys.OrderBy(k => k, StringComparer.Ordinal).ToArray()); - Assert.Equal(plain["commodity:plate"], withDesigns["commodity:plate"]); + var prices = EconomyBalance.Prices(f.Cache, out _); + Assert.Equal(new[] { "commodity:plate", "gear:laser", "hull:skiff" }, prices.Keys.OrderBy(k => k, StringComparer.Ordinal).ToArray()); // Laser takes two plates and skiff one, with no labour on either recipe. - Assert.Equal(2 * plain["commodity:plate"], withDesigns["gear:laser"], 9); - Assert.Equal(plain["commodity:plate"], withDesigns["hull:skiff"], 9); + Assert.Equal(2 * prices["commodity:plate"], prices["gear:laser"], 9); + Assert.Equal(prices["commodity:plate"], prices["hull:skiff"], 9); + f.Gear("bare", new (string, int)[0], recipe: false); + Assert.DoesNotContain("gear:bare", EconomyBalance.Prices(f.Cache, out _).Keys); } private static string Root => RunStartTests.FindRepoRoot(); diff --git a/tests/Aetheria.Shared.Tests/Golden/economy-balance-base.txt b/tests/Aetheria.Shared.Tests/Golden/economy-balance-base.txt index 7bda3e2fb..a3b2a267c 100644 --- a/tests/Aetheria.Shared.Tests/Golden/economy-balance-base.txt +++ b/tests/Aetheria.Shared.Tests/Golden/economy-balance-base.txt @@ -1,17 +1,7 @@ -median implied wage 0.00722 per worker-second, spread 2, 70 links, 0 unpriced -23 faults -H-margin (6) - 0271bb97-4ce8-4d64-97c3-8bfd3f76b2c6: Light Machine Gun sells at or below its inputs: implied wage -0.03456 per worker-second. - 1b4a2bb358eb432eb1cfc0ccf3317303: Mine Launcher sells at or below its inputs: implied wage -0.00356 per worker-second. - 2fd0d88b-f565-4021-85b4-02d9eae7be58: Long Slug Rifle sells at or below its inputs: implied wage -0.01696 per worker-second. - 679fb6a1-cefb-4adc-a49c-71942602196b: Slug Rifle sells at or below its inputs: implied wage -0.02067 per worker-second. - 6af6446e40cb4cdd90d7a3fee04394d4: Flak Gun sells at or below its inputs: implied wage -0.01048 per worker-second. - d02bcf71f2c8420b878f036cd1a33bea: Point Defense Gun sells at or below its inputs: implied wage -0.029 per worker-second. -H-wage (17) +median implied wage 0.00722 per worker-second, spread 2, 74 links, 0 unpriced +14 faults +H-wage (14) 043997a8-0661-4206-ab8a-10215ecf4efc: Regolith: implied wage 0.00071 is 0.1x the median 0.00722, outside the spread of 2. - 13116166-f0c8-43cf-a35f-8fd448bc630c: Autocannon: implied wage 0.00248 is 0.34x the median 0.00722, outside the spread of 2. - 3aa1ac05-6d55-4569-8a4b-e1c3c6e07c61: Charged Scattergun: implied wage 0.23396 is 32.39x the median 0.00722, outside the spread of 2. - 8ac84e31-f0cf-43b2-8611-3316adfa4010: Cluster Cannon: implied wage 0.03952 is 5.47x the median 0.00722, outside the spread of 2. commodity:ammonia: Ammonia: implied wage 0.025 is 3.46x the median 0.00722, outside the spread of 2. commodity:anorthite: Anorthite: implied wage 0.00333 is 0.46x the median 0.00722, outside the spread of 2. commodity:brannerite: Brannerite: implied wage 0.015 is 2.08x the median 0.00722, outside the spread of 2. @@ -27,16 +17,9 @@ H-wage (17) commodity:wolframite: Wolframite: implied wage 0.02 is 2.77x the median 0.00722, outside the spread of 2. Links by wage over the median (output | station kind | labour | price | derived cost | wage | ratio) - 0271bb97-4ce8-4d64-97c3-8bfd3f76b2c6 (Light Machine Gun) | Fabrication Station | 54000 | 500 | 2154.75 | -0.03456 | -4.78x - d02bcf71f2c8420b878f036cd1a33bea (Point Defense Gun) | Fabrication Station | 54000 | 800 | 2154.75 | -0.029 | -4.02x - 679fb6a1-cefb-4adc-a49c-71942602196b (Slug Rifle) | Fabrication Station | 54000 | 1250 | 2154.75 | -0.02067 | -2.86x - 2fd0d88b-f565-4021-85b4-02d9eae7be58 (Long Slug Rifle) | Fabrication Station | 54000 | 1450 | 2154.75 | -0.01696 | -2.35x - 6af6446e40cb4cdd90d7a3fee04394d4 (Flak Gun) | Fabrication Station | 54000 | 1800 | 2154.75 | -0.01048 | -1.45x - 1b4a2bb358eb432eb1cfc0ccf3317303 (Mine Launcher) | Fabrication Station | 43200 | 1250 | 1307.13 | -0.00356 | -0.49x commodity:orthoclase (Orthoclase) | Mining Station | 6000 | 1 | 10.83 | 0.00067 | 0.09x 043997a8-0661-4206-ab8a-10215ecf4efc (Regolith) | Mining Station | 8400 | 1 | 10.11 | 0.00071 | 0.1x commodity:sylvite (Sylvite) | Mining Station | 4800 | 2 | 8.67 | 0.00167 | 0.23x - 13116166-f0c8-43cf-a35f-8fd448bc630c (Autocannon) | Fabrication Station | 54000 | 2500 | 2154.75 | 0.00248 | 0.34x commodity:troilite (Troilite) | Mining Station | 6000 | 4 | 10.83 | 0.00267 | 0.37x commodity:anorthite (Anorthite) | Mining Station | 7200 | 6 | 13 | 0.00333 | 0.46x commodity:magnetite (Magnetite) | Mining Station | 6000 | 6 | 10.83 | 0.004 | 0.55x @@ -52,11 +35,19 @@ Links by wage over the median (output | station kind | labour | price | derived commodity:iron (Iron) | Processing Station | 8400 | 36 | 46.58 | 0.00714 | 0.99x commodity:nitrocellulose (Nitrocellulose) | Munitions Works | 12000 | 103 | 101.47 | 0.00717 | 0.99x commodity:he-warhead (High-Explosive Warhead) | Munitions Works | 21600 | 693 | 587.08 | 0.00718 | 0.99x + commodity:coil-barrel (Coil Barrel) | Fabrication Station | 72000 | 6363 | 3582.94 | 0.00719 | 1x commodity:titanium (Titanium) | Processing Station | 16800 | 191 | 186.33 | 0.0072 | 1x commodity:tungsten (Tungsten) | Processing Station | 16800 | 301 | 186.33 | 0.0072 | 1x + 8ac84e31-f0cf-43b2-8611-3316adfa4010 (Cluster Cannon) | Fabrication Station | 108000 | 9942 | 7844.06 | 0.0072 | 1x + 13116166-f0c8-43cf-a35f-8fd448bc630c (Autocannon) | Fabrication Station | 72000 | 4856 | 3413.22 | 0.00721 | 1x + 0271bb97-4ce8-4d64-97c3-8bfd3f76b2c6 (Light Machine Gun) | Fabrication Station | 54000 | 2756 | 2154.75 | 0.00722 | 1x 08c07793-bc06-48dc-adc2-c7e61ef2cb2b (Uranium) | Processing Station | 9000 | 155 | 108.33 | 0.00722 | 1x + 1b4a2bb358eb432eb1cfc0ccf3317303 (Mine Launcher) | Fabrication Station | 43200 | 1716 | 1307.13 | 0.00722 | 1x + 2fd0d88b-f565-4021-85b4-02d9eae7be58 (Long Slug Rifle) | Fabrication Station | 72000 | 3268 | 2657.42 | 0.00722 | 1x 3085fc8a-ec0d-4f6f-a339-ea43edb573e6 (Ammo) | Munitions Works | 18000 | 181 | 183.67 | 0.00722 | 1x 36746041-a5bd-4b95-aa18-294acaaeae62 (Gold) | Processing Station | 3600 | 726 | 78 | 0.00722 | 1x + 679fb6a1-cefb-4adc-a49c-71942602196b (Slug Rifle) | Fabrication Station | 54000 | 3138 | 2527.42 | 0.00722 | 1x + 6af6446e40cb4cdd90d7a3fee04394d4 (Flak Gun) | Fabrication Station | 72000 | 6022 | 3845.47 | 0.00722 | 1x 8776c2fd-45f6-4ca6-8ef0-5214be830182 (Diamond) | Mining Station | 14400 | 104 | 104 | 0.00722 | 1x a8e259fc-fbf1-477a-8248-0277611f1859 (Potassium) | Processing Station | 1800 | 15 | 30.33 | 0.00722 | 1x commodity:aluminium (Aluminium) | Processing Station | 10800 | 108 | 143 | 0.00722 | 1x @@ -71,7 +62,12 @@ Links by wage over the median (output | station kind | labour | price | derived commodity:nitric-acid (Nitric Acid) | Processing Station | 3600 | 31 | 25.28 | 0.00722 | 1x commodity:platinum-group-metals (Platinum Group Metals) | Processing Station | 18000 | 1480 | 208 | 0.00722 | 1x commodity:rare-earth-oxides (Rare Earth Oxides) | Processing Station | 32400 | 474 | 299 | 0.00722 | 1x + commodity:rifled-barrel (Rifled Barrel) | Fabrication Station | 36000 | 1384 | 1385.94 | 0.00722 | 1x commodity:rocket-motor (Rocket Motor) | Munitions Works | 18000 | 455 | 457.76 | 0.00722 | 1x + commodity:tracking-feed (Tracking Feed) | Fabrication Station | 36000 | 3498 | 1298.92 | 0.00722 | 1x + d02bcf71f2c8420b878f036cd1a33bea (Point Defense Gun) | Fabrication Station | 54000 | 4890 | 2702.19 | 0.00722 | 1x + 3aa1ac05-6d55-4569-8a4b-e1c3c6e07c61 (Charged Scattergun) | Fabrication Station | 144000 | 29221 | 16874.72 | 0.00723 | 1x + commodity:lined-barrel (Lined Barrel) | Fabrication Station | 51000 | 1609 | 1390.28 | 0.00724 | 1x commodity:niobium (Niobium) | Processing Station | 21000 | 452 | 216.67 | 0.00724 | 1x commodity:gun-forging (Gun Forging) | Processing Station | 72000 | 638 | 649.28 | 0.00725 | 1x commodity:mines (Mines) | Munitions Works | 18000 | 441 | 390.86 | 0.00728 | 1.01x @@ -92,11 +88,9 @@ Links by wage over the median (output | station kind | labour | price | derived commodity:ammonia (Ammonia) | Volatiles Station | 2400 | 15 | 4.33 | 0.025 | 3.46x commodity:monazite (Monazite) | Mining Station | 6000 | 80 | 21.67 | 0.02667 | 3.69x commodity:columbite (Columbite) | Mining Station | 6000 | 100 | 21.67 | 0.03333 | 4.62x - 8ac84e31-f0cf-43b2-8611-3316adfa4010 (Cluster Cannon) | Fabrication Station | 54000 | 4500 | 2154.75 | 0.03952 | 5.47x commodity:sperrylite (Sperrylite) | Mining Station | 4800 | 450 | 34.67 | 0.09375 | 12.98x commodity:native-gold (Native Gold) | Mining Station | 3600 | 350 | 26 | 0.09722 | 13.46x commodity:isoferroplatinum (Isoferroplatinum) | Mining Station | 3600 | 650 | 26 | 0.18056 | 25x - 3aa1ac05-6d55-4569-8a4b-e1c3c6e07c61 (Charged Scattergun) | Fabrication Station | 54000 | 15000 | 2154.75 | 0.23396 | 32.39x Belts (kind: abundance-weighted price and derived cost per unit; each ore: share, extraction wage ratio, price, cost) Basaltic: price 9.37, cost 12.35 diff --git a/tests/Aetheria.Shared.Tests/MunitionsBillsTests.cs b/tests/Aetheria.Shared.Tests/MunitionsBillsTests.cs index 01b888a53..d24803d1e 100644 --- a/tests/Aetheria.Shared.Tests/MunitionsBillsTests.cs +++ b/tests/Aetheria.Shared.Tests/MunitionsBillsTests.cs @@ -49,6 +49,9 @@ public sealed class MunitionsBillsTests : IDisposable var scarce = new[] { "commodity:niobium", "commodity:rare-earth-oxides", "commodity:platinum-group-metals" }; Assert.All(scarce, key => Assert.Contains(key, Reach(cache, Gun("Charged Scattergun")))); Assert.All(scarce, key => Assert.DoesNotContain(key, Reach(cache, Gun("Light Machine Gun")))); + var guns = new[] { "Light Machine Gun", "Point Defense Gun", "Slug Rifle", "Long Slug Rifle", "Flak Gun", "Autocannon", "Cluster Cannon", "Charged Scattergun" }.Select(Gun).ToArray(); + Assert.Equal("Light Machine Gun", guns.OrderBy(g => g.Price).First().Name); + Assert.Equal("Charged Scattergun", guns.OrderBy(g => g.Price).Last().Name); } // Kills: a rename that misses a stat term, a seller's profile or a bin, or one that does not converge. diff --git a/tools/AetherDb/EconomyCommand.cs b/tools/AetherDb/EconomyCommand.cs index 94b3271dd..4195a9a0b 100644 --- a/tools/AetherDb/EconomyCommand.cs +++ b/tools/AetherDb/EconomyCommand.cs @@ -71,7 +71,7 @@ public static class EconomyCommand { EconomyChecks.LRecipe, EconomyChecks.LLore, EconomyChecks.LProductive, EconomyChecks.LOneKindList, EconomyChecks.LWeights, EconomyChecks.LShape, EconomyChecks.LPrice }; // A batch is compiled code under tools/AetherDb/Economy/ and runs with the operator's authority: reviewed code, never an input. - private const string Usage = "economy report | author [...] [apply] | " + EconomyPrices.Usage + " | balance [--loop [...]] [--cap ]\nbalance reads the chain and changes nothing; --loop adds the player loop (a mining sortie per seed, default seeds 1 2 3 69 97, every belt of each, cap 150 sim seconds a sortie) and the offered gear ladders. A batch is reviewed code: it runs on a trial copy and must write only through EconomyAuthor. After the batches, author reprices every made commodity to the price its chain derives; with no batch it reprices alone."; + private const string Usage = "economy report | author [...] [apply] | " + EconomyPrices.Usage + " | balance [--loop [...]] [--cap ]\nbalance reads the chain and changes nothing; --loop adds the player loop (a mining sortie per seed, default seeds 1 2 3 69 97, every belt of each, cap 150 sim seconds a sortie) and the offered gear ladders. A batch is reviewed code: it runs on a trial copy and must write only through EconomyAuthor. After the batches, author reprices every made good (a commodity, or a design with a recipe) to the price its chain derives; with no batch it reprices alone."; public static int Run(string[] args, TextWriter output) { @@ -172,12 +172,12 @@ public static class EconomyCommand 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))); 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 authored, derived; each design: price | derived | minutes at median | minutes at best | purse covers)"); + 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.WidthAuthored)}, {Width(ladder.WidthDerived)}"); + output.WriteLine($" {ladder.Category}: {Width(ladder.Width)}"); 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.Derived.HasValue ? d.Derived.Value.ToString("0.##", inv) : "-", + 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")); } } @@ -316,7 +316,8 @@ public static class EconomyCommand } } - // Every made commodity takes the price its chain derives. The one writer of a made price: batches may set any, this overwrites it. + // Every made good (a commodity, or a design with a recipe) takes the price its chain derives. The one writer of a made price: + // batches may set any, this overwrites it. private static void Reprice(EconomyAuthor author) { var prices = EconomyBalance.Prices(author.Catalog, out var unsettled); diff --git a/tools/AetherDb/EconomyLoop.cs b/tools/AetherDb/EconomyLoop.cs index d5bb68801..5866c12a1 100644 --- a/tools/AetherDb/EconomyLoop.cs +++ b/tools/AetherDb/EconomyLoop.cs @@ -53,7 +53,8 @@ public sealed class LoopDesign public string Key; public string Name; public int Price; - public double? Derived; + // The design has a recipe, so its price is derived from its chain; otherwise the authored price stands. + public bool Chained; public double? MinutesAtMedian; public double? MinutesAtBest; public bool Covered; @@ -64,8 +65,7 @@ public sealed class LoopLadder public string Category; public List Designs; // Dearest over cheapest, for a category of two or more priced designs; null otherwise. - public double? WidthAuthored; - public double? WidthDerived; + public double? Width; } public sealed class LoopReport @@ -246,7 +246,7 @@ public static class EconomyLoop var rates = samples.Where(s => s.Measured).Select(s => s.RatePerMinute).OrderBy(r => r).ToList(); var median = rates.Count == 0 ? 0 : rates.Count % 2 == 1 ? rates[rates.Count / 2] : (rates[rates.Count / 2 - 1] + rates[rates.Count / 2]) / 2; var best = rates.Count == 0 ? 0 : rates[rates.Count - 1]; - var derived = EconomyBalance.Prices(catalog, out _, designs: true); + var derived = EconomyBalance.Prices(catalog, out _); double? Minutes(int price, double rate) => rate > 0 ? price / rate : (double?) null; double? Width(IEnumerable prices) { @@ -261,15 +261,14 @@ public static class EconomyLoop var key = catalog.RefOf(design).Key.Value; return new LoopDesign { - Key = key, Name = design.Name, Price = design.Price, Derived = derived.TryGetValue(key, out var d) ? d : (double?) null, + Key = key, Name = design.Name, Price = design.Price, Chained = derived.ContainsKey(key), MinutesAtMedian = Minutes(design.Price, median), MinutesAtBest = Minutes(design.Price, best), Covered = design.Price <= settings.StartingCredits }; }).OrderBy(d => d.Price).ThenBy(d => d.Key, StringComparer.Ordinal).ToList(); return new LoopLadder { Category = g.Key, Designs = designs, - WidthAuthored = Width(designs.Select(d => (double) d.Price)), - WidthDerived = Width(designs.Where(d => d.Derived.HasValue).Select(d => d.Derived.Value)) + Width = Width(designs.Select(d => (double) d.Price)) }; }).ToList(); @@ -287,9 +286,8 @@ public static class EconomyLoop var (min, max) = (settings.EconomyLadderMin, settings.EconomyLadderMax); if (min > 0 || max > 0) foreach (var ladder in ladders) - foreach (var (width, which) in new[] { (ladder.WidthAuthored, "authored"), (ladder.WidthDerived, "derived") }) - if (width.HasValue && ((min > 0 && width.Value < min) || (max > 0 && width.Value > max))) - faults.Add(new EconomyFault(HLadder, ladder.Category, $"the {which} ladder is {width.Value:0.##}x wide, outside the band {min:0.##} to {max:0.##}.")); + if (ladder.Width.HasValue && ((min > 0 && ladder.Width.Value < min) || (max > 0 && ladder.Width.Value > max))) + faults.Add(new EconomyFault(HLadder, ladder.Category, $"the ladder is {ladder.Width.Value:0.##}x wide, outside the band {min:0.##} to {max:0.##}.")); return new LoopReport { Samples = samples, Median = median, Best = best, Purse = settings.StartingCredits, Ladders = ladders, Faults = faults }; } }