Next() 공개 메소드

Get random Int32 [0, Int32.MaxValue)
public Next ( ) : int
리턴 int
예제 #1
0
        public static void CreateSlopes(TerrainData data, int baseSeed)
        {
            var plane = data.Size.Plane;

            plane.Range().AsParallel().ForAll(p =>
            {
                int z = data.GetHeight(p);

                int count = 0;
                Direction dir = Direction.None;

                var r = new MWCRandom(p, baseSeed);

                int offset = r.Next(8);

                // Count the tiles around this tile which are higher. Create slope to a random direction, but skip
                // the slope if all 8 tiles are higher.
                // Count to 10. If 3 successive slopes, create one in the middle
                int successive = 0;
                for (int i = 0; i < 10; ++i)
                {
                    var d = DirectionExtensions.PlanarDirections[(i + offset) % 8];

                    var t = p + d;

                    if (plane.Contains(t) && data.GetHeight(t) > z)
                    {
                        if (i < 8)
                            count++;
                        successive++;

                        if (successive == 3)
                        {
                            dir = DirectionExtensions.PlanarDirections[((i - 1) + offset) % 8];
                        }
                        else if (dir == Direction.None)
                        {
                            dir = d;
                        }
                    }
                    else
                    {
                        successive = 0;
                    }
                }

                if (count > 0 && count < 8)
                {
                    var p3d = new IntPoint3(p, z);

                    var td = data.GetTileData(p3d);
                    td.TerrainID = dir.ToSlope();
                    data.SetTileData(p3d, td);
                }
            });
        }
예제 #2
0
 public ushort GetHeuristic(IntVector3 p)
 {
     // Add a bit random so that the river doesn't go straight
     var r = new MWCRandom(p, 1);
     return (ushort)(p.Z * 10 + r.Next(4));
 }
예제 #3
0
        public static void CreateTrees(TerrainData terrain, Random random)
        {
            var grid = terrain.TileGrid;
            var heightMap = terrain.HeightMap;

            var materials = Materials.GetMaterials(MaterialCategory.Wood).ToArray();

            int baseSeed = random.Next();
            if (baseSeed == 0)
                baseSeed = 1;

            terrain.Size.Plane.Range().AsParallel().ForAll(p2d =>
            {
                int z = heightMap[p2d.Y, p2d.X];

                var p = new IntPoint3(p2d, z);

                var td = grid[p.Z, p.Y, p.X];

                if (td.InteriorID == InteriorID.Grass)
                {
                    var r = new MWCRandom(p, baseSeed);

                    if (r.Next(8) == 0)
                    {
                        td.InteriorID = r.Next(2) == 0 ? InteriorID.Tree : InteriorID.Sapling;
                        td.InteriorMaterialID = materials[r.Next(materials.Length)].ID;
                        grid[p.Z, p.Y, p.X] = td;
                    }
                }
            });
        }
예제 #4
0
        public static void CreateVegetation(TerrainData terrain, Random random, int vegetationLimit)
        {
            var grassMaterials = Materials.GetMaterials(MaterialCategory.Grass).ToArray();
            var woodMaterials = Materials.GetMaterials(MaterialCategory.Wood).ToArray();
            var berryMaterials = Materials.GetMaterials(MaterialCategory.Berry).ToArray();

            int baseSeed = random.Next();
            if (baseSeed == 0)
                baseSeed = 1;

            terrain.Size.Plane.Range().AsParallel().ForAll(p2d =>
            {
                int z = terrain.GetSurfaceLevel(p2d);

                var p = new IntVector3(p2d, z);

                if (z >= vegetationLimit)
                    return;

                var td = terrain.GetTileData(p);

                if (td.WaterLevel > 0)
                    return;

                if (terrain.GetMaterial(p.Down).Category != MaterialCategory.Soil)
                    return;

                var r = new MWCRandom(p, baseSeed);

                int v = r.Next(100);

                if (v >= 95)
                {
                    td.ID = TileID.Sapling;
                    td.MaterialID = woodMaterials[r.Next(woodMaterials.Length)].ID;
                }
                else if (v >= 90)
                {
                    td.ID = TileID.Tree;
                    td.MaterialID = woodMaterials[r.Next(woodMaterials.Length)].ID;
                }
                else if (v >= 80)
                {
                    td.ID = TileID.Shrub;
                    td.MaterialID = berryMaterials[r.Next(berryMaterials.Length)].ID;
                }
                else
                {
                    td.ID = TileID.Grass;
                    td.MaterialID = grassMaterials[r.Next(grassMaterials.Length)].ID;
                }

                terrain.SetTileDataNoHeight(p, td);
            });
        }