private void DebugRiver(int index, WaterConfiguration river, List <PointD> riverCoordinates) { string debugFilename = string.Format("{0}\\debug\\rivers\\{1}_{2}_{3}.jpg", System.Windows.Forms.Application.StartupPath, zoneConfiguration.ZoneId, index, river.Name); if (index == 0) { DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(debugFilename)); if (di.Exists) { di.EnumerateFiles().ToList().ForEach(f => f.Delete()); } else { di.Create(); } } using (MagickImage debugRiver = new MagickImage(MagickColors.Transparent, zoneConfiguration.TargetMapSize, zoneConfiguration.TargetMapSize)) { debugRiver.BackgroundColor = Color.White; debugRiver.Settings.FillColor = new MagickColor(0, 0, ushort.MaxValue, 256 * 128); double resizeFactor = zoneConfiguration.TargetMapSize / zoneConfiguration.Heightmap.Heightmap.Width; DrawablePolygon poly = new DrawablePolygon(riverCoordinates); debugRiver.Draw(poly); List <PointD> orginalCoords = river.GetCoordinates(); for (int i = 0; i < riverCoordinates.Count(); i++) { double x, y; if (riverCoordinates[i].X > zoneConfiguration.TargetMapSize / 2) { x = riverCoordinates[i].X - 15; } else { x = riverCoordinates[i].X + 1; } if (riverCoordinates[i].Y < zoneConfiguration.TargetMapSize / 2) { y = riverCoordinates[i].Y + 15; } else { y = riverCoordinates[i].Y - 1; } debugRiver.Settings.FontPointsize = 14.0; debugRiver.Settings.FillColor = Color.Black; DrawableText text = new DrawableText(x, y, string.Format("{0} ({1}/{2})", i, orginalCoords[i].X, orginalCoords[i].Y)); debugRiver.Draw(text); } debugRiver.Quality = 100; debugRiver.Write(debugFilename); } }
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(); }
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(); }
private void DebugRiver(int index, WaterConfiguration river, List<Coordinate> riverCoordinates) { string debugFilename = string.Format("{0}\\debug\\rivers\\{1}_{2}_{3}.jpg", System.Windows.Forms.Application.StartupPath, zoneConfiguration.ZoneId, index, river.Name); if (index == 0) { DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(debugFilename)); if (di.Exists) di.EnumerateFiles().ToList().ForEach(f => f.Delete()); else di.Create(); } using (MagickImage debugRiver = new MagickImage(MagickColor.Transparent, zoneConfiguration.TargetMapSize, zoneConfiguration.TargetMapSize)) { debugRiver.BackgroundColor = Color.White; debugRiver.FillColor = new MagickColor(0, 0, ushort.MaxValue, 256 * 128); double resizeFactor = zoneConfiguration.TargetMapSize / zoneConfiguration.Heightmap.Heightmap.Width; DrawablePolygon poly = new DrawablePolygon(riverCoordinates); debugRiver.Draw(poly); List<Coordinate> orginalCoords = river.GetCoordinates(); for (int i = 0; i < riverCoordinates.Count(); i++) { double x, y; if (riverCoordinates[i].X > zoneConfiguration.TargetMapSize / 2) x = riverCoordinates[i].X - 15; else x = riverCoordinates[i].X + 1; if (riverCoordinates[i].Y < zoneConfiguration.TargetMapSize / 2) y = riverCoordinates[i].Y + 15; else y = riverCoordinates[i].Y - 1; debugRiver.FontPointsize = 14.0; debugRiver.FillColor = Color.Black; DrawableText text = new DrawableText(x, y, string.Format("{0} ({1}/{2})", i, orginalCoords[i].X, orginalCoords[i].Y)); debugRiver.Draw(text); } debugRiver.Quality = 100; debugRiver.Write(debugFilename); } }