Page MenuHomeWildfire Games
Paste P125

smileys mapgen noise generator
ActivePublic

Authored by elexis on May 25 2018, 10:51 PM.
Index: binaries/data/mods/public/maps/random/anatolian_plateau.js
===================================================================
--- binaries/data/mods/public/maps/random/anatolian_plateau.js (revision 21820)
+++ binaries/data/mods/public/maps/random/anatolian_plateau.js (working copy)
@@ -1,5 +1,6 @@
Engine.LoadLibrary("rmgen");
Engine.LoadLibrary("rmgen-common");
+Engine.LoadLibrary("heightmap");
const tPrimary = ["steppe_grass_a", "steppe_grass_c", "steppe_grass_d"];
const tGrass = ["steppe_grass_a", "steppe_grass_b", "steppe_grass_c", "steppe_grass_d"];
@@ -35,6 +36,8 @@
var g_Map = new RandomMap(heightLand, tPrimary);
+setBaseTerrainPerlinNoise(24, 1, 2); // change last param to something like 20 to see stuff easily.
+
var numPlayers = getNumPlayers();
var clPlayer = g_Map.createTileClass();
Index: binaries/data/mods/public/maps/random/heightmap/heightmap.js
===================================================================
--- binaries/data/mods/public/maps/random/heightmap/heightmap.js (revision 21820)
+++ binaries/data/mods/public/maps/random/heightmap/heightmap.js (working copy)
@@ -1,3 +1,4 @@
+Engine.LoadLibrary("rmgen");
/**
* Heightmap manipulation functionality
*
@@ -224,6 +225,32 @@
}
/**
+ * TODO: Docs
+ */
+function setBaseTerrainPerlinNoise(frequency = 24, octaves = 1, heightScale = 2)
+{
+ let noise2D = new Noise2D(frequency);
+ let heightMap = g_Map.height;
+ for (let octave = 0; octave < octaves; ++octave)
+ {
+ for (let x = 0; x < heightMap.length; ++x)
+ {
+ for (let y = 0; y < heightMap[0].length; ++y)
+ {
+ let ix = x / heightMap.length;
+ let iy = y / heightMap.length;
+ heightMap[x][y] += noise2D.get(ix, iy) * heightScale;
+ }
+ }
+ frequency *= 0.75; // kinda simplistic and crude.
+ // even cruder.
+ heightScale *= 0.75; // not sure about this.
+ noise2D = new Noise2D(frequency);
+ }
+ return heightMap
+}
+
+/**
* Meant to place e.g. resource spots within a height range
* @param {array} [heightRange] - The height range in which to place the entities (An associative array with keys "min" and "max" each containing a float)
* @param {array} [avoidPoints=[]] - An array of objects of the form { "x": int, "y": int, "dist": int }, points that will be avoided in the given dist e.g. start locations

Event Timeline

elexis created this paste.May 25 2018, 10:51 PM
lyv changed the visibility from "All Users" to "Public (No Login Required)".Mar 25 2019, 8:52 PM