From 4fc2808989a392c9ce3335e54e00b1a18a97a9c6 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 11 Jul 2026 18:44:19 +0100 Subject: [PATCH] Restore authored hull cargo capacity --- Aetheria.State.Daemon.Smoke/Program.cs | 23 +++++++++ .../AetheriaRuntimeCargoCapacityQueries.cs | 47 +++++++++++++++++++ .../Runtime/AetheriaRuntimeCatalogSnapshot.cs | 8 +++- .../Runtime/AetheriaRuntimeCatalogStore.cs | 5 +- 4 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCargoCapacityQueries.cs diff --git a/Aetheria.State.Daemon.Smoke/Program.cs b/Aetheria.State.Daemon.Smoke/Program.cs index 5352416fb..9406c13bd 100644 --- a/Aetheria.State.Daemon.Smoke/Program.cs +++ b/Aetheria.State.Daemon.Smoke/Program.cs @@ -22,6 +22,29 @@ internal sealed class AetheriaDaemonYmirSmokeChecks AgentPatrolsHistoricalOrbitCircuitThroughMovementCommands(); TickReconcilesAndEvaluatesCatalogBehaviors(); AgentMinesAsteroidThroughEquippedBehavior(); + CargoCapacityComesFromHullAndCatalogVolumes(); + } + + private static void CargoCapacityComesFromHullAndCatalogVolumes() + { + var hull = CatalogItem("hauler-hull"); + hull.HullCapacity = PerformanceStat(20); + var gear = CatalogItem("scanner"); + gear.Volume = 3; + var ore = CatalogItem("ore"); + ore.Volume = 2; + var catalog = new AetheriaRuntimeCatalogSnapshot([hull, gear, ore], [], []); + var entity = Entity(0, 0, "workers"); + entity.HullItemKey = hull.ItemKey; + entity.Equipment = [new AetheriaRuntimeLoadoutItemSlotCommit { Item = new AetheriaRuntimeLoadoutItemCommit { ItemKey = gear.ItemKey } }]; + entity.CargoContents = [new AetheriaRuntimeCargoBayLoadoutCommit { Items = [new AetheriaRuntimeLoadoutItemSlotCommit { Item = new AetheriaRuntimeLoadoutItemCommit { ItemKey = ore.ItemKey, Quantity = 4 } }] }]; + + RequireNear(20, AetheriaRuntimeCargoCapacityQueries.Capacity(entity, catalog), 0.000001, + "cargo capacity must evaluate the authored hull performance stat"); + RequireNear(11, AetheriaRuntimeCargoCapacityQueries.Occupied(entity, catalog), 0.000001, + "equipment and stacked cargo must consume catalog volume"); + RequireEqual(4, AetheriaRuntimeCargoCapacityQueries.UnitsThatFit(entity, catalog, ore.ItemKey), + "available cargo volume must determine whole units that fit"); } private static void AgentMinesAsteroidThroughEquippedBehavior() diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCargoCapacityQueries.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCargoCapacityQueries.cs new file mode 100644 index 000000000..779ee1470 --- /dev/null +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCargoCapacityQueries.cs @@ -0,0 +1,47 @@ +using System; +using System.Linq; + +#nullable enable + +namespace GameCult.Aetheria.State.Verse +{ + public static class AetheriaRuntimeCargoCapacityQueries + { + public static double Capacity(AetheriaRuntimeEntitySnapshotCommit? entity, AetheriaRuntimeCatalogSnapshot? catalog) + { + if (entity == null || catalog == null) + return 0; + var hull = catalog.FindItem(entity.HullItemKey ?? ""); + if (hull == null) + return 0; + return Math.Max(0, AetheriaRuntimeDaemonItemStatQueries.EvaluatePerformanceStat( + hull.HullCapacity, + new AetheriaRuntimeLoadoutItemCommit { ItemKey = hull.ItemKey, Quality = 1, Durability = 1, Enabled = true }, + 1)); + } + + public static double Occupied(AetheriaRuntimeEntitySnapshotCommit? entity, AetheriaRuntimeCatalogSnapshot? catalog) + { + if (entity == null || catalog == null) + return 0; + var equipment = (entity.Equipment ?? Array.Empty()) + .Sum(slot => Volume(slot?.Item, catalog)); + var cargo = (entity.CargoContents ?? Array.Empty()) + .SelectMany(bay => bay?.Items ?? Array.Empty()) + .Sum(slot => Volume(slot?.Item, catalog)); + return equipment + cargo; + } + + public static double Available(AetheriaRuntimeEntitySnapshotCommit? entity, AetheriaRuntimeCatalogSnapshot? catalog) => + Math.Max(0, Capacity(entity, catalog) - Occupied(entity, catalog)); + + public static int UnitsThatFit(AetheriaRuntimeEntitySnapshotCommit? entity, AetheriaRuntimeCatalogSnapshot? catalog, string itemKey) + { + var volume = catalog?.FindItem(itemKey ?? "")?.Volume ?? 0; + return volume <= 0 ? int.MaxValue : Math.Max(0, (int)Math.Floor(Available(entity, catalog) / volume)); + } + + private static double Volume(AetheriaRuntimeLoadoutItemCommit? item, AetheriaRuntimeCatalogSnapshot catalog) => + item == null ? 0 : Math.Max(0, catalog.FindItem(item.ItemKey ?? "")?.Volume ?? 0) * Math.Max(1, item.Quantity); + } +} diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCatalogSnapshot.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCatalogSnapshot.cs index 1e48ff63c..a12936c4f 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCatalogSnapshot.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCatalogSnapshot.cs @@ -185,7 +185,8 @@ namespace GameCult.Aetheria.State.Verse IReadOnlyList audioStats, IReadOnlyList effectivenessCurveKeys, string simpleCommodityCategory, - string compoundCommodityCategory) + string compoundCommodityCategory, + AetheriaRuntimeBehaviorValue? hullCapacity = null) { ItemKey = itemKey; Name = name; @@ -235,6 +236,10 @@ namespace GameCult.Aetheria.State.Verse EffectivenessCurveKeys = effectivenessCurveKeys; SimpleCommodityCategory = simpleCommodityCategory; CompoundCommodityCategory = compoundCommodityCategory; + HullCapacity = hullCapacity ?? new AetheriaRuntimeBehaviorValue( + "", "", 0, false, "", "", + Array.Empty(), + Array.Empty()); } public string ItemKey { get; set; } @@ -247,6 +252,7 @@ namespace GameCult.Aetheria.State.Verse public double SpecificHeat { get; set; } public double Conductivity { get; set; } public double Volume { get; set; } + public AetheriaRuntimeBehaviorValue HullCapacity { get; set; } public int ShapeWidth { get; set; } public int ShapeHeight { get; set; } public int OccupiedCells { get; set; } diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCatalogStore.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCatalogStore.cs index f148d5747..3e9ba5b58 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCatalogStore.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCatalogStore.cs @@ -707,7 +707,7 @@ namespace GameCult.Aetheria.State.Verse var hardpointType = ReadFieldString(ref reader, fields, 12); var hullType = ReadFieldString(ref reader, fields, 13); var behaviorKinds = ReadFieldStringArray(ref reader, fields, 14); - SkipField(ref reader, fields, 15); + var hullCapacity = ReadFieldBehaviorValue(ref reader, fields, 15); var maxStack = ReadFieldInt32(ref reader, fields, 16); var stackable = ReadFieldBool(ref reader, fields, 17); var duration = ReadFieldDouble(ref reader, fields, 18); @@ -792,7 +792,8 @@ namespace GameCult.Aetheria.State.Verse audioStats, effectivenessCurveKeys, simpleCommodityCategory, - compoundCommodityCategory); + compoundCommodityCategory, + hullCapacity); } private static AetheriaRuntimeCorporation ReadCorporation(byte[] payload)