Exemplo n.º 1
0
        public MapBackground(ZoneConfiguration zoneConfiguration)
        {
            this.zoneConfiguration        = zoneConfiguration;
            this.textureZoneId            = zoneConfiguration.ZoneId;
            this.textureZoneDataDirectory = zoneConfiguration.ZoneDirectory;

            string flipX      = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, "terrain", "flip_x");
            string flipY      = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, "terrain", "flip_y");
            string useTexture = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, "terrain", "use_texture");

            if (!string.IsNullOrEmpty(flipX))
            {
                this.flipX = (Convert.ToInt32(flipX) != 0) ? true : false;
            }
            if (!string.IsNullOrEmpty(flipY))
            {
                this.flipY = (Convert.ToInt32(flipY) != 0) ? true : false;
            }

            if (!string.IsNullOrEmpty(useTexture))
            {
                int useTextureInt = Convert.ToInt32(useTexture);
                useTexture                    = (useTextureInt < 10) ? "00" + useTextureInt : (useTextureInt < 100) ? "0" + useTextureInt : useTextureInt.ToString();
                this.textureZoneId            = useTexture;
                this.textureZoneDataDirectory = zoneConfiguration.GetZoneDirectory(useTexture);
            }
        }
Exemplo n.º 2
0
        public MapFixtures(ZoneConfiguration zoneConfiguration, List <WaterConfiguration> rivers)
        {
            this.zoneConfiguration = zoneConfiguration;
            this.rivers            = rivers;

            // Load Renderer Configurations

            // Initialize the fixtures loader, loads CSV files and polygons
            FixturesLoader.Initialize(zoneConfiguration);

            // Prepare models
            m_fixtures = FixturesLoader.GetDrawableFixtures();
        }
Exemplo n.º 3
0
        public MapFixtures(ZoneConfiguration zoneConfiguration, List<WaterConfiguration> rivers)
        {
            this.zoneConfiguration = zoneConfiguration;
            this.rivers = rivers;

            // Load Renderer Configurations

            // Initialize the fixtures loader, loads CSV files and polygons
            FixturesLoader.Initialize(zoneConfiguration);

            // Prepare models
            m_fixtures = FixturesLoader.GetDrawableFixtures();
        }
Exemplo n.º 4
0
        public MapHeightmap(ZoneConfiguration zoneConfiguration)
        {
            MainForm.Log("Preloading zone heightmap ...", MainForm.LogLevel.notice);

            this.zoneConfiguration = zoneConfiguration;
            this.m_terrainfactor = Convert.ToInt32(DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, "terrain", "scalefactor"));
            this.m_offsetfactor = Convert.ToInt32(DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, "terrain", "offsetfactor"));
            this.m_heightmapFile = new FileInfo(string.Format("{0}\\data\\heightmaps\\zone{1}_heightmap.png", System.Windows.Forms.Application.StartupPath, zoneConfiguration.ZoneId));

            if (!System.IO.Directory.Exists(m_heightmapFile.DirectoryName))
            {
                Directory.CreateDirectory(m_heightmapFile.DirectoryName);
            }

            // Generate it, needed for lightmap, river and fixtures
            GenerateHeightmap();
        }
Exemplo n.º 5
0
        public MapHeightmap(ZoneConfiguration zoneConfiguration)
        {
            MainForm.Log("Preloading zone heightmap ...", MainForm.LogLevel.notice);

            this.zoneConfiguration = zoneConfiguration;
            this.m_terrainfactor   = Convert.ToInt32(DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, "terrain", "scalefactor"));
            this.m_offsetfactor    = Convert.ToInt32(DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, "terrain", "offsetfactor"));
            this.m_heightmapFile   = new FileInfo(string.Format("{0}\\data\\heightmaps\\zone{1}_heightmap.png", System.Windows.Forms.Application.StartupPath, zoneConfiguration.ZoneId));

            if (!System.IO.Directory.Exists(m_heightmapFile.DirectoryName))
            {
                Directory.CreateDirectory(m_heightmapFile.DirectoryName);
            }

            // Generate it, needed for lightmap, river and fixtures
            GenerateHeightmap();
        }
