From 3ccb9801854d1610c17ff997f25fc84c68bb1e47 Mon Sep 17 00:00:00 2001 From: Nibu Date: Thu, 12 Nov 2026 23:01:04 +0000 Subject: [PATCH] Ore sheet: DemoOre batch and tests for the Asteroid ore yields, holdability and prices Co-Authored-By: Claude Sonnet 5.5 --- GameData/Aetheria.cc | 4 +- .../DemoOreSheetTests.cs | 92 +++++++++++++++++++ tools/AetherDb/Economy/DemoOre.cs | 44 +++++++++ 3 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 tests/Aetheria.Shared.Tests/DemoOreSheetTests.cs create mode 100644 tools/AetherDb/Economy/DemoOre.cs diff --git a/GameData/Aetheria.cc b/GameData/Aetheria.cc index f4cfdc4a3..ef463cde8 100644 --- a/GameData/Aetheria.cc +++ b/GameData/Aetheria.cc @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9edc8434524f43f751c89416479cf07fba03b424f266cb8bfc1870bd46eef6a7 -size 220537 +oid sha256:62a6678e741e296449b6ac8cd8698e071a873ea39bc9c0303abe68887310dceb +size 220731 diff --git a/tests/Aetheria.Shared.Tests/DemoOreSheetTests.cs b/tests/Aetheria.Shared.Tests/DemoOreSheetTests.cs new file mode 100644 index 000000000..24ef521eb --- /dev/null +++ b/tests/Aetheria.Shared.Tests/DemoOreSheetTests.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using CultMath; +using GameCult.Caching; +using Xunit; + +// The interim ore sheet (rulings mining-demo-ore-minimal-yields-now, mining-demo-ore-prices-gear-scale): what the shipped catalog's +// Asteroid belt holds can be carried and sold, so mine, sell, repair closes on the existing stations. +public sealed class DemoOreSheetTests : IDisposable +{ + private static readonly string[] Ores = { "Rock", "New Metals", "Gold" }; + private readonly string _root = Path.Combine(Path.GetTempPath(), "aetheria-demoore-" + Guid.NewGuid().ToString("N")); + + public DemoOreSheetTests() => Directory.CreateDirectory(_root); + public void Dispose() => Directory.Delete(_root, true); + + private CultCache Shipped() + { + var path = Path.Combine(_root, "Aetheria.cc"); + File.Copy(TestCatalog.Repo, path, true); + return AetheriaStores.Open(path, catalogWritable: true, registry: TestCatalog.Registry()); + } + + private static CultRecordRef Asteroid(CultCache cache) => + cache.RefOf(cache.GetAll().Single(k => k.Name == "Asteroid")); + + [Fact] + public void AsteroidYieldsThreeOresInKeyOrder() + { + using var cache = Shipped(); + var yield = FieldKinds.Yield(Asteroid(cache), default, cache); + var amounts = yield.ToDictionary(y => cache.Get(y.Commodity).Name, y => y.Amount); + Assert.Equal(Ores.OrderBy(n => n).ToArray(), amounts.Keys.OrderBy(n => n).ToArray()); + Assert.Equal(6f, amounts["Rock"]); + Assert.Equal(3f, amounts["New Metals"]); + Assert.Equal(1f, amounts["Gold"]); + Assert.Equal(yield.Select(y => y.Commodity.Key.Value).OrderBy(k => k, StringComparer.Ordinal), yield.Select(y => y.Commodity.Key.Value)); + } + + [Fact] + public void EveryYieldedOreCanBeHeldAndSold() + { + using var cache = Shipped(); + var shape = new Shape(5, 5); + foreach (var cell in shape.AllCoordinates) shape[cell] = true; + var bay = new Shape(4, 4); + foreach (var cell in bay.AllCoordinates) bay[cell] = true; + cache.Upsert(new VerseGrammar { Revision = 1 }); + cache.Upsert(new HullData { Name = "OreSkiff", HullType = HullType.Ship, Shape = shape, Price = 1000, Durability = 10, Armor = 10 }); + cache.Upsert(new CargoBayData { Name = "OreBay", Shape = new Shape(), InteriorShape = bay, Price = 20, Durability = 4 }); + cache.FlushAsync().GetAwaiter().GetResult(); + var items = new ItemManager(1u, cache, new ProvenanceLedger(), AuthoredSettings.Load(RestoredHullsTests.FindRepoRoot()).Read("GameplaySettings"), _ => { }); + var zone = new Zone(items, new PlanetSettings(), new ZonePack(), new GalaxyZone { Name = "Test Zone", Owner = null }, null); + EquippableItem Mint(string design) + { + var data = cache.GetByName(design); + return new EquippableItem + { + Data = cache.RefOf(data), Durability = data.Durability, + Lot = items.Lots.Add(new Lot { Design = cache.RefOf(data), Origin = new Attributed(), Quality = .5f, Roles = new List() }) + }; + } + var ship = new Ship(items, zone, Mint("OreSkiff"), new EntitySettings()); + Assert.True(ship.TryEquip(Mint("OreBay"), new int2(1, 1))); + + foreach (var (commodity, _) in FieldKinds.Yield(Asteroid(cache), default, cache)) + { + var data = cache.Get(commodity); + Assert.NotNull(data.Shape); + Assert.True(data.Price > 0, data.Name); + Assert.True(data.Mass > 0, data.Name); + Assert.True(ship.CargoBays.Single().TryStore(new SimpleCommodity { Data = cache.RefOf(data), Quantity = 1 }), data.Name); + } + } + + [Fact] + public void TheSheetConverges() + { + var path = Path.Combine(_root, "Converge.cc"); + File.Copy(Path.Combine(RestoredHullsTests.FindRepoRoot(), "GameData", "Aetheria.cc"), path); + var before = File.ReadAllBytes(path); + var output = new StringWriter(); + Assert.Equal(0, EconomyCommand.Author(path, new List { new DemoOre() }, true, output, TestCatalog.Registry(), _root)); + Assert.Equal(before, File.ReadAllBytes(path)); + + using var cache = AetheriaStores.Open(path, registry: TestCatalog.Registry()); + var ids = cache.GetAll().Single(k => k.Name == "Asteroid").Yields.Select(y => y.Id).ToArray(); + Assert.Equal(new[] { "a57e0c000001", "a57e0c000002", "a57e0c000003" }, ids); + } +} diff --git a/tools/AetherDb/Economy/DemoOre.cs b/tools/AetherDb/Economy/DemoOre.cs new file mode 100644 index 000000000..df2a2aff2 --- /dev/null +++ b/tools/AetherDb/Economy/DemoOre.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using GameCult.Caching; + +// Interim ore sheet (ruling mining-demo-ore-minimal-yields-now): the Asteroid field kind yields Rock, New Metals and Gold, and those +// three can be held (a 1x1 shape, a mass) and are sold (a price). The economy ores batch may rewrite the yields by element id. +// Prices are ruling mining-demo-ore-prices-gear-scale, gear-scale so the mine, sell, repair loop closes: a retune is an edit here and a rerun. +// Munitions and MunitionsFeed never rewrite these three commodities, so rerunning them does not clobber this sheet. +public sealed class DemoOre : EconomyBatch +{ + private const int RockPrice = 200; + private const int NewMetalsPrice = 1000; + private const int GoldPrice = 5000; + + // Authored element ids (the cache takes a hand-written id only as 12 lowercase hex): asteroid-rock, asteroid-new-metals, asteroid-gold. + private const string RockId = "a57e0c000001"; + private const string NewMetalsId = "a57e0c000002"; + private const string GoldId = "a57e0c000003"; + + public override void Author(EconomyAuthor author) + { + author.Edit("Rock", o => { o.Shape = new Shape(); o.Price = RockPrice; }); + author.Edit("New Metals", o => { o.Shape = new Shape(); o.Price = NewMetalsPrice; o.Mass = 2; }); + author.Edit("Gold", o => { o.Shape = new Shape(); o.Price = GoldPrice; }); + + var kinds = author.Catalog.GetAll().Where(k => k.Name == "Asteroid").ToArray(); + if (kinds.Length != 1) throw new InvalidOperationException($"{kinds.Length} field kinds are named 'Asteroid'; the ore sheet needs exactly one."); + var asteroid = kinds[0]; + asteroid.Yields = new List + { + Yield(author, "Rock", 6, RockId), + Yield(author, "New Metals", 3, NewMetalsId), + Yield(author, "Gold", 1, GoldId) + }; + author.Put(asteroid, author.Catalog.RefOf(asteroid).Key); + } + + private static FieldYield Yield(EconomyAuthor author, string name, float abundance, string id) + { + var item = author.Catalog.GetAll().Single(i => i.Name == name); + return new FieldYield { Commodity = new CultRecordRef(author.Catalog.RefOf(item).Key), Abundance = abundance, Regional = false, Id = id }; + } +}