From 069198eb6ba55265814730e5cbd25cf2eed2db14 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 17 Jul 2026 00:56:01 +0100 Subject: [PATCH] Make cargo transfers spatial and atomic --- Aetheria.State.Daemon.Smoke/Program.cs | 188 +++++++++++++++++ .../AetheriaRuntimeDaemonOperations.cs | 73 +++---- .../AetheriaRuntimeRefitTransactions.cs | 191 +++++++++++++++++- docs/aetheria-perfect-machine-map.md | 8 +- docs/original-game-migration-matrix.md | 2 +- 5 files changed, 403 insertions(+), 59 deletions(-) diff --git a/Aetheria.State.Daemon.Smoke/Program.cs b/Aetheria.State.Daemon.Smoke/Program.cs index 2f154b549..144504b02 100644 --- a/Aetheria.State.Daemon.Smoke/Program.cs +++ b/Aetheria.State.Daemon.Smoke/Program.cs @@ -169,6 +169,7 @@ internal sealed class AetheriaDaemonYmirSmokeChecks MissingWorldPhysicsOwnerCannotAdvanceShips, DockingUsesRealBaysAndFossilUndockRules, RefitIsAtomicAndUsesTypedPlacement, + CargoTransferUsesSpatialAtomicTransaction, TractorRampsAndPullsThroughYmirWithoutTeleportingCargo, PickupIsCapacityCheckedExactlyOnceAndExpires, TradePurchaseDerivesAcceptanceFromDaemonState, @@ -678,6 +679,144 @@ internal sealed class AetheriaDaemonYmirSmokeChecks "deployed refit rejection must preserve installed equipment"); } + private static void CargoTransferUsesSpatialAtomicTransaction() + { + var cargoBay = CatalogItem("grid-cargo-bay"); + cargoBay.Category = AetheriaRuntimeItemCategories.CargoBay; + cargoBay.ShapeWidth = 1; + cargoBay.ShapeHeight = 1; + cargoBay.ShapeCells = [new AetheriaRuntimeShapeCell(0, 0)]; + cargoBay.InteriorShapeWidth = 2; + cargoBay.InteriorShapeHeight = 1; + cargoBay.InteriorOccupiedCells = 2; + cargoBay.InteriorShapeCells = [new AetheriaRuntimeShapeCell(0, 0), new AetheriaRuntimeShapeCell(1, 0)]; + var commodity = CatalogItem("grid-commodity"); + commodity.Category = AetheriaRuntimeItemCategories.SimpleCommodity; + commodity.ShapeWidth = 1; + commodity.ShapeHeight = 1; + commodity.ShapeCells = [new AetheriaRuntimeShapeCell(0, 0)]; + commodity.Stackable = true; + commodity.MaxStack = 10; + var blocker = CatalogItem("grid-blocker"); + blocker.ShapeWidth = 1; + blocker.ShapeHeight = 1; + blocker.ShapeCells = [new AetheriaRuntimeShapeCell(0, 0)]; + var catalog = new AetheriaRuntimeCatalogSnapshot([cargoBay, commodity, blocker], [], []); + + AetheriaRuntimeEntitySnapshotCommit CargoEntity(int index, params AetheriaRuntimeLoadoutItemSlotCommit[] items) + { + var entity = Entity(index, 0, "player"); + entity.CargoBays = + [ + new AetheriaRuntimeLoadoutItemSlotCommit + { + Item = new AetheriaRuntimeLoadoutItemCommit { ItemKey = cargoBay.ItemKey, Quantity = 1 } + } + ]; + entity.CargoContents = [new AetheriaRuntimeCargoBayLoadoutCommit { Items = items }]; + return entity; + } + + var source = CargoEntity(0, new AetheriaRuntimeLoadoutItemSlotCommit + { + X = 0, + Y = 0, + Rotation = "None", + Item = new AetheriaRuntimeLoadoutItemCommit + { + ItemKey = commodity.ItemKey, + Quantity = 4, + Quality = 0.75, + Durability = 0.5, + Temperature = 333 + } + }); + var destination = CargoEntity( + 1, + new AetheriaRuntimeLoadoutItemSlotCommit + { + X = 0, + Y = 0, + Item = new AetheriaRuntimeLoadoutItemCommit { ItemKey = blocker.ItemKey, Quantity = 1 } + }, + new AetheriaRuntimeLoadoutItemSlotCommit + { + X = 1, + Y = 0, + Item = new AetheriaRuntimeLoadoutItemCommit { ItemKey = commodity.ItemKey, Quantity = 8 } + }); + var run = new AetheriaRuntimeRunCheckpointCommit + { + RunId = "cargo-grid-smoke", + CurrentZoneIndex = 0, + CurrentEntityKey = "zone.0.entity.0", + Zones = [new AetheriaRuntimeZoneSnapshotCommit { ZoneIndex = 0, Entities = [source, destination] }] + }; + var context = new AetheriaRuntimeDaemonOperationContext { Catalog = catalog }; + + AetheriaRuntimeDaemonCommandDocument Transfer(string id, int quantity, int x, bool positioned = true) + { + var command = AetheriaRuntimeDaemonCommandDocument.Create( + AetheriaRuntimeDaemonCommandKinds.TransferCargoItem, + "pilot", + run.RunId, + 0, + run.CurrentEntityKey); + command.CommandId = id; + command.TextValue = commodity.ItemKey; + command.CargoTransfer = new AetheriaRuntimeCargoTransferCommand + { + OriginEntityKey = "zone.0.entity.0", + OriginCargoIndex = 0, + DestinationEntityKey = "zone.0.entity.1", + DestinationCargoIndex = 0, + SourceX = 0, + SourceY = 0, + DestinationX = x, + DestinationY = 0, + HasDestinationPosition = positioned, + Quantity = quantity + }; + return command; + } + + var overfill = AetheriaRuntimeDaemonOperations.Execute(run, [Transfer("cargo-overfill", 3, 1)], context); + RequireEqual(AetheriaRuntimeDaemonRejectionReasons.CargoStackLimit, + overfill.RejectedCommandReasons["cargo-overfill"], + "an explicit commodity stack overfill must reject atomically"); + RequireEqual(4, source.CargoContents[0].Items.Single().Item.Quantity, + "stack-limit rejection must not decrement the source stack"); + RequireEqual(8, destination.CargoContents[0].Items.Single(slot => slot.Item.ItemKey == commodity.ItemKey).Item.Quantity, + "stack-limit rejection must not partially fill the destination stack"); + + var stacked = AetheriaRuntimeDaemonOperations.Execute(run, [Transfer("cargo-stack", 2, 1)], context); + Require(stacked.AppliedCommandIds.Contains("cargo-stack"), + "a complete explicit stack merge must commit"); + RequireEqual(2, source.CargoContents[0].Items.Single().Item.Quantity, + "accepted stack merge must remove exactly the requested source quantity"); + RequireEqual(10, destination.CargoContents[0].Items.Single(slot => slot.Item.ItemKey == commodity.ItemKey).Item.Quantity, + "accepted stack merge must fill the destination to the typed maximum"); + + var occupied = AetheriaRuntimeDaemonOperations.Execute(run, [Transfer("cargo-overlap", 1, 0)], context); + RequireEqual(AetheriaRuntimeDaemonRejectionReasons.CargoNoFit, + occupied.RejectedCommandReasons["cargo-overlap"], + "an occupied cell containing another item must reject spatial placement"); + RequireEqual(2, source.CargoContents[0].Items.Single().Item.Quantity, + "spatial rejection must leave the source stack untouched"); + + destination.CargoContents[0].Items = []; + var placed = AetheriaRuntimeDaemonOperations.Execute(run, [Transfer("cargo-place", 2, 0, positioned: false)], context); + Require(placed.AppliedCommandIds.Contains("cargo-place") && source.CargoContents[0].Items.Count == 0, + "unpositioned transfer must commit only after finding the first authored interior cell"); + var moved = destination.CargoContents[0].Items.Single(); + Require(moved.X == 0 && moved.Y == 0 && moved.Item.Quantity == 2, + "unpositioned cargo placement must use deterministic interior order"); + RequireNear(0.75, moved.Item.Quality, 0.000001, + "cargo transfer must preserve source instance quality"); + RequireNear(333, moved.Item.Temperature, 0.000001, + "cargo transfer must preserve source instance temperature"); + } + private static void VolumeSurfaceKeepsNativeShaderAbiInAssetVariant() { var player = Entity(0, 0, "player"); @@ -2169,11 +2308,33 @@ internal sealed class AetheriaDaemonYmirSmokeChecks homeHull.HullCapacity = PerformanceStat(100); var iron = CatalogItem("iron"); iron.SimpleCommodityCategory = "ore"; + iron.Category = AetheriaRuntimeItemCategories.SimpleCommodity; + iron.ShapeWidth = 1; + iron.ShapeHeight = 1; + iron.ShapeCells = [new AetheriaRuntimeShapeCell(0, 0)]; + iron.Stackable = true; + iron.MaxStack = 100; iron.Volume = 1; var minerCargo = CatalogItem("miner-cargo"); + minerCargo.Category = AetheriaRuntimeItemCategories.CargoBay; + minerCargo.ShapeWidth = 1; + minerCargo.ShapeHeight = 1; + minerCargo.ShapeCells = [new AetheriaRuntimeShapeCell(0, 0)]; + minerCargo.InteriorShapeWidth = 2; + minerCargo.InteriorShapeHeight = 1; minerCargo.InteriorOccupiedCells = 2; + minerCargo.InteriorShapeCells = [new AetheriaRuntimeShapeCell(0, 0), new AetheriaRuntimeShapeCell(1, 0)]; var homeCargo = CatalogItem("home-cargo"); + homeCargo.Category = AetheriaRuntimeItemCategories.CargoBay; + homeCargo.ShapeWidth = 1; + homeCargo.ShapeHeight = 1; + homeCargo.ShapeCells = [new AetheriaRuntimeShapeCell(0, 0)]; + homeCargo.InteriorShapeWidth = 10; + homeCargo.InteriorShapeHeight = 10; homeCargo.InteriorOccupiedCells = 100; + homeCargo.InteriorShapeCells = Enumerable.Range(0, 10) + .SelectMany(y => Enumerable.Range(0, 10).Select(x => new AetheriaRuntimeShapeCell(x, y))) + .ToArray(); miner.HullItemKey = minerHull.ItemKey; home.HullItemKey = homeHull.ItemKey; miner.CargoContents = [new AetheriaRuntimeCargoBayLoadoutCommit()]; @@ -2765,14 +2926,40 @@ internal sealed class AetheriaDaemonYmirSmokeChecks private static void AgentCompletesHaulTaskThroughMovementAndCargoCommands() { + var cargoBay = CatalogItem("haul-cargo-bay"); + cargoBay.Category = AetheriaRuntimeItemCategories.CargoBay; + cargoBay.ShapeWidth = 1; + cargoBay.ShapeHeight = 1; + cargoBay.ShapeCells = [new AetheriaRuntimeShapeCell(0, 0)]; + cargoBay.InteriorShapeWidth = 4; + cargoBay.InteriorShapeHeight = 4; + cargoBay.InteriorOccupiedCells = 16; + cargoBay.InteriorShapeCells = Enumerable.Range(0, 4) + .SelectMany(y => Enumerable.Range(0, 4).Select(x => new AetheriaRuntimeShapeCell(x, y))) + .ToArray(); + var ore = CatalogItem("ore"); + ore.Category = AetheriaRuntimeItemCategories.SimpleCommodity; + ore.ShapeWidth = 1; + ore.ShapeHeight = 1; + ore.ShapeCells = [new AetheriaRuntimeShapeCell(0, 0)]; + ore.Stackable = true; + ore.MaxStack = 100; + var catalog = new AetheriaRuntimeCatalogSnapshot([cargoBay, ore], [], []); + AetheriaRuntimeLoadoutItemSlotCommit InstalledCargoBay() => new() + { + Item = new AetheriaRuntimeLoadoutItemCommit { ItemKey = cargoBay.ItemKey, Quantity = 1 } + }; var origin = Entity(0, 0, "workers"); origin.Kind = "station"; + origin.CargoBays = [InstalledCargoBay()]; origin.CargoContents = [Cargo(("ore", 5, 2, 3))]; var agent = Entity(1, 0, "workers"); agent.AgentTaskCapabilities = [AetheriaRuntimeAgentTaskTypes.Haul]; + agent.CargoBays = [InstalledCargoBay()]; agent.CargoContents = [Cargo()]; var destination = Entity(2, 50, "workers"); destination.Kind = "station"; + destination.CargoBays = [InstalledCargoBay()]; destination.CargoContents = [Cargo()]; var run = new AetheriaRuntimeRunCheckpointCommit { @@ -2815,6 +3002,7 @@ internal sealed class AetheriaDaemonYmirSmokeChecks FixedDeltaSeconds = 0.1, SimulationTimeSeconds = frame * 0.1, ObservedCommands = frame == 0 ? [issue] : Array.Empty(), + Catalog = catalog, BuildPublications = false }); sawPickup |= tick.OperationResult.AppliedCommandIds.Any(id => id.EndsWith(":pickup", StringComparison.Ordinal)); diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperations.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperations.cs index 69c34a2e6..5ccdae231 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperations.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperations.cs @@ -79,6 +79,9 @@ namespace GameCult.Aetheria.State.Verse public const string RefitBayNotEmpty = "refit-bay-not-empty"; public const string RefitNoFit = "refit-no-fit"; public const string InvalidCargoDestination = "invalid-cargo-destination"; + public const string InvalidCargoSource = "invalid-cargo-source"; + public const string CargoNoFit = "cargo-no-fit"; + public const string CargoStackLimit = "cargo-stack-limit"; } public static class AetheriaRuntimeDaemonOperations @@ -188,7 +191,7 @@ namespace GameCult.Aetheria.State.Verse case AetheriaRuntimeDaemonCommandKinds.SetDockedCurrentShip: return ApplySetDockedCurrentShip(run, command.TargetEntityKey); case AetheriaRuntimeDaemonCommandKinds.TransferCargoItem: - return ApplyTransferCargoItem(run, command, context.Catalog); + return ApplyTransferCargoItem(run, command, context); case AetheriaRuntimeDaemonCommandKinds.EquipItem: return ApplyEquipItem(run, command, context); case AetheriaRuntimeDaemonCommandKinds.StoreItem: @@ -799,61 +802,31 @@ namespace GameCult.Aetheria.State.Verse private static bool ApplyTransferCargoItem( AetheriaRuntimeRunCheckpointCommit run, AetheriaRuntimeDaemonCommandDocument command, - AetheriaRuntimeCatalogSnapshot? catalog) + AetheriaRuntimeDaemonOperationContext context) { var transfer = command.CargoTransfer ?? new AetheriaRuntimeCargoTransferCommand(); - if (!TryResolveCargoBay( - run, - transfer.OriginEntityKey, - transfer.OriginCargoIndex, - out var originEntity, - out var originCargoIndex, - out _) || - !TryResolveCargoBay( - run, - transfer.DestinationEntityKey, - transfer.DestinationCargoIndex, - out var destinationEntity, - out var destinationCargoIndex, - out _)) - { - return false; - } - - if (!transfer.HasDestinationPosition && - string.Equals(transfer.OriginEntityKey ?? "", transfer.DestinationEntityKey ?? "", StringComparison.Ordinal) && - transfer.OriginCargoIndex == transfer.DestinationCargoIndex) - { - return false; - } - - var sourceX = transfer.SourceX; - var sourceY = transfer.SourceY; var quantity = transfer.Quantity > 0 ? transfer.Quantity : (int)Math.Round(command.ScalarValue); - if (quantity <= 0 || quantity > AetheriaRuntimeCargoCapacityQueries.UnitsThatFit(destinationEntity, catalog, command.TextValue, destinationCargoIndex)) - return false; - if (!TryRemoveCargoItemQuantity( - originEntity, - originCargoIndex, - command.TextValue, - sourceX, - sourceY, - quantity, - out var slot)) - { - return false; - } + if (!TryResolveEntity(run, transfer.OriginEntityKey, out _, out _, out var origin) || + !TryResolveEntity(run, transfer.DestinationEntityKey, out _, out _, out var destination)) + return context.Reject(AetheriaRuntimeDaemonRejectionReasons.InvalidCargoSource); - slot.X = transfer.HasDestinationPosition - ? transfer.DestinationX - : slot.X; - slot.Y = transfer.HasDestinationPosition - ? transfer.DestinationY - : slot.Y; - AddCargoItem(destinationEntity, destinationCargoIndex, slot); - return true; + return AetheriaRuntimeRefitTransactions.TryTransferCargo( + origin, + transfer.OriginCargoIndex, + transfer.SourceX, + transfer.SourceY, + destination, + transfer.DestinationCargoIndex, + command.TextValue ?? "", + quantity, + transfer.DestinationX, + transfer.DestinationY, + transfer.HasDestinationPosition, + context.Catalog, + out var reason) + || context.Reject(reason); } private static bool ApplyEquipItem( diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeRefitTransactions.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeRefitTransactions.cs index b13387b5a..70543b882 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeRefitTransactions.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeRefitTransactions.cs @@ -58,6 +58,133 @@ namespace GameCult.Aetheria.State.Verse public static class AetheriaRuntimeRefitTransactions { + public static bool TryTransferCargo( + AetheriaRuntimeEntitySnapshotCommit origin, + int originCargoIndex, + int sourceX, + int sourceY, + AetheriaRuntimeEntitySnapshotCommit destination, + int destinationCargoIndex, + string itemKey, + int quantity, + int destinationX, + int destinationY, + bool hasDestinationPosition, + AetheriaRuntimeCatalogSnapshot? catalog, + out string rejectionReason) + { + rejectionReason = ""; + if (origin == null || destination == null || catalog == null || quantity <= 0) + return Reject(AetheriaRuntimeDaemonRejectionReasons.InvalidCargoSource, out rejectionReason); + + var originPlan = new EntityPlan(origin); + var destinationPlan = ReferenceEquals(origin, destination) + ? originPlan + : new EntityPlan(destination); + if (ReferenceEquals(originPlan, destinationPlan) && + originCargoIndex == destinationCargoIndex && + !hasDestinationPosition) + { + return Reject(AetheriaRuntimeDaemonRejectionReasons.InvalidCargoDestination, out rejectionReason); + } + if (originCargoIndex < 0 || originCargoIndex >= originPlan.CargoContents.Count) + return Reject(AetheriaRuntimeDaemonRejectionReasons.InvalidCargoSource, out rejectionReason); + if (destinationCargoIndex < 0 || + destinationCargoIndex >= destinationPlan.CargoBays.Count || + destinationCargoIndex >= destinationPlan.CargoContents.Count) + { + return Reject(AetheriaRuntimeDaemonRejectionReasons.InvalidCargoDestination, out rejectionReason); + } + + var sourceItems = originPlan.CargoContents[originCargoIndex]; + var sourceIndex = sourceItems.FindIndex(slot => + slot?.Item != null && + string.Equals(slot.Item.ItemKey ?? "", itemKey ?? "", StringComparison.Ordinal) && + slot.X == sourceX && slot.Y == sourceY); + if (sourceIndex < 0 || sourceItems[sourceIndex].Item == null || + quantity > Math.Max(0, sourceItems[sourceIndex].Item.Quantity)) + { + return Reject(AetheriaRuntimeDaemonRejectionReasons.InvalidCargoSource, out rejectionReason); + } + + if (ReferenceEquals(originPlan, destinationPlan) && + originCargoIndex == destinationCargoIndex && + hasDestinationPosition && + sourceX == destinationX && sourceY == destinationY) + { + return true; + } + + var sourceSlot = sourceItems[sourceIndex]; + var moved = CloneSlot(sourceSlot); + moved.Item.Quantity = quantity; + if (quantity == sourceSlot.Item.Quantity) + sourceItems.RemoveAt(sourceIndex); + else + sourceSlot.Item.Quantity -= quantity; + + var item = catalog.FindItem(itemKey ?? ""); + var bay = catalog.FindItem(destinationPlan.CargoBays[destinationCargoIndex].Item?.ItemKey ?? ""); + if (item == null || bay == null || Cells(item.ShapeCells).Count == 0) + return Reject(AetheriaRuntimeDaemonRejectionReasons.InvalidCargoDestination, out rejectionReason); + + var destinationItems = destinationPlan.CargoContents[destinationCargoIndex]; + if (hasDestinationPosition) + { + var stack = destinationItems.FirstOrDefault(slot => + SlotOccupies(slot, destinationX, destinationY, catalog) && + string.Equals(slot.Item?.ItemKey ?? "", itemKey ?? "", StringComparison.Ordinal)); + if (stack != null) + { + var maxStack = Math.Max(1, item.MaxStack); + if (!item.Stackable || stack.Item.Quantity + quantity > maxStack) + return Reject(AetheriaRuntimeDaemonRejectionReasons.CargoStackLimit, out rejectionReason); + stack.Item.Quantity += quantity; + } + else if (!TryPlaceCargoSlot( + destinationItems, + bay, + item, + moved, + destinationX, + destinationY, + true, + catalog)) + { + return Reject(AetheriaRuntimeDaemonRejectionReasons.CargoNoFit, out rejectionReason); + } + } + else + { + var remaining = quantity; + if (item.Stackable) + { + var maxStack = Math.Max(1, item.MaxStack); + foreach (var stack in destinationItems.Where(slot => + slot?.Item != null && + string.Equals(slot.Item.ItemKey ?? "", itemKey ?? "", StringComparison.Ordinal))) + { + var transferred = Math.Min(remaining, Math.Max(0, maxStack - stack.Item.Quantity)); + stack.Item.Quantity += transferred; + remaining -= transferred; + if (remaining == 0) break; + } + } + + if (remaining > 0) + { + moved.Item.Quantity = remaining; + if (!TryPlaceCargoSlot(destinationItems, bay, item, moved, 0, 0, false, catalog)) + return Reject(AetheriaRuntimeDaemonRejectionReasons.CargoNoFit, out rejectionReason); + } + } + + originPlan.ApplyCargoOnly(); + if (!ReferenceEquals(originPlan, destinationPlan)) + destinationPlan.ApplyCargoOnly(); + return true; + } + public static bool TryEquip( AetheriaRuntimeEntitySnapshotCommit origin, string sourceKind, @@ -277,6 +404,51 @@ namespace GameCult.Aetheria.State.Verse return true; } + private static bool TryPlaceCargoSlot( + List destinationItems, + AetheriaRuntimeCatalogItem bay, + AetheriaRuntimeCatalogItem item, + AetheriaRuntimeLoadoutItemSlotCommit slot, + int requestedX, + int requestedY, + bool hasRequestedPosition, + AetheriaRuntimeCatalogSnapshot catalog) + { + var occupied = OccupiedCargoCells(destinationItems, catalog); + var rotation = ParseRotation(slot.Rotation); + if (!TryFindPlacement( + Cells(bay.InteriorShapeCells), + Math.Max(0, bay.InteriorShapeWidth), + Math.Max(0, bay.InteriorShapeHeight), + item, + rotation, + occupied, + requestedX, + requestedY, + hasRequestedPosition, + out var x, + out var y)) + { + return false; + } + slot.X = x; + slot.Y = y; + destinationItems.Add(slot); + return true; + } + + private static bool SlotOccupies( + AetheriaRuntimeLoadoutItemSlotCommit? slot, + int x, + int y, + AetheriaRuntimeCatalogSnapshot catalog) + { + var item = catalog.FindItem(slot?.Item?.ItemKey ?? ""); + return slot != null && item != null && + RotatedCells(item, ParseRotation(slot.Rotation)) + .Any(cell => slot.X + cell.X == x && slot.Y + cell.Y == y); + } + private static bool TryFindPlacement( HashSet<(int X, int Y)> target, int width, @@ -405,9 +577,12 @@ namespace GameCult.Aetheria.State.Verse public EntityPlan(AetheriaRuntimeEntitySnapshotCommit entity) { _entity = entity; - Equipment = (entity.Equipment ?? Array.Empty()).ToList(); - CargoBays = (entity.CargoBays ?? Array.Empty()).ToList(); - DockingBays = (entity.DockingBays ?? Array.Empty()).ToList(); + Equipment = (entity.Equipment ?? Array.Empty()) + .Select(CloneSlot).ToList(); + CargoBays = (entity.CargoBays ?? Array.Empty()) + .Select(CloneSlot).ToList(); + DockingBays = (entity.DockingBays ?? Array.Empty()) + .Select(CloneSlot).ToList(); CargoContents = CloneContents(entity.CargoContents, CargoBays.Count); DockingContents = CloneContents(entity.DockingBayContents, DockingBays.Count); DockingAssignments = (entity.DockingBayAssignments ?? Array.Empty()).ToList(); @@ -547,12 +722,20 @@ namespace GameCult.Aetheria.State.Verse .ToArray(); } + public void ApplyCargoOnly() + { + _entity.CargoContents = CargoContents + .Select(items => new AetheriaRuntimeCargoBayLoadoutCommit { Items = items.ToArray() }) + .ToArray(); + } + private static List> CloneContents( IReadOnlyList? contents, int count) { var result = (contents ?? Array.Empty()) - .Select(bay => (bay?.Items ?? Array.Empty()).ToList()) + .Select(bay => (bay?.Items ?? Array.Empty()) + .Select(CloneSlot).ToList()) .ToList(); while (result.Count < count) result.Add(new List()); return result; diff --git a/docs/aetheria-perfect-machine-map.md b/docs/aetheria-perfect-machine-map.md index 133bbe42d..efd9266b9 100644 --- a/docs/aetheria-perfect-machine-map.md +++ b/docs/aetheria-perfect-machine-map.md @@ -2907,12 +2907,12 @@ Docked refit ownership follows the fossil's `Entity.ItemFits`, `TryEquip`, and - Forbidden writers: Unity occupancy checks, renderer inventory graphs, client-supplied acceptance/rejection reasons, and remove-first mutation paths cannot decide or repair a refit. -- Shared paths: cargo-to-equipment equip, equipment reposition, equipment-to- - cargo store, reconnect, and loadout restore use the same typed collection and - placement semantics where their contracts overlap. +- Shared paths: cargo-to-cargo transfer, cargo-to-equipment equip, equipment + reposition, equipment-to-cargo store, reconnect, and loadout restore use the + same typed collection and placement semantics where their contracts overlap. - Cut line: generated cargo and docking bays no longer masquerade as ordinary equipment; unconditional destination appends and source removal before - destination validation are removed from refit operations. + destination validation are removed from refit and cargo-transfer operations. - Verification layer: daemon smokes compare source and destination state before and after rejection, cover hardpoint type/shape/rotation, interior occupancy, deployed-state rejection, nonempty bay rejection, category routing, exact diff --git a/docs/original-game-migration-matrix.md b/docs/original-game-migration-matrix.md index 180a7e9b9..35ac70a54 100644 --- a/docs/original-game-migration-matrix.md +++ b/docs/original-game-migration-matrix.md @@ -29,7 +29,7 @@ validation proves contract shape, not wiring, exclusivity, lowering, or parity. | Tractor/scoop | analog tractor and physical timed pickups | daemon + Ymir | tractor power, pickup body and receipt | pickup world entity plus beam/interaction feedback | fossil 2/s power ramp and authored forward radius/traction/distance feed pickup bodies into the shared Ymir world; ship contact collects exactly once when capacity permits or applies the fossil 25-unit rejection kick; Aetheria maps pickup collision only against ship bodies, so stations and other world bodies cannot become cargo writers; 30s daemon lifetime; instant cargo teleport deleted; current-zone pickups occupy ordinary rows in the shared Eve entity SoA body with stable logical identity and provider-owned assets; `pilot.scoop` advertises a generic `button-hold.v1` scalar contract, the released client sends `1` on press and `0` on release through `SetTractorPower`, both receipts reconcile, and daemon power returns exactly to zero; the provider build removes the fossil's embedded tractor object from ship prefabs, and `beam.presentation` attaches the sole standalone effect to the SoA ship; released warm witnesses prove successful exactly-once Ymir collection and controlled-player `cargo-capacity` rejection with unchanged cargo | polish provider beam shape/attachment | | Dock/undock | wormhole-first interact; first eligible bay; component prerequisites | daemon + Ymir placement | dock commands/context | camera/UI transition | daemon docking now preserves the fossil transaction: stable zone order selects the first entity with a real empty bay inside the fixed 25-unit XZ center radius; undock checks installed Cockpit, Thruster-or-AetherDrive, Reactor, then empty bay cargo in source order; rejection reasons survive committed command facts into generic Eve receipts; success removes parentage without moving, stopping, or rotating the ship. Ymir world entities retain gravity/query bodies but do not invent ship/station rigidbody collision response that would make the 25-unit rule unreachable; ship/pickup Begin contacts remain enabled. The live generic Unity witness also proves advertised actions, bay assignment, dock-parent SoA inclusion and sensor sharing, camera retargeting, controlled-subject hiding, movement suppression, and restoration on undock | reconnect, docked inventory/trade surfaces, and authored dock-camera blend/effect chronology | | Wormhole travel | `ActionGameManager.EnterWormhole` plus `Ship` enter/exit state | daemon fixed-step transition plus Ymir exclusion | current-entity transition state and feedback chronology | provider-selected generic transition lowering | command acceptance no longer moves an entity immediately; player interact, explicit travel, and agent routing derive the same canonical adjacent-zone wormhole and proximity gate, then persist four-second `entering`, authoritative transfer, four-second `exiting`, and one-frame `completed` phases. The daemon owns smootherstep XZ motion, the fossil 1000-unit visual-depth lever, deterministic 20-unit exit direction, 50-unit exit radius, target-adjacency discovery, and exactly-once start/transfer/completion events. Flight and every world-physics implementation receive no transitioning body; Ymir resumes on the tick after completion. Smoke serializes and rehydrates mid-entry and proves agents traverse multi-edge routes through the same command boundary | generic provider transition effect/camera lowering and live multi-zone pilot witness | -| Inventory/equipment | `Entity.ItemFits`, `TryEquip`, `TryUnequip`, inventory panels + ServerShared | daemon atomic refit transaction | typed inventory/equipment state, commands, exact receipts | generic UI | generated cargo and docking bays now occupy their typed collections instead of masquerading as ordinary equipment; docked equip/reposition/store validates the complete destination on cloned state before committing either side, uses authored hull interior and hardpoint geometry, forces hardpoint rotation, rejects occupied cells and deployed ships, preserves exact item instance fields and weapon-group membership, routes bay categories with aligned content/assignment arrays, and refuses to unequip nonempty/occupied bays; exact reasons reach generic Eve receipts | cargo-to-cargo spatial placement, live generic refit controls, reconnect after accepted and rejected moves, and full fossil inventory chronology | +| Inventory/equipment | `Entity.ItemFits`, `TryEquip`, `TryUnequip`, `EquippedCargoBay.ItemFits`/`TryStore`, inventory panels + ServerShared | daemon atomic inventory transactions | typed inventory/equipment state, commands, exact receipts | generic UI | generated cargo and docking bays now occupy their typed collections instead of masquerading as ordinary equipment; docked equip/reposition/store validates the complete destination on cloned state before committing either side, uses authored hull interior and hardpoint geometry, forces hardpoint rotation, rejects occupied cells and deployed ships, preserves exact item instance fields and weapon-group membership, routes bay categories with aligned content/assignment arrays, and refuses to unequip nonempty/occupied bays. Cargo transfer now uses the same plan-first rule with typed bay interiors, rotated item footprints, deterministic free-cell search, exact stack maxima, and no partial source/destination mutation on rejection; exact reasons reach generic Eve receipts | live generic refit controls, reconnect after accepted and rejected moves, commodity multi-stack chronology, and full fossil inventory feedback parity | | Trade | trade UI/economy | daemon | stock, quote, purchase commands | generic UI | daemon derives station, stock row, catalog item, current price, quantity, credits, target capacity, and hull-vs-cargo result; Eve advertises only currently available stock actions; generic Unity live witness receives an authoritative purchase receipt while paused | sell flow, quote expiry, contested stock, and full trade surface parity | | Action bar/input | input shell and rebinding UI | daemon advertises actions; client owns bindings | input capability and action descriptors | universal binding UI | contracts wired; cargo actions are catalog-filtered to consumables the current actor can actually activate, including suppression of active non-stackable items | dynamic equipment behavior validity and runtime action-bar quantity/fill proof | | Pilot camera | ARPG follow/dock cameras | Eve view semantics + runtime | camera rig and semantic view id | EveUnity camera rig | daemon dock state selects distinct contracts instead of collapsing both fossil cameras: undocked flight advertises the entity-forward `Third Person Rig` framing (distance 30, screen 0.64/0.19, FOV 60, lens 1-4096) and the shared `aim.presentation` convergence point as its look-at; Aetheria translates the fossil Cinemachine top-origin screen Y of `0.81` to Eve's bottom-origin viewport Y of `0.19`; EveUnity solves native pose while preserving both optical aim and advertised entity framing, without provider types; the retained dock projection remains separate | reproduce the dock camera's separate follow/look-at subjects, blend timeline, noise, and reconnect state |