예제 #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 static void CreateSoil(TerrainData data, int soilLimit)
        {
            int w = data.Width;
            int h = data.Height;

            for (int y = 0; y < h; ++y)
            {
                for (int x = 0; x < w; ++x)
                {
                    int z = data.GetHeight(x, y);

                    var p = new IntPoint3(x, y, z);

                    if (z < soilLimit)
                    {
                        var td = data.GetTileData(p);

                        td.TerrainMaterialID = MaterialID.Loam;

                        data.SetTileData(p, td);
                    }
                }
            }
        }