Exemplo n.º 6
0
        public MapBackground(ZoneConfiguration zoneConfiguration)
        {
            this.zoneConfiguration = zoneConfiguration;
            this.textureZoneId = zoneConfiguration.ZoneId;
            this.textureZoneDataDirectory = zoneConfiguration.ZoneDirectory;

            string flipX = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, "terrain", "flip_x");
            string flipY = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, "terrain", "flip_y");
            string useTexture = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, "terrain", "use_texture");

            if (!string.IsNullOrEmpty(flipX)) this.flipX = (Convert.ToInt32(flipX) != 0) ? true : false;
            if (!string.IsNullOrEmpty(flipY)) this.flipY = (Convert.ToInt32(flipY) != 0) ? true : false;

            if (!string.IsNullOrEmpty(useTexture))
            {
                int useTextureInt = Convert.ToInt32(useTexture);
                useTexture = (useTextureInt < 10) ? "00" + useTextureInt : (useTextureInt < 100) ? "0" + useTextureInt : useTextureInt.ToString();
                this.textureZoneId = useTexture;
                this.textureZoneDataDirectory = zoneConfiguration.GetZoneDirectory(useTexture);
            }
        }
Exemplo n.º 7
0
        public MapWater(ZoneConfiguration zoneConfiguration)
        {
            MainForm.ProgressStartMarquee("Loading water configurations ...");
            this.zoneConfiguration = zoneConfiguration;

            bool riversFound = true;
            int  riverIndex  = 0;

            while (riversFound)
            {
                string riverIndexString = "river" + ((riverIndex < 10) ? "0" + riverIndex : riverIndex.ToString());

                // Check if there is a section
                string riverCheck = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "name");
                if (string.IsNullOrEmpty(riverCheck))
                {
                    riversFound = false;
                    continue;
                }

                WaterConfiguration waterConf = new WaterConfiguration(riverCheck);
                waterConf.Texture      = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "texture");
                waterConf.Multitexture = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "multitexture");
                waterConf.Flow         = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "flow");
                waterConf.Height       = Convert.ToInt32(DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "height"));
                waterConf.Bankpoints   = Convert.ToInt32(DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "bankpoints"));
                waterConf.Extend_PosX  = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "Extend_PosX");
                waterConf.Extend_PosY  = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "Extend_PosY");
                waterConf.Extend_NegX  = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "Extend_NegX");
                waterConf.Extend_NegY  = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "Extend_NegY");
                waterConf.Tesselation  = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "Tesselation");
                waterConf.Type         = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "type");

                // Adjust some river heights
                if (zoneConfiguration.ZoneId == "168" || zoneConfiguration.ZoneId == "171" || zoneConfiguration.ZoneId == "178")
                {
                    waterConf.Height += 30;
                }

                // Ignore some definitions
                if (zoneConfiguration.ZoneId == "163" && riverIndexString == "river14")
                {
                    riverIndex++;
                    continue;
                }

                string color     = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "color");
                string baseColor = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "base_color");
                if (color.Length >= 6)
                {
                    waterConf.Color = ColorTranslator.FromWin32(Convert.ToInt32((string.IsNullOrEmpty(baseColor)) ? color : baseColor));
                }

                for (int i = 0; i < waterConf.Bankpoints; i++)
                {
                    string coordinatesIndexString = (i < 10) ? "0" + i : i.ToString();
                    string left  = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "left" + coordinatesIndexString);
                    string right = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "right" + coordinatesIndexString);

                    if (string.IsNullOrEmpty(left) || string.IsNullOrEmpty(right))
                    {
                        continue;
                    }

                    string[] leftArr  = left.Split(',');
                    string[] rightArr = right.Split(',');

                    PointD leftPoint = new PointD((Convert.ToInt32(leftArr[0]) >= 0) ? Convert.ToInt32(leftArr[0]) : 0, (Convert.ToInt32(leftArr[1]) >= 0) ? Convert.ToInt32(leftArr[1]) : 0);
                    waterConf.LeftCoordinates.Add(leftPoint);

                    PointD rightPoint = new PointD((Convert.ToInt32(rightArr[0]) >= 0) ? Convert.ToInt32(rightArr[0]) : 0, (Convert.ToInt32(rightArr[1]) >= 0) ? Convert.ToInt32(rightArr[1]) : 0);
                    waterConf.RightCoordinates.Add(rightPoint);
                }

                this.m_waterAreas.Add(waterConf);

                riverIndex++;
            }

            MainForm.ProgressReset();
        }
