diff --git a/Assets/Scripts/ServerShared/RegionLegs.cs b/Assets/Scripts/ServerShared/RegionLegs.cs index 5125cc4c9..d6bfba77d 100644 --- a/Assets/Scripts/ServerShared/RegionLegs.cs +++ b/Assets/Scripts/ServerShared/RegionLegs.cs @@ -42,7 +42,7 @@ public static class RegionLegs foreach (var (zone, station, makes) in stations) { if (station.Faction == null) continue; - foreach (var good in StationWants.Drawable(station).Where(good => !makes.Contains(good)).OrderBy(good => good.Value, StringComparer.Ordinal)) + foreach (var good in StationWants.Consumed(station).Where(good => !makes.Contains(good)).OrderBy(good => good.Value, StringComparer.Ordinal)) { // The nearest producer of its own faction by jumps, then zone index, then entity order (the list's order: the first // of equals wins). diff --git a/Assets/Scripts/ServerShared/StationWants.cs b/Assets/Scripts/ServerShared/StationWants.cs index 3988bf737..a091067b2 100644 --- a/Assets/Scripts/ServerShared/StationWants.cs +++ b/Assets/Scripts/ServerShared/StationWants.cs @@ -80,20 +80,20 @@ public static class StationWants } } - private static HashSet Drawn(Entity station) => Draws(station, startableOnly: true); - - // Every good the station may draw: what its installed recipe facilities draw, startable or not (what a seeded haul leg may bring it, which - // does not wait for room), and what its crew eats. The one reader of what gear could use; Drawn is the startable part. - public static IReadOnlyCollection Drawable(Entity station) => Draws(station, startableOnly: false); + // Every good the station's installed recipe facilities consume, startable or not: what a standing haul order may carry to it (a + // seeded leg waits on room and never writes an order for a good no installed recipe takes). The crew's table is not here: it is + // bought by sale, never hauled by a seeded leg. Drawn is the startable part. + public static IReadOnlyCollection Consumed(Entity station) => + FacilityRecipes(station).SelectMany(recipe => Production.Draws(station.ItemManager.ItemData, recipe)).ToHashSet(); // The goods its installed recipe facilities make: the set Allocation builds. public static IReadOnlyCollection Makes(Entity station) => FacilityRecipes(station).Select(recipe => recipe.Output.Key).ToHashSet(); - private static HashSet Draws(Entity station, bool startableOnly) + private static HashSet Drawn(Entity station) { var catalog = station.ItemManager.ItemData; var wants = new HashSet(); - foreach (var recipe in FacilityRecipes(station).Where(recipe => !startableOnly || CanStart(station, recipe))) + foreach (var recipe in FacilityRecipes(station).Where(recipe => CanStart(station, recipe))) foreach (var draw in Production.Draws(catalog, recipe)) wants.Add(draw); // What its crew eats: the table of every habitation unit that runs (the module defines what and how much it consumes). diff --git a/tests/Aetheria.Shared.Tests/RegionLegsTests.cs b/tests/Aetheria.Shared.Tests/RegionLegsTests.cs index 9c8bb55e8..2838f6713 100644 --- a/tests/Aetheria.Shared.Tests/RegionLegsTests.cs +++ b/tests/Aetheria.Shared.Tests/RegionLegsTests.cs @@ -44,6 +44,7 @@ public sealed partial class RunStartTests Assert.Same(At(order.From.Key).Faction, At(order.To.Key).Faction); Assert.Equal(order.Goods.Select(good => good.Key.Value).OrderBy(v => v, StringComparer.Ordinal), order.Goods.Select(good => good.Key.Value)); Assert.Empty(order.Goods.Select(good => good.Key).Intersect(StationWants.Makes(At(order.To.Key)))); + Assert.Empty(order.Goods.Select(good => good.Key).Except(StationWants.Consumed(At(order.To.Key)))); } var expectedGoods = 0; for (var s = 0; s < stations.Length; s++) @@ -51,7 +52,7 @@ public sealed partial class RunStartTests var (zone, station) = stations[s]; if (station.Faction == null) continue; var makes = StationWants.Makes(station); - foreach (var good in StationWants.Drawable(station).Where(good => !makes.Contains(good))) + foreach (var good in StationWants.Consumed(station).Where(good => !makes.Contains(good))) { var producers = stations.Select((x, index) => (x.Zone, x.Station, index)).Where(x => x.Station != station && x.Station.Faction == station.Faction && StationWants.Makes(x.Station).Contains(good)).ToArray(); @@ -63,8 +64,8 @@ public sealed partial class RunStartTests } } Assert.Equal(expectedGoods, orders.Sum(order => order.Goods.Count)); - // Seeds 1 to 97 hold the whole range the spec probed: dozens of orders, and legs that jump. - Assert.InRange(orders.Length, 20, 80); + // Seeds 1 to 97: a dozen to several dozen orders (a crew-only good has none), and legs that jump. + Assert.InRange(orders.Length, 10, 80); } } }