diff --git a/binaries/data/mods/public/maps/random/aegean_sea.js b/binaries/data/mods/public/maps/random/aegean_sea.js index e2014e9db0..268e0b0ff2 100644 --- a/binaries/data/mods/public/maps/random/aegean_sea.js +++ b/binaries/data/mods/public/maps/random/aegean_sea.js @@ -154,46 +154,25 @@ for (var i = 0; i < numPlayers; i++) placeDefaultDecoratives(fx, fz, aBush1, clBaseResource, radius); } - RMS.SetProgress(30); -const WATER_WIDTH = 0.35; +paintRiver({ + "horizontal": false, + "parallel": false, + "position": 0.5, + "width": 0.35, + "fadeDist": 0.025, + "deviation": 0, + "waterHeight": -3, + "landHeight": 2, + "meanderShort": 20, + "meanderLong": 0, + "waterFunc": (ix, iz, height) => { -log("Creating the sea"); -var theta = randFloat(0, 1); -var theta2 = randFloat(0, 1); -var seed = randFloat(2,3); -var seed2 = randFloat(2,3); -for (var ix = 0; ix < mapSize; ix++) -{ - for (var iz = 0; iz < mapSize; iz++) - { - var x = ix / (mapSize + 1.0); - var z = iz / (mapSize + 1.0); - - // add the rough shape of the water - var km = 20/scaleByMapSize(35, 160); - var cu = km*rndRiver(theta+z*0.5*(mapSize/64),seed); - var cu2 = km*rndRiver(theta2+z*0.5*(mapSize/64),seed2); - - var fadeDist = 0.05; - - if ((x > cu + 0.5 - WATER_WIDTH/2) && (x < cu2 + 0.5 + WATER_WIDTH/2)) - { - var h; - if (x < (cu + 0.5 + fadeDist - WATER_WIDTH/2)) - h = 2 - 5.0 * (1 - ((cu + 0.5 + fadeDist - WATER_WIDTH/2) - x)/fadeDist); - else if (x > (cu2 + 0.5 - fadeDist + WATER_WIDTH/2)) - h = 2 - 5.0 * (1 - (x - (cu2 + 0.5 - fadeDist + WATER_WIDTH/2))/fadeDist); - else - h = -3.0; - - setHeight(ix, iz, h); - if (h < 0.7) - addToClass(ix, iz, clWater); - } + if (height < 0.7) + addToClass(ix, iz, clWater); } -} +}); paintTerrainBasedOnHeight(-20, 1, 0, tWater); paintTerrainBasedOnHeight(1, 2, 0, tShore); diff --git a/binaries/data/mods/public/maps/random/danubius.js b/binaries/data/mods/public/maps/random/danubius.js index 4c4ad4bab5..79afb31f03 100644 --- a/binaries/data/mods/public/maps/random/danubius.js +++ b/binaries/data/mods/public/maps/random/danubius.js @@ -408,49 +408,36 @@ for (let i = 0; i < numPlayers; ++i) RMS.SetProgress(20); log("Creating the river"); -var theta = randFloat(0, 0.8); -var theta2 = randFloat(0, 1.2); -var seed = randFloat(3, 5); -var seed2 = randFloat(2, 6); -var fadeDist = 0.05; +paintRiver({ + "horizontal": false, + "parallel": true, + "position": 0.5, + "width": waterWidth, + "fadeDist": 0.025, + "deviation": 0, + "waterHeight": -3, + "landHeight": 2, + "meanderShort": 30, + "meanderLong": 0, + "waterFunc": (ix, iz, height) => { -for (let ix = 0; ix < mapSize; ++ix) - for (let iz = 0; iz < mapSize; ++iz) - { - let x = ix / (mapSize + 1); - let z = iz / (mapSize + 1); - - // Add the rough shape of the water - let km = 30 / scaleByMapSize(35, 100); - let cu = km * rndRiver(theta + z * mapSize / 128, seed); - let cu2 = km * rndRiver(theta2 + z * mapSize / 128, seed2); - - if (x < cu + 0.5 - waterWidth / 2) - { - addToClass(ix, iz, clLand[0]); - continue; - } - - if (x > cu2 + 0.5 + waterWidth / 2) - { - addToClass(ix, iz, clLand[1]); - continue; - } - - let height = -3; - if (x < cu + 0.5 + fadeDist - waterWidth / 2) - height = 2 - 5 * (1 - ((cu + 0.5 + fadeDist - waterWidth / 2) - x) / fadeDist); - else if (x > (cu2 + 0.5 - fadeDist + waterWidth / 2)) - height = 2 - 5 * (1 - (x - (cu2 + 0.5 - fadeDist + waterWidth / 2)) / fadeDist); - - setHeight(ix, iz, height); if (height < 0.7) addToClass(ix, iz, clWater); // Distinguish left and right shoreline if (0 < height && height < 1 && iz > ShorelineDistance && iz < mapSize - ShorelineDistance) addToClass(ix, iz, clShore[ix < mapSize / 2 ? 0 : 1]); + }, + "landFunc": (ix, iz, shoreDist1, shoreDist2) => { + + if (shoreDist1 > 0) + addToClass(ix, iz, clLand[0]); + + if (shoreDist2 < 0) + addToClass(ix, iz, clLand[1]); } +}); + RMS.SetProgress(30); log("Creating shores..."); diff --git a/binaries/data/mods/public/maps/random/english_channel.js b/binaries/data/mods/public/maps/random/english_channel.js index 662f031037..9d3d0e0806 100644 --- a/binaries/data/mods/public/maps/random/english_channel.js +++ b/binaries/data/mods/public/maps/random/english_channel.js @@ -43,8 +43,6 @@ const aLillies = "actor|props/flora/water_lillies.xml"; const pForestD = [tGrassDForest + TERRAIN_SEPARATOR + oBeech, tGrassDForest]; const pForestP = [tGrassPForest + TERRAIN_SEPARATOR + oOak, tGrassPForest]; -const WATER_WIDTH = 0.25; - InitMap(); const numPlayers = getNumPlayers(); @@ -157,49 +155,25 @@ for (var i = 0; i < numPlayers; i++) } RMS.SetProgress(10); -log("Creating sea"); - -var theta = randFloat(0, 1); -var theta2 = randFloat(0, 1); - -var seed = randFloat(2,3); -var seed2 = randFloat(2,3); - -for (var ix = 0; ix < mapSize; ix++) - for (var iz = 0; iz < mapSize; iz++) - { - var x = ix / (mapSize + 1.0); - var z = iz / (mapSize + 1.0); - - // add the rough shape of the water - var km = 20/scaleByMapSize(35, 160); - - var fadeDist = 0.02; - - var cu = km*rndRiver(theta+x*0.5*(mapSize/64),seed); - var cu2 = km*rndRiver(theta2+x*0.5*(mapSize/64),seed2); - - if (z > cu + 0.5 - WATER_WIDTH/2 && - z < cu2 + 0.5 + WATER_WIDTH/2) - { - var h; - if (z < (cu + 0.5 + fadeDist - WATER_WIDTH/2)) - h = 3 - 7 * (1 - ((cu + 0.5 + fadeDist - WATER_WIDTH/2) - z)/fadeDist); - else if (z > (cu2 + 0.5 - fadeDist + WATER_WIDTH/2)) - h = 3 - 7 * (1 - (z - (cu2 + 0.5 - fadeDist + WATER_WIDTH/2))/fadeDist); - else - h = -4.0; - - if (h < -1.5) - placeTerrain(ix, iz, tWater); - else - placeTerrain(ix, iz, tShore); - - setHeight(ix, iz, h); - } - else - setHeight(ix, iz, 3.1); +paintRiver({ + "horizontal": true, + "parallel": false, + "position": 0.5, + "width": 0.25, + "fadeDist": 0.01, + "deviation": 0, + "waterHeight": -4, + "landHeight": 3, + "meanderShort": 20, + "meanderLong": 0, + "waterFunc": (ix, iz, height) => { + placeTerrain(ix, iz, height < -1.5 ? tWater : tShore); + }, + "landFunc": (ix, iz, shoreDist1, shoreDist2) => { + setHeight(ix, iz, 3.1); } +}); + RMS.SetProgress(20); log("Creating rivers"); diff --git a/binaries/data/mods/public/maps/random/guadalquivir_river.js b/binaries/data/mods/public/maps/random/guadalquivir_river.js index 2e2f3bf40b..2340368ef1 100644 --- a/binaries/data/mods/public/maps/random/guadalquivir_river.js +++ b/binaries/data/mods/public/maps/random/guadalquivir_river.js @@ -1,6 +1,6 @@ RMS.LoadLibrary("rmgen"); -const tGrass = ["medit_grass_field_a", "medit_grass_field_b"];; +const tGrass = ["medit_grass_field_a", "medit_grass_field_b"]; const tForestFloorC = "medit_plants_dirt"; const tForestFloorP = "medit_grass_shrubs"; const tCliff = ["medit_cliff_grass", "medit_cliff_greek", "medit_cliff_greek_2", "medit_cliff_aegean", "medit_cliff_italia", "medit_cliff_italia_grass"]; @@ -36,8 +36,6 @@ const aRockMedium = "actor|geology/stone_granite_med.xml"; const aBushMedium = "actor|props/flora/bush_medit_me.xml"; const aBushSmall = "actor|props/flora/bush_medit_sm.xml"; -// terrain + entity (for painting) - const pForestP = [tForestFloorP + TERRAIN_SEPARATOR + oPoplar, tForestFloorP]; const pForestC = [tForestFloorC + TERRAIN_SEPARATOR + oCarob, tForestFloorC]; @@ -57,39 +55,26 @@ var clFood = createTileClass(); var clBaseResource = createTileClass(); var clSettlement = createTileClass(); var clLand = createTileClass(); -var clUpperLand = createTileClass(); var clRiver = createTileClass(); var clShallow = createTileClass(); -//Create the continent body -var fx = fractionToTiles(0.5); -var fz = fractionToTiles(0.7); -var ix = round(fx); -var iz = round(fz); - -var placer = new RectPlacer(0, floor(mapSize * 0.70), mapSize - 1, mapSize - 1); -var terrainPainter = new LayeredPainter( - [tWater, tShore, tGrass], // terrains - [4, 2] // widths -); -var elevationPainter = new SmoothElevationPainter( - ELEVATION_SET, // type - 3, // elevation - 4 // blend radius -); -createArea(placer, [terrainPainter, elevationPainter, paintClass(clUpperLand)], null); - -var placer = new ChainPlacer(2, floor(scaleByMapSize(5, 12)), floor(scaleByMapSize(60, 700)), 1, ix, iz, 0, [floor(mapSize * 0.49)]); -var terrainPainter = new LayeredPainter( - [tGrass, tGrass, tGrass], // terrains - [4, 2] // widths -); -var elevationPainter = new SmoothElevationPainter( - ELEVATION_SET, // type - 3, // elevation - 4 // blend radius -); -createArea(placer, [terrainPainter, elevationPainter, paintClass(clLand)], null); +log("Create the continent body"); +createArea( + new ChainPlacer( + 2, + Math.floor(scaleByMapSize(5, 12)), + Math.floor(scaleByMapSize(60, 700)), + 1, + Math.floor(fractionToTiles(0.5)), + Math.floor(fractionToTiles(0.7)), + 0, + [Math.floor(mapSize * 0.49)]), + [ + new LayeredPainter([tGrass, tGrass, tGrass], [4, 2]), + new SmoothElevationPainter(ELEVATION_SET, 3, 4), + paintClass(clLand) + ], + null); var playerIDs = primeSortAllPlayers(); @@ -116,10 +101,10 @@ for (var i = 0; i < numPlayers; i++) var elevation = 20; // get the x and z in tiles - fx = fractionToTiles(playerX[i]); - fz = fractionToTiles(playerZ[i]); - ix = round(fx); - iz = round(fz); + let fx = fractionToTiles(playerX[i]); + let fz = fractionToTiles(playerZ[i]); + let ix = Math.round(fx); + let iz = Math.round(fz); addToClass(ix, iz, clPlayer); addToClass(ix+5, iz, clPlayer); addToClass(ix, iz+5, clPlayer); @@ -128,7 +113,7 @@ for (var i = 0; i < numPlayers; i++) // create the city patch var cityRadius = radius/3; - placer = new ClumpPlacer(PI*cityRadius*cityRadius, 0.6, 0.3, 10, ix, iz); + var placer = new ClumpPlacer(PI*cityRadius*cityRadius, 0.6, 0.3, 10, ix, iz); var painter = new LayeredPainter([tRoadWild, tRoad], [1]); createArea(placer, painter, null); @@ -189,69 +174,35 @@ for (var i = 0; i < numPlayers; i++) RMS.SetProgress(20); -const WATER_WIDTH = 0.07; +var shallowHeight = -1.5; +paintRiver({ + "horizontal": false, + "parallel": true, + "constraint": stayClasses(clLand, 0), + "position": 0.5, + "width": 0.07, + "fadeDist": 0.025, + "deviation": 0.005, + "waterHeight": -3, + "landHeight": 2, + "meanderShort": 12, + "meanderLong": 0, + "waterFunc": (ix, iz, height) => { + addToClass(ix, iz, clRiver); + placeTerrain(ix, iz, tWater); -log("Creating river"); + let z = iz / (mapSize + 1.0); -var theta = randFloat(0, 1); -var seed = randFloat(2,3); - -for (var ix = 0; ix < mapSize; ix++) - for (var iz = 0; iz < mapSize; iz++) - { - var x = ix / (mapSize + 1.0); - var z = iz / (mapSize + 1.0); - - var h = 0; - var distToWater = 0; - - h = 32 * (z - 0.5); - - // add the rough shape of the water - var km = 12/scaleByMapSize(35, 160); - var cu = km*rndRiver(theta+z*0.5*(mapSize/64),seed); - var zk = z*randFloat(0.995,1.005); - var xk = x*randFloat(0.995,1.005); - if (-3.0 < getHeight(ix, iz)){ - if ((xk > cu+((1.0-WATER_WIDTH)/2))&&(xk < cu+((1.0+WATER_WIDTH)/2))) + if (height < shallowHeight && ( + z > 0.3 && z < 0.4 || + z > 0.5 && z < 0.6 || + z > 0.7 && z < 0.8)) { - if (xk < cu+((1.05-WATER_WIDTH)/2)) - { - h = -3 + 200.0* abs(cu+((1.05-WATER_WIDTH)/2-xk)); - if ((((zk>0.3)&&(zk<0.4))||((zk>0.5)&&(zk<0.6))||((zk>0.7)&&(zk<0.8)))&&(h<-1.5)) - { - h=-1.5; - addToClass(ix, iz, clShallow); - } - - } - else if (xk > (cu+(0.95+WATER_WIDTH)/2)) - { - h = -3 + 200.0*(xk-(cu+((0.95+WATER_WIDTH)/2))); - if ((((zk>0.3)&&(zk<0.4))||((zk>0.5)&&(zk<0.6))||((zk>0.7)&&(zk<0.8)))&&(h<-1.5)) - { - h=-1.5; - addToClass(ix, iz, clShallow); - } - } - else - { - if (((zk>0.3)&&(zk<0.4))||((zk>0.5)&&(zk<0.6))||((zk>0.7)&&(zk<0.8))){ - h = -1.5; - addToClass(ix, iz, clShallow); - } - else - { - h = -3.0; - } - } - setHeight(ix, iz, h); - addToClass(ix, iz, clRiver); - placeTerrain(ix, iz, tWater); - } + setHeight(ix, iz, shallowHeight); + addToClass(ix, iz, clShallow); } } -} +}); paintTerrainBasedOnHeight(1, 3, 0, tShore); paintTerrainBasedOnHeight(-8, 1, 2, tWater); @@ -320,7 +271,7 @@ createDecoration [avoidClasses(clHill, 1, clPlayer, 1, clDirt, 1, clRiver, 1), stayClasses(clLand, 6)] ); -// create water decoration in the shallow parts +log("Create water decoration in the shallow parts"); createDecoration ( [[new SimpleObject(aReeds, 1,3, 0,1)], diff --git a/binaries/data/mods/public/maps/random/hyrcanian_shores.js b/binaries/data/mods/public/maps/random/hyrcanian_shores.js index 5d1fb4f2de..fe8c23e677 100644 --- a/binaries/data/mods/public/maps/random/hyrcanian_shores.js +++ b/binaries/data/mods/public/maps/random/hyrcanian_shores.js @@ -40,8 +40,6 @@ const aBushSmall = "actor|props/flora/bush_medit_sm_lush.xml"; const pForestD = [tGrassDForest + TERRAIN_SEPARATOR + oPoplar, tGrassDForest]; const pForestP = [tGrassPForest + TERRAIN_SEPARATOR + oOak, tGrassPForest]; -const WATER_WIDTH = 0.25; - InitMap(); const numPlayers = getNumPlayers(); @@ -146,42 +144,32 @@ for (var i = 0; i < numPlayers; i++) } RMS.SetProgress(10); -log("Creating sea and northern hills..."); -var theta = randFloat(0, 1); -var seed = randFloat(2,3); -for (var ix = 0; ix < mapSize; ix++) - for (var iz = 0; iz < mapSize; iz++) - { - var x = ix / (mapSize + 1.0); - var z = iz / (mapSize + 1.0); +paintRiver({ + "horizontal": true, + "parallel": true, + "position": 1, + "width": 0.5, + "fadeDist": 0.05, + "deviation": 0, + "waterHeight": -3, + "landHeight": 1, + "meanderShort": 20, + "meanderLong": 0, + "waterFunc": (ix, iz, height) => { - // add the rough shape of the water - var km = 20/scaleByMapSize(35, 160); - var cu = km*rndRiver(theta+x*0.5*(mapSize/64),seed); + if (height < 0) + addToClass(ix, iz, clWater); - var fadeDist = 0.05; - - if (z < 0.25) - addToClass(ix, iz, clHighlands); - - if (z > cu + 0.75) - { - var h; - if ((z < (cu + 0.75 + fadeDist))&&(z > (cu + 0.75))) - h = 1 - 4.0 * (1 - ((cu + 0.75 + fadeDist) - z)/fadeDist); - else - h = -3.0; - - if (h < -1.5) - placeTerrain(ix, iz, tWater); - else - placeTerrain(ix, iz, tShore); - - setHeight(ix, iz, h); - if (h < 0) - addToClass(ix, iz, clWater); - } + if (height < -1.5) + placeTerrain(ix, iz, tWater); + else + placeTerrain(ix, iz, tShore); + }, + "landFunc": (ix, iz, shoreDist1, shoreDist2) => { + addToClass(ix, iz, clHighlands); } +}); + RMS.SetProgress(20); log("Creating fish..."); diff --git a/binaries/data/mods/public/maps/random/kerala.js b/binaries/data/mods/public/maps/random/kerala.js index b99a5a3433..d1e78ec572 100644 --- a/binaries/data/mods/public/maps/random/kerala.js +++ b/binaries/data/mods/public/maps/random/kerala.js @@ -141,31 +141,28 @@ for (var i = 0; i < numPlayers; i++) RMS.SetProgress(15); -// create western sea -var fadedistance = 8; +const waterPos = 0.31; +const mountainPos = 0.69; -for (var ix = 0; ix < mapSize; ix++) -{ - for (var iz = 0; iz < mapSize; iz++) - { - if (ix < 0.31 * mapSize) - { - if (ix > 0.31 * mapSize - fadedistance) - { - setHeight(ix, iz, 3 - 8 * (0.31 * mapSize - ix) / fadedistance); - if (ix, iz, 3 - 8 * (0.31 * mapSize - ix) / fadedistance < 0.5) - addToClass(ix, iz, clWater); - } - else - { - setHeight(ix, iz, -5); - addToClass(ix, iz, clWater); - } - } - else if (ix > 0.69 * mapSize) - addToClass(ix, iz, clMountains); +paintRiver({ + "horizontal": false, + "parallel": false, + "position": 0, + "width": 2 * waterPos, + "fadeDist": 0.025, + "deviation": 0, + "waterHeight": -5, + "landHeight": 3, + "meanderShort": 20, + "meanderLong": 0, + "waterFunc": (ix, iz, height) => { + addToClass(ix, iz, clWater); + }, + "landFunc": (ix, iz, shoreDist1, shoreDist2) => { + if (ix > mountainPos * mapSize) + addToClass(ix, iz, clMountains) } -} +}); log("Creating shores..."); for (var i = 0; i < scaleByMapSize(20,120); i++) diff --git a/binaries/data/mods/public/maps/random/phoenician_levant.js b/binaries/data/mods/public/maps/random/phoenician_levant.js index f1d17b3f3e..b0f84fb6f8 100644 --- a/binaries/data/mods/public/maps/random/phoenician_levant.js +++ b/binaries/data/mods/public/maps/random/phoenician_levant.js @@ -145,40 +145,28 @@ for (var i = 0; i < numPlayers; i++) RMS.SetProgress(30); -log("Creating sea"); +paintRiver({ + "horizontal": false, + "parallel": true, + "position": 0, + "width": 1, + "fadeDist": 0.05, + "deviation": 0, + "waterHeight": -3, + "landHeight": 1, + "meanderShort": 20, + "meanderLong": 0, + "waterFunc": (ix, iz, height) => { -var theta = randFloat(0, 1); -var seed = randFloat(2,3); -for (var ix = 0; ix < mapSize; ix++) - for (var iz = 0; iz < mapSize; iz++) - { - var x = ix / (mapSize + 1.0); - var z = iz / (mapSize + 1.0); + if (height < 0) + addToClass(ix, iz, clWater); - // add the rough shape of the water - var km = 20/scaleByMapSize(35, 160); - var cu = km*rndRiver(theta+z*0.5*(mapSize/64),seed); - - var fadeDist = 0.05; - - if (x < cu + 0.5) - { - var h; - if (x < (cu + 0.5 + fadeDist)) - h = 1 + 4.0 * (1 - ((cu + 0.5 + fadeDist) - x)/fadeDist); - else - h = -3.0; - - if (h < -1.5) - placeTerrain(ix, iz, tWater); - else - placeTerrain(ix, iz, tShore); - - setHeight(ix, iz, h); - if (h < 0) - addToClass(ix, iz, clWater); - } + if (height < -1.5) + placeTerrain(ix, iz, tWater); + else + placeTerrain(ix, iz, tShore); } +}); RMS.SetProgress(40); diff --git a/binaries/data/mods/public/maps/random/rmgen/misc.js b/binaries/data/mods/public/maps/random/rmgen/misc.js index 37148d375c..4bd7547604 100644 --- a/binaries/data/mods/public/maps/random/rmgen/misc.js +++ b/binaries/data/mods/public/maps/random/rmgen/misc.js @@ -128,6 +128,85 @@ function rndRiver(f, seed) return rndRa; } +/** + * Creates a meandering river at the given location and width. + * Optionally calls a function on the affected tiles. + * + * @property horizontal - Whether the river is horizontal or vertical + * @property parallel - Whether the shorelines should be parallel or meander separately. + * @property position - Location of the river. Number between 0 and 1. + * @property width - Size between the two shorelines. Number between 0 and 1. + * @property fadeDist - Size of the shoreline. + * @property deviation - Fuzz effect on the shoreline if greater than 0. + * @property waterHeight - Ground height of the riverbed. + * @proeprty landHeight - Ground height of the end of the shoreline. + * @property meanderShort - Strength of frequent meanders. + * @property meanderLong - Strength of less frequent meanders. + * @property waterFunc - Optional function called on water tiles, providing ix, iz, height. + * @property landFunc - Optional function called on land tiles, providing ix, iz, shoreDist1, shoreDist2. + */ +function paintRiver(args) +{ + log("Creating the river"); + + let theta1 = randFloat(0, 1); + let theta2 = randFloat(0, 1); + + let seed1 = randFloat(2, 3); + let seed2 = randFloat(2, 3); + + let meanderShort = args.meanderShort / scaleByMapSize(35, 160); + let meanderLong = args.meanderLong / scaleByMapSize(35, 100); + + let mapSize = g_Map.size; + + for (let ix = 0; ix < mapSize; ++ix) + for (let iz = 0; iz < mapSize; ++iz) + { + if (args.constraint && !args.constraint.allows(ix, iz)) + continue; + + let x = ix / (mapSize + 1.0); + let z = iz / (mapSize + 1.0); + + let coord1 = args.horizontal ? z : x; + let coord2 = args.horizontal ? x : z; + + // River curve at this place + let cu1 = meanderShort * rndRiver(theta1 + coord2 * mapSize / 128, seed1); + let cu2 = meanderShort * rndRiver(theta2 + coord2 * mapSize / 128, seed2); + + cu1 += meanderLong * rndRiver(theta2 + coord2 * mapSize / 256, seed2); + cu2 += meanderLong * rndRiver(theta2 + coord2 * mapSize / 256, seed2); + if (args.parallel) + cu2 = cu1; + + // Fuzz the river border + let devCoord1 = coord1 * randFloat(1 - args.deviation, 1 + args.deviation); + let devCoord2 = coord2 * randFloat(1 - args.deviation, 1 + args.deviation); + + let shoreDist1 = -devCoord1 + cu1 + args.position - args.width / 2; + let shoreDist2 = -devCoord1 + cu2 + args.position + args.width / 2; + + if (shoreDist1 < 0 && shoreDist2 > 0) + { + let height = args.waterHeight; + + if (shoreDist1 > -args.fadeDist) + height += (args.landHeight - args.waterHeight) * (1 + shoreDist1 / args.fadeDist); + else if (shoreDist2 < args.fadeDist) + height += (args.landHeight - args.waterHeight) * (1 - shoreDist2 / args.fadeDist); + + setHeight(ix, iz, height); + + if (args.waterFunc) + args.waterFunc(ix, iz, height); + } + else if (args.landFunc) + args.landFunc(ix, iz, shoreDist1, shoreDist2); + } +} + ///////////////////////////////////////////////////////////////////////////////////////// // createStartingPlayerEntities // diff --git a/binaries/data/mods/public/maps/random/the_nile.js b/binaries/data/mods/public/maps/random/the_nile.js index 444d408c14..2810288803 100644 --- a/binaries/data/mods/public/maps/random/the_nile.js +++ b/binaries/data/mods/public/maps/random/the_nile.js @@ -160,90 +160,71 @@ for (var i = 0; i < numPlayers; i++) RMS.SetProgress(30); -const WATER_WIDTH = 0.1; - -log("Creating river"); -var theta = randFloat(0, 1); -var seed = randFloat(2,3); -var theta2 = randFloat(0, 1); -var seed2 = randFloat(2,3); -var rifp = 0; -var rifp2 = 0; - -for (var ix = 0; ix < mapSize; ix++) - for (var iz = 0; iz < mapSize; iz++) +const riverTextures = [ { - var x = ix / (mapSize + 1.0); - var z = iz / (mapSize + 1.0); + "left": 0, + "right": 0.04, + "tileClass": tLush + }, + { + "left": 0.04, + "right": 0.06, + "tileClass": tSLush + }, + { + "left": 0.06, + "right": 0.09, + "tileClass": tSDry + } +]; - var h = 0; - var distToWater = 0; +const plantFrequency = 2; - h = 32 * (z - 0.5); - if ((x < 0.25)||(x > 0.75)) +var plantID = 0; + +paintRiver({ + "horizontal": false, + "parallel": true, + "position": 0.5, + "width": 0.1, + "fadeDist": 0.025, + "deviation": 0.005, + "waterHeight": -3, + "landHeight": 2, + "meanderShort": 12, + "meanderLong": 50, + "waterFunc": (ix, iz, height) => { + + addToClass(ix, iz, clWater); + placeTerrain(ix, iz, tShore); + + // Place river bushes + if (height <= -0.2 || height >= 0.1) + return; + + if (plantID % plantFrequency == 0) + { + plantID = 0; + placeObject(ix, iz, aPlants, 0, randFloat(0, TWO_PI)); + } + ++plantID; + }, + "landFunc": (ix, iz, shoreDist1, shoreDist2) => { + + let x = ix / (mapSize + 1.0); + if (x < 0.25 || x > 0.75) addToClass(ix, iz, clDesert); - // add the rough shape of the water - var km = 12/scaleByMapSize(35, 160); - var cu = km*rndRiver(theta+z*0.5*(mapSize/64),seed)+(50/scaleByMapSize(35, 100))*rndRiver(theta2+z*0.5*(mapSize/128),seed2); - var zk = z*randFloat(0.995,1.005); - var xk = x*randFloat(0.995,1.005); - - if (-3.0 >= getHeight(ix, iz)) - continue; - - if ((xk > cu+((1.0-WATER_WIDTH)/2))&&(xk < cu+((1.0+WATER_WIDTH)/2))) - { - if (xk < cu+((1.05-WATER_WIDTH)/2)) + for (let riv of riverTextures) + if (-shoreDist1 > -riv.right && -shoreDist1 < -riv.left || + -shoreDist2 > riv.left && -shoreDist2 < riv.right) { - h = -3 + 200.0* abs(cu+((1.05-WATER_WIDTH)/2-xk)); - if ((h < 0.1)&&(h>-0.2)) - { - if (rifp%2 == 0) - { - rifp = 0; - placeObject(ix, iz, aPlants, 0, randFloat(0,TWO_PI)); - } - ++rifp; - } + placeTerrain(ix, iz, riv.tileClass); + addToClass(ix, iz, clShore); } - else if (xk > (cu+(0.95+WATER_WIDTH)/2)) - { - h = -3 + 200.0*(xk-(cu+((0.95+WATER_WIDTH)/2))); - if ((h < 0.1)&&(h>-0.2)) - { - if (rifp2%2 == 0) - { - rifp2 = 0; - placeObject(ix, iz, aPlants, 0, randFloat(0,TWO_PI)); - } - ++rifp2; - } - } - else - h = -3.0; - - setHeight(ix, iz, h); - addToClass(ix, iz, clWater); - placeTerrain(ix, iz, tShore); - } - - if (((xk > cu+((1.0-WATER_WIDTH)/2)-0.04)&&(xk < cu+((1.0-WATER_WIDTH)/2)))||((xk > cu+((1.0+WATER_WIDTH)/2))&&(xk < cu+((1.0+WATER_WIDTH)/2) + 0.04))) - { - placeTerrain(ix, iz, tLush); - addToClass(ix, iz, clShore); - } - else if (((xk > cu+((1.0-WATER_WIDTH)/2)-0.06)&&(xk < cu+((1.0-WATER_WIDTH)/2)-0.04))||((xk > cu+((1.0+WATER_WIDTH)/2)+0.04)&&(xk < cu+((1.0+WATER_WIDTH)/2) + 0.06))) - { - placeTerrain(ix, iz, tSLush); - addToClass(ix, iz, clShore); - } - else if (((xk > cu+((1.0-WATER_WIDTH)/2)-0.09)&&(xk < cu+((1.0-WATER_WIDTH)/2)-0.06))||((xk > cu+((1.0+WATER_WIDTH)/2)+0.06)&&(xk < cu+((1.0+WATER_WIDTH)/2) + 0.09))) - { - placeTerrain(ix, iz, tSDry); - addToClass(ix, iz, clShore); - } } +}); + RMS.SetProgress(40); log("Creating bumps..."); diff --git a/binaries/data/mods/public/maps/random/unknown.js b/binaries/data/mods/public/maps/random/unknown.js index 88345fb4d5..28447ecc40 100644 --- a/binaries/data/mods/public/maps/random/unknown.js +++ b/binaries/data/mods/public/maps/random/unknown.js @@ -303,108 +303,27 @@ else if (md == 3) //central sea playerX[i] = playerPos[i]; } - var WATER_WIDTH = randFloat(0.22,0.3)+scaleByMapSize(1,4)/20; - log("Creating sea"); - var theta = randFloat(0, 1); - var theta2 = randFloat(0, 1); - var seed = randFloat(2,3); - var seed2 = randFloat(2,3); - for (var ix = 0; ix < mapSize; ix++) - { - for (var iz = 0; iz < mapSize; iz++) - { - var x = ix / (mapSize + 1.0); - var z = iz / (mapSize + 1.0); - - // add the rough shape of the water - var km = 20/scaleByMapSize(35, 160); - - var fadeDist = 0.05; - - if (mdd1 == 1) //vertical - { - var cu = km*rndRiver(theta+z*0.5*(mapSize/64),seed); - var cu2 = km*rndRiver(theta2+z*0.5*(mapSize/64),seed2); - - if ((x > cu + 0.5 - WATER_WIDTH/2) && (x < cu2 + 0.5 + WATER_WIDTH/2)) - { - var h; - if (x < (cu + 0.5 + fadeDist - WATER_WIDTH/2)) - { - h = 3 - 6 * (1 - ((cu + 0.5 + fadeDist - WATER_WIDTH/2) - x)/fadeDist); - } - else if (x > (cu2 + 0.5 - fadeDist + WATER_WIDTH/2)) - { - h = 3 - 6 * (1 - (x - (cu2 + 0.5 - fadeDist + WATER_WIDTH/2))/fadeDist); - } - else - { - h = -3.0; - } - - if (h < -1.5) - { - placeTerrain(ix, iz, tWater); - } - else - { - placeTerrain(ix, iz, tShore); - } - - setHeight(ix, iz, h); - if (h < 0){ - addToClass(ix, iz, clWater); - } - } - else - { - setHeight(ix, iz, 3.1); - addToClass(ix, iz, clLand); - } - } - else //horizontal - { - var cu = km*rndRiver(theta+x*0.5*(mapSize/64),seed); - var cu2 = km*rndRiver(theta2+x*0.5*(mapSize/64),seed2); - - if ((z > cu + 0.5 - WATER_WIDTH/2) && (z < cu2 + 0.5 + WATER_WIDTH/2)) - { - var h; - if (z < (cu + 0.5 + fadeDist - WATER_WIDTH/2)) - { - h = 3 - 6 * (1 - ((cu + 0.5 + fadeDist - WATER_WIDTH/2) - z)/fadeDist); - } - else if (z > (cu2 + 0.5 - fadeDist + WATER_WIDTH/2)) - { - h = 3 - 6 * (1 - (z - (cu2 + 0.5 - fadeDist + WATER_WIDTH/2))/fadeDist); - } - else - { - h = -3.0; - } - - if (h < -1.5) - { - placeTerrain(ix, iz, tWater); - } - else - { - placeTerrain(ix, iz, tShore); - } - - setHeight(ix, iz, h); - if (h < 0){ - addToClass(ix, iz, clWater); - } - } - else - { - setHeight(ix, iz, 3.1); - addToClass(ix, iz, clLand); - } - } + paintRiver({ + "horizontal": mdd1 != 1, + "parallel": false, + "position": 0.5, + "width": randFloat(0.22, 0.3) + scaleByMapSize(1, 4) / 20, + "fadeDist": 0.025, + "deviation": 0, + "waterHeight": -3, + "landHeight": 3, + "meanderShort": 20, + "meanderLong": 0, + "waterFunc": (ix, iz, height) => { + placeTerrain(ix, iz, height < -1.5 ? tWater : tShore); + if (height < 0) + addToClass(ix, iz, clWater); + }, + "landFunc": (ix, iz, shoreDist1, shoreDist2) => { + setHeight(ix, iz, 3.1); + addToClass(ix, iz, clLand); } - } + }); if (randBool(1/3)) { diff --git a/binaries/data/mods/public/maps/random/unknown_land.js b/binaries/data/mods/public/maps/random/unknown_land.js index 260ce1e6cc..07bf6b325e 100644 --- a/binaries/data/mods/public/maps/random/unknown_land.js +++ b/binaries/data/mods/public/maps/random/unknown_land.js @@ -168,108 +168,27 @@ else if (md == 3) //central sea playerX[i] = playerPos[i]; } - var WATER_WIDTH = randFloat(0.22,0.3)+scaleByMapSize(1,4)/20; - log("Creating sea"); - var theta = randFloat(0, 1); - var theta2 = randFloat(0, 1); - var seed = randFloat(2,3); - var seed2 = randFloat(2,3); - for (var ix = 0; ix < mapSize; ix++) - { - for (var iz = 0; iz < mapSize; iz++) - { - var x = ix / (mapSize + 1.0); - var z = iz / (mapSize + 1.0); - - // add the rough shape of the water - var km = 20/scaleByMapSize(35, 160); - - var fadeDist = 0.05; - - if (mdd1 == 1) //vertical - { - var cu = km*rndRiver(theta+z*0.5*(mapSize/64),seed); - var cu2 = km*rndRiver(theta2+z*0.5*(mapSize/64),seed2); - - if ((x > cu + 0.5 - WATER_WIDTH/2) && (x < cu2 + 0.5 + WATER_WIDTH/2)) - { - var h; - if (x < (cu + 0.5 + fadeDist - WATER_WIDTH/2)) - { - h = 3 - 6 * (1 - ((cu + 0.5 + fadeDist - WATER_WIDTH/2) - x)/fadeDist); - } - else if (x > (cu2 + 0.5 - fadeDist + WATER_WIDTH/2)) - { - h = 3 - 6 * (1 - (x - (cu2 + 0.5 - fadeDist + WATER_WIDTH/2))/fadeDist); - } - else - { - h = -3.0; - } - - if (h < -1.5) - { - placeTerrain(ix, iz, tWater); - } - else - { - placeTerrain(ix, iz, tShore); - } - - setHeight(ix, iz, h); - if (h < 0){ - addToClass(ix, iz, clWater); - } - } - else - { - setHeight(ix, iz, 3.1); - addToClass(ix, iz, clLand); - } - } - else //horizontal - { - var cu = km*rndRiver(theta+x*0.5*(mapSize/64),seed); - var cu2 = km*rndRiver(theta2+x*0.5*(mapSize/64),seed2); - - if ((z > cu + 0.5 - WATER_WIDTH/2) && (z < cu2 + 0.5 + WATER_WIDTH/2)) - { - var h; - if (z < (cu + 0.5 + fadeDist - WATER_WIDTH/2)) - { - h = 3 - 6 * (1 - ((cu + 0.5 + fadeDist - WATER_WIDTH/2) - z)/fadeDist); - } - else if (z > (cu2 + 0.5 - fadeDist + WATER_WIDTH/2)) - { - h = 3 - 6 * (1 - (z - (cu2 + 0.5 - fadeDist + WATER_WIDTH/2))/fadeDist); - } - else - { - h = -3.0; - } - - if (h < -1.5) - { - placeTerrain(ix, iz, tWater); - } - else - { - placeTerrain(ix, iz, tShore); - } - - setHeight(ix, iz, h); - if (h < 0){ - addToClass(ix, iz, clWater); - } - } - else - { - setHeight(ix, iz, 3.1); - addToClass(ix, iz, clLand); - } - } + paintRiver({ + "horizontal": mdd1 != 1, + "parallel": false, + "position": 0.5, + "width": randFloat(0.22, 0.3) + scaleByMapSize(1, 4) / 20, + "fadeDist": 0.025, + "deviation": 0, + "waterHeight": -3, + "landHeight": 3, + "meanderShort": 20, + "meanderLong": 0, + "waterFunc": (ix, iz, height) => { + placeTerrain(ix, iz, height < -1.5 ? tWater : tShore); + if (height < 0) + addToClass(ix, iz, clWater); + }, + "landFunc": (ix, iz, shoreDist1, shoreDist2) => { + setHeight(ix, iz, 3.1); + addToClass(ix, iz, clLand); } - } + }); // linked if (mdd1 == 1) //vertical diff --git a/binaries/data/mods/public/maps/random/unknown_nomad.js b/binaries/data/mods/public/maps/random/unknown_nomad.js index c3580acf15..ad26bfcb43 100644 --- a/binaries/data/mods/public/maps/random/unknown_nomad.js +++ b/binaries/data/mods/public/maps/random/unknown_nomad.js @@ -216,108 +216,27 @@ else if (md == 3) //central sea { var playerIDs = primeSortAllPlayers(); - var WATER_WIDTH = randFloat(0.22,0.3)+scaleByMapSize(1,4)/20; - log("Creating sea"); - var theta = randFloat(0, 1); - var theta2 = randFloat(0, 1); - var seed = randFloat(2,3); - var seed2 = randFloat(2,3); - for (var ix = 0; ix < mapSize; ix++) - { - for (var iz = 0; iz < mapSize; iz++) - { - var x = ix / (mapSize + 1.0); - var z = iz / (mapSize + 1.0); - - // add the rough shape of the water - var km = 20/scaleByMapSize(35, 160); - - var fadeDist = 0.05; - - if (mdd1 == 1) //vertical - { - var cu = km*rndRiver(theta+z*0.5*(mapSize/64),seed); - var cu2 = km*rndRiver(theta2+z*0.5*(mapSize/64),seed2); - - if ((x > cu + 0.5 - WATER_WIDTH/2) && (x < cu + 0.5 + WATER_WIDTH/2)) - { - var h; - if (x < (cu + 0.5 + fadeDist - WATER_WIDTH/2)) - { - h = 3 - 6 * (1 - ((cu + 0.5 + fadeDist - WATER_WIDTH/2) - x)/fadeDist); - } - else if (x > (cu2 + 0.5 - fadeDist + WATER_WIDTH/2)) - { - h = 3 - 6 * (1 - (x - (cu2 + 0.5 - fadeDist + WATER_WIDTH/2))/fadeDist); - } - else - { - h = -3.0; - } - - if (h < -1.5) - { - placeTerrain(ix, iz, tWater); - } - else - { - placeTerrain(ix, iz, tShore); - } - - setHeight(ix, iz, h); - if (h < 0){ - addToClass(ix, iz, clWater); - } - } - else - { - setHeight(ix, iz, 3.1); - addToClass(ix, iz, clLand); - } - } - else //horizontal - { - var cu = km*rndRiver(theta+x*0.5*(mapSize/64),seed); - var cu2 = km*rndRiver(theta2+x*0.5*(mapSize/64),seed2); - - if ((z > cu + 0.5 - WATER_WIDTH/2) && (z < cu + 0.5 + WATER_WIDTH/2)) - { - var h; - if (z < (cu + 0.5 + fadeDist - WATER_WIDTH/2)) - { - h = 3 - 6 * (1 - ((cu + 0.5 + fadeDist - WATER_WIDTH/2) - z)/fadeDist); - } - else if (z > (cu2 + 0.5 - fadeDist + WATER_WIDTH/2)) - { - h = 3 - 6 * (1 - (z - (cu2 + 0.5 - fadeDist + WATER_WIDTH/2))/fadeDist); - } - else - { - h = -3.0; - } - - if (h < -1.5) - { - placeTerrain(ix, iz, tWater); - } - else - { - placeTerrain(ix, iz, tShore); - } - - setHeight(ix, iz, h); - if (h < 0){ - addToClass(ix, iz, clWater); - } - } - else - { - setHeight(ix, iz, 3.1); - addToClass(ix, iz, clLand); - } - } + paintRiver({ + "horizontal": mdd1 != 1, + "parallel": false, + "position": 0.5, + "width": randFloat(0.22, 0.3) + scaleByMapSize(1, 4) / 20, + "fadeDist": 0.025, + "deviation": 0, + "waterHeight": -3, + "landHeight": 3, + "meanderShort": 20, + "meanderLong": 0, + "waterFunc": (ix, iz, height) => { + placeTerrain(ix, iz, height < -1.5 ? tWater : tShore); + if (height < 0) + addToClass(ix, iz, clWater); + }, + "landFunc": (ix, iz, shoreDist1, shoreDist2) => { + setHeight(ix, iz, 3.1); + addToClass(ix, iz, clLand); } - } + }); if (randBool(1/3)) {