/// <summary>
        /// Initializes the system generator and generates a new system if enabled and no system was
        /// generated yet.
        /// </summary>
        /// <param name="sessionComponent"></param>
        public override void Init(MyObjectBuilder_SessionComponent sessionComponent)
        {
            MyPluginLog.Log("Initializing Star system generator");

            if (!MySettingsSession.Static.IsEnabled())
            {
                MyPluginLog.Log("Plugin is not enabled or client is not the server, aborting");
                return;
            }

            LoadPlanetDefinitions();

            if (StarSystem.Count() <= 0)
            {
                StarSystem = GenerateNewStarSystem();
            }

            MyPluginLog.Log("Initializing Star system generator completed");
        }
        /// <summary>
        /// Generates a completely new system based on the
        /// world settings.
        /// </summary>
        /// <returns></returns>
        private MyObjectBuilder_SystemData GenerateNewStarSystem()
        {
            MyPluginLog.Log("Generating a new Solar system ...");

            int seed = MySession.Static.Settings.ProceduralSeed + Guid.NewGuid().GetHashCode();
            MyObjectBuilder_SystemData system = new MyObjectBuilder_SystemData();

            var settings = MySettingsSession.Static.Settings.GeneratorSettings;

            var orbitDistances       = settings.MinMaxOrbitDistance;
            var planetsAmount        = settings.MinMaxPlanets;
            var asteroidObjectAmount = settings.MinMaxAsteroidObjects;
            var worldSize            = settings.WorldSize;

            var asteroidProviders = MyAsteroidObjectsManager.Static.AsteroidObjectProviders;

            using (MyRandom.Instance.PushSeed(seed))
            {
                long planetCount          = MyRandom.Instance.Next(planetsAmount.Min, planetsAmount.Max + 1);
                long asteroidObjectCount  = MyRandom.Instance.Next(asteroidObjectAmount.Min, asteroidObjectAmount.Max + 1);
                long systemSize           = planetCount + asteroidObjectCount;
                int  currentPlanetIndex   = 0;
                int  currentAsteroidIndex = 0;
                long currentOrbitDistance = 0;

                double planetProb = planetCount / (double)(planetCount + asteroidObjectCount);

                if (m_suns.Count > 0)
                {
                    MyPlanetGeneratorDefinition sunDef = m_suns[MyRandom.Instance.Next(0, m_suns.Count)];
                    MySystemPlanet sun = new MySystemPlanet();
                    sun.CenterPosition = Vector3D.Zero;
                    sun.SubtypeId      = sunDef.Id.SubtypeId.String;
                    sun.DisplayName    = sunDef.Id.SubtypeId.String;
                    sun.Diameter       = CalculatePlanetDiameter(sunDef) * 2;
                    sun.ChildObjects   = new HashSet <MySystemObject>();
                    sun.Generated      = false;
                    sun.Type           = MySystemObjectType.PLANET;

                    system.CenterObject   = sun;
                    currentOrbitDistance += (long)sun.Diameter * 2 + (long)sunDef.AtmosphereHeight;
                }
                else
                {
                    system.CenterObject             = new MySystemObject();
                    system.CenterObject.Type        = MySystemObjectType.EMPTY;
                    system.CenterObject.DisplayName = "System center";
                }

                while (planetCount > 0 || asteroidObjectCount > 0)
                {
                    currentOrbitDistance += MyRandom.Instance.Next(orbitDistances.Min, orbitDistances.Max);

                    //Maybe rework to override orbit distance, so all objects fit
                    if (worldSize >= 0 && currentOrbitDistance >= worldSize)
                    {
                        return(system);
                    }

                    MySystemObject obj = null;

                    if (asteroidObjectCount <= 0 || (MyRandom.Instance.NextDouble() <= planetProb && planetCount > 0)) // Generate planet
                    {
                        obj = GeneratePlanet(currentPlanetIndex++, Math.Sin((system.Count() - 1) * Math.PI / systemSize), currentOrbitDistance);
                        planetCount--;
                    }
                    else if (asteroidObjectCount > 0) // Generate asteroid object
                    {
                        int providerIndex = MyRandom.Instance.Next(0, asteroidProviders.Keys.Count);
                        MyAbstractAsteroidObjectProvider provider = null;
                        foreach (var prov in asteroidProviders)
                        {
                            if (!prov.Value.IsSystemGeneratable())
                            {
                                continue;
                            }

                            if (providerIndex-- == 0)
                            {
                                provider = prov.Value;
                            }
                        }

                        if (provider == null)
                        {
                            continue;
                        }

                        obj = provider.GenerateInstance(currentAsteroidIndex++, null, currentOrbitDistance);

                        if (obj == null)
                        {
                            continue;
                        }

                        (obj as MySystemAsteroids).AsteroidTypeName = provider.GetTypeName();

                        asteroidObjectCount--;
                    }
                    if (obj == null)
                    {
                        continue;
                    }

                    obj.ParentId = system.CenterObject.Id;
                    system.CenterObject.ChildObjects.Add(obj);
                }
            }

            MyPluginLog.Log("Solar system generated ...");

            return(system);
        }