diff --git a/Assets/Scripts/ServerShared/ZoneGenerator.cs b/Assets/Scripts/ServerShared/ZoneGenerator.cs index 4a4cfcf9a..6597f8541 100644 --- a/Assets/Scripts/ServerShared/ZoneGenerator.cs +++ b/Assets/Scripts/ServerShared/ZoneGenerator.cs @@ -603,7 +603,8 @@ public static class ZoneGenerator upper *= 1 - 1e-6f; float AtLeast(GeneratorPlanet child, float edge) { - var m = WellMass(child); + // A bodyless node stands in for one body of its family's mass, which it becomes if its ring cannot stand + var m = child.Empty ? Family(child) : WellMass(child); var mInto = WellMass(into); return m <= 0 || mInto <= 0 ? edge : Math.Max(edge, 2 * CuspMargin * Roche(m) * Strength(mInto) / Strength(m)); } @@ -656,6 +657,9 @@ public static class ZoneGenerator if (ring.Count == 0) return; var heavy = ring.OrderByDescending(c => c.Mass).First(); var ringDistance = Math.Min(.5f * cap, share * reach / (GravityField.Beta * GravityField.Beta * (1 + GravityField.RingReach))); + PlaceChildren(node.Children.Where(c => !ring.Contains(c)).ToList(), + () => (1 + GravityField.RingReach) * ringDistance * GravityField.Beta, upper, heavy); + // The heavy member's mass is final only now (the outer children fold into it). if (ringDistance < RocheMargin * Roche(heavy.Mass)) { // The pair cannot keep its heavy member outside its Roche margin inside its node's reach: the node is one body. @@ -669,8 +673,6 @@ public static class ZoneGenerator member.Distance = ringDistance; chordCap[member] = .2f * 2 * ringDistance * sin(PI / ring.Count); } - PlaceChildren(node.Children.Where(c => !ring.Contains(c)).ToList(), - () => (1 + GravityField.RingReach) * ringDistance * GravityField.Beta, upper, heavy); } var queue = new Queue(); diff --git a/tests/Aetheria.Shared.Tests/ChildrenWithinReachTests.cs b/tests/Aetheria.Shared.Tests/ChildrenWithinReachTests.cs index a0d2b1408..9b40f5a44 100644 --- a/tests/Aetheria.Shared.Tests/ChildrenWithinReachTests.cs +++ b/tests/Aetheria.Shared.Tests/ChildrenWithinReachTests.cs @@ -231,6 +231,8 @@ public sealed class ChildrenWithinReachTests : IClassFixture("ZoneSettings"); var planetSettings = authored.Read("PlanetSettings"); + zoneSettings.RosetteProbability = 0; // a rosette or binary holds a bodyless node + zoneSettings.BinaryCreationProbability = 0; const float mass = 300000f; var trees = 0; var folded = 0; @@ -241,7 +243,7 @@ public sealed class ChildrenWithinReachTests : IClassFixture p.Empty || p.Ring) || wideTree.Any(p => p.Empty || p.Ring)) continue; + trees++; if (tightTree.Length < wideTree.Length) folded++; Assert.True(Math.Abs(tightTree.Sum(p => p.Mass) - mass) <= 1e-3f * mass, $"seed {seed}: a folded tree's bodies sum to {tightTree.Sum(p => p.Mass)}, not {mass}"); diff --git a/tests/Aetheria.Shared.Tests/RestoredHullsTests.cs b/tests/Aetheria.Shared.Tests/RestoredHullsTests.cs index d21051f0f..641c0d54a 100644 --- a/tests/Aetheria.Shared.Tests/RestoredHullsTests.cs +++ b/tests/Aetheria.Shared.Tests/RestoredHullsTests.cs @@ -500,11 +500,8 @@ public sealed class RestoredHullsTests var pack = ZoneGenerator.GenerateZone(items, zoneSettings, AuthoredPlanetSettings(), galaxy, galaxy.Entrance, isTutorial: true); - var roots = pack.Planets.Select(p => cache.Get(p).Orbit) - .Select(cache.Get) - .Select(o => o.Parent.IsSet() ? o.Parent.Key.Value : "(root)") - .Distinct().Count(); - Assert.True(roots > 1, $"this fixture no longer produces a multi-root entrance (only {roots} distinct parent); it no longer tests the fragmented-topology case."); + var roots = pack.Planets.Select(p => cache.Get(cache.Get(p).Orbit)).Count(o => !o.Parent.IsSet()); + Assert.True(roots > 1, $"this fixture no longer produces a multi-root entrance (only {roots} root); it no longer tests the fragmented-topology case."); var stations = pack.Entities.OfType() .Where(e => (cache.Get(e.Hull.Data) as HullData)?.HullType == HullType.Station).ToArray(); diff --git a/tests/Aetheria.Shared.Tests/StationPlacementTests.cs b/tests/Aetheria.Shared.Tests/StationPlacementTests.cs index e3333c1be..82f16e4ed 100644 --- a/tests/Aetheria.Shared.Tests/StationPlacementTests.cs +++ b/tests/Aetheria.Shared.Tests/StationPlacementTests.cs @@ -154,7 +154,7 @@ public sealed class StationPlacementTests : IDisposable { var t = k / 64.0 * longest; Assert.True(length(zone.OrbitPositionAt(entity.OrbitData, t) - zone.OrbitPositionAt(body.Orbit.Key, t)) >= margin * .999f, - $"seed {built.Seed}: an entity passes within {margin} of an unrelated body at instant {k}"); + $"seed {built.Seed}: a {TypeOf(built.Items, entity)} on a ring of {orbit.Data.Distance} passes within {margin} of an unrelated body (mass {body.Mass}, ring {bodyOrbit.Data.Distance}, same parent {bodyOrbit.Data.Parent.Key.Equals(orbit.Data.Parent.Key)}) at instant {k}"); } } }