Index: binaries/data/mods/public/maps/random/aegean_sea.js =================================================================== --- binaries/data/mods/public/maps/random/aegean_sea.js +++ binaries/data/mods/public/maps/random/aegean_sea.js @@ -1,8 +1,6 @@ Engine.LoadLibrary("rmgen"); Engine.LoadLibrary("rmgen-common"); -TILE_CENTERED_HEIGHT_MAP = true; - const tCity = "medit_city_pavement"; const tCityPlaza = "medit_city_pavement"; const tHill = ["medit_grass_shrubs", "medit_rocks_grass_shrubs", "medit_rocks_shrubs", "medit_rocks_grass", "medit_shrubs"]; Index: binaries/data/mods/public/maps/random/alpine_valley.js =================================================================== --- binaries/data/mods/public/maps/random/alpine_valley.js +++ binaries/data/mods/public/maps/random/alpine_valley.js @@ -1,8 +1,6 @@ Engine.LoadLibrary("rmgen"); Engine.LoadLibrary("rmgen-common"); -TILE_CENTERED_HEIGHT_MAP = true; - /** * This class creates random mountainranges without enclosing any area completely. * Index: binaries/data/mods/public/maps/random/archipelago.js =================================================================== --- binaries/data/mods/public/maps/random/archipelago.js +++ binaries/data/mods/public/maps/random/archipelago.js @@ -2,8 +2,6 @@ Engine.LoadLibrary("rmgen-common"); Engine.LoadLibrary("rmbiome"); -TILE_CENTERED_HEIGHT_MAP = true; - setSelectedBiome(); const biomeTweaks = Engine.ReadJSONFile("maps/random/archipelago_biome_tweaks.json"); Index: binaries/data/mods/public/maps/random/ardennes_forest.js =================================================================== --- binaries/data/mods/public/maps/random/ardennes_forest.js +++ binaries/data/mods/public/maps/random/ardennes_forest.js @@ -89,7 +89,7 @@ for (var iz = 0; iz < mapSize; iz++) { let position = new Vector2D(ix, iz); - let h = g_Map.getHeight(position); + let h = g_Map.getVertexHeight(position); if (h > heightRavineHill) { clHill.add(position); @@ -98,7 +98,7 @@ var x = ix / (mapSize + 1.0); var z = iz / (mapSize + 1.0); var n = (noise0.get(x, z) - 0.5) * heightRavineHill; - g_Map.setHeight(position, h + n); + g_Map.setVertexHeight(position, h + n); } } @@ -261,7 +261,7 @@ for (var iz = 0; iz < mapSize; iz++) { let position = new Vector2D(ix, iz); - let h = g_Map.getHeight(position); + let h = g_Map.getVertexHeight(position); if (h > 35 && randBool(0.1) || h < 15 && randBool(0.05) && clHillDeco.countMembersInRadius(position, 1) == 0) @@ -292,10 +292,10 @@ { let position = new Vector2D(ix, iz); var z = iz / (mapSize + 1.0); - var h = g_Map.getHeight(position); + var h = g_Map.getVertexHeight(position); var pn = playerNearness(x,z); var n = (noise0.get(x,z) - 0.5) * 10; - g_Map.setHeight(position, h + (n * pn)); + g_Map.setVertexHeight(position, h + (n * pn)); } } Index: binaries/data/mods/public/maps/random/bahrain.js =================================================================== --- binaries/data/mods/public/maps/random/bahrain.js +++ binaries/data/mods/public/maps/random/bahrain.js @@ -158,7 +158,7 @@ for (let position of playerPosition) createArea( new ClumpPlacer(diskArea(defaultPlayerBaseRadius() * 0.8), 0.95, 0.6, Infinity, position), - new SmoothElevationPainter(ELEVATION_SET, g_Map.getHeight(position), 6)); + new SmoothElevationPainter(ELEVATION_SET, g_Map.getVertexHeight(position), 6)); } addElements([ Index: binaries/data/mods/public/maps/random/belgian_uplands.js =================================================================== --- binaries/data/mods/public/maps/random/belgian_uplands.js +++ binaries/data/mods/public/maps/random/belgian_uplands.js @@ -134,7 +134,7 @@ var textureMinHeight = heightRange.min; for (var i = 0; i < textueByHeight.length; i++) { - if (g_Map.getHeight(position) >= textureMinHeight && g_Map.getHeight(position) <= textueByHeight[i].upperHeightLimit) + if (g_Map.getVertexHeight(position) >= textureMinHeight && g_Map.getVertexHeight(position) <= textueByHeight[i].upperHeightLimit) { createTerrain(textueByHeight[i].terrain).place(position); Index: binaries/data/mods/public/maps/random/caledonian_meadows.js =================================================================== --- binaries/data/mods/public/maps/random/caledonian_meadows.js +++ binaries/data/mods/public/maps/random/caledonian_meadows.js @@ -196,7 +196,7 @@ /** * Base terrain shape generation and settings */ -let heightScale = (g_Map.size + 256) / 768 / 4; +let heightScale = (g_Map.getSize() + 256) / 768 / 4; let heightRange = { "min": MIN_HEIGHT * heightScale, "max": MAX_HEIGHT * heightScale }; // Water coverage @@ -299,7 +299,7 @@ for (let position of playerPosition) createArea( new DiskPlacer(35, position), - new SmoothElevationPainter(ELEVATION_SET, g_Map.getHeight(position), 35)); + new SmoothElevationPainter(ELEVATION_SET, g_Map.getVertexHeight(position), 35)); g_Map.log("Creating paths between players"); let clPath = g_Map.createTileClass(); @@ -330,7 +330,6 @@ /** * Divide tiles in areas by height and avoid paths */ -let tchm = getTileCenteredHeightmap(); let areas = heighLimits.map(heightLimit => []); for (let x = 0; x < tchm.length; ++x) for (let y = 0; y < tchm[0].length; ++y) @@ -342,7 +341,8 @@ let minHeight = heightRange.min; for (let h = 0; h < heighLimits.length; ++h) { - if (tchm[x][y] >= minHeight && tchm[x][y] <= heighLimits[h]) + const tileHeight = g_Map.getTileHeight(new Vector2D(x, y)); + if (tileHeight >= minHeight && tileHeight <= heighLimits[h]) { areas[h].push(position); break; Index: binaries/data/mods/public/maps/random/corinthian_isthmus.js =================================================================== --- binaries/data/mods/public/maps/random/corinthian_isthmus.js +++ binaries/data/mods/public/maps/random/corinthian_isthmus.js @@ -4,8 +4,6 @@ setSelectedBiome(); -TILE_CENTERED_HEIGHT_MAP = true; - const tCity = g_Terrains.road; const tCityPlaza = g_Terrains.roadWild; const tHill = g_Terrains.hill; Index: binaries/data/mods/public/maps/random/corsica.js =================================================================== --- binaries/data/mods/public/maps/random/corsica.js +++ binaries/data/mods/public/maps/random/corsica.js @@ -291,7 +291,7 @@ if (isSettlement) return undefined; - let height = g_Map.getHeight(position); + let height = g_Map.getVertexHeight(position); let slope = g_Map.getSlope(position); if (height >= 0.5 && height < 1.5 && isShore) Index: binaries/data/mods/public/maps/random/deep_forest.js =================================================================== --- binaries/data/mods/public/maps/random/deep_forest.js +++ binaries/data/mods/public/maps/random/deep_forest.js @@ -184,7 +184,7 @@ if (avoidClasses(clPath, 1, clHill, border ? 0 : 1).allows(position)) { createTerrain(border ? terrainWoodBorder : terrainWood).place(position); - g_Map.setHeight(position, randFloat(0, 1)); + g_Map.setVertexHeight(position, randFloat(0, 1)); clForest.add(position); } } @@ -192,7 +192,7 @@ // General height map let hVarMiddleHill = fractionToTiles(1 / 64) * (1 + Math.cos(3/2 * Math.PI * radius / mapRadius)); var hVarHills = 5 * (1 + Math.sin(x / 10) * Math.sin(z / 10)); - g_Map.setHeight(position, g_Map.getHeight(position) + hVarMiddleHill + hVarHills + 1); + g_Map.setVertexHeight(position, g_Map.getVertexHeight(position) + hVarMiddleHill + hVarHills + 1); } Engine.SetProgress(95); Index: binaries/data/mods/public/maps/random/dodecanese.js =================================================================== --- binaries/data/mods/public/maps/random/dodecanese.js +++ binaries/data/mods/public/maps/random/dodecanese.js @@ -1,8 +1,6 @@ Engine.LoadLibrary("rmgen"); Engine.LoadLibrary("rmgen-common"); -TILE_CENTERED_HEIGHT_MAP = true; - const tCity = "medit_city_pavement"; const tCityPlaza = "medit_city_pavement"; const tHill = ["medit_grass_shrubs", "medit_rocks_grass_shrubs", "medit_rocks_shrubs", "medit_rocks_grass", "medit_shrubs"]; @@ -363,7 +361,6 @@ ++bridges; // This bridge model is not centered on the horizontal plane, so the angle is messy - // TILE_CENTERED_HEIGHT_MAP also influences the outcome of the placement. let bridgeOrientation = direction % 2 ? 0 : Math.PI / 2; bridgeCenter1[direction % 2 ? "y" : "x"] += 0.25; bridgeCenter2[direction % 2 ? "y" : "x"] -= 0.25; Index: binaries/data/mods/public/maps/random/elephantine.js =================================================================== --- binaries/data/mods/public/maps/random/elephantine.js +++ binaries/data/mods/public/maps/random/elephantine.js @@ -18,8 +18,6 @@ Engine.LoadLibrary("rmgen"); Engine.LoadLibrary("rmgen-common"); -TILE_CENTERED_HEIGHT_MAP = true; - const tPrimary = ["savanna_dirt_rocks_a_red", "savanna_dirt_a_red", "savanna_dirt_b_red"]; const tDirt = ["new_savanna_dirt_c", "new_savanna_dirt_d", "savanna_dirt_b_red", "savanna_dirt_plants_cracked"]; const tWater = "desert_sand_wet"; Index: binaries/data/mods/public/maps/random/english_channel.js =================================================================== --- binaries/data/mods/public/maps/random/english_channel.js +++ binaries/data/mods/public/maps/random/english_channel.js @@ -107,7 +107,7 @@ createTerrain(height < -1.5 ? tWater : tShore).place(position); }, "landFunc": (position, shoreDist1, shoreDist2) => { - g_Map.setHeight(position, heightLand + 0.1); + g_Map.setVertexHeight(position, heightLand + 0.1); } }); Index: binaries/data/mods/public/maps/random/gear.js =================================================================== --- binaries/data/mods/public/maps/random/gear.js +++ binaries/data/mods/public/maps/random/gear.js @@ -2,8 +2,6 @@ Engine.LoadLibrary("rmgen-common"); Engine.LoadLibrary("rmbiome"); -TILE_CENTERED_HEIGHT_MAP = true; - setSelectedBiome(); const tMainTerrain = g_Terrains.mainTerrain; Index: binaries/data/mods/public/maps/random/guadalquivir_river.js =================================================================== --- binaries/data/mods/public/maps/random/guadalquivir_river.js +++ binaries/data/mods/public/maps/random/guadalquivir_river.js @@ -138,7 +138,7 @@ z > 0.5 && z < 0.6 || z > 0.7 && z < 0.8)) { - g_Map.setHeight(position, heightShallow); + g_Map.setVertexHeight(position, heightShallow); clShallow.add(position); } } Index: binaries/data/mods/public/maps/random/gulf_of_bothnia.js =================================================================== --- binaries/data/mods/public/maps/random/gulf_of_bothnia.js +++ binaries/data/mods/public/maps/random/gulf_of_bothnia.js @@ -2,8 +2,6 @@ Engine.LoadLibrary("rmgen-common"); Engine.LoadLibrary("rmbiome"); -TILE_CENTERED_HEIGHT_MAP = true; - if (g_MapSettings.Biome) setSelectedBiome(); else Index: binaries/data/mods/public/maps/random/heightmap/heightmap.js =================================================================== --- binaries/data/mods/public/maps/random/heightmap/heightmap.js +++ binaries/data/mods/public/maps/random/heightmap/heightmap.js @@ -4,11 +4,6 @@ * A heightmapt is an array of width arrays of height floats * Width and height is normally mapSize+1 (Number of vertices is one bigger than number of tiles in each direction) * The default heightmap is g_Map.height (See the Map object) - * - * @warning - Ambiguous naming and potential confusion: - * To use this library use TILE_CENTERED_HEIGHT_MAP = false (default) - * Otherwise TILE_CENTERED_HEIGHT_MAP has nothing to do with any tile centered map in this library - * @todo - TILE_CENTERED_HEIGHT_MAP should be removed and g_Map.height should never be tile centered */ /** @@ -230,10 +225,10 @@ * @param {Object} [avoidClass=undefined] - TileClass to be avoided * @param {integer} [minDistance=30] - How many tile widths the entities to place have to be away from each other, start locations and the map border * @param {array} [heightmap=g_Map.height] - The reliefmap the entities should be distributed on - * @param {integer} [maxTries=2 * g_Map.size] - How often random player distributions are rolled to be compared (256 to 1024) + * @param {integer} [maxTries=2 * g_Map.getSize()] - How often random player distributions are rolled to be compared (256 to 1024) * @param {boolean} [isCircular=g_MapSettings.CircularMap] - If the map is circular or rectangular */ -function getPointsByHeight(heightRange, avoidPoints = [], avoidClass = undefined, minDistance = 20, maxTries = 2 * g_Map.size, heightmap = g_Map.height, isCircular = g_MapSettings.CircularMap) +function getPointsByHeight(heightRange, avoidPoints = [], avoidClass = undefined, minDistance = 20, maxTries = 2 * g_Map.getSize(), heightmap = g_Map.height, isCircular = g_MapSettings.CircularMap) { const points = []; const placements = clone(avoidPoints); @@ -268,27 +263,6 @@ return points; } -/** - * Returns an approximation of the heights of the tiles between the vertices, a tile centered heightmap - * A tile centered heightmap is one smaller in width and height than an ordinary heightmap - * It is meant to e.g. texture a map by height (x/y coordinates correspond to those of the terrain texture map) - * Don't use this to override g_Map height (Potentially breaks the map)! - * @param {array} [heightmap=g_Map.height] - A reliefmap the tile centered version should be build from - */ -function getTileCenteredHeightmap(heightmap = g_Map.height) -{ - let max_x = heightmap.length - 1; - let max_y = heightmap[0].length - 1; - let tchm = []; - for (let x = 0; x < max_x; ++x) - { - tchm[x] = new Float32Array(max_y); - for (let y = 0; y < max_y; ++y) - tchm[x][y] = 0.25 * (heightmap[x][y] + heightmap[x + 1][y] + heightmap[x][y + 1] + heightmap[x + 1][y + 1]); - } - return tchm; -} - /** * Returns a slope map (same form as the a heightmap with one less width and height) * Not normalized. Only returns the steepness (float), not the direction of incline. Index: binaries/data/mods/public/maps/random/hellas.js =================================================================== --- binaries/data/mods/public/maps/random/hellas.js +++ binaries/data/mods/public/maps/random/hellas.js @@ -18,8 +18,6 @@ Engine.LoadLibrary("rmgen"); Engine.LoadLibrary("rmgen-common"); -TILE_CENTERED_HEIGHT_MAP = true; - var mapStyles = [ // mainland { @@ -192,7 +190,7 @@ for (let position of playerPosition) createArea( new ClumpPlacer(diskArea(playerRadius), 0.95, 0.6, Infinity, position), - new SmoothElevationPainter(ELEVATION_SET, g_Map.getHeight(position), playerRadius / 2)); + new SmoothElevationPainter(ELEVATION_SET, g_Map.getVertexHeight(position), playerRadius / 2)); Engine.SetProgress(38); } Index: binaries/data/mods/public/maps/random/islands.js =================================================================== --- binaries/data/mods/public/maps/random/islands.js +++ binaries/data/mods/public/maps/random/islands.js @@ -2,8 +2,6 @@ Engine.LoadLibrary("rmgen-common"); Engine.LoadLibrary("rmbiome"); -TILE_CENTERED_HEIGHT_MAP = true; - setSelectedBiome(); const tMainTerrain = g_Terrains.mainTerrain; Index: binaries/data/mods/public/maps/random/jebel_barkal.js =================================================================== --- binaries/data/mods/public/maps/random/jebel_barkal.js +++ binaries/data/mods/public/maps/random/jebel_barkal.js @@ -6,8 +6,6 @@ Engine.LoadLibrary("rmgen-common"); Engine.LoadLibrary("heightmap"); -TILE_CENTERED_HEIGHT_MAP = true; - const tSand = "desert_sand_dunes_100"; const tHilltop = ["new_savanna_dirt_c", "new_savanna_dirt_d"]; const tHillGround = ["savanna_dirt_rocks_a", "savanna_dirt_rocks_b", "savanna_dirt_rocks_c"]; @@ -348,7 +346,7 @@ minHeightSource, maxHeightSource)); -const heightDesert = g_Map.getHeight(mapCenter); +const heightDesert = g_Map.getVertexHeight(mapCenter); const heightFertileLand = heightDesert - heightScale(2); const heightShoreline = heightFertileLand - heightScale(0.5); const heightWaterLevel = heightFertileLand - heightScale(3); Index: binaries/data/mods/public/maps/random/latium.js =================================================================== --- binaries/data/mods/public/maps/random/latium.js +++ binaries/data/mods/public/maps/random/latium.js @@ -144,7 +144,7 @@ let c = startAngle ? z : x; let distToWater = clWater.has(position) ? 0 : (0.5 - WATER_WIDTH - Math.abs(c - 0.5)); - let h = distToWater ? heightHill * (1 - Math.abs(c - 0.5) / (0.5 - WATER_WIDTH)) : g_Map.getHeight(position); + let h = distToWater ? heightHill * (1 - Math.abs(c - 0.5) / (0.5 - WATER_WIDTH)) : g_Map.getVertexHeight(position); // add some base noise var baseNoise = 16*noise0.get(x,z) + 8*noise1.get(x,z) + 4*noise2.get(x,z) - (16+8+4)/2; @@ -181,7 +181,7 @@ if (cliffNoise > 0) h += 19 * Math.min(cliffNoise, 0.045) / 0.045; } - g_Map.setHeight(position, h); + g_Map.setVertexHeight(position, h); } Engine.SetProgress(20); @@ -205,7 +205,7 @@ let maxH = -Infinity; for (let vertex of g_TileVertices) { - let height = g_Map.getHeight(Vector2D.add(position, vertex)); + let height = g_Map.getVertexHeight(Vector2D.add(position, vertex)); minH = Math.min(minH, height); maxH = Math.max(maxH, height); } @@ -219,7 +219,7 @@ var maxNz = Math.min(iz + 2, mapSize); for (let nx = Math.max(ix - 1, 0); nx <= maxNx; ++nx) for (let nz = Math.max(iz - 1, 0); nz <= maxNz; ++nz) - minAdjHeight = Math.min(minAdjHeight, g_Map.getHeight(new Vector2D(nx, nz))); + minAdjHeight = Math.min(minAdjHeight, g_Map.getVertexHeight(new Vector2D(nx, nz))); } // choose a terrain based on elevation @@ -267,7 +267,7 @@ clCliff.add(position); // forests - if (g_Map.getHeight(position) < 11 && diffH < 2 && minH > 1) + if (g_Map.getVertexHeight(position) < 11 && diffH < 2 && minH > 1) { var forestNoise = (noise6.get(x,z) + 0.5*noise7.get(x,z)) / 1.5 * pn - 0.59; Index: binaries/data/mods/public/maps/random/lower_nubia.js =================================================================== --- binaries/data/mods/public/maps/random/lower_nubia.js +++ binaries/data/mods/public/maps/random/lower_nubia.js @@ -32,8 +32,6 @@ Engine.LoadLibrary("rmgen"); Engine.LoadLibrary("rmgen-common"); -TILE_CENTERED_HEIGHT_MAP = true; - const tSand = "desert_sand_dunes_100"; const tPlateau = ["savanna_dirt_a", "savanna_dirt_b"]; const tNilePlants = "desert_plants_a"; @@ -208,7 +206,7 @@ for (let position of playerPosition) createArea( new ClumpPlacer(diskArea(defaultPlayerBaseRadius() * 0.8), 0.95, 0.6, Infinity, position), - new SmoothElevationPainter(ELEVATION_SET, g_Map.getHeight(position), 6)); + new SmoothElevationPainter(ELEVATION_SET, g_Map.getVertexHeight(position), 6)); } Engine.SetProgress(43); Index: binaries/data/mods/public/maps/random/marmara.js =================================================================== --- binaries/data/mods/public/maps/random/marmara.js +++ binaries/data/mods/public/maps/random/marmara.js @@ -134,7 +134,7 @@ for (let position of playerPosition) createArea( new ClumpPlacer(diskArea(defaultPlayerBaseRadius() * 0.8), 0.95, 0.6, Infinity, position), - new SmoothElevationPainter(ELEVATION_SET, g_Map.getHeight(position), 6)); + new SmoothElevationPainter(ELEVATION_SET, g_Map.getVertexHeight(position), 6)); } Engine.SetProgress(50); Index: binaries/data/mods/public/maps/random/mediterranean.js =================================================================== --- binaries/data/mods/public/maps/random/mediterranean.js +++ binaries/data/mods/public/maps/random/mediterranean.js @@ -21,8 +21,6 @@ Engine.LoadLibrary("rmgen2"); Engine.LoadLibrary("rmbiome"); -TILE_CENTERED_HEIGHT_MAP = true; - const tWater = "medit_sand_wet"; const tSnowedRocks = ["alpine_cliff_b", "alpine_cliff_snow"]; setBiome("generic/aegean"); @@ -178,7 +176,7 @@ createArea( new ClumpPlacer(diskArea(defaultPlayerBaseRadius() * 0.8), 0.95, 0.6, Infinity, playerPosition[i]), - new SmoothElevationPainter(ELEVATION_SET, g_Map.getHeight(playerPosition[i]), 6)); + new SmoothElevationPainter(ELEVATION_SET, g_Map.getVertexHeight(playerPosition[i]), 6)); createBase(playerIDs[i], playerPosition[i], mapSize >= 384); } Index: binaries/data/mods/public/maps/random/ngorongoro.js =================================================================== --- binaries/data/mods/public/maps/random/ngorongoro.js +++ binaries/data/mods/public/maps/random/ngorongoro.js @@ -151,7 +151,7 @@ for (let position of playerPosition) createArea( new ClumpPlacer(diskArea(defaultPlayerBaseRadius() * 0.8), 0.95, 0.6, Infinity, position), - new SmoothElevationPainter(ELEVATION_SET, g_Map.getHeight(position), 6)); + new SmoothElevationPainter(ELEVATION_SET, g_Map.getVertexHeight(position), 6)); } g_Map.log("Render lowlands"); Index: binaries/data/mods/public/maps/random/oasis.js =================================================================== --- binaries/data/mods/public/maps/random/oasis.js +++ binaries/data/mods/public/maps/random/oasis.js @@ -273,7 +273,7 @@ for (var sandz = 0; sandz < mapSize; sandz += 4) { let position = new Vector2D(sandx, sandz); - let height = g_Map.getHeight(position); + let height = g_Map.getVertexHeight(position); if (height > heightSand) { Index: binaries/data/mods/public/maps/random/phoenician_levant.js =================================================================== --- binaries/data/mods/public/maps/random/phoenician_levant.js +++ binaries/data/mods/public/maps/random/phoenician_levant.js @@ -1,8 +1,6 @@ Engine.LoadLibrary("rmgen"); Engine.LoadLibrary("rmgen-common"); -//TILE_CENTERED_HEIGHT_MAP = true; - const tCity = "medit_city_pavement"; const tCityPlaza = "medit_city_pavement"; const tHill = ["medit_dirt", "medit_dirt_b", "medit_dirt_c", "medit_rocks_grass", "medit_rocks_grass"]; Index: binaries/data/mods/public/maps/random/pompeii.js =================================================================== --- binaries/data/mods/public/maps/random/pompeii.js +++ binaries/data/mods/public/maps/random/pompeii.js @@ -177,7 +177,7 @@ for (let position of playerPosition) createArea( new ClumpPlacer(diskArea(defaultPlayerBaseRadius() * 0.8), 0.95, 0.6, Infinity, position), - new SmoothElevationPainter(ELEVATION_SET, g_Map.getHeight(position), 6)); + new SmoothElevationPainter(ELEVATION_SET, g_Map.getVertexHeight(position), 6)); } Engine.SetProgress(50); Index: binaries/data/mods/public/maps/random/pyrenean_sierra.js =================================================================== --- binaries/data/mods/public/maps/random/pyrenean_sierra.js +++ binaries/data/mods/public/maps/random/pyrenean_sierra.js @@ -1,6 +1,6 @@ Engine.LoadLibrary("rmgen"); Engine.LoadLibrary("rmgen-common"); -TILE_CENTERED_HEIGHT_MAP = true; +Engine.LoadLibrary("heightmap"); const tGrassSpecific = ["new_alpine_grass_d","new_alpine_grass_d", "new_alpine_grass_e"]; const tGrass = ["new_alpine_grass_d", "new_alpine_grass_b", "new_alpine_grass_e"]; @@ -143,16 +143,16 @@ g_Map.log("Creating initial sinusoidal noise"); var baseHeights = []; -for (var ix = 0; ix < mapSize; ix++) +for (var ix = 0; ix <= mapSize; ix++) { baseHeights.push([]); - for (var iz = 0; iz < mapSize; iz++) + for (var iz = 0; iz <= mapSize; iz++) { let position = new Vector2D(ix, iz); if (g_Map.inMapBounds(position)) { let height = heightBase + randFloat(-1, 1) + scaleByMapSize(1, 3) * (Math.cos(ix / scaleByMapSize(5, 30)) + Math.sin(iz / scaleByMapSize(5, 30))); - g_Map.setHeight(position, height); + g_Map.setVertexHeight(position, height); baseHeights[ix].push(height); } else @@ -244,7 +244,7 @@ new Vector2D(distance, 0).rotate(-startAngle - direction * Math.PI / 2) ]).round(); - g_Map.setHeight(pos, baseHeights[pos.x][pos.y] + (heightMountain + peakHeight + randFloat(-9, 9)) * sigmoid(sigmoidX, peakPosition)); + g_Map.setVertexHeight(pos, baseHeights[pos.x][pos.y] + (heightMountain + peakHeight + randFloat(-9, 9)) * sigmoid(sigmoidX, peakPosition)); } } } @@ -343,7 +343,7 @@ for (let z = 0; z < mapSize; ++z) { let position = new Vector2D(x, z); - let height = g_Map.getHeight(position); + let height = g_Map.getVertexHeight(position); let heightDiff = g_Map.getSlope(position); let terrainShore = getShoreTerrain(position, height, heightDiff); @@ -447,7 +447,10 @@ g_Map.log("Creating fish"); group = new SimpleGroup( [new SimpleObject(oFish, 2,3, 0,2)], true, clFood ); -createObjectGroupsDeprecated(group, 0, [avoidClasses(clFood, 15), stayClasses(clWater, 6)], 20 * numPlayers, 60 ); +createObjectGroupsDeprecated(group, 0, [avoidClasses(clFood, 15), stayClasses(clWater, 6)], 20 * numPlayers, 60); + +g_Map.log("Smoothing elevations"); +splashErodeMap(); placePlayersNomad(clPlayer, avoidClasses(clWater, 4, clPyrenneans, 4, clForest, 1, clMetal, 4, clRock, 4, clFood, 2)); Index: binaries/data/mods/public/maps/random/red_sea.js =================================================================== --- binaries/data/mods/public/maps/random/red_sea.js +++ binaries/data/mods/public/maps/random/red_sea.js @@ -20,8 +20,6 @@ Engine.LoadLibrary("rmgen2"); Engine.LoadLibrary("rmbiome"); -TILE_CENTERED_HEIGHT_MAP = true; - setBiome("generic/sahara"); g_Terrains.mainTerrain = new Array(4).fill("desert_sand_dunes_50").concat(["desert_sand_dunes_rocks", "desert_dirt_rough_2"]); @@ -133,7 +131,7 @@ for (let position of playerPosition) createArea( new ClumpPlacer(diskArea(defaultPlayerBaseRadius() * 0.8), 0.95, 0.6, Infinity, position), - new SmoothElevationPainter(ELEVATION_SET, g_Map.getHeight(position), 6)); + new SmoothElevationPainter(ELEVATION_SET, g_Map.getVertexHeight(position), 6)); } addElements(shuffleArray([ Index: binaries/data/mods/public/maps/random/rivers.js =================================================================== --- binaries/data/mods/public/maps/random/rivers.js +++ binaries/data/mods/public/maps/random/rivers.js @@ -141,11 +141,13 @@ let newHeight = isShallow ? heightShallows : Math.max(height, heightSeaGround); - if (g_Map.getHeight(position) < newHeight) + let tileHeight = g_Map.getTileHeight(position); + if (tileHeight < newHeight) return; - g_Map.setHeight(position, newHeight); - createTerrain(height >= 0 ? tShore : tWater).place(position); + g_Map.setVertexHeight(position, newHeight); + createTerrain(tileHeight >= 0 ? tShore : tWater).place(position); + warn(`${tileHeight} == ${height}`); if (isShallow) clShallow.add(position); Index: binaries/data/mods/public/maps/random/rmgen-common/gaia_terrain.js =================================================================== --- binaries/data/mods/public/maps/random/rmgen-common/gaia_terrain.js +++ binaries/data/mods/public/maps/random/rmgen-common/gaia_terrain.js @@ -190,10 +190,10 @@ if (distance > radius) continue; - if (g_Map.getHeight(position) < newHeight) - g_Map.setHeight(position, newHeight); - else if (g_Map.getHeight(position) >= newHeight && g_Map.getHeight(position) < newHeight + 4) - g_Map.setHeight(position, newHeight + 4); + if (g_Map.getVertexHeight(position) < newHeight) + g_Map.setVertexHeight(position, newHeight); + else if (g_Map.getVertexHeight(position) >= newHeight && g_Map.getVertexHeight(position) < newHeight + 4) + g_Map.setVertexHeight(position, newHeight + 4); if (terrain) createTerrain(terrain).place(position); @@ -405,7 +405,7 @@ height += (args.heightLand - args.heightRiverbed) * (1 - shoreDist2 / args.fadeDist); if (args.minHeight === undefined || height < args.minHeight) - g_Map.setHeight(vecPoint, height); + g_Map.setVertexHeight(vecPoint, height); if (args.waterFunc) args.waterFunc(vecPoint, height, riverFraction); @@ -538,8 +538,8 @@ { let bound = x => Math.max(0, Math.min(Math.round(x), g_Map.height.length - 1)); - let startHeight = args.startHeight !== undefined ? args.startHeight : g_Map.getHeight(new Vector2D(bound(args.start.x), bound(args.start.y))); - let endHeight = args.endHeight !== undefined ? args.endHeight : g_Map.getHeight(new Vector2D(bound(args.end.x), bound(args.end.y))); + let startHeight = args.startHeight !== undefined ? args.startHeight : g_Map.getVertexHeight(new Vector2D(bound(args.start.x), bound(args.start.y))); + let endHeight = args.endHeight !== undefined ? args.endHeight : g_Map.getVertexHeight(new Vector2D(bound(args.end.x), bound(args.end.y))); let passageVec = Vector2D.sub(args.end, args.start); let widthDirection = passageVec.perpendicular().normalize(); @@ -566,10 +566,10 @@ let smoothDistance = args.smoothWidth + Math.abs(stepWidth) - halfPassageWidth; - g_Map.setHeight( + g_Map.setVertexHeight( location, smoothDistance > 0 ? - (g_Map.getHeight(location) * smoothDistance + passageHeight / smoothDistance) / (smoothDistance + 1 / smoothDistance) : + (g_Map.getVertexHeight(location) * smoothDistance + passageHeight / smoothDistance) / (smoothDistance + 1 / smoothDistance) : passageHeight); if (args.tileClass) @@ -600,8 +600,8 @@ let ipos = pos.clone().round(); if (g_Map.validHeight(ipos) && - g_Map.getHeight(ipos) >= minHeight && - g_Map.getHeight(ipos) <= maxHeight) + g_Map.getVertexHeight(ipos) >= minHeight && + g_Map.getVertexHeight(ipos) <= maxHeight) return pos.add(stepVec.mult(offset)); } Index: binaries/data/mods/public/maps/random/rmgen/Constraint.js =================================================================== --- binaries/data/mods/public/maps/random/rmgen/Constraint.js +++ binaries/data/mods/public/maps/random/rmgen/Constraint.js @@ -188,7 +188,7 @@ HeightConstraint.prototype.allows = function(position) { - return this.minHeight <= g_Map.getHeight(position) && g_Map.getHeight(position) <= this.maxHeight; + return this.minHeight <= g_Map.getTileHeight(position) && g_Map.getTileHeight(position) <= this.maxHeight; }; /** Index: binaries/data/mods/public/maps/random/rmgen/RandomMap.js =================================================================== --- binaries/data/mods/public/maps/random/rmgen/RandomMap.js +++ binaries/data/mods/public/maps/random/rmgen/RandomMap.js @@ -9,7 +9,8 @@ this.logger = new RandomMapLogger(); // Size must be 0 to 1024, divisible by patches - this.size = g_MapSettings.Size; + this.tileCount = g_MapSettings.Size; + this.verticesCount = this.tileCount + 1; // Create name <-> id maps for textures this.nameToID = {}; @@ -17,11 +18,11 @@ // Texture 2D array this.texture = []; - for (let x = 0; x < this.size; ++x) + for (let x = 0; x < this.tileCount; ++x) { - this.texture[x] = new Uint16Array(this.size); + this.texture[x] = new Uint16Array(this.tileCount); - for (let z = 0; z < this.size; ++z) + for (let z = 0; z < this.tileCount; ++z) this.texture[x][z] = this.getTextureID( typeof baseTerrain == "string" ? baseTerrain : pickRandom(baseTerrain)); } @@ -29,24 +30,20 @@ // Create 2D arrays for terrain objects and areas this.terrainEntities = []; - for (let i = 0; i < this.size; ++i) + for (let i = 0; i < this.tileCount; ++i) { this.terrainEntities[i] = []; - for (let j = 0; j < this.size; ++j) + for (let j = 0; j < this.tileCount; ++j) this.terrainEntities[i][j] = undefined; } // Create 2D array for heightmap - let mapSize = this.size; - if (!TILE_CENTERED_HEIGHT_MAP) - ++mapSize; - this.height = []; - for (let i = 0; i < mapSize; ++i) + for (let i = 0; i < this.verticesCount; ++i) { - this.height[i] = new Float32Array(mapSize); + this.height[i] = new Float32Array(this.verticesCount); - for (let j = 0; j < mapSize; ++j) + for (let j = 0; j < this.verticesCount; ++j) this.height[i][j] = baseHeight; } @@ -135,10 +132,10 @@ RandomMap.prototype.getSize = function() { - return this.size; + return this.tileCount; }; -RandomMap.prototype.getArea = function(size = this.size) +RandomMap.prototype.getArea = function (size = this.tileCount) { return this.isCircularMap ? diskArea(size / 2) : size * size; }; @@ -148,18 +145,18 @@ */ RandomMap.prototype.getCenter = function() { - return deepfreeze(new Vector2D(this.size / 2, this.size / 2)); + return deepfreeze(new Vector2D(this.tileCount / 2, this.tileCount / 2)); }; /** - * Returns a human-readable reference to the smallest and greatest coordinates of the map. + * Returns a human-readable reference to the smallest and greatest tiles' coordinates of the map. */ RandomMap.prototype.getBounds = function() { return deepfreeze({ "left": 0, - "right": this.size, - "top": this.size, + "right": this.tileCount, + "top": this.tileCount, "bottom": 0 }); }; @@ -173,9 +170,9 @@ RandomMap.prototype.validTile = function(position, distance = 0) { if (this.isCircularMap()) - return Math.round(position.distanceTo(this.getCenter())) < this.size / 2 - distance - 1; + return Math.round(position.distanceTo(this.getCenter())) < this.tileCount / 2 - distance - 1; - return position.x >= distance && position.y >= distance && position.x < this.size - distance && position.y < this.size - distance; + return position.x >= distance && position.y >= distance && position.x < this.tileCount - distance && position.y < this.tileCount - distance; }; /** @@ -188,27 +185,24 @@ }; /** - * Determines whether the given coordinates are within the tile grid, passable or not. + * Determines whether the given tile coordinates are within the tile grid, passable or not. * Should be used to restrict texture painting. */ RandomMap.prototype.inMapBounds = function(position) { - return position.x >= 0 && position.y >= 0 && position.x < this.size && position.y < this.size; + return position.x >= 0 && position.y >= 0 && position.x < this.tileCount && position.y < this.tileCount; }; /** - * Determines whether the given coordinates are within the heightmap grid. + * Determines whether the given vertex coordinates are within the heightmap grid. * Should be used to restrict elevation changes. */ -RandomMap.prototype.validHeight = function(position) +RandomMap.prototype.validVertex = function (position) { if (position.x < 0 || position.y < 0) return false; - if (TILE_CENTERED_HEIGHT_MAP) - return position.x < this.size && position.y < this.size; - - return position.x <= this.size && position.y <= this.size; + return position.x < this.verticesCount && position.y < this.verticesCount; }; /** @@ -224,12 +218,12 @@ // Uniformly distributed on the disk return Vector2D.add( this.getCenter(), - new Vector2D((this.size / 2 - border) * Math.sqrt(randFloat(0, 1)), 0).rotate(randomAngle()).floor()); + new Vector2D((this.tileCount / 2 - border) * Math.sqrt(randFloat(0, 1)), 0).rotate(randomAngle()).floor()); // Rectangular coordinates return new Vector2D( - randIntExclusive(border, this.size - border), - randIntExclusive(border, this.size - border)); + randIntExclusive(border, this.tileCount - border), + randIntExclusive(border, this.tileCount - border)); }; /** @@ -257,18 +251,42 @@ this.texture[position.x][position.y] = this.getTextureID(texture); }; -RandomMap.prototype.getHeight = function(position) +RandomMap.prototype.getTileHeight = function (position) { - if (!this.validHeight(position)) - throw new Error("getHeight: invalid vertex position " + uneval(position)); + let heightSum = 0; + + for (let delta of g_TileVertices) + { + let vertex = Vector2D.add(position, delta); + if (g_Map.validVertex(vertex)) + heightSum += g_Map.getVertexHeight(vertex); + } + + return heightSum / 4; +}; + +RandomMap.prototype.setTileHeight = function (position, height) +{ + for (let delta of g_TileVertices) + { + let vertex = Vector2D.add(position, delta); + if (g_Map.validVertex(vertex)) + g_Map.setVertexHeight(vertex, height); + } +}; + +RandomMap.prototype.getVertexHeight = function (position) +{ + if (!this.validVertex(position)) + throw new Error("getVertexHeight: invalid vertex position " + uneval(position)); return this.height[position.x][position.y]; }; -RandomMap.prototype.setHeight = function(position, height) +RandomMap.prototype.setVertexHeight = function (position, height) { - if (!this.validHeight(position)) - throw new Error("setHeight: invalid vertex position " + uneval(position)); + if (!this.validVertex(position)) + throw new Error("setVertexHeight: invalid vertex position " + uneval(position)); this.height[position.x][position.y] = height; }; @@ -329,7 +347,7 @@ RandomMap.prototype.createTileClass = function() { - return new TileClass(this.size); + return new TileClass(this.tileCount); }; /** @@ -337,8 +355,8 @@ */ RandomMap.prototype.getExactHeight = function(position) { - let xi = Math.min(Math.floor(position.x), this.size); - let zi = Math.min(Math.floor(position.y), this.size); + let xi = Math.min(Math.floor(position.x), this.tileCount); + let zi = Math.min(Math.floor(position.y), this.tileCount); let xf = position.x - xi; let zf = position.y - zi; @@ -350,28 +368,6 @@ return (1 - zf) * ((1 - xf) * h00 + xf * h10) + zf * ((1 - xf) * h01 + xf * h11); }; -// Converts from the tile centered height map to the corner based height map, used when TILE_CENTERED_HEIGHT_MAP = true -RandomMap.prototype.cornerHeight = function(position) -{ - let count = 0; - let sumHeight = 0; - - for (let vertex of g_TileVertices) - { - let pos = Vector2D.sub(position, vertex); - if (this.validHeight(pos)) - { - ++count; - sumHeight += this.getHeight(pos); - } - } - - if (!count) - return 0; - - return sumHeight / count; -}; - RandomMap.prototype.getAdjacentPoints = function(position) { let adjacentPositions = []; @@ -395,7 +391,7 @@ if (!adjacentPositions.length) return 0; - return adjacentPositions.reduce((totalHeight, pos) => totalHeight + this.getHeight(pos), 0) / adjacentPositions.length; + return adjacentPositions.reduce((totalHeight, pos) => totalHeight + this.getTileHeight(pos), 0) / adjacentPositions.length; }; /** @@ -408,7 +404,7 @@ return 0; return adjacentPositions.reduce((totalSlope, adjacentPos) => - totalSlope + Math.abs(this.getHeight(adjacentPos) - this.getHeight(position)), 0) / adjacentPositions.length; + totalSlope + Math.abs(this.getTileHeight(adjacentPos) - this.getTileHeight(position)), 0) / adjacentPositions.length; }; /** @@ -423,8 +419,8 @@ entity.rotation.y = Math.PI / 2 - entity.rotation.y; // Terrain objects e.g. trees - for (let x = 0; x < this.size; ++x) - for (let z = 0; z < this.size; ++z) + for (let x = 0; x < this.tileCount; ++x) + for (let z = 0; z < this.tileCount; ++z) if (this.terrainEntities[x][z]) this.entities.push(this.terrainEntities[x][z]); @@ -441,14 +437,14 @@ */ RandomMap.prototype.exportHeightData = function() { - let heightmapSize = this.size + 1; + let heightmapSize = this.tileCount + 1; let heightmap = new Uint16Array(Math.square(heightmapSize)); for (let x = 0; x < heightmapSize; ++x) for (let z = 0; z < heightmapSize; ++z) { let position = new Vector2D(x, z); - let currentHeight = TILE_CENTERED_HEIGHT_MAP ? this.cornerHeight(position) : this.getHeight(position); + let currentHeight = this.getVertexHeight(position); // Correct height by SEA_LEVEL and prevent under/overflow in terrain data heightmap[z * heightmapSize + x] = Math.max(0, Math.min(0xFFFF, Math.floor((currentHeight + SEA_LEVEL) * HEIGHT_UNITS_PER_METRE))); @@ -462,15 +458,15 @@ */ RandomMap.prototype.exportTerrainTextures = function() { - let tileIndex = new Uint16Array(Math.square(this.size)); - let tilePriority = new Uint16Array(Math.square(this.size)); + let tileIndex = new Uint16Array(Math.square(this.tileCount)); + let tilePriority = new Uint16Array(Math.square(this.tileCount)); - for (let x = 0; x < this.size; ++x) - for (let z = 0; z < this.size; ++z) + for (let x = 0; x < this.tileCount; ++x) + for (let z = 0; z < this.tileCount; ++z) { // TODO: For now just use the texture's index as priority, might want to do this another way - tileIndex[z * this.size + x] = this.texture[x][z]; - tilePriority[z * this.size + x] = this.texture[x][z]; + tileIndex[z * this.tileCount + x] = this.texture[x][z]; + tilePriority[z * this.tileCount + x] = this.texture[x][z]; } return { @@ -490,7 +486,7 @@ "entities": this.exportEntityList(), "height": this.exportHeightData(), "seaLevel": SEA_LEVEL, - "size": this.size, + "size": this.tileCount, "textureNames": this.IDToName, "tileData": this.exportTerrainTextures(), "Camera": g_Camera, Index: binaries/data/mods/public/maps/random/rmgen/library.js =================================================================== --- binaries/data/mods/public/maps/random/rmgen/library.js +++ binaries/data/mods/public/maps/random/rmgen/library.js @@ -38,11 +38,6 @@ const g_ActorPrefix = "actor|"; -/** - * Sets whether setHeight operates on the center of a tile or on the vertices. - */ -var TILE_CENTERED_HEIGHT_MAP = false; - function actorTemplate(templateName) { return g_ActorPrefix + templateName + ".xml"; Index: binaries/data/mods/public/maps/random/rmgen/painter/ElevationBlendingPainter.js =================================================================== --- binaries/data/mods/public/maps/random/rmgen/painter/ElevationBlendingPainter.js +++ binaries/data/mods/public/maps/random/rmgen/painter/ElevationBlendingPainter.js @@ -10,5 +10,5 @@ ElevationBlendingPainter.prototype.paint = function(area) { for (let point of area.getPoints()) - g_Map.setHeight(point, this.strength * this.targetHeight + (1 - this.strength) * g_Map.getHeight(point)); + g_Map.setVertexHeight(point, this.strength * this.targetHeight + (1 - this.strength) * g_Map.getVertexHeight(point)); }; Index: binaries/data/mods/public/maps/random/rmgen/painter/ElevationPainter.js =================================================================== --- binaries/data/mods/public/maps/random/rmgen/painter/ElevationPainter.js +++ binaries/data/mods/public/maps/random/rmgen/painter/ElevationPainter.js @@ -9,10 +9,5 @@ ElevationPainter.prototype.paint = function(area) { for (let point of area.getPoints()) - for (let vertex of g_TileVertices) - { - let position = Vector2D.add(point, vertex); - if (g_Map.validHeight(position)) - g_Map.setHeight(position, this.elevation); - } + g_Map.setTileHeight(point, this.elevation); }; Index: binaries/data/mods/public/maps/random/rmgen/painter/HeightmapPainter.js =================================================================== --- binaries/data/mods/public/maps/random/rmgen/painter/HeightmapPainter.js +++ binaries/data/mods/public/maps/random/rmgen/painter/HeightmapPainter.js @@ -18,7 +18,7 @@ HeightmapPainter.prototype.getScale = function() { - return this.verticesPerSide / (g_Map.getSize() + 1); + return this.verticesPerSide / (g_Map.getSize()); }; HeightmapPainter.prototype.scaleHeight = function(height) @@ -26,8 +26,8 @@ if (this.normalMinHeight === undefined || this.normalMaxHeight === undefined) return height / this.getScale() / HEIGHT_UNITS_PER_METRE; - let minHeight = this.normalMinHeight * (g_Map.getSize() + 1) / 321; - let maxHeight = this.normalMaxHeight * (g_Map.getSize() + 1) / 321; + let minHeight = this.normalMinHeight * (g_Map.getSize()) / 321; + let maxHeight = this.normalMaxHeight * (g_Map.getSize()) / 321; return minHeight + (maxHeight - minHeight) * height / 0xFFFF; }; @@ -48,7 +48,7 @@ { let vertexPos = Vector2D.add(point, vertex); - if (!g_Map.validHeight(vertexPos) || seen[vertexPos.x][vertexPos.y]) + if (!g_Map.validVertex(vertexPos) || seen[vertexPos.x][vertexPos.y]) continue; seen[vertexPos.x][vertexPos.y] = 1; @@ -62,7 +62,7 @@ Vector2D.sub(sourceTilePos, brushCenter), Vector2D.sub(rightTop, brushSize).sub(brushCenter))); - g_Map.setHeight(vertexPos, bicubicInterpolation( + g_Map.setVertexHeight(vertexPos, bicubicInterpolation( Vector2D.sub(sourcePos, brushPosition).sub(brushCenter), ...getPointsInBoundingBox(getBoundingBox([brushPosition, Vector2D.add(brushPosition, brushSize)])).map(pos => this.scaleHeight(this.heightmap[pos.x][pos.y])))); Index: binaries/data/mods/public/maps/random/rmgen/painter/RandomElevationPainter.js =================================================================== --- binaries/data/mods/public/maps/random/rmgen/painter/RandomElevationPainter.js +++ binaries/data/mods/public/maps/random/rmgen/painter/RandomElevationPainter.js @@ -10,10 +10,5 @@ RandomElevationPainter.prototype.paint = function(area) { for (let point of area.getPoints()) - for (let vertex of g_TileVertices) - { - let position = Vector2D.add(point, vertex); - if (g_Map.validHeight(position)) - g_Map.setHeight(position, randFloat(this.minHeight, this.maxHeight)); - } + g_Map.setTileHeight(point, randFloat(this.minHeight, this.maxHeight)); }; Index: binaries/data/mods/public/maps/random/rmgen/painter/SmoothElevationPainter.js =================================================================== --- binaries/data/mods/public/maps/random/rmgen/painter/SmoothElevationPainter.js +++ binaries/data/mods/public/maps/random/rmgen/painter/SmoothElevationPainter.js @@ -54,9 +54,9 @@ let nz = point.y + dz; let position = new Vector2D(nx, nz); - if (g_Map.validHeight(position) && !gotHeightPt[nx][nz]) + if (g_Map.validVertex(position) && !gotHeightPt[nx][nz]) { - newHeight[nx][nz] = g_Map.getHeight(position); + newHeight[nx][nz] = g_Map.getVertexHeight(position); gotHeightPt[nx][nz] = 1; heightPoints.push(position); } @@ -77,7 +77,7 @@ a = (distance - 1) / this.blendRadius; if (this.type == ELEVATION_SET) - newHeight[point.x][point.y] = (1 - a) * g_Map.getHeight(point); + newHeight[point.x][point.y] = (1 - a) * g_Map.getVertexHeight(point); newHeight[point.x][point.y] += a * this.elevation + randFloat(-0.5, 0.5) * this.randomElevation; } @@ -100,7 +100,7 @@ { let nz = point.y + dz; - if (g_Map.validHeight(new Vector2D(nx, nz))) + if (g_Map.validVertex(new Vector2D(nx, nz))) { sum += newHeight[nx][nz]; ++count; @@ -108,7 +108,7 @@ } } - g_Map.setHeight(point, (newHeight[point.x][point.y] + sum / count) / 2); + g_Map.setVertexHeight(point, (newHeight[point.x][point.y] + sum / count) / 2); } }; Index: binaries/data/mods/public/maps/random/rmgen/painter/SmoothingPainter.js =================================================================== --- binaries/data/mods/public/maps/random/rmgen/painter/SmoothingPainter.js +++ binaries/data/mods/public/maps/random/rmgen/painter/SmoothingPainter.js @@ -37,7 +37,7 @@ for (let tileVertex of g_TileVertices) { let vertex = Vector2D.add(point, tileVertex); - if (!g_Map.validHeight(vertex) || seen[vertex.x][vertex.y]) + if (!g_Map.validVertex(vertex) || seen[vertex.x][vertex.y]) continue; seen[vertex.x][vertex.y] = 1; @@ -49,17 +49,17 @@ { let position = Vector2D.add(vertex, brushPoint); let distance = Math.abs(brushPoint.x) + Math.abs(brushPoint.y); - if (!distance || !g_Map.validHeight(position)) + if (!distance || !g_Map.validVertex(position)) continue; - sumWeightedHeights += g_Map.getHeight(position) / distance; + sumWeightedHeights += g_Map.getVertexHeight(position) / distance; sumWeights += 1 / distance; } - g_Map.setHeight( + g_Map.setVertexHeight( vertex, this.strength * sumWeightedHeights / sumWeights + - (1 - this.strength) * g_Map.getHeight(vertex)); + (1 - this.strength) * g_Map.getVertexHeight(vertex)); } } }; Index: binaries/data/mods/public/maps/random/rmgen/placer/noncentered/HeightPlacer.js =================================================================== --- binaries/data/mods/public/maps/random/rmgen/placer/noncentered/HeightPlacer.js +++ binaries/data/mods/public/maps/random/rmgen/placer/noncentered/HeightPlacer.js @@ -12,17 +12,27 @@ */ function HeightPlacer(mode, minElevation, maxElevation) { - this.withinHeightRange = - mode == Elevation_ExcludeMin_ExcludeMax ? position => g_Map.getHeight(position) > minElevation && g_Map.getHeight(position) < maxElevation : - mode == Elevation_IncludeMin_ExcludeMax ? position => g_Map.getHeight(position) >= minElevation && g_Map.getHeight(position) < maxElevation : - mode == Elevation_ExcludeMin_IncludeMax ? position => g_Map.getHeight(position) > minElevation && g_Map.getHeight(position) <= maxElevation : - mode == Elevation_IncludeMin_IncludeMax ? position => g_Map.getHeight(position) >= minElevation && g_Map.getHeight(position) <= maxElevation : - undefined; - - if (!this.withinHeightRange) + if (mode < 0 || mode > 3) throw new Error("Invalid HeightPlacer mode: " + mode); + + this.mode = mode; + this.minElevation = minElevation; + this.maxElevation = maxElevation; } +HeightPlacer.prototype.withinHeightRange = function (position) +{ + let actualMin = this.minElevation; + let actualMax = this.maxElevation; + if (this.mode == Elevation_IncludeMin_ExcludeMax || this.mode == Elevation_IncludeMin_IncludeMax) + actualMin = actualMin - 1; + + if (this.mode == Elevation_ExcludeMin_IncludeMax || this.mode == Elevation_IncludeMin_IncludeMax) + actualMax = actualMax + 1; + + return g_Map.getTileHeight(position) > actualMin && g_Map.getTileHeight(position) < actualMax; +}; + HeightPlacer.prototype.place = function(constraint) { let mapSize = g_Map.getSize(); Index: binaries/data/mods/public/maps/random/rmgen2/gaia.js =================================================================== --- binaries/data/mods/public/maps/random/rmgen2/gaia.js +++ binaries/data/mods/public/maps/random/rmgen2/gaia.js @@ -43,7 +43,7 @@ if (g_TileClasses.forest.has(end) || !stayClasses(g_TileClasses.bluff, 12).allows(end)) continue; - if ((g_Map.getHeight(end.clone().floor()) - g_Map.getHeight(start.clone().floor())) / start.distanceTo(end) > 1.5) + if ((g_Map.getVertexHeight(end.clone().floor()) - g_Map.getVertexHeight(start.clone().floor())) / start.distanceTo(end) > 1.5) continue; let area = createPassage({ @@ -153,7 +153,7 @@ for (let point of areasBluff[0].getPoints()) { let dist = Math.abs(distanceOfPointFromLine(baseLine.start, baseLine.end, point)); - g_Map.setHeight(point, Math.max(g_Map.getHeight(point) * (1 - dist / slopeLength) - 2, baseHeight)); + g_Map.setVertexHeight(point, Math.max(g_Map.getVertexHeight(point) * (1 - dist / slopeLength) - 2, baseHeight)); } // Flatten all points adjacent to but not on the bluff Index: binaries/data/mods/public/maps/random/schwarzwald.js =================================================================== --- binaries/data/mods/public/maps/random/schwarzwald.js +++ binaries/data/mods/public/maps/random/schwarzwald.js @@ -104,7 +104,7 @@ // Set height limits and water level by map size. // Set target min and max height depending on map size to make average steepness about the same on all map sizes. -var heightRange = { 'min': MIN_HEIGHT * (g_Map.size + 512) / 8192, 'max': MAX_HEIGHT * (g_Map.size + 512) / 8192, 'avg': (MIN_HEIGHT * (g_Map.size + 512) + MAX_HEIGHT * (g_Map.size + 512)) / 16384 }; +var heightRange = { 'min': MIN_HEIGHT * (g_Map.getSize() + 512) / 8192, 'max': MAX_HEIGHT * (g_Map.getSize() + 512) / 8192, 'avg': (MIN_HEIGHT * (g_Map.getSize() + 512) + MAX_HEIGHT * (g_Map.getSize() + 512)) / 16384 }; // Set average water coverage. var averageWaterCoverage = 1/5; // NOTE: Since erosion is not predictable actual water coverage might vary much with the same values. @@ -147,7 +147,7 @@ createArea( new ClumpPlacer(diskArea(20), 0.8, 0.8, Infinity, playerPosition[i]), - new SmoothElevationPainter(ELEVATION_SET, g_Map.getHeight(playerPosition[i]), 20)); + new SmoothElevationPainter(ELEVATION_SET, g_Map.getVertexHeight(playerPosition[i]), 20)); } placePlayerBases({ Index: binaries/data/mods/public/maps/random/snowflake_searocks.js =================================================================== --- binaries/data/mods/public/maps/random/snowflake_searocks.js +++ binaries/data/mods/public/maps/random/snowflake_searocks.js @@ -2,8 +2,6 @@ Engine.LoadLibrary("rmgen-common"); Engine.LoadLibrary("rmbiome"); -TILE_CENTERED_HEIGHT_MAP = true; - setSelectedBiome(); const tMainTerrain = g_Terrains.mainTerrain; Index: binaries/data/mods/public/maps/random/tests/test_SmoothingPainter.js =================================================================== --- binaries/data/mods/public/maps/random/tests/test_SmoothingPainter.js +++ binaries/data/mods/public/maps/random/tests/test_SmoothingPainter.js @@ -25,7 +25,7 @@ { g_Map = new RandomMap(0, 0, "blackness"); - let centerHeight = g_Map.getHeight(center); + let centerHeight = g_Map.getVertexHeight(center); createArea( new RectPlacer(min, max), @@ -34,7 +34,7 @@ new SmoothingPainter(2, 1, 1) ]); - TS_ASSERT_GREATER_EQUAL(g_Map.getHeight(center), centerHeight); - TS_ASSERT_LESS_EQUAL(g_Map.getHeight(center), minHeight); + TS_ASSERT_GREATER_EQUAL(g_Map.getVertexHeight(center), centerHeight); + TS_ASSERT_LESS_EQUAL(g_Map.getVertexHeight(center), minHeight); } } Index: binaries/data/mods/public/maps/random/unknown.js =================================================================== --- binaries/data/mods/public/maps/random/unknown.js +++ binaries/data/mods/public/maps/random/unknown.js @@ -2,8 +2,6 @@ Engine.LoadLibrary("rmgen-common"); Engine.LoadLibrary("rmbiome"); -TILE_CENTERED_HEIGHT_MAP = true; - setSelectedBiome(); const tMainTerrain = g_Terrains.mainTerrain; @@ -298,7 +296,7 @@ clWater.add(position); }, "landFunc": (position, shoreDist1, shoreDist2) => { - g_Map.setHeight(position, 3.1); + g_Map.setVertexHeight(position, 3.1); clLand.add(position); } }); Index: binaries/data/mods/public/maps/random/wild_lake.js =================================================================== --- binaries/data/mods/public/maps/random/wild_lake.js +++ binaries/data/mods/public/maps/random/wild_lake.js @@ -356,7 +356,7 @@ */ // Height range by map size -let heightScale = (g_Map.size + 512) / 1024 / 5; +let heightScale = (g_Map.getSize() + 512) / 1024 / 5; let heightRange = { "min": MIN_HEIGHT * heightScale, "max": MAX_HEIGHT * heightScale }; // Water coverage @@ -378,7 +378,7 @@ [medH, medH, medH, medH, medH, medH], [medH, medH, medH, medH, medH, medH], ]; -if (g_Map.size < 256) +if (g_Map.getSize() < 256) { initialHeightmap = [ [medH, medH, medH, medH, medH], @@ -388,7 +388,7 @@ [medH, medH, medH, medH, medH] ]; } -if (g_Map.size >= 384) +if (g_Map.getSize() >= 384) { initialHeightmap = [ [medH, medH, medH, medH, medH, medH, medH, medH], @@ -411,7 +411,7 @@ g_Map.log("Smoothing map"); createArea( new MapBoundsPlacer(), - new SmoothingPainter(1, 0.5, Math.ceil(g_Map.size/128) + 1)); + new SmoothingPainter(1, 0.5, Math.ceil(g_Map.getSize() / 128) + 1)); g_Map.log("Rescaling map"); rescaleHeightmap(heightRange.min, heightRange.max); @@ -442,25 +442,20 @@ for (let position of playerPosition) createArea( new ClumpPlacer(diskArea(20), 0.8, 0.8, Infinity, position), - new SmoothElevationPainter(ELEVATION_SET, g_Map.getHeight(position), 20)); + new SmoothElevationPainter(ELEVATION_SET, g_Map.getVertexHeight(position), 20)); Engine.SetProgress(30); -/** - * Calculate tile centered height map after start position smoothing but before placing paths - * This has nothing to to with TILE_CENTERED_HEIGHT_MAP which should be false! - */ -let tchm = getTileCenteredHeightmap(); - g_Map.log("Get points per height"); let areas = heighLimits.map(heightLimit => []); -for (let x = 0; x < tchm.length; ++x) - for (let y = 0; y < tchm[0].length; ++y) +for (let x = 0; x < g_Map.getSize(); ++x) + for (let y = 0; y < g_Map.getSize(); ++y) { let minHeight = heightRange.min; for (let h = 0; h < heighLimits.length; ++h) { - if (tchm[x][y] >= minHeight && tchm[x][y] <= heighLimits[h]) + const tileHeight = g_Map.getTileHeight(new Vector2D(x, y)); + if (tileHeight >= minHeight && tileHeight <= heighLimits[h]) { areas[h].push(new Vector2D(x, y)); break; @@ -535,11 +530,11 @@ else for (let p = 0; p < playerIDs.length; ++p) { - placeCivDefaultStartingEntities(playerPosition[p], playerIDs[p], g_Map.size > 192); + placeCivDefaultStartingEntities(playerPosition[p], playerIDs[p], g_Map.getSize() > 192); placeStartLocationResources(playerPosition[p]); } -let mercenaryCamps = isNomad() ? 0 : Math.ceil(g_Map.size / 256); +let mercenaryCamps = isNomad() ? 0 : Math.ceil(g_Map.getSize() / 256); g_Map.log("Placing at most " + mercenaryCamps + " mercenary camps"); for (let i = 0; i < resourceSpots.length; ++i) { @@ -574,7 +569,7 @@ if (radius) createArea( new DiskPlacer(radius, resourceSpots[i]), - new SmoothElevationPainter(ELEVATION_SET, g_Map.getHeight(resourceSpots[i]), radius / 3)); + new SmoothElevationPainter(ELEVATION_SET, g_Map.getVertexHeight(resourceSpots[i]), radius / 3)); } g_Map.ExportMap();