Skip to content

Commit

Permalink
Changed asteroid ring generation, added probability setting
Browse files Browse the repository at this point in the history
  • Loading branch information
thorwin99 committed Sep 24, 2019
1 parent 981c605 commit 06116ce
Show file tree
Hide file tree
Showing 10 changed files with 246 additions and 226 deletions.
50 changes: 36 additions & 14 deletions SEWorldGenPlugin/GUI/PluginSettingsGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
using Sandbox.Game.Localization;
using Sandbox.Graphics.GUI;
using SEWorldGenPlugin.ObjectBuilders;
using SEWorldGenPlugin.Utilities;
using SEWorldGenPlugin.Utilities.SEWorldGenPlugin.Utilities;
using System;
using VRage.Utils;
using VRageMath;
using SEWorldGenPlugin.Utilities;

namespace SEWorldGenPlugin.GUI
{
Expand All @@ -19,6 +18,7 @@ public class PluginSettingsGui : MyGuiScreenBase
private MyGuiControlLabel m_sizeCapLabel;
private MyGuiControlLabel m_moonProbLabel;
private MyGuiControlLabel m_ringWidthLabel;
private MyGuiControlLabel m_ringProbLabel;
private MyGuiControlLabel m_beltHeightLabel;
private MyGuiControlLabel m_beltProbLabel;

Expand All @@ -28,6 +28,7 @@ public class PluginSettingsGui : MyGuiScreenBase
private MyGuiControlLabel m_sizeCapValue;
private MyGuiControlLabel m_moonProbValue;
private MyGuiControlLabel m_ringWidthValue;
private MyGuiControlLabel m_ringProbValue;
private MyGuiControlLabel m_beltHeightValue;
private MyGuiControlLabel m_beltProbValue;

Expand All @@ -38,6 +39,7 @@ public class PluginSettingsGui : MyGuiScreenBase
private MyGuiControlSlider m_sizeCapSlider;
private MyGuiControlSlider m_moonProbSlider;
private MyGuiControlSlider m_ringWidthSlider;
private MyGuiControlSlider m_ringProbSlider;
private MyGuiControlSlider m_beltHeightSlider;
private MyGuiControlSlider m_beltProbSlider;

Expand Down Expand Up @@ -82,18 +84,20 @@ public void BuildControls()
m_sizeCapLabel = MakeLabel("Planet size cap");
m_moonProbLabel = MakeLabel("Moon spawn probability");
m_ringWidthLabel = MakeLabel("Average ring width");
m_ringProbLabel = MakeLabel("Ring spawn probability");
m_beltHeightLabel = MakeLabel("Average belt height");
m_beltProbLabel = MakeLabel("Belt spawn probability");

m_useGlobalCheck = new MyGuiControlCheckbox();
m_objAmountSlider = new MyGuiControlSlider(Vector2.Zero, 0f, 100f, x2, 15f, null, null, 0, 0.8f, 0.05f, "White", MyTexts.TOOLTIPS.SYS_OBJ_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: true);
m_orbDistanceSlider = new MyGuiControlSlider(Vector2.Zero, 1000f, 100000f, x2, 50500f, null, null, 0, 0.8f, 0.05f, "White", MyTexts.TOOLTIPS.ORB_DIST_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: true);
m_sizeMultiplierSlider = new MyGuiControlSlider(Vector2.Zero, 1f, 10f, x2, 2f, null, null, 0, 0.8f, 0.05f, "White", MyTexts.TOOLTIPS.SIZE_MUL_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: true);
m_sizeCapSlider = new MyGuiControlSlider(Vector2.Zero, 120f, 2400f, x2, 1200f, null, null, 0, 0.8f, 0.05f, "White", MyTexts.TOOLTIPS.SIZE_CAP_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: true);
m_moonProbSlider = new MyGuiControlSlider(Vector2.Zero, 0f, 1f, x2, 0.5f, null, null, 0, 0.8f, 0.05f, "White", MyTexts.TOOLTIPS.MOON_PROB_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: false);
m_ringWidthSlider = new MyGuiControlSlider(Vector2.Zero, 1000f, 10000f, x2, 5000f, null, null, 0, 0.8f, 0.05f, "White", MyTexts.TOOLTIPS.RING_WIDTH_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: true);
m_beltHeightSlider = new MyGuiControlSlider(Vector2.Zero, 4000f, 40000f, x2, 22000f, null, null, 0, 0.8f, 0.05f, "White", MyTexts.TOOLTIPS.BELT_HEIGHT_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: true);
m_beltProbSlider = new MyGuiControlSlider(Vector2.Zero, 0f, 1f, x2, 0.4f, null, null, 0, 0.8f, 0.05f, "White", MyTexts.TOOLTIPS.BELT_PROB_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: false);
m_objAmountSlider = new MyGuiControlSlider(Vector2.Zero, 0f, 100f, x2, 15f, null, null, 0, 0.8f, 0.05f, "White", MyPluginTexts.TOOLTIPS.SYS_OBJ_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: true);
m_orbDistanceSlider = new MyGuiControlSlider(Vector2.Zero, 1000f, 100000f, x2, 50500f, null, null, 0, 0.8f, 0.05f, "White", MyPluginTexts.TOOLTIPS.ORB_DIST_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: true);
m_sizeMultiplierSlider = new MyGuiControlSlider(Vector2.Zero, 1f, 10f, x2, 2f, null, null, 0, 0.8f, 0.05f, "White", MyPluginTexts.TOOLTIPS.SIZE_MUL_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: true);
m_sizeCapSlider = new MyGuiControlSlider(Vector2.Zero, 120f, 2400f, x2, 1200f, null, null, 0, 0.8f, 0.05f, "White", MyPluginTexts.TOOLTIPS.SIZE_CAP_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: true);
m_moonProbSlider = new MyGuiControlSlider(Vector2.Zero, 0f, 1f, x2, 0.5f, null, null, 0, 0.8f, 0.05f, "White", MyPluginTexts.TOOLTIPS.MOON_PROB_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: false);
m_ringWidthSlider = new MyGuiControlSlider(Vector2.Zero, 10000f, 100000f, x2, 15000f, null, null, 0, 0.8f, 0.05f, "White", MyPluginTexts.TOOLTIPS.RING_WIDTH_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: true);
m_ringProbSlider = new MyGuiControlSlider(Vector2.Zero, 0f, 1f, x2, 0.5f, null, null, 0, 0.8f, 0.05f, "White", MyPluginTexts.TOOLTIPS.RING_PROB_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: false);
m_beltHeightSlider = new MyGuiControlSlider(Vector2.Zero, 4000f, 40000f, x2, 22000f, null, null, 0, 0.8f, 0.05f, "White", MyPluginTexts.TOOLTIPS.BELT_HEIGHT_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: true);
m_beltProbSlider = new MyGuiControlSlider(Vector2.Zero, 0f, 1f, x2, 0.4f, null, null, 0, 0.8f, 0.05f, "White", MyPluginTexts.TOOLTIPS.BELT_PROB_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: false);

m_objAmountValue = MakeLabel(m_objAmountSlider.Value.ToString());
m_objAmountValue.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER;
Expand All @@ -107,12 +111,14 @@ public void BuildControls()
m_moonProbValue.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER;
m_ringWidthValue = MakeLabel(m_ringWidthSlider.Value.ToString());
m_ringWidthValue.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER;
m_ringProbValue = MakeLabel(m_ringProbSlider.Value.ToString());
m_ringProbValue.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER;
m_beltHeightValue = MakeLabel(m_beltHeightSlider.Value.ToString());
m_beltHeightValue.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER;
m_beltProbValue = MakeLabel(String.Format("{0:0.00}", m_beltProbSlider.Value));
m_beltProbValue.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER;

m_useGlobalCheck.SetToolTip(MyTexts.TOOLTIPS.USE_GLOBAL_CHECK);
m_useGlobalCheck.SetToolTip(MyPluginTexts.TOOLTIPS.USE_GLOBAL_CHECK);
m_useGlobalCheck.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER;

m_objAmountSlider.ValueChanged = (Action<MyGuiControlSlider>)Delegate.Combine(m_objAmountSlider.ValueChanged, (Action<MyGuiControlSlider>)delegate (MyGuiControlSlider s)
Expand All @@ -139,13 +145,17 @@ public void BuildControls()
{
m_ringWidthValue.Text = s.Value.ToString();
});
m_ringProbSlider.ValueChanged = (Action<MyGuiControlSlider>)Delegate.Combine(m_ringProbSlider.ValueChanged, (Action<MyGuiControlSlider>)delegate (MyGuiControlSlider s)
{
m_ringProbValue.Text = String.Format("{0:0.00}", s.Value);
});
m_beltHeightSlider.ValueChanged = (Action<MyGuiControlSlider>)Delegate.Combine(m_beltHeightSlider.ValueChanged, (Action<MyGuiControlSlider>)delegate (MyGuiControlSlider s)
{
m_beltHeightValue.Text = s.Value.ToString();
});
m_beltProbSlider.ValueChanged = (Action<MyGuiControlSlider>)Delegate.Combine(m_beltProbSlider.ValueChanged, (Action<MyGuiControlSlider>)delegate (MyGuiControlSlider s)
{
m_beltProbValue.Text = String.Format("{0:0.00}", s.Value); ;
m_beltProbValue.Text = String.Format("{0:0.000}", s.Value); ;
});
m_useGlobalCheck.IsCheckedChanged = (Action<MyGuiControlCheckbox>)Delegate.Combine(m_useGlobalCheck.IsCheckedChanged, (Action<MyGuiControlCheckbox>)delegate (MyGuiControlCheckbox s)
{
Expand All @@ -155,6 +165,7 @@ public void BuildControls()
m_sizeCapSlider.Enabled = !s.IsChecked;
m_moonProbSlider.Enabled = !s.IsChecked;
m_ringWidthSlider.Enabled = !s.IsChecked;
m_ringProbSlider.Enabled = !s.IsChecked;
m_beltHeightSlider.Enabled = !s.IsChecked;
m_beltProbSlider.Enabled = !s.IsChecked;
});
Expand Down Expand Up @@ -186,6 +197,10 @@ public void BuildControls()
Controls.Add(m_ringWidthSlider);
Controls.Add(m_ringWidthValue);

Controls.Add(m_ringProbLabel);
Controls.Add(m_ringProbSlider);
Controls.Add(m_ringProbValue);

Controls.Add(m_beltHeightLabel);
Controls.Add(m_beltHeightSlider);
Controls.Add(m_beltHeightValue);
Expand Down Expand Up @@ -226,11 +241,15 @@ public void BuildControls()
m_ringWidthSlider.Position = m_ringWidthLabel.Position + offset2;
m_ringWidthValue.Position = m_ringWidthLabel.Position + offset3;

m_beltHeightLabel.Position = start + offset * 7;
m_ringProbLabel.Position = start + offset * 7;
m_ringProbSlider.Position = m_ringProbLabel.Position + offset2;
m_ringProbValue.Position = m_ringProbLabel.Position + offset3;

m_beltHeightLabel.Position = start + offset * 8;
m_beltHeightSlider.Position = m_beltHeightLabel.Position + offset2;
m_beltHeightValue.Position = m_beltHeightLabel.Position + offset3;

m_beltProbLabel.Position = start + offset * 8;
m_beltProbLabel.Position = start + offset * 9;
m_beltProbSlider.Position = m_beltProbLabel.Position + offset2;
m_beltProbValue.Position = m_beltProbLabel.Position + offset3;

Expand Down Expand Up @@ -262,6 +281,8 @@ public void SetSettings(MyObjectBuilder_PluginSettings settings, bool useGlobal)

m_ringWidthSlider.Value = (settings.GeneratorSettings.PlanetSettings.RingSettings.MinPlanetRingWidth + settings.GeneratorSettings.PlanetSettings.RingSettings.MaxPlanetRingWidth) / 2;

m_ringProbSlider.Value = settings.GeneratorSettings.PlanetSettings.RingSettings.PlanetRingProbability;

m_beltHeightSlider.Value = (settings.GeneratorSettings.BeltSettings.MinBeltHeight + settings.GeneratorSettings.BeltSettings.MaxBeltHeight) / 2;
}

