Trojan swarms: a belt on a copy of its host's rail whose rocks ride the rail's period
Rulings trojans-first, trojans-ride-host-period-with-stations. AsteroidBeltData key 11 RidesRail; AsteroidBelt.Extent is the one belt extent rule (replaces Zone's inline farthest-rock loop and the Math.Max at the well node); a swarm's Periods are its rail's period. The generator draws swarms from a stream of its own (TrojanStream), so no other draw in the zone moves. Tuning defaults are the spec's proposals; the code default TrojanProbability 0 draws none. Existing annulus tests skip swarm rails. Builds. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
67517f407f
commit
92d6153c2e
7 changed files with 83 additions and 19 deletions
|
|
@ -79,11 +79,11 @@ public sealed class ChildrenWithinReachTests : IClassFixture<ChildrenWithinReach
|
|||
private static Dictionary<CultRecordKey, float> BodyMass(Zone zone) =>
|
||||
zone.Planets.Values.Where(b => !(b is AsteroidBeltData)).GroupBy(b => b.Orbit.Key).ToDictionary(g => g.Key, g => g.First().Mass);
|
||||
|
||||
// The generated orbits: every body's and its ancestors', which leaves out stations, turrets and Lagrange copies.
|
||||
// The generated orbits: every body's and its ancestors', which leaves out stations, turrets, Lagrange copies and swarm rails (a copy of the host's rail, like a Lagrange copy).
|
||||
private static HashSet<CultRecordKey> Placed(Zone zone)
|
||||
{
|
||||
var placed = new HashSet<CultRecordKey>();
|
||||
foreach (var body in zone.Planets.Values)
|
||||
foreach (var body in zone.Planets.Values.Where(b => !(b is AsteroidBeltData { RidesRail: true })))
|
||||
for (var key = body.Orbit.Key; placed.Add(key) && zone.Orbits[key].Data.Parent.IsSet();) key = zone.Orbits[key].Data.Parent.Key;
|
||||
return placed;
|
||||
}
|
||||
|
|
@ -332,7 +332,7 @@ public sealed class ChildrenWithinReachTests : IClassFixture<ChildrenWithinReach
|
|||
foreach (var (seed, zone) in _zones.All)
|
||||
{
|
||||
var mass = BodyMass(zone);
|
||||
foreach (var (beltKey, belt) in zone.AsteroidBelts)
|
||||
foreach (var (beltKey, belt) in zone.AsteroidBelts.Where(b => !b.Value.Data.RidesRail))
|
||||
{
|
||||
belts++;
|
||||
var orbit = zone.Planets[beltKey].Orbit.Key;
|
||||
|
|
@ -374,7 +374,7 @@ public sealed class ChildrenWithinReachTests : IClassFixture<ChildrenWithinReach
|
|||
{
|
||||
var mass = BodyMass(zone);
|
||||
var placed = Placed(zone);
|
||||
var beltAt = zone.AsteroidBelts.ToDictionary(b => zone.Planets[b.Key].Orbit.Key, b => b.Value.Data.Asteroids);
|
||||
var beltAt = zone.AsteroidBelts.Where(b => !b.Value.Data.RidesRail).ToDictionary(b => zone.Planets[b.Key].Orbit.Key, b => b.Value.Data.Asteroids);
|
||||
foreach (var (orbit, rocks) in beltAt)
|
||||
{
|
||||
var parent = zone.Orbits[orbit].Data.Parent.Key;
|
||||
|
|
@ -424,7 +424,7 @@ public sealed class ChildrenWithinReachTests : IClassFixture<ChildrenWithinReach
|
|||
{ Exponent = authored.Exponent, Multiplier = authored.Multiplier * .02f, Constant = authored.Constant * .02f });
|
||||
int belts = 0, filled = 0;
|
||||
foreach (var (seed, zone) in narrow.All)
|
||||
foreach (var (key, belt) in zone.AsteroidBelts)
|
||||
foreach (var (key, belt) in zone.AsteroidBelts.Where(b => !b.Value.Data.RidesRail))
|
||||
{
|
||||
var rocks = belt.Data.Asteroids;
|
||||
if (rocks.Length < 2) continue;
|
||||
|
|
|
|||
|
|
@ -81,6 +81,10 @@ public sealed class StationPlacementTests : IDisposable
|
|||
|
||||
private static float Turns(float turns) => turns - (float) Math.Floor(turns);
|
||||
|
||||
// A Trojan swarm's rail is a copy of its host's, not a station's source.
|
||||
private static bool SwarmRail(Zone zone, CultRecordKey orbit) =>
|
||||
zone.Planets.Values.Any(b => b is AsteroidBeltData { RidesRail: true } && b.Orbit.Key.Equals(orbit));
|
||||
|
||||
[Fact]
|
||||
public void AStationSitsAtItsPlanetsL4OrL5()
|
||||
{
|
||||
|
|
@ -96,7 +100,7 @@ public sealed class StationPlacementTests : IDisposable
|
|||
foreach (var station in zone.Entities.OfType<OrbitalEntity>().Where(e => TypeOf(built.Items, e) == HullType.Station))
|
||||
{
|
||||
var orbit = zone.Orbits[station.OrbitData];
|
||||
var sources = zone.Orbits.Where(o => !ridden.Contains(o.Key) && SameRing(o.Value, orbit)).ToList();
|
||||
var sources = zone.Orbits.Where(o => !ridden.Contains(o.Key) && !SwarmRail(zone, o.Key) && SameRing(o.Value, orbit)).ToList();
|
||||
if (sources.Count == 0)
|
||||
{
|
||||
// The tutorial entrance's one exception: a station on its own orbit round a root node, beyond the node's ring
|
||||
|
|
@ -156,7 +160,7 @@ public sealed class StationPlacementTests : IDisposable
|
|||
foreach (var station in Orbitals(built).Where(e => TypeOf(built.Items, e) == HullType.Station))
|
||||
{
|
||||
var orbit = zone.Orbits[station.OrbitData];
|
||||
var sources = zone.Orbits.Where(o => !ridden.Contains(o.Key) && SameRing(o.Value, orbit)).ToList();
|
||||
var sources = zone.Orbits.Where(o => !ridden.Contains(o.Key) && !SwarmRail(zone, o.Key) && SameRing(o.Value, orbit)).ToList();
|
||||
if (sources.Count == 0) continue; // the tutorial entrance's own orbit round a root
|
||||
stations++;
|
||||
Assert.Contains(bodyOrbits, key => key.Equals(sources[0].Key));
|
||||
|
|
@ -173,12 +177,12 @@ public sealed class StationPlacementTests : IDisposable
|
|||
var placed = new HashSet<CultRecordKey>();
|
||||
foreach (var body in zone.Planets.Values)
|
||||
for (var key = body.Orbit.Key; placed.Add(key) && zone.Orbits[key].Data.Parent.IsSet();) key = zone.Orbits[key].Data.Parent.Key;
|
||||
var beltExtent = zone.AsteroidBelts.ToDictionary(b => zone.Planets[b.Key].Orbit.Key, b => b.Value.Data.Asteroids.Select(a => a.Distance).DefaultIfEmpty(0f).Max());
|
||||
var beltExtent = zone.AsteroidBelts.ToDictionary(b => zone.Planets[b.Key].Orbit.Key, b => b.Value.Extent(zone.Orbits[zone.Planets[b.Key].Orbit.Key].Data.Distance));
|
||||
var nodes = placed.Select(k =>
|
||||
{
|
||||
var d = zone.Orbits[k].Data;
|
||||
return new WellNode(k, d.Parent.Key, d.Distance, d.Phase, mass.TryGetValue(k, out var m) ? m : 0f,
|
||||
beltExtent.TryGetValue(k, out var e) ? Math.Max(e, d.Distance) : d.Distance, d.FixedPosition + OrbitData.Evaluate(frac(d.Phase)) * d.Distance);
|
||||
beltExtent.TryGetValue(k, out var e) ? e : d.Distance, d.FixedPosition + OrbitData.Evaluate(frac(d.Phase)) * d.Distance);
|
||||
}).ToList();
|
||||
var wells = WellTree.Build(nodes, zone.Settings, zone.Pack.Radius);
|
||||
return Math.Max(wells.Support(orbit), 1.5f * zone.Settings.RocheLimit.Evaluate(mass[orbit]));
|
||||
|
|
@ -353,7 +357,7 @@ public sealed class StationPlacementTests : IDisposable
|
|||
foreach (var station in Orbitals(built).Where(e => TypeOf(built.Items, e) == HullType.Station))
|
||||
{
|
||||
var orbit = zone.Orbits[station.OrbitData];
|
||||
var strays = zone.Orbits.Count(o => !ridden.Contains(o.Key) && SameRing(o.Value, orbit));
|
||||
var strays = zone.Orbits.Count(o => !ridden.Contains(o.Key) && !SwarmRail(zone, o.Key) && SameRing(o.Value, orbit));
|
||||
Assert.True(strays == 1, $"seed {built.Seed}: a station's ring holds {strays} orbits no entity rides, not just its source's");
|
||||
stations++;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue