From 4217394cc25d23809d99b5022012993a864e463f Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 16 Jun 2026 16:57:18 +0100 Subject: [PATCH] Carry typed orbit keys through zone construction --- .voidbot/state/aetheria.cc | Bin 185404 -> 186189 bytes Aetheria.State.Verify/Program.cs | 102 +++++++++++++++++- Aetheria.State/README.md | 2 +- Assets/Scripts/ServerShared/Zone.cs | 20 ++-- .../ServerShared/ZoneConstructionData.cs | 8 ++ Assets/Scripts/ServerShared/ZoneGenerator.cs | 22 +++- 6 files changed, 136 insertions(+), 18 deletions(-) diff --git a/.voidbot/state/aetheria.cc b/.voidbot/state/aetheria.cc index 1c61547d4b99f4009e2d58dcb6bf26dfe5c75a35..bfbb96a2954d354c9bd31a080ae3fd7160225571 100644 GIT binary patch delta 1764 zcmb7F&ud&o9A{oaf2D^sZLp=4d<78;$>vu#X^Pr34TMneM{5!GqVwLH-8baz%*)KY zUALD-ig*#EtYp%Fc+l2>B8rDx1X~YkTLeAEe?dHWSMWRYcGK0+gQtDWerLX)U-O-B zw}*cIa_FnO!J+cph4T5*x#`ZI15epEe+mwC9tH0nDOTrZW-7PHXh#m*=&sDqP5G5W zgJZ#u!#B?k?wlPY!ymMNBSRG_7(`NNqw>gbDL}DEs#t@NO^B#cEnshFDUY}T)5=&3 zOEPXFDhbql`1AoZw;!PrLiu7Yp}uuQ`ATWnauK(8m7S{tX+p@!i4*T zFwI$}xG=yqgi?udaEH3xlPVX6*BLYw%`&F6$D8AVNu*}5##$OUGGH_YSw#Y2&eNES z8uWJ397`29EvPD4hm_T5)PlBj1YqU*>N0Ms>e8JkrM$lT;p+%U=c>UQ?vQS^FDqDK zH;?RcpKi<4P(TU1Zkdt|Ca8#*XHnbZA4<8l##n~ujze2W)D(O5>px-SL=Sd~)p-W8 ziSm`U*K?+wL%Vn0NO+VWWQ~#*9lSFW+Mu++>zPyrGHMbHxFby=!&;^qtjEO@pKOQd zWMLEtT1QjRAxCpUC)7FJN5dr4U>t;}7dpsk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0e6gG!L|C>-nFe-P{s^2bktu^d)|13UW9(DaeT zrn+a diff --git a/Aetheria.State.Verify/Program.cs b/Aetheria.State.Verify/Program.cs index 042a083c0..1d3b04a3b 100644 --- a/Aetheria.State.Verify/Program.cs +++ b/Aetheria.State.Verify/Program.cs @@ -20,6 +20,7 @@ RequireTypedOrbitConsumerKeys(root); RequireKeyedOrbitRuntimeWrappers(root); RequireNativeZoneKeyResolution(root); RequireTypedZoneRuntimeCollections(root); +RequireTypedZoneConstructionKeys(root); RequireTypedAsteroidZoneApi(root); RequireTypedFactionShellLinks(root); RequireFactionKeyIdentity(root); @@ -1010,8 +1011,8 @@ static void RequireTypedOrbitalEntityOrbitKeys(string root) }, [Path.Combine(root, "Assets", "Scripts", "ServerShared", "ZoneGenerator.cs")] = new[] { - "turret.OrbitKey = Zone.OrbitKey(turretOrbit.ID);", - "station.OrbitKey = Zone.OrbitKey(lagrangeOrbit.ID);" + "turret.OrbitKey = turretOrbit.OrbitKey;", + "station.OrbitKey = lagrangeOrbit.OrbitKey;" }, [Path.Combine(root, "Assets", "Scripts", "Gameplay", "ActionGameManager.cs")] = new[] { @@ -1152,7 +1153,7 @@ static void RequireKeyedOrbitRuntimeWrappers(string root) { "public Orbit Orbit;", "public Orbit Orbit { get; }", - "var runtimeBelt = new AsteroidBelt(belt, Orbits[OrbitKey(belt.Orbit)]);", + "var runtimeBelt = new AsteroidBelt(belt, Orbits[belt.OrbitKey]);", "AsteroidBelts[runtimeBelt.BodyKey] = runtimeBelt;", "belt.NewOrbitPosition = GetOrbitPosition(belt.Orbit.ParentOrbitKey);", "public AsteroidBelt(AsteroidBeltConstructionData data, Orbit orbit)", @@ -1261,7 +1262,14 @@ static void RequireNativeZoneKeyResolution(string root) "if (_asteroidBeltsById.TryGetValue(bodyId, out var belt))", "var parentPosition = string.IsNullOrWhiteSpace(orbit.ParentOrbitKey)", ": GetOrbitPosition(orbit.ParentOrbitKey);", - "return TryGetOrbit(orbitKey, out var orbit) ? orbit.Velocity : float2.zero;" + "return TryGetOrbit(orbitKey, out var orbit) ? orbit.Velocity : float2.zero;", + "var runtimeBelt = new AsteroidBelt(belt, Orbits[belt.OrbitKey]);", + "var runtimeSun = new Sun(settings, sun, Orbits[planet.OrbitKey]);", + "var runtimeGas = new GasGiant(settings, gas, Orbits[planet.OrbitKey]);", + "var runtimePlanet = new Planet(settings, planet, Orbits[planet.OrbitKey]);", + "BodyKey = data.BodyKey ?? \"\";", + "OrbitKey = data.OrbitKey ?? \"\";", + "ParentOrbitKey = data.ParentOrbitKey ?? \"\";" }; var missingSymbols = requiredSymbols .Where(symbol => !zoneSource.Contains(symbol, StringComparison.Ordinal)) @@ -1355,6 +1363,92 @@ static void RequireTypedZoneRuntimeCollections(string root) } } +static void RequireTypedZoneConstructionKeys(string root) +{ + var checkedFiles = new[] + { + Path.Combine(root, "Assets", "Scripts", "ServerShared", "ZoneConstructionData.cs"), + Path.Combine(root, "Assets", "Scripts", "ServerShared", "ZoneGenerator.cs"), + Path.Combine(root, "Assets", "Scripts", "ServerShared", "Zone.cs") + }; + + var forbiddenSymbols = new[] + { + "var runtimeBelt = new AsteroidBelt(belt, Orbits[OrbitKey(belt.Orbit)]);", + "var runtimeSun = new Sun(settings, sun, Orbits[OrbitKey(planet.Orbit)]);", + "var runtimeGas = new GasGiant(settings, gas, Orbits[OrbitKey(planet.Orbit)]);", + "var runtimePlanet = new Planet(settings, planet, Orbits[OrbitKey(planet.Orbit)]);", + "turret.OrbitKey = Zone.OrbitKey(turretOrbit.ID);", + "station.OrbitKey = Zone.OrbitKey(lagrangeOrbit.ID);" + }; + + var hits = checkedFiles + .Where(File.Exists) + .SelectMany(path => File.ReadLines(path) + .Select((line, index) => new { Path = path, LineNumber = index + 1, Line = line })) + .Where(line => forbiddenSymbols.Any(symbol => line.Line.Contains(symbol, StringComparison.Ordinal))) + .Select(line => $"{Path.GetRelativePath(root, line.Path)}:{line.LineNumber}: {line.Line.Trim()}") + .ToArray(); + + if (hits.Length > 0) + { + throw new InvalidOperationException( + "Zone construction and generation must hand orbit/body identity through typed key fields instead of recomputing runtime authority from legacy GUID refs: " + + string.Join("; ", hits)); + } + + var requiredSymbols = new Dictionary + { + [Path.Combine(root, "Assets", "Scripts", "ServerShared", "ZoneConstructionData.cs")] = new[] + { + "public string BodyKey = \"\";", + "public string OrbitKey = \"\";", + "public string ParentOrbitKey = \"\";" + }, + [Path.Combine(root, "Assets", "Scripts", "ServerShared", "ZoneGenerator.cs")] = new[] + { + "data.OrbitKey = Zone.OrbitKey(data.ID);", + "data.ParentOrbitKey = orbitInverseMap[data].Parent != null", + "planetData.BodyKey = Zone.BodyKey(planetData.ID);", + "planetData.OrbitKey = orbitMap[planet].OrbitKey;", + "lagrangeOrbit.OrbitKey = Zone.OrbitKey(lagrangeOrbit.ID);", + "ParentOrbitKey = baseOrbit.ParentOrbitKey,", + "turretOrbit.OrbitKey = Zone.OrbitKey(turretOrbit.ID);", + "ParentOrbitKey = orbit.ParentOrbitKey,", + "turret.OrbitKey = turretOrbit.OrbitKey;", + "station.OrbitKey = lagrangeOrbit.OrbitKey;" + }, + [Path.Combine(root, "Assets", "Scripts", "ServerShared", "Zone.cs")] = new[] + { + "var runtimeBelt = new AsteroidBelt(belt, Orbits[belt.OrbitKey]);", + "var runtimeSun = new Sun(settings, sun, Orbits[planet.OrbitKey]);", + "var runtimeGas = new GasGiant(settings, gas, Orbits[planet.OrbitKey]);", + "var runtimePlanet = new Planet(settings, planet, Orbits[planet.OrbitKey]);", + "BodyKey = data.BodyKey ?? \"\";", + "OrbitKey = data.OrbitKey ?? \"\";", + "ParentOrbitKey = data.ParentOrbitKey ?? \"\";" + } + }; + + var missingSymbols = requiredSymbols + .Where(pair => !File.Exists(pair.Key) || pair.Value.Any(symbol => !File.ReadAllText(pair.Key).Contains(symbol, StringComparison.Ordinal))) + .SelectMany(pair => + { + var text = File.Exists(pair.Key) ? File.ReadAllText(pair.Key) : ""; + return pair.Value + .Where(symbol => !text.Contains(symbol, StringComparison.Ordinal)) + .Select(symbol => $"{Path.GetRelativePath(root, pair.Key)}: missing {symbol}"); + }) + .ToArray(); + + if (missingSymbols.Length > 0) + { + throw new InvalidOperationException( + "Zone construction inputs and generator seams must retain typed orbit/body keys as the handoff authority: " + + string.Join("; ", missingSymbols)); + } +} + static void RequireTypedAsteroidZoneApi(string root) { var zoneSourcePath = Path.Combine(root, "Assets", "Scripts", "ServerShared", "Zone.cs"); diff --git a/Aetheria.State/README.md b/Aetheria.State/README.md index 6bccea6ec..0d7e05962 100644 --- a/Aetheria.State/README.md +++ b/Aetheria.State/README.md @@ -214,7 +214,7 @@ needs actual allegiance weights, not only display counts. Runtime checkpoints now persist session faction relationships into typed run state, and runtime sessions publish typed state-host liveness. Zone checkpoints persist generated orbit/body rows into `AetheriaZoneState`, so `ZoneConstructionBlueprint` is a -one-shot construction input rather than the retained surface carrying celestial graph facts. Entity checkpoints +one-shot construction input carrying typed orbit/body keys rather than the retained surface carrying celestial graph facts. Entity checkpoints persist hull simulation grids into `AetheriaEntitySnapshot`, so `EntityConstructionBlueprint` is no longer the only surface carrying those live values. Run checkpoints project the flattened live entity graph, including diff --git a/Assets/Scripts/ServerShared/Zone.cs b/Assets/Scripts/ServerShared/Zone.cs index 1a65b9475..f64820f5e 100644 --- a/Assets/Scripts/ServerShared/Zone.cs +++ b/Assets/Scripts/ServerShared/Zone.cs @@ -70,22 +70,22 @@ public class Zone switch (planet) { case AsteroidBeltConstructionData belt: - var runtimeBelt = new AsteroidBelt(belt, Orbits[OrbitKey(belt.Orbit)]); + var runtimeBelt = new AsteroidBelt(belt, Orbits[belt.OrbitKey]); AsteroidBelts[runtimeBelt.BodyKey] = runtimeBelt; _asteroidBeltsById[runtimeBelt.ID] = runtimeBelt; break; case SunConstructionData sun: - var runtimeSun = new Sun(settings, sun, Orbits[OrbitKey(planet.Orbit)]); + var runtimeSun = new Sun(settings, sun, Orbits[planet.OrbitKey]); PlanetInstances[runtimeSun.BodyKey] = runtimeSun; _planetsById[runtimeSun.ID] = runtimeSun; break; case GasGiantConstructionData gas: - var runtimeGas = new GasGiant(settings, gas, Orbits[OrbitKey(planet.Orbit)]); + var runtimeGas = new GasGiant(settings, gas, Orbits[planet.OrbitKey]); PlanetInstances[runtimeGas.BodyKey] = runtimeGas; _planetsById[runtimeGas.ID] = runtimeGas; break; default: - var runtimePlanet = new Planet(settings, planet, Orbits[OrbitKey(planet.Orbit)]); + var runtimePlanet = new Planet(settings, planet, Orbits[planet.OrbitKey]); PlanetInstances[runtimePlanet.BodyKey] = runtimePlanet; _planetsById[runtimePlanet.ID] = runtimePlanet; break; @@ -439,9 +439,9 @@ public class Planet Settings = settings; Orbit = orbit; ID = data.ID; - BodyKey = Zone.BodyKey(data.ID); + BodyKey = data.BodyKey ?? ""; Name = data.Name ?? ""; - OrbitKey = Zone.OrbitKey(data.Orbit); + OrbitKey = data.OrbitKey ?? ""; Mass = data.Mass; Resources = data.Resources; BodyRadiusMultiplier = data.BodyRadiusMultiplier; @@ -552,9 +552,9 @@ public class AsteroidBelt _asteroids = data.Asteroids; Orbit = orbit; ID = data.ID; - BodyKey = Zone.BodyKey(data.ID); + BodyKey = data.BodyKey ?? ""; Name = data.Name ?? ""; - OrbitKey = Zone.OrbitKey(data.Orbit); + OrbitKey = data.OrbitKey ?? ""; Mass = data.Mass; Resources = data.Resources; BodyRadiusMultiplier = data.BodyRadiusMultiplier; @@ -596,8 +596,8 @@ public class Orbit public Orbit(PlanetSettings settings, OrbitConstructionData data) { ID = data.ID; - OrbitKey = Zone.OrbitKey(data.ID); - ParentOrbitKey = Zone.OrbitKey(data.Parent); + OrbitKey = data.OrbitKey ?? ""; + ParentOrbitKey = data.ParentOrbitKey ?? ""; Distance = data.Distance; Phase = data.Phase; FixedPosition = data.FixedPosition; diff --git a/Assets/Scripts/ServerShared/ZoneConstructionData.cs b/Assets/Scripts/ServerShared/ZoneConstructionData.cs index 65c123549..936902f5e 100644 --- a/Assets/Scripts/ServerShared/ZoneConstructionData.cs +++ b/Assets/Scripts/ServerShared/ZoneConstructionData.cs @@ -25,10 +25,14 @@ public abstract class BodyConstructionData : INamedEntry { public Guid ID = Guid.NewGuid(); + public string BodyKey = ""; + public string Name = ""; public Guid Orbit; + public string OrbitKey = ""; + public float Mass = 0; public Dictionary Resources = new Dictionary(); @@ -107,8 +111,12 @@ public class OrbitConstructionData { public Guid ID = Guid.NewGuid(); + public string OrbitKey = ""; + public Guid Parent; + public string ParentOrbitKey = ""; + public float Distance; public float Phase; diff --git a/Assets/Scripts/ServerShared/ZoneGenerator.cs b/Assets/Scripts/ServerShared/ZoneGenerator.cs index c21093d20..d8f2cfe00 100644 --- a/Assets/Scripts/ServerShared/ZoneGenerator.cs +++ b/Assets/Scripts/ServerShared/ZoneGenerator.cs @@ -102,11 +102,14 @@ public static class ZoneGenerator { var data = new OrbitConstructionData { + OrbitKey = "", + ParentOrbitKey = "", FixedPosition = planet.FixedPosition, Distance = planet.Distance, //Period = planet.Period, Phase = planet.Phase }; + data.OrbitKey = Zone.OrbitKey(data.ID); orbitMap[planet] = data; orbitInverseMap[data] = planet; return data; @@ -114,9 +117,14 @@ public static class ZoneGenerator // Link orbit construction parents to generated orbit IDs. foreach (var data in blueprint.Orbits) + { data.Parent = orbitInverseMap[data].Parent != null ? orbitMap[orbitInverseMap[data].Parent].ID : Guid.Empty; + data.ParentOrbitKey = orbitInverseMap[data].Parent != null + ? orbitMap[orbitInverseMap[data].Parent].OrbitKey + : ""; + } // Cache resource densities // var resourceMaps = mapLayers.Values @@ -159,8 +167,10 @@ public static class ZoneGenerator throw new ArgumentOutOfRangeException(); } + planetData.BodyKey = Zone.BodyKey(planetData.ID); planetData.Mass = planet.Mass; planetData.Orbit = orbitMap[planet].ID; + planetData.OrbitKey = orbitMap[planet].OrbitKey; // planetData.Resources = planetResources; planetData.Name = planetData.ID.ToString().Substring(0, 8); if (planetData is AsteroidBeltConstructionData beltData) @@ -255,10 +265,13 @@ public static class ZoneGenerator var lagrangeOrbit = new OrbitConstructionData { ID = Guid.NewGuid(), + OrbitKey = "", Parent = baseOrbit.Parent, + ParentOrbitKey = baseOrbit.ParentOrbitKey, Distance = baseOrbit.Distance, Phase = baseOrbit.Phase + PI / 3 * sign(random.NextFloat() - .5f) }; + lagrangeOrbit.OrbitKey = Zone.OrbitKey(lagrangeOrbit.ID); blueprint.Orbits.Add(lagrangeOrbit); return lagrangeOrbit; } @@ -270,14 +283,17 @@ public static class ZoneGenerator var turretOrbit = new OrbitConstructionData { ID = Guid.NewGuid(), + OrbitKey = "", Parent = orbit.Parent, + ParentOrbitKey = orbit.ParentOrbitKey, Distance = orbit.Distance, Phase = orbit.Phase + phase }; + turretOrbit.OrbitKey = Zone.OrbitKey(turretOrbit.ID); blueprint.Orbits.Add(turretOrbit); var turret = loadoutGenerator.GenerateTurretLoadout(); if (turret == null) return; - turret.OrbitKey = Zone.OrbitKey(turretOrbit.ID); + turret.OrbitKey = turretOrbit.OrbitKey; blueprint.Entities.Add(turret); } @@ -297,7 +313,7 @@ public static class ZoneGenerator var orbit = selectedStationOrbits[i]; var lagrangeOrbit = CreateLagrangeOrbit(orbit); var station = GetLoadoutGenerator(story.Faction).GenerateStationLoadout(); - station.OrbitKey = Zone.OrbitKey(lagrangeOrbit.ID); + station.OrbitKey = lagrangeOrbit.OrbitKey; station.SecurityLevel = story.Security; station.SecurityRadius = blueprint.Radius; station.Story = i; @@ -314,7 +330,7 @@ public static class ZoneGenerator var lagrangeOrbit = CreateLagrangeOrbit(orbit); var station = GetLoadoutGenerator(nearestFaction).GenerateStationLoadout(); if (station == null) continue; - station.OrbitKey = Zone.OrbitKey(lagrangeOrbit.ID); + station.OrbitKey = lagrangeOrbit.OrbitKey; station.SecurityLevel = security; station.SecurityRadius = blueprint.Radius; blueprint.Entities.Add(station);