A Facility row stays for facilities: general gear never takes an empty one; drain and fit tests follow the silo

A hull with two Facility rows serving a kind with one facility left the second to the docking bay (Entity.UnoccupiedSpace and ItemFits counted
empty hardpoint cells as free for general gear); the rows are the hull's stated facility capacity (ruling station-facilities-on-typed-mounts),
and StationFacilityFitTests.NoInteriorGearSitsOnAFacilityRow pins it. The drain tests change with the cut: the shipped refinery drains into its
silo, and the Room stall fault is pinned by a silo jammed full. Zenith's refinery intake pin names the non-silo bays.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-11-28 17:25:16 +01:00
commit 483176723d
4 changed files with 43 additions and 23 deletions

View file

@ -1473,8 +1473,10 @@ public abstract class Entity
var emptyShape = new Shape(HullData.Shape.Width, HullData.Shape.Height);
foreach (var v in HullData.Shape.Coordinates)
{
// Empty hardpoint cells count as free: general gear may use them until hardpoint gear claims them
if (HullData.InteriorCells[v] && GearOccupancy[v.x, v.y] == null)
// Empty hardpoint cells count as free: general gear may use them until hardpoint gear claims them. A Facility row
// is the exception: it is the hull's stated facility capacity (ruling station-facilities-on-typed-mounts), so a row
// no facility fills stays empty rather than taking a docking bay or a heater.
if (HullData.InteriorCells[v] && GearOccupancy[v.x, v.y] == null && !OnFacilityRow(v.x, v.y))
emptyShape[v] = true;
}
@ -1558,7 +1560,7 @@ public abstract class Entity
// general gear may take it until hardpoint gear claims it, which is the same rule
// UnoccupiedSpace reports, so what generation is offered and what equipping accepts agree.
var itemCoord = hullCoord + itemData.Shape.Rotate(i, item.Rotation);
if (!hullData.InteriorCells[itemCoord] || !IsFree(itemCoord.x, itemCoord.y, moving))
if (!hullData.InteriorCells[itemCoord] || !IsFree(itemCoord.x, itemCoord.y, moving) || OnFacilityRow(itemCoord.x, itemCoord.y))
return false;
}
}
@ -1571,6 +1573,8 @@ public abstract class Entity
return true;
}
private bool OnFacilityRow(int x, int y) => Hardpoints[x, y]?.Type == HardpointType.Facility;
// A cell is free when no gear occupies it, or when the only occupant is the item being moved: a re-place of
// equipped gear is judged against the hull minus that item's own cells (the caller unequips, then equips).
private bool IsFree(int x, int y, EquippedItem moving) => GearOccupancy[x, y] == null || GearOccupancy[x, y] == moving;

View file

