1 Engine.LoadLibrary("rmgen");
2 Engine.LoadLibrary("rmgen-common");
3 Engine.LoadLibrary("rmbiome");
5 function* GenerateMap()
9 const tMainTerrain = g_Terrains.mainTerrain;
10 const tForestFloor1 = g_Terrains.forestFloor1;
11 const tForestFloor2 = g_Terrains.forestFloor2;
12 const tCliff = g_Terrains.cliff;
13 const tTier1Terrain = g_Terrains.tier1Terrain;
14 const tTier2Terrain = g_Terrains.tier2Terrain;
15 const tTier3Terrain = g_Terrains.tier3Terrain;
16 const tHill = g_Terrains.hill;
17 const tRoad = g_Terrains.road;
18 const tRoadWild = g_Terrains.roadWild;
19 const tTier4Terrain = g_Terrains.tier4Terrain;
20 let tShore = g_Terrains.shore;
21 let tWater = g_Terrains.water;
22 if (currentBiome() == "generic/india")
24 tShore = "tropic_dirt_b_plants";
25 tWater = "tropic_dirt_b";
27 const oTree1 = g_Gaia.tree1;
28 const oTree2 = g_Gaia.tree2;
29 const oTree3 = g_Gaia.tree3;
30 const oTree4 = g_Gaia.tree4;
31 const oTree5 = g_Gaia.tree5;
32 const oFruitBush = g_Gaia.fruitBush;
33 const oMainHuntableAnimal = g_Gaia.mainHuntableAnimal;
34 const oFish = g_Gaia.fish;
35 const oSecondaryHuntableAnimal = g_Gaia.secondaryHuntableAnimal;
36 const oStoneLarge = g_Gaia.stoneLarge;
37 const oStoneSmall = g_Gaia.stoneSmall;
38 const oMetalLarge = g_Gaia.metalLarge;
39 const oMetalSmall = g_Gaia.metalSmall;
41 const aGrass = g_Decoratives.grass;
42 const aGrassShort = g_Decoratives.grassShort;
43 const aReeds = g_Decoratives.reeds;
44 const aLillies = g_Decoratives.lillies;
45 const aRockLarge = g_Decoratives.rockLarge;
46 const aRockMedium = g_Decoratives.rockMedium;
47 const aBushMedium = g_Decoratives.bushMedium;
48 const aBushSmall = g_Decoratives.bushSmall;
51 tForestFloor2 + TERRAIN_SEPARATOR + oTree1,
52 tForestFloor2 + TERRAIN_SEPARATOR + oTree2,
56 tForestFloor1 + TERRAIN_SEPARATOR + oTree4,
57 tForestFloor1 + TERRAIN_SEPARATOR + oTree5,
61 const heightSeaGround = -3;
62 const heightShallows = -1;
65 globalThis.g_Map = new RandomMap(heightLand, tMainTerrain);
67 const numPlayers = getNumPlayers();
68 const mapSize = g_Map.getSize();
69 const mapCenter = g_Map.getCenter();
71 const clPlayer = g_Map.createTileClass();
72 const clHill = g_Map.createTileClass();
73 const clForest = g_Map.createTileClass();
74 const clWater = g_Map.createTileClass();
75 const clDirt = g_Map.createTileClass();
76 const clRock = g_Map.createTileClass();
77 const clMetal = g_Map.createTileClass();
78 const clFood = g_Map.createTileClass();
79 const clBaseResource = g_Map.createTileClass();
80 const clShallow = g_Map.createTileClass();
82 const [playerIDs, playerPosition, playerAngle, startAngle] =
83 playerPlacementCircle(fractionToTiles(0.35));
86 "PlayerPlacement": [playerIDs, playerPosition],
87 "PlayerTileClass": clPlayer,
88 "BaseResourceClass": clBaseResource,
90 "outerTerrain": tRoadWild,
96 "template": oFruitBush
100 { "template": oMetalLarge },
101 { "template": oStoneLarge }
109 "template": aGrassShort
113 g_Map.log("Creating central lake");
115 new ClumpPlacer(diskArea(fractionToTiles(0.075)), 0.7, 0.1, Infinity, mapCenter),
117 new LayeredPainter([tShore, tWater], [1]),
118 new SmoothElevationPainter(ELEVATION_SET, heightSeaGround, 4),
119 new TileClassPainter(clWater)
122 g_Map.log("Creating rivers between opponents");
123 const numRivers = isNomad() ? randIntInclusive(4, 8) : numPlayers;
124 const rivers = distributePointsOnCircle(numRivers, startAngle + Math.PI / numRivers,
125 fractionToTiles(0.5), mapCenter)[0];
126 for (let i = 0; i < numRivers; ++i)
128 if (isNomad() ? randBool() : areAllies(playerIDs[i], playerIDs[(i + 1) % numPlayers]))
131 const shallowLocation = randFloat(0.2, 0.7);
132 const shallowWidth = randFloat(0.12, 0.21);
138 "width": scaleByMapSize(10, 30),
141 "heightLand": heightLand,
142 "heightRiverbed": heightSeaGround,
143 "minHeight": heightSeaGround,
146 "waterFunc": (position, height, riverFraction) => {
148 clWater.add(position);
150 const isShallow = height < heightShallows &&
151 riverFraction > shallowLocation &&
152 riverFraction < shallowLocation + shallowWidth;
154 const newHeight = isShallow ? heightShallows : Math.max(height, heightSeaGround);
156 if (g_Map.getHeight(position) < newHeight)
159 g_Map.setHeight(position, newHeight);
160 createTerrain(height >= 0 ? tShore : tWater).place(position);
163 clShallow.add(position);
169 createBumps(avoidClasses(clWater, 2, clPlayer, 20));
172 createHills([tMainTerrain, tCliff, tHill],
173 avoidClasses(clPlayer, 20, clHill, 15, clWater, 2), clHill, scaleByMapSize(3, 15));
175 createMountains(tCliff,
176 avoidClasses(clPlayer, 20, clHill, 15, clWater, 2), clHill, scaleByMapSize(3, 15));
178 const [forestTrees, stragglerTrees] = getTreeCounts(...rBiomeTreeCount(1));
179 createDefaultForests(
180 [tMainTerrain, tForestFloor1, tForestFloor2, pForest1, pForest2],
181 avoidClasses(clPlayer, 20, clForest, 17, clHill, 0, clWater, 2),
187 g_Map.log("Creating dirt patches");
188 createLayeredPatches(
189 [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)],
190 [[tMainTerrain, tTier1Terrain], [tTier1Terrain, tTier2Terrain], [tTier2Terrain, tTier3Terrain]],
192 avoidClasses(clWater, 3, clForest, 0, clHill, 0, clDirt, 5, clPlayer, 12),
193 scaleByMapSize(15, 45),
196 g_Map.log("Creating grass patches");
198 [scaleByMapSize(2, 4), scaleByMapSize(3, 7), scaleByMapSize(5, 15)],
200 avoidClasses(clWater, 3, clForest, 0, clHill, 0, clDirt, 5, clPlayer, 12),
201 scaleByMapSize(15, 45),
205 g_Map.log("Creating metal mines");
206 createBalancedMetalMines(
210 avoidClasses(clWater, 3, clForest, 1, clPlayer, scaleByMapSize(20, 35), clHill, 1)
213 g_Map.log("Creating stone mines");
214 createBalancedStoneMines(
218 avoidClasses(clWater, 3, clForest, 1, clPlayer, scaleByMapSize(20, 35), clHill, 1, clMetal, 10)
225 if (currentBiome() == "generic/india")
230 [new SimpleObject(aRockMedium, 1, 3, 0, 1)],
231 [new SimpleObject(aRockLarge, 1, 2, 0, 1), new SimpleObject(aRockMedium, 1, 3, 0, 2)],
232 [new SimpleObject(aGrassShort, 1, 2, 0, 1)],
233 [new SimpleObject(aGrass, 2, 4, 0, 1.8), new SimpleObject(aGrassShort, 3, 6, 1.2, 2.5)],
234 [new SimpleObject(aBushMedium, 1, 2, 0, 2), new SimpleObject(aBushSmall, 2, 4, 0, 2)]
237 scaleByMapAreaAbsolute(16),
238 scaleByMapAreaAbsolute(8),
239 planetm * scaleByMapAreaAbsolute(13),
240 planetm * scaleByMapAreaAbsolute(13),
241 planetm * scaleByMapAreaAbsolute(13)
243 avoidClasses(clWater, 0, clForest, 0, clPlayer, 0, clHill, 0));
247 [new SimpleObject(aReeds, 1, 3, 0, 1)],
248 [new SimpleObject(aLillies, 1, 2, 0, 1)]
251 scaleByMapAreaAbsolute(800),
252 scaleByMapAreaAbsolute(800)
254 stayClasses(clShallow, 0));
260 [new SimpleObject(oMainHuntableAnimal, 5, 7, 0, 4)],
261 [new SimpleObject(oSecondaryHuntableAnimal, 2, 3, 0, 2)]
267 avoidClasses(clWater, 3, clForest, 0, clPlayer, 20, clHill, 1, clFood, 20),
272 [new SimpleObject(oFruitBush, 5, 7, 0, 4)]
277 avoidClasses(clWater, 3, clForest, 0, clPlayer, 20, clHill, 1, clFood, 10),
282 [new SimpleObject(oFish, 2, 3, 0, 2)]
287 [avoidClasses(clFood, 20), stayClasses(clWater, 6)],
292 createStragglerTrees(
293 [oTree1, oTree2, oTree4, oTree3],
294 avoidClasses(clWater, 5, clForest, 7, clHill, 1, clPlayer, 12, clMetal, 6, clRock, 6),
298 placePlayersNomad(clPlayer,
299 avoidClasses(clWater, 4, clForest, 1, clMetal, 4, clRock, 4, clFood, 2, clHill, 4));
301 setWaterWaviness(3.0);
302 setWaterType("lake");