Carry typed orbit keys through zone construction
This commit is contained in:
parent
397f3aff5a
commit
4217394cc2
6 changed files with 136 additions and 18 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<string, float> Resources = new Dictionary<string, float>();
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue