Skip to content

Commit

Permalink
b85
Browse files Browse the repository at this point in the history
  • Loading branch information
innominata committed Aug 12, 2021
1 parent 9cf9f9a commit 957b3ff
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 45 deletions.
4 changes: 2 additions & 2 deletions GalacticScale2/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
[assembly: AssemblyVersion("2.0.85.0")]
[assembly: AssemblyFileVersion("2.0.85.0")]
2 changes: 1 addition & 1 deletion GalacticScale2/Scripts/Bootstrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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}");
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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}");
Expand All @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 957b3ff

Please sign in to comment.