Station kinds: StationKindData catalog list, HullData.Kind, placed station Kind; GenerateStationLoadout takes a kind (the kindless draw is deleted)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
00e60344ab
commit
fba7bd1b47
17 changed files with 700 additions and 24 deletions
|
|
@ -7,7 +7,7 @@ using GameCult.Caching.MessagePack;
|
|||
// Aetheria's stores: one home store per type, composed here and nowhere else.
|
||||
public static class AetheriaStores
|
||||
{
|
||||
public static readonly Type[] CatalogTypes = { typeof(ItemData), typeof(ShipAuthoring), typeof(Faction), typeof(FactionProductData), typeof(PersonalityAttribute), typeof(InputLayout), typeof(Loadout), typeof(FieldKindData), typeof(VerseGrammar), typeof(VerseVerb) };
|
||||
public static readonly Type[] CatalogTypes = { typeof(ItemData), typeof(ShipAuthoring), typeof(Faction), typeof(FactionProductData), typeof(PersonalityAttribute), typeof(InputLayout), typeof(Loadout), typeof(FieldKindData), typeof(VerseGrammar), typeof(VerseVerb), typeof(StationKindData) };
|
||||
public static readonly Type[] RunTypes = { typeof(OrbitData), typeof(BodyData), typeof(SavedZone), typeof(SavedGame), typeof(ProvenanceLedger) };
|
||||
public static readonly Type[] PlayerTypes = { typeof(PlayerSettings) };
|
||||
|
||||
|
|
@ -42,6 +42,7 @@ public static class AetheriaStores
|
|||
foreach (var data in cache.GetAll<ConsumableItemData>()) CultRecordRefs.Validate(data);
|
||||
VerseGrammarValidation.ValidateAll(cache.GetAll<VerseVerb>());
|
||||
ValidateBins(cache);
|
||||
StationKinds.Validate(cache);
|
||||
return cache;
|
||||
}
|
||||
catch
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@ public static class EntitySerializer
|
|||
{
|
||||
Orbit = new CultRecordRef<OrbitData>(orbital.OrbitData),
|
||||
SecurityLevel = orbital.SecurityLevel,
|
||||
SecurityRadius = orbital.SecurityRadius
|
||||
SecurityRadius = orbital.SecurityRadius,
|
||||
Kind = orbital.Kind
|
||||
};
|
||||
else if (entity is Ship ship)
|
||||
pack = new ShipPack
|
||||
|
|
@ -120,6 +121,7 @@ public static class EntitySerializer
|
|||
Restore(itemManager, zone, pack, entity);
|
||||
entity.SecurityLevel = pack.SecurityLevel;
|
||||
entity.SecurityRadius = pack.SecurityRadius;
|
||||
entity.Kind = pack.Kind;
|
||||
if (pack.Story >= 0) entity.Story = zone.GalaxyZone.Locations[pack.Story];
|
||||
return entity;
|
||||
}
|
||||
|
|
@ -214,6 +216,7 @@ public class OrbitalEntityPack : EntityPack
|
|||
[Key(18)] public int Story = -1;
|
||||
[Key(19)] public SecurityLevel SecurityLevel;
|
||||
[Key(20)] public float SecurityRadius;
|
||||
[Key(22)] public CultRecordRef<StationKindData> Kind;
|
||||
}
|
||||
|
||||
[MessagePackObject,
|
||||
|
|
@ -237,7 +240,7 @@ public abstract class EntityPack
|
|||
[Key(14)] public EntitySettings Settings;
|
||||
[Key(15)] public CultRecordRef<Faction> Faction;
|
||||
[Key(16)] public int[][] WeaponGroups;
|
||||
// Keys 17-20 belong to the subclasses; the base's next free key is 21.
|
||||
// Keys 17-20 belong to the subclasses; the base's next free key is 23 (Boss is 21, the orbital pack's Kind is 22).
|
||||
[Key(21)] public bool Boss;
|
||||
|
||||
private int _price;
|
||||
|
|
|
|||
|
|
@ -549,6 +549,12 @@ public class HullData : EquippableItemData
|
|||
[Inspectable, JsonProperty("visual"), Key(32)]
|
||||
public CultRecordRef<ShipAuthoring> Visual;
|
||||
|
||||
// What a station hull is built to be (StationKinds): set on every Station hull and on no other. The hull names its kind
|
||||
// and the kind names no hull, so a package can add a faction's model of a kind without editing any kind record.
|
||||
// Key 33 is the next free key.
|
||||
[Inspectable, JsonProperty("kind"), Key(33)]
|
||||
public CultRecordRef<StationKindData> Kind;
|
||||
|
||||
// The farthest corner of any occupied hull cell from the centre of mass the schematic frame uses, in world
|
||||
// units: a true bound on how far the hull reaches from its position (the half-diagonal of the bounding box is not,
|
||||
// as FireControl.Detonate's comment records). A cell at (x, y) spans x +/- .5 and y +/- .5.
|
||||
|
|
|
|||
|
|
@ -74,9 +74,12 @@ public class LoadoutGenerator
|
|||
return EntitySerializer.Pack(entity) as OrbitalEntityPack;
|
||||
}
|
||||
|
||||
public OrbitalEntityPack GenerateStationLoadout()
|
||||
// A station of one kind: the hull is drawn among the station hulls the kind calls for in this faction's hands
|
||||
// (StationKinds.HullKindFor), so a faction with no model of the kind builds its stand-in's hull and keeps the kind.
|
||||
public OrbitalEntityPack GenerateStationLoadout(CultRecordRef<StationKindData> kind)
|
||||
{
|
||||
var (hullProduct, hullData) = RandomHull(HullType.Station);
|
||||
var hullKind = StationKinds.HullKindFor(ItemManager.ItemData, Faction, kind);
|
||||
var (hullProduct, hullData) = RandomHull(HullType.Station, hull => hull.Kind.Key.Equals(hullKind.Key));
|
||||
if(hullData==null)
|
||||
{
|
||||
ItemManager.Log("Unable to generate station loadout: no compatible hull found!");
|
||||
|
|
@ -85,6 +88,9 @@ public class LoadoutGenerator
|
|||
var hull = ItemManager.CreateInstance(hullProduct) as EquippableItem;
|
||||
var entity = new OrbitalEntity(ItemManager, null, hull, default, ItemManager.GameplaySettings.DefaultEntitySettings);
|
||||
entity.Faction = Faction;
|
||||
entity.Kind = kind;
|
||||
// A stand-in hull keeps its own model but not its own name: the station is what its kind says it is.
|
||||
if (!hullData.Kind.Key.Equals(kind.Key) && ItemManager.ItemData.Get(kind) is { } kindData) entity.Name = kindData.Name;
|
||||
|
||||
// Hardpoint gear goes in first so the docking bay can only take space that gear left free
|
||||
EquipHardpoints(entity);
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ public class OrbitalEntity : Entity
|
|||
public float SecurityRadius;
|
||||
public LocationStory Story;
|
||||
public bool CanTow;
|
||||
// What this station is for (StationKinds): its own fact, which under a stand-in hull differs from the hull's kind.
|
||||
public CultRecordRef<StationKindData> Kind;
|
||||
|
||||
public OrbitalEntity(ItemManager itemManager, Zone zone, EquippableItem hull, CultRecordKey orbit, EntitySettings settings) : base(itemManager, zone, hull, settings)
|
||||
{
|
||||
|
|
|
|||
128
Assets/Scripts/ServerShared/StationKinds.cs
Normal file
128
Assets/Scripts/ServerShared/StationKinds.cs
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameCult.Caching;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
// What a station is for: one authored catalog record per kind (mining, trade-hub, shipyard...). The catalog's list of
|
||||
// these records is the one list of station kinds. A kind names no hull: the hull names its kind (HullData.Kind), and
|
||||
// which hull a faction builds for a kind is derived from the products that faction makes (StationKinds), so a package can
|
||||
// add a faction's model of a kind without editing any kind record. Records are keyed station-kind:<id>.
|
||||
[CultDocument("aetheria.stationkinddata", "1"), MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class StationKindData
|
||||
{
|
||||
[CultName, JsonProperty("name"), Key(0)]
|
||||
public string Name = "";
|
||||
|
||||
[JsonProperty("description"), Key(1)]
|
||||
public string Description = "";
|
||||
|
||||
// A faction with no model of this kind builds the stand-in's hull and the station stays this kind. Ignored once the
|
||||
// faction offers a model of this kind.
|
||||
[JsonProperty("standIns"), Key(2)]
|
||||
public List<StationKindStandIn> StandIns = new List<StationKindStandIn>();
|
||||
|
||||
public static CultRecordKey KeyOf(string id) => new CultRecordKey("station-kind:" + id);
|
||||
}
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class StationKindStandIn
|
||||
{
|
||||
[JsonProperty("faction"), Key(0)]
|
||||
public CultRecordRef<Faction> Faction;
|
||||
|
||||
// The kind whose model this faction builds in place of the owning kind's.
|
||||
[JsonProperty("kind"), Key(1)]
|
||||
public CultRecordRef<StationKindData> Kind;
|
||||
}
|
||||
|
||||
// The one owner of which kinds a faction builds, which kind a station gets, and which hull kind stands in.
|
||||
public static class StationKinds
|
||||
{
|
||||
// The kinds this faction can place: those of the station hulls its products offer, and those that stand in for it.
|
||||
// Ordered by key so a choice never depends on store order. Empty for no faction.
|
||||
public static CultRecordRef<StationKindData>[] KindsOf(CultCache catalog, Faction faction)
|
||||
{
|
||||
if (faction == null) return Array.Empty<CultRecordRef<StationKindData>>();
|
||||
var kinds = new HashSet<string>(OfferedStationHulls(catalog, faction).Select(hull => hull.Kind.Key.Value), StringComparer.Ordinal);
|
||||
foreach (var kind in catalog.GetAll<StationKindData>())
|
||||
if (kind.StandIns.Any(standIn => catalog.Get(standIn.Faction) == faction))
|
||||
kinds.Add(catalog.RefOf(kind).Key.Value);
|
||||
return Ordered(kinds);
|
||||
}
|
||||
|
||||
// A station's kind: a stable pick among the faction's kinds by the station's site key. It draws nothing from any random
|
||||
// stream, so adding the kind to generation moves no other roll. A faction with no kinds falls back to any kind some
|
||||
// offered station hull carries, logged, and the hull draw then falls back to any maker. Unset when the catalog has none.
|
||||
public static CultRecordRef<StationKindData> Choose(CultCache catalog, Faction faction, CultRecordKey siteKey, Action<string> log = null)
|
||||
{
|
||||
var pool = KindsOf(catalog, faction);
|
||||
if (pool.Length == 0)
|
||||
{
|
||||
pool = Ordered(new HashSet<string>(
|
||||
catalog.GetAll<FactionProductData>().Where(product => LoadoutGenerator.IsOffered(catalog, product))
|
||||
.Select(product => catalog.Get(product.Design) as HullData)
|
||||
.Where(hull => hull != null && hull.HullType == HullType.Station && hull.Kind.IsSet())
|
||||
.Select(hull => hull.Kind.Key.Value), StringComparer.Ordinal));
|
||||
if (pool.Length == 0) return default;
|
||||
log?.Invoke($"{faction?.Name ?? "This galaxy"} builds no station kind; placing a station of any kind some maker offers.");
|
||||
}
|
||||
return pool[(int) (siteKey.Value.StableHash() % (uint) pool.Length)];
|
||||
}
|
||||
|
||||
// The kind of hull a faction builds for a station kind: the kind itself when the faction offers a model of it (a model
|
||||
// wins over a stale stand-in), else the kind its stand-in names, else the kind itself (the hull draw then falls back to
|
||||
// any maker).
|
||||
public static CultRecordRef<StationKindData> HullKindFor(CultCache catalog, Faction faction, CultRecordRef<StationKindData> kind)
|
||||
{
|
||||
if (!kind.IsSet() || faction == null) return kind;
|
||||
if (OfferedStationHulls(catalog, faction).Any(hull => hull.Kind.Key.Equals(kind.Key))) return kind;
|
||||
var standIn = catalog.Get(kind)?.StandIns.FirstOrDefault(entry => catalog.Get(entry.Faction) == faction);
|
||||
return standIn != null && standIn.Kind.IsSet() ? standIn.Kind : kind;
|
||||
}
|
||||
|
||||
// Open refuses a malformed kind catalog, naming the record and field. Every Station hull names a kind the catalog holds
|
||||
// and no other hull names one; every stand-in names a faction and a kind the catalog holds, is never its own kind, and
|
||||
// does not stand on another stand-in for the same faction (one hop).
|
||||
public static void Validate(CultCache catalog)
|
||||
{
|
||||
foreach (var hull in catalog.GetAll<HullData>())
|
||||
{
|
||||
if (hull.HullType == HullType.Station)
|
||||
{
|
||||
if (!hull.Kind.IsSet())
|
||||
throw new InvalidOperationException($"Station hull '{hull.Name}' has no Kind; a station hull names the station kind it is built to be.");
|
||||
if (catalog.Get(hull.Kind) == null)
|
||||
throw new InvalidOperationException($"Station hull '{hull.Name}' Kind names no station kind this catalog holds.");
|
||||
}
|
||||
else if (hull.Kind.IsSet())
|
||||
throw new InvalidOperationException($"Hull '{hull.Name}' is a {hull.HullType} and names a Kind; only a station hull has one.");
|
||||
}
|
||||
foreach (var kind in catalog.GetAll<StationKindData>())
|
||||
{
|
||||
var self = catalog.RefOf(kind).Key;
|
||||
for (var i = 0; i < kind.StandIns.Count; i++)
|
||||
{
|
||||
var entry = kind.StandIns[i];
|
||||
var at = $"Station kind '{kind.Name}' StandIns[{i}]";
|
||||
var faction = catalog.Get(entry.Faction);
|
||||
if (faction == null) throw new InvalidOperationException($"{at}.Faction names no faction this catalog holds.");
|
||||
var other = catalog.Get(entry.Kind);
|
||||
if (other == null) throw new InvalidOperationException($"{at}.Kind names no station kind this catalog holds.");
|
||||
if (entry.Kind.Key.Equals(self)) throw new InvalidOperationException($"{at}.Kind is the kind itself; a kind cannot stand in for itself.");
|
||||
if (other.StandIns.Any(next => catalog.Get(next.Faction) == faction))
|
||||
throw new InvalidOperationException($"{at}.Kind stands in for the same faction itself; a stand-in is one hop.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<HullData> OfferedStationHulls(CultCache catalog, Faction faction) =>
|
||||
catalog.GetAll<FactionProductData>()
|
||||
.Where(product => LoadoutGenerator.IsOffered(catalog, product) && catalog.Get(product.Manufacturer) == faction)
|
||||
.Select(product => catalog.Get(product.Design) as HullData)
|
||||
.Where(hull => hull != null && hull.HullType == HullType.Station && hull.Kind.IsSet());
|
||||
|
||||
private static CultRecordRef<StationKindData>[] Ordered(IEnumerable<string> keys) =>
|
||||
keys.OrderBy(key => key, StringComparer.Ordinal).Select(key => new CultRecordRef<StationKindData>(new CultRecordKey(key))).ToArray();
|
||||
}
|
||||
11
Assets/Scripts/ServerShared/StationKinds.cs.meta
Normal file
11
Assets/Scripts/ServerShared/StationKinds.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7b3e1a94c2d84f6e9a05d1c8e4f27b63
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -419,7 +419,8 @@ public static class ZoneGenerator
|
|||
if (i >= selectedStationOrbits.Length) { itemManager.Log($"Story station for {story.Faction?.Name} has no rail clear of the bodies; its story has nowhere to live!"); continue; }
|
||||
var orbit = selectedStationOrbits[i];
|
||||
var lagrangeOrbit = CreateLagrangeOrbit(orbit);
|
||||
var station = GetLoadoutGenerator(story.Faction).GenerateStationLoadout();
|
||||
var station = GetLoadoutGenerator(story.Faction).GenerateStationLoadout(
|
||||
StationKinds.Choose(cache, story.Faction, cache.RefOf(lagrangeOrbit).Key, itemManager.Log));
|
||||
if (station == null)
|
||||
{
|
||||
itemManager.Log($"Story station for {story.Faction?.Name} could not be generated; its story has nowhere to live!");
|
||||
|
|
@ -440,7 +441,8 @@ public static class ZoneGenerator
|
|||
var security = (SecurityLevel) ((int) ((1f - pow(random.NextFloat(), factionPresence / 2f)) * 3f));
|
||||
|
||||
var lagrangeOrbit = CreateLagrangeOrbit(orbit);
|
||||
var station = GetLoadoutGenerator(nearestFaction).GenerateStationLoadout();
|
||||
var station = GetLoadoutGenerator(nearestFaction).GenerateStationLoadout(
|
||||
StationKinds.Choose(cache, nearestFaction, cache.RefOf(lagrangeOrbit).Key, itemManager.Log));
|
||||
if (station == null)
|
||||
{
|
||||
if (isTutorialEntrance)
|
||||
|
|
|
|||
Loading…
Reference in a new issue