Facility vocabulary: HardpointType.Facility, FacilityData, RecipeData.Facility, StationKindData.Facilities

HardpointType.Facility is appended after ControlModule (value 13) with ship_cc's names in step: an
internal station mount, no anchor, filled only by a kind's Facilities. FacilityData is an inert
BehaviorData (union arm 53). RecipeData.Facility (Key 10) and StationKindData.Facilities (Key 3) read
unset and empty from older records. HullKindFault refuses a Facility row on a Ship or Turret hull.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-11-28 02:14:29 +01:00
commit d932484721
11 changed files with 122 additions and 8 deletions

View file

@ -200,6 +200,7 @@ public interface IPowerConsumer
Union(50, typeof(ListenerData)),
Union(51, typeof(ScannerData)),
Union(52, typeof(LockWeaponData)),
Union(53, typeof(FacilityData)),
JsonObject(MemberSerialization.OptIn)]
public abstract class BehaviorData
{

View file

@ -0,0 +1,26 @@
using MessagePack;
using Newtonsoft.Json;
// The facility gear a station carries to run recipes: a GearData of HardpointType Facility whose Behaviors hold one of these. The type
// says where it mounts (a hull's Facility rows), this says it runs recipes. It holds no field of its own: which recipes a facility
// runs is derived from RecipeData.Facility, so no list is stored here.
[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class FacilityData : BehaviorData
{
public override Behavior CreateInstance(EquippedItem item)
{
return new Facility(this, item);
}
public override Behavior CreateInstance(ConsumableItemEffect item)
{
return new Facility(this, item);
}
}
// The installed facility that will run its recipes (ruling demand-consumed-inputs-processed-by-facilities). It runs nothing until
// follow-up facility-production: it is seated, priced and carried, and that is all.
public class Facility : Behavior
{
public Facility(FacilityData data, EquippedItem item) : base(data, item) { }
public Facility(FacilityData data, ConsumableItemEffect item) : base(data, item) { }
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a65a21b40f2a4daba2b058018ba5e8d7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -49,7 +49,10 @@ public enum HardpointType
Energy,
Ballistic,
Launcher,
ControlModule
ControlModule,
// A station facility mount: only a station hull carries one (StationKinds.HullKindFault). Internal: no anchor, nothing on the
// model. Filled only by a kind's Facilities; the random hardpoint fill never touches it. Appended: stored types keep their values.
Facility
}
public enum WeaponType

View file

@ -35,7 +35,8 @@ public class RecipeData
[JsonProperty("upkeep"), Key(5)]
public List<CommodityCount> Upkeep = new List<CommodityCount>();
// The kind of station that runs this recipe.
// The kind of station that runs this recipe: the kind whose Facilities list Facility. A checked mirror of Facility, no longer an
// owner; follow-up recipe-station-kind-derived deletes it once every reader reads the facility.
[JsonProperty("stationKind"), Key(6)]
public CultRecordRef<StationKindData> StationKind;
@ -52,6 +53,11 @@ public class RecipeData
[JsonProperty("roleInputs"), Key(9)]
public List<ItemRole> RoleInputs = new List<ItemRole>();
// The facility gear design that runs this recipe: a GearData of HardpointType Facility holding a FacilityData. Records written
// before key 10 read it unset.
[JsonProperty("facility"), Key(10)]
public CultRecordRef<ItemData> Facility;
public static CultRecordKey KeyOf(CultRecordKey outputKey) => new CultRecordKey("recipe:" + outputKey.Value);
}

View file

@ -23,6 +23,11 @@ public class StationKindData
[JsonProperty("standIns"), Key(2)]
public List<StationKindStandIn> StandIns = new List<StationKindStandIn>();
// The facility gear a station of this kind is fitted with (ruling installed-gear-decides-what-a-station-buys). Records written
// before key 3 read it empty.
[JsonProperty("facilities"), Key(3)]
public List<CultRecordRef<ItemData>> Facilities = new List<CultRecordRef<ItemData>>();
public static CultRecordKey KeyOf(string id) => new CultRecordKey("station-kind:" + id);
}
@ -98,7 +103,8 @@ public static class StationKinds
return standIn != null && standIn.Kind.IsSet() && OfferedKinds(catalog).Contains(standIn.Kind.Key.Value) ? standIn.Kind : default;
}
// What is wrong with a hull's kind, or null: a Station hull names a kind the catalog holds, and no other hull names one.
// What is wrong with a hull's station facts, or null: a Station hull names a kind the catalog holds, and no other hull names one
// or carries a Facility row.
// The one rule, applied to the catalog on Open and to each mod package on Compose.
public static string HullKindFault(CultCache catalog, HullData hull)
{
@ -109,8 +115,13 @@ public static class StationKinds
if (catalog.Get(hull.Kind) == null)
return $"Station hull '{hull.Name}' Kind names no station kind this catalog holds.";
}
else if (hull.Kind.IsSet())
return $"Hull '{hull.Name}' is a {hull.HullType} and names a Kind; only a station hull has one.";
else
{
if (hull.Kind.IsSet())
return $"Hull '{hull.Name}' is a {hull.HullType} and names a Kind; only a station hull has one.";
if (hull.Hardpoints.Any(hardpoint => hardpoint.Type == HardpointType.Facility))
return $"Hull '{hull.Name}' is a {hull.HullType} and has a Facility row; only a station hull takes facilities.";
}
return null;
}

