Skip to content

Commit

Permalink
Implemented request #24 as configuration file only option. If enabled…
Browse files Browse the repository at this point in the history
…, the first planet will spawn in the center and has no limitation as to how large it can be.
  • Loading branch information
thorwin99 committed Apr 13, 2020
1 parent a5e1832 commit a1d997b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion SEWorldGenPlugin/GUI/PluginWorldSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ protected override void BuildControls()

if (m_isNewGame)
{
PlSettings = new MyObjectBuilder_PluginSettings();
PlSettings = MySettings.Static.Settings;
PlSettings.GeneratorSettings.PlanetSettings.BlacklistedPlanets = MySettings.Static.Settings.GeneratorSettings.PlanetSettings.BlacklistedPlanets;
PlSettings.GeneratorSettings.PlanetSettings.Moons = MySettings.Static.Settings.GeneratorSettings.PlanetSettings.Moons;
PlSettings.GeneratorSettings.PlanetSettings.MandatoryPlanets = MySettings.Static.Settings.GeneratorSettings.PlanetSettings.MandatoryPlanets;
Expand Down
19 changes: 13 additions & 6 deletions SEWorldGenPlugin/Generator/SystemGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,12 @@ private void GenerateSystem()
{
if (tmp_distance >= m_settings.WorldSize && m_settings.WorldSize > 0) return;

int distToPrev = MyRandom.Instance.Next(m_settings.MinOrbitDistance, m_settings.MaxOrbitDistance);
tmp_distance += distToPrev;
if (i != 0 || !m_settings.FirstPlanetCenter)
{
int distToPrev = MyRandom.Instance.Next(m_settings.MinOrbitDistance, m_settings.MaxOrbitDistance);
tmp_distance += distToPrev;
}


if(MyRandom.Instance.NextDouble()/* * ((i % 6) * (i % 6) / 12.5)*/ < 1 - m_settings.BeltSettings.BeltProbability && m_planetDefinitions.Count != 0){
GeneratePlanet(i, tmp_distance, numberPlanets, ref totalPlanets);
Expand Down Expand Up @@ -182,7 +186,11 @@ private void GeneratePlanet(int index, long distance, int totalObjects, ref int
{
MyPlanetItem planet = new MyPlanetItem();

var def = GetPlanetDefinition((int)(m_settings.PlanetSettings.PlanetSizeCap * Math.Sin(index * Math.PI / totalObjects)));
double mod = distance == 0 && m_settings.FirstPlanetCenter ? 1 : Math.Sin(index * Math.PI / totalObjects);

var def = GetPlanetDefinition((int)(m_settings.PlanetSettings.PlanetSizeCap * mod));

var size = SizeByGravity(def.SurfaceGravity);

var angle = MyRandom.Instance.GetRandomFloat(0, (float)(2 * Math.PI));
var height = MyRandom.Instance.GetRandomFloat((float)Math.PI / 180 * -5, (float)Math.PI / 180 * 5);
Expand All @@ -191,7 +199,7 @@ private void GeneratePlanet(int index, long distance, int totalObjects, ref int
planet.DisplayName = "Planet " + (++planetIndex);
planet.Type = SystemObjectType.PLANET;
planet.DefName = def.Id.SubtypeId.String;
planet.Size = SizeByGravity(def.SurfaceGravity);
planet.Size = size;
planet.PlanetRing = GenerateRing(def.SurfaceGravity, planet.Size);
planet.OffsetPosition = pos;
planet.CenterPosition = pos;
Expand Down Expand Up @@ -262,7 +270,7 @@ private MyPlanetGeneratorDefinition GetPlanetDefinition(float maximumSize)
size = SizeByGravity(def.SurfaceGravity);
tries++;

} while (size >= maximumSize && tries < 10000);
} while (size > maximumSize && tries < 10000);

return def;
}
Expand Down Expand Up @@ -302,7 +310,6 @@ private void ShuffleMandatoryPlanets()
int n = m_mandatoryPlanets.Count;
while(n > 1)
{
n--;
int index = MyRandom.Instance.Next(n - 1);
var value = m_mandatoryPlanets[index];
m_mandatoryPlanets[index] = m_mandatoryPlanets[n];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public GeneratorSettings()
BeltSettings = new BeltSettings();
SemiRandomizedGeneration = false;
WorldSize = -1;
FirstPlanetCenter = false;
}

[ProtoMember(1)]
Expand Down Expand Up @@ -73,6 +74,9 @@ public GeneratorSettings()
[ProtoMember(10)]
public long WorldSize;

[ProtoMember(10)]
public bool FirstPlanetCenter;

public void Verify()
{
Verifier.VerifyInt(0, MaxObjectsInSystem, 5, "MinObjectsInSystem", ref MinObjectsInSystem);
Expand Down

0 comments on commit a1d997b

Please sign in to comment.