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 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(); }