Expand All @@ -282,6 +303,7 @@ public bool GetSettings(ref MyObjectBuilder_PluginSettings settings)

settings.GeneratorSettings.PlanetSettings.RingSettings.MinPlanetRingWidth = (int)m_ringWidthSlider.Value / 10;
settings.GeneratorSettings.PlanetSettings.RingSettings.MaxPlanetRingWidth = (int)m_ringWidthSlider.Value * 2 - settings.GeneratorSettings.PlanetSettings.RingSettings.MinPlanetRingWidth;
settings.GeneratorSettings.PlanetSettings.RingSettings.PlanetRingProbability = m_ringProbSlider.Value;

settings.GeneratorSettings.BeltSettings.MinBeltHeight = (int)m_beltHeightSlider.Value / 10;
settings.GeneratorSettings.BeltSettings.MaxBeltHeight = (int)m_beltHeightSlider.Value * 2 - settings.GeneratorSettings.BeltSettings.MinBeltHeight;
Expand Down
2 changes: 1 addition & 1 deletion SEWorldGenPlugin/GUI/PluginWorldSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Sandbox.Graphics.GUI;
using SEWorldGenPlugin.ObjectBuilders;
using SEWorldGenPlugin.Session;
using SEWorldGenPlugin.Utilities.SEWorldGenPlugin.Utilities;
using SEWorldGenPlugin.Utilities;
using System;
using System.IO;
using System.Text;
Expand Down
2 changes: 1 addition & 1 deletion SEWorldGenPlugin/Generator/Asteroids/AsteroidRingShape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public ContainmentType Contains(Vector3D point)
private double GetHeightAtRad(double rad)
{
if (rad < radius || rad > radius + width) throw new ArgumentOutOfRangeException("The radius " + rad + " has to be less than " + (radius + width) + " and larger than " + radius);
return Math.Sin((rad - radius) * Math.PI / width) * Math.Sin((rad - radius) * Math.PI / width) * 0.5 * height + 1;//Plus one to make asteroids on edges possible
return Math.Sin((rad - radius) * Math.PI / width) * Math.Sin((rad - radius) * Math.PI / width) * 0.5 * height + 100;//Plus 100 to make asteroids on edges possible
}
}
}
10 changes: 5 additions & 5 deletions SEWorldGenPlugin/Generator/SystemGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Sandbox.ModAPI;
using SEWorldGenPlugin.ObjectBuilders;
using SEWorldGenPlugin.Session;
using SEWorldGenPlugin.Utilities.SEWorldGenPlugin.Utilities;
using SEWorldGenPlugin.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -106,7 +106,7 @@ private void GenerateSystem()
int distToPrev = MyRandom.Instance.Next(m_settings.MinOrbitDistance, m_settings.MaxOrbitDistance);
tmp_distance += distToPrev;

