diff --git a/SEWorldGenPlugin/Generator/MyStarSystemGenerator.cs b/SEWorldGenPlugin/Generator/MyStarSystemGenerator.cs index f38f7e7..5c9c59f 100644 --- a/SEWorldGenPlugin/Generator/MyStarSystemGenerator.cs +++ b/SEWorldGenPlugin/Generator/MyStarSystemGenerator.cs @@ -171,13 +171,13 @@ private void AddAllPersistentGps() case MySystemObjectType.MOON: if (settings.MoonGPSMode == MyGPSGenerationMode.PERSISTENT) { - MyGPSManager.Static.AddPersistentGps(item.DisplayName, MOON_GPS_COLOR, item.CenterPosition); + MyGPSManager.Static.AddPersistentGps(item.DisplayName, MOON_GPS_COLOR, item.CenterPosition, item.Id); } break; case MySystemObjectType.PLANET: if (settings.PlanetGPSMode == MyGPSGenerationMode.PERSISTENT) { - MyGPSManager.Static.AddPersistentGps(item.DisplayName, PLANET_GPS_COLOR, item.CenterPosition); + MyGPSManager.Static.AddPersistentGps(item.DisplayName, PLANET_GPS_COLOR, item.CenterPosition, item.Id); } break; case MySystemObjectType.ASTEROIDS: @@ -187,7 +187,7 @@ private void AddAllPersistentGps() MyAbstractAsteroidObjectProvider provider = null; if (MyAsteroidObjectsManager.Static.AsteroidObjectProviders.TryGetValue(asteroid.AsteroidTypeName, out provider)) { - MyGPSManager.Static.AddPersistentGps(item.DisplayName, RING_GPS_COLOR, provider.GetAsteroidObjectShape(asteroid).GetPointInShape()); + MyGPSManager.Static.AddPersistentGps(item.DisplayName, RING_GPS_COLOR, provider.GetAsteroidObjectShape(asteroid).GetPointInShape(), item.Id); } } break; diff --git a/SEWorldGenPlugin/Generator/ProceduralGeneration/MyProceduralAsteroidsModule.cs b/SEWorldGenPlugin/Generator/ProceduralGeneration/MyProceduralAsteroidsModule.cs index cc3b012..8487e98 100644 --- a/SEWorldGenPlugin/Generator/ProceduralGeneration/MyProceduralAsteroidsModule.cs +++ b/SEWorldGenPlugin/Generator/ProceduralGeneration/MyProceduralAsteroidsModule.cs @@ -209,27 +209,27 @@ public override void UpdateGpsForPlayer(MyEntityTracker entity) if(shape.Contains(entityPosition) != ContainmentType.Disjoint) { - MyGPSManager.Static.RemoveDynamicGps(asteroid.DisplayName, Color.Yellow, player.GetPlayerIdentityId()); + MyGPSManager.Static.RemoveDynamicGps(player.GetPlayerIdentityId(), asteroid.Id); } Vector3D closestPos = shape.GetClosestPoint(entityPosition); double distance = Vector3D.Subtract(entityPosition, closestPos).Length(); if (distance > 5000000) { - MyGPSManager.Static.RemoveDynamicGps(asteroid.DisplayName, Color.Yellow, player.GetPlayerIdentityId()); + MyGPSManager.Static.RemoveDynamicGps(player.GetPlayerIdentityId(), asteroid.Id); } else if(distance > 5) { - if(MyGPSManager.Static.DynamicGpsExists(asteroid.DisplayName, Color.Yellow, player.GetPlayerIdentityId())) + if(MyGPSManager.Static.DynamicGpsExists(asteroid.Id, player.GetPlayerIdentityId())) { - MyGPSManager.Static.ModifyDynamicGps(asteroid.DisplayName, Color.Yellow, closestPos, player.GetPlayerIdentityId()); + MyGPSManager.Static.ModifyDynamicGps(asteroid.DisplayName, Color.Yellow, closestPos, player.GetPlayerIdentityId(), asteroid.Id); continue; } - MyGPSManager.Static.AddDynamicGps(asteroid.DisplayName, Color.Yellow, closestPos, player.GetPlayerIdentityId()); + MyGPSManager.Static.AddDynamicGps(asteroid.DisplayName, Color.Yellow, closestPos, player.GetPlayerIdentityId(), asteroid.Id); } else { - MyGPSManager.Static.RemoveDynamicGps(asteroid.DisplayName, Color.Yellow, player.GetPlayerIdentityId()); + MyGPSManager.Static.RemoveDynamicGps(player.GetPlayerIdentityId(), asteroid.Id); } } } @@ -264,8 +264,6 @@ protected override MyProceduralCell GenerateCellSeeds(Vector3I cellId) var ring = GetAsteroidObjectAt(position); - MyPluginLog.Debug("Asteroid object is there " + ring); - if (ring == null) continue; var cellObjectSeed = new MyObjectSeed(cell, position, MyRandom.Instance.Next(ring.AsteroidSize.Min, ring.AsteroidSize.Max)); diff --git a/SEWorldGenPlugin/Generator/ProceduralGeneration/MyProceduralPlanetModule.cs b/SEWorldGenPlugin/Generator/ProceduralGeneration/MyProceduralPlanetModule.cs index f316add..754e7b1 100644 --- a/SEWorldGenPlugin/Generator/ProceduralGeneration/MyProceduralPlanetModule.cs +++ b/SEWorldGenPlugin/Generator/ProceduralGeneration/MyProceduralPlanetModule.cs @@ -80,29 +80,26 @@ public override void UpdateGpsForPlayer(MyEntityTracker tracker) if (settings.PlanetGPSMode != MyGPSGenerationMode.DISCOVERY && settings.MoonGPSMode != MyGPSGenerationMode.DISCOVERY) return; - if(systemObjects.Count > 0) + foreach(var obj in systemObjects) { - foreach(var obj in systemObjects) + if((obj.Type == MySystemObjectType.MOON && settings.MoonGPSMode == MyGPSGenerationMode.DISCOVERY) || (obj.Type == MySystemObjectType.PLANET && settings.PlanetGPSMode == MyGPSGenerationMode.DISCOVERY)) { - if(obj.Type == MySystemObjectType.MOON || obj.Type == MySystemObjectType.PLANET) - { - var distance = Vector3D.Distance(tracker.CurrentPosition, obj.CenterPosition); + var distance = Vector3D.Distance(tracker.CurrentPosition, obj.CenterPosition); - if(distance <= 50000000) + if(distance <= 50000000) + { + if (MyGPSManager.Static.DynamicGpsExists(obj.Id, entity.GetPlayerIdentityId())) { - if (MyGPSManager.Static.DynamicGpsExists(obj.DisplayName, GPS_COLOR, entity.GetPlayerIdentityId())) - { - MyGPSManager.Static.ModifyDynamicGps(obj.DisplayName, GPS_COLOR, obj.CenterPosition, entity.GetPlayerIdentityId()); - } - else - { - MyGPSManager.Static.AddDynamicGps(obj.DisplayName, GPS_COLOR, obj.CenterPosition, entity.GetPlayerIdentityId()); - } - return; + MyGPSManager.Static.ModifyDynamicGps(obj.DisplayName, GPS_COLOR, obj.CenterPosition, entity.GetPlayerIdentityId(), obj.Id); } - - MyGPSManager.Static.RemoveDynamicGps(obj.DisplayName, GPS_COLOR, entity.GetPlayerIdentityId()); + else + { + MyGPSManager.Static.AddDynamicGps(obj.DisplayName, GPS_COLOR, obj.CenterPosition, entity.GetPlayerIdentityId(), obj.Id); + } + continue; } + + MyGPSManager.Static.RemoveDynamicGps(entity.GetPlayerIdentityId(), obj.Id); } } } diff --git a/SEWorldGenPlugin/ObjectBuilders/MyObjectBuilder_WorldGpsData.cs b/SEWorldGenPlugin/ObjectBuilders/MyObjectBuilder_WorldGpsData.cs index 5c21ebf..8be1489 100644 --- a/SEWorldGenPlugin/ObjectBuilders/MyObjectBuilder_WorldGpsData.cs +++ b/SEWorldGenPlugin/ObjectBuilders/MyObjectBuilder_WorldGpsData.cs @@ -1,4 +1,5 @@ using ProtoBuf; +using System; using System.Collections.Generic; using VRage; using VRageMath; @@ -37,9 +38,15 @@ public class PersistentGpsData public SerializableVector3D Position = Vector3D.Zero; /// - /// A set of all players, that already know of this gps. + /// The Id of the gps object /// [ProtoMember(4)] + public Guid Id = Guid.Empty; + + /// + /// A set of all players, that already know of this gps. + /// + [ProtoMember(5)] public HashSet PlayerIds = new HashSet(); } } diff --git a/SEWorldGenPlugin/Session/MyGPSManager.cs b/SEWorldGenPlugin/Session/MyGPSManager.cs index 9aa55fd..e44adb6 100644 --- a/SEWorldGenPlugin/Session/MyGPSManager.cs +++ b/SEWorldGenPlugin/Session/MyGPSManager.cs @@ -18,7 +18,7 @@ public class MyGPSManager : MySessionComponentBase /// /// Struct that identifies a gps /// - struct MyGpsId + struct MyGpsData { public string Name; @@ -26,14 +26,30 @@ struct MyGpsId public Vector3D Position; - public MyGpsId(string name, Vector3 color, Vector3D position) + public Guid Id; + + public HashSet Players; + + public MyGpsData(string name, Vector3 color, Vector3D position, Guid id) + { + Name = name; + Color = color; + Position = position; + Id = id; + Players = new HashSet(); + } + + public MyGpsData(string name, Vector3 color, Vector3D position, Guid id, HashSet players) { Name = name; Color = color; Position = position; + Id = id; + Players = players; } } + /// /// File name for the save file containing the gps data /// @@ -45,15 +61,15 @@ public MyGpsId(string name, Vector3 color, Vector3D position) public static MyGPSManager Static; /// - /// A map of all global gpss and the players that gps is known to + /// A map of all global gps ids and data /// - private Dictionary> m_globalGpss; + private Dictionary m_globalGpss; /// /// A map of all dynamic gpss and their corresponding player ids to the hash of the gps, /// to allow modification of it. /// - private Dictionary, int> m_dynamicGpss; + private Dictionary, int> m_dynamicGpss; /// /// Adds a new gps persistent gps to all players @@ -61,27 +77,32 @@ public MyGpsId(string name, Vector3 color, Vector3D position) /// Name of the gps /// Color of the gps /// Position of the gps - public void AddPersistentGps(string name, Color color, Vector3D pos) + /// The id of the gps + public void AddPersistentGps(string name, Color color, Vector3D pos, Guid id) { - MyGpsId id = new MyGpsId(name, color, pos); + MyGpsData data = new MyGpsData() + { + Name = name, + Color = color, + Position = pos, + Id = id, + Players = new HashSet() + }; if (!m_globalGpss.ContainsKey(id)) { MyPluginLog.Debug("Adding new persistent gps " + name); - m_globalGpss[id] = new HashSet(); + m_globalGpss[id] = data; } } /// /// Checks if a given persistent gps already exists /// - /// Name of the gps - /// Color of the gps - /// Position of the gps + /// The id of the gps /// True if the persistent gps exists - public bool PersistenGpsExists(string name, Color color, Vector3D pos) + public bool PersistenGpsExists(Guid id) { - MyGpsId id = new MyGpsId(name, color, pos); return m_globalGpss.ContainsKey(id); } @@ -91,12 +112,12 @@ public bool PersistenGpsExists(string name, Color color, Vector3D pos) /// Name of the gps /// Color of the gps /// Position of the gps - /// Player, the gps belongs to + /// Player, the gps belongs to + /// The id of the gps /// False, if the gps is already added, else true - public bool AddDynamicGps(string name, Color color, Vector3D pos, long playerId) + public bool AddDynamicGps(string name, Color color, Vector3D pos, long playerId, Guid id) { - MyGpsId id = new MyGpsId(name, color, pos); - Tuple key = new Tuple(id, playerId); + Tuple key = new Tuple(id, playerId); if (m_dynamicGpss.ContainsKey(key)) return false; MyGps gps = new MyGps @@ -123,12 +144,12 @@ public bool AddDynamicGps(string name, Color color, Vector3D pos, long playerId) /// Name of the existing gps /// Color of the gps, needs to be the same as the old one /// New Position of the gps - /// + /// + /// The id of the gps /// - public bool ModifyDynamicGps(string name, Color color, Vector3D pos, long playerId) + public bool ModifyDynamicGps(string name, Color color, Vector3D pos, long playerId, Guid id) { - MyGpsId id = new MyGpsId(name, color, pos); - Tuple key = new Tuple(id, playerId); + Tuple key = new Tuple(id, playerId); if (m_dynamicGpss.ContainsKey(key)) { @@ -138,6 +159,8 @@ public bool ModifyDynamicGps(string name, Color color, Vector3D pos, long player if (gps == null) return false; gps.Coords = pos; + gps.Name = name; + gps.GPSColor = color; MySession.Static.Gpss.SendModifyGps(playerId, gps); @@ -153,14 +176,12 @@ public bool ModifyDynamicGps(string name, Color color, Vector3D pos, long player /// /// Tries to remove a dynamic gps marker from the player /// - /// Name of the gps - /// Color of the gps - /// Player, the gps belongs to + /// The gps id + /// The player id of the player this gps belongs to /// - public bool RemoveDynamicGps(string name, Color color, long playerId) + public bool RemoveDynamicGps(long playerId, Guid id) { - MyGpsId id = new MyGpsId(name, color, Vector3D.Zero); - Tuple key = new Tuple(id, playerId); + Tuple key = new Tuple(id, playerId); if (m_dynamicGpss.ContainsKey(key)) { @@ -174,14 +195,12 @@ public bool RemoveDynamicGps(string name, Color color, long playerId) /// /// Checks, whether or not the gps already exists. /// - /// Name of the gps - /// Color of the gps - /// Player, the gps belongs to + /// The gps id + /// The player id of the player this gps belongs to /// - public bool DynamicGpsExists(string name, Color color, long playerId) + public bool DynamicGpsExists(Guid id, long playerId) { - MyGpsId id = new MyGpsId(name, color, Vector3D.Zero); - Tuple key = new Tuple(id, playerId); + Tuple key = new Tuple(id, playerId); return m_dynamicGpss.ContainsKey(key); } @@ -198,19 +217,19 @@ public override void UpdateBeforeSimulation() { foreach (var p in MySession.Static.Players.GetOnlinePlayers()) { - if (m_globalGpss[entry].Contains(p.Identity.IdentityId)) continue; + if (m_globalGpss[entry].Players.Contains(p.Identity.IdentityId)) continue; MyGps gps = new MyGps { - Name = entry.Name, - Coords = entry.Position, - GPSColor = entry.Color, + Name = m_globalGpss[entry].Name, + Coords = m_globalGpss[entry].Position, + GPSColor = m_globalGpss[entry].Color, ShowOnHud = true, AlwaysVisible = false, DiscardAt = null }; MySession.Static.Gpss.SendAddGps(p.Identity.IdentityId, ref gps, playSoundOnCreation: false); - m_globalGpss[entry].Add(p.Identity.IdentityId); + m_globalGpss[entry].Players.Add(p.Identity.IdentityId); } } } @@ -234,13 +253,13 @@ public override void LoadData() ob = new MyObjectBuilder_WorldGpsData(); } - m_globalGpss = new Dictionary>(); - m_dynamicGpss = new Dictionary, int>(); + m_globalGpss = new Dictionary(); + m_dynamicGpss = new Dictionary, int>(); foreach(var item in ob.PersistentGpss) { - var id = new MyGpsId(item.Name, item.Color, item.Position); - m_globalGpss[id] = item.PlayerIds; + var data = new MyGpsData(item.Name, item.Color, item.Position, item.Id, item.PlayerIds); + m_globalGpss[item.Id] = data; } MyPluginLog.Log("Loading GPS manager data completed"); @@ -256,13 +275,14 @@ public override void SaveData() MyPluginLog.Log("Saving GPS manager data"); MyObjectBuilder_WorldGpsData ob = new MyObjectBuilder_WorldGpsData(); - foreach(var entry in m_globalGpss.Keys) + foreach(var entry in m_globalGpss) { PersistentGpsData item = new PersistentGpsData(); - item.Name = entry.Name; - item.Color = entry.Color; - item.Position = entry.Position; - item.PlayerIds = m_globalGpss[entry]; + item.Name = entry.Value.Name; + item.Color = entry.Value.Color; + item.Position = entry.Value.Position; + item.PlayerIds = entry.Value.Players; + item.Id = entry.Key; ob.PersistentGpss.Add(item); }