ReturnedGoodsLandInTheOutputBays: a silo with room for one stack gives the hauler back a stack and no stock bay takes the rest

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-12-01 06:36:42 +01:00
commit e8e2087be8

View file

@ -94,21 +94,29 @@ public sealed partial class RunStartTests
Assert.Equal(leg.To.OrbitData, HaulRun.Leg(leg.Hauler, leg.Order));
}
// What a hauler gives back at From lands where the From's outputs land (OutputBays: its silo), never in a stock bay.
// What a hauler gives back at From lands where the From's outputs land (OutputBays: its silo) and nowhere else: with the silo full but
// for one stack's room, a hold of a stack and two more gives back the stack and keeps the two, and no stock bay takes any.
[Fact]
public void ReturnedGoodsLandInTheOutputBays()
{
var (_, _, legs) = SeededRegion(1, quiet: true);
var leg = legs.First(candidate => candidate.From.CargoBays.Any(bay => bay.Data is SiloData) && candidate.From.CargoBays.Any(bay => !(bay.Data is SiloData)));
var good = leg.Good;
Assert.True(leg.Hauler.CargoBays[0].TryStore(new SimpleCommodity { Data = new CultRecordRef<ItemData>(good), Quantity = 3 }));
var max = _cache.Get<SimpleCommodityData>(good).MaxStack;
var silos = leg.From.CargoBays.Where(bay => bay.Data is SiloData).ToArray();
foreach (var bay in silos)
while (bay.TryStore(new SimpleCommodity { Data = new CultRecordRef<ItemData>(good), Quantity = 1 })) { }
var freed = silos.SelectMany(bay => bay.Cargo.Keys).OfType<ICommodityStack>().First(stack => ((ItemInstance) stack).Data.Key.Equals(good));
silos.First(bay => bay.Cargo.ContainsKey((ItemInstance) freed)).Remove((ItemInstance) freed);
Assert.True(leg.Hauler.CargoBays[0].TryStore(new SimpleCommodity { Data = new CultRecordRef<ItemData>(good), Quantity = max }));
Assert.True(leg.Hauler.CargoBays[0].TryStore(new SimpleCommodity { Data = new CultRecordRef<ItemData>(good), Quantity = 2 }));
leg.Hauler.HaulSeen = new HaulSeen { Refusals = { new HaulRefusal { Good = new CultRecordRef<ItemData>(good), At = leg.FromZone.Contents.ExactTime } } };
var stock = leg.From.CargoBays.Where(bay => !(bay.Data is SiloData)).Sum(bay => bay.Count(good));
var silo = leg.From.CargoBays.Where(bay => bay.Data is SiloData).Sum(bay => bay.Count(good));
var silo = silos.Sum(bay => bay.Count(good));
Assert.True(HaulRun.CanCall(leg.Hauler, leg.From, leg.Order));
Assert.True(HaulRun.Call(leg.Hauler, leg.From));
Assert.Equal(0, Held(new[] { leg.Hauler }, good));
Assert.Equal(silo + 3, leg.From.CargoBays.Where(bay => bay.Data is SiloData).Sum(bay => bay.Count(good)));
Assert.Equal(silo + max, silos.Sum(bay => bay.Count(good)));
Assert.Equal(2, Held(new[] { leg.Hauler }, good));
Assert.Equal(stock, leg.From.CargoBays.Where(bay => !(bay.Data is SiloData)).Sum(bay => bay.Count(good)));
}