1
0
forked from 0ad/0ad

Remove usage of var in map scripts

Comments by: @Stan, @sera @elexis
Differential Revision: https://code.wildfiregames.com/D5273
This was SVN commit r28101.
This commit is contained in:
phosit 2024-06-04 19:39:19 +00:00
parent c6df8f9372
commit 922ab00c06
8 changed files with 83 additions and 80 deletions

View File

@ -200,7 +200,7 @@ Engine.SetProgress(75);
// Roaming animals
{
var placeRoaming = function(name, objs)
const placeRoaming = function(name, objs)
{
g_Map.log("Creating roaming " + name);
const group = new SimpleGroup(objs, true, clFood);
@ -237,7 +237,7 @@ Engine.SetProgress(75);
// Animals that hang around watering holes
{
// TODO: these have a high retry factor because our mapgen constraint logic is bad.
var placeWateringHoleAnimals = function(name, objs, numberOfGroups)
const placeWateringHoleAnimals = function(name, objs, numberOfGroups)
{
g_Map.log("Creating " + name + " around watering holes");
const group = new SimpleGroup(objs, true, clFood);

View File

@ -236,10 +236,10 @@ MountainRangeBuilder.prototype.CreateMountainRanges = function(map)
setBiome(g_MapSettings.Biome ?? "alpine/winter");
var heightLand = 3;
var heightOffsetBump = 2;
var snowlineHeight = 29;
var heightMountain = 30;
const heightLand = 3;
const heightOffsetBump = 2;
const snowlineHeight = 29;
const heightMountain = 30;
const pForest = [g_Terrains.forestFloor + TERRAIN_SEPARATOR + g_Gaia.tree1, g_Terrains.forestFloor];
@ -257,7 +257,7 @@ const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
var [playerIDs, playerPosition, playerAngle, startAngle] = playerPlacementCircle(fractionToTiles(0.35));
const [playerIDs, playerPosition, playerAngle, startAngle] = playerPlacementCircle(fractionToTiles(0.35));
placePlayerBases({
"PlayerPlacement": [playerIDs, playerPosition],
@ -341,7 +341,7 @@ const types = [
[[g_Terrains.forestFloor, g_Terrains.mainTerrain, pForest], [g_Terrains.forestFloor, pForest]]
];
var size = forestTrees / (scaleByMapSize(2,8) * numPlayers);
const size = forestTrees / (scaleByMapSize(2, 8) * numPlayers);
const num = Math.floor(size / types.length);
for (const type of types)
@ -382,7 +382,7 @@ for (const size of [scaleByMapSize(2, 32), scaleByMapSize(3, 48), scaleByMapSize
Engine.SetProgress(65);
g_Map.log("Creating stone mines");
var group = new SimpleGroup(
let group = new SimpleGroup(
[
new SimpleObject(g_Gaia.stoneSmall, 0, 2, 0, 4, 0, 2 * Math.PI, 1),
new SimpleObject(g_Gaia.stoneLarge, 1, 1, 0, 4, 0, 2 * Math.PI, 4)
@ -473,7 +473,7 @@ createStragglerTrees(
stragglerTrees);
g_Map.log("Creating small grass tufts");
var planetm = 1;
const planetm = 1;
group = new SimpleGroup(
[new SimpleObject(g_Decoratives.grassShort, 1, 2, 0, 1, -Math.PI / 8, Math.PI / 8)]

View File

@ -302,32 +302,32 @@ for (let ix = 0; ix < mapSize; ix++)
Engine.SetProgress(60);
g_Map.log("Creating forests");
var [forestTrees, stragglerTrees] = getTreeCounts(1300, 8000, 0.8);
var [forestTreesJoin, forestTrees] = getTreeCounts(forestTrees, forestTrees, 0.25);
const [protoPorestTrees, stragglerTrees] = getTreeCounts(1300, 8000, 0.8);
const [forestTreesJoin, forestTrees] = getTreeCounts(protoPorestTrees, protoPorestTrees, 0.25);
var num = forestTrees / scaleByMapSize(20, 70);
const treeNum = forestTrees / scaleByMapSize(20, 70);
createAreasInAreas(
new ClumpPlacer(forestTrees / num, 0.1, 0.1, Infinity),
new ClumpPlacer(forestTrees / treeNum, 0.1, 0.1, Infinity),
[
new TerrainPainter(pForest),
new TileClassPainter(clForest)
],
avoidClasses(clPlayer, 5, clBaseResource, 4, clForest, 5, clHill, 4),
num,
treeNum,
100,
[explorableArea]
);
var num = forestTreesJoin / (scaleByMapSize(4, 6) * numPlayers);
const joinNum = forestTreesJoin / (scaleByMapSize(4, 6) * numPlayers);
createAreasInAreas(
new ClumpPlacer(forestTreesJoin / num, 0.1, 0.1, Infinity),
new ClumpPlacer(forestTreesJoin / joinNum, 0.1, 0.1, Infinity),
[
new TerrainPainter(pForest),
new TileClassPainter(clForest),
new TileClassPainter(clForestJoin)
],
[avoidClasses(clPlayer, 5, clBaseResource, 4, clForestJoin, 5, clHill, 4), borderClasses(clForest, 1, 4)],
num,
joinNum,
100,
[explorableArea]
);
@ -436,13 +436,13 @@ Engine.SetProgress(90);
g_Map.log("Creating straggler trees");
const types = [oOak, oOakLarge, oPine, oAleppoPine];
var num = Math.floor(stragglerTrees / types.length);
const stragglerNum = Math.floor(stragglerTrees / types.length);
for (const type of types)
createObjectGroupsByAreasDeprecated(
new SimpleGroup([new SimpleObject(type, 1, 1, 0, 3)], true, clForest),
0,
avoidClasses(clForest, 4, clHill, 5, clPlayer, 10, clBaseResource, 2, clMetal, 5, clRock, 5),
num, 20,
stragglerNum, 20,
[explorableArea]);
Engine.SetProgress(95);

View File

@ -85,8 +85,8 @@ const centralIslandPosition = new Array(numPlayers).fill(0).map((v, i) =>
const areas = [];
var nPlayer = 0;
var playerPosition = [];
let nPlayer = 0;
const playerPosition = [];
function createCycladicArchipelagoIsland(position, tileClass, radius, coralRadius)
{
@ -186,7 +186,7 @@ Engine.SetProgress(38);
paintTileClassBasedOnHeight(-Infinity, 0, Elevation_ExcludeMin_ExcludeMax, clWater);
g_Map.log("Creating forests");
var forestTypes = [
const forestTypes = [
[[tForestFloor, tGrass, pPalmForest], [tForestFloor, pPalmForest]],
[[tForestFloor, tGrass, pPineForest], [tForestFloor, pPineForest]],
[[tForestFloor, tGrass, pPoplarForest], [tForestFloor, pPoplarForest]],

View File

@ -196,19 +196,19 @@ createObjectGroupsDeprecated(
10 * numPlayers,
60);
var [forestTrees, stragglerTrees] = getTreeCounts(...rBiomeTreeCount(0.7));
const [forestTreesMainIsland, stragglerTreesMainIsland] = getTreeCounts(...rBiomeTreeCount(0.7));
createForests(
[tMainTerrain, tForestFloor1, tForestFloor2, pForest1, pForest2],
[avoidClasses(clPlayer, 25, clForest, 10, clBaseResource, 3, clMetal, 6, clRock, 6, clMountain, 2), stayClasses(clHill, 6)],
clForest,
forestTrees);
forestTreesMainIsland);
const types = [oTree1, oTree2, oTree4, oTree3];
createStragglerTrees(
types,
[avoidClasses(clBaseResource, 2, clMetal, 6, clRock, 6, clMountain, 2, clPlayer, 25), stayClasses(clHill, 6)],
clForest,
stragglerTrees);
stragglerTreesMainIsland);
Engine.SetProgress(65);
g_Map.log("Creating dirt patches");
@ -256,7 +256,7 @@ createFood(
Engine.SetProgress(85);
var planetm = currentBiome() == "generic/india" ? 8 : 1;
const planetm = currentBiome() == "generic/india" ? 8 : 1;
createDecoration(
[
[new SimpleObject(aRockMedium, 1, 3, 0, 1)],
@ -274,12 +274,12 @@ createDecoration(
],
avoidClasses(clForest, 2, clPlayer, 20, clMountain, 5, clFood, 1, clBaseResource, 2));
var [forestTrees, stragglerTrees] = getTreeCounts(...rBiomeTreeCount(0.1));
const [forestTreesSurrounding, stragglerTreesSurrounding] = getTreeCounts(...rBiomeTreeCount(0.1));
createForests(
[tMainTerrain, tForestFloor1, tForestFloor2, pForest1, pForest2],
avoidClasses(clPlayer, 30, clHill, 10, clFood, 5),
clForest,
forestTrees);
forestTreesSurrounding);
g_Map.log("Creating small grass tufts");
createObjectGroupsDeprecated(

View File

@ -71,12 +71,12 @@ const clFood = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
var WATER_WIDTH = 0.1;
var horizontal = randBool();
const WATER_WIDTH = 0.1;
g_Map.log("Creating players");
var startAngle = randBool() ? 0 : Math.PI / 2;
var playerPosition = playerPlacementLine(startAngle + Math.PI / 2, mapCenter, fractionToTiles(randFloat(0.42, 0.46)));
const startAngle = randBool() ? 0 : Math.PI / 2;
const playerPosition = playerPlacementLine(startAngle + Math.PI / 2, mapCenter,
fractionToTiles(randFloat(0.42, 0.46)));
function distanceToPlayers(x, z)
{
@ -122,32 +122,36 @@ for (const x of [mapBounds.left, mapBounds.right])
Engine.SetProgress(10);
g_Map.log("Painting elevation");
var noise0 = new Noise2D(scaleByMapSize(4, 16));
var noise1 = new Noise2D(scaleByMapSize(8, 32));
var noise2 = new Noise2D(scaleByMapSize(15, 60));
const noise0 = new Noise2D(scaleByMapSize(4, 16));
const noise1 = new Noise2D(scaleByMapSize(8, 32));
const noise2 = new Noise2D(scaleByMapSize(15, 60));
var noise2a = new Noise2D(scaleByMapSize(20, 80));
var noise2b = new Noise2D(scaleByMapSize(35, 140));
const noise2a = new Noise2D(scaleByMapSize(20, 80));
const noise2b = new Noise2D(scaleByMapSize(35, 140));
var noise3 = new Noise2D(scaleByMapSize(4, 16));
var noise4 = new Noise2D(scaleByMapSize(6, 24));
var noise5 = new Noise2D(scaleByMapSize(11, 44));
const noise3 = new Noise2D(scaleByMapSize(4, 16));
const noise4 = new Noise2D(scaleByMapSize(6, 24));
const noise5 = new Noise2D(scaleByMapSize(11, 44));
for (var ix = 0; ix <= mapSize; ix++)
for (var iz = 0; iz <= mapSize; iz++)
for (let ix = 0; ix <= mapSize; ix++)
for (let iz = 0; iz <= mapSize; iz++)
{
const position = new Vector2D(ix, iz);
var x = ix / (mapSize + 1.0);
var z = iz / (mapSize + 1.0);
var pn = playerNearness(x, z);
const x = ix / (mapSize + 1.0);
const z = iz / (mapSize + 1.0);
const pn = playerNearness(x, z);
const c = startAngle ? z : x;
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);
// 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 )
{
baseNoise *= pn;
@ -186,19 +190,19 @@ for (var ix = 0; ix <= mapSize; ix++)
Engine.SetProgress(20);
g_Map.log("Painting terrain");
var noise6 = new Noise2D(scaleByMapSize(10, 40));
var noise7 = new Noise2D(scaleByMapSize(20, 80));
var noise8 = new Noise2D(scaleByMapSize(13, 52));
var noise9 = new Noise2D(scaleByMapSize(26, 104));
var noise10 = new Noise2D(scaleByMapSize(50, 200));
const noise6 = new Noise2D(scaleByMapSize(10, 40));
const noise7 = new Noise2D(scaleByMapSize(20, 80));
const noise8 = new Noise2D(scaleByMapSize(13, 52));
const noise9 = new Noise2D(scaleByMapSize(26, 104));
const noise10 = new Noise2D(scaleByMapSize(50, 200));
for (var ix = 0; ix < mapSize; ix++)
for (var iz = 0; iz < mapSize; iz++)
for (let ix = 0; ix < mapSize; ix++)
for (let iz = 0; iz < mapSize; iz++)
{
const position = new Vector2D(ix, iz);
var x = ix / (mapSize + 1.0);
var z = iz / (mapSize + 1.0);
var pn = playerNearness(x, z);
const x = ix / (mapSize + 1.0);
const z = iz / (mapSize + 1.0);
const pn = playerNearness(x, z);
// Compute height difference
let minH = +Infinity;
@ -209,14 +213,14 @@ for (var ix = 0; ix < mapSize; ix++)
minH = Math.min(minH, 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
var minAdjHeight = minH;
let minAdjHeight = minH;
if (maxH > 15)
{
var maxNx = Math.min(ix + 2, mapSize);
var maxNz = Math.min(iz + 2, mapSize);
const maxNx = Math.min(ix + 2, mapSize);
const maxNz = Math.min(iz + 2, mapSize);
for (let nx = Math.max(ix - 1, 0); nx <= maxNx; ++nx)
for (let nz = Math.max(iz - 1, 0); nz <= maxNz; ++nz)
minAdjHeight = Math.min(minAdjHeight, g_Map.getHeight(new Vector2D(nx, nz)));
@ -269,7 +273,7 @@ for (var ix = 0; ix < mapSize; ix++)
// forests
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
if (forestNoise > 0 && randBool())
@ -298,7 +302,7 @@ for (var ix = 0; ix < mapSize; ix++)
// grass variations
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)
t = (diffH > 1.2) ? tDirtCliff : tDirt;
else if (grassNoise < 0.34)
@ -357,7 +361,7 @@ placePlayerBases({
Engine.SetProgress(40);
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(aBushMed, 0,1, 0,2), new SimpleObject(aBushMedDry, 0,1, 0,2)]
);

View File

@ -65,11 +65,11 @@ const islandBetweenPlayerAndCenterDist = 0.16;
const islandBetweenPlayerAndCenterRadius = 0.81;
const centralIslandRadius = 0.36;
var [playerIDs, playerPosition, playerAngle, startAngle] = playerPlacementCircle(fractionToTiles(0.35));
const [playerIDs, playerPosition, playerAngle, startAngle] = playerPlacementCircle(fractionToTiles(0.35));
var numIslands = 0;
var isConnected = [];
var islandPos = [];
let numIslands = 0;
const isConnected = [];
const islandPos = [];
function initIsConnected()
{
@ -99,10 +99,9 @@ function createIslandAtRadialLocation(playerID, islandID, playerIDOffset, distFr
createIsland(islandID, islandRadius, clLand);
}
function createSnowflakeSearockWithCenter(sizeID)
function createSnowflakeSearockWithCenter([tertiaryIslandDist, tertiaryIslandRadius,
islandBetweenPlayersDist, islandBetweenPlayersRadius])
{
const [tertiaryIslandDist, tertiaryIslandRadius, islandBetweenPlayersDist, islandBetweenPlayersRadius] = islandSizes[sizeID];
const islandID_center = 4 * numPlayers;
numIslands = islandID_center + 1;
initIsConnected();
@ -199,19 +198,19 @@ else if (mapSize <= 192)
else if (mapSize <= 256)
{
if (numPlayers < 6)
createSnowflakeSearockWithCenter("medium");
createSnowflakeSearockWithCenter(islandSizes.medium);
else
createSnowflakeSearockWithoutCenter();
}
else if (mapSize <= 320)
{
if (numPlayers < 8)
createSnowflakeSearockWithCenter("medium");
createSnowflakeSearockWithCenter(islandSizes.medium);
else
createSnowflakeSearockWithoutCenter();
}
else
createSnowflakeSearockWithCenter(numPlayers < 6 ? "large1" : "large2");
createSnowflakeSearockWithCenter(islandSizes["large" + (numPlayers < 6 ? "1" : "2")]);
g_Map.log("Creating player islands");
for (let i = 0; i < numPlayers; ++i)

View File

@ -72,9 +72,9 @@ const clBaseResource = g_Map.createTileClass();
const clLand = g_Map.createTileClass();
const clShallow = g_Map.createTileClass();
var landElevationPainter = new SmoothElevationPainter(ELEVATION_SET, heightLand, 4);
const landElevationPainter = new SmoothElevationPainter(ELEVATION_SET, heightLand, 4);
var unknownMapFunctions = {
const unknownMapFunctions = {
"land": [
"Continent",
"Isthmus",
@ -99,11 +99,11 @@ var unknownMapFunctions = {
* because nomad maps randomize the locations after the terrain generation.
* The locations should only determined by the landscape functions to avoid placing bodies of water and resources into civic centers and the starting resources.
*/
var playerIDs = sortAllPlayers();
var playerPosition = [];
let playerIDs = sortAllPlayers();
let playerPosition = [];
var g_StartingTreasures = false;
var g_StartingWalls = true;
let g_StartingTreasures = false;
let g_StartingWalls = true;
function createUnknownMap()
{