Small random map cleanup.
[0ad.git] / binaries / data / mods / public / maps / random / river_archipelago.js
blob9e465e265a0732ee73481b622a7f18ddf87b99ec
1 Engine.LoadLibrary("rmgen");
2 Engine.LoadLibrary("rmgen-common");
4 const tGrass = ["tropic_grass_c", "tropic_grass_c", "tropic_grass_c", "tropic_grass_c", "tropic_grass_plants", "tropic_plants", "tropic_plants_b"];
5 const tGrassA = "tropic_plants_c";
6 const tGrassB = "tropic_plants_c";
7 const tGrassC = "tropic_grass_c";
8 const tForestFloor = "tropic_grass_plants";
9 const tCliff = ["tropic_cliff_a", "tropic_cliff_a", "tropic_cliff_a", "tropic_cliff_a_plants"];
10 const tPlants = "tropic_plants";
11 const tRoad = "tropic_citytile_a";
12 const tRoadWild = "tropic_citytile_plants";
13 const tShoreBlend = "tropic_beach_dry_plants";
14 const tShore = "tropic_beach_dry";
15 const tWater = "tropic_beach_wet";
17 const oTree = "gaia/flora_tree_toona";
18 const oPalm1 = "gaia/flora_tree_palm_tropic";
19 const oPalm2 = "gaia/flora_tree_palm_tropical";
20 const oStoneLarge = "gaia/geology_stonemine_tropic_quarry";
21 const oStoneSmall = "gaia/geology_stone_tropic_a";
22 const oMetalLarge = "gaia/geology_metal_tropic_slabs";
23 const oFish = "gaia/fauna_fish";
24 const oDeer = "gaia/fauna_deer";
25 const oTiger = "gaia/fauna_tiger";
26 const oBoar = "gaia/fauna_boar";
27 const oPeacock = "gaia/fauna_peacock";
28 const oBush = "gaia/flora_bush_berry";
29 const oSpearman = "units/maur_infantry_spearman_b";
30 const oArcher = "units/maur_infantry_archer_b";
31 const oArcherElephant = "units/maur_elephant_archer_b";
33 const aRockLarge = "actor|geology/stone_granite_large.xml";
34 const aRockMedium = "actor|geology/stone_granite_med.xml";
35 const aBush1 = "actor|props/flora/plant_tropic_a.xml";
36 const aBush2 = "actor|props/flora/plant_lg.xml";
37 const aBush3 = "actor|props/flora/plant_tropic_large.xml";
39 const pForestD = [tForestFloor + TERRAIN_SEPARATOR + oTree, tForestFloor];
40 const pForestP1 = [tForestFloor + TERRAIN_SEPARATOR + oPalm1, tForestFloor];
41 const pForestP2 = [tForestFloor + TERRAIN_SEPARATOR + oPalm2, tForestFloor];
43 const heightSeaGround = -8;
44 const heightWaterLevel = 0;
45 const heightShore = 1;
46 const heightShoreBlend = 2.8;
47 const heightLand = 3;
48 const heightHill = 25;
50 var g_Map = new RandomMap(heightSeaGround, tGrass);
52 const numPlayers = getNumPlayers();
53 const mapCenter = g_Map.getCenter();
54 const mapBounds = g_Map.getBounds();
56 var clPlayer = g_Map.createTileClass();
57 var clPlayerTerritory = g_Map.createTileClass();
58 var clHill = g_Map.createTileClass();
59 var clForest = g_Map.createTileClass();
60 var clWater = g_Map.createTileClass();
61 var clDirt = g_Map.createTileClass();
62 var clRock = g_Map.createTileClass();
63 var clMetal = g_Map.createTileClass();
64 var clFood = g_Map.createTileClass();
65 var clBaseResource = g_Map.createTileClass();
66 var clGaia = g_Map.createTileClass();
67 var clStrip = [];
69 var startAngle = randomAngle();
70 var connectPlayers = randBool();
72 // Map layout
73 var stripWidthsLeft = connectPlayers ?
74         [[0.03, 0.09], [0.14, 0.25], [0.36, 0.46]] : 
75         [[0, 0.06], [0.12, 0.23], [0.33, 0.43]];
77 // Mirror
78 var stripWidthsRight = clone(stripWidthsLeft);
79 stripWidthsRight.reverse();
80 stripWidthsRight = stripWidthsRight.map(strip => [1 - strip[1], 1 - strip[0]]);
82 var stripWidths = stripWidthsLeft.concat(stripWidthsRight);
84 g_Map.log("Creating strips");
85 for (let i = 0; i < stripWidths.length; ++i)
87         clStrip[i] = g_Map.createTileClass();
89         let isPlayerStrip = i == 2 || i == 3;
90         for (let j = 0; j < scaleByMapSize(20, 100); ++j)
91         {
92                 let position = new Vector2D(
93                         randFloat(mapBounds.bottom, mapBounds.top),
94                         fractionToTiles(randFloat(...stripWidths[i]))).rotateAround(startAngle, mapCenter).round();
96                 createArea(
97                         new ChainPlacer(
98                                 1,
99                                 Math.floor(scaleByMapSize(3, connectPlayers && isPlayerStrip ? 8 : 7)),
100                                 Math.floor(scaleByMapSize(30, 60)),
101                                 Infinity,
102                                 position),
103                         [
104                                 new TerrainPainter(tGrass),
105                                 new SmoothElevationPainter(ELEVATION_SET, heightLand, 3),
106                                 new TileClassPainter(clStrip[i])
107                         ]);
108         }
110 Engine.SetProgress(20);
112 var playerPosition = playerPlacementLine(startAngle, mapCenter, fractionToTiles(1 - stripWidthsLeft[2][0] - stripWidthsLeft[2][1]));
114 // Either left vs right or top vs bottom
115 var playerIDs = randBool() ? sortAllPlayers() : primeSortAllPlayers();
117 g_Map.log("Ensuring player territory");
118 var playerRadius = scaleByMapSize(12, 20);
119 for (let i = 0; i < numPlayers; ++i)
120         createArea(
121                 new ChainPlacer(1, 6, 40, 1, playerPosition[i], 0, [Math.floor(playerRadius)]),
122                 [
123                         new TerrainPainter(tGrass),
124                         new SmoothElevationPainter(ELEVATION_SET, heightLand, 4),
125                         new TileClassPainter(clPlayerTerritory)
126                 ]);
128 placePlayerBases({
129         "PlayerPlacement": [playerIDs, playerPosition],
130         "PlayerTileClass": clPlayer,
131         "BaseResourceClass": clBaseResource,
132         "baseResourceConstraint": stayClasses(clPlayerTerritory, 4),
133         "Walls": "towers",
134         "CityPatch": {
135                 "outerTerrain": tRoadWild,
136                 "innerTerrain": tRoad,
137                 "radius": playerRadius / 3
138         },
139         "Chicken": {
140                 "template": oPeacock
141         },
142         "Berries": {
143                 "template": oBush
144         },
145         "Mines": {
146                 "types": [
147                         { "template": oMetalLarge },
148                         { "template": oStoneLarge }
149                 ]
150         },
151         "Trees": {
152                 "template": oTree,
153                 "count": 40
154         }
155         // No decoratives
157 Engine.SetProgress(35);
159 var areaWater = createArea(
160         new HeightPlacer(Elevation_IncludeMin_ExcludeMax, -Infinity, heightWaterLevel),
161         [
162                 new TerrainPainter(tWater),
163                 new TileClassPainter(clWater)
164         ]);
166 createArea(
167         new HeightPlacer(Elevation_IncludeMin_ExcludeMax, heightWaterLevel, heightShore),
168         new TerrainPainter(tShore));
170 createArea(
171         new HeightPlacer(Elevation_IncludeMin_ExcludeMax, heightShore, heightShoreBlend),
172         new TerrainPainter(tShoreBlend));
174 Engine.SetProgress(40);
176 if (!isNomad())
178         g_Map.log("Creating gaia");
179         for (let i = 0; i < 2; ++i)
180                 for (let j = 0; j < scaleByMapSize(1, 8); ++j)
181                         createObjectGroups(
182                                 new SimpleGroup(
183                                         [
184                                                 new SimpleObject(oSpearman, 8, 12, 2, 3),
185                                                 new SimpleObject(oArcher, 8, 12, 2, 3),
186                                                 new SimpleObject(oArcherElephant, 2, 3, 4, 5)
187                                         ],
188                                         true,
189                                         clGaia),
190                                 0,
191                                 [
192                                         avoidClasses(
193                                                 clWater, 2,
194                                                 clForest, 1,
195                                                 clPlayerTerritory, 0,
196                                                 clHill, 1,
197                                                 clGaia, 15),
198                                         stayClasses(clStrip[i == 0 ? 0 : stripWidths.length - 1], 1)
199                                 ],
200                                 scaleByMapSize(5, 10),
201                                 50);
204 g_Map.log("Creating hills");
205 createAreas(
206         new ChainPlacer(1, Math.floor(scaleByMapSize(4, 6)), Math.floor(scaleByMapSize(16, 40)), 0.1),
207         [
208                 new LayeredPainter([tCliff, tGrass], [3]),
209                 new SmoothElevationPainter(ELEVATION_SET, heightHill, 3),
210                 new TileClassPainter(clHill)
211         ],
212         [
213                 avoidClasses(
214                         clPlayerTerritory, 0,
215                         clHill, 5,
216                         clGaia, 1,
217                         clWater, 2)
218         ],
219         scaleByMapSize(1, 5));
221 createBumps(avoidClasses(clPlayer, 8, clWater, 2), scaleByMapSize(20, 150), 2, 8, 4, 1, 4);
222 Engine.SetProgress(50);
224 g_Map.log("Creating forests");
225 var [forestTrees, stragglerTrees] = getTreeCounts(1000, 4000, 0.7);
226 var types = [
227         [[tGrass, tGrass, tGrass, tGrass, pForestD], [tGrass, tGrass, tGrass, pForestD]],
228         [[tGrass, tGrass, tGrass, tGrass, pForestP1], [tGrass, tGrass, tGrass, pForestP1]],
229         [[tGrass, tGrass, tGrass, tGrass, pForestP2], [tGrass, tGrass, tGrass, pForestP2]]
231 var size = forestTrees / (scaleByMapSize(3, 6) * numPlayers);
232 var num = Math.floor(size / types.length);
233 for (let type of types)
234         createAreas(
235                 new ChainPlacer(
236                         1,
237                         Math.floor(scaleByMapSize(3, 5)),
238                         forestTrees / (num * Math.floor(scaleByMapSize(2, 4))),
239                         0.5),
240                 [
241                         new LayeredPainter(type, [2]),
242                         new TileClassPainter(clForest)
243                 ],
244                 avoidClasses(
245                         clPlayer, 12,
246                         clForest, 6,
247                         clHill, 0,
248                         clGaia, 1,
249                         clWater, 2),
250                 num);
252 createStragglerTrees(
253         [oTree, oPalm1, oPalm2],
254         avoidClasses(
255                 clWater, 5,
256                 clForest, 1,
257                 clHill, 1,
258                 clPlayer, 8,
259                 clBaseResource, 4,
260                 clGaia, 1,
261                 clMetal, 4,
262                 clRock, 4),
263         clForest,
264         stragglerTrees);
266 Engine.SetProgress(60);
268 g_Map.log("Creating grass patches");
269 for (let size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)])
270         createAreas(
271                 new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), size, 0.5),
272                 [
273                         new LayeredPainter([tGrassC, tGrassA, tGrassB], [2, 1]),
274                         new TileClassPainter(clDirt)
275                 ],
276                 avoidClasses(
277                         clWater, 8,
278                         clForest, 0,
279                         clHill, 0,
280                         clGaia, 1,
281                         clPlayerTerritory, 0,
282                         clDirt, 16),
283                 scaleByMapSize(20, 80));
285 g_Map.log("Creating dirt patches");
286 for (let size of [scaleByMapSize(2, 4), scaleByMapSize(3, 7), scaleByMapSize(5, 15)])
287         createAreas(
288                 new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), size, 0.5),
289                 [
290                         new TerrainPainter(tPlants),
291                         new TileClassPainter(clDirt)
292                 ],
293                 avoidClasses(
294                         clWater, 8,
295                         clForest, 0,
296                         clHill, 0,
297                         clGaia, 1,
298                         clPlayerTerritory, 0,
299                         clDirt, 16),
300                 scaleByMapSize(20, 80));
302 g_Map.log("Creating stone mines");
303 createObjectGroups(
304         new SimpleGroup(
305                 [
306                         new SimpleObject(oStoneSmall, 0, 2, 0, 4),
307                         new SimpleObject(oStoneLarge, 1, 1, 0, 4)
308                 ],
309                 true,
310                 clRock),
311         0,
312         avoidClasses(
313                 clWater, 3,
314                 clForest, 1,
315                 clPlayerTerritory, 0,
316                 clGaia, 1,
317                 clRock, 10,
318                 clHill, 1),
319                 scaleByMapSize(4, 16),
320                 50);
322 g_Map.log("Creating small stone mines");
323 createObjectGroups(
324         new SimpleGroup([new SimpleObject(oStoneSmall, 2, 5, 1, 3)], true, clRock),
325         0,
326         avoidClasses(
327                 clWater, 4,
328                 clForest, 1,
329                 clPlayerTerritory, 0,
330                 clGaia, 1,
331                 clRock, 10,
332                 clHill, 1),
333         scaleByMapSize(2, 8),
334         50);
336 g_Map.log("Creating metal mines");
337 createObjectGroups(
338         new SimpleGroup([new SimpleObject(oMetalLarge, 1, 1, 0, 4)], true, clMetal),
339         0,
340         avoidClasses(
341                 clWater, 4,
342                 clForest, 1,
343                 clPlayerTerritory, 0,
344                 clGaia, 1,
345                 clMetal, 10,
346                 clRock, 5,
347                 clHill, 1),
348         scaleByMapSize(4, 16),
349         50);
351 g_Map.log("Creating small decorative rocks");
352 createObjectGroups(
353         new SimpleGroup([new SimpleObject(aRockMedium, 1, 3, 0, 1)], true),
354         0,
355         avoidClasses(
356                 clWater, 2,
357                 clForest, 1,
358                 clGaia, 1,
359                 clPlayer, 8,
360                 clBaseResource, 4,
361                 clHill, 0),
362         scaleByMapSize(50, 800),
363         20);
365 g_Map.log("Creating large decorative rocks");
366 createObjectGroups(
367         new SimpleGroup([
368                         new SimpleObject(aRockLarge, 1, 2, 0, 1),
369                         new SimpleObject(aRockMedium, 1, 3, 0, 2)
370                 ],
371                 true),
372         0,
373         avoidClasses(
374                 clWater, 2,
375                 clForest, 1,
376                 clGaia, 1,
377                 clPlayer, 8,
378                 clBaseResource, 4,
379                 clHill, 0),
380         scaleByMapSize(25, 400),
381         50);
383 g_Map.log("Creating small grass tufts");
384 createObjectGroups(
385         new SimpleGroup([new SimpleObject(aBush1, 1, 2, 0, 1)]),
386         0,
387         avoidClasses(
388                 clWater, 4,
389                 clHill, 2,
390                 clPlayer, 8,
391                 clGaia, 1,
392                 clBaseResource, 4,
393                 clDirt, 0),
394         scaleByMapSize(100, 500));
395 Engine.SetProgress(70);
397 g_Map.log("Creating large grass tufts");
398         createObjectGroups(
399                 new SimpleGroup([
400                         new SimpleObject(aBush2, 2, 4, 0, 1.8, -Math.PI / 8, Math.PI / 8),
401                         new SimpleObject(aBush1, 3, 6, 1.2, 2.5, -Math.PI / 8, Math.PI / 8)
402                 ]),
403                 0,
404                 avoidClasses(
405                         clWater, 4,
406                         clHill, 2,
407                         clGaia, 1,
408                         clPlayer, 8,
409                         clBaseResource, 4,
410                         clDirt, 1,
411                         clForest, 0),
412                 scaleByMapSize(100, 500));
413 Engine.SetProgress(85);
415 g_Map.log("Creating bushes");
416         createObjectGroups(
417                 new SimpleGroup([
418                         new SimpleObject(aBush3, 1, 2, 0, 2),
419                         new SimpleObject(aBush2, 2, 4, 0, 2)
420                 ]), 0,
421                 avoidClasses(
422                         clWater, 4,
423                         clHill, 1,
424                         clPlayerTerritory, 0,
425                         clGaia, 1,
426                         clDirt, 1),
427                 scaleByMapSize(100, 500));
429 g_Map.log("Creating deer");
430         createObjectGroups(
431                 new SimpleGroup([new SimpleObject(oDeer, 5, 7, 0, 4)], true, clFood),
432                 0,
433                 avoidClasses(
434                         clWater, 4,
435                         clForest, 0,
436                         clPlayerTerritory, 0,
437                         clGaia, 1,
438                         clHill, 1,
439                         clFood, 20),
440                 3 * numPlayers,
441                 20);
443 g_Map.log("Creating boar");
444         createObjectGroups(
445                 new SimpleGroup([new SimpleObject(oBoar, 2, 4, 0, 4)], true, clFood),
446                 0,
447                 avoidClasses(
448                         clWater, 4,
449                         clForest, 0,
450                         clPlayerTerritory, 0,
451                         clGaia, 1,
452                         clHill, 1,
453                         clRock, 4,
454                         clMetal, 4,
455                         clFood, 20),
456                 2 * numPlayers,
457                 20);
459 g_Map.log("Creating tigers");
460 createObjectGroups(
461         new SimpleGroup([new SimpleObject(oTiger, 1, 1, 0, 4)], true, clFood),
462         0,
463         avoidClasses(
464                 clWater, 4,
465                 clForest, 0,
466                 clPlayerTerritory, 0,
467                 clGaia, 1,
468                 clHill, 1,
469                 clRock, 4,
470                 clMetal, 4,
471                 clFood, 20),
472         2 * numPlayers,
473         20);
474 Engine.SetProgress(95);
476 g_Map.log("Creating berry bush");
477 createObjectGroups(
478         new SimpleGroup([new SimpleObject(oBush, 5, 7, 0, 4)], true, clFood),
479         0,
480         avoidClasses(
481                 clWater, 4,
482                 clForest, 0,
483                 clPlayerTerritory, 0,
484                 clGaia, 1,
485                 clHill, 1,
486                 clRock, 4,
487                 clMetal, 4,
488                 clFood, 10),
489                 randIntInclusive(1, 4) * numPlayers,
490                 20);
492 g_Map.log("Creating fish");
493 createObjectGroupsByAreas(
494         new SimpleGroup([new SimpleObject(oFish, 2, 3, 0, 2)], true, clFood),
495         0,
496         [avoidClasses(clFood, 15), stayClasses(clWater, 4)],
497         scaleByMapSize(20, 100),
498         20,
499         [areaWater]);
501 placePlayersNomad(clPlayer, avoidClasses(clWater, 4, clForest, 1, clMetal, 4, clRock, 4, clFood, 2));
503 setSunColor(0.6, 0.6, 0.6);
504 setSunElevation(Math.PI/ 3);
506 setWaterColor(0.424, 0.534, 0.639);
507 setWaterTint(0.369, 0.765, 0.745);
508 setWaterWaviness(1.0);
509 setWaterType("default");
510 setWaterMurkiness(0.35);
512 setFogFactor(0.03);
513 setFogThickness(0.2);
515 setPPEffect("hdr");
516 setPPContrast(0.7);
517 setPPSaturation(0.65);
518 setPPBloom(0.6);
520 setSkySet("stratus");
521 g_Map.ExportMap();