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 <noreply@anthropic.com>
This commit is contained in:
soul 2026-11-29 10:32:54 +01:00
commit 051bf201cd
7 changed files with 63 additions and 31 deletions

BIN
Assets/Resources/Settings.asset (Stored with Git LFS)

Binary file not shown.

View file

@ -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();

View file

@ -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;

View file

@ -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;

View file

@ -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<Wormhole> 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

View file

@ -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)

View file

@ -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>("GameplaySettings").WormholeExitRadius;
var gameplay = AuthoredSettings.Load(FindRepoRoot()).Read<GameplaySettings>("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>("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);
}
}
}
}