From 051bf201cd0314e3fc130bb50e42c69e3e77be88 Mon Sep 17 00:00:00 2001 From: soul Date: Sun, 29 Nov 2026 10:32:54 +0100 Subject: [PATCH] Zone.Wormholes owns where wormholes are; the ratio moves to GameplaySettings The renderer derived wormhole positions from GameSettings.WormholeDistanceRatio and the player's exit read them back from its instances. Zone.Wormholes (and WormholeTo) now derive them from GameplaySettings.WormholeDistanceRatio, which Settings.asset carries under GameplaySettings (0.75, unchanged); ZoneRenderer draws what the zone says. WormholesAreTheZones pins the positions, the exit gate included. Co-Authored-By: Claude Sonnet 5.5 --- Assets/Resources/Settings.asset | 4 +- Assets/Scripts/Gameplay/ActionGameManager.cs | 2 +- Assets/Scripts/Gameplay/GameSettings.cs | 1 - Assets/Scripts/ServerShared/Settings.cs | 2 + Assets/Scripts/ServerShared/Zone.cs | 19 +++++++++ Assets/Scripts/Zone Display/ZoneRenderer.cs | 22 +--------- tests/Aetheria.Shared.Tests/RunGoalTests.cs | 44 ++++++++++++++++---- 7 files changed, 63 insertions(+), 31 deletions(-) diff --git a/Assets/Resources/Settings.asset b/Assets/Resources/Settings.asset index e8b979ab6..9f35df950 100644 --- a/Assets/Resources/Settings.asset +++ b/Assets/Resources/Settings.asset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:31254278cae0f0e18aebd8c29c84a71e68b85b5975a28d32672299d6bc459391 -size 13821 +oid sha256:ff18e9bdf194e6e38f309d39e06266fabd1cf6bc0a9ef026153972338efc8e92 +size 13823 diff --git a/Assets/Scripts/Gameplay/ActionGameManager.cs b/Assets/Scripts/Gameplay/ActionGameManager.cs index 3bcc6b2a4..c64e6bb2e 100644 --- a/Assets/Scripts/Gameplay/ActionGameManager.cs +++ b/Assets/Scripts/Gameplay/ActionGameManager.cs @@ -831,7 +831,7 @@ public class ActionGameManager : MonoBehaviour foreach (var zone in wormhole.Target.AdjacentZones) CurrentGalaxy.DiscoveredZones.Add(zone); SectorMap.QueueZoneReveal(wormhole.Target.AdjacentZones); - ship.ExitWormhole(ZoneRenderer.WormholeInstances.Keys.First(w => w.Target == oldZone.GalaxyZone).Position, + ship.ExitWormhole(Zone.WormholeTo(oldZone.GalaxyZone), Settings.GameplaySettings.WormholeExitVelocity * ItemManager.Random.NextFloat2Direction()); CurrentEntity.Zone = Zone; SaveRun(); diff --git a/Assets/Scripts/Gameplay/GameSettings.cs b/Assets/Scripts/Gameplay/GameSettings.cs index d3cac605e..5a693464a 100644 --- a/Assets/Scripts/Gameplay/GameSettings.cs +++ b/Assets/Scripts/Gameplay/GameSettings.cs @@ -13,7 +13,6 @@ public class GameSettings : ScriptableObject public string StartingHullName = "Longinus"; public float HeatstrokePhasingFloor = 0; public float HeatstrokePhasingFrequency = 5; - public float WormholeDistanceRatio; // The follow camera's distance from the hull's centre of mass, as a multiple of the hull's reach // (Contacts.Radius); 1.5 keeps the Longinus at about 30 m. public float FollowCameraDistancePerReach = 1.5f; diff --git a/Assets/Scripts/ServerShared/Settings.cs b/Assets/Scripts/ServerShared/Settings.cs index 450f07048..19cf75bc8 100644 --- a/Assets/Scripts/ServerShared/Settings.cs +++ b/Assets/Scripts/ServerShared/Settings.cs @@ -226,6 +226,8 @@ public class GameplaySettings public float WormholeDepth = 1000; public float WormholeExitVelocity = 20; public float WormholeExitRadius = 50; + // Wormholes sit at the zone's radius times this (Zone.Wormholes, the one owner of where they are). + public float WormholeDistanceRatio = .75f; public float WormholeAnimationDuration = 4; public float WormholeExitCurveStart = .8f; public float ThermalWearExponent = .01f; diff --git a/Assets/Scripts/ServerShared/Zone.cs b/Assets/Scripts/ServerShared/Zone.cs index 7514a9f9c..5bf7d2bfe 100644 --- a/Assets/Scripts/ServerShared/Zone.cs +++ b/Assets/Scripts/ServerShared/Zone.cs @@ -124,6 +124,25 @@ public class Zone public GalaxyZone GalaxyZone { get; } public Galaxy Galaxy { get; } + // The zone's wormholes, the one owner of where they are: one toward each adjacent zone at the zone's radius times + // GameplaySettings.WormholeDistanceRatio, then, in the galaxy's exit zone, the run's exit gate (presentation only: whether it + // opens is RunGoal.ExitOpen, read when it is used). Plain data derived on every call, stored nowhere; none without a GalaxyZone. + public IEnumerable Wormholes + { + get + { + if (GalaxyZone == null) yield break; + var ratio = _itemManager.GameplaySettings.WormholeDistanceRatio; + foreach (var adjacent in GalaxyZone.AdjacentZones) + yield return new Wormhole { Target = adjacent, Position = normalize(adjacent.Position - GalaxyZone.Position) * Pack.Radius * ratio }; + if (GalaxyZone == Galaxy.Exit) + yield return new Wormhole { Exit = true, Position = RunGoal.ExitGatePosition(this, ratio) }; + } + } + + // Where this zone's wormhole to `target` sits. + public float2 WormholeTo(GalaxyZone target) => Wormholes.First(wormhole => wormhole.Target == target).Position; + // Cut 6b (docs/fire-control-cut.md, 6.1, Soul finding 6): one zone, one stable identity -- a galaxy seed // reproduces it, and nothing else in the zone (an NPC joining, a shop opening, a wormhole exit) can // perturb it. FireControl.Commit builds its own local generator from this and the shot's own id instead diff --git a/Assets/Scripts/Zone Display/ZoneRenderer.cs b/Assets/Scripts/Zone Display/ZoneRenderer.cs index 384469060..b893828a4 100644 --- a/Assets/Scripts/Zone Display/ZoneRenderer.cs +++ b/Assets/Scripts/Zone Display/ZoneRenderer.cs @@ -283,26 +283,8 @@ public class ZoneRenderer : MonoBehaviour if (_clouds.Remove(e.Value, out var instance)) Destroy(instance.gameObject); })); - if (zone.GalaxyZone != null) - { - foreach (var adjacentZone in zone.GalaxyZone.AdjacentZones) - { - var dir = normalize(adjacentZone.Position - zone.GalaxyZone.Position); - AddWormhole(new Wormhole - { - Target = adjacentZone, - Position = dir * zone.Pack.Radius * Settings.WormholeDistanceRatio - }); - } - - // The run's exit gate is presentation only: whether it opens is RunGoal.ExitOpen, read when it is used. - if (zone.GalaxyZone == zone.Galaxy.Exit) - AddWormhole(new Wormhole - { - Exit = true, - Position = RunGoal.ExitGatePosition(zone, Settings.WormholeDistanceRatio) - }); - } + // The renderer draws wormholes; Zone.Wormholes decides where they are. + foreach (var wormhole in zone.Wormholes) AddWormhole(wormhole); } private void LoadMine(Zone zone, Mine mine) diff --git a/tests/Aetheria.Shared.Tests/RunGoalTests.cs b/tests/Aetheria.Shared.Tests/RunGoalTests.cs index dd58c5133..57af0f4b4 100644 --- a/tests/Aetheria.Shared.Tests/RunGoalTests.cs +++ b/tests/Aetheria.Shared.Tests/RunGoalTests.cs @@ -566,19 +566,49 @@ public sealed partial class RunStartTests [Fact] public void Exit_gate_shares_no_point_with_a_wormhole() { - var ratio = float.Parse(File.ReadLines(Path.Combine(FindRepoRoot(), "Assets", "Resources", "Settings.asset")) - .Select(line => Regex.Match(line, @"^ WormholeDistanceRatio: (.+)$")).First(match => match.Success).Groups[1].Value.Trim(), - System.Globalization.CultureInfo.InvariantCulture); - var reach = AuthoredSettings.Load(FindRepoRoot()).Read("GameplaySettings").WormholeExitRadius; + var gameplay = AuthoredSettings.Load(FindRepoRoot()).Read("GameplaySettings"); + var ratio = gameplay.WormholeDistanceRatio; + var reach = gameplay.WormholeExitRadius; foreach (var seed in DemoSeeds) { var galaxy = DemoGalaxy(seed); var zone = ZoneOf(galaxy, galaxy.Exit); var gate = RunGoal.ExitGatePosition(zone, ratio); - foreach (var adjacent in galaxy.Exit.AdjacentZones) + foreach (var wormhole in zone.Wormholes.Where(wormhole => !wormhole.Exit)) + Assert.True(math.length(gate - wormhole.Position) > 2 * reach, $"seed {seed}: the exit gate sits {math.length(gate - wormhole.Position)} from a wormhole"); + } + } + + // Zone.Wormholes is where the zones' wormholes are: toward each adjacent zone at the zone's radius times the authored ratio, + // and the exit gate in the exit zone only. The expected positions are written out here from the geometry, position for position. + [Fact] + public void WormholesAreTheZones() + { + var ratio = AuthoredSettings.Load(FindRepoRoot()).Read("GameplaySettings").WormholeDistanceRatio; + Assert.Equal(.75f, ratio); + foreach (var seed in DemoSeeds) + { + var galaxy = DemoGalaxy(seed); + foreach (var galaxyZone in new[] { galaxy.Entrance, galaxy.Exit }) { - var wormhole = math.normalize(adjacent.Position - galaxy.Exit.Position) * zone.Pack.Radius * ratio; - Assert.True(math.length(gate - wormhole) > 2 * reach, $"seed {seed}: the exit gate sits {math.length(gate - wormhole)} from a wormhole"); + var zone = ZoneOf(galaxy, galaxyZone); + var expected = galaxyZone.AdjacentZones + .Select(adjacent => (adjacent, position: math.normalize(adjacent.Position - galaxyZone.Position) * zone.Pack.Radius * ratio)).ToList(); + var actual = zone.Wormholes.ToList(); + Assert.Equal(expected.Count + (galaxyZone == galaxy.Exit ? 1 : 0), actual.Count); + for (var i = 0; i < expected.Count; i++) + { + Assert.Same(expected[i].adjacent, actual[i].Target); + Assert.Equal(expected[i].position, actual[i].Position); + Assert.Equal(expected[i].position, zone.WormholeTo(expected[i].adjacent)); + Assert.False(actual[i].Exit); + } + if (galaxyZone == galaxy.Exit) + { + Assert.True(actual[^1].Exit); + Assert.Null(actual[^1].Target); + Assert.Equal(RunGoal.ExitGatePosition(zone, ratio), actual[^1].Position); + } } } }