Exemplo n.º 1
0
        public void RandomizeHeights(int LevelCount)
        {
            var    hmSource         = new clsHeightmap();
            var    hmA              = new clsHeightmap();
            var    hmB              = new clsHeightmap();
            var    IntervalCount    = 0;
            var    AlterationLevels = new clsHeightmap.sHeights();
            var    hmAlteration     = new sHeightmaps();
            float  LevelHeight      = 0;
            double HeightRange      = 0;
            var    Level            = 0;
            double IntervalHeight   = 0;
            double Variation        = 0;
            var    X = 0;
            var    Y = 0;

            IntervalCount = LevelCount - 1;

            AlterationLevels.Heights = new float[IntervalCount + 1];
            var MinMax = new clsHeightmap.sMinMax();

            hmAlteration.Heightmaps    = new clsHeightmap[IntervalCount + 1];
            hmSource.HeightData.Height = new long[Terrain.TileSize.Y + 1, Terrain.TileSize.X + 1];
            hmSource.HeightData.SizeX  = Terrain.TileSize.X + 1;
            hmSource.HeightData.SizeY  = Terrain.TileSize.Y + 1;
            for (Y = 0; Y <= Terrain.TileSize.Y; Y++)
            {
                for (X = 0; X <= Terrain.TileSize.X; X++)
                {
                    hmSource.HeightData.Height[Y, X] = Convert.ToInt32(Terrain.Vertices[X, Y].Height / hmSource.HeightScale);
                }
            }
            hmSource.MinMaxGet(ref MinMax);
            HeightRange    = 255.0D;
            IntervalHeight = HeightRange / IntervalCount;
            Variation      = IntervalHeight / 4.0D;
            for (Level = 0; Level <= IntervalCount; Level++)
            {
                LevelHeight =
                    Convert.ToSingle(Convert.ToDouble(MinMax.Min + Convert.ToInt32(Level * MinMax.Max / IntervalCount)) * hmSource.HeightScale);
                AlterationLevels.Heights[Level] = LevelHeight;
                hmB.GenerateNewOfSize(Terrain.TileSize.Y + 1, Terrain.TileSize.X + 1, 2.0F, 10000.0D);
                hmAlteration.Heightmaps[Level] = new clsHeightmap();
                hmAlteration.Heightmaps[Level].Rescale(hmB, LevelHeight - Variation, LevelHeight + Variation);
            }
            hmA.FadeMultiple(hmSource, ref hmAlteration, ref AlterationLevels);
            hmB.Rescale(hmA, Math.Max(Convert.ToDouble(Convert.ToDouble(MinMax.Min * hmSource.HeightScale) - Variation), 0.0D),
                        Math.Min(Convert.ToDouble(Convert.ToDouble(MinMax.Max * hmSource.HeightScale) + Variation), 255.9D));
            for (Y = 0; Y <= Terrain.TileSize.Y; Y++)
            {
                for (X = 0; X <= Terrain.TileSize.X; X++)
                {
                    Terrain.Vertices[X, Y].Height = Convert.ToByte((hmB.HeightData.Height[Y, X] * hmB.HeightScale));
                }
            }
        }
Exemplo n.º 2
0
        public BooleanMap GenerateTerrainMap(float Scale, float Density)
        {
            var ReturnResult = default(BooleanMap);
            var hmB          = new clsHeightmap();
            var hmC          = new clsHeightmap();

            hmB.GenerateNewOfSize(Terrain.TileSize.Y + 1, Terrain.TileSize.X + 1, Scale, 1.0D);
            hmC.Rescale(hmB, 0.0D, 1.0D);
            ReturnResult = new BooleanMap();
            ReturnResult.Convert_Heightmap(hmC, ((1.0D - Density) / hmC.HeightScale).ToLong());
            return(ReturnResult);
        }
