Skip to content

Commit

Permalink
Fixed bug #30 which was caused by planets having no moons around them
Browse files Browse the repository at this point in the history
  • Loading branch information
thorwin99 committed May 18, 2020
1 parent 9d06d1f commit 6a94b0c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class ProceduralGenerator : MySessionComponentBase

public override void LoadData()
{
MyLog.Default.WriteLine("PData");
Static = this;

m_seed = MySession.Static.Settings.ProceduralSeed;
Expand Down Expand Up @@ -84,7 +85,7 @@ public override void UpdateBeforeSimulation()
if (!Enabled)
return;

if (!Sync.IsServer || !SettingsSession.Static.Settings.Enable || MySession.Static.Settings.WorldSizeKm != 0) return;
if (!Sync.IsServer || !SettingsSession.Static.Settings.Enable || MySession.Static.Settings.WorldSizeKm > 0) return;

if (SettingsSession.Static.Settings.GeneratorSettings.AsteroidGenerator == AsteroidGenerator.PLUGIN)
{
Expand Down Expand Up @@ -190,15 +191,14 @@ public void TrackEntityRanged(MyEntity entity, double range)

public override void Init(MyObjectBuilder_SessionComponent sessionComponent)
{
if (!Sync.IsServer || !SettingsSession.Static.Settings.Enable || MySession.Static.Settings.WorldSizeKm != 0) return;
MyLog.Default.WriteLine("PInit");

if (!Sync.IsServer || !SettingsSession.Static.Settings.Enable || MySession.Static.Settings.WorldSizeKm > 0) return;
base.Init(sessionComponent);

Enabled = true;

m_seed = MySession.Static.Settings.ProceduralSeed;

planetModule.GeneratePlanets();
}

override public bool UpdatedBeforeInit()
Expand Down
17 changes: 15 additions & 2 deletions SEWorldGenPlugin/Generator/ProceduralGen/ProceduralPlanetModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using SEWorldGenPlugin.Session;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using VRage.Game.Entity;
using VRage.Game.Voxels;
using VRage.Library.Utils;
Expand All @@ -33,6 +34,7 @@ public void GeneratePlanets()
{
foreach(var obj in SystemGenerator.Static.m_objects)
{
if (obj == null) continue;
if (obj.Type != SystemObjectType.PLANET) continue;

MyPlanetItem planet = (MyPlanetItem)obj;
Expand All @@ -47,6 +49,12 @@ public void GeneratePlanets()
planet.CenterPosition = planet.OffsetPosition;
}
MyPlanet generatedPlanet = MyWorldGenerator.AddPlanet(name, planet.DisplayName, planet.DefName, planet.CenterPosition - GetPlanetOffset(definition, planet.Size), m_seed, planet.Size, true, id, false, true);

if(generatedPlanet == null)
{
continue;
}

planet.CenterPosition = generatedPlanet.PositionComp.GetPosition();
generatedPlanet.DisplayNameText = planet.DisplayName;
generatedPlanet.AsteroidName = planet.DisplayName;
Expand All @@ -55,9 +63,13 @@ public void GeneratePlanets()
planet.PlanetRing.Center = planet.CenterPosition;
List<Vector3D> spawnedMoons = new List<Vector3D>();

for(int i = 0; i < planet.PlanetMoons.Length; i++)
for (int i = 0; i < planet.PlanetMoons.Length; i++)
{
MyPlanetMoonItem moon = planet.PlanetMoons[i];
if(moon == null)
{
continue;
}
MyPlanetGeneratorDefinition moonDef = GetDefinition(moon.DefName);
if (moonDef == null) continue;
var position = new Vector3D(0, 0, 0);
Expand All @@ -76,9 +88,10 @@ public void GeneratePlanets()
MyPlanet spawnedMoon = MyWorldGenerator.AddPlanet(storageNameMoon, moon.DisplayName, moon.DefName, position, m_seed, moon.Size, true, mId, false, true);
spawnedMoons.Add(spawnedMoon.PositionComp.GetPosition());

if(SettingsSession.Static.Settings.GeneratorSettings.PlanetSettings.ShowMoonGPS)
if (SettingsSession.Static.Settings.GeneratorSettings.PlanetSettings.ShowMoonGPS)
GlobalGpsManager.Static.AddGps(moon.DisplayName, Color.Aqua, spawnedMoon.PositionComp.GetPosition());
}

planet.Generated = true;
if (SettingsSession.Static.Settings.GeneratorSettings.PlanetSettings.ShowPlanetGPS)
GlobalGpsManager.Static.AddGps(planet.DisplayName, Color.Aqua, generatedPlanet.PositionComp.GetPosition());
Expand Down
2 changes: 1 addition & 1 deletion SEWorldGenPlugin/Generator/SystemGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public override void Init(MyObjectBuilder_SessionComponent sessionComponent)
{
InitNet();

if (!Sync.IsServer || !SettingsSession.Static.Settings.Enable || MySession.Static.Settings.WorldSizeKm != 0) return;
if (!Sync.IsServer || !SettingsSession.Static.Settings.Enable || MySession.Static.Settings.WorldSizeKm > 0) return;

MyObjectBuilder_StarSystem b = GetConfig();
m_objects = b.SystemObjects;
Expand Down
2 changes: 1 addition & 1 deletion SEWorldGenPlugin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.7.3")]
[assembly: AssemblyVersion("1.7.3.1")]
[assembly: AssemblyFileVersion("1.0.0")]

0 comments on commit 6a94b0c

Please sign in to comment.