From c5d1f87cd202663f2f26ca90a973d9763070dda3 Mon Sep 17 00:00:00 2001
From: Adam Frisby
Date: Mon, 3 Mar 2008 08:35:59 +0000
Subject: * Removed and sorted using clauses in a number of files. * Cleaned up
 ITerrainChannel * Implemented Raise, Lower, Smooth, Flatten, Noise Terrain
 Paint Brushes * Implemented Raise, Lower, Smooth, Flatten, Noise Terrain Fill
 Brushes * Implemented Export functionality for RAW32 terrain loader *
 Implemented Import/Export for SLRAW terrain loader * Implemented Export for
 JPEG terrain loader

---
 .../Environment/Interfaces/ITerrainChannel.cs      |   2 +-
 .../Modules/AgentAssetTransactionModule.cs         |   1 -
 .../Environment/Modules/AgentAssetsTransactions.cs |   2 -
 .../Environment/Modules/AssetDownloadModule.cs     |   4 +-
 .../Environment/Modules/AvatarFactoryModule.cs     |   3 +-
 .../Environment/Modules/BetaGridLikeMoneyModule.cs |   6 +-
 OpenSim/Region/Environment/Modules/ChatModule.cs   |   1 -
 .../Region/Environment/Modules/FriendsModule.cs    |   9 +-
 OpenSim/Region/Environment/Modules/GroupsModule.cs |   6 +-
 .../Environment/Modules/InstantMessageModule.cs    |   2 -
 OpenSim/Region/Environment/Modules/SunModule.cs    |   1 -
 .../Modules/Terrain/FileLoaders/JPEG.cs            |  79 ++++++++++++
 .../Modules/Terrain/FileLoaders/LLRAW.cs           | 132 +++++++++++++++++++++
 .../Modules/Terrain/FileLoaders/RAW32.cs           |  50 +++++++-
 .../Modules/Terrain/FileLoaders/Terragen.cs        |  36 +++++-
 .../Modules/Terrain/FloodBrushes/FlattenArea.cs    |  73 ++++++++++++
 .../Modules/Terrain/FloodBrushes/LowerArea.cs      |  53 +++++++++
 .../Modules/Terrain/FloodBrushes/NoiseArea.cs      |  57 +++++++++
 .../Modules/Terrain/FloodBrushes/RaiseArea.cs      |  31 ++++-
 .../Modules/Terrain/FloodBrushes/SmoothArea.cs     | 107 +++++++++++++++++
 .../Modules/Terrain/PaintBrushes/FlattenSphere.cs  | 125 +++++++++++++++++++
 .../Modules/Terrain/PaintBrushes/LowerSphere.cs    |  65 ++++++++++
 .../Modules/Terrain/PaintBrushes/NoiseSphere.cs    |  73 ++++++++++++
 .../Modules/Terrain/PaintBrushes/RaiseSphere.cs    |  32 ++++-
 .../Modules/Terrain/PaintBrushes/SmoothSphere.cs   | 130 ++++++++++++++++++++
 .../Environment/Modules/Terrain/TerrainModule.cs   |  79 +++++++++---
 .../Environment/Modules/TextureDownloadModule.cs   |   2 -
 .../Environment/Modules/TextureNotFoundSender.cs   |   3 -
 .../Modules/VoiceChat/VoiceChatServer.cs           |   2 +-
 OpenSim/Region/Environment/Scenes/Scene.cs         |   4 +-
 OpenSim/Region/Environment/Scenes/SceneBase.cs     |  11 +-
 31 files changed, 1112 insertions(+), 69 deletions(-)
 create mode 100644 OpenSim/Region/Environment/Modules/Terrain/FileLoaders/JPEG.cs
 create mode 100644 OpenSim/Region/Environment/Modules/Terrain/FileLoaders/LLRAW.cs
 create mode 100644 OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/FlattenArea.cs
 create mode 100644 OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/LowerArea.cs
 create mode 100644 OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/NoiseArea.cs
 create mode 100644 OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/SmoothArea.cs
 create mode 100644 OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/FlattenSphere.cs
 create mode 100644 OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/LowerSphere.cs
 create mode 100644 OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/NoiseSphere.cs
 create mode 100644 OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/SmoothSphere.cs

(limited to 'OpenSim')

diff --git a/OpenSim/Region/Environment/Interfaces/ITerrainChannel.cs b/OpenSim/Region/Environment/Interfaces/ITerrainChannel.cs
index cc02268..f0d600a 100644
--- a/OpenSim/Region/Environment/Interfaces/ITerrainChannel.cs
+++ b/OpenSim/Region/Environment/Interfaces/ITerrainChannel.cs
@@ -26,7 +26,6 @@
 * 
 */
 
-using System;
 namespace OpenSim.Region.Environment.Interfaces
 {
     public interface ITerrainChannel
@@ -34,5 +33,6 @@ namespace OpenSim.Region.Environment.Interfaces
         int Height { get; }
         double this[int x, int y] { get; set; }
         int Width { get; }
+        float[] GetFloatsSerialised();
     }
 }
diff --git a/OpenSim/Region/Environment/Modules/AgentAssetTransactionModule.cs b/OpenSim/Region/Environment/Modules/AgentAssetTransactionModule.cs
index 99d6db1..492e7b5 100644
--- a/OpenSim/Region/Environment/Modules/AgentAssetTransactionModule.cs
+++ b/OpenSim/Region/Environment/Modules/AgentAssetTransactionModule.cs
@@ -28,7 +28,6 @@
 
 using System;
 using System.Collections.Generic;
-using System.Text;
 using libsecondlife;
 using Nini.Config;
 using OpenSim.Framework;
