Ore sheet: DemoOre batch and tests for the Asteroid ore yields, holdability and prices

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Nibu 2026-11-12 23:01:04 +00:00
commit 3ccb980185
3 changed files with 138 additions and 2 deletions

BIN
GameData/Aetheria.cc (Stored with Git LFS)

Binary file not shown.

View file

@ -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<FieldKindData> Asteroid(CultCache cache) =>
cache.RefOf(cache.GetAll<FieldKindData>().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>("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<EquippableItemData>(design);
return new EquippableItem
{
Data = cache.RefOf<ItemData>(data), Durability = data.Durability,
Lot = items.Lots.Add(new Lot { Design = cache.RefOf<ItemData>(data), Origin = new Attributed(), Quality = .5f, Roles = new List<RoleFill>() })
};
}
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<ItemData>(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<EconomyBatch> { 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<FieldKindData>().Single(k => k.Name == "Asteroid").Yields.Select(y => y.Id).ToArray();
Assert.Equal(new[] { "a57e0c000001", "a57e0c000002", "a57e0c000003" }, ids);
}
}

View file

@ -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<SimpleCommodityData>("Rock", o => { o.Shape = new Shape(); o.Price = RockPrice; });
author.Edit<SimpleCommodityData>("New Metals", o => { o.Shape = new Shape(); o.Price = NewMetalsPrice; o.Mass = 2; });
author.Edit<SimpleCommodityData>("Gold", o => { o.Shape = new Shape(); o.Price = GoldPrice; });
var kinds = author.Catalog.GetAll<FieldKindData>().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<FieldYield>
{
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<SimpleCommodityData>().Single(i => i.Name == name);
return new FieldYield { Commodity = new CultRecordRef<SimpleCommodityData>(author.Catalog.RefOf(item).Key), Abundance = abundance, Regional = false, Id = id };
}
}