Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/maps/random/caledonian_meadows.js
Show First 20 Lines • Show All 275 Lines • ▼ Show 20 Lines | for (let y = minDistance; y < heightmap[0].length - minDistance; ++y) | ||||
if (heightmap[x][y] > heightRange.min && heightmap[x][y] < heightRange.max && // Has correct height | if (heightmap[x][y] > heightRange.min && heightmap[x][y] < heightRange.max && // Has correct height | ||||
(!isCircular || r - getDistance(x, y, r, r) >= minDistance)) // Enough distance to map border | (!isCircular || r - getDistance(x, y, r, r) >= minDistance)) // Enough distance to map border | ||||
validVertices.push({ "x": x, "y": y , "dist": minDistance}); | validVertices.push({ "x": x, "y": y , "dist": minDistance}); | ||||
} | } | ||||
} | } | ||||
for (let tries = 0; tries < maxTries; ++tries) | for (let tries = 0; tries < maxTries; ++tries) | ||||
{ | { | ||||
let point = validVertices[randInt(validVertices.length)]; | let point = pickRandom(validVertices); | ||||
if (placements.every(p => getDistance(p.x, p.y, point.x, point.y) > max(minDistance, p.dist))) | if (placements.every(p => getDistance(p.x, p.y, point.x, point.y) > max(minDistance, p.dist))) | ||||
{ | { | ||||
points.push(point); | points.push(point); | ||||
placements.push(point); | placements.push(point); | ||||
} | } | ||||
if ((tries != 0) && (tries % 100 == 0)) // Time Check | if ((tries != 0) && (tries % 100 == 0)) // Time Check | ||||
log(points.length + " points found after " + tries + " tries after " + ((new Date().getTime() - genStartTime) / 1000) + "s"); | log(points.length + " points found after " + tries + " tries after " + ((new Date().getTime() - genStartTime) / 1000) + "s"); | ||||
} | } | ||||
Show All 17 Lines | |||||
{ | { | ||||
placeObject(point.x, point.y, centerEntity, 0, randFloat(0, TWO_PI)); | placeObject(point.x, point.y, centerEntity, 0, randFloat(0, TWO_PI)); | ||||
let quantity = randInt(11, 23); | let quantity = randInt(11, 23); | ||||
let dAngle = TWO_PI / quantity; | let dAngle = TWO_PI / quantity; | ||||
for (let i = 0; i < quantity; ++i) | for (let i = 0; i < quantity; ++i) | ||||
{ | { | ||||
let angle = i * dAngle + randFloat(0, dAngle); | let angle = i * dAngle + randFloat(0, dAngle); | ||||
let dist = randFloat(2, 5); | let dist = randFloat(2, 5); | ||||
placeObject(point.x + dist * Math.cos(angle), point.y + dist * Math.sin(angle), decorations[randInt(0, decorations.length - 1)], 0, randFloat(0, TWO_PI)); | placeObject(point.x + dist * Math.cos(angle), point.y + dist * Math.sin(angle), pickRandom(decorations), 0, randFloat(0, 2 * PI)); | ||||
} | } | ||||
} | } | ||||
// Food, fences with domestic animals | // Food, fences with domestic animals | ||||
wallStyles["other"]["sheepIn"] = new WallElement("sheepIn", "gaia/fauna_sheep", PI / 4, -1.5, 0.75, PI/2); | wallStyles["other"]["sheepIn"] = new WallElement("sheepIn", "gaia/fauna_sheep", PI / 4, -1.5, 0.75, PI/2); | ||||
wallStyles["other"]["foodBin"] = new WallElement("foodBin", "gaia/special_treasure_food_bin", PI/2, 1.5); | wallStyles["other"]["foodBin"] = new WallElement("foodBin", "gaia/special_treasure_food_bin", PI/2, 1.5); | ||||
wallStyles["other"]["sheep"] = new WallElement("sheep", "gaia/fauna_sheep", 0, 0, 0.75); | wallStyles["other"]["sheep"] = new WallElement("sheep", "gaia/fauna_sheep", 0, 0, 0.75); | ||||
wallStyles["other"]["farm"] = new WallElement("farm", "structures/brit_farmstead", PI, 0, -3); | wallStyles["other"]["farm"] = new WallElement("farm", "structures/brit_farmstead", PI, 0, -3); | ||||
Show All 23 Lines | let groveActors = [ | ||||
"actor|geology/highland1_moss.xml", "actor|geology/highland2_moss.xml", | "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.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" | "actor|props/flora/bush_tempe_a.xml", "actor|props/flora/bush_tempe_b.xml", "actor|props/flora/ferns.xml" | ||||
]; | ]; | ||||
let clGrove = createTileClass(); | let clGrove = createTileClass(); | ||||
function placeGrove(point) | function placeGrove(point) | ||||
{ | { | ||||
placeObject(point.x, point.y, ["structures/gaul_outpost", "gaia/flora_tree_oak_new"][randInt(0, 1)], 0, randFloat(0, TWO_PI)); | placeObject(point.x, point.y, pickRandom(["structures/gaul_outpost", "gaia/flora_tree_oak_new"]), 0, randFloat(0, 2 * PI)); | ||||
let quantity = randInt(20, 30); | let quantity = randIntInclusive(20, 30); | ||||
let dAngle = TWO_PI / quantity; | let dAngle = TWO_PI / quantity; | ||||
for (let i = 0; i < quantity; ++i) | for (let i = 0; i < quantity; ++i) | ||||
{ | { | ||||
let angle = i * dAngle + randFloat(0, dAngle); | let angle = dAngle * randFloat(i, i+1); | ||||
let dist = randFloat(2, 5); | let dist = randFloat(2, 5); | ||||
let objectList = groveEntities; | let objectList = groveEntities; | ||||
if (i % 3 == 0) | if (i % 3 == 0) | ||||
objectList = groveActors; | objectList = groveActors; | ||||
let x = point.x + dist * Math.cos(angle); | let x = point.x + dist * Math.cos(angle); | ||||
let y = point.y + dist * Math.sin(angle); | let y = point.y + dist * Math.sin(angle); | ||||
placeObject(x, y, objectList[randInt(0, objectList.length - 1)], 0, randFloat(0, TWO_PI)); | placeObject(x, y, pickRandom(objectList), 0, randFloat(0, 2 * PI)); | ||||
createArea(new ClumpPlacer(5, 1, 1, 1, floor(x), floor(y)), [new TerrainPainter("temp_grass_plants"), paintClass(clGrove)]); | createArea(new ClumpPlacer(5, 1, 1, 1, floor(x), floor(y)), [new TerrainPainter("temp_grass_plants"), paintClass(clGrove)]); | ||||
} | } | ||||
} | } | ||||
// Camps with fire and gold treasure | // Camps with fire and gold treasure | ||||
function placeCamp(point, | function placeCamp(point, | ||||
centerEntity = "actor|props/special/eyecandy/campfire.xml", | centerEntity = "actor|props/special/eyecandy/campfire.xml", | ||||
otherEntities = ["gaia/special_treasure_metal", "gaia/special_treasure_standing_stone", | otherEntities = ["gaia/special_treasure_metal", "gaia/special_treasure_standing_stone", | ||||
"units/brit_infantry_slinger_b", "units/brit_infantry_javelinist_b", "units/gaul_infantry_slinger_b", "units/gaul_infantry_javelinist_b", "units/gaul_champion_fanatic", | "units/brit_infantry_slinger_b", "units/brit_infantry_javelinist_b", "units/gaul_infantry_slinger_b", "units/gaul_infantry_javelinist_b", "units/gaul_champion_fanatic", | ||||
"actor|props/special/common/waypoint_flag.xml", "actor|props/special/eyecandy/barrel_a.xml", "actor|props/special/eyecandy/basket_celt_a.xml", "actor|props/special/eyecandy/crate_a.xml", "actor|props/special/eyecandy/dummy_a.xml", "actor|props/special/eyecandy/handcart_1.xml", "actor|props/special/eyecandy/handcart_1_broken.xml", "actor|props/special/eyecandy/sack_1.xml", "actor|props/special/eyecandy/sack_1_rough.xml" | "actor|props/special/common/waypoint_flag.xml", "actor|props/special/eyecandy/barrel_a.xml", "actor|props/special/eyecandy/basket_celt_a.xml", "actor|props/special/eyecandy/crate_a.xml", "actor|props/special/eyecandy/dummy_a.xml", "actor|props/special/eyecandy/handcart_1.xml", "actor|props/special/eyecandy/handcart_1_broken.xml", "actor|props/special/eyecandy/sack_1.xml", "actor|props/special/eyecandy/sack_1_rough.xml" | ||||
] | ] | ||||
) | ) | ||||
{ | { | ||||
placeObject(point.x, point.y, centerEntity, 0, randFloat(0, TWO_PI)); | placeObject(point.x, point.y, centerEntity, 0, randFloat(0, TWO_PI)); | ||||
let quantity = randInt(5, 11); | let quantity = randInt(5, 11); | ||||
let dAngle = TWO_PI / quantity; | let dAngle = TWO_PI / quantity; | ||||
for (let i = 0; i < quantity; ++i) | for (let i = 0; i < quantity; ++i) | ||||
{ | { | ||||
let angle = i * dAngle + randFloat(0, dAngle); | let angle = i * dAngle + randFloat(0, dAngle); | ||||
let dist = randFloat(1, 3); | let dist = randFloat(1, 3); | ||||
placeObject(point.x + dist * Math.cos(angle), point.y + dist * Math.sin(angle), otherEntities[randInt(0, otherEntities.length - 1)], 0, randFloat(0, TWO_PI)); | placeObject(point.x + dist * Math.cos(angle), point.y + dist * Math.sin(angle), pickRandom(otherEntities), 0, randFloat(0, 2 * PI)); | ||||
} | } | ||||
} | } | ||||
function placeStartLocationResources(point, foodEntities = ["gaia/flora_bush_berry", "gaia/fauna_chicken", "gaia/fauna_chicken"]) | function placeStartLocationResources(point, foodEntities = ["gaia/flora_bush_berry", "gaia/fauna_chicken", "gaia/fauna_chicken"]) | ||||
{ | { | ||||
let currentAngle = randFloat(0, TWO_PI); | let currentAngle = randFloat(0, TWO_PI); | ||||
// Stone and chicken | // Stone and chicken | ||||
Show All 13 Lines | function placeStartLocationResources(point, foodEntities = ["gaia/flora_bush_berry", "gaia/fauna_chicken", "gaia/fauna_chicken"]) | ||||
{ | { | ||||
angle = currentAngle + randFloat(0, dAngle); | angle = currentAngle + randFloat(0, dAngle); | ||||
dist = randFloat(10, 15); | dist = randFloat(10, 15); | ||||
let objectList = groveEntities; | let objectList = groveEntities; | ||||
if (i % 2 == 0) | if (i % 2 == 0) | ||||
objectList = groveActors; | objectList = groveActors; | ||||
x = point.x + dist * Math.cos(angle); | x = point.x + dist * Math.cos(angle); | ||||
y = point.y + dist * Math.sin(angle); | y = point.y + dist * Math.sin(angle); | ||||
placeObject(x, y, objectList[randInt(0, objectList.length - 1)], 0, randFloat(0, TWO_PI)); | placeObject(x, y, pickRandom(objectList), 0, randFloat(0, 2 * PI)); | ||||
createArea(new ClumpPlacer(5, 1, 1, 1, floor(x), floor(y)), [new TerrainPainter("temp_grass_plants"), paintClass(clGrove)]); | createArea(new ClumpPlacer(5, 1, 1, 1, floor(x), floor(y)), [new TerrainPainter("temp_grass_plants"), paintClass(clGrove)]); | ||||
currentAngle += dAngle; | currentAngle += dAngle; | ||||
} | } | ||||
// Metal and chicken | // Metal and chicken | ||||
dAngle = TWO_PI * 2 / 9; | dAngle = TWO_PI * 2 / 9; | ||||
angle = currentAngle + randFloat(dAngle / 4, 3 * dAngle / 4); | angle = currentAngle + randFloat(dAngle / 4, 3 * dAngle / 4); | ||||
dist = 13; | dist = 13; | ||||
x = point.x + dist * Math.cos(angle); | x = point.x + dist * Math.cos(angle); | ||||
y = point.y + dist * Math.sin(angle); | y = point.y + dist * Math.sin(angle); | ||||
placeMine({ "x": x, "y": y }, "gaia/geology_metal_temperate_slabs"); | placeMine({ "x": x, "y": y }, "gaia/geology_metal_temperate_slabs"); | ||||
currentAngle += dAngle; | currentAngle += dAngle; | ||||
// Berries | // Berries | ||||
quantity = 15; | quantity = 15; | ||||
dAngle = TWO_PI / quantity * 2 / 9; | dAngle = TWO_PI / quantity * 2 / 9; | ||||
for (let i = 0; i < quantity; ++i) | for (let i = 0; i < quantity; ++i) | ||||
{ | { | ||||
angle = currentAngle + randFloat(0, dAngle); | angle = currentAngle + randFloat(0, dAngle); | ||||
dist = randFloat(10, 15); | dist = randFloat(10, 15); | ||||
x = point.x + dist * Math.cos(angle); | x = point.x + dist * Math.cos(angle); | ||||
y = point.y + dist * Math.sin(angle); | y = point.y + dist * Math.sin(angle); | ||||
placeObject(x, y, foodEntities[randInt(0, foodEntities.length - 1)], 0, randFloat(0, TWO_PI)); | placeObject(x, y, pickRandom(foodEntities), 0, randFloat(0, 2 * PI)); | ||||
currentAngle += dAngle; | currentAngle += dAngle; | ||||
} | } | ||||
} | } | ||||
log("Functions loaded after " + ((new Date().getTime() - genStartTime) / 1000) + "s"); // Time Check | log("Functions loaded after " + ((new Date().getTime() - genStartTime) / 1000) + "s"); // Time Check | ||||
/** | /** | ||||
* Environment settings | * Environment settings | ||||
▲ Show 20 Lines • Show All 250 Lines • ▼ Show 20 Lines | |||||
for (let h = 0; h < heighLimits.length; ++h) | for (let h = 0; h < heighLimits.length; ++h) | ||||
{ | { | ||||
for (let t = 0; t < areas[h].length; ++t) | for (let t = 0; t < areas[h].length; ++t) | ||||
{ | { | ||||
let x = areas[h][t].x; | let x = areas[h][t].x; | ||||
let y = areas[h][t].y; | let y = areas[h][t].y; | ||||
let actor = undefined; | let actor = undefined; | ||||
let texture = myBiome[h].texture[randInt(myBiome[h].texture.length)]; | let texture = pickRandom(myBiome[h].texture); | ||||
if (slopeMap[x][y] < 0.4 * (minSlope[h] + maxSlope[h])) | if (slopeMap[x][y] < 0.4 * (minSlope[h] + maxSlope[h])) | ||||
{ | { | ||||
if (randFloat() < myBiome[h].actor[1]) | if (randFloat() < myBiome[h].actor[1]) | ||||
actor = myBiome[h].actor[0][randInt(myBiome[h].actor[0].length)]; | actor = pickRandom(myBiome[h].actor[0]); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
texture = myBiome[h].textureHS[randInt(myBiome[h].textureHS.length)]; | texture = pickRandom(myBiome[h].textureHS); | ||||
if (randFloat() < myBiome[h].actorHS[1]) | if (randFloat() < myBiome[h].actorHS[1]) | ||||
actor = myBiome[h].actorHS[0][randInt(myBiome[h].actorHS[0].length)]; | actor = pickRandom(myBiome[h].actorHS[0]); | ||||
} | } | ||||
g_Map.setTexture(x, y, texture); | g_Map.setTexture(x, y, texture); | ||||
if (actor) | if (actor) | ||||
placeObject(x + randFloat(), y + randFloat(), actor, 0, randFloat() * TWO_PI); | placeObject(x + randFloat(), y + randFloat(), actor, 0, randFloat() * TWO_PI); | ||||
} | } | ||||
} | } | ||||
log("Terrain texture placement finished after " + ((new Date().getTime() - genStartTime) / 1000) + "s"); // Time Check | log("Terrain texture placement finished after " + ((new Date().getTime() - genStartTime) / 1000) + "s"); // Time Check | ||||
Show All 12 Lines | |||||
for (let i = 0; i < resourceSpots.length; ++i) | for (let i = 0; i < resourceSpots.length; ++i) | ||||
{ | { | ||||
let choice = i % 5; | let choice = i % 5; | ||||
if (choice == 0) | if (choice == 0) | ||||
placeMine(resourceSpots[i], "gaia/geology_stonemine_temperate_formation"); | placeMine(resourceSpots[i], "gaia/geology_stonemine_temperate_formation"); | ||||
if (choice == 1) | if (choice == 1) | ||||
placeMine(resourceSpots[i], "gaia/geology_metal_temperate_slabs"); | placeMine(resourceSpots[i], "gaia/geology_metal_temperate_slabs"); | ||||
if (choice == 2) | if (choice == 2) | ||||
placeCustomFortress(resourceSpots[i].x, resourceSpots[i].y, fences[randInt(0, fences.length - 1)], "other", 0, randFloat(0, TWO_PI)); | placeCustomFortress(resourceSpots[i].x, resourceSpots[i].y, pickRandom(fences), "other", 0, randFloat(0, 2 * PI)); | ||||
if (choice == 3) | if (choice == 3) | ||||
placeGrove(resourceSpots[i]); | placeGrove(resourceSpots[i]); | ||||
if (choice == 4) | if (choice == 4) | ||||
placeCamp(resourceSpots[i]); | placeCamp(resourceSpots[i]); | ||||
} | } | ||||
/** | /** | ||||
* Stop Timer | * Stop Timer | ||||
*/ | */ | ||||
log("Map generation finished after " + ((new Date().getTime() - genStartTime) / 1000) + "s"); | log("Map generation finished after " + ((new Date().getTime() - genStartTime) / 1000) + "s"); | ||||
/** | /** | ||||
* Export map data | * Export map data | ||||
*/ | */ | ||||
ExportMap(); | ExportMap(); |
Wildfire Games · Phabricator