public void SeedFillVoxelFile() { SpaceEngineersCore.LoadDefinitions(); var materials = SpaceEngineersCore.Resources.GetMaterialList(); Assert.IsTrue(materials.Count > 0, "Materials should exist. Has the developer got Space Engineers installed?"); var stoneMaterial = materials.FirstOrDefault(m => m.Id.SubtypeId.Contains("Stone_01")); Assert.IsNotNull(stoneMaterial, "Stone material should exist."); var ironMaterial = materials.FirstOrDefault(m => m.Id.SubtypeId.Contains("Iron_02")); Assert.IsNotNull(ironMaterial, "Iron material should exist."); var goldMaterial = materials.FirstOrDefault(m => m.Id.SubtypeId.Contains("Gold")); Assert.IsNotNull(goldMaterial, "Gold material should exist."); var voxelMap = MyVoxelBuilder.BuildAsteroidCube(false, 64, 64, 64, stoneMaterial.Id.SubtypeId, stoneMaterial.Id.SubtypeId, false, 0); //var voxelMap = MyVoxelBuilder.BuildAsteroidSphere(true, 64, stoneMaterial.Id.SubtypeId, stoneMaterial.Id.SubtypeId, false, 0); var filler = new AsteroidSeedFiller(); var fillProperties = new AsteroidSeedFillProperties { MainMaterial = new SEToolbox.Models.MaterialSelectionModel { Value = stoneMaterial.Id.SubtypeId }, FirstMaterial = new SEToolbox.Models.MaterialSelectionModel { Value = ironMaterial.Id.SubtypeId }, FirstRadius = 3, FirstVeins = 2, SecondMaterial = new SEToolbox.Models.MaterialSelectionModel { Value = goldMaterial.Id.SubtypeId }, SecondRadius = 1, SecondVeins = 1, }; filler.FillAsteroid(voxelMap, fillProperties); Assert.AreEqual(128, voxelMap.Size.X, "Voxel Bounding size must match."); Assert.AreEqual(128, voxelMap.Size.Y, "Voxel Bounding size must match."); Assert.AreEqual(128, voxelMap.Size.Z, "Voxel Bounding size must match."); Assert.AreEqual(64, voxelMap.BoundingContent.SizeInt().X + 1, "Voxel Content size must match."); Assert.AreEqual(64, voxelMap.BoundingContent.SizeInt().Y + 1, "Voxel Content size must match."); Assert.AreEqual(64, voxelMap.BoundingContent.SizeInt().Z + 1, "Voxel Content size must match."); var voxCells = voxelMap.SumVoxelCells(); Assert.AreEqual(66846720, voxCells, "Voxel cells must match."); IList<byte> materialAssets; Dictionary<byte, long> materialVoxelCells; voxelMap.CalculateMaterialCellAssets(out materialAssets, out materialVoxelCells); var stoneAssets = materialAssets.Where(c => c == SpaceEngineersCore.Resources.GetMaterialIndex(stoneMaterial.Id.SubtypeId)).ToList(); var ironAssets = materialAssets.Where(c => c == SpaceEngineersCore.Resources.GetMaterialIndex(ironMaterial.Id.SubtypeId)).ToList(); var goldAssets = materialAssets.Where(c => c == SpaceEngineersCore.Resources.GetMaterialIndex(goldMaterial.Id.SubtypeId)).ToList(); var sumAssets = (stoneAssets.Count + ironAssets.Count + goldAssets.Count) * 255; // A cube should produce full voxcells, so all of them are 255. Assert.AreEqual(voxCells, sumAssets, "Assets sum should equal cells"); // Seeder is too random to provide stable values. //Assert.AreEqual(236032, stoneAssets.Count, "Stone assets should equal."); //Assert.AreEqual(23040, ironAssets.Count , "Iron assets should equal."); //Assert.AreEqual(3072, goldAssets.Count, "Gold assets should equal."); // Strip the original material. //voxelMap.RemoveMaterial(stoneMaterial.Id.SubtypeId, null); //const string fileNew = @".\TestOutput\randomSeedMaterialCube.vx2"; //voxelMap.Save(fileNew); //var lengthNew = new FileInfo(fileNew).Length; }
public IMyVoxelFillProperties CreateRandom(int index, MaterialSelectionModel defaultMaterial, IEnumerable<MaterialSelectionModel> materialsCollection, IEnumerable<GenerateVoxelDetailModel> voxelCollection) { int idx; var randomModel = new AsteroidSeedFillProperties { Index = index, MainMaterial = defaultMaterial, FirstMaterial = defaultMaterial, SecondMaterial = defaultMaterial, ThirdMaterial = defaultMaterial, FourthMaterial = defaultMaterial, FifthMaterial = defaultMaterial, SixthMaterial = defaultMaterial, SeventhMaterial = defaultMaterial, }; // Must be by reference, not value. var largeVoxelFileList = voxelCollection.Where(v => v.FileSize > 100000).ToList(); var smallVoxelFileList = voxelCollection.Where(v => v.FileSize > 0 && v.FileSize < 100000).ToList(); // Random Asteroid. var d = RandomUtil.GetDouble(1, 100); var islarge = false; if (largeVoxelFileList.Count == 0 && smallVoxelFileList.Count == 0) { // no asteroids? You are so screwed. throw new Exception("No valid asteroids found. Re-validate your game cache."); } if (largeVoxelFileList.Count == 0) // empty last list? Force to small list. d = 1; if (smallVoxelFileList.Count == 0) // empty small list? Force to large list. d = 100; if (d > 70) { idx = RandomUtil.GetInt(largeVoxelFileList.Count); randomModel.VoxelFile = largeVoxelFileList[idx]; islarge = true; } else { idx = RandomUtil.GetInt(smallVoxelFileList.Count); randomModel.VoxelFile = smallVoxelFileList[idx]; } // Random Main Material non-Rare. var nonRare = materialsCollection.Where(m => m.IsRare == false).ToArray(); idx = RandomUtil.GetInt(nonRare.Length); randomModel.MainMaterial = nonRare[idx]; int chunks, chunkSize; double multiplier = 1.0; var rare = materialsCollection.Where(m => m.IsRare && m.MinedRatio >= 1).ToList(); var superRare = materialsCollection.Where(m => m.IsRare && m.MinedRatio < 1).ToList(); if (islarge) { // Random 1-4 are rare. chunks = 20; chunkSize = 5; if (rare.Count > 0) { idx = RandomUtil.GetInt(rare.Count); randomModel.FirstMaterial = rare[idx]; randomModel.FirstVeins = RandomUtil.GetInt((int)(chunks * multiplier), (int)(chunks * 1.5 * multiplier)); randomModel.FirstRadius = RandomUtil.GetInt((int)(chunkSize * multiplier), (int)(chunkSize * 1.5 * multiplier)); rare.RemoveAt(idx); } multiplier *= 0.85; if (rare.Count > 0) { idx = RandomUtil.GetInt(rare.Count); randomModel.SecondMaterial = rare[idx]; randomModel.SecondVeins = RandomUtil.GetInt((int)(chunks * multiplier), (int)(chunks * 1.5 * multiplier)); randomModel.SecondRadius = RandomUtil.GetInt((int)(chunkSize * multiplier), (int)(chunkSize * 1.5 * multiplier)); rare.RemoveAt(idx); } multiplier *= 0.85; if (rare.Count > 0) { idx = RandomUtil.GetInt(rare.Count); randomModel.ThirdMaterial = rare[idx]; randomModel.ThirdVeins = RandomUtil.GetInt((int)(chunks * multiplier), (int)(chunks * 1.5 * multiplier)); randomModel.ThirdRadius = RandomUtil.GetInt((int)(chunkSize * multiplier), (int)(chunkSize * 1.5 * multiplier)); rare.RemoveAt(idx); } multiplier *= 0.85; if (rare.Count > 0) { idx = RandomUtil.GetInt(rare.Count); randomModel.FourthMaterial = rare[idx]; randomModel.FourthVeins = RandomUtil.GetInt((int)(chunks * multiplier), (int)(chunks * 1.5 * multiplier)); randomModel.FourthRadius = RandomUtil.GetInt((int)(chunkSize * multiplier), (int)(chunkSize * 1.5 * multiplier)); rare.RemoveAt(idx); } // Random 5-7 are super-rare multiplier = 1.0; chunks = 50; chunkSize = 2; if (superRare.Count > 0) { idx = RandomUtil.GetInt(superRare.Count); randomModel.FifthMaterial = superRare[idx]; randomModel.FifthVeins = RandomUtil.GetInt((int)(chunks * multiplier), (int)(chunks * 1.5 * multiplier)); randomModel.FifthRadius = RandomUtil.GetInt((int)(chunkSize * multiplier), (int)(chunkSize * 1.5 * multiplier)); superRare.RemoveAt(idx); } multiplier *= 0.5; if (superRare.Count > 0) { idx = RandomUtil.GetInt(superRare.Count); randomModel.SixthMaterial = superRare[idx]; randomModel.SixthVeins = RandomUtil.GetInt((int)(chunks * multiplier), (int)(chunks * 1.5 * multiplier)); randomModel.SixthRadius = RandomUtil.GetInt((int)(chunkSize * multiplier), (int)(chunkSize * 1.5 * multiplier)); superRare.RemoveAt(idx); } multiplier *= 0.5; if (superRare.Count > 0) { idx = RandomUtil.GetInt(superRare.Count); randomModel.SeventhMaterial = superRare[idx]; randomModel.SeventhVeins = RandomUtil.GetInt((int)(chunks * multiplier), (int)(chunks * 1.5 * multiplier)); randomModel.SeventhRadius = RandomUtil.GetInt((int)(chunkSize * multiplier), (int)(chunkSize * 1.5 * multiplier)); superRare.RemoveAt(idx); } multiplier *= 0.5; } else // Small Asteroid. { // Random 1-3 are rare. chunks = 10; chunkSize = 2; if (rare.Count > 0) { idx = RandomUtil.GetInt(rare.Count); randomModel.FirstMaterial = rare[idx]; randomModel.FirstVeins = RandomUtil.GetInt((int)(chunks * multiplier), (int)(chunks * 1.5 * multiplier)); randomModel.FirstRadius = RandomUtil.GetInt((int)(chunkSize * multiplier), (int)(chunkSize * 1.5 * multiplier)); rare.RemoveAt(idx); } multiplier *= 0.75; if (rare.Count > 0) { idx = RandomUtil.GetInt(rare.Count); randomModel.SecondMaterial = rare[idx]; randomModel.SecondVeins = RandomUtil.GetInt((int)(chunks * multiplier), (int)(chunks * 1.5 * multiplier)); randomModel.SecondRadius = RandomUtil.GetInt((int)(chunkSize * multiplier), (int)(chunkSize * 1.5 * multiplier)); rare.RemoveAt(idx); } multiplier *= 0.75; if (rare.Count > 0) { idx = RandomUtil.GetInt(rare.Count); randomModel.ThirdMaterial = rare[idx]; randomModel.ThirdVeins = RandomUtil.GetInt((int)(chunks * multiplier), (int)(chunks * 1.5 * multiplier)); randomModel.ThirdRadius = RandomUtil.GetInt((int)(chunkSize * multiplier), (int)(chunkSize * 1.5 * multiplier)); rare.RemoveAt(idx); } // Random 4-5 is super-rare multiplier = 1.0; chunks = 15; if (superRare.Count > 0) { idx = RandomUtil.GetInt(superRare.Count); randomModel.FourthMaterial = superRare[idx]; randomModel.FourthVeins = RandomUtil.GetInt((int)(chunks * multiplier), (int)(chunks * 1.5 * multiplier)); randomModel.FourthRadius = 0; superRare.RemoveAt(idx); } multiplier *= 0.5; if (superRare.Count > 0) { idx = RandomUtil.GetInt(superRare.Count); randomModel.FifthMaterial = superRare[idx]; randomModel.FifthVeins = RandomUtil.GetInt((int)(chunks * multiplier), (int)(chunks * 1.5 * multiplier)); randomModel.FifthRadius = 0; superRare.RemoveAt(idx); } } return randomModel; }
public IMyVoxelFillProperties CreateRandom(int index, MaterialSelectionModel defaultMaterial, IEnumerable <MaterialSelectionModel> materialsCollection, IEnumerable <GenerateVoxelDetailModel> voxelCollection) { int idx; var randomModel = new AsteroidSeedFillProperties { Index = index, MainMaterial = defaultMaterial, FirstMaterial = defaultMaterial, SecondMaterial = defaultMaterial, ThirdMaterial = defaultMaterial, FourthMaterial = defaultMaterial, FifthMaterial = defaultMaterial, SixthMaterial = defaultMaterial, SeventhMaterial = defaultMaterial, }; // Must be by reference, not value. var largeVoxelFileList = voxelCollection.Where(v => v.FileSize > 100000).ToList(); var smallVoxelFileList = voxelCollection.Where(v => v.FileSize > 0 && v.FileSize < 100000).ToList(); // Random Asteroid. var d = RandomUtil.GetDouble(1, 100); var islarge = false; if (largeVoxelFileList.Count == 0 && smallVoxelFileList.Count == 0) { // no asteroids? You are so screwed. throw new Exception("No valid asteroids found. Re-validate your game cache."); } if (largeVoxelFileList.Count == 0) // empty last list? Force to small list. { d = 1; } if (smallVoxelFileList.Count == 0) // empty small list? Force to large list. { d = 100; } if (d > 70) { idx = RandomUtil.GetInt(largeVoxelFileList.Count); randomModel.VoxelFile = largeVoxelFileList[idx]; islarge = true; } else { idx = RandomUtil.GetInt(smallVoxelFileList.Count); randomModel.VoxelFile = smallVoxelFileList[idx]; } // Random Main Material non-Rare. var nonRare = materialsCollection.Where(m => m.IsRare == false).ToArray(); idx = RandomUtil.GetInt(nonRare.Length); randomModel.MainMaterial = nonRare[idx]; int chunks, chunkSize; double multiplier = 1.0; var rare = materialsCollection.Where(m => m.IsRare && m.MinedRatio >= 2).ToList(); var superRare = materialsCollection.Where(m => m.IsRare && m.MinedRatio < 2).ToList(); if (islarge) { // Random 1-4 are rare. chunks = 20; chunkSize = 5; if (rare.Count > 0) { idx = RandomUtil.GetInt(rare.Count); randomModel.FirstMaterial = rare[idx]; randomModel.FirstVeins = RandomUtil.GetInt((int)(chunks * multiplier), (int)(chunks * 1.5 * multiplier)); randomModel.FirstRadius = RandomUtil.GetInt((int)(chunkSize * multiplier), (int)(chunkSize * 1.5 * multiplier)); rare.RemoveAt(idx); } multiplier *= 0.85; if (rare.Count > 0) { idx = RandomUtil.GetInt(rare.Count); randomModel.SecondMaterial = rare[idx]; randomModel.SecondVeins = RandomUtil.GetInt((int)(chunks * multiplier), (int)(chunks * 1.5 * multiplier)); randomModel.SecondRadius = RandomUtil.GetInt((int)(chunkSize * multiplier), (int)(chunkSize * 1.5 * multiplier)); rare.RemoveAt(idx); } multiplier *= 0.85; if (rare.Count > 0) { idx = RandomUtil.GetInt(rare.Count); randomModel.ThirdMaterial = rare[idx]; randomModel.ThirdVeins = RandomUtil.GetInt((int)(chunks * multiplier), (int)(chunks * 1.5 * multiplier)); randomModel.ThirdRadius = RandomUtil.GetInt((int)(chunkSize * multiplier), (int)(chunkSize * 1.5 * multiplier)); rare.RemoveAt(idx); } multiplier *= 0.85; if (rare.Count > 0) { idx = RandomUtil.GetInt(rare.Count); randomModel.FourthMaterial = rare[idx]; randomModel.FourthVeins = RandomUtil.GetInt((int)(chunks * multiplier), (int)(chunks * 1.5 * multiplier)); randomModel.FourthRadius = RandomUtil.GetInt((int)(chunkSize * multiplier), (int)(chunkSize * 1.5 * multiplier)); rare.RemoveAt(idx); } // Random 5-7 are super-rare multiplier = 1.0; chunks = 50; chunkSize = 2; if (superRare.Count > 0) { idx = RandomUtil.GetInt(superRare.Count); randomModel.FifthMaterial = superRare[idx]; randomModel.FifthVeins = RandomUtil.GetInt((int)(chunks * multiplier), (int)(chunks * 1.5 * multiplier)); randomModel.FifthRadius = RandomUtil.GetInt((int)(chunkSize * multiplier), (int)(chunkSize * 1.5 * multiplier)); superRare.RemoveAt(idx); } multiplier *= 0.5; if (superRare.Count > 0) { idx = RandomUtil.GetInt(superRare.Count); randomModel.SixthMaterial = superRare[idx]; randomModel.SixthVeins = RandomUtil.GetInt((int)(chunks * multiplier), (int)(chunks * 1.5 * multiplier)); randomModel.SixthRadius = RandomUtil.GetInt((int)(chunkSize * multiplier), (int)(chunkSize * 1.5 * multiplier)); superRare.RemoveAt(idx); } multiplier *= 0.5; if (superRare.Count > 0) { idx = RandomUtil.GetInt(superRare.Count); randomModel.SeventhMaterial = superRare[idx]; randomModel.SeventhVeins = RandomUtil.GetInt((int)(chunks * multiplier), (int)(chunks * 1.5 * multiplier)); randomModel.SeventhRadius = RandomUtil.GetInt((int)(chunkSize * multiplier), (int)(chunkSize * 1.5 * multiplier)); superRare.RemoveAt(idx); } multiplier *= 0.5; } else // Small Asteroid. { // Random 1-3 are rare. chunks = 10; chunkSize = 2; if (rare.Count > 0) { idx = RandomUtil.GetInt(rare.Count); randomModel.FirstMaterial = rare[idx]; randomModel.FirstVeins = RandomUtil.GetInt((int)(chunks * multiplier), (int)(chunks * 1.5 * multiplier)); randomModel.FirstRadius = RandomUtil.GetInt((int)(chunkSize * multiplier), (int)(chunkSize * 1.5 * multiplier)); rare.RemoveAt(idx); } multiplier *= 0.75; if (rare.Count > 0) { idx = RandomUtil.GetInt(rare.Count); randomModel.SecondMaterial = rare[idx]; randomModel.SecondVeins = RandomUtil.GetInt((int)(chunks * multiplier), (int)(chunks * 1.5 * multiplier)); randomModel.SecondRadius = RandomUtil.GetInt((int)(chunkSize * multiplier), (int)(chunkSize * 1.5 * multiplier)); rare.RemoveAt(idx); } multiplier *= 0.75; if (rare.Count > 0) { idx = RandomUtil.GetInt(rare.Count); randomModel.ThirdMaterial = rare[idx]; randomModel.ThirdVeins = RandomUtil.GetInt((int)(chunks * multiplier), (int)(chunks * 1.5 * multiplier)); randomModel.ThirdRadius = RandomUtil.GetInt((int)(chunkSize * multiplier), (int)(chunkSize * 1.5 * multiplier)); rare.RemoveAt(idx); } // Random 4-5 is super-rare multiplier = 1.0; chunks = 15; if (superRare.Count > 0) { idx = RandomUtil.GetInt(superRare.Count); randomModel.FourthMaterial = superRare[idx]; randomModel.FourthVeins = RandomUtil.GetInt((int)(chunks * multiplier), (int)(chunks * 1.5 * multiplier)); randomModel.FourthRadius = 0; superRare.RemoveAt(idx); } multiplier *= 0.5; if (superRare.Count > 0) { idx = RandomUtil.GetInt(superRare.Count); randomModel.FifthMaterial = superRare[idx]; randomModel.FifthVeins = RandomUtil.GetInt((int)(chunks * multiplier), (int)(chunks * 1.5 * multiplier)); randomModel.FifthRadius = 0; superRare.RemoveAt(idx); } } return(randomModel); }