Exemplo n.º 3
0
        public void RandomizeHeights(int LevelCount)
        {
            var hmSource = new clsHeightmap();
            var hmA = new clsHeightmap();
            var hmB = new clsHeightmap();
            var IntervalCount = 0;
            var AlterationLevels = new clsHeightmap.sHeights();
            var hmAlteration = new sHeightmaps();
            float LevelHeight = 0;
            double HeightRange = 0;
            var Level = 0;
            double IntervalHeight = 0;
            double Variation = 0;
            var X = 0;
            var Y = 0;

            IntervalCount = LevelCount - 1;

            AlterationLevels.Heights = new float[IntervalCount + 1];
            var MinMax = new clsHeightmap.sMinMax();
            hmAlteration.Heightmaps = new clsHeightmap[IntervalCount + 1];
            hmSource.HeightData.Height = new long[Terrain.TileSize.Y + 1, Terrain.TileSize.X + 1];
            hmSource.HeightData.SizeX = Terrain.TileSize.X + 1;
            hmSource.HeightData.SizeY = Terrain.TileSize.Y + 1;
            for ( Y = 0; Y <= Terrain.TileSize.Y; Y++ )
            {
                for ( X = 0; X <= Terrain.TileSize.X; X++ )
                {
                    hmSource.HeightData.Height[Y, X] = Convert.ToInt32(Terrain.Vertices[X, Y].Height / hmSource.HeightScale);
                }
            }
            hmSource.MinMaxGet(ref MinMax);
            HeightRange = 255.0D;
            IntervalHeight = HeightRange / IntervalCount;
            Variation = IntervalHeight / 4.0D;
            for ( Level = 0; Level <= IntervalCount; Level++ )
            {
                LevelHeight =
                    Convert.ToSingle(Convert.ToDouble(MinMax.Min + Convert.ToInt32(Level * MinMax.Max / IntervalCount)) * hmSource.HeightScale);
                AlterationLevels.Heights[Level] = LevelHeight;
                hmB.GenerateNewOfSize(Terrain.TileSize.Y + 1, Terrain.TileSize.X + 1, 2.0F, 10000.0D);
                hmAlteration.Heightmaps[Level] = new clsHeightmap();
                hmAlteration.Heightmaps[Level].Rescale(hmB, LevelHeight - Variation, LevelHeight + Variation);
            }
            hmA.FadeMultiple(hmSource, ref hmAlteration, ref AlterationLevels);
            hmB.Rescale(hmA, Math.Max(Convert.ToDouble(Convert.ToDouble(MinMax.Min * hmSource.HeightScale) - Variation), 0.0D),
                Math.Min(Convert.ToDouble(Convert.ToDouble(MinMax.Max * hmSource.HeightScale) + Variation), 255.9D));
            for ( Y = 0; Y <= Terrain.TileSize.Y; Y++ )
            {
                for ( X = 0; X <= Terrain.TileSize.X; X++ )
                {
                    Terrain.Vertices[X, Y].Height = Convert.ToByte((hmB.HeightData.Height[Y, X] * hmB.HeightScale));
                }
            }
        }
Exemplo n.º 4
0
        public BooleanMap GenerateTerrainMap(float Scale, float Density)
        {
            var ReturnResult = default(BooleanMap);
            var hmB = new clsHeightmap();
            var hmC = new clsHeightmap();

            hmB.GenerateNewOfSize(Terrain.TileSize.Y + 1, Terrain.TileSize.X + 1, Scale, 1.0D);
            hmC.Rescale(hmB, 0.0D, 1.0D);
            ReturnResult = new BooleanMap();
            ReturnResult.Convert_Heightmap(hmC, (int)((1.0D - Density) / hmC.HeightScale));
            return ReturnResult;
        }
