Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/maps/random/latium.js
Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | |||||
const clCliff = g_Map.createTileClass(); | const clCliff = g_Map.createTileClass(); | ||||
const clForest = g_Map.createTileClass(); | const clForest = g_Map.createTileClass(); | ||||
const clMetal = g_Map.createTileClass(); | const clMetal = g_Map.createTileClass(); | ||||
const clRock = g_Map.createTileClass(); | const clRock = g_Map.createTileClass(); | ||||
const clFood = g_Map.createTileClass(); | const clFood = g_Map.createTileClass(); | ||||
const clPlayer = g_Map.createTileClass(); | const clPlayer = g_Map.createTileClass(); | ||||
const clBaseResource = g_Map.createTileClass(); | const clBaseResource = g_Map.createTileClass(); | ||||
var WATER_WIDTH = 0.1; | const WATER_WIDTH = 0.1; | ||||
var horizontal = randBool(); | |||||
g_Map.log("Creating players"); | g_Map.log("Creating players"); | ||||
var startAngle = randBool() ? 0 : Math.PI / 2; | const startAngle = randBool() ? 0 : Math.PI / 2; | ||||
var playerPosition = playerPlacementLine(startAngle + Math.PI / 2, mapCenter, fractionToTiles(randFloat(0.42, 0.46))); | const playerPosition = playerPlacementLine(startAngle + Math.PI / 2, mapCenter, | ||||
fractionToTiles(randFloat(0.42, 0.46))); | |||||
function distanceToPlayers(x, z) | function distanceToPlayers(x, z) | ||||
{ | { | ||||
let r = Infinity; | let r = Infinity; | ||||
for (let i = 0; i < numPlayers; ++i) | for (let i = 0; i < numPlayers; ++i) | ||||
{ | { | ||||
let dx = x - tilesToFraction(playerPosition[i].x); | let dx = x - tilesToFraction(playerPosition[i].x); | ||||
let dz = z - tilesToFraction(playerPosition[i].y); | let dz = z - tilesToFraction(playerPosition[i].y); | ||||
Show All 29 Lines | paintRiver({ | ||||
"meanderLong": 0, | "meanderLong": 0, | ||||
"waterFunc": (position, height, z) => { | "waterFunc": (position, height, z) => { | ||||
clWater.add(position); | clWater.add(position); | ||||
} | } | ||||
}); | }); | ||||
Engine.SetProgress(10); | Engine.SetProgress(10); | ||||
g_Map.log("Painting elevation"); | g_Map.log("Painting elevation"); | ||||
var noise0 = new Noise2D(scaleByMapSize(4, 16)); | const noise0 = new Noise2D(scaleByMapSize(4, 16)); | ||||
var noise1 = new Noise2D(scaleByMapSize(8, 32)); | const noise1 = new Noise2D(scaleByMapSize(8, 32)); | ||||
var noise2 = new Noise2D(scaleByMapSize(15, 60)); | const noise2 = new Noise2D(scaleByMapSize(15, 60)); | ||||
var noise2a = new Noise2D(scaleByMapSize(20, 80)); | const noise2a = new Noise2D(scaleByMapSize(20, 80)); | ||||
var noise2b = new Noise2D(scaleByMapSize(35, 140)); | const noise2b = new Noise2D(scaleByMapSize(35, 140)); | ||||
var noise3 = new Noise2D(scaleByMapSize(4, 16)); | const noise3 = new Noise2D(scaleByMapSize(4, 16)); | ||||
var noise4 = new Noise2D(scaleByMapSize(6, 24)); | const noise4 = new Noise2D(scaleByMapSize(6, 24)); | ||||
var noise5 = new Noise2D(scaleByMapSize(11, 44)); | const noise5 = new Noise2D(scaleByMapSize(11, 44)); | ||||
for (var ix = 0; ix <= mapSize; ix++) | for (let ix = 0; ix <= mapSize; ix++) | ||||
for (var iz = 0; iz <= mapSize; iz++) | for (let iz = 0; iz <= mapSize; iz++) | ||||
{ | { | ||||
const position = new Vector2D(ix, iz); | const position = new Vector2D(ix, iz); | ||||
var x = ix / (mapSize + 1.0); | const x = ix / (mapSize + 1.0); | ||||
var z = iz / (mapSize + 1.0); | const z = iz / (mapSize + 1.0); | ||||
var pn = playerNearness(x, z); | const pn = playerNearness(x, z); | ||||
const c = startAngle ? z : x; | const c = startAngle ? z : x; | ||||
const distToWater = clWater.has(position) ? 0 : (0.5 - WATER_WIDTH - Math.abs(c - 0.5)); | const distToWater = clWater.has(position) ? 0 : (0.5 - WATER_WIDTH - Math.abs(c - 0.5)); | ||||
let h = distToWater ? heightHill * (1 - Math.abs(c - 0.5) / (0.5 - WATER_WIDTH)) : g_Map.getHeight(position); | let h = distToWater ? heightHill * (1 - Math.abs(c - 0.5) / (0.5 - WATER_WIDTH)) : g_Map.getHeight(position); | ||||
// add some base noise | // add some base noise | ||||
var baseNoise = 16*noise0.get(x,z) + 8*noise1.get(x,z) + 4*noise2.get(x,z) - (16+8+4)/2; | let baseNoise = | ||||
16 * noise0.get(x, z) + | |||||
8 * noise1.get(x, z) + | |||||
4 * noise2.get(x, z) - | |||||
(16 + 8 + 4) / 2; | |||||
if ( baseNoise < 0 ) | if ( baseNoise < 0 ) | ||||
{ | { | ||||
baseNoise *= pn; | baseNoise *= pn; | ||||
baseNoise *= Math.max(0.1, distToWater / (0.5 - WATER_WIDTH)); | baseNoise *= Math.max(0.1, distToWater / (0.5 - WATER_WIDTH)); | ||||
} | } | ||||
const oldH = h; | const oldH = h; | ||||
h += baseNoise; | h += baseNoise; | ||||
Show All 22 Lines | if ( h > -10 ) | ||||
if (cliffNoise > 0) | if (cliffNoise > 0) | ||||
h += 19 * Math.min(cliffNoise, 0.045) / 0.045; | h += 19 * Math.min(cliffNoise, 0.045) / 0.045; | ||||
} | } | ||||
g_Map.setHeight(position, h); | g_Map.setHeight(position, h); | ||||
} | } | ||||
Engine.SetProgress(20); | Engine.SetProgress(20); | ||||
g_Map.log("Painting terrain"); | g_Map.log("Painting terrain"); | ||||
var noise6 = new Noise2D(scaleByMapSize(10, 40)); | const noise6 = new Noise2D(scaleByMapSize(10, 40)); | ||||
var noise7 = new Noise2D(scaleByMapSize(20, 80)); | const noise7 = new Noise2D(scaleByMapSize(20, 80)); | ||||
var noise8 = new Noise2D(scaleByMapSize(13, 52)); | const noise8 = new Noise2D(scaleByMapSize(13, 52)); | ||||
var noise9 = new Noise2D(scaleByMapSize(26, 104)); | const noise9 = new Noise2D(scaleByMapSize(26, 104)); | ||||
var noise10 = new Noise2D(scaleByMapSize(50, 200)); | const noise10 = new Noise2D(scaleByMapSize(50, 200)); | ||||
for (var ix = 0; ix < mapSize; ix++) | for (let ix = 0; ix < mapSize; ix++) | ||||
for (var iz = 0; iz < mapSize; iz++) | for (let iz = 0; iz < mapSize; iz++) | ||||
{ | { | ||||
const position = new Vector2D(ix, iz); | const position = new Vector2D(ix, iz); | ||||
var x = ix / (mapSize + 1.0); | const x = ix / (mapSize + 1.0); | ||||
var z = iz / (mapSize + 1.0); | const z = iz / (mapSize + 1.0); | ||||
var pn = playerNearness(x, z); | const pn = playerNearness(x, z); | ||||
// Compute height difference | // Compute height difference | ||||
let minH = +Infinity; | let minH = +Infinity; | ||||
let maxH = -Infinity; | let maxH = -Infinity; | ||||
for (const vertex of g_TileVertices) | for (const vertex of g_TileVertices) | ||||
{ | { | ||||
const height = g_Map.getHeight(Vector2D.add(position, vertex)); | const height = g_Map.getHeight(Vector2D.add(position, vertex)); | ||||
minH = Math.min(minH, height); | minH = Math.min(minH, height); | ||||
maxH = Math.max(maxH, height); | maxH = Math.max(maxH, height); | ||||
} | } | ||||
var diffH = maxH - minH; | const diffH = maxH - minH; | ||||
// figure out if we're at the top of a cliff using min adjacent height | // figure out if we're at the top of a cliff using min adjacent height | ||||
var minAdjHeight = minH; | let minAdjHeight = minH; | ||||
if (maxH > 15) | if (maxH > 15) | ||||
{ | { | ||||
var maxNx = Math.min(ix + 2, mapSize); | const maxNx = Math.min(ix + 2, mapSize); | ||||
var maxNz = Math.min(iz + 2, mapSize); | const maxNz = Math.min(iz + 2, mapSize); | ||||
for (let nx = Math.max(ix - 1, 0); nx <= maxNx; ++nx) | for (let nx = Math.max(ix - 1, 0); nx <= maxNx; ++nx) | ||||
for (let nz = Math.max(iz - 1, 0); nz <= maxNz; ++nz) | for (let nz = Math.max(iz - 1, 0); nz <= maxNz; ++nz) | ||||
minAdjHeight = Math.min(minAdjHeight, g_Map.getHeight(new Vector2D(nx, nz))); | minAdjHeight = Math.min(minAdjHeight, g_Map.getHeight(new Vector2D(nx, nz))); | ||||
} | } | ||||
// choose a terrain based on elevation | // choose a terrain based on elevation | ||||
let t = tGrass; | let t = tGrass; | ||||
Show All 36 Lines | for (let iz = 0; iz < mapSize; iz++) | ||||
// Don't place resources onto potentially impassable mountains | // Don't place resources onto potentially impassable mountains | ||||
if (minH >= 20) | if (minH >= 20) | ||||
clCliff.add(position); | clCliff.add(position); | ||||
// forests | // forests | ||||
if (g_Map.getHeight(position) < 11 && diffH < 2 && minH > 1) | if (g_Map.getHeight(position) < 11 && diffH < 2 && minH > 1) | ||||
{ | { | ||||
var forestNoise = (noise6.get(x,z) + 0.5*noise7.get(x,z)) / 1.5 * pn - 0.59; | const forestNoise = (noise6.get(x, z) + 0.5 * noise7.get(x, z)) / 1.5 * pn - 0.59; | ||||
// Thin out trees a bit | // Thin out trees a bit | ||||
if (forestNoise > 0 && randBool()) | if (forestNoise > 0 && randBool()) | ||||
{ | { | ||||
if (minH < 11 && minH >= 4) | if (minH < 11 && minH >= 4) | ||||
{ | { | ||||
const typeNoise = noise10.get(x,z); | const typeNoise = noise10.get(x,z); | ||||
Show All 12 Lines | if (g_Map.getHeight(position) < 11 && diffH < 2 && minH > 1) | ||||
clForest.add(position); | clForest.add(position); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// grass variations | // grass variations | ||||
if (t == tGrass) | if (t == tGrass) | ||||
{ | { | ||||
var grassNoise = (noise8.get(x,z) + 0.6*noise9.get(x,z)) / 1.6; | const grassNoise = (noise8.get(x, z) + 0.6 * noise9.get(x, z)) / 1.6; | ||||
if (grassNoise < 0.3) | if (grassNoise < 0.3) | ||||
t = (diffH > 1.2) ? tDirtCliff : tDirt; | t = (diffH > 1.2) ? tDirtCliff : tDirt; | ||||
else if (grassNoise < 0.34) | else if (grassNoise < 0.34) | ||||
{ | { | ||||
t = (diffH > 1.2) ? tGrassCliff : tGrassDry; | t = (diffH > 1.2) ? tGrassCliff : tGrassDry; | ||||
if (diffH < 0.5 && randBool(0.02)) | if (diffH < 0.5 && randBool(0.02)) | ||||
g_Map.placeEntityAnywhere(aGrassDry, 0, randomPositionOnTile(position), randomAngle()); | g_Map.placeEntityAnywhere(aGrassDry, 0, randomPositionOnTile(position), randomAngle()); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | "Trees": { | ||||
"minDist": 10, | "minDist": 10, | ||||
"maxDist": 11 | "maxDist": 11 | ||||
} | } | ||||
// No decoratives | // No decoratives | ||||
}); | }); | ||||
Engine.SetProgress(40); | Engine.SetProgress(40); | ||||
g_Map.log("Creating bushes"); | g_Map.log("Creating bushes"); | ||||
var group = new SimpleGroup( | let group = new SimpleGroup( | ||||
[new SimpleObject(aBushSmall, 0,2, 0,2), new SimpleObject(aBushSmallDry, 0,2, 0,2), | [new SimpleObject(aBushSmall, 0,2, 0,2), new SimpleObject(aBushSmallDry, 0,2, 0,2), | ||||
new SimpleObject(aBushMed, 0,1, 0,2), new SimpleObject(aBushMedDry, 0,1, 0,2)] | new SimpleObject(aBushMed, 0,1, 0,2), new SimpleObject(aBushMedDry, 0,1, 0,2)] | ||||
); | ); | ||||
createObjectGroupsDeprecated(group, 0, | createObjectGroupsDeprecated(group, 0, | ||||
avoidClasses(clWater, 4, clCliff, 2), | avoidClasses(clWater, 4, clCliff, 2), | ||||
scaleByMapSize(9, 146), 50 | scaleByMapSize(9, 146), 50 | ||||
); | ); | ||||
Engine.SetProgress(45); | Engine.SetProgress(45); | ||||
▲ Show 20 Lines • Show All 101 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator