Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/maps/random/rmgen/misc.js
Show First 20 Lines • Show All 631 Lines • ▼ Show 20 Lines | function createMountain(maxHeight, minRadius, maxRadius, numCircles, constraint, x, z, terrain, tileclass, fcc, q) | ||||
var circles = []; | var circles = []; | ||||
for (var i = 0; i < numCircles; ++i) | for (var i = 0; i < numCircles; ++i) | ||||
{ | { | ||||
var badPoint = false; | var badPoint = false; | ||||
var [cx, cz] = pickRandom(edges); | var [cx, cz] = pickRandom(edges); | ||||
if (queueEmpty) | if (queueEmpty) | ||||
{ | var radius = randIntInclusive(minRadius, maxRadius); | ||||
var radius = randInt(minRadius, maxRadius); | |||||
} | |||||
else | else | ||||
{ | { | ||||
var radius = q.pop(); | var radius = q.pop(); | ||||
queueEmpty = (q.length ? false : true); | queueEmpty = (q.length ? false : true); | ||||
} | } | ||||
var sx = cx - radius, lx = cx + radius; | var sx = cx - radius, lx = cx + radius; | ||||
var sz = cz - radius, lz = cz + radius; | var sz = cz - radius, lz = cz + radius; | ||||
▲ Show 20 Lines • Show All 131 Lines • ▼ Show 20 Lines | for (var i = 0; i < numFinalCircles; ++i) | ||||
for (var ix = sx; ix <= lx; ++ix) | for (var ix = sx; ix <= lx; ++ix) | ||||
{ | { | ||||
for (var iz = sz; iz <= lz; ++ iz) | for (var iz = sz; iz <= lz; ++ iz) | ||||
{ | { | ||||
dx = ix - cx; | dx = ix - cx; | ||||
dz = iz - cz; | dz = iz - cz; | ||||
distance2 = dx * dx + dz * dz; | distance2 = dx * dx + dz * dz; | ||||
var newHeight = round((Math.sin(PI*(2*((radius - sqrt(distance2))/radius)/3 - 1/6)) + 0.5) * 2 / 3 *clumpHeight) + randInt(0,2); | var newHeight = Math.round((Math.sin(PI * (2 * ((radius - Math.sqrt(distance2)) / radius) / 3 - 1/6)) + 0.5) * 2/3 * clumpHeight) + randIntInclusive(0, 2); | ||||
if (dx * dx + dz * dz <= radius2) | if (dx * dx + dz * dz <= radius2) | ||||
{ | { | ||||
if (g_Map.getHeight(ix, iz) < newHeight) | if (g_Map.getHeight(ix, iz) < newHeight) | ||||
g_Map.setHeight(ix, iz, newHeight); | g_Map.setHeight(ix, iz, newHeight); | ||||
else if (g_Map.getHeight(ix, iz) >= newHeight && g_Map.getHeight(ix, iz) < newHeight + 4) | else if (g_Map.getHeight(ix, iz) >= newHeight && g_Map.getHeight(ix, iz) < newHeight + 4) | ||||
g_Map.setHeight(ix, iz, newHeight + 4); | g_Map.setHeight(ix, iz, newHeight + 4); | ||||
if (terrain !== undefined) | if (terrain !== undefined) | ||||
placeTerrain(ix, iz, terrain); | placeTerrain(ix, iz, terrain); | ||||
if (tileclass !== undefined) | if (tileclass !== undefined) | ||||
addToClass(ix, iz, tileclass); | addToClass(ix, iz, tileclass); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } |
Wildfire Games · Phabricator