Exemplo n.º 5
0
        public void GenerateMasterTerrain(ref sGenerateMasterTerrainArgs Args)
        {
            var X = 0;
            var Y = 0;
            var A = 0;
            int[,] TerrainType = null;
            float[,] Slope = null;

            var TerrainNum = 0;

            var bmA = new BooleanMap();
            var Layer_Num = 0;
            var LayerResult = new BooleanMap[Args.LayerCount];
            var bmB = new BooleanMap();
            double BestSlope = 0;
            double CurrentSlope = 0;
            var hmB = new clsHeightmap();
            var hmC = new clsHeightmap();

            double difA = 0;
            double difB = 0;
            var NewTri = default(bool);
            var CliffSlope = Math.Atan(255.0D * Constants.DefaultHeightMultiplier / (2.0D * (Args.LevelCount - 1.0D) * Constants.TerrainGridSpacing)) -
                             MathUtil.RadOf1Deg; //divided by 2 due to the terrain height randomization

            Tileset = Args.Tileset.Tileset;

            for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ )
            {
                for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
                {
                    difA = Math.Abs((Terrain.Vertices[X + 1, Y + 1].Height) - Terrain.Vertices[X, Y].Height);
                    difB = Math.Abs((Terrain.Vertices[X, Y + 1].Height) - Terrain.Vertices[X + 1, Y].Height);
                    if ( difA == difB )
                    {
                        if ( App.Random.Next() >= 0.5F )
                        {
                            NewTri = false;
                        }
                        else
                        {
                            NewTri = true;
                        }
                    }
                    else if ( difA < difB )
                    {
                        NewTri = false;
                    }
                    else
                    {
                        NewTri = true;
                    }
                    if ( !(Terrain.Tiles[X, Y].Tri == NewTri) )
                    {
                        Terrain.Tiles[X, Y].Tri = NewTri;
                    }
                }
            }

            for ( A = 0; A <= Args.LayerCount - 1; A++ )
            {
                Args.Layers[A].Terrainmap = new BooleanMap();
                if ( Args.Layers[A].TerrainmapDensity == 1.0F )
                {
                    Args.Layers[A].Terrainmap.ValueData.Value = new bool[Terrain.TileSize.Y, Terrain.TileSize.X];
                    Args.Layers[A].Terrainmap.ValueData.Size = Terrain.TileSize;
                    for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ )
                    {
                        for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
                        {
                            Args.Layers[A].Terrainmap.ValueData.Value[Y, X] = true;
                        }
                    }
                }
                else
                {
                    hmB.GenerateNewOfSize(Terrain.TileSize.Y, Terrain.TileSize.X, Convert.ToSingle(Args.Layers[A].TerrainmapScale), 1.0D);
                    hmC.Rescale(hmB, 0.0D, 1.0D);
                    Args.Layers[A].Terrainmap.Convert_Heightmap(hmC, (int)((1.0F - Args.Layers[A].TerrainmapDensity) / hmC.HeightScale));
                }
            }

            var Pos = new XYInt();

            TerrainType = new int[Terrain.TileSize.X, Terrain.TileSize.Y];
            Slope = new float[Terrain.TileSize.X, Terrain.TileSize.Y];
            for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ )
            {
                for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
                {
                    //get slope
                    BestSlope = 0.0D;

                    Pos.X = (int)((X + 0.25D) * Constants.TerrainGridSpacing);
                    Pos.Y = (int)((Y + 0.25D) * Constants.TerrainGridSpacing);
                    CurrentSlope = GetTerrainSlopeAngle(Pos);
                    if ( CurrentSlope > BestSlope )
                    {
                        BestSlope = CurrentSlope;
                    }

                    Pos.X = (int)((X + 0.75D) * Constants.TerrainGridSpacing);
                    Pos.Y = (int)((Y + 0.25D) * Constants.TerrainGridSpacing);
                    CurrentSlope = GetTerrainSlopeAngle(Pos);
                    if ( CurrentSlope > BestSlope )
                    {
                        BestSlope = CurrentSlope;
                    }

                    Pos.X = (int)((X + 0.25D) * Constants.TerrainGridSpacing);
                    Pos.Y = (int)((Y + 0.75D) * Constants.TerrainGridSpacing);
                    CurrentSlope = GetTerrainSlopeAngle(Pos);
                    if ( CurrentSlope > BestSlope )
                    {
                        BestSlope = CurrentSlope;
                    }

                    Pos.X = (int)((X + 0.75D) * Constants.TerrainGridSpacing);
                    Pos.Y = (int)((Y + 0.75D) * Constants.TerrainGridSpacing);
                    CurrentSlope = GetTerrainSlopeAngle(Pos);
                    if ( CurrentSlope > BestSlope )
                    {
                        BestSlope = CurrentSlope;
                    }

                    Slope[X, Y] = (float)BestSlope;
                }
            }
            for ( Layer_Num = 0; Layer_Num <= Args.LayerCount - 1; Layer_Num++ )
            {
                TerrainNum = Args.Layers[Layer_Num].TileNum;
                if ( TerrainNum >= 0 )
                {
                    //do other layer constraints
                    LayerResult[Layer_Num] = new BooleanMap();
                    LayerResult[Layer_Num].Copy(Args.Layers[Layer_Num].Terrainmap);
                    if ( Args.Layers[Layer_Num].WithinLayer >= 0 )
                    {
                        if ( Args.Layers[Layer_Num].WithinLayer < Layer_Num )
                        {
                            bmA.Within(LayerResult[Layer_Num], LayerResult[Args.Layers[Layer_Num].WithinLayer]);
                            LayerResult[Layer_Num].ValueData = bmA.ValueData;
                            bmA.ValueData = new BooleanMapDataValue();
                        }
                    }
                    for ( A = 0; A <= Layer_Num - 1; A++ )
                    {
                        if ( Args.Layers[Layer_Num].AvoidLayers[A] )
                        {
                            bmA.Expand_One_Tile(LayerResult[A]);
                            bmB.Remove(LayerResult[Layer_Num], bmA);
                            LayerResult[Layer_Num].ValueData = bmB.ValueData;
                            bmB.ValueData = new BooleanMapDataValue();
                        }
                    }
                    //do height and slope constraints
                    for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ )
                    {
                        for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
                        {
                            if ( LayerResult[Layer_Num].ValueData.Value[Y, X] )
                            {
                                if ( Terrain.Vertices[X, Y].Height < Args.Layers[Layer_Num].HeightMin
                                     || Terrain.Vertices[X, Y].Height > Args.Layers[Layer_Num].HeightMax )
                                {
                                    LayerResult[Layer_Num].ValueData.Value[Y, X] = false;
                                }
                                if ( Args.Layers[Layer_Num].IsCliff )
                                {
                                    if ( LayerResult[Layer_Num].ValueData.Value[Y, X] )
                                    {
                                        if ( Slope[X, Y] < CliffSlope )
                                        {
                                            LayerResult[Layer_Num].ValueData.Value[Y, X] = false;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ )
                    {
                        for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
                        {
                            if ( LayerResult[Layer_Num].ValueData.Value[Y, X] )
                            {
                                TerrainType[X, Y] = TerrainNum;
                            }
                        }
                    }
                }
            }

            //set water tiles

            for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ )
            {
                for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
                {
                    if ( Args.Watermap.ValueData.Value[Y, X] )
                    {
                        if ( Slope[X, Y] < CliffSlope )
                        {
                            TerrainType[X, Y] = 17;
                        }
                    }
                }
            }

            //set border tiles to cliffs
            for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ )
            {
                for ( X = 0; X <= 2; X++ )
                {
                    TerrainType[X, Y] = Args.Tileset.BorderTextureNum;
                }
                for ( X = Terrain.TileSize.X - 4; X <= Terrain.TileSize.X - 1; X++ )
                {
                    TerrainType[X, Y] = Args.Tileset.BorderTextureNum;
                }
            }
            for ( X = 3; X <= Terrain.TileSize.X - 5; X++ )
            {
                for ( Y = 0; Y <= 2; Y++ )
                {
                    TerrainType[X, Y] = Args.Tileset.BorderTextureNum;
                }
                for ( Y = Terrain.TileSize.Y - 4; Y <= Terrain.TileSize.Y - 1; Y++ )
                {
                    TerrainType[X, Y] = Args.Tileset.BorderTextureNum;
                }
            }

            for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ )
            {
                for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
                {
                    Terrain.Tiles[X, Y].Texture.TextureNum = TerrainType[X, Y];
                }
            }
        }
