Skip to content

Commit

Permalink
Merge pull request #154 from Touhma/TransitionFix
Browse files Browse the repository at this point in the history
Transition fix
  • Loading branch information
innominata authored Jan 26, 2022
2 parents fcd4eff + cc2e2f4 commit 838f35c
Show file tree
Hide file tree
Showing 25 changed files with 1,191 additions and 1,030 deletions.
5 changes: 2 additions & 3 deletions GalacticScale2/DSP_Plugins.GalacticScale.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
<ItemGroup Label="Core">
<PackageReference Include="BepInEx.Analyzers" Version="1.*" PrivateAssets="all" />
<PackageReference Include="BepInEx.Core" Version="5.*" PrivateAssets="all" />
<PackageReference Include="DysonSphereProgram.GameLibs" Version="*-*" IncludeAssets="compile" PrivateAssets="all" />
<PackageReference Include="UnityEngine.Modules">
<Version>2018.4.12</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -53,8 +52,8 @@
<Reference Include="0Harmony, Version=2.5.5.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\HarmonyX.2.5.5\lib\net45\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\DysonSphereProgram.GameLibs.0.8.23.9989-r.0\lib\net45\Assembly-CSharp.dll</HintPath>
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\..\Program Files (x86)\Steam\steamapps\common\Dyson Sphere Program\DSPGAME_Data\Managed\publicized_assemblies\Assembly-CSharp_publicized.dll</HintPath>
</Reference>
<Reference Include="BepInEx, Version=5.4.15.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\BepInEx.BaseLib.5.4.16\lib\net35\BepInEx.dll</HintPath>
Expand Down
2 changes: 1 addition & 1 deletion GalacticScale2/Scripts/Bootstrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public partial class GS2
[BepInDependency(NebulaAPI.NebulaModAPI.API_GUID)]
public class Bootstrap : BaseUnityPlugin
{
public const string VERSION = "2.2.0.16";
public const string VERSION = "2.2.0.23";

public new static ManualLogSource Logger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static partial class GS2
{
public static GalaxyData ProcessGalaxy(GameDesc desc, bool sketchOnly = false)
{
Log($"Start ProcessGalaxy:{sketchOnly} StarCount:{gameDesc.starCount} Seed:{gameDesc.galaxySeed} Called By{GetCaller()}");
Log($"Start ProcessGalaxy:{sketchOnly} StarCount:{gameDesc.starCount} Seed:{gameDesc.galaxySeed} Called By{GetCaller()}. Galaxy StarCount : {galaxy?.stars?.Length}");
var random = new Random(GSSettings.Seed);
try
{
Expand Down
52 changes: 32 additions & 20 deletions GalacticScale2/Scripts/GalacticScale2.0/Generators/GS2Dev/Orbits.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace GalacticScale.Generators
Expand Down Expand Up @@ -31,24 +32,27 @@ public void NamePlanets(GSStar star)

private void AssignPlanetOrbits(GSStar star)
{
// GS2.Warn("Start:"+star.Planets.Count);
GS2.Warn($"-------------------------------------------------------------------------------");
GS2.Warn($"--{star.Name}-----------------------------------------------------------------------------");
GS2.Warn($"--{star.displayType}-----------------------------------------------------------------------------");
GS2.Warn($"Assigning Planet Orbits for {star.Name}:{star.Planets.Count} planets to assign");
var r = new GS2.Random(star.Seed);
var orbits = new List<Orbit>();
ref var planets = ref star.Planets;
var brokenPlanets = new GSPlanets();
planets.Sort(PlanetSortBySystemRadius);
// GS2.WarnJson((from s in planets select s.details).ToList());
GS2.WarnJson((from s in planets select s.details).ToList());
CalculateHabitableZone(star);
var minimumOrbit = CalculateMinimumOrbit(star);
var maximumOrbit = CalculateMaximumOrbit(star);
GS2.Warn($"Minimum Orbit:{minimumOrbit} Maximum Orbit:{maximumOrbit}");
var freeOrbitRanges = new List<(float inner, float outer)>();

//Warn("Orbit Count 0");
if (star == birthStar)
{
var birthRadius = Mathf.Clamp(r.NextFloat(star.genData.Get("minHZ").Float(0f), star.genData.Get("maxHZ").Float(100f)), star.RadiusAU * 1.5f, 100f);
//Warn(
//$"Selected Orbit {birthRadius} for planet {birthPlanet.Name}. Hz:{star.genData.Get("minHZ").Float(0f)}-{star.genData.Get("maxHZ").Float(100f)}");
GS2.Warn($"Selected Orbit {birthRadius} for planet {birthPlanet.Name}. Hz:{star.genData.Get("minHZ").Float(0f)}-{star.genData.Get("maxHZ").Float(100f)}");
var orbit = new Orbit(birthRadius);
orbit.planets.Add(birthPlanet);
birthPlanet.OrbitRadius = birthRadius;
Expand All @@ -65,12 +69,12 @@ private void AssignPlanetOrbits(GSStar star)
freeOrbitRanges.Add((minimumOrbit, maximumOrbit));
}

// GS2.Warn("Begin Loop:" + star.Planets.Count);
GS2.Warn("Begin Loop:" + star.Planets.Count);
for (var i = 0; i < planets.Count; i++)
{
Orbit orbit;
var planet = planets[i];
// GS2.Log($"Finding Orbit for planet index {i} - {planet.Name}");
GS2.Log($"Finding Orbit for planet index {i} - {planet.Name}");
if (planet == birthPlanet)
// planet.Name += " BIRTH";
continue;
Expand All @@ -79,33 +83,39 @@ private void AssignPlanetOrbits(GSStar star)
//planet.OrbitInclination = 0f;


// Log($"Orbit Count > 1. Free orbit range count = {freeOrbitRanges.Count}");
GS2.Log($"Orbit Count > 1. Free orbit range count = {freeOrbitRanges.Count}");
var availableOrbits = new List<(float inner, float outer)>();
foreach (var range in freeOrbitRanges)
// GS2.Log($"Free orbits:{range}. Checking SystemRadius:{planet.SystemRadius}. {(0.05f+ 2 * planet.SystemRadius)}");
{
GS2.Log($"Free orbits:{range}. Checking SystemRadius:{planet.SystemRadius}. {(0.05f + 2 * planet.SystemRadius)}");


if (range.outer - range.inner > 0.05f + 2 * planet.SystemRadius)
{
//(1 + 1 * (GetSystemDensityBiasForStar(star) / 50)) * 2*planet.SystemRadius)
// Log($"Adding {range}");
GS2.Log($"Adding {range}");
availableOrbits.Add(range);
}
}

if (availableOrbits.Count == 0)
if (availableOrbits.Count == 0)
{
// Warn("Free Orbit Ranges:");
// LogJson(freeOrbitRanges);
// Warn($"No Orbit Ranges found for planet {planet.Name} {planet.genData["hosttype"]} {planet.genData["hostname"]} radius:{planet.SystemRadius}");
GS2.Warn("Free Orbit Ranges:");
GS2.LogJson(freeOrbitRanges);
GS2.Warn($"No Orbit Ranges found for planet {planet.Name} {planet.genData["hosttype"]} {planet.genData["hostname"]} radius:{planet.SystemRadius}");
var success = false;
foreach (var existingOrbit in orbits)
if (existingOrbit.hasRoom && existingOrbit.SystemRadius > planet.SystemRadius)
{
// Warn($"Existing orbit {existingOrbit.radius} used for planet {planet.Name}");
GS2.Warn($"Existing orbit {existingOrbit.radius} used for planet {planet.Name}");
existingOrbit.planets.Add(planet);
planet.OrbitRadius = existingOrbit.radius;
planet.OrbitalPeriod = Utils.CalculateOrbitPeriod(planet.OrbitRadius);
success = true;
break;
}

// GS2.Log($"{planet.Name} orbit radius {planet.OrbitRadius}");
GS2.Log($"{planet.Name} orbit radius {planet.OrbitRadius}");
if (success) continue;

GS2.Warn($"After all that, just couldn't find an orbit for {planet.Name} {planet.genData["hosttype"]} {planet.genData["hostname"]} . Throwing planet into the sun.");
Expand All @@ -118,20 +128,22 @@ private void AssignPlanetOrbits(GSStar star)

if (availableOrbits.Count == 0)

// GS2.Log($"No Available Orbits Found for Planet {planet.Name}");
{
GS2.Log($"No Available Orbits Found for Planet {planet.Name}");
continue;
}
var selectedRange = r.Item(availableOrbits);
// GS2.Log($"radius = r.NextFloat({selectedRange.inner + planet.SystemRadius}, {selectedRange.outer - planet.SystemRadius})");
GS2.Log($"radius = r.NextFloat({selectedRange.inner + planet.SystemRadius}, {selectedRange.outer - planet.SystemRadius})");
var radius = r.NextFloat(selectedRange.inner + planet.SystemRadius, selectedRange.outer - planet.SystemRadius);
freeOrbitRanges.Remove(selectedRange);
orbit = new Orbit(radius);
orbit.planets.Add(planet);
planet.OrbitRadius = radius;
// GS2.Log($"-{planet.Name} orbit radius {planet.OrbitRadius}");
GS2.Log($"-{planet.Name} orbit radius {planet.OrbitRadius}");

planet.OrbitalPeriod = Utils.CalculateOrbitPeriod(planet.OrbitRadius);
// Log(
// $"selected orbit({radius}) for {planet.Name}({planet.SystemRadius}) SelectedRange:{selectedRange.inner}, {selectedRange.outer} New Ranges: {selectedRange.inner},{radius - planet.SystemRadius}({radius - planet.SystemRadius - selectedRange.inner}) | {radius + planet.SystemRadius}, {selectedRange.outer}({selectedRange.outer - radius - planet.SystemRadius})");
GS2.Warn(
$"selected orbit({radius}) for {planet.Name}({planet.SystemRadius}) SelectedRange:{selectedRange.inner}, {selectedRange.outer} New Ranges: {selectedRange.inner},{radius - planet.SystemRadius}({radius - planet.SystemRadius - selectedRange.inner}) | {radius + planet.SystemRadius}, {selectedRange.outer}({selectedRange.outer - radius - planet.SystemRadius})");
orbits.Add(orbit);
var minGap = 0.1f;

Expand Down
35 changes: 25 additions & 10 deletions GalacticScale2/Scripts/GalacticScale2.0/Generators/GS2Dev/Stars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ private int ParsePlanetSize(int size)

private FloatPair CalculateHabitableZone(GSStar star)
{
GS2.Warn($"Calculating Habitable Zone for {star.Name}");
var lum = star.luminosity;
var flp = Utils.CalculateHabitableZone(lum);
var min = flp.low;
Expand All @@ -213,22 +214,23 @@ private FloatPair CalculateHabitableZone(GSStar star)

if (star.genData.Get("hasBinary", false))
{
// GS2.Warn($"{star.Name} Binary offset : {star.genData.Get("binaryOffset", 1f)}");
// GS2.Warn($"Increasing by {star.genData.Get("binaryOffset", 1)*60f}");
// GS2.Warn($"Star RadiusAU:{star.RadiusAU}");
// GS2.WarnJson(GSSettings.Stars.Select(o=>(o.Name,o.RadiusAU)).ToList());
GS2.Warn($"{star.Name} Binary offset : {star.genData.Get("binaryOffset", 1f)}");
GS2.Warn($"Increasing by {star.genData.Get("binaryOffset", 1)*60f}");
GS2.Warn($"Star RadiusAU:{star.RadiusAU}");
GS2.WarnJson(GSSettings.Stars.Select(o=>(o.Name,o.RadiusAU)).ToList());
min += star.genData.Get("binaryOffset", 1f) * 60f;
max += star.genData.Get("binaryOffset", 1f) * 60f;
}

star.genData.Set("minHZ", min);
star.genData.Set("maxHZ", max);
// GS2.Warn($"HZ of {star.Name} {min}:{max}");
GS2.Warn($"HZ of {star.Name} {min}:{max}");
return new FloatPair(min, max);
}

private float CalculateMinimumOrbit(GSStar star)
{
Warn($"Calculating Minimum Orbit for {star.Name}");
var sl = GetTypeLetterFromStar(star);

var radius = star.RadiusAU;
Expand All @@ -237,21 +239,27 @@ private float CalculateMinimumOrbit(GSStar star)

if (preferences.GetBool($"{sl}orbitOverride"))
{

var fp = preferences.GetFloatFloat($"{sl}orbits", new FloatPair(0.02f, 20f));
Warn($"Using Star Type Override {fp.low}");
min = fp.low;
}

if (star.genData.Get("hasBinary", false)) min += star.genData.Get("binaryOffset", 1f) * 60f;
if (star.genData.Get("hasBinary", false))
{
Warn("Increasing for Binary");
min += star.genData.Get("binaryOffset", 1f) * 60f;
}
min = Clamp(min, radius * 1.1f, 100f);
star.genData.Set("minOrbit", min);
// Warn($"Getting Min Orbit for Star {star.Name} Min:{min}");
Warn($"Getting Min Orbit for Star {star.Name} Min:{min}");
return min;
}

private float CalculateMaximumOrbit(GSStar star)
{
var sl = GetTypeLetterFromStar(star);

Warn($"Calculating Maximum Orbit for {star.Name}");
var minMaxOrbit = 5f;
var lum = star.luminosity;
var hzMax = star.genData.Get("maxHZ");
Expand All @@ -264,12 +272,19 @@ private float CalculateMaximumOrbit(GSStar star)
var max = Clamp(Max(maxByPlanetCount, minMaxOrbit, maxOrbitByLuminosity, maxOrbitByRadius, maxOrbitByHabitableZone), star.genData.Get("minOrbit") * 2f, star.MaxOrbit);
if (preferences.GetBool($"{sl}orbitOverride"))
{

var fp = preferences.GetFloatFloat($"{sl}orbits", new FloatPair(0.02f, 20f));
max = fp.high;
Warn($"Using Star Type Override {fp.high} from {fp} in {sl}orbits");
}

// Warn($"Getting Max Orbit for Star {star.Name} HardCap:{star.MaxOrbit} MaxbyRadius({star.radius}):{maxOrbitByRadius} MaxbyPlanets({star.PlanetCount}):{maxByPlanetCount} MaxbyLum({lum}):{maxOrbitByLuminosity} MaxByHZ({hzMax}):{maxOrbitByHabitableZone} Max({max}):{max} HabitableZone:{star.genData.Get("minHZ")}:{hzMax}");
if (star.genData.Get("hasBinary", false)) max += star.genData.Get("binaryOffset", 1f) * 60f;
Warn($"Getting Max Orbit for Star {star.Name}\r\n HardCap:{star.MaxOrbit} \r\nMaxbyRadius({star.radius}):{maxOrbitByRadius} \r\nMaxbyPlanets({star.PlanetCount}):{maxByPlanetCount} \r\nMaxbyLum({lum}):{maxOrbitByLuminosity} \r\nMaxByHZ({hzMax}):{maxOrbitByHabitableZone} \r\n HabitableZone:{star.genData.Get("minHZ")}:{hzMax}");
Warn($"Final Max({max}):{max}");
if (star.genData.Get("hasBinary", false))
{
Warn("Increasing Max Orbit for Binary");
max += star.genData.Get("binaryOffset", 1f) * 60f;
}
star.genData.Set("maxOrbit", max);
return max;
}
Expand Down
16 changes: 8 additions & 8 deletions GalacticScale2/Scripts/GalacticScale2.0/IO/Json.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,24 +104,24 @@ public static GSTheme LoadJsonTheme(string filename)

public static bool LoadSettingsFromJson(string path)
{
// Log("Start");
Log("Start");
if (!CheckJsonFileExists(path)) return false;

// Log("Path = " + path);
Log("Path = " + path);
var serializer = new fsSerializer();
GSSettings.Stars.Clear();
// Log("Initializing ThemeLibrary");
Log("Initializing ThemeLibrary");
GSSettings.ThemeLibrary = ThemeLibrary.Vanilla();
GSSettings.GalaxyParams = new GSGalaxyParams();
// Log("Reading JSON");
Log("Reading JSON");
var json = File.ReadAllText(path);
var result = GSSettings.Instance;
// Log("Parsing JSON");
Log("Parsing JSON");
var data = fsJsonParser.Parse(json);
// Log("Trying To Deserialize JSON");
Log("Trying To Deserialize JSON");
serializer.TryDeserialize(data, ref result);
// LogJson(result.galaxyParams);
// Log("End");
LogJson(result.galaxyParams);
Log("End");
return true;
}

Expand Down
Loading

0 comments on commit 838f35c

Please sign in to comment.