Asteroids
Added asteroids to zone generation
This commit is contained in:
parent
776e08a1d1
commit
b0556d3900
22 changed files with 4872 additions and 4891 deletions
|
|
@ -22,6 +22,15 @@ public class GlobalData : DatabaseEntry
|
|||
|
||||
[InspectableField] [JsonProperty("heatRadiationMultiplier")] [Key(3)]
|
||||
public float HeatRadiationMultiplier = 1;
|
||||
|
||||
[InspectableField] [JsonProperty("galaxyArms")] [Key(13)]
|
||||
public int Arms = 4;
|
||||
|
||||
[InspectableField] [JsonProperty("galaxyTwist")] [Key(14)]
|
||||
public float Twist = 10;
|
||||
|
||||
[InspectableField] [JsonProperty("galaxyTwistPower")] [Key(15)]
|
||||
public float TwistPower = 2;
|
||||
|
||||
[InspectableField] [JsonProperty("radiusPower")] [Key(4)]
|
||||
public float RadiusPower = 1.75f;
|
||||
|
|
@ -50,15 +59,6 @@ public class GlobalData : DatabaseEntry
|
|||
[InspectableField] [JsonProperty("rosetteProbability")] [Key(12)]
|
||||
public float RosetteProbability = .25f;
|
||||
|
||||
[InspectableField] [JsonProperty("galaxyArms")] [Key(13)]
|
||||
public int Arms = 4;
|
||||
|
||||
[InspectableField] [JsonProperty("galaxyTwist")] [Key(14)]
|
||||
public float Twist = 10;
|
||||
|
||||
[InspectableField] [JsonProperty("galaxyTwistPower")] [Key(15)]
|
||||
public float TwistPower = 2;
|
||||
|
||||
[InspectableField] [JsonProperty("mapLayers")] [Key(16)]
|
||||
public Dictionary<string, Guid> MapLayers = new Dictionary<string, Guid>();
|
||||
|
||||
|
|
@ -86,6 +86,15 @@ public class GlobalData : DatabaseEntry
|
|||
[InspectableField] [JsonProperty("gravityRadiusMultiplier")] [Key(24)]
|
||||
public float GravityRadiusMultiplier = 1f;
|
||||
|
||||
[InspectableField] [JsonProperty("beltProbability")] [Key(25)]
|
||||
public float BeltProbability = .05f;
|
||||
|
||||
[InspectableField] [JsonProperty("beltMassCeiling")] [Key(25)]
|
||||
public float BeltMassCeiling = 500f;
|
||||
|
||||
[InspectableField] [JsonProperty("beltMassRatio")] [Key(26)]
|
||||
public float BeltMassRatio = 100f;
|
||||
|
||||
public float PlanetRadius(float mass)
|
||||
{
|
||||
return pow(mass, 1 / RadiusPower);
|
||||
|
|
|
|||
|
|
@ -93,6 +93,9 @@ public class PlanetData : DatabaseEntry, INamedEntry
|
|||
[JsonProperty("zone")] [Key(4)]
|
||||
public Guid Zone;
|
||||
|
||||
[JsonProperty("belt")] [Key(5)]
|
||||
public bool Belt;
|
||||
|
||||
// [JsonProperty("radius")] [Key(5)]
|
||||
// public float GravityRadius;
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using System.Globalization;
|
|||
using System.Linq;
|
||||
using MessagePack;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
//using UnityEngine;
|
||||
// TODO: USE THIS EVERYWHERE
|
||||
using static Unity.Mathematics.math;
|
||||
using Random = Unity.Mathematics.Random;
|
||||
|
|
@ -32,7 +32,7 @@ public class ZoneGenerator
|
|||
|
||||
var zoneMass = lerp(global.MinimumZoneMass, global.MaximumZoneMass, mass.Evaluate(zone.Position, global));
|
||||
|
||||
Debug.Log($"Generating zone at position {zone.Position} with radius {zoneRadius} and mass {zoneMass}");
|
||||
//Debug.Log($"Generating zone at position {zone.Position} with radius {zoneRadius} and mass {zoneMass}");
|
||||
|
||||
var planets = GenerateEntities(global, zone, zoneMass, zoneRadius);
|
||||
|
||||
|
|
@ -69,7 +69,8 @@ public class ZoneGenerator
|
|||
Mass = planet.Mass,
|
||||
ID = Guid.NewGuid(),
|
||||
Orbit = orbitMap[planet].ID,
|
||||
Zone = zone.ID
|
||||
Zone = zone.ID,
|
||||
Belt = planet.Belt
|
||||
};
|
||||
planetDatum.Name = planetDatum.ID.ToString().Substring(0, 8);
|
||||
return planetDatum;
|
||||
|
|
@ -144,17 +145,21 @@ public class ZoneGenerator
|
|||
|
||||
// Get all children that are above the satellite creation mass floor and not rosette members
|
||||
var satelliteCandidates = rosette
|
||||
? root.AllPlanets().Where(p => p.Parent != root && p.Mass > global.SatelliteCreationMassFloor)
|
||||
: root.AllPlanets().Where(p => p.Mass > global.SatelliteCreationMassFloor);
|
||||
|
||||
? root.AllPlanets().Where(p => p != root && p.Parent != root && p.Mass > global.SatelliteCreationMassFloor)
|
||||
: root.AllPlanets().Where(p => p != root && p.Mass > global.SatelliteCreationMassFloor);
|
||||
|
||||
var binaries = new List<Planet>();
|
||||
foreach (var planet in satelliteCandidates)
|
||||
{
|
||||
// There's a chance of generating satellites for each qualified planet
|
||||
if (random.NextFloat() < global.SatelliteCreationProbability)
|
||||
{
|
||||
// Sometimes the satellite is so massive that it forms a binary system (like Earth!)
|
||||
if(random.NextFloat() < global.BinaryCreationProbability)
|
||||
if (random.NextFloat() < global.BinaryCreationProbability)
|
||||
{
|
||||
planet.ExpandRosette(2);
|
||||
binaries.AddRange(planet.Children);
|
||||
}
|
||||
// Otherwise, terrestrial planets get a couple satellites while gas giants get many
|
||||
else planet.ExpandSolar(
|
||||
count: planet.Mass < global.GasGiantMass ? random.NextInt(1,3) : random.NextInt(4,10),
|
||||
|
|
@ -167,6 +172,14 @@ public class ZoneGenerator
|
|||
}
|
||||
}
|
||||
|
||||
// Get all children that are below the belt creation mass floor and not rosette members, also exclude binaries
|
||||
var beltCandidates = rosette
|
||||
? root.AllPlanets().Where(p => p != root && p.Parent != root && p.Mass < global.BeltMassCeiling && !binaries.Contains(p))
|
||||
: root.AllPlanets().Where(p => p != root && p.Mass < global.BeltMassCeiling && !binaries.Contains(p));
|
||||
foreach(var planet in beltCandidates)
|
||||
if (random.NextFloat() < global.BeltProbability)
|
||||
planet.Belt = true;
|
||||
|
||||
return root.AllPlanets().ToArray();
|
||||
}
|
||||
}
|
||||
|
|
@ -185,6 +198,7 @@ public class Planet
|
|||
public float ChildDistanceMinimum;
|
||||
public float ChildDistanceMaximum;
|
||||
public bool Empty = false;
|
||||
public bool Belt = false;
|
||||
public List<Planet> Children = new List<Planet>(); // Planets orbiting this one are referred to as children
|
||||
public Planet Parent;
|
||||
|
||||
|
|
@ -198,7 +212,7 @@ public class Planet
|
|||
// https://en.wikipedia.org/wiki/Klemperer_rosette
|
||||
public void ExpandRosette(int vertices)
|
||||
{
|
||||
Debug.Log("Expanding Rosette");
|
||||
//Debug.Log("Expanding Rosette");
|
||||
|
||||
// Rosette children replace the parent, parent orbital node is left empty
|
||||
Empty = true;
|
||||
|
|
@ -245,7 +259,7 @@ public class Planet
|
|||
// Create children that mimic the distribution of planetary masses in the solar system
|
||||
public void ExpandSolar(int count, float massMulMin, float massMulMax, float distMulMin, float distMulMax, float jupiterJump, float massFraction)
|
||||
{
|
||||
Debug.Log("Expanding Solar");
|
||||
//Debug.Log("Expanding Solar");
|
||||
// Expansion is impossible when child space is full
|
||||
if (count == 0 || ChildDistanceMaximum < ChildDistanceMinimum)
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -29,8 +29,8 @@ public class StrategyGameManager : MonoBehaviour
|
|||
public float ZoneSizeScale = .01f;
|
||||
public float ZoneMassScale = .01f;
|
||||
public float ZoneMassPower = .5f;
|
||||
public float ZoneOrbitSpeed = 10;
|
||||
public MeshRenderer ZoneBackground;
|
||||
public MeshRenderer ZoneBoundary;
|
||||
|
||||
private DatabaseCache _cache;
|
||||
private GameContext _context;
|
||||
|
|
@ -47,6 +47,8 @@ public class StrategyGameManager : MonoBehaviour
|
|||
private Dictionary<Guid, float2> _orbitPositions = new Dictionary<Guid, float2>();
|
||||
private Vector3 _galaxyCameraPos = -Vector3.forward;
|
||||
private float _galaxyOrthoSize = 50;
|
||||
private Material _boundaryMaterial;
|
||||
private Material _backgroundMaterial;
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
|
@ -94,6 +96,9 @@ public class StrategyGameManager : MonoBehaviour
|
|||
Camera.transform.position = -Vector3.forward;
|
||||
}
|
||||
};
|
||||
|
||||
_boundaryMaterial = ZoneBoundary.material;
|
||||
_backgroundMaterial = ZoneBackground.material;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
|
|
@ -126,7 +131,7 @@ public class StrategyGameManager : MonoBehaviour
|
|||
{
|
||||
var orbitData = _cache.Get<OrbitData>(orbit);
|
||||
_orbitPositions[orbit] = GetOrbitPosition(orbitData.Parent) + (orbitData.Period < .01f ? float2.zero :
|
||||
OrbitData.Evaluate(Time.time * ZoneOrbitSpeed / orbitData.Period + orbitData.Phase) *
|
||||
OrbitData.Evaluate(Time.time / orbitData.Period + orbitData.Phase) *
|
||||
orbitData.Distance);
|
||||
}
|
||||
|
||||
|
|
@ -215,7 +220,9 @@ public class StrategyGameManager : MonoBehaviour
|
|||
_zoneObjects[planet.ID] = planetObject;
|
||||
planetObject.Label.text = planet.Name;
|
||||
planetObject.GravityMesh.gameObject.SetActive(true);
|
||||
planetObject.GravityMesh.transform.localScale = Vector3.one * (pow(planet.Mass,_context.GlobalData.GravityRadiusExponent) * _context.GlobalData.GravityRadiusMultiplier * ZoneSizeScale);
|
||||
planetObject.GravityMesh.transform.localScale =
|
||||
Vector3.one * (pow(planet.Mass, _context.GlobalData.GravityRadiusExponent) *
|
||||
_context.GlobalData.GravityRadiusMultiplier * ZoneSizeScale);
|
||||
var depth = pow(planet.Mass, ZoneMassPower) * ZoneMassScale;
|
||||
if (depth > zoneDepth)
|
||||
zoneDepth = depth;
|
||||
|
|
@ -226,12 +233,15 @@ public class StrategyGameManager : MonoBehaviour
|
|||
PlanetSprite);
|
||||
}
|
||||
}
|
||||
ZoneBackground.material.SetFloat("_HeightRange", zoneDepth);
|
||||
var radius = (_zoneResponse.Zone.Radius * ZoneSizeScale * 2);
|
||||
_backgroundMaterial.SetFloat("_ClipDistance", radius);
|
||||
_backgroundMaterial.SetFloat("_HeightRange", zoneDepth + _boundaryMaterial.GetFloat("_Depth"));
|
||||
ZoneBoundary.transform.localScale = Vector3.one * radius;
|
||||
|
||||
foreach (var wormhole in _zoneResponse.Zone.Wormholes)
|
||||
{
|
||||
var otherZone = _galaxyResponseZones[wormhole];
|
||||
var wormholeObject = Instantiate(ZoneObjectPrefab);
|
||||
var wormholeObject = Instantiate(ZoneObjectPrefab, ZoneRoot);
|
||||
_wormholes.Add(wormholeObject);
|
||||
var direction = otherZone.Position - _zoneResponse.Zone.Position;
|
||||
wormholeObject.transform.position = (Vector2) (normalize(direction) * _zoneResponse.Zone.Radius * .95f * ZoneSizeScale);
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ public class ZoneGeneratorTest : MonoBehaviour
|
|||
public MeshRenderer ZoneBackground;
|
||||
public MeshRenderer ZoneBoundary;
|
||||
public ZoneObject ZoneObjectPrefab;
|
||||
public ParticleSystem BeltPrefab;
|
||||
public Texture2D PlanetSprite;
|
||||
public Texture2D GasGiantSprite;
|
||||
public Texture2D SunSprite;
|
||||
|
|
@ -23,6 +24,7 @@ public class ZoneGeneratorTest : MonoBehaviour
|
|||
|
||||
private DatabaseCache _cache;
|
||||
private Dictionary<Guid, ZoneObject> _zoneObjects = new Dictionary<Guid, ZoneObject>();
|
||||
private Dictionary<Guid, ParticleSystem> _zoneBelts = new Dictionary<Guid, ParticleSystem>();
|
||||
private List<ZoneObject> _wormholes = new List<ZoneObject>();
|
||||
private Dictionary<Guid, float2> _orbitPositions = new Dictionary<Guid, float2>();
|
||||
private GameContext _context;
|
||||
|
|
@ -39,7 +41,7 @@ public class ZoneGeneratorTest : MonoBehaviour
|
|||
{
|
||||
var orbitData = _cache.Get<OrbitData>(orbit);
|
||||
_orbitPositions[orbit] = GetOrbitPosition(orbitData.Parent) + (orbitData.Period < .01f ? Unity.Mathematics.float2.zero :
|
||||
OrbitData.Evaluate(Time.time * ZoneOrbitSpeed / orbitData.Period + orbitData.Phase) *
|
||||
OrbitData.Evaluate(Time.time * ZoneOrbitSpeed / -orbitData.Period + orbitData.Phase) *
|
||||
orbitData.Distance);
|
||||
}
|
||||
|
||||
|
|
@ -68,6 +70,13 @@ public class ZoneGeneratorTest : MonoBehaviour
|
|||
|
||||
planet.Value.transform.position = (Vector2) GetOrbitPosition(planetData.Orbit) * ZoneSizeScale;
|
||||
}
|
||||
|
||||
foreach (var belt in _zoneBelts)
|
||||
{
|
||||
var planetData = _cache.Get<PlanetData>(belt.Key);
|
||||
|
||||
belt.Value.transform.position = (Vector2) GetOrbitPosition(_cache.Get<OrbitData>(planetData.Orbit).Parent) * ZoneSizeScale;
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.Space))
|
||||
{
|
||||
PopulateZone();
|
||||
|
|
@ -81,6 +90,8 @@ public class ZoneGeneratorTest : MonoBehaviour
|
|||
_zoneObjects.Clear();
|
||||
foreach (var zoneObject in _wormholes) Destroy(zoneObject.gameObject); //zoneObject.GetComponent<Prototype>().ReturnToPool();
|
||||
_wormholes.Clear();
|
||||
foreach (var belt in _zoneBelts.Values) Destroy(belt.gameObject);
|
||||
_zoneBelts.Clear();
|
||||
|
||||
float2 position;
|
||||
do
|
||||
|
|
@ -105,26 +116,42 @@ public class ZoneGeneratorTest : MonoBehaviour
|
|||
float zoneDepth = 0;
|
||||
foreach (var planet in planets)
|
||||
{
|
||||
var planetObject = Instantiate(ZoneObjectPrefab, transform);
|
||||
_zoneObjects[planet.ID] = planetObject;
|
||||
planetObject.Label.text = planet.Name;
|
||||
planetObject.GravityMesh.gameObject.SetActive(true);
|
||||
planetObject.GravityMesh.transform.localScale =
|
||||
Vector3.one * (pow(planet.Mass, Galaxy.MapData.GlobalData.GravityRadiusExponent) *
|
||||
Galaxy.MapData.GlobalData.GravityRadiusMultiplier * 2 * ZoneSizeScale);
|
||||
var depth = pow(planet.Mass, ZoneMassPower) * ZoneMassScale;
|
||||
if (depth > zoneDepth)
|
||||
zoneDepth = depth;
|
||||
planetObject.GravityMesh.material.SetFloat("_Depth", depth);
|
||||
planetObject.Icon.material.SetTexture("_MainTex",
|
||||
planet.Mass > Galaxy.MapData.GlobalData.SunMass ? SunSprite :
|
||||
planet.Mass > Galaxy.MapData.GlobalData.GasGiantMass ? GasGiantSprite :
|
||||
PlanetSprite);
|
||||
if (!planet.Belt)
|
||||
{
|
||||
var planetObject = Instantiate(ZoneObjectPrefab, transform);
|
||||
_zoneObjects[planet.ID] = planetObject;
|
||||
planetObject.Label.text = planet.Name;
|
||||
planetObject.GravityMesh.gameObject.SetActive(true);
|
||||
planetObject.GravityMesh.transform.localScale =
|
||||
Vector3.one * (pow(planet.Mass, Galaxy.MapData.GlobalData.GravityRadiusExponent) *
|
||||
Galaxy.MapData.GlobalData.GravityRadiusMultiplier * 2 * ZoneSizeScale);
|
||||
var depth = pow(planet.Mass, ZoneMassPower) * ZoneMassScale;
|
||||
if (depth > zoneDepth)
|
||||
zoneDepth = depth;
|
||||
planetObject.GravityMesh.material.SetFloat("_Depth", depth);
|
||||
planetObject.Icon.material.SetTexture("_MainTex",
|
||||
planet.Mass > Galaxy.MapData.GlobalData.SunMass ? SunSprite :
|
||||
planet.Mass > Galaxy.MapData.GlobalData.GasGiantMass ? GasGiantSprite :
|
||||
PlanetSprite);
|
||||
}
|
||||
else
|
||||
{
|
||||
var beltObject = Instantiate(BeltPrefab, transform);
|
||||
_zoneBelts[planet.ID] = beltObject;
|
||||
var orbit = _cache.Get<OrbitData>(planet.Orbit);
|
||||
var beltEmission = beltObject.emission;
|
||||
beltEmission.rateOverTime = new ParticleSystem.MinMaxCurve(planet.Mass / Galaxy.MapData.GlobalData.BeltMassRatio * orbit.Distance);
|
||||
var beltShape = beltObject.shape;
|
||||
beltShape.radius = orbit.Distance * ZoneSizeScale;
|
||||
beltShape.donutRadius = orbit.Distance * ZoneSizeScale / 2;
|
||||
var beltVelocity = beltObject.velocityOverLifetime;
|
||||
beltVelocity.orbitalZ = orbit.Distance * ZoneSizeScale * PI / orbit.Period * ZoneOrbitSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
var radius = (zone.Radius * ZoneSizeScale * 2);
|
||||
ZoneBackground.material.SetFloat("_ClipDistance", radius);
|
||||
var zoneRadius = (zone.Radius * ZoneSizeScale * 2);
|
||||
ZoneBackground.material.SetFloat("_ClipDistance", zoneRadius);
|
||||
ZoneBackground.material.SetFloat("_HeightRange", zoneDepth + _boundaryMaterial.GetFloat("_Depth"));
|
||||
ZoneBoundary.transform.localScale = Vector3.one * radius;
|
||||
ZoneBoundary.transform.localScale = Vector3.one * zoneRadius;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue