diff --git a/binaries/data/mods/public/maps/random/ambush.js b/binaries/data/mods/public/maps/random/ambush.js index 87db672d6c..cf3cc968bf 100644 --- a/binaries/data/mods/public/maps/random/ambush.js +++ b/binaries/data/mods/public/maps/random/ambush.js @@ -7,7 +7,13 @@ InitMap(); setSelectedBiome(); initTileClasses(); -resetTerrain(g_Terrains.mainTerrain, g_TileClasses.land, getMapBaseHeight()); +createArea( + new MapBoundsPlacer(), + [ + new TerrainPainter(g_Terrains.mainTerrain), + paintClass(g_TileClasses.land) + ]); + Engine.SetProgress(10); const pos = randomStartingPositionPattern(getTeamsArray()); diff --git a/binaries/data/mods/public/maps/random/empire.js b/binaries/data/mods/public/maps/random/empire.js index d11fc0f861..4eda2ff247 100644 --- a/binaries/data/mods/public/maps/random/empire.js +++ b/binaries/data/mods/public/maps/random/empire.js @@ -7,7 +7,13 @@ InitMap(); setSelectedBiome(); initTileClasses(); -resetTerrain(g_Terrains.mainTerrain, g_TileClasses.land, getMapBaseHeight()); +createArea( + new MapBoundsPlacer(), + [ + new TerrainPainter(g_Terrains.mainTerrain), + paintClass(g_TileClasses.land) + ]); + Engine.SetProgress(10); const teamsArray = getTeamsArray(); diff --git a/binaries/data/mods/public/maps/random/frontier.js b/binaries/data/mods/public/maps/random/frontier.js index a2d195ae2e..9c979e4789 100644 --- a/binaries/data/mods/public/maps/random/frontier.js +++ b/binaries/data/mods/public/maps/random/frontier.js @@ -8,12 +8,18 @@ setSelectedBiome(); initTileClasses(); Engine.SetProgress(10); -// Pick a random elevation with a bias towards lower elevations +log("Picking a random elevation with a bias towards lower elevations..."); var randElevation = randIntInclusive(0, 29); if (randElevation < 25) randElevation = randIntInclusive(1, 4); -resetTerrain(g_Terrains.mainTerrain, g_TileClasses.land, randElevation); +createArea( + new MapBoundsPlacer(), + [ + new TerrainPainter(g_Terrains.mainTerrain), + new ElevationPainter(randElevation), + paintClass(g_TileClasses.land) + ]); Engine.SetProgress(20); const startPositions = randomStartingPositionPattern(getTeamsArray()); diff --git a/binaries/data/mods/public/maps/random/harbor.js b/binaries/data/mods/public/maps/random/harbor.js index 8b169a4f19..1222f4e89d 100644 --- a/binaries/data/mods/public/maps/random/harbor.js +++ b/binaries/data/mods/public/maps/random/harbor.js @@ -9,7 +9,12 @@ initTileClasses(); setFogFactor(0.04); -resetTerrain(g_Terrains.mainTerrain, g_TileClasses.land, getMapBaseHeight()); +createArea( + new MapBoundsPlacer(), + [ + new TerrainPainter(g_Terrains.mainTerrain), + paintClass(g_TileClasses.land) + ]); Engine.SetProgress(10); const mapSize = getMapSize(); diff --git a/binaries/data/mods/public/maps/random/hells_pass.js b/binaries/data/mods/public/maps/random/hells_pass.js index 8a6d7cb7fb..daa71755e7 100644 --- a/binaries/data/mods/public/maps/random/hells_pass.js +++ b/binaries/data/mods/public/maps/random/hells_pass.js @@ -7,7 +7,12 @@ InitMap(); setSelectedBiome(); initTileClasses(); -resetTerrain(g_Terrains.mainTerrain, g_TileClasses.land, getMapBaseHeight()); +createArea( + new MapBoundsPlacer(), + [ + new TerrainPainter(g_Terrains.mainTerrain), + paintClass(g_TileClasses.land) + ]); Engine.SetProgress(10); const teamsArray = getTeamsArray(); diff --git a/binaries/data/mods/public/maps/random/lions_den.js b/binaries/data/mods/public/maps/random/lions_den.js index 3c1fddb9ab..357ade4b53 100644 --- a/binaries/data/mods/public/maps/random/lions_den.js +++ b/binaries/data/mods/public/maps/random/lions_den.js @@ -19,7 +19,13 @@ const mapCenter = getMapCenter(); const numPlayers = getNumPlayers(); const startAngle = randomAngle(); -resetTerrain(topTerrain, g_TileClasses.land, hillHeight); +createArea( + new MapBoundsPlacer(), + [ + new TerrainPainter(topTerrain), + new ElevationPainter(hillHeight), + paintClass(g_TileClasses.land) + ]); Engine.SetProgress(10); addBases("radial", fractionToTiles(0.4), fractionToTiles(randFloat(0.05, 0.1)), startAngle); diff --git a/binaries/data/mods/public/maps/random/rmgen/library.js b/binaries/data/mods/public/maps/random/rmgen/library.js index 7dfae86910..2a8bda39d0 100644 --- a/binaries/data/mods/public/maps/random/rmgen/library.js +++ b/binaries/data/mods/public/maps/random/rmgen/library.js @@ -367,11 +367,6 @@ function setHeight(x, z, height) g_Map.setHeight(x, z, height); } -function initHeight(height) -{ - g_Map.initHeight(height); -} - /** * Utility functions for classes */ diff --git a/binaries/data/mods/public/maps/random/rmgen/map.js b/binaries/data/mods/public/maps/random/rmgen/map.js index 0a046ab3df..cca20222a9 100644 --- a/binaries/data/mods/public/maps/random/rmgen/map.js +++ b/binaries/data/mods/public/maps/random/rmgen/map.js @@ -58,16 +58,6 @@ function Map(size, baseHeight) this.entityCount = 150; } -/** - * Sets the elevation of the entire heightmap grid to the given value. - */ -Map.prototype.initHeight = function(height) -{ - for (let i = 0; i < this.size; ++i) - for (let j = 0; j < this.size; ++j) - this.height[i][j] = height; -}; - /** * Returns the ID of a texture name. * Creates a new ID if there isn't one assigned yet. diff --git a/binaries/data/mods/public/maps/random/rmgen/placer_noncentered.js b/binaries/data/mods/public/maps/random/rmgen/placer_noncentered.js index bcdcbc3858..d63d49bc25 100644 --- a/binaries/data/mods/public/maps/random/rmgen/placer_noncentered.js +++ b/binaries/data/mods/public/maps/random/rmgen/placer_noncentered.js @@ -30,6 +30,20 @@ RectPlacer.prototype.place = function(constraint) return points; }; +/** + * The MapBoundsPlacer returns all points on the tilemap that meet the constraint. + */ +function MapBoundsPlacer() +{ + let mapBounds = getMapBounds(); + this.rectPlacer = new RectPlacer(mapBounds.left, mapBounds.top, mapBounds.right, mapBounds.bottom); +} + +MapBoundsPlacer.prototype.place = function(constraint) +{ + return this.rectPlacer.place(constraint); +}; + /** * HeightPlacer constants determining whether the extrema should be included by the placer too. */ diff --git a/binaries/data/mods/public/maps/random/rmgen2/setup.js b/binaries/data/mods/public/maps/random/rmgen2/setup.js index 0066aab255..339f9f6506 100644 --- a/binaries/data/mods/public/maps/random/rmgen2/setup.js +++ b/binaries/data/mods/public/maps/random/rmgen2/setup.js @@ -110,22 +110,6 @@ function pickSize(sizes) return g_Sizes.normal; } -/** - * Paints the entire map with the given terrain texture, tileclass and elevation. - */ -function resetTerrain(terrain, tileClass, elevation) -{ - let mapCenter = getMapCenter(); - createArea( - new ClumpPlacer(getMapArea(), 1, 1, 1, mapCenter.x, mapCenter.y), - [ - new LayeredPainter([terrain], []), - new SmoothElevationPainter(ELEVATION_SET, elevation, 1), - paintClass(tileClass) - ], - null); -} - /** * Choose starting locations for all players. * diff --git a/binaries/data/mods/public/maps/random/stronghold.js b/binaries/data/mods/public/maps/random/stronghold.js index 78686ebe89..91531ddac6 100644 --- a/binaries/data/mods/public/maps/random/stronghold.js +++ b/binaries/data/mods/public/maps/random/stronghold.js @@ -7,7 +7,12 @@ InitMap(); setSelectedBiome(); initTileClasses(); -resetTerrain(g_Terrains.mainTerrain, g_TileClasses.land, getMapBaseHeight()); +createArea( + new MapBoundsPlacer(), + [ + new TerrainPainter(g_Terrains.mainTerrain), + paintClass(g_TileClasses.land) + ]); Engine.SetProgress(20); addBases("stronghold", fractionToTiles(randFloat(0.2, 0.35)), fractionToTiles(randFloat(0.05, 0.1)), randomAngle()); diff --git a/binaries/data/mods/public/maps/random/the_unknown/unknown_common.js b/binaries/data/mods/public/maps/random/the_unknown/unknown_common.js index 1921c0b712..de978a04fc 100644 --- a/binaries/data/mods/public/maps/random/the_unknown/unknown_common.js +++ b/binaries/data/mods/public/maps/random/the_unknown/unknown_common.js @@ -337,7 +337,10 @@ function unknownCentralRiver() { let waterHeight = -4; let shallowHeight = -2; - initHeight(landHeight); + + createArea( + new MapBoundsPlacer(), + new ElevationPainter(landHeight)); let horizontal = randBool(); let riverAngle = horizontal ? 0 : Math.PI / 2; @@ -401,7 +404,9 @@ function unknownCentralRiver() function unknownRiversAndLake() { let waterHeight = -4; - initHeight(landHeight); + createArea( + new MapBoundsPlacer(), + new ElevationPainter(landHeight)); let startAngle; if (!isNomad()) @@ -475,7 +480,10 @@ function unknownRiversAndLake() function unknownEdgeSeas() { let waterHeight = -4; - initHeight(landHeight); + + createArea( + new MapBoundsPlacer(), + new ElevationPainter(landHeight)); let horizontal = randBool(); if (!isNomad()) @@ -513,7 +521,10 @@ function unknownEdgeSeas() function unknownGulf() { let waterHeight = -3; - initHeight(landHeight); + + createArea( + new MapBoundsPlacer(), + new ElevationPainter(landHeight)); let startAngle = randomAngle(); if (!isNomad()) @@ -554,7 +565,9 @@ function unknownLakes() { let waterHeight = -5; - initHeight(landHeight); + createArea( + new MapBoundsPlacer(), + new ElevationPainter(landHeight)); if (!isNomad()) { @@ -580,7 +593,10 @@ function unknownPasses() { let mountainHeight = 24; let waterHeight = -4; - initHeight(landHeight); + + createArea( + new MapBoundsPlacer(), + new ElevationPainter(landHeight)); let playerAngle; let startAngle; @@ -659,7 +675,9 @@ function unknownLowlands() let mountainHeight = 30; log("Creating mountain that is going to separate players..."); - initHeight(mountainHeight); + createArea( + new MapBoundsPlacer(), + new ElevationPainter(mountainHeight)); let playerAngle; let startAngle; @@ -713,7 +731,9 @@ function unknownLowlands() */ function unknownMainland() { - initHeight(3); + createArea( + new MapBoundsPlacer(), + new ElevationPainter(3)); if (!isNomad()) {