ZoneGenerator: an overflow station seats on the root that asks the least of the zone, and the roots move apart to give its floor room

Ruling overflow-station-clears-root-first. The seat is a root with no massive child, else a bodyless node, else a root with children (most massive first, least spacing within a kind); outside the entrance a root with massive children takes the station beyond its massive children's ring group. The station's own orbit raises the root's support to Beta x its distance and its reach floor to Beta squared x it, so in a zone of two or more massive roots all roots move outward from the zone centre by the factor that keeps that floor within Reach x the nearest massive root's distance (root-window-floor).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-11-29 00:51:00 +01:00
commit c0229d4154

View file

@ -353,17 +353,46 @@ public static class ZoneGenerator
.Select(p => (orbit: orbitMap[p], extent: Extent(p), direct: false)).ToArray();
if (sources.Length < required)
{
// A station the rails cannot seat orbits a root node beyond its ring group (or, for a body, its whole family), never at
// a ring member's distance, and sits there, not at a Lagrange point. The shortfall shares the first one's phase
// (drawn once) spread evenly round the turn.
// A station the rails cannot seat orbits a root node, never at a ring member's distance and not at a Lagrange point (ruling
// overflow-station-clears-root-first). It seats where it adds the least to a family: a root with no massive child first, then a bodyless
// node, then a root with children, the most massive of each first, at its family's support or, with massive children, beyond
// their ring group ((1 + RingReach) x Beta x the innermost). Its own orbit raises that root's support to Beta x its distance and
// its reach floor to Beta squared x it, so in a zone of two or more massive roots the roots must lie far enough apart that the
// floor stays within Reach x the nearest massive root's distance (root-window-floor: subzones exactly isolated). Within the first kind that has a root, the one that
// asks the least spacing is the seat, the most massive on a tie; the zone's roots then move outward from its centre together
// by that factor, so the spacing reads the result. The shortfall shares the first one's phase (drawn once) spread evenly round the turn.
float FamilyMass(GeneratorPlanet n) => (n.Empty || n.Belt ? 0f : n.Mass) + n.Children.Sum(FamilyMass);
var roots = planets.Where(p => p.Parent == null).ToList();
var rootNode = roots.FirstOrDefault(p => p.Children.Count > 0) ?? (roots.Count > 1 ? roots.OrderByDescending(p => p.Mass).First() : null);
var massiveRoots = roots.Where(r => FamilyMass(r) > 0f).ToList();
float SeatDistance(GeneratorPlanet r) => r.Children.Any(Massive) && (r.Empty || galaxyZone != galaxy.Entrance)
? Math.Max(r.Empty ? 0f : Extent(r), (1 + GravityField.RingReach) * GravityField.Beta * r.Children.Where(Massive).Min(c => c.Distance))
: Extent(r);
// How far the roots must move apart for this root to take the station: 1 when it already clears.
float Spacing(GeneratorPlanet r)
{
if (massiveRoots.Count < 2 || !massiveRoots.Contains(r)) return 1f;
var nearest = massiveRoots.Where(o => o != r).Min(o => length(o.FixedPosition - r.FixedPosition));
return Math.Max(1f, GravityField.Beta * GravityField.Beta * SeatDistance(r) / (GravityField.Reach * nearest) * (1 + 1e-3f));
}
var seats = new[]
{
roots.Where(r => !r.Empty && !r.Children.Any(Massive)).ToList(),
roots.Where(r => r.Empty && r.Children.Any(Massive)).ToList(),
roots.Where(r => !r.Empty && r.Children.Any(Massive)).ToList(),
}.FirstOrDefault(kind => kind.Count > 0);
var rootNode = seats?.OrderBy(Spacing).ThenByDescending(FamilyMass).First();
if (rootNode == null)
throw new InvalidOperationException(
$"Zone {galaxyZone.Name} must seat all {required} of its dealt stations, but it has no candidate orbit at all -- every planet in the zone is a parentless root.");
var distance = rootNode.Empty
? (1 + GravityField.RingReach) * GravityField.Beta * rootNode.Children.Where(Massive).Min(c => c.Distance)
: Extent(rootNode);
var distance = SeatDistance(rootNode);
var spacing = Spacing(rootNode);
if (spacing > 1f)
foreach (var root in roots)
{
root.FixedPosition *= spacing;
orbitMap[root].FixedPosition = root.FixedPosition;
cache.Upsert(orbitMap[root]);
}
var shortfall = required - sources.Length;
var phase = random.NextFloat();
var withDirect = sources.ToList();