diff --git a/SEWorldGenPlugin/Generator/MyStarSystemGenerator.cs b/SEWorldGenPlugin/Generator/MyStarSystemGenerator.cs index b50fe8f..346d7a5 100644 --- a/SEWorldGenPlugin/Generator/MyStarSystemGenerator.cs +++ b/SEWorldGenPlugin/Generator/MyStarSystemGenerator.cs @@ -114,7 +114,6 @@ public override void Init(MyObjectBuilder_SessionComponent sessionComponent) } CheckIntegrityOfSystem(); - AddPlanetDeleteAction(); } /// @@ -656,28 +655,6 @@ private void LoadPlanetDefinitions() } } - /// - /// Adds the action called, when planets are deleted - /// - private void AddPlanetDeleteAction() - { - List planets = MyEntityList.GetEntityList(MyEntityList.MyEntityTypeEnum.Planets); - foreach(var p in planets) - { - var e = MyEntities.GetEntityById(p.EntityId) as MyPlanet; - e.OnClose += OnPlanetClose; - } - - MyEntities.OnEntityAdd += delegate (MyEntity entity) - { - if(entity is MyPlanet) - { - MyPluginLog.Debug("Planet created, adding close action"); - entity.OnClose += OnPlanetClose; - } - }; - } - /// /// 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 @@ -693,6 +670,7 @@ private void CheckIntegrityOfSystem() { 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) @@ -706,6 +684,7 @@ private void CheckIntegrityOfSystem() { 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); } } } @@ -713,38 +692,6 @@ private void CheckIntegrityOfSystem() MyPluginLog.Debug("Integrity check complete"); } - /// - /// Action for planet close - /// - /// Entity that gets closed - public static void OnPlanetClose(MyEntity entity) - { - MyPlanet e = null; - if (entity is MyPlanet) - { - e = entity as MyPlanet; - } - else return; - - MyPluginLog.Log("Planet " + e.StorageName + " is getting removed. Removing its star system instance"); - foreach (var obj in Static.StarSystem.GetAllObjects()) - { - if (obj is MySystemPlanet) - { - var planet = obj as MySystemPlanet; - - if (planet.EntityId == e.EntityId) - { - if (Static.StarSystem.RemoveObject(planet.Id)) - { - MyPluginLog.Log("Star system instance of planet " + e.StorageName + " was removed"); - } - break; - } - } - } - } - /// /// Loads the system data xml file from the world folder, or, /// if none exist, returns a new one. @@ -772,6 +719,8 @@ public override void UpdateBeforeSimulation() if (!MySettingsSession.Static.IsEnabled()) return; + CheckIntegrityOfSystem(); + List planets = MyEntityList.GetEntityList(MyEntityList.MyEntityTypeEnum.Planets); foreach (var p in planets) { diff --git a/SEWorldGenPlugin/Session/MyGPSManager.cs b/SEWorldGenPlugin/Session/MyGPSManager.cs index 5808878..085c0c4 100644 --- a/SEWorldGenPlugin/Session/MyGPSManager.cs +++ b/SEWorldGenPlugin/Session/MyGPSManager.cs @@ -106,6 +106,34 @@ public bool PersistenGpsExists(Guid id) return m_globalGpss.ContainsKey(id); } + /// + /// Removes the given persistent gps if it exists + /// + /// Id of persistent gps + public void RemovePersistentGps(Guid id) + { + if (PersistenGpsExists(id)) + { + + MyGps gps = new MyGps + { + Name = m_globalGpss[id].Name, + Coords = m_globalGpss[id].Position, + GPSColor = m_globalGpss[id].Color, + ShowOnHud = true, + AlwaysVisible = false, + DiscardAt = null + }; + + foreach (var playerId in m_globalGpss[id].Players) + { + MySession.Static.Gpss.SendDelete(playerId, gps.CalculateHash()); + } + + m_globalGpss.Remove(id); + } + } + /// /// Adds a new Dynamic gps to the player /// @@ -236,6 +264,9 @@ public override void UpdateBeforeSimulation() AlwaysVisible = false, DiscardAt = null }; + + gps.CalculateHash(); + MySession.Static.Gpss.SendAddGps(p.Identity.IdentityId, ref gps, playSoundOnCreation: false); m_globalGpss[entry].Players.Add(p.Identity.IdentityId); }