@ -4,8 +4,9 @@ using System.Linq;
using GameCult.Caching;
using Xunit;
// The station-drain stage of `economy balance --drain` (EconomyDrain) on the demo run of seed 1: the shipped refinery stalls Room the
// moment a sale fills it, the trade hub's silo and stock bay take ore apart, and the window by steps agrees with the window by spans.
// The station-drain stage of `economy balance --drain` (EconomyDrain) on the demo run of seed 1: the shipped refinery drains its first
// fill into its silo (a silo the outputs cannot land in is the Room stall fault), the trade hub's silo and stock bay take ore apart, and
// the window by steps agrees with the window by spans.
public sealed class EconomyDrainTests
{
private static string Root => RunStartTests.FindRepoRoot();
@ -29,6 +30,16 @@ public sealed class EconomyDrainTests
foreach (var gear in bay.Cargo.Keys.Where(item => !(item is ICommodityStack)).ToList()) bay.Remove(gear);
}
// A silo the refinery's outputs cannot land in: every cell holds Iron, so a recipe with room under its share still ends its cycle
// with nowhere to put the batch.
private static void JamSilo(DemoArena demo)
{
var iron = new CultRecordKey("commodity:iron");
var stack = demo.Cache.Get<SimpleCommodityData>(iron).MaxStack;
foreach (var bay in demo.Processing.CargoBays.Where(bay => bay.Data is SiloData))
while (bay.TryStore(new SimpleCommodity { Data = new CultRecordRef<ItemData>(iron), Quantity = stack })) { }
}
[Fact]
public void DrainIsDeterministic()
{
@ -77,11 +88,17 @@ public sealed class EconomyDrainTests
[Fact]
public void WindowAgreesWithSpans()
{
// Long enough for the first cycle to end: Room is inside the window, not only the horizon (Soul s1, window-stall-vacuous).
// Long enough for the first cycle to end: a Room stall is inside the window, not only the horizon (Soul s1, window-stall-vacuous).
// The shipped refinery lands its first batch in the silo and never stalls; the jammed silo does, and both agree with the spans.
var sample = EconomyDrain.Run(Root, 1, 700, 1, Seed1.Value);
Assert.All(sample.Stations, station => Assert.Empty(station.WindowDisagreements));
Assert.DoesNotContain(EconomyDrain.Report(new[] { sample }), fault => fault.Invariant == EconomyDrain.HSim);
Assert.True(Station(sample, "processing").Facilities.Single().WindowSteps.TryGetValue(Stall.Room, out var roomSteps) && roomSteps > 0);
Assert.False(Station(sample, "processing").Facilities.Single().WindowSteps.TryGetValue(Stall.Room, out var shippedRoom) && shippedRoom > 0);
var jammed = EconomyDrain.Run(Root, 1, 700, 1, Seed1.Value, beforeWindow: JamSilo);
Assert.All(jammed.Stations, station => Assert.Empty(station.WindowDisagreements));
Assert.DoesNotContain(EconomyDrain.Report(new[] { jammed }), fault => fault.Invariant == EconomyDrain.HSim);
Assert.True(Station(jammed, "processing").Facilities.Single().WindowSteps.TryGetValue(Stall.Room, out var roomSteps) && roomSteps > 0);
// A facility that does not run on screen while the spans run it: the held counts and the run part.
var off = EconomyDrain.Run(Root, 1, 120, 1, Seed1.Value, beforeWindow: demo =>
@ -113,24 +130,23 @@ public sealed class EconomyDrainTests
[Fact]
public void AFullRefineryIsAStallFault()
{
// The sale fills the stock bay's free cells; the outputs land in the silo, so the ore drains to nothing and the stall is Inputs.
var shipped = EconomyDrain.Run(Root, 1, 30, 4, Seed1.Value);
var refinery = Station(shipped, "processing");
Assert.True(refinery.Filled);
Assert.Equal(Stall.Room, refinery.Facilities.Single().HorizonEnd);
Assert.NotNull(refinery.FirstRoomStall);
var fault = Assert.Single(EconomyDrain.Report(new[] { shipped }), f => f.Invariant == EconomyDrain.HStall);
Assert.Contains("Room", fault.Message);
Assert.Contains(refinery.Outputs, pile => pile.Hourly.Any(units => units > 0));
Assert.NotNull(refinery.Ores[0].EmptyAt);
Assert.Null(refinery.FirstRoomStall);
Assert.Equal(Stall.Inputs, refinery.Facilities.Single().HorizonEnd);
Assert.DoesNotContain(EconomyDrain.Report(new[] { shipped }), f => f.Invariant == EconomyDrain.HStall);
// The sale fills every cell: a bay emptied before the fill is filled again by the next sortie. With the starting gear put
// away after the fill (eight cells) there is room for outputs: the ore drains to nothing, the block reports how long that
// takes, and the stall is Inputs, not a fault.
var made = EconomyDrain.Run(Root, 1, 30, 24, Seed1.Value, beforeWindow: PutGearAway);
var roomy = Station(made, "processing");
Assert.Contains(roomy.Outputs, pile => pile.Hourly.Any(units => units > 0));
Assert.NotNull(roomy.Ores[0].EmptyAt);
Assert.Null(roomy.FirstRoomStall);
Assert.Equal(Stall.Inputs, roomy.Facilities.Single().HorizonEnd);
Assert.DoesNotContain(EconomyDrain.Report(new[] { made }), f => f.Invariant == EconomyDrain.HStall);
// Positive control: a silo the batch cannot land in ends the horizon stalled Room with ore still held, which is the fault.
var jammed = EconomyDrain.Run(Root, 1, 30, 4, Seed1.Value, beforeWindow: JamSilo);
var stuck = Station(jammed, "processing");
Assert.Equal(Stall.Room, stuck.Facilities.Single().HorizonEnd);
Assert.NotNull(stuck.FirstRoomStall);
var fault = Assert.Single(EconomyDrain.Report(new[] { jammed }), f => f.Invariant == EconomyDrain.HStall);
Assert.Contains("Room", fault.Message);
}
// A sortie the base loop faults is a fault of its own and no sortie of the fill count (Soul s1, fill-count-artifact).

View file

@ -45,7 +45,7 @@ public sealed partial class RunStartTests
Assert.Equal(0, stock.Count(good));
var drawn = StationWants.Of(refinery).First(key => FieldKinds.IsOre(_cache, _cache.Get(new CultRecordRef<ItemData>(key))));
Assert.Equal(refinery.CargoBays, StationWants.Bays(refinery, drawn));
Assert.Equal(refinery.CargoBays.Where(bay => !(bay.Data is SiloData)), StationWants.Bays(refinery, drawn));
var ore = new SimpleCommodity { Data = new CultRecordRef<ItemData>(drawn), Quantity = 5 };
Assert.True(hold.TryStore(ore));
var taken = StationServices.TrySellPart(hold, refinery, ore, ref credits);

View file

@ -69,7 +69,7 @@ public sealed class StationFacilityFitTests
{
using var cache = RestoredHullsTests.OpenCatalog();
var mining = cache.Get(Kind("mining"));
var extra = cache.Get(Kind("processing")).Facilities.Single();
var extra = cache.Get(Kind("processing")).Facilities.First();
mining.Facilities.Add(extra);
var maker = cache.GetAll<Faction>().First(faction => StationKinds.FieldableKindsOf(cache, faction).Any(kind => kind.Key.Equals(Kind("mining").Key)));
var error = Assert.Throws<InvalidLoadoutException>(() => Generate(cache, maker, Kind("mining"), 1));