Improved Resource Placement Formula
Resource placement now uses a more straightforward power distribution formula with fixed minimum and maximum and a single value to control curvature Sector mass and radius now also follow power distribution
This commit is contained in:
parent
bc2d6ccea6
commit
17673cd264
6 changed files with 76 additions and 38 deletions
|
|
@ -12,6 +12,7 @@
|
|||
<explicitExcludes>
|
||||
<Path>.git</Path>
|
||||
<Path>.idea</Path>
|
||||
<Path>Asset Sources</Path>
|
||||
<Path>Economy.Server</Path>
|
||||
<Path>Economy.Shared</Path>
|
||||
<Path>GameData</Path>
|
||||
|
|
|
|||
BIN
Asset Sources/Lucent.psd
(Stored with Git LFS)
Normal file
BIN
Asset Sources/Lucent.psd
(Stored with Git LFS)
Normal file
Binary file not shown.
|
|
@ -69,6 +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 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));
|
||||
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, float ceiling) => 1 / (1 - pow(min(random.NextFloat(), ceiling), 1 - pow(clamp(bias,0,.99f), 1 / power))) - 1;
|
||||
|
||||
|
|
|
|||
|
|
@ -62,65 +62,77 @@ public class GlobalData : DatabaseEntry
|
|||
[InspectableField, JsonProperty("zoneRadiusMax"), Key(17)]
|
||||
public float MaximumZoneRadius = 2000;
|
||||
|
||||
[InspectableField, JsonProperty("zoneMassMin"), Key(18)]
|
||||
[InspectableField, JsonProperty("zoneRadiusExp"), Key(18)]
|
||||
public float ZoneRadiusExponent = -.75f;
|
||||
|
||||
[InspectableField, JsonProperty("zoneMassMin"), Key(19)]
|
||||
public float MinimumZoneMass = 10000;
|
||||
|
||||
[InspectableField, JsonProperty("zoneMassMax"), Key(19)]
|
||||
[InspectableField, JsonProperty("zoneMassMax"), Key(20)]
|
||||
public float MaximumZoneMass = 100000;
|
||||
|
||||
[InspectableField, JsonProperty("orbitPeriodExponent"), Key(20)]
|
||||
[InspectableField, JsonProperty("zoneMassExp"), Key(21)]
|
||||
public float ZoneMassExponent = -.75f;
|
||||
|
||||
[InspectableField, JsonProperty("orbitPeriodExponent"), Key(22)]
|
||||
public float OrbitPeriodExponent = 1.5f;
|
||||
|
||||
[InspectableField, JsonProperty("orbitPeriodMultiplier"), Key(21)]
|
||||
[InspectableField, JsonProperty("orbitPeriodMultiplier"), Key(23)]
|
||||
public float OrbitPeriodMultiplier = 1f;
|
||||
|
||||
[InspectableField, JsonProperty("gravityRadiusExponent"), Key(22)]
|
||||
[InspectableField, JsonProperty("gravityRadiusExponent"), Key(24)]
|
||||
public float GravityRadiusExponent = 1.5f;
|
||||
|
||||
[InspectableField, JsonProperty("gravityRadiusMultiplier"), Key(23)]
|
||||
[InspectableField, JsonProperty("gravityRadiusMultiplier"), Key(25)]
|
||||
public float GravityRadiusMultiplier = 1f;
|
||||
|
||||
[InspectableField, JsonProperty("beltProbability"), Key(24)]
|
||||
[InspectableField, JsonProperty("beltProbability"), Key(26)]
|
||||
public float BeltProbability = .05f;
|
||||
|
||||
[InspectableField, JsonProperty("beltMassCeiling"), Key(25)]
|
||||
[InspectableField, JsonProperty("beltMassCeiling"), Key(27)]
|
||||
public float BeltMassCeiling = 500f;
|
||||
|
||||
[InspectableField, JsonProperty("beltMassRatio"), Key(26)]
|
||||
[InspectableField, JsonProperty("beltMassRatio"), Key(28)]
|
||||
public float BeltMassRatio = 100f;
|
||||
|
||||
[InspectableField, JsonProperty("beltMassExponent"), Key(27)]
|
||||
[InspectableField, JsonProperty("beltMassExponent"), Key(29)]
|
||||
public float BeltMassExponent = 100f;
|
||||
|
||||
[InspectableField, JsonProperty("asteroidSizeMin"), Key(28)]
|
||||
[InspectableField, JsonProperty("asteroidSizeMin"), Key(30)]
|
||||
public float AsteroidSizeMin = 2f;
|
||||
|
||||
[InspectableField, JsonProperty("asteroidSizeMax"), Key(29)]
|
||||
[InspectableField, JsonProperty("asteroidSizeMax"), Key(31)]
|
||||
public float AsteroidSizeMax = 10f;
|
||||
|
||||
[InspectableField, JsonProperty("asteroidSizeExponent"), Key(30)]
|
||||
[InspectableField, JsonProperty("asteroidSizeExponent"), Key(32)]
|
||||
public float AsteroidSizeExponent = 2f;
|
||||
|
||||
[InspectableField, JsonProperty("asteroidRotationSpeed"), Key(31)]
|
||||
[InspectableField, JsonProperty("asteroidRotationSpeed"), Key(33)]
|
||||
public float AsteroidRotationSpeed = 2f;
|
||||
|
||||
[InspectableField, JsonProperty("dockingDistance"), Key(32)]
|
||||
[InspectableField, JsonProperty("dockingDistance"), Key(34)]
|
||||
public float DockingDistance = 25;
|
||||
|
||||
[InspectableField, JsonProperty("warpDistance"), Key(33)]
|
||||
[InspectableField, JsonProperty("warpDistance"), Key(35)]
|
||||
public float WarpDistance = 25;
|
||||
|
||||
[InspectableField, JsonProperty("orbitSpeedMultiplier"), Key(34)]
|
||||
[InspectableField, JsonProperty("orbitSpeedMultiplier"), Key(36)]
|
||||
public float OrbitSpeedMultiplier = .25f;
|
||||
|
||||
[InspectableField, JsonProperty("targetPersistenceDuration"), Key(35)]
|
||||
[InspectableField, JsonProperty("targetPersistenceDuration"), Key(37)]
|
||||
public float TargetPersistenceDuration = 3;
|
||||
|
||||
[InspectableField, JsonProperty("heatRadiationPower"), Key(36)]
|
||||
[InspectableField, JsonProperty("heatRadiationPower"), Key(38)]
|
||||
public float HeatRadiationPower = 1;
|
||||
|
||||
[InspectableField, JsonProperty("heatRadiationMultiplier"), Key(37)]
|
||||
[InspectableField, JsonProperty("heatRadiationMultiplier"), Key(39)]
|
||||
public float HeatRadiationMultiplier = 1;
|
||||
|
||||
[InspectableField, JsonProperty("resourceDensityMinimum"), Key(40)]
|
||||
public float ResourceDensityMinimum = .1f;
|
||||
|
||||
[InspectableField, JsonProperty("resourceDensityMaximum"), Key(41)]
|
||||
public float ResourceDensityMaximum = 1.5f;
|
||||
|
||||
public float PlanetRadius(float mass)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -48,17 +48,21 @@ public class SimpleCommodityData : ItemData
|
|||
[InspectableDatabaseLink(typeof(GalaxyMapLayerData)), JsonProperty("resourceDensity"), Key(7)]
|
||||
public List<Guid> ResourceDensity = new List<Guid>();
|
||||
|
||||
// Controls the bias power variable during resource placement
|
||||
[InspectableField, JsonProperty("resourceDensityBiasPower"), Key(8)]
|
||||
public float DensityBiasPower = 5;
|
||||
// Controls the lowest value in the resource distribution curve
|
||||
[InspectableField, JsonProperty("minimum"), Key(8)]
|
||||
public float Minimum = 1;
|
||||
|
||||
// Controls the bias power variable during resource placement
|
||||
[InspectableField, JsonProperty("resourceRandomCeiling"), Key(9)]
|
||||
public float RandomCeiling = .9f;
|
||||
// Controls the highest value in the resource distribution curve
|
||||
[InspectableField, JsonProperty("maximum"), Key(9)]
|
||||
public float Maximum = 100;
|
||||
|
||||
// Controls the shape of the resource distribution curve
|
||||
[InspectableField, JsonProperty("exponent"), Key(10)]
|
||||
public float Exponent = -.75f;
|
||||
|
||||
// Minimum amount of resources needed for presence to register
|
||||
[InspectableField, JsonProperty("resourceFloor"), Key(10)]
|
||||
public float ResourceFloor = 10f;
|
||||
[InspectableField, JsonProperty("floor"), Key(11)]
|
||||
public float Floor = 5f;
|
||||
}
|
||||
|
||||
[MessagePackObject,
|
||||
|
|
|
|||
|
|
@ -19,18 +19,28 @@ public class ZoneGenerator
|
|||
out OrbitData[] orbitData,
|
||||
out PlanetData[] planetsData)
|
||||
{
|
||||
var zoneRadius = lerp(context.GlobalData.MinimumZoneRadius,
|
||||
var zoneRadius = context.Random.NextPowerDistribution(
|
||||
context.GlobalData.MinimumZoneRadius,
|
||||
context.GlobalData.MaximumZoneRadius,
|
||||
mapLayers.First(m => m.Name == "Radius")
|
||||
.Evaluate(zone.Position,
|
||||
context.GlobalData));
|
||||
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 = lerp(context.GlobalData.MinimumZoneMass,
|
||||
var zoneMass = context.Random.NextPowerDistribution(
|
||||
context.GlobalData.MinimumZoneMass,
|
||||
context.GlobalData.MaximumZoneMass,
|
||||
mapLayers.First(m => m.Name == "Mass")
|
||||
.Evaluate(zone.Position,
|
||||
context.GlobalData));
|
||||
context.GlobalData.ZoneMassExponent,
|
||||
1 / lerp(
|
||||
context.GlobalData.ResourceDensityMinimum,
|
||||
context.GlobalData.ResourceDensityMaximum,
|
||||
mapLayers
|
||||
.First(m => m.Name == "Mass")
|
||||
.Evaluate(zone.Position, context.GlobalData)));
|
||||
|
||||
//Debug.Log($"Generating zone at position {zone.Position} with radius {zoneRadius} and mass {zoneMass}");
|
||||
|
||||
|
|
@ -76,8 +86,8 @@ public class ZoneGenerator
|
|||
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.DensityBiasPower, r.RandomCeiling);
|
||||
if (r.ResourceFloor < quantity) dictionary.Add(r.ID, quantity);
|
||||
float quantity = ResourceValue(r, context, r.ResourceDensity.Aggregate(1f, (m, rdm) => m * resourceMaps[rdm]));
|
||||
if (r.Floor < quantity) dictionary.Add(r.ID, quantity);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -107,6 +117,12 @@ public class ZoneGenerator
|
|||
zone.Planets = planetsData.Select(pd => pd.ID).ToArray();
|
||||
zone.Orbits = orbitData.Select(od => od.ID).ToList();
|
||||
}
|
||||
|
||||
static float ResourceValue(SimpleCommodityData resource, GameContext context, float density)
|
||||
{
|
||||
return context.Random.NextPowerDistribution(resource.Minimum, resource.Maximum, resource.Exponent,
|
||||
1 / lerp(context.GlobalData.ResourceDensityMinimum, context.GlobalData.ResourceDensityMaximum, density));
|
||||
}
|
||||
|
||||
public static Planet[] GenerateEntities(GameContext context, ZoneData data, float mass, float radius)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue