diff --git a/tests/Aetheria.Shared.Tests/ConsumableSupplyTests.cs b/tests/Aetheria.Shared.Tests/ConsumableSupplyTests.cs index 23dcd935e..30f68c6e0 100644 --- a/tests/Aetheria.Shared.Tests/ConsumableSupplyTests.cs +++ b/tests/Aetheria.Shared.Tests/ConsumableSupplyTests.cs @@ -71,6 +71,8 @@ public sealed class ConsumableSupplyTests : IDisposable return shape; } + private static HardpointData CrewRow() => new HardpointData { Type = HardpointType.Facility, Position = new CultMath.int2(1, 1), Shape = Solid(2, 2), Transform = "Fa.1" }; + private Rig Build(Offer offer, Holds holds = Holds.Pinned) { var root = Path.Combine(_root, "rig" + _rigs++); @@ -87,7 +89,7 @@ public sealed class ConsumableSupplyTests : IDisposable // Interior for the crate, the capacitor and the tractor beam every generated ship carries. var hub = new CultRecordRef(seed.Upsert(new StationKindData { Name = "Hub" }).Key); var skiff = seed.Upsert(new HullData { Name = "Skiff", HullType = HullType.Ship, Shape = Solid(5, 3), Price = 100 }); - var platform = seed.Upsert(new HullData { Name = "Platform", HullType = HullType.Station, Kind = hub, Shape = Solid(5, 5), Price = 100 }); + var platform = seed.Upsert(new HullData { Name = "Platform", HullType = HullType.Station, Kind = hub, Shape = Solid(5, 5), Price = 100, Hardpoints = { CrewRow() } }); // A hold with no cell cannot take a consumable. var crate = seed.Upsert(new CargoBayData { @@ -102,8 +104,9 @@ public sealed class ConsumableSupplyTests : IDisposable Name = "Heater", Hardpoint = HardpointType.Tool, Shape = new Shape(), Price = 1, Behaviors = { new ThermotoggleData { HighPass = false }, new HeatData() } }); - // Every station carries Crew Quarters, installed through a not-offered product (one interior cell: the Outpost is a cell wider for it). - var quarters = seed.Upsert(new GearData { Name = "Quarters", Hardpoint = HardpointType.Tool, Shape = new Shape(), Price = 1, Behaviors = { new HabitationData { Capacity = 1 } } }); + // Every station carries Crew Quarters on a Facility row, installed through a not-offered product (the Outpost is two cells wider + // for its row: it keeps its four interior gear cells). + var quarters = seed.Upsert(new GearData { Name = "Quarters", Hardpoint = HardpointType.Facility, Shape = Solid(2, 2), Price = 1, Behaviors = { new HabitationData { Capacity = 1 } } }); seed.Upsert(new FactionProductData { Name = "Quarters by Maker", Design = new CultRecordRef(quarters.Key), Manufacturer = maker, NotOffered = true }); // Hardpoint gear no hull in this catalog has a hardpoint for: it has no home. var orphan = seed.Upsert(new GearData { Name = "Orphan", Hardpoint = HardpointType.Sensors, Shape = new Shape(), Price = 1 }); @@ -112,7 +115,7 @@ public sealed class ConsumableSupplyTests : IDisposable if (holds != Holds.Pinned) { sold.Add(("Cutter", seed.Upsert(new HullData { Name = "Cutter", HullType = HullType.Ship, Shape = Solid(5, 3), Price = 100 }).Key)); - sold.Add(("Outpost", seed.Upsert(new HullData { Name = "Outpost", HullType = HullType.Station, Kind = hub, Shape = Solid(5, 4), Price = 100 }).Key)); + sold.Add(("Outpost", seed.Upsert(new HullData { Name = "Outpost", HullType = HullType.Station, Kind = hub, Shape = Solid(6, 4), Price = 100, Hardpoints = { CrewRow() } }).Key)); sold.Add(("Plate", seed.Upsert(new GearData { Name = "Plate", Hardpoint = HardpointType.Tool, Shape = Solid(2, 2), Price = 1 }).Key)); } diff --git a/tests/Aetheria.Shared.Tests/HabitationTests.cs b/tests/Aetheria.Shared.Tests/HabitationTests.cs index e76ed0179..6c5c2ff49 100644 --- a/tests/Aetheria.Shared.Tests/HabitationTests.cs +++ b/tests/Aetheria.Shared.Tests/HabitationTests.cs @@ -148,6 +148,36 @@ public sealed class HabitationTests : IDisposable Assert.Equal(0, partial.Held(_water)); } + [Fact] + public void AnUnsetRowOwesNothing() + { + // A row that names no commodity consumes nothing and keeps nothing owed, however long it steps: Owed stays a fraction below one. + var data = Table(); + data.Table.Add(new HabitationRow { PerOccupantHour = 1000, Basic = true }); + var hold = Stocked(1000, 1000); + Habitants state = null; + for (var span = 0; span < 50; span++) (state, _) = Upkeep.Advance(data, state, 3600, hold); + Assert.Equal(3, state.Owed.Length); + Assert.Equal(0, state.Owed[2]); + Assert.All(state.Owed, owed => Assert.InRange(owed, 0, 1)); + } + + [Fact] + public void ADisabledOrDestroyedHabitationUnitBuysNothing() + { + // StationWants.Drawn reads the unit's table only while it runs: a unit switched off or shot out is no crew. + var world = Build(); + var eaten = new[] { _water, _air }; + Assert.All(eaten, good => Assert.Contains(good, StationWants.Of(world.Station))); + var unit = world.Station.Equipment.Single(equipped => equipped.Behaviors.OfType().Any()); + unit.Enabled.Value = false; + Assert.All(eaten, good => Assert.DoesNotContain(good, StationWants.Of(world.Station))); + unit.Enabled.Value = true; + Assert.All(eaten, good => Assert.Contains(good, StationWants.Of(world.Station))); + unit.EquippableItem.Durability = 0; + Assert.All(eaten, good => Assert.DoesNotContain(good, StationWants.Of(world.Station))); + } + [Fact] public void NullStateIsFullCapacity() { diff --git a/tests/Aetheria.Shared.Tests/RunStartTests.cs b/tests/Aetheria.Shared.Tests/RunStartTests.cs index 2772d5f7f..6619d25ca 100644 --- a/tests/Aetheria.Shared.Tests/RunStartTests.cs +++ b/tests/Aetheria.Shared.Tests/RunStartTests.cs @@ -151,11 +151,15 @@ public sealed partial class RunStartTests : IDisposable .Concat(station.CargoBays.SelectMany(bay => bay.Cargo.Keys).OfType()) .Select(item => (_items.GetData(item).Name, _items.Brand(item).Product)); + // Station plant: a not-offered product whose design mounts on a Facility row. The one exemption from the reach rule. + private bool IsInstalledPlant(FactionProductData product) => + product.NotOffered && _cache.Get(product.Design) is EquippableItemData design && design.HardpointType == HardpointType.Facility; + private string Maker(FactionProductData product) => product == null ? "nobody" : _cache.Get(product.Manufacturer)?.Name ?? "nobody"; // Every faction's stations, in a main-sector galaxy, carry a heater and a reactor, and nothing, equipped or - // stocked, from a manufacturer that faction cannot reach (LoadoutGenerator.IsAvailable, the one reach rule). Installed plant, which a - // not-offered product makes (the Crew Quarters, as a facility), is no one's draw and so outside the rule. + // stocked, from a manufacturer that faction cannot reach (LoadoutGenerator.IsAvailable, the one reach rule). Only station plant, a + // not-offered product of Facility gear on a Facility row (the kind's facilities and the Crew Quarters), is no one's draw and so outside it. [Fact] public void EveryFactionsStationsCarryOnlyGearItCanReachIncludingAHeaterAndAReactor() { @@ -170,7 +174,7 @@ public sealed partial class RunStartTests : IDisposable var station = EntitySerializer.Unpack(_items, zone, generator.GenerateStationLoadout(TestStationKinds.TradeHub)); Assert.True(station.Equipment.Count(IsHeater) == 1, $"{faction.Name} station {i}: no heater"); Assert.True(station.Equipment.Any(item => item.Behaviors.OfType().Any()), $"{faction.Name} station {i}: no reactor"); - var unreachable = Made(station).Where(made => made.product == null || (LoadoutGenerator.IsOffered(_cache, made.product) && !generator.IsAvailable(made.product))).ToList(); + var unreachable = Made(station).Where(made => made.product == null || (!IsInstalledPlant(made.product) && !generator.IsAvailable(made.product))).ToList(); Assert.True(unreachable.Count == 0, $"{faction.Name} station {i} carries {string.Join(", ", unreachable.Select(u => u.item + " by " + Maker(u.product)))}"); } @@ -220,7 +224,7 @@ public sealed partial class RunStartTests : IDisposable { station = EntitySerializer.Unpack(_items, zone, generator.GenerateStationLoadout(TestStationKinds.TradeHub)); Assert.True(station.Equipment.Any(item => item.Behaviors.OfType().Any()), $"station {i}: no reactor"); - var foreign = Made(station).Where(made => made.product == null || (LoadoutGenerator.IsOffered(_cache, made.product) && !generator.IsAvailable(made.product)) || + var foreign = Made(station).Where(made => made.product == null || (!IsInstalledPlant(made.product) && !generator.IsAvailable(made.product)) || made.product.Manufacturer.Key.Equals(_cache.RefOf(zhestokost).Key)).ToList(); Assert.True(foreign.Count == 0, $"station {i} carries {string.Join(", ", foreign.Select(u => u.item + " by " + Maker(u.product)))}"); } diff --git a/tests/Aetheria.Shared.Tests/StationFacilityFitTests.cs b/tests/Aetheria.Shared.Tests/StationFacilityFitTests.cs index 8d7fcee36..b1aa1c437 100644 --- a/tests/Aetheria.Shared.Tests/StationFacilityFitTests.cs +++ b/tests/Aetheria.Shared.Tests/StationFacilityFitTests.cs @@ -40,7 +40,8 @@ public sealed class StationFacilityFitTests foreach (var (maker, kind, seed) in cases) { var (items, station) = Generate(cache, maker, kind, seed); - var wanted = cache.Get(kind).Facilities.Select(facility => cache.Get(facility).Name).OrderBy(name => name, StringComparer.Ordinal).ToArray(); + // The kind's facilities and the one Crew Quarters every station carries (StationKinds.InstalledDesigns). + var wanted = StationKinds.InstalledDesigns(cache, cache.Get(kind)).Select(design => design.Name).OrderBy(name => name, StringComparer.Ordinal).ToArray(); Assert.Equal(wanted, FacilityKeys(station)); Assert.All(station.Equipment.Concat(station.CargoBays).Where(item => item.Data.HardpointType == HardpointType.Facility), item => Assert.Equal(HardpointType.Facility, item.Hardpoint.Type)); @@ -70,7 +71,9 @@ public sealed class StationFacilityFitTests using var cache = RestoredHullsTests.OpenCatalog(); var mining = cache.Get(Kind("mining")); var extra = cache.Get(Kind("processing")).Facilities.First(); - // Twice, so the kind needs three rows whichever hull of the kind is drawn: no hull has more than two. + // Three times, so the kind needs five rows whichever hull of the kind is drawn: no hull has more than three (two for its facilities + // and the Crew Quarters' row). + mining.Facilities.Add(extra); mining.Facilities.Add(extra); mining.Facilities.Add(extra); var maker = cache.GetAll().First(faction => StationKinds.FieldableKindsOf(cache, faction).Any(kind => kind.Key.Equals(Kind("mining").Key))); diff --git a/tests/Aetheria.Shared.Tests/StationKindTests.cs b/tests/Aetheria.Shared.Tests/StationKindTests.cs index d91b76f3a..048ec2847 100644 --- a/tests/Aetheria.Shared.Tests/StationKindTests.cs +++ b/tests/Aetheria.Shared.Tests/StationKindTests.cs @@ -203,12 +203,14 @@ public sealed class StationKindTests : IDisposable public void AStationGeneratesWithItsFacilityRowUnfilledAndUnlogged() { var world = World.Make(this, zenithOffered: true); - Assert.Single(world.Zenith.Hardpoints, row => row.Type == HardpointType.Facility); + Assert.Equal(2, world.Zenith.Hardpoints.Count(row => row.Type == HardpointType.Facility)); // its kind's silo row and the Crew Quarters' row for (uint seed = 1; seed <= 8; seed++) { var pack = world.Generator(world.Au, seed).GenerateStationLoadout(Kind("trade-hub")); Assert.Equal("Zenith", world.HullName(pack)); - Assert.DoesNotContain(pack.Equipment, entry => entry.item != null && ((EquippableItemData) world.Items.GetData(entry.item)).HardpointType == HardpointType.Facility); + // Only the Crew Quarters sits on a Facility row of Zenith's pack (the trade hub's silo is a bay): nothing else decides a row. + Assert.All(pack.Equipment.Where(entry => entry.item != null && ((EquippableItemData) world.Items.GetData(entry.item)).HardpointType == HardpointType.Facility), + entry => Assert.True(StationKinds.IsCrewQuarters(world.Items.GetData(entry.item)))); } Assert.DoesNotContain(world.Log, line => line.Contains("Facility hardpoint")); }