Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/maps/random/rmgen2/gaia.js
Show First 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | for (var i = 0; i < count; ++i) | ||||
var points = rendered[0].points; | var points = rendered[0].points; | ||||
var corners = findCorners(points); | var corners = findCorners(points); | ||||
// Seed an array the size of the bounding box | // Seed an array the size of the bounding box | ||||
var bb = createBoundingBox(points, corners); | var bb = createBoundingBox(points, corners); | ||||
// Get a random starting position for the baseline and the endline | // Get a random starting position for the baseline and the endline | ||||
var angle = randInt(4); | var angle = randIntInclusive(0, 3); | ||||
var opAngle = angle - 2; | var opAngle = angle - 2; | ||||
if (angle < 2) | if (angle < 2) | ||||
opAngle = angle + 2; | opAngle = angle + 2; | ||||
// Find the edges of the bluff | // Find the edges of the bluff | ||||
var baseLine; | var baseLine; | ||||
var endLine; | var endLine; | ||||
▲ Show 20 Lines • Show All 310 Lines • ▼ Show 20 Lines | function addElevation(constraint, el) | ||||
var widths = []; | var widths = []; | ||||
// Allow for shore and cliff rendering | // Allow for shore and cliff rendering | ||||
for (var s = el.painter.length; s > 2; --s) | for (var s = el.painter.length; s > 2; --s) | ||||
widths.push(1); | widths.push(1); | ||||
for (var i = 0; i < count; ++i) | for (var i = 0; i < count; ++i) | ||||
{ | { | ||||
var elevation = el.minElevation + randInt(el.maxElevation - el.minElevation); | var elevation = randIntExclusive(el.minElevation, el.maxElevation); | ||||
var smooth = Math.floor(elevation / el.steepness); | var smooth = Math.floor(elevation / el.steepness); | ||||
var offset = getRandomDeviation(size, el.deviation); | var offset = getRandomDeviation(size, el.deviation); | ||||
var pMinSize = Math.floor(minSize * offset); | var pMinSize = Math.floor(minSize * offset); | ||||
var pMaxSize = Math.floor(maxSize * offset); | var pMaxSize = Math.floor(maxSize * offset); | ||||
var pSpread = Math.floor(spread * offset); | var pSpread = Math.floor(spread * offset); | ||||
var pSmooth = Math.abs(Math.floor(smooth * offset)); | var pSmooth = Math.abs(Math.floor(smooth * offset)); | ||||
var pElevation = Math.floor(elevation * offset); | var pElevation = Math.floor(elevation * offset); | ||||
▲ Show 20 Lines • Show All 185 Lines • ▼ Show 20 Lines | addElevation(constraint, { | ||||
"maxElevation": 30, | "maxElevation": 30, | ||||
"steepness": 8 | "steepness": 8 | ||||
}); | }); | ||||
for (var i = 0; i < 40; ++i) | for (var i = 0; i < 40; ++i) | ||||
{ | { | ||||
var placer = new ChainPlacer(3, 15, 1, 0.5); | var placer = new ChainPlacer(3, 15, 1, 0.5); | ||||
var terrainPainter = new LayeredPainter([plateauTile, plateauTile], [3]); | var terrainPainter = new LayeredPainter([plateauTile, plateauTile], [3]); | ||||
var hillElevation = 4 + randInt(15); | var hillElevation = randIntInclusive(4, 18); | ||||
var elevationPainter = new SmoothElevationPainter(ELEVATION_MODIFY, hillElevation, hillElevation - 2); | var elevationPainter = new SmoothElevationPainter(ELEVATION_MODIFY, hillElevation, hillElevation - 2); | ||||
createAreas( | createAreas( | ||||
placer, | placer, | ||||
[ | [ | ||||
terrainPainter, | terrainPainter, | ||||
elevationPainter, | elevationPainter, | ||||
paintClass(g_TileClasses.hill) | paintClass(g_TileClasses.hill) | ||||
▲ Show 20 Lines • Show All 654 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
/** | /** | ||||
* Returns a number within a random deviation of a base number. | * Returns a number within a random deviation of a base number. | ||||
*/ | */ | ||||
function getRandomDeviation(base, deviation) | function getRandomDeviation(base, deviation) | ||||
{ | { | ||||
deviation = Math.min(base, deviation); | deviation = Math.min(base, deviation); | ||||
deviation = base + randInt(20 * deviation) / 10 - deviation; | deviation = base + randIntExclusive(0, 20 * deviation) / 10 - deviation; | ||||
return deviation.toFixed(2); | return deviation.toFixed(2); | ||||
} | } | ||||
/** | /** | ||||
* Import a given digital elevation model. | * Import a given digital elevation model. | ||||
* Scale it to the mapsize and paint the textures specified by coordinate on it. | * Scale it to the mapsize and paint the textures specified by coordinate on it. | ||||
* | * | ||||
* @param heightmap - An array with a square number of heights | * @param heightmap - An array with a square number of heights | ||||
▲ Show 20 Lines • Show All 51 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator