CalculateMaterialCellAssets() public method

public CalculateMaterialCellAssets ( IList &materialAssetList, long>.Dictionary &materialVoxelCells ) : void
materialAssetList IList
materialVoxelCells long>.Dictionary
return void
Exemplo n.º 1
0
        public void FillAsteroid(MyVoxelMap asteroid, IMyVoxelFillProperties fillProperties)
        {
            var properties = (AsteroidByteFillProperties)fillProperties;

            IList<byte> baseAssets;
            Dictionary<byte, long> materialVoxelCells;

            asteroid.CalculateMaterialCellAssets(out baseAssets, out materialVoxelCells);

            var distribution = new List<double> { Double.NaN };
            var materialSelection = new List<byte> { SpaceEngineersCore.Resources.GetMaterialIndex(properties.MainMaterial.Value) };

            if (properties.SecondPercent > 0)
            {
                distribution.Add((double)properties.SecondPercent / 100);
                materialSelection.Add(SpaceEngineersCore.Resources.GetMaterialIndex(properties.SecondMaterial.Value));
            }
            if (properties.ThirdPercent > 0)
            {
                distribution.Add((double)properties.ThirdPercent / 100);
                materialSelection.Add(SpaceEngineersCore.Resources.GetMaterialIndex(properties.ThirdMaterial.Value));
            }
            if (properties.FourthPercent > 0)
            {
                distribution.Add((double)properties.FourthPercent / 100);
                materialSelection.Add(SpaceEngineersCore.Resources.GetMaterialIndex(properties.FourthMaterial.Value));
            }
            if (properties.FifthPercent > 0)
            {
                distribution.Add((double)properties.FifthPercent / 100);
                materialSelection.Add(SpaceEngineersCore.Resources.GetMaterialIndex(properties.FifthMaterial.Value));
            }
            if (properties.SixthPercent > 0)
            {
                distribution.Add((double)properties.SixthPercent / 100);
                materialSelection.Add(SpaceEngineersCore.Resources.GetMaterialIndex(properties.SixthMaterial.Value));
            }
            if (properties.SeventhPercent > 0)
            {
                distribution.Add((double)properties.SeventhPercent / 100);
                materialSelection.Add(SpaceEngineersCore.Resources.GetMaterialIndex(properties.SeventhMaterial.Value));
            }

            var newDistributiuon = new List<byte>();
            int count;
            for (var i = 1; i < distribution.Count(); i++)
            {
                count = (int)Math.Floor(distribution[i] * baseAssets.Count); // Round down.
                for (var j = 0; j < count; j++)
                {
                    newDistributiuon.Add(materialSelection[i]);
                }
            }
            count = baseAssets.Count - newDistributiuon.Count;
            for (var j = 0; j < count; j++)
            {
                newDistributiuon.Add(materialSelection[0]);
            }

            newDistributiuon.Shuffle();
            asteroid.SetMaterialAssets(newDistributiuon);
            //asteroid.ForceVoxelFaceMaterial(_dataModel.BaseMaterial.DisplayName);
        }
