From 8e12594fc0e53c37e162379fef070603fabf6c40 Mon Sep 17 00:00:00 2001 From: Thorwin Vogt Date: Sat, 14 Sep 2019 18:01:31 +0200 Subject: [PATCH] Changed seeds and added gps markers and names for objects --- .../ProceduralAsteroidsRingModule.cs | 2 +- .../ProceduralGen/ProceduralGenerator.cs | 6 +- .../ProceduralGen/ProceduralPlanetModule.cs | 9 ++- SEWorldGenPlugin/Generator/SystemGenerator.cs | 60 +++++++++++++++---- 4 files changed, 57 insertions(+), 20 deletions(-) diff --git a/SEWorldGenPlugin/Generator/ProceduralGen/ProceduralAsteroidsRingModule.cs b/SEWorldGenPlugin/Generator/ProceduralGen/ProceduralAsteroidsRingModule.cs index 8a0c9bd..7a3a3b4 100644 --- a/SEWorldGenPlugin/Generator/ProceduralGen/ProceduralAsteroidsRingModule.cs +++ b/SEWorldGenPlugin/Generator/ProceduralGen/ProceduralAsteroidsRingModule.cs @@ -24,7 +24,7 @@ public class ProceduralAsteroidsRingModule : ProceduralModule { private const int OBJECT_SIZE_MIN = 128; private const int OBJECT_SIZE_MAX = 512; - private const int SUBCELL_SIZE = (int)(OBJECT_SIZE_MAX * 3); + private const int SUBCELL_SIZE = OBJECT_SIZE_MAX * 3; private const int SUBCELLS = 6; public ProceduralAsteroidsRingModule(int seed) : base(seed, SUBCELLS * SUBCELL_SIZE) diff --git a/SEWorldGenPlugin/Generator/ProceduralGen/ProceduralGenerator.cs b/SEWorldGenPlugin/Generator/ProceduralGen/ProceduralGenerator.cs index 8351007..a202686 100644 --- a/SEWorldGenPlugin/Generator/ProceduralGen/ProceduralGenerator.cs +++ b/SEWorldGenPlugin/Generator/ProceduralGen/ProceduralGenerator.cs @@ -1,6 +1,4 @@ -using Sandbox.Engine.Multiplayer; -using Sandbox.Engine.Utils; -using Sandbox.Game.Entities; +using Sandbox.Game.Entities; using Sandbox.Game.Entities.Character; using Sandbox.Game.Multiplayer; using Sandbox.Game.World; @@ -12,9 +10,7 @@ using VRage.Game; using VRage.Game.Components; using VRage.Game.Entity; -using VRage.Library.Utils; using VRage.Utils; -using VRageMath; /* * Code is primarily taken from the Space Engineers GitHub repository. diff --git a/SEWorldGenPlugin/Generator/ProceduralGen/ProceduralPlanetModule.cs b/SEWorldGenPlugin/Generator/ProceduralGen/ProceduralPlanetModule.cs index a0f6c82..43e8208 100644 --- a/SEWorldGenPlugin/Generator/ProceduralGen/ProceduralPlanetModule.cs +++ b/SEWorldGenPlugin/Generator/ProceduralGen/ProceduralPlanetModule.cs @@ -54,7 +54,6 @@ public void GeneratePlanets(MyEntity e) planet.CenterPosition = generatedPlanet.PositionComp.GetPosition(); if (planet.PlanetRing != null) planet.PlanetRing.Center = planet.CenterPosition; - List spawnedMoons = new List(); for(int i = 0; i < planet.PlanetMoons.Length; i++) @@ -73,9 +72,13 @@ public void GeneratePlanets(MyEntity e) threshold++; } while (ObstructedPlace(position, spawnedMoons, planet.Size, planet.PlanetRing) && threshold < 10000); - spawnedMoons.Add(CreatePlanet(position, moon.Size, ref moonDef).PositionComp.GetPosition()); + MyPlanet spawnedMoon = CreatePlanet(position, moon.Size, ref moonDef); + spawnedMoons.Add(spawnedMoon.PositionComp.GetPosition()); + + SystemGenerator.AddObjectGps(moon, spawnedMoon.PositionComp.GetPosition()); } planet.Generated = true; + SystemGenerator.AddObjectGps(planet, planet.CenterPosition); } } @@ -167,7 +170,7 @@ private MyPlanet CreatePlanet(Vector3D? position, float? size, ref MyPlanetGener planetInitArguments.MarkAreaEmpty = true; planetInitArguments.AtmosphereSettings = generatorDef.AtmosphereSettings.HasValue ? generatorDef.AtmosphereSettings.Value : MyAtmosphereSettings.Defaults(); planetInitArguments.SurfaceGravity = generatorDef.SurfaceGravity; - planetInitArguments.AddGps = true; + planetInitArguments.AddGps = false; planetInitArguments.SpherizeWithDistance = true; planetInitArguments.Generator = generatorDef; planetInitArguments.UserCreated = false; diff --git a/SEWorldGenPlugin/Generator/SystemGenerator.cs b/SEWorldGenPlugin/Generator/SystemGenerator.cs index 50d63d9..242e11e 100644 --- a/SEWorldGenPlugin/Generator/SystemGenerator.cs +++ b/SEWorldGenPlugin/Generator/SystemGenerator.cs @@ -1,6 +1,7 @@ using Sandbox.Definitions; using Sandbox.Engine.Multiplayer; using Sandbox.Game.Multiplayer; +using Sandbox.Game.Screens.Helpers; using Sandbox.Game.World; using Sandbox.ModAPI; using SEWorldGenPlugin.ObjectBuilders; @@ -27,6 +28,7 @@ public class SystemGenerator : MySessionComponentBase private const int MIN_RING_WIDTH = 10000; private const int MAX_RING_WIDTH = 100000; private const int MIN_RING_HEIGHT = 1000; + private string[] greek_letters = new string[10] {"Alpha", "Beta", "Gamma", "Delta", "Epsilon", "Zeta", "Eta", "Theta", "Iota", "Kappa"}; private const string STORAGE_FILE = "SystemData.xml"; @@ -53,12 +55,17 @@ public override void Init(MyObjectBuilder_SessionComponent sessionComponent) MyObjectBuilder_StarSystem b = GetConfig(); m_objects = b.SystemObjects; - m_seed = MySession.Static.Settings.ProceduralSeed; + m_seed = MySession.Static.Settings.ProceduralSeed + MyRandom.Instance.CreateRandomSeed(); if (b == null || m_objects == null || m_objects.Count == 0) { GenerateSystem(); } + + MySession.Static.OnReady += delegate + { + AddBeltsGpss(); + }; } public override void LoadData() @@ -69,9 +76,7 @@ public override void LoadData() m_planetDefinitions = MyDefinitionManager.Static.GetPlanetsGeneratorsDefinitions().ToList(); FilterDefinitions(); - - m_seed = MySession.Static.Settings.ProceduralSeed + MyRandom.Instance.CreateRandomSeed(); - + MySession.Static.Settings.ProceduralDensity = 0; } @@ -95,6 +100,7 @@ private void GenerateSystem() { int numberPlanets = MyRandom.Instance.Next(MIN_PLANETS_COUNT, MAX_PLANETS_COUNT); long tmp_distance = 0; + int totalBelts = 0; for (int i = 0; i < numberPlanets; i++) { @@ -102,20 +108,21 @@ private void GenerateSystem() tmp_distance += distToPrev; if(MyRandom.Instance.NextDouble() * ((i % 6) * (i & 6) / 12.5) < 0.5){ - GeneratePlanet(i, tmp_distance); + GeneratePlanet(i, tmp_distance, numberPlanets); } else { - GenerateBelt(tmp_distance); + GenerateBelt(tmp_distance, ref totalBelts); } } } } - private void GenerateBelt(long distance) + private void GenerateBelt(long distance, ref int beltIndex) { MySystemBeltItem belt = new MySystemBeltItem(); + belt.DisplayName = "Belt " + greek_letters[beltIndex++]; belt.Type = SystemObjectType.BELT; belt.Height = MyRandom.Instance.Next(4000, 40000); belt.Radius = distance; @@ -125,29 +132,30 @@ private void GenerateBelt(long distance) m_objects.Add(belt); } - private void GeneratePlanet(int maxSize, long distance) + private void GeneratePlanet(int index, long distance, int totalObjects) { MyPlanetItem planet = new MyPlanetItem(); - var def = GetPlanetDefinition(maxSize); + var def = GetPlanetDefinition((int)(MAX_PLANET_SIZE * Math.Sin(index * Math.PI / totalObjects))); var angle = MyRandom.Instance.GetRandomFloat(0, (float)(2 * Math.PI)); var height = MyRandom.Instance.GetRandomFloat((float)Math.PI / 180 * -5, (float)Math.PI / 180 * 5); Vector3D pos = new Vector3D(distance * Math.Sin(angle), distance * Math.Cos(angle), distance * Math.Sin(height)); + planet.DisplayName = "Planet " + (index + 1); planet.Type = SystemObjectType.PLANET; planet.DefName = def.Id.SubtypeId.String; planet.Size = SizeByGravity(def.SurfaceGravity); planet.PlanetRing = GenerateRing(def.SurfaceGravity, planet.Size); planet.OffsetPosition = pos; planet.CenterPosition = Vector3D.Zero; - planet.PlanetMoons = GenerateMoons(planet.Size, def.SurfaceGravity); + planet.PlanetMoons = GenerateMoons(planet.Size, def.SurfaceGravity, planet.DisplayName); planet.Generated = false; m_objects.Add(planet); } - private MyPlanetMoonItem[] GenerateMoons(float planetSize, float surfaceGravity) + private MyPlanetMoonItem[] GenerateMoons(float planetSize, float surfaceGravity, string planetName) { int numMoons = MyRandom.Instance.Next(0, GetMaxMoonCount(surfaceGravity)); MyPlanetMoonItem[] moons = new MyPlanetMoonItem[numMoons]; @@ -162,6 +170,7 @@ private MyPlanetMoonItem[] GenerateMoons(float planetSize, float surfaceGravity) item.DefName = def.Id.SubtypeName.ToString(); item.Distance = dist; item.Size = SizeByGravity(def.SurfaceGravity); + item.DisplayName = planetName + " " + (char)('A' + i); moons[i] = item; } @@ -181,6 +190,7 @@ private MyPlanetRingItem GenerateRing(float surfaceGravity, float planetSize) ring.Height = MyRandom.Instance.Next(MIN_RING_HEIGHT, ring.Width / 10); ring.AngleDegrees = MyRandom.Instance.Next(-180, 180); ring.Radius = MyRandom.Instance.Next((int)(planetSize * 0.5 * 0.75), (int)(planetSize)); + ring.DisplayName = ""; return ring; } @@ -270,5 +280,33 @@ private void SaveConfig() writer.Close(); } } + + private void AddBeltsGpss() + { + foreach (var obj in m_objects) + { + if (obj.Type != SystemObjectType.BELT) continue; + + Vector3D pos = new Vector3D(((MySystemBeltItem)obj).Radius + ((MySystemBeltItem)obj).Width / 2, 0, 0); ; + + AddObjectGps(obj, pos); + } + } + + public static void AddObjectGps(MySystemItem obj, Vector3D position) + { + MyGps gps = new MyGps() + { + Name = obj.DisplayName, + Coords = position, + ShowOnHud = true, + GPSColor = Color.LightGray, + AlwaysVisible = true, + DiscardAt = TimeSpan.FromDays(100) + }; + + gps.UpdateHash(); + MySession.Static.Gpss.SendAddGps(MySession.Static.LocalPlayerId, ref gps); + } } }