CrewQuarters batch: the Crew Quarters design (HabitationData, twenty occupants, Water, Oxygen and Algae) and its not-offered product (cut habitation-gear)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-11-28 23:19:57 +01:00
commit cf91042828
2 changed files with 75 additions and 2 deletions

View file

@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Linq;
using GameCult.Caching;
using GameCult.Caching.MessagePack;
using MessagePack;
// Economy content: the Crew Quarters every station carries (aetheria-living-world, cut habitation-gear; rulings
// installed-gear-decides-what-a-station-buys, mass-populations-live-in-blooms). A 2x2 interior GearData on a Tool mount holding
// HabitationData: twenty occupants who eat Water, Oxygen and Algae, all basic, sold by a NotOffered product branded as the facilities
// are (a design no product sells is an unsold design; a not-offered product is on no market, and stations install it through
// LoadoutGenerator.InstalledProduct). The commodities are looked up by name, never created. The rates are first drafts, sim-tuned
// knobs (ruling economy-numbers-are-sim-tuned-knobs), as are the thermal band (shared with Facilities) and the price. Writes whole
// values, only where they differ, so a rerun touches nothing.
public sealed class CrewQuarters : EconomyBatch
{
private const int Capacity = 20;
private static readonly (string Commodity, float PerOccupantHour)[] Table = { ("Water", 2f), ("Oxygen", 1.5f), ("Algae", 1f) };
private const string Id = "crew-quarters";
private const string Name = "Crew Quarters";
private const string Description = "Bunks, galleys and recyclers for a station's crew: twenty people who drink, breathe and eat what the station hauls in.";
public override void Author(EconomyAuthor author)
{
var catalog = author.Catalog;
var options = CultDocumentMessagePackSerialization.OptionsFor(typeof(ItemData).Assembly);
var rows = Table.Select(row => (Key: Named(catalog, row.Commodity), row.PerOccupantHour)).ToArray();
var designKey = new CultRecordKey("habitation:" + Id);
var shape = new Shape(2, 2);
foreach (var cell in shape.AllCoordinates) shape[cell] = true;
// A stored behavior carries a cache-minted element id, so a design is compared by its fields, never by bytes.
if (!(catalog.Get(designKey) is GearData held && held.Name == Name && held.Description == Description && held.Hardpoint == HardpointType.Tool
&& held.Durability == 100 && held.Mass == 250 && held.Price == 1000 && held.Shape.Width == 2 && held.Shape.Height == 2 && held.Shape.Coordinates.Length == 4
&& held.Behaviors.Count == 1 && held.Behaviors[0] is HabitationData habitation && habitation.Capacity == Capacity && habitation.Table.Count == rows.Length
&& habitation.Table.Zip(rows, (have, want) => have.Commodity.Key.Equals(want.Key) && have.PerOccupantHour == want.PerOccupantHour && have.Basic).All(same => same)
&& held.MinimumTemperature == Facilities.ThermalMin && held.MaximumTemperature == Facilities.ThermalMax
&& held.OptimalTemperature == Facilities.ThermalOptimal && held.PlateauWidth == Facilities.ThermalPlateau))
author.Put(new GearData
{
Name = Name, Description = Description, Hardpoint = HardpointType.Tool, Shape = shape,
Durability = 100, Mass = 250, Price = 1000,
Behaviors =
{
new HabitationData
{
Capacity = Capacity,
Table = rows.Select(row => new HabitationRow { Commodity = new CultRecordRef<ItemData>(row.Key), PerOccupantHour = row.PerOccupantHour, Basic = true }).ToList()
}
},
MinimumTemperature = Facilities.ThermalMin, MaximumTemperature = Facilities.ThermalMax,
OptimalTemperature = Facilities.ThermalOptimal, PlateauWidth = Facilities.ThermalPlateau
}, designKey);
var maker = Facilities.MakerOf(catalog, StationKindData.KeyOf("residential").Value);
var product = new FactionProductData
{
Name = $"{maker.Faction.Name} {Name}", Description = Description, Design = new CultRecordRef<CraftedItemData>(designKey),
Manufacturer = new CultRecordRef<Faction>(maker.Key), NotOffered = true
};
var productKey = new CultRecordKey("product:habitation:" + Id);
var heldProduct = catalog.Get(productKey) as FactionProductData;
if (heldProduct == null || !MessagePackSerializer.Serialize(heldProduct, options).SequenceEqual(MessagePackSerializer.Serialize(product, options)))
author.Put(product, productKey);
}
private static CultRecordKey Named(CultCache catalog, string name)
{
var named = catalog.GetAll<ItemData>().Where(item => item.Name == name).ToArray();
if (named.Length != 1) throw new InvalidOperationException($"{named.Length} items are named '{name}'; the crew quarters need exactly one.");
return catalog.RefOf(named[0]).Key;
}
}

View file

@ -17,7 +17,7 @@ public sealed class Facilities : EconomyBatch
// is Active only while its cells are inside the band, and a station's cells start at 280 and cool toward 0 with no heater, so the
// band holds that whole range: full performance from 0 to 560 around 280, tapering to nothing at 1000, with the floor just below
// 0 so a cell that has cooled all the way is still inside it. Gear that leaves these unauthored gets GearData's 0 to 100.
private const float ThermalMin = -1, ThermalMax = 1000, ThermalOptimal = 280, ThermalPlateau = 560;
internal const float ThermalMin = -1, ThermalMax = 1000, ThermalOptimal = 280, ThermalPlateau = 560;
private static readonly (string Kind, string Id, string Name, string Description)[] Table =
{
@ -103,7 +103,7 @@ public sealed class Facilities : EconomyBatch
}
// The first faction by key that places the kind, else the first by key: the brand of a facility's product.
private static (CultRecordKey Key, Faction Faction) MakerOf(CultCache catalog, string kindKey)
internal static (CultRecordKey Key, Faction Faction) MakerOf(CultCache catalog, string kindKey)
{
var factions = catalog.GetAll<Faction>().Select(faction => (Key: catalog.RefOf(faction).Key, Faction: faction)).OrderBy(pair => pair.Key.Value, StringComparer.Ordinal).ToArray();
var maker = factions.FirstOrDefault(pair => StationKinds.KindsOf(catalog, pair.Faction).Any(kind => kind.Key.Value == kindKey));