diff --git a/.idea/.idea.Aetheria-Economy/.idea/indexLayout.xml b/.idea/.idea.Aetheria-Economy/.idea/indexLayout.xml index 75ee64a49..454370e0d 100644 --- a/.idea/.idea.Aetheria-Economy/.idea/indexLayout.xml +++ b/.idea/.idea.Aetheria-Economy/.idea/indexLayout.xml @@ -12,6 +12,7 @@ .git .idea + Asset Sources Economy.Server Economy.Shared GameData diff --git a/Asset Sources/Lucent.psd b/Asset Sources/Lucent.psd new file mode 100644 index 000000000..3ee36fc4c --- /dev/null +++ b/Asset Sources/Lucent.psd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c8209eb766b4b9ce857e3d7f4d025b4064585b6f290b5bcbd0dc861b99951472 +size 169495 diff --git a/Assets/Scripts/ServerShared/Extensions.cs b/Assets/Scripts/ServerShared/Extensions.cs index b61ef016e..d2c3c2ece 100644 --- a/Assets/Scripts/ServerShared/Extensions.cs +++ b/Assets/Scripts/ServerShared/Extensions.cs @@ -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(this IEnumerable 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; diff --git a/Assets/Scripts/ServerShared/GlobalData.cs b/Assets/Scripts/ServerShared/GlobalData.cs index 2ddcc799a..9ba8411c1 100644 --- a/Assets/Scripts/ServerShared/GlobalData.cs +++ b/Assets/Scripts/ServerShared/GlobalData.cs @@ -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) { diff --git a/Assets/Scripts/ServerShared/ItemData.cs b/Assets/Scripts/ServerShared/ItemData.cs index d039a4d15..bf760b50f 100644 --- a/Assets/Scripts/ServerShared/ItemData.cs +++ b/Assets/Scripts/ServerShared/ItemData.cs @@ -48,17 +48,21 @@ public class SimpleCommodityData : ItemData [InspectableDatabaseLink(typeof(GalaxyMapLayerData)), JsonProperty("resourceDensity"), Key(7)] public List ResourceDensity = new List(); - // 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, diff --git a/Assets/Scripts/ServerShared/ZoneGenerator.cs b/Assets/Scripts/ServerShared/ZoneGenerator.cs index ef27fb07e..7463f7f7a 100644 --- a/Assets/Scripts/ServerShared/ZoneGenerator.cs +++ b/Assets/Scripts/ServerShared/ZoneGenerator.cs @@ -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) {