Exemplo n.º 8
0
 public MapLightmap(ZoneConfiguration zoneConfiguration)
 {
     this.zoneConfiguration = zoneConfiguration;
     this.RecalculateLights();
 }
Exemplo n.º 9
0
 public MapLightmap(ZoneConfiguration zoneConfiguration)
 {
     this.zoneConfiguration = zoneConfiguration;
     this.RecalculateLights();
 }
Exemplo n.º 10
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="zoneConfiguration"></param>
 public MapBounds(ZoneConfiguration zoneConfiguration)
 {
     this.zoneConfiguration = zoneConfiguration;
     ParseBounds();
 }
Exemplo n.º 11
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="zoneConfiguration"></param>
 public MapBounds(ZoneConfiguration zoneConfiguration)
 {
     this.zoneConfiguration = zoneConfiguration;
     ParseBounds();
 }
Exemplo n.º 12
0
        public MapWater(ZoneConfiguration zoneConfiguration)
        {
            MainForm.ProgressStartMarquee("Loading water configurations ...");
            this.zoneConfiguration = zoneConfiguration;

            bool riversFound = true;
            int riverIndex = 0;

            while (riversFound)
            {
                string riverIndexString = "river" + ((riverIndex < 10) ? "0" + riverIndex : riverIndex.ToString());

                // Check if there is a section
                string riverCheck = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "name");
                if (string.IsNullOrEmpty(riverCheck))
                {
                    riversFound = false;
                    continue;
                }

                WaterConfiguration waterConf = new WaterConfiguration(riverCheck);
                waterConf.Texture = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "texture");
                waterConf.Multitexture = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "multitexture");
                waterConf.Flow = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "flow");
                waterConf.Height = Convert.ToInt32(DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "height"));
                waterConf.Bankpoints = Convert.ToInt32(DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "bankpoints"));
                waterConf.Extend_PosX = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "Extend_PosX");
                waterConf.Extend_PosY = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "Extend_PosY");
                waterConf.Extend_NegX = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "Extend_NegX");
                waterConf.Extend_NegY = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "Extend_NegY");
                waterConf.Tesselation = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "Tesselation");
                waterConf.Type = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "type");

                // Adjust some river heights heights
                if (zoneConfiguration.ZoneId == "168" || zoneConfiguration.ZoneId == "171" || zoneConfiguration.ZoneId == "178")
                {
                    waterConf.Height += 30;
                }

                string color = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "color");
                string baseColor = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "base_color");
                if (color.Length >= 6)
                {
                    waterConf.Color = ColorTranslator.FromWin32(Convert.ToInt32((string.IsNullOrEmpty(baseColor)) ? color : baseColor));
                }

                for (int i = 0; i < waterConf.Bankpoints; i++)
                {
                    string coordinatesIndexString = (i < 10) ? "0" + i : i.ToString();
                    string left = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "left" + coordinatesIndexString);
                    string right = DataWrapper.GetDatFileProperty(zoneConfiguration.SectorDatStreamReader, riverIndexString, "right" + coordinatesIndexString);

                    if (string.IsNullOrEmpty(left) || string.IsNullOrEmpty(right))
                    {
                        continue;
                    }

                    string[] leftArr = left.Split(',');
                    string[] rightArr = right.Split(',');

                    Coordinate leftPoint = new Coordinate(Convert.ToInt32(leftArr[0]), Convert.ToInt32(leftArr[1]));
                    if (leftPoint.X < 0) leftPoint.X = 0;
                    if (leftPoint.Y < 0) leftPoint.Y = 0;

                    waterConf.LeftCoordinates.Add(leftPoint);

                    Coordinate rightPoint = new Coordinate(Convert.ToInt32(rightArr[0]), Convert.ToInt32(rightArr[1]));
                    if (rightPoint.X < 0) rightPoint.X = 0;
                    if (rightPoint.Y < 0) rightPoint.Y = 0;

                    waterConf.RightCoordinates.Add(rightPoint);
                }

                this.m_waterAreas.Add(waterConf);

                riverIndex++;
            }

            MainForm.ProgressReset();
        }