diff --git a/OpenSim/Region/Environment/Modules/AgentAssetsTransactions.cs b/OpenSim/Region/Environment/Modules/AgentAssetsTransactions.cs
index bfca1a2..097fa3e 100644
--- a/OpenSim/Region/Environment/Modules/AgentAssetsTransactions.cs
+++ b/OpenSim/Region/Environment/Modules/AgentAssetsTransactions.cs
@@ -28,11 +28,9 @@
 
 using System;
 using System.Collections.Generic;
-using System.Text;
 using System.IO;
 using libsecondlife;
 using libsecondlife.Packets;
-using OpenSim.Framework.Servers;
 using OpenSim.Framework;
 using OpenSim.Framework.Communications.Cache;
 
diff --git a/OpenSim/Region/Environment/Modules/AssetDownloadModule.cs b/OpenSim/Region/Environment/Modules/AssetDownloadModule.cs
index 33c0ce2..74102c2 100644
--- a/OpenSim/Region/Environment/Modules/AssetDownloadModule.cs
+++ b/OpenSim/Region/Environment/Modules/AssetDownloadModule.cs
@@ -29,12 +29,12 @@
 using System;
 using System.Collections.Generic;
 using System.Threading;
+using libsecondlife;
+using libsecondlife.Packets;
 using Nini.Config;
 using OpenSim.Framework;
 using OpenSim.Region.Environment.Interfaces;
 using OpenSim.Region.Environment.Scenes;
-using libsecondlife;
-using libsecondlife.Packets;
 
 namespace OpenSim.Region.Environment.Modules
 {
diff --git a/OpenSim/Region/Environment/Modules/AvatarFactoryModule.cs b/OpenSim/Region/Environment/Modules/AvatarFactoryModule.cs
index 1551707..7b54634 100644
--- a/OpenSim/Region/Environment/Modules/AvatarFactoryModule.cs
+++ b/OpenSim/Region/Environment/Modules/AvatarFactoryModule.cs
@@ -33,10 +33,9 @@ using libsecondlife;
 using Nini.Config;
 using OpenSim.Framework;
 using OpenSim.Framework.Communications.Cache;
-using OpenSim.Framework.Console;
+using OpenSim.Framework.Data;
 using OpenSim.Region.Environment.Interfaces;
 using OpenSim.Region.Environment.Scenes;
-using OpenSim.Framework.Data;
 using OpenSim.Framework.Data.Base;
 
 namespace OpenSim.Region.Environment.Modules
diff --git a/OpenSim/Region/Environment/Modules/BetaGridLikeMoneyModule.cs b/OpenSim/Region/Environment/Modules/BetaGridLikeMoneyModule.cs
index 649b80e..d53083f 100644
--- a/OpenSim/Region/Environment/Modules/BetaGridLikeMoneyModule.cs
+++ b/OpenSim/Region/Environment/Modules/BetaGridLikeMoneyModule.cs
@@ -26,15 +26,13 @@
 * 
 */
 
-using Nini.Config;
 using System;
-using System.Collections;
 using System.Collections.Generic;
+using libsecondlife;
+using Nini.Config;
 using OpenSim.Framework;
-using OpenSim.Framework.Console;
 using OpenSim.Region.Environment.Interfaces;
 using OpenSim.Region.Environment.Scenes;
-using libsecondlife;
 using MoneyTransferArgs = OpenSim.Region.Environment.Scenes.EventManager.MoneyTransferArgs;
 
 namespace OpenSim.Region.Environment.Modules
diff --git a/OpenSim/Region/Environment/Modules/ChatModule.cs b/OpenSim/Region/Environment/Modules/ChatModule.cs
index a21aefe..e8d480c 100644
--- a/OpenSim/Region/Environment/Modules/ChatModule.cs
+++ b/OpenSim/Region/Environment/Modules/ChatModule.cs
@@ -35,7 +35,6 @@ using System.Threading;
 using libsecondlife;
 using Nini.Config;
 using OpenSim.Framework;
-using OpenSim.Framework.Console;
 using OpenSim.Region.Environment.Interfaces;
 using OpenSim.Region.Environment.Scenes;
 
diff --git a/OpenSim/Region/Environment/Modules/FriendsModule.cs b/OpenSim/Region/Environment/Modules/FriendsModule.cs
index 4d06750..a681bb9 100644
--- a/OpenSim/Region/Environment/Modules/FriendsModule.cs
+++ b/OpenSim/Region/Environment/Modules/FriendsModule.cs
@@ -26,16 +26,13 @@
 * 
 */
 
-using Nini.Config;
-using System;
-using System.Collections;
 using System.Collections.Generic;
+using libsecondlife;
+using Nini.Config;
+using Nwc.XmlRpc;
 using OpenSim.Framework;
-using OpenSim.Framework.Console;
 using OpenSim.Region.Environment.Interfaces;
 using OpenSim.Region.Environment.Scenes;
-using libsecondlife;
-using Nwc.XmlRpc;
 
 namespace OpenSim.Region.Environment.Modules
 {
diff --git a/OpenSim/Region/Environment/Modules/GroupsModule.cs b/OpenSim/Region/Environment/Modules/GroupsModule.cs
index 2d8efce..b8980a0 100644
--- a/OpenSim/Region/Environment/Modules/GroupsModule.cs
+++ b/OpenSim/Region/Environment/Modules/GroupsModule.cs
@@ -26,15 +26,13 @@
 * 
 */
 
-using Nini.Config;
 using System;
-using System.Collections;
 using System.Collections.Generic;
+using libsecondlife;
+using Nini.Config;
 using OpenSim.Framework;
-using OpenSim.Framework.Console;
 using OpenSim.Region.Environment.Interfaces;
 using OpenSim.Region.Environment.Scenes;
-using libsecondlife;
 
 namespace OpenSim.Region.Environment.Modules
 {
diff --git a/OpenSim/Region/Environment/Modules/InstantMessageModule.cs b/OpenSim/Region/Environment/Modules/InstantMessageModule.cs
index 70f3d99..425e275 100644
--- a/OpenSim/Region/Environment/Modules/InstantMessageModule.cs
+++ b/OpenSim/Region/Environment/Modules/InstantMessageModule.cs
@@ -30,9 +30,7 @@ using System.Collections;
 using System.Collections.Generic;
 using libsecondlife;
 using Nini.Config;
-using Nwc.XmlRpc;
 using OpenSim.Framework;
-using OpenSim.Framework.Console;
 using OpenSim.Region.Environment.Interfaces;
 using OpenSim.Region.Environment.Scenes;
 
diff --git a/OpenSim/Region/Environment/Modules/SunModule.cs b/OpenSim/Region/Environment/Modules/SunModule.cs
index fb80f68..4895a0f 100644
--- a/OpenSim/Region/Environment/Modules/SunModule.cs
+++ b/OpenSim/Region/Environment/Modules/SunModule.cs
@@ -31,7 +31,6 @@ using System.Collections.Generic;
 using libsecondlife;
 using Nini.Config;
 using OpenSim.Framework;
-using OpenSim.Framework.Console;
 using OpenSim.Region.Environment.Interfaces;
 using OpenSim.Region.Environment.Scenes;
 
diff --git a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/JPEG.cs b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/JPEG.cs
new file mode 100644
index 0000000..57e6cd8
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/JPEG.cs
@@ -0,0 +1,79 @@
+/*
+* Copyright (c) Contributors, http://opensimulator.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System;
+using System.IO;
+using System.Drawing;
+using OpenSim.Region.Environment.Interfaces;
+
+namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
+{
+    public class JPEG : ITerrainLoader
+    {
+        #region ITerrainLoader Members
+
+        public ITerrainChannel LoadFile(string filename)
+        {
+            throw new NotImplementedException();
+        }
+
+        private Bitmap CreateBitmapFromMap(ITerrainChannel map)
+        {
+            Bitmap gradientmapLd = new Bitmap("defaultstripe.png");
+
+            int pallete = gradientmapLd.Height;
+
+            Bitmap bmp = new Bitmap(heightmap.w, heightmap.h);
+            Color[] colours = new Color[pallete];
+
+            for (int i = 0; i < pallete; i++)
+            {
+                colours[i] = gradientmapLd.GetPixel(0, i);
+            }
+
+            for (int y = 0; y < copy.h; y++)
+            {
+                for (int x = 0; x < copy.w; x++)
+                {
+                    // 512 is the largest possible height before colours clamp
+                    int colorindex = (int)(Math.Max(Math.Min(1.0, map[x, y] / 512.0), 0.0) * (pallete - 1));
+                    bmp.SetPixel(x, map.Height - y - 1, colours[colorindex]);
+                }
+            }
+            return bmp;
+        }
+
+        public void SaveFile(string filename, ITerrainChannel map)
+        {
+            Bitmap colours = CreateBitmapFromMap(map);
+
+            colours.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg);
+        }
+
+        #endregion
+    }
+}
\ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/LLRAW.cs b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/LLRAW.cs
new file mode 100644
index 0000000..58dc6c7
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/LLRAW.cs
@@ -0,0 +1,132 @@
+/*
+* Copyright (c) Contributors, http://opensimulator.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System;
+using System.IO;
+using OpenSim.Region.Environment.Interfaces;
+
+namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
+{
+    public class LLRAW : ITerrainLoader
+    {
+        #region ITerrainLoader Members
+
+        public ITerrainChannel LoadFile(string filename)
+        {
+            TerrainChannel retval = new TerrainChannel();
+
+            FileInfo file = new FileInfo(filename);
+            FileStream s = file.Open(FileMode.Open, FileAccess.Read);
+            BinaryReader bs = new BinaryReader(s);
+            int x, y;
+            for (y = 0; y < retval.Height; y++)
+            {
+                for (x = 0; x < retval.Width; x++)
+                {
+                    retval[x, y] = (double)bs.ReadByte() * ((double)bs.ReadByte() / 127.0);
+                    bs.ReadBytes(11); // Advance the stream to next bytes.
+                }
+            }
+
+            bs.Close();
+            s.Close();
+
+            return retval;
+        }
+
+        public void SaveFile(string filename, ITerrainChannel map)
+        {
+            FileInfo file = new FileInfo(filename);
+            FileStream s = file.Open(FileMode.CreateNew, FileAccess.Write);
+            BinaryWriter binStream = new BinaryWriter(s);
+
+            // Generate a smegging big lookup table to speed the operation up (it needs it)
+            double[] lookupHeightTable = new double[65536];
+            int i, j, x, y;
+            for (i = 0; i < 256; i++)
+            {
+                for (j = 0; j < 256; j++)
+                {
+                    lookupHeightTable[i + (j * 256)] = ((double)i * ((double)j / 127.0));
+                }
+            }
+
+            // Output the calculated raw
+            for (y = 0; y < map.Height; y++)
+            {
+                for (x = 0; x < map.Width; x++)
+                {
+                    double t = map[x, y];
+                    double min = double.MaxValue;
+                    int index = 0;
+
+                    for (i = 0; i < 65536; i++)
+                    {
+                        if (Math.Abs(t - lookupHeightTable[i]) < min)
+                        {
+                            min = Math.Abs(t - lookupHeightTable[i]);
+                            index = i;
+                        }
+                    }
+
+                    byte red = (byte)(index & 0xFF);
+                    byte green = (byte)((index >> 8) & 0xFF);
+                    byte blue   = 20;
+                    byte alpha1 = 0; // Land Parcels
+                    byte alpha2 = 0; // For Sale Land
+                    byte alpha3 = 0; // Public Edit Object
+                    byte alpha4 = 0; // Public Edit Land
+                    byte alpha5 = 255; // Safe Land
+                    byte alpha6 = 255; // Flying Allowed
+                    byte alpha7 = 255; // Create Landmark
+                    byte alpha8 = 255; // Outside Scripts
+                    byte alpha9 = red;
+                    byte alpha10 = green;
+
+                    binStream.Write(red);
+                    binStream.Write(green);
+                    binStream.Write(blue);
+                    binStream.Write(alpha1);
+                    binStream.Write(alpha2);
+                    binStream.Write(alpha3);
+                    binStream.Write(alpha4);
+                    binStream.Write(alpha5);
+                    binStream.Write(alpha6);
+                    binStream.Write(alpha7);
+                    binStream.Write(alpha8);
+                    binStream.Write(alpha9);
+                    binStream.Write(alpha10);
+                }
+            }
+
+            binStream.Close();
+            s.Close();
+        }
+
+        #endregion
+    }
+}
diff --git a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/RAW32.cs b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/RAW32.cs
index bf716c5..d69d62a 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/RAW32.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/RAW32.cs
@@ -1,8 +1,32 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
+/*
+* Copyright (c) Contributors, http://opensimulator.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System;
 using System.IO;
-using OpenSim.Region.Environment.Modules.Terrain;
 using OpenSim.Region.Environment.Interfaces;
 
 namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
@@ -33,9 +57,23 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
             return retval;
         }
 
-        public void SaveFile(string filename)
+        public void SaveFile(string filename, ITerrainChannel map)
         {
-            throw new NotImplementedException();
+            FileInfo file = new FileInfo(filename);
+            FileStream s = file.Open(FileMode.CreateNew, FileAccess.Write);
+            BinaryWriter bs = new BinaryWriter(s);
+
+            int x, y;
+            for (y = 0; y < h; y++)
+            {
+                for (x = 0; x < w; x++)
+                {
+                    bs.Write((float)map[x, y]);
+                }
+            }
+
+            bs.Close();
+            s.Close();
         }
 
         #endregion
diff --git a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/Terragen.cs b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/Terragen.cs
index b12d99f..d93400f 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/Terragen.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/Terragen.cs
@@ -1,8 +1,33 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
+/*
+* Copyright (c) Contributors, http://opensimulator.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System;
 using System.IO;
-using OpenSim.Region.Environment.Modules.Terrain;
+using System.Text;
 using OpenSim.Region.Environment.Interfaces;
 
 namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
@@ -79,8 +104,9 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
             return retval;
         }
 
-        public void SaveFile(string filename)
+        public void SaveFile(string filename, ITerrainChannel map)
         {
+            char[] header = "TERRAGENTERRAIN".ToCharArray();
             throw new NotImplementedException();
         }
 
diff --git a/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/FlattenArea.cs b/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/FlattenArea.cs
new file mode 100644
index 0000000..d022fbe
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/FlattenArea.cs
@@ -0,0 +1,73 @@
+/*
+* Copyright (c) Contributors, http://opensimulator.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System;
+using System.Collections.Generic;
+using System.Text;
+using OpenSim.Region.Environment.Modules.Terrain;
+using OpenSim.Region.Environment.Interfaces;
+
+namespace OpenSim.Region.Environment.Modules.Terrain.FloodBrushes
+{
+    public class FlattenArea : ITerrainFloodEffect
+    {
+        #region ITerrainFloodEffect Members
+
+        public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength)
+        {
+            double sum = 0.0;
+            double steps = 0.0;
+            double avg = 0.0;
+
+            int x, y;
+            for (x = 0; x < map.Width; x++)
+            {
+                for (y = 0; y < map.Height; y++)
+                {
+                    if (fillArea[x, y] == true)
+                    {
+                        sum += map[x, y];
+                        steps += 1.0;
+                    }
+                }
+            }
+
+            avg = sum / steps;
+
+            for (x = 0; x < map.Width; x++)
+            {
+                for (y = 0; y < map.Height; y++)
+                {
+                    if (fillArea[x, y] == true)
+                        map[x, y] = avg;
+                }
+            }
+        }
+
+        #endregion
+    }
+}
diff --git a/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/LowerArea.cs b/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/LowerArea.cs
new file mode 100644
index 0000000..1706575
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/LowerArea.cs
@@ -0,0 +1,53 @@
+/*
+* Copyright (c) Contributors, http://opensimulator.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using OpenSim.Region.Environment.Interfaces;
+
+namespace OpenSim.Region.Environment.Modules.Terrain.FloodBrushes
+{
+    public class LowerArea : ITerrainFloodEffect
+    {
+        #region ITerrainFloodEffect Members
+
+        public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength)
+        {
+            int x, y;
+            for (x = 0; x < map.Width; x++)
+            {
+                for (y = 0; y < map.Height; y++)
+                {
+                    if (fillArea[x, y] == true)
+                    {
+                        map[x, y] -= strength;
+                    }
+                }
+            }
+        }
+
+        #endregion
+    }
+}
diff --git a/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/NoiseArea.cs b/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/NoiseArea.cs
new file mode 100644
index 0000000..690ca53
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/NoiseArea.cs
@@ -0,0 +1,57 @@
+/*
+* Copyright (c) Contributors, http://opensimulator.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using OpenSim.Region.Environment.Interfaces;
+
+namespace OpenSim.Region.Environment.Modules.Terrain.FloodBrushes
+{
+    public class NoiseArea : ITerrainFloodEffect
+    {
+        #region ITerrainFloodEffect Members
+
+        public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength)
+        {
+            int x, y;
+            for (x = 0; x < map.Width; x++)
+            {
+                for (y = 0; y < map.Height; y++)
+                {
+                    if (fillArea[x, y] == true)
+                    {
+                        lock (OpenSim.Framework.Util.RandomClass)
+                        {
+                            double noise = OpenSim.Framework.Util.RandomClass.NextDouble();
+                            map[x, y] += (noise - 0.5) * strength;
+                        }
+                    }
+                }
+            }
+        }
+
+        #endregion
+    }
+}
diff --git a/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/RaiseArea.cs b/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/RaiseArea.cs
index 258b363..aad7aa4 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/RaiseArea.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/RaiseArea.cs
@@ -1,7 +1,30 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-using OpenSim.Region.Environment.Modules.Terrain;
+/*
+* Copyright (c) Contributors, http://opensimulator.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
 using OpenSim.Region.Environment.Interfaces;
 
 namespace OpenSim.Region.Environment.Modules.Terrain.FloodBrushes
diff --git a/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/SmoothArea.cs b/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/SmoothArea.cs
new file mode 100644
index 0000000..aa685e4
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/SmoothArea.cs
@@ -0,0 +1,107 @@
+/*
+* Copyright (c) Contributors, http://opensimulator.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using OpenSim.Region.Environment.Interfaces;
+
+namespace OpenSim.Region.Environment.Modules.Terrain.FloodBrushes
+{
+    public class SmoothArea : ITerrainFloodEffect
+    {
+        private double GetBilinearInterpolate(double x, double y, ITerrainChannel map)
+        {
+            int w = map.Width;
+            int h = map.Height;
+
+            if (x > w - 2.0)
+                x = w - 2.0;
+            if (y > h - 2.0)
+                y = h - 2.0;
+            if (x < 0.0)
+                x = 0.0;
+            if (y < 0.0)
+                y = 0.0;
+
+            int stepSize = 1;
+            double h00 = map[(int)x, (int)y];
+            double h10 = map[(int)x + stepSize, (int)y];
+            double h01 = map[(int)x, (int)y + stepSize];
+            double h11 = map[(int)x + stepSize, (int)y + stepSize];
+            double h1 = h00;
+            double h2 = h10;
+            double h3 = h01;
+            double h4 = h11;
+            double a00 = h1;
+            double a10 = h2 - h1;
+            double a01 = h3 - h1;
+            double a11 = h1 - h2 - h3 + h4;
+            double partialx = x - (int)x;
+            double partialz = y - (int)y;
+            double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz);
+            return hi;
+        }
+
+        #region ITerrainFloodEffect Members
+
+        public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength)
+        {
+            double area = strength;
+            double step = strength / 4.0;
+
+            double[,] manipulate = new double[map.Width, map.Height];
+            int x, y;
+            double n, l;
+            for (x = 0; x < map.Width; x++)
+            {
+                for (y = 0; y < map.Height; y++)
+                {
+                    double average = 0.0;
+                    int avgsteps = 0;
+
+                    for (n = 0.0 - area; n < area; n += step)
+                    {
+                        for (l = 0.0 - area; l < area; l += step)
+                        {
+                            avgsteps++;
+                            average += GetBilinearInterpolate(x + n, y + l, map);
+                        }
+                    }
+
+                    manipulate[x, y] = average / avgsteps;
+                }
+            }
+            for (x = 0; x < map.Width; x++)
+            {
+                for (y = 0; y < map.Height; y++)
+                {
+                    map[x, y] = manipulate[x, y];
+                }
+            }
+        }
+
+        #endregion
+    }
+}
\ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/FlattenSphere.cs b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/FlattenSphere.cs
new file mode 100644
index 0000000..d2cf1bc
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/FlattenSphere.cs
@@ -0,0 +1,125 @@
+/*
+* Copyright (c) Contributors, http://opensimulator.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using OpenSim.Region.Environment.Interfaces;
+
+namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
+{
+    public class FlattenSphere : ITerrainPaintableEffect
+    {
+        private double SphericalFactor(double x, double y, double rx, double ry, double size)
+        {
+            double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry));
+            return z;
+        }
+
+        private double GetBilinearInterpolate(double x, double y, ITerrainChannel map)
+        {
+            int w = map.Width;
+            int h = map.Height;
+
+            if (x > w - 2.0)
+                x = w - 2.0;
+            if (y > h - 2.0)
+                y = h - 2.0;
+            if (x < 0.0)
+                x = 0.0;
+            if (y < 0.0)
+                y = 0.0;
+
+            int stepSize = 1;
+            double h00 = map[(int)x, (int)y];
+            double h10 = map[(int)x + stepSize, (int)y];
+            double h01 = map[(int)x, (int)y + stepSize];
+            double h11 = map[(int)x + stepSize, (int)y + stepSize];
+            double h1 = h00;
+            double h2 = h10;
+            double h3 = h01;
+            double h4 = h11;
+            double a00 = h1;
+            double a10 = h2 - h1;
+            double a01 = h3 - h1;
+            double a11 = h1 - h2 - h3 + h4;
+            double partialx = x - (int)x;
+            double partialz = y - (int)y;
+            double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz);
+            return hi;
+        }
+
+        #region ITerrainPaintableEffect Members
+
+        public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength)
+        {
+            int x, y;
+            double[,] tweak = new double[map.Width, map.Height];
+
+            double n, l;
+            double area = strength;
+            double step = strength / 4.0;
+
+            double sum = 0.0;
+            double step2 = 0.0;
+            double avg = 0.0;
+
+            // compute delta map 
+            for (x = 0; x < map.Width; x++)
+            {
+                for (y = 0; y < map.Height; y++)
+                {
+                    double z = SphericalFactor(x, y, rx, ry, strength);
+
+                    if (z > 0) // add in non-zero amount 
+                    {
+                        sum += map[x, y] * z;
+                        step2 += z;
+                    }
+                }
+            }
+
+            avg = sum / step2;
+
+            // blend in map 
+            for (x = 0; x < map.Width; x++)
+            {
+                for (y = 0; y < map.Height; y++)
+                {
+                    double z = SphericalFactor(x, y, rx, ry, strength);
+
+                    if (z > 0) // add in non-zero amount 
+                    {
+                        if (z > 1.0)
+                            z = 1.0;
+
+                        map[x, y] = (map[x, y] * (1.0 - z)) + (avg * z);
+                    }
+                }
+            }
+        }
+
+        #endregion
+    }
+}
\ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/LowerSphere.cs b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/LowerSphere.cs
new file mode 100644
index 0000000..4a05e76
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/LowerSphere.cs
@@ -0,0 +1,65 @@
+/*
+* Copyright (c) Contributors, http://opensimulator.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System;
+using OpenSim.Region.Environment.Interfaces;
+
+namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
+{
+    public class LowerSphere : ITerrainPaintableEffect
+    {
+        #region ITerrainPaintableEffect Members
+
+        public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength)
+        {
+            int x, y;
+            for (x = 0; x < map.Width; x++)
+            {
+                // Skip everything unlikely to be affected
+                if (Math.Abs(x - rx) > strength * 1.1)
+                    continue;
+
+                for (y = 0; y < map.Height; y++)
+                {
+                    // Skip everything unlikely to be affected
+                    if (Math.Abs(y - ry) > strength * 1.1)
+                        continue;
+
+                    // Calculate a sphere and add it to the heighmap
+                    double z = strength;
+                    z *= z;
+                    z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
+
+                    if (z > 0.0)
+                        map[x, y] -= z;
+                }
+            }
+        }
+
+        #endregion
+    }
+}
diff --git a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/NoiseSphere.cs b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/NoiseSphere.cs
new file mode 100644
index 0000000..226bd3e
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/NoiseSphere.cs
@@ -0,0 +1,73 @@
+/*
+* Copyright (c) Contributors, http://opensimulator.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System;
+using OpenSim.Framework;
+using OpenSim.Region.Environment.Interfaces;
+
+namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
+{
+    public class NoiseSphere : ITerrainPaintableEffect
+    {
+        #region ITerrainPaintableEffect Members
+
+        public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength)
+        {
+            int x, y;
+            for (x = 0; x < map.Width; x++)
+            {
+                // Skip everything unlikely to be affected
+                if (Math.Abs(x - rx) > strength * 1.1)
+                    continue;
+
+                for (y = 0; y < map.Height; y++)
+                {
+                    // Skip everything unlikely to be affected
+                    if (Math.Abs(y - ry) > strength * 1.1)
+                        continue;
+
+                    // Calculate a sphere and add it to the heighmap
+                    double z = strength;
+                    z *= z;
+                    z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
+
+                    double noise;
+
+                    lock (Util.RandomClass)
+                    {
+                        noise = Util.RandomClass.NextDouble();
+                    }
+
+                    if (z > 0.0)
+                        map[x, y] += (noise - 0.5) * z;
+                }
+            }
+        }
+
+        #endregion
+    }
+}
diff --git a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/RaiseSphere.cs b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/RaiseSphere.cs
index ff7ec0b..fad5b11 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/RaiseSphere.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/RaiseSphere.cs
@@ -1,7 +1,31 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-using OpenSim.Region.Environment.Modules.Terrain;
+/*
+* Copyright (c) Contributors, http://opensimulator.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System;
 using OpenSim.Region.Environment.Interfaces;
 
 namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
diff --git a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/SmoothSphere.cs b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/SmoothSphere.cs
new file mode 100644
index 0000000..076b3cc
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/SmoothSphere.cs
@@ -0,0 +1,130 @@
+/*
+* Copyright (c) Contributors, http://opensimulator.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using OpenSim.Region.Environment.Interfaces;
+
+namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
+{
+    public class SmoothSphere : ITerrainPaintableEffect
+    {
+        private double SphericalFactor(double x, double y, double rx, double ry, double size)
+        {
+            double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry));
+            return z;
+        }
+
+        private double GetBilinearInterpolate(double x, double y, ITerrainChannel map)
+        {
+            int w = map.Width;
+            int h = map.Height;
+
+            if (x > w - 2.0)
+                x = w - 2.0;
+            if (y > h - 2.0)
+                y = h - 2.0;
+            if (x < 0.0)
+                x = 0.0;
+            if (y < 0.0)
+                y = 0.0;
+
+            int stepSize = 1;
+            double h00 = map[(int)x, (int)y];
+            double h10 = map[(int)x + stepSize, (int)y];
+            double h01 = map[(int)x, (int)y + stepSize];
+            double h11 = map[(int)x + stepSize, (int)y + stepSize];
+            double h1 = h00;
+            double h2 = h10;
+            double h3 = h01;
+            double h4 = h11;
+            double a00 = h1;
+            double a10 = h2 - h1;
+            double a01 = h3 - h1;
+            double a11 = h1 - h2 - h3 + h4;
+            double partialx = x - (int)x;
+            double partialz = y - (int)y;
+            double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz);
+            return hi;
+        }
+
+        #region ITerrainPaintableEffect Members
+
+        public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength)
+        {
+            int x, y;
+            double[,] tweak = new double[map.Width, map.Height];
+            
+            double n, l;
+            double area = strength;
+            double step = strength / 4.0;
+            
+            // compute delta map 
+            for (x = 0; x < map.Width; x++)
+            {
+                for (y = 0; y < map.Height; y++)
+                {
+                    double z = SphericalFactor(x, y, rx, ry, strength);
+                    
+                    if (z > 0) // add in non-zero amount 
+                    {
+                        double average = 0.0;
+                        int avgsteps = 0;
+                        
+                        for (n = 0.0 - area; n < area; n += step)
+                        {
+                            for (l = 0.0 - area; l < area; l += step)
+                            {
+                                avgsteps++;
+                                average += GetBilinearInterpolate(x + n, y + l, map);
+                            }
+                        }
+                        tweak[x, y] = average / avgsteps;
+                    }
+                }
+            }
+            // blend in map 
+            for (x = 0; x < map.Width; x++)
+            {
+                for (y = 0; y < map.Height; y++)
+                {
+                    double z = SphericalFactor(x, y, rx, ry, strength);
+                    
+                    if (z > 0) // add in non-zero amount 
+                    {
+                        double da = z;
+                        double a = (map[x, y] - tweak[x, y]) * da;
+                        double newz = map[x, y] - a;
+
+                        if (newz > 0.0)
+                            map[x, y] = newz;
+                    }
+                }
+            }
+        }
+
+        #endregion
+    }
+}
\ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs b/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs
index 22b5fd9..1542230 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs
@@ -26,16 +26,13 @@
 * 
 */
 
-using Nini.Config;
 using System;
-using System.Collections;
 using System.Collections.Generic;
+using libsecondlife;
+using Nini.Config;
 using OpenSim.Framework;
-using OpenSim.Framework.Console;
-using OpenSim.Region.Environment.Modules;
 using OpenSim.Region.Environment.Interfaces;
 using OpenSim.Region.Environment.Scenes;
-using libsecondlife;
 
 namespace OpenSim.Region.Environment.Modules.Terrain
 {
@@ -57,7 +54,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain
     public interface ITerrainLoader 
     {
         ITerrainChannel LoadFile(string filename);
-        void SaveFile(string filename);
+        void SaveFile(string filename, ITerrainChannel map);
     }
 
     /// <summary>
@@ -85,6 +82,19 @@ namespace OpenSim.Region.Environment.Modules.Terrain
             return copy;
         }
 
+        public float[] GetFloatsSerialised()
+        {
+            float[] heights = new float[Width * Height];
+            int i;
+
+            for (i = 0; i < Width * Height; i++)
+            {
+                heights[i] = (float)map[i % Width, i / Width];
+            }
+
+            return heights;
+        }
+
         public double this[int x, int y]
         {
             get
@@ -102,6 +112,11 @@ namespace OpenSim.Region.Environment.Modules.Terrain
             map = new double[Constants.RegionSize, Constants.RegionSize];
         }
 
+        public TerrainChannel(double[,] import)
+        {
+            map = import;
+        }
+
         public TerrainChannel(bool createMap)
         {
             if (createMap)
@@ -139,13 +154,27 @@ namespace OpenSim.Region.Environment.Modules.Terrain
 
         private void InstallDefaultEffects()
         {
-            m_painteffects[StandardTerrainEffects.Raise] = new PaintBrushes.RaiseSphere();
-            m_floodeffects[StandardTerrainEffects.Raise] = new FloodBrushes.RaiseArea();
-
-            // Float[256,256] array format (RAW32)
+            // Draggable Paint Brush Effects
+            m_painteffects[StandardTerrainEffects.Raise]    = new PaintBrushes.RaiseSphere();
+            m_painteffects[StandardTerrainEffects.Lower]    = new PaintBrushes.LowerSphere();
+            m_painteffects[StandardTerrainEffects.Smooth]   = new PaintBrushes.SmoothSphere();
+            m_painteffects[StandardTerrainEffects.Noise]    = new PaintBrushes.NoiseSphere();
+            m_painteffects[StandardTerrainEffects.Flatten]  = new PaintBrushes.FlattenSphere();
+
+            // Area of effect selection effects
+            m_floodeffects[StandardTerrainEffects.Raise]    = new FloodBrushes.RaiseArea();
+            m_floodeffects[StandardTerrainEffects.Lower]    = new FloodBrushes.LowerArea();
+            m_floodeffects[StandardTerrainEffects.Smooth]   = new FloodBrushes.SmoothArea();
+            m_floodeffects[StandardTerrainEffects.Noise]    = new FloodBrushes.NoiseArea();
+            m_floodeffects[StandardTerrainEffects.Flatten]  = new FloodBrushes.FlattenArea();
+
+            // Filesystem load/save loaders
             m_loaders[".r32"] = new FileLoaders.RAW32();
             m_loaders[".f32"] = m_loaders[".r32"];
             m_loaders[".ter"] = new FileLoaders.Terragen();
+            m_loaders[".raw"] = new FileLoaders.LLRAW();
+            m_loaders[".jpg"] = new FileLoaders.JPEG();
+            m_loaders[".jpeg"] = m_loaders[".jpg"];
         }
 
         public void LoadFromFile(string filename)
@@ -162,14 +191,21 @@ namespace OpenSim.Region.Environment.Modules.Terrain
 
         public void SaveToFile(string filename)
         {
-            foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders)
+            try
             {
-                if (filename.EndsWith(loader.Key))
+                foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders)
                 {
-                    loader.Value.SaveFile(filename);
-                    return;
+                    if (filename.EndsWith(loader.Key))
+                    {
+                        loader.Value.SaveFile(filename, m_channel);
+                        return;
+                    }
                 }
             }
+            catch (NotImplementedException)
+            {
+                m_log.Error("Unable to save to " + filename + ", saving of this file format has not been implemented.");
+            }
         }
 
         public void Initialise(Scene scene, IConfigSource config)
@@ -177,7 +213,20 @@ namespace OpenSim.Region.Environment.Modules.Terrain
             m_scene = scene;
             m_gConfig = config;
 
-            m_channel = new TerrainChannel();
+            // Install terrain module in the simulator
+            if (m_scene.Heightmap == null)
+            {
+                lock (m_scene)
+                {
+                    m_channel = new TerrainChannel();
+                    m_scene.Heightmap = m_channel;
+                }
+            }
+            else
+            {
+                m_channel = m_scene.Heightmap;
+            }
+
             m_scene.EventManager.OnNewClient += EventManager_OnNewClient;
         }
 
diff --git a/OpenSim/Region/Environment/Modules/TextureDownloadModule.cs b/OpenSim/Region/Environment/Modules/TextureDownloadModule.cs
index 2b2ac42..a015b5d 100644
--- a/OpenSim/Region/Environment/Modules/TextureDownloadModule.cs
+++ b/OpenSim/Region/Environment/Modules/TextureDownloadModule.cs
@@ -29,10 +29,8 @@ using System;
 using System.Collections.Generic;
 using System.Threading;
 using libsecondlife;
-using libsecondlife.Packets;
 using Nini.Config;
 using OpenSim.Framework;
-using OpenSim.Framework.Console;
 using OpenSim.Region.Environment.Interfaces;
 using OpenSim.Region.Environment.Scenes;
 
diff --git a/OpenSim/Region/Environment/Modules/TextureNotFoundSender.cs b/OpenSim/Region/Environment/Modules/TextureNotFoundSender.cs
index f85e900..7d39c0d 100644
--- a/OpenSim/Region/Environment/Modules/TextureNotFoundSender.cs
+++ b/OpenSim/Region/Environment/Modules/TextureNotFoundSender.cs
@@ -7,11 +7,8 @@
  * To change this template use Tools | Options | Coding | Edit Standard Headers.
  */
 
-using System;
-
 using libsecondlife;
 using libsecondlife.Packets;
-
 using OpenSim.Framework;
 using OpenSim.Region.Environment.Interfaces;
 
diff --git a/OpenSim/Region/Environment/Modules/VoiceChat/VoiceChatServer.cs b/OpenSim/Region/Environment/Modules/VoiceChat/VoiceChatServer.cs
index 5ec0ca8..3ace5fc 100644
--- a/OpenSim/Region/Environment/Modules/VoiceChat/VoiceChatServer.cs
+++ b/OpenSim/Region/Environment/Modules/VoiceChat/VoiceChatServer.cs
@@ -261,7 +261,7 @@ namespace OpenSim.Region.Environment.Modules.VoiceChat
                             }
                         }
                     }
