Station and belt kinds are seeded: the pick hashes the zone seed and the place in generation order, not a minted key

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-10-23 01:21:02 +02:00
commit 37a8110907
6 changed files with 54 additions and 40 deletions

View file

@ -52,10 +52,11 @@ public static class StationKinds
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
// A station's kind: a stable pick among the faction's kinds by the station's site, which generation names by the zone's
// seed and the station's place in its orbit order (never by a key the cache mints). 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)
public static CultRecordRef<StationKindData> Choose(CultCache catalog, Faction faction, string site, Action<string> log = null)
{
var pool = KindsOf(catalog, faction);
if (pool.Length == 0)
@ -68,7 +69,7 @@ public static class StationKinds
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)];
return pool[(int) (site.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
@ -82,22 +83,34 @@ public static class StationKinds
return standIn != null && standIn.Kind.IsSet() ? standIn.Kind : kind;
}
// 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.
// The one rule, applied to the catalog on Open and to each mod package on Compose.
public static string HullKindFault(CultCache catalog, HullData hull)
{
if (hull.HullType == HullType.Station)
{
if (!hull.Kind.IsSet())
return $"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)
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.";
return null;
}
// 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)
// does not stand on another stand-in for the same faction (one hop). A caller that gives kindlessStation is the owner
// of the catalog being repaired: a Station hull with no Kind is reported to it by name instead of refused.
public static void Validate(CultCache catalog, Action<string> kindlessStation = null)
{
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.");
var fault = HullKindFault(catalog, hull);
if (fault == null) continue;
if (kindlessStation != null && hull.HullType == HullType.Station && !hull.Kind.IsSet()) kindlessStation(fault);
else throw new InvalidOperationException(fault);
}
foreach (var kind in catalog.GetAll<StationKindData>())
{