Exemplo n.º 13
0
        /// <summary>
        /// Render selected Zones as Background Worker
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void drawMapBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                ZoneSelection zone = (ZoneSelection)e.Argument;

                // Start BackgroundWorker
                Log(string.Format("Start creating map for zone {0} ...", zone.Id), LogLevel.notice);

                // The filename
                string targetFilePath = string.Format("{0}\\maps", Application.StartupPath);

                string pattern = filePatternTextBox.Text;
                if (string.IsNullOrEmpty(pattern))
                {
                    pattern = "zone{id}_{size}";
                }

                // Replace some values
                pattern = pattern.Replace("{id}", zone.Id);
                pattern = pattern.Replace("{name}", zone.Name);
                pattern = pattern.Replace("{expansion}", zone.Expansion);
                pattern = pattern.Replace("{type}", zone.Type);
                pattern = pattern.Replace("{size}", TargetMapSize.ToString());
                pattern = Tools.MakeValidFileName(pattern);

                // File extension
                string fileExtension         = "jpg";
                string selectedFileExtension = "JPEG";
                this.Invoke((MethodInvoker) delegate()
                {
                    selectedFileExtension = fileTypeComboBox.Text;
                });
                switch (selectedFileExtension)
                {
                case "PNG":
                    fileExtension = "png";
                    break;

                case "JPEG":
                default:
                    fileExtension = "jpg";
                    break;
                }

                // The Target File
                FileInfo mapFile = new FileInfo(string.Format("{0}\\maps\\{1}.{2}", Application.StartupPath, pattern, fileExtension));
                if (!Directory.Exists(mapFile.DirectoryName))
                {
                    Directory.CreateDirectory(mapFile.DirectoryName);
                }

                bool     lightmap         = generateLightmapCheckBox.Checked;
                double   lightmapZScale   = Convert.ToDouble(heightmapZScaleTextBox.Value);
                double   lightmapLightMin = Convert.ToDouble(heightmapLightMinTextBox.Value);
                double   lightmapLightMax = Convert.ToDouble(heightmapLightMaxTextBox.Value);
                double[] lightmapZVector  = new double[] { Convert.ToDouble(heightmapZVector1TextBox.Value), Convert.ToDouble(heightmapZVector2TextBox.Value), Convert.ToDouble(heightmapZVector3TextBox.Value) };

                bool  rivers = generateRiversCheckBox.Checked;
                bool  riversUseDefaultColor = riversUseDefaultColorCheckBox.Checked;
                Color riversColor           = Properties.Settings.Default.mapRiverColor;
                int   riverOpacity          = Convert.ToInt32(mapRiversOpacityTextBox.Value);

                bool  bounds               = generateBoundsCheckBox.Checked;
                Color boundsColor          = Properties.Settings.Default.mapBoundsColor;
                int   boundsOpacity        = Convert.ToInt32(mapBoundsOpacityTextBox.Text);
                bool  excludeBoundsFromMap = excludeBoundsFromMapCheckbox.Checked;

                bool fixtures = drawFixturesCheckBox.Checked;
                bool trees    = drawTreesCheckBox.Checked;

                // Generate the map
                using (ZoneConfiguration conf = new ZoneConfiguration(zone.Id, TargetMapSize))
                {
                    // Create Background
                    MapBackground background = new MapBackground(conf);

                    MainForm.Log("Rendering background ...", LogLevel.notice);
                    using (MagickImage map = background.Draw())
                    {
                        if (map != null)
                        {
                            MainForm.Log("Finished background rendering!", LogLevel.success);

                            // Create lightmap
                            if (lightmap)
                            {
                                MainForm.Log("Rendering lightmap ...", LogLevel.notice);
                                MapLightmap lightmapGenerator = new MapLightmap(conf);
                                lightmapGenerator.ZScale   = lightmapZScale;
                                lightmapGenerator.LightMin = lightmapLightMin;
                                lightmapGenerator.LightMax = lightmapLightMax;
                                lightmapGenerator.ZVector  = lightmapZVector;
                                lightmapGenerator.RecalculateLights();
                                lightmapGenerator.Draw(map);
                                MainForm.Log("Finished lightmap rendering!", LogLevel.success);
                            }

                            // We need this for fixtures
                            MainForm.Log("Loading water configurations ...", LogLevel.notice);
                            MapWater river = new MapWater(conf);
                            MainForm.Log("Finished loading water configurations!", LogLevel.success);

                            MapFixtures fixturesGenerator = null;
                            if (fixtures || trees)
                            {
                                MainForm.Log("Loading fixtures ...", LogLevel.notice);
                                fixturesGenerator = new MapFixtures(conf, river.WaterAreas);
                                fixturesGenerator.DrawFixtures      = drawFixturesCheckBox.Checked;
                                fixturesGenerator.DrawTrees         = drawTreesCheckBox.Checked;
                                fixturesGenerator.DrawTreesAsImages = treesAsImages.Checked;
                                fixturesGenerator.TreeTransparency  = Convert.ToInt32(mapTreeTransparencyTextBox.Value);
                                fixturesGenerator.Start();
                                MainForm.Log("Finished loading fixtures!", LogLevel.success);
                            }

                            // Draw Fixtures below water
                            if (fixtures || trees)
                            {
                                MainForm.Log("Rendering fixtures below water level ...", LogLevel.notice);
                                fixturesGenerator.Draw(map, true);
                                MainForm.Log("Finished rendering fixtures below water level!", LogLevel.success);
                            }

                            // Create Rivers
                            if (rivers)
                            {
                                MainForm.Log("Rendering water ...", LogLevel.notice);
                                river.WaterColor        = riversColor;
                                river.WaterTransparency = riverOpacity;
                                river.UseClientColors   = riversUseDefaultColor;
                                river.Draw(map);
                                MainForm.Log("Finished water rendering!", LogLevel.success);
                            }

                            // Draw Fixtures above water
                            if (fixtures || trees)
                            {
                                MainForm.Log("Rendering fixtures above water level ...", LogLevel.notice);
                                fixturesGenerator.Draw(map, false);
                                MainForm.Log("Finished rendering fixtures above water level!", LogLevel.success);
                            }

                            if (fixturesGenerator != null)
                            {
                                fixturesGenerator.Dispose();
                            }

                            // Create bounds
                            if (bounds)
                            {
                                MainForm.Log("Adding zone bounds ...", LogLevel.notice);
                                MapBounds mapBounds = new MapBounds(conf);
                                mapBounds.BoundsColor    = boundsColor;
                                mapBounds.Transparency   = boundsOpacity;
                                mapBounds.ExcludeFromMap = excludeBoundsFromMap;
                                mapBounds.Draw(map);
                                MainForm.Log("Finished zone bunds!", LogLevel.success);
                            }

                            MainForm.Log(string.Format("Writing map image {0} ...", mapFile.Name));
                            ProgressStartMarquee("Writing map image ...");
                            map.Quality = Convert.ToInt32(mapQualityTextBox.Value);
                            map.Write(mapFile.FullName);
                        }
                    }
                }


                if (mapFile.Exists)
                {
                    LoadImage(mapFile.FullName);
                    ProgressReset();
                }
                else
                {
                    Log("Errors during progress!", LogLevel.error);
                }
            }
            catch (Exception ex)
            {
                MainForm.Log("Unhandled Exception thrown!", LogLevel.error);
                MainForm.Log(ex.Message, LogLevel.error);
                MainForm.Log(ex.StackTrace, LogLevel.error);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Render selected Zones as Background Worker
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void drawMapBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                ZoneSelection zone = (ZoneSelection)e.Argument;

                // Start BackgroundWorker
                Log(string.Format("Start creating map for zone {0} ...", zone.Id), LogLevel.notice);

                // The filename
                string targetFilePath = string.Format("{0}\\maps", Application.StartupPath);

                string pattern = filePatternTextBox.Text;
                if (string.IsNullOrEmpty(pattern)) pattern = "zone{id}_{size}";

                // Replace some values
                pattern = pattern.Replace("{id}", zone.Id);
                pattern = pattern.Replace("{name}", zone.Name);
                pattern = pattern.Replace("{expansion}", zone.Expansion);
                pattern = pattern.Replace("{type}", zone.Type);
                pattern = pattern.Replace("{size}", TargetMapSize.ToString());
                pattern = Tools.MakeValidFileName(pattern);

                // File extension
                string fileExtension = "jpg";
                string selectedFileExtension = "JPEG";
                this.Invoke((MethodInvoker)delegate()
                {
                    selectedFileExtension = fileTypeComboBox.Text;
                });
                switch (selectedFileExtension)
                {
                    case "PNG":
                        fileExtension = "png";
                        break;
                    case "JPEG":
                    default:
                        fileExtension = "jpg";
                        break;
                }

                // The Target File
                FileInfo mapFile = new FileInfo(string.Format("{0}\\maps\\{1}.{2}", Application.StartupPath, pattern, fileExtension));
                if (!Directory.Exists(mapFile.DirectoryName))
                {
                    Directory.CreateDirectory(mapFile.DirectoryName);
                }

                bool lightmap = generateLightmapCheckBox.Checked;
                double lightmapZScale = Convert.ToDouble(heightmapZScaleTextBox.Value);
                double lightmapLightMin = Convert.ToDouble(heightmapLightMinTextBox.Value);
                double lightmapLightMax = Convert.ToDouble(heightmapLightMaxTextBox.Value);
                double[] lightmapZVector = new double[] { Convert.ToDouble(heightmapZVector1TextBox.Value), Convert.ToDouble(heightmapZVector2TextBox.Value), Convert.ToDouble(heightmapZVector3TextBox.Value) };

                bool rivers = generateRiversCheckBox.Checked;
                bool riversUseDefaultColor = riversUseDefaultColorCheckBox.Checked;
                Color riversColor = Properties.Settings.Default.mapRiverColor;
                int riverOpacity = Convert.ToInt32(mapRiversOpacityTextBox.Value);

                bool bounds = generateBoundsCheckBox.Checked;
                Color boundsColor = Properties.Settings.Default.mapBoundsColor;
                int boundsOpacity = Convert.ToInt32(mapBoundsOpacityTextBox.Text);
                bool excludeBoundsFromMap = excludeBoundsFromMapCheckbox.Checked;

                bool fixtures = drawFixturesCheckBox.Checked;
                bool trees = drawTreesCheckBox.Checked;

                // Generate the map
                using (ZoneConfiguration conf = new ZoneConfiguration(zone.Id, TargetMapSize))
                {
                    // Create Background
                    MapBackground background = new MapBackground(conf);

                    MainForm.Log("Rendering background ...", LogLevel.notice);
                    using (MagickImage map = background.Draw())
                    {
                        if (map != null)
                        {
                            MainForm.Log("Finished background rendering!", LogLevel.success);

                            // Create lightmap
                            if (lightmap)
                            {
                                MainForm.Log("Rendering lightmap ...", LogLevel.notice);
                                MapLightmap lightmapGenerator = new MapLightmap(conf);
                                lightmapGenerator.ZScale = lightmapZScale;
                                lightmapGenerator.LightMin = lightmapLightMin;
                                lightmapGenerator.LightMax = lightmapLightMax;
                                lightmapGenerator.ZVector = lightmapZVector;
                                lightmapGenerator.RecalculateLights();
                                lightmapGenerator.Draw(map);
                                MainForm.Log("Finished lightmap rendering!", LogLevel.success);
                            }

                            // We need this for fixtures
                            MainForm.Log("Loading water configurations ...", LogLevel.notice);
                            MapWater river = new MapWater(conf);
                            MainForm.Log("Finished loading water configurations!", LogLevel.success);

                            MapFixtures fixturesGenerator = null;
                            if (fixtures || trees)
                            {
                                MainForm.Log("Loading fixtures ...", LogLevel.notice);
                                fixturesGenerator = new MapFixtures(conf, river.WaterAreas);
                                fixturesGenerator.DrawFixtures = drawFixturesCheckBox.Checked;
                                fixturesGenerator.DrawTrees = drawTreesCheckBox.Checked;
                                fixturesGenerator.DrawTreesAsImages = treesAsImages.Checked;
                                fixturesGenerator.TreeTransparency = Convert.ToInt32(mapTreeTransparencyTextBox.Value);
                                fixturesGenerator.Start();
                                MainForm.Log("Finished loading fixtures!", LogLevel.success);
                            }

                            // Draw Fixtures below water
                            if (fixtures || trees)
                            {
                                MainForm.Log("Rendering fixtures below water level ...", LogLevel.notice);
                                fixturesGenerator.Draw(map, true);
                                MainForm.Log("Finished rendering fixtures below water level!", LogLevel.success);
                            }

                            // Create Rivers
                            if (rivers)
                            {
                                MainForm.Log("Rendering water ...", LogLevel.notice);
                                river.WaterColor = riversColor;
                                river.WaterTransparency = riverOpacity;
                                river.UseClientColors = riversUseDefaultColor;
                                river.Draw(map);
                                MainForm.Log("Finished water rendering!", LogLevel.success);
                            }

                            // Draw Fixtures above water
                            if (fixtures || trees)
                            {
                                MainForm.Log("Rendering fixtures above water level ...", LogLevel.notice);
                                fixturesGenerator.Draw(map, false);
                                MainForm.Log("Finished rendering fixtures above water level!", LogLevel.success);
                            }

                            if (fixturesGenerator != null)
                            {
                                fixturesGenerator.Dispose();
                            }

                            // Create bounds
                            if (bounds)
                            {
                                MainForm.Log("Adding zone bounds ...", LogLevel.notice);
                                MapBounds mapBounds = new MapBounds(conf);
                                mapBounds.BoundsColor = boundsColor;
                                mapBounds.Transparency = boundsOpacity;
                                mapBounds.ExcludeFromMap = excludeBoundsFromMap;
                                mapBounds.Draw(map);
                                MainForm.Log("Finished zone bunds!", LogLevel.success);
                            }

                            MainForm.Log(string.Format("Writing map image {0} ...", mapFile.Name));
                            ProgressStartMarquee("Writing map image ...");
                            map.Quality = Convert.ToInt32(mapQualityTextBox.Value);
                            map.Write(mapFile.FullName);
                        }
                    }
                }

                if (mapFile.Exists)
                {
                    LoadImage(mapFile.FullName);
                    ProgressReset();
                }
                else
                {
                    Log("Errors during progress!", LogLevel.error);
                }
            }
            catch (Exception ex)
            {
                MainForm.Log("Unhandled Exception thrown!", LogLevel.error);
                MainForm.Log(ex.Message, LogLevel.error);
                MainForm.Log(ex.StackTrace, LogLevel.error);
            }
        }