public void GenerateHeightmap(Random random) { int mapWidth = Settings.MapWidth; int mapHeight = Settings.MapHeight; Altitude = new double[mapWidth, mapHeight]; double[,] heightmap = new DiamondSquare(random, mapWidth, mapHeight, 1, Settings.Roughness, false, false).GenerateHeightmap(); double heightmapWidth = heightmap.GetUpperBound(0); double heightmapDepth = heightmap.GetUpperBound(1); double widthRatio = heightmapWidth / mapWidth; double heightRatio = heightmapDepth / mapHeight; int middleX = mapWidth / 2; int middleY = mapHeight / 2; int edgeSizeX = mapWidth / 4; int edgeSizeY = mapHeight / 4; int smoothThresholdX = middleX - edgeSizeX; int smoothThresholdY = middleY - edgeSizeY; double heightScale = Settings.HeightScale; double floorHeight = Settings.BaseHeight - heightScale; for (int x = 0; x < mapWidth; x++) { for (int y = 0; y < mapHeight; y++) { double multiplier = 1.0; if (Settings.OceanBorder) { int dx = Math.Abs(middleX - x); int dy = Math.Abs(middleY - y); if (dx >= smoothThresholdX) { multiplier *= 1 - (dx - smoothThresholdX) / (double)(edgeSizeX); } if (dy >= smoothThresholdY) { multiplier *= 1 - (dy - smoothThresholdY) / (double)(edgeSizeY); } } if (Settings.Noise > 0) { multiplier *= random.NextDouble(1 - Settings.Noise, 1); } int x2 = (int)Math.Round((x) * widthRatio); int y2 = (int)Math.Round((y) * heightRatio); Altitude[x, y] = floorHeight + (heightmap[x2, y2] * heightScale + heightScale) * multiplier; } } }
public void Generate(Random rng) { Altitude = new double[SizeX, SizeY]; double[,] heightmap = new DiamondSquare(rng, SizeX, SizeY, 1, Roughness, WrapX, WrapY).GenerateHeightmap(); double heightmapWidth = heightmap.GetUpperBound(0); double heightmapDepth = heightmap.GetUpperBound(1); double widthRatio = heightmapWidth / SizeX; double heightRatio = heightmapDepth / SizeY; int middleX = SizeX / 2; int middleY = SizeY / 2; int edgeSizeX = SizeX / 4; int edgeSizeY = SizeY / 4; int smoothThresholdX = middleX - edgeSizeX; int smoothThresholdY = middleY - edgeSizeY; for (int x = 0; x < SizeX; x++) { for (int y = 0; y < SizeY; y++) { double multiplier = 1.0; if (SmoothEdges) { int dx = Math.Abs(middleX - x); int dy = Math.Abs(middleY - y); if (dx >= smoothThresholdX) { multiplier *= 1 - (dx - smoothThresholdX) / (double)(edgeSizeX); } if (dy >= smoothThresholdY) { multiplier *= 1 - (dy - smoothThresholdY) / (double)(edgeSizeY); } } if (Noise > 0) { multiplier *= rng.NextDouble(1 - Noise, 1); } int x2 = (int)Math.Round((x) * widthRatio); int y2 = (int)Math.Round((y) * heightRatio); Altitude[x, y] = FloorHeight + (heightmap[x2, y2] * AltitudeScale + AltitudeScale) * multiplier; } } }