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