From 67afbdc65fd1885eb0063dfbb38d86652cdbd0a3 Mon Sep 17 00:00:00 2001 From: soul Date: Sun, 29 Nov 2026 05:43:48 +0100 Subject: [PATCH] The quarters seat with the facilities through InstalledDesigns, one call site; the drain asks by Habitants.Size and pins the short-span count EquipCrewQuarters and its filters are deleted (seating last protected nothing: the digest re-measure covers the stream). Co-Authored-By: Claude Sonnet 5.5 --- .../Scripts/ServerShared/LoadoutGenerator.cs | 26 +++++-------------- .../EconomyDrainTests.cs | 17 +++++++++++- tools/AetherDb/EconomyDrain.cs | 4 +-- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/Assets/Scripts/ServerShared/LoadoutGenerator.cs b/Assets/Scripts/ServerShared/LoadoutGenerator.cs index 4f225f32c..d6a9fa29b 100644 --- a/Assets/Scripts/ServerShared/LoadoutGenerator.cs +++ b/Assets/Scripts/ServerShared/LoadoutGenerator.cs @@ -161,8 +161,6 @@ public class LoadoutGenerator if (cargo.TryStore(instance)) stocked += cells; } - EquipCrewQuarters(entity, kind); - entity.CanTow = hullData.CanTow; return EntitySerializer.Pack(entity) as OrbitalEntityPack; @@ -379,31 +377,21 @@ public class LoadoutGenerator throw new InvalidLoadoutException("Failed to equip selected tractor beam!"); } - // Installs the station kind's Facilities, largest shape first then by name (StationKinds.InstalledDesigns' order, which - // FacilityRoomFaults counts rows in), each on a free Facility row that takes it. The brand is derived, never drawn: the station - // faction's own product of the design, else the first by name. A facility is on no market, so the product need not be offered. Draws - // nothing from Random. - private void EquipFacilities(Entity entity, CultRecordRef kind) => - Install(entity, kind, StationKinds.InstalledDesigns(ItemManager.ItemData, ItemManager.ItemData.Get(kind)).Where(design => !StationKinds.IsCrewQuarters(design))); - - // Installs the Crew Quarters on the station's last Facility row, after every other draw of the loadout: making the unit takes a lot from - // the item stream, and made last it moves no draw the station's own generation makes (the cargo bay it draws, the gear it stocks). + // Installs what the station's kind installs (StationKinds.InstalledDesigns: its facilities, largest shape first then by name, then the + // Crew Quarters; the order FacilityRoomFaults counts rows in), each on a free Facility row that takes it. The brand is derived, never + // drawn: the station faction's own product of the design, else the first by name. A facility is on no market, so the product need not + // be offered. Draws nothing from Random. // // CONJURE (ruling economy-is-never-faked): every station is handed a Crew Quarters here from a not-offered product that no facility // makes, as it is handed its kind's facilities. This is interim scaffolding, named so it is deleted and not forgotten: follow-up // conjuring-site-deletions removes it once habitat gear works (a gear-works facility making Crew Quarters) exist to supply the // station's quarters, and the installation then comes from that production. - private void EquipCrewQuarters(Entity entity, CultRecordRef kind) - { - var quarters = StationKinds.InstalledDesigns(ItemManager.ItemData, ItemManager.ItemData.Get(kind)).Where(StationKinds.IsCrewQuarters).ToArray(); - if (quarters.Length == 0) throw new InvalidLoadoutException("No crew quarters design in the catalog for station!"); - Install(entity, kind, quarters); - } - - private void Install(Entity entity, CultRecordRef kind, IEnumerable designs) + private void EquipFacilities(Entity entity, CultRecordRef kind) { var kindData = ItemManager.ItemData.Get(kind); var hullName = ItemManager.GetData(entity.Hull).Name; + var designs = StationKinds.InstalledDesigns(ItemManager.ItemData, kindData); + if (!designs.Any(StationKinds.IsCrewQuarters)) throw new InvalidLoadoutException("No crew quarters design in the catalog for station!"); foreach (var design in designs) { var product = InstalledProduct(design); diff --git a/tests/Aetheria.Shared.Tests/EconomyDrainTests.cs b/tests/Aetheria.Shared.Tests/EconomyDrainTests.cs index a03990f5f..712bfc9de 100644 --- a/tests/Aetheria.Shared.Tests/EconomyDrainTests.cs +++ b/tests/Aetheria.Shared.Tests/EconomyDrainTests.cs @@ -74,11 +74,26 @@ public sealed class EconomyDrainTests Assert.Equal(("Crew Quarters", 20, 120, 7200.0), (crew.Name, crew.Occupants, crew.Spans, crew.Seconds)); // Twenty occupants over two hours at the drafted rates: Water 2.0, Oxygen 1.5 and Algae 1.0 per occupant hour. Assert.Equal(new[] { ("Algae", 40.0), ("Oxygen", 60.0), ("Water", 80.0) }, crew.Asked.OrderBy(kv => kv.Key, StringComparer.Ordinal).Select(kv => (kv.Key, Math.Round(kv.Value, 6)))); - Assert.True(crew.ShortSpans > crew.Spans / 2, $"short in {crew.ShortSpans} of {crew.Spans} spans"); + // Pinned: the first span owes no whole unit of any row (20 occupants x 2 Water an hour is 0.67 a span), every later one owes some + // and the hold has none. + Assert.Equal(119, crew.ShortSpans); Assert.Contains("crew Crew Quarters (20 occupants): per sim hour asked ", Printed(sample)); } } + // What the crew asks reads its population: a quarters holding ten of its twenty asks half (the figure reads Habitants.Size, not Capacity). + [Fact] + public void TheCrewAsksForItsPopulationNotItsCapacity() + { + var sample = EconomyDrain.Run(Root, 1, 30, 2, Seed1.Value, demo => + { + var quarters = demo.Processing.Equipment.Single(unit => unit.Behaviors.OfType().Any()); + quarters.EquippableItem.Habitants = new Habitants { Size = 10, Owed = new double[3] }; + }); + var crew = Assert.Single(Station(sample, "processing").Crew); + Assert.Equal(new[] { ("Algae", 20.0), ("Oxygen", 30.0), ("Water", 40.0) }, crew.Asked.OrderBy(kv => kv.Key, StringComparer.Ordinal).Select(kv => (kv.Key, Math.Round(kv.Value, 6)))); + } + // A drain copy shares no object with the live station: EntitySerializer.Pack alone puts the live stacks in the pack, so a copy // made from it would move the original's units when it sells or takes (Soul s1, copy-isolation-unpinned). [Fact] diff --git a/tools/AetherDb/EconomyDrain.cs b/tools/AetherDb/EconomyDrain.cs index e21d16f85..b9984da00 100644 --- a/tools/AetherDb/EconomyDrain.cs +++ b/tools/AetherDb/EconomyDrain.cs @@ -409,7 +409,7 @@ public static class EconomyDrain // The copy's facilities and crew quarters, each advanced through `seconds` of sim time in spans of RegionClock.Span by the off-screen // step the game ships (RegionClock.AdvanceInstalled), in equipment order. Returns the Stall each facility ended in; each sees the sim - // time and the stalls after every span. With a tally, each span adds what the crew asked of the hold (occupants x rate x span) and + // time and the stalls after every span. With a tally, each span adds what the crew asked of the hold (the unit's Habitants.Size, Capacity before its first step, x rate x span) and // whether a quarters' step went short (Habitation.Shortfall), indexed as Drain.Crew. public Stall[] Spans(Entity copy, double seconds, Action each = null, IReadOnlyList tally = null) { @@ -431,7 +431,7 @@ public static class EconomyDrain foreach (var row in data.Table) { var name = Name(Demo.Cache, row.Commodity.Key.Value); - tally[c].Asked[name] = tally[c].Asked.GetValueOrDefault(name) + data.Capacity * row.PerOccupantHour * span / 3600; + tally[c].Asked[name] = tally[c].Asked.GetValueOrDefault(name) + (crews[c].EquippableItem.Habitants?.Size ?? data.Capacity) * row.PerOccupantHour * span / 3600; } } at += span;