-                    catch(ObjectDisposedException e)
+                    catch(ObjectDisposedException)
                     {
                         m_log.Warn("[VOICECHAT]: Connection has been already closed");
                     }
diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs
index a20e466..845de22 100644
--- a/OpenSim/Region/Environment/Scenes/Scene.cs
+++ b/OpenSim/Region/Environment/Scenes/Scene.cs
@@ -31,14 +31,12 @@ using System.Drawing;
 using System.Drawing.Imaging;
 using System.Threading;
 using System.Timers;
-using Axiom.Math;
 using libsecondlife;
 using libsecondlife.Packets;
 using OpenJPEGNet;
 using OpenSim.Framework;
 using OpenSim.Framework.Communications;
 using OpenSim.Framework.Communications.Cache;
-using OpenSim.Framework.Console;
 using OpenSim.Framework.Servers;
 using OpenSim.Region.Environment.Interfaces;
 using OpenSim.Region.Environment.LandManagement;
@@ -1002,6 +1000,8 @@ namespace OpenSim.Region.Environment.Scenes
                 }
                 else
                 {
+                    // TODO: Install 'GetDefaultTerrainProvider' method here?
+                    Heightmap = new Modules.Terrain.TerrainChannel(map);
                     Terrain.SetHeights2D(map);
                 }
 
diff --git a/OpenSim/Region/Environment/Scenes/SceneBase.cs b/OpenSim/Region/Environment/Scenes/SceneBase.cs
index 3f7edfb..2a2dea1 100644
--- a/OpenSim/Region/Environment/Scenes/SceneBase.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneBase.cs
@@ -112,7 +112,16 @@ namespace OpenSim.Region.Environment.Scenes
         /// <param name="RemoteClient">Client to send to</param>
         public virtual void SendLayerData(IClientAPI RemoteClient)
         {
-            RemoteClient.SendLayerData(Terrain.GetHeights1D());
+            bool usingTerrainModule = false;
+
+            if (usingTerrainModule)
+            {
+                RemoteClient.SendLayerData(Heightmap.GetFloatsSerialised());
+            }
+            else
+            {
+                RemoteClient.SendLayerData(Terrain.GetHeights1D());
+            }
         }
 
         #endregion
-- 
cgit v1.1