Asteroids & Refactoring
We have proper belts that hug the Grid, reactive properties for planet instance data, and more!
This commit is contained in:
parent
a981a46170
commit
1f90d3639a
42 changed files with 614 additions and 597 deletions
|
|
@ -40,7 +40,7 @@ public abstract class ControllerBase : IBehavior, IController, IInitializableBeh
|
|||
protected Func<float2> TargetPosition;
|
||||
protected Func<float2> TargetVelocity;
|
||||
protected bool MatchVelocity;
|
||||
protected List<SimplifiedZoneData> Path;
|
||||
protected List<ZoneDefinition> Path;
|
||||
protected Guid Task;
|
||||
protected bool Moving;
|
||||
protected bool Waiting;
|
||||
|
|
@ -116,7 +116,7 @@ public abstract class ControllerBase : IBehavior, IController, IInitializableBeh
|
|||
if (Moving)
|
||||
{
|
||||
if(_entity.Parent!=Guid.Empty)
|
||||
_context.RemoveParent(_entity);
|
||||
_entity.RemoveParent();
|
||||
|
||||
var targetPosition = TargetPosition();
|
||||
var distance = length(targetPosition - _entity.Position);
|
||||
|
|
@ -179,12 +179,12 @@ public abstract class ControllerBase : IBehavior, IController, IInitializableBeh
|
|||
var homeEntity = _context.Cache.Get<Entity>(HomeEntity);
|
||||
if (Zone == homeEntity.Zone) MoveTo(homeEntity, true, () =>
|
||||
{
|
||||
_context.SetParent(_entity, homeEntity);
|
||||
_entity.SetParent(homeEntity);
|
||||
onFinish?.Invoke();
|
||||
});
|
||||
else MoveTo(homeEntity.Zone.Data.ID, () => MoveTo(homeEntity, true, () =>
|
||||
{
|
||||
_context.SetParent(_entity, homeEntity);
|
||||
_entity.SetParent(homeEntity);
|
||||
onFinish?.Invoke();
|
||||
}));
|
||||
}
|
||||
|
|
@ -235,7 +235,7 @@ public abstract class ControllerBase : IBehavior, IController, IInitializableBeh
|
|||
path.RemoveAt(0);
|
||||
if (path.Count > 0)
|
||||
{
|
||||
MoveTo(Zone.WormholePosition(Path[0].ZoneID), false, OnNextZone);
|
||||
MoveTo(Zone.WormholePosition(Path[0]), false, OnNextZone);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ public class HaulingController : ControllerBase, IBehavior, IPersistentBehavior
|
|||
var haulingTask = _context.Cache.Get<HaulingTask>(Task);
|
||||
var target = Zone.Entities[haulingTask.Origin] as OrbitalEntity;
|
||||
|
||||
_context.SetParent(_entity, target);
|
||||
_entity.SetParent(target);
|
||||
var itemData = _context.Cache.Get<ItemData>(haulingTask.ItemType);
|
||||
int quantity = min((int) ((_entity.Capacity - _entity.OccupiedCapacity) / itemData.Size), haulingTask.Quantity - _itemsDelivered);
|
||||
if (itemData is SimpleCommodityData)
|
||||
|
|
@ -116,7 +116,7 @@ public class HaulingController : ControllerBase, IBehavior, IPersistentBehavior
|
|||
var haulingTask = _context.Cache.Get<HaulingTask>(Task);
|
||||
var target = Zone.Entities[haulingTask.Target] as OrbitalEntity;
|
||||
|
||||
_context.SetParent(_entity, target);
|
||||
_entity.SetParent(target);
|
||||
|
||||
var itemData = _context.Cache.Get<ItemData>(haulingTask.ItemType);
|
||||
if (itemData is SimpleCommodityData)
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public class TowingController : ControllerBase, IBehavior, IPersistentBehavior
|
|||
var towingTask = _context.Cache.Get<StationTowing>(Task);
|
||||
var target = Zone.Entities[towingTask.Station] as OrbitalEntity;
|
||||
|
||||
_context.SetParent(target, _entity);
|
||||
target.SetParent(_entity);
|
||||
|
||||
_entity.SetMessage("Entering delivery phase.");
|
||||
|
||||
|
|
@ -80,7 +80,7 @@ public class TowingController : ControllerBase, IBehavior, IPersistentBehavior
|
|||
var towingTask = _context.Cache.Get<StationTowing>(Task);
|
||||
var target = Zone.Entities[towingTask.Station] as OrbitalEntity;
|
||||
|
||||
_context.RemoveParent(target);
|
||||
target.RemoveParent();
|
||||
|
||||
_entity.SetMessage("Target delivered. Returning Home.");
|
||||
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ public class WanderController : ControllerBase, IBehavior
|
|||
var randomEntity = entities[_context.Random.NextInt(entities.Length)];
|
||||
MoveTo(randomEntity, true, () =>
|
||||
{
|
||||
_context.SetParent(_entity, randomEntity);
|
||||
_entity.SetParent(randomEntity);
|
||||
_dockTime = _context.Random.NextFloat(_data.RandomDockTime);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -379,6 +379,22 @@ public abstract class Entity : DatabaseEntry, IMessagePackSerializationCallbackR
|
|||
Children.Remove(entity.ID);
|
||||
ChildEvent.Change();
|
||||
}
|
||||
|
||||
public void SetParent(Entity parent)
|
||||
{
|
||||
Parent = parent.ID;
|
||||
parent.AddChild(this);
|
||||
}
|
||||
|
||||
public void RemoveParent()
|
||||
{
|
||||
if (Parent == Guid.Empty)
|
||||
return;
|
||||
|
||||
var parent = Zone.Entities[Parent];
|
||||
parent.RemoveChild(this);
|
||||
Parent = Guid.Empty;
|
||||
}
|
||||
|
||||
public Guid Build(BlueprintData blueprint, float quality, string name, bool direct = false)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -22,26 +22,16 @@ public class ExponentialCurve
|
|||
}
|
||||
|
||||
[Serializable, MessagePackObject, JsonObject]
|
||||
public class GravitySettings
|
||||
public class ExponentialLerp
|
||||
{
|
||||
[JsonProperty("gravityDepth"), Key(0)]
|
||||
public ExponentialCurve GravityDepth;
|
||||
[JsonProperty("exponent"), Key(0)]
|
||||
public float Exponent;
|
||||
|
||||
[JsonProperty("gravityRadius"), Key(1)]
|
||||
public ExponentialCurve GravityRadius;
|
||||
[JsonProperty("max"), Key(1)]
|
||||
public float Minimum;
|
||||
|
||||
[JsonProperty("waveDepth"), Key(2)]
|
||||
public ExponentialCurve WaveDepth;
|
||||
[JsonProperty("min"), Key(2)]
|
||||
public float Maximum;
|
||||
|
||||
[JsonProperty("waveRadius"), Key(3)]
|
||||
public ExponentialCurve WaveRadius;
|
||||
|
||||
[JsonProperty("waveFrequency"), Key(4)]
|
||||
public ExponentialCurve WaveFrequency;
|
||||
|
||||
[JsonProperty("waveSpeed"), Key(5)]
|
||||
public ExponentialCurve WaveSpeed;
|
||||
|
||||
[JsonProperty("gravityStrength"), Key(6)]
|
||||
public float GravityStrength;
|
||||
public float Evaluate(float value) => Minimum + pow(saturate(value), Exponent) * (Maximum - Minimum);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ public static class Extensions
|
|||
}
|
||||
|
||||
private static Random? _random;
|
||||
private static Random Random => (Random) (_random ?? (_random = new Random((uint) (DateTime.Now.Ticks%uint.MaxValue))));
|
||||
//private static 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 NextPowerDistribution(this ref Random random, float min, float max, float exp, float randexp) =>
|
||||
pow((pow(max, exp + 1) - pow(min, exp + 1)) * pow(random.NextFloat(), randexp) + pow(min, exp + 1), 1 / (exp + 1));
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ using static Unity.Mathematics.math;
|
|||
using float2 = Unity.Mathematics.float2;
|
||||
using Random = Unity.Mathematics.Random;
|
||||
using JM.LinqFaster;
|
||||
using UniRx;
|
||||
using float4 = Unity.Mathematics.float4;
|
||||
|
||||
public class GameContext
|
||||
|
|
@ -15,7 +16,7 @@ public class GameContext
|
|||
public Dictionary<string, GalaxyMapLayerData> MapLayers = new Dictionary<string, GalaxyMapLayerData>();
|
||||
public SimpleCommodityData[] Resources;
|
||||
public Dictionary<Guid, List<IController>> CorporationControllers = new Dictionary<Guid, List<IController>>();
|
||||
public Dictionary<Guid, SimplifiedZoneData> GalaxyZones;
|
||||
public Dictionary<Guid, ZoneDefinition> GalaxyZones;
|
||||
|
||||
private Action<string> _logger;
|
||||
|
||||
|
|
@ -76,67 +77,67 @@ public class GameContext
|
|||
_logger(s);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
foreach(var zone in _zones.Values)
|
||||
zone.Update(_deltaTime);
|
||||
|
||||
foreach (var corporation in Cache.GetAll<Corporation>())
|
||||
{
|
||||
foreach (var tasks in corporation.Tasks
|
||||
.Select(id => Cache.Get<AgentTask>(id)) // Fetch the tasks from the database cache
|
||||
.Where(task => !task.Reserved) // Filter out tasks that have already been reserved
|
||||
.GroupBy(task => task.Type)) // Group tasks by type
|
||||
{
|
||||
// Create a list of available controllers for this task type
|
||||
var availableControllers = CorporationControllers[corporation.ID]
|
||||
.Where(controller => controller.Available && controller.TaskType == tasks.Key).ToList();
|
||||
|
||||
// Iterate over the highest priority tasks for which controllers are available
|
||||
foreach (var task in tasks.OrderByDescending(task => task.Priority).Take(availableControllers.Count))
|
||||
{
|
||||
// Find the nearest controller for this task
|
||||
IController nearestController = availableControllers[0];
|
||||
List<SimplifiedZoneData> nearestControllerPath = FindPath(GalaxyZones[availableControllers.First().Zone.Data.ID], GalaxyZones[task.Zone], true);
|
||||
foreach (var controller in availableControllers.Skip(1))
|
||||
{
|
||||
var path = FindPath(GalaxyZones[controller.Zone.Data.ID], GalaxyZones[task.Zone], true);
|
||||
if (path.Count < nearestControllerPath.Count)
|
||||
{
|
||||
nearestControllerPath = path;
|
||||
nearestController = controller;
|
||||
}
|
||||
}
|
||||
task.Reserved = true;
|
||||
nearestController.AssignTask(task.ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// public void Update()
|
||||
// {
|
||||
// foreach(var zone in _zones.Values)
|
||||
// zone.Update((float) Time, _deltaTime);
|
||||
//
|
||||
// foreach (var corporation in Cache.GetAll<Corporation>())
|
||||
// {
|
||||
// foreach (var tasks in corporation.Tasks
|
||||
// .Select(id => Cache.Get<AgentTask>(id)) // Fetch the tasks from the database cache
|
||||
// .Where(task => !task.Reserved) // Filter out tasks that have already been reserved
|
||||
// .GroupBy(task => task.Type)) // Group tasks by type
|
||||
// {
|
||||
// // Create a list of available controllers for this task type
|
||||
// var availableControllers = CorporationControllers[corporation.ID]
|
||||
// .Where(controller => controller.Available && controller.TaskType == tasks.Key).ToList();
|
||||
//
|
||||
// // Iterate over the highest priority tasks for which controllers are available
|
||||
// foreach (var task in tasks.OrderByDescending(task => task.Priority).Take(availableControllers.Count))
|
||||
// {
|
||||
// // Find the nearest controller for this task
|
||||
// IController nearestController = availableControllers[0];
|
||||
// List<ZoneDefinition> nearestControllerPath = FindPath(GalaxyZones[availableControllers.First().Zone.Data.ID], GalaxyZones[task.Zone], true);
|
||||
// foreach (var controller in availableControllers.Skip(1))
|
||||
// {
|
||||
// var path = FindPath(GalaxyZones[controller.Zone.Data.ID], GalaxyZones[task.Zone], true);
|
||||
// if (path.Count < nearestControllerPath.Count)
|
||||
// {
|
||||
// nearestControllerPath = path;
|
||||
// nearestController = controller;
|
||||
// }
|
||||
// }
|
||||
// task.Reserved = true;
|
||||
// nearestController.AssignTask(task.ID);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
public Zone GetZone(Guid zone)
|
||||
{
|
||||
if (_zones.ContainsKey(zone)) return _zones[zone];
|
||||
|
||||
// var zoneData = Cache.Get<ZoneData>(zone);
|
||||
// if (zoneData == null) throw new ArgumentException("Zone parameter is not a valid zone ID!", nameof(zone));
|
||||
//
|
||||
// return GetZone(zoneData);
|
||||
return null;
|
||||
}
|
||||
|
||||
public Zone GetZone(ZonePack zonePack)
|
||||
{
|
||||
var z = new Zone(this, zonePack);
|
||||
_zones.Add(zonePack.Data.ID, z);
|
||||
return z;
|
||||
}
|
||||
|
||||
public void UnloadZone(Guid zone)
|
||||
{
|
||||
_zones.Remove(zone);
|
||||
}
|
||||
// public Zone GetZone(Guid zone)
|
||||
// {
|
||||
// if (_zones.ContainsKey(zone)) return _zones[zone];
|
||||
//
|
||||
// // var zoneData = Cache.Get<ZoneData>(zone);
|
||||
// // if (zoneData == null) throw new ArgumentException("Zone parameter is not a valid zone ID!", nameof(zone));
|
||||
// //
|
||||
// // return GetZone(zoneData);
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// public Zone GetZone(ZonePack zonePack)
|
||||
// {
|
||||
// var z = new Zone(this, zonePack);
|
||||
// _zones.Add(zonePack.Data.ID, z);
|
||||
// return z;
|
||||
// }
|
||||
//
|
||||
// public void UnloadZone(Guid zone)
|
||||
// {
|
||||
// _zones.Remove(zone);
|
||||
// }
|
||||
|
||||
// public void Warp(Entity entity, Guid targetZone)
|
||||
// {
|
||||
|
|
@ -535,10 +536,9 @@ public class GameContext
|
|||
var orbit = new OrbitData
|
||||
{
|
||||
Context = this,
|
||||
Distance = distance,
|
||||
Distance = new ReactiveProperty<float>(distance),
|
||||
Parent = zone.Orbits.Values.Select(o=>o.Data)
|
||||
.First(orbitData => orbitData.Parent == Guid.Empty).ID,
|
||||
Period = _globalData.OrbitalPeriod(distance),
|
||||
Phase = Random.NextFloat()
|
||||
};
|
||||
zone.AddOrbit(orbit);
|
||||
|
|
@ -686,10 +686,10 @@ public class GameContext
|
|||
{
|
||||
public float Cost;
|
||||
public DijkstraNode Parent;
|
||||
public SimplifiedZoneData Zone;
|
||||
public ZoneDefinition Zone;
|
||||
}
|
||||
|
||||
public List<SimplifiedZoneData> FindPath(SimplifiedZoneData source, SimplifiedZoneData target, bool bestFirst = false)
|
||||
public List<ZoneDefinition> FindPath(ZoneDefinition source, ZoneDefinition target, bool bestFirst = false)
|
||||
{
|
||||
SortedList<float,DijkstraNode> members = new SortedList<float,DijkstraNode>{{0,new DijkstraNode{Zone = source}}};
|
||||
List<DijkstraNode> searched = new List<DijkstraNode>();
|
||||
|
|
@ -715,22 +715,6 @@ public class GameContext
|
|||
}
|
||||
}
|
||||
|
||||
public void SetParent(Entity child, Entity parent)
|
||||
{
|
||||
child.Parent = parent.ID;
|
||||
parent.AddChild(child);
|
||||
}
|
||||
|
||||
public void RemoveParent(Entity child)
|
||||
{
|
||||
if (child.Parent == Guid.Empty)
|
||||
return;
|
||||
|
||||
var parent = Cache.Get<Entity>(child.Parent);
|
||||
parent.RemoveChild(child);
|
||||
child.Parent = Guid.Empty;
|
||||
}
|
||||
|
||||
// public bool MoveCargo(Entity source, Entity target, ItemInstance item, int quantity = int.MaxValue)
|
||||
// {
|
||||
// if (item is CraftedItemInstance craftedItemInstance)
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ public class GlobalData : DatabaseEntry
|
|||
[InspectableField, JsonProperty("radiusPower"), Key(7)]
|
||||
public float RadiusPower = 1.75f;
|
||||
|
||||
[InspectableField, JsonProperty("massFloor"), Key(8)]
|
||||
[InspectableField, JsonProperty("massFloor"), Key(8)]
|
||||
public float MassFloor = 1;
|
||||
|
||||
[InspectableField, JsonProperty("sunMass"), Key(9)]
|
||||
|
|
@ -80,12 +80,6 @@ public class GlobalData : DatabaseEntry
|
|||
[InspectableField, JsonProperty("orbitPeriodMultiplier"), Key(23)]
|
||||
public float OrbitPeriodMultiplier = 1f;
|
||||
|
||||
[InspectableField, JsonProperty("gravityRadiusExponent"), Key(24)]
|
||||
public float GravityRadiusExponent = 1.5f;
|
||||
|
||||
[InspectableField, JsonProperty("gravityRadiusMultiplier"), Key(25)]
|
||||
public float GravityRadiusMultiplier = 1f;
|
||||
|
||||
[InspectableField, JsonProperty("beltProbability"), Key(26)]
|
||||
public float BeltProbability = .05f;
|
||||
|
||||
|
|
@ -115,9 +109,6 @@ public class GlobalData : DatabaseEntry
|
|||
|
||||
[InspectableField, JsonProperty("warpDistance"), Key(35)]
|
||||
public float WarpDistance = 25;
|
||||
|
||||
[InspectableField, JsonProperty("orbitSpeedMultiplier"), Key(36)]
|
||||
public float OrbitSpeedMultiplier = .25f;
|
||||
|
||||
[InspectableField, JsonProperty("targetPersistenceDuration"), Key(37)]
|
||||
public float TargetPersistenceDuration = 3;
|
||||
|
|
@ -171,11 +162,6 @@ public class GlobalData : DatabaseEntry
|
|||
{
|
||||
return pow(mass, 1 / RadiusPower);
|
||||
}
|
||||
|
||||
public float OrbitalPeriod(float distance)
|
||||
{
|
||||
return pow(distance, OrbitPeriodExponent) * OrbitPeriodMultiplier;
|
||||
}
|
||||
}
|
||||
|
||||
[Inspectable, Serializable, RethinkTable("Galaxy"), MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
|
|
@ -223,14 +209,14 @@ public class GalaxyMapLayerData : DatabaseEntry, INamedEntry
|
|||
[InspectableField, JsonProperty("name"), Key(14)]
|
||||
public string Name;
|
||||
|
||||
public float Evaluate(float2 uv, GlobalData data)
|
||||
public float Evaluate(float2 uv, GalaxyShapeSettings settings)
|
||||
{
|
||||
float2 offset = -float2(.5f, .5f)+uv;
|
||||
float circle = (.5f-length(offset))*2;
|
||||
float angle = pow(length(offset)*2,data.TwistPower) * data.Twist;
|
||||
float angle = pow(length(offset)*2,settings.TwistExponent) * settings.Twist;
|
||||
float2 t = float2(offset.x*cos(angle) - offset.y*sin(angle), offset.x*sin(angle) + offset.y*cos(angle));
|
||||
float atan = atan2(t.y,t.x);
|
||||
float spokes = (sin(atan*data.Arms) + SpokeOffset) * SpokeScale;
|
||||
float spokes = (sin(atan*settings.Arms) + SpokeOffset) * SpokeScale;
|
||||
float noise = fBm(uv + float2(NoisePosition), NoiseOctaves, NoiseFrequency, NoiseOffset, NoiseAmplitude, NoiseLacunarity, NoiseGain);
|
||||
float shape = lerp(spokes - EdgeReduction * length(offset), 1, pow(circle, CoreBoostPower) * CoreBoost) + CoreBoostOffset;
|
||||
float gal = max(shape - noise * saturate(circle), 0);
|
||||
|
|
|
|||
|
|
@ -94,13 +94,13 @@ public class GalaxyRequestMessage : Message
|
|||
[MessagePackObject]
|
||||
public class GalaxyResponseMessage : Message
|
||||
{
|
||||
[Key(0)] public SimplifiedZoneData[] Zones;
|
||||
[Key(0)] public ZoneDefinition[] Zones;
|
||||
[Key(1)] public GalaxyMapLayerData StarDensity;
|
||||
[Key(2)] public GlobalData GlobalData;
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public class SimplifiedZoneData
|
||||
public class ZoneDefinition
|
||||
{
|
||||
[Key(0)] public Guid ZoneID;
|
||||
[Key(1)] public Guid[] Links;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using MessagePack;
|
||||
using MessagePack.ReactivePropertyExtension;
|
||||
using MessagePack.Resolvers;
|
||||
|
||||
public static class RegisterResolver
|
||||
|
|
@ -15,7 +16,8 @@ public static class RegisterResolver
|
|||
MathResolver.Instance,
|
||||
TypeResolver.Instance,
|
||||
NativeGuidResolver.Instance,
|
||||
StandardResolver.Instance
|
||||
StandardResolver.Instance,
|
||||
ReactivePropertyResolver.Instance
|
||||
);
|
||||
var options = MessagePackSerializerOptions.Standard.WithResolver(resolver);
|
||||
MessagePackSerializer.DefaultOptions = options;
|
||||
|
|
|
|||
67
Assets/Scripts/ServerShared/Settings.cs
Normal file
67
Assets/Scripts/ServerShared/Settings.cs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[Serializable, MessagePackObject(keyAsPropertyName:true), JsonObject]
|
||||
public class PlanetSettings
|
||||
{
|
||||
public ExponentialCurve GravityDepth;
|
||||
public ExponentialCurve GravityRadius;
|
||||
public ExponentialCurve WaveDepth;
|
||||
public ExponentialCurve WaveRadius;
|
||||
public ExponentialCurve WaveFrequency;
|
||||
public ExponentialCurve WaveSpeed;
|
||||
public ExponentialCurve FogTintRadius;
|
||||
public ExponentialCurve LightRadius;
|
||||
public ExponentialCurve BodyRadius;
|
||||
public ExponentialLerp AsteroidSize;
|
||||
public ExponentialLerp AsteroidHitpoints;
|
||||
public ExponentialLerp AsteroidRespawnTime;
|
||||
public float GravityStrength;
|
||||
public float MiningDifficulty = 500f;
|
||||
|
||||
public ExponentialCurve OrbitPeriod;
|
||||
}
|
||||
|
||||
[Serializable, MessagePackObject(keyAsPropertyName:true), JsonObject]
|
||||
public class GalaxyShapeSettings
|
||||
{
|
||||
public int Arms = 4;
|
||||
public float Twist = 10;
|
||||
public float TwistExponent = 2;
|
||||
}
|
||||
|
||||
[Serializable, MessagePackObject(keyAsPropertyName:true), JsonObject]
|
||||
public class ZoneGenerationSettings
|
||||
{
|
||||
public GalaxyShapeSettings ShapeSettings;
|
||||
|
||||
public ExponentialCurve PlanetSafetyRadius;
|
||||
|
||||
public float MassFloor = 1;
|
||||
public float SunMass = 10000;
|
||||
public float GasGiantMass = 2000;
|
||||
public float PlanetMass = 100f;
|
||||
|
||||
public int SatellitePasses = 4;
|
||||
public float SatelliteCreationMassFloor = 100;
|
||||
public float SatelliteCreationProbability = .25f;
|
||||
public float BinaryCreationProbability = .25f;
|
||||
public float RosetteProbability = .25f;
|
||||
|
||||
public ExponentialLerp ZoneRadius;
|
||||
public ExponentialLerp ZoneMass;
|
||||
|
||||
public float BeltProbability = .05f;
|
||||
public float BeltMassCeiling = 500f;
|
||||
|
||||
public ExponentialCurve AsteroidCount;
|
||||
public ExponentialLerp AsteroidRotationSpeed;
|
||||
|
||||
public float ResourceDensityMinimum = .1f;
|
||||
public float ResourceDensityMaximum = 1.5f;
|
||||
}
|
||||
11
Assets/Scripts/ServerShared/Settings.cs.meta
Normal file
11
Assets/Scripts/ServerShared/Settings.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1f6f6d13d38104545bd2a9bc42773ad3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -2,45 +2,64 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UniRx;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
using float2 = Unity.Mathematics.float2;
|
||||
using Random = Unity.Mathematics.Random;
|
||||
|
||||
public class Zone
|
||||
{
|
||||
public float ZoneDepth;
|
||||
public float ZoneDepthExponent;
|
||||
public float ZoneDepthRadius;
|
||||
public GravitySettings GravitySettings;
|
||||
//public HashSet<Guid> Planets = new HashSet<Guid>();
|
||||
public Dictionary<Guid, Entity> Entities = new Dictionary<Guid, Entity>();
|
||||
//public Dictionary<Guid, OrbitData> Orbits = new Dictionary<Guid, OrbitData>();
|
||||
public Dictionary<Guid, BodyData> Planets = new Dictionary<Guid, BodyData>();
|
||||
public Dictionary<Guid, Planet> PlanetInstances = new Dictionary<Guid, Planet>();
|
||||
|
||||
public Dictionary<Guid, Orbit> Orbits = new Dictionary<Guid, Orbit>();
|
||||
public Dictionary<Guid, AsteroidBelt> AsteroidBelts = new Dictionary<Guid, AsteroidBelt>();
|
||||
|
||||
private HashSet<Guid> _updatedOrbits;
|
||||
|
||||
private GameContext _context;
|
||||
private PlanetSettings _settings;
|
||||
private float _time;
|
||||
private Random _random;
|
||||
|
||||
public ZoneData Data { get; }
|
||||
|
||||
public Zone(GameContext context, ZonePack pack)
|
||||
public Zone(PlanetSettings settings, ZonePack pack)
|
||||
{
|
||||
Data = pack.Data;
|
||||
_context = context;
|
||||
_settings = settings;
|
||||
_random = new Random(Convert.ToUInt32(abs(Data.ID.GetHashCode())));
|
||||
|
||||
foreach (var orbit in pack.Orbits)
|
||||
{
|
||||
Orbits.Add(orbit.ID, new Orbit(orbit));
|
||||
Orbits.Add(orbit.ID, new Orbit(_settings, orbit));
|
||||
}
|
||||
foreach (var planet in pack.Planets) Planets.Add(planet.ID, planet);
|
||||
|
||||
foreach (var planet in pack.Planets)
|
||||
{
|
||||
Planets.Add(planet.ID, planet);
|
||||
switch (planet)
|
||||
{
|
||||
case AsteroidBeltData belt:
|
||||
AsteroidBelts[belt.ID] = new AsteroidBelt(belt.Asteroids.Length);
|
||||
break;
|
||||
case GasGiantData gas:
|
||||
PlanetInstances.Add(gas.ID, new GasGiant(settings, gas));
|
||||
break;
|
||||
default:
|
||||
PlanetInstances.Add(planet.ID, new Planet(settings, planet));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var entity in pack.Entities) Entities.Add(entity.ID, entity);
|
||||
|
||||
foreach (var belt in pack.Planets.Where(p => p is AsteroidBeltData).Cast<AsteroidBeltData>())
|
||||
AsteroidBelts[belt.ID] = new AsteroidBelt(belt.Asteroids.Length);
|
||||
|
||||
// TODO: Associate planets with stored entities for planetary colonies
|
||||
}
|
||||
|
||||
|
|
@ -57,11 +76,12 @@ public class Zone
|
|||
|
||||
public void AddOrbit(OrbitData orbit)
|
||||
{
|
||||
Orbits.Add(orbit.ID, new Orbit(orbit));
|
||||
Orbits.Add(orbit.ID, new Orbit(_settings, orbit));
|
||||
}
|
||||
|
||||
public void Update(float deltaTime)
|
||||
public void Update(float time, float deltaTime)
|
||||
{
|
||||
_time = time;
|
||||
_updatedOrbits = new HashSet<Guid>();
|
||||
foreach (var orbit in Orbits)
|
||||
{
|
||||
|
|
@ -76,40 +96,40 @@ public class Zone
|
|||
foreach (var entity in Entities.Values) entity.Update(deltaTime);
|
||||
}
|
||||
|
||||
public float2 WormholePosition(Guid target)
|
||||
public float2 WormholePosition(ZoneDefinition target)
|
||||
{
|
||||
var direction = _context.Cache.Get<ZoneData>(target).Position - Data.Position;
|
||||
var direction = target.Position - Data.Position;
|
||||
return normalize(direction) * Data.Radius * .95f;
|
||||
}
|
||||
|
||||
// Determine orbital position recursively, caching parent positions to avoid repeated calculations
|
||||
public float2 GetOrbitPosition(Guid orbit)
|
||||
public float2 GetOrbitPosition(Guid orbitID)
|
||||
{
|
||||
// Root orbit is fixed at center
|
||||
if(orbit==Guid.Empty)
|
||||
// Root orbit is fixed at origin
|
||||
if(orbitID==Guid.Empty)
|
||||
return float2.zero;
|
||||
|
||||
if (!_updatedOrbits.Contains(orbit))
|
||||
if (!_updatedOrbits.Contains(orbitID))
|
||||
{
|
||||
var orbitData = Orbits[orbit].Data;
|
||||
var orbit = Orbits[orbitID];
|
||||
float2 pos = float2.zero;
|
||||
if (orbitData.Period > .01f)
|
||||
if (orbit.Period.Value > .01f)
|
||||
{
|
||||
var phase = (float) frac(_context.Time / orbitData.Period * _context.GlobalData.OrbitSpeedMultiplier);
|
||||
pos = OrbitData.Evaluate(frac(phase + orbitData.Phase)) * orbitData.Distance;
|
||||
var phase = (float) frac(_time / orbit.Period.Value);
|
||||
pos = OrbitData.Evaluate(frac(phase + orbit.Data.Phase)) * orbit.Data.Distance.Value;
|
||||
|
||||
if (float.IsNaN(pos.x))
|
||||
{
|
||||
_context.Log("Orbit position is NaN, something went very wrong!");
|
||||
//_context.Log("Orbit position is NaN, something went very wrong!");
|
||||
pos = float2.zero;
|
||||
}
|
||||
}
|
||||
|
||||
_updatedOrbits.Add(orbit);
|
||||
return GetOrbitPosition(orbitData.Parent) + pos;
|
||||
_updatedOrbits.Add(orbitID);
|
||||
return GetOrbitPosition(orbit.Data.Parent) + pos;
|
||||
}
|
||||
|
||||
return Orbits[orbit].Position;
|
||||
return Orbits[orbitID].Position;
|
||||
}
|
||||
|
||||
public float2 GetOrbitVelocity(Guid orbit)
|
||||
|
|
@ -169,20 +189,20 @@ public class Zone
|
|||
var orbitPosition = GetOrbitPosition(orbitData.Parent);
|
||||
for (var i = 0; i < beltData.Asteroids.Length; i++)
|
||||
{
|
||||
var size = beltData.Asteroids[i].Size;
|
||||
float size;
|
||||
if(belt.RespawnTimers.ContainsKey(i)) size = 0;
|
||||
else if (belt.Damage.ContainsKey(i))
|
||||
{
|
||||
var hpLerp = unlerp(_context.GlobalData.AsteroidSizeMin, _context.GlobalData.AsteroidSizeMax, size);
|
||||
var asteroidHitpoints = lerp(_context.GlobalData.AsteroidHitpointsMin, _context.GlobalData.AsteroidHitpointsMax, pow(hpLerp, _context.GlobalData.AsteroidHitpointsPower));
|
||||
var sizeLerp = (asteroidHitpoints - belt.Damage[i]) / asteroidHitpoints;
|
||||
size = lerp(_context.GlobalData.AsteroidSizeMin, size, sizeLerp);
|
||||
var asteroidHitpoints = _settings.AsteroidHitpoints.Evaluate(beltData.Asteroids[i].Size);
|
||||
var damage = (asteroidHitpoints - belt.Damage[i]) / asteroidHitpoints;
|
||||
size = _settings.AsteroidSize.Evaluate(damage * beltData.Asteroids[i].Size);
|
||||
}
|
||||
else size = _settings.AsteroidSize.Evaluate(beltData.Asteroids[i].Size);
|
||||
|
||||
belt.Transforms[i] = float4(
|
||||
OrbitData.Evaluate((float) frac(_context.Time / _context.GlobalData.OrbitalPeriod(beltData.Asteroids[i].Distance) * _context.GlobalData.OrbitSpeedMultiplier +
|
||||
OrbitData.Evaluate((float) frac(_time / _settings.OrbitPeriod.Evaluate(beltData.Asteroids[i].Distance) +
|
||||
beltData.Asteroids[i].Phase)) * beltData.Asteroids[i].Distance + orbitPosition,
|
||||
(float) (_context.Time * beltData.Asteroids[i].RotationSpeed % (PI * 2)), size);
|
||||
(float) (_time * beltData.Asteroids[i].RotationSpeed % (PI * 2)), size);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -191,30 +211,29 @@ public class Zone
|
|||
var parentPosition = GetOrbitPosition(parent);
|
||||
var delta = position - parentPosition;
|
||||
var distance = length(delta);
|
||||
var period = _context.GlobalData.OrbitalPeriod(distance);
|
||||
var period = _settings.OrbitPeriod.Evaluate(distance);
|
||||
var phase = atan2(delta.y, delta.x) / (PI * 2);
|
||||
var currentPhase = frac(_context.Time / period * _context.GlobalData.OrbitSpeedMultiplier);
|
||||
var currentPhase = frac(_time / period);
|
||||
var storedPhase = (float) frac(phase - currentPhase);
|
||||
|
||||
var orbit = new OrbitData
|
||||
{
|
||||
Context = _context,
|
||||
Distance = distance,
|
||||
Distance = new ReactiveProperty<float>(distance),
|
||||
Parent = parent,
|
||||
Period = period,
|
||||
Phase = storedPhase
|
||||
};
|
||||
Orbits.Add(orbit.ID, new Orbit(orbit));
|
||||
Orbits.Add(orbit.ID, new Orbit(_settings, orbit));
|
||||
return orbit;
|
||||
}
|
||||
|
||||
public void MineAsteroid(Entity miner, Guid asteroidBelt, int asteroid, float damage, float efficiency, float penetration)
|
||||
{
|
||||
var planetData = Planets[asteroidBelt];
|
||||
var beltData = Planets[asteroidBelt] as AsteroidBeltData;
|
||||
var belt = AsteroidBelts[asteroidBelt];
|
||||
var asteroidTransform = belt.Transforms[asteroid];
|
||||
var hpLerp = unlerp(_context.GlobalData.AsteroidSizeMin, _context.GlobalData.AsteroidSizeMax, asteroidTransform.w);
|
||||
var asteroidHitpoints = lerp(_context.GlobalData.AsteroidHitpointsMin, _context.GlobalData.AsteroidHitpointsMax, pow(hpLerp, _context.GlobalData.AsteroidHitpointsPower));
|
||||
|
||||
var size = beltData.Asteroids[asteroid].Size;
|
||||
var asteroidHitpoints = _settings.AsteroidHitpoints.Evaluate(size);
|
||||
|
||||
if (!belt.Damage.ContainsKey(asteroid))
|
||||
belt.Damage[asteroid] = 0;
|
||||
|
|
@ -226,53 +245,48 @@ public class Zone
|
|||
|
||||
if (belt.Damage[asteroid] > asteroidHitpoints)
|
||||
{
|
||||
belt.RespawnTimers[asteroid] =
|
||||
lerp(_context.GlobalData.AsteroidRespawnMin, _context.GlobalData.AsteroidRespawnMax, hpLerp);
|
||||
belt.RespawnTimers[asteroid] = _settings.AsteroidRespawnTime.Evaluate(size);
|
||||
belt.Damage.Remove(asteroid);
|
||||
belt.MiningAccumulator.Remove((miner.ID, asteroid));
|
||||
return;
|
||||
}
|
||||
|
||||
var resourceCount = planetData.Resources.Sum(x => x.Value);
|
||||
var resource = planetData.Resources.MaxBy(x => pow(x.Value, 1f / penetration) * _context.Random.NextFloat());
|
||||
if (efficiency * _context.Random.NextFloat() * belt.MiningAccumulator[(miner.ID, asteroid)] * resourceCount / _context.GlobalData.MiningDifficulty > 1 && miner.OccupiedCapacity < miner.Capacity - 1)
|
||||
var resourceCount = beltData.Resources.Sum(x => x.Value);
|
||||
var resource = beltData.Resources.MaxBy(x => pow(x.Value, 1f / penetration) * _random.NextFloat());
|
||||
if (efficiency * _random.NextFloat() * belt.MiningAccumulator[(miner.ID, asteroid)] * resourceCount / _settings.MiningDifficulty > 1 && miner.OccupiedCapacity < miner.Capacity - 1)
|
||||
{
|
||||
belt.MiningAccumulator.Remove((miner.ID, asteroid));
|
||||
var newSimpleCommodity = new SimpleCommodity
|
||||
{
|
||||
Context = _context,
|
||||
Data = resource.Key,
|
||||
Quantity = 1
|
||||
};
|
||||
_context.Cache.Add(newSimpleCommodity);
|
||||
miner.AddCargo(newSimpleCommodity);
|
||||
}
|
||||
}
|
||||
public float GetHeight(float2 position)
|
||||
{
|
||||
float result = -PowerPulse(length(position)/ZoneDepthRadius, ZoneDepthExponent) * ZoneDepth;
|
||||
foreach (var body in Planets.Values)
|
||||
foreach (var body in PlanetInstances.Values)
|
||||
{
|
||||
if (body is AsteroidBeltData) continue;
|
||||
|
||||
var p = (position - GetOrbitPosition(body.Orbit));
|
||||
var p = (position - GetOrbitPosition(body.BodyData.Orbit));
|
||||
var dist = length(p);
|
||||
var gravityRadius = GravitySettings.GravityRadius.Evaluate(body.Mass.Value) * body.GravityRadiusMultiplier.Value;
|
||||
var gravityRadius = body.GravityWellRadius.Value;
|
||||
if (dist < gravityRadius)
|
||||
{
|
||||
var depth = GravitySettings.GravityDepth.Evaluate(body.Mass.Value) * body.GravityDepthMultiplier.Value;
|
||||
result -= PowerPulse(dist / gravityRadius, body.GravityDepthExponent.Value) * depth;
|
||||
var depth = body.GravityWellDepth.Value;
|
||||
result -= PowerPulse(dist / gravityRadius, body.BodyData.GravityDepthExponent.Value) * depth;
|
||||
}
|
||||
|
||||
if (body is GasGiantData)
|
||||
if (body is GasGiant gas)
|
||||
{
|
||||
var waveRadius = GravitySettings.WaveRadius.Evaluate(body.Mass.Value) * body.GravityRadiusMultiplier.Value;
|
||||
var waveRadius = gas.GravityWavesRadius.Value;
|
||||
if(dist < waveRadius)
|
||||
{
|
||||
var depth = GravitySettings.WaveDepth.Evaluate(body.Mass.Value) * body.GravityDepthMultiplier.Value;
|
||||
var frequency = GravitySettings.WaveFrequency.Evaluate(body.Mass.Value);
|
||||
var speed = GravitySettings.WaveSpeed.Evaluate(body.Mass.Value);
|
||||
result -= RadialWaves(dist / gravityRadius, 8, 1.5f, frequency, (float) (_context.Time * speed)) * depth;
|
||||
var depth = gas.GravityWavesDepth.Value;
|
||||
var frequency = _settings.WaveFrequency.Evaluate(body.BodyData.Mass.Value);
|
||||
var speed = _settings.WaveSpeed.Evaluate(body.BodyData.Mass.Value);
|
||||
result -= RadialWaves(dist / waveRadius, 8, 1.5f, frequency, _time * speed) * depth;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -284,17 +298,19 @@ public class Zone
|
|||
{
|
||||
var normal = GetNormal(position);
|
||||
var f = new float2(normal.x, normal.z);
|
||||
return f * GravitySettings.GravityStrength * lengthsq(f);// * Mathf.Abs(GetHeight(position));
|
||||
return f * _settings.GravityStrength * lengthsq(f);// * Mathf.Abs(GetHeight(position));
|
||||
}
|
||||
|
||||
public static float PowerPulse(float x, float exponent)
|
||||
{
|
||||
x *= 2;
|
||||
x = clamp(x, -1, 1);
|
||||
return pow((x + 1) * (1 - x), exponent);
|
||||
}
|
||||
|
||||
public static float RadialWaves(float x, float maskExponent, float sineExponent, float frequency, float phase)
|
||||
{
|
||||
x *= 2;
|
||||
return PowerPulse(x, maskExponent) * cos(pow(x, sineExponent) * frequency + phase);
|
||||
}
|
||||
|
||||
|
|
@ -322,6 +338,55 @@ public class Zone
|
|||
}
|
||||
}
|
||||
|
||||
public class Planet
|
||||
{
|
||||
public BodyData BodyData;
|
||||
public ReadOnlyReactiveProperty<float> GravityWellDepth;
|
||||
public ReadOnlyReactiveProperty<float> GravityWellRadius;
|
||||
public ReadOnlyReactiveProperty<float> BodyRadius;
|
||||
|
||||
public Planet(PlanetSettings settings, BodyData data)
|
||||
{
|
||||
BodyData = data;
|
||||
BodyRadius = new ReadOnlyReactiveProperty<float>(
|
||||
data.Mass.CombineLatest(data.BodyRadiusMultiplier,
|
||||
(mass, radius) => settings.BodyRadius.Evaluate(mass) * radius));
|
||||
GravityWellRadius = new ReadOnlyReactiveProperty<float>(
|
||||
data.Mass.CombineLatest(data.GravityRadiusMultiplier,
|
||||
(mass, radius) => settings.GravityRadius.Evaluate(mass) * radius));
|
||||
GravityWellDepth = new ReadOnlyReactiveProperty<float>(
|
||||
data.Mass.CombineLatest(data.GravityDepthMultiplier,
|
||||
(mass, depth) => settings.GravityDepth.Evaluate(mass) * depth));
|
||||
}
|
||||
}
|
||||
|
||||
public class GasGiant : Planet
|
||||
{
|
||||
public GasGiantData GasGiantData;
|
||||
public ReadOnlyReactiveProperty<float> GravityWavesDepth;
|
||||
public ReadOnlyReactiveProperty<float> GravityWavesRadius;
|
||||
public ReadOnlyReactiveProperty<float> GravityWavesSpeed;
|
||||
|
||||
public GasGiant(PlanetSettings settings, GasGiantData data) : base(settings, data)
|
||||
{
|
||||
GasGiantData = data;
|
||||
GravityWavesDepth = new ReadOnlyReactiveProperty<float>(
|
||||
data.Mass.CombineLatest(data.WaveDepthMultiplier,
|
||||
(mass, depth) => settings.WaveDepth.Evaluate(mass) * depth));
|
||||
GravityWavesRadius = new ReadOnlyReactiveProperty<float>(
|
||||
data.Mass.CombineLatest(data.WaveRadiusMultiplier,
|
||||
(mass, radius) => settings.WaveRadius.Evaluate(mass) * radius));
|
||||
GravityWavesSpeed = new ReadOnlyReactiveProperty<float>(
|
||||
data.Mass.CombineLatest(data.WaveSpeedMultiplier,
|
||||
(mass, speed) => settings.WaveSpeed.Evaluate(mass) * speed));
|
||||
}
|
||||
}
|
||||
|
||||
// public class Sun : GasGiant
|
||||
// {
|
||||
//
|
||||
// }
|
||||
|
||||
public class AsteroidBelt
|
||||
{
|
||||
public float4[] Transforms; // x, y, rotation, scale
|
||||
|
|
@ -343,9 +408,11 @@ public class Orbit
|
|||
public float2 Velocity = float2.zero;
|
||||
public float2 Position = float2.zero;
|
||||
public float2 PreviousPosition = float2.zero;
|
||||
public ReadOnlyReactiveProperty<float> Period;
|
||||
|
||||
public Orbit(OrbitData data)
|
||||
public Orbit(PlanetSettings settings, OrbitData data)
|
||||
{
|
||||
Data = data;
|
||||
Period = new ReadOnlyReactiveProperty<float>(data.Distance.Select(f => settings.OrbitPeriod.Evaluate(f)));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,13 +116,16 @@ public abstract class BodyData : DatabaseEntry, INamedEntry
|
|||
[JsonProperty("resources"), Key(4)]
|
||||
public Dictionary<Guid, float> Resources = new Dictionary<Guid, float>();
|
||||
|
||||
[JsonProperty("radiusMul")] [Key(5)]
|
||||
[JsonProperty("bodyRadiusMul")] [Key(5)]
|
||||
public ReactiveProperty<float> BodyRadiusMultiplier = new ReactiveProperty<float>(1);
|
||||
|
||||
[JsonProperty("gravRadiusMul")] [Key(6)]
|
||||
public ReactiveProperty<float> GravityRadiusMultiplier = new ReactiveProperty<float>(1);
|
||||
|
||||
[JsonProperty("depthMul")] [Key(6)]
|
||||
[JsonProperty("depthMul")] [Key(7)]
|
||||
public ReactiveProperty<float> GravityDepthMultiplier = new ReactiveProperty<float>(1);
|
||||
|
||||
[JsonProperty("depthExp")] [Key(7)]
|
||||
[JsonProperty("depthExp")] [Key(8)]
|
||||
public ReactiveProperty<float> GravityDepthExponent = new ReactiveProperty<float>(8);
|
||||
|
||||
[IgnoreMember] public string EntryName
|
||||
|
|
@ -141,50 +144,69 @@ public class PlanetData : BodyData
|
|||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class AsteroidBeltData : BodyData
|
||||
{
|
||||
[JsonProperty("asteroids"), Key(8)]
|
||||
[JsonProperty("asteroids"), Key(9)]
|
||||
public Asteroid[] Asteroids;
|
||||
}
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class GasGiantData : BodyData
|
||||
{
|
||||
[JsonProperty("firstOffsetDomainRotationSpeed"), Key(8)]
|
||||
[JsonProperty("firstOffsetDomainRotationSpeed"), Key(9)]
|
||||
public ReactiveProperty<float> FirstOffsetDomainRotationSpeed = new ReactiveProperty<float>(1);
|
||||
|
||||
[JsonProperty("firstOffsetRotationSpeed"), Key(9)]
|
||||
[JsonProperty("firstOffsetRotationSpeed"), Key(10)]
|
||||
public ReactiveProperty<float> FirstOffsetRotationSpeed = new ReactiveProperty<float>(1);
|
||||
|
||||
[JsonProperty("secondOffsetDomainRotationSpeed"), Key(10)]
|
||||
[JsonProperty("secondOffsetDomainRotationSpeed"), Key(11)]
|
||||
public ReactiveProperty<float> SecondOffsetDomainRotationSpeed = new ReactiveProperty<float>(1);
|
||||
|
||||
[JsonProperty("secondOffsetRotationSpeed"), Key(11)]
|
||||
[JsonProperty("secondOffsetRotationSpeed"), Key(12)]
|
||||
public ReactiveProperty<float> SecondOffsetRotationSpeed = new ReactiveProperty<float>(1);
|
||||
|
||||
[JsonProperty("albedoRotationSpeed"), Key(12)]
|
||||
[JsonProperty("albedoRotationSpeed"), Key(13)]
|
||||
public ReactiveProperty<float> AlbedoRotationSpeed = new ReactiveProperty<float>(1);
|
||||
|
||||
[JsonProperty("gravRadiusMul")] [Key(14)]
|
||||
public ReactiveProperty<float> WaveRadiusMultiplier = new ReactiveProperty<float>(1);
|
||||
|
||||
[JsonProperty("depthMul")] [Key(15)]
|
||||
public ReactiveProperty<float> WaveDepthMultiplier = new ReactiveProperty<float>(1);
|
||||
|
||||
[JsonProperty("depthExp")] [Key(16)]
|
||||
public ReactiveProperty<float> WaveDepthExponent = new ReactiveProperty<float>(8);
|
||||
|
||||
[JsonProperty("depthExp")] [Key(17)]
|
||||
public ReactiveProperty<float> WaveSpeedMultiplier = new ReactiveProperty<float>(8);
|
||||
|
||||
[JsonProperty("materialOverrides"), Key(13)]
|
||||
[JsonProperty("materialOverrides"), Key(18)]
|
||||
public List<string> MaterialOverrides = new List<string>();
|
||||
|
||||
[JsonProperty("colors"), Key(14)]
|
||||
[JsonProperty("colors"), Key(19)]
|
||||
public ReactiveProperty<float4[]> Colors = new ReactiveProperty<float4[]>();
|
||||
}
|
||||
|
||||
public class SunData : GasGiantData
|
||||
{
|
||||
[JsonProperty("lightColor"), Key(15)]
|
||||
[JsonProperty("lightColor"), Key(20)]
|
||||
public ReactiveProperty<float3> LightColor = new ReactiveProperty<float3>(float3.zero);
|
||||
|
||||
[JsonProperty("fogTintColor"), Key(16)]
|
||||
[JsonProperty("fogTintColor"), Key(21)]
|
||||
public ReactiveProperty<float3> FogTintColor = new ReactiveProperty<float3>(float3.zero);
|
||||
}
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class Asteroid
|
||||
{
|
||||
[JsonProperty("distance"), Key(0)]
|
||||
public float Distance;
|
||||
|
||||
[JsonProperty("phase"), Key(1)]
|
||||
public float Phase;
|
||||
|
||||
[JsonProperty("size"), Key(2)]
|
||||
public float Size;
|
||||
|
||||
[JsonProperty("rotationSpeed"), Key(3)]
|
||||
public float RotationSpeed;
|
||||
}
|
||||
|
||||
|
|
@ -195,13 +217,13 @@ public class OrbitData : DatabaseEntry
|
|||
public Guid Parent;
|
||||
|
||||
[JsonProperty("distance"), Key(2)]
|
||||
public float Distance;
|
||||
public ReactiveProperty<float> Distance;
|
||||
|
||||
[JsonProperty("phase"), Key(3)]
|
||||
public float Phase;
|
||||
|
||||
[JsonProperty("period"), Key(4)]
|
||||
public float Period;
|
||||
|
||||
// [JsonProperty("period"), Key(4)]
|
||||
// public float Period;
|
||||
|
||||
public static float2 Evaluate(float phase)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using MessagePack;
|
||||
using UniRx;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
using Random = Unity.Mathematics.Random;
|
||||
|
|
@ -11,13 +12,42 @@ using Random = Unity.Mathematics.Random;
|
|||
public class ZoneGenerator
|
||||
{
|
||||
public static ZonePack GenerateZone(
|
||||
GameContext context,
|
||||
ZoneGenerationSettings settings,
|
||||
Dictionary<string,GalaxyMapLayerData> mapLayers,
|
||||
IEnumerable<SimpleCommodityData> resources,
|
||||
string name,
|
||||
float2 position)
|
||||
{
|
||||
var random = new Random(Convert.ToUInt32(abs(name.GetHashCode())));
|
||||
var radius = settings.ZoneRadius.Evaluate(random.NextFloat() * mapLayers["Radius"].Evaluate(position, settings.ShapeSettings));
|
||||
var mass = settings.ZoneMass.Evaluate(random.NextFloat() * mapLayers["Mass"].Evaluate(position, settings.ShapeSettings));
|
||||
|
||||
return GenerateZone(settings, mapLayers, resources, name, position, mass, radius, random);
|
||||
}
|
||||
|
||||
public static ZonePack GenerateZone(
|
||||
ZoneGenerationSettings settings,
|
||||
Dictionary<string,GalaxyMapLayerData> mapLayers,
|
||||
IEnumerable<SimpleCommodityData> resources,
|
||||
float mass,
|
||||
float radius)
|
||||
{
|
||||
var name = Guid.NewGuid().ToString().Substring(0, 8);
|
||||
var position = float2(0f);
|
||||
var random = new Random(Convert.ToUInt32(abs(name.GetHashCode())));
|
||||
|
||||
return GenerateZone(settings, mapLayers, resources, name, position, mass, radius, random);
|
||||
}
|
||||
|
||||
private static ZonePack GenerateZone(
|
||||
ZoneGenerationSettings settings,
|
||||
Dictionary<string,GalaxyMapLayerData> mapLayers,
|
||||
IEnumerable<SimpleCommodityData> resources,
|
||||
string name,
|
||||
float2 position,
|
||||
IEnumerable<GalaxyMapLayerData> mapLayers,
|
||||
IEnumerable<SimpleCommodityData> resources,
|
||||
float mass = 0,
|
||||
float radius = 0)
|
||||
float mass,
|
||||
float radius,
|
||||
Random random)
|
||||
{
|
||||
var zone = new ZoneData
|
||||
{
|
||||
|
|
@ -30,33 +60,12 @@ public class ZoneGenerator
|
|||
Data = zone
|
||||
};
|
||||
|
||||
var zoneRadius = radius != 0 ? radius : context.Random.NextPowerDistribution(
|
||||
context.GlobalData.MinimumZoneRadius,
|
||||
context.GlobalData.MaximumZoneRadius,
|
||||
context.GlobalData.ZoneRadiusExponent,
|
||||
1 / lerp(
|
||||
context.GlobalData.ResourceDensityMinimum,
|
||||
context.GlobalData.ResourceDensityMaximum,
|
||||
mapLayers
|
||||
.First(m => m.Name == "Radius")
|
||||
.Evaluate(zone.Position, context.GlobalData)));
|
||||
zone.Radius = zoneRadius;
|
||||
|
||||
var zoneMass = mass != 0 ? mass : context.Random.NextPowerDistribution(
|
||||
context.GlobalData.MinimumZoneMass,
|
||||
context.GlobalData.MaximumZoneMass,
|
||||
context.GlobalData.ZoneMassExponent,
|
||||
1 / lerp(
|
||||
context.GlobalData.ResourceDensityMinimum,
|
||||
context.GlobalData.ResourceDensityMaximum,
|
||||
mapLayers
|
||||
.First(m => m.Name == "Mass")
|
||||
.Evaluate(zone.Position, context.GlobalData)));
|
||||
zone.Mass = zoneMass;
|
||||
zone.Radius = radius;
|
||||
zone.Mass = mass;
|
||||
|
||||
//Debug.Log($"Generating zone at position {zone.Position} with radius {zoneRadius} and mass {zoneMass}");
|
||||
|
||||
var planets = GenerateEntities(context, zone, zoneMass, zoneRadius);
|
||||
var planets = GenerateEntities(settings, ref random, zone);
|
||||
|
||||
// Create collections to map between zone generator output and database entries
|
||||
var orbitMap = new Dictionary<GeneratorPlanet, OrbitData>();
|
||||
|
|
@ -67,8 +76,8 @@ public class ZoneGenerator
|
|||
{
|
||||
var data = new OrbitData
|
||||
{
|
||||
Distance = planet.Distance,
|
||||
Period = planet.Period,
|
||||
Distance = new ReactiveProperty<float>(planet.Distance),
|
||||
//Period = planet.Period,
|
||||
Phase = planet.Phase
|
||||
};
|
||||
orbitMap[planet] = data;
|
||||
|
|
@ -83,21 +92,22 @@ public class ZoneGenerator
|
|||
: Guid.Empty;
|
||||
|
||||
// Cache resource densities
|
||||
var resourceMaps = mapLayers.ToDictionary(m => m.ID, m => m.Evaluate(zone.Position, context.GlobalData));
|
||||
var resourceMaps = mapLayers.Values
|
||||
.ToDictionary(m => m.ID, m => m.Evaluate(zone.Position, settings.ShapeSettings));
|
||||
|
||||
pack.Planets = planets.Where(p=>!p.Empty).Select(planet =>
|
||||
{
|
||||
Dictionary<Guid, float> planetResources = new Dictionary<Guid, float>();
|
||||
BodyType 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;
|
||||
planet.Mass > settings.SunMass ? BodyType.Sun :
|
||||
planet.Mass > settings.GasGiantMass ? BodyType.GasGiant :
|
||||
planet.Mass > settings.PlanetMass ? BodyType.Planet : BodyType.Planetoid;
|
||||
|
||||
foreach (var r in resources)
|
||||
{
|
||||
if ((bodyType & r.ResourceBodyType) != 0)
|
||||
{
|
||||
float quantity = ResourceValue(r, context, r.ResourceDensity.Aggregate(1f, (m, rdm) => m * resourceMaps[rdm]));
|
||||
float quantity = ResourceValue(ref random, settings, r, r.ResourceDensity.Aggregate(1f, (m, rdm) => m * resourceMaps[rdm]));
|
||||
if (r.Floor < quantity) planetResources.Add(r.ID, quantity);
|
||||
}
|
||||
}
|
||||
|
|
@ -129,21 +139,21 @@ public class ZoneGenerator
|
|||
if (planetData is AsteroidBeltData beltData)
|
||||
{
|
||||
beltData.Asteroids =
|
||||
Enumerable.Range(0, (int) (pow(planetData.Mass.Value, context.GlobalData.BeltMassExponent) / context.GlobalData.BeltMassRatio * orbitMap[planet].Distance))
|
||||
Enumerable.Range(0, (int) (settings.AsteroidCount.Evaluate(beltData.Mass.Value * orbitMap[planet].Distance.Value)))
|
||||
.Select(_ => new Asteroid
|
||||
{
|
||||
Distance = context.Random.NextFloat(orbitMap[planet].Distance * .5f, orbitMap[planet].Distance * 1.5f),
|
||||
Phase = context.Random.NextFloat(),
|
||||
Size = pow(context.Random.NextFloat(), context.GlobalData.AsteroidSizeExponent) *
|
||||
(context.GlobalData.AsteroidSizeMax - context.GlobalData.AsteroidSizeMin) +
|
||||
context.GlobalData.AsteroidSizeMin,
|
||||
RotationSpeed = context.Random.NextFloat() * context.GlobalData.AsteroidRotationSpeed
|
||||
}).ToArray();
|
||||
Distance = random.NextFloat(orbitMap[planet].Distance.Value * .5f, orbitMap[planet].Distance.Value * 1.5f),
|
||||
Phase = random.NextFloat(),
|
||||
Size = random.NextFloat(),
|
||||
RotationSpeed = settings.AsteroidRotationSpeed.Evaluate(random.NextFloat())
|
||||
})
|
||||
//.OrderByDescending(a=>a.Size)
|
||||
.ToArray();
|
||||
}
|
||||
else if (planetData is GasGiantData gas)
|
||||
{
|
||||
var times = Enumerable.Range(0, 5).Select(i => (float) i / 4).ToArray();
|
||||
gas.Colors.Value = times.Select(time => float4(context.Random.NextFloat3(),time)).ToArray();
|
||||
gas.Colors.Value = times.Select(time => float4(random.NextFloat3(),time)).ToArray();
|
||||
gas.AlbedoRotationSpeed.Value = -3;
|
||||
gas.FirstOffsetRotationSpeed.Value = 5;
|
||||
gas.FirstOffsetDomainRotationSpeed.Value = 0;
|
||||
|
|
@ -151,7 +161,7 @@ public class ZoneGenerator
|
|||
gas.SecondOffsetDomainRotationSpeed.Value = -25;
|
||||
if (planetData is SunData sun)
|
||||
{
|
||||
sun.FogTintColor.Value = sun.LightColor.Value = context.Random.NextFloat3();
|
||||
sun.FogTintColor.Value = sun.LightColor.Value = random.NextFloat3();
|
||||
gas.FirstOffsetDomainRotationSpeed.Value = 5;
|
||||
}
|
||||
}
|
||||
|
|
@ -161,36 +171,34 @@ public class ZoneGenerator
|
|||
return pack;
|
||||
}
|
||||
|
||||
static float ResourceValue(SimpleCommodityData resource, GameContext context, float density)
|
||||
static float ResourceValue(ref Random random, ZoneGenerationSettings settings, SimpleCommodityData resource, float density)
|
||||
{
|
||||
return context.Random.NextPowerDistribution(resource.Minimum, resource.Maximum, resource.Exponent,
|
||||
1 / lerp(context.GlobalData.ResourceDensityMinimum, context.GlobalData.ResourceDensityMaximum, density));
|
||||
return random.NextPowerDistribution(resource.Minimum, resource.Maximum, resource.Exponent,
|
||||
1 / lerp(settings.ResourceDensityMinimum, settings.ResourceDensityMaximum, density));
|
||||
}
|
||||
|
||||
public static GeneratorPlanet[] GenerateEntities(GameContext context, ZoneData data, float mass, float radius)
|
||||
public static GeneratorPlanet[] GenerateEntities(ZoneGenerationSettings settings, ref Random random, ZoneData zone)
|
||||
{
|
||||
var random = new Random();
|
||||
random.InitState(unchecked((uint)data.Name.GetHashCode()));
|
||||
|
||||
var root = new GeneratorPlanet
|
||||
{
|
||||
Context = context,
|
||||
Mass = mass,
|
||||
ChildDistanceMaximum = radius * .75f,
|
||||
ChildDistanceMinimum = context.GlobalData.PlanetRadius(mass)
|
||||
Settings = settings,
|
||||
Mass = zone.Mass,
|
||||
ChildDistanceMaximum = zone.Radius * .75f,
|
||||
ChildDistanceMinimum = settings.PlanetSafetyRadius.Evaluate(zone.Mass)
|
||||
};
|
||||
|
||||
// There is some chance of generating a rosette or binary system
|
||||
// Probabilities which are fixed for the entire galaxy are in GlobalData, contained in the GameContext
|
||||
var rosette = random.NextFloat() < context.GlobalData.RosetteProbability;
|
||||
var rosette = random.NextFloat() < settings.RosetteProbability;
|
||||
|
||||
if (rosette)
|
||||
{
|
||||
// Create a rosette with a number of vertices between 2 and 9 inclusive
|
||||
root.ExpandRosette((int)(random.NextFloat(1, 5) + random.NextFloat(1, 5)));
|
||||
root.ExpandRosette(ref random, (int)(random.NextFloat(1, 5) + random.NextFloat(1, 5)));
|
||||
|
||||
// Create a small number of less massive "captured" planets orbiting past the rosette
|
||||
root.ExpandSolar(
|
||||
ref random,
|
||||
count: (int)(random.NextFloat(1, 3) * random.NextFloat(1, 2)),
|
||||
massMulMin: .6f,
|
||||
massMulMax: .8f,
|
||||
|
|
@ -200,11 +208,12 @@ public class ZoneGenerator
|
|||
massFraction: .1f);
|
||||
|
||||
var averageChildMass = root.Children.Sum(p => p.Mass) / root.Children.Count;
|
||||
foreach(var p in root.Children.Where(c=>c.Mass>context.GlobalData.GasGiantMass))
|
||||
foreach(var p in root.Children.Where(c=>c.Mass>settings.GasGiantMass))
|
||||
{
|
||||
var m = p.Mass / averageChildMass;
|
||||
// Give each child in the rosette its own mini solar system
|
||||
p.ExpandSolar(
|
||||
ref random,
|
||||
count: (int) (random.NextFloat(1, 3 * m) + random.NextFloat(1, 3 * m)),
|
||||
massMulMin: 0.75f,
|
||||
massMulMax: 2.5f,
|
||||
|
|
@ -219,6 +228,7 @@ public class ZoneGenerator
|
|||
{
|
||||
// Create a regular old boring solar system
|
||||
root.ExpandSolar(
|
||||
ref random,
|
||||
count: random.NextInt(5, 15),
|
||||
massMulMin: 0.5f,
|
||||
massMulMax: 2.0f,
|
||||
|
|
@ -229,43 +239,65 @@ 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 != root && p.Parent != root && p.Mass > context.GlobalData.SatelliteCreationMassFloor)
|
||||
: root.AllPlanets().Where(p => p != root && p.Mass > context.GlobalData.SatelliteCreationMassFloor);
|
||||
|
||||
var alreadyExpanded = new List<GeneratorPlanet>();
|
||||
var binaries = new List<GeneratorPlanet>();
|
||||
foreach (var planet in satelliteCandidates)
|
||||
for(int i=0; i<settings.SatellitePasses; i++)
|
||||
{
|
||||
// There's a chance of generating satellites for each qualified planet
|
||||
if (random.NextFloat() < context.GlobalData.SatelliteCreationProbability)
|
||||
// Get all children that are above the satellite creation mass floor and not rosette members
|
||||
var satelliteCandidates = rosette
|
||||
? root.AllPlanets().Where(p =>
|
||||
p != root &&
|
||||
p.Parent != root &&
|
||||
p.Mass > settings.SatelliteCreationMassFloor &&
|
||||
!alreadyExpanded.Contains(p))
|
||||
: root.AllPlanets().Where(p =>
|
||||
p != root &&
|
||||
p.Mass > settings.SatelliteCreationMassFloor &&
|
||||
!alreadyExpanded.Contains(p));
|
||||
|
||||
foreach (var planet in satelliteCandidates)
|
||||
{
|
||||
// Sometimes the satellite is so massive that it forms a binary system (like Earth!)
|
||||
if (random.NextFloat() < context.GlobalData.BinaryCreationProbability)
|
||||
// There's a chance of generating satellites for each qualified planet
|
||||
if (random.NextFloat() < settings.SatelliteCreationProbability)
|
||||
{
|
||||
planet.ExpandRosette(2);
|
||||
binaries.AddRange(planet.Children);
|
||||
// Sometimes the satellite is so massive that it forms a binary system (like Earth!)
|
||||
if (random.NextFloat() < settings.BinaryCreationProbability)
|
||||
{
|
||||
planet.ExpandRosette(ref random, 2);
|
||||
binaries.AddRange(planet.Children);
|
||||
}
|
||||
// Otherwise, terrestrial planets get a couple satellites while gas giants get many
|
||||
else
|
||||
{
|
||||
planet.ExpandSolar(
|
||||
ref random,
|
||||
count: planet.Mass < settings.GasGiantMass ? random.NextInt(1, 3) : random.NextInt(2, 6),
|
||||
massMulMin: .75f,
|
||||
massMulMax: 1.5f,
|
||||
distMulMin: 1.05f,
|
||||
distMulMax: 1.25f,
|
||||
jupiterJump: 1,
|
||||
massFraction: .15f); // Planetary satellites are not nearly as massive as planets themselves
|
||||
}
|
||||
alreadyExpanded.Add(planet);
|
||||
}
|
||||
// Otherwise, terrestrial planets get a couple satellites while gas giants get many
|
||||
else planet.ExpandSolar(
|
||||
count: planet.Mass < context.GlobalData.GasGiantMass ? random.NextInt(1,3) : random.NextInt(4,10),
|
||||
massMulMin: .75f,
|
||||
massMulMax: 1.5f,
|
||||
distMulMin: 1.05f,
|
||||
distMulMax: 1.25f,
|
||||
jupiterJump: 1,
|
||||
massFraction: .15f); // Planetary satellites are not nearly as massive as planets themselves
|
||||
}
|
||||
}
|
||||
|
||||
// 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 < context.GlobalData.BeltMassCeiling && !binaries.Contains(p))
|
||||
: root.AllPlanets().Where(p => p != root && p.Mass < context.GlobalData.BeltMassCeiling && !binaries.Contains(p));
|
||||
? root.AllPlanets().Where(p => p != root && p.Parent != root && p.Mass < settings.BeltMassCeiling && !binaries.Contains(p))
|
||||
: root.AllPlanets().Where(p => p != root && p.Mass < settings.BeltMassCeiling && !binaries.Contains(p));
|
||||
|
||||
foreach(var planet in beltCandidates.Reverse())
|
||||
if (random.NextFloat() < context.GlobalData.BeltProbability && !planet.Parent.Children.Any(p=>p.Belt))
|
||||
if (random.NextFloat() < settings.BeltProbability && !planet.Parent.Children.Any(p=>p.Belt))
|
||||
planet.Belt = true;
|
||||
|
||||
var totalMass = root.AllPlanets().Sum(p => p.Mass);
|
||||
var rootMass = root.Mass;
|
||||
foreach (var planet in root.AllPlanets())
|
||||
planet.Mass = (planet.Mass / totalMass) * rootMass;
|
||||
|
||||
return root.AllPlanets().ToArray();
|
||||
}
|
||||
}
|
||||
|
|
@ -275,11 +307,11 @@ public class ZoneGenerator
|
|||
// Because they were objects we observed to move in the sky instead of remaining fixed like the stars
|
||||
public class GeneratorPlanet
|
||||
{
|
||||
public GameContext Context;
|
||||
public ZoneGenerationSettings Settings;
|
||||
public float Distance;
|
||||
public float Phase;
|
||||
public float Mass;
|
||||
public float Period;
|
||||
//public float Period;
|
||||
public float ChildDistanceMinimum;
|
||||
public float ChildDistanceMaximum;
|
||||
public bool Empty = false;
|
||||
|
|
@ -295,7 +327,7 @@ public class GeneratorPlanet
|
|||
|
||||
// Create children that fill a single orbit, equally spaced
|
||||
// https://en.wikipedia.org/wiki/Klemperer_rosette
|
||||
public void ExpandRosette(int vertices)
|
||||
public void ExpandRosette(ref Random random, int vertices)
|
||||
{
|
||||
//Debug.Log("Expanding Rosette");
|
||||
|
||||
|
|
@ -306,7 +338,7 @@ public class GeneratorPlanet
|
|||
var sharedMass = Mass / vertices * 2;
|
||||
|
||||
// Proportion of the masses of sequential pairs is random, but only for even vertex counts
|
||||
var proportion = vertices % 2 == 0 ? Context.Random.NextFloat(.5f,.95f) : .5f;
|
||||
var proportion = vertices % 2 == 0 ? random.NextFloat(.5f,.95f) : .5f;
|
||||
|
||||
// Place children at a fixed distance in the center of the range
|
||||
var dist = (ChildDistanceMinimum + ChildDistanceMaximum) / 2;
|
||||
|
|
@ -318,22 +350,22 @@ public class GeneratorPlanet
|
|||
var p1 = OrbitData.Evaluate(1.0f / vertices) * dist;
|
||||
|
||||
// Maximum child distance is half the distance to the neighbor minus the neighbor's radius
|
||||
var p0ChildDist = (distance(p0, p1) * proportion - Context.GlobalData.PlanetRadius(sharedMass * (1 - proportion))) * .75f;
|
||||
var p1ChildDist = (distance(p0, p1) * (1 - proportion) - Context.GlobalData.PlanetRadius(sharedMass * proportion)) * .75f;
|
||||
var p0ChildDist = (distance(p0, p1) * proportion - Settings.PlanetSafetyRadius.Evaluate(sharedMass * (1 - proportion))) * .75f;
|
||||
var p1ChildDist = (distance(p0, p1) * (1 - proportion) - Settings.PlanetSafetyRadius.Evaluate(sharedMass * proportion)) * .75f;
|
||||
|
||||
for (int i = 0; i < vertices; i++)
|
||||
{
|
||||
var child = new GeneratorPlanet
|
||||
{
|
||||
Context = Context,
|
||||
Settings = Settings,
|
||||
Parent = this,
|
||||
Mass = sharedMass * (i % 2 == 0 ? proportion : 1 - proportion), // Masses alternate
|
||||
Distance = dist,
|
||||
Phase = (float) i / vertices,
|
||||
ChildDistanceMaximum = (i % 2 == 0 ? p0ChildDist : p1ChildDist)
|
||||
};
|
||||
child.ChildDistanceMinimum = Context.GlobalData.PlanetRadius(child.Mass) * 2;
|
||||
child.Period = Context.GlobalData.OrbitalPeriod(child.Distance);
|
||||
child.ChildDistanceMinimum = Settings.PlanetSafetyRadius.Evaluate(child.Mass) * 2;
|
||||
//child.Period = Settings..Evaluate(child.Distance);
|
||||
Children.Add(child);
|
||||
}
|
||||
|
||||
|
|
@ -341,7 +373,7 @@ public class GeneratorPlanet
|
|||
}
|
||||
|
||||
// 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)
|
||||
public void ExpandSolar(ref Random random, int count, float massMulMin, float massMulMax, float distMulMin, float distMulMax, float jupiterJump, float massFraction)
|
||||
{
|
||||
//Debug.Log("Expanding Solar");
|
||||
// Expansion is impossible when child space is full
|
||||
|
|
@ -360,13 +392,13 @@ public class GeneratorPlanet
|
|||
// jupiterJump is an additional mass multiplier applied after half of the planets
|
||||
for (var i = 1; i < count; i++)
|
||||
{
|
||||
massTotal += masses[i] = masses[i - 1] * Context.Random.NextFloat(massMulMin, massMulMax) * (count/2==i ? jupiterJump : 1);
|
||||
distances[i] = distances[i - 1] * Context.Random.NextFloat(distMulMin, distMulMax);
|
||||
massTotal += masses[i] = masses[i - 1] * random.NextFloat(massMulMin, massMulMax) * (count/2==i ? jupiterJump : 1);
|
||||
distances[i] = distances[i - 1] * random.NextFloat(distMulMin, distMulMax);
|
||||
}
|
||||
|
||||
// Add some randomness to child masses
|
||||
for (var i = 0; i < masses.Length; i++)
|
||||
masses[i] *= Context.Random.NextFloat(.1f, 1f);
|
||||
masses[i] *= random.NextFloat(.1f, 1f);
|
||||
|
||||
// Normalize the masses of the children
|
||||
for (var i = 0; i < count; i++)
|
||||
|
|
@ -378,24 +410,24 @@ public class GeneratorPlanet
|
|||
var oldDistances = (float[]) distances.Clone();
|
||||
for (var i = 0; i < count; i++)
|
||||
distances[i] = lerp(ChildDistanceMinimum, ChildDistanceMaximum,
|
||||
(oldDistances[i] - oldDistances[0]) / (oldDistances[count - 1] - oldDistances[0])) + Context.GlobalData.PlanetRadius(masses[i]);
|
||||
(oldDistances[i] - oldDistances[0]) / (oldDistances[count - 1] - oldDistances[0])) + Settings.PlanetSafetyRadius.Evaluate(masses[i]);
|
||||
}
|
||||
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
// Only instantiate children above the mass floor
|
||||
if (masses[i] > Context.GlobalData.MassFloor)
|
||||
if (masses[i] > Settings.MassFloor)
|
||||
{
|
||||
var child = new GeneratorPlanet
|
||||
{
|
||||
Context = Context,
|
||||
Settings = Settings,
|
||||
Parent = this,
|
||||
Mass = masses[i],
|
||||
Distance = distances[i],
|
||||
Phase = Context.Random.NextFloat()
|
||||
Phase = random.NextFloat()
|
||||
};
|
||||
child.Period = Context.GlobalData.OrbitalPeriod(child.Distance);
|
||||
child.ChildDistanceMinimum = Context.GlobalData.PlanetRadius(child.Mass) * 2;
|
||||
//child.Period = Context.GlobalData.OrbitalPeriod(child.Distance);
|
||||
child.ChildDistanceMinimum = Settings.PlanetSafetyRadius.Evaluate(child.Mass) * 2;
|
||||
// Maximum child distance of child is the smallest distance to either of its neighbors
|
||||
child.ChildDistanceMaximum = min(i == 0 ? child.Distance - ChildDistanceMinimum : child.Distance - distances[i - 1],
|
||||
i < count - 1 ? distances[i + 1] - child.Distance : float.PositiveInfinity);
|
||||
|
|
|
|||
Loading…
Reference in a new issue