1 Engine.LoadLibrary("rmgen");
2 Engine.LoadLibrary("rmgen-common");
3 Engine.LoadLibrary("rmbiome");
7 const tMainTerrain = g_Terrains.mainTerrain;
8 const tForestFloor1 = g_Terrains.forestFloor1;
9 const tForestFloor2 = g_Terrains.forestFloor2;
10 const tCliff = g_Terrains.cliff;
11 const tTier1Terrain = g_Terrains.tier1Terrain;
12 const tTier2Terrain = g_Terrains.tier2Terrain;
13 const tTier3Terrain = g_Terrains.tier3Terrain;
14 const tHill = g_Terrains.mainTerrain;
15 const tRoad = g_Terrains.road;
16 const tRoadWild = g_Terrains.roadWild;
17 const tTier4Terrain = g_Terrains.tier4Terrain;
18 const tWater = g_Terrains.water;
20 const oTree1 = g_Gaia.tree1;
21 const oTree2 = g_Gaia.tree2;
22 const oTree3 = g_Gaia.tree3;
23 const oTree4 = g_Gaia.tree4;
24 const oTree5 = g_Gaia.tree5;
25 const oFruitBush = g_Gaia.fruitBush;
26 const oMainHuntableAnimal = g_Gaia.mainHuntableAnimal;
27 const oSecondaryHuntableAnimal = g_Gaia.secondaryHuntableAnimal;
28 const oStoneLarge = g_Gaia.stoneLarge;
29 const oStoneSmall = g_Gaia.stoneSmall;
30 const oMetalLarge = g_Gaia.metalLarge;
32 const aGrass = g_Decoratives.grass;
33 const aGrassShort = g_Decoratives.grassShort;
34 const aRockLarge = g_Decoratives.rockLarge;
35 const aRockMedium = g_Decoratives.rockMedium;
36 const aBushMedium = g_Decoratives.bushMedium;
37 const aBushSmall = g_Decoratives.bushSmall;
39 const pForest1 = [tForestFloor2 + TERRAIN_SEPARATOR + oTree1, tForestFloor2 + TERRAIN_SEPARATOR + oTree2, tForestFloor2];
40 const pForest2 = [tForestFloor1 + TERRAIN_SEPARATOR + oTree4, tForestFloor1 + TERRAIN_SEPARATOR + oTree5, tForestFloor1];
42 const heightIsland = 20;
43 const heightSeaGround = -5;
45 var g_Map = new RandomMap(heightSeaGround, tWater);
47 const numPlayers = getNumPlayers();
48 const mapSize = g_Map.getSize();
49 const mapCenter = g_Map.getCenter();
51 var clPlayer = g_Map.createTileClass();
52 var clForest = g_Map.createTileClass();
53 var clDirt = g_Map.createTileClass();
54 var clRock = g_Map.createTileClass();
55 var clMetal = g_Map.createTileClass();
56 var clFood = g_Map.createTileClass();
57 var clBaseResource = g_Map.createTileClass();
58 var clLand = g_Map.createTileClass();
60 const playerIslandRadius = scaleByMapSize(15, 30);
62 const islandBetweenPlayerAndCenterDist = 0.16;
63 const islandBetweenPlayerAndCenterRadius = 0.81;
64 const centralIslandRadius = 0.36;
66 var [playerIDs, playerPosition, playerAngle, startAngle] = playerPlacementCircle(fractionToTiles(0.35));
72 function initIsConnected()
74 for (let m = 0; m < numIslands; ++m)
77 for (let n = 0; n < numIslands; ++n)
78 isConnected[m][n] = 0;
82 function createIsland(islandID, size, tileClass)
85 new ClumpPlacer(size * diskArea(playerIslandRadius), 0.95, 0.6, Infinity, islandPos[islandID]),
87 new LayeredPainter([tCliff, tHill], [2]),
88 new SmoothElevationPainter(ELEVATION_SET, heightIsland, 2),
89 new TileClassPainter(tileClass)
93 function createIslandAtRadialLocation(playerID, islandID, playerIDOffset, distFromCenter, islandRadius)
95 let angle = startAngle + (playerID * 2 + playerIDOffset) * Math.PI / numPlayers;
96 islandPos[islandID] = Vector2D.add(mapCenter, new Vector2D(fractionToTiles(distFromCenter), 0).rotate(-angle)).round();
97 createIsland(islandID, islandRadius, clLand);
100 function createSnowflakeSearockWithCenter(sizeID)
102 let [tertiaryIslandDist, tertiaryIslandRadius, islandBetweenPlayersDist, islandBetweenPlayersRadius] = islandSizes[sizeID];
104 let islandID_center = 4 * numPlayers;
105 numIslands = islandID_center + 1;
108 g_Map.log("Creating central island");
109 islandPos[islandID_center] = mapCenter;
110 createIsland(islandID_center, centralIslandRadius, clLand);
112 for (let playerID = 0; playerID < numPlayers; ++playerID)
114 let playerID_neighbor = playerID + 1 < numPlayers ? playerID + 1 : 0;
116 let islandID_player = playerID;
117 let islandID_playerNeighbor = playerID_neighbor;
118 let islandID_betweenPlayers = playerID + numPlayers;
119 let islandID_betweenPlayerAndCenter = playerID + 2 * numPlayers;
120 let islandID_betweenPlayerAndCenterNeighbor = playerID_neighbor + 2 * numPlayers;
121 let islandID_tertiary = playerID + 3 * numPlayers;
123 g_Map.log("Creating island between the player and their neighbor");
124 isConnected[islandID_betweenPlayers][islandID_player] = 1;
125 isConnected[islandID_betweenPlayers][islandID_playerNeighbor] = 1;
126 createIslandAtRadialLocation(playerID, islandID_betweenPlayers, 1, islandBetweenPlayersDist, islandBetweenPlayersRadius);
128 g_Map.log("Creating an island between the player and the center");
129 isConnected[islandID_betweenPlayerAndCenter][islandID_player] = 1;
130 isConnected[islandID_betweenPlayerAndCenter][islandID_center] = 1;
131 isConnected[islandID_betweenPlayerAndCenter][islandID_betweenPlayerAndCenterNeighbor] = 1;
132 createIslandAtRadialLocation(playerID, islandID_betweenPlayerAndCenter, 0, islandBetweenPlayerAndCenterDist, islandBetweenPlayerAndCenterRadius);
134 g_Map.log("Creating tertiary island, at the map border");
135 isConnected[islandID_tertiary][islandID_betweenPlayers] = 1;
136 createIslandAtRadialLocation(playerID, islandID_tertiary, 1, tertiaryIslandDist, tertiaryIslandRadius);
141 * Creates one island in front of every player and connects it with the neighbors.
143 function createSnowflakeSearockWithoutCenter()
145 numIslands = 2 * numPlayers;
148 for (let playerID = 0; playerID < numPlayers; ++playerID)
150 let playerID_neighbor = playerID + 1 < numPlayers ? playerID + 1 : 0;
152 let islandID_player = playerID;
153 let islandID_playerNeighbor = playerID_neighbor;
154 let islandID_inFrontOfPlayer = playerID + numPlayers;
155 let islandID_inFrontOfPlayerNeighbor = playerID_neighbor + numPlayers;
157 isConnected[islandID_player][islandID_playerNeighbor] = 1;
158 isConnected[islandID_player][islandID_inFrontOfPlayer] = 1;
159 isConnected[islandID_inFrontOfPlayer][islandID_inFrontOfPlayerNeighbor] = 1;
161 createIslandAtRadialLocation(playerID, islandID_inFrontOfPlayer, 0, islandBetweenPlayerAndCenterDist, islandBetweenPlayerAndCenterRadius);
165 function createSnowflakeSearockTiny()
167 numIslands = numPlayers + 1;
170 let islandID_center = numPlayers;
172 g_Map.log("Creating central island");
173 islandPos[islandID_center] = mapCenter;
174 createIsland(numPlayers, 1, clLand);
176 for (let playerID = 0; playerID < numPlayers; ++playerID)
178 let islandID_player = playerID;
179 isConnected[islandID_player][islandID_center] = 1;
183 const islandSizes = {
184 "medium": [0.41, 0.49, 0.26, 1],
185 "large1": [0.41, 0.49, 0.24, 1],
186 "large2": [0.41, 0.36, 0.28, 0.81]
191 createSnowflakeSearockTiny();
193 else if (mapSize <= 192)
195 createSnowflakeSearockWithoutCenter();
197 else if (mapSize <= 256)
200 createSnowflakeSearockWithCenter("medium");
202 createSnowflakeSearockWithoutCenter();
204 else if (mapSize <= 320)
207 createSnowflakeSearockWithCenter("medium");
209 createSnowflakeSearockWithoutCenter();
212 createSnowflakeSearockWithCenter(numPlayers < 6 ? "large1" : "large2");
214 g_Map.log("Creating player islands");
215 for (let i = 0; i < numPlayers; ++i)
217 islandPos[i] = playerPosition[i];
218 createIsland(i, 1, isNomad() ? clLand : clPlayer);
222 "PlayerPlacement": [playerIDs, playerPosition],
223 // PlayerTileClass already marked above
224 "BaseResourceClass": clBaseResource,
225 "baseResourceConstraint": stayClasses(clPlayer, 4),
228 "outerTerrain": tRoadWild,
229 "innerTerrain": tRoad
234 "template": oFruitBush,
235 "distance": playerIslandRadius - 4
239 { "template": oMetalLarge },
240 { "template": oStoneLarge }
242 "distance": playerIslandRadius - 4
246 "count": scaleByMapSize(10, 50),
251 "template": aGrassShort
254 Engine.SetProgress(30);
256 g_Map.log("Creating connectors");
257 for (let i = 0; i < numIslands; ++i)
258 for (let j = 0; j < numIslands; ++j)
259 if (isConnected[i][j])
261 "start": islandPos[i],
266 "constraints": new HeightConstraint(-Infinity, heightIsland - 1),
269 "edgeTerrain": tCliff
272 g_Map.log("Creating forests");
273 var [forestTrees, stragglerTrees] = getTreeCounts(...rBiomeTreeCount(1));
275 [[tForestFloor2, tMainTerrain, pForest1], [tForestFloor2, pForest1]],
276 [[tForestFloor1, tMainTerrain, pForest2], [tForestFloor1, pForest2]]
279 var size = forestTrees / (scaleByMapSize(2, 8) * numPlayers) * (currentBiome() == "generic/savanna" ? 2 : 1);
280 var num = Math.floor(size / types.length);
281 for (let type of types)
283 new ClumpPlacer(forestTrees / num, 0.1, 0.1, Infinity),
285 new LayeredPainter(type, [2]),
286 new TileClassPainter(clForest)
288 [avoidClasses(clPlayer, 6, clForest, 10), stayClasses(clLand, 4)],
290 Engine.SetProgress(55);
292 g_Map.log("Creating stone mines");
293 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);
294 createObjectGroupsDeprecated(group, 0,
295 [avoidClasses(clForest, 1, clPlayer, 10, clRock, 10), stayClasses(clLand, 5)],
296 5*scaleByMapSize(4,16), 100
299 g_Map.log("Creating small stone quarries");
300 group = new SimpleGroup([new SimpleObject(oStoneSmall, 2,5, 1,3)], true, clRock);
301 createObjectGroupsDeprecated(group, 0,
302 [avoidClasses(clForest, 1, clPlayer, 10, clRock, 10), stayClasses(clLand, 5)],
303 5*scaleByMapSize(4,16), 100
306 g_Map.log("Creating metal mines");
307 group = new SimpleGroup([new SimpleObject(oMetalLarge, 1,1, 0,4)], true, clMetal);
308 createObjectGroupsDeprecated(group, 0,
309 [avoidClasses(clForest, 1, clPlayer, 10, clMetal, 10, clRock, 5), stayClasses(clLand, 5)],
310 5*scaleByMapSize(4,16), 100
313 Engine.SetProgress(65);
314 g_Map.log("Creating dirt patches");
315 for (let size of [scaleByMapSize(3, 48), scaleByMapSize(5, 84), scaleByMapSize(8, 128)])
317 new ClumpPlacer(size, 0.3, 0.06, 0.5),
319 new LayeredPainter([[tMainTerrain, tTier1Terrain],[tTier1Terrain, tTier2Terrain], [tTier2Terrain, tTier3Terrain]], [1, 1]),
320 new TileClassPainter(clDirt)
322 [avoidClasses(clForest, 0, clDirt, 5, clPlayer, 12), stayClasses(clLand, 5)],
323 scaleByMapSize(15, 45));
325 g_Map.log("Creating grass patches");
326 for (let size of [scaleByMapSize(2, 32), scaleByMapSize(3, 48), scaleByMapSize(5, 80)])
328 new ClumpPlacer(size, 0.3, 0.06, 0.5),
329 new TerrainPainter(tTier4Terrain),
330 [avoidClasses(clForest, 0, clDirt, 5, clPlayer, 12), stayClasses(clLand, 5)],
331 scaleByMapSize(15, 45));
333 g_Map.log("Creating small decorative rocks");
334 group = new SimpleGroup(
335 [new SimpleObject(aRockMedium, 1,3, 0,1)],
338 createObjectGroupsDeprecated(
340 [avoidClasses(clForest, 0, clPlayer, 0), stayClasses(clLand, 4)],
341 scaleByMapSize(16, 262), 50
344 g_Map.log("Creating large decorative rocks");
345 group = new SimpleGroup(
346 [new SimpleObject(aRockLarge, 1,2, 0,1), new SimpleObject(aRockMedium, 1,3, 0,2)],
349 createObjectGroupsDeprecated(
351 [avoidClasses(clForest, 0, clPlayer, 0), stayClasses(clLand, 4)],
352 scaleByMapSize(8, 131), 50
355 Engine.SetProgress(70);
357 g_Map.log("Creating deer");
358 group = new SimpleGroup(
359 [new SimpleObject(oMainHuntableAnimal, 5,7, 0,4)],
362 createObjectGroupsDeprecated(group, 0,
363 [avoidClasses(clForest, 0, clPlayer, 10, clFood, 20), stayClasses(clLand, 4)],
367 Engine.SetProgress(75);
369 g_Map.log("Creating sheep");
370 group = new SimpleGroup(
371 [new SimpleObject(oSecondaryHuntableAnimal, 2,3, 0,2)],
374 createObjectGroupsDeprecated(group, 0,
375 [avoidClasses(clForest, 0, clPlayer, 10, clFood, 20), stayClasses(clLand, 4)],
379 g_Map.log("Creating fruits");
380 group = new SimpleGroup(
381 [new SimpleObject(oFruitBush, 5,7, 0,4)],
384 createObjectGroupsDeprecated(group, 0,
385 [avoidClasses(clForest, 0, clPlayer, 10, clFood, 20), stayClasses(clLand, 4)],
388 Engine.SetProgress(85);
390 createStragglerTrees(
391 [oTree1, oTree2, oTree4, oTree3],
392 [avoidClasses(clForest, 1, clPlayer, 9, clMetal, 6, clRock, 6), stayClasses(clLand, 4)],
397 if (currentBiome() == "generic/tropic")
400 g_Map.log("Creating small grass tufts");
401 group = new SimpleGroup(
402 [new SimpleObject(aGrassShort, 1,2, 0,1, -Math.PI / 8, Math.PI / 8)]
404 createObjectGroupsDeprecated(group, 0,
405 [avoidClasses(clPlayer, 2, clDirt, 0), stayClasses(clLand, 4)],
406 planetm * scaleByMapSize(13, 200)
409 Engine.SetProgress(90);
411 g_Map.log("Creating large grass tufts");
412 group = new SimpleGroup(
413 [new SimpleObject(aGrass, 2,4, 0,1.8, -Math.PI / 8, Math.PI / 8), new SimpleObject(aGrassShort, 3,6, 1.2,2.5, -Math.PI / 8, Math.PI / 8)]
415 createObjectGroupsDeprecated(group, 0,
416 [avoidClasses(clPlayer, 2, clDirt, 1, clForest, 0), stayClasses(clLand, 4)],
417 planetm * scaleByMapSize(13, 200)
419 Engine.SetProgress(95);
421 g_Map.log("Creating bushes");
422 group = new SimpleGroup(
423 [new SimpleObject(aBushMedium, 1,2, 0,2), new SimpleObject(aBushSmall, 2,4, 0,2)]
425 createObjectGroupsDeprecated(group, 0,
426 [avoidClasses(clPlayer, 1, clDirt, 1), stayClasses(clLand, 4)],
427 planetm * scaleByMapSize(13, 200), 50
433 stayClasses(clLand, 8),
434 avoidClasses(clForest, 1, clMetal, 4, clRock, 4, clFood, 2)
437 setSkySet(pickRandom(["cirrus", "cumulus", "sunny"]));
438 setSunRotation(randomAngle());
439 setSunElevation(Math.PI * randFloat(1/5, 1/3));