if(MyRandom.Instance.NextDouble() * ((i % 6) * (i % 6) / 12.5) < 1 - m_settings.BeltSettings.BeltProbability){
if(MyRandom.Instance.NextDouble()/* * ((i % 6) * (i % 6) / 12.5)*/ < 1 - m_settings.BeltSettings.BeltProbability){
GeneratePlanet(i, tmp_distance, numberPlanets);
}
else
Expand Down Expand Up @@ -181,15 +181,15 @@ private MyPlanetMoonItem[] GenerateMoons(float planetSize, float surfaceGravity,

private MyPlanetRingItem GenerateRing(float surfaceGravity, float planetSize)
{
if (MyRandom.Instance.NextFloat() / surfaceGravity > 0.3 && false) return null;
if (MyRandom.Instance.NextFloat() > m_settings.PlanetSettings.RingSettings.PlanetRingProbability * surfaceGravity) return null;

MyPlanetRingItem ring = new MyPlanetRingItem();

ring.Type = SystemObjectType.RING;
ring.RoidSize = MyRandom.Instance.Next(64, Math.Min((int)(Math.Max(surfaceGravity * 0.5 * 128, 64)), 512));
ring.Width = MyRandom.Instance.Next(m_settings.PlanetSettings.RingSettings.MinPlanetRingWidth, m_settings.PlanetSettings.RingSettings.MaxPlanetRingWidth);
ring.Height = MyRandom.Instance.Next(m_settings.PlanetSettings.RingSettings.MinPlanetRingWidth / 10, ring.Width / 10);
ring.AngleDegrees = MyRandom.Instance.Next(-180, 180);
ring.AngleDegrees = MyRandom.Instance.Next(-20, 20);
ring.Radius = MyRandom.Instance.Next((int)(planetSize * 0.5 * 0.75), (int)(planetSize));
ring.DisplayName = "";

Expand All @@ -215,7 +215,7 @@ private MyPlanetGeneratorDefinition GetPlanetDefinition(float maximumSize)

private int SizeByGravity(float gravity)
{
return (int)Math.Min(Math.Sqrt(gravity * 120000 * 120000 * m_settings.PlanetSettings.SizeMultiplier * m_settings.PlanetSettings.SizeMultiplier), m_settings.PlanetSettings.PlanetSizeCap);
return (int)Math.Min(Math.Sqrt(gravity * 120000 * 120000 * m_settings.PlanetSettings.SizeMultiplier * m_settings.PlanetSettings.SizeMultiplier), m_settings.PlanetSettings.PlanetSizeCap);
}

private int GetMaxMoonCount(float gravity)
Expand Down
2 changes: 1 addition & 1 deletion SEWorldGenPlugin/MySettings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using SEWorldGenPlugin.ObjectBuilders;
using SEWorldGenPlugin.Utilities.SEWorldGenPlugin.Utilities;
using SEWorldGenPlugin.Utilities;
using System;
using VRage.Utils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,23 @@ public PlanetRingSettings()
{
MinPlanetRingWidth = 10000;
MaxPlanetRingWidth = 100000;
PlanetRingProbability = 0.5f;
}

[ProtoMember(1)]
public int MinPlanetRingWidth;

[ProtoMember(2)]
public int MaxPlanetRingWidth;
[ProtoMember(2)]
public float PlanetRingProbability;


public void Verify()
{
Verifier.VerifyInt(0, MaxPlanetRingWidth, 10000, "PlanetRingSettings.MinPlanetRingWidth", ref MinPlanetRingWidth);
Verifier.VerifyInt(MinPlanetRingWidth, int.MaxValue, 100000, "PlanetRingSettings.MaxPlanetRingWidth", ref MaxPlanetRingWidth);
Verifier.VerifyFloat(0, 1, 0.5f, "PlanetRingSettings.PlanetRingProbability", ref PlanetRingProbability);
}
}

Expand All @@ -131,7 +136,7 @@ public BeltSettings()
{
MinBeltHeight = 4000;
MaxBeltHeight = 40000;
BeltProbability = 0.4f;
BeltProbability = 0.2f;
}

[ProtoMember(1)]
Expand Down
2 changes: 1 addition & 1 deletion SEWorldGenPlugin/SEWorldGenPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
<Compile Include="Startup.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utilities\FileUtils.cs" />
<Compile Include="Utilities\MyTexts.cs" />
<Compile Include="Utilities\MyPluginTexts.cs" />
<Compile Include="Utilities\Verifier.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion SEWorldGenPlugin/Session/SettingsSession.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using SEWorldGenPlugin.ObjectBuilders;
using SEWorldGenPlugin.Utilities.SEWorldGenPlugin.Utilities;
using SEWorldGenPlugin.Utilities;
using VRage.Game;
using VRage.Game.Components;
using VRage.Utils;
Expand Down
Loading

0 comments on commit 06116ce

Please sign in to comment.