private void SaveTerrain(string filename)
        {
            if (File.Exists(filename))
            {
                File.Delete(filename);
            }

            XMLReader xmlReader = new XMLReader();

            xmlReader.CreateDocument();
            xmlReader.SetRoot("Terrain");

            xmlReader.AddElement("drawskybox", Editor.bDrawSkybox.ToString());
            xmlReader.AddElement("skybox", selectedSky);

            if (Editor.heightmap != null)
            {
                Editor.heightmap.UpdateHeightFile();

                //Heightmap Texture
                string title = Path.GetFileNameWithoutExtension(filename);
                Editor.heightmap.heightmap.Save(title + "_height.bmp", ImageFileFormat.Bmp);
                xmlReader.AddElement("heightmap", title + "_height.bmp");

                //Colormap Texture
                Editor.heightmap.colormap.Save(title + "_color.tga", ImageFileFormat.Tga);
                xmlReader.AddElement("colormap", title + "_color.tga");

                //Heightmap Settings
                xmlReader.AddElement("cellsize", Editor.heightmap.cellSize.X + ";" + Editor.heightmap.cellSize.Y);
                xmlReader.AddElement("maxheight", Editor.heightmap.maxHeight.ToString());
                xmlReader.AddElement("smooth", Editor.heightmap.bSmooth.ToString());
                xmlReader.AddElement("drawdetail", Editor.heightmap.bDrawDetail.ToString());
                xmlReader.AddElement("ambientlight", Editor.heightmap.ambientLight.X + ";" + Editor.heightmap.ambientLight.Y + ";" + Editor.heightmap.ambientLight.Z);

                //Texture Layers Settings
                if (Editor.heightmap.textureLayer != null)
                {
                    for (int i = 0; i < Editor.heightmap.textureLayer.Length; i++)
                    {
                        xmlReader.AddElement("layer" + i + "tex", Editor.heightmap.textureLayer[i].layerTex);
                        xmlReader.AddElement("layer" + i + "texScale", Editor.heightmap.textureLayer[i].scale.ToString().Replace('.', ';'));
                    }
                }
            }

            //Sun Settings
            xmlReader.AddElement("drawsun", Editor.bDrawSun.ToString());
            xmlReader.AddElement("suncolor", Editor.sun.color.X + ";" + Editor.sun.color.Y + ";" + Editor.sun.color.Z);
            xmlReader.AddElement("angle", MathHelper.ToDegrees(Editor.sun.rotation.Y).ToString());
            xmlReader.AddElement("elevation", MathHelper.ToDegrees(Editor.sun.rotation.X).ToString());
            xmlReader.AddElement("longitudespeed", Editor.sun.LongitudeSpeed.ToString());
            xmlReader.AddElement("latitudespeed", Editor.sun.LatitudeSpeed.ToString());
            xmlReader.AddElement("intensity", Editor.sun.lightPower.ToString());
            xmlReader.AddElement("sunraycollision", checkBox4.Checked.ToString());

            //Fog Settings
            xmlReader.AddElement("usefog", Editor.bUseFog.ToString());
            xmlReader.AddElement("fogcolor", Editor.fogColor.ToVector3().X + ";" + Editor.fogColor.ToVector3().Y + ";" + Editor.fogColor.ToVector3().Z);
            xmlReader.AddElement("fogstart", Editor.fogStart.ToString());
            xmlReader.AddElement("fogend", Editor.fogEnd.ToString());
            xmlReader.AddElement("fogdensity", Editor.fogDensity.ToString());

            xmlReader.Save(filename);

            Editor.console.Add("File saved successfuly!");
        }