Exemplo n.º 6
0
        public void GenerateMasterTerrain(ref sGenerateMasterTerrainArgs Args)
        {
            var X = 0;
            var Y = 0;
            var A = 0;

            int[,] TerrainType = null;
            float[,] Slope     = null;

            var TerrainNum = 0;

            var    bmA          = new BooleanMap();
            var    Layer_Num    = 0;
            var    LayerResult  = new BooleanMap[Args.LayerCount];
            var    bmB          = new BooleanMap();
            double BestSlope    = 0;
            double CurrentSlope = 0;
            var    hmB          = new clsHeightmap();
            var    hmC          = new clsHeightmap();

            double difA       = 0;
            double difB       = 0;
            var    NewTri     = default(bool);
            var    CliffSlope = Math.Atan(255.0D * Constants.DefaultHeightMultiplier / (2.0D * (Args.LevelCount - 1.0D) * Constants.TerrainGridSpacing)) -
                                MathUtil.RadOf1Deg; //divided by 2 due to the terrain height randomization

            Tileset = Args.Tileset.Tileset;

            for (Y = 0; Y <= Terrain.TileSize.Y - 1; Y++)
            {
                for (X = 0; X <= Terrain.TileSize.X - 1; X++)
                {
                    difA = Math.Abs((Terrain.Vertices[X + 1, Y + 1].Height) - Terrain.Vertices[X, Y].Height);
                    difB = Math.Abs((Terrain.Vertices[X, Y + 1].Height) - Terrain.Vertices[X + 1, Y].Height);
                    if (difA == difB)
                    {
                        if (App.Random.Next() >= 0.5F)
                        {
                            NewTri = false;
                        }
                        else
                        {
                            NewTri = true;
                        }
                    }
                    else if (difA < difB)
                    {
                        NewTri = false;
                    }
                    else
                    {
                        NewTri = true;
                    }
                    if (!(Terrain.Tiles[X, Y].Tri == NewTri))
                    {
                        Terrain.Tiles[X, Y].Tri = NewTri;
                    }
                }
            }

            for (A = 0; A <= Args.LayerCount - 1; A++)
            {
                Args.Layers[A].Terrainmap = new BooleanMap();
                if (Args.Layers[A].TerrainmapDensity == 1.0F)
                {
                    Args.Layers[A].Terrainmap.ValueData.Value = new bool[Terrain.TileSize.Y, Terrain.TileSize.X];
                    Args.Layers[A].Terrainmap.ValueData.Size  = Terrain.TileSize;
                    for (Y = 0; Y <= Terrain.TileSize.Y - 1; Y++)
                    {
                        for (X = 0; X <= Terrain.TileSize.X - 1; X++)
                        {
                            Args.Layers[A].Terrainmap.ValueData.Value[Y, X] = true;
                        }
                    }
                }
                else
                {
                    hmB.GenerateNewOfSize(Terrain.TileSize.Y, Terrain.TileSize.X, Convert.ToSingle(Args.Layers[A].TerrainmapScale), 1.0D);
                    hmC.Rescale(hmB, 0.0D, 1.0D);
                    Args.Layers[A].Terrainmap.Convert_Heightmap(hmC, ((1.0F - Args.Layers[A].TerrainmapDensity) / hmC.HeightScale).ToLong());
                }
            }

            var Pos = new XYInt();

            TerrainType = new int[Terrain.TileSize.X, Terrain.TileSize.Y];
            Slope       = new float[Terrain.TileSize.X, Terrain.TileSize.Y];
            for (Y = 0; Y <= Terrain.TileSize.Y - 1; Y++)
            {
                for (X = 0; X <= Terrain.TileSize.X - 1; X++)
                {
                    //get slope
                    BestSlope = 0.0D;

                    Pos.X        = ((X + 0.25D) * Constants.TerrainGridSpacing).ToInt();
                    Pos.Y        = ((Y + 0.25D) * Constants.TerrainGridSpacing).ToInt();
                    CurrentSlope = GetTerrainSlopeAngle(Pos);
                    if (CurrentSlope > BestSlope)
                    {
                        BestSlope = CurrentSlope;
                    }

                    Pos.X        = ((X + 0.75D) * Constants.TerrainGridSpacing).ToInt();
                    Pos.Y        = ((Y + 0.25D) * Constants.TerrainGridSpacing).ToInt();
                    CurrentSlope = GetTerrainSlopeAngle(Pos);
                    if (CurrentSlope > BestSlope)
                    {
                        BestSlope = CurrentSlope;
                    }

                    Pos.X        = ((X + 0.25D) * Constants.TerrainGridSpacing).ToInt();
                    Pos.Y        = ((Y + 0.75D) * Constants.TerrainGridSpacing).ToInt();
                    CurrentSlope = GetTerrainSlopeAngle(Pos);
                    if (CurrentSlope > BestSlope)
                    {
                        BestSlope = CurrentSlope;
                    }

                    Pos.X        = ((X + 0.75D) * Constants.TerrainGridSpacing).ToInt();
                    Pos.Y        = ((Y + 0.75D) * Constants.TerrainGridSpacing).ToInt();
                    CurrentSlope = GetTerrainSlopeAngle(Pos);
                    if (CurrentSlope > BestSlope)
                    {
                        BestSlope = CurrentSlope;
                    }

                    Slope[X, Y] = (float)BestSlope;
                }
            }
            for (Layer_Num = 0; Layer_Num <= Args.LayerCount - 1; Layer_Num++)
            {
                TerrainNum = Args.Layers[Layer_Num].TileNum;
                if (TerrainNum >= 0)
                {
                    //do other layer constraints
                    LayerResult[Layer_Num] = new BooleanMap();
                    LayerResult[Layer_Num].Copy(Args.Layers[Layer_Num].Terrainmap);
                    if (Args.Layers[Layer_Num].WithinLayer >= 0)
                    {
                        if (Args.Layers[Layer_Num].WithinLayer < Layer_Num)
                        {
                            bmA.Within(LayerResult[Layer_Num], LayerResult[Args.Layers[Layer_Num].WithinLayer]);
                            LayerResult[Layer_Num].ValueData = bmA.ValueData;
                            bmA.ValueData = new BooleanMapDataValue();
                        }
                    }
                    for (A = 0; A <= Layer_Num - 1; A++)
                    {
                        if (Args.Layers[Layer_Num].AvoidLayers[A])
                        {
                            bmA.ExpandOneTile(LayerResult[A]);
                            bmB.Remove(LayerResult[Layer_Num], bmA);
                            LayerResult[Layer_Num].ValueData = bmB.ValueData;
                            bmB.ValueData = new BooleanMapDataValue();
                        }
                    }
                    //do height and slope constraints
                    for (Y = 0; Y <= Terrain.TileSize.Y - 1; Y++)
                    {
                        for (X = 0; X <= Terrain.TileSize.X - 1; X++)
                        {
                            if (LayerResult[Layer_Num].ValueData.Value[Y, X])
                            {
                                if (Terrain.Vertices[X, Y].Height <Args.Layers[Layer_Num].HeightMin ||
                                                                   Terrain.Vertices[X, Y].Height> Args.Layers[Layer_Num].HeightMax)
                                {
                                    LayerResult[Layer_Num].ValueData.Value[Y, X] = false;
                                }
                                if (Args.Layers[Layer_Num].IsCliff)
                                {
                                    if (LayerResult[Layer_Num].ValueData.Value[Y, X])
                                    {
                                        if (Slope[X, Y] < CliffSlope)
                                        {
                                            LayerResult[Layer_Num].ValueData.Value[Y, X] = false;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    for (Y = 0; Y <= Terrain.TileSize.Y - 1; Y++)
                    {
                        for (X = 0; X <= Terrain.TileSize.X - 1; X++)
                        {
                            if (LayerResult[Layer_Num].ValueData.Value[Y, X])
                            {
                                TerrainType[X, Y] = TerrainNum;
                            }
                        }
                    }
                }
            }

            //set water tiles

            for (Y = 0; Y <= Terrain.TileSize.Y - 1; Y++)
            {
                for (X = 0; X <= Terrain.TileSize.X - 1; X++)
                {
                    if (Args.Watermap.ValueData.Value[Y, X])
                    {
                        if (Slope[X, Y] < CliffSlope)
                        {
                            TerrainType[X, Y] = 17;
                        }
                    }
                }
            }

            //set border tiles to cliffs
            for (Y = 0; Y <= Terrain.TileSize.Y - 1; Y++)
            {
                for (X = 0; X <= 2; X++)
                {
                    TerrainType[X, Y] = Args.Tileset.BorderTextureNum;
                }
                for (X = Terrain.TileSize.X - 4; X <= Terrain.TileSize.X - 1; X++)
                {
                    TerrainType[X, Y] = Args.Tileset.BorderTextureNum;
                }
            }
            for (X = 3; X <= Terrain.TileSize.X - 5; X++)
            {
                for (Y = 0; Y <= 2; Y++)
                {
                    TerrainType[X, Y] = Args.Tileset.BorderTextureNum;
                }
                for (Y = Terrain.TileSize.Y - 4; Y <= Terrain.TileSize.Y - 1; Y++)
                {
                    TerrainType[X, Y] = Args.Tileset.BorderTextureNum;
                }
            }

            for (Y = 0; Y <= Terrain.TileSize.Y - 1; Y++)
            {
                for (X = 0; X <= Terrain.TileSize.X - 1; X++)
                {
                    Terrain.Tiles[X, Y].Texture.TextureNum = TerrainType[X, Y];
                }
            }
        }