From 957b3ffee80f99bb728cb23f55eaaf7e2aa40b01 Mon Sep 17 00:00:00 2001 From: innominata Date: Thu, 12 Aug 2021 20:44:41 +1200 Subject: [PATCH] b85 --- GalacticScale2/Properties/AssemblyInfo.cs | 4 +- GalacticScale2/Scripts/Bootstrap.cs | 2 +- .../Generators/GS2Dev/GS2Generator.cs | 9 +-- .../Generators/GS2Dev/Planets.cs | 69 +++++++++++-------- .../Generators/GS2Dev/Stars.cs | 6 +- .../Patches/UIVirtualStarmap/_OnLateUpdate.cs | 14 ++-- 6 files changed, 59 insertions(+), 45 deletions(-) diff --git a/GalacticScale2/Properties/AssemblyInfo.cs b/GalacticScale2/Properties/AssemblyInfo.cs index 01c72cac..63aac918 100644 --- a/GalacticScale2/Properties/AssemblyInfo.cs +++ b/GalacticScale2/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.0.84.1")] -[assembly: AssemblyFileVersion("2.0.84.1")] \ No newline at end of file +[assembly: AssemblyVersion("2.0.85.0")] +[assembly: AssemblyFileVersion("2.0.85.0")] \ No newline at end of file diff --git a/GalacticScale2/Scripts/Bootstrap.cs b/GalacticScale2/Scripts/Bootstrap.cs index 347c424c..0e63ebab 100644 --- a/GalacticScale2/Scripts/Bootstrap.cs +++ b/GalacticScale2/Scripts/Bootstrap.cs @@ -7,7 +7,7 @@ namespace GalacticScale { - [BepInPlugin("dsp.galactic-scale.2", "Galactic Scale 2 Plug-In", "2.0.84.1")] + [BepInPlugin("dsp.galactic-scale.2", "Galactic Scale 2 Plug-In", "2.0.85.0")] [BepInDependency("space.customizing.console", BepInDependency.DependencyFlags.SoftDependency)] public class Bootstrap : BaseUnityPlugin { diff --git a/GalacticScale2/Scripts/GalacticScale2.0/Generators/GS2Dev/GS2Generator.cs b/GalacticScale2/Scripts/GalacticScale2.0/Generators/GS2Dev/GS2Generator.cs index 4af9d27e..291978e6 100644 --- a/GalacticScale2/Scripts/GalacticScale2.0/Generators/GS2Dev/GS2Generator.cs +++ b/GalacticScale2/Scripts/GalacticScale2.0/Generators/GS2Dev/GS2Generator.cs @@ -47,6 +47,7 @@ public void Generate(int starCount, StarData forcedBirthStar = null) Log($"Start {GSSettings.Seed}"); GSSettings.Reset(GSSettings.Seed); + random = new GS2.Random(GSSettings.Seed); highStopwatch.Begin(); InitForcedStars(); SetupBaseThemes(); @@ -58,7 +59,7 @@ public void Generate(int starCount, StarData forcedBirthStar = null) GSSettings.GalaxyParams.graphMaxStars = 512; //starCount = preferences.GetInt("defaultStarCount", 64); SetGalaxyDensity(preferences.GetInt("galaxyDensity", 5)); - random = new GS2.Random(GSSettings.Seed); + highStopwatch.Begin(); CalculateFrequencies(); Log($"Frequencies Caltulated: {highStopwatch.duration:F5}"); @@ -346,7 +347,7 @@ public void SetGalaxyDensity(int density) } - private int ClampedNormal(int min, int max, int bias) + private int ClampedNormal(GS2.Random random, int min, int max, int bias) { var range = max - min; var average = bias / 100f * range + min; @@ -359,7 +360,7 @@ private int ClampedNormal(int min, int max, int bias) return result; } - private float ClampedNormal(float min, float max, int bias) + private float ClampedNormal(GS2.Random random, float min, float max, int bias) { var range = max - min; var average = bias / 100f * range + min; @@ -372,7 +373,7 @@ private float ClampedNormal(float min, float max, int bias) return result; } - private int ClampedNormalSize(int min, int max, int bias) + private int ClampedNormalSize(GS2.Random random, int min, int max, int bias) { var range = max - min; var average = bias / 100f * range + min; diff --git a/GalacticScale2/Scripts/GalacticScale2.0/Generators/GS2Dev/Planets.cs b/GalacticScale2/Scripts/GalacticScale2.0/Generators/GS2Dev/Planets.cs index 8430e968..909ef972 100644 --- a/GalacticScale2/Scripts/GalacticScale2.0/Generators/GS2Dev/Planets.cs +++ b/GalacticScale2/Scripts/GalacticScale2.0/Generators/GS2Dev/Planets.cs @@ -22,49 +22,62 @@ private void GeneratePlanetsForStar(GSStar star) { star.Planets = new GSPlanets(); // GS2.Warn($"Creating Planets for {star.Name}"); - var gasChance = GetGasChanceForStar(star); + var random = new GS2.Random(star.Seed); var starBodyCount = GetStarPlanetCount(star); if (starBodyCount == 0) return; var moonChance = GetMoonChanceForStar(star); + var gasChance = GetGasChanceForStar(star); var moonMoonChance = preferences.GetFloat("chanceMoonMoon", 5f) / 100f; + var subMoonChance = moonMoonChance * moonChance; + moonChance = moonChance - subMoonChance; + var gasCount = Mathf.RoundToInt(starBodyCount * (float)gasChance); + var telluricCount = starBodyCount - gasCount; + if (telluricCount == 0 && star == birthStar) + { + telluricCount = 1; + gasCount--; + } + var moonCount = Mathf.RoundToInt(telluricCount * (float)moonChance); + if (telluricCount == 0 && star == birthStar) + { + telluricCount = 1; + moonCount--; + } + var secondaryMoonCount = Mathf.RoundToInt((moonCount -1) * (float)subMoonChance); + moonCount -= secondaryMoonCount; + + - var moonCount = 0; - var secondaryMoonCount = 0; var moons = new GSPlanets(); if (star == birthStar) { birthPlanet = star.Planets.Add(new GSPlanet("BirthPlanet", "Mediterranean", preferences.GetInt("birthPlanetSize", 200), -1, -1, -1, -1, -1, -1, -1, -1, new GSPlanets())); GS2.Log($"Created Birth Planet in star {star.Name}: {birthPlanet}"); } - for (var i = (star == birthStar) ? 1 : 0; i < starBodyCount; i++) + for (var i = (star == birthStar) ? 1 : 0; i < telluricCount; i++) { - if (random.NextPick(moonChance) && star.Planets.Count > 1) - { - moonCount++; - } - else - { - var isGas = CalculateIsGas(star); - var radius = GetStarPlanetSize(star); - var p = new GSPlanet("planet_" + i, (isGas) ? "Gas" : "Barren", radius, -1, -1, -1, -1, -1, -1, -1, -1, new GSPlanets()); - if (isGas && !preferences.GetBool("hugeGasGiants", true)) p.Radius = 80; - if (isGas) p.Scale = 10f; - star.Planets.Add(p); - p.genData.Add("hosttype", "star"); - p.genData.Add("hostname", star.Name); - // GS2.Log($"Created Planet:{p}"); - } + var radius = GetStarPlanetSize(star); + var p = new GSPlanet("planet_" + i, "Barren", radius, -1, -1, -1, -1, -1, -1, -1, -1, new GSPlanets()); + star.Planets.Add(p); + p.genData.Add("hosttype", "star"); + p.genData.Add("hostname", star.Name); + + } + for (var i = 0; i < gasCount; i++) + { + var radius = GetStarPlanetSize(star); + var p = new GSPlanet("planet_" + i, "Gas" , radius, -1, -1, -1, -1, -1, -1, -1, -1, new GSPlanets()); + if (!preferences.GetBool("hugeGasGiants", true)) p.Radius = 80; + p.Scale = 10f; + star.Planets.Add(p); + p.genData.Add("hosttype", "star"); + p.genData.Add("hostname", star.Name); + } - GS2.Log($"StarPlanetCount:{star.Planets.Count} BirthStar?:{star == birthStar}"); + // GS2.Log($"StarPlanetCount:{star.Planets.Count} BirthStar?:{star == birthStar}"); for (var i = 0; i < moonCount; i++) { - if (preferences.GetBool("secondarySatellites") && random.NextPick(moonMoonChance) && i != 0) - { - secondaryMoonCount++; - } - else - { GSPlanet randomPlanet; GSPlanets gasPlanets = new GSPlanets(); GSPlanets telPlanets = new GSPlanets(); @@ -91,7 +104,7 @@ private void GeneratePlanetsForStar(GSStar star) moon.genData.Add("hosttype", "planet"); moon.genData.Add("hostname", randomPlanet.Name); // GS2.Log($"Added {moon} to {randomPlanet}"); - } + } for (var i = 0; i < secondaryMoonCount; i++) { diff --git a/GalacticScale2/Scripts/GalacticScale2.0/Generators/GS2Dev/Stars.cs b/GalacticScale2/Scripts/GalacticScale2.0/Generators/GS2Dev/Stars.cs index 2f6d4b66..9a99b5d2 100644 --- a/GalacticScale2/Scripts/GalacticScale2.0/Generators/GS2Dev/Stars.cs +++ b/GalacticScale2/Scripts/GalacticScale2.0/Generators/GS2Dev/Stars.cs @@ -58,7 +58,7 @@ private int GetStarPlanetCount(GSStar star) var min = GetMinPlanetCountForStar(star); var max = GetMaxPlanetCountForStar(star); //int result = random.NextInclusive(min, max); - var result = ClampedNormal(min, max, GetCountBiasForStar(star)); + var result = ClampedNormal(new GS2.Random(star.Seed), min, max, GetCountBiasForStar(star)); //Log($"{star.Name} count :{result} min:{min} max:{max}"); return result; } @@ -83,7 +83,7 @@ private int GetStarMoonSize(GSStar star, int hostRadius, bool hostGas) var range = max - min; var sd = (float) range / 4; //int size = Utils.ParsePlanetSize(random.Next(min, max)); - var size = Mathf.Clamp(ClampedNormalSize(min, max, GetSizeBiasForStar(star)), min, GetMaxPlanetSizeForStar(star)); + var size = Mathf.Clamp(ClampedNormalSize(new GS2.Random(star.Seed), min, max, GetSizeBiasForStar(star)), min, GetMaxPlanetSizeForStar(star)); //if (size > hostRadius) //{ //Warn($"MoonSize {size} selected for {star.Name} moon with host size {hostRadius} avg:{average} sd:{sd} max:{max} min:{min} range:{range} hostGas:{hostGas}"); @@ -96,7 +96,7 @@ private int GetStarPlanetSize(GSStar star) var min = GetMinPlanetSizeForStar(star); var max = GetMaxPlanetSizeForStar(star); var bias = GetSizeBiasForStar(star); - return ClampedNormalSize(min, max, bias); + return ClampedNormalSize(new GS2.Random(star.Seed), min, max, bias); } private (float min, float max) CalculateHabitableZone(GSStar star) { diff --git a/GalacticScale2/Scripts/GalacticScale2.0/Patches/UIVirtualStarmap/_OnLateUpdate.cs b/GalacticScale2/Scripts/GalacticScale2.0/Patches/UIVirtualStarmap/_OnLateUpdate.cs index 6b709a2a..e24883cc 100644 --- a/GalacticScale2/Scripts/GalacticScale2.0/Patches/UIVirtualStarmap/_OnLateUpdate.cs +++ b/GalacticScale2/Scripts/GalacticScale2.0/Patches/UIVirtualStarmap/_OnLateUpdate.cs @@ -61,7 +61,7 @@ public static bool _OnLateUpdate(ref UIVirtualStarmap __instance) if (flag2 & flag1) { - GS2.Log("0"); + // GS2.Log("0"); if (pressing) { GS2.ActiveGenerator.Generate(GSSettings.StarCount, __instance.starPool[index1].starData); @@ -71,13 +71,13 @@ public static bool _OnLateUpdate(ref UIVirtualStarmap __instance) // __instance.clickText.Translate(); } - GS2.Log(__instance.starPool[index1].starData.name + " - " + - __instance.starPool[index2].starData.name); + // GS2.Log(__instance.starPool[index1].starData.name + " - " + + // __instance.starPool[index2].starData.name); var sd = __instance.starPool[index2]?.starData; - GS2.Log("1"); - if (__instance.starPool[index2]?.nameText?.text != null) __instance.starPool[index2].nameText.text = $"{__instance.starPool[index2].textContent} \r\n Gas Giants:{Utils.GetStarDataGasCount(sd)}\r\nPlanets:{Utils.GetStarDataTelluricCount(sd)}\n\n Moons:{Utils.GetStarDataMoonCount(sd)}"; - GS2.Log("2"); - GS2.Log($"{sd?.planetCount}"); + // GS2.Log("1"); + if (__instance.starPool[index2]?.nameText?.text != null) __instance.starPool[index2].nameText.text = $"{__instance.starPool[index2].textContent}\r\nGas Giants:{Utils.GetStarDataGasCount(sd)}\r\nPlanets:{Utils.GetStarDataTelluricCount(sd)}\n\nMoons:{Utils.GetStarDataMoonCount(sd)}"; + // GS2.Log("2"); + // GS2.Log($"{sd?.planetCount}"); __instance.starPool[index2].nameText.rectTransform.sizeDelta = new Vector2( __instance.starPool[index2].nameText.preferredWidth, __instance.starPool[index2].nameText.preferredHeight);