Fix the two incorrect replacements in rP21434, refs #4950.
[0ad.git] / binaries / data / mods / public / maps / random / river_archipelago.js
blob8bffb6687f01996f985c8d9c882d74737f8ee900
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 heightLand = 3;
45 const heightHill = 25;
47 var g_Map = new RandomMap(heightSeaGround, tGrass);
49 const numPlayers = getNumPlayers();
50 const mapCenter = g_Map.getCenter();
51 const mapBounds = g_Map.getBounds();
53 var clPlayer = g_Map.createTileClass();
54 var clPlayerTerritory = g_Map.createTileClass();
55 var clHill = g_Map.createTileClass();
56 var clForest = g_Map.createTileClass();
57 var clWater = g_Map.createTileClass();
58 var clDirt = g_Map.createTileClass();
59 var clRock = g_Map.createTileClass();
60 var clMetal = g_Map.createTileClass();
61 var clFood = g_Map.createTileClass();
62 var clBaseResource = g_Map.createTileClass();
63 var clGaia = g_Map.createTileClass();
64 var clStrip = [];
66 var startAngle = randomAngle();
67 var connectPlayers = randBool();
69 // Map layout
70 var stripWidthsLeft = connectPlayers ?
71         [[0.03, 0.09], [0.14, 0.25], [0.36, 0.46]] : 
72         [[0, 0.06], [0.12, 0.23], [0.33, 0.43]];
74 // Mirror
75 var stripWidthsRight = clone(stripWidthsLeft);
76 stripWidthsRight.reverse();
77 stripWidthsRight = stripWidthsRight.map(strip => [1 - strip[1], 1 - strip[0]]);
79 var stripWidths = stripWidthsLeft.concat(stripWidthsRight);
81 g_Map.log("Creating strips");
82 for (let i = 0; i < stripWidths.length; ++i)
84         clStrip[i] = g_Map.createTileClass();
86         let isPlayerStrip = i == 2 || i == 3;
87         for (let j = 0; j < scaleByMapSize(20, 100); ++j)
88         {
89                 let position = new Vector2D(
90                         randFloat(mapBounds.bottom, mapBounds.top),
91                         fractionToTiles(randFloat(...stripWidths[i]))).rotateAround(startAngle, mapCenter).round();
93                 createArea(
94                         new ChainPlacer(
95                                 1,
96                                 Math.floor(scaleByMapSize(3, connectPlayers && isPlayerStrip ? 8 : 7)),
97                                 Math.floor(scaleByMapSize(30, 60)),
98                                 Infinity,
99                                 position),
100                         [
101                                 new TerrainPainter(tGrass),
102                                 new SmoothElevationPainter(ELEVATION_SET, heightLand, 3),
103                                 new TileClassPainter(clStrip[i])
104                         ]);
105         }
107 Engine.SetProgress(20);
109 var playerPosition = playerPlacementLine(startAngle, mapCenter, fractionToTiles(1 - stripWidthsLeft[2][0] - stripWidthsLeft[2][1]));
111 // Either left vs right or top vs bottom
112 var playerIDs = randBool() ? sortAllPlayers() : primeSortAllPlayers();
114 g_Map.log("Ensuring player territory");
115 var playerRadius = scaleByMapSize(12, 20);
116 for (let i = 0; i < numPlayers; ++i)
117         createArea(
118                 new ChainPlacer(1, 6, 40, 1, playerPosition[i], 0, [Math.floor(playerRadius)]),
119                 [
120                         new TerrainPainter(tGrass),
121                         new SmoothElevationPainter(ELEVATION_SET, heightLand, 4),
122                         new TileClassPainter(clPlayerTerritory)
123                 ]);
125 placePlayerBases({
126         "PlayerPlacement": [playerIDs, playerPosition],
127         "PlayerTileClass": clPlayer,
128         "BaseResourceClass": clBaseResource,
129         "baseResourceConstraint": stayClasses(clPlayerTerritory, 4),
130         "Walls": "towers",
131         "CityPatch": {
132                 "outerTerrain": tRoadWild,
133                 "innerTerrain": tRoad,
134                 "radius": playerRadius / 3
135         },
136         "Chicken": {
137                 "template": oPeacock
138         },
139         "Berries": {
140                 "template": oBush
141         },
142         "Mines": {
143                 "types": [
144                         { "template": oMetalLarge },
145                         { "template": oStoneLarge }
146                 ]
147         },
148         "Trees": {
149                 "template": oTree,
150                 "count": 40
151         }
152         // No decoratives
154 Engine.SetProgress(35);
156 paintTerrainBasedOnHeight(-10, 0, 1, tWater);
157 paintTileClassBasedOnHeight(-10, 0, 1, clWater);
158 paintTerrainBasedOnHeight(1, 2.8, 1, tShoreBlend);
159 paintTerrainBasedOnHeight(0, 1, 1, tShore);
160 Engine.SetProgress(40);
162 if (!isNomad())
164         g_Map.log("Creating gaia");
165         for (let i = 0; i < 2; ++i)
166                 for (let j = 0; j < scaleByMapSize(1, 8); ++j)
167                         createObjectGroupsDeprecated(
168                                 new SimpleGroup(
169                                         [
170                                                 new SimpleObject(oSpearman, 8, 12, 2, 3),
171                                                 new SimpleObject(oArcher, 8, 12, 2, 3),
172                                                 new SimpleObject(oArcherElephant, 2, 3, 4, 5)
173                                         ],
174                                         true,
175                                         clGaia),
176                                 0,
177                                 [
178                                         avoidClasses(
179                                                 clWater, 2,
180                                                 clForest, 1,
181                                                 clPlayerTerritory, 0,
182                                                 clHill, 1,
183                                                 clGaia, 15),
184                                         stayClasses(clStrip[i == 0 ? 0 : stripWidths.length - 1], 1)
185                                 ],
186                                 scaleByMapSize(5, 10),
187                                 50);
190 g_Map.log("Creating hills");
191 createAreas(
192         new ChainPlacer(1, Math.floor(scaleByMapSize(4, 6)), Math.floor(scaleByMapSize(16, 40)), 0.1),
193         [
194                 new LayeredPainter([tCliff, tGrass], [3]),
195                 new SmoothElevationPainter(ELEVATION_SET, heightHill, 3),
196                 new TileClassPainter(clHill)
197         ],
198         [
199                 avoidClasses(
200                         clPlayerTerritory, 0,
201                         clHill, 5,
202                         clGaia, 1,
203                         clWater, 2)
204         ],
205         scaleByMapSize(1, 5));
207 createBumps(avoidClasses(clPlayer, 8, clWater, 2), scaleByMapSize(20, 150), 2, 8, 4, 1, 4);
208 Engine.SetProgress(50);
210 g_Map.log("Creating forests");
211 var [forestTrees, stragglerTrees] = getTreeCounts(1000, 4000, 0.7);
212 var types = [
213         [[tGrass, tGrass, tGrass, tGrass, pForestD], [tGrass, tGrass, tGrass, pForestD]],
214         [[tGrass, tGrass, tGrass, tGrass, pForestP1], [tGrass, tGrass, tGrass, pForestP1]],
215         [[tGrass, tGrass, tGrass, tGrass, pForestP2], [tGrass, tGrass, tGrass, pForestP2]]
217 var size = forestTrees / (scaleByMapSize(3, 6) * numPlayers);
218 var num = Math.floor(size / types.length);
219 for (let type of types)
220         createAreas(
221                 new ChainPlacer(
222                         1,
223                         Math.floor(scaleByMapSize(3, 5)),
224                         forestTrees / (num * Math.floor(scaleByMapSize(2, 4))),
225                         0.5),
226                 [
227                         new LayeredPainter(type, [2]),
228                         new TileClassPainter(clForest)
229                 ],
230                 avoidClasses(
231                         clPlayer, 12,
232                         clForest, 6,
233                         clHill, 0,
234                         clGaia, 1,
235                         clWater, 2),
236                 num);
238 createStragglerTrees(
239         [oTree, oPalm1, oPalm2],
240         avoidClasses(
241                 clWater, 5,
242                 clForest, 1,
243                 clHill, 1,
244                 clPlayer, 8,
245                 clBaseResource, 4,
246                 clGaia, 1,
247                 clMetal, 4,
248                 clRock, 4),
249         clForest,
250         stragglerTrees);
252 Engine.SetProgress(60);
254 g_Map.log("Creating grass patches");
255 for (let size of [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)])
256         createAreas(
257                 new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), size, 0.5),
258                 [
259                         new LayeredPainter([tGrassC, tGrassA, tGrassB], [2, 1]),
260                         new TileClassPainter(clDirt)
261                 ],
262                 avoidClasses(
263                         clWater, 8,
264                         clForest, 0,
265                         clHill, 0,
266                         clGaia, 1,
267                         clPlayerTerritory, 0,
268                         clDirt, 16),
269                 scaleByMapSize(20, 80));
271 g_Map.log("Creating dirt patches");
272 for (let size of [scaleByMapSize(2, 4), scaleByMapSize(3, 7), scaleByMapSize(5, 15)])
273         createAreas(
274                 new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), size, 0.5),
275                 [
276                         new TerrainPainter(tPlants),
277                         new TileClassPainter(clDirt)
278                 ],
279                 avoidClasses(
280                         clWater, 8,
281                         clForest, 0,
282                         clHill, 0,
283                         clGaia, 1,
284                         clPlayerTerritory, 0,
285                         clDirt, 16),
286                 scaleByMapSize(20, 80));
288 g_Map.log("Creating stone mines");
289 createObjectGroupsDeprecated(
290         new SimpleGroup(
291                 [
292                         new SimpleObject(oStoneSmall, 0, 2, 0, 4),
293                         new SimpleObject(oStoneLarge, 1, 1, 0, 4)
294                 ],
295                 true,
296                 clRock),
297         0,
298         avoidClasses(
299                 clWater, 3,
300                 clForest, 1,
301                 clPlayerTerritory, 0,
302                 clGaia, 1,
303                 clRock, 10,
304                 clHill, 1),
305                 9 * scaleByMapSize(1, 4),
306                 100);
308 g_Map.log("Creating small stone mines");
309 createObjectGroupsDeprecated(
310         new SimpleGroup([new SimpleObject(oStoneSmall, 2, 5, 1, 3)], true, clRock),
311         0,
312         avoidClasses(
313                 clWater, 4,
314                 clForest, 1,
315                 clPlayerTerritory, 0,
316                 clGaia, 1,
317                 clRock, 10,
318                 clHill, 1),
319                 9 * scaleByMapSize(1, 4),
320         100);
322 g_Map.log("Creating metal mines");
323 createObjectGroupsDeprecated(
324         new SimpleGroup([new SimpleObject(oMetalLarge, 1, 1, 0, 4)], true, clMetal),
325         0,
326         avoidClasses(
327                 clWater, 4,
328                 clForest, 1,
329                 clPlayerTerritory, 0,
330                 clGaia, 1,
331                 clMetal, 10,
332                 clRock, 5,
333                 clHill, 1),
334         9 * scaleByMapSize(1, 4),
335         100);
337 g_Map.log("Creating small decorative rocks");
338 createObjectGroupsDeprecated(
339         new SimpleGroup([new SimpleObject(aRockMedium, 1, 3, 0, 1)], true),
340         0,
341         avoidClasses(
342                 clWater, 2,
343                 clForest, 1,
344                 clGaia, 1,
345                 clPlayer, 8,
346                 clBaseResource, 4,
347                 clHill, 0),
348         3 * scaleByMapSize(16, 262),
349         50);
351 g_Map.log("Creating large decorative rocks");
352 createObjectGroupsDeprecated(
353         new SimpleGroup([
354                         new SimpleObject(aRockLarge, 1, 2, 0, 1),
355                         new SimpleObject(aRockMedium, 1, 3, 0, 2)
356                 ],
357                 true),
358         0,
359         avoidClasses(
360                 clWater, 2,
361                 clForest, 1,
362                 clGaia, 1,
363                 clPlayer, 8,
364                 clBaseResource, 4,
365                 clHill, 0),
366         3 * scaleByMapSize(8, 131),
367         50);
369 g_Map.log("Creating small grass tufts");
370 createObjectGroupsDeprecated(
371         new SimpleGroup([new SimpleObject(aBush1, 1, 2, 0, 1, -Math.PI / 8, Math.PI / 8)]),
372         0,
373         avoidClasses(
374                 clWater, 4,
375                 clHill, 2,
376                 clPlayer, 8,
377                 clGaia, 1,
378                 clBaseResource, 4,
379                 clDirt, 0),
380         8 * scaleByMapSize(13, 200));
381 Engine.SetProgress(70);
383 g_Map.log("Creating large grass tufts");
384         createObjectGroupsDeprecated(
385                 new SimpleGroup([
386                         new SimpleObject(aBush2, 2, 4, 0, 1.8, -Math.PI / 8, Math.PI / 8),
387                         new SimpleObject(aBush1, 3, 6, 1.2, 2.5, -Math.PI / 8, Math.PI / 8)
388                 ]),
389                 0,
390                 avoidClasses(
391                         clWater, 4,
392                         clHill, 2,
393                         clGaia, 1,
394                         clPlayer, 8,
395                         clBaseResource, 4,
396                         clDirt, 1,
397                         clForest, 0),
398                 8 * scaleByMapSize(13, 200));
399 Engine.SetProgress(85);
401 g_Map.log("Creating bushes");
402         createObjectGroupsDeprecated(
403                 new SimpleGroup([
404                         new SimpleObject(aBush3, 1, 2, 0, 2),
405                         new SimpleObject(aBush2, 2, 4, 0, 2)
406                 ]), 0,
407                 avoidClasses(
408                         clWater, 4,
409                         clHill, 1,
410                         clPlayerTerritory, 0,
411                         clGaia, 1,
412                         clDirt, 1),
413                 8 * scaleByMapSize(13, 200), 50);
415 g_Map.log("Creating deer");
416         createObjectGroupsDeprecated(
417                 new SimpleGroup([new SimpleObject(oDeer, 5, 7, 0, 4)], true, clFood),
418                 0,
419                 avoidClasses(
420                         clWater, 4,
421                         clForest, 0,
422                         clPlayerTerritory, 0,
423                         clGaia, 1,
424                         clHill, 1,
425                         clFood, 20),
426                 3 * numPlayers,
427                 50);
429 g_Map.log("Creating boar");
430         createObjectGroupsDeprecated(
431                 new SimpleGroup([new SimpleObject(oBoar, 2, 4, 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                 50);
443 g_Map.log("Creating tigers");
444 createObjectGroupsDeprecated(
445         new SimpleGroup([new SimpleObject(oTiger, 1, 1, 0, 4)], true, clFood),
446         0,
447         avoidClasses(
448                 clWater, 4,
449                 clForest, 0,
450                 clPlayerTerritory, 0,
451                 clGaia, 1,
452                 clHill, 1,
453                 clFood, 20),
454         3 * numPlayers,
455         50);
456 Engine.SetProgress(95);
458 g_Map.log("Creating berry bush");
459 createObjectGroupsDeprecated(
460         new SimpleGroup([new SimpleObject(oBush, 5, 7, 0, 4)], true, clFood),
461         0,
462         avoidClasses(
463                 clWater, 4,
464                 clForest, 0,
465                 clPlayerTerritory, 0,
466                 clGaia, 1,
467                 clHill, 1,
468                 clFood, 10),
469                 randIntInclusive(1, 4) * numPlayers + 2,
470                 50);
472 g_Map.log("Creating fish");
473 createObjectGroupsDeprecated(
474         new SimpleGroup([new SimpleObject(oFish, 2, 3, 0, 2)], true, clFood),
475         0,
476         [avoidClasses(clFood, 15), stayClasses(clWater, 4)],
477         200,
478         100);
480 placePlayersNomad(clPlayer, avoidClasses(clWater, 4, clForest, 1, clMetal, 4, clRock, 4, clFood, 2));
482 setSunColor(0.6, 0.6, 0.6);
483 setSunElevation(Math.PI/ 3);
485 setWaterColor(0.424, 0.534, 0.639);
486 setWaterTint(0.369, 0.765, 0.745);
487 setWaterWaviness(1.0);
488 setWaterType("default");
489 setWaterMurkiness(0.35);
491 setFogFactor(0.03);
492 setFogThickness(0.2);
494 setPPEffect("hdr");
495 setPPContrast(0.7);
496 setPPSaturation(0.65);
497 setPPBloom(0.6);
499 setSkySet("stratus");
500 g_Map.ExportMap();