public void UpdateFromProvinces() { Width *= 4; Height *= 4; TerrainMap.LockBits(); Refine(); File.Delete(Globals.MapOutputTotalDir + "map\\terrain.bmp"); GrayBMP_File.CreateGrayBitmapFile(TerrainMap.Source, Globals.MapOutputTotalDir + "map\\terrain.bmp"); TerrainMap.Source.Dispose(); TerrainMap = null; GrayBMP_File.CreateGrayBitmapFile(Trees.Source, Globals.MapOutputTotalDir + "map\\trees.bmp", true); LockBitmap rivers = new LockBitmap(Width, Height); rivers.LockBits(); for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { rivers.SetPixel(x, y, Color.FromArgb(255, 255, 0, 128)); } } rivers.UnlockBits(); GrayBMP_File.CreateGrayBitmapFile(rivers.Source, Globals.MapOutputTotalDir + "map\\rivers.bmp", false, true); }
private void CreateInitialTerrainMap() { Map.LockBits(); TerrainMap.LockBits(); for (int x = 0; x < Map.Width; x++) { for (int y = 0; y < Map.Height; y++) { Color col = Color.AliceBlue; float height = Map.GetHeight(x, y) / 255.0f; float sealevel = (96 / 255.0f); bool sea = height < sealevel; if (sea) { col = Color.FromArgb(255, 69, 91, 186); } else { col = Color.FromArgb(255, 130, 158, 75); } TerrainMap.SetPixel(x, y, col); } } TerrainMap.UnlockBits(); Map.UnlockBits(); }
private void CreateTerrainMap() { MoistureMap.ResizeImage(Map.Width, Map.Height); HeatMap.LockBits(); MoistureMap.LockBits(); Map.LockBits(); Trees.LockBits(); TerrainMap.LockBits(); MapGenManager.instance.ProvinceMap.LockBits(); NoiseGenerator noiseH = new NoiseGenerator(); NoiseGenerator noiseM = new NoiseGenerator(); noiseM.Octaves = 4; for (int x = 0; x < Map.Width; x++) { for (int y = 0; y < Map.Height; y++) { Color col = Color.AliceBlue; float heat = GetHeat(x, y); // + (Rand.Next(-30, 30) / 8000.0f); float moisture = GetMoisture(x * 4, y * 4); // + (Rand.Next(-30, 30) / 8000.0f); float no = (float)((float)((noiseH.Noise(x / DivNoise / 8, y / DivNoise / 8)) - 0.5f) * 0.2); float tree = (float)((float)((noiseM.Noise(x / DivNoise, y / DivNoise)) - 0.5f)); tree += no * 12.0f; heat += no * 3.0f; moisture -= no * 3.0f; float height = Map.GetHeight(x, y) / 255.0f; float desertLevel = 0.48f; float shyDesertLevel = 0.43f; float desertDry = 0.6f; float shyDry = 0.62f; float coastalDesertLevel = 0.7f; float tundraWetLevel = 0.25f; float jungleLevel = 0.8f; float arcticLevel = 0.13f; float hillLevel = 0.55f; float mountainLevel = 0.60f; float highmountainLevel = 0.8f; heat += height / 8.0f; moisture -= height / 8.0f; float sealevel = (98 / 255.0f); tree += (height - sealevel) * 2.3f; tree += moisture * 1.9f; bool hot = heat > desertLevel; bool slightlyHot = !hot && heat > shyDesertLevel; bool cold = heat < arcticLevel; bool wet = moisture > coastalDesertLevel; bool dry = moisture < desertDry; bool nearlyDry = moisture < desertDry; bool wetCold = moisture > tundraWetLevel; bool sea = Color.FromArgb(255, 69, 91, 186) == TerrainMap.GetPixel(x, y); bool trees = tree > 0.99f; bool temptrees = tree > 0.99f; if (sea) { col = SeaColor; } else { if (hot || slightlyHot) { if (wet) { col = Color.FromArgb(255, 40, 180, 149); if (trees && wet) { float dx = x / (float)Width; float dy = y / (float)Height; int tx = (int)(Trees.Width * dx); int ty = (int)(Trees.Height * dy); if (Rand.Next(2) == 0) { if (height > 107 / 255.0f) { Trees.SetPixel(tx, ty, Color.FromArgb(255, 154, 156, 51)); } } } } else if (hot && dry) { col = DesertSandColor; } else if (slightlyHot && dry) { col = SandyGrassColor; } else { if (nearlyDry) { col = DesertSandColor; } else { col = TemperateGrassColor; } } } else if (cold) { col = NorthernGrassColor; if (temptrees) { col = Color.FromArgb(255, 0, 86, 6); float dx = x / (float)Width; float dy = y / (float)Height; int tx = (int)(Trees.Width * dx); int ty = (int)(Trees.Height * dy); if (Rand.Next(4) == 0) { if (height > 107 / 255.0f) { Trees.SetPixel(tx, ty, Color.FromArgb(255, 30, 139, 109)); } } } else { if (Rand.Next(18) == 0) { float dx = x / (float)Width; float dy = y / (float)Height; int tx = (int)(Trees.Width * dx); int ty = (int)(Trees.Height * dy); if (height > 107 / 255.0f) { Trees.SetPixel(tx, ty, Color.FromArgb(255, 30, 139, 109)); } } } } else { col = TemperateGrassColor; if (temptrees) { col = TemperateForestColor; float dx = x / (float)Width; float dy = y / (float)(Height); int tx = (int)(Trees.Width * dx); int ty = (int)(Trees.Height * dy); if (Rand.Next(4) == 0) { if (height > 107 / 255.0f) { Trees.SetPixel(tx, ty, Color.FromArgb(255, 76, 156, 51)); } } } else { if (Rand.Next(18) == 0) { float dx = x / (float)Width; float dy = y / (float)Height; int tx = (int)(Trees.Width * dx); int ty = (int)(Trees.Height * dy); if (height > 107 / 255.0f) { Trees.SetPixel(tx, ty, Color.FromArgb(255, 76, 156, 51)); } } } } // height += no * 2.0f; // height -= sealevel; if (height > highmountainLevel) { if (hot) { col = SandMountainColor; } else { col = SnowMountainTopColor; } } else if (height > mountainLevel) { if (hot) { col = HillsDesertColor; } else { col = MountainRockColor; } } else if (height > hillLevel) { if (hot) { } else { col = SteppesColor; } } else { var ccol = MapGenManager.instance.ProvinceMap.GetPixel(x, y); if (ccol.R == 0 && ccol.G == 0 && ccol.B == 0) { if (!hot && !slightlyHot) { col = SteppesColor; } else { col = DesertSandColor; float dx = x / (float)Width; float dy = y / (float)(Height); int tx = (int)(Trees.Width * dx); int ty = (int)(Trees.Height * dy); Trees.SetPixel(tx, ty, Color.FromArgb(255, 0, 0, 0)); } } } } TerrainMap.SetPixel(x, y, col); } } MapGenManager.instance.ProvinceMap.UnlockBits(); TerrainMap.UnlockBits(); HeatMap.UnlockBits(); MoistureMap.UnlockBits(); MoistureMap.Source.Dispose(); // HeatMap.Source.Dispose(); // HeatMap = null; MoistureMap = null; HeatMap.Source.Dispose(); HeatMap = null; Map.UnlockBits(); Trees.UnlockBits(); }
public void CreateColorMap() { GC.Collect(); GC.WaitForPendingFinalizers(); Bitmap ocean = ConvertTo24bpp(new Bitmap(Directory.GetCurrentDirectory() + "\\data\\ocean.png")); Bitmap grass = ConvertTo24bpp(new Bitmap(Directory.GetCurrentDirectory() + "\\data\\grass.png")); Bitmap desert = ConvertTo24bpp(new Bitmap(Directory.GetCurrentDirectory() + "\\data\\desert.png")); Bitmap mountain = ConvertTo24bpp(new Bitmap(Directory.GetCurrentDirectory() + "\\data\\mountain.png")); Bitmap mountainAlpha = new Bitmap(Width, Height, PixelFormat.Format8bppIndexed); Bitmap grassAlpha = new Bitmap(Width, Height, PixelFormat.Format8bppIndexed); Bitmap desertAlpha = new Bitmap(Width, Height, PixelFormat.Format8bppIndexed); Bitmap finalMap = new Bitmap(Width, Height, PixelFormat.Format24bppRgb); LockBitmap lOcean = new LockBitmap(ocean); LockBitmap lMountain = new LockBitmap(mountain); LockBitmap lGrass = new LockBitmap(grass); LockBitmap lDesert = new LockBitmap(desert); LockBitmap lGrassAlpha = new LockBitmap(grassAlpha); LockBitmap lDesertAlpha = new LockBitmap(desertAlpha); LockBitmap lMountainAlpha = new LockBitmap(mountainAlpha); LockBitmap lFinal = new LockBitmap(finalMap); lGrassAlpha.LockBits(); lDesertAlpha.LockBits(); lMountainAlpha.LockBits(); TerrainMap.LockBits(); for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { Color col = TerrainMap.GetPixel(x, y); if (col != SeaColor) { lGrassAlpha.SetPixel(x, y, Color.White); if (col == SandyGrassColor) { lDesertAlpha.SetPixel(x, y, Color.LightGray); lMountainAlpha.SetPixel(x, y, Color.FromArgb(255, 0x50, 0x50, 0x50)); } else if (col == SteppesColor) { lMountainAlpha.SetPixel(x, y, Color.Gray); } else if (col == DesertSandColor) { lDesertAlpha.SetPixel(x, y, Color.White); } else if (col == MountainRockColor || col == HillsDesertColor || col == SandMountainColor || col == SnowMountainTopColor) { lMountainAlpha.SetPixel(x, y, Color.White); } } } } TerrainMap.UnlockBits(); lGrassAlpha.Blur(1); lDesertAlpha.Blur(1); lMountainAlpha.Blur(1); lOcean.LockBits(); lGrass.LockBits(); lDesert.LockBits(); lMountain.LockBits(); lFinal.LockBits(); for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { int sx = x; if (sx >= 3072) { sx -= 3072; } float grassAlphaVal = lGrassAlpha.GetPixel(x, y).R / 255.0f; float desertAlphaVal = lDesertAlpha.GetPixel(x, y).R / 255.0f; float mountainAlphaValue = lMountainAlpha.GetPixel(x, y).R / 255.0f; Color seaCol = lOcean.GetPixel(sx, y); Color grassCol = lGrass.GetPixel(sx, y); Color mountainCol = lMountain.GetPixel(sx, y); Color desCol = lDesert.GetPixel(sx, y); float r = seaCol.R / 255.0f; float g = seaCol.G / 255.0f; float b = seaCol.B / 255.0f; r = Lerp(r, grassCol.R / 255.0f, grassAlphaVal); g = Lerp(g, grassCol.G / 255.0f, grassAlphaVal); b = Lerp(b, grassCol.B / 255.0f, grassAlphaVal); r = Lerp(r, desCol.R / 255.0f, desertAlphaVal); g = Lerp(g, desCol.G / 255.0f, desertAlphaVal); b = Lerp(b, desCol.B / 255.0f, desertAlphaVal); r = Lerp(r, mountainCol.R / 255.0f, mountainAlphaValue); g = Lerp(g, mountainCol.G / 255.0f, mountainAlphaValue); b = Lerp(b, mountainCol.B / 255.0f, mountainAlphaValue); Color final = Color.FromArgb(255, (int)(r * 255), (int)(g * 255), (int)(b * 255)); lFinal.SetPixel(x, y, final); } } lGrassAlpha.UnlockBits(); lDesertAlpha.UnlockBits(); lMountainAlpha.UnlockBits(); lGrassAlpha.Source.Dispose(); lMountainAlpha.Source.Dispose(); lDesertAlpha.Source.Dispose(); lGrassAlpha = null; lDesertAlpha = null; lMountainAlpha = null; lOcean.UnlockBits(); lGrass.UnlockBits(); lDesert.UnlockBits(); lMountain.UnlockBits(); lFinal.UnlockBits(); if (!Directory.Exists(Globals.MapOutputTotalDir)) { Directory.CreateDirectory(Globals.MapOutputTotalDir); } if (!Directory.Exists(Globals.MapOutputTotalDir + "map\\")) { Directory.CreateDirectory(Globals.MapOutputTotalDir + "map\\"); } if (!Directory.Exists(Globals.MapOutputTotalDir + "map\\terrain\\")) { Directory.CreateDirectory(Globals.MapOutputTotalDir + "map\\terrain\\"); } if (File.Exists(Globals.MapOutputTotalDir + "map\\terrain\\colormap.dds")) { File.Delete(Globals.MapOutputTotalDir + "map\\terrain\\colormap.dds"); } lOcean.Source.Dispose(); lGrass.Source.Dispose(); lDesert.Source.Dispose(); lMountain.Source.Dispose(); GC.Collect(); GC.WaitForPendingFinalizers(); DevIL.DevIL.SaveBitmap(Globals.MapOutputTotalDir + "map\\terrain\\colormap.dds", lFinal.Source); lFinal.Source.Dispose(); lFinal = null; }