Beispiel #1
0
        public void GenerateOres()
        {
            foreach (VoxelType type in VoxelLibrary.GetTypes())
            {
                if (type.SpawnClusters || type.SpawnVeins)
                {
                    int numEvents = (int)MathFunctions.Rand(75*(1.0f - type.Rarity), 100*(1.0f - type.Rarity));
                    for (int i = 0; i < numEvents; i++)
                    {
                        BoundingBox clusterBounds = new BoundingBox
                        {
                            Max = new Vector3(Bounds.Max.X, type.MaxSpawnHeight, Bounds.Max.Z),
                            Min = new Vector3(Bounds.Min.X, type.MinSpawnHeight, Bounds.Min.Z)
                        };

                        if (type.SpawnClusters)
                        {

                            OreCluster cluster = new OreCluster()
                            {
                                Size =
                                    new Vector3(MathFunctions.Rand(type.ClusterSize*0.25f, type.ClusterSize),
                                        MathFunctions.Rand(type.ClusterSize*0.25f, type.ClusterSize),
                                        MathFunctions.Rand(type.ClusterSize*0.25f, type.ClusterSize)),
                                Transform = MathFunctions.RandomTransform(clusterBounds),
                                Type = type
                            };
                            ChunkGen.GenerateCluster(cluster, ChunkData);
                        }

                        if (type.SpawnVeins)
                        {
                            OreVein vein = new OreVein()
                            {
                                Length = MathFunctions.Rand(type.VeinLength*0.75f, type.VeinLength*1.25f),
                                Start = MathFunctions.RandVector3Box(clusterBounds),
                                Type = type
                            };
                            ChunkGen.GenerateVein(vein, ChunkData);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public void GenerateVein(OreVein vein, ChunkData chunks)
        {
            Voxel   vox           = new Voxel();
            Vector3 curr          = vein.Start;
            Vector3 directionBias = MathFunctions.RandVector3Box(-1, 1, -0.1f, 0.1f, -1, 1);

            for (float t = 0; t < vein.Length; t++)
            {
                if (curr.Y > vein.Type.MaxSpawnHeight ||
                    curr.Y < vein.Type.MinSpawnHeight)
                {
                    continue;
                }
                Vector3 p = new Vector3(curr.X, curr.Y, curr.Z);
                if (!chunks.GetVoxel(p, ref vox))
                {
                    continue;
                }

                if (vox.IsEmpty)
                {
                    continue;
                }

                if (!MathFunctions.RandEvent(vein.Type.SpawnProbability))
                {
                    continue;
                }

                if (!vein.Type.SpawnInSoil && vox.Type.IsSoil)
                {
                    continue;
                }

                vox.Type = vein.Type;
                Vector3 step = directionBias + MathFunctions.RandVector3Box(-1, 1, -1, 1, -1, 1) * 0.25f;
                step.Normalize();
                curr += step;
            }
        }
        public void GenerateVein(OreVein vein, ChunkData chunks)
        {
            Vector3 curr          = vein.Start;
            Vector3 directionBias = MathFunctions.RandVector3Box(-1, 1, -0.1f, 0.1f, -1, 1);

            for (float t = 0; t < vein.Length; t++)
            {
                if (curr.Y > vein.Type.MaxSpawnHeight ||
                    curr.Y < vein.Type.MinSpawnHeight ||
                    curr.Y <= 1)
                {
                    continue;
                }
                Vector3 p = new Vector3(curr.X, curr.Y, curr.Z);

                var vox = new VoxelHandle(chunks, GlobalVoxelCoordinate.FromVector3(p));

                if (!vox.IsValid || vox.IsEmpty)
                {
                    continue;
                }

                if (!MathFunctions.RandEvent(vein.Type.SpawnProbability))
                {
                    continue;
                }

                if (!vein.Type.SpawnOnSurface && (vox.Type.IsSurface || vox.Type.IsSoil))
                {
                    continue;
                }

                vox.RawSetType(vein.Type);
                Vector3 step = directionBias + MathFunctions.RandVector3Box(-1, 1, -1, 1, -1, 1) * 0.25f;
                step.Normalize();
                curr += step;
            }
        }