From b30528dcb5fc6c4d61948e8280c0e5b12354d46e Mon Sep 17 00:00:00 2001 From: 8vogt <8vogt@informatik.uni-hamburg.de> Date: Wed, 10 Mar 2021 18:53:58 +0100 Subject: [PATCH] Fixed an issue, where ore would only spawn as Mg or Si --- .../MyProceduralAsteroidsModule.cs | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/SEWorldGenPlugin/Generator/ProceduralGeneration/MyProceduralAsteroidsModule.cs b/SEWorldGenPlugin/Generator/ProceduralGeneration/MyProceduralAsteroidsModule.cs index b95e6aa..3eb1e10 100644 --- a/SEWorldGenPlugin/Generator/ProceduralGeneration/MyProceduralAsteroidsModule.cs +++ b/SEWorldGenPlugin/Generator/ProceduralGeneration/MyProceduralAsteroidsModule.cs @@ -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; @@ -41,11 +42,14 @@ public class MyProceduralAsteroidsModule : MyAbstractProceduralCellModule private List m_tmpAsteroids; private bool m_isSaving = false; + private MyAsteroidGeneratorDefinition m_definition; + public MyProceduralAsteroidsModule(int seed) : base(seed, CELL_SIZE) { m_tmpAsteroids = new List(); m_providerType = typeof(MyProceduralWorldGenerator).Assembly.GetType("Sandbox.Game.World.Generator.MyCompositeShapeProvider"); m_createRoid = m_providerType.GetMethod("CreateAsteroidShape"); + m_definition = GetData(); MySession.Static.OnSavingCheckpoint += delegate { @@ -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; @@ -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); } @@ -376,5 +381,39 @@ public override void UpdateCells() m_isSaving = false; } } + + /// + /// Retreives the data for the vanilla asteroid generator to + /// correctly generate asteroids. + /// + /// The asteroid generator definition + 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; + } } }