private void MapGenerator_ResizeEnd(object sender, EventArgs e) { if (landDrawBitmap == null) { return; } var oldLand = landProxyBitmap; var oldMount = mountainProxyBitmap; if (landDrawBitmap.Source.Width != preview.Width || landDrawBitmap.Source.Height != preview.Height) { landDrawBitmap = new LockBitmap(new Bitmap(preview.Width, preview.Height)); mountainDrawBitmap = new LockBitmap(new Bitmap(preview.Width, preview.Height)); } using (Graphics gg = Graphics.FromImage(landDrawBitmap.Source)) { gg.Clear(Color.Transparent); gg.SmoothingMode = SmoothingMode.Default; gg.DrawImage(oldLand.Source, new Rectangle(0, 0, preview.Width, preview.Height)); } using (Graphics gg = Graphics.FromImage(mountainDrawBitmap.Source)) { gg.Clear(Color.Transparent); gg.SmoothingMode = SmoothingMode.Default; gg.DrawImage(oldMount.Source, new Rectangle(0, 0, preview.Width, preview.Height)); } }
public MapGenerator() { InitializeComponent(); if (randomize.Checked) { Rand.SetSeed(new Random().Next(1000000)); seedBox.Value = Rand.Next(10000000); } climate.SelectedIndex = Globals.Climate = 0; land.Checked = true; mediumBrush.Checked = true; //Color.FromArgb(255, 69, 91, 186) randHigh.Checked = true; landDrawBitmap = new LockBitmap(new Bitmap(preview.Width, preview.Height)); mountainDrawBitmap = new LockBitmap(new Bitmap(preview.Width, preview.Height)); landProxyBitmap = new LockBitmap(new Bitmap(3072 / 2, 2048 / 2)); mountainProxyBitmap = new LockBitmap(new Bitmap(3072 / 2, 2048 / 2)); var a = new SolidBrush(Color.FromArgb(255, 130, 158, 75)); var b = new SolidBrush(Color.FromArgb(255, 130 + 40, 158 + 40, 75 + 40)); var c = new SolidBrush(Color.FromArgb(255, 65, 42, 17)); var d = new SolidBrush(Color.FromArgb(255, 69, 91, 186)); using (Graphics gg = Graphics.FromImage(landDrawBitmap.Source)) { gg.Clear(Color.FromArgb(255, 69, 91, 186)); } using (Graphics gg = Graphics.FromImage(mountainDrawBitmap.Source)) { gg.Clear(Color.Transparent); } }
public void SetColour(LockBitmap bmp, int province, Color col) { // this.ProvinceColorMap = col; // ProvinceParser provinceParser = ProvinceIDMap[province]; // foreach (var point in provinceParser.Points) { // bmp.SetPixel(point.X, point.Y, col); } // bmp.UnlockBits(); }
private void newMap_Click(object sender, EventArgs e) { SeaCommands.Clear(); LandCommands.Clear(); MountainCommands.Clear(); landProxyBitmap = new LockBitmap(new Bitmap(3072 / 2, 2048 / 2)); mountainProxyBitmap = new LockBitmap(new Bitmap(3072 / 2, 2048 / 2)); var a = new SolidBrush(Color.FromArgb(255, 130, 158, 75)); var b = new SolidBrush(Color.FromArgb(255, 130 + 40, 158 + 40, 75 + 40)); var c = new SolidBrush(Color.FromArgb(255, 65, 42, 17)); var d = new SolidBrush(Color.FromArgb(255, 69, 91, 186)); using (Graphics gg = Graphics.FromImage(landProxyBitmap.Source)) { gg.Clear(Color.FromArgb(255, 69, 91, 186)); } using (Graphics gg = Graphics.FromImage(mountainProxyBitmap.Source)) { gg.Clear(Color.Transparent); } preview.Invalidate(); }
public void Load() { String provincesDir = Globals.GameDir + "history\\provinces\\"; foreach (var file in Directory.GetFiles(provincesDir)) { String name = file.Substring(file.LastIndexOf('\\') + 1); int id = Convert.ToInt32(name.Split('-')[0].Trim()); } TitleManager.instance.Load(); // foreach (var provinceParser in Provinces) { // provinceParser.DoTitleOwnership(); } for (int n = 0; n < 2000; n++) { ProvinceParser parser = new ProvinceParser(new ScriptScope()); parser.Name = "c_unnamed" + n; parser.id = n + 1; ProvinceIDMap[parser.id] = parser; // TitleManager.instance.CreateDukeScriptScope(); Provinces.Add(parser); } provincesDir = Globals.GameDir + "history\\provinces\\"; foreach (var file in Directory.GetFiles(provincesDir)) { String name = file.Substring(file.LastIndexOf('\\') + 1); int id = Convert.ToInt32(name.Split('-')[0].Trim()); { Script s = ScriptLoader.instance.Load(file); ScriptCommand terrain = (ScriptCommand)s.Root.Find("terrain"); if (terrain != null) { var ter = terrain.Value.ToString(); LoadedTerrain[id] = ter; } else { } } ProvinceIDMap[id].land = true; } //s ProvinceBitmap = new Bitmap(Globals.MapDir + "map\\provinces.bmp"); ProvinceBitmap = ResizeBitmap(ProvinceBitmap, (int)(ProvinceBitmap.Width * SizeMod), (int)(ProvinceBitmap.Height * SizeMod)); ProvinceRenderBitmap = new Bitmap(ProvinceBitmap.Width, ProvinceBitmap.Height); LoadDefinitions(); ProvincePixelMap = new ProvinceParser[ProvinceBitmap.Width, ProvinceBitmap.Height]; CreateLandscape(); LockBitmap lockBitmap = new LockBitmap(ProvinceBitmap); lockBitmap.LockBits(); for (int x = 0; x < lockBitmap.Width; x++) for (int y = 0; y < lockBitmap.Height; y++) { Color col = lockBitmap.GetPixel(x, y); // col2 = Color.FromArgb(255, col.R, col.G, col.B); if (ProvinceColorMap.ContainsKey(col)) { ProvincePixelMap[x, y] = ProvinceColorMap[col]; ProvinceColorMap[col].Points.Add(new Point(x, y)); } int minX = x - 1; int minY = y - 1; if (minX < 0) minX = 0; if (minY < 0) minY = 0; for (int xx = minX; xx <= x; xx++) { for (int yy = minY; yy <= y; yy++) { if (xx == x && yy == y) continue; Color col2 = lockBitmap.GetPixel(xx, yy); if (col2 != col && ProvinceColorMap.ContainsKey(col2) && ProvinceColorMap.ContainsKey(col)) { ProvinceColorMap[col].AddAdjacent(ProvinceColorMap[col2]); } } } } for (int y = lockBitmap.Height - 1; y >= 0; y--) for (int x = lockBitmap.Width - 1; x >= 0; x--) { Color col = lockBitmap.GetPixel(x, y); // col2 = Color.FromArgb(255, col.R, col.G, col.B); int maxX = x+1; int maxY = y+1; maxX = Math.Min(lockBitmap.Width - 1, maxX); maxY = Math.Min(lockBitmap.Height - 1, maxY); for (int xx = x; xx <= maxX; xx++) { for (int yy = y; yy <= maxY; yy++) { if (xx == x && yy == y) continue; Color col2 = lockBitmap.GetPixel(xx, yy); if (col2 != col && ProvinceColorMap.ContainsKey(col2) && ProvinceColorMap.ContainsKey(col)) { ProvinceColorMap[col].AddAdjacent(ProvinceColorMap[col2]); } } } } lockBitmap.UnlockBits(); foreach (var provinceParser in Provinces) { int maxX = -1000000; int maxY = -1000000; int minX = 1000000; int minY = 1000000; if (provinceParser.Points.Count == 0) continue; foreach (var point in provinceParser.Points) { if (point.X > maxX) maxX = point.X; if (point.Y > maxY) maxY = point.Y; if (point.X < minX) minX = point.X; if (point.Y < minY) minY = point.Y; } Bitmap bmp = new Bitmap(maxX - minX + 1, maxY - minY + 1); ProvinceMapBitmap b = new ProvinceMapBitmap() {Bitmap = bmp, MapPoint = new Point(minX, minY)}; LockBitmap lb = new LockBitmap(b.Bitmap); lb.LockBits(); for (int x = 0; x < lb.Width; x++) { for (int y = 0; y < lb.Height; y++) { lb.SetPixel(x, y, Color.Transparent); } } foreach (var point in provinceParser.Points) { lb.SetPixel(point.X-minX, point.Y-minY, Color.White); } lb.UnlockBits(); ProvinceBitmaps[provinceParser.id] = b; } LoadAdjacencies(); Simulation.SimulationManager.instance.Init(); }
public void Load() { String provincesDir = Globals.GameDir + "history\\provinces\\"; foreach (var file in Directory.GetFiles(provincesDir)) { String name = file.Substring(file.LastIndexOf('\\') + 1); int id = Convert.ToInt32(name.Split('-')[0].Trim()); } TitleManager.instance.Load(); // foreach (var provinceParser in Provinces) { // provinceParser.DoTitleOwnership(); } for (int n = 0; n < 2000; n++) { ProvinceParser parser = new ProvinceParser(new ScriptScope()); parser.Name = "c_unnamed" + n; parser.id = n + 1; ProvinceIDMap[parser.id] = parser; // TitleManager.instance.CreateDukeScriptScope(); Provinces.Add(parser); } provincesDir = Globals.GameDir + "history\\provinces\\"; foreach (var file in Directory.GetFiles(provincesDir)) { String name = file.Substring(file.LastIndexOf('\\') + 1); int id = Convert.ToInt32(name.Split('-')[0].Trim()); { Script s = ScriptLoader.instance.Load(file); ScriptCommand terrain = (ScriptCommand)s.Root.Find("terrain"); if (terrain != null) { var ter = terrain.Value.ToString(); LoadedTerrain[id] = ter; } else { } } ProvinceIDMap[id].land = true; } //s ProvinceBitmap = new Bitmap(Globals.MapDir + "map\\provinces.bmp"); ProvinceBitmap = ResizeBitmap(ProvinceBitmap, (int)(ProvinceBitmap.Width * SizeMod), (int)(ProvinceBitmap.Height * SizeMod)); ProvinceRenderBitmap = new Bitmap(ProvinceBitmap.Width, ProvinceBitmap.Height); LoadDefinitions(); ProvincePixelMap = new ProvinceParser[ProvinceBitmap.Width, ProvinceBitmap.Height]; CreateLandscape(); LockBitmap lockBitmap = new LockBitmap(ProvinceBitmap); lockBitmap.LockBits(); for (int x = 0; x < lockBitmap.Width; x++) { for (int y = 0; y < lockBitmap.Height; y++) { Color col = lockBitmap.GetPixel(x, y); // col2 = Color.FromArgb(255, col.R, col.G, col.B); if (ProvinceColorMap.ContainsKey(col)) { ProvincePixelMap[x, y] = ProvinceColorMap[col]; ProvinceColorMap[col].Points.Add(new Point(x, y)); } int minX = x - 1; int minY = y - 1; if (minX < 0) { minX = 0; } if (minY < 0) { minY = 0; } for (int xx = minX; xx <= x; xx++) { for (int yy = minY; yy <= y; yy++) { if (xx == x && yy == y) { continue; } Color col2 = lockBitmap.GetPixel(xx, yy); if (col2 != col && ProvinceColorMap.ContainsKey(col2) && ProvinceColorMap.ContainsKey(col)) { ProvinceColorMap[col].AddAdjacent(ProvinceColorMap[col2]); } } } } } for (int y = lockBitmap.Height - 1; y >= 0; y--) { for (int x = lockBitmap.Width - 1; x >= 0; x--) { Color col = lockBitmap.GetPixel(x, y); // col2 = Color.FromArgb(255, col.R, col.G, col.B); int maxX = x + 1; int maxY = y + 1; maxX = Math.Min(lockBitmap.Width - 1, maxX); maxY = Math.Min(lockBitmap.Height - 1, maxY); for (int xx = x; xx <= maxX; xx++) { for (int yy = y; yy <= maxY; yy++) { if (xx == x && yy == y) { continue; } Color col2 = lockBitmap.GetPixel(xx, yy); if (col2 != col && ProvinceColorMap.ContainsKey(col2) && ProvinceColorMap.ContainsKey(col)) { ProvinceColorMap[col].AddAdjacent(ProvinceColorMap[col2]); } } } } } lockBitmap.UnlockBits(); foreach (var provinceParser in Provinces) { int maxX = -1000000; int maxY = -1000000; int minX = 1000000; int minY = 1000000; if (provinceParser.Points.Count == 0) { continue; } foreach (var point in provinceParser.Points) { if (point.X > maxX) { maxX = point.X; } if (point.Y > maxY) { maxY = point.Y; } if (point.X < minX) { minX = point.X; } if (point.Y < minY) { minY = point.Y; } } Bitmap bmp = new Bitmap(maxX - minX + 1, maxY - minY + 1); ProvinceMapBitmap b = new ProvinceMapBitmap() { Bitmap = bmp, MapPoint = new Point(minX, minY) }; LockBitmap lb = new LockBitmap(b.Bitmap); lb.LockBits(); for (int x = 0; x < lb.Width; x++) { for (int y = 0; y < lb.Height; y++) { lb.SetPixel(x, y, Color.Transparent); } } foreach (var point in provinceParser.Points) { lb.SetPixel(point.X - minX, point.Y - minY, Color.White); } lb.UnlockBits(); ProvinceBitmaps[provinceParser.id] = b; } LoadAdjacencies(); Simulation.SimulationManager.instance.Init(); }
private void generateDrawn_Click(object sender, EventArgs e) { if (MessageBox.Show("Are you sure you want to generate?", "Are you sure?", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } if (Globals.GameDir.Trim().Length == 0) { MessageBox.Show( "You need to set the CK2 game directory in the main interface Configuration tab before generating maps", "Error"); return; } Form1.instance.clear(); if (Globals.MapOutputDir == null) { FolderBrowserDialog d = new FolderBrowserDialog(); d.Description = "Choose root folder you would like to store your custom maps."; if (d.ShowDialog() == DialogResult.OK) { Globals.MapOutputDir = d.SelectedPath; } } Globals.MapName = this.mapOutputDrawn.Text; if (!Directory.Exists(Globals.MapOutputTotalDir)) { Directory.CreateDirectory(Globals.MapOutputTotalDir); } if (!Directory.Exists(Globals.MapOutputTotalDir + "map\\")) { Directory.CreateDirectory(Globals.MapOutputTotalDir + "map\\"); } // MapGenManager.instance.Width /= 4; // MapGenManager.instance.Height /= 4; CopyDir(Directory.GetCurrentDirectory() + "\\data\\mapstuff", Globals.MapOutputTotalDir + "map"); CopyDir(Directory.GetCurrentDirectory() + "\\data\\common", Globals.MapOutputTotalDir + "common"); float delta = 1.0f; if (vhigh.Checked) { delta = 2.5f; } if (high.Checked) { delta = 1.75f; } if (normal.Checked) { delta = 1.2f; } if (low.Checked) { delta = 0.85f; } if (vLow.Checked) { delta = 0.6f; } if (mapvlarge.Checked) { MapGenManager.instance.Width = 4096; } if (maplarge.Checked) { MapGenManager.instance.Width = 3200; } if (mapnorm.Checked) { MapGenManager.instance.Width = 3072; } if (mapsmall.Checked) { MapGenManager.instance.Width = 2048; } // MapGenManager.instance.Width /= 4; // MapGenManager.instance.Height /= 4; LockBitmap lBit = new LockBitmap(landBitmapOut); LockBitmap mBit = new LockBitmap(mountainBitmap); MapGenManager.instance.Create(false, DrawnSeed, 1500, delta, lBit, mBit); lBit.UnlockBits(); mBit.UnlockBits(); // MapGenManager.instance.Create(usedSeed, 1300); // MapGenManager.instance.Create(usedSeed, 600); LockBitmap waterColorMap = new LockBitmap( DevIL.DevIL.LoadBitmap(Directory.GetCurrentDirectory() + "\\data\\mapstuff\\terrain\\colormap_water.dds")); waterColorMap.ResizeImage(MapGenManager.instance.Width, MapGenManager.instance.Height); DevIL.DevIL.SaveBitmap(Globals.MapOutputTotalDir + "map\\terrain\\colormap_water.dds", waterColorMap.Source); // LockBitmap normalMap = new LockBitmap(new Bitmap((Directory.GetCurrentDirectory() + "\\data\\mapstuff\\world_normal_height.bmp"))); // normalMap.ResizeImage(MapGenManager.instance.Width, MapGenManager.instance.Height); // normalMap.Save24(Globals.MapOutputTotalDir + "map\\world_normal_height.bmp"); //preview.Image = DevIL.DevIL.LoadBitmap(Globals.MapOutputTotalDir + "map\\terrain\\colormap.dds"); landBitmap = DevIL.DevIL.LoadBitmap(Globals.MapOutputTotalDir + "map\\terrain\\colormap.dds"); preview.Invalidate(); // map = null; exportButton.Enabled = false; if ( MessageBox.Show("Would you like to load this map to generate a world history on?", "Load Map?", MessageBoxButtons.YesNo) == DialogResult.Yes) { Form1.instance.SetMap(Globals.MapOutputTotalDir); map = null; ProvinceBitmapManager.instance = new ProvinceBitmapManager(); MapGenManager.instance = new MapGenManager(); Close(); } ProvinceBitmapManager.instance = new ProvinceBitmapManager(); MapGenManager.instance = new MapGenManager(); map = null; }
private void generateFromDraw_Click(object sender, EventArgs e) { generateDrawn.Enabled = true; int ow = 1; int oh = 1; int w = 3072; int h = 2048; if (mapvlarge.Checked) { w = 4096; } if (maplarge.Checked) { w = 3200; } if (mapnorm.Checked) { w = 3072; } if (mapsmall.Checked) { w = 2048; } { Bitmap bmp = new Bitmap(w / 2, h / 2, PixelFormat.Format24bppRgb); Bitmap bmp2 = new Bitmap(w / 2, h / 2, PixelFormat.Format24bppRgb); LockBitmap lbmp2 = new LockBitmap(bmp2); LockBitmap lbmp = new LockBitmap(bmp); float deltaX = w / (float)preview.Width; float deltaY = h / (float)preview.Height; lbmp.LockBits(); lbmp2.LockBits(); landProxyBitmap.LockBits(); mountainProxyBitmap.LockBits(); for (int x = 0; x < bmp.Width; x++) { for (int y = 0; y < bmp.Height; y++) { float dx = mountainProxyBitmap.Width / (float)bmp.Width; float dy = mountainProxyBitmap.Height / (float)bmp.Height; var col = mountainProxyBitmap.GetPixel((int)(x * dx), (int)(y * dy)); var col2 = landProxyBitmap.GetPixel((int)(x * dx), (int)(y * dy)); int xx = x; int yy = y; if (col.R > 0 && col.A > 0) { lbmp.SetPixel(xx, yy, Color.White); } else { lbmp.SetPixel(xx, yy, Color.Black); } if (col2.R != 69 && col2.A > 0) { lbmp2.SetPixel(xx, yy, Color.White); } else { lbmp2.SetPixel(xx, yy, Color.Black); } } } lbmp2.UnlockBits(); lbmp.UnlockBits(); landProxyBitmap.UnlockBits(); mountainProxyBitmap.UnlockBits(); /* Graphics g = Graphics.FromImage(bmp); * * foreach (var drawCommand in MountainCommands) * { * var r = new Rectangle(drawCommand.Point.X - drawCommand.Radius, drawCommand.Point.Y - drawCommand.Radius, * drawCommand.Radius * 2, drawCommand.Radius * 2); * * Rectangle rect = new Rectangle((int)(r.X * deltaX), (int)(r.Y * deltaY), (int)((r.Right * deltaX) - (r.Left * deltaX)), (int)((r.Bottom * deltaY) - r.Top * deltaY)); * * g.FillEllipse(a, rect); * } */ int rand = 32; if (randMed.Checked) { rand = 32; } if (randHigh.Checked) { rand = 32; } ow = bmp.Width; oh = bmp.Height; lbmp.ResizeImage(ow / rand, oh / rand); lbmp.ResizeImage(ow * 2, oh * 2); mountainBitmap = lbmp.Source; rand = 8; BitmapSelect.Randomness = 0.75f; if (randMed.Checked) { rand = 16; BitmapSelect.Randomness = 1f; } if (randHigh.Checked) { rand = 64; BitmapSelect.Randomness = 1f; } if (randMin.Checked) { rand = 2; BitmapSelect.Randomness = 0.5f; } ow = bmp2.Width; oh = bmp2.Height; lbmp2.ResizeImage(ow / rand, oh / rand); lbmp2.ResizeImage(ow * 2, oh * 2); landBitmap = lbmp2.Source; } map = new GeneratedTerrainMap(); int seed = Rand.Next(1000000); LockBitmap lBit = new LockBitmap(landBitmap); LockBitmap mBit = new LockBitmap(mountainBitmap); map.Init(ow / 4, oh / 4, lBit, lBit, mBit, seed); lBit.UnlockBits(); mBit.UnlockBits(); DrawnSeed = seed; landBitmap = map.Map.Source; landBitmapOut = lBit.Source; mountainBitmap = mBit.Source; preview.Invalidate(); }
private void generateFromHeightMap_Click(object sender, EventArgs e) { if (mapvlarge.Checked) { MapGenManager.instance.Width = 4096; } if (maplarge.Checked) { MapGenManager.instance.Width = 3200; } if (mapnorm.Checked) { MapGenManager.instance.Width = 3072; } if (mapsmall.Checked) { MapGenManager.instance.Width = 2048; } adjustedHeight = new LockBitmap(new Bitmap(MapGenManager.instance.Width, 2048, HeightMapBitmap.Source.PixelFormat)); HeightMapBitmap.LockBits(); bFromHeightMap = true; adjustedHeight.LockBits(); float seaLevel = (float)this.seaLevel.Value; for (int x = 0; x < adjustedHeight.Width; x++) { for (int y = 0; y < adjustedHeight.Height; y++) { adjustedHeight.SetPixel(x, y, 89 / 255.0f); } } for (int x = 0; x < HeightMapBitmap.Width; x++) { for (int y = 0; y < HeightMapBitmap.Height; y++) { byte h = HeightMapBitmap.GetHeight(x, y); int xa = x; int ya = y; int halfo = HeightMapBitmap.Width / 2; int halfa = adjustedHeight.Width / 2; int startX = halfa - halfo; xa += startX; if (HeightMapBitmap.Height < adjustedHeight.Height) { halfo = HeightMapBitmap.Height / 2; halfa = adjustedHeight.Height / 2; ya += halfa - halfo; } if (h < seaLevel) { float below = 89; adjustedHeight.SetPixel(xa, ya, below / 255.0f); } else { h -= (byte)seaLevel; float delta = h / (255.0f - seaLevel); delta *= (float)(reliefScale.Value) / 100.0f; float below = delta * (255.0f - 98.0f); below += 98; adjustedHeight.SetPixel(xa, ya, below / 255.0f); } } } HeightMapBitmap.UnlockBits(); adjustedHeight.UnlockBits(); // adjustedHeight.ResizeImage(adjustedHeight.Width / 2, adjustedHeight.Height / 2); // adjustedHeight.ResizeImage(adjustedHeight.Width, adjustedHeight.Height); HeightMapBitmap.Source.Dispose(); HeightMapBitmap = null; GC.Collect(); exportButton_Click(null, new EventArgs()); /* * * { * map = new GeneratedTerrainMap(); * * int ow = 1; * int oh = 1; * int w = 3072; * int h = 2048; * if (mapvlarge.Checked) * w = 4096; * * if (maplarge.Checked) * w = 3200; * * if (mapnorm.Checked) * w = 3072; * * if (mapsmall.Checked) * w = 2048; * * * int seed = Rand.Next(1000000); * * map.InitFromHeightMap(w / 4, h / 4, adjustedHeight); * * DrawnSeed = seed; * landBitmap = map.Map.Source; * * preview.Image = landBitmap; * preview.Invalidate(); * } */ }