Skip to content

Commit

Permalink
Fixed an issue, where ore would only spawn as Mg or Si
Browse files Browse the repository at this point in the history
  • Loading branch information
8vogt committed Mar 10, 2021
1 parent d086630 commit b30528d
Showing 1 changed file with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Sandbox.Engine.Voxels;
using Sandbox.Definitions;
using Sandbox.Engine.Voxels;
using Sandbox.Game.Entities;
using Sandbox.Game.Entities.Character;
using Sandbox.Game.World;
Expand Down Expand Up @@ -41,11 +42,14 @@ public class MyProceduralAsteroidsModule : MyAbstractProceduralCellModule
private List<MyVoxelBase> m_tmpAsteroids;
private bool m_isSaving = false;

private MyAsteroidGeneratorDefinition m_definition;

public MyProceduralAsteroidsModule(int seed) : base(seed, CELL_SIZE)
{
m_tmpAsteroids = new List<MyVoxelBase>();
m_providerType = typeof(MyProceduralWorldGenerator).Assembly.GetType("Sandbox.Game.World.Generator.MyCompositeShapeProvider");
m_createRoid = m_providerType.GetMethod("CreateAsteroidShape");
m_definition = GetData();

MySession.Static.OnSavingCheckpoint += delegate
{
Expand Down Expand Up @@ -168,7 +172,7 @@ public override void GenerateLoadedCellObjects()

if (exists) continue;

var storage = CreateAsteroidStorage(GetAsteroidVoxelSize(seed.Size), seed.Params.Seed, seed.Size, 3);
var storage = CreateAsteroidStorage(GetAsteroidVoxelSize(seed.Size), seed.Params.Seed, seed.Size, m_definition.UseGeneratorSeed ? seed.Params.GeneratorSeed : 0);
Vector3D pos = seed.BoundingVolume.Center - MathHelper.GetNearestBiggerPowerOfTwo(seed.Size) / 2;

MyVoxelMap voxelMap;
Expand Down Expand Up @@ -278,6 +282,7 @@ protected override MyProceduralCell GenerateCellSeeds(Vector3I cellId)
cellObjectSeed.Params.Type = VRage.Game.MyObjectSeedType.Asteroid;
cellObjectSeed.Params.Seed = MyRandom.Instance.Next();
cellObjectSeed.Params.Index = index++;
cellObjectSeed.Params.GeneratorSeed = m_definition.UseGeneratorSeed ? MyRandom.Instance.Next() : 0;

cell.AddObject(cellObjectSeed);
}
Expand Down Expand Up @@ -376,5 +381,39 @@ public override void UpdateCells()
m_isSaving = false;
}
}

/// <summary>
/// Retreives the data for the vanilla asteroid generator to
/// correctly generate asteroids.
/// </summary>
/// <returns>The asteroid generator definition</returns>
private MyAsteroidGeneratorDefinition GetData()
{
MyAsteroidGeneratorDefinition myAsteroidGeneratorDefinition = null;
int voxelGeneratorVersion = MySession.Static.Settings.VoxelGeneratorVersion;
foreach (MyAsteroidGeneratorDefinition value in MyDefinitionManager.Static.GetAsteroidGeneratorDefinitions().Values)
{
if (value.Version == voxelGeneratorVersion)
{
myAsteroidGeneratorDefinition = value;
break;
}
}
if (myAsteroidGeneratorDefinition == null)
{
MyPluginLog.Log("Generator of version " + voxelGeneratorVersion + "not found!");
{
foreach (MyAsteroidGeneratorDefinition value2 in MyDefinitionManager.Static.GetAsteroidGeneratorDefinitions().Values)
{
if (myAsteroidGeneratorDefinition == null || (value2.Version > voxelGeneratorVersion && (myAsteroidGeneratorDefinition.Version < voxelGeneratorVersion || value2.Version < myAsteroidGeneratorDefinition.Version)))
{
myAsteroidGeneratorDefinition = value2;
}
}
return myAsteroidGeneratorDefinition;
}
}
return myAsteroidGeneratorDefinition;
}
}
}

0 comments on commit b30528d

Please sign in to comment.