Exemplo n.º 2
0
        public void VoxelLoadSaveVx2V1()
        {
            SpaceEngineersCore.LoadDefinitions();
            var materials = SpaceEngineersCore.Resources.GetMaterialList();
            Assert.IsTrue(materials.Count > 0, "Materials should exist. Has the developer got Space Engineers installed?");

            const string fileOriginal = @".\TestAssets\AsteroidV1Format.vx2";
            const string fileNew = @".\TestOutput\AsteroidV1Format_save.vx2";

            var voxelMap = new MyVoxelMap();
            voxelMap.Load(fileOriginal, materials[0].Id.SubtypeId);
        
            IList<byte> materialAssets;
            Dictionary<byte, long> materialVoxelCells;
            voxelMap.CalculateMaterialCellAssets(out materialAssets, out materialVoxelCells);
            Assert.AreEqual(594485, materialAssets.Count, "Asset count should be equal.");

            var asset0 = materialAssets.Where(c => c == 0).ToList();
            Assert.AreEqual(0, asset0.Count, "asset0 count should be equal.");

            var asset1 = materialAssets.Where(c => c == 1).ToList();
            Assert.AreEqual(0, asset1.Count, "asset1 Asset count should be equal.");

            var asset2 = materialAssets.Where(c => c == 2).ToList();
            Assert.AreEqual(0, asset2.Count, "asset2 Asset count should be equal.");

            var asset3 = materialAssets.Where(c => c == 3).ToList();
            Assert.AreEqual(251145, asset3.Count, "asset3 Asset count should be equal.");

            var asset4 = materialAssets.Where(c => c == 4).ToList();
            Assert.AreEqual(0, asset4.Count, "asset4 Asset count should be equal.");

            var asset5 = materialAssets.Where(c => c == 5).ToList();
            Assert.AreEqual(0, asset5.Count, "asset5 Asset count should be equal.");

            var asset6 = materialAssets.Where(c => c == 6).ToList();
            Assert.AreEqual(217283, asset6.Count, "asset6 Asset count should be equal.");

            var asset7 = materialAssets.Where(c => c == 7).ToList();
            Assert.AreEqual(237, asset7.Count, "asset7 Asset count should be equal.");

            var asset8 = materialAssets.Where(c => c == 8).ToList();
            Assert.AreEqual(9608, asset8.Count, "asset8 Asset count should be equal.");

            var asset9 = materialAssets.Where(c => c == 9).ToList();
            Assert.AreEqual(40801, asset9.Count, "asset9 Asset count should be equal.");

            var asset10 = materialAssets.Where(c => c == 10).ToList();
            Assert.AreEqual(152, asset10.Count, "asset10 Asset count should be equal.");

            var assetNameCount = voxelMap.CountAssets(materialAssets);
            Assert.IsTrue(assetNameCount.Count > 0, "Contains assets.");

            voxelMap.Save(fileNew);

            var lengthOriginal = new FileInfo(fileOriginal).Length;
            var lengthNew = new FileInfo(fileNew).Length;

            Assert.AreEqual(88299, lengthOriginal, "File size must match.");
            Assert.AreEqual(72296, lengthNew, "File size must match.");
        }
Exemplo n.º 3
0
        public static Dictionary<string, long> GetMaterialAssetDetails(string filename)
        {
            var map = new MyVoxelMap();
            map.Load(filename, SpaceEngineersCore.Resources.GetDefaultMaterialName(), true);

            if (!map.IsValid)
                return new Dictionary<string, long>();

            IList<byte> materialAssetList;
            Dictionary<byte, long> materialVoxelCells;

            map.CalculateMaterialCellAssets(out materialAssetList, out materialVoxelCells);
            return map.CountAssets(materialVoxelCells);
        }
Exemplo n.º 4
0
        public void VoxelMaterialAssetsGenerateFixed()
        {
            SpaceEngineersCore.LoadDefinitions();
            var materials = SpaceEngineersCore.Resources.GetMaterialList();
            Assert.IsTrue(materials.Count > 0, "Materials should exist. Has the developer got Space Engineers installed?");

            var files = new[] { @".\TestAssets\Arabian_Border_7.vx2", @".\TestAssets\cube_52x52x52.vx2" };

            foreach (var fileOriginal in files)
            {
                foreach (var material in materials)
                {
                    var fileNewVoxel =
                        Path.Combine(Path.GetDirectoryName(Path.GetFullPath(fileOriginal)),
                            Path.GetFileNameWithoutExtension(fileOriginal) + "_" + material.Id.SubtypeId + ".vx2").ToLower();

                    var voxelMap = new MyVoxelMap();
                    voxelMap.Load(fileOriginal, materials[0].Id.SubtypeId);

                    IList<byte> materialAssets;
                    Dictionary<byte, long> materialVoxelCells;
                    voxelMap.CalculateMaterialCellAssets(out materialAssets, out materialVoxelCells);

                    var distribution = new[] { Double.NaN, .99, };
                    var materialSelection = new byte[] { 0, SpaceEngineersCore.Resources.GetMaterialIndex(material.Id.SubtypeId) };

                    var newDistributiuon = new List<byte>();
                    int count;
                    for (var i = 1; i < distribution.Count(); i++)
                    {
                        count = (int)Math.Floor(distribution[i] * materialAssets.Count); // Round down.
                        for (var j = 0; j < count; j++)
                        {
                            newDistributiuon.Add(materialSelection[i]);
                        }
                    }
                    count = materialAssets.Count - newDistributiuon.Count;
                    for (var j = 0; j < count; j++)
                    {
                        newDistributiuon.Add(materialSelection[0]);
                    }

                    newDistributiuon.Shuffle();

                    voxelMap.SetMaterialAssets(newDistributiuon);
                    voxelMap.Save(fileNewVoxel);
                }
            }
        }
