Skip to content

Commit

Permalink
Changed seeds and added gps markers and names for objects
Browse files Browse the repository at this point in the history
  • Loading branch information
thorwin99 committed Sep 14, 2019
1 parent 7d83df5 commit 8e12594
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public void GeneratePlanets(MyEntity e)
planet.CenterPosition = generatedPlanet.PositionComp.GetPosition();
if (planet.PlanetRing != null)
planet.PlanetRing.Center = planet.CenterPosition;

List<Vector3D> spawnedMoons = new List<Vector3D>();

for(int i = 0; i < planet.PlanetMoons.Length; i++)
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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;
Expand Down
60 changes: 49 additions & 11 deletions SEWorldGenPlugin/Generator/SystemGenerator.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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";

Expand All @@ -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()
Expand All @@ -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;
}

Expand All @@ -95,27 +100,29 @@ 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++)
{
int distToPrev = MyRandom.Instance.Next(MIN_PLANET_DISTANCE, MAX_PLANET_DISTANCE);
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;
Expand All @@ -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];
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 8e12594

Please sign in to comment.