StationWants.Stack reads a compound commodity's MaxStack; the demo loop sells the stack its hold holds

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-12-01 17:18:19 +01:00
commit 515e861edf
2 changed files with 8 additions and 4 deletions

View file

@ -166,7 +166,8 @@ public static class StationWants
return holding;
}
private static int Stack(CultCache catalog, CultRecordKey good) => catalog.Get<SimpleCommodityData>(good)?.MaxStack ?? 1;
private static int Stack(CultCache catalog, CultRecordKey good) =>
catalog.Get<ItemData>(good) is CompoundCommodityData compound ? compound.MaxStack : catalog.Get<SimpleCommodityData>(good)?.MaxStack ?? 1;
// The cells the floors take: each good's one-cycle floor in MaxStack units. A hull whose floors exceed its stock room cannot start a cycle
// of every slot at once.

View file

@ -82,9 +82,12 @@ public sealed partial class RunStartTests
var oreGood = zenithWants.OrderBy(good => good.Value, StringComparer.Ordinal).First();
var fresh = new SimpleCommodity { Data = new CultRecordRef<ItemData>(oreGood), Quantity = 5 };
Assert.True(player.CargoBays[0].TryStore(fresh));
var atZenith = StationServices.TrySellPart(player.CargoBays[0], zenith, fresh, ref credits);
Assert.Equal((5, SaleRefusal.None), (atZenith.Sold, atZenith.Refusal));
Assert.Equal(5, silo.Count(oreGood));
// The refinery takes only its shares of the ore, so the hold may still carry this good and the five units merge into its stack: sell the stack the hold holds.
var offered = player.CargoBays[0].Cargo.Keys.OfType<SimpleCommodity>().First(stack => stack.Data.Key.Equals(oreGood));
var atZenith = StationServices.TrySellPart(player.CargoBays[0], zenith, offered, ref credits);
Assert.Equal((atZenith.Offered, SaleRefusal.None), (atZenith.Sold, atZenith.Refusal));
Assert.True(atZenith.Sold >= 5);
Assert.Equal(atZenith.Sold, silo.Count(oreGood));
var cell = Enumerable.Range(0, player.MaxArmor.GetLength(0)).SelectMany(x => Enumerable.Range(0, player.MaxArmor.GetLength(1)).Select(y => (x, y)))
.First(c => player.MaxArmor[c.x, c.y] > 0);