View file

@ -32,6 +32,40 @@ public sealed class RecipeSchemaTests
Assert.Equal(4, counted.Count);
}
// A record keeps the slots it was written with: one cut short of a later key reads that member as it starts out.
private static byte[] CutShort(byte[] record, int slots)
{
var reader = new MessagePackReader(record);
var count = reader.ReadArrayHeader();
Assert.True(count > slots);
var start = reader.Consumed;
for (var i = 0; i < slots; i++) reader.Skip();
var writer = new System.Buffers.ArrayBufferWriter<byte>();
var write = new MessagePackWriter(writer);
write.WriteArrayHeader(slots);
write.Flush();
return writer.WrittenSpan.ToArray().Concat(record.Skip((int) start).Take((int) (reader.Consumed - start))).ToArray();
}
[Fact]
public void RecordsWrittenBeforeFacilityKeysReadUnsetAndEmpty()
{
var options = GameCult.Caching.MessagePack.CultDocumentMessagePackSerialization.OptionsFor(typeof(RecipeData).Assembly);
var item = new CultRecordRef<ItemData>(new CultRecordKey("gear:mill-works"));
var recipe = new RecipeData { Output = item, Facility = item };
var kind = new StationKindData { Name = "Mill", Facilities = new System.Collections.Generic.List<CultRecordRef<ItemData>> { item } };
var current = MessagePackSerializer.Deserialize<RecipeData>(MessagePackSerializer.Serialize(recipe, options), options);
Assert.Equal("gear:mill-works", current.Facility.Key.Value);
Assert.Equal("gear:mill-works", MessagePackSerializer.Deserialize<StationKindData>(MessagePackSerializer.Serialize(kind, options), options).Facilities.Single().Key.Value);
var oldRecipe = MessagePackSerializer.Deserialize<RecipeData>(CutShort(MessagePackSerializer.Serialize(recipe, options), 10), options);
Assert.False(oldRecipe.Facility.IsSet());
Assert.Equal("gear:mill-works", oldRecipe.Output.Key.Value);
var oldKind = MessagePackSerializer.Deserialize<StationKindData>(CutShort(MessagePackSerializer.Serialize(kind, options), 3), options);
Assert.Empty(oldKind.Facilities);
Assert.Equal("Mill", oldKind.Name);
}
[Fact]
public void RoleCountSurvivesTheStore()
{

View file

@ -287,7 +287,7 @@ public sealed class ShipAuthoringTests
[Theory]
[InlineData(HardpointType.Hull), InlineData(HardpointType.Tool), InlineData(HardpointType.Thermal), InlineData(HardpointType.WarpDrive),
InlineData(HardpointType.Reactor), InlineData(HardpointType.Shield), InlineData(HardpointType.Sensors),
InlineData(HardpointType.ControlModule)]
InlineData(HardpointType.ControlModule), InlineData(HardpointType.Facility)]
public void AnInternalHardpointCarriesNoAnchor(HardpointType type)
{
WithOnly(type).Validate();

View file

@ -176,6 +176,27 @@ public sealed class StationKindTests : IDisposable
Assert.Contains("only a station hull has one", turretWithKind);
}
// station-facilities-on-typed-mounts: only a station hull carries a Facility row.
[Fact]
public void OpenRefusesAFacilityRowOnAnythingButAStationHull()
{
HullData WithFacility(HullType type, CultRecordRef<StationKindData> kind = default)
{
var hull = Hull(type, kind);
hull.Hardpoints.Add(new HardpointData { Type = HardpointType.Facility, Position = new int2(0, 0), Shape = new Shape(2, 2), Transform = "Fa.1" });
return hull;
}
foreach (var type in new[] { HullType.Ship, HullType.Turret })
Assert.Contains("only a station hull takes facilities", OpenRefusal(cache => cache.Upsert(WithFacility(type))));
SeedAndReopen(cache =>
{
var kind = new CultRecordRef<StationKindData>(cache.Upsert(new StationKindData { Name = "Hub" }).Key);
cache.Upsert(WithFacility(HullType.Station, kind));
}, out var path);
using var opened = AetheriaStores.Open(path);
Assert.Contains(opened.GetAll<HullData>(), hull => hull.Hardpoints.Any(row => row.Type == HardpointType.Facility));
}
[Fact]
public void OpenRefusesBadStandIn()
{

View file

@ -50,7 +50,7 @@ HARDPOINT_MEMBERS = ("Type", "Position", "Shape", "Transform", "Rotation", "Armo
ANCHOR_MEMBERS = ("Id", "Role", "ModelNodeId", "ParentId", "Order")
# Enum member names in value order (HardpointType, ItemRotation, HullType).
HARDPOINT_TYPE_NAMES = ("Hull", "Tool", "Thermal", "Thruster", "WarpDrive", "Reactor", "Radiator",
"Shield", "Sensors", "Energy", "Ballistic", "Launcher", "ControlModule")
"Shield", "Sensors", "Energy", "Ballistic", "Launcher", "ControlModule", "Facility")
ROTATION_NAMES = ("None", "CounterClockwise", "Reversed", "Clockwise")
HULL_TYPE_NAMES = ("Ship", "Station", "Turret")

View file

@ -38,7 +38,8 @@ A row has all of `id`, `kind`, `cell`, `footprint`, `rotation`, `armor`, `arc`:
- `id` is the mount id the model's anchor binds to (`aetheria.id`); unique in the manifest.
- `kind` is one of `ship_cc.HARDPOINT_TYPE_NAMES` (Hull, Tool, Thermal, Thruster, WarpDrive, Reactor, Radiator, Shield, Sensors,
Energy, Ballistic, Launcher, ControlModule). The packager keeps no list of its own.
Energy, Ballistic, Launcher, ControlModule, Facility). The packager keeps no list of its own. A `Facility` row is internal (no
anchor, nothing on the model) and only a Station hull takes one.
- `cell` is `[x, y]`, whole numbers of at least 0: the footprint's lowest-x, lowest-y cell on the raster. `x` runs across, `y` from
the stern (0) toward the bow, as the layout panel shows it. Cells are in schematic space, not model space.
- `footprint` is rows of `#` (the mount's cells) and `.` separated by `/`, all one width, at least one `#`. The first row is the top