1
0
forked from 0ad/0ad

rmgen: var -> let -> const

One should always use the variable declaration with the least possible
scope.
This patch cleans up many (but not all) of the `var` in rmgen and
replaces them with `let` or `const`.
The same is done for `let` -> `const`.

comments by: @sera @Stan
Differential revision: https://code.wildfiregames.com/D5214
This was SVN commit r28036.
This commit is contained in:
marder 2024-02-17 11:13:52 +00:00
parent e9bc76040d
commit 04ce68f42e
119 changed files with 2757 additions and 2758 deletions

View File

@ -53,25 +53,25 @@ const heightShore = 1;
const heightLand = 2;
const heightIsland = 6;
var g_Map = new RandomMap(heightShore, tHill);
const g_Map = new RandomMap(heightShore, tHill);
const numPlayers = getNumPlayers();
const mapCenter = g_Map.getCenter();
const mapBounds = g_Map.getBounds();
var clPlayer = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clWater = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
var clGrass = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clIsland = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clWater = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
const clGrass = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clIsland = g_Map.createTileClass();
var startAngle = randomAngle();
const startAngle = randomAngle();
placePlayerBases({
"PlayerPlacement": playerPlacementRiver(startAngle , fractionToTiles(0.6)),
@ -123,7 +123,7 @@ Engine.SetProgress(40);
createBumps(avoidClasses(clWater, 2, clPlayer, 20));
var [forestTrees, stragglerTrees] = getTreeCounts(500, 3000, 0.7);
const [forestTrees, stragglerTrees] = getTreeCounts(500, 3000, 0.7);
createForests(
[tForestFloor, tForestFloor, tForestFloor, pForest, pForest],
avoidClasses(clPlayer, 20, clForest, 17, clWater, 2, clBaseResource, 3),
@ -276,7 +276,7 @@ createFood(
Engine.SetProgress(90);
var types = [oDatePalm, oSDatePalm, oCarob, oFanPalm, oPoplar, oCypress];
const types = [oDatePalm, oSDatePalm, oCarob, oFanPalm, oPoplar, oCypress];
createStragglerTrees(
types,
avoidClasses(clForest, 1, clWater, 2, clPlayer, 12, clMetal, 6, clHill, 1),

View File

@ -9,64 +9,64 @@ else
// Pick some biome defaults and overload a few settings.
var tPrimary = g_Terrains.mainTerrain;
var tForestFloor = g_Terrains.tier3Terrain;
var tCliff = ["savanna_cliff_a", "savanna_cliff_a_red", "savanna_cliff_b", "savanna_cliff_b_red"];
var tSecondary = g_Terrains.tier1Terrain;
var tGrassShrubs = g_Terrains.tier2Terrain;
var tDirt = g_Terrains.tier3Terrain;
var tDirt2 = g_Terrains.tier4Terrain;
var tDirt3 = g_Terrains.dirt;
var tDirt4 = g_Terrains.dirt;
var tCitytiles = "savanna_tile_a";
var tShore = g_Terrains.shore;
var tWater = g_Terrains.water;
const tPrimary = g_Terrains.mainTerrain;
const tForestFloor = g_Terrains.tier3Terrain;
const tCliff = ["savanna_cliff_a", "savanna_cliff_a_red", "savanna_cliff_b", "savanna_cliff_b_red"];
const tSecondary = g_Terrains.tier1Terrain;
const tGrassShrubs = g_Terrains.tier2Terrain;
const tDirt = g_Terrains.tier3Terrain;
const tDirt2 = g_Terrains.tier4Terrain;
const tDirt3 = g_Terrains.dirt;
const tDirt4 = g_Terrains.dirt;
const tCitytiles = "savanna_tile_a";
const tShore = g_Terrains.shore;
const tWater = g_Terrains.water;
var oBaobab = pickRandom(["gaia/tree/baobab", "gaia/tree/baobab_3_mature", "gaia/tree/acacia"]);
var oPalm = "gaia/tree/bush_tropic";
var oPalm2 = "gaia/tree/cretan_date_palm_short";
var oBerryBush = "gaia/fruit/berry_01";
var oWildebeest = "gaia/fauna_wildebeest";
var oZebra = "gaia/fauna_zebra";
var oRhino = "gaia/fauna_rhinoceros_white";
var oLion = "gaia/fauna_lion";
var oLioness = "gaia/fauna_lioness";
var oHawk = "birds/buzzard";
var oGiraffe = "gaia/fauna_giraffe";
var oGiraffe2 = "gaia/fauna_giraffe_infant";
var oGazelle = "gaia/fauna_gazelle";
var oElephant = "gaia/fauna_elephant_african_bush";
var oElephant2 = "gaia/fauna_elephant_african_infant";
var oCrocodile = "gaia/fauna_crocodile_nile";
var oFish = g_Gaia.fish;
var oStoneLarge = g_Gaia.stoneLarge;
var oStoneSmall = g_Gaia.stoneSmall;
var oMetalLarge = g_Gaia.metalLarge;
var oMetalSmall = g_Gaia.metalSmall;
const oBaobab = pickRandom(["gaia/tree/baobab", "gaia/tree/baobab_3_mature", "gaia/tree/acacia"]);
const oPalm = "gaia/tree/bush_tropic";
const oPalm2 = "gaia/tree/cretan_date_palm_short";
const oBerryBush = "gaia/fruit/berry_01";
const oWildebeest = "gaia/fauna_wildebeest";
const oZebra = "gaia/fauna_zebra";
const oRhino = "gaia/fauna_rhinoceros_white";
const oLion = "gaia/fauna_lion";
const oLioness = "gaia/fauna_lioness";
const oHawk = "birds/buzzard";
const oGiraffe = "gaia/fauna_giraffe";
const oGiraffe2 = "gaia/fauna_giraffe_infant";
const oGazelle = "gaia/fauna_gazelle";
const oElephant = "gaia/fauna_elephant_african_bush";
const oElephant2 = "gaia/fauna_elephant_african_infant";
const oCrocodile = "gaia/fauna_crocodile_nile";
const oFish = g_Gaia.fish;
const oStoneLarge = g_Gaia.stoneLarge;
const oStoneSmall = g_Gaia.stoneSmall;
const oMetalLarge = g_Gaia.metalLarge;
const oMetalSmall = g_Gaia.metalSmall;
var aBush = g_Decoratives.bushMedium;
var aRock = g_Decoratives.rockMedium;
const aBush = g_Decoratives.bushMedium;
const aRock = g_Decoratives.rockMedium;
const pForest = [tForestFloor + TERRAIN_SEPARATOR + oPalm, tForestFloor + TERRAIN_SEPARATOR + oPalm2, tForestFloor];
var heightSeaGround = -5;
var heightLand = 2;
var heightCliff = 3;
const heightSeaGround = -5;
const heightLand = 2;
const heightCliff = 3;
var g_Map = new RandomMap(heightLand, tPrimary);
const g_Map = new RandomMap(heightLand, tPrimary);
const numPlayers = getNumPlayers();
const mapSize = g_Map.getSize();
var clPlayer = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clWater = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clWater = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
placePlayerBases({
"PlayerPlacement": playerPlacementCircle(fractionToTiles(0.35)),

View File

@ -81,23 +81,23 @@ else
const pForest = [tForestFloor + TERRAIN_SEPARATOR + oPine, tForestFloor];
var heightSeaGround = -5;
var heightLand = 3;
const heightSeaGround = -5;
const heightLand = 3;
var g_Map = new RandomMap(heightLand, tPrimary);
const g_Map = new RandomMap(heightLand, tPrimary);
const numPlayers = getNumPlayers();
const mapSize = g_Map.getSize();
var clPlayer = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clWater = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clWater = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
placePlayerBases({
"PlayerPlacement": playerPlacementCircle(fractionToTiles(0.35)),
@ -149,7 +149,7 @@ paintTerrainBasedOnHeight(Math.floor(scaleByMapSize(20, 40)), 100, 3, tSnowLimit
createBumps(avoidClasses(clWater, 2, clPlayer, 20));
var [forestTrees, stragglerTrees] = getTreeCounts(500, 3000, 0.7);
const [forestTrees, stragglerTrees] = getTreeCounts(500, 3000, 0.7);
createForests(
[tPrimary, tForestFloor, tForestFloor, pForest, pForest],
avoidClasses(clPlayer, 20, clForest, 17, clHill, 0, clWater, 2),

View File

@ -113,14 +113,14 @@ MountainRangeBuilder.prototype.RemoveInvalidEdges = function()
{
this.UpdateCurrentEdge();
let comparedEdge = this.possibleEdges[i];
let comparedEdgeStart = this.vertices[comparedEdge[0]];
let comparedEdgeEnd = this.vertices[comparedEdge[1]];
const comparedEdge = this.possibleEdges[i];
const comparedEdgeStart = this.vertices[comparedEdge[0]];
const comparedEdgeEnd = this.vertices[comparedEdge[1]];
let edge0Equal = this.currentEdgeStart == comparedEdgeStart;
let edge1Equal = this.currentEdgeStart == comparedEdgeEnd;
let edge2Equal = this.currentEdgeEnd == comparedEdgeEnd;
let edge3Equal = this.currentEdgeEnd == comparedEdgeStart;
const edge0Equal = this.currentEdgeStart == comparedEdgeStart;
const edge1Equal = this.currentEdgeStart == comparedEdgeEnd;
const edge2Equal = this.currentEdgeEnd == comparedEdgeEnd;
const edge3Equal = this.currentEdgeEnd == comparedEdgeStart;
if (!edge0Equal && !edge2Equal && !edge1Equal && !edge3Equal && testLineIntersection(this.currentEdgeStart, this.currentEdgeEnd, comparedEdgeStart, comparedEdgeEnd, this.minDistance) ||
( edge0Equal && !edge2Equal || !edge1Equal && edge3Equal) && distanceOfPointFromLine(this.currentEdgeStart, this.currentEdgeEnd, comparedEdgeEnd) < this.minDistance ||
@ -140,13 +140,13 @@ MountainRangeBuilder.prototype.RemoveInvalidEdges = function()
*/
MountainRangeBuilder.prototype.HasCycles = function()
{
let tree = [];
let backtree = [];
let pointQueue = [this.currentEdge[0]];
const tree = [];
const backtree = [];
const pointQueue = [this.currentEdge[0]];
while (pointQueue.length)
{
let selectedPoint = pointQueue.shift();
const selectedPoint = pointQueue.shift();
if (tree.indexOf(selectedPoint) == -1)
{
@ -184,7 +184,7 @@ MountainRangeBuilder.prototype.PaintCurrentEdge = function()
return false;
// Creating circular mountains at both ends of that mountainrange
for (let point of [this.currentEdgeStart, this.currentEdgeEnd])
for (const point of [this.currentEdgeStart, this.currentEdgeEnd])
createArea(
new ClumpPlacer(diskArea(this.mountainWidth / 2), 0.95, 0.6, Infinity, point),
this.painters,
@ -200,7 +200,7 @@ MountainRangeBuilder.prototype.CreateMountainRanges = function()
{
g_Map.log("Creating mountainrange with " + this.possibleEdges.length + " possible edges");
let max = this.possibleEdges.length;
const max = this.possibleEdges.length;
while (this.possibleEdges.length)
{
@ -290,19 +290,19 @@ var heightMountain = 30;
const pForest = [tForestFloor + TERRAIN_SEPARATOR + oPine, tForestFloor];
var g_Map = new RandomMap(heightLand, tPrimary);
const g_Map = new RandomMap(heightLand, tPrimary);
const numPlayers = getNumPlayers();
const mapCenter = g_Map.getCenter();
var clPlayer = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
var [playerIDs, playerPosition, playerAngle, startAngle] = playerPlacementCircle(fractionToTiles(0.35));
@ -382,15 +382,15 @@ createAreas(
Engine.SetProgress(50);
g_Map.log("Creating forests");
var [forestTrees, stragglerTrees] = getTreeCounts(500, 3000, 0.7);
var types = [
const [forestTrees, stragglerTrees] = getTreeCounts(500, 3000, 0.7);
const types = [
[[tForestFloor, tPrimary, pForest], [tForestFloor, pForest]]
];
var size = forestTrees / (scaleByMapSize(2,8) * numPlayers);
var num = Math.floor(size / types.length);
for (let type of types)
const num = Math.floor(size / types.length);
for (const type of types)
createAreas(
new ClumpPlacer(forestTrees / num, 0.1, 0.1, Infinity),
[
@ -402,7 +402,7 @@ for (let type of types)
Engine.SetProgress(60);
g_Map.log("Creating dirt patches");
for (let size of [scaleByMapSize(3, 48), scaleByMapSize(5, 84), scaleByMapSize(8, 128)])
for (const size of [scaleByMapSize(3, 48), scaleByMapSize(5, 84), scaleByMapSize(8, 128)])
createAreas(
new ClumpPlacer(size, 0.3, 0.06, 0.5),
[
@ -413,7 +413,7 @@ for (let size of [scaleByMapSize(3, 48), scaleByMapSize(5, 84), scaleByMapSize(8
scaleByMapSize(15, 45));
g_Map.log("Creating grass patches");
for (let size of [scaleByMapSize(2, 32), scaleByMapSize(3, 48), scaleByMapSize(5, 80)])
for (const size of [scaleByMapSize(2, 32), scaleByMapSize(3, 48), scaleByMapSize(5, 80)])
createAreas(
new ClumpPlacer(size, 0.3, 0.06, 0.5),
new TerrainPainter(tSecondary),

View File

@ -5,11 +5,11 @@ Engine.LoadLibrary("rmbiome");
setSelectedBiome();
var heightLand = 2;
const heightLand = 2;
var g_Map = new RandomMap(heightLand, g_Terrains.mainTerrain);
var mapCenter = g_Map.getCenter();
var mapSize = g_Map.getSize();
const g_Map = new RandomMap(heightLand, g_Terrains.mainTerrain);
const mapCenter = g_Map.getCenter();
const mapSize = g_Map.getSize();
initTileClasses(["bluffsPassage", "nomadArea"]);
createArea(
@ -18,21 +18,20 @@ createArea(
Engine.SetProgress(10);
if (!isNomad())
{
let pattern = g_MapSettings.TeamPlacement || pickRandom(["line", "radial", "randomGroup", "stronghold"]);
var [playerIDs, playerPosition] =
createBases(
...playerPlacementByPattern(
pattern,
fractionToTiles(randFloat(0.2, 0.35)),
fractionToTiles(randFloat(0.08, 0.1)),
randomAngle(),
undefined),
g_PlayerbaseTypes[pattern].walls);
const pattern = g_MapSettings.TeamPlacement || pickRandom(["line", "radial", "randomGroup", "stronghold"]);
let [playerIDs, playerPosition] =
createBases(
...playerPlacementByPattern(
pattern,
fractionToTiles(randFloat(0.2, 0.35)),
fractionToTiles(randFloat(0.08, 0.1)),
randomAngle(),
undefined),
g_PlayerbaseTypes[pattern].walls);
if (!isNomad())
markPlayerAvoidanceArea(playerPosition, defaultPlayerBaseRadius());
}
Engine.SetProgress(20);
addElements([

View File

@ -31,21 +31,21 @@ const aBushSmall = "actor|props/flora/bush_medit_sm.xml";
const pForest = [tForestFloor + TERRAIN_SEPARATOR + oPoplar, tForestFloor];
var heightLand = 1;
var heightOffsetBump = 2;
const heightLand = 1;
const heightOffsetBump = 2;
var g_Map = new RandomMap(heightLand, tPrimary);
const g_Map = new RandomMap(heightLand, tPrimary);
var numPlayers = getNumPlayers();
const numPlayers = getNumPlayers();
var clPlayer = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
placePlayerBases({
"PlayerPlacement": playerPlacementCircle(fractionToTiles(0.35)),
@ -85,11 +85,11 @@ createAreas(
scaleByMapSize(300, 800));
g_Map.log("Creating forests");
var [forestTrees, stragglerTrees] = getTreeCounts(220, 1000, 0.65);
var types = [[[tForestFloor, tGrass, pForest], [tForestFloor, pForest]]];
var size = forestTrees / (scaleByMapSize(2,8) * numPlayers);
var num = 4 * Math.floor(size / types.length);
for (let type of types)
const [forestTrees, stragglerTrees] = getTreeCounts(220, 1000, 0.65);
const types = [[[tForestFloor, tGrass, pForest], [tForestFloor, pForest]]];
const size = forestTrees / (scaleByMapSize(2,8) * numPlayers);
const num = 4 * Math.floor(size / types.length);
for (const type of types)
createAreas(
new ChainPlacer(1, Math.floor(scaleByMapSize(2, 3)), 4, Infinity),
[
@ -132,7 +132,7 @@ createLayeredPatches(
Engine.SetProgress(60);
g_Map.log("Creating stone mines");
var group = new SimpleGroup([new SimpleObject(oStoneSmall, 0, 2, 0, 4, 0, 2 * Math.PI, 1), new SimpleObject(oStoneLarge, 1, 1, 0, 4, 0, 2 * Math.PI, 4)], true, clRock);
let group = new SimpleGroup([new SimpleObject(oStoneSmall, 0, 2, 0, 4, 0, 2 * Math.PI, 1), new SimpleObject(oStoneLarge, 1, 1, 0, 4, 0, 2 * Math.PI, 4)], true, clRock);
createObjectGroupsDeprecated(group, 0,
avoidClasses(clForest, 1, clPlayer, 20, clRock, 10, clHill, 1),
scaleByMapSize(1,4), 100

View File

@ -46,27 +46,27 @@ const aBushSmall = g_Decoratives.bushSmall;
const pForest1 = [tForestFloor2 + TERRAIN_SEPARATOR + oTree1, tForestFloor2 + TERRAIN_SEPARATOR + oTree2, tForestFloor2];
const pForest2 = [tForestFloor1 + TERRAIN_SEPARATOR + oTree4, tForestFloor1 + TERRAIN_SEPARATOR + oTree5, tForestFloor1];
var heightSeaGround = -5;
var heightLand = 3;
var heightShore = 1;
const heightSeaGround = -5;
const heightLand = 3;
const heightShore = 1;
var g_Map = new RandomMap(heightSeaGround, tWater);
const g_Map = new RandomMap(heightSeaGround, tWater);
const numPlayers = getNumPlayers();
var clPlayer = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
var clLand = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
const clLand = g_Map.createTileClass();
var islandRadius = scaleByMapSize(22, 31);
const islandRadius = scaleByMapSize(22, 31);
var [playerIDs, playerPosition] = playerPlacementCircle(fractionToTiles(0.35));
const [playerIDs, playerPosition] = playerPlacementCircle(fractionToTiles(0.35));
g_Map.log("Creating player islands");
for (let i = 0; i < numPlayers; ++i)
@ -155,7 +155,7 @@ else
// adjust biomes (especially wood)
const biomeSpecifics = biomeTweaks[currentBiome()] || biomeTweaks.baseline;
var [forestTrees, stragglerTrees] = getTreeCounts(...rBiomeTreeCount(biomeSpecifics.treeAmount));
const [forestTrees, stragglerTrees] = getTreeCounts(...rBiomeTreeCount(biomeSpecifics.treeAmount));
createForests(
[tMainTerrain, tForestFloor1, tForestFloor2, pForest1, pForest2],
[avoidClasses(clPlayer, biomeSpecifics.forestPlayerSpacing, clForest, biomeSpecifics.forestForestSpacing, clHill, 0), stayClasses(clLand, 3)],
@ -202,7 +202,7 @@ createMines(
);
Engine.SetProgress(65);
var planetm = currentBiome() == "generic/india" ? 8 : 1;
const planetm = currentBiome() == "generic/india" ? 8 : 1;
createDecoration(
[
[new SimpleObject(aRockMedium, 1, 3, 0, 1)],

View File

@ -9,53 +9,53 @@ setPPSaturation(0.48);
setPPContrast(0.53);
setPPBloom(0.12);
var tPrimary = ["alpine_grass_rocky"];
var tForestFloor = "alpine_grass";
var tCliff = ["polar_cliff_a", "polar_cliff_b", "polar_cliff_snow"];
var tSecondary = "alpine_grass";
var tHalfSnow = ["polar_grass_snow", "ice_dirt"];
var tSnowLimited = ["polar_snow_rocks", "polar_ice"];
var tDirt = "ice_dirt";
var tShore = "alpine_shore_rocks";
var tWater = "polar_ice_b";
var tHill = "polar_ice_cracked";
const tPrimary = ["alpine_grass_rocky"];
const tForestFloor = "alpine_grass";
const tCliff = ["polar_cliff_a", "polar_cliff_b", "polar_cliff_snow"];
const tSecondary = "alpine_grass";
const tHalfSnow = ["polar_grass_snow", "ice_dirt"];
const tSnowLimited = ["polar_snow_rocks", "polar_ice"];
const tDirt = "ice_dirt";
const tShore = "alpine_shore_rocks";
const tWater = "polar_ice_b";
const tHill = "polar_ice_cracked";
var oBush = "gaia/tree/bush_badlands";
var oBush2 = "gaia/tree/bush_temperate";
var oBerryBush = "gaia/fruit/berry_01";
var oRabbit = "gaia/fauna_rabbit";
var oMuskox = "gaia/fauna_muskox";
var oDeer = "gaia/fauna_deer";
var oWolf = "gaia/fauna_wolf";
var oWhaleFin = "gaia/fauna_whale_fin";
var oWhaleHumpback = "gaia/fauna_whale_humpback";
var oFish = "gaia/fish/generic";
var oStoneLarge = "gaia/rock/alpine_large";
var oStoneSmall = "gaia/rock/alpine_small";
var oMetalLarge = "gaia/ore/alpine_large";
var oWoodTreasure = "gaia/treasure/wood";
const oBush = "gaia/tree/bush_badlands";
const oBush2 = "gaia/tree/bush_temperate";
const oBerryBush = "gaia/fruit/berry_01";
const oRabbit = "gaia/fauna_rabbit";
const oMuskox = "gaia/fauna_muskox";
const oDeer = "gaia/fauna_deer";
const oWolf = "gaia/fauna_wolf";
const oWhaleFin = "gaia/fauna_whale_fin";
const oWhaleHumpback = "gaia/fauna_whale_humpback";
const oFish = "gaia/fish/generic";
const oStoneLarge = "gaia/rock/alpine_large";
const oStoneSmall = "gaia/rock/alpine_small";
const oMetalLarge = "gaia/ore/alpine_large";
const oWoodTreasure = "gaia/treasure/wood";
var aRockLarge = "actor|geology/stone_granite_med.xml";
var aRockMedium = "actor|geology/stone_granite_med.xml";
const aRockLarge = "actor|geology/stone_granite_med.xml";
const aRockMedium = "actor|geology/stone_granite_med.xml";
const pForest = [tForestFloor + TERRAIN_SEPARATOR + oBush, tForestFloor + TERRAIN_SEPARATOR + oBush2, tForestFloor];
var heightSeaGround = -5;
var heightLand = 2;
const heightSeaGround = -5;
const heightLand = 2;
var g_Map = new RandomMap(heightLand, tPrimary);
const g_Map = new RandomMap(heightLand, tPrimary);
const numPlayers = getNumPlayers();
var clPlayer = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clWater = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clWater = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
placePlayerBases({
"PlayerPlacement": playerPlacementCircle(fractionToTiles(0.35)),
@ -128,7 +128,7 @@ createBumps(avoidClasses(clPlayer, 6, clWater, 2), scaleByMapSize(30, 300), 1, 8
paintTerrainBasedOnHeight(4, 15, 0, tCliff);
paintTerrainBasedOnHeight(15, 100, 3, tSnowLimited);
var [forestTrees, stragglerTrees] = getTreeCounts(500, 3000, 0.7);
const [forestTrees, stragglerTrees] = getTreeCounts(500, 3000, 0.7);
createForests(
[tSecondary, tForestFloor, tForestFloor, pForest, pForest],
avoidClasses(

View File

@ -44,7 +44,7 @@ const aCeltHomestead = "actor|structures/celts/homestead.xml";
const aCeltHouse = "actor|structures/celts/house.xml";
const aCeltLongHouse = "actor|structures/celts/longhouse.xml";
var pForest = [
const pForest = [
tPineForestFloor+TERRAIN_SEPARATOR+oOak, tForestFloor,
tPineForestFloor+TERRAIN_SEPARATOR+oPine, tForestFloor,
tPineForestFloor+TERRAIN_SEPARATOR+oAleppoPine, tForestFloor,
@ -57,22 +57,22 @@ const heightRavineHill = 40;
const heightHill = 50;
const heightOffsetRavine = 10;
var g_Map = new RandomMap(heightHill, tPrimary);
const g_Map = new RandomMap(heightHill, tPrimary);
const numPlayers = getNumPlayers();
const mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
var clPlayer = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clForestJoin = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
var clHillDeco = g_Map.createTileClass();
var clExplorable = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clForestJoin = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
const clHillDeco = g_Map.createTileClass();
const clExplorable = g_Map.createTileClass();
g_Map.log("Creating the central dip");
createArea(
@ -84,33 +84,33 @@ createArea(
Engine.SetProgress(5);
g_Map.log("Finding hills");
var noise0 = new Noise2D(20);
for (var ix = 0; ix < mapSize; ix++)
for (var iz = 0; iz < mapSize; iz++)
const noise0 = new Noise2D(20);
for (let ix = 0; ix < mapSize; ix++)
for (let iz = 0; iz < mapSize; iz++)
{
let position = new Vector2D(ix, iz);
let h = g_Map.getHeight(position);
const position = new Vector2D(ix, iz);
const h = g_Map.getHeight(position);
if (h > heightRavineHill)
{
clHill.add(position);
// Add hill noise
var x = ix / (mapSize + 1.0);
var z = iz / (mapSize + 1.0);
var n = (noise0.get(x, z) - 0.5) * heightRavineHill;
const x = ix / (mapSize + 1.0);
const z = iz / (mapSize + 1.0);
const n = (noise0.get(x, z) - 0.5) * heightRavineHill;
g_Map.setHeight(position, h + n);
}
}
var [playerIDs, playerPosition] = playerPlacementCircle(fractionToTiles(0.3));
const [playerIDs, playerPosition] = playerPlacementCircle(fractionToTiles(0.3));
function distanceToPlayers(x, z)
{
var r = 10000;
for (var i = 0; i < numPlayers; i++)
let r = 10000;
for (let i = 0; i < numPlayers; i++)
{
var dx = x - tilesToFraction(playerPosition[i].x);
var dz = z - tilesToFraction(playerPosition[i].y);
let dx = x - tilesToFraction(playerPosition[i].x);
let dz = z - tilesToFraction(playerPosition[i].y);
r = Math.min(r, Math.square(dx) + Math.square(dz));
}
return Math.sqrt(r);
@ -118,7 +118,7 @@ function distanceToPlayers(x, z)
function playerNearness(x, z)
{
var d = fractionToTiles(distanceToPlayers(x,z));
let d = fractionToTiles(distanceToPlayers(x,z));
if (d < 13)
return 0;
@ -172,9 +172,9 @@ for (let i = 0; i < numPlayers; ++i)
Engine.SetProgress(30);
g_Map.log("Creating hills");
for (let size of [scaleByMapSize(50, 800), scaleByMapSize(50, 400), scaleByMapSize(10, 30), scaleByMapSize(10, 30)])
for (const size of [scaleByMapSize(50, 800), scaleByMapSize(50, 400), scaleByMapSize(10, 30), scaleByMapSize(10, 30)])
{
let mountains = createAreas(
const mountains = createAreas(
new ClumpPlacer(size, 0.1, 0.2, 0.1),
[
new LayeredPainter([tCliff, [tForestFloor, tForestFloor, tCliff]], [2]),
@ -196,7 +196,7 @@ for (let size of [scaleByMapSize(50, 800), scaleByMapSize(50, 400), scaleByMapSi
20,
mountains);
let ravine = createAreas(
const ravine = createAreas(
new ClumpPlacer(size, 0.1, 0.2, 0.1),
[
new LayeredPainter([tCliff, tForestFloor], [2]),
@ -257,11 +257,11 @@ for (let size of [scaleByMapSize(50, 800), scaleByMapSize(50, 400), scaleByMapSi
Engine.SetProgress(50);
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++)
{
let position = new Vector2D(ix, iz);
let h = g_Map.getHeight(position);
const position = new Vector2D(ix, iz);
const h = g_Map.getHeight(position);
if (h > 35 && randBool(0.1) ||
h < 15 && randBool(0.05) && clHillDeco.countMembersInRadius(position, 1) == 0)
@ -272,7 +272,7 @@ for (var ix = 0; ix < mapSize; ix++)
randomAngle());
}
var explorableArea = createArea(
const explorableArea = createArea(
new MapBoundsPlacer(),
undefined,
[
@ -285,16 +285,16 @@ new TileClassPainter(clExplorable).paint(explorableArea);
Engine.SetProgress(55);
// Add some general noise - after placing height dependant trees
for (var ix = 0; ix < mapSize; ix++)
for (let ix = 0; ix < mapSize; ix++)
{
var x = ix / (mapSize + 1.0);
for (var iz = 0; iz < mapSize; iz++)
const x = ix / (mapSize + 1.0);
for (let iz = 0; iz < mapSize; iz++)
{
let position = new Vector2D(ix, iz);
var z = iz / (mapSize + 1.0);
var h = g_Map.getHeight(position);
var pn = playerNearness(x,z);
var n = (noise0.get(x,z) - 0.5) * 10;
const position = new Vector2D(ix, iz);
const z = iz / (mapSize + 1.0);
const h = g_Map.getHeight(position);
const pn = playerNearness(x,z);
const n = (noise0.get(x,z) - 0.5) * 10;
g_Map.setHeight(position, h + (n * pn));
}
}
@ -335,7 +335,7 @@ createAreasInAreas(
Engine.SetProgress(70);
g_Map.log("Creating grass patches");
for (let size of [scaleByMapSize(3, 48), scaleByMapSize(5, 84), scaleByMapSize(8, 128)])
for (const size of [scaleByMapSize(3, 48), scaleByMapSize(5, 84), scaleByMapSize(8, 128)])
createAreas(
new ClumpPlacer(size, 0.3, 0.06, 0.5),
new TerrainPainter([tGrass, tGrassPatch]),
@ -343,7 +343,7 @@ for (let size of [scaleByMapSize(3, 48), scaleByMapSize(5, 84), scaleByMapSize(8
scaleByMapSize(15, 45));
g_Map.log("Creating chopped forest patches");
for (let size of [scaleByMapSize(20, 120)])
for (const size of [scaleByMapSize(20, 120)])
createAreas(
new ClumpPlacer(size, 0.3, 0.06, 0.5),
new TerrainPainter(tForestFloor),
@ -435,9 +435,9 @@ createObjectGroupsByAreasDeprecated(
Engine.SetProgress(90);
g_Map.log("Creating straggler trees");
var types = [oOak, oOakLarge, oPine, oAleppoPine];
const types = [oOak, oOakLarge, oPine, oAleppoPine];
var num = Math.floor(stragglerTrees / types.length);
for (let type of types)
for (const type of types)
createObjectGroupsByAreasDeprecated(
new SimpleGroup([new SimpleObject(type, 1, 1, 0, 3)], true, clForest),
0,

View File

@ -38,19 +38,19 @@ const pForest2 = [tForestFloor + TERRAIN_SEPARATOR + oAleppoPine, tForestFloor];
const heightLand = 3;
var g_Map = new RandomMap(heightLand, tPrimary);
const g_Map = new RandomMap(heightLand, tPrimary);
const numPlayers = getNumPlayers();
var clPlayer = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
var clTreasure = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
const clTreasure = g_Map.createTileClass();
placePlayerBases({
"PlayerPlacement": playerPlacementCircle(fractionToTiles(0.35)),
@ -87,7 +87,7 @@ createMountains(tCliff, avoidClasses(clPlayer, 20, clHill, 8), clHill, scaleByMa
Engine.SetProgress(25);
var [forestTrees, stragglerTrees] = getTreeCounts(500, 3000, 0.7);
const [forestTrees, stragglerTrees] = getTreeCounts(500, 3000, 0.7);
createForests(
[tGrass, tForestFloor, tForestFloor, pForest1, pForest2],
avoidClasses(clPlayer, 20, clForest, 14, clHill, 1),
@ -178,7 +178,7 @@ createFood(
clFood);
g_Map.log("Creating food treasures");
var group = new SimpleGroup(
let group = new SimpleGroup(
[new SimpleObject(oFoodTreasure, 2,3, 0,2)],
true, clTreasure
);

View File

@ -75,10 +75,10 @@ const heightSeaGround = heightScale(-6);
const heightWaterLevel = heightScale(0);
const heightShoreline = heightScale(0.5);
var g_Map = new RandomMap(0, g_Terrains.mainTerrain);
var mapBounds = g_Map.getBounds();
var mapCenter = g_Map.getCenter();
var numPlayers = getNumPlayers();
const g_Map = new RandomMap(0, g_Terrains.mainTerrain);
const mapBounds = g_Map.getBounds();
const mapCenter = g_Map.getCenter();
const numPlayers = getNumPlayers();
g_Map.LoadHeightmapImage("bahrain.png", 0, 15);
Engine.SetProgress(15);
@ -113,7 +113,7 @@ createArea(
Engine.SetProgress(35);
g_Map.log("Marking island");
var areaIsland = createArea(
const areaIsland = createArea(
new RectPlacer(new Vector2D(fractionToTiles(0.4), mapBounds.top), new Vector2D(fractionToTiles(0.6), mapCenter.y), Infinity),
new TileClassPainter(g_TileClasses.island),
avoidClasses(g_TileClasses.water, 0));
@ -145,7 +145,7 @@ Engine.SetProgress(45);
if (!isNomad())
{
g_Map.log("Placing players");
let [playerIDs, playerPosition] = createBases(
const [playerIDs, playerPosition] = createBases(
...playerPlacementRandom(
sortAllPlayers(),
[
@ -155,7 +155,7 @@ if (!isNomad())
"towers");
g_Map.log("Flatten the initial CC area");
for (let position of playerPosition)
for (const position of playerPosition)
createArea(
new ClumpPlacer(diskArea(defaultPlayerBaseRadius() * 0.8), 0.95, 0.6, Infinity, position),
new SmoothElevationPainter(ELEVATION_SET, g_Map.getHeight(position), 6));
@ -417,7 +417,7 @@ createObjectGroups(
Engine.SetProgress(85);
g_Map.log("Creating treasures");
for (let treasure of [g_Gaia.woodTreasure, g_Gaia.foodTreasure])
for (const treasure of [g_Gaia.woodTreasure, g_Gaia.foodTreasure])
createObjectGroups(
new SimpleGroup([new SimpleObject(treasure, 1, 1, 0, 2)], true),
0,

View File

@ -6,22 +6,22 @@ const tPrimary = ["temp_grass", "temp_grass_b", "temp_grass_c", "temp_grass_d",
"temp_grass_long_b", "temp_grass_clovers_2", "temp_grass_mossy", "temp_grass_plants"];
const heightLand = 0;
var g_Map = new RandomMap(heightLand, tPrimary);
var numPlayers = getNumPlayers();
var mapSize = g_Map.getSize();
var mapCenter = g_Map.getCenter();
const g_Map = new RandomMap(heightLand, tPrimary);
const numPlayers = getNumPlayers();
const mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
// Set target min and max height depending on map size to make average stepness the same on all map sizes
var heightRange = {"min": MIN_HEIGHT * mapSize / 8192, "max": MAX_HEIGHT * mapSize / 8192};
const heightRange = {"min": MIN_HEIGHT * mapSize / 8192, "max": MAX_HEIGHT * mapSize / 8192};
// Since erosion is not predictable, actual water coverage can differ much with the same value
var averageWaterCoverage = scaleByMapSize(1/5, 1/3);
const averageWaterCoverage = scaleByMapSize(1/5, 1/3);
var heightSeaGround = -MIN_HEIGHT + heightRange.min + averageWaterCoverage * (heightRange.max - heightRange.min);
var heightSeaGroundAdjusted = heightSeaGround + MIN_HEIGHT;
const heightSeaGround = -MIN_HEIGHT + heightRange.min + averageWaterCoverage * (heightRange.max - heightRange.min);
const heightSeaGroundAdjusted = heightSeaGround + MIN_HEIGHT;
setWaterHeight(heightSeaGround);
var textueByHeight = [];
const textueByHeight = [];
// Deep water
textueByHeight.push({"upperHeightLimit": heightRange.min + 1/3 * (heightSeaGroundAdjusted - heightRange.min), "terrain": "temp_sea_rocks"});
@ -49,7 +49,7 @@ textueByHeight.push({"upperHeightLimit": heightSeaGroundAdjusted + 2/6 * (height
"terrain": ["temp_grass", "temp_grass_d", "temp_grass_long_b", "temp_grass_plants"]});
// Medium level grass
// var testActor = "actor|geology/decal_stone_medit_a.xml";
// const testActor = "actor|geology/decal_stone_medit_a.xml";
textueByHeight.push({"upperHeightLimit": heightSeaGroundAdjusted + 3/6 * (heightRange.max - heightSeaGroundAdjusted),
"terrain": ["temp_grass", "temp_grass_b", "temp_grass_c", "temp_grass_mossy"]});
@ -63,8 +63,8 @@ var terrains = ["temp_grass_plants|gaia/tree/euro_beech", "temp_grass_mossy|gaia
"temp_grass_long|gaia/fruit/apple", "temp_grass_clovers|gaia/fruit/berry_01", "temp_grass_clovers_2|gaia/fruit/grapes",
"temp_grass_plants|gaia/fauna_deer", "temp_grass_long_b|gaia/fauna_rabbit"];
var numTerrains = terrains.length;
for (var i = 0; i < numTerrains; i++)
const numTerrains = terrains.length;
for (let i = 0; i < numTerrains; i++)
terrains.push("temp_grass_plants");
textueByHeight.push({"upperHeightLimit": heightSeaGroundAdjusted + 5/6 * (heightRange.max - heightSeaGroundAdjusted), "terrain": terrains});
@ -77,11 +77,11 @@ textueByHeight.push({"upperHeightLimit": heightSeaGroundAdjusted + 6/6 * (height
Engine.SetProgress(5);
var lowerHeightLimit = textueByHeight[3].upperHeightLimit;
var upperHeightLimit = textueByHeight[6].upperHeightLimit;
const lowerHeightLimit = textueByHeight[3].upperHeightLimit;
const upperHeightLimit = textueByHeight[6].upperHeightLimit;
var playerPosition;
var playerIDs;
let playerPosition;
let playerIDs;
while (true)
{
@ -100,13 +100,13 @@ while (true)
rescaleHeightmap(heightRange.min, heightRange.max, g_Map.height);
g_Map.log("Mark valid heightrange for player starting positions");
let tHeightRange = g_Map.createTileClass();
let area = createArea(
const tHeightRange = g_Map.createTileClass();
const area = createArea(
new DiskPlacer(fractionToTiles(0.5) - MAP_BORDER_WIDTH, mapCenter),
new TileClassPainter(tHeightRange),
new HeightConstraint(lowerHeightLimit, upperHeightLimit));
let players = area && playerPlacementRandom(sortAllPlayers(), stayClasses(tHeightRange, 15), true);
const players = area && playerPlacementRandom(sortAllPlayers(), stayClasses(tHeightRange, 15), true);
if (players)
{
[playerIDs, playerPosition] = players;
@ -118,7 +118,7 @@ while (true)
Engine.SetProgress(60);
g_Map.log("Painting terrain by height and add props");
var propDensity = 1; // 1 means as determined in the loop, less for large maps as set below
let propDensity = 1; // 1 means as determined in the loop, less for large maps as set below
if (mapSize > 500)
propDensity = 1/4;
else if (mapSize > 400)
@ -127,12 +127,12 @@ else if (mapSize > 400)
for (let x = 0; x < mapSize; ++x)
for (let y = 0; y < mapSize; ++y)
{
let position = new Vector2D(x, y);
const position = new Vector2D(x, y);
if (!g_Map.validHeight(position))
continue;
var textureMinHeight = heightRange.min;
for (var i = 0; i < textueByHeight.length; i++)
let textureMinHeight = heightRange.min;
for (let i = 0; i < textueByHeight.length; i++)
{
if (g_Map.getHeight(position) >= textureMinHeight && g_Map.getHeight(position) <= textueByHeight[i].upperHeightLimit)
{
@ -254,9 +254,9 @@ else
{
g_Map.log("Placing players and starting resources");
let resourceDistance = 8;
let resourceSpacing = 1;
let resourceCount = 4;
const resourceDistance = 8;
const resourceSpacing = 1;
const resourceCount = 4;
for (let i = 0; i < numPlayers; ++i)
{
@ -264,10 +264,10 @@ else
for (let j = 1; j <= 4; ++j)
{
let uAngle = BUILDING_ORIENTATION - Math.PI * (2-j) / 2;
const uAngle = BUILDING_ORIENTATION - Math.PI * (2-j) / 2;
for (let k = 0; k < resourceCount; ++k)
{
let pos = Vector2D.sum([
const pos = Vector2D.sum([
playerPosition[i],
new Vector2D(resourceDistance, 0).rotate(-uAngle),
new Vector2D(k * resourceSpacing, 0).rotate(-uAngle - Math.PI/2),

View File

@ -50,19 +50,19 @@ const heightHill = 15;
const heightOffsetBump1 = 2;
const heightOffsetBump2 = 1;
var g_Map = new RandomMap(heightLand, tShoreBlend);
const g_Map = new RandomMap(heightLand, tShoreBlend);
const numPlayers = getNumPlayers();
var clPlayer = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clWater = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clWater = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
placePlayerBases({
"PlayerPlacement": playerPlacementCircle(fractionToTiles(0.35)),
@ -145,7 +145,7 @@ createAreas(
scaleByMapSize(50, 100));
g_Map.log("Creating mud patches");
for (let size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)])
for (const size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)])
createAreas(
new ChainPlacer(2, Math.floor(scaleByMapSize(3, 6)), size, Infinity),
[

View File

@ -3,18 +3,18 @@ Engine.LoadLibrary("rmgen-common");
Engine.LoadLibrary("rmbiome");
Engine.LoadLibrary("heightmap");
var tGrove = "temp_grass_plants";
var tPath = "road_rome_a";
const tGrove = "temp_grass_plants";
const tPath = "road_rome_a";
var oGroveEntities = ["structures/gaul/outpost", "gaia/tree/oak_new"];
const oGroveEntities = ["structures/gaul/outpost", "gaia/tree/oak_new"];
var g_Map = new RandomMap(0, "whiteness");
const g_Map = new RandomMap(0, "whiteness");
/**
* Design resource spots
*/
// Mines
let decorations = [
const decorations = [
"actor|geology/gray1.xml", "actor|geology/gray_rock1.xml",
"actor|geology/highland1.xml", "actor|geology/highland2.xml", "actor|geology/highland3.xml",
"actor|geology/highland_c.xml", "actor|geology/highland_d.xml", "actor|geology/highland_e.xml",
@ -25,8 +25,8 @@ let decorations = [
function placeMine(point, centerEntity)
{
g_Map.placeEntityPassable(centerEntity, 0, point, randomAngle());
let quantity = randIntInclusive(11, 23);
let dAngle = 2 * Math.PI / quantity;
const quantity = randIntInclusive(11, 23);
const dAngle = 2 * Math.PI / quantity;
for (let i = 0; i < quantity; ++i)
g_Map.placeEntityPassable(
@ -47,7 +47,7 @@ g_WallStyles.other = {
"farmstead": { "angle": Math.PI, "length": 0, "indent": -3, "bend": 0, "templateName": "structures/brit/farmstead" }
};
let fences = [
const fences = [
new Fortress("fence", [
"foodBin", "farmstead", "bench",
"turn_0.25", "sheep", "turn_0.25", "fence",
@ -79,13 +79,13 @@ let fences = [
"turn_0.25", "sheep", "turn_0.25", "fence_short", "sheep", "fence"
])
];
let num = fences.length;
const num = fences.length;
for (let i = 0; i < num; ++i)
fences.push(new Fortress("fence", clone(fences[i].wall).reverse()));
// Groves, only wood
let groveEntities = ["gaia/tree/bush_temperate", "gaia/tree/euro_beech"];
let groveActors = [
const groveEntities = ["gaia/tree/bush_temperate", "gaia/tree/euro_beech"];
const groveActors = [
"actor|geology/highland1_moss.xml", "actor|geology/highland2_moss.xml",
"actor|props/flora/bush.xml", "actor|props/flora/bush_dry_a.xml", "actor|props/flora/bush_highlands.xml",
"actor|props/flora/bush_tempe_a.xml", "actor|props/flora/bush_tempe_b.xml", "actor|props/flora/ferns.xml"
@ -94,16 +94,16 @@ let groveActors = [
function placeGrove(point)
{
g_Map.placeEntityPassable(pickRandom(oGroveEntities), 0, point, randomAngle());
let quantity = randIntInclusive(20, 30);
let dAngle = 2 * Math.PI / quantity;
const quantity = randIntInclusive(20, 30);
const dAngle = 2 * Math.PI / quantity;
for (let i = 0; i < quantity; ++i)
{
let angle = dAngle * randFloat(i, i + 1);
let dist = randFloat(2, 5);
const angle = dAngle * randFloat(i, i + 1);
const dist = randFloat(2, 5);
let objectList = groveEntities;
if (i % 3 == 0)
objectList = groveActors;
let position = Vector2D.add(point, new Vector2D(dist, 0).rotate(-angle));
const position = Vector2D.add(point, new Vector2D(dist, 0).rotate(-angle));
g_Map.placeEntityPassable(pickRandom(objectList), 0, position, randomAngle());
createArea(
new ClumpPlacer(5, 1, 1, Infinity, position),
@ -121,12 +121,12 @@ function placeCamp(point,
)
{
g_Map.placeEntityPassable(centerEntity, 0, point, randomAngle());
let quantity = randIntInclusive(5, 11);
let dAngle = 2 * Math.PI / quantity;
const quantity = randIntInclusive(5, 11);
const dAngle = 2 * Math.PI / quantity;
for (let i = 0; i < quantity; ++i)
{
let angle = dAngle * randFloat(i, i + 1);
let dist = randFloat(1, 3);
const angle = dAngle * randFloat(i, i + 1);
const dist = randFloat(1, 3);
g_Map.placeEntityPassable(pickRandom(otherEntities), 0, Vector2D.add(point, new Vector2D(dist, 0).rotate(-angle)), randomAngle());
}
}
@ -137,7 +137,7 @@ function placeStartLocationResources(point, foodEntities = ["gaia/fruit/berry_01
// Stone and chicken
let dAngle = 4/9 * Math.PI;
let angle = currentAngle + randFloat(1, 3) * dAngle / 4;
let stonePosition = Vector2D.add(point, new Vector2D(12, 0).rotate(-angle));
const stonePosition = Vector2D.add(point, new Vector2D(12, 0).rotate(-angle));
placeMine(stonePosition, "gaia/rock/temperate_large");
currentAngle += dAngle;
@ -150,7 +150,7 @@ function placeStartLocationResources(point, foodEntities = ["gaia/fruit/berry_01
let objectList = groveEntities;
if (i % 2 == 0)
objectList = groveActors;
let woodPosition = Vector2D.add(point, new Vector2D(randFloat(10, 15), 0).rotate(-angle));
const woodPosition = Vector2D.add(point, new Vector2D(randFloat(10, 15), 0).rotate(-angle));
g_Map.placeEntityPassable(pickRandom(objectList), 0, woodPosition, randomAngle());
createArea(
new ClumpPlacer(5, 1, 1, Infinity, woodPosition),
@ -161,7 +161,7 @@ function placeStartLocationResources(point, foodEntities = ["gaia/fruit/berry_01
// Metal and chicken
dAngle = 2 * Math.PI * 2 / 9;
angle = currentAngle + dAngle * randFloat(1, 3) / 4;
let metalPosition = Vector2D.add(point, new Vector2D(13, 0).rotate(-angle));
const metalPosition = Vector2D.add(point, new Vector2D(13, 0).rotate(-angle));
placeMine(metalPosition, "gaia/ore/temperate_large");
currentAngle += dAngle;
@ -171,7 +171,7 @@ function placeStartLocationResources(point, foodEntities = ["gaia/fruit/berry_01
for (let i = 0; i < quantity; ++i)
{
angle = currentAngle + randFloat(0, dAngle);
let berriesPosition = Vector2D.add(point, new Vector2D(randFloat(10, 15), 0).rotate(-angle));
const berriesPosition = Vector2D.add(point, new Vector2D(randFloat(10, 15), 0).rotate(-angle));
g_Map.placeEntityPassable(pickRandom(foodEntities), 0, berriesPosition, randomAngle());
currentAngle += dAngle;
}
@ -188,18 +188,18 @@ g_Environment.Water.WaterBody.Murkiness = 0.4;
/**
* Base terrain shape generation and settings
*/
let heightScale = (g_Map.size + 256) / 768 / 4;
let heightRange = { "min": MIN_HEIGHT * heightScale, "max": MAX_HEIGHT * heightScale };
const heightScale = (g_Map.size + 256) / 768 / 4;
const heightRange = { "min": MIN_HEIGHT * heightScale, "max": MAX_HEIGHT * heightScale };
// Water coverage
let averageWaterCoverage = 1/5; // NOTE: Since terrain generation is quite unpredictable actual water coverage might vary much with the same value
let heightSeaGround = -MIN_HEIGHT + heightRange.min + averageWaterCoverage * (heightRange.max - heightRange.min); // Water height in environment and the engine
let heightSeaGroundAdjusted = heightSeaGround + MIN_HEIGHT; // Water height in RMGEN
const averageWaterCoverage = 1/5; // NOTE: Since terrain generation is quite unpredictable actual water coverage might vary much with the same value
const heightSeaGround = -MIN_HEIGHT + heightRange.min + averageWaterCoverage * (heightRange.max - heightRange.min); // Water height in environment and the engine
const heightSeaGroundAdjusted = heightSeaGround + MIN_HEIGHT; // Water height in RMGEN
setWaterHeight(heightSeaGround);
g_Map.log("Generating terrain using diamon-square");
let medH = (heightRange.min + heightRange.max) / 2;
let initialHeightmap = [[medH, medH], [medH, medH]];
const medH = (heightRange.min + heightRange.max) / 2;
const initialHeightmap = [[medH, medH], [medH, medH]];
setBaseTerrainDiamondSquare(heightRange.min, heightRange.max, initialHeightmap, 0.8);
g_Map.log("Apply erosion");
@ -210,7 +210,7 @@ rescaleHeightmap(heightRange.min, heightRange.max);
Engine.SetProgress(25);
let heighLimits = [
const heighLimits = [
heightRange.min + 1/3 * (heightSeaGroundAdjusted - heightRange.min), // 0 Deep water
heightRange.min + 2/3 * (heightSeaGroundAdjusted - heightRange.min), // 1 Medium Water
heightRange.min + (heightSeaGroundAdjusted - heightRange.min), // 2 Shallow water
@ -223,11 +223,11 @@ let heighLimits = [
heightSeaGroundAdjusted + 7/8 * (heightRange.max - heightSeaGroundAdjusted), // 9 Upper forest border
heightSeaGroundAdjusted + (heightRange.max - heightSeaGroundAdjusted)]; // 10 Hilltop
let playerHeight = (heighLimits[4] + heighLimits[5]) / 2; // Average player height
const playerHeight = (heighLimits[4] + heighLimits[5]) / 2; // Average player height
g_Map.log("Determining height-dependent biome");
// Texture and actor presets
let myBiome = [];
const myBiome = [];
myBiome.push({ // 0 Deep water
"texture": ["shoreline_stoney_a"],
"entity": [["gaia/fish/generic", "actor|geology/stone_granite_boulder.xml"], 0.02],
@ -284,17 +284,17 @@ myBiome.push({ // 10 Hilltop
"textureHS": ["alpine_cliff_c"], "entityHS": [["actor|geology/highland1.xml"], 0.0]
});
let [playerIDs, playerPosition] = groupPlayersCycle(getStartLocationsByHeightmap({ "min": heighLimits[4], "max": heighLimits[5] }, 1000, 30));
const [playerIDs, playerPosition] = groupPlayersCycle(getStartLocationsByHeightmap({ "min": heighLimits[4], "max": heighLimits[5] }, 1000, 30));
Engine.SetProgress(30);
g_Map.log("Smoothing player locations");
for (let position of playerPosition)
for (const position of playerPosition)
createArea(
new DiskPlacer(35, position),
new SmoothElevationPainter(ELEVATION_SET, g_Map.getHeight(position), 35));
g_Map.log("Creating paths between players");
let clPath = g_Map.createTileClass();
const clPath = g_Map.createTileClass();
for (let i = 0; i < playerPosition.length; ++i)
createArea(
new RandomPathPlacer(playerPosition[i], playerPosition[(i + 1) % playerPosition.length], 4, 2, false),
@ -313,21 +313,21 @@ createArea(
Engine.SetProgress(45);
g_Map.log("Determining resource locations");
let avoidPoints = playerPosition.map(pos => pos.clone());
const avoidPoints = playerPosition.map(pos => pos.clone());
for (let i = 0; i < avoidPoints.length; ++i)
avoidPoints[i].dist = 30;
let resourceSpots = getPointsByHeight({ "min": (heighLimits[3] + heighLimits[4]) / 2, "max": (heighLimits[5] + heighLimits[6]) / 2 }, avoidPoints, clPath);
const resourceSpots = getPointsByHeight({ "min": (heighLimits[3] + heighLimits[4]) / 2, "max": (heighLimits[5] + heighLimits[6]) / 2 }, avoidPoints, clPath);
Engine.SetProgress(55);
/**
* Divide tiles in areas by height and avoid paths
*/
let tchm = getTileCenteredHeightmap();
let areas = heighLimits.map(heightLimit => []);
const tchm = getTileCenteredHeightmap();
const areas = heighLimits.map(heightLimit => []);
for (let x = 0; x < tchm.length; ++x)
for (let y = 0; y < tchm[0].length; ++y)
{
let position = new Vector2D(x, y);
const position = new Vector2D(x, y);
if (!avoidClasses(clPath, 0).allows(position))
continue;
@ -347,16 +347,16 @@ for (let x = 0; x < tchm.length; ++x)
/**
* Get max slope of each area
*/
let slopeMap = getSlopeMap();
let minSlope = [];
let maxSlope = [];
const slopeMap = getSlopeMap();
const minSlope = [];
const maxSlope = [];
for (let h = 0; h < heighLimits.length; ++h)
{
minSlope[h] = Infinity;
maxSlope[h] = 0;
for (let point of areas[h])
for (const point of areas[h])
{
let slope = slopeMap[point.x][point.y];
const slope = slopeMap[point.x][point.y];
if (slope > maxSlope[h])
maxSlope[h] = slope;
@ -368,7 +368,7 @@ for (let h = 0; h < heighLimits.length; ++h)
g_Map.log("Painting areas by height and slope");
for (let h = 0; h < heighLimits.length; ++h)
for (let point of areas[h])
for (const point of areas[h])
{
let entity;
let texture = pickRandom(myBiome[h].texture);
@ -405,8 +405,8 @@ else
g_Map.log("Placing resources, farmsteads, groves and camps");
for (let i = 0; i < resourceSpots.length; ++i)
{
let pos = new Vector2D(resourceSpots[i].x, resourceSpots[i].y);
let choice = i % (isNomad() ? 4 : 5);
const pos = new Vector2D(resourceSpots[i].x, resourceSpots[i].y);
const choice = i % (isNomad() ? 4 : 5);
if (choice == 0)
placeMine(pos, "gaia/rock/temperate_large_02");
if (choice == 1)

View File

@ -51,24 +51,24 @@ const heightSeaGround = -7;
const heightLand = 3;
const heightHill = 20;
var g_Map = new RandomMap(heightLand, tPrimary);
const g_Map = new RandomMap(heightLand, tPrimary);
var numPlayers = getNumPlayers();
var mapSize = g_Map.getSize();
const numPlayers = getNumPlayers();
const mapSize = g_Map.getSize();
var clPlayer = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clWater = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clWater = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
var playerHillRadius = defaultPlayerBaseRadius() / (isNomad() ? 1.5 : 1);
const playerHillRadius = defaultPlayerBaseRadius() / (isNomad() ? 1.5 : 1);
var [playerIDs, playerPosition, playerAngle] = playerPlacementCircle(fractionToTiles(0.35));
const [playerIDs, playerPosition, playerAngle] = playerPlacementCircle(fractionToTiles(0.35));
g_Map.log("Creating player hills and ramps");
for (let i = 0; i < numPlayers; ++i)
@ -81,7 +81,7 @@ for (let i = 0; i < numPlayers; ++i)
new TileClassPainter(clPlayer)
]);
let angle = playerAngle[i] + Math.PI * (1 + randFloat(-1, 1) / 8);
const angle = playerAngle[i] + Math.PI * (1 + randFloat(-1, 1) / 8);
createPassage({
"start": Vector2D.add(playerPosition[i], new Vector2D(playerHillRadius + 15, 0).rotate(-angle)),
"end": Vector2D.add(playerPosition[i], new Vector2D(playerHillRadius - 3, 0).rotate(-angle)),
@ -125,8 +125,8 @@ placePlayerBases({
Engine.SetProgress(10);
g_Map.log("Creating lakes");
var numLakes = Math.round(scaleByMapSize(1,4) * numPlayers);
var waterAreas = createAreas(
const numLakes = Math.round(scaleByMapSize(1,4) * numPlayers);
const waterAreas = createAreas(
new ClumpPlacer(scaleByMapSize(100, 250), 0.8, 0.1, Infinity),
[
new LayeredPainter([tShoreBlend, tShore, tWater], [1, 1]),
@ -139,7 +139,7 @@ var waterAreas = createAreas(
Engine.SetProgress(15);
g_Map.log("Creating reeds");
var group = new SimpleGroup(
const group = new SimpleGroup(
[new SimpleObject(aReeds, 5,10, 0,4), new SimpleObject(aLillies, 0,1, 0,4)], true
);
createObjectGroupsByAreas(group, 0,
@ -169,7 +169,7 @@ Engine.SetProgress(30);
createHills([tCliff, tCliff, tHill], avoidClasses(clPlayer, 2, clWater, 5, clHill, 15), clHill, scaleByMapSize(1, 4) * numPlayers);
Engine.SetProgress(35);
var [forestTrees, stragglerTrees] = getTreeCounts(...rBiomeTreeCount(1));
const [forestTrees, stragglerTrees] = getTreeCounts(...rBiomeTreeCount(1));
createDefaultForests(
[tGrass, tGrassDForest, tGrassPForest, pForestP, pForestD],
avoidClasses(clPlayer, 1, clWater, 3, clForest, 17, clHill, 1),

View File

@ -44,26 +44,26 @@ const pForest2 = [tForestFloor1 + TERRAIN_SEPARATOR + oTree4, tForestFloor1 + TE
const heightLand = 3;
const heightHill = 30;
var g_Map = new RandomMap(heightHill, tMainTerrain);
const g_Map = new RandomMap(heightHill, tMainTerrain);
var numPlayers = getNumPlayers();
var mapSize = g_Map.getSize();
var mapCenter = g_Map.getCenter();
const numPlayers = getNumPlayers();
const mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
var clPlayer = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clHill2 = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
var clLand = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clHill2 = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
const clLand = g_Map.createTileClass();
var playerCanyonRadius = scaleByMapSize(18, 32);
const playerCanyonRadius = scaleByMapSize(18, 32);
var [playerIDs, playerPosition] = playerPlacementCircle(fractionToTiles(0.35));
const [playerIDs, playerPosition] = playerPlacementCircle(fractionToTiles(0.35));
g_Map.log("Reserving space for the players, their initial forests and some less space therein without trees");
for (let i = 0; i < numPlayers; ++i)
@ -108,9 +108,9 @@ for (let i = 0; i < scaleByMapSize(9, 16); ++i)
for (let g = 0; g < scaleByMapSize(5, 30); ++g)
{
let position = new Vector2D(randIntInclusive(1, mapSize - 1), randIntInclusive(1, mapSize - 1));
const position = new Vector2D(randIntInclusive(1, mapSize - 1), randIntInclusive(1, mapSize - 1));
let newarea = createArea(
const newarea = createArea(
new ClumpPlacer(diskArea(fractionToTiles(0.06)), 0.7, 0.1, Infinity, position),
[
new TerrainPainter(tMainTerrain),
@ -121,11 +121,11 @@ for (let g = 0; g < scaleByMapSize(5, 30); ++g)
if (newarea !== null)
{
var distances = [];
var d1 = 9999;
var d2 = 9999;
var p1 = -1;
var p2 = 0;
let distances = [];
let d1 = 9999;
let d2 = 9999;
let p1 = -1;
let p2 = 0;
for (let i = 0; i < numPlayers; ++i)
distances.push(position.distanceTo(playerPosition[i]));
@ -146,7 +146,7 @@ for (let g = 0; g < scaleByMapSize(5, 30); ++g)
}
}
for (let playerID of [p1, p2])
for (const playerID of [p1, p2])
if (playerPosition[playerID])
createArea(
new PathPlacer(position, playerPosition[playerID], scaleByMapSize(11, 17), 0.4, scaleByMapSize(3, 12), 0.1, 0.1),
@ -161,8 +161,8 @@ for (let g = 0; g < scaleByMapSize(5, 30); ++g)
g_Map.log("Creating paths from players to neighbor and center");
for (let i = 0; i < numPlayers; ++i)
{
let neighbor = i + 1 < numPlayers ? i + 1 : 0;
for (let position of [playerPosition[neighbor], mapCenter])
const neighbor = i + 1 < numPlayers ? i + 1 : 0;
for (const position of [playerPosition[neighbor], mapCenter])
createArea(
new PathPlacer(
playerPosition[i],
@ -225,7 +225,7 @@ createHills([tCliff, tCliff, tHill], [avoidClasses(clPlayer, 2, clHill, 8, clHil
// create hills outside the canyon
createHills([tCliff, tCliff, tMainTerrain], avoidClasses(clLand, 1, clHill, 1), clHill, scaleByMapSize(20, 150), undefined, undefined, undefined, undefined, 40);
var [forestTrees, stragglerTrees] = getTreeCounts(...rBiomeTreeCount(1));
const [forestTrees, stragglerTrees] = getTreeCounts(...rBiomeTreeCount(1));
createForests(
[tMainTerrain, tForestFloor1, tForestFloor2, pForest1, pForest2],
[avoidClasses(clPlayer, 1, clForest, 15, clHill, 1, clHill2, 0), stayClasses(clLand, 4)],
@ -271,7 +271,7 @@ createMines(
Engine.SetProgress(65);
var planetm = 1;
let planetm = 1;
if (currentBiome() == "generic/india")
planetm = 8;
@ -294,7 +294,7 @@ createDecoration(
avoidClasses(clForest, 0, clPlayer, 0, clHill, 0));
g_Map.log("Creating actor trees");
var group = new SimpleGroup(
const group = new SimpleGroup(
[new SimpleObject(aTree, 1,1, 0,1)],
true
);
@ -338,7 +338,7 @@ createStragglerTrees(
g_Map.log("Creating treasures");
for (let i = 0; i < randIntInclusive(3, 8); ++i)
for (let template of [oFoodTreasure, oWoodTreasure])
for (const template of [oFoodTreasure, oWoodTreasure])
g_Map.placeEntityPassable(
template,
0,

View File

@ -45,21 +45,21 @@ const pForest2 = [tForestFloor1 + TERRAIN_SEPARATOR + oTree4, tForestFloor1 + TE
const heightSeaGround = -5;
const heightLand = 3;
var g_Map = new RandomMap(heightSeaGround, tWater);
const g_Map = new RandomMap(heightSeaGround, tWater);
var numPlayers = getNumPlayers();
var mapSize = g_Map.getSize();
var mapCenter = g_Map.getCenter();
const numPlayers = getNumPlayers();
const mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
var clPlayer = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
var clLand = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
const clLand = g_Map.createTileClass();
g_Map.log("Creating continent");
createArea(
@ -76,7 +76,7 @@ createArea(
new TileClassPainter(clLand)
]);
var [playerIDs, playerPosition] = playerPlacementCircle(fractionToTiles(0.25));
const [playerIDs, playerPosition] = playerPlacementCircle(fractionToTiles(0.25));
g_Map.log("Ensuring initial player land");
for (let i = 0; i < numPlayers; ++i)
@ -136,7 +136,7 @@ if (randBool())
else
createMountains(tCliff, [avoidClasses(clPlayer, 20, clHill, 15, clBaseResource, 3), stayClasses(clLand, 5)], clHill, scaleByMapSize(1, 4) * numPlayers);
var [forestTrees, stragglerTrees] = getTreeCounts(...rBiomeTreeCount(1));
const [forestTrees, stragglerTrees] = getTreeCounts(...rBiomeTreeCount(1));
createDefaultForests(
[tMainTerrain, tForestFloor1, tForestFloor2, pForest1, pForest2],
[avoidClasses(clPlayer, 20, clForest, 17, clHill, 0, clBaseResource,2), stayClasses(clLand, 4)],
@ -182,7 +182,7 @@ createBalancedStoneMines(
Engine.SetProgress(65);
// create decoration
var planetm = 1;
let planetm = 1;
if (currentBiome() == "generic/india")
planetm = 8;

View File

@ -54,34 +54,34 @@ const pForest = [
tForestFloor
];
var heightSeaGround = -7;
var heightShallow = -0.8;
var heightLand = 3;
const heightSeaGround = -7;
const heightShallow = -0.8;
const heightLand = 3;
var g_Map = new RandomMap(heightLand, tHill);
const g_Map = new RandomMap(heightLand, tHill);
const numPlayers = getNumPlayers();
const mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
var clPlayer = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clWater = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
var clGrass = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clPassageway = g_Map.createTileClass();
var clShallow = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
let clWater = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
const clGrass = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clPassageway = g_Map.createTileClass();
const clShallow = g_Map.createTileClass();
g_Map.log("Creating the main river");
var riverAngle = randomAngle();
var riverWidth = scaleByMapSize(20, 90);
var riverStart = new Vector2D(mapCenter.x, 0).rotateAround(riverAngle, mapCenter);
var riverEnd = new Vector2D(mapCenter.x, mapSize).rotateAround(riverAngle, mapCenter);
const riverAngle = randomAngle();
const riverWidth = scaleByMapSize(20, 90);
const riverStart = new Vector2D(mapCenter.x, 0).rotateAround(riverAngle, mapCenter);
const riverEnd = new Vector2D(mapCenter.x, mapSize).rotateAround(riverAngle, mapCenter);
createArea(
new PathPlacer(riverStart, riverEnd, riverWidth, 0.2, scaleByMapSize(0.3, 1), 0.04, 0.01),

View File

@ -1,90 +1,90 @@
Engine.LoadLibrary("rmgen");
Engine.LoadLibrary("rmgen-common");
var tGrass = ["medit_grass_field", "medit_grass_field_b", "temp_grass_c"];
var tLushGrass = ["medit_grass_field","medit_grass_field_a"];
const tGrass = ["medit_grass_field", "medit_grass_field_b", "temp_grass_c"];
const tLushGrass = ["medit_grass_field","medit_grass_field_a"];
var tSteepCliffs = ["temp_cliff_b", "temp_cliff_a"];
var tCliffs = ["temp_cliff_b", "medit_cliff_italia", "medit_cliff_italia_grass"];
var tHill = ["medit_cliff_italia_grass","medit_cliff_italia_grass", "medit_grass_field", "medit_grass_field", "temp_grass"];
var tMountain = ["medit_cliff_italia_grass","medit_cliff_italia"];
const tSteepCliffs = ["temp_cliff_b", "temp_cliff_a"];
const tCliffs = ["temp_cliff_b", "medit_cliff_italia", "medit_cliff_italia_grass"];
const tHill = ["medit_cliff_italia_grass","medit_cliff_italia_grass", "medit_grass_field", "medit_grass_field", "temp_grass"];
const tMountain = ["medit_cliff_italia_grass","medit_cliff_italia"];
var tRoad = ["medit_city_tile","medit_rocks_grass","medit_grass_field_b"];
var tRoadWild = ["medit_rocks_grass","medit_grass_field_b"];
const tRoad = ["medit_city_tile","medit_rocks_grass","medit_grass_field_b"];
const tRoadWild = ["medit_rocks_grass","medit_grass_field_b"];
var tShoreBlend = ["medit_sand_wet","medit_rocks_wet"];
var tShore = ["medit_rocks","medit_sand","medit_sand"];
var tSandTransition = ["medit_sand","medit_rocks_grass","medit_rocks_grass","medit_rocks_grass"];
var tVeryDeepWater = ["medit_sea_depths","medit_sea_coral_deep"];
var tDeepWater = ["medit_sea_coral_deep","tropic_ocean_coral"];
var tCreekWater = "medit_sea_coral_plants";
const tShoreBlend = ["medit_sand_wet","medit_rocks_wet"];
const tShore = ["medit_rocks","medit_sand","medit_sand"];
const tSandTransition = ["medit_sand","medit_rocks_grass","medit_rocks_grass","medit_rocks_grass"];
const tVeryDeepWater = ["medit_sea_depths","medit_sea_coral_deep"];
const tDeepWater = ["medit_sea_coral_deep","tropic_ocean_coral"];
const tCreekWater = "medit_sea_coral_plants";
var ePine = "gaia/tree/aleppo_pine";
var ePalmTall = "gaia/tree/cretan_date_palm_tall";
var eFanPalm = "gaia/tree/medit_fan_palm";
var eApple = "gaia/fruit/apple";
var eBush = "gaia/fruit/berry_01";
var eFish = "gaia/fish/generic";
var ePig = "gaia/fauna_pig";
var eStoneMine = "gaia/rock/mediterranean_large";
var eMetalMine = "gaia/ore/mediterranean_large";
const ePine = "gaia/tree/aleppo_pine";
const ePalmTall = "gaia/tree/cretan_date_palm_tall";
const eFanPalm = "gaia/tree/medit_fan_palm";
const eApple = "gaia/fruit/apple";
const eBush = "gaia/fruit/berry_01";
const eFish = "gaia/fish/generic";
const ePig = "gaia/fauna_pig";
const eStoneMine = "gaia/rock/mediterranean_large";
const eMetalMine = "gaia/ore/mediterranean_large";
var aRock = "actor|geology/stone_granite_med.xml";
var aLargeRock = "actor|geology/stone_granite_large.xml";
var aBushA = "actor|props/flora/bush_medit_sm_lush.xml";
var aBushB = "actor|props/flora/bush_medit_me_lush.xml";
var aPlantA = "actor|props/flora/plant_medit_artichoke.xml";
var aPlantB = "actor|props/flora/grass_tufts_a.xml";
var aPlantC = "actor|props/flora/grass_soft_tuft_a.xml";
const aRock = "actor|geology/stone_granite_med.xml";
const aLargeRock = "actor|geology/stone_granite_large.xml";
const aBushA = "actor|props/flora/bush_medit_sm_lush.xml";
const aBushB = "actor|props/flora/bush_medit_me_lush.xml";
const aPlantA = "actor|props/flora/plant_medit_artichoke.xml";
const aPlantB = "actor|props/flora/grass_tufts_a.xml";
const aPlantC = "actor|props/flora/grass_soft_tuft_a.xml";
var aStandingStone = "actor|props/special/eyecandy/standing_stones.xml";
const aStandingStone = "actor|props/special/eyecandy/standing_stones.xml";
var heightSeaGround = -8;
var heightCreeks = -5;
var heightBeaches = -1;
var heightMain = 5;
const heightSeaGround = -8;
const heightCreeks = -5;
const heightBeaches = -1;
const heightMain = 5;
var heightOffsetMainRelief = 30;
var heightOffsetLevel1 = 9;
var heightOffsetLevel2 = 8;
var heightOffsetBumps = 2;
var heightOffsetAntiBumps = -5;
const heightOffsetMainRelief = 30;
const heightOffsetLevel1 = 9;
const heightOffsetLevel2 = 8;
const heightOffsetBumps = 2;
const heightOffsetAntiBumps = -5;
var g_Map = new RandomMap(heightSeaGround, tVeryDeepWater);
const g_Map = new RandomMap(heightSeaGround, tVeryDeepWater);
var numPlayers = getNumPlayers();
var mapSize = g_Map.getSize();
var mapCenter = g_Map.getCenter();
const numPlayers = getNumPlayers();
const mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
var clIsland = g_Map.createTileClass();
var clCreek = g_Map.createTileClass();
var clWater = g_Map.createTileClass();
var clCliffs = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clShore = g_Map.createTileClass();
var clPlayer = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
var clPassage = g_Map.createTileClass();
var clSettlement = g_Map.createTileClass();
const clIsland = g_Map.createTileClass();
const clCreek = g_Map.createTileClass();
const clWater = g_Map.createTileClass();
const clCliffs = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clShore = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
const clPassage = g_Map.createTileClass();
const clSettlement = g_Map.createTileClass();
var radiusBeach = fractionToTiles(0.57);
var radiusCreeks = fractionToTiles(0.52);
var radiusIsland = fractionToTiles(0.4);
var radiusLevel1 = fractionToTiles(0.35);
var radiusPlayer = fractionToTiles(0.25);
var radiusLevel2 = fractionToTiles(0.2);
const radiusBeach = fractionToTiles(0.57);
const radiusCreeks = fractionToTiles(0.52);
const radiusIsland = fractionToTiles(0.4);
const radiusLevel1 = fractionToTiles(0.35);
const radiusPlayer = fractionToTiles(0.25);
const radiusLevel2 = fractionToTiles(0.2);
var creeksArea = () => randBool() ? randFloat(10, 50) : scaleByMapSize(75, 100) + randFloat(0, 20);
const creeksArea = () => randBool() ? randFloat(10, 50) : scaleByMapSize(75, 100) + randFloat(0, 20);
var nbCreeks = scaleByMapSize(6, 15);
var nbSubIsland = 5;
var nbBeaches = scaleByMapSize(2, 5);
var nbPassagesLevel1 = scaleByMapSize(4, 8);
var nbPassagesLevel2 = scaleByMapSize(2, 4);
const nbCreeks = scaleByMapSize(6, 15);
const nbSubIsland = 5;
const nbBeaches = scaleByMapSize(2, 5);
const nbPassagesLevel1 = scaleByMapSize(4, 8);
const nbPassagesLevel2 = scaleByMapSize(2, 4);
g_Map.log("Creating Corsica and Sardinia");
var swapAngle = randBool() ? Math.PI / 2 : 0;
var islandLocations = [new Vector2D(0.05, 0.05), new Vector2D(0.95, 0.95)].map(v => v.mult(mapSize).rotateAround(-swapAngle, mapCenter));
const swapAngle = randBool() ? Math.PI / 2 : 0;
const islandLocations = [new Vector2D(0.05, 0.05), new Vector2D(0.95, 0.95)].map(v => v.mult(mapSize).rotateAround(-swapAngle, mapCenter));
for (let island = 0; island < 2; ++island)
{
@ -100,8 +100,8 @@ for (let island = 0; island < 2; ++island)
g_Map.log("Creating subislands");
for (let i = 0; i < nbSubIsland + 1; ++i)
{
let angle = Math.PI * (island + i / (nbSubIsland * 2)) + swapAngle;
let location = Vector2D.add(islandLocations[island], new Vector2D(radiusIsland, 0).rotate(-angle));
const angle = Math.PI * (island + i / (nbSubIsland * 2)) + swapAngle;
const location = Vector2D.add(islandLocations[island], new Vector2D(radiusIsland, 0).rotate(-angle));
createArea(
new ClumpPlacer(diskArea(fractionToTiles(0.09)), 0.6, 0.03, Infinity, location),
[
@ -114,8 +114,8 @@ for (let island = 0; island < 2; ++island)
g_Map.log("Creating creeks");
for (let i = 0; i < nbCreeks + 1; ++i)
{
let angle = Math.PI * (island + i * (1 / (nbCreeks * 2))) + swapAngle;
let location = Vector2D.add(islandLocations[island], new Vector2D(radiusCreeks, 0).rotate(-angle));
const angle = Math.PI * (island + i * (1 / (nbCreeks * 2))) + swapAngle;
const location = Vector2D.add(islandLocations[island], new Vector2D(radiusCreeks, 0).rotate(-angle));
createArea(
new ClumpPlacer(creeksArea(), 0.4, 0.01, Infinity, location),
[
@ -128,9 +128,9 @@ for (let island = 0; island < 2; ++island)
g_Map.log("Creating beaches");
for (let i = 0; i < nbBeaches + 1; ++i)
{
let angle = Math.PI * (island + (i / (nbBeaches * 2.5)) + 1 / (nbBeaches * 6) + randFloat(-1, 1) / (nbBeaches * 7)) + swapAngle;
let start = Vector2D.add(islandLocations[island], new Vector2D(radiusIsland, 0).rotate(-angle));
let end = Vector2D.add(islandLocations[island], new Vector2D(radiusBeach, 0).rotate(-angle));
const angle = Math.PI * (island + (i / (nbBeaches * 2.5)) + 1 / (nbBeaches * 6) + randFloat(-1, 1) / (nbBeaches * 7)) + swapAngle;
const start = Vector2D.add(islandLocations[island], new Vector2D(radiusIsland, 0).rotate(-angle));
const end = Vector2D.add(islandLocations[island], new Vector2D(radiusBeach, 0).rotate(-angle));
createArea(
new ClumpPlacer(130, 0.7, 0.8, Infinity, Vector2D.add(start, Vector2D.mult(end, 3)).div(4)),
@ -159,7 +159,7 @@ for (let island = 0; island < 2; ++island)
g_Map.log("Creating first level passages");
for (let i = 0; i <= nbPassagesLevel1; ++i)
{
let angle = Math.PI * (i / 7 + 1 / 9 + island) + swapAngle;
const angle = Math.PI * (i / 7 + 1 / 9 + island) + swapAngle;
createPassage({
"start": Vector2D.add(islandLocations[island], new Vector2D(radiusLevel1 + 10, 0).rotate(-angle)),
"end": Vector2D.add(islandLocations[island], new Vector2D(radiusLevel1 - 4, 0).rotate(-angle)),
@ -183,7 +183,7 @@ for (let island = 0; island < 2; ++island)
g_Map.log("Creating second level passages");
for (let i = 0; i < nbPassagesLevel2; ++i)
{
let angle = Math.PI * (i / (2 * nbPassagesLevel2) + 1 / (4 * nbPassagesLevel2) + island) + swapAngle;
const angle = Math.PI * (i / (2 * nbPassagesLevel2) + 1 / (4 * nbPassagesLevel2) + island) + swapAngle;
createPassage({
"start": Vector2D.add(islandLocations[island], new Vector2D(radiusLevel2 + 3, 0).rotate(-angle)),
"end": Vector2D.add(islandLocations[island], new Vector2D(radiusLevel2 - 6, 0).rotate(-angle)),
@ -198,13 +198,13 @@ for (let island = 0; island < 2; ++island)
Engine.SetProgress(30);
g_Map.log("Determining player locations");
var playerIDs = sortAllPlayers();
var playerPosition = [];
var playerAngle = [];
var p = 0;
const playerIDs = sortAllPlayers();
let playerPosition = [];
let playerAngle = [];
let p = 0;
for (let island = 0; island < 2; ++island)
{
let playersPerIsland = island == 0 ? Math.ceil(numPlayers / 2) : Math.floor(numPlayers / 2);
const playersPerIsland = island == 0 ? Math.ceil(numPlayers / 2) : Math.floor(numPlayers / 2);
for (let i = 0; i < playersPerIsland; ++i)
{
@ -270,8 +270,8 @@ g_Map.log("Painting land");
for (let mapX = 0; mapX < mapSize; ++mapX)
for (let mapZ = 0; mapZ < mapSize; ++mapZ)
{
let position = new Vector2D(mapX, mapZ);
let terrain = getCosricaSardiniaTerrain(position);
const position = new Vector2D(mapX, mapZ);
const terrain = getCosricaSardiniaTerrain(position);
if (!terrain)
continue;
@ -283,16 +283,16 @@ for (let mapX = 0; mapX < mapSize; ++mapX)
function getCosricaSardiniaTerrain(position)
{
let isWater = clWater.countMembersInRadius(position, 3);
let isShore = clShore.countMembersInRadius(position, 2);
let isPassage = clPassage.countMembersInRadius(position, 2);
let isSettlement = clSettlement.countMembersInRadius(position, 2);
const isWater = clWater.countMembersInRadius(position, 3);
const isShore = clShore.countMembersInRadius(position, 2);
const isPassage = clPassage.countMembersInRadius(position, 2);
const isSettlement = clSettlement.countMembersInRadius(position, 2);
if (isSettlement)
return undefined;
let height = g_Map.getHeight(position);
let slope = g_Map.getSlope(position);
const height = g_Map.getHeight(position);
const slope = g_Map.getSlope(position);
if (height >= 0.5 && height < 1.5 && isShore)
return tSandTransition;
@ -339,7 +339,7 @@ function getCosricaSardiniaTerrain(position)
Engine.SetProgress(65);
g_Map.log("Creating mines");
for (let mine of [eMetalMine, eStoneMine])
for (const mine of [eMetalMine, eStoneMine])
createObjectGroupsDeprecated(
new SimpleGroup(
[
@ -422,7 +422,7 @@ createObjectGroupsDeprecated(
50);
g_Map.log("Creating large decorative rocks");
var rocksGroup = new SimpleGroup(
const rocksGroup = new SimpleGroup(
[
new SimpleObject(aLargeRock, 1, 2, 0, 1),
new SimpleObject(aRock, 1, 3, 0, 2)
@ -449,7 +449,7 @@ createObjectGroupsDeprecated(
500);
g_Map.log("Creating decorative plants");
var plantGroups = [
const plantGroups = [
new SimpleGroup(
[
new SimpleObject(aPlantA, 3, 7, 0, 3),
@ -464,7 +464,7 @@ var plantGroups = [
],
true)
];
for (let group of plantGroups)
for (const group of plantGroups)
createObjectGroupsDeprecated(
group,
0,

View File

@ -49,41 +49,41 @@ const heightLand = 3;
const heightHill = 12;
const heightOffsetBump = 2;
var g_Map = new RandomMap(heightSeaGround, tWater);
const g_Map = new RandomMap(heightSeaGround, tWater);
const numPlayers = getNumPlayers();
const mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
var clCoral = g_Map.createTileClass();
var clPlayer = g_Map.createTileClass();
var clIsland = g_Map.createTileClass();
var clCity = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clWater = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
const clCoral = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clIsland = g_Map.createTileClass();
const clCity = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clWater = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
//array holding starting islands based on number of players
var startingPlaces=[[0],[0,3],[0,2,4],[0,1,3,4],[0,1,2,3,4],[0,1,2,3,4,5]];
const startingPlaces=[[0],[0,3],[0,2,4],[0,1,3,4],[0,1,2,3,4],[0,1,2,3,4,5]];
var startAngle = randomAngle();
const startAngle = randomAngle();
var islandRadius = scaleByMapSize(15, 40);
var islandCount = Math.max(6, numPlayers);
var islandPosition = distributePointsOnCircle(islandCount, startAngle, fractionToTiles(0.39), mapCenter)[0].map(position => position.round());
const islandRadius = scaleByMapSize(15, 40);
const islandCount = Math.max(6, numPlayers);
const islandPosition = distributePointsOnCircle(islandCount, startAngle, fractionToTiles(0.39), mapCenter)[0].map(position => position.round());
var centralIslandRadius = scaleByMapSize(15, 30);
var centralIslandCount = Math.floor(scaleByMapSize(1, 4));
var centralIslandPosition = new Array(numPlayers).fill(0).map((v, i) =>
const centralIslandRadius = scaleByMapSize(15, 30);
const centralIslandCount = Math.floor(scaleByMapSize(1, 4));
const centralIslandPosition = new Array(numPlayers).fill(0).map((v, i) =>
Vector2D.add(mapCenter, new Vector2D(fractionToTiles(randFloat(0.1, 0.16)), 0).rotate(
-startAngle - Math.PI * (i * 2 / centralIslandCount + randFloat(-1, 1) / 8)).round()));
var areas = [];
const areas = [];
var nPlayer = 0;
var playerPosition = [];
@ -114,7 +114,7 @@ function createCycladicArchipelagoIsland(position, tileClass, radius, coralRadiu
g_Map.log("Creating player islands");
for (let i = 0; i < islandCount; ++i)
{
let isPlayerIsland = numPlayers >= 6 || i == startingPlaces[numPlayers - 1][nPlayer];
const isPlayerIsland = numPlayers >= 6 || i == startingPlaces[numPlayers - 1][nPlayer];
if (isPlayerIsland)
{
playerPosition[nPlayer] = islandPosition[i];
@ -124,7 +124,7 @@ for (let i = 0; i < islandCount; ++i)
}
g_Map.log("Creating central islands");
for (let position of centralIslandPosition)
for (const position of centralIslandPosition)
createCycladicArchipelagoIsland(position, clIsland, centralIslandRadius, 2);
placePlayerBases({
@ -193,7 +193,7 @@ var forestTypes = [
[[tForestFloor, tGrass, pMainForest], [tForestFloor, pMainForest]]
];
for (let type of forestTypes)
for (const type of forestTypes)
createAreasInAreas(
new ClumpPlacer(randIntInclusive(6, 17), 0.1, 0.1, Infinity),
[
@ -207,7 +207,7 @@ for (let type of forestTypes)
Engine.SetProgress(42);
g_Map.log("Creating stone mines");
var group = new SimpleGroup([new SimpleObject(oStoneSmall, 0, 2, 0, 4, 0, 2 * Math.PI, 1), new SimpleObject(oStoneLarge, 1, 1, 0, 4, 0, 2 * Math.PI, 4)], true, clRock);
let group = new SimpleGroup([new SimpleObject(oStoneSmall, 0, 2, 0, 4, 0, 2 * Math.PI, 1), new SimpleObject(oStoneLarge, 1, 1, 0, 4, 0, 2 * Math.PI, 4)], true, clRock);
createObjectGroupsByAreasDeprecated(group, 0,
[avoidClasses(clWater, 1, clForest, 1, clHill, 1, clPlayer, 5, clRock, 6)],
scaleByMapSize(4,16), 200, areas
@ -215,7 +215,7 @@ createObjectGroupsByAreasDeprecated(group, 0,
Engine.SetProgress(46);
g_Map.log("Creating small stone mines");
var group = new SimpleGroup([new SimpleObject(oStoneSmall, 2,5, 1,3)], true, clRock);
group = new SimpleGroup([new SimpleObject(oStoneSmall, 2,5, 1,3)], true, clRock);
createObjectGroupsByAreasDeprecated(group, 0,
[avoidClasses(clWater, 1, clForest, 1, clHill, 1, clPlayer, 5, clRock, 6)],
scaleByMapSize(4,16), 200, areas
@ -231,7 +231,7 @@ createObjectGroupsByAreasDeprecated(group, 0,
Engine.SetProgress(54);
g_Map.log("Creating shrub patches");
for (let size of [scaleByMapSize(2, 32), scaleByMapSize(3, 48), scaleByMapSize(5, 80)])
for (const size of [scaleByMapSize(2, 32), scaleByMapSize(3, 48), scaleByMapSize(5, 80)])
createAreasInAreas(
new ClumpPlacer(size, 0.3, 0.06, 0.5),
[
@ -245,7 +245,7 @@ for (let size of [scaleByMapSize(2, 32), scaleByMapSize(3, 48), scaleByMapSize(5
Engine.SetProgress(58);
g_Map.log("Creating grass patches");
for (let size of [scaleByMapSize(2, 32), scaleByMapSize(3, 48), scaleByMapSize(5, 80)])
for (const size of [scaleByMapSize(2, 32), scaleByMapSize(3, 48), scaleByMapSize(5, 80)])
createAreasInAreas(
new ClumpPlacer(size, 0.3, 0.06, 0.5),
[
@ -259,7 +259,7 @@ for (let size of [scaleByMapSize(2, 32), scaleByMapSize(3, 48), scaleByMapSize(5
Engine.SetProgress(62);
g_Map.log("Creating straggler trees");
for (let tree of [oCarob, oBeech, oLombardyPoplar, oLombardyPoplar, oPine])
for (const tree of [oCarob, oBeech, oLombardyPoplar, oLombardyPoplar, oPine])
createObjectGroupsByAreasDeprecated(
new SimpleGroup([new SimpleObject(tree, 1,1, 0,1)], true, clForest),
0,

View File

@ -137,48 +137,48 @@ const heightLand = 3;
const heightPath = 1.5;
const heightIsland = 6;
var g_Map = new RandomMap(heightLand, tPrimary);
const g_Map = new RandomMap(heightLand, tPrimary);
const numPlayers = getNumPlayers();
const mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
const mapBounds = g_Map.getBounds();
var clPlayer = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clWater = g_Map.createTileClass();
var clLand = [g_Map.createTileClass(), g_Map.createTileClass()];
var clPatrolPointSiegeEngine = [g_Map.createTileClass(), g_Map.createTileClass()];
var clPatrolPointSoldier = [g_Map.createTileClass(), g_Map.createTileClass()];
var clShore = [g_Map.createTileClass(), g_Map.createTileClass()];
var clShoreUngarrisonPoint = [g_Map.createTileClass(), g_Map.createTileClass()];
var clShip = g_Map.createTileClass();
var clShipPatrol = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clIsland = g_Map.createTileClass();
var clTreasure = g_Map.createTileClass();
var clWaterLog = g_Map.createTileClass();
var clGauls = g_Map.createTileClass();
var clTower = g_Map.createTileClass();
var clOutpost = g_Map.createTileClass();
var clPath = g_Map.createTileClass();
var clRitualPlace = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clWater = g_Map.createTileClass();
const clLand = [g_Map.createTileClass(), g_Map.createTileClass()];
const clPatrolPointSiegeEngine = [g_Map.createTileClass(), g_Map.createTileClass()];
const clPatrolPointSoldier = [g_Map.createTileClass(), g_Map.createTileClass()];
const clShore = [g_Map.createTileClass(), g_Map.createTileClass()];
const clShoreUngarrisonPoint = [g_Map.createTileClass(), g_Map.createTileClass()];
const clShip = g_Map.createTileClass();
const clShipPatrol = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clIsland = g_Map.createTileClass();
const clTreasure = g_Map.createTileClass();
const clWaterLog = g_Map.createTileClass();
const clGauls = g_Map.createTileClass();
const clTower = g_Map.createTileClass();
const clOutpost = g_Map.createTileClass();
const clPath = g_Map.createTileClass();
const clRitualPlace = g_Map.createTileClass();
var startAngle = randomAngle();
var waterWidth = fractionToTiles(0.3);
const startAngle = randomAngle();
const waterWidth = fractionToTiles(0.3);
// How many treasures will be placed near the gallic civic centers
var gallicCCTreasureCount = randIntInclusive(8, 12);
const gallicCCTreasureCount = randIntInclusive(8, 12);
// How many treasures will be placed randomly on the map at most
var randomTreasureCount = randIntInclusive(0, scaleByMapSize(0, 2));
const randomTreasureCount = randIntInclusive(0, scaleByMapSize(0, 2));
var ritualParticipants = [
const ritualParticipants = [
{
"radius": 0.6,
"templates": [oFemale],
@ -233,7 +233,7 @@ g_WallStyles.danubius_spikes = {
"overlap": 0
};
var fortressDanubiusVillage = new Fortress(
const fortressDanubiusVillage = new Fortress(
"Geto-Dacian Tribal Confederation",
new Array(2).fill([
"gate", "pillar", "hut", "long", "long",
@ -242,47 +242,47 @@ var fortressDanubiusVillage = new Fortress(
"cornerIn", "defense_tower", "long", "tavern", "long", "pillar"
]).reduce((result, items) => result.concat(items), []));
var palisadeCorner = ["turn_0.25", "spike_single", "turn_0.25"];
var palisadeGate = ["spike_single", "gap_3.6", "spike_single"];
var palisadeWallShort = new Array(3).fill("spikes_tall");
var palisadeWallLong = new Array(5).fill("spikes_tall");
var palisadeSideShort = [...palisadeGate, ...palisadeWallShort, ...palisadeCorner, ...palisadeWallShort];
var palisadeSideLong = [...palisadeGate, ...palisadeWallShort, ...palisadeCorner, ...palisadeWallLong];
var fortressDanubiusSpikes = new Fortress(
const palisadeCorner = ["turn_0.25", "spike_single", "turn_0.25"];
const palisadeGate = ["spike_single", "gap_3.6", "spike_single"];
const palisadeWallShort = new Array(3).fill("spikes_tall");
const palisadeWallLong = new Array(5).fill("spikes_tall");
const palisadeSideShort = [...palisadeGate, ...palisadeWallShort, ...palisadeCorner, ...palisadeWallShort];
const palisadeSideLong = [...palisadeGate, ...palisadeWallShort, ...palisadeCorner, ...palisadeWallLong];
const fortressDanubiusSpikes = new Fortress(
"Spikes Of The Geto-Dacian Tribal Confederation",
[...palisadeSideLong, ...palisadeSideShort, ...palisadeSideLong, ...palisadeSideShort]);
// Place a gallic village on small maps and larger
var gallicCC = mapSize >= smallMapSize;
const gallicCC = mapSize >= smallMapSize;
if (gallicCC)
{
g_Map.log("Creating gallic villages");
let gaulCityRadius = 12;
let gaulCityBorderDistance = mapSize < mediumMapSize ? 10 : 18;
const gaulCityRadius = 12;
const gaulCityBorderDistance = mapSize < mediumMapSize ? 10 : 18;
// Whether to add a celtic ritual and a path from the gallic city leading to it
let addCelticRitual = randBool(0.9);
const addCelticRitual = randBool(0.9);
// One village left and right of the river
for (let i = 0; i < 2; ++i)
{
let civicCenterPosition = new Vector2D(
const civicCenterPosition = new Vector2D(
i == 0 ? mapBounds.left + gaulCityBorderDistance : mapBounds.right - gaulCityBorderDistance,
mapCenter.y).rotateAround(startAngle, mapCenter);
if (addCelticRitual)
{
// Don't position the meeting place at the center of the map
let meetingPlacePosition = new Vector2D(
const meetingPlacePosition = new Vector2D(
i == 0 ? mapBounds.left + waterWidth : mapBounds.right - waterWidth,
mapCenter.y + fractionToTiles(randFloat(0.1, 0.4)) * (randBool() ? 1 : -1)).rotateAround(startAngle, mapCenter);
// Radius of the meeting place
let mRadius = scaleByMapSize(4, 6);
const mRadius = scaleByMapSize(4, 6);
// Create a path connecting the gallic city with a meeting place at the shoreline.
// To avoid the path going through the palisade wall, start it at the gate, not at the city center.
let pathStart = Vector2D.add(civicCenterPosition, new Vector2D(gaulCityRadius * (i == 0 ? 1 : -1), 0).rotate(startAngle));
const pathStart = Vector2D.add(civicCenterPosition, new Vector2D(gaulCityRadius * (i == 0 ? 1 : -1), 0).rotate(startAngle));
createArea(
new PathPlacer(pathStart, meetingPlacePosition, 4, 0.4, 4, 0.2, 0.05),
[
@ -302,9 +302,9 @@ if (gallicCC)
g_Map.placeEntityAnywhere(aCampfire, 0, meetingPlacePosition, randomAngle());
for (let participants of ritualParticipants)
for (const participants of ritualParticipants)
{
let [positions, angles] = distributePointsOnCircle(participants.count, startAngle, participants.radius * mRadius, meetingPlacePosition);
const [positions, angles] = distributePointsOnCircle(participants.count, startAngle, participants.radius * mRadius, meetingPlacePosition);
for (let j = 0; j < positions.length; ++j)
g_Map.placeEntityPassable(pickRandom(participants.templates), 0, positions[j], angles[j] + participants.angle);
}
@ -380,7 +380,7 @@ paintRiver({
"meanderShort": 30,
"meanderLong": 0,
"waterFunc": (position, height, riverFraction) => {
let origPos = position.clone().rotateAround(-startAngle, mapCenter);
const origPos = position.clone().rotateAround(-startAngle, mapCenter);
// Distinguish left and right shoreline
if (0 < height && height < 1 &&
origPos.y > ShorelineDistance && origPos.y < mapSize - ShorelineDistance)
@ -399,13 +399,13 @@ Engine.SetProgress(30);
paintTileClassBasedOnHeight(-Infinity, 0.7, Elevation_ExcludeMin_ExcludeMax, clWater);
var areasLand = [0, 1].map(i =>
const areasLand = [0, 1].map(i =>
createArea(
new MapBoundsPlacer(),
undefined,
stayClasses(clLand[i], 0)));
var areasWater =
const areasWater =
[createArea(
new MapBoundsPlacer(),
undefined,
@ -434,7 +434,7 @@ else
Engine.SetProgress(45);
var [forestTrees, stragglerTrees] = getTreeCounts(500, 3000, 0.7);
const [forestTrees, stragglerTrees] = getTreeCounts(500, 3000, 0.7);
createForests(
[tForestFloor, tForestFloor, tForestFloor, pForest1, pForest2],
avoidClasses(clPlayer, 16, clForest, 17, clWater, 5, clHill, 2, clGauls, 5, clPath, 1),
@ -455,7 +455,7 @@ createLayeredPatches(
Engine.SetProgress(55);
g_Map.log("Creating islands");
var areaIslands = createAreas(
const areaIslands = createAreas(
new ChainPlacer(Math.floor(scaleByMapSize(3, 4)), Math.floor(scaleByMapSize(4, 8)), Math.floor(scaleByMapSize(50, 80)), 0.5),
[
new LayeredPainter([tWater, tShore, tIsland], [2, 1]),
@ -720,7 +720,7 @@ createObjectGroupsByAreas(
g_Map.log("Creating ungarrison points for ships");
for (let i = 0; i < 2; ++i)
{
let areaShore = [createArea(
const areaShore = [createArea(
new MapBoundsPlacer(),
undefined,
stayClasses(clShore[i], 0))];

View File

@ -1,66 +1,66 @@
Engine.LoadLibrary("rmgen");
Engine.LoadLibrary("rmgen-common");
var templateStone = "gaia/rock/temperate_small";
var templateStoneMine = "gaia/rock/temperate_large";
var templateMetalMine = "gaia/ore/temperate_large";
var templateTemple = "gaia/ruins/unfinished_greek_temple";
const templateStone = "gaia/rock/temperate_small";
const templateStoneMine = "gaia/rock/temperate_large";
const templateMetalMine = "gaia/ore/temperate_large";
const templateTemple = "gaia/ruins/unfinished_greek_temple";
var terrainPrimary = ["temp_grass", "temp_grass_b", "temp_grass_c", "temp_grass_d", "temp_grass_long_b", "temp_grass_clovers_2", "temp_grass_mossy", "temp_grass_plants"];
var terrainWood = ['temp_grass_mossy|gaia/tree/oak', 'temp_forestfloor_pine|gaia/tree/pine', 'temp_mud_plants|gaia/tree/dead',
const terrainPrimary = ["temp_grass", "temp_grass_b", "temp_grass_c", "temp_grass_d", "temp_grass_long_b", "temp_grass_clovers_2", "temp_grass_mossy", "temp_grass_plants"];
const terrainWood = ['temp_grass_mossy|gaia/tree/oak', 'temp_forestfloor_pine|gaia/tree/pine', 'temp_mud_plants|gaia/tree/dead',
'temp_plants_bog|gaia/tree/oak_large', "temp_dirt_gravel_plants|gaia/tree/aleppo_pine", 'temp_forestfloor_autumn|gaia/tree/carob'];
var terrainWoodBorder = ['temp_grass_plants|gaia/tree/euro_beech', 'temp_grass_mossy|gaia/tree/poplar', 'temp_grass_mossy|gaia/tree/poplar_lombardy',
const terrainWoodBorder = ['temp_grass_plants|gaia/tree/euro_beech', 'temp_grass_mossy|gaia/tree/poplar', 'temp_grass_mossy|gaia/tree/poplar_lombardy',
'temp_grass_long|gaia/tree/bush_temperate', 'temp_mud_plants|gaia/tree/bush_temperate', 'temp_mud_plants|gaia/tree/bush_badlands',
'temp_grass_long|gaia/fruit/apple', 'temp_grass_clovers|gaia/fruit/berry_01', 'temp_grass_clovers_2|gaia/fruit/grapes',
'temp_grass_plants|gaia/fauna_deer', "temp_grass_long_b|gaia/fauna_rabbit", "temp_grass_plants"];
var terrainBase = ["temp_dirt_gravel", "temp_grass_b"];
var terrainBaseBorder = ["temp_grass_b", "temp_grass_b", "temp_grass", "temp_grass_c", "temp_grass_mossy"];
var terrainBaseCenter = ['temp_dirt_gravel', 'temp_dirt_gravel', 'temp_grass_b'];
var terrainPath = ['temp_road', "temp_road_overgrown", 'temp_grass_b'];
var terrainHill = ["temp_highlands", "temp_highlands", "temp_highlands", "temp_dirt_gravel_b", "temp_cliff_a"];
var terrainHillBorder = ["temp_highlands", "temp_highlands", "temp_highlands", "temp_dirt_gravel_b", "temp_dirt_gravel_plants",
const terrainBase = ["temp_dirt_gravel", "temp_grass_b"];
const terrainBaseBorder = ["temp_grass_b", "temp_grass_b", "temp_grass", "temp_grass_c", "temp_grass_mossy"];
const terrainBaseCenter = ['temp_dirt_gravel', 'temp_dirt_gravel', 'temp_grass_b'];
const terrainPath = ['temp_road', "temp_road_overgrown", 'temp_grass_b'];
const terrainHill = ["temp_highlands", "temp_highlands", "temp_highlands", "temp_dirt_gravel_b", "temp_cliff_a"];
const terrainHillBorder = ["temp_highlands", "temp_highlands", "temp_highlands", "temp_dirt_gravel_b", "temp_dirt_gravel_plants",
"temp_highlands", "temp_highlands", "temp_highlands", "temp_dirt_gravel_b", "temp_dirt_gravel_plants",
"temp_highlands", "temp_highlands", "temp_highlands", "temp_cliff_b", "temp_dirt_gravel_plants",
"temp_highlands", "temp_highlands", "temp_highlands", "temp_cliff_b", "temp_dirt_gravel_plants",
"temp_highlands|gaia/fauna_goat"];
var heightPath = -2;
var heightLand = 0;
var heightOffsetRandomPath = 1;
const heightPath = -2;
const heightLand = 0;
const heightOffsetRandomPath = 1;
var g_Map = new RandomMap(heightLand, terrainPrimary);
const g_Map = new RandomMap(heightLand, terrainPrimary);
var mapSize = g_Map.getSize();
var mapRadius = mapSize/2;
var mapCenter = g_Map.getCenter();
const mapSize = g_Map.getSize();
const mapRadius = mapSize/2;
const mapCenter = g_Map.getCenter();
var clPlayer = g_Map.createTileClass();
var clPath = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clPath = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
var numPlayers = getNumPlayers();
var baseRadius = 20;
var minPlayerRadius = Math.min(mapRadius - 1.5 * baseRadius, 5/8 * mapRadius);
var maxPlayerRadius = Math.min(mapRadius - baseRadius, 3/4 * mapRadius);
var playerPosition = [];
var playerAngle = [];
var playerAngleStart = randomAngle();
var playerAngleAddAvrg = 2 * Math.PI / numPlayers;
var playerAngleMaxOff = playerAngleAddAvrg/4;
const numPlayers = getNumPlayers();
const baseRadius = 20;
const minPlayerRadius = Math.min(mapRadius - 1.5 * baseRadius, 5/8 * mapRadius);
const maxPlayerRadius = Math.min(mapRadius - baseRadius, 3/4 * mapRadius);
let playerPosition = [];
let playerAngle = [];
const playerAngleStart = randomAngle();
const playerAngleAddAvrg = 2 * Math.PI / numPlayers;
const playerAngleMaxOff = playerAngleAddAvrg/4;
var radiusEC = Math.max(mapRadius/8, baseRadius/2);
var resourceRadius = fractionToTiles(1/3);
var resourcePerPlayer = [templateStone, templateMetalMine];
const radiusEC = Math.max(mapRadius/8, baseRadius/2);
const resourceRadius = fractionToTiles(1/3);
const resourcePerPlayer = [templateStone, templateMetalMine];
// For large maps there are memory errors with too many trees. A density of 256x192/mapArea works with 0 players.
// Around each player there is an area without trees so with more players the max density can increase a bit.
var maxTreeDensity = Math.min(256 * (192 + 8 * numPlayers) / Math.square(mapSize), 1); // Has to be tweeked but works ok
var bushChance = 1/3; // 1 means 50% chance in deepest wood, 0.5 means 25% chance in deepest wood
const maxTreeDensity = Math.min(256 * (192 + 8 * numPlayers) / Math.square(mapSize), 1); // Has to be tweeked but works ok
const bushChance = 1/3; // 1 means 50% chance in deepest wood, 0.5 means 25% chance in deepest wood
var playerIDs = sortAllPlayers();
for (var i=0; i < numPlayers; i++)
const playerIDs = sortAllPlayers();
for (let i=0; i < numPlayers; i++)
{
playerAngle[i] = (playerAngleStart + i * playerAngleAddAvrg + randFloat(0, playerAngleMaxOff)) % (2 * Math.PI);
playerPosition[i] = Vector2D.add(mapCenter, new Vector2D(randFloat(minPlayerRadius, maxPlayerRadius), 0).rotate(-playerAngle[i]).round());
@ -105,12 +105,12 @@ placePlayerBases({
Engine.SetProgress(30);
g_Map.log("Painting paths");
var pathBlending = numPlayers <= 4;
const pathBlending = numPlayers <= 4;
for (let i = 0; i < numPlayers + (pathBlending ? 1 : 0); ++i)
for (let j = pathBlending ? 0 : i + 1; j < numPlayers + 1; ++j)
{
let pathStart = i < numPlayers ? playerPosition[i] : mapCenter;
let pathEnd = j < numPlayers ? playerPosition[j] : mapCenter;
const pathStart = i < numPlayers ? playerPosition[i] : mapCenter;
const pathEnd = j < numPlayers ? playerPosition[j] : mapCenter;
createArea(
new RandomPathPlacer(pathStart, pathEnd, 1.25, baseRadius / 2, pathBlending),
@ -127,13 +127,13 @@ g_Map.log("Placing expansion resources");
for (let i = 0; i < numPlayers; ++i)
for (let rIndex = 0; rIndex < resourcePerPlayer.length; ++rIndex)
{
let angleDist = numPlayers > 1 ?
const angleDist = numPlayers > 1 ?
(playerAngle[(i + 1) % numPlayers] - playerAngle[i] + 2 * Math.PI) % (2 * Math.PI) :
2 * Math.PI;
// they are supposed to be in between players on the same radius
let angle = playerAngle[i] + angleDist * (rIndex + 1) / (resourcePerPlayer.length + 1);
let position = Vector2D.add(mapCenter, new Vector2D(resourceRadius, 0).rotate(-angle)).round();
const angle = playerAngle[i] + angleDist * (rIndex + 1) / (resourcePerPlayer.length + 1);
const position = Vector2D.add(mapCenter, new Vector2D(resourceRadius, 0).rotate(-angle)).round();
g_Map.placeEntityPassable(resourcePerPlayer[rIndex], 0, position, randomAngle());
@ -161,26 +161,26 @@ createArea(
]);
// Woods and general height map
for (var x = 0; x < mapSize; x++)
for (var z = 0; z < mapSize; z++)
for (let x = 0; x < mapSize; x++)
for (let z = 0; z < mapSize; z++)
{
let position = new Vector2D(x, z);
const position = new Vector2D(x, z);
// The 0.5 is a correction for the entities placed on the center of tiles
var radius = mapCenter.distanceTo(Vector2D.add(position, new Vector2D(0.5, 0.5)));
var minDistToSL = mapSize;
for (var i=0; i < numPlayers; i++)
const radius = mapCenter.distanceTo(Vector2D.add(position, new Vector2D(0.5, 0.5)));
let minDistToSL = mapSize;
for (let i=0; i < numPlayers; i++)
minDistToSL = Math.min(minDistToSL, position.distanceTo(playerPosition[i]));
// Woods tile based
var tDensFactSL = Math.max(Math.min((minDistToSL - baseRadius) / baseRadius, 1), 0);
var tDensFactRad = Math.abs((resourceRadius - radius) / resourceRadius);
var tDensFactEC = Math.max(Math.min((radius - radiusEC) / radiusEC, 1), 0);
var tDensActual = maxTreeDensity * tDensFactSL * tDensFactRad * tDensFactEC;
const tDensFactSL = Math.max(Math.min((minDistToSL - baseRadius) / baseRadius, 1), 0);
const tDensFactRad = Math.abs((resourceRadius - radius) / resourceRadius);
const tDensFactEC = Math.max(Math.min((radius - radiusEC) / radiusEC, 1), 0);
const tDensActual = maxTreeDensity * tDensFactSL * tDensFactRad * tDensFactEC;
if (randBool(tDensActual) && g_Map.validTile(position))
{
let border = tDensActual < randFloat(0, bushChance * maxTreeDensity);
const border = tDensActual < randFloat(0, bushChance * maxTreeDensity);
if (avoidClasses(clPath, 1, clHill, border ? 0 : 1).allows(position))
{
createTerrain(border ? terrainWoodBorder : terrainWood).place(position);
@ -190,8 +190,8 @@ for (var x = 0; x < mapSize; x++)
}
// General height map
let hVarMiddleHill = fractionToTiles(1 / 64) * (1 + Math.cos(3/2 * Math.PI * radius / mapRadius));
var hVarHills = 5 * (1 + Math.sin(x / 10) * Math.sin(z / 10));
const hVarMiddleHill = fractionToTiles(1 / 64) * (1 + Math.cos(3/2 * Math.PI * radius / mapRadius));
const hVarHills = 5 * (1 + Math.sin(x / 10) * Math.sin(z / 10));
g_Map.setHeight(position, g_Map.getHeight(position) + hVarMiddleHill + hVarHills + 1);
}
Engine.SetProgress(95);

View File

@ -74,33 +74,33 @@ const heightOffsetBump = 2;
const heightHill = 8;
const heightVolano = 25;
var g_Map = new RandomMap(heightSeaGround, tWater);
var numPlayers = getNumPlayers();
const g_Map = new RandomMap(heightSeaGround, tWater);
const numPlayers = getNumPlayers();
var clIsland = g_Map.createTileClass();
var clWater = g_Map.createTileClass();
var clPlayer = g_Map.createTileClass();
var clPlayerIsland = g_Map.createTileClass();
var clShore = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
var clGrass = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clVolcano = g_Map.createTileClass();
var clBridge = g_Map.createTileClass();
const clIsland = g_Map.createTileClass();
const clWater = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clPlayerIsland = g_Map.createTileClass();
const clShore = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
const clGrass = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clVolcano = g_Map.createTileClass();
const clBridge = g_Map.createTileClass();
const playerIslandRadius = scaleByMapSize(20, 29);
const bridgeLength = 16;
const maxBridges = scaleByMapSize(2, 12);
var [playerIDs, playerPosition] = playerPlacementRandom(sortAllPlayers());
const [playerIDs, playerPosition] = playerPlacementRandom(sortAllPlayers());
g_Map.log("Creating player islands");
for (let position of playerPosition)
for (const position of playerPosition)
createArea(
new ChainPlacer(2, 6, scaleByMapSize(15, 50), Infinity, position, 0, [playerIslandRadius]),
[
@ -139,7 +139,7 @@ createAreas(
Engine.SetProgress(35);
g_Map.log("Creating volcano");
var areasVolcano = createAreas(
const areasVolcano = createAreas(
new ClumpPlacer(diskArea(scaleByMapSize(4, 8)), 0.5, 0.5, 0.1),
[
new LayeredPainter([tLavaOuter, tLavaInner], [4]),
@ -182,7 +182,7 @@ paintTerrainBasedOnHeight(heightCoralsLower, heightCoralsUpper, Elevation_Includ
paintTerrainBasedOnHeight(heightCoralsUpper, heightShoreLower, Elevation_IncludeMin_ExcludeMax, tCoralsUpper);
g_Map.log("Painting shoreline");
var areaShoreline = createArea(
const areaShoreline = createArea(
new HeightPlacer(Elevation_IncludeMin_ExcludeMax, heightShoreLower, heightShoreUpper),
[
new TerrainPainter(tShoreLower),
@ -258,7 +258,7 @@ Engine.SetProgress(80);
placePlayersNomad(clPlayer, avoidClasses(clWater, 12, clVolcano, 4, clMetal, 4, clRock, 4, clHill, 4));
var [forestTrees, stragglerTrees] = getTreeCounts(800, 4000, 0.7);
const [forestTrees, stragglerTrees] = getTreeCounts(800, 4000, 0.7);
createForests(
[tForestFloor, tForestFloor, tForestFloor, pForest1, pForest2],
avoidClasses(clWater, 2, clPlayer, 4, clVolcano, 2, clForest, 1, clBaseResource, 4, clMetal, 4, clRock, 4),
@ -330,32 +330,32 @@ createDecoration(
avoidClasses(clWater, 4, clPlayer, 5, clVolcano, 4, clForest, 1, clBaseResource, 4, clRock, 4, clMetal, 4, clHill, 1));
g_Map.log("Creating bridges");
var bridges = 0;
for (let bridgeStart of shuffleArray(areaShoreline.getPoints()))
let bridges = 0;
for (const bridgeStart of shuffleArray(areaShoreline.getPoints()))
{
if (new NearTileClassConstraint(clBridge, bridgeLength * 8).allows(bridgeStart))
continue;
for (let direction = 0; direction < 4; ++direction)
{
let bridgeAngle = direction * Math.PI / 2;
let bridgeDirection = new Vector2D(1, 0).rotate(bridgeAngle);
const bridgeAngle = direction * Math.PI / 2;
const bridgeDirection = new Vector2D(1, 0).rotate(bridgeAngle);
let areaOffset = new Vector2D(1, 1);
const areaOffset = new Vector2D(1, 1);
let bridgeOffset = new Vector2D(direction % 2 ? 2 : 0, direction % 2 ? 0 : 2);
let bridgeCenter1 = Vector2D.add(bridgeStart, Vector2D.mult(bridgeDirection, bridgeLength / 2));
let bridgeCenter2 = Vector2D.add(bridgeCenter1, bridgeOffset);
const bridgeOffset = new Vector2D(direction % 2 ? 2 : 0, direction % 2 ? 0 : 2);
const bridgeCenter1 = Vector2D.add(bridgeStart, Vector2D.mult(bridgeDirection, bridgeLength / 2));
const bridgeCenter2 = Vector2D.add(bridgeCenter1, bridgeOffset);
if (avoidClasses(clWater, 0).allows(bridgeCenter1) && avoidClasses(clWater, 0).allows(bridgeCenter2))
continue;
let bridgeEnd1 = Vector2D.add(bridgeStart, Vector2D.mult(bridgeDirection, bridgeLength));
let bridgeEnd2 = Vector2D.add(bridgeEnd1, bridgeOffset);
const bridgeEnd1 = Vector2D.add(bridgeStart, Vector2D.mult(bridgeDirection, bridgeLength));
const bridgeEnd2 = Vector2D.add(bridgeEnd1, bridgeOffset);
if (avoidClasses(clShore, 0).allows(bridgeEnd1) && avoidClasses(clShore, 0).allows(bridgeEnd2))
continue;
let bridgePerpendicular = bridgeDirection.perpendicular();
let bridgeP = Vector2D.mult(bridgePerpendicular, bridgeLength / 2).round();
const bridgePerpendicular = bridgeDirection.perpendicular();
const bridgeP = Vector2D.mult(bridgePerpendicular, bridgeLength / 2).round();
if (avoidClasses(clWater, 0).allows(Vector2D.add(bridgeCenter1, bridgeP)) ||
avoidClasses(clWater, 0).allows(Vector2D.sub(bridgeCenter2, bridgeP)))
continue;
@ -364,7 +364,7 @@ for (let bridgeStart of shuffleArray(areaShoreline.getPoints()))
// This bridge model is not centered on the horizontal plane, so the angle is messy
// TILE_CENTERED_HEIGHT_MAP also influences the outcome of the placement.
let bridgeOrientation = direction % 2 ? 0 : Math.PI / 2;
const bridgeOrientation = direction % 2 ? 0 : Math.PI / 2;
bridgeCenter1[direction % 2 ? "y" : "x"] += 0.25;
bridgeCenter2[direction % 2 ? "y" : "x"] -= 0.25;
@ -378,7 +378,7 @@ for (let bridgeStart of shuffleArray(areaShoreline.getPoints()))
new TileClassPainter(clBridge)
]);
for (let center of [bridgeStart, bridgeEnd2])
for (const center of [bridgeStart, bridgeEnd2])
createArea(
new DiskPlacer(2, center),
new SmoothingPainter(1, 1, 1));

View File

@ -187,7 +187,7 @@ createArea(
Engine.SetProgress(10);
g_Map.log("Marking islands");
var areaIsland = createArea(
const areaIsland = createArea(
new ConvexPolygonPlacer(
[
new Vector2D(mapCenter.x - riverWidthBorder / 2, mapBounds.top),
@ -248,7 +248,7 @@ placePlayerBases({
Engine.SetProgress(22);
g_Map.log("Creating temple");
var groupTemple = createObjectGroupsByAreas(
const groupTemple = createObjectGroupsByAreas(
new SimpleGroup([new RandomObject(g_Map.getSize() >= 320 ? [oWonder] : oTemples, 1, 1, 0, 1, riverAngle, riverAngle)], true, clTemple),
0,
stayClasses(clIsland, scaleByMapSize(10, 20)),
@ -258,7 +258,7 @@ var groupTemple = createObjectGroupsByAreas(
Engine.SetProgress(34);
g_Map.log("Creating pyramid");
var groupPyramid = createObjectGroupsByAreas(
const groupPyramid = createObjectGroupsByAreas(
new SimpleGroup([new SimpleObject(oPyramid, 1, 1, 0, 1, riverAngle, riverAngle)], true, clTemple),
0,
[stayClasses(clIsland, scaleByMapSize(10, 20)), avoidClasses(clTemple, scaleByMapSize(20, 50)), avoidCollisions],
@ -268,11 +268,11 @@ var groupPyramid = createObjectGroupsByAreas(
Engine.SetProgress(37);
g_Map.log("Painting city patches");
var cityCenters = [
const cityCenters = [
groupTemple[0] && groupTemple[0][0] && { "pos": Vector2D.from3D(groupTemple[0][0].position), "radius": 10 },
groupPyramid[0] && groupPyramid[0][0] && { "pos": Vector2D.from3D(groupPyramid[0][0].position), "radius": 6 },].filter(pos => !!pos);
var areaCityPatch = cityCenters.map(cityCenter =>
const areaCityPatch = cityCenters.map(cityCenter =>
createArea(
new DiskPlacer(cityCenter.radius, cityCenter.pos),
new LayeredPainter([tRoadWildIsland, tRoadIsland], [2]),
@ -339,7 +339,7 @@ createObjectGroups(
200);
Engine.SetProgress(49);
var [forestTrees, stragglerTrees] = getTreeCounts(400, 3000, 0.7);
const [forestTrees, stragglerTrees] = getTreeCounts(400, 3000, 0.7);
createForests(
[tForestFloorLand, tForestFloorLand, tForestFloorLand, pForestPalmsLand, pForest2Land],
[avoidCollisions, avoidClasses(clIsland, 0, clPlayer, 20, clForest, 18, clWater, 2)],

View File

@ -5,7 +5,7 @@ Engine.LoadLibrary("rmbiome");
setSelectedBiome();
var g_Map = new RandomMap(2, g_Terrains.mainTerrain);
const g_Map = new RandomMap(2, g_Terrains.mainTerrain);
initTileClasses();
@ -28,7 +28,7 @@ createBases(
Engine.SetProgress(20);
// Change the starting angle and add the players again
var rotation = Math.PI;
let rotation = Math.PI;
if (teamsArray.length == 2)
rotation = Math.PI / 2;

View File

@ -40,28 +40,28 @@ const aLillies = "actor|props/flora/water_lillies.xml";
const pForestD = [tGrassDForest + TERRAIN_SEPARATOR + oBeech, tGrassDForest];
var heightSeaGround = -4;
var heightShore = 1;
var heightLand = 3;
const heightSeaGround = -4;
const heightShore = 1;
const heightLand = 3;
var g_Map = new RandomMap(heightShore, tPrimary);
const g_Map = new RandomMap(heightShore, tPrimary);
const numPlayers = getNumPlayers();
const mapCenter = g_Map.getCenter();
const mapBounds = g_Map.getBounds();
var clPlayer = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clWater = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
var clShallow = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clWater = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
const clShallow = g_Map.createTileClass();
var startAngle = randomAngle();
const startAngle = randomAngle();
placePlayerBases({
"PlayerPlacement": playerPlacementRiver(startAngle + Math.PI / 2, fractionToTiles(0.6)),
@ -135,7 +135,7 @@ Engine.SetProgress(30);
createHills([tCliff, tCliff, tHill], avoidClasses(clPlayer, 20, clHill, 15, clWater, 5), clHill, scaleByMapSize(1, 4) * numPlayers);
Engine.SetProgress(50);
var [forestTrees, stragglerTrees] = getTreeCounts(500, 3000, 0.7);
const [forestTrees, stragglerTrees] = getTreeCounts(500, 3000, 0.7);
createForests(
[tGrass, tGrassDForest, tGrassDForest, pForestD, pForestD],
avoidClasses(clPlayer, 20, clForest, 17, clHill, 0, clWater, 6),

View File

@ -51,33 +51,33 @@ const pForestP = [
tForestFloor1
];
var heightSeaGround = -4;
var heightLand = 1;
var heightHill = 18;
var heightPlayerHill = 25;
const heightSeaGround = -4;
const heightLand = 1;
const heightHill = 18;
const heightPlayerHill = 25;
var g_Map = new RandomMap(heightLand, tHillMedium1);
const g_Map = new RandomMap(heightLand, tHillMedium1);
var numPlayers = getNumPlayers();
var mapCenter = g_Map.getCenter();
const numPlayers = getNumPlayers();
const mapCenter = g_Map.getCenter();
var clPlayer = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clWater = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clGrass = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
var clBumps = g_Map.createTileClass();
var clTower = g_Map.createTileClass();
var clRain = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clWater = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clGrass = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
const clBumps = g_Map.createTileClass();
const clTower = g_Map.createTileClass();
const clRain = g_Map.createTileClass();
var playerMountainSize = defaultPlayerBaseRadius();
const playerMountainSize = defaultPlayerBaseRadius();
var [playerIDs, playerPosition] = playerPlacementCircle(fractionToTiles(0.35));
const [playerIDs, playerPosition] = playerPlacementCircle(fractionToTiles(0.35));
g_Map.log("Creating CC mountains");
if (!isNomad())
@ -167,14 +167,14 @@ createAreas(
Engine.SetProgress(35);
g_Map.log("Creating forests");
var [forestTrees, stragglerTrees] = getTreeCounts(1200, 3000, 0.7);
var types = [
const [forestTrees, stragglerTrees] = getTreeCounts(1200, 3000, 0.7);
const types = [
[[tGrassB, tGrassA, pForestD], [tGrassB, pForestD]],
[[tGrassB, tGrassA, pForestP], [tGrassB, pForestP]]
];
var size = forestTrees / (scaleByMapSize(4, 12) * numPlayers);
var num = Math.floor(size / types.length);
for (let type of types)
const size = forestTrees / (scaleByMapSize(4, 12) * numPlayers);
const num = Math.floor(size / types.length);
for (const type of types)
createAreas(
new ClumpPlacer(forestTrees / num, 0.1, 0.1, Infinity),
[
@ -190,8 +190,8 @@ for (let type of types)
Engine.SetProgress(40);
g_Map.log("Creating hill patches");
for (let size of [scaleByMapSize(3, 48), scaleByMapSize(5, 84), scaleByMapSize(8, 128)])
for (let type of [[tHillMedium1, tHillDark], [tHillDark, tHillMedium2], [tHillMedium1, tHillMedium2]])
for (const size of [scaleByMapSize(3, 48), scaleByMapSize(5, 84), scaleByMapSize(8, 128)])
for (const type of [[tHillMedium1, tHillDark], [tHillDark, tHillMedium2], [tHillMedium1, tHillMedium2]])
createAreas(
new ClumpPlacer(size, 0.3, 0.06, 0.5),
[

View File

@ -68,20 +68,20 @@ const numPlayers = getNumPlayers();
const mapCenter = g_Map.getCenter();
const mapBounds = g_Map.getBounds();
var clPlayer = g_Map.createTileClass();
var clKushiteVillages = g_Map.createTileClass();
var clRiver = g_Map.createTileClass();
var clShore = g_Map.createTileClass();
var clDunes = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
var clRain = g_Map.createTileClass();
var clCataract = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clKushiteVillages = g_Map.createTileClass();
const clRiver = g_Map.createTileClass();
const clShore = g_Map.createTileClass();
const clDunes = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
const clRain = g_Map.createTileClass();
const clCataract = g_Map.createTileClass();
var kushVillageBuildings = {
const kushVillageBuildings = {
"houseA": { "template": oHouse, "offset": new Vector2D(5, 5) },
"houseB": { "template": oHouse, "offset": new Vector2D(5, 0) },
"houseC": { "template": oHouse, "offset": new Vector2D(5, -5) },
@ -124,7 +124,7 @@ paintRiver({
createTerrain(tRiverBank).place(position);
},
"landFunc": (position, shoreDist1, shoreDist2) => {
for (let riv of riverTextures)
for (const riv of riverTextures)
if (riv.left < +shoreDist1 && +shoreDist1 < riv.right || riv.left < -shoreDist2 && -shoreDist2 < riv.right)
{
riv.tileClass.add(position);
@ -136,11 +136,11 @@ paintRiver({
Engine.SetProgress(10);
g_Map.log("Creating cataracts");
for (let x of [fractionToTiles(randFloat(0.15, 0.25)), fractionToTiles(randFloat(0.75, 0.85))])
for (const x of [fractionToTiles(randFloat(0.15, 0.25)), fractionToTiles(randFloat(0.75, 0.85))])
{
let anglePassage = riverAngle + Math.PI / 2 * randFloat(0.8, 1.2);
const anglePassage = riverAngle + Math.PI / 2 * randFloat(0.8, 1.2);
let areaPassage = createArea(
const areaPassage = createArea(
new PathPlacer(
new Vector2D(x, mapBounds.bottom).rotateAround(anglePassage, mapCenter),
new Vector2D(x, mapBounds.top).rotateAround(anglePassage, mapCenter),
@ -173,7 +173,7 @@ for (let x of [fractionToTiles(randFloat(0.15, 0.25)), fractionToTiles(randFloat
[areaPassage]);
}
var [playerIDs, playerPosition] = playerPlacementRandom(sortAllPlayers(), avoidClasses(clRiver, 15, clPlayer, 30));
const [playerIDs, playerPosition] = playerPlacementRandom(sortAllPlayers(), avoidClasses(clRiver, 15, clPlayer, 30));
placePlayerBases({
"PlayerPlacement": [playerIDs, playerPosition],
"BaseResourceClass": clBaseResource,
@ -208,10 +208,10 @@ placePlayerBases({
Engine.SetProgress(15);
g_Map.log("Getting random coordinates for Kushite settlements");
var kushiteTownPositions = [];
let kushiteTownPositions = [];
for (let retryCount = 0; retryCount < scaleByMapSize(3, 10); ++retryCount)
{
let coordinate = g_Map.randomCoordinate(true);
const coordinate = g_Map.randomCoordinate(true);
if (new AndConstraint(avoidClasses(clPlayer, 40, clForest, 5, clKushiteVillages, 50, clRiver, 15)).allows(coordinate))
{
kushiteTownPositions.push(coordinate);
@ -225,9 +225,9 @@ for (let retryCount = 0; retryCount < scaleByMapSize(3, 10); ++retryCount)
}
g_Map.log("Placing the Kushite buildings");
for (let coordinate of kushiteTownPositions)
for (const coordinate of kushiteTownPositions)
{
for (let building in kushVillageBuildings)
for (const building in kushVillageBuildings)
g_Map.placeEntityPassable(kushVillageBuildings[building].template, 0, Vector2D.add(coordinate, kushVillageBuildings[building].offset), Math.PI);
createObjectGroup(new SimpleGroup([new SimpleObject(oKushUnits, 5, 7, 1, 2)], true, clKushiteVillages, coordinate), 0);
@ -261,7 +261,7 @@ createAreas(
Engine.SetProgress(25);
var [forestTrees, stragglerTrees] = getTreeCounts(400, 2000, 0.7);
const [forestTrees, stragglerTrees] = getTreeCounts(400, 2000, 0.7);
createForests(
[tMainDirt[0], tForestFloor, tForestFloor, pForestP, pForestP],
avoidClasses(clPlayer, 20, clForest, 20, clDunes, 2, clRiver, 20, clKushiteVillages, 10),
@ -270,7 +270,7 @@ createForests(
Engine.SetProgress(40);
g_Map.log("Creating dirt patches");
for (let size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)])
for (const size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)])
createAreas(
new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), size, 0.5),
new LayeredPainter([tSecondaryDirt, tDirt], [1]),
@ -278,7 +278,7 @@ for (let size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8,
scaleByMapSize(50, 90));
g_Map.log("Creating patches of farmland");
for (let size of [scaleByMapSize(30, 40), scaleByMapSize(35, 50)])
for (const size of [scaleByMapSize(30, 40), scaleByMapSize(35, 50)])
createAreas(
new ClumpPlacer(size, 0.4, 0.6),
new TerrainPainter(tFarmland),

View File

@ -17,8 +17,8 @@ const tTier4Terrain = g_Terrains.tier4Terrain;
const tShore = g_Terrains.shore;
const tWater = g_Terrains.water;
var tHill = g_Terrains.hill;
var tDirt = g_Terrains.dirt;
let tHill = g_Terrains.hill;
let tDirt = g_Terrains.dirt;
if (currentBiome() == "generic/temperate")
{
tDirt = ["medit_shrubs_a", "grass_field"];
@ -52,7 +52,7 @@ const heightLand = 6;
const heightStartingIslands = 2;
const shoreRadius = 6;
var g_Map = new RandomMap(heightSeaGround, tWater);
const g_Map = new RandomMap(heightSeaGround, tWater);
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
@ -69,7 +69,7 @@ const mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
g_Map.log("Creating player islands...");
var [playerIDs, playerPosition] = playerPlacementCircle(fractionToTiles(0.38));
const [playerIDs, playerPosition] = playerPlacementCircle(fractionToTiles(0.38));
for (let i = 0; i < numPlayers; ++i)
createArea(
@ -131,7 +131,7 @@ createArea(
for (let m = 0; m < randIntInclusive(20, 34); ++m)
{
let elevRand = randIntInclusive(6, 20);
const elevRand = randIntInclusive(6, 20);
createArea(
new ChainPlacer(
7,
@ -151,7 +151,7 @@ for (let m = 0; m < randIntInclusive(20, 34); ++m)
for (let m = 0; m < randIntInclusive(8, 17); ++m)
{
let elevRand = randIntInclusive(15, 29);
const elevRand = randIntInclusive(15, 29);
createArea(
new ChainPlacer(
5,
@ -203,7 +203,7 @@ createForests(
clForest,
forestTrees);
let types = [oTree1, oTree2, oTree4, oTree3];
const types = [oTree1, oTree2, oTree4, oTree3];
createStragglerTrees(
types,
[avoidClasses(clBaseResource, 2, clMetal, 6, clRock, 6, clMountain, 2, clPlayer, 25), stayClasses(clHill, 6)],
@ -212,8 +212,8 @@ createStragglerTrees(
Engine.SetProgress(65);
g_Map.log("Creating dirt patches");
var numb = currentBiome() == "generic/savanna" ? 3 : 1;
for (let size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)])
const numb = currentBiome() == "generic/savanna" ? 3 : 1;
for (const size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)])
createAreas(
new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), size, 0.5),
[
@ -228,7 +228,7 @@ paintTerrainBasedOnHeight(1, heightStartingIslands, 0, tMainTerrain);
paintTerrainBasedOnHeight(heightSeaGround, 1, 3, tTier1Terrain);
g_Map.log("Creating grass patches");
for (let size of [scaleByMapSize(2, 4), scaleByMapSize(3, 7), scaleByMapSize(5, 15)])
for (const size of [scaleByMapSize(2, 4), scaleByMapSize(3, 7), scaleByMapSize(5, 15)])
createAreas(
new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), size, 0.5),
new TerrainPainter(tTier4Terrain),

View File

@ -42,41 +42,41 @@ const pForestD = [tForestFloor + TERRAIN_SEPARATOR + oBeech, tForestFloor];
const pForestO = [tForestFloor + TERRAIN_SEPARATOR + oOak, tForestFloor];
const pForestP = [tForestFloor + TERRAIN_SEPARATOR + oPine, tForestFloor];
var heightSeaGround = -4;
var heightLand = 3;
const heightSeaGround = -4;
const heightLand = 3;
var g_Map = new RandomMap(heightLand, tGrass);
const g_Map = new RandomMap(heightLand, tGrass);
const numPlayers = getNumPlayers();
var clPlayer = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clWater = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clWater = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
var treasures = [
const treasures = [
{ "template": oFoodTreasure, "count": 5 },
{ "template": oWoodTreasure, "count": 5 },
{ "template": oMetalTreasure, "count": 4 },
{ "template": oStoneTreasure, "count": 2 }
];
var [playerIDs, playerPosition] = playerPlacementCircle(fractionToTiles(0.35));
const [playerIDs, playerPosition] = playerPlacementCircle(fractionToTiles(0.35));
g_Map.log("Creating playerbases");
var playerAngle = BUILDING_ORIENTATION;
const playerAngle = BUILDING_ORIENTATION;
for (let i = 0; i < numPlayers; ++i)
{
if (isNomad())
break;
// CC and units
for (let dist of [6, 8])
for (const dist of [6, 8])
{
let ents = getStartingEntities(playerIDs[i]);
@ -97,8 +97,8 @@ for (let i = 0; i < numPlayers; ++i)
0);
// Ground texture
var civ = getCivCode(playerIDs[i]);
var tilesSize = civ == "cart" ? 23 : 21;
const civ = getCivCode(playerIDs[i]);
const tilesSize = civ == "cart" ? 23 : 21;
createArea(
new ConvexPolygonPlacer(
new Array(4).fill(0).map((zero, j) => new Vector2D(tilesSize, 0).rotate(j * Math.PI / 2 - playerAngle - Math.PI/4).add(playerPosition[i])),
@ -109,7 +109,7 @@ for (let i = 0; i < numPlayers; ++i)
]);
// Fortress
var wall = ["gate", "tower", "long",
const wall = ["gate", "tower", "long",
"cornerIn", "long", "barracks", "tower", "long", "tower", "long",
"cornerIn", "long", "stable", "tower", "gate", "tower", "long",
"cornerIn", "long", "temple", "tower", "long", "tower", "long",
@ -119,8 +119,8 @@ for (let i = 0; i < numPlayers; ++i)
}
g_Map.log("Creating lakes");
var numLakes = Math.round(scaleByMapSize(1,4) * numPlayers);
var waterAreas = createAreas(
const numLakes = Math.round(scaleByMapSize(1,4) * numPlayers);
const waterAreas = createAreas(
new ClumpPlacer(scaleByMapSize(100,250), 0.8, 0.1, Infinity),
[
new LayeredPainter([tShore, tWater], [1]),
@ -162,15 +162,15 @@ createHills([tCliff, tCliff, tHill], avoidClasses(clPlayer, 5, clWater, 5, clHil
Engine.SetProgress(40);
g_Map.log("Creating forests");
var [forestTrees, stragglerTrees] = getTreeCounts(500, 2500, 0.7);
var types = [
const [forestTrees, stragglerTrees] = getTreeCounts(500, 2500, 0.7);
const types = [
[[tForestFloor, tGrass, pForestD], [tForestFloor, pForestD]],
[[tForestFloor, tGrass, pForestO], [tForestFloor, pForestO]],
[[tForestFloor, tGrass, pForestP], [tForestFloor, pForestP]]
];
var size = forestTrees / (scaleByMapSize(3,6) * numPlayers);
var num = Math.floor(size / types.length);
for (let type of types)
const size = forestTrees / (scaleByMapSize(3,6) * numPlayers);
const num = Math.floor(size / types.length);
for (const type of types)
createAreas(
new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), forestTrees / num, 0.5),
[

View File

@ -6,11 +6,11 @@ Engine.LoadLibrary("rmbiome");
setSelectedBiome();
// Random elevation with a bias towards lower elevations
var randElevation = randIntInclusive(0, 29);
let randElevation = randIntInclusive(0, 29);
if (randElevation < 25)
randElevation = randIntInclusive(1, 4);
var g_Map = new RandomMap(randElevation, g_Terrains.mainTerrain);
const g_Map = new RandomMap(randElevation, g_Terrains.mainTerrain);
initTileClasses();
createArea(
@ -22,7 +22,7 @@ Engine.SetProgress(20);
if (!isNomad())
{
// Note: `|| pickRandom(...)` is needed for atlas.
let pattern = g_MapSettings.TeamPlacement || pickRandom(["line", "radial", "randomGroup", "stronghold"]);
const pattern = g_MapSettings.TeamPlacement || pickRandom(["line", "radial", "randomGroup", "stronghold"]);
createBases(
...playerPlacementByPattern(
pattern,
@ -34,7 +34,7 @@ if (!isNomad())
}
Engine.SetProgress(40);
var features = [
let features = [
{
"func": addBluffs,
"baseHeight": randElevation,

View File

@ -43,39 +43,39 @@ const aBushSmall = g_Decoratives.bushSmall;
const pForest1 = [tForestFloor2 + TERRAIN_SEPARATOR + oTree1, tForestFloor2 + TERRAIN_SEPARATOR + oTree2, tForestFloor2];
const pForest2 = [tForestFloor1 + TERRAIN_SEPARATOR + oTree4, tForestFloor1 + TERRAIN_SEPARATOR + oTree5, tForestFloor1];
var heightSeaGround = -4;
var heightShallow = -2;
var heightLand = 3;
var heightRing = 4;
var heightHill = 20;
const heightSeaGround = -4;
const heightShallow = -2;
const heightLand = 3;
const heightRing = 4;
const heightHill = 20;
var g_Map = new RandomMap(heightLand, tMainTerrain);
const g_Map = new RandomMap(heightLand, tMainTerrain);
const numPlayers = getNumPlayers();
const mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
var clPlayer = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clWater = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clWater = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
var radiusPlayers = fractionToTiles(0.35);
var radiusCentralLake = fractionToTiles(0.27);
var radiusCentralRingLand = fractionToTiles(0.21);
var radiusCentralWaterRing = fractionToTiles(0.17);
var radiusCentralIsland = fractionToTiles(0.14);
var radiusCentralHill = fractionToTiles(0.12);
const radiusPlayers = fractionToTiles(0.35);
const radiusCentralLake = fractionToTiles(0.27);
const radiusCentralRingLand = fractionToTiles(0.21);
const radiusCentralWaterRing = fractionToTiles(0.17);
const radiusCentralIsland = fractionToTiles(0.14);
const radiusCentralHill = fractionToTiles(0.12);
var [playerIDs, playerPosition, playerAngle, startAngle] = playerPlacementCircle(radiusPlayers);
const [playerIDs, playerPosition, playerAngle, startAngle] = playerPlacementCircle(radiusPlayers);
g_Map.log("Determining number of rivers between players");
var split = 1;
let split = 1;
if (mapSize == 128 && numPlayers <= 2)
split = 2;
else if (mapSize == 192 && numPlayers <= 3)
@ -123,9 +123,9 @@ createArea(
g_Map.log("Creating rivers between players");
for (let m = 0; m < numPlayers * split; ++m)
{
let angle = startAngle + (m + 0.5) * 2 * Math.PI / (numPlayers * split);
let position1 = Vector2D.add(mapCenter, new Vector2D(fractionToTiles(0.15), 0).rotate(-angle));
let position2 = Vector2D.add(mapCenter, new Vector2D(fractionToTiles(0.6), 0).rotate(-angle));
const angle = startAngle + (m + 0.5) * 2 * Math.PI / (numPlayers * split);
const position1 = Vector2D.add(mapCenter, new Vector2D(fractionToTiles(0.15), 0).rotate(-angle));
const position2 = Vector2D.add(mapCenter, new Vector2D(fractionToTiles(0.6), 0).rotate(-angle));
createArea(
new PathPlacer(position1, position2, scaleByMapSize(14, 40), 0, scaleByMapSize(3, 9), 0.2, 0.05),
new SmoothElevationPainter(ELEVATION_SET, heightSeaGround, 4),
@ -135,9 +135,9 @@ for (let m = 0; m < numPlayers * split; ++m)
g_Map.log("Create path from the island to the center");
for (let m = 0; m < numPlayers * split; ++m)
{
let angle = startAngle + m * 2 * Math.PI / (numPlayers * split);
let position1 = Vector2D.add(mapCenter, new Vector2D(fractionToTiles(0.05), 0).rotate(-angle));
let position2 = Vector2D.add(mapCenter, new Vector2D(fractionToTiles(0.49), 0).rotate(-angle));
const angle = startAngle + m * 2 * Math.PI / (numPlayers * split);
const position1 = Vector2D.add(mapCenter, new Vector2D(fractionToTiles(0.05), 0).rotate(-angle));
const position2 = Vector2D.add(mapCenter, new Vector2D(fractionToTiles(0.49), 0).rotate(-angle));
createArea(
new PathPlacer(position1, position2, scaleByMapSize(10, 40), 0, scaleByMapSize(3, 9), 0.2, 0.05),
new SmoothElevationPainter(ELEVATION_SET, heightLand, 4));
@ -204,7 +204,7 @@ if (randBool())
else
createMountains(tCliff, avoidClasses(clPlayer, 20, clHill, 15, clWater, 2), clHill, scaleByMapSize(1, 4) * numPlayers);
var [forestTrees, stragglerTrees] = getTreeCounts(...rBiomeTreeCount(1));
const [forestTrees, stragglerTrees] = getTreeCounts(...rBiomeTreeCount(1));
createForests(
[tMainTerrain, tForestFloor1, tForestFloor2, pForest1, pForest2],
avoidClasses(clPlayer, 20, clForest, 17, clHill, 0, clWater, 2),
@ -259,7 +259,7 @@ createObjectGroupsDeprecated(
Engine.SetProgress(65);
var planetm = 1;
let planetm = 1;
if (currentBiome() == "generic/india")
planetm = 8;

View File

@ -36,32 +36,32 @@ const aBushSmall = "actor|props/flora/bush_medit_sm.xml";
const pForestP = [tForestFloorP + TERRAIN_SEPARATOR + oPoplar, tForestFloorP];
const pForestC = [tForestFloorC + TERRAIN_SEPARATOR + oCarob, tForestFloorC];
var heightSeaGround = -3;
var heightShallow = -1.5;
var heightShore = 2;
var heightLand = 3;
const heightSeaGround = -3;
const heightShallow = -1.5;
const heightShore = 2;
const heightLand = 3;
var g_Map = new RandomMap(heightSeaGround, tWater);
const g_Map = new RandomMap(heightSeaGround, tWater);
const numPlayers = getNumPlayers();
const mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
const mapBounds = g_Map.getBounds();
var clPlayer = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
var clLand = g_Map.createTileClass();
var clRiver = g_Map.createTileClass();
var clShallow = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
const clLand = g_Map.createTileClass();
const clRiver = g_Map.createTileClass();
const clShallow = g_Map.createTileClass();
g_Map.log("Create the continent body");
var startAngle = randomAngle();
var continentCenter = new Vector2D(fractionToTiles(0.5), fractionToTiles(0.7)).rotateAround(startAngle, mapCenter).round();
const startAngle = randomAngle();
const continentCenter = new Vector2D(fractionToTiles(0.5), fractionToTiles(0.7)).rotateAround(startAngle, mapCenter).round();
createArea(
new ChainPlacer(
@ -78,8 +78,8 @@ createArea(
new TileClassPainter(clLand)
]);
var playerIDs = sortAllPlayers();
var playerPosition = playerPlacementArcs(
const playerIDs = sortAllPlayers();
const playerPosition = playerPlacementArcs(
playerIDs,
continentCenter,
fractionToTiles(0.35),
@ -149,7 +149,7 @@ paintTerrainBasedOnHeight(-8, 1, 2, tWater);
createBumps([avoidClasses(clPlayer, 20, clRiver, 1), stayClasses(clLand, 3)]);
var [forestTrees, stragglerTrees] = getTreeCounts(500, 3000, 0.7);
const [forestTrees, stragglerTrees] = getTreeCounts(500, 3000, 0.7);
createForests(
[tGrass, tForestFloorP, tForestFloorC, pForestC, pForestP],
[avoidClasses(clPlayer, 20, clForest, 17, clRiver, 1), stayClasses(clLand, 7)],

View File

@ -62,24 +62,24 @@ const pForest2 = [
tForestFloor + TERRAIN_SEPARATOR + oTree4,
tForestFloor + TERRAIN_SEPARATOR + oTree5, tForestFloor];
var g_Map = new RandomMap(heightLand, tPrimary);
const g_Map = new RandomMap(heightLand, tPrimary);
const numPlayers = getNumPlayers();
const mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
var clPlayer = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clLake = g_Map.createTileClass();
var clWater = isLakeFrozen ? g_Map.createTileClass() : clLake;
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clLake = g_Map.createTileClass();
const clWater = isLakeFrozen ? g_Map.createTileClass() : clLake;
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
var startAngle = randomAngle();
const startAngle = randomAngle();
placePlayerBases({
"PlayerPlacement": [sortAllPlayers(), ...playerPlacementCustomAngle(
@ -114,15 +114,15 @@ placePlayerBases({
Engine.SetProgress(20);
g_Map.log("Creating the gulf");
var gulfLakePositions = [
const gulfLakePositions = [
{ "numCircles": 200, "x": fractionToTiles(0), "radius": fractionToTiles(0.175) },
{ "numCircles": 120, "x": fractionToTiles(0.3), "radius": fractionToTiles(0.2) },
{ "numCircles": 100, "x": fractionToTiles(0.5), "radius": fractionToTiles(0.225) }
];
for (let gulfLake of gulfLakePositions)
for (const gulfLake of gulfLakePositions)
{
let position = Vector2D.add(mapCenter, new Vector2D(gulfLake.x, 0).rotate(-startAngle)).round();
const position = Vector2D.add(mapCenter, new Vector2D(gulfLake.x, 0).rotate(-startAngle)).round();
createArea(
new ChainPlacer(
@ -185,7 +185,7 @@ if (randBool())
else
createMountains(tCliff, avoidClasses(clPlayer, 20, clHill, 15, clLake, 0), clHill, scaleByMapSize(1, 4) * numPlayers, Math.floor(scaleByMapSize(20, 40)));
var [forestTrees, stragglerTrees] = getTreeCounts(500, 3000, 0.7);
const [forestTrees, stragglerTrees] = getTreeCounts(500, 3000, 0.7);
createDefaultForests(
[tForestFloor, tForestFloor, tForestFloor, pForest1, pForest2],
avoidClasses(clPlayer, 20, clForest, 16, clHill, 0, clLake, 2),

View File

@ -5,11 +5,11 @@ Engine.LoadLibrary("rmbiome");
setSelectedBiome();
var heightSeaGround = -18;
var heightLand = 2;
var heightOffsetHarbor = -11;
const heightSeaGround = -18;
const heightLand = 2;
const heightOffsetHarbor = -11;
var g_Map = new RandomMap(heightLand, g_Terrains.mainTerrain);
const g_Map = new RandomMap(heightLand, g_Terrains.mainTerrain);
initTileClasses();
@ -325,9 +325,9 @@ function addCenterLake()
function addHarbors()
{
for (let position of playerPosition)
for (const position of playerPosition)
{
let harborPosition = Vector2D.add(position, Vector2D.sub(mapCenter, position).div(2.5).round());
const harborPosition = Vector2D.add(position, Vector2D.sub(mapCenter, position).div(2.5).round());
createArea(
new ClumpPlacer(1200, 0.5, 0.5, Infinity, harborPosition),
[
@ -345,12 +345,12 @@ function addHarbors()
function addSpines()
{
let smallSpines = mapSize <= 192;
let spineSize = smallSpines ? 0.02 : 0.5;
let spineTapering = smallSpines ?-0.1 : -1.4;
let heightOffsetSpine = smallSpines ? 20 : 35;
const smallSpines = mapSize <= 192;
const spineSize = smallSpines ? 0.02 : 0.5;
const spineTapering = smallSpines ?-0.1 : -1.4;
const heightOffsetSpine = smallSpines ? 20 : 35;
let numPlayers = getNumPlayers();
const numPlayers = getNumPlayers();
let spineTile = g_Terrains.dirt;
if (currentBiome() == "generic/arctic")
@ -368,9 +368,9 @@ function addSpines()
for (let i = 0; i < numPlayers * split; ++i)
{
let tang = startAngle + (i + 0.5) * 2 * Math.PI / (numPlayers * split);
let start = Vector2D.add(mapCenter, new Vector2D(fractionToTiles(0.12), 0).rotate(-tang));
let end = Vector2D.add(mapCenter, new Vector2D(fractionToTiles(0.4), 0).rotate(-tang));
const tang = startAngle + (i + 0.5) * 2 * Math.PI / (numPlayers * split);
const start = Vector2D.add(mapCenter, new Vector2D(fractionToTiles(0.12), 0).rotate(-tang));
const end = Vector2D.add(mapCenter, new Vector2D(fractionToTiles(0.4), 0).rotate(-tang));
createArea(
new PathPlacer(start, end, scaleByMapSize(14, spineSize), 0.6, 0.1, 0.4, spineTapering),

View File

@ -18,7 +18,7 @@
*/
function getMinAndMaxHeight(heightmap = g_Map.height)
{
let height = {
const height = {
"min": Infinity,
"max": -Infinity
};
@ -42,7 +42,7 @@ function getMinAndMaxHeight(heightmap = g_Map.height)
*/
function rescaleHeightmap(minHeight = MIN_HEIGHT, maxHeight = MAX_HEIGHT, heightmap = g_Map.height)
{
let oldHeightRange = getMinAndMaxHeight(heightmap);
const oldHeightRange = getMinAndMaxHeight(heightmap);
for (let x = 0; x < heightmap.length; ++x)
for (let y = 0; y < heightmap[x].length; ++y)
heightmap[x][y] = minHeight + (heightmap[x][y] - oldHeightRange.min) / (oldHeightRange.max - oldHeightRange.min) * (maxHeight - minHeight);
@ -62,7 +62,7 @@ function translateHeightmap(offset, defaultHeight = undefined, heightmap = g_Map
defaultHeight = getMinAndMaxHeight(heightmap).min;
offset.round();
let sourceHeightmap = clone(heightmap);
const sourceHeightmap = clone(heightmap);
for (let x = 0; x < heightmap.length; ++x)
for (let y = 0; y < heightmap[x].length; ++y)
heightmap[x][y] =
@ -86,16 +86,16 @@ function translateHeightmap(offset, defaultHeight = undefined, heightmap = g_Map
*/
function getStartLocationsByHeightmap(heightRange, maxTries = 1000, minDistToBorder = 20, numberOfPlayers = g_MapSettings.PlayerData.length - 1, heightmap = g_Map.height, isCircular = g_MapSettings.CircularMap)
{
let validStartLoc = [];
let mapCenter = g_Map.getCenter();
let mapSize = g_Map.getSize();
const validStartLoc = [];
const mapCenter = g_Map.getCenter();
const mapSize = g_Map.getSize();
let heightConstraint = new HeightConstraint(heightRange.min, heightRange.max);
const heightConstraint = new HeightConstraint(heightRange.min, heightRange.max);
for (let x = minDistToBorder; x < mapSize - minDistToBorder; ++x)
for (let y = minDistToBorder; y < mapSize - minDistToBorder; ++y)
{
let position = new Vector2D(x, y);
const position = new Vector2D(x, y);
if (heightConstraint.allows(position) && (!isCircular || position.distanceTo(mapCenter)) < mapSize / 2 - minDistToBorder)
validStartLoc.push(position);
}
@ -105,7 +105,7 @@ function getStartLocationsByHeightmap(heightRange, maxTries = 1000, minDistToBor
for (let tries = 0; tries < maxTries; ++tries)
{
let startLoc = [];
const startLoc = [];
let minDist = Infinity;
for (let p = 0; p < numberOfPlayers; ++p)
@ -114,7 +114,7 @@ function getStartLocationsByHeightmap(heightRange, maxTries = 1000, minDistToBor
for (let p1 = 0; p1 < numberOfPlayers - 1; ++p1)
for (let p2 = p1 + 1; p2 < numberOfPlayers; ++p2)
{
let dist = startLoc[p1].distanceTo(startLoc[p2]);
const dist = startLoc[p1].distanceTo(startLoc[p2]);
if (dist < minDist)
minDist = dist;
}
@ -146,7 +146,7 @@ function setBaseTerrainDiamondSquare(minHeight = MIN_HEIGHT, maxHeight = MAX_HEI
g_Map.log("Generating map using the diamond-square algorithm");
initialHeightmap = (initialHeightmap || [[randFloat(minHeight / 2, maxHeight / 2), randFloat(minHeight / 2, maxHeight / 2)], [randFloat(minHeight / 2, maxHeight / 2), randFloat(minHeight / 2, maxHeight / 2)]]);
let heightRange = maxHeight - minHeight;
const heightRange = maxHeight - minHeight;
if (heightRange <= 0)
warn("setBaseTerrainDiamondSquare: heightRange <= 0");
@ -157,7 +157,7 @@ function setBaseTerrainDiamondSquare(minHeight = MIN_HEIGHT, maxHeight = MAX_HEI
while (initialHeightmap.length < heightmap.length)
{
newHeightmap = [];
let oldWidth = initialHeightmap.length;
const oldWidth = initialHeightmap.length;
// Square
for (let x = 0; x < 2 * oldWidth - 1; ++x)
{
@ -215,7 +215,7 @@ function setBaseTerrainDiamondSquare(minHeight = MIN_HEIGHT, maxHeight = MAX_HEI
}
// Cut initialHeightmap to fit target width
let shift = [Math.floor((newHeightmap.length - heightmap.length) / 2), Math.floor((newHeightmap[0].length - heightmap[0].length) / 2)];
const shift = [Math.floor((newHeightmap.length - heightmap.length) / 2), Math.floor((newHeightmap[0].length - heightmap[0].length) / 2)];
for (let x = 0; x < heightmap.length; ++x)
for (let y = 0; y < heightmap[0].length; ++y)
heightmap[x][y] = newHeightmap[x + shift[0]][y + shift[1]];
@ -277,9 +277,9 @@ function getPointsByHeight(heightRange, avoidPoints = [], avoidClass = undefined
*/
function getTileCenteredHeightmap(heightmap = g_Map.height)
{
let max_x = heightmap.length - 1;
let max_y = heightmap[0].length - 1;
let tchm = [];
const max_x = heightmap.length - 1;
const max_y = heightmap[0].length - 1;
const tchm = [];
for (let x = 0; x < max_x; ++x)
{
tchm[x] = new Float32Array(max_y);
@ -297,11 +297,11 @@ function getTileCenteredHeightmap(heightmap = g_Map.height)
*/
function getSlopeMap(inclineMap = getInclineMap(g_Map.height))
{
let max_x = inclineMap.length;
let slopeMap = [];
const max_x = inclineMap.length;
const slopeMap = [];
for (let x = 0; x < max_x; ++x)
{
let max_y = inclineMap[x].length;
const max_y = inclineMap[x].length;
slopeMap[x] = new Float32Array(max_y);
for (let y = 0; y < max_y; ++y)
slopeMap[x][y] = Math.euclidDistance2D(0, 0, inclineMap[x][y].x, inclineMap[x][y].y);
@ -319,18 +319,18 @@ function getSlopeMap(inclineMap = getInclineMap(g_Map.height))
function getInclineMap(heightmap)
{
heightmap = (heightmap || g_Map.height);
let max_x = heightmap.length - 1;
let max_y = heightmap[0].length - 1;
let inclineMap = [];
const max_x = heightmap.length - 1;
const max_y = heightmap[0].length - 1;
const inclineMap = [];
for (let x = 0; x < max_x; ++x)
{
inclineMap[x] = [];
for (let y = 0; y < max_y; ++y)
{
let dx = heightmap[x + 1][y] - heightmap[x][y];
let dy = heightmap[x][y + 1] - heightmap[x][y];
let next_dx = heightmap[x + 1][y + 1] - heightmap[x][y + 1];
let next_dy = heightmap[x + 1][y + 1] - heightmap[x + 1][y];
const dx = heightmap[x + 1][y] - heightmap[x][y];
const dy = heightmap[x][y + 1] - heightmap[x][y];
const next_dx = heightmap[x + 1][y + 1] - heightmap[x][y + 1];
const next_dy = heightmap[x + 1][y + 1] - heightmap[x + 1][y];
inclineMap[x][y] = { "x": 0.5 * (dx + next_dx), "y": 0.5 * (dy + next_dy) };
}
}
@ -339,7 +339,7 @@ function getInclineMap(heightmap)
function getGrad(wrapped = true, scalarField = g_Map.height)
{
let vectorField = [];
const vectorField = [];
let max_x = scalarField.length;
let max_y = scalarField[0].length;
if (!wrapped)
@ -365,28 +365,28 @@ function getGrad(wrapped = true, scalarField = g_Map.height)
function splashErodeMap(strength = 1, heightmap = g_Map.height)
{
let max_x = heightmap.length;
let max_y = heightmap[0].length;
const max_x = heightmap.length;
const max_y = heightmap[0].length;
let dHeight = getGrad(heightmap);
const dHeight = getGrad(heightmap);
for (let x = 0; x < max_x; ++x)
{
let next_x = (x + 1) % max_x;
let prev_x = (x + max_x - 1) % max_x;
const next_x = (x + 1) % max_x;
const prev_x = (x + max_x - 1) % max_x;
for (let y = 0; y < max_y; ++y)
{
let next_y = (y + 1) % max_y;
let prev_y = (y + max_y - 1) % max_y;
const next_y = (y + 1) % max_y;
const prev_y = (y + max_y - 1) % max_y;
let slopes = [-dHeight[x][y].x, -dHeight[x][y].y, dHeight[prev_x][y].x, dHeight[x][prev_y].y];
const slopes = [-dHeight[x][y].x, -dHeight[x][y].y, dHeight[prev_x][y].x, dHeight[x][prev_y].y];
let sumSlopes = 0;
for (let i = 0; i < slopes.length; ++i)
if (slopes[i] > 0)
sumSlopes += slopes[i];
let drain = [];
const drain = [];
for (let i = 0; i < slopes.length; ++i)
{
drain.push(0);

View File

@ -20,7 +20,7 @@ Engine.LoadLibrary("rmgen-common");
TILE_CENTERED_HEIGHT_MAP = true;
var mapStyles = [
const mapStyles = [
// mainland
{
"minMapSize": 0,
@ -56,47 +56,47 @@ const heightHighlands = heightScale(60);
const heightmapMin = 0;
const heightmapMax = 100;
var g_Map = new RandomMap(0, biomes.lowlands.terrains.main);
var mapSize = g_Map.getSize();
var mapCenter = g_Map.getCenter();
var numPlayers = getNumPlayers();
const g_Map = new RandomMap(0, biomes.lowlands.terrains.main);
const mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
const numPlayers = getNumPlayers();
var clWater;
var clCliffs;
var clPlayer = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
var clDock = g_Map.createTileClass();
let clWater = g_Map.createTileClass();
let clCliffs = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
const clDock = g_Map.createTileClass();
var constraintLowlands = new HeightConstraint(heightShoreline, heightLowlands);
var constraintHighlands = new HeightConstraint(heightLowlands, heightHighlands);
var constraintMountains = new HeightConstraint(heightHighlands, Infinity);
const constraintLowlands = new HeightConstraint(heightShoreline, heightLowlands);
const constraintHighlands = new HeightConstraint(heightLowlands, heightHighlands);
const constraintMountains = new HeightConstraint(heightHighlands, Infinity);
var [minLandRatio, maxLandRatio] = mapStyles.filter(mapStyle => mapSize >= mapStyle.minMapSize).sort((a, b) => a.enabled - b.enabled).pop().landRatio;
var [minCliffRatio, maxCliffRatio] = [maxLandRatio < 0.75 ? 0 : 0.08, 0.18];
const [minLandRatio, maxLandRatio] = mapStyles.filter(mapStyle => mapSize >= mapStyle.minMapSize).sort((a, b) => a.enabled - b.enabled).pop().landRatio;
const [minCliffRatio, maxCliffRatio] = [maxLandRatio < 0.75 ? 0 : 0.08, 0.18];
var playerIDs = sortAllPlayers();
var playerPosition;
let playerIDs = sortAllPlayers();
let playerPosition;
// Pick a random subset of the heightmap that meets the mapStyle and has space for all players
var subAreaSize;
var subAreaTopLeft;
let subAreaSize;
let subAreaTopLeft;
while (true)
{
subAreaSize = Math.floor(randFloat(0.01, 0.2) * heightmapHellas.length);
subAreaTopLeft = new Vector2D(randFloat(0, 1), randFloat(0, 1)).mult(heightmapHellas.length - subAreaSize).floor();
let heightmap = extractHeightmap(heightmapHellas, subAreaTopLeft, subAreaSize);
let heightmapPainter = new HeightmapPainter(heightmap, heightmapMin, heightmapMax);
const heightmap = extractHeightmap(heightmapHellas, subAreaTopLeft, subAreaSize);
const heightmapPainter = new HeightmapPainter(heightmap, heightmapMin, heightmapMax);
// Quick area test
let points = new DiskPlacer(heightmap.length / 2 - MAP_BORDER_WIDTH, new Vector2D(1, 1).mult(heightmap.length / 2)).place(new NullConstraint());
const points = new DiskPlacer(heightmap.length / 2 - MAP_BORDER_WIDTH, new Vector2D(1, 1).mult(heightmap.length / 2)).place(new NullConstraint());
let landArea = 0;
for (let point of points)
for (const point of points)
if (heightmapPainter.scaleHeight(heightmap[point.x][point.y]) > heightShoreline)
++landArea;
@ -111,7 +111,7 @@ while (true)
heightmapPainter);
g_Map.log("Measuring land area");
let passableLandArea = createArea(
const passableLandArea = createArea(
new DiskPlacer(fractionToTiles(0.5), mapCenter),
undefined,
new HeightConstraint(heightShoreline, Infinity));
@ -145,7 +145,7 @@ while (true)
clCliffs = g_Map.createTileClass();
// Marking cliffs
let cliffsArea = createArea(
const cliffsArea = createArea(
new MapBoundsPlacer(),
new TileClassPainter(clCliffs),
[
@ -169,7 +169,7 @@ while (true)
break;
g_Map.log("Finding player locations");
let players = playerPlacementRandom(
const players = playerPlacementRandom(
playerIDs,
avoidClasses(
clCliffs, scaleByMapSize(6, 15),
@ -188,8 +188,8 @@ Engine.SetProgress(35);
if (!isNomad())
{
g_Map.log("Flattening initial CC area");
let playerRadius = defaultPlayerBaseRadius() * 0.8;
for (let position of playerPosition)
const playerRadius = defaultPlayerBaseRadius() * 0.8;
for (const position of playerPosition)
createArea(
new ClumpPlacer(diskArea(playerRadius), 0.95, 0.6, Infinity, position),
new SmoothElevationPainter(ELEVATION_SET, g_Map.getHeight(position), playerRadius / 2));
@ -242,7 +242,7 @@ for (let i = 0; i < numPlayers; ++i)
if (isNomad())
break;
let localBiome = constraintHighlands.allows(playerPosition[i]) ? biomes.highlands : biomes.lowlands;
const localBiome = constraintHighlands.allows(playerPosition[i]) ? biomes.highlands : biomes.lowlands;
placePlayerBase({
"playerID": playerIDs[i],
"playerPosition": playerPosition[i],
@ -296,9 +296,9 @@ placeDocks(
50);
Engine.SetProgress(65);
let [forestTrees, stragglerTrees] = getTreeCounts(600, 4000, 0.7);
let biomeTreeRatioHighlands = 0.4;
for (let biome of ["lowlands", "highlands"])
const [forestTrees, stragglerTrees] = getTreeCounts(600, 4000, 0.7);
const biomeTreeRatioHighlands = 0.4;
for (const biome of ["lowlands", "highlands"])
createForests(
[
biomes[biome].terrains.main,
@ -316,11 +316,11 @@ for (let biome of ["lowlands", "highlands"])
Engine.SetProgress(70);
g_Map.log("Creating stone mines");
var minesStone = [
const minesStone = [
[new SimpleObject(biomes.common.gaia.mines.stoneLarge, 1, 1, 0, 4, 0, 2 * Math.PI, 4)],
[new SimpleObject(biomes.common.gaia.mines.stoneSmall, 2, 3, 1, 3, 0, 2 * Math.PI, 1)]
];
for (let mine of minesStone)
for (const mine of minesStone)
createObjectGroups(
new SimpleGroup(mine, true, clRock),
0,
@ -330,11 +330,11 @@ for (let mine of minesStone)
Engine.SetProgress(75);
g_Map.log("Creating metal mines");
var minesMetal = [
const minesMetal = [
[new SimpleObject(biomes.common.gaia.mines.metalLarge, 1, 1, 0, 4, 0, 2 * Math.PI, 4)],
[new SimpleObject(biomes.common.gaia.mines.metalSmall, 2, 3, 1, 3, 0, 2 * Math.PI, 1)]
];
for (let mine of minesMetal)
for (const mine of minesMetal)
createObjectGroups(
new SimpleGroup(mine, true, clMetal),
0,
@ -343,7 +343,7 @@ for (let mine of minesMetal)
50);
Engine.SetProgress(80);
for (let biome of ["lowlands", "highlands"])
for (const biome of ["lowlands", "highlands"])
createStragglerTrees(
biomes[biome].gaia.flora.trees,
[
@ -417,8 +417,8 @@ createObjectGroups(
Engine.SetProgress(95);
g_Map.log("Creating grass patches");
for (let biome of ["lowlands", "highlands"])
for (let patch of biomes[biome].terrains.patches)
for (const biome of ["lowlands", "highlands"])
for (const patch of biomes[biome].terrains.patches)
createPatches(
[scaleByMapSize(3, 7), scaleByMapSize(5, 15)],
patch,
@ -430,7 +430,7 @@ for (let biome of ["lowlands", "highlands"])
clDirt);
Engine.SetProgress(96);
for (let biome of ["lowlands", "highlands"])
for (const biome of ["lowlands", "highlands"])
{
createDecoration(
[

View File

@ -8,7 +8,7 @@ setSelectedBiome();
const heightLand = 1;
const heightBarrier = 30;
var g_Map = new RandomMap(heightLand, g_Terrains.mainTerrain);
const g_Map = new RandomMap(heightLand, g_Terrains.mainTerrain);
initTileClasses();
@ -256,7 +256,7 @@ g_Map.ExportMap();
function placeBarriers()
{
var spineTerrain = g_Terrains.dirt;
let spineTerrain = g_Terrains.dirt;
if (currentBiome() == "generic/arctic")
spineTerrain = g_Terrains.tier1Terrain;
@ -267,14 +267,14 @@ function placeBarriers()
if (currentBiome() == "generic/autumn")
spineTerrain = g_Terrains.tier4Terrain;
let spineCount = isNomad() ? randIntInclusive(1, 4) : teamsArray.length;
const spineCount = isNomad() ? randIntInclusive(1, 4) : teamsArray.length;
for (let i = 0; i < spineCount; ++i)
{
var mSize = 8;
var mWaviness = 0.6;
var mOffset = 0.5;
var mTaper = -1.5;
let mSize = 8;
let mWaviness = 0.6;
let mOffset = 0.5;
let mTaper = -1.5;
if (spineCount > 3 || g_Map.getSize() <= 192)
{
@ -291,9 +291,9 @@ function placeBarriers()
mTaper = -0.7;
}
let angle = startAngle + (i + 0.5) * 2 * Math.PI / spineCount;
let start = Vector2D.add(mapCenter, new Vector2D(fractionToTiles(0.075), 0).rotate(-angle));
let end = Vector2D.add(mapCenter, new Vector2D(fractionToTiles(0.42), 0).rotate(-angle));
const angle = startAngle + (i + 0.5) * 2 * Math.PI / spineCount;
const start = Vector2D.add(mapCenter, new Vector2D(fractionToTiles(0.075), 0).rotate(-angle));
const end = Vector2D.add(mapCenter, new Vector2D(fractionToTiles(0.42), 0).rotate(-angle));
createArea(
new PathPlacer(start, end, scaleByMapSize(14, mSize), mWaviness, 0.1, mOffset, mTaper),
[

View File

@ -49,27 +49,27 @@ const heightLand = 1;
const heightOffsetBump = 4;
const heightHill = 15;
var g_Map = new RandomMap(heightLand, tPrimary);
const g_Map = new RandomMap(heightLand, tPrimary);
const mapCenter = g_Map.getCenter();
const mapBounds = g_Map.getBounds();
const numPlayers = getNumPlayers();
var clPlayer = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clWater = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
var clHighlands = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clWater = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
const clHighlands = g_Map.createTileClass();
var waterPosition = fractionToTiles(0.25);
var highlandsPosition = fractionToTiles(0.75);
const waterPosition = fractionToTiles(0.25);
const highlandsPosition = fractionToTiles(0.75);
var startAngle = randomAngle();
const startAngle = randomAngle();
placePlayerBases({
"PlayerPlacement": [sortAllPlayers(), playerPlacementLine(startAngle, mapCenter, fractionToTiles(0.2))],
@ -169,7 +169,7 @@ g_Map.log("Creating mainland forests");
const [forestTrees, stragglerTrees] = getTreeCounts(1000, 3500, 0.85);
const highlandShare = 0.4;
{
var types = [
const types = [
[[tGrassDForest, tGrass, pForestD], [tGrassDForest, pForestD]]
];
const numberOfForests = scaleByMapSize(20, 100) / types[0].length;
@ -187,7 +187,7 @@ const highlandShare = 0.4;
g_Map.log("Creating highland forests");
{
var types = [
const types = [
[[tGrassDForest, tGrass, pForestP], [tGrassDForest, pForestP]]
];
const numberOfForests = scaleByMapSize(8, 50) / types[0].length;
@ -209,7 +209,7 @@ g_Map.log("Creating highland forests");
Engine.SetProgress(70);
g_Map.log("Creating dirt patches");
for (let size of [scaleByMapSize(3, 48), scaleByMapSize(5, 84), scaleByMapSize(8, 128)])
for (const size of [scaleByMapSize(3, 48), scaleByMapSize(5, 84), scaleByMapSize(8, 128)])
createAreas(
new ClumpPlacer(size, 0.3, 0.06, 0.5),
[
@ -221,7 +221,7 @@ for (let size of [scaleByMapSize(3, 48), scaleByMapSize(5, 84), scaleByMapSize(8
Engine.SetProgress(75);
g_Map.log("Creating grass patches");
for (let size of [scaleByMapSize(2, 32), scaleByMapSize(3, 48), scaleByMapSize(5, 80)])
for (const size of [scaleByMapSize(2, 32), scaleByMapSize(3, 48), scaleByMapSize(5, 80)])
createAreas(
new ClumpPlacer(size, 0.3, 0.06, 0.5),
new LayeredPainter([tGrassC, tGrassPatch], [2]),
@ -231,7 +231,7 @@ for (let size of [scaleByMapSize(2, 32), scaleByMapSize(3, 48), scaleByMapSize(5
Engine.SetProgress(80);
g_Map.log("Creating stone mines");
var group = new SimpleGroup([new SimpleObject(oStoneSmall, 0, 2, 0, 4, 0, 2 * Math.PI, 1), new SimpleObject(oStoneLarge, 1, 1, 0, 4, 0, 2 * Math.PI, 4)], true, clRock);
let group = new SimpleGroup([new SimpleObject(oStoneSmall, 0, 2, 0, 4, 0, 2 * Math.PI, 1), new SimpleObject(oStoneLarge, 1, 1, 0, 4, 0, 2 * Math.PI, 4)], true, clRock);
createObjectGroupsDeprecated(group, 0,
[avoidClasses(clWater, 0, clForest, 1, clPlayer, 20, clRock, 10, clHill, 2)],
scaleByMapSize(4,16), 100

View File

@ -28,19 +28,19 @@ const heightLand = 1;
const heightShore = 3;
const heightOffsetBump = 2;
var g_Map = new RandomMap(heightLand, tGrass1);
const g_Map = new RandomMap(heightLand, tGrass1);
var numPlayers = getNumPlayers();
var mapSize = g_Map.getSize();
var mapCenter = g_Map.getCenter();
const numPlayers = getNumPlayers();
const mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
var clPlayer = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clWater = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clWater = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
placePlayerBases({
"PlayerPlacement": playerPlacementCircle(fractionToTiles(0.35)),
@ -120,7 +120,7 @@ Engine.SetProgress(55);
g_Map.log("Creating stone mines");
for (let i = 0; i < scaleByMapSize(12, 30); ++i)
{
let position = new Vector2D(randIntInclusive(1, mapSize - 1), randIntInclusive(1, mapSize - 1));
const position = new Vector2D(randIntInclusive(1, mapSize - 1), randIntInclusive(1, mapSize - 1));
if (avoidClasses(clPlayer, 30, clRock, 25, clWater, 10).allows(position))
{
createStoneMineFormation(position, oStoneSmall, tDirt4);

View File

@ -49,7 +49,7 @@ const heightSeaGround = -10;
const heightLand = 3;
const heightHill = 18;
var g_Map = new RandomMap(heightSeaGround, tWater);
const g_Map = new RandomMap(heightSeaGround, tWater);
const numPlayers = getNumPlayers();
const mapSize = g_Map.getSize();
@ -65,14 +65,14 @@ const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
const clLand = g_Map.createTileClass();
var startAngle = randomAngle();
const startAngle = randomAngle();
var teams = getTeamsArray();
var numTeams = teams.filter(team => team).length;
var teamPosition = distributePointsOnCircle(numTeams, startAngle, fractionToTiles(0.3), mapCenter)[0];
var teamRadius = fractionToTiles(0.05);
const teams = getTeamsArray();
const numTeams = teams.filter(team => team).length;
const teamPosition = distributePointsOnCircle(numTeams, startAngle, fractionToTiles(0.3), mapCenter)[0];
const teamRadius = fractionToTiles(0.05);
var teamNo = 0;
let teamNo = 0;
g_Map.log("Creating player islands and bases");
@ -83,7 +83,7 @@ for (let i = 0; i < teams.length; ++i)
++teamNo;
let [playerPosition, playerAngle] = distributePointsOnCircle(teams[i].length, startAngle + 2 * Math.PI / teams[i].length, teamRadius, teamPosition[i]);
const [playerPosition, playerAngle] = distributePointsOnCircle(teams[i].length, startAngle + 2 * Math.PI / teams[i].length, teamRadius, teamPosition[i]);
playerPosition.forEach(position => position.round());
for (let p = 0; p < teams[i].length; ++p)
@ -101,17 +101,17 @@ for (let i = 0; i < teams.length; ++i)
placeCivDefaultStartingEntities(playerPosition[p], teams[i][p], false);
}
let mineAngle = randFloat(-1, 1) * Math.PI / teams[i].length;
let mines = [
const mineAngle = randFloat(-1, 1) * Math.PI / teams[i].length;
const mines = [
{ "template": oMetalLarge, "angle": mineAngle },
{ "template": oStoneLarge, "angle": mineAngle + Math.PI / 4 }
];
// Mines
for (let p = 0; p < teams[i].length; ++p)
for (let mine of mines)
for (const mine of mines)
{
let position = Vector2D.add(playerPosition[p], new Vector2D(g_InitialMineDistance, 0).rotate(-playerAngle[p] - mine.angle));
const position = Vector2D.add(playerPosition[p], new Vector2D(g_InitialMineDistance, 0).rotate(-playerAngle[p] - mine.angle));
createObjectGroup(
new SimpleGroup([new SimpleObject(mine.template, 1, 1, 0, 4)], true, clBaseResource, position),
0,
@ -121,11 +121,11 @@ for (let i = 0; i < teams.length; ++i)
// Trees
for (let p = 0; p < teams[i].length; ++p)
{
let tries = 10;
const tries = 10;
for (let x = 0; x < tries; ++x)
{
let tAngle = playerAngle[p] + randFloat(-1, 1) * 2 * Math.PI / teams[i].length;
let treePosition = Vector2D.add(playerPosition[p], new Vector2D(16, 0).rotate(-tAngle)).round();
const tAngle = playerAngle[p] + randFloat(-1, 1) * 2 * Math.PI / teams[i].length;
const treePosition = Vector2D.add(playerPosition[p], new Vector2D(16, 0).rotate(-tAngle)).round();
if (createObjectGroup(
new SimpleGroup([new SimpleObject(oTree2, g_InitialTrees, g_InitialTrees, 0, 7)], true, clBaseResource, treePosition),
0,
@ -229,7 +229,7 @@ createMines(
[avoidClasses(clForest, 1, clPlayer, 40, clMetal, 20), stayClasses(clLand, 4)],
clRock);
var [forestTrees, stragglerTrees] = getTreeCounts(...rBiomeTreeCount(1));
const [forestTrees, stragglerTrees] = getTreeCounts(...rBiomeTreeCount(1));
createForests(
[tMainTerrain, tForestFloor1, tForestFloor2, pForest1, pForest2],
[avoidClasses(clPlayer, 10, clForest, 20, clBaseResource, 5, clRock, 6, clMetal, 6), stayClasses(clLand, 3)],
@ -282,7 +282,7 @@ createFood(
if (currentBiome() == "generic/sahara")
{
g_Map.log("Creating obelisks");
let group = new SimpleGroup(
const group = new SimpleGroup(
[new SimpleObject(oObelisk, 1, 1, 0, 1)],
true
);
@ -294,8 +294,8 @@ if (currentBiome() == "generic/sahara")
}
g_Map.log("Creating dirt patches");
let numb = currentBiome() == "generic/savanna" ? 3 : 1;
for (let size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)])
const numb = currentBiome() == "generic/savanna" ? 3 : 1;
for (const size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)])
createAreas(
new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), size, 0.5),
[
@ -306,7 +306,7 @@ for (let size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8,
numb*scaleByMapSize(15, 45));
g_Map.log("Creating grass patches");
for (let size of [scaleByMapSize(2, 4), scaleByMapSize(3, 7), scaleByMapSize(5, 15)])
for (const size of [scaleByMapSize(2, 4), scaleByMapSize(3, 7), scaleByMapSize(5, 15)])
createAreas(
new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), size, 0.5),
new TerrainPainter(tTier4Terrain),
@ -376,7 +376,7 @@ createObjectGroupsDeprecated(group, 0,
);
g_Map.log("Creating small grass tufts");
let planetm = currentBiome() == "generic/india" ? 8 : 1;
const planetm = currentBiome() == "generic/india" ? 8 : 1;
group = new SimpleGroup(
[new SimpleObject(aGrassShort, 1, 2, 0, 1, -Math.PI / 8, Math.PI / 8)]
);

View File

@ -50,25 +50,25 @@ const heightLand = 3;
const heightOffsetBump = 2;
const heightHill = 18;
var g_Map = new RandomMap(heightSeaGround, tWater);
const g_Map = new RandomMap(heightSeaGround, tWater);
const numPlayers = getNumPlayers();
const mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
var clPlayer = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
var clLand = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
const clLand = g_Map.createTileClass();
var playerIslandRadius = scaleByMapSize(20, 29);
const playerIslandRadius = scaleByMapSize(20, 29);
var [playerIDs, playerPosition, playerAngle] = playerPlacementCircle(fractionToTiles(0.35));
const [playerIDs, playerPosition, playerAngle] = playerPlacementCircle(fractionToTiles(0.35));
if (!isNomad())
{
@ -84,7 +84,7 @@ if (!isNomad())
new TileClassPainter(clPlayer)
]);
let dockLocation = findLocationInDirectionBasedOnHeight(playerPosition[i], mapCenter, -3 , heightLand - 0.5, heightLand);
const dockLocation = findLocationInDirectionBasedOnHeight(playerPosition[i], mapCenter, -3 , heightLand - 0.5, heightLand);
g_Map.placeEntityPassable(oDock, playerIDs[i], dockLocation, playerAngle[i] + Math.PI);
}
}
@ -179,17 +179,17 @@ createAreas(
scaleByMapSize(4, 13));
g_Map.log("Creating forests");
var [forestTrees, stragglerTrees] = getTreeCounts(...rBiomeTreeCount(1));
var types = [
const [forestTrees, stragglerTrees] = getTreeCounts(...rBiomeTreeCount(1));
const types = [
[[tForestFloor2, tMainTerrain, pForest1], [tForestFloor2, pForest1]],
[[tForestFloor1, tMainTerrain, pForest2], [tForestFloor1, pForest2]]
];
if (currentBiome() != "generic/savanna")
{
var size = forestTrees / (scaleByMapSize(3,6) * numPlayers);
var num = Math.floor(size / types.length);
for (let type of types)
const size = forestTrees / (scaleByMapSize(3,6) * numPlayers);
const num = Math.floor(size / types.length);
for (const type of types)
createAreas(
new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), forestTrees / (num * Math.floor(scaleByMapSize(2, 5))), 0.5),
[
@ -202,8 +202,8 @@ if (currentBiome() != "generic/savanna")
Engine.SetProgress(50);
g_Map.log("Creating dirt patches");
var numberOfPatches = scaleByMapSize(15, 45) * (currentBiome() == "generic/savanna" ? 3 : 1);
for (let size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)])
const numberOfPatches = scaleByMapSize(15, 45) * (currentBiome() == "generic/savanna" ? 3 : 1);
for (const size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)])
createAreas(
new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), size, 0.5),
[
@ -214,7 +214,7 @@ for (let size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8,
numberOfPatches);
g_Map.log("Creating grass patches");
for (let size of [scaleByMapSize(2, 4), scaleByMapSize(3, 7), scaleByMapSize(5, 15)])
for (const size of [scaleByMapSize(2, 4), scaleByMapSize(3, 7), scaleByMapSize(5, 15)])
createAreas(
new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), size, 0.5),
new TerrainPainter(tTier4Terrain),
@ -224,7 +224,7 @@ for (let size of [scaleByMapSize(2, 4), scaleByMapSize(3, 7), scaleByMapSize(5,
Engine.SetProgress(55);
g_Map.log("Creating stone mines");
var group = new SimpleGroup([new SimpleObject(oStoneSmall, 0, 2, 0, 4, 0, 2 * Math.PI, 1), new SimpleObject(oStoneLarge, 1, 1, 0, 4, 0, 2 * Math.PI, 4)], true, clRock);
let group = new SimpleGroup([new SimpleObject(oStoneSmall, 0, 2, 0, 4, 0, 2 * Math.PI, 1), new SimpleObject(oStoneLarge, 1, 1, 0, 4, 0, 2 * Math.PI, 4)], true, clRock);
createObjectGroupsDeprecated(group, 0,
[avoidClasses(clForest, 1, clPlayer, 0, clRock, 10, clHill, 1), stayClasses(clLand, 5)],
scaleByMapSize(4,16), 100
@ -320,7 +320,7 @@ createStragglerTrees(
clForest,
stragglerTrees);
var planetm = 1;
let planetm = 1;
if (currentBiome() == "generic/india")
planetm = 8;

View File

@ -217,7 +217,7 @@ const layoutFertileLandTextures = [
}
];
var layoutKushTemples = [
const layoutKushTemples = [
...new Array(2).fill(0).map((v, i) =>
({
"template": oTempleApedemak,
@ -370,7 +370,7 @@ createArea(
new HeightConstraint(-Infinity, heightDesert));
// Fertile land
var widthFertileLand = fractionToTiles(0.33);
const widthFertileLand = fractionToTiles(0.33);
paintRiver({
"parallel": true,
"start": new Vector2D(mapBounds.left, mapBounds.bottom).rotateAround(-riverAngle, mapCenter),
@ -388,7 +388,7 @@ paintRiver({
},
"landFunc": (position, shoreDist1, shoreDist2) => {
for (let riv of layoutFertileLandTextures)
for (const riv of layoutFertileLandTextures)
if (riv.left < +shoreDist1 && +shoreDist1 < riv.right ||
riv.left < -shoreDist2 && -shoreDist2 < riv.right)
{
@ -426,7 +426,7 @@ const playerPosition = playerPlacementArcs(
if (!isNomad())
{
g_Map.log("Marking player positions");
for (let position of playerPosition)
for (const position of playerPosition)
addCivicCenterAreaToClass(position, clPlayer);
}
@ -454,10 +454,10 @@ const stayDesert = new StaticConstraint(stayClasses(clDesert, 0));
const stayFertileLand = new StaticConstraint(stayClasses(clFertileLand, 0));
g_Map.log("Finding possible irrigation canal locations");
var irrigationCanalAreas = [];
let irrigationCanalAreas = [];
for (let i = 0; i < 30; ++i)
{
let x = fractionToTiles(randFloat(0, 1));
const x = fractionToTiles(randFloat(0, 1));
irrigationCanalAreas.push(
createArea(
new PathPlacer(
@ -474,8 +474,8 @@ for (let i = 0; i < 30; ++i)
}
g_Map.log("Creating irrigation canals");
var irrigationCanalLocations = [];
for (let area of irrigationCanalAreas)
let irrigationCanalLocations = [];
for (const area of irrigationCanalAreas)
{
if (!area.getPoints().length ||
area.getPoints().some(point => !avoidClasses(clPlayer, scaleByMapSize(8, 13), clIrrigationCanal, scaleByMapSize(15, 25)).allows(point)))
@ -492,16 +492,16 @@ for (let area of irrigationCanalAreas)
}
g_Map.log("Creating passages");
var previousPassageY = randIntInclusive(0, widthFertileLand);
var areasPassages = [];
let previousPassageY = randIntInclusive(0, widthFertileLand);
let areasPassages = [];
irrigationCanalLocations.sort((a, b) => a - b);
for (let i = 0; i < irrigationCanalLocations.length; ++i)
{
let previous = i == 0 ? mapBounds.left : irrigationCanalLocations[i - 1];
let next = i == irrigationCanalLocations.length - 1 ? mapBounds.right : irrigationCanalLocations[i + 1];
const previous = i == 0 ? mapBounds.left : irrigationCanalLocations[i - 1];
const next = i == irrigationCanalLocations.length - 1 ? mapBounds.right : irrigationCanalLocations[i + 1];
let x1 = (irrigationCanalLocations[i] + previous) / 2;
let x2 = (irrigationCanalLocations[i] + next) / 2;
const x1 = (irrigationCanalLocations[i] + previous) / 2;
const x2 = (irrigationCanalLocations[i] + next) / 2;
let y;
// The passages should be at different locations, so that enemies can't attack each other easily
@ -509,7 +509,7 @@ for (let i = 0; i < irrigationCanalLocations.length; ++i)
{
y = (previousPassageY + randIntInclusive(0.2 * widthFertileLand, 0.8 * widthFertileLand)) % widthFertileLand;
let pos = new Vector2D((x1 + x2) / 2, y).rotateAround(-riverAngle, mapCenter).round();
const pos = new Vector2D((x1 + x2) / 2, y).rotateAround(-riverAngle, mapCenter).round();
if (g_Map.validTilePassable(new Vector2D(pos.x, pos.y)) &&
avoidClasses(clDesert, 12).allows(pos) &&
@ -517,7 +517,7 @@ for (let i = 0; i < irrigationCanalLocations.length; ++i)
break;
}
let area =
const area =
createArea(
new PathPlacer(
new Vector2D(x1, y).rotateAround(-riverAngle, mapCenter),
@ -582,7 +582,7 @@ Engine.SetProgress(50);
for (let i = 0; i < numPlayers; ++i)
{
let isDesert = clDesert.has(playerPosition[i]);
const isDesert = clDesert.has(playerPosition[i]);
placePlayerBase({
"playerID": playerIDs[i],
"playerPosition": playerPosition[i],
@ -664,26 +664,26 @@ Engine.SetProgress(60);
// The city is a circle segment of this maximum size
g_Map.log("Computing city grid");
var gridCenter = new Vector2D(0, fractionToTiles(0.3)).rotate(-riverAngle).add(mapCenter).round();
var gridMaxAngle = Math.min(scaleByMapSize(1/3, 1), 2/3) * Math.PI;
var gridStartAngle = -Math.PI / 2 -gridMaxAngle / 2 + riverAngle;
var gridRadius = y => hillRadius + 18 * y;
const gridCenter = new Vector2D(0, fractionToTiles(0.3)).rotate(-riverAngle).add(mapCenter).round();
const gridMaxAngle = Math.min(scaleByMapSize(1/3, 1), 2/3) * Math.PI;
const gridStartAngle = -Math.PI / 2 -gridMaxAngle / 2 + riverAngle;
const gridRadius = y => hillRadius + 18 * y;
var gridPointsX = layoutKushTemples.length;
var gridPointsY = Math.floor(scaleByMapSize(2, 5));
var gridPointXCenter = Math.floor(gridPointsX / 2);
var gridPointYCenter = Math.floor(gridPointsY / 2);
const gridPointsX = layoutKushTemples.length;
const gridPointsY = Math.floor(scaleByMapSize(2, 5));
const gridPointXCenter = Math.floor(gridPointsX / 2);
const gridPointYCenter = Math.floor(gridPointsY / 2);
// Maps from grid position to map position
var cityGridPosition = [];
var cityGridAngle = [];
let cityGridPosition = [];
let cityGridAngle = [];
for (let y = 0; y < gridPointsY; ++y)
[cityGridPosition[y], cityGridAngle[y]] = distributePointsOnCircularSegment(
gridPointsX, gridMaxAngle, gridStartAngle, gridRadius(y), gridCenter);
g_Map.log("Marking city path crossings");
for (let y in cityGridPosition)
for (let x in cityGridPosition[y])
for (const y in cityGridPosition)
for (const x in cityGridPosition[y])
{
cityGridPosition[y][x].round();
createArea(
@ -695,11 +695,11 @@ for (let y in cityGridPosition)
}
g_Map.log("Marking horizontal city paths");
var areasCityPaths = [];
const areasCityPaths = [];
for (let y = 0; y < gridPointsY; ++y)
for (let x = 1; x < gridPointsX; ++x)
{
let width = y == gridPointYCenter ? pathWidthSecondary : pathWidth;
const width = y == gridPointYCenter ? pathWidthSecondary : pathWidth;
areasCityPaths.push(
createArea(
new PathPlacer(cityGridPosition[y][x - 1], cityGridPosition[y][x], width, 0, 8, 0, 0, Infinity),
@ -710,7 +710,7 @@ g_Map.log("Marking vertical city paths");
for (let y = 1; y < gridPointsY; ++y)
for (let x = 0; x < gridPointsX; ++x)
{
let width =
const width =
Math.abs(x - gridPointXCenter) == 0 ?
pathWidthCenter :
Math.abs(x - gridPointXCenter) == 1 ?
@ -725,11 +725,11 @@ for (let y = 1; y < gridPointsY; ++y)
Engine.SetProgress(70);
g_Map.log("Placing kushite temples");
var entitiesTemples = [];
var templePosition = [];
let entitiesTemples = [];
const templePosition = [];
for (let i = 0; i < layoutKushTemples.length; ++i)
{
let x = i + (gridPointsX - layoutKushTemples.length) / 2;
const x = i + (gridPointsX - layoutKushTemples.length) / 2;
templePosition[i] = Vector2D.add(cityGridPosition[0][x], layoutKushTemples[i].pathOffset.rotate(-Math.PI / 2 - cityGridAngle[0][x]));
entitiesTemples[i] = g_Map.placeEntityPassable(layoutKushTemples[i].template, 0, templePosition[i], cityGridAngle[0][x]);
}
@ -767,15 +767,15 @@ createArea(
]);
g_Map.log("Placing lion statues in the central path");
var statueCount = scaleByMapSize(10, 40);
var centralPathStart = cityGridPosition[0][gridPointXCenter];
var centralPathLength = centralPathStart.distanceTo(cityGridPosition[gridPointsY - 1][gridPointXCenter]);
var centralPathAngle = cityGridAngle[0][gridPointXCenter];
const statueCount = scaleByMapSize(10, 40);
const centralPathStart = cityGridPosition[0][gridPointXCenter];
const centralPathLength = centralPathStart.distanceTo(cityGridPosition[gridPointsY - 1][gridPointXCenter]);
const centralPathAngle = cityGridAngle[0][gridPointXCenter];
for (let i = 0; i < 2; ++i)
for (let stat = 0; stat < statueCount; ++stat)
{
let start = new Vector2D(0, pathWidthCenter * 3/4 * (i - 0.5)).rotate(centralPathAngle).add(centralPathStart);
let position = new Vector2D(centralPathLength, 0).mult(stat / statueCount).rotate(-centralPathAngle).add(start).add(new Vector2D(0.5, 0.5));
const start = new Vector2D(0, pathWidthCenter * 3/4 * (i - 0.5)).rotate(centralPathAngle).add(centralPathStart);
const position = new Vector2D(centralPathLength, 0).mult(stat / statueCount).rotate(-centralPathAngle).add(start).add(new Vector2D(0.5, 0.5));
if (!avoidClasses(clPathCrossing, 2).allows(position))
continue;
@ -785,12 +785,12 @@ for (let i = 0; i < 2; ++i)
}
g_Map.log("Placing guardian infantry in the central path");
var centralChampionsCount = scaleByMapSize(2, 40);
const centralChampionsCount = scaleByMapSize(2, 40);
for (let i = 0; i < 2; ++i)
for (let champ = 0; champ < centralChampionsCount; ++champ)
{
let start = new Vector2D(0, pathWidthCenter * 1/2 * (i - 0.5)).rotate(-centralPathAngle).add(centralPathStart);
let position = new Vector2D(centralPathLength, 0).mult(champ / centralChampionsCount).rotate(-centralPathAngle).add(start).add(new Vector2D(0.5, 0.5));
const start = new Vector2D(0, pathWidthCenter * 1/2 * (i - 0.5)).rotate(-centralPathAngle).add(centralPathStart);
const position = new Vector2D(centralPathLength, 0).mult(champ / centralChampionsCount).rotate(-centralPathAngle).add(start).add(new Vector2D(0.5, 0.5));
if (!avoidClasses(clPathCrossing, 2).allows(position))
continue;
@ -800,21 +800,21 @@ for (let i = 0; i < 2; ++i)
}
g_Map.log("Placing kushite statues in the secondary paths");
for (let x of [gridPointXCenter - 1, gridPointXCenter + 1])
for (const x of [gridPointXCenter - 1, gridPointXCenter + 1])
{
g_Map.placeEntityAnywhere(aStatueKush, 0, cityGridPosition[gridPointYCenter][x], cityGridAngle[gridPointYCenter][x]);
clPathStatues.add(cityGridPosition[gridPointYCenter][x]);
}
g_Map.log("Creating ritual place near the wonder");
var ritualPosition = Vector2D.average([
const ritualPosition = Vector2D.average([
templePosition[Math.floor(templePosition.length / 2) - 1],
templePosition[Math.ceil(templePosition.length / 2) - 1],
cityGridPosition[0][gridPointXCenter],
cityGridPosition[0][gridPointXCenter - 1]
]).round();
var ritualAngle = (cityGridAngle[0][gridPointXCenter] + cityGridAngle[0][gridPointXCenter - 1]) / 2 + Math.PI / 2;
const ritualAngle = (cityGridAngle[0][gridPointXCenter] + cityGridAngle[0][gridPointXCenter - 1]) / 2 + Math.PI / 2;
g_Map.placeEntityPassable(aStatueKush, 0, ritualPosition, ritualAngle - Math.PI / 2);
@ -832,26 +832,26 @@ createArea(
new ElevationPainter(heightDesert + heightOffsetStatue));
g_Map.log("Placing healers at the ritual place");
var [healerPosition, healerAngle] = distributePointsOnCircularSegment(
const [healerPosition, healerAngle] = distributePointsOnCircularSegment(
scaleByMapSize(2, 10), Math.PI, ritualAngle, scaleByMapSize(2, 3), ritualPosition);
for (let i = 0; i < healerPosition.length; ++i)
g_Map.placeEntityPassable(oKushHealer, 0, healerPosition[i], healerAngle[i] + Math.PI);
g_Map.log("Placing statues at the ritual place");
var [statuePosition, statueAngle] = distributePointsOnCircularSegment(
const [statuePosition, statueAngle] = distributePointsOnCircularSegment(
scaleByMapSize(4, 8), Math.PI, ritualAngle, scaleByMapSize(3, 4), ritualPosition);
for (let i = 0; i < statuePosition.length; ++i)
g_Map.placeEntityPassable(pickRandom(aStatues), 0, statuePosition[i], statueAngle[i] + Math.PI);
g_Map.log("Placing palms at the ritual place");
var palmPosition = distributePointsOnCircularSegment(
const palmPosition = distributePointsOnCircularSegment(
scaleByMapSize(6, 16), Math.PI, ritualAngle, scaleByMapSize(4, 5), ritualPosition)[0];
for (let i = 0; i < palmPosition.length; ++i)
if (avoidClasses(clTemple, 1).allows(palmPosition[i]))
g_Map.placeEntityPassable(oPalmPath, 0, palmPosition[i], randomAngle());
g_Map.log("Painting city paths");
var areaPaths = createArea(
const areaPaths = createArea(
new MapBoundsPlacer(),
[
new LayeredPainter([tPathWild, tPath], [1]),
@ -880,14 +880,14 @@ for (let y = 1; y < gridPointsY; ++y)
],
new StaticConstraint(avoidClasses(clPath, 0)));
var entitiesGates;
let entitiesGates;
if (placeNapataWall)
{
g_Map.log("Placing front walls");
let wallGridMaxAngleSummand = scaleByMapSize(0.04, 0.03) * Math.PI;
let wallGridStartAngle = gridStartAngle - wallGridMaxAngleSummand / 2;
let wallGridRadiusFront = gridRadius(gridPointsY - 1) + pathWidth - 1;
let wallGridMaxAngleFront = gridMaxAngle + wallGridMaxAngleSummand;
const wallGridMaxAngleSummand = scaleByMapSize(0.04, 0.03) * Math.PI;
const wallGridStartAngle = gridStartAngle - wallGridMaxAngleSummand / 2;
const wallGridRadiusFront = gridRadius(gridPointsY - 1) + pathWidth - 1;
const wallGridMaxAngleFront = gridMaxAngle + wallGridMaxAngleSummand;
let entitiesWalls = placeCircularWall(
gridCenter,
wallGridRadiusFront,
@ -901,11 +901,11 @@ if (placeNapataWall)
0);
g_Map.log("Placing side and back walls");
let wallGridRadiusBack = hillRadius - scaleByMapSize(15, 25);
let wallGridMaxAngleBack = gridMaxAngle + wallGridMaxAngleSummand;
let wallGridPositionFront = distributePointsOnCircularSegment(gridPointsX, wallGridMaxAngleBack, wallGridStartAngle, wallGridRadiusFront, gridCenter)[0];
let wallGridPositionBack = distributePointsOnCircularSegment(gridPointsX, wallGridMaxAngleBack, wallGridStartAngle, wallGridRadiusBack, gridCenter)[0];
let wallGridPosition = [wallGridPositionFront[0], ...wallGridPositionBack, wallGridPositionFront[wallGridPositionFront.length - 1]];
const wallGridRadiusBack = hillRadius - scaleByMapSize(15, 25);
const wallGridMaxAngleBack = gridMaxAngle + wallGridMaxAngleSummand;
const wallGridPositionFront = distributePointsOnCircularSegment(gridPointsX, wallGridMaxAngleBack, wallGridStartAngle, wallGridRadiusFront, gridCenter)[0];
const wallGridPositionBack = distributePointsOnCircularSegment(gridPointsX, wallGridMaxAngleBack, wallGridStartAngle, wallGridRadiusBack, gridCenter)[0];
const wallGridPosition = [wallGridPositionFront[0], ...wallGridPositionBack, wallGridPositionFront[wallGridPositionFront.length - 1]];
for (let x = 1; x < wallGridPosition.length; ++x)
entitiesWalls = entitiesWalls.concat(
placeLinearWall(
@ -941,7 +941,7 @@ if (placeNapataWall)
]);
g_Map.log("Painting gate terrain");
for (let entity of entitiesGates)
for (const entity of entitiesGates)
createArea(
new DiskPlacer(pathWidth, entity.GetPosition2D()),
[
@ -956,7 +956,7 @@ if (placeNapataWall)
Engine.SetProgress(70);
g_Map.log("Finding road starting points");
var roadStartLocations = shuffleArray(
const roadStartLocations = shuffleArray(
entitiesGates ?
entitiesGates.map(entity => entity.GetPosition2D()) :
[
@ -966,24 +966,24 @@ var roadStartLocations = shuffleArray(
]);
g_Map.log("Finding possible roads");
var roadConstraint = new StaticConstraint(
let roadConstraint = new StaticConstraint(
[
stayDesert,
avoidClasses(clHill, 0, clCity, 0, clPyramid, 6, clPlayer, 16)
]);
var areaCityPaths = new Area(areasCityPaths.reduce((points, area) => points.concat(area.getPoints()), []));
var areaRoads = [];
for (let roadStart of roadStartLocations)
const areaCityPaths = new Area(areasCityPaths.reduce((points, area) => points.concat(area.getPoints()), []));
const areaRoads = [];
for (const roadStart of roadStartLocations)
{
if (areaRoads.length >= scaleByMapSize(2, 5))
break;
let closestPoint = areaCityPaths.getClosestPointTo(roadStart);
const closestPoint = areaCityPaths.getClosestPointTo(roadStart);
roadConstraint = new StaticConstraint([roadConstraint, avoidClasses(clRoad, 20)]);
for (let tries = 0; tries < 30; ++tries)
{
let area = createArea(
const area = createArea(
new PathPlacer(
Vector2D.add(closestPoint, new Vector2D(0, 3/4 * mapSize).rotate(closestPoint.angleTo(roadStart))),
roadStart,
@ -1014,7 +1014,7 @@ createArea(
[stayClasses(clRoad, 0), avoidClasses(clPath, 0)]);
g_Map.log("Marking road palm area");
var areaRoadPalms = createArea(
const areaRoadPalms = createArea(
new MapBoundsPlacer(),
undefined,
[
@ -1045,7 +1045,7 @@ if (areaRoadPalms && areaRoadPalms.getPoints().length)
Engine.SetProgress(75);
g_Map.log("Marking city bush area");
var areaCityBushes =
const areaCityBushes =
createArea(
new MapBoundsPlacer(),
undefined,
@ -1072,7 +1072,7 @@ var areaCityBushes =
]);
g_Map.log("Marking city palm area");
var areaCityPalms =
const areaCityPalms =
createArea(
new MapBoundsPlacer(),
undefined,
@ -1102,7 +1102,7 @@ createObjectGroupsByAreas(
if (placeNapataWall)
{
g_Map.log("Marking wall palm area");
var areaWallPalms = createArea(
const areaWallPalms = createArea(
new MapBoundsPlacer(),
undefined,
new StaticConstraint([
@ -1132,7 +1132,7 @@ Engine.SetProgress(80);
g_Map.log("Setting up common constraints and areas");
const nearWater = new NearTileClassConstraint(clWater, 3);
var avoidCollisionsNomad = new AndConstraint(
const avoidCollisionsNomad = new AndConstraint(
[
new StaticConstraint(avoidClasses(
clCliff, 0, clHill, 0, clPlayer, 15, clWater, 1, clPath, 2, clRitualPlace, 10,
@ -1140,7 +1140,7 @@ var avoidCollisionsNomad = new AndConstraint(
avoidClasses(clForest, 1, clRock, 4, clMetal, 4, clFood, 2, clSoldier, 1, clTreasure, 1)
]);
var avoidCollisions = new AndConstraint(
let avoidCollisions = new AndConstraint(
[
avoidCollisionsNomad,
new StaticConstraint(avoidClasses(clRoad, 6, clFood, 6))
@ -1188,8 +1188,8 @@ const mineObjectsPerBiome = [
for (let i = 0; i < scaleByMapSize(6, 22); ++i)
{
let mineObjectsBiome = pickRandom(mineObjectsPerBiome);
for (let i in mineObjectsBiome.desert)
const mineObjectsBiome = pickRandom(mineObjectsPerBiome);
for (const i in mineObjectsBiome.desert)
createObjectGroupsByAreas(
new SimpleGroup(mineObjectsBiome.desert[i], true, mineObjectsBiome.tileClass),
0,
@ -1201,7 +1201,7 @@ for (let i = 0; i < scaleByMapSize(6, 22); ++i)
for (let i = 0; i < (isNomad() ? scaleByMapSize(6, 16) : scaleByMapSize(0, 8)); ++i)
{
let mineObjectsBiome = pickRandom(mineObjectsPerBiome);
const mineObjectsBiome = pickRandom(mineObjectsPerBiome);
createObjectGroupsByAreas(
new SimpleGroup(mineObjectsBiome.fertileLand.small, true, mineObjectsBiome.tileClass),
0,
@ -1297,7 +1297,7 @@ if (!isNomad())
Engine.SetProgress(85);
g_Map.log("Marking irrigation canal tree area");
var areaIrrigationCanalTrees = createArea(
const areaIrrigationCanalTrees = createArea(
new MapBoundsPlacer(),
undefined,
[
@ -1392,7 +1392,7 @@ createObjectGroupsByAreas(
[areaHilltop]);
g_Map.log("Placing treasures in the city");
var pathBorderConstraint = new AndConstraint([
const pathBorderConstraint = new AndConstraint([
new StaticConstraint([new NearTileClassConstraint(clCity, 1)]),
avoidClasses(clTreasure, 2, clStatue, 10, clPathStatues, 4, clWall, 2, clForest, 1)
]);
@ -1464,7 +1464,7 @@ createObjectGroupsByAreas(
[areaWater]);
g_Map.log("Creating reeds at the irrigation canals");
for (let area of areasPassages)
for (const area of areasPassages)
createObjectGroupsByAreas(
new SimpleGroup([new RandomObject(aWaterDecoratives, 2, 4, 1, 2)], true),
0,

View File

@ -37,27 +37,27 @@ const heightSeaGround = -5;
const heightLand = 3;
const heightHill = 25;
var g_Map = new RandomMap(heightLand, tGrass);
const g_Map = new RandomMap(heightLand, tGrass);
const numPlayers = getNumPlayers();
const mapCenter = g_Map.getCenter();
const mapBounds = g_Map.getBounds();
var clPlayer = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clWater = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clWater = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
var waterPosition = fractionToTiles(0.31);
var playerPosition = fractionToTiles(0.55);
var mountainPosition = fractionToTiles(0.69);
const waterPosition = fractionToTiles(0.31);
const playerPosition = fractionToTiles(0.55);
const mountainPosition = fractionToTiles(0.69);
var startAngle = randomAngle();
const startAngle = randomAngle();
placePlayerBases({
"PlayerPlacement": [
@ -110,7 +110,7 @@ paintRiver({
});
g_Map.log("Marking mountain area");
var areaMountains = createArea(
const areaMountains = createArea(
new ConvexPolygonPlacer(
[
new Vector2D(mountainPosition, mapBounds.top),
@ -123,7 +123,7 @@ var areaMountains = createArea(
g_Map.log("Creating shores");
for (let i = 0; i < scaleByMapSize(20, 120); ++i)
{
let position = new Vector2D(fractionToTiles(randFloat(0.28, 0.34)), fractionToTiles(randFloat(0.1, 0.9))).rotateAround(startAngle - Math.PI / 2, mapCenter).round();
const position = new Vector2D(fractionToTiles(randFloat(0.28, 0.34)), fractionToTiles(randFloat(0.1, 0.9))).rotateAround(startAngle - Math.PI / 2, mapCenter).round();
createArea(
new ChainPlacer(1, Math.floor(scaleByMapSize(4, 6)), Math.floor(scaleByMapSize(16, 30)), Infinity, position),
[
@ -154,14 +154,14 @@ createAreasInAreas(
[areaMountains]);
g_Map.log("Creating forests");
var [forestTrees, stragglerTrees] = getTreeCounts(1000, 6000, 0.7);
var types = [
const [forestTrees, stragglerTrees] = getTreeCounts(1000, 6000, 0.7);
const types = [
[[tGrass, tGrass, tGrass, tGrass, pForestD], [tGrass, tGrass, tGrass, pForestD]],
[[tGrass, tGrass, tGrass, tGrass, pForestP], [tGrass, tGrass, tGrass, pForestP]]
];
var size = forestTrees / (scaleByMapSize(3,6) * numPlayers);
var num = Math.floor(size / types.length);
for (let type of types)
const forestSize = forestTrees / (scaleByMapSize(3,6) * numPlayers);
const num = Math.floor(forestSize / types.length);
for (const type of types)
createAreas(
new ChainPlacer(
1,
@ -178,7 +178,7 @@ for (let type of types)
Engine.SetProgress(70);
g_Map.log("Creating grass patches");
for (let size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)])
for (const size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)])
createAreas(
new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), size, 0.5),
[
@ -188,7 +188,7 @@ for (let size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8,
avoidClasses(clWater, 8, clForest, 0, clHill, 0, clPlayer, 12, clDirt, 16),
scaleByMapSize(20, 80));
for (let size of [scaleByMapSize(2, 4), scaleByMapSize(3, 7), scaleByMapSize(5, 15)])
for (const size of [scaleByMapSize(2, 4), scaleByMapSize(3, 7), scaleByMapSize(5, 15)])
createAreas(
new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), size, 0.5),
[
@ -199,7 +199,7 @@ for (let size of [scaleByMapSize(2, 4), scaleByMapSize(3, 7), scaleByMapSize(5,
scaleByMapSize(20, 80));
g_Map.log("Creating stone mines");
var group = new SimpleGroup([new SimpleObject(oStoneSmall, 0, 2, 0, 4, 0, 2 * Math.PI, 1), new SimpleObject(oStoneLarge, 1, 1, 0, 4, 0, 2 * Math.PI, 4)], true, clRock);
let group = new SimpleGroup([new SimpleObject(oStoneSmall, 0, 2, 0, 4, 0, 2 * Math.PI, 1), new SimpleObject(oStoneLarge, 1, 1, 0, 4, 0, 2 * Math.PI, 4)], true, clRock);
createObjectGroupsDeprecated(group, 0,
avoidClasses(clWater, 3, clForest, 1, clPlayer, 20, clRock, 10, clHill, 1),
scaleByMapSize(4,16), 100

View File

@ -45,23 +45,23 @@ const pForest2 = [tForestFloor1 + TERRAIN_SEPARATOR + oTree4, tForestFloor1 + TE
const heightSeaGround = -3;
const heightLand = 3;
var g_Map = new RandomMap(heightLand, tMainTerrain);
const g_Map = new RandomMap(heightLand, tMainTerrain);
const numPlayers = getNumPlayers();
const mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
var clPlayer = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clWater = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clWater = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
var [playerIDs, playerPosition] = playerPlacementCircle(fractionToTiles(0.35));
const [playerIDs, playerPosition] = playerPlacementCircle(fractionToTiles(0.35));
g_Map.log("Preventing water in player territory");
for (let i = 0; i < numPlayers; ++i)
@ -180,7 +180,7 @@ createBalancedStoneMines(
Engine.SetProgress(65);
var planetm = 1;
let planetm = 1;
if (currentBiome() == "generic/india")
planetm = 8;

View File

@ -55,21 +55,21 @@ const heightLand = 0;
const heightPlayer = 5;
const heightHill = 12;
var g_Map = new RandomMap(heightLand, tGrass);
const g_Map = new RandomMap(heightLand, tGrass);
const numPlayers = getNumPlayers();
const mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
const mapBounds = g_Map.getBounds();
var clWater = g_Map.createTileClass();
var clCliff = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clPlayer = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
const clWater = g_Map.createTileClass();
const clCliff = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
var WATER_WIDTH = 0.1;
var horizontal = randBool();
@ -83,8 +83,8 @@ function distanceToPlayers(x, z)
let r = Infinity;
for (let i = 0; i < numPlayers; ++i)
{
var dx = x - tilesToFraction(playerPosition[i].x);
var dz = z - tilesToFraction(playerPosition[i].y);
let dx = x - tilesToFraction(playerPosition[i].x);
let dz = z - tilesToFraction(playerPosition[i].y);
r = Math.min(r, Math.square(dx) + Math.square(dz));
}
return Math.sqrt(r);
@ -92,7 +92,7 @@ function distanceToPlayers(x, z)
function playerNearness(x, z)
{
var d = fractionToTiles(distanceToPlayers(x,z));
let d = fractionToTiles(distanceToPlayers(x,z));
if (d < 13)
return 0;
@ -103,7 +103,7 @@ function playerNearness(x, z)
return 1;
}
for (let x of [mapBounds.left, mapBounds.right])
for (const x of [mapBounds.left, mapBounds.right])
paintRiver({
"parallel": true,
"start": new Vector2D(x, mapBounds.top).rotateAround(startAngle, mapCenter),
@ -136,14 +136,14 @@ var noise5 = new Noise2D(scaleByMapSize(11, 44));
for (var ix = 0; ix <= mapSize; ix++)
for (var iz = 0; iz <= mapSize; iz++)
{
let position = new Vector2D(ix, iz);
const position = new Vector2D(ix, iz);
var x = ix / (mapSize + 1.0);
var z = iz / (mapSize + 1.0);
var pn = playerNearness(x, z);
let c = startAngle ? z : x;
let distToWater = clWater.has(position) ? 0 : (0.5 - WATER_WIDTH - Math.abs(c - 0.5));
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
@ -153,7 +153,7 @@ for (var ix = 0; ix <= mapSize; ix++)
baseNoise *= pn;
baseNoise *= Math.max(0.1, distToWater / (0.5 - WATER_WIDTH));
}
var oldH = h;
const oldH = h;
h += baseNoise;
// add some higher-frequency noise on land
@ -163,7 +163,7 @@ for (var ix = 0; ix <= mapSize; ix++)
// create cliff noise
if ( h > -10 )
{
var cliffNoise = (noise3.get(x,z) + 0.5*noise4.get(x,z)) / 1.5;
let cliffNoise = (noise3.get(x,z) + 0.5*noise4.get(x,z)) / 1.5;
if (h < 1)
{
var u = 1 - 0.3*((h-1)/-10);
@ -195,7 +195,7 @@ var noise10 = new Noise2D(scaleByMapSize(50, 200));
for (var ix = 0; ix < mapSize; ix++)
for (var iz = 0; iz < mapSize; iz++)
{
let position = new Vector2D(ix, iz);
const position = new Vector2D(ix, iz);
var x = ix / (mapSize + 1.0);
var z = iz / (mapSize + 1.0);
var pn = playerNearness(x, z);
@ -203,9 +203,9 @@ for (var ix = 0; ix < mapSize; ix++)
// Compute height difference
let minH = +Infinity;
let maxH = -Infinity;
for (let vertex of g_TileVertices)
for (const vertex of g_TileVertices)
{
let height = g_Map.getHeight(Vector2D.add(position, vertex));
const height = g_Map.getHeight(Vector2D.add(position, vertex));
minH = Math.min(minH, height);
maxH = Math.max(maxH, height);
}
@ -223,7 +223,7 @@ for (var ix = 0; ix < mapSize; ix++)
}
// choose a terrain based on elevation
var t = tGrass;
let t = tGrass;
// water
if (maxH < -12)
@ -276,7 +276,7 @@ for (var ix = 0; ix < mapSize; ix++)
{
if (minH < 11 && minH >= 4)
{
var typeNoise = noise10.get(x,z);
const typeNoise = noise10.get(x,z);
if (typeNoise < 0.43 && forestNoise < 0.05)
t = pPoplarForest;

View File

@ -12,7 +12,7 @@ const heightPath = 10;
const heightDen = 15;
const heightHill = 50;
var g_Map = new RandomMap(heightHill, topTerrain);
const g_Map = new RandomMap(heightHill, topTerrain);
const mapCenter = g_Map.getCenter();
const numPlayers = getNumPlayers();
@ -434,10 +434,10 @@ g_Map.ExportMap();
function createSunkenTerrain()
{
var base = g_Terrains.mainTerrain;
var middle = g_Terrains.dirt;
var lower = g_Terrains.tier2Terrain;
var road = g_Terrains.road;
let base = g_Terrains.mainTerrain;
let middle = g_Terrains.dirt;
let lower = g_Terrains.tier2Terrain;
let road = g_Terrains.road;
if (currentBiome() == "generic/arctic")
{
@ -469,9 +469,9 @@ function createSunkenTerrain()
if (currentBiome() == "generic/autumn")
middle = g_Terrains.shore;
var expSize = diskArea(fractionToTiles(0.14)) / numPlayers;
var expDist = 0.1 + numPlayers / 200;
var expAngle = 0.75;
let expSize = diskArea(fractionToTiles(0.14)) / numPlayers;
let expDist = 0.1 + numPlayers / 200;
let expAngle = 0.75;
if (numPlayers <= 2)
{
@ -479,8 +479,8 @@ function createSunkenTerrain()
expAngle = 0.72;
}
var nRoad = 0.44;
var nExp = 0.425;
let nRoad = 0.44;
let nExp = 0.425;
if (numPlayers < 4)
{
@ -506,17 +506,17 @@ function createSunkenTerrain()
new TileClassPainter(g_TileClasses.mountain)
]);
let getCoords = (distance, playerID, playerIDOffset) => {
let angle = startAngle + (playerID + playerIDOffset) * 2 * Math.PI / numPlayers;
const getCoords = (distance, playerID, playerIDOffset) => {
const angle = startAngle + (playerID + playerIDOffset) * 2 * Math.PI / numPlayers;
return Vector2D.add(mapCenter, new Vector2D(fractionToTiles(distance), 0).rotate(-angle)).round();
};
for (let i = 0; i < numPlayers; ++i)
{
let playerPosition = getCoords(0.4, i, 0);
const playerPosition = getCoords(0.4, i, 0);
// Path from player to expansion
let expansionPosition = getCoords(expDist, i, expAngle);
const expansionPosition = getCoords(expDist, i, expAngle);
createArea(
new PathPlacer(playerPosition, expansionPosition, 12, 0.7, 0.5, 0.1, -1),
[
@ -526,10 +526,10 @@ function createSunkenTerrain()
]);
// Path from player to neighbor
for (let neighborOffset of [-0.5, 0.5])
for (const neighborOffset of [-0.5, 0.5])
{
let neighborPosition = getCoords(nRoad, i, neighborOffset);
let pathPosition = getCoords(0.47, i, 0);
const neighborPosition = getCoords(nRoad, i, neighborOffset);
const pathPosition = getCoords(0.47, i, 0);
createArea(
new PathPlacer(pathPosition, neighborPosition, 19, 0.4, 0.5, 0.1, -0.6),
[
@ -562,7 +562,7 @@ function createSunkenTerrain()
g_Map.log("Creating the expansions between players");
for (let i = 0; i < numPlayers; ++i)
{
let position = getCoords(nExp, i, 0.5);
const position = getCoords(nExp, i, 0.5);
createArea(
new ClumpPlacer(expSize, 0.9, 0.3, Infinity, position),
[

View File

@ -42,27 +42,27 @@ const heightShallows = -2;
const heightLand = 3;
const heightOffsetBump = 2;
var g_Map = new RandomMap(heightLand, tPrimary);
const g_Map = new RandomMap(heightLand, tPrimary);
const numPlayers = getNumPlayers();
const mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
const mapBounds = g_Map.getBounds();
var clPlayer = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clWater = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
var clShallow = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clWater = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
const clShallow = g_Map.createTileClass();
var shallowWidth = scaleByMapSize(8, 12);
const shallowWidth = scaleByMapSize(8, 12);
var startAngle = randomAngle();
const startAngle = randomAngle();
placePlayerBases({
"PlayerPlacement": playerPlacementRiver(startAngle + Math.PI / 2, fractionToTiles(0.5)),
@ -97,7 +97,7 @@ placePlayerBases({
});
Engine.SetProgress(20);
var riverPositions = [
const riverPositions = [
new Vector2D(mapBounds.left + 1, mapCenter.y),
new Vector2D(mapBounds.right - 1, mapCenter.y)
].map(v => v.rotateAround(startAngle, mapCenter));
@ -110,7 +110,7 @@ createArea(
Engine.SetProgress(25);
g_Map.log("Creating small puddles at the map border to ensure players being separated");
for (let riverPosition of riverPositions)
for (const riverPosition of riverPositions)
createArea(
new ClumpPlacer(diskArea(scaleByMapSize(5, 10)), 0.95, 0.6, Infinity, riverPosition),
new SmoothElevationPainter(ELEVATION_SET, heightSeaGround, 2),
@ -120,7 +120,7 @@ Engine.SetProgress(30);
g_Map.log("Creating the shallows of the main river");
for (let i = 0; i <= randIntInclusive(3, scaleByMapSize(4, 6)); ++i)
{
let location = fractionToTiles(randFloat(0.15, 0.85));
const location = fractionToTiles(randFloat(0.15, 0.85));
createPassage({
"start": new Vector2D(location, mapBounds.top).rotateAround(startAngle, mapCenter),
"end": new Vector2D(location, mapBounds.bottom).rotateAround(startAngle, mapCenter),
@ -163,7 +163,7 @@ createAreas(
);
Engine.SetProgress(55);
var [forestTrees, stragglerTrees] = getTreeCounts(500, 2500, 0.7);
const [forestTrees, stragglerTrees] = getTreeCounts(500, 2500, 0.7);
createForests(
[tGrass, tGrassDForest, tGrassPForest, pForestB, pForestO],
avoidClasses(clPlayer, 15, clWater, 3, clForest, 16, clHill, 1),
@ -172,7 +172,7 @@ createForests(
Engine.SetProgress(70);
g_Map.log("Creating dirt patches");
for (let size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)])
for (const size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)])
createAreas(
new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), size, 0.5),
[
@ -184,7 +184,7 @@ for (let size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8,
);
g_Map.log("Creating grass patches");
for (let size of [scaleByMapSize(2, 4), scaleByMapSize(3, 7), scaleByMapSize(5, 15)])
for (const size of [scaleByMapSize(2, 4), scaleByMapSize(3, 7), scaleByMapSize(5, 15)])
createAreas(
new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), size, 0.5),
new LayeredPainter([tGrassPatchBlend, tGrassPatch], [1]),
@ -194,7 +194,7 @@ for (let size of [scaleByMapSize(2, 4), scaleByMapSize(3, 7), scaleByMapSize(5,
Engine.SetProgress(80);
g_Map.log("Creating stone mines");
var group = new SimpleGroup([new SimpleObject(oStoneSmall, 0, 2, 0, 4, 0, 2 * Math.PI, 1), new SimpleObject(oStoneLarge, 1, 1, 0, 4, 0, 2 * Math.PI, 4)], true, clRock);
let group = new SimpleGroup([new SimpleObject(oStoneSmall, 0, 2, 0, 4, 0, 2 * Math.PI, 1), new SimpleObject(oStoneLarge, 1, 1, 0, 4, 0, 2 * Math.PI, 4)], true, clRock);
createObjectGroupsDeprecated(group, 0,
[avoidClasses(clWater, 0, clForest, 1, clPlayer, 15, clRock, 10, clHill, 1)],
scaleByMapSize(4,16), 100

View File

@ -109,7 +109,7 @@ const heightmapWaterThreshold = convertHeightmap1Dto2D(Engine.LoadHeightmapImage
Engine.SetProgress(3);
g_Map.log("Composing heightmap");
var heightmapCombined = [];
let heightmapCombined = [];
for (let x = 0; x < heightmapLand.length; ++x)
{
heightmapCombined[x] = new Float32Array(heightmapLand.length);
@ -140,7 +140,7 @@ g_Map.log("Creating Nile passages");
const riverAngle = Math.PI * 3 / 4;
for (let i = 0; i < scaleByMapSize(8, 15); ++i)
{
let x = fractionToTiles(randFloat(0, 1));
const x = fractionToTiles(randFloat(0, 1));
createArea(
new PathPlacer(
new Vector2D(x, mapBounds.bottom).rotateAround(riverAngle, mapCenter),
@ -197,15 +197,15 @@ createArea(
new HeightConstraint(heightPlateau2, Infinity));
Engine.SetProgress(38);
var playerIDs = [];
var playerPosition = [];
let playerIDs = [];
let playerPosition = [];
if (!isNomad())
{
g_Map.log("Finding player locations");
[playerIDs, playerPosition] = playerPlacementRandom(sortAllPlayers(), avoidClasses(clWater, scaleByMapSize(8, 12), clCliff, scaleByMapSize(8, 12)));
g_Map.log("Flatten the initial CC area");
for (let position of playerPosition)
for (const position of playerPosition)
createArea(
new ClumpPlacer(diskArea(defaultPlayerBaseRadius() * 0.8), 0.95, 0.6, Infinity, position),
new SmoothElevationPainter(ELEVATION_SET, g_Map.getHeight(position), 6));
@ -327,11 +327,11 @@ Engine.SetProgress(73);
const avoidCollisions = avoidClasses(clPlayer, 12, clBaseResource, 5, clWater, 1, clForest, 1, clRock, 4, clMetal, 4, clFood, 6, clCliff, 0, clPyramid, 6);
g_Map.log("Creating straggler trees and bushes");
var stragglerTreeObjects = [
const stragglerTreeObjects = [
[new SimpleObject(oAcacia, 1, 1, 0, 0), new SimpleObject(oBushBadlands, 0, 1, 2, 2)],
[new SimpleObject(oTreeDead, 1, 1, 0, 0), new SimpleObject(oBushBadlands, 0, 1, 2, 2)]
];
for (let objects of stragglerTreeObjects)
for (const objects of stragglerTreeObjects)
createObjectGroups(
new SimpleGroup(objects, true, clForest),
0,

View File

@ -41,18 +41,18 @@ const pForest2 = [tForestFloor1 + TERRAIN_SEPARATOR + oTree4, tForestFloor1 + TE
const heightLand = 3;
var g_Map = new RandomMap(heightLand, tMainTerrain);
const g_Map = new RandomMap(heightLand, tMainTerrain);
const numPlayers = getNumPlayers();
var clPlayer = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
placePlayerBases({
"PlayerPlacement": playerPlacementCircle(fractionToTiles(0.35)),
@ -88,7 +88,7 @@ if (randBool())
else
createMountains(tCliff, avoidClasses(clPlayer, 20, clHill, 15), clHill, scaleByMapSize(3, 15));
var [forestTrees, stragglerTrees] = getTreeCounts(...rBiomeTreeCount(1));
const [forestTrees, stragglerTrees] = getTreeCounts(...rBiomeTreeCount(1));
createDefaultForests(
[tMainTerrain, tForestFloor1, tForestFloor2, pForest1, pForest2],
avoidClasses(clPlayer, 20, clForest, 18, clHill, 0),
@ -133,7 +133,7 @@ createBalancedStoneMines(
Engine.SetProgress(65);
var planetm = 1;
let planetm = 1;
if (currentBiome() == "generic/india")
planetm = 8;

View File

@ -59,8 +59,8 @@ const heightSeaGround = heightScale(scaleByMapSize(-6, -4));
const heightWaterLevel = heightScale(0);
const heightShoreline = heightScale(0);
var g_Map = new RandomMap(0, g_Terrains.mainTerrain);
var mapCenter = g_Map.getCenter();
const g_Map = new RandomMap(0, g_Terrains.mainTerrain);
const mapCenter = g_Map.getCenter();
initTileClasses(["shoreline"]);
@ -121,7 +121,7 @@ Engine.SetProgress(45);
if (!isNomad())
{
g_Map.log("Placing players");
let [playerIDs, playerPosition] = createBases(
const [playerIDs, playerPosition] = createBases(
...playerPlacementRandom(
sortAllPlayers(),
[
@ -131,7 +131,7 @@ if (!isNomad())
true);
g_Map.log("Flatten the initial CC area");
for (let position of playerPosition)
for (const position of playerPosition)
createArea(
new ClumpPlacer(diskArea(defaultPlayerBaseRadius() * 0.8), 0.95, 0.6, Infinity, position),
new SmoothElevationPainter(ELEVATION_SET, g_Map.getHeight(position), 6));

View File

@ -34,21 +34,21 @@ const heightWaterLevel = heightScale(0);
const heightShoreline = heightScale(0.5);
const heightSnow = heightScale(10);
var g_Map = new RandomMap(heightWaterLevel, g_Terrains.mainTerrain);
var mapSize = g_Map.getSize();
var mapCenter = g_Map.getCenter();
var mapBounds = g_Map.getBounds();
const g_Map = new RandomMap(heightWaterLevel, g_Terrains.mainTerrain);
const mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
const mapBounds = g_Map.getBounds();
g_Map.LoadHeightmapImage("mediterranean.png", 0, 40);
Engine.SetProgress(15);
initTileClasses(["autumn", "desert", "medit", "polar", "steppe", "temp", "shoreline", "africa", "northern_europe", "southern_europe", "western_europe", "eastern_europe"]);
var northernTopLeft = new Vector2D(fractionToTiles(0.3), fractionToTiles(0.7));
var westernTopLeft = new Vector2D(fractionToTiles(0.7), fractionToTiles(0.47));
var africaTop = fractionToTiles(0.33);
const northernTopLeft = new Vector2D(fractionToTiles(0.3), fractionToTiles(0.7));
const westernTopLeft = new Vector2D(fractionToTiles(0.7), fractionToTiles(0.47));
const africaTop = fractionToTiles(0.33);
var climateZones = [
const climateZones = [
{
"tileClass": g_TileClasses.northern_europe,
"position1": new Vector2D(northernTopLeft.x, mapBounds.top),
@ -114,7 +114,7 @@ createArea(
Engine.SetProgress(35);
g_Map.log("Marking climate zones");
for (let zone of climateZones)
for (const zone of climateZones)
{
setBiome(zone.biome);
createArea(
@ -133,7 +133,7 @@ for (let zone of climateZones)
Engine.SetProgress(40);
g_Map.log("Fuzzing biome borders");
for (let zone of climateZones)
for (const zone of climateZones)
{
setBiome(zone.biome);
@ -163,7 +163,7 @@ if (!isNomad())
{
g_Map.log("Finding player positions");
let [playerIDs, playerPosition] = playerPlacementRandom(
const [playerIDs, playerPosition] = playerPlacementRandom(
sortAllPlayers(),
[
avoidClasses(g_TileClasses.mountain, 5),
@ -185,7 +185,7 @@ if (!isNomad())
}
Engine.SetProgress(50);
for (let zone of climateZones)
for (const zone of climateZones)
{
setBiome(zone.biome);

View File

@ -48,26 +48,26 @@ const heightLand = 3;
const heightHill = 18;
const heightOffsetBump = 2;
var g_Map = new RandomMap(heightSeaGround, tWater);
const g_Map = new RandomMap(heightSeaGround, tWater);
const numPlayers = getNumPlayers();
const mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
var clPlayer = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
var clLand = g_Map.createTileClass();
var clIsland = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
const clLand = g_Map.createTileClass();
const clIsland = g_Map.createTileClass();
var startAngle = randomAngle();
var playerIDs = sortAllPlayers();
var [playerPosition, playerAngle] = playerPlacementCustomAngle(
const startAngle = randomAngle();
const playerIDs = sortAllPlayers();
const [playerPosition, playerAngle] = playerPlacementCustomAngle(
fractionToTiles(0.35),
mapCenter,
i => startAngle - Math.PI * (i + 1) / (numPlayers + 1));
@ -87,7 +87,7 @@ for (let i = 0; i < numPlayers; ++i)
if (isNomad())
continue;
let dockLocation = findLocationInDirectionBasedOnHeight(playerPosition[i], mapCenter, -3 , 2.6, 3);
const dockLocation = findLocationInDirectionBasedOnHeight(playerPosition[i], mapCenter, -3 , 2.6, 3);
g_Map.placeEntityPassable(oDock, playerIDs[i], dockLocation, playerAngle[i] + Math.PI);
}
Engine.SetProgress(10);
@ -128,7 +128,7 @@ placePlayerBases({
Engine.SetProgress(15);
g_Map.log("Create the continent body");
var continentPosition = Vector2D.add(mapCenter, new Vector2D(0, fractionToTiles(0.38)).rotate(-startAngle)).round();
const continentPosition = Vector2D.add(mapCenter, new Vector2D(0, fractionToTiles(0.38)).rotate(-startAngle)).round();
createArea(
new ClumpPlacer(diskArea(fractionToTiles(0.4)), 0.8, 0.08, Infinity, continentPosition),
[
@ -181,17 +181,17 @@ createAreas(
Engine.SetProgress(34);
g_Map.log("Creating forests");
var [forestTrees, stragglerTrees] = getTreeCounts(...rBiomeTreeCount(1));
var types = [
const [forestTrees, stragglerTrees] = getTreeCounts(...rBiomeTreeCount(1));
const types = [
[[tForestFloor2, tMainTerrain, pForest1], [tForestFloor2, pForest1]],
[[tForestFloor1, tMainTerrain, pForest2], [tForestFloor1, pForest2]]
];
var size = forestTrees / (scaleByMapSize(2,8) * numPlayers) *
const forestSize = forestTrees / (scaleByMapSize(2,8) * numPlayers) *
(currentBiome() == "generic/savanna" ? 2 : 1);
var num = Math.floor(size / types.length);
for (let type of types)
const num = Math.floor(forestSize / types.length);
for (const type of types)
createAreas(
new ClumpPlacer(forestTrees / num, 0.1, 0.1, Infinity),
[
@ -203,7 +203,7 @@ for (let type of types)
Engine.SetProgress(38);
g_Map.log("Creating dirt patches");
for (let size of [scaleByMapSize(3, 48), scaleByMapSize(5, 84), scaleByMapSize(8, 128)])
for (const size of [scaleByMapSize(3, 48), scaleByMapSize(5, 84), scaleByMapSize(8, 128)])
createAreas(
new ClumpPlacer(size, 0.3, 0.06, 0.5),
[
@ -225,7 +225,7 @@ for (let size of [scaleByMapSize(3, 48), scaleByMapSize(5, 84), scaleByMapSize(8
Engine.SetProgress(42);
g_Map.log("Creating grass patches");
for (let size of [scaleByMapSize(2, 32), scaleByMapSize(3, 48), scaleByMapSize(5, 80)])
for (const size of [scaleByMapSize(2, 32), scaleByMapSize(3, 48), scaleByMapSize(5, 80)])
createAreas(
new ClumpPlacer(size, 0.3, 0.06, 0.5),
new TerrainPainter(tTier4Terrain),
@ -234,7 +234,7 @@ for (let size of [scaleByMapSize(2, 32), scaleByMapSize(3, 48), scaleByMapSize(5
Engine.SetProgress(46);
g_Map.log("Creating stone mines");
var group = new SimpleGroup([new SimpleObject(oStoneSmall, 0, 2, 0, 4, 0, 2 * Math.PI, 1), new SimpleObject(oStoneLarge, 1, 1, 0, 4, 0, 2 * Math.PI, 4)], true, clRock);
let group = new SimpleGroup([new SimpleObject(oStoneSmall, 0, 2, 0, 4, 0, 2 * Math.PI, 1), new SimpleObject(oStoneLarge, 1, 1, 0, 4, 0, 2 * Math.PI, 4)], true, clRock);
createObjectGroupsDeprecated(group, 0,
[avoidClasses(clForest, 1, clPlayer, 10, clRock, 10, clHill, 1), stayClasses(clLand, 7)],
scaleByMapSize(4,16), 100
@ -331,7 +331,7 @@ createStragglerTrees(
Engine.SetProgress(86);
var planetm = currentBiome() == "generic/india" ? 8 : 1;
const planetm = currentBiome() == "generic/india" ? 8 : 1;
g_Map.log("Creating small grass tufts");
group = new SimpleGroup(

View File

@ -55,25 +55,25 @@ const heightOffsetHill2 = 16;
const heightOffsetHill3 = 16;
const heightOffsetBump = 2;
var g_Map = new RandomMap(heightLand, tPrimary);
const g_Map = new RandomMap(heightLand, tPrimary);
const numPlayers = getNumPlayers();
const mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
var clPlayer = g_Map.createTileClass();
var clHill1 = g_Map.createTileClass();
var clOasis = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clPatch = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill1 = g_Map.createTileClass();
const clOasis = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clPatch = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
var oasisRadius = scaleByMapSize(14, 40);
const oasisRadius = scaleByMapSize(14, 40);
var [playerIDs, playerPosition] = playerPlacementCircle(fractionToTiles(0.35));
const [playerIDs, playerPosition] = playerPlacementCircle(fractionToTiles(0.35));
if (!isNomad())
for (let i = 0; i < numPlayers; ++i)
@ -154,13 +154,13 @@ createArea(
Engine.SetProgress(30);
g_Map.log("Creating oasis wildlife");
var num = Math.round(Math.PI * oasisRadius / 8);
var constraint = new AndConstraint([borderClasses(clOasis, 0, 3), avoidClasses(clOasis, 0)]);
for (var i = 0; i < num; ++i)
let num = Math.round(Math.PI * oasisRadius / 8);
let constraint = new AndConstraint([borderClasses(clOasis, 0, 3), avoidClasses(clOasis, 0)]);
for (let i = 0; i < num; ++i)
{
let animalPosition;
let r = 0;
let angle = 2 * Math.PI / num * i;
const angle = 2 * Math.PI / num * i;
do {
// Work outward until constraint met
animalPosition = Vector2D.add(mapCenter, new Vector2D(r, 0).rotate(-angle)).round();
@ -183,11 +183,11 @@ for (var i = 0; i < num; ++i)
g_Map.log("Creating oasis fish");
constraint = new AndConstraint([borderClasses(clOasis, 15, 0), avoidClasses(clFood, 5)]);
num = Math.round(Math.PI * oasisRadius / 16);
for (var i = 0; i < num; ++i)
for (let i = 0; i < num; ++i)
{
let fishPosition;
var r = 0;
var angle = 2 * Math.PI / num * i;
let r = 0;
const angle = 2 * Math.PI / num * i;
do {
// Work outward until constraint met
fishPosition = Vector2D.add(mapCenter, new Vector2D(r, 0).rotate(-angle));
@ -199,7 +199,7 @@ for (var i = 0; i < num; ++i)
Engine.SetProgress(35);
g_Map.log("Creating level 1 hills");
var hillAreas = createAreas(
let hillAreas = createAreas(
new ClumpPlacer(scaleByMapSize(50,300), 0.25, 0.1, 0.5),
[
new LayeredPainter([tCliff, tSand], [1]),
@ -276,8 +276,8 @@ createAreas(
Engine.SetProgress(65);
g_Map.log("Creating forests");
var [forestTrees, stragglerTrees] = getTreeCounts(500, 2500, 0.5);
var num = g_DefaultNumberOfForests;
const [forestTrees, stragglerTrees] = getTreeCounts(500, 2500, 0.5);
num = g_DefaultNumberOfForests;
createAreas(
new ClumpPlacer(forestTrees / num, 0.15, 0.1, 0.5),
[

View File

@ -1,7 +1,7 @@
Engine.LoadLibrary("rmgen");
Engine.LoadLibrary("rmgen-common");
var g_Map = new RandomMap(0, "grass1_spring");
const g_Map = new RandomMap(0, "grass1_spring");
placePlayerBases({
"PlayerPlacement": playerPlacementCircle(fractionToTiles(0.39))

View File

@ -85,8 +85,8 @@ function setBiomeEden()
g_Gaia.secondaryHuntableAnimal = "gaia/fauna_elephant_african_bush";
}
var g_Map = new RandomMap(0, g_Terrains.mainTerrain);
var mapCenter = g_Map.getCenter();
const g_Map = new RandomMap(0, g_Terrains.mainTerrain);
const mapCenter = g_Map.getCenter();
initTileClasses(["eden", "highlands"]);
@ -135,7 +135,7 @@ Engine.SetProgress(55);
if (!isNomad())
{
g_Map.log("Placing players");
let [playerIDs, playerPosition] = createBases(
const [playerIDs, playerPosition] = createBases(
...playerPlacementRandom(
sortAllPlayers(),
[
@ -148,7 +148,7 @@ if (!isNomad())
true);
g_Map.log("Flatten the initial CC area");
for (let position of playerPosition)
for (const position of playerPosition)
createArea(
new ClumpPlacer(diskArea(defaultPlayerBaseRadius() * 0.8), 0.95, 0.6, Infinity, position),
new SmoothElevationPainter(ELEVATION_SET, g_Map.getHeight(position), 6));

View File

@ -32,25 +32,25 @@ const heightLake = -4;
const heightLand = 3;
const heightHill = 25;
var g_Map = new RandomMap(heightLand, tSnowA);
const g_Map = new RandomMap(heightLand, tSnowA);
const numPlayers = getNumPlayers();
const mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
const mapBounds = g_Map.getBounds();
var clPlayer = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clWater = g_Map.createTileClass();
var clIsland = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clWater = g_Map.createTileClass();
const clIsland = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
var startAngle = randomAngle();
const startAngle = randomAngle();
placePlayerBases({
"PlayerPlacement": [
@ -97,7 +97,7 @@ paintTileClassBasedOnHeight(-Infinity, 0.5, Elevation_ExcludeMin_ExcludeMax, clW
g_Map.log("Creating shores");
for (let i = 0; i < scaleByMapSize(20, 120); ++i)
{
let position = new Vector2D(fractionToTiles(randFloat(0.1, 0.9)), fractionToTiles(randFloat(0.67, 0.74))).rotateAround(startAngle, mapCenter).round();
const position = new Vector2D(fractionToTiles(randFloat(0.1, 0.9)), fractionToTiles(randFloat(0.67, 0.74))).rotateAround(startAngle, mapCenter).round();
createArea(
new ChainPlacer(1, Math.floor(scaleByMapSize(4, 6)), Math.floor(scaleByMapSize(16, 30)), Infinity, position),
[
@ -150,16 +150,16 @@ createAreas(
);
g_Map.log("Creating forests");
var [forestTrees, stragglerTrees] = getTreeCounts(100, 625, 0.7);
var types = [
const [forestTrees, stragglerTrees] = getTreeCounts(100, 625, 0.7);
const types = [
[[tSnowA, tSnowA, tSnowA, tSnowA, pForestD], [tSnowA, tSnowA, tSnowA, pForestD]],
[[tSnowA, tSnowA, tSnowA, tSnowA, pForestS], [tSnowA, tSnowA, tSnowA, pForestS]]
];
var size = forestTrees / (scaleByMapSize(3,6) * numPlayers);
const forestSize = forestTrees / (scaleByMapSize(3,6) * numPlayers);
var num = Math.floor(size / types.length);
for (let type of types)
const num = Math.floor(forestSize / types.length);
for (const type of types)
createAreas(
new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), forestTrees / (num * Math.floor(scaleByMapSize(2, 4))), Infinity),
[
@ -179,7 +179,7 @@ createObjectGroupsDeprecated(
Engine.SetProgress(70);
g_Map.log("Creating dirt patches");
for (let size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)])
for (const size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)])
createAreas(
new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), size, 0.5),
[
@ -194,7 +194,7 @@ for (let size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8,
clDirt, 16),
scaleByMapSize(20, 80));
for (let size of [scaleByMapSize(2, 4), scaleByMapSize(3, 7), scaleByMapSize(5, 15)])
for (const size of [scaleByMapSize(2, 4), scaleByMapSize(3, 7), scaleByMapSize(5, 15)])
createAreas(
new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), size, 0.5),
[
@ -210,7 +210,7 @@ for (let size of [scaleByMapSize(2, 4), scaleByMapSize(3, 7), scaleByMapSize(5,
scaleByMapSize(20, 80));
g_Map.log("Creating stone mines");
var group = new SimpleGroup([new SimpleObject(oStoneSmall, 0, 2, 0, 4, 0, 2 * Math.PI, 1), new SimpleObject(oStoneLarge, 1, 1, 0, 4, 0, 2 * Math.PI, 4)], true, clRock);
let group = new SimpleGroup([new SimpleObject(oStoneSmall, 0, 2, 0, 4, 0, 2 * Math.PI, 1), new SimpleObject(oStoneLarge, 1, 1, 0, 4, 0, 2 * Math.PI, 4)], true, clRock);
createObjectGroupsDeprecated(group, 0,
avoidClasses(clWater, 3, clForest, 1, clPlayer, 20, clRock, 10, clHill, 1),
scaleByMapSize(8,32), 100

View File

@ -43,30 +43,30 @@ const heightOasisPath = 4;
const heightOffsetBump = 4;
const heightOffsetDune = 18;
var g_Map = new RandomMap(heightLand, tSand);
const g_Map = new RandomMap(heightLand, tSand);
const numPlayers = getNumPlayers();
const mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
var clPlayer = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clOasis = g_Map.createTileClass();
var clPassage = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clOasis = g_Map.createTileClass();
const clPassage = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
var waterRadius = scaleByMapSize(7, 50);
var shoreDistance = scaleByMapSize(4, 10);
var forestDistance = scaleByMapSize(6, 20);
const waterRadius = scaleByMapSize(7, 50);
const shoreDistance = scaleByMapSize(4, 10);
const forestDistance = scaleByMapSize(6, 20);
var [playerIDs, playerPosition] = playerPlacementCircle(fractionToTiles(0.35));
const [playerIDs, playerPosition] = playerPlacementCircle(fractionToTiles(0.35));
g_Map.log("Creating small oasis near the players...");
var forestDist = 1.2 * defaultPlayerBaseRadius();
const forestDist = 1.2 * defaultPlayerBaseRadius();
for (let i = 0; i < numPlayers; ++i)
{
let forestPosition;
@ -87,7 +87,7 @@ for (let i = 0; i < numPlayers; ++i)
let flowerPosition;
let reedsPosition;
do {
let waterAngle = forestAngle + randFloat(1, 5) / 3 * Math.PI;
const waterAngle = forestAngle + randFloat(1, 5) / 3 * Math.PI;
waterPosition = Vector2D.add(forestPosition, new Vector2D(6, 0).rotate(-waterAngle)).round();
flowerPosition = Vector2D.add(forestPosition, new Vector2D(3, 0).rotate(-waterAngle)).round();
reedsPosition = Vector2D.add(forestPosition, new Vector2D(5, 0).rotate(-waterAngle)).round();
@ -175,8 +175,8 @@ Engine.SetProgress(50);
if (mapSize > 150 && randBool())
{
g_Map.log("Creating path though the oasis");
let pathWidth = scaleByMapSize(7, 18);
let points = distributePointsOnCircle(2, randomAngle(), waterRadius + shoreDistance + forestDistance + pathWidth, mapCenter)[0];
const pathWidth = scaleByMapSize(7, 18);
const points = distributePointsOnCircle(2, randomAngle(), waterRadius + shoreDistance + forestDistance + pathWidth, mapCenter)[0];
createArea(
new PathPlacer(points[0], points[1], pathWidth, 0.4, 1, 0.2, 0),
[
@ -186,7 +186,7 @@ if (mapSize > 150 && randBool())
]);
}
g_Map.log("Creating some straggler trees around the passage");
var group = new SimpleGroup([new SimpleObject(ePalmTall, 1,1, 0,0),new SimpleObject(ePalmShort, 1, 2, 1, 2), new SimpleObject(aBushA, 0,2, 1,3)], true, clForest);
let group = new SimpleGroup([new SimpleObject(ePalmTall, 1,1, 0,0),new SimpleObject(ePalmShort, 1, 2, 1, 2), new SimpleObject(aBushA, 0,2, 1,3)], true, clForest);
createObjectGroupsDeprecated(group, 0, stayClasses(clPassage, 3), scaleByMapSize(60, 250), 100);
g_Map.log("Creating stone mines");
@ -237,7 +237,7 @@ Engine.SetProgress(85);
g_Map.log("Creating oasis animals");
for (let i = 0; i < scaleByMapSize(5, 30); ++i)
{
let animalPos = Vector2D.add(mapCenter, new Vector2D(forestDistance + shoreDistance + waterRadius, 0).rotate(randomAngle()));
const animalPos = Vector2D.add(mapCenter, new Vector2D(forestDistance + shoreDistance + waterRadius, 0).rotate(randomAngle()));
createObjectGroup(
new RandomGroup(
@ -255,7 +255,7 @@ for (let i = 0; i < scaleByMapSize(5, 30); ++i)
Engine.SetProgress(90);
g_Map.log("Creating bushes");
var group = new SimpleGroup(
group = new SimpleGroup(
[new SimpleObject(aBushB, 1,2, 0,2), new SimpleObject(aBushA, 2,4, 0,2)]
);
createObjectGroupsDeprecated(group, 0,
@ -263,17 +263,17 @@ createObjectGroupsDeprecated(group, 0,
scaleByMapSize(10, 40), 20
);
var objectsWaterFlora = [
const objectsWaterFlora = [
new SimpleObject(aReedsA, 5, 12, 0, 2),
new SimpleObject(aReedsB, 5, 12, 0, 2)
];
g_Map.log("Creating sand blows and beautifications");
for (var sandx = 0; sandx < mapSize; sandx += 4)
for (var sandz = 0; sandz < mapSize; sandz += 4)
for (let sandx = 0; sandx < mapSize; sandx += 4)
for (let sandz = 0; sandz < mapSize; sandz += 4)
{
let position = new Vector2D(sandx, sandz);
let height = g_Map.getHeight(position);
const position = new Vector2D(sandx, sandz);
const height = g_Map.getHeight(position);
if (height > heightSand)
{

View File

@ -39,21 +39,21 @@ const pForestO = [tForestFloor + TERRAIN_SEPARATOR + oOak, tForestFloor + TERRAI
const heightLand = 10;
const heightOffsetValley = -10;
var g_Map = new RandomMap(heightLand, tDirtMain);
const g_Map = new RandomMap(heightLand, tDirtMain);
const numPlayers = getNumPlayers();
const mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
var clPlayer = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clPatch = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
var clCP = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clPatch = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
const clCP = g_Map.createTileClass();
placePlayerBases({
"PlayerPlacement": playerPlacementCircle(fractionToTiles(0.35)),
@ -156,19 +156,19 @@ for (let i = 0; i < scaleByMapSize(20, 80); ++i)
Engine.SetProgress(35);
g_Map.log("Creating forests");
var [forestTrees, stragglerTrees] = getTreeCounts(500, 2500, 0.7);
var types = [
const [forestTrees, stragglerTrees] = getTreeCounts(500, 2500, 0.7);
const types = [
[[tDirtMain, tForestFloor, pForestO], [tForestFloor, pForestO]],
[[tDirtMain, tForestFloor, pForestO], [tForestFloor, pForestO]]
];
var size = forestTrees / (scaleByMapSize(3,6) * numPlayers);
var num = Math.floor(size / types.length);
for (let type of types)
const forestSize = forestTrees / (scaleByMapSize(3,6) * numPlayers);
const num = Math.floor(forestSize / types.length);
for (const type of types)
createAreas(
new ChainPlacer(
Math.floor(scaleByMapSize(1, 2)),
Math.floor(scaleByMapSize(2, 5)),
Math.floor(size / Math.floor(scaleByMapSize(8, 3))),
Math.floor(forestSize / Math.floor(scaleByMapSize(8, 3))),
Infinity),
[
new LayeredPainter(type, [2]),
@ -229,7 +229,7 @@ createObjectGroupsDeprecated(
50);
g_Map.log("Creating small stone quarries");
var group = new SimpleGroup([new SimpleObject(oStoneSmall, 2, 5, 1, 3), new RandomObject(aBushes, 2, 4, 0, 2)], true, clRock);
let group = new SimpleGroup([new SimpleObject(oStoneSmall, 2, 5, 1, 3), new RandomObject(aBushes, 2, 4, 0, 2)], true, clRock);
createObjectGroupsDeprecated(group, 0,
stayClasses(clCP, 6),
5*scaleByMapSize(5,30), 50

View File

@ -47,26 +47,26 @@ const heightIsland = 6;
const heightHill = 15;
const heightOffsetBump = 2;
var g_Map = new RandomMap(heightLand, tHill);
const g_Map = new RandomMap(heightLand, tHill);
const numPlayers = getNumPlayers();
const mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
const mapBounds = g_Map.getBounds();
var clPlayer = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clWater = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
var clGrass = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clIsland = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clWater = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
const clGrass = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clIsland = g_Map.createTileClass();
var startAngle = randIntInclusive(0, 3) * Math.PI / 2;
const startAngle = randIntInclusive(0, 3) * Math.PI / 2;
placePlayerBases({
"PlayerPlacement": [
@ -138,8 +138,8 @@ createAreas(
scaleByMapSize(1, 4) * numPlayers * 3);
g_Map.log("Creating forests");
var [forestTrees, stragglerTrees] = getTreeCounts(500, 2500, 0.5);
var num = scaleByMapSize(10,42);
const [forestTrees, stragglerTrees] = getTreeCounts(500, 2500, 0.5);
const num = scaleByMapSize(10,42);
createAreas(
new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), forestTrees / (num * Math.floor(scaleByMapSize(2, 5))), 0.5),
[
@ -152,7 +152,7 @@ createAreas(
Engine.SetProgress(50);
g_Map.log("Creating grass patches");
for (let size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)])
for (const size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)])
createAreas(
new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), size, 0.5),
[
@ -166,7 +166,7 @@ for (let size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8,
Engine.SetProgress(55);
g_Map.log("Creating dirt patches");
for (let size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)])
for (const size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)])
createAreas(
new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), size, 0.5),
[
@ -193,12 +193,12 @@ createAreas(
100);
g_Map.log("Creating cyprus mines");
var mines = [
const mines = [
new SimpleGroup([new SimpleObject(oStoneSmall, 0, 2, 0, 4, 0, 2 * Math.PI, 1), new SimpleObject(oStoneLarge, 1, 1, 0, 4, 0, 2 * Math.PI, 4)], true, clRock),
new SimpleGroup([new SimpleObject(oMetalLarge, 1, 1, 0, 4)], true, clMetal),
new SimpleGroup([new SimpleObject(oStoneSmall, 2, 5, 1, 3)], true, clRock)
];
for (let mine of mines)
for (const mine of mines)
createObjectGroups(
mine,
0,
@ -209,7 +209,7 @@ for (let mine of mines)
scaleByMapSize(4, 16));
g_Map.log("Creating stone mines");
var group = new SimpleGroup([new SimpleObject(oStoneSmall, 0, 2, 0, 4, 0, 2 * Math.PI, 1), new SimpleObject(oStoneLarge, 1, 1, 0, 4, 0, 2 * Math.PI, 4)], true, clRock);
let group = new SimpleGroup([new SimpleObject(oStoneSmall, 0, 2, 0, 4, 0, 2 * Math.PI, 1), new SimpleObject(oStoneLarge, 1, 1, 0, 4, 0, 2 * Math.PI, 4)], true, clRock);
createObjectGroupsDeprecated(group, 0,
avoidClasses(clForest, 1, clPlayer, 20, clRock, 10, clWater, 3, clHill, 1),
scaleByMapSize(4,16), 100
@ -293,12 +293,12 @@ createObjectGroupsDeprecated(group, 0,
);
Engine.SetProgress(90);
var stragglerTreeConfig = [
const stragglerTreeConfig = [
[1, avoidClasses(clForest, 0, clWater, 4, clPlayer, 8, clMetal, 6, clHill, 1)],
[3, [stayClasses(clIsland, 9), avoidClasses(clRock, 4, clMetal, 4)]]
];
for (let [amount, constraint] of stragglerTreeConfig)
for (const [amount, constraint] of stragglerTreeConfig)
createStragglerTrees(
[oDatePalm, oSDatePalm, oCarob, oFanPalm, oPoplar, oCypress],
constraint,

View File

@ -1,51 +1,51 @@
Engine.LoadLibrary("rmgen");
Engine.LoadLibrary("rmgen-common");
var tPrimary = ["alpine_snow_01"];
var tSecondary = "alpine_snow_02";
var tShore = "alpine_ice_01";
var tWater = "alpine_ice_01";
const tPrimary = ["alpine_snow_01"];
const tSecondary = "alpine_snow_02";
const tShore = "alpine_ice_01";
const tWater = "alpine_ice_01";
var oArcticFox = "gaia/fauna_fox_arctic";
var oArcticWolf = "gaia/fauna_wolf_arctic_violent";
var oMuskox = "gaia/fauna_muskox";
var oWalrus = "gaia/fauna_walrus";
var oWhaleFin = "gaia/fauna_whale_fin";
var oWhaleHumpback = "gaia/fauna_whale_humpback";
var oFish = "gaia/fish/generic";
var oStoneLarge = "gaia/rock/polar_01";
var oStoneSmall = "gaia/rock/alpine_small";
var oMetalLarge = "gaia/ore/polar_01";
var oWoodTreasure = "gaia/treasure/wood";
var oMarket = "skirmish/structures/default_market";
const oArcticFox = "gaia/fauna_fox_arctic";
const oArcticWolf = "gaia/fauna_wolf_arctic_violent";
const oMuskox = "gaia/fauna_muskox";
const oWalrus = "gaia/fauna_walrus";
const oWhaleFin = "gaia/fauna_whale_fin";
const oWhaleHumpback = "gaia/fauna_whale_humpback";
const oFish = "gaia/fish/generic";
const oStoneLarge = "gaia/rock/polar_01";
const oStoneSmall = "gaia/rock/alpine_small";
const oMetalLarge = "gaia/ore/polar_01";
const oWoodTreasure = "gaia/treasure/wood";
const oMarket = "skirmish/structures/default_market";
var aRockLarge = "actor|geology/stone_granite_med.xml";
var aRockMedium = "actor|geology/stone_granite_med.xml";
var aIceberg = "actor|props/special/eyecandy/iceberg.xml";
const aRockLarge = "actor|geology/stone_granite_med.xml";
const aRockMedium = "actor|geology/stone_granite_med.xml";
const aIceberg = "actor|props/special/eyecandy/iceberg.xml";
var heightSeaGround = -10;
var heightLand = 2;
var heightCliff = 3;
const heightSeaGround = -10;
const heightLand = 2;
const heightCliff = 3;
var g_Map = new RandomMap(heightLand, tPrimary);
const g_Map = new RandomMap(heightLand, tPrimary);
const numPlayers = getNumPlayers();
const mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
var clPlayer = g_Map.createTileClass();
var clWater = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
var clArcticWolf = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clWater = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
const clArcticWolf = g_Map.createTileClass();
var [playerIDs, playerPosition] = playerPlacementCircle(fractionToTiles(0.35));
const [playerIDs, playerPosition] = playerPlacementCircle(fractionToTiles(0.35));
var treasures = [{
const treasures = [{
"template": oWoodTreasure,
"count": isNomad() ? 16 : 14
}];
@ -54,7 +54,7 @@ g_Map.log("Creating player markets");
if (!isNomad())
for (let i = 0; i < numPlayers; ++i)
{
let marketPos = Vector2D.add(playerPosition[i], new Vector2D(12, 0).rotate(randomAngle())).round();
const marketPos = Vector2D.add(playerPosition[i], new Vector2D(12, 0).rotate(randomAngle())).round();
g_Map.placeEntityPassable(oMarket, playerIDs[i], marketPos, BUILDING_ORIENTATION);
addCivicCenterAreaToClass(marketPos, clBaseResource);
}
@ -242,7 +242,7 @@ else
if (isNomad())
{
let constraint = avoidClasses(clWater, 4, clMetal, 4, clRock, 4, clHill, 4, clFood, 2);
const constraint = avoidClasses(clWater, 4, clMetal, 4, clRock, 4, clHill, 4, clFood, 2);
[playerIDs, playerPosition] = placePlayersNomad(clPlayer, constraint);
for (let i = 0; i < numPlayers; ++i)

View File

@ -88,8 +88,8 @@ const heightDockMax = heightScale(1);
const heightLavaVesuv = heightScale(38);
const heightMountains = 140;
var g_Map = new RandomMap(0, g_Terrains.mainTerrain);
var mapCenter = g_Map.getCenter();
const g_Map = new RandomMap(0, g_Terrains.mainTerrain);
const mapCenter = g_Map.getCenter();
initTileClasses(["decorative", "lava", "dock"]);
@ -137,7 +137,7 @@ createArea(
Engine.SetProgress(45);
g_Map.log("Painting lava");
var areaVesuv = createArea(
const areaVesuv = createArea(
new RectPlacer(new Vector2D(mapCenter.x, fractionToTiles(0.3)), new Vector2D(fractionToTiles(0.7), fractionToTiles(0.15))),
[
new LayeredPainter([g_Terrains.lavaOuter,g_Terrains.lavaInner, g_Terrains.lavaCenter], [scaleByMapSize(1, 3), 2]),
@ -164,7 +164,7 @@ Engine.SetProgress(48);
if (!isNomad())
{
g_Map.log("Placing players");
let [playerIDs, playerPosition] = createBases(
const [playerIDs, playerPosition] = createBases(
...playerPlacementRandom(
sortAllPlayers(),
[
@ -174,7 +174,7 @@ if (!isNomad())
false);
g_Map.log("Flatten the initial CC area");
for (let position of playerPosition)
for (const position of playerPosition)
createArea(
new ClumpPlacer(diskArea(defaultPlayerBaseRadius() * 0.8), 0.95, 0.6, Infinity, position),
new SmoothElevationPainter(ELEVATION_SET, g_Map.getHeight(position), 6));
@ -182,11 +182,11 @@ if (!isNomad())
Engine.SetProgress(50);
g_Map.log("Placing docks");
var dockTypes = [
const dockTypes = [
{ "template": g_Gaia.dock, "count": scaleByMapSize(1, 2) },
{ "template": g_Gaia.dockRubble, "count": scaleByMapSize(2, 3) }
];
for (let dockType of dockTypes)
for (const dockType of dockTypes)
placeDocks(
dockType.template,
0,

View File

@ -73,36 +73,36 @@ const heightMountain = heightHighRocks + 20;
const heightOffsetHill = 7;
const heightOffsetHillRandom = 2;
var g_Map = new RandomMap(heightInit, tGrass);
const g_Map = new RandomMap(heightInit, tGrass);
const numPlayers = getNumPlayers();
const mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
var clPass = g_Map.createTileClass();
var clPyrenneans = g_Map.createTileClass();
var clPlayer = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clWater = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
const clPass = g_Map.createTileClass();
const clPyrenneans = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clWater = g_Map.createTileClass();
var startAngle = randomAngle();
var oceanAngle = startAngle + randFloat(-1, 1) * Math.PI / 12;
const startAngle = randomAngle();
const oceanAngle = startAngle + randFloat(-1, 1) * Math.PI / 12;
var mountainLength = fractionToTiles(0.68);
var mountainWidth = scaleByMapSize(15, 55);
const mountainLength = fractionToTiles(0.68);
const mountainWidth = scaleByMapSize(15, 55);
var mountainPeaks = 100 * scaleByMapSize(1, 10);
var mountainOffset = randFloat(-1, 1) * scaleByMapSize(1, 12);
const mountainPeaks = 100 * scaleByMapSize(1, 10);
const mountainOffset = randFloat(-1, 1) * scaleByMapSize(1, 12);
var passageLength = scaleByMapSize(8, 50);
const passageLength = scaleByMapSize(8, 50);
var terrainPerHeight = [
const terrainPerHeight = [
{
"maxHeight": heightGrass,
"steepness": 5,
@ -142,16 +142,16 @@ var terrainPerHeight = [
];
g_Map.log("Creating initial sinusoidal noise");
var baseHeights = [];
for (var ix = 0; ix < mapSize; ix++)
let baseHeights = [];
for (let ix = 0; ix < mapSize; ix++)
{
baseHeights.push([]);
for (var iz = 0; iz < mapSize; iz++)
for (let iz = 0; iz < mapSize; iz++)
{
let position = new Vector2D(ix, iz);
const position = new Vector2D(ix, iz);
if (g_Map.inMapBounds(position))
{
let height = heightBase + randFloat(-1, 1) + scaleByMapSize(1, 3) * (Math.cos(ix / scaleByMapSize(5, 30)) + Math.sin(iz / scaleByMapSize(5, 30)));
const height = heightBase + randFloat(-1, 1) + scaleByMapSize(1, 3) * (Math.cos(ix / scaleByMapSize(5, 30)) + Math.sin(iz / scaleByMapSize(5, 30)));
g_Map.setHeight(position, height);
baseHeights[ix].push(height);
}
@ -160,8 +160,8 @@ for (var ix = 0; ix < mapSize; ix++)
}
}
var playerIDs = sortAllPlayers();
var playerPosition = playerPlacementArcs(
const playerIDs = sortAllPlayers();
const playerPosition = playerPlacementArcs(
playerIDs,
mapCenter,
fractionToTiles(0.35),
@ -198,9 +198,9 @@ placePlayerBases({
Engine.SetProgress(30);
g_Map.log("Creating the pyreneans");
var mountainVec = new Vector2D(mountainLength, 0).rotate(-startAngle);
var mountainStart = Vector2D.sub(mapCenter, Vector2D.div(mountainVec, 2));
var mountainDirection = mountainVec.clone().normalize();
const mountainVec = new Vector2D(mountainLength, 0).rotate(-startAngle);
const mountainStart = Vector2D.sub(mapCenter, Vector2D.div(mountainVec, 2));
const mountainDirection = mountainVec.clone().normalize();
createPyreneans();
paintTileClassBasedOnHeight(heightPyreneans, Infinity, Elevation_ExcludeMin_ExcludeMax, clPyrenneans);
Engine.SetProgress(40);
@ -222,23 +222,23 @@ function createPyreneans()
{
for (let peak = 0; peak < mountainPeaks; ++peak)
{
let peakPosition = peak / mountainPeaks;
let peakHeight = randFloat(0, 10);
const peakPosition = peak / mountainPeaks;
const peakHeight = randFloat(0, 10);
for (let distance = 0; distance < mountainWidth; distance += 1/3)
{
let rest = 2 * (1 - distance / mountainWidth);
const rest = 2 * (1 - distance / mountainWidth);
let sigmoidX =
const sigmoidX =
- 1 * (rest - 1.9) +
- 4 *
(rest - randFloat(0.9, 1.1)) *
(rest - randFloat(0.9, 1.1)) *
(rest - randFloat(0.9, 1.1));
for (let direction of [-1, 1])
for (const direction of [-1, 1])
{
let pos = Vector2D.sum([
const pos = Vector2D.sum([
Vector2D.add(mountainStart, Vector2D.mult(mountainDirection, peakPosition * mountainLength)),
new Vector2D(mountainOffset, 0).rotate(-peakPosition * Math.PI * 4),
new Vector2D(distance, 0).rotate(-startAngle - direction * Math.PI / 2)
@ -251,14 +251,14 @@ function createPyreneans()
}
g_Map.log("Creating passages");
var passageLocation = 0.35;
var passageVec = mountainDirection.perpendicular().mult(passageLength);
const passageLocation = 0.35;
const passageVec = mountainDirection.perpendicular().mult(passageLength);
for (let passLoc of [passageLocation, 1 - passageLocation])
for (let direction of [1, -1])
for (const passLoc of [passageLocation, 1 - passageLocation])
for (const direction of [1, -1])
{
let passageStart = Vector2D.add(mountainStart, Vector2D.mult(mountainVec, passLoc));
let passageEnd = Vector2D.add(passageStart, Vector2D.mult(passageVec, direction));
const passageStart = Vector2D.add(mountainStart, Vector2D.mult(mountainVec, passLoc));
const passageEnd = Vector2D.add(passageStart, Vector2D.mult(passageVec, direction));
createPassage({
"start": passageStart,
@ -279,7 +279,7 @@ createArea(
new NearTileClassConstraint(clPyrenneans, 1));
g_Map.log("Creating oceans");
for (let ocean of distributePointsOnCircle(2, oceanAngle, fractionToTiles(0.48), mapCenter)[0])
for (const ocean of distributePointsOnCircle(2, oceanAngle, fractionToTiles(0.48), mapCenter)[0])
createArea(
new ClumpPlacer(diskArea(fractionToTiles(0.18)), 0.9, 0.05, Infinity, ocean),
[
@ -305,12 +305,12 @@ createAreas(
avoidClasses(clWater, 5, clPlayer, 20, clBaseResource, 6, clPyrenneans, 2), scaleByMapSize(5, 35));
g_Map.log("Creating forests");
var types = [[tForestTransition, pForestLandVeryLight, pForestLandLight, pForestLand]];
var size = scaleByMapSize(40, 115) * Math.PI;
var num = Math.floor(scaleByMapSize(8,40) / types.length);
for (let type of types)
const types = [[tForestTransition, pForestLandVeryLight, pForestLandLight, pForestLand]];
const forestSize = scaleByMapSize(40, 115) * Math.PI;
let num = Math.floor(scaleByMapSize(8,40) / types.length);
for (const type of types)
createAreas(
new ClumpPlacer(size, 0.2, 0.1, Infinity),
new ClumpPlacer(forestSize, 0.2, 0.1, Infinity),
[
new LayeredPainter(type, [scaleByMapSize(1, 2), scaleByMapSize(3, 6), scaleByMapSize(3, 6)]),
new TileClassPainter(clForest)
@ -320,14 +320,14 @@ for (let type of types)
Engine.SetProgress(60);
g_Map.log("Creating lone trees");
var num = scaleByMapSize(80,400);
num = scaleByMapSize(80,400);
var group = new SimpleGroup([new SimpleObject(oPine, 1,2, 1,3),new SimpleObject(oBeech, 1,2, 1,3)], true, clForest);
let group = new SimpleGroup([new SimpleObject(oPine, 1,2, 1,3),new SimpleObject(oBeech, 1,2, 1,3)], true, clForest);
createObjectGroupsDeprecated(group, 0, avoidClasses(clWater, 3, clForest, 1, clPlayer, 8,clPyrenneans, 1), num, 20 );
g_Map.log("Painting terrain by height and slope");
for (let i = 0; i < terrainPerHeight.length; ++i)
for (let steep of [false, true])
for (const steep of [false, true])
createArea(
new MapBoundsPlacer(),
new TerrainPainter(steep ? terrainPerHeight[i].terrainSteep : terrainPerHeight[i].terrainGround),
@ -342,11 +342,11 @@ for (let i = 0; i < terrainPerHeight.length; ++i)
for (let x = 0; x < mapSize; ++x)
for (let z = 0; z < mapSize; ++z)
{
let position = new Vector2D(x, z);
let height = g_Map.getHeight(position);
let heightDiff = g_Map.getSlope(position);
const position = new Vector2D(x, z);
const height = g_Map.getHeight(position);
const heightDiff = g_Map.getSlope(position);
let terrainShore = getShoreTerrain(position, height, heightDiff);
const terrainShore = getShoreTerrain(position, height, heightDiff);
if (terrainShore)
createTerrain(terrainShore).place(position);
}
@ -367,7 +367,7 @@ function getShoreTerrain(position, height, heightDiff)
}
g_Map.log("Creating dirt patches");
for (let size of [scaleByMapSize(3, 20), scaleByMapSize(5, 40), scaleByMapSize(8, 60)])
for (const size of [scaleByMapSize(3, 20), scaleByMapSize(5, 40), scaleByMapSize(8, 60)])
createAreas(
new ClumpPlacer(size, 0.3, 0.06, 0.5),
[
@ -378,7 +378,7 @@ for (let size of [scaleByMapSize(3, 20), scaleByMapSize(5, 40), scaleByMapSize(8
scaleByMapSize(15, 45));
g_Map.log("Creating grass patches");
for (let size of [scaleByMapSize(2, 32), scaleByMapSize(3, 48), scaleByMapSize(5, 80)])
for (const size of [scaleByMapSize(2, 32), scaleByMapSize(3, 48), scaleByMapSize(5, 80)])
createAreas(
new ClumpPlacer(size, 0.3, 0.06, 0.5),
new TerrainPainter(tLushGrass),
@ -389,7 +389,7 @@ Engine.SetProgress(70);
// making more in dirt areas so as to appear different
g_Map.log("Creating small grass tufts");
var group = new SimpleGroup( [new SimpleObject(aGrassShort, 1,2, 0,1, -Math.PI / 8, Math.PI / 8)] );
group = new SimpleGroup( [new SimpleObject(aGrassShort, 1,2, 0,1, -Math.PI / 8, Math.PI / 8)] );
createObjectGroupsDeprecated(group, 0, avoidClasses(clWater, 2, clHill, 2, clPlayer, 5, clDirt, 0, clPyrenneans,2), scaleByMapSize(13, 200) );
createObjectGroupsDeprecated(group, 0, stayClasses(clDirt,1), scaleByMapSize(13, 200),10);

View File

@ -77,7 +77,7 @@ Engine.SetProgress(25);
g_Map.log("Creating shallows");
for (let i = 0; i < scaleByMapSize(5, 12); ++i)
{
let x = fractionToTiles(randFloat(0, 1));
const x = fractionToTiles(randFloat(0, 1));
createPassage({
"start": new Vector2D(x, mapBounds.bottom).rotateAround(riverAngle + Math.PI / 2 * randFloat(0.8, 1.2), mapCenter),
"end": new Vector2D(x, mapBounds.top).rotateAround(riverAngle + Math.PI / 2 * randFloat(0.8, 1.2), mapCenter),

View File

@ -59,8 +59,8 @@ const heightWaterLevel = heightScale(0);
const heightShoreline = heightScale(0.5);
const heightHills = heightScale(16);
var g_Map = new RandomMap(0, g_Terrains.mainTerrain);
var mapCenter = g_Map.getCenter();
const g_Map = new RandomMap(0, g_Terrains.mainTerrain);
const mapCenter = g_Map.getCenter();
initTileClasses(["shoreline"]);
@ -120,7 +120,7 @@ Engine.SetProgress(45);
if (!isNomad())
{
g_Map.log("Placing players");
let [playerIDs, playerPosition] = createBases(
const [playerIDs, playerPosition] = createBases(
...playerPlacementRandom(
sortAllPlayers(),
[
@ -130,7 +130,7 @@ if (!isNomad())
true);
g_Map.log("Flatten the initial CC area");
for (let position of playerPosition)
for (const position of playerPosition)
createArea(
new ClumpPlacer(diskArea(defaultPlayerBaseRadius() * 0.8), 0.95, 0.6, Infinity, position),
new SmoothElevationPainter(ELEVATION_SET, g_Map.getHeight(position), 6));
@ -294,7 +294,7 @@ addElements([
Engine.SetProgress(80);
g_Map.log("Painting dirt patches");
var dirtPatches = [
const dirtPatches = [
{
"sizes": [2, 4],
"count": scaleByMapSize(2, 5),
@ -306,7 +306,7 @@ var dirtPatches = [
"terrain": g_Terrains.additionalDirt2
}
];
for (let dirtPatch of dirtPatches)
for (const dirtPatch of dirtPatches)
createPatches(
dirtPatch.sizes,
dirtPatch.terrain,

View File

@ -40,18 +40,18 @@ const heightLand = 1;
const heightOffsetBumpWater = 1;
const heightOffsetBumpLand = 2;
var g_Map = new RandomMap(heightLand, tGrass);
const g_Map = new RandomMap(heightLand, tGrass);
const numPlayers = getNumPlayers();
var clPlayer = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clWater = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clWater = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
placePlayerBases({
"PlayerPlacement": playerPlacementCircle(fractionToTiles(0.35)),
@ -116,14 +116,14 @@ createAreas(
scaleByMapSize(50, 100));
g_Map.log("Creating forests");
var [forestTrees, stragglerTrees] = getTreeCounts(500, 2500, 0.7);
var types = [
const [forestTrees, stragglerTrees] = getTreeCounts(500, 2500, 0.7);
const types = [
[[tForestFloor, tGrass, pForestD], [tForestFloor, pForestD]],
[[tForestFloor, tGrass, pForestP], [tForestFloor, pForestP]]
];
var size = forestTrees / (scaleByMapSize(3,6) * numPlayers);
var num = Math.floor(size / types.length);
for (let type of types)
const forestSize = forestTrees / (scaleByMapSize(3,6) * numPlayers);
const num = Math.floor(forestSize / types.length);
for (const type of types)
createAreas(
new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), forestTrees / (num * Math.floor(scaleByMapSize(2, 4))), Infinity),
[
@ -135,7 +135,7 @@ for (let type of types)
Engine.SetProgress(50);
g_Map.log("Creating mud patches");
for (let size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)])
for (const size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)])
createAreas(
new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), size, Infinity),
[
@ -146,7 +146,7 @@ for (let size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8,
scaleByMapSize(15, 45));
g_Map.log("Creating stone mines");
var group = new SimpleGroup([new SimpleObject(oStoneSmall, 0, 2, 0, 4, 0, 2 * Math.PI, 1), new SimpleObject(oStoneLarge, 1, 1, 0, 4, 0, 2 * Math.PI, 4)], true, clRock);
let group = new SimpleGroup([new SimpleObject(oStoneSmall, 0, 2, 0, 4, 0, 2 * Math.PI, 1), new SimpleObject(oStoneLarge, 1, 1, 0, 4, 0, 2 * Math.PI, 4)], true, clRock);
createObjectGroupsDeprecated(group, 0,
[avoidClasses(clWater, 0, clForest, 1, clPlayer, 20, clRock, 10)],
scaleByMapSize(4,16), 100

View File

@ -47,49 +47,49 @@ const heightShoreBlend = 2.8;
const heightLand = 3;
const heightHill = 25;
var g_Map = new RandomMap(heightSeaGround, tGrass);
const g_Map = new RandomMap(heightSeaGround, tGrass);
const numPlayers = getNumPlayers();
const mapCenter = g_Map.getCenter();
const mapBounds = g_Map.getBounds();
var clPlayer = g_Map.createTileClass();
var clPlayerTerritory = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clWater = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
var clGaia = g_Map.createTileClass();
var clStrip = [];
const clPlayer = g_Map.createTileClass();
const clPlayerTerritory = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clWater = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
const clGaia = g_Map.createTileClass();
const clStrip = [];
var startAngle = randomAngle();
var connectPlayers = randBool();
const startAngle = randomAngle();
const connectPlayers = randBool();
// Map layout
var stripWidthsLeft = connectPlayers ?
const stripWidthsLeft = connectPlayers ?
[[0.03, 0.09], [0.14, 0.25], [0.36, 0.46]] :
[[0, 0.06], [0.12, 0.23], [0.33, 0.43]];
// Mirror
var stripWidthsRight = clone(stripWidthsLeft);
let stripWidthsRight = clone(stripWidthsLeft);
stripWidthsRight.reverse();
stripWidthsRight = stripWidthsRight.map(strip => [1 - strip[1], 1 - strip[0]]);
var stripWidths = stripWidthsLeft.concat(stripWidthsRight);
const stripWidths = stripWidthsLeft.concat(stripWidthsRight);
g_Map.log("Creating strips");
for (let i = 0; i < stripWidths.length; ++i)
{
clStrip[i] = g_Map.createTileClass();
let isPlayerStrip = i == 2 || i == 3;
const isPlayerStrip = i == 2 || i == 3;
for (let j = 0; j < scaleByMapSize(20, 100); ++j)
{
let position = new Vector2D(
const position = new Vector2D(
randFloat(mapBounds.bottom, mapBounds.top),
fractionToTiles(randFloat(...stripWidths[i]))).rotateAround(startAngle, mapCenter).round();
@ -109,13 +109,13 @@ for (let i = 0; i < stripWidths.length; ++i)
}
Engine.SetProgress(20);
var playerPosition = playerPlacementLine(startAngle, mapCenter, fractionToTiles(1 - stripWidthsLeft[2][0] - stripWidthsLeft[2][1]));
const playerPosition = playerPlacementLine(startAngle, mapCenter, fractionToTiles(1 - stripWidthsLeft[2][0] - stripWidthsLeft[2][1]));
// Either left vs right or top vs bottom
var playerIDs = randBool() ? sortAllPlayers() : primeSortAllPlayers();
const playerIDs = randBool() ? sortAllPlayers() : primeSortAllPlayers();
g_Map.log("Ensuring player territory");
var playerRadius = scaleByMapSize(12, 20);
const playerRadius = scaleByMapSize(12, 20);
for (let i = 0; i < numPlayers; ++i)
createArea(
new ChainPlacer(1, 6, 40, 1, playerPosition[i], 0, [Math.floor(playerRadius)]),
@ -156,7 +156,7 @@ placePlayerBases({
});
Engine.SetProgress(35);
var areaWater = createArea(
const areaWater = createArea(
new HeightPlacer(Elevation_IncludeMin_ExcludeMax, -Infinity, heightWaterLevel),
[
new TerrainPainter(tWater),
@ -222,15 +222,15 @@ createBumps(avoidClasses(clPlayer, 8, clWater, 2), scaleByMapSize(20, 150), 2, 8
Engine.SetProgress(50);
g_Map.log("Creating forests");
var [forestTrees, stragglerTrees] = getTreeCounts(1000, 4000, 0.7);
var types = [
const [forestTrees, stragglerTrees] = getTreeCounts(1000, 4000, 0.7);
const types = [
[[tGrass, tGrass, tGrass, tGrass, pForestD], [tGrass, tGrass, tGrass, pForestD]],
[[tGrass, tGrass, tGrass, tGrass, pForestP1], [tGrass, tGrass, tGrass, pForestP1]],
[[tGrass, tGrass, tGrass, tGrass, pForestP2], [tGrass, tGrass, tGrass, pForestP2]]
];
var size = forestTrees / (scaleByMapSize(3, 6) * numPlayers);
var num = Math.floor(size / types.length);
for (let type of types)
const forestSize = forestTrees / (scaleByMapSize(3, 6) * numPlayers);
const num = Math.floor(forestSize / types.length);
for (const type of types)
createAreas(
new ChainPlacer(
1,
@ -266,7 +266,7 @@ createStragglerTrees(
Engine.SetProgress(60);
g_Map.log("Creating grass patches");
for (let size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)])
for (const size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)])
createAreas(
new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), size, 0.5),
[
@ -283,7 +283,7 @@ for (let size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8,
scaleByMapSize(20, 80));
g_Map.log("Creating dirt patches");
for (let size of [scaleByMapSize(2, 4), scaleByMapSize(3, 7), scaleByMapSize(5, 15)])
for (const size of [scaleByMapSize(2, 4), scaleByMapSize(3, 7), scaleByMapSize(5, 15)])
createAreas(
new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), size, 0.5),
[

View File

@ -15,8 +15,8 @@ const tHill = g_Terrains.hill;
const tRoad = g_Terrains.road;
const tRoadWild = g_Terrains.roadWild;
const tTier4Terrain = g_Terrains.tier4Terrain;
var tShore = g_Terrains.shore;
var tWater = g_Terrains.water;
let tShore = g_Terrains.shore;
let tWater = g_Terrains.water;
if (currentBiome() == "generic/india")
{
tShore = "tropic_dirt_b_plants";
@ -52,24 +52,24 @@ const heightSeaGround = -3;
const heightShallows = -1;
const heightLand = 1;
var g_Map = new RandomMap(heightLand, tMainTerrain);
const g_Map = new RandomMap(heightLand, tMainTerrain);
const numPlayers = getNumPlayers();
const mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
var clPlayer = g_Map.createTileClass();
var clHill = g_Map.createTileClass();
var clForest = g_Map.createTileClass();
var clWater = g_Map.createTileClass();
var clDirt = g_Map.createTileClass();
var clRock = g_Map.createTileClass();
var clMetal = g_Map.createTileClass();
var clFood = g_Map.createTileClass();
var clBaseResource = g_Map.createTileClass();
var clShallow = g_Map.createTileClass();
const clPlayer = g_Map.createTileClass();
const clHill = g_Map.createTileClass();
const clForest = g_Map.createTileClass();
const clWater = g_Map.createTileClass();
const clDirt = g_Map.createTileClass();
const clRock = g_Map.createTileClass();
const clMetal = g_Map.createTileClass();
const clFood = g_Map.createTileClass();
const clBaseResource = g_Map.createTileClass();
const clShallow = 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],
@ -109,15 +109,15 @@ createArea(
]);
g_Map.log("Creating rivers between opponents");
let numRivers = isNomad() ? randIntInclusive(4, 8) : numPlayers;
let rivers = distributePointsOnCircle(numRivers, startAngle + Math.PI / numRivers, fractionToTiles(0.5), mapCenter)[0];
const numRivers = isNomad() ? randIntInclusive(4, 8) : numPlayers;
const rivers = distributePointsOnCircle(numRivers, startAngle + Math.PI / numRivers, fractionToTiles(0.5), mapCenter)[0];
for (let i = 0; i < numRivers; ++i)
{
if (isNomad() ? randBool() : areAllies(playerIDs[i], playerIDs[(i + 1) % numPlayers]))
continue;
let shallowLocation = randFloat(0.2, 0.7);
let shallowWidth = randFloat(0.12, 0.21);
const shallowLocation = randFloat(0.2, 0.7);
const shallowWidth = randFloat(0.12, 0.21);
paintRiver({
"parallel": true,
@ -135,11 +135,11 @@ for (let i = 0; i < numRivers; ++i)
clWater.add(position);
let isShallow = height < heightShallows &&
const isShallow = height < heightShallows &&
riverFraction > shallowLocation &&
riverFraction < shallowLocation + shallowWidth;
let newHeight = isShallow ? heightShallows : Math.max(height, heightSeaGround);
const newHeight = isShallow ? heightShallows : Math.max(height, heightSeaGround);
if (g_Map.getHeight(position) < newHeight)
return;
@ -161,7 +161,7 @@ if (randBool())
else
createMountains(tCliff, avoidClasses(clPlayer, 20, clHill, 15, clWater, 2), clHill, scaleByMapSize(3, 15));
var [forestTrees, stragglerTrees] = getTreeCounts(...rBiomeTreeCount(1));
const [forestTrees, stragglerTrees] = getTreeCounts(...rBiomeTreeCount(1));
createDefaultForests(
[tMainTerrain, tForestFloor1, tForestFloor2, pForest1, pForest2],
avoidClasses(clPlayer, 20, clForest, 17, clHill, 0, clWater, 2),
@ -206,7 +206,7 @@ createBalancedStoneMines(
Engine.SetProgress(65);
var planetm = 1;
let planetm = 1;
if (currentBiome() == "generic/india")
planetm = 8;

View File

@ -32,7 +32,7 @@ function setBiome(biomeID)
loadBiomeFile(biomeID);
Engine.LoadLibrary("rmbiome/" + dirname(biomeID));
let setupBiomeFunc = global["setupBiome_" + basename(biomeID)];
const setupBiomeFunc = global["setupBiome_" + basename(biomeID)];
if (setupBiomeFunc)
setupBiomeFunc();
}
@ -42,7 +42,7 @@ function setBiome(biomeID)
*/
function loadBiomeFile(file)
{
let path = "maps/random/rmbiome/" + file + ".json";
const path = "maps/random/rmbiome/" + file + ".json";
if (!Engine.FileExists(path))
{
@ -50,10 +50,10 @@ function loadBiomeFile(file)
return;
}
let biome = Engine.ReadJSONFile(path);
const biome = Engine.ReadJSONFile(path);
let copyProperties = (from, to) => {
for (let prop in from)
const copyProperties = (from, to) => {
for (const prop in from)
{
if (from[prop] !== null && typeof from[prop] == "object" && !Array.isArray(from[prop]))
{
@ -67,7 +67,7 @@ function loadBiomeFile(file)
}
};
for (let rmsGlobal in biome)
for (const rmsGlobal in biome)
{
if (rmsGlobal == "Description")
continue;

View File

@ -95,7 +95,7 @@ function createDefaultForests(terrainSet, constraints, tileClass, totalNumberOfT
function createStragglerTrees(templateNames, constraint, tileClass, treeCount, retryFactor)
{
g_Map.log("Creating straggler trees");
for (let templateName of templateNames)
for (const templateName of templateNames)
createObjectGroupsDeprecated(
new SimpleGroup([new SimpleObject(templateName, 1, 1, 0, 3)], true, tileClass),
0,
@ -110,7 +110,7 @@ function createStragglerTrees(templateNames, constraint, tileClass, treeCount, r
*/
function createMines(objects, constraint, tileClass, count)
{
for (let object of objects)
for (const object of objects)
createObjectGroupsDeprecated(
new SimpleGroup(object, true, tileClass),
0,
@ -226,7 +226,7 @@ function createStoneMineFormation(position, templateName, terrain, radius = 2.5,
for (let i = 0; i < count; ++i)
{
let pos = Vector2D.add(position, new Vector2D(radius + randFloat(0, maxOffset), 0).rotate(-angle)).round();
const pos = Vector2D.add(position, new Vector2D(radius + randFloat(0, maxOffset), 0).rotate(-angle)).round();
g_Map.placeEntityPassable(templateName, 0, pos, randomAngle());
angle += 3/2 * Math.PI / count;
}
@ -280,28 +280,28 @@ function createDecoration(objects, counts, constraint)
*/
function placeDocks(template, playerID, count, tileClassWater, tileClassDock, heightMin, heightMax, constraints, offset, retryFactor)
{
let mapCenter = g_Map.getCenter();
const mapCenter = g_Map.getCenter();
g_Map.log("Marking dock search start area");
let areaSearchStart = createArea(
const areaSearchStart = createArea(
new DiskPlacer(fractionToTiles(0.5) - 10, mapCenter),
undefined,
avoidClasses(tileClassWater, 6));
g_Map.log("Marking dock search end area");
let areaSearchEnd = createArea(
const areaSearchEnd = createArea(
new DiskPlacer(fractionToTiles(0.5) - 10, mapCenter),
undefined,
stayClasses(tileClassWater, 20));
g_Map.log("Marking land area");
let areaLand = createArea(
const areaLand = createArea(
new MapBoundsPlacer(),
undefined,
avoidClasses(tileClassWater, 0));
g_Map.log("Marking water area");
let areaWater = createArea(
const areaWater = createArea(
new MapBoundsPlacer(),
undefined,
stayClasses(tileClassWater, 0));
@ -310,14 +310,14 @@ function placeDocks(template, playerID, count, tileClassWater, tileClassDock, he
return;
// TODO: computing the exact intersection with the waterplane would both not require us to pass reasonable heights and be more precise
let constraint = new AndConstraint(constraints);
const constraint = new AndConstraint(constraints);
g_Map.log("Placing docks");
for (let i = 0; i < count; ++i)
for (let tries = 0; tries < retryFactor; ++tries)
{
let positionLand = pickRandom(areaSearchStart.getPoints());
let positionWaterLarge = areaSearchEnd.getClosestPointTo(positionLand);
let positionDock = findLocationInDirectionBasedOnHeight(positionWaterLarge, positionLand, heightMin, heightMax, offset);
const positionLand = pickRandom(areaSearchStart.getPoints());
const positionWaterLarge = areaSearchEnd.getClosestPointTo(positionLand);
const positionDock = findLocationInDirectionBasedOnHeight(positionWaterLarge, positionLand, heightMin, heightMax, offset);
if (!positionDock)
continue;
@ -326,7 +326,7 @@ function placeDocks(template, playerID, count, tileClassWater, tileClassDock, he
if (!g_Map.inMapBounds(positionDock) || !constraint.allows(positionDock))
continue;
let angle = positionDock.angleTo(Vector2D.average(new DiskPlacer(8, positionDock).place(stayClasses(tileClassWater, 0))));
const angle = positionDock.angleTo(Vector2D.average(new DiskPlacer(8, positionDock).place(stayClasses(tileClassWater, 0))));
g_Map.placeEntityPassable(template, playerID, positionDock, -angle + Math.PI / 2);
tileClassDock.add(positionDock);

View File

@ -46,7 +46,7 @@ function createHills(terrainset, constraints, tileClass, count, minSize, maxSize
function createMountains(terrain, constraints, tileClass, count, maxHeight, minRadius, maxRadius, numCircles)
{
g_Map.log("Creating mountains");
let mapSize = g_Map.getSize();
const mapSize = g_Map.getSize();
for (let i = 0; i < (count || scaleByMapSize(1, 4) * getNumPlayers()); ++i)
createMountain(
@ -67,8 +67,8 @@ function createMountains(terrain, constraints, tileClass, count, maxHeight, minR
*/
function createMountain(maxHeight, minRadius, maxRadius, numCircles, constraints, x, z, terrain, tileClass, fcc = 0, q = [])
{
let position = new Vector2D(x, z);
let constraint = new AndConstraint(constraints);
const position = new Vector2D(x, z);
const constraint = new AndConstraint(constraints);
if (!g_Map.inMapBounds(position) || !constraint.allows(position))
return;
@ -76,7 +76,7 @@ function createMountain(maxHeight, minRadius, maxRadius, numCircles, constraints
let mapSize = g_Map.getSize();
let queueEmpty = !q.length;
let gotRet = [];
const gotRet = [];
for (let i = 0; i < mapSize; ++i)
{
gotRet[i] = [];
@ -88,13 +88,13 @@ function createMountain(maxHeight, minRadius, maxRadius, numCircles, constraints
minRadius = Math.max(1, Math.min(minRadius, maxRadius));
let edges = [[x, z]];
let circles = [];
const edges = [[x, z]];
const circles = [];
for (let i = 0; i < numCircles; ++i)
{
let badPoint = false;
let [cx, cz] = pickRandom(edges);
const [cx, cz] = pickRandom(edges);
let radius;
if (queueEmpty)
@ -105,18 +105,18 @@ function createMountain(maxHeight, minRadius, maxRadius, numCircles, constraints
queueEmpty = !q.length;
}
let sx = Math.max(0, cx - radius);
let sz = Math.max(0, cz - radius);
let lx = Math.min(cx + radius, mapSize);
let lz = Math.min(cz + radius, mapSize);
const sx = Math.max(0, cx - radius);
const sz = Math.max(0, cz - radius);
const lx = Math.min(cx + radius, mapSize);
const lz = Math.min(cz + radius, mapSize);
let radius2 = Math.square(radius);
const radius2 = Math.square(radius);
for (let ix = sx; ix <= lx; ++ix)
{
for (let iz = sz; iz <= lz; ++iz)
{
let pos = new Vector2D(ix, iz);
const pos = new Vector2D(ix, iz);
if (Math.euclidDistance2D(ix, iz, cx, cz) > radius2 || !g_Map.inMapBounds(pos))
continue;
@ -127,7 +127,7 @@ function createMountain(maxHeight, minRadius, maxRadius, numCircles, constraints
break;
}
let state = gotRet[ix][iz];
const state = gotRet[ix][iz];
if (state == -1)
{
gotRet[ix][iz] = -2;
@ -167,23 +167,23 @@ function createMountain(maxHeight, minRadius, maxRadius, numCircles, constraints
}
}
for (let [cx, cz, radius] of circles)
for (const [cx, cz, radius] of circles)
{
let circlePosition = new Vector2D(cx, cz);
let sx = Math.max(0, cx - radius);
let sz = Math.max(0, cz - radius);
let lx = Math.min(cx + radius, mapSize);
let lz = Math.min(cz + radius, mapSize);
const circlePosition = new Vector2D(cx, cz);
const sx = Math.max(0, cx - radius);
const sz = Math.max(0, cz - radius);
const lx = Math.min(cx + radius, mapSize);
const lz = Math.min(cz + radius, mapSize);
let clumpHeight = radius / maxRadius * maxHeight * randFloat(0.8, 1.2);
const clumpHeight = radius / maxRadius * maxHeight * randFloat(0.8, 1.2);
for (let ix = sx; ix <= lx; ++ix)
for (let iz = sz; iz <= lz; ++iz)
{
let position = new Vector2D(ix, iz);
let distance = position.distanceTo(circlePosition);
const position = new Vector2D(ix, iz);
const distance = position.distanceTo(circlePosition);
let newHeight =
const newHeight =
randIntInclusive(0, 2) +
Math.round(2/3 * clumpHeight * (Math.sin(Math.PI * 2/3 * (3/4 - distance / radius)) + 0.5));
@ -218,8 +218,8 @@ function createVolcano(position, tileClass, terrainTexture, lavaTextures, smoke,
{
g_Map.log("Creating volcano");
let clLava = g_Map.createTileClass();
let layers = [
const clLava = g_Map.createTileClass();
const layers = [
{
"clumps": diskArea(scaleByMapSize(18, 25)),
"elevation": 15,
@ -265,7 +265,7 @@ function createVolcano(position, tileClass, terrainTexture, lavaTextures, smoke,
if (smoke)
{
let num = Math.floor(diskArea(scaleByMapSize(3, 5)));
const num = Math.floor(diskArea(scaleByMapSize(3, 5)));
createObjectGroup(
new SimpleGroup(
[new SimpleObject("actor|particle/smoke.xml", num, num, 0, 7)],
@ -282,7 +282,7 @@ function createVolcano(position, tileClass, terrainTexture, lavaTextures, smoke,
*/
function createPatches(sizes, terrain, constraints, count, tileClass, failFraction = 0.5)
{
for (let size of sizes)
for (const size of sizes)
createAreas(
new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), size, failFraction),
[
@ -298,7 +298,7 @@ function createPatches(sizes, terrain, constraints, count, tileClass, failFract
*/
function createLayeredPatches(sizes, terrains, terrainWidths, constraints, count, tileClass, failFraction = 0.5)
{
for (let size of sizes)
for (const size of sizes)
createAreas(
new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), size, failFraction),
[
@ -335,45 +335,45 @@ function paintRiver(args)
g_Map.log("Creating river");
// Model the river meandering as the sum of two sine curves.
let meanderShort = fractionToTiles(args.meanderShort / scaleByMapSize(35, 160));
let meanderLong = fractionToTiles(args.meanderLong / scaleByMapSize(35, 100));
const meanderShort = fractionToTiles(args.meanderShort / scaleByMapSize(35, 160));
const meanderLong = fractionToTiles(args.meanderLong / scaleByMapSize(35, 100));
// Unless the river is parallel, each riverside will receive an own random seed and starting angle.
let seed1 = randFloat(2, 3);
let seed2 = randFloat(2, 3);
const seed1 = randFloat(2, 3);
const seed2 = randFloat(2, 3);
let startingAngle1 = randFloat(0, 1);
let startingAngle2 = randFloat(0, 1);
const startingAngle1 = randFloat(0, 1);
const startingAngle2 = randFloat(0, 1);
// Computes the deflection of the river at a given point.
let riverCurve = (riverFraction, startAngle, seed) =>
const riverCurve = (riverFraction, startAngle, seed) =>
meanderShort * rndRiver(startAngle + fractionToTiles(riverFraction) / 128, seed) +
meanderLong * rndRiver(startAngle + fractionToTiles(riverFraction) / 256, seed);
// Describe river location in vectors.
let riverLength = args.start.distanceTo(args.end);
let unitVecRiver = Vector2D.sub(args.start, args.end).normalize();
const riverLength = args.start.distanceTo(args.end);
const unitVecRiver = Vector2D.sub(args.start, args.end).normalize();
// Describe river boundaries.
let riverMinX = Math.min(args.start.x, args.end.x);
let riverMinZ = Math.min(args.start.y, args.end.y);
let riverMaxX = Math.max(args.start.x, args.end.x);
let riverMaxZ = Math.max(args.start.y, args.end.y);
const riverMinX = Math.min(args.start.x, args.end.x);
const riverMinZ = Math.min(args.start.y, args.end.y);
const riverMaxX = Math.max(args.start.x, args.end.x);
const riverMaxZ = Math.max(args.start.y, args.end.y);
let mapSize = g_Map.getSize();
const mapSize = g_Map.getSize();
for (let ix = 0; ix < mapSize; ++ix)
for (let iz = 0; iz < mapSize; ++iz)
{
let vecPoint = new Vector2D(ix, iz);
const vecPoint = new Vector2D(ix, iz);
if (args.constraint && !args.constraint.allows(vecPoint))
continue;
// Compute the shortest distance to the river.
let distanceToRiver = distanceOfPointFromLine(args.start, args.end, vecPoint);
const distanceToRiver = distanceOfPointFromLine(args.start, args.end, vecPoint);
// Closest point on the river (i.e the foot of the perpendicular).
let river = Vector2D.sub(vecPoint, unitVecRiver.perpendicular().mult(distanceToRiver));
const river = Vector2D.sub(vecPoint, unitVecRiver.perpendicular().mult(distanceToRiver));
// Only process points that actually are perpendicular with the river.
if (river.x < riverMinX || river.x > riverMaxX ||
@ -381,18 +381,18 @@ function paintRiver(args)
continue;
// Coordinate between 0 and 1 on the axis parallel to the river.
let riverFraction = river.distanceTo(args.start) / riverLength;
const riverFraction = river.distanceTo(args.start) / riverLength;
// Amplitude of the river at this location.
let riverCurve1 = riverCurve(riverFraction, startingAngle1, seed1);
let riverCurve2 = args.parallel ? riverCurve1 : riverCurve(riverFraction, startingAngle2, seed2);
const riverCurve1 = riverCurve(riverFraction, startingAngle1, seed1);
const riverCurve2 = args.parallel ? riverCurve1 : riverCurve(riverFraction, startingAngle2, seed2);
// Add noise.
let deviation = args.deviation * randFloat(-1, 1);
const deviation = args.deviation * randFloat(-1, 1);
// Compute the distance to the shoreline.
let shoreDist1 = riverCurve1 + distanceToRiver - deviation - args.width / 2;
let shoreDist2 = riverCurve2 + distanceToRiver - deviation + args.width / 2;
const shoreDist1 = riverCurve1 + distanceToRiver - deviation - args.width / 2;
const shoreDist2 = riverCurve2 + distanceToRiver - deviation + args.width / 2;
// Create the elevation for the water and the slopy shoreline and call the user functions.
if (shoreDist1 < 0 && shoreDist2 > 0)
@ -426,10 +426,10 @@ function rndRiver(f, seed)
for (let i = 0; i <= f; ++i)
rndRw = 10 * (rndRw % 1);
let rndRr = f % 1;
const rndRr = f % 1;
let retVal = (Math.floor(f) % 2 ? -1 : 1) * rndRr * (rndRr - 1);
let rndRe = Math.floor(rndRw) % 5;
const rndRe = Math.floor(rndRw) % 5;
if (rndRe == 0)
retVal *= 2.3 * (rndRr - 0.5) * (rndRr - 0.5);
else if (rndRe == 1)
@ -450,15 +450,15 @@ function rndRiver(f, seed)
function createTributaryRivers(riverAngle, riverCount, riverWidth, heightRiverbed, heightRange, maxAngle, tributaryRiverTileClass, shallowTileClass, constraint)
{
g_Map.log("Creating tributary rivers");
let waviness = 0.4;
let smoothness = scaleByMapSize(3, 12);
let offset = 0.1;
let tapering = 0.05;
let heightShallow = -2;
const waviness = 0.4;
const smoothness = scaleByMapSize(3, 12);
const offset = 0.1;
const tapering = 0.05;
const heightShallow = -2;
let mapSize = g_Map.getSize();
let mapCenter = g_Map.getCenter();
let mapBounds = g_Map.getBounds();
const mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
const mapBounds = g_Map.getBounds();
let riverConstraint = avoidClasses(tributaryRiverTileClass, 3);
if (shallowTileClass)
@ -467,19 +467,19 @@ function createTributaryRivers(riverAngle, riverCount, riverWidth, heightRiverbe
for (let i = 0; i < riverCount; ++i)
{
// Determining tributary river location
let searchCenter = new Vector2D(fractionToTiles(randFloat(tapering, 1 - tapering)), mapCenter.y);
let sign = randBool() ? 1 : -1;
let distanceVec = new Vector2D(0, sign * tapering);
const searchCenter = new Vector2D(fractionToTiles(randFloat(tapering, 1 - tapering)), mapCenter.y);
const sign = randBool() ? 1 : -1;
const distanceVec = new Vector2D(0, sign * tapering);
let searchStart = Vector2D.add(searchCenter, distanceVec).rotateAround(riverAngle, mapCenter);
let searchEnd = Vector2D.sub(searchCenter, distanceVec).rotateAround(riverAngle, mapCenter);
const searchStart = Vector2D.add(searchCenter, distanceVec).rotateAround(riverAngle, mapCenter);
const searchEnd = Vector2D.sub(searchCenter, distanceVec).rotateAround(riverAngle, mapCenter);
let start = findLocationInDirectionBasedOnHeight(searchStart, searchEnd, heightRange[0], heightRange[1], 4);
const start = findLocationInDirectionBasedOnHeight(searchStart, searchEnd, heightRange[0], heightRange[1], 4);
if (!start)
continue;
start.round();
let end = Vector2D.add(mapCenter, new Vector2D(mapSize, 0).rotate(riverAngle - sign * randFloat(maxAngle, 2 * Math.PI - maxAngle))).round();
const end = Vector2D.add(mapCenter, new Vector2D(mapSize, 0).rotate(riverAngle - sign * randFloat(maxAngle, 2 * Math.PI - maxAngle))).round();
// Create river
if (!createArea(
@ -502,7 +502,7 @@ function createTributaryRivers(riverAngle, riverCount, riverWidth, heightRiverbe
if (shallowTileClass)
{
g_Map.log("Creating shallows in the tributary rivers");
for (let z of [0.25, 0.75])
for (const z of [0.25, 0.75])
createPassage({
"start": new Vector2D(mapBounds.left, fractionToTiles(z)).rotateAround(riverAngle, mapCenter),
"end": new Vector2D(mapBounds.right, fractionToTiles(z)).rotateAround(riverAngle, mapCenter),
@ -536,27 +536,27 @@ function createTributaryRivers(riverAngle, riverCount, riverWidth, heightRiverbe
*/
function createPassage(args)
{
let bound = x => Math.max(0, Math.min(Math.round(x), g_Map.height.length - 1));
const bound = x => Math.max(0, Math.min(Math.round(x), g_Map.height.length - 1));
let startHeight = args.startHeight !== undefined ? args.startHeight : g_Map.getHeight(new Vector2D(bound(args.start.x), bound(args.start.y)));
let endHeight = args.endHeight !== undefined ? args.endHeight : g_Map.getHeight(new Vector2D(bound(args.end.x), bound(args.end.y)));
const startHeight = args.startHeight !== undefined ? args.startHeight : g_Map.getHeight(new Vector2D(bound(args.start.x), bound(args.start.y)));
const endHeight = args.endHeight !== undefined ? args.endHeight : g_Map.getHeight(new Vector2D(bound(args.end.x), bound(args.end.y)));
let passageVec = Vector2D.sub(args.end, args.start);
let widthDirection = passageVec.perpendicular().normalize();
let lengthStep = 1 / (2 * passageVec.length());
let points = [];
const passageVec = Vector2D.sub(args.end, args.start);
const widthDirection = passageVec.perpendicular().normalize();
const lengthStep = 1 / (2 * passageVec.length());
const points = [];
let constraint = args.constraints && new StaticConstraint(args.constraints);
const constraint = args.constraints && new StaticConstraint(args.constraints);
for (let lengthFraction = 0; lengthFraction <= 1; lengthFraction += lengthStep)
{
let locationLength = Vector2D.add(args.start, Vector2D.mult(passageVec, lengthFraction));
let halfPassageWidth = (args.startWidth + (args.endWidth - args.startWidth) * lengthFraction) / 2;
let passageHeight = startHeight + (endHeight - startHeight) * lengthFraction;
const locationLength = Vector2D.add(args.start, Vector2D.mult(passageVec, lengthFraction));
const halfPassageWidth = (args.startWidth + (args.endWidth - args.startWidth) * lengthFraction) / 2;
const passageHeight = startHeight + (endHeight - startHeight) * lengthFraction;
for (let stepWidth = -halfPassageWidth; stepWidth <= halfPassageWidth; stepWidth += 0.5)
{
let location = Vector2D.add(locationLength, Vector2D.mult(widthDirection, stepWidth)).round();
const location = Vector2D.add(locationLength, Vector2D.mult(widthDirection, stepWidth)).round();
if (!g_Map.inMapBounds(location) ||
constraint && !constraint.allows(location))
@ -564,7 +564,7 @@ function createPassage(args)
points.push(location);
let smoothDistance = args.smoothWidth + Math.abs(stepWidth) - halfPassageWidth;
const smoothDistance = args.smoothWidth + Math.abs(stepWidth) - halfPassageWidth;
g_Map.setHeight(
location,
@ -590,14 +590,14 @@ function createPassage(args)
*/
function findLocationInDirectionBasedOnHeight(startPoint, endPoint, minHeight, maxHeight, offset = 0)
{
let stepVec = Vector2D.sub(endPoint, startPoint);
let distance = Math.ceil(stepVec.length());
const stepVec = Vector2D.sub(endPoint, startPoint);
const distance = Math.ceil(stepVec.length());
stepVec.normalize();
for (let i = 0; i < distance; ++i)
{
let pos = Vector2D.add(startPoint, Vector2D.mult(stepVec, i));
let ipos = pos.clone().round();
const pos = Vector2D.add(startPoint, Vector2D.mult(stepVec, i));
const ipos = pos.clone().round();
if (g_Map.validHeight(ipos) &&
g_Map.getHeight(ipos) >= minHeight &&

View File

@ -76,7 +76,7 @@ function placeStartingEntities(location, playerID, civEntities, dist = 6, orient
{
// Place the central structure
let i = 0;
let firstTemplate = civEntities[i].Template;
const firstTemplate = civEntities[i].Template;
if (firstTemplate.startsWith("structures/"))
{
g_Map.placeEntityPassable(firstTemplate, playerID, location, orientation);
@ -84,15 +84,15 @@ function placeStartingEntities(location, playerID, civEntities, dist = 6, orient
}
// Place entities surrounding it
let space = 2;
const space = 2;
for (let j = i; j < civEntities.length; ++j)
{
let angle = orientation - Math.PI * (1 - j / 2);
let count = civEntities[j].Count || 1;
const angle = orientation - Math.PI * (1 - j / 2);
const count = civEntities[j].Count || 1;
for (let num = 0; num < count; ++num)
{
let position = Vector2D.sum([
const position = Vector2D.sum([
location,
new Vector2D(dist, 0).rotate(-angle),
new Vector2D(space * (-num + (count - 1) / 2), 0).rotate(angle)
@ -118,7 +118,7 @@ function placeCivDefaultStartingEntities(position, playerID, wallType, dist = 6,
*/
function placeStartingWalls(position, playerID, wallType, orientation = BUILDING_ORIENTATION)
{
let civ = getCivCode(playerID);
const civ = getCivCode(playerID);
if (civ != "iber" || g_Map.getSize() <= 128)
return;
@ -138,7 +138,7 @@ function placePlayerBases(playerBaseArgs)
{
g_Map.log("Creating playerbases");
let [playerIDs, playerPosition] = playerBaseArgs.PlayerPlacement;
const [playerIDs, playerPosition] = playerBaseArgs.PlayerPlacement;
for (let i = 0; i < getNumPlayers(); ++i)
{
@ -166,20 +166,20 @@ function placePlayerBase(playerBaseArgs)
if (playerBaseArgs.PlayerTileClass)
addCivicCenterAreaToClass(playerBaseArgs.playerPosition, playerBaseArgs.PlayerTileClass);
for (let functionID of g_PlayerBaseFunctions)
for (const functionID of g_PlayerBaseFunctions)
{
let funcName = "placePlayerBase" + functionID;
let func = global[funcName];
const funcName = "placePlayerBase" + functionID;
const func = global[funcName];
if (!func)
throw new Error("Could not find " + funcName);
if (!playerBaseArgs[functionID])
continue;
let args = playerBaseArgs[functionID];
const args = playerBaseArgs[functionID];
// Copy some global arguments to the arguments for each function
for (let prop of ["playerID", "playerPosition", "BaseResourceClass", "baseResourceConstraint"])
for (const prop of ["playerID", "playerPosition", "BaseResourceClass", "baseResourceConstraint"])
args[prop] = playerBaseArgs[prop];
func(args);
@ -221,7 +221,7 @@ function getPlayerBaseArgs(playerBaseArgs)
function placePlayerBaseCityPatch(args)
{
let [get, basePosition, baseResourceConstraint] = getPlayerBaseArgs(args);
const [get, basePosition, baseResourceConstraint] = getPlayerBaseArgs(args);
let painters = [];
@ -243,18 +243,18 @@ function placePlayerBaseCityPatch(args)
function placePlayerBaseStartingAnimal(args)
{
let [get, basePosition, baseResourceConstraint] = getPlayerBaseArgs(args);
const [get, basePosition, baseResourceConstraint] = getPlayerBaseArgs(args);
const template = get("template", "gaia/fauna_chicken");
const count = template === "gaia/fauna_chicken" ? 5 :
Math.round(5 * (Engine.GetTemplate("gaia/fauna_chicken").ResourceSupply.Max / Engine.GetTemplate(get("template")).ResourceSupply.Max))
Math.round(5 * (Engine.GetTemplate("gaia/fauna_chicken").ResourceSupply.Max / Engine.GetTemplate(get("template")).ResourceSupply.Max));
for (let i = 0; i < get("groupCount", 2); ++i)
{
let success = false;
for (let tries = 0; tries < get("maxTries", 30); ++tries)
{
let position = new Vector2D(0, get("distance", 9)).rotate(randomAngle()).add(basePosition);
const position = new Vector2D(0, get("distance", 9)).rotate(randomAngle()).add(basePosition);
if (createObjectGroup(
new SimpleGroup(
[
@ -286,10 +286,10 @@ function placePlayerBaseStartingAnimal(args)
function placePlayerBaseBerries(args)
{
let [get, basePosition, baseResourceConstraint] = getPlayerBaseArgs(args);
const [get, basePosition, baseResourceConstraint] = getPlayerBaseArgs(args);
for (let tries = 0; tries < get("maxTries", 30); ++tries)
{
let position = new Vector2D(0, get("distance", 12)).rotate(randomAngle()).add(basePosition);
const position = new Vector2D(0, get("distance", 12)).rotate(randomAngle()).add(basePosition);
if (createObjectGroup(
new SimpleGroup(
[new SimpleObject(args.template, get("minCount", 5), get("maxCount", 5), get("maxDist", 1), get("maxDist", 3))],
@ -306,10 +306,10 @@ function placePlayerBaseBerries(args)
function placePlayerBaseMines(args)
{
let [get, basePosition, baseResourceConstraint] = getPlayerBaseArgs(args);
const [get, basePosition, baseResourceConstraint] = getPlayerBaseArgs(args);
let angleBetweenMines = randFloat(get("minAngle", Math.PI / 6), get("maxAngle", Math.PI / 3));
let mineCount = args.types.length;
const angleBetweenMines = randFloat(get("minAngle", Math.PI / 6), get("maxAngle", Math.PI / 3));
const mineCount = args.types.length;
let groupElements = [];
if (args.groupElements)
@ -319,10 +319,10 @@ function placePlayerBaseMines(args)
{
// First find a place where all mines can be placed
let pos = [];
let startAngle = randomAngle();
const startAngle = randomAngle();
for (let i = 0; i < mineCount; ++i)
{
let angle = startAngle + angleBetweenMines * (i + (mineCount - 1) / 2);
const angle = startAngle + angleBetweenMines * (i + (mineCount - 1) / 2);
pos[i] = new Vector2D(0, get("distance", 12)).rotate(angle).add(basePosition).round();
if (!g_Map.validTilePassable(pos[i]) || !baseResourceConstraint.allows(pos[i]))
{
@ -360,13 +360,13 @@ function placePlayerBaseMines(args)
function placePlayerBaseTrees(args)
{
let [get, basePosition, baseResourceConstraint] = getPlayerBaseArgs(args);
const [get, basePosition, baseResourceConstraint] = getPlayerBaseArgs(args);
let num = Math.floor(get("count", scaleByMapSize(7, 20)));
const num = Math.floor(get("count", scaleByMapSize(7, 20)));
for (let x = 0; x < get("maxTries", 30); ++x)
{
let position = new Vector2D(0, randFloat(get("minDist", 11), get("maxDist", 13))).rotate(randomAngle()).add(basePosition).round();
const position = new Vector2D(0, randFloat(get("minDist", 11), get("maxDist", 13))).rotate(randomAngle()).add(basePosition).round();
if (createObjectGroup(
new SimpleGroup(
@ -386,7 +386,7 @@ function placePlayerBaseTreasures(args)
{
let [get, basePosition, baseResourceConstraint] = getPlayerBaseArgs(args);
for (let resourceTypeArgs of args.types)
for (const resourceTypeArgs of args.types)
{
get = (property, defaultVal) => resourceTypeArgs[property] === undefined ? defaultVal : resourceTypeArgs[property];
@ -394,7 +394,7 @@ function placePlayerBaseTreasures(args)
for (let tries = 0; tries < get("maxTries", 30); ++tries)
{
let position = new Vector2D(0, randFloat(get("minDist", 11), get("maxDist", 13))).rotate(randomAngle()).add(basePosition).round();
const position = new Vector2D(0, randFloat(get("minDist", 11), get("maxDist", 13))).rotate(randomAngle()).add(basePosition).round();
if (createObjectGroup(
new SimpleGroup(
@ -422,14 +422,14 @@ function placePlayerBaseTreasures(args)
*/
function placePlayerBaseDecoratives(args)
{
let [get, basePosition, baseResourceConstraint] = getPlayerBaseArgs(args);
const [get, basePosition, baseResourceConstraint] = getPlayerBaseArgs(args);
for (let i = 0; i < get("count", scaleByMapSize(2, 5)); ++i)
{
let success = false;
for (let x = 0; x < get("maxTries", 30); ++x)
{
let position = new Vector2D(0, randIntInclusive(get("minDist", 8), get("maxDist", 11))).rotate(randomAngle()).add(basePosition).round();
const position = new Vector2D(0, randIntInclusive(get("minDist", 8), get("maxDist", 11))).rotate(randomAngle()).add(basePosition).round();
if (createObjectGroup(
new SimpleGroup(
@ -457,25 +457,25 @@ function placePlayersNomad(playerClass, constraints)
g_Map.log("Placing nomad starting units");
let distance = scaleByMapSize(60, 240);
let constraint = new StaticConstraint(constraints);
const distance = scaleByMapSize(60, 240);
const constraint = new StaticConstraint(constraints);
let numPlayers = getNumPlayers();
let playerIDs = shuffleArray(sortAllPlayers());
let playerPosition = [];
const numPlayers = getNumPlayers();
const playerIDs = shuffleArray(sortAllPlayers());
const playerPosition = [];
for (let i = 0; i < numPlayers; ++i)
{
let objects = getStartingEntities(playerIDs[i]).filter(ents => ents.Template.startsWith("units/")).map(
const objects = getStartingEntities(playerIDs[i]).filter(ents => ents.Template.startsWith("units/")).map(
ents => new SimpleObject(ents.Template, ents.Count || 1, ents.Count || 1, 1, 3));
// Add treasure if too few resources for a civic center
let ccCost = Engine.GetTemplate("structures/" + getCivCode(playerIDs[i]) + "/civil_centre").Cost.Resources;
for (let resourceType in ccCost)
const ccCost = Engine.GetTemplate("structures/" + getCivCode(playerIDs[i]) + "/civil_centre").Cost.Resources;
for (const resourceType in ccCost)
{
let treasureTemplate = g_NomadTreasureTemplates[resourceType];
const treasureTemplate = g_NomadTreasureTemplates[resourceType];
let count = Math.max(0, Math.ceil(
const count = Math.max(0, Math.ceil(
(ccCost[resourceType] - (g_MapSettings.StartingResources || 0)) /
Engine.GetTemplate(treasureTemplate).Treasure.Resources[resourceType]));
@ -483,9 +483,9 @@ function placePlayersNomad(playerClass, constraints)
}
// Try place these entities at a random location
let group = new SimpleGroup(objects, true, playerClass);
const group = new SimpleGroup(objects, true, playerClass);
let success = false;
for (let distanceFactor of [1, 1/2, 1/4, 0])
for (const distanceFactor of [1, 1/2, 1/4, 0])
if (createObjectGroups(group, playerIDs[i], new AndConstraint([constraint, avoidClasses(playerClass, distance * distanceFactor)]), 1, 200, false).length)
{
success = true;
@ -516,7 +516,7 @@ function sortPlayers(playerIDs)
*/
function sortAllPlayers()
{
let playerIDs = [];
const playerIDs = [];
for (let i = 0; i < getNumPlayers(); ++i)
playerIDs.push(i+1);
@ -528,7 +528,7 @@ function sortAllPlayers()
*/
function primeSortPlayers(playerIDs)
{
let prime = [];
const prime = [];
for (let i = 0; i < Math.floor(playerIDs.length / 2); ++i)
{
prime.push(playerIDs[i]);
@ -552,14 +552,14 @@ function primeSortAllPlayers()
*/
function partitionPlayers(playerIDs)
{
let teamIDs = Array.from(new Set(playerIDs.map(getPlayerTeam)));
const teamIDs = Array.from(new Set(playerIDs.map(getPlayerTeam)));
let teams = teamIDs.map(teamID => playerIDs.filter(playerID => getPlayerTeam(playerID) == teamID));
if (teamIDs.indexOf(-1) != -1)
teams = teams.concat(teams.splice(teamIDs.indexOf(-1), 1)[0].map(playerID => [playerID]));
if (teams.length == 1)
{
let idx = Math.floor(teams[0].length / 2);
const idx = Math.floor(teams[0].length / 2);
teams = [teams[0].slice(idx), teams[0].slice(0, idx)];
}
@ -578,14 +578,14 @@ function partitionPlayers(playerIDs)
*/
function getTeamsArray()
{
var playerIDs = sortAllPlayers();
var numPlayers = getNumPlayers();
let playerIDs = sortAllPlayers();
let numPlayers = getNumPlayers();
// Group players by team
var teams = [];
let teams = [];
for (let i = 0; i < numPlayers; ++i)
{
let team = getPlayerTeam(playerIDs[i]);
const team = getPlayerTeam(playerIDs[i]);
if (team == -1)
continue;
@ -634,8 +634,8 @@ function playerPlacementByPattern(patternName, distance = undefined, groupedDist
*/
function playerPlacementCircle(radius, startingAngle = undefined, center = undefined)
{
let startAngle = startingAngle !== undefined ? startingAngle : randomAngle();
let [playerPosition, playerAngle] = distributePointsOnCircle(getNumPlayers(), startAngle, radius, center || g_Map.getCenter());
const startAngle = startingAngle !== undefined ? startingAngle : randomAngle();
const [playerPosition, playerAngle] = distributePointsOnCircle(getNumPlayers(), startAngle, radius, center || g_Map.getCenter());
return [sortAllPlayers(), playerPosition.map(p => p.round()), playerAngle, startAngle];
}
@ -645,10 +645,10 @@ function playerPlacementCircle(radius, startingAngle = undefined, center = undef
*/
function playerPlacementCustomAngle(radius, center, playerAngleFunc)
{
let playerPosition = [];
let playerAngle = [];
const playerPosition = [];
const playerAngle = [];
let numPlayers = getNumPlayers();
const numPlayers = getNumPlayers();
for (let i = 0; i < numPlayers; ++i)
{
@ -678,9 +678,9 @@ function playerPlacementArc(playerIDs, center, radius, startAngle, endAngle)
*/
function playerPlacementArcs(playerIDs, center, radius, mapAngle, startAngle, endAngle)
{
let [east, west] = partitionPlayers(playerIDs);
let eastPosition = playerPlacementArc(east, center, radius, mapAngle + startAngle, mapAngle + endAngle);
let westPosition = playerPlacementArc(west, center, radius, mapAngle - startAngle, mapAngle - endAngle);
const [east, west] = partitionPlayers(playerIDs);
const eastPosition = playerPlacementArc(east, center, radius, mapAngle + startAngle, mapAngle + endAngle);
const westPosition = playerPlacementArc(west, center, radius, mapAngle - startAngle, mapAngle - endAngle);
return playerIDs.map(playerID => east.indexOf(playerID) != -1 ?
eastPosition[east.indexOf(playerID)] :
westPosition[west.indexOf(playerID)]);
@ -693,18 +693,18 @@ function playerPlacementArcs(playerIDs, center, radius, mapAngle, startAngle, en
*/
function playerPlacementRiver(angle, width, center = undefined)
{
let numPlayers = getNumPlayers();
let numPlayersEven = numPlayers % 2 == 0;
let mapSize = g_Map.getSize();
let centerPosition = center || g_Map.getCenter();
let playerPosition = [];
const numPlayers = getNumPlayers();
const numPlayersEven = numPlayers % 2 == 0;
const mapSize = g_Map.getSize();
const centerPosition = center || g_Map.getCenter();
const playerPosition = [];
for (let i = 0; i < numPlayers; ++i)
{
let currentPlayerEven = i % 2 == 0;
const currentPlayerEven = i % 2 == 0;
let offsetDivident = numPlayersEven || currentPlayerEven ? (i + 1) % 2 : 0;
let offsetDivisor = numPlayersEven ? 0 : currentPlayerEven ? +1 : -1;
const offsetDivident = numPlayersEven || currentPlayerEven ? (i + 1) % 2 : 0;
const offsetDivisor = numPlayersEven ? 0 : currentPlayerEven ? +1 : -1;
playerPosition[i] = new Vector2D(
width * (i % 2) + (mapSize - width) / 2,
@ -721,8 +721,8 @@ function playerPlacementRiver(angle, width, center = undefined)
*/
function playerPlacementLine(angle, center, width)
{
let playerPosition = [];
let numPlayers = getNumPlayers();
const playerPosition = [];
const numPlayers = getNumPlayers();
for (let i = 0; i < numPlayers; ++i)
playerPosition[i] = Vector2D.add(
@ -748,19 +748,19 @@ function playerPlacementLine(angle, center, width)
*/
function placeLine(teamsArray, distance, groupedDistance, startAngle)
{
let playerIDs = [];
let playerPosition = [];
const playerIDs = [];
const playerPosition = [];
let mapCenter = g_Map.getCenter();
let dist = fractionToTiles(0.45);
const mapCenter = g_Map.getCenter();
const dist = fractionToTiles(0.45);
for (let i = 0; i < teamsArray.length; ++i)
{
var safeDist = distance;
let safeDist = distance;
if (distance + teamsArray[i].length * groupedDistance > dist)
safeDist = dist - teamsArray[i].length * groupedDistance;
var teamAngle = startAngle + (i + 1) * 2 * Math.PI / teamsArray.length;
let teamAngle = startAngle + (i + 1) * 2 * Math.PI / teamsArray.length;
for (let p = 0; p < teamsArray[i].length; ++p)
{
@ -782,16 +782,16 @@ function placeLine(teamsArray, distance, groupedDistance, startAngle)
*/
function placeStronghold(teamsArray, distance, groupedDistance, startAngle)
{
var mapCenter = g_Map.getCenter();
let mapCenter = g_Map.getCenter();
let playerIDs = [];
let playerPosition = [];
const playerIDs = [];
const playerPosition = [];
for (let i = 0; i < teamsArray.length; ++i)
{
var teamAngle = startAngle + (i + 1) * 2 * Math.PI / teamsArray.length;
var teamPosition = Vector2D.add(mapCenter, new Vector2D(distance, 0).rotate(-teamAngle));
var teamGroupDistance = groupedDistance;
let teamAngle = startAngle + (i + 1) * 2 * Math.PI / teamsArray.length;
let teamPosition = Vector2D.add(mapCenter, new Vector2D(distance, 0).rotate(-teamAngle));
let teamGroupDistance = groupedDistance;
// If we have a team of above average size, make sure they're spread out
if (teamsArray[i].length > 4)
@ -804,9 +804,9 @@ function placeStronghold(teamsArray, distance, groupedDistance, startAngle)
// TODO: Ensure players are not placed outside of the map area, similar to placeLine
// Create player base
for (var p = 0; p < teamsArray[i].length; ++p)
for (let p = 0; p < teamsArray[i].length; ++p)
{
var angle = startAngle + (p + 1) * 2 * Math.PI / teamsArray[i].length;
let angle = startAngle + (p + 1) * 2 * Math.PI / teamsArray[i].length;
playerIDs.push(teamsArray[i][p]);
playerPosition.push(Vector2D.add(teamPosition, new Vector2D(teamGroupDistance, 0).rotate(-angle)).round());
}
@ -825,11 +825,11 @@ function playerPlacementRandom(playerIDs, constraints = undefined)
let attempts = 0;
let resets = 0;
let mapCenter = g_Map.getCenter();
const mapCenter = g_Map.getCenter();
let playerMinDistSquared = Math.square(fractionToTiles(0.25));
let borderDistance = fractionToTiles(0.08);
const borderDistance = fractionToTiles(0.08);
let area = createArea(new MapBoundsPlacer(), undefined, new AndConstraint(constraints));
const area = createArea(new MapBoundsPlacer(), undefined, new AndConstraint(constraints));
for (let i = 0; i < getNumPlayers(); ++i)
{
@ -887,8 +887,8 @@ function groupPlayersByArea(playerIDs, locations)
for (let i = 1; i < playerIDs.length; ++i)
{
let team1 = getPlayerTeam(playerIDs[i - 1]);
let team2 = getPlayerTeam(playerIDs[i]);
const team1 = getPlayerTeam(playerIDs[i - 1]);
const team2 = getPlayerTeam(playerIDs[i]);
++teamSize;
if (team1 != -1 && team1 == team2)
teamDist += permutation[i - 1].distanceTo(permutation[i]);
@ -918,9 +918,9 @@ function groupPlayersByArea(playerIDs, locations)
*/
function groupPlayersCycle(startLocations)
{
let startLocationOrder = sortPointsShortestCycle(startLocations);
const startLocationOrder = sortPointsShortestCycle(startLocations);
let newStartLocations = [];
const newStartLocations = [];
for (let i = 0; i < startLocations.length; ++i)
newStartLocations.push(startLocations[startLocationOrder[i]]);
@ -928,11 +928,11 @@ function groupPlayersCycle(startLocations)
// Sort players by team
let playerIDs = [];
let teams = [];
const teams = [];
for (let i = 0; i < g_MapSettings.PlayerData.length - 1; ++i)
{
playerIDs.push(i+1);
let t = g_MapSettings.PlayerData[i + 1].Team;
const t = g_MapSettings.PlayerData[i + 1].Team;
if (teams.indexOf(t) == -1 && t !== undefined)
teams.push(t);
}
@ -950,7 +950,7 @@ function groupPlayersCycle(startLocations)
let maxTeamDist = 0;
for (let pi = 0; pi < playerIDs.length - 1; ++pi)
{
let t1 = getPlayerTeam(playerIDs[(pi + s) % playerIDs.length]);
const t1 = getPlayerTeam(playerIDs[(pi + s) % playerIDs.length]);
if (teams.indexOf(t1) === -1)
continue;
@ -979,7 +979,7 @@ function groupPlayersCycle(startLocations)
if (bestShift)
{
let newPlayerIDs = [];
const newPlayerIDs = [];
for (let i = 0; i < playerIDs.length; ++i)
newPlayerIDs.push(playerIDs[(i + bestShift) % playerIDs.length]);
playerIDs = newPlayerIDs;

View File

@ -22,14 +22,14 @@ var g_FortressTypes = createDefaultFortressTypes();
*/
function loadWallsetsFromCivData()
{
let wallsets = {};
for (let civ in g_CivData)
const wallsets = {};
for (const civ in g_CivData)
{
let civInfo = g_CivData[civ];
const civInfo = g_CivData[civ];
if (!civInfo.WallSets)
continue;
for (let path of civInfo.WallSets)
for (const path of civInfo.WallSets)
{
// File naming conventions:
// - structures/wallset_{style}
@ -47,12 +47,12 @@ function loadWallsetsFromCivData()
function loadWallset(wallsetPath, civ)
{
let newWallset = { "curves": [] };
const newWallset = { "curves": [] };
const wallsetData = GetTemplateDataHelper(wallsetPath, null, null, g_Resources).wallSet;
for (let element in wallsetData.templates)
for (const element in wallsetData.templates)
if (element == "curves")
for (let filename of wallsetData.templates.curves)
for (const filename of wallsetData.templates.curves)
newWallset.curves.push(readyWallElement(filename, civ));
else
newWallset[element] = readyWallElement(wallsetData.templates[element], civ);
@ -86,12 +86,12 @@ function Fortress(type, wall=[], centerToFirstElement=undefined)
function createDefaultFortressTypes()
{
let defaultFortresses = {};
const defaultFortresses = {};
/**
* Define some basic default fortress types.
*/
let addFortress = (type, walls) => defaultFortresses[type] = { "wall": walls.concat(walls, walls, walls) };
const addFortress = (type, walls) => defaultFortresses[type] = { "wall": walls.concat(walls, walls, walls) };
addFortress("tiny", ["gate", "tower", "short", "cornerIn", "short", "tower"]);
addFortress("small", ["gate", "tower", "medium", "cornerIn", "medium", "tower"]);
addFortress("medium", ["gate", "tower", "long", "cornerIn", "long", "tower"]);
@ -104,7 +104,7 @@ function createDefaultFortressTypes()
* Define some fortresses based on those above, but designed for use
* with the "palisades" wallset.
*/
for (let fortressType in defaultFortresses)
for (const fortressType in defaultFortresses)
{
const fillTowersBetween = ["short", "medium", "long", "start", "end", "cornerIn", "cornerOut"];
const newKey = fortressType + "Palisades";
@ -156,7 +156,7 @@ function getWallElement(element, style)
// Attempt to derive any unknown elements.
// Defaults to a wall tower piece
const quarterBend = Math.PI / 2;
let wallset = g_WallStyles[style];
const wallset = g_WallStyles[style];
let civ = style.split("/")[0];
let ret = wallset.tower ? clone(wallset.tower) : { "angle": 0, "bend": 0, "length": 0, "indent": 0 };
@ -164,7 +164,7 @@ function getWallElement(element, style)
{
case "cornerIn":
if (wallset.curves)
for (let curve of wallset.curves)
for (const curve of wallset.curves)
if (curve.bend == quarterBend)
ret = curve;
@ -179,7 +179,7 @@ function getWallElement(element, style)
case "cornerOut":
if (wallset.curves)
for (let curve of wallset.curves)
for (const curve of wallset.curves)
if (curve.bend == quarterBend)
{
ret = clone(curve);
@ -245,7 +245,7 @@ function getWallElement(element, style)
if (!g_CivData[civ])
civ = Object.keys(g_CivData)[0];
let templateName = "structures/" + civ + "/" + element;
const templateName = "structures/" + civ + "/" + element;
if (Engine.TemplateExists(templateName))
{
ret.indent = ret.length * (element == "outpost" || element.endsWith("_tower") ? -3 : 3.5);
@ -272,7 +272,7 @@ function readyWallElement(path, civCode)
{
path = path.replace(/\{civ\}/g, civCode);
const template = GetTemplateDataHelper(Engine.GetTemplate(path), null, null, g_Resources);
let length = template.wallPiece ? template.wallPiece.length : template.obstruction.shape.width;
const length = template.wallPiece ? template.wallPiece.length : template.obstruction.shape.width;
return deepfreeze({
"templateName": path,
@ -297,12 +297,12 @@ function readyWallElement(path, civCode)
function getWallAlignment(position, wall = [], style = "athen_stone", orientation = 0)
{
style = validateStyle(style);
let alignment = [];
let wallPosition = position.clone();
const alignment = [];
const wallPosition = position.clone();
for (let i = 0; i < wall.length; ++i)
{
let element = getWallElement(wall[i], style);
const element = getWallElement(wall[i], style);
if (!element && i == 0)
{
warn("Not a valid wall element: style = " + style + ", wall[" + i + "] = " + wall[i] + "; " + uneval(element));
@ -320,7 +320,7 @@ function getWallAlignment(position, wall = [], style = "athen_stone", orientatio
if (i + 1 < wall.length)
{
orientation += element.bend;
let nextElement = getWallElement(wall[i + 1], style);
const nextElement = getWallElement(wall[i + 1], style);
if (!nextElement)
{
warn("Not a valid wall element: style = " + style + ", wall[" + (i + 1) + "] = " + wall[i + 1] + "; " + uneval(nextElement));
@ -330,8 +330,8 @@ function getWallAlignment(position, wall = [], style = "athen_stone", orientatio
let distance = (element.length + nextElement.length) / 2 - g_WallStyles[style].overlap;
// Corrections for elements with indent AND bending
let indent = element.indent;
let bend = element.bend;
const indent = element.indent;
const bend = element.bend;
if (bend != 0 && indent != 0)
{
// Indent correction to adjust distance
@ -373,8 +373,8 @@ function getWallLength(style, wall)
style = validateStyle(style);
let length = 0;
let overlap = g_WallStyles[style].overlap;
for (let element of wall)
const overlap = g_WallStyles[style].overlap;
for (const element of wall)
length += getWallElement(element, style).length - overlap;
return length;
@ -420,10 +420,10 @@ function placeWall(position, wall = [], style, playerId = 0, orientation = 0, co
{
style = validateStyle(style, playerId);
let entities = [];
let constraint = new StaticConstraint(constraints);
const entities = [];
const constraint = new StaticConstraint(constraints);
for (let align of getWallAlignment(position, wall, style, orientation))
for (const align of getWallAlignment(position, wall, style, orientation))
if (align.templateName && g_Map.inMapBounds(align.position) && constraint.allows(align.position.clone().floor()))
entities.push(g_Map.placeEntityPassable(align.templateName, playerId, align.position, align.angle));
@ -454,7 +454,7 @@ function placeCustomFortress(centerPosition, fortress, style, playerId = 0, orie
centerToFirstElement = getCenterToFirstElement(getWallAlignment(new Vector2D(0, 0), fortress.wall, style));
// Placing the fortress wall
let position = Vector2D.sum([
const position = Vector2D.sum([
centerPosition,
new Vector2D(centerToFirstElement.x, 0).rotate(-orientation),
new Vector2D(centerToFirstElement.y, 0).perpendicular().rotate(-orientation)
@ -493,13 +493,13 @@ function placeLinearWall(startPosition, targetPosition, wallPart = undefined, st
style = validateStyle(style, playerId);
// Check arguments
for (let element of wallPart)
for (const element of wallPart)
if (getWallElement(element, style).bend != 0)
warn("placeLinearWall : Bending is not supported by this function, but the following bending wall element was used: " + element);
// Setup number of wall parts
let totalLength = startPosition.distanceTo(targetPosition);
let wallPartLength = getWallLength(style, wallPart);
const totalLength = startPosition.distanceTo(targetPosition);
const wallPartLength = getWallLength(style, wallPart);
let numParts = Math.ceil(totalLength / wallPartLength);
if (endWithFirst)
numParts = Math.ceil((totalLength - getWallElement(wallPart[0], style).length) / wallPartLength);
@ -510,27 +510,27 @@ function placeLinearWall(startPosition, targetPosition, wallPart = undefined, st
scaleFactor = totalLength / (numParts * wallPartLength + getWallElement(wallPart[0], style).length);
// Setup angle
let wallAngle = getAngle(startPosition.x, startPosition.y, targetPosition.x, targetPosition.y);
let placeAngle = wallAngle - Math.PI / 2;
const wallAngle = getAngle(startPosition.x, startPosition.y, targetPosition.x, targetPosition.y);
const placeAngle = wallAngle - Math.PI / 2;
// Place wall entities
let entities = [];
let position = startPosition.clone();
let overlap = g_WallStyles[style].overlap;
let constraint = new StaticConstraint(constraints);
const entities = [];
const position = startPosition.clone();
const overlap = g_WallStyles[style].overlap;
const constraint = new StaticConstraint(constraints);
for (let partIndex = 0; partIndex < numParts; ++partIndex)
for (let elementIndex = 0; elementIndex < wallPart.length; ++elementIndex)
{
let wallEle = getWallElement(wallPart[elementIndex], style);
const wallEle = getWallElement(wallPart[elementIndex], style);
let wallLength = (wallEle.length - overlap) / 2;
let dist = new Vector2D(scaleFactor * wallLength, 0).rotate(-wallAngle);
const wallLength = (wallEle.length - overlap) / 2;
const dist = new Vector2D(scaleFactor * wallLength, 0).rotate(-wallAngle);
// Length correction
position.add(dist);
// Indent correction
let place = Vector2D.add(position, new Vector2D(0, wallEle.indent).rotate(-wallAngle));
const place = Vector2D.add(position, new Vector2D(0, wallEle.indent).rotate(-wallAngle));
if (wallEle.templateName && g_Map.inMapBounds(place) && constraint.allows(place.clone().floor()))
entities.push(g_Map.placeEntityPassable(wallEle.templateName, playerId, place, placeAngle + wallEle.angle));
@ -540,8 +540,8 @@ function placeLinearWall(startPosition, targetPosition, wallPart = undefined, st
if (endWithFirst)
{
let wallEle = getWallElement(wallPart[0], style);
let wallLength = (wallEle.length - overlap) / 2;
const wallEle = getWallElement(wallPart[0], style);
const wallLength = (wallEle.length - overlap) / 2;
position.add(new Vector2D(scaleFactor * wallLength, 0).rotate(-wallAngle));
if (wallEle.templateName && g_Map.inMapBounds(position) && constraint.allows(position.clone().floor()))
entities.push(g_Map.placeEntityPassable(wallEle.templateName, playerId, position, placeAngle + wallEle.angle));
@ -583,13 +583,13 @@ function placeCircularWall(center, radius, wallPart, style, playerId = 0, orient
if (maxBendOff > Math.PI / 2 || maxBendOff < 0)
warn("placeCircularWall : maxBendOff should satisfy 0 < maxBendOff < PI/2 (~1.5rad) but it is: " + maxBendOff);
for (let element of wallPart)
for (const element of wallPart)
if (getWallElement(element, style).bend != 0)
warn("placeCircularWall : Bending is not supported by this function, but the following bending wall element was used: " + element);
// Setup number of wall parts
let totalLength = maxAngle * radius;
let wallPartLength = getWallLength(style, wallPart);
const totalLength = maxAngle * radius;
const wallPartLength = getWallLength(style, wallPart);
let numParts = Math.ceil(totalLength / wallPartLength);
if (endWithFirst)
numParts = Math.ceil((totalLength - getWallElement(wallPart[0], style).length) / wallPartLength);
@ -600,21 +600,21 @@ function placeCircularWall(center, radius, wallPart, style, playerId = 0, orient
scaleFactor = totalLength / (numParts * wallPartLength + getWallElement(wallPart[0], style).length);
// Place wall entities
let entities = [];
let constraint = new StaticConstraint(constraints);
const entities = [];
const constraint = new StaticConstraint(constraints);
let actualAngle = orientation;
let position = Vector2D.add(center, new Vector2D(radius, 0).rotate(-actualAngle));
let overlap = g_WallStyles[style].overlap;
const overlap = g_WallStyles[style].overlap;
for (let partIndex = 0; partIndex < numParts; ++partIndex)
for (let wallEle of wallPart)
{
wallEle = getWallElement(wallEle, style);
// Width correction
let addAngle = scaleFactor * (wallEle.length - overlap) / radius;
let target = Vector2D.add(center, new Vector2D(radius, 0).rotate(-actualAngle - addAngle));
let place = Vector2D.average([position, target]);
let placeAngle = actualAngle + addAngle / 2;
const addAngle = scaleFactor * (wallEle.length - overlap) / radius;
const target = Vector2D.add(center, new Vector2D(radius, 0).rotate(-actualAngle - addAngle));
const place = Vector2D.average([position, target]);
const placeAngle = actualAngle + addAngle / 2;
// Indent correction
place.sub(new Vector2D(wallEle.indent, 0).rotate(-placeAngle));
@ -622,7 +622,7 @@ function placeCircularWall(center, radius, wallPart, style, playerId = 0, orient
// Placement
if (wallEle.templateName && g_Map.inMapBounds(place) && constraint.allows(place.clone().floor()))
{
let entity = g_Map.placeEntityPassable(wallEle.templateName, playerId, place, placeAngle + wallEle.angle);
const entity = g_Map.placeEntityPassable(wallEle.templateName, playerId, place, placeAngle + wallEle.angle);
if (entity)
entities.push(entity);
}
@ -634,11 +634,11 @@ function placeCircularWall(center, radius, wallPart, style, playerId = 0, orient
if (endWithFirst)
{
let wallEle = getWallElement(wallPart[0], style);
let addAngle = scaleFactor * wallEle.length / radius;
let target = Vector2D.add(center, new Vector2D(radius, 0).rotate(-actualAngle - addAngle));
let place = Vector2D.average([position, target]);
let placeAngle = actualAngle + addAngle / 2;
const wallEle = getWallElement(wallPart[0], style);
const addAngle = scaleFactor * wallEle.length / radius;
const target = Vector2D.add(center, new Vector2D(radius, 0).rotate(-actualAngle - addAngle));
const place = Vector2D.average([position, target]);
const placeAngle = actualAngle + addAngle / 2;
if (g_Map.inMapBounds(place) && constraint.allows(place.clone().floor()))
entities.push(g_Map.placeEntityPassable(wallEle.templateName, playerId, place, placeAngle + wallEle.angle));
}
@ -668,28 +668,28 @@ function placePolygonalWall(centerPosition, radius, wallPart, cornerWallElement
style = validateStyle(style, playerId);
let entities = [];
let constraint = new StaticConstraint(constraints);
let angleAdd = Math.PI * 2 / numCorners;
let angleStart = orientation - angleAdd / 2;
let corners = new Array(numCorners).fill(0).map((zero, i) =>
const constraint = new StaticConstraint(constraints);
const angleAdd = Math.PI * 2 / numCorners;
const angleStart = orientation - angleAdd / 2;
const corners = new Array(numCorners).fill(0).map((zero, i) =>
Vector2D.add(centerPosition, new Vector2D(radius, 0).rotate(-angleStart - i * angleAdd)));
for (let i = 0; i < numCorners; ++i)
{
let angleToCorner = getAngle(corners[i].x, corners[i].y, centerPosition.x, centerPosition.y);
const angleToCorner = getAngle(corners[i].x, corners[i].y, centerPosition.x, centerPosition.y);
if (g_Map.inMapBounds(corners[i]) && constraint.allows(corners[i].clone().floor()))
{
let entity = g_Map.placeEntityPassable(getWallElement(cornerWallElement, style).templateName, playerId, corners[i], angleToCorner);
const entity = g_Map.placeEntityPassable(getWallElement(cornerWallElement, style).templateName, playerId, corners[i], angleToCorner);
if (entity)
entities.push(entity);
}
if (!skipFirstWall || i != 0)
{
let cornerLength = getWallElement(cornerWallElement, style).length / 2;
let cornerAngle = angleToCorner + angleAdd / 2;
let targetCorner = (i + 1) % numCorners;
let cornerPosition = new Vector2D(cornerLength, 0).rotate(-cornerAngle).perpendicular();
const cornerLength = getWallElement(cornerWallElement, style).length / 2;
const cornerAngle = angleToCorner + angleAdd / 2;
const targetCorner = (i + 1) % numCorners;
const cornerPosition = new Vector2D(cornerLength, 0).rotate(-cornerAngle).perpendicular();
entities = entities.concat(
placeLinearWall(
@ -734,11 +734,11 @@ function placeIrregularPolygonalWall(centerPosition, radius, cornerWallElement =
// Generating a generic wall part assortment with each wall part including 1 gate lengthened by walls and towers
// NOTE: It might be a good idea to write an own function for that...
let defaultWallPartsAssortment = [["short"], ["medium"], ["long"], ["gate", "tower", "short"]];
let centeredWallPart = ["gate"];
let extendingWallPartAssortment = [["tower", "long"], ["tower", "medium"]];
const defaultWallPartsAssortment = [["short"], ["medium"], ["long"], ["gate", "tower", "short"]];
const centeredWallPart = ["gate"];
const extendingWallPartAssortment = [["tower", "long"], ["tower", "medium"]];
defaultWallPartsAssortment.push(centeredWallPart);
for (let assortment of extendingWallPartAssortment)
for (const assortment of extendingWallPartAssortment)
{
let wallPart = centeredWallPart;
for (let j = 0; j < radius; ++j)
@ -760,7 +760,7 @@ function placeIrregularPolygonalWall(centerPosition, radius, cornerWallElement =
// Setup angles
let angleToCover = Math.PI * 2;
let angleAddList = [];
const angleAddList = [];
for (let i = 0; i < numCorners; ++i)
{
// Randomize covered angles. Variety scales down with raising angle though...
@ -769,7 +769,7 @@ function placeIrregularPolygonalWall(centerPosition, radius, cornerWallElement =
}
// Setup corners
let corners = [];
const corners = [];
let angleActual = orientation - angleAddList[0] / 2;
for (let i = 0; i < numCorners; ++i)
{
@ -780,28 +780,28 @@ function placeIrregularPolygonalWall(centerPosition, radius, cornerWallElement =
}
// Setup best wall parts for the different walls (a bit confusing naming...)
let wallPartLengths = [];
const wallPartLengths = [];
let maxWallPartLength = 0;
for (let wallPart of wallPartsAssortment)
for (const wallPart of wallPartsAssortment)
{
let length = getWallLength(style, wallPart);
const length = getWallLength(style, wallPart);
wallPartLengths.push(length);
if (length > maxWallPartLength)
maxWallPartLength = length;
}
let wallPartList = []; // This is the list of the wall parts to use for the walls between the corners, not to confuse with wallPartsAssortment!
const wallPartList = []; // This is the list of the wall parts to use for the walls between the corners, not to confuse with wallPartsAssortment!
for (let i = 0; i < numCorners; ++i)
{
let bestWallPart = []; // This is a simple wall part not a wallPartsAssortment!
let bestWallLength = Infinity;
let targetCorner = (i + 1) % numCorners;
const targetCorner = (i + 1) % numCorners;
// NOTE: This is not quite the length the wall will be in the end. Has to be tweaked...
let wallLength = corners[i].distanceTo(corners[targetCorner]);
let numWallParts = Math.ceil(wallLength / maxWallPartLength);
const wallLength = corners[i].distanceTo(corners[targetCorner]);
const numWallParts = Math.ceil(wallLength / maxWallPartLength);
for (let partIndex = 0; partIndex < wallPartsAssortment.length; ++partIndex)
{
let linearWallLength = numWallParts * wallPartLengths[partIndex];
const linearWallLength = numWallParts * wallPartLengths[partIndex];
if (linearWallLength < bestWallLength && linearWallLength > wallLength)
{
bestWallPart = wallPartsAssortment[partIndex];
@ -813,20 +813,20 @@ function placeIrregularPolygonalWall(centerPosition, radius, cornerWallElement =
// Place Corners and walls
let entities = [];
let constraint = new StaticConstraint(constraints);
const constraint = new StaticConstraint(constraints);
for (let i = 0; i < numCorners; ++i)
{
let angleToCorner = getAngle(corners[i].x, corners[i].y, centerPosition.x, centerPosition.y);
const angleToCorner = getAngle(corners[i].x, corners[i].y, centerPosition.x, centerPosition.y);
if (g_Map.inMapBounds(corners[i]) && constraint.allows(corners[i].clone().floor()))
entities.push(
g_Map.placeEntityPassable(getWallElement(cornerWallElement, style).templateName, playerId, corners[i], angleToCorner));
if (!skipFirstWall || i != 0)
{
let cornerLength = getWallElement(cornerWallElement, style).length / 2;
let targetCorner = (i + 1) % numCorners;
let startAngle = angleToCorner + angleAddList[i] / 2;
let targetAngle = angleToCorner + angleAddList[targetCorner] / 2;
const cornerLength = getWallElement(cornerWallElement, style).length / 2;
const targetCorner = (i + 1) % numCorners;
const startAngle = angleToCorner + angleAddList[i] / 2;
const targetAngle = angleToCorner + angleAddList[targetCorner] / 2;
entities = entities.concat(
placeLinearWall(
@ -867,10 +867,10 @@ function placeGenericFortress(center, radius = 20, playerId = 0, style, irregula
style = validateStyle(style, playerId);
// Setup some vars
let startAngle = randomAngle();
let actualOff = new Vector2D(radius, 0).rotate(-startAngle);
const startAngle = randomAngle();
const actualOff = new Vector2D(radius, 0).rotate(-startAngle);
let actualAngle = startAngle;
let pointDistance = getWallLength(style, ["long", "tower"]);
const pointDistance = getWallLength(style, ["long", "tower"]);
// Searching for a well fitting point derivation
let tries = 0;
@ -879,20 +879,20 @@ function placeGenericFortress(center, radius = 20, playerId = 0, style, irregula
let overlap;
while (tries < maxTries && minOverlap > g_WallStyles[style].overlap)
{
let pointDerivation = [];
const pointDerivation = [];
let distanceToTarget = 1000;
while (true)
{
let indent = randFloat(-irregularity * pointDistance, irregularity * pointDistance);
let tmp = new Vector2D(radius + indent, 0).rotate(-actualAngle - pointDistance / radius);
let tmpAngle = getAngle(actualOff.x, actualOff.y, tmp.x, tmp.y);
const indent = randFloat(-irregularity * pointDistance, irregularity * pointDistance);
const tmp = new Vector2D(radius + indent, 0).rotate(-actualAngle - pointDistance / radius);
const tmpAngle = getAngle(actualOff.x, actualOff.y, tmp.x, tmp.y);
actualOff.add(new Vector2D(pointDistance, 0).rotate(-tmpAngle));
actualAngle = getAngle(0, 0, actualOff.x, actualOff.y);
pointDerivation.push(actualOff.clone());
distanceToTarget = pointDerivation[0].distanceTo(actualOff);
let numPoints = pointDerivation.length;
const numPoints = pointDerivation.length;
if (numPoints > 3 && distanceToTarget < pointDistance) // Could be done better...
{
overlap = pointDistance - pointDerivation[numPoints - 1].distanceTo(pointDerivation[0]);
@ -910,12 +910,12 @@ function placeGenericFortress(center, radius = 20, playerId = 0, style, irregula
log("placeGenericFortress: Reduced overlap to " + minOverlap + " after " + tries + " tries");
// Place wall
let entities = [];
let constraint = new StaticConstraint(constraints);
const entities = [];
const constraint = new StaticConstraint(constraints);
for (let pointIndex = 0; pointIndex < bestPointDerivation.length; ++pointIndex)
{
let start = Vector2D.add(center, bestPointDerivation[pointIndex]);
let target = Vector2D.add(center, bestPointDerivation[(pointIndex + 1) % bestPointDerivation.length]);
const target = Vector2D.add(center, bestPointDerivation[(pointIndex + 1) % bestPointDerivation.length]);
let angle = getAngle(start.x, start.y, target.x, target.y);
let element = (pointIndex + 1) % gateOccurence == 0 ? "gate" : "long";
@ -923,7 +923,7 @@ function placeGenericFortress(center, radius = 20, playerId = 0, style, irregula
if (element.templateName)
{
let pos = Vector2D.add(start, new Vector2D(start.distanceTo(target) / 2, 0).rotate(-angle));
const pos = Vector2D.add(start, new Vector2D(start.distanceTo(target) / 2, 0).rotate(-angle));
if (g_Map.inMapBounds(pos) && constraint.allows(pos.clone().floor()))
entities.push(g_Map.placeEntityPassable(element.templateName, playerId, pos, angle - Math.PI / 2 + element.angle));
}
@ -932,8 +932,8 @@ function placeGenericFortress(center, radius = 20, playerId = 0, style, irregula
start = Vector2D.add(center, bestPointDerivation[(pointIndex + bestPointDerivation.length - 1) % bestPointDerivation.length]);
angle = getAngle(start.x, start.y, target.x, target.y);
let tower = getWallElement("tower", style);
let pos = Vector2D.add(center, bestPointDerivation[pointIndex]);
const tower = getWallElement("tower", style);
const pos = Vector2D.add(center, bestPointDerivation[pointIndex]);
if (g_Map.inMapBounds(pos) && constraint.allows(pos.clone().floor()))
entities.push(
g_Map.placeEntityPassable(tower.templateName, playerId, pos, angle - Math.PI / 2 + tower.angle));

View File

@ -6,10 +6,10 @@ function Area(points)
{
this.points = deepfreeze(points);
let mapSize = g_Map.getSize();
const mapSize = g_Map.getSize();
this.cache = new Array(mapSize).fill(0).map(() => new Uint8Array(mapSize));
for (let point of points)
for (const point of points)
this.cache[point.x][point.y] = 1;
}
@ -31,9 +31,9 @@ Area.prototype.getClosestPointTo = function(position)
let closestPoint = this.points[0];
let shortestDistance = Infinity;
for (let point of this.points)
for (const point of this.points)
{
let currentDistance = point.distanceToSquared(position);
const currentDistance = point.distanceToSquared(position);
if (currentDistance < shortestDistance)
{
shortestDistance = currentDistance;

View File

@ -214,7 +214,7 @@ SlopeConstraint.prototype.allows = function(position)
*/
function StaticConstraint(constraints)
{
let mapSize = g_Map.getSize();
const mapSize = g_Map.getSize();
this.constraint = new AndConstraint(constraints);
this.cache = new Array(mapSize).fill(0).map(() => new Uint8Array(mapSize));

View File

@ -41,9 +41,9 @@ SimpleGroup.prototype.place = function(playerID, constraint)
// Test if the Objects can be placed at the given location
// Place none of them if one can't be placed.
for (let object of this.objects)
for (const object of this.objects)
{
let entitySpecs = object.place(this.centerPosition, playerID, avoidPositions, constraint, 30);
const entitySpecs = object.place(this.centerPosition, playerID, avoidPositions, constraint, 30);
if (!entitySpecs)
return undefined;
@ -58,8 +58,8 @@ SimpleGroup.prototype.place = function(playerID, constraint)
}
// Create and place entities as specified
let entities = [];
for (let entitySpecs of entitySpecsResult)
const entities = [];
for (const entitySpecs of entitySpecsResult)
{
// The Object must ensure that non-actor entities are not placed at the impassable map-border
entities.push(

View File

@ -7,7 +7,7 @@ function easeCurve(t)
// Find mod of number but only positive values
function modPos(num, m)
{
var p = num % m;
let p = num % m;
if (p < 0)
p += m;
@ -27,12 +27,12 @@ function Noise2D(freq)
this.freq = freq;
this.grads = [];
for (var i=0; i < freq; ++i)
for (let i=0; i < freq; ++i)
{
this.grads[i] = [];
for (var j=0; j < freq; ++j)
for (let j=0; j < freq; ++j)
{
var a = randomAngle();
let a = randomAngle();
this.grads[i][j] = new Vector2D(Math.cos(a), Math.sin(a));
}
}
@ -43,24 +43,24 @@ Noise2D.prototype.get = function(x, y)
x *= this.freq;
y *= this.freq;
var ix = modPos(Math.floor(x), this.freq);
var iy = modPos(Math.floor(y), this.freq);
let ix = modPos(Math.floor(x), this.freq);
let iy = modPos(Math.floor(y), this.freq);
var fx = x - ix;
var fy = y - iy;
let fx = x - ix;
let fy = y - iy;
var ix1 = (ix+1) % this.freq;
var iy1 = (iy+1) % this.freq;
let ix1 = (ix+1) % this.freq;
let iy1 = (iy+1) % this.freq;
var s = this.grads[ix][iy].dot(new Vector2D(fx, fy));
var t = this.grads[ix1][iy].dot(new Vector2D(fx-1, fy));
var u = this.grads[ix][iy1].dot(new Vector2D(fx, fy-1));
var v = this.grads[ix1][iy1].dot(new Vector2D(fx-1, fy-1));
let s = this.grads[ix][iy].dot(new Vector2D(fx, fy));
let t = this.grads[ix1][iy].dot(new Vector2D(fx-1, fy));
let u = this.grads[ix][iy1].dot(new Vector2D(fx, fy-1));
let v = this.grads[ix1][iy1].dot(new Vector2D(fx-1, fy-1));
var ex = easeCurve(fx);
var ey = easeCurve(fy);
var a = s + ex*(t-s);
var b = u + ex*(v-u);
let ex = easeCurve(fx);
let ey = easeCurve(fy);
let a = s + ex*(t-s);
let b = u + ex*(v-u);
return (a + ey*(b-a)) * 0.5 + 0.5;
};
@ -79,15 +79,15 @@ function Noise3D(freq, vfreq)
this.vfreq = vfreq;
this.grads = [];
for (var i=0; i < freq; ++i)
for (let i=0; i < freq; ++i)
{
this.grads[i] = [];
for (var j=0; j < freq; ++j)
for (let j=0; j < freq; ++j)
{
this.grads[i][j] = [];
for(var k=0; k < vfreq; ++k)
for(let k=0; k < vfreq; ++k)
{
var v = new Vector3D();
let v = new Vector3D();
do
{
v.set(randFloat(-1, 1), randFloat(-1, 1), randFloat(-1, 1));
@ -108,39 +108,39 @@ Noise3D.prototype.get = function(x, y, z)
y *= this.freq;
z *= this.vfreq;
var ix =modPos(Math.floor(x), this.freq);
var iy = modPos(Math.floor(y), this.freq);
var iz = modPos(Math.floor(z), this.vfreq);
let ix =modPos(Math.floor(x), this.freq);
let iy = modPos(Math.floor(y), this.freq);
let iz = modPos(Math.floor(z), this.vfreq);
var fx = x - ix;
var fy = y - iy;
var fz = z - iz;
let fx = x - ix;
let fy = y - iy;
let fz = z - iz;
var ix1 = (ix+1) % this.freq;
var iy1 = (iy+1) % this.freq;
var iz1 = (iz+1) % this.vfreq;
let ix1 = (ix+1) % this.freq;
let iy1 = (iy+1) % this.freq;
let iz1 = (iz+1) % this.vfreq;
var s0 = this.grads[ix][iy][iz].dot(new Vector3D(fx, fy, fz));
var t0 = this.grads[ix1][iy][iz].dot(new Vector3D(fx-1, fy, fz));
var u0 = this.grads[ix][iy1][iz].dot(new Vector3D(fx, fy-1, fz));
var v0 = this.grads[ix1][iy1][iz].dot(new Vector3D(fx-1, fy-1, fz));
let s0 = this.grads[ix][iy][iz].dot(new Vector3D(fx, fy, fz));
let t0 = this.grads[ix1][iy][iz].dot(new Vector3D(fx-1, fy, fz));
let u0 = this.grads[ix][iy1][iz].dot(new Vector3D(fx, fy-1, fz));
let v0 = this.grads[ix1][iy1][iz].dot(new Vector3D(fx-1, fy-1, fz));
var s1 = this.grads[ix][iy][iz1].dot(new Vector3D(fx, fy, fz-1));
var t1 = this.grads[ix1][iy][iz1].dot(new Vector3D(fx-1, fy, fz-1));
var u1 = this.grads[ix][iy1][iz1].dot(new Vector3D(fx, fy-1, fz-1));
var v1 = this.grads[ix1][iy1][iz1].dot(new Vector3D(fx-1, fy-1, fz-1));
let s1 = this.grads[ix][iy][iz1].dot(new Vector3D(fx, fy, fz-1));
let t1 = this.grads[ix1][iy][iz1].dot(new Vector3D(fx-1, fy, fz-1));
let u1 = this.grads[ix][iy1][iz1].dot(new Vector3D(fx, fy-1, fz-1));
let v1 = this.grads[ix1][iy1][iz1].dot(new Vector3D(fx-1, fy-1, fz-1));
var ex = easeCurve(fx);
var ey = easeCurve(fy);
var ez = easeCurve(fz);
let ex = easeCurve(fx);
let ey = easeCurve(fy);
let ez = easeCurve(fz);
var a0 = s0 + ex*(t0-s0);
var b0 = u0 + ex*(v0-u0);
var c0 = a0 + ey*(b0-a0);
let a0 = s0 + ex*(t0-s0);
let b0 = u0 + ex*(v0-u0);
let c0 = a0 + ey*(b0-a0);
var a1 = s1 + ex*(t1-s1);
var b1 = u1 + ex*(v1-u1);
var c1 = a1 + ey*(b1-a1);
let a1 = s1 + ex*(t1-s1);
let b1 = u1 + ex*(v1-u1);
let c1 = a1 + ey*(b1-a1);
return (c0 + ez*(c1-c0)) * 0.5 + 0.5;
};

View File

@ -28,17 +28,17 @@ function SimpleObject(templateName, minCount, maxCount, minDistance, maxDistance
SimpleObject.prototype.place = function(centerPosition, playerID, avoidPositions, constraint, maxRetries)
{
let entitySpecs = [];
const entitySpecs = [];
let numRetries = 0;
let validTile = pos => this.templateName.startsWith(g_ActorPrefix) ? g_Map.validTile(pos) : g_Map.validTilePassable(pos);
const validTile = pos => this.templateName.startsWith(g_ActorPrefix) ? g_Map.validTile(pos) : g_Map.validTilePassable(pos);
for (let i = 0; i < randIntInclusive(this.minCount, this.maxCount); ++i)
while (true)
{
let distance = randFloat(this.minDistance, this.maxDistance);
let angle = randomAngle();
const distance = randFloat(this.minDistance, this.maxDistance);
const angle = randomAngle();
let position = Vector2D.sum([centerPosition, new Vector2D(0.5, 0.5), new Vector2D(distance, 0).rotate(-angle)]);
const position = Vector2D.sum([centerPosition, new Vector2D(0.5, 0.5), new Vector2D(distance, 0).rotate(-angle)]);
if (validTile(position) &&
(!avoidPositions ||

View File

@ -71,9 +71,9 @@ RandomMap.prototype.log = function(text)
RandomMap.prototype.LoadMapTerrain = function(filename)
{
g_Map.log("Loading terrain file " + filename);
let mapTerrain = Engine.LoadMapTerrain("maps/random/" + filename + ".pmp");
const mapTerrain = Engine.LoadMapTerrain("maps/random/" + filename + ".pmp");
let heightmapPainter = new HeightmapPainter(convertHeightmap1Dto2D(mapTerrain.height));
const heightmapPainter = new HeightmapPainter(convertHeightmap1Dto2D(mapTerrain.height));
createArea(
new MapBoundsPlacer(),
@ -94,7 +94,7 @@ RandomMap.prototype.LoadHeightmapImage = function(filename, normalMinHeight, nor
{
g_Map.log("Loading heightmap " + filename);
let heightmapPainter = new HeightmapPainter(
const heightmapPainter = new HeightmapPainter(
convertHeightmap1Dto2D(Engine.LoadHeightmapImage("maps/random/" + filename)), normalMinHeight, normalMaxHeight);
createArea(
@ -113,7 +113,7 @@ RandomMap.prototype.getTextureID = function(texture)
if (texture in this.nameToID)
return this.nameToID[texture];
let id = this.IDToName.length;
const id = this.IDToName.length;
this.nameToID[texture] = id;
this.IDToName[id] = texture;
@ -217,7 +217,7 @@ RandomMap.prototype.validHeight = function(position)
*/
RandomMap.prototype.randomCoordinate = function(passableOnly)
{
let border = passableOnly ? MAP_BORDER_WIDTH : 0;
const border = passableOnly ? MAP_BORDER_WIDTH : 0;
if (this.isCircularMap())
// Polar coordinates
@ -278,7 +278,7 @@ RandomMap.prototype.setHeight = function(position, height)
*/
RandomMap.prototype.placeEntityAnywhere = function(templateName, playerID, position, orientation)
{
let entity = new Entity(this.getEntityID(), templateName, playerID, position, orientation);
const entity = new Entity(this.getEntityID(), templateName, playerID, position, orientation);
this.entities.push(entity);
return entity;
};
@ -310,7 +310,7 @@ RandomMap.prototype.getTerrainEntity = function(position)
*/
RandomMap.prototype.setTerrainEntity = function(templateName, playerID, position, orientation)
{
let tilePosition = position.clone().floor();
const tilePosition = position.clone().floor();
if (!this.validTilePassable(tilePosition))
throw new Error("setTerrainEntity: invalid tile position " + uneval(position));
@ -320,7 +320,7 @@ RandomMap.prototype.setTerrainEntity = function(templateName, playerID, position
RandomMap.prototype.deleteTerrainEntity = function(position)
{
let tilePosition = position.clone().floor();
const tilePosition = position.clone().floor();
if (!this.validTilePassable(tilePosition))
throw new Error("setTerrainEntity: invalid tile position " + uneval(position));
@ -337,15 +337,15 @@ RandomMap.prototype.createTileClass = function()
*/
RandomMap.prototype.getExactHeight = function(position)
{
let xi = Math.min(Math.floor(position.x), this.size);
let zi = Math.min(Math.floor(position.y), this.size);
let xf = position.x - xi;
let zf = position.y - zi;
const xi = Math.min(Math.floor(position.x), this.size);
const zi = Math.min(Math.floor(position.y), this.size);
const xf = position.x - xi;
const zf = position.y - zi;
let h00 = this.height[xi][zi];
let h01 = this.height[xi][zi + 1];
let h10 = this.height[xi + 1][zi];
let h11 = this.height[xi + 1][zi + 1];
const h00 = this.height[xi][zi];
const h01 = this.height[xi][zi + 1];
const h10 = this.height[xi + 1][zi];
const h11 = this.height[xi + 1][zi + 1];
return (1 - zf) * ((1 - xf) * h00 + xf * h10) + zf * ((1 - xf) * h01 + xf * h11);
};
@ -356,9 +356,9 @@ RandomMap.prototype.cornerHeight = function(position)
let count = 0;
let sumHeight = 0;
for (let vertex of g_TileVertices)
for (const vertex of g_TileVertices)
{
let pos = Vector2D.sub(position, vertex);
const pos = Vector2D.sub(position, vertex);
if (this.validHeight(pos))
{
++count;
@ -374,11 +374,11 @@ RandomMap.prototype.cornerHeight = function(position)
RandomMap.prototype.getAdjacentPoints = function(position)
{
let adjacentPositions = [];
const adjacentPositions = [];
for (let adjacentCoordinate of g_AdjacentCoordinates)
for (const adjacentCoordinate of g_AdjacentCoordinates)
{
let adjacentPos = Vector2D.add(position, adjacentCoordinate).round();
const adjacentPos = Vector2D.add(position, adjacentCoordinate).round();
if (this.inMapBounds(adjacentPos))
adjacentPositions.push(adjacentPos);
}
@ -391,7 +391,7 @@ RandomMap.prototype.getAdjacentPoints = function(position)
*/
RandomMap.prototype.getAverageHeight = function(position)
{
let adjacentPositions = this.getAdjacentPoints(position);
const adjacentPositions = this.getAdjacentPoints(position);
if (!adjacentPositions.length)
return 0;
@ -403,7 +403,7 @@ RandomMap.prototype.getAverageHeight = function(position)
*/
RandomMap.prototype.getSlope = function(position)
{
let adjacentPositions = this.getAdjacentPoints(position);
const adjacentPositions = this.getAdjacentPoints(position);
if (!adjacentPositions.length)
return 0;
@ -416,10 +416,10 @@ RandomMap.prototype.getSlope = function(position)
*/
RandomMap.prototype.exportEntityList = function()
{
let nonTerrainCount = this.entities.length;
const nonTerrainCount = this.entities.length;
// Change rotation from simple 2d to 3d befor giving to engine
for (let entity of this.entities)
for (const entity of this.entities)
entity.rotation.y = Math.PI / 2 - entity.rotation.y;
// Terrain objects e.g. trees
@ -441,14 +441,14 @@ RandomMap.prototype.exportEntityList = function()
*/
RandomMap.prototype.exportHeightData = function()
{
let heightmapSize = this.size + 1;
let heightmap = new Uint16Array(Math.square(heightmapSize));
const heightmapSize = this.size + 1;
const heightmap = new Uint16Array(Math.square(heightmapSize));
for (let x = 0; x < heightmapSize; ++x)
for (let z = 0; z < heightmapSize; ++z)
{
let position = new Vector2D(x, z);
let currentHeight = TILE_CENTERED_HEIGHT_MAP ? this.cornerHeight(position) : this.getHeight(position);
const position = new Vector2D(x, z);
const currentHeight = TILE_CENTERED_HEIGHT_MAP ? this.cornerHeight(position) : this.getHeight(position);
// Correct height by SEA_LEVEL and prevent under/overflow in terrain data
heightmap[z * heightmapSize + x] = Math.max(0, Math.min(0xFFFF, Math.floor((currentHeight + SEA_LEVEL) * HEIGHT_UNITS_PER_METRE)));
@ -462,8 +462,8 @@ RandomMap.prototype.exportHeightData = function()
*/
RandomMap.prototype.exportTerrainTextures = function()
{
let tileIndex = new Uint16Array(Math.square(this.size));
let tilePriority = new Uint16Array(Math.square(this.size));
const tileIndex = new Uint16Array(Math.square(this.size));
const tilePriority = new Uint16Array(Math.square(this.size));
for (let x = 0; x < this.size; ++x)
for (let z = 0; z < this.size; ++z)

View File

@ -50,9 +50,9 @@ function actorTemplate(templateName)
function getObstructionSize(templateName, margin = 0)
{
let obstruction = Engine.GetTemplate(templateName).Obstruction;
const obstruction = Engine.GetTemplate(templateName).Obstruction;
let obstructionSize =
const obstructionSize =
obstruction.Static ?
new Vector2D(obstruction.Static["@depth"], obstruction.Static["@width"]) :
// Used for gates, should consider the position too
@ -110,14 +110,14 @@ function randomPositionOnTile(tilePosition)
*/
function retryPlacing(placeFunc, retryFactor, amount, behaveDeprecated = false)
{
let maxFail = amount * retryFactor;
const maxFail = amount * retryFactor;
let results = [];
const results = [];
let bad = 0;
while (results.length < amount && bad <= maxFail)
{
let result = placeFunc();
const result = placeFunc();
if (result !== undefined || behaveDeprecated)
results.push(result);
@ -146,7 +146,7 @@ function createObjectGroupsByAreasDeprecated(group, player, constraints, amount,
*/
function createAreas(centeredPlacer, painter, constraints, amount, retryFactor = 10)
{
let placeFunc = function() {
const placeFunc = function() {
centeredPlacer.setCenterPosition(g_Map.randomCoordinate(false));
return createArea(centeredPlacer, painter, constraints);
};
@ -162,11 +162,11 @@ function createAreasInAreas(centeredPlacer, painter, constraints, amount, retryF
{
areas = areas.filter(area => area.getPoints().length);
if (!areas.length) {
log("createAreasInAreas: 'areas' was either empty or only contained empty areas thus returning an empty array.\n" + new Error().stack)
log("createAreasInAreas: 'areas' was either empty or only contained empty areas thus returning an empty array.\n" + new Error().stack);
return [];
}
let placeFunc = function() {
const placeFunc = function() {
centeredPlacer.setCenterPosition(pickRandom(pickRandom(areas).getPoints()));
return createArea(centeredPlacer, painter, constraints);
};
@ -180,7 +180,7 @@ function createAreasInAreas(centeredPlacer, painter, constraints, amount, retryF
*/
function createObjectGroups(group, player, constraints, amount, retryFactor = 10, behaveDeprecated = false)
{
let placeFunc = function() {
const placeFunc = function() {
group.setCenterPosition(g_Map.randomCoordinate(true));
return createObjectGroup(group, player, constraints);
};
@ -196,11 +196,11 @@ function createObjectGroupsByAreas(group, player, constraints, amount, retryFact
{
areas = areas.filter(area => area.getPoints().length);
if (!areas.length) {
log("createObjectGroupsByAreas: 'areas' was either empty or only contained empty areas.\n" + new Error().stack)
log("createObjectGroupsByAreas: 'areas' was either empty or only contained empty areas.\n" + new Error().stack);
return [];
}
let placeFunc = function() {
const placeFunc = function() {
group.setCenterPosition(pickRandom(pickRandom(areas).getPoints()));
return createObjectGroup(group, player, constraints);
};
@ -221,11 +221,11 @@ function createTerrain(terrain)
*/
function createArea(placer, painters, constraints)
{
let points = placer.place(new AndConstraint(constraints));
const points = placer.place(new AndConstraint(constraints));
if (!points)
return undefined;
let area = new Area(points);
const area = new Area(points);
new MultiPainter(painters).paint(area);
@ -270,7 +270,7 @@ function createObjectGroup(group, player, constraints)
*/
function avoidClasses(/*class1, dist1, class2, dist2, etc*/)
{
let ar = [];
const ar = [];
for (let i = 0; i < arguments.length/2; ++i)
ar.push(new AvoidTileClassConstraint(arguments[2*i], arguments[2*i+1]));
@ -286,7 +286,7 @@ function avoidClasses(/*class1, dist1, class2, dist2, etc*/)
*/
function stayClasses(/*class1, dist1, class2, dist2, etc*/)
{
let ar = [];
const ar = [];
for (let i = 0; i < arguments.length/2; ++i)
ar.push(new StayInTileClassConstraint(arguments[2*i], arguments[2*i+1]));
@ -302,7 +302,7 @@ function stayClasses(/*class1, dist1, class2, dist2, etc*/)
*/
function borderClasses(/*class1, idist1, odist1, class2, idist2, odist2, etc*/)
{
let ar = [];
const ar = [];
for (let i = 0; i < arguments.length/3; ++i)
ar.push(new BorderTileClassConstraint(arguments[3*i], arguments[3*i+1], arguments[3*i+2]));
@ -318,7 +318,7 @@ function borderClasses(/*class1, idist1, odist1, class2, idist2, odist2, etc*/)
*/
function extractHeightmap(heightmap, topLeft, size)
{
let result = [];
const result = [];
for (let x = 0; x < size; ++x)
{
result[x] = new Float32Array(size);
@ -330,8 +330,8 @@ function extractHeightmap(heightmap, topLeft, size)
function convertHeightmap1Dto2D(heightmap)
{
let result = [];
let hmSize = Math.sqrt(heightmap.length);
const result = [];
const hmSize = Math.sqrt(heightmap.length);
for (let x = 0; x < hmSize; ++x)
{
result[x] = new Float32Array(hmSize);
@ -351,6 +351,6 @@ function getDifficulties()
*/
function getDifficulty()
{
let level = g_MapSettings.TriggerDifficulty || 3;
const level = g_MapSettings.TriggerDifficulty || 3;
return getDifficulties().find(difficulty => difficulty.Difficulty == level).Difficulty;
}

View File

@ -44,8 +44,8 @@ function distributePointsOnCircle(pointCount, startAngle, radius, center)
*/
function distributePointsOnCircularSegment(pointCount, maxAngle, startAngle, radius, center)
{
let points = [];
let angle = [];
const points = [];
const angle = [];
pointCount = Math.round(pointCount);
for (let i = 0; i < pointCount; ++i)
@ -75,9 +75,9 @@ function distanceOfPointFromLine(lineStart, lineEnd, point)
*/
function testLineIntersection(start1, end1, start2, end2, width)
{
let start1end1 = Vector2D.sub(start1, end1);
let start2end2 = Vector2D.sub(start2, end2);
let start1start2 = Vector2D.sub(start1, start2);
const start1end1 = Vector2D.sub(start1, end1);
const start2end2 = Vector2D.sub(start2, end2);
const start1start2 = Vector2D.sub(start1, start2);
return (
Math.abs(distanceOfPointFromLine(start1, end1, start2)) < width ||
@ -93,10 +93,10 @@ function testLineIntersection(start1, end1, start2, end2, width)
*/
function getBoundingBox(points)
{
let min = points[0].clone();
let max = points[0].clone();
const min = points[0].clone();
const max = points[0].clone();
for (let point of points)
for (const point of points)
{
min.set(Math.min(min.x, point.x), Math.min(min.y, point.y));
max.set(Math.max(max.x, point.x), Math.max(max.y, point.y));
@ -110,7 +110,7 @@ function getBoundingBox(points)
function getPointsInBoundingBox(boundingBox)
{
let points = [];
const points = [];
for (let x = boundingBox.min.x; x <= boundingBox.max.x; ++x)
for (let y = boundingBox.min.y; y <= boundingBox.max.y; ++y)
points.push(new Vector2D(x, y));
@ -124,8 +124,8 @@ function getPointsInBoundingBox(boundingBox)
*/
function sortPointsShortestCycle(points)
{
let order = [];
let distances = [];
const order = [];
const distances = [];
if (points.length <= 3)
{
for (let i = 0; i < points.length; ++i)
@ -135,7 +135,7 @@ function sortPointsShortestCycle(points)
}
// Just add the first 3 points
let pointsToAdd = points.map(p => p.clone());
const pointsToAdd = points.map(p => p.clone());
for (let i = 0; i < 3; ++i)
{
order.push(i);
@ -147,7 +147,7 @@ function sortPointsShortestCycle(points)
distances.push(points[order[0]].distanceTo(points[order[order.length - 1]]));
// Add remaining points so the path lengthens the least
let numPointsToAdd = pointsToAdd.length;
const numPointsToAdd = pointsToAdd.length;
for (let i = 0; i < numPointsToAdd; ++i)
{
let indexToAddTo;
@ -156,10 +156,10 @@ function sortPointsShortestCycle(points)
let minDist2 = 0;
for (let k = 0; k < order.length; ++k)
{
let dist1 = pointsToAdd[0].distanceTo(points[order[k]]);
let dist2 = pointsToAdd[0].distanceTo(points[order[(k + 1) % order.length]]);
const dist1 = pointsToAdd[0].distanceTo(points[order[k]]);
const dist2 = pointsToAdd[0].distanceTo(points[order[(k + 1) % order.length]]);
let enlengthen = dist1 + dist2 - distances[k];
const enlengthen = dist1 + dist2 - distances[k];
if (enlengthen < minEnlengthen)
{
indexToAddTo = k;

View File

@ -7,7 +7,7 @@ function CityPainter(templates, angle, playerID)
this.playerID = playerID;
this.templates = templates.map(template => {
let obstructionSize = getObstructionSize(template.templateName, template.margin || 0);
const obstructionSize = getObstructionSize(template.templateName, template.margin || 0);
return {
"templateName": template.templateName,
"maxCount": template.maxCount !== undefined ? template.maxCount : Infinity,
@ -27,42 +27,42 @@ CityPainter.prototype.paint = function(area)
{
let templates = this.templates;
let templateCounts = {};
for (let template of this.templates)
const templateCounts = {};
for (const template of this.templates)
templateCounts[template.templateName] = 0;
let mapCenter = g_Map.getCenter();
let mapSize = g_Map.getSize();
const mapCenter = g_Map.getCenter();
const mapSize = g_Map.getSize();
// TODO: Due to the rounding, this is wasting a lot of space.
// The city would be much denser if it would test for actual shape intersection or
// if it would use a custom, more fine-grained obstruction grid
let tileClass = g_Map.createTileClass();
const tileClass = g_Map.createTileClass();
let processed = new Array(mapSize).fill(0).map(() => new Uint8Array(mapSize));
const processed = new Array(mapSize).fill(0).map(() => new Uint8Array(mapSize));
for (let x = 0; x < mapSize; x += 0.5)
for (let y = 0; y < mapSize; y += 0.5)
{
let point = new Vector2D(x, y).rotateAround(this.angle, mapCenter).round();
const point = new Vector2D(x, y).rotateAround(this.angle, mapCenter).round();
if (!area.contains(point) || processed[point.x][point.y] || !g_Map.validTilePassable(point))
continue;
processed[point.x][point.y] = 1;
for (let template of shuffleArray(templates))
for (const template of shuffleArray(templates))
{
if (template.constraint && !template.constraint.allows(point))
continue;
// Randomize building angle while keeping it aligned
let buildingAngle = this.angle + randIntInclusive(0, 3) * Math.PI / 2;
const buildingAngle = this.angle + randIntInclusive(0, 3) * Math.PI / 2;
// Place the entity if all points are within the boundaries and don't collide with the other entities
let obstructionCorners = template.obstructionCorners.map(obstructionCorner =>
const obstructionCorners = template.obstructionCorners.map(obstructionCorner =>
Vector2D.add(point, obstructionCorner.clone().rotate(buildingAngle)));
let obstructionPoints = new ConvexPolygonPlacer(obstructionCorners, 0).place(
const obstructionPoints = new ConvexPolygonPlacer(obstructionCorners, 0).place(
new AndConstraint([new StayAreasConstraint([area]), avoidClasses(tileClass, 0), new PassableMapAreaConstraint()]));
if (!obstructionPoints)
@ -73,7 +73,7 @@ CityPainter.prototype.paint = function(area)
if (template.painter)
template.painter.paint(new Area(obstructionPoints));
for (let obstructionPoint of obstructionPoints)
for (const obstructionPoint of obstructionPoints)
tileClass.add(obstructionPoint);
++templateCounts[template.templateName];

View File

@ -9,6 +9,6 @@ function ElevationBlendingPainter(targetHeight, strength)
ElevationBlendingPainter.prototype.paint = function(area)
{
for (let point of area.getPoints())
for (const point of area.getPoints())
g_Map.setHeight(point, this.strength * this.targetHeight + (1 - this.strength) * g_Map.getHeight(point));
};

View File

@ -8,10 +8,10 @@ function ElevationPainter(elevation)
ElevationPainter.prototype.paint = function(area)
{
for (let point of area.getPoints())
for (let vertex of g_TileVertices)
for (const point of area.getPoints())
for (const vertex of g_TileVertices)
{
let position = Vector2D.add(point, vertex);
const position = Vector2D.add(point, vertex);
if (g_Map.validHeight(position))
g_Map.setHeight(position, this.elevation);
}

View File

@ -26,37 +26,37 @@ HeightmapPainter.prototype.scaleHeight = function(height)
if (this.normalMinHeight === undefined || this.normalMaxHeight === undefined)
return height / this.getScale() / HEIGHT_UNITS_PER_METRE;
let minHeight = this.normalMinHeight * (g_Map.getSize() + 1) / 321;
let maxHeight = this.normalMaxHeight * (g_Map.getSize() + 1) / 321;
const minHeight = this.normalMinHeight * (g_Map.getSize() + 1) / 321;
const maxHeight = this.normalMaxHeight * (g_Map.getSize() + 1) / 321;
return minHeight + (maxHeight - minHeight) * height / 0xFFFF;
};
HeightmapPainter.prototype.paint = function(area)
{
let scale = this.getScale();
let leftBottom = new Vector2D(0, 0);
let rightTop = new Vector2D(this.verticesPerSide, this.verticesPerSide);
let brushSize = new Vector2D(3, 3);
let brushCenter = new Vector2D(1, 1);
const scale = this.getScale();
const leftBottom = new Vector2D(0, 0);
const rightTop = new Vector2D(this.verticesPerSide, this.verticesPerSide);
const brushSize = new Vector2D(3, 3);
const brushCenter = new Vector2D(1, 1);
// Additional complexity to process all 4 vertices of each tile, i.e the last row too
let seen = new Array(g_Map.height.length).fill(0).map(zero => new Uint8Array(g_Map.height.length).fill(0));
const seen = new Array(g_Map.height.length).fill(0).map(zero => new Uint8Array(g_Map.height.length).fill(0));
for (let point of area.getPoints())
for (let vertex of g_TileVertices)
for (const point of area.getPoints())
for (const vertex of g_TileVertices)
{
let vertexPos = Vector2D.add(point, vertex);
const vertexPos = Vector2D.add(point, vertex);
if (!g_Map.validHeight(vertexPos) || seen[vertexPos.x][vertexPos.y])
continue;
seen[vertexPos.x][vertexPos.y] = 1;
let sourcePos = Vector2D.mult(vertexPos, scale);
let sourceTilePos = sourcePos.clone().floor();
const sourcePos = Vector2D.mult(vertexPos, scale);
const sourceTilePos = sourcePos.clone().floor();
let brushPosition = Vector2D.max(
const brushPosition = Vector2D.max(
leftBottom,
Vector2D.min(
Vector2D.sub(sourceTilePos, brushCenter),

View File

@ -13,6 +13,6 @@ function MultiPainter(painters)
MultiPainter.prototype.paint = function(area)
{
for (let painter of this.painters)
for (const painter of this.painters)
painter.paint(area);
};

View File

@ -9,10 +9,10 @@ function RandomElevationPainter(minHeight, maxHeight)
RandomElevationPainter.prototype.paint = function(area)
{
for (let point of area.getPoints())
for (let vertex of g_TileVertices)
for (const point of area.getPoints())
for (const vertex of g_TileVertices)
{
let position = Vector2D.add(point, vertex);
const position = Vector2D.add(point, vertex);
if (g_Map.validHeight(position))
g_Map.setHeight(position, randFloat(this.minHeight, this.maxHeight));
}

View File

@ -31,11 +31,11 @@ function SmoothElevationPainter(type, elevation, blendRadius, randomElevation =
SmoothElevationPainter.prototype.paint = function(area)
{
// The heightmap grid has one more vertex per side than the tile grid
let heightmapSize = g_Map.height.length;
const heightmapSize = g_Map.height.length;
// Remember height inside the area before changing it
let gotHeightPt = [];
let newHeight = [];
const gotHeightPt = [];
const newHeight = [];
for (let i = 0; i < heightmapSize; ++i)
{
gotHeightPt[i] = new Uint8Array(heightmapSize);
@ -43,16 +43,16 @@ SmoothElevationPainter.prototype.paint = function(area)
}
// Get heightmap grid vertices within or adjacent to the area
let brushSize = 2;
let heightPoints = [];
for (let point of area.getPoints())
const brushSize = 2;
const heightPoints = [];
for (const point of area.getPoints())
for (let dx = -1; dx < 1 + brushSize; ++dx)
{
let nx = point.x + dx;
const nx = point.x + dx;
for (let dz = -1; dz < 1 + brushSize; ++dz)
{
let nz = point.y + dz;
let position = new Vector2D(nx, nz);
const nz = point.y + dz;
const position = new Vector2D(nx, nz);
if (g_Map.validHeight(position) && !gotHeightPt[nx][nz])
{
@ -63,7 +63,7 @@ SmoothElevationPainter.prototype.paint = function(area)
}
}
let withinArea = (area, position) => g_TileVertices.some(vertexPos => area.contains(Vector2D.sub(position, vertexPos)));
const withinArea = (area, position) => g_TileVertices.some(vertexPos => area.contains(Vector2D.sub(position, vertexPos)));
// Change height inside the area depending on the distance to the border
breadthFirstSearchPaint({
@ -84,7 +84,7 @@ SmoothElevationPainter.prototype.paint = function(area)
});
// Smooth everything out
for (let point of heightPoints)
for (const point of heightPoints)
{
if (!withinArea(area, point))
continue;
@ -94,11 +94,11 @@ SmoothElevationPainter.prototype.paint = function(area)
for (let dx = -1; dx <= 1; ++dx)
{
let nx = point.x + dx;
const nx = point.x + dx;
for (let dz = -1; dz <= 1; ++dz)
{
let nz = point.y + dz;
const nz = point.y + dz;
if (g_Map.validHeight(new Vector2D(nx, nz)))
{
@ -126,27 +126,27 @@ SmoothElevationPainter.prototype.paint = function(area)
function breadthFirstSearchPaint(args)
{
// These variables save which points were visited already and the shortest distance to the area
let saw = [];
let dist = [];
const saw = [];
const dist = [];
for (let i = 0; i < args.gridSize; ++i)
{
saw[i] = new Uint8Array(args.gridSize);
dist[i] = new Uint16Array(args.gridSize);
}
let withinGrid = (x, z) => Math.min(x, z) >= 0 && Math.max(x, z) < args.gridSize;
const withinGrid = (x, z) => Math.min(x, z) >= 0 && Math.max(x, z) < args.gridSize;
// Find all points outside of the area, mark them as seen and set zero distance
let pointQueue = [];
for (let point of args.area.getPoints())
const pointQueue = [];
for (const point of args.area.getPoints())
// The brushSize is added because the entire brushSize is by definition part of the area
for (let dx = -1; dx < 1 + args.brushSize; ++dx)
{
let nx = point.x + dx;
const nx = point.x + dx;
for (let dz = -1; dz < 1 + args.brushSize; ++dz)
{
let nz = point.y + dz;
let position = new Vector2D(nx, nz);
const nz = point.y + dz;
const position = new Vector2D(nx, nz);
if (!withinGrid(nx, nz) || args.withinArea(args.area, position) || saw[nx][nz])
continue;
@ -161,8 +161,8 @@ function breadthFirstSearchPaint(args)
// Call the paintTile method for each point within the area, with distance == 1 for the border.
while (pointQueue.length)
{
let point = pointQueue.shift();
let distance = dist[point.x][point.y];
const point = pointQueue.shift();
const distance = dist[point.x][point.y];
if (args.withinArea(args.area, point))
args.paintTile(point, distance);
@ -170,11 +170,11 @@ function breadthFirstSearchPaint(args)
// Enqueue neighboring points
for (let dx = -1; dx <= 1; ++dx)
{
let nx = point.x + dx;
const nx = point.x + dx;
for (let dz = -1; dz <= 1; ++dz)
{
let nz = point.y + dz;
let position = new Vector2D(nx, nz);
const nz = point.y + dz;
const position = new Vector2D(nx, nz);
if (!withinGrid(nx, nz) || !args.withinArea(args.area, position) || saw[nx][nz])
continue;

View File

@ -23,20 +23,20 @@ function SmoothingPainter(size, strength, iterations)
SmoothingPainter.prototype.paint = function(area)
{
let brushPoints = getPointsInBoundingBox(getBoundingBox(
const brushPoints = getPointsInBoundingBox(getBoundingBox(
new Array(2).fill(0).map((zero, i) => new Vector2D(1, 1).mult(this.size).mult(i ? 1 : -1))));
for (let i = 0; i < this.iterations; ++i)
{
let heightmap = clone(g_Map.height);
const heightmap = clone(g_Map.height);
// Additional complexity to process all 4 vertices of each tile, i.e the last row too
let seen = new Array(heightmap.length).fill(0).map(zero => new Uint8Array(heightmap.length).fill(0));
const seen = new Array(heightmap.length).fill(0).map(zero => new Uint8Array(heightmap.length).fill(0));
for (let point of area.getPoints())
for (let tileVertex of g_TileVertices)
for (const point of area.getPoints())
for (const tileVertex of g_TileVertices)
{
let vertex = Vector2D.add(point, tileVertex);
const vertex = Vector2D.add(point, tileVertex);
if (!g_Map.validHeight(vertex) || seen[vertex.x][vertex.y])
continue;
@ -45,10 +45,10 @@ SmoothingPainter.prototype.paint = function(area)
let sumWeightedHeights = 0;
let sumWeights = 0;
for (let brushPoint of brushPoints)
for (const brushPoint of brushPoints)
{
let position = Vector2D.add(vertex, brushPoint);
let distance = Math.abs(brushPoint.x) + Math.abs(brushPoint.y);
const position = Vector2D.add(vertex, brushPoint);
const distance = Math.abs(brushPoint.x) + Math.abs(brushPoint.y);
if (!distance || !g_Map.validHeight(position))
continue;

View File

@ -9,6 +9,6 @@ function TerrainPainter(terrain)
TerrainPainter.prototype.paint = function(area)
{
for (let point of area.getPoints())
for (const point of area.getPoints())
this.terrain.place(point);
};

View File

@ -13,12 +13,12 @@ function TerrainTextureArrayPainter(textureIDs, textureNames)
TerrainTextureArrayPainter.prototype.paint = function(area)
{
let sourceSize = Math.sqrt(this.textureIDs.length);
let scale = sourceSize / g_Map.getSize();
const sourceSize = Math.sqrt(this.textureIDs.length);
const scale = sourceSize / g_Map.getSize();
for (let point of area.getPoints())
for (const point of area.getPoints())
{
let sourcePos = Vector2D.mult(point, scale).floor();
const sourcePos = Vector2D.mult(point, scale).floor();
g_Map.setTexture(point, this.textureNames[this.textureIDs[sourcePos.x * sourceSize + sourcePos.y]]);
}
};

View File

@ -8,6 +8,6 @@ function TileClassPainter(tileClass)
TileClassPainter.prototype.paint = function(area)
{
for (let point of area.getPoints())
for (const point of area.getPoints())
this.tileClass.add(point);
};

View File

@ -8,6 +8,6 @@ function TileClassUnPainter(tileClass)
TileClassUnPainter.prototype.paint = function(area)
{
for (let point of area.getPoints())
for (const point of area.getPoints())
this.tileClass.remove(point);
};

View File

@ -34,30 +34,30 @@ ChainPlacer.prototype.place = function(constraint)
if (!g_Map.inMapBounds(this.centerPosition) || !constraint.allows(this.centerPosition))
return undefined;
let points = [];
const points = [];
let size = g_Map.getSize();
let failed = 0;
let count = 0;
let gotRet = new Array(size).fill(0).map(p => new Array(size).fill(-1));
const gotRet = new Array(size).fill(0).map(p => new Array(size).fill(-1));
--size;
this.minRadius = Math.min(this.maxRadius, Math.max(this.minRadius, 1));
let edges = [this.centerPosition];
const edges = [this.centerPosition];
for (let i = 0; i < this.numCircles; ++i)
{
let chainPos = pickRandom(edges);
let radius = this.queue.length ? this.queue.pop() : randIntInclusive(this.minRadius, this.maxRadius);
let radius2 = Math.square(radius);
const chainPos = pickRandom(edges);
const radius = this.queue.length ? this.queue.pop() : randIntInclusive(this.minRadius, this.maxRadius);
const radius2 = Math.square(radius);
let bbox = getPointsInBoundingBox(getBoundingBox([
const bbox = getPointsInBoundingBox(getBoundingBox([
new Vector2D(Math.max(0, chainPos.x - radius), Math.max(0, chainPos.y - radius)),
new Vector2D(Math.min(chainPos.x + radius, size), Math.min(chainPos.y + radius, size))
]));
for (let position of bbox)
for (const position of bbox)
{
if (position.distanceToSquared(chainPos) >= radius2)
continue;
@ -70,7 +70,7 @@ ChainPlacer.prototype.place = function(constraint)
continue;
}
let state = gotRet[position.x][position.y];
const state = gotRet[position.x][position.y];
if (state == -1)
{
points.push(position);
@ -86,7 +86,7 @@ ChainPlacer.prototype.place = function(constraint)
}
}
for (let pos of bbox)
for (const pos of bbox)
{
if (this.maxDistance &&
(Math.abs(this.centerPosition.x - pos.x) > this.maxDistance ||

View File

@ -30,25 +30,25 @@ ClumpPlacer.prototype.place = function(constraint)
if (!g_Map.inMapBounds(this.centerPosition) || !constraint.allows(this.centerPosition))
return undefined;
var points = [];
let points = [];
var size = g_Map.getSize();
var gotRet = new Array(size).fill(0).map(p => new Uint8Array(size)); // booleans
var radius = Math.sqrt(this.size / Math.PI);
var perim = 4 * radius * 2 * Math.PI;
var intPerim = Math.ceil(perim);
let size = g_Map.getSize();
let gotRet = new Array(size).fill(0).map(p => new Uint8Array(size)); // booleans
let radius = Math.sqrt(this.size / Math.PI);
let perim = 4 * radius * 2 * Math.PI;
let intPerim = Math.ceil(perim);
var ctrlPts = 1 + Math.floor(1.0/Math.max(this.smoothness,1.0/intPerim));
let ctrlPts = 1 + Math.floor(1.0/Math.max(this.smoothness,1.0/intPerim));
if (ctrlPts > radius * 2 * Math.PI)
ctrlPts = Math.floor(radius * 2 * Math.PI) + 1;
var noise = new Float32Array(intPerim); //float32
var ctrlCoords = new Float32Array(ctrlPts+1); //float32
var ctrlVals = new Float32Array(ctrlPts+1); //float32
let noise = new Float32Array(intPerim); //float32
let ctrlCoords = new Float32Array(ctrlPts+1); //float32
let ctrlVals = new Float32Array(ctrlPts+1); //float32
// Generate some interpolated noise
for (var i=0; i < ctrlPts; i++)
for (let i=0; i < ctrlPts; i++)
{
ctrlCoords[i] = i * perim / ctrlPts;
ctrlVals[i] = randFloat(0, 2);
@ -78,14 +78,14 @@ ClumpPlacer.prototype.place = function(constraint)
let count = 0;
for (let stepAngle = 0; stepAngle < intPerim; ++stepAngle)
{
let position = this.centerPosition.clone();
let radiusUnitVector = new Vector2D(0, 1).rotate(-2 * Math.PI * stepAngle / perim);
let maxRadiusSteps = Math.ceil(radius * (1 + (1 - this.coherence) * noise[stepAngle]));
const position = this.centerPosition.clone();
const radiusUnitVector = new Vector2D(0, 1).rotate(-2 * Math.PI * stepAngle / perim);
const maxRadiusSteps = Math.ceil(radius * (1 + (1 - this.coherence) * noise[stepAngle]));
count += maxRadiusSteps;
for (let stepRadius = 0; stepRadius < maxRadiusSteps; ++stepRadius)
{
let tilePos = position.clone().floor();
const tilePos = position.clone().floor();
if (g_Map.inMapBounds(tilePos) && constraint.allows(tilePos))
{

View File

@ -18,14 +18,14 @@ DiskPlacer.prototype.setCenterPosition = function(position)
DiskPlacer.prototype.place = function(constraint)
{
let points = [];
const points = [];
const xMin = Math.floor(Math.max(0, this.centerPosition.x - this.radius));
const yMin = Math.floor(Math.max(0, this.centerPosition.y - this.radius));
const xMax = Math.ceil(Math.min(g_Map.getSize() - 1, this.centerPosition.x + this.radius));
const yMax = Math.ceil(Math.min(g_Map.getSize() - 1, this.centerPosition.y + this.radius));
let it = new Vector2D();
const it = new Vector2D();
for (it.x = xMin; it.x <= xMax; ++it.x)
for (it.y = yMin; it.y <= yMax; ++it.y)
{

View File

@ -9,11 +9,11 @@ function ConvexPolygonPlacer(points, failFraction = 0)
ConvexPolygonPlacer.prototype.place = function(constraint)
{
let points = [];
const points = [];
let count = 0;
let failed = 0;
for (let point of getPointsInBoundingBox(getBoundingBox(this.polygonVertices)))
for (const point of getPointsInBoundingBox(getBoundingBox(this.polygonVertices)))
{
if (this.polygonVertices.some((vertex, i) =>
distanceOfPointFromLine(this.polygonVertices[i], this.polygonVertices[(i + 1) % this.polygonVertices.length], point) > 0))
@ -36,13 +36,13 @@ ConvexPolygonPlacer.prototype.place = function(constraint)
*/
ConvexPolygonPlacer.prototype.getConvexHull = function(points)
{
let uniquePoints = [];
for (let point of points)
const uniquePoints = [];
for (const point of points)
if (uniquePoints.every(p => p.x != point.x || p.y != point.y))
uniquePoints.push(point);
// Start with the leftmost point
let result = [uniquePoints.reduce((leftMost, point) => point.x < leftMost.x ? point : leftMost, uniquePoints[0])];
const result = [uniquePoints.reduce((leftMost, point) => point.x < leftMost.x ? point : leftMost, uniquePoints[0])];
// Add the vector most left of the most recently added point until a cycle is reached
while (result.length < uniquePoints.length)
@ -50,7 +50,7 @@ ConvexPolygonPlacer.prototype.getConvexHull = function(points)
let nextLeftmostPoint;
// Of all points, find the one that is leftmost
for (let point of uniquePoints)
for (const point of uniquePoints)
{
if (point == result[result.length - 1])
continue;

View File

@ -13,11 +13,11 @@ EntitiesObstructionPlacer.prototype.place = function(constraint)
{
let points = [];
for (let entity of this.entities)
for (const entity of this.entities)
{
let halfObstructionSize = getObstructionSize(entity.templateName, this.margin).div(2);
const halfObstructionSize = getObstructionSize(entity.templateName, this.margin).div(2);
let obstructionCorners = [
const obstructionCorners = [
new Vector2D(-halfObstructionSize.x, -halfObstructionSize.y),
new Vector2D(-halfObstructionSize.x, +halfObstructionSize.y),
new Vector2D(+halfObstructionSize.x, -halfObstructionSize.y),

View File

@ -25,7 +25,7 @@ function HeightPlacer(mode, minElevation, maxElevation)
HeightPlacer.prototype.place = function(constraint)
{
let mapSize = g_Map.getSize();
const mapSize = g_Map.getSize();
return getPointsInBoundingBox(getBoundingBox([new Vector2D(0, 0), new Vector2D(mapSize - 1, mapSize - 1)])).filter(
point => this.withinHeightRange(point) && constraint.allows(point));

View File

@ -3,7 +3,7 @@
*/
function MapBoundsPlacer(failFraction = Infinity)
{
let mapBounds = g_Map.getBounds();
const mapBounds = g_Map.getBounds();
this.rectPlacer = new RectPlacer(new Vector2D(mapBounds.left, mapBounds.top), new Vector2D(mapBounds.right, mapBounds.bottom), failFraction);
}

Some files were not shown because too many files have changed in this diff Show More