Asteroid Belt Upgrade
Asteroids now use custom particle system with collider so they can be clicked, plus they now orbit at varying speeds! Fixed flags enum inspector; resources were being assigned to wrong body type: gas giants had planet resources, suns had gas giant resources, asteroids had nothing
This commit is contained in:
parent
ba681abeb6
commit
7c30a72c71
14 changed files with 516 additions and 202 deletions
|
|
@ -69,8 +69,8 @@ public static class Extensions
|
|||
private static Random? _random;
|
||||
private static Random Random => (Random) (_random ?? (_random = new Random((uint) (DateTime.Now.Ticks%uint.MaxValue))));
|
||||
// public static T RandomElement<T>(this IEnumerable<T> enumerable) => enumerable.ElementAt(Random.NextInt(0, enumerable.Count()));
|
||||
public static float NextUnbounded(this Random random) => 1 / (1 - random.NextFloat()) - 1;
|
||||
public static float NextUnbounded(this Random random, float bias, float power) => 1 / (1 - pow(random.NextFloat(), 1 - pow(clamp(bias,0,.99f), 1 / power))) - 1;
|
||||
public static float NextUnbounded(this ref Random random) => 1 / (1 - random.NextFloat()) - 1;
|
||||
public static float NextUnbounded(this ref Random random, float bias, float power) => 1 / (1 - pow(random.NextFloat(), 1 - pow(clamp(bias,0,.99f), 1 / power))) - 1;
|
||||
|
||||
private static Dictionary<Type,Type[]> InterfaceClasses = new Dictionary<Type, Type[]>();
|
||||
public static Type[] GetAllInterfaceClasses(this Type type)
|
||||
|
|
|
|||
|
|
@ -41,8 +41,8 @@ public class GlobalData : DatabaseEntry
|
|||
[InspectableField, JsonProperty("gasGiantMass"), Key(10)]
|
||||
public float GasGiantMass = 2000;
|
||||
|
||||
[InspectableField, JsonProperty("dockingDistance"), Key(11)]
|
||||
public float DockingDistance = 10;
|
||||
[InspectableField, JsonProperty("planetMass"), Key(11)]
|
||||
public float PlanetMass = 100f;
|
||||
|
||||
[InspectableField, JsonProperty("satelliteCreationMassFloor"), Key(12)]
|
||||
public float SatelliteCreationMassFloor = 100;
|
||||
|
|
@ -95,10 +95,22 @@ public class GlobalData : DatabaseEntry
|
|||
[InspectableField, JsonProperty("beltMassExponent"), Key(27)]
|
||||
public float BeltMassExponent = 100f;
|
||||
|
||||
[InspectableField, JsonProperty("planetMass"), Key(28)]
|
||||
public float PlanetMass = 100f;
|
||||
[InspectableField, JsonProperty("asteroidSizeMin"), Key(28)]
|
||||
public float AsteroidSizeMin = 2f;
|
||||
|
||||
[InspectableField, JsonProperty("orbitSpeedMultiplier"), Key(29)]
|
||||
[InspectableField, JsonProperty("asteroidSizeMax"), Key(29)]
|
||||
public float AsteroidSizeMax = 10f;
|
||||
|
||||
[InspectableField, JsonProperty("asteroidSizeExponent"), Key(30)]
|
||||
public float AsteroidSizeExponent = 2f;
|
||||
|
||||
[InspectableField, JsonProperty("asteroidRotationSpeed"), Key(31)]
|
||||
public float AsteroidRotationSpeed = 2f;
|
||||
|
||||
[InspectableField, JsonProperty("dockingDistance"), Key(32)]
|
||||
public float DockingDistance = 10;
|
||||
|
||||
[InspectableField, JsonProperty("orbitSpeedMultiplier"), Key(33)]
|
||||
public float OrbitSpeedMultiplier = .25f;
|
||||
|
||||
public float PlanetRadius(float mass)
|
||||
|
|
|
|||
|
|
@ -92,6 +92,9 @@ public class PlanetData : DatabaseEntry, INamedEntry
|
|||
|
||||
[JsonProperty("resources"), Key(6)]
|
||||
public Dictionary<Guid, float> Resources = new Dictionary<Guid, float>();
|
||||
|
||||
[JsonProperty("asteroids"), Key(7)]
|
||||
public float4[] Asteroids; // Distance, Phase, Size, RotationSpeed
|
||||
|
||||
// [JsonProperty("radius")] [Key(5)]
|
||||
// public float GravityRadius;
|
||||
|
|
|
|||
|
|
@ -67,34 +67,40 @@ public class ZoneGenerator
|
|||
|
||||
planetsData = planets.Where(p=>!p.Empty).Select(planet =>
|
||||
{
|
||||
var planetData = new PlanetData
|
||||
Dictionary<Guid, float> dictionary = new Dictionary<Guid, float>();
|
||||
foreach (var r in resources)
|
||||
{
|
||||
var bodyType = (planet.Belt ? BodyType.Asteroid :
|
||||
planet.Mass > context.GlobalData.SunMass ? BodyType.Sun :
|
||||
planet.Mass > context.GlobalData.GasGiantMass ? BodyType.GasGiant :
|
||||
planet.Mass > context.GlobalData.PlanetMass ? BodyType.Planet : BodyType.Planetoid);
|
||||
if ((bodyType & r.ResourceBodyType) != 0)
|
||||
{
|
||||
float quantity = context.Random.NextUnbounded(r.ResourceDensity.Aggregate(1f, (m, rdm) => m * resourceMaps[rdm]), r.ResourceDensityBiasPower);
|
||||
if (r.ResourceFloor < quantity) dictionary.Add(r.ID, quantity);
|
||||
}
|
||||
}
|
||||
|
||||
var planetData = new PlanetData
|
||||
{
|
||||
Mass = planet.Mass,
|
||||
ID = Guid.NewGuid(),
|
||||
Orbit = orbitMap[planet].ID,
|
||||
Zone = zone.ID,
|
||||
Belt = planet.Belt,
|
||||
Resources = resources
|
||||
// Filter resources where the body type matches the current planet
|
||||
.Where(r =>
|
||||
((planet.Belt ? BodyType.Asteroid :
|
||||
planet.Mass > context.GlobalData.SunMass ? BodyType.Sun :
|
||||
planet.Mass > context.GlobalData.GasGiantMass ? BodyType.GasGiant :
|
||||
planet.Mass > context.GlobalData.PlanetMass ? BodyType.Planet : BodyType.Planetoid) & r.ResourceBodyType) != 0)
|
||||
// NextUnbounded is our extension function containing resource placement formula
|
||||
// Obtain bias variable by multiplying all resource maps together
|
||||
.Select(r => new
|
||||
{
|
||||
resource = r,
|
||||
quantity = context.Random.NextUnbounded(
|
||||
r.ResourceDensity.Aggregate(1f, (m, rdm) => m * resourceMaps[rdm]),
|
||||
r.ResourceDensityBiasPower)
|
||||
})
|
||||
// Only include resources above a minimum quantity
|
||||
.Where(r => r.resource.ResourceFloor < r.quantity)
|
||||
.ToDictionary(r => r.resource.ID, r => r.quantity)
|
||||
Resources = dictionary
|
||||
};
|
||||
planetData.Name = planetData.ID.ToString().Substring(0, 8);
|
||||
if (planet.Belt)
|
||||
{
|
||||
planetData.Asteroids =
|
||||
Enumerable.Range(0, (int) (pow(planetData.Mass, context.GlobalData.BeltMassExponent) / context.GlobalData.BeltMassRatio * orbitMap[planet].Distance))
|
||||
.Select(_ => float4(context.Random.NextFloat(orbitMap[planet].Distance * .5f, orbitMap[planet].Distance * 1.5f),
|
||||
context.Random.NextFloat(),
|
||||
pow(context.Random.NextFloat(), context.GlobalData.AsteroidSizeExponent) * (context.GlobalData.AsteroidSizeMax - context.GlobalData.AsteroidSizeMin) + context.GlobalData.AsteroidSizeMin,
|
||||
context.Random.NextFloat() * context.GlobalData.AsteroidRotationSpeed))
|
||||
.ToArray();
|
||||
}
|
||||
return planetData;
|
||||
}).ToArray();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue