/// <summary> /// Checks all planets of the star system, and whether they are still existent as objects /// in the world. Just to clear up deleted objects from the system at world loading /// </summary> private void CheckIntegrityOfSystem() { foreach (var obj in StarSystem.GetAllObjects()) { if (obj is MySystemPlanet) { if (!MyEntities.EntityExists((obj as MySystemPlanet).EntityId) && (obj as MySystemPlanet).Generated) { MyPluginLog.Debug("Planet " + obj.Id + " does not exist anymore, deleting it", LogLevel.WARNING); StarSystem.RemoveObject(obj.Id); MyGPSManager.Static.RemovePersistentGps(obj.Id); } } else if (obj is MySystemAsteroids) { var instance = obj as MySystemAsteroids; if (MyAsteroidObjectsManager.Static.AsteroidObjectProviders.ContainsKey(instance.AsteroidTypeName)) { var data = MyAsteroidObjectsManager.Static.AsteroidObjectProviders[instance.AsteroidTypeName].GetInstanceData(instance); if (data == null) { MyPluginLog.Debug("Asteroid instance " + obj.Id + " has no data attached, deleting it", LogLevel.WARNING); MyAsteroidObjectsManager.Static.AsteroidObjectProviders[instance.AsteroidTypeName].RemoveInstance(instance); MyGPSManager.Static.RemovePersistentGps(obj.Id); } } } } }
/// <summary> /// Loads the data for the system generator and filters the definition according to /// the global config /// </summary> public override void LoadData() { MyPluginLog.Log("Load Star system generator component"); Static = this; LoadNetworking(); if (!MySettingsSession.Static.IsEnabled()) { return; } MyPluginLog.Log("Loading definitions and network data"); var data = LoadSystemData(); StarSystem = data; MyPluginLog.Log("Loaded system data. Checking Asteroid objects"); if (StarSystem != null && StarSystem.CenterObject != null) { foreach (var obj in StarSystem.GetAllObjects()) { if (obj.Type == MySystemObjectType.ASTEROIDS) { var asteroid = obj as MySystemAsteroids; var provider = MyAsteroidObjectsManager.Static.AsteroidObjectProviders[asteroid.AsteroidTypeName]; if (!provider.TryLoadObject(asteroid)) { MyPluginLog.Log("No data found associated with asteroid object " + asteroid.DisplayName + " (" + asteroid.Id + "), Removing it.", LogLevel.WARNING); StarSystem.RemoveObject(asteroid.Id); } } } } MyPluginLog.Log("All asteroid objects checked"); m_planets = new List <MyPlanetGeneratorDefinition>(); m_moons = new List <MyPlanetGeneratorDefinition>(); m_suns = new List <MyPlanetGeneratorDefinition>(); m_gasGiants = new List <MyPlanetGeneratorDefinition>(); m_mandatoryPlanets = new List <MyPlanetGeneratorDefinition>(); m_mandatoryMoons = new List <MyPlanetGeneratorDefinition>(); MyPluginLog.Log("Load Star system generator component completed"); }