diff --git a/Aetheria.State.Daemon.Smoke/Program.cs b/Aetheria.State.Daemon.Smoke/Program.cs index 8f0c74ab4..83601edf0 100644 --- a/Aetheria.State.Daemon.Smoke/Program.cs +++ b/Aetheria.State.Daemon.Smoke/Program.cs @@ -274,12 +274,28 @@ internal sealed class AetheriaDaemonYmirSmokeChecks unavailableHull.HardpointType = "Hull"; unavailableHull.HullType = "Ship"; unavailableHull.ShapeWidth = 4; unavailableHull.ShapeHeight = 4; unavailableHull.OccupiedCells = 16; unavailableHull.ShapeCells = cells4; + var stationHull = Item("station-hull", AetheriaRuntimeItemCategories.Hull, "forge", 120); + stationHull.HardpointType = "Hull"; stationHull.HullType = "Station"; + stationHull.ShapeWidth = 4; stationHull.ShapeHeight = 4; stationHull.OccupiedCells = 16; + stationHull.ShapeCells = cells4; + stationHull.Hardpoints = + [ + new AetheriaRuntimeHardpoint("ControlModule", 0, 0, 1, 1, 1, one, "", "None", 0) + ]; var cockpit = Item("cockpit", AetheriaRuntimeItemCategories.Gear, "forge", 20, "ControlModule", "Cockpit"); var wrongController = Item("cheap-turret-controller", AetheriaRuntimeItemCategories.Gear, "forge", 1, "ControlModule", "TurretController"); var weapon = Item("cannon", AetheriaRuntimeItemCategories.Weapon, "forge", 40, "Weapon", "LockWeapon"); var cargo = Item("cargo-bay", AetheriaRuntimeItemCategories.CargoBay, "forge", 30); cargo.HardpointType = "Internal"; + cargo.InteriorShapeWidth = 2; cargo.InteriorShapeHeight = 2; cargo.InteriorOccupiedCells = 4; + cargo.InteriorShapeCells = + [ + new AetheriaRuntimeShapeCell(0, 0), new AetheriaRuntimeShapeCell(1, 0), + new AetheriaRuntimeShapeCell(0, 1), new AetheriaRuntimeShapeCell(1, 1) + ]; + var docking = Item("docking-bay", AetheriaRuntimeItemCategories.DockingBay, "forge", 35); + docking.HardpointType = "Internal"; var capacitor = Item("capacitor", AetheriaRuntimeItemCategories.Gear, "forge", 25, "", "Capacitor"); capacitor.HardpointType = "Internal"; var faction = new AetheriaRuntimeCorporation("forge", "Forge", "F", "", "", "", 1, 1, @@ -287,13 +303,14 @@ internal sealed class AetheriaDaemonYmirSmokeChecks var foreign = new AetheriaRuntimeCorporation("foreign", "Foreign", "X", "", "", "", 1, 1, [new AetheriaRuntimeCorporationAllegiance("foreign", 1)]); var catalog = new AetheriaRuntimeCatalogSnapshot( - [availableHull, unavailableHull, cockpit, wrongController, weapon, cargo, capacitor], + [availableHull, unavailableHull, stationHull, cockpit, wrongController, weapon, cargo, docking, capacitor], [faction, foreign], Array.Empty()); var homes = new Dictionary { ["forge"] = 0, ["foreign"] = 1 }; var adjacency = new Dictionary> { [0] = [1], [1] = [0] }; var first = new AetheriaDaemonLoadoutGenerator(catalog, 42, 0, homes, adjacency).Build("ship", "forge", []); var second = new AetheriaDaemonLoadoutGenerator(catalog, 42, 0, homes, adjacency).Build("ship", "forge", []); + var station = new AetheriaDaemonLoadoutGenerator(catalog, 84, 0, homes, adjacency).Build("station", "forge", []); RequireEqual("available-hull", first.HullItemKey, "loadout generation must exclude manufacturers outside the faction allegiance graph"); @@ -307,6 +324,13 @@ internal sealed class AetheriaDaemonYmirSmokeChecks Require(first.HullItemKey == second.HullItemKey && first.Equipment.Select(value => value.ItemKey).SequenceEqual(second.Equipment.Select(value => value.ItemKey)), "same seed, map, faction and catalog must produce the same loadout"); + Require(station.Equipment.Any(value => value.ItemKey == "docking-bay") && + station.Equipment.Any(value => value.ItemKey == "cargo-bay") && + station.Equipment.Any(value => value.ItemKey == "capacitor") && + station.Equipment.Any(value => value.ItemKey == "cheap-turret-controller"), + "stations must fit docking, cargo, capacitor, and turret-controller roles before inventory generation"); + Require(station.Cargo.Length == 4 && station.Cargo.All(value => value.Item.ItemKey != "cheap-foreign-hull"), + "station inventory draws must be packed to cargo capacity and exclude unavailable manufacturers"); } private static AetheriaRuntimeBehaviorValue PerformanceStat(double value) => new( diff --git a/Aetheria.State.Daemon/AetheriaDaemonLoadoutGenerator.cs b/Aetheria.State.Daemon/AetheriaDaemonLoadoutGenerator.cs index 58cab6af7..6f4706512 100644 --- a/Aetheria.State.Daemon/AetheriaDaemonLoadoutGenerator.cs +++ b/Aetheria.State.Daemon/AetheriaDaemonLoadoutGenerator.cs @@ -70,19 +70,17 @@ public sealed class AetheriaDaemonLoadoutGenerator previous.Add(item); } - AddFreeSpaceItem(hull, availabilityFactionKey, occupied, slots, 3, item => + var cargoBay = AddFreeSpaceItem(hull, availabilityFactionKey, occupied, slots, 3, item => string.Equals(item.Category, AetheriaRuntimeItemCategories.CargoBay, StringComparison.Ordinal)); AddFreeSpaceItem(hull, availabilityFactionKey, occupied, slots, 2, item => IsGear(item) && HasBehavior(item, "Capacitor")); - var cargo = (scenarioCargo ?? Array.Empty()) - .Where(key => !string.IsNullOrWhiteSpace(key) && _catalog.FindItem(key) != null) - .Select((key, index) => CargoSlot(index, key)) - .ToArray(); + var cargo = PackCargo(cargoBay, availabilityFactionKey, scenarioCargo, + string.Equals(entityKind, "station", StringComparison.OrdinalIgnoreCase)); return new AetheriaDaemonLoadout(hull.ItemKey, slots.ToArray(), cargo); } - private void AddFreeSpaceItem( + private AetheriaRuntimeCatalogItem AddFreeSpaceItem( AetheriaRuntimeCatalogItem hull, string factionKey, HashSet<(int X, int Y)> occupied, @@ -102,6 +100,51 @@ public sealed class AetheriaDaemonLoadoutGenerator var fit = selected.Fit.Value; slots.Add(Slot(fit.X, fit.Y, selected.Item.ItemKey)); Reserve(occupied, selected.Item, fit.X, fit.Y, fit.Rotation); + return selected.Item; + } + + private AetheriaLoadoutItemSlot[] PackCargo( + AetheriaRuntimeCatalogItem cargoBay, + string factionKey, + IReadOnlyList scenarioCargo, + bool includeStationInventory) + { + var candidates = new List(); + foreach (var key in scenarioCargo ?? Array.Empty()) + { + var item = _catalog.FindItem(key); + if (item != null) candidates.Add(item); + } + if (includeStationInventory) + { + var pool = Available(factionKey) + .Where(item => !string.Equals(item.Category, AetheriaRuntimeItemCategories.CargoBay, StringComparison.Ordinal) && + !string.Equals(item.Category, AetheriaRuntimeItemCategories.DockingBay, StringComparison.Ordinal) && + (!string.Equals(item.Category, AetheriaRuntimeItemCategories.Hull, StringComparison.Ordinal) || + string.Equals(item.HullType, "Ship", StringComparison.Ordinal))) + .ToList(); + for (var draw = 0; draw < 16 && pool.Count > 0; draw++) + { + var selected = PickWeighted(pool, 1, factionKey, item => item); + if (selected == null) break; + candidates.Add(selected); + pool.Remove(selected); + } + } + + var interiorCells = Cells(cargoBay.InteriorShapeCells); + var width = Math.Max(1, cargoBay.InteriorShapeWidth); + var height = Math.Max(1, cargoBay.InteriorShapeHeight); + var occupied = new HashSet<(int X, int Y)>(); + var packed = new List(); + foreach (var item in candidates.OrderByDescending(value => value.OccupiedCells)) + { + var fit = FindFit(interiorCells, width, height, item, occupied); + if (!fit.HasValue) continue; + Reserve(occupied, item, fit.Value.X, fit.Value.Y, fit.Value.Rotation); + packed.Add(CargoSlot(fit.Value.X, fit.Value.Y, item.ItemKey)); + } + return packed.ToArray(); } private AetheriaRuntimeCatalogItem? Pick( @@ -191,14 +234,23 @@ public sealed class AetheriaDaemonLoadoutGenerator AetheriaRuntimeCatalogItem item, HashSet<(int X, int Y)> occupied) { - var hullCells = Cells(hull.ShapeCells); + return FindFit(Cells(hull.ShapeCells), Math.Max(1, hull.ShapeWidth), Math.Max(1, hull.ShapeHeight), item, occupied); + } + + private static (int X, int Y, int Rotation)? FindFit( + HashSet<(int X, int Y)> targetCells, + int width, + int height, + AetheriaRuntimeCatalogItem item, + HashSet<(int X, int Y)> occupied) + { for (var rotation = 0; rotation < 4; rotation++) { var cells = RotatedCells(item, rotation).ToArray(); - for (var y = 0; y < Math.Max(1, hull.ShapeHeight); y++) - for (var x = 0; x < Math.Max(1, hull.ShapeWidth); x++) + for (var y = 0; y < height; y++) + for (var x = 0; x < width; x++) { - if (cells.All(cell => hullCells.Contains((cell.X + x, cell.Y + y)) && + if (cells.All(cell => targetCells.Contains((cell.X + x, cell.Y + y)) && !occupied.Contains((cell.X + x, cell.Y + y)))) return (x, y, rotation); } @@ -249,9 +301,12 @@ public sealed class AetheriaDaemonLoadoutGenerator Quality = 1, Durability = 1, Quantity = 1, Enabled = true }; - private static AetheriaLoadoutItemSlot CargoSlot(int index, string itemKey) => new() + private static AetheriaLoadoutItemSlot CargoSlot(int index, string itemKey) => + CargoSlot(index % 4, index / 4, itemKey); + + private static AetheriaLoadoutItemSlot CargoSlot(int x, int y, string itemKey) => new() { - Position = new AetheriaGridCoord { X = index % 4, Y = index / 4 }, + Position = new AetheriaGridCoord { X = x, Y = y }, Item = new AetheriaLoadoutItem { ItemKey = itemKey, Quality = 1, Durability = 1, Quantity = 1, Enabled = true } }; } diff --git a/Aetheria.State.Verify/Program.cs b/Aetheria.State.Verify/Program.cs index 791db3a5c..54a31acc4 100644 --- a/Aetheria.State.Verify/Program.cs +++ b/Aetheria.State.Verify/Program.cs @@ -1242,7 +1242,9 @@ static void RequireDaemonPlayableRunGenerationAuthority(string root) "Math.Pow(item.Price, _priceExponent)", "Distance(_zoneIndex, _homeZones[item.ManufacturerKey])", "FitsHardpoint(candidate, hardpoint)", - "HasBehavior(candidate, controllerKind)" + "HasBehavior(candidate, controllerKind)", + "for (var draw = 0; draw < 16 && pool.Count > 0; draw++)", + "FindFit(interiorCells, width, height, item, occupied)" }; var daemonText = daemonProgram + "\n" + daemonZoneGenerator + "\n" + daemonLoadoutGenerator; diff --git a/docs/original-game-migration-matrix.md b/docs/original-game-migration-matrix.md index 94b2be9f4..45b14f6a3 100644 --- a/docs/original-game-migration-matrix.md +++ b/docs/original-game-migration-matrix.md @@ -17,7 +17,7 @@ validation proves contract shape, not wiring, exclusivity, lowering, or parity. |---|---|---|---|---|---|---| | Run/session state | `ServerShared`, `ActionGameManager` | Aetheria daemon/CultCache | provider/session advertisement | all clients | owner-exists; wired; projected; not proven | restart and multi-client convergence | | Entity identity/loadout | `ServerShared/Entity*` | daemon | typed entity and inventory surfaces | EveUnity/Electron | owner-exists; wired; projected; not proven | loadout round trip and reconnect | -| Loadout generation | map/faction availability, item cost, hull hardpoints and role constraints | daemon using canonical galaxy, faction knowledge/economy and typed catalog | generated loadout plus provenance/availability facts | Eve inspection and refit surfaces | daemon now uses the fossil candidate filter and seeded weighted selection: manufacturer must be present and allied, ally weight decays by home-zone graph distance, price uses the authored exponent, hardpoints require exact type/cell/rotation fit and controller role, and cargo/capacitor plus station docking equipment must fit remaining hull space; Terminus explicitly maps combat-role factions to catalog availability corporations | multi-zone generated-world parity, station inventory draws, faction-local stream/call-order parity, and generation provenance projection | +| Loadout generation | map/faction availability, item cost, hull hardpoints and role constraints | daemon using canonical galaxy, faction knowledge/economy and typed catalog | generated loadout plus provenance/availability facts | Eve inspection and refit surfaces | daemon now uses the fossil candidate filter and seeded weighted selection: manufacturer must be present and allied, ally weight decays by home-zone graph distance, price uses the authored exponent, hardpoints require exact type/cell/rotation fit and controller role, and cargo/capacitor plus station docking equipment must fit remaining hull space; stations draw up to sixteen faction-available equipment rows and pack largest-first into the selected cargo bay's actual interior shape; Terminus explicitly maps combat-role factions to catalog availability corporations | multi-zone generated-world parity, faction-local stream/call-order parity, and generation provenance projection | | Flight intent | `Ship`, `Thruster`, `AetherDrive`, input paths | daemon intent + Ymir physics | analog movement/look/tractor | EveUnity input driver | movement intents feed Ymir-owned body integration; authored thrust allocation, torque, energy and heat remain simplified | prove original drive/equipment behavior ordering and runtime interpolation | | Collision | Unity physics and entity handlers | Ymir | collision/result facts | visual interpolation only | Ymir.Core world stepping wired for entity bodies, radial fields and contacts; missing-owner negative proof passes | publish authoritative collision events and prove Unity cannot write transforms back | | Targeting/contacts | sensors + `ActionGameManager` | daemon | contact/target semantics | target HUD and indicators | simplified owner wired/projected; daemon weapon lock now acquires and decays from facing, elapsed time, and observer-local contact confidence instead of granting an immediate perfect lock | target-switch reset, angular decay, visibility/nearest/explicit cases, and runtime lock feedback |