Exemplo n.º 5
0
        public void VoxelMaterialAssetsRandom()
        {
            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_05"));
            Assert.IsNotNull(stoneMaterial, "Stone material should exist.");
            var goldMaterial = materials.FirstOrDefault(m => m.Id.SubtypeId.Contains("Gold"));
            Assert.IsNotNull(goldMaterial, "Gold material should exist.");
            var uraniumMaterial = materials.FirstOrDefault(m => m.Id.SubtypeId.Contains("Uraninite_01"));
            Assert.IsNotNull(uraniumMaterial, "Uranium material should exist.");

            const string fileOriginal = @".\TestAssets\Arabian_Border_7.vx2";
            const string fileNewVoxel = @".\TestOutput\Arabian_Border_7_mixed.vx2";

            var voxelMap = new MyVoxelMap();
            voxelMap.Load(fileOriginal, materials[0].Id.SubtypeId);
            IList<byte> materialAssets;
            Dictionary<byte, long> materialVoxelCells;
            voxelMap.CalculateMaterialCellAssets(out materialAssets, out materialVoxelCells);

            Assert.AreEqual(35465, materialAssets.Count, "Asset count should be equal.");

            var distribution = new[] { Double.NaN, .5, .25 };
            var materialSelection = new[] { SpaceEngineersCore.Resources.GetMaterialIndex(stoneMaterial.Id.SubtypeId), SpaceEngineersCore.Resources.GetMaterialIndex(goldMaterial.Id.SubtypeId), SpaceEngineersCore.Resources.GetMaterialIndex(uraniumMaterial.Id.SubtypeId) };

            var newDistributiuon = new List<byte>();
            int count;
            for (var i = 1; i < distribution.Count(); i++)
            {
                count = (int)Math.Floor(distribution[i] * materialAssets.Count); // Round down.
                for (var j = 0; j < count; j++)
                {
                    newDistributiuon.Add(materialSelection[i]);
                }
            }
            count = materialAssets.Count - newDistributiuon.Count;
            for (var j = 0; j < count; j++)
            {
                newDistributiuon.Add(materialSelection[0]);
            }

            newDistributiuon.Shuffle();

            var assetNameCount = voxelMap.CountAssets(newDistributiuon);

            Assert.AreEqual(3, assetNameCount.Count, "Asset Mertials count should be equal.");
            Assert.AreEqual(8867, assetNameCount[stoneMaterial.Id.SubtypeId], "Asset Mertials count should be equal.");
            Assert.AreEqual(17732, assetNameCount[goldMaterial.Id.SubtypeId], "Asset Mertials count should be equal.");
            Assert.AreEqual(8866, assetNameCount[uraniumMaterial.Id.SubtypeId], "Asset Mertials count should be equal.");

            voxelMap.SetMaterialAssets(newDistributiuon);

            voxelMap.CalculateMaterialCellAssets(out materialAssets, out materialVoxelCells);
            var cellCount = voxelMap.SumVoxelCells();

            voxelMap.Save(fileNewVoxel);
        }
