private void generateLandmass_Click(object sender, EventArgs e) { map = new GeneratedTerrainMap(); if (randomize.Checked) { seedBox.Value = Rand.Next(10000000); } int seed = (int)seedBox.Value; usedSeed = seed; int w = 3072; if (mapvlarge.Checked) { w = 4096; } if (maplarge.Checked) { w = 3200; } if (mapnorm.Checked) { w = 3072; } if (mapsmall.Checked) { w = 2048; } map.Init(w / 10, 2048 / 10, usedSeed); preview.Image = map.Map.Source; exportButton.Enabled = true; }
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(); }