Exemplo n.º 6
0
        public void VoxelMaterialAssets_FixedSize_MixedContent()
        {
            SpaceEngineersCore.LoadDefinitions();
            var materials = SpaceEngineersCore.Resources.GetMaterialList();
            Assert.IsTrue(materials.Count > 0, "Materials should exist. Has the developer got Space Engineers installed?");

            var goldMaterial = materials.FirstOrDefault(m => m.Id.SubtypeId.Contains("Gold"));
            Assert.IsNotNull(goldMaterial, "Gold material should exist.");

            const string fileOriginal = @".\TestAssets\test_cube_mixed_2x2x2.vx2";

            var voxelMap = new MyVoxelMap();
            voxelMap.Load(fileOriginal, materials[0].Id.SubtypeId);
            var cellCount = voxelMap.SumVoxelCells();
            IList<byte> materialAssets;
            Dictionary<byte, long> materialVoxelCells;
            voxelMap.CalculateMaterialCellAssets(out materialAssets, out materialVoxelCells);
            var assetNameCount = voxelMap.CountAssets(materialAssets);

            Assert.AreEqual(8 * 255, cellCount, "Cell count should be equal.");
            Assert.AreEqual(8, materialAssets.Count, "Asset count should be equal.");
            Assert.AreEqual(8, assetNameCount.Count, "Asset Mertials count should be equal.");
        }
Exemplo n.º 7
0
        public void VoxelMaterialAssets_MixedGeneratedAsset()
        {
            SpaceEngineersCore.LoadDefinitions();
            var materials = SpaceEngineersCore.Resources.GetMaterialList();
            Assert.IsTrue(materials.Count > 0, "Materials should exist. Has the developer got Space Engineers installed?");

            var goldMaterial = materials.FirstOrDefault(m => m.Id.SubtypeId.Contains("Gold"));
            Assert.IsNotNull(goldMaterial, "Gold material should exist.");

            const string fileOriginal = @".\TestAssets\asteroid0moon4.vx2";

            var voxelMap = new MyVoxelMap();
            voxelMap.Load(fileOriginal, materials[0].Id.SubtypeId);

            IList<byte> materialAssets;
            Dictionary<byte, long> materialVoxelCells;
            voxelMap.CalculateMaterialCellAssets(out materialAssets, out materialVoxelCells);

            Assert.AreEqual(44135, materialAssets.Count, "Asset count should be equal.");

            var otherAssets = materialAssets.Where(c => c != 4).ToList();

            Assert.AreEqual(0, otherAssets.Count, "Other Asset count should be equal.");

            var assetNameCount = voxelMap.CountAssets(materialAssets);
            Assert.IsTrue(assetNameCount.Count > 0, "Contains assets.");
        }
Exemplo n.º 8
0
        public void VoxelLoadStock()
        {
            SpaceEngineersCore.LoadDefinitions();
            var materials = SpaceEngineersCore.Resources.GetMaterialList();
            Assert.IsTrue(materials.Count > 0, "Materials should exist. Has the developer got Space Engineers installed?");

            var contentPath = ToolboxUpdater.GetApplicationContentPath();
            var redShipCrashedAsteroidPath = Path.Combine(contentPath, "VoxelMaps", "RedShipCrashedAsteroid.vx2");

            var voxelMap = new MyVoxelMap();
            voxelMap.Load(redShipCrashedAsteroidPath, materials[0].Id.SubtypeId);

            Assert.AreEqual(1, voxelMap.FileVersion, "FileVersion should be equal.");

            IList<byte> materialAssets;
            Dictionary<byte, long> materialVoxelCells;
            voxelMap.CalculateMaterialCellAssets(out materialAssets, out materialVoxelCells);
            Assert.AreEqual(563742, materialAssets.Count, "Asset count should be equal.");

            var asset0 = materialAssets.Where(c => c == 0).ToList();
            Assert.AreEqual(563742, asset0.Count, "asset0 count should be equal.");

            var assetNameCount = voxelMap.CountAssets(materialAssets);
            Assert.IsTrue(assetNameCount.Count > 0, "Contains assets.");

            var lengthOriginal = new FileInfo(redShipCrashedAsteroidPath).Length;
            Assert.AreEqual(51819, lengthOriginal, "File size must match.");
        }