Fix the two incorrect replacements in rP21434, refs #4950.
[0ad.git] / binaries / data / mods / public / maps / random / survivalofthefittest.js
blobb729fcc289f19078ec1a561412d06470b9220fc8
1 Engine.LoadLibrary("rmgen");
2 Engine.LoadLibrary("rmgen-common");
3 Engine.LoadLibrary("rmbiome");
5 setSelectedBiome();
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 tHill = g_Terrains.hill;
12 const tTier1Terrain = g_Terrains.tier1Terrain;
13 const tTier2Terrain = g_Terrains.tier2Terrain;
14 const tTier3Terrain = g_Terrains.tier3Terrain;
15 const tTier4Terrain = g_Terrains.tier4Terrain;
17 const oTree1 = g_Gaia.tree1;
18 const oTree2 = g_Gaia.tree2;
19 const oTree3 = g_Gaia.tree3;
20 const oTree4 = g_Gaia.tree4;
21 const oTree5 = g_Gaia.tree5;
23 const aGrass = g_Decoratives.grass;
24 const aGrassShort = g_Decoratives.grassShort;
25 const aRockLarge = g_Decoratives.rockLarge;
26 const aRockMedium = g_Decoratives.rockMedium;
27 const aBushMedium = g_Decoratives.bushMedium;
28 const aBushSmall = g_Decoratives.bushSmall;
29 const aWaypointFlag = "actor|props/special/common/waypoint_flag.xml";
31 const pForest1 = [tForestFloor2 + TERRAIN_SEPARATOR + oTree1, tForestFloor2 + TERRAIN_SEPARATOR + oTree2, tForestFloor2];
32 const pForest2 = [tForestFloor1 + TERRAIN_SEPARATOR + oTree4, tForestFloor1 + TERRAIN_SEPARATOR + oTree5, tForestFloor1];
34 const oTreasureSeeker = "undeletable|skirmish/units/default_support_female_citizen";
36 const triggerPointAttacker = "trigger/trigger_point_A";
37 const triggerPointTreasures = [
38         "trigger/trigger_point_B",
39         "trigger/trigger_point_C",
40         "trigger/trigger_point_D"
43 const heightLand = 3;
44 const heightHill = 30;
46 var g_Map = new RandomMap(heightHill, tMainTerrain);
48 var numPlayers = getNumPlayers();
49 var mapSize = g_Map.getSize();
50 var mapCenter = g_Map.getCenter();
52 var clPlayer = g_Map.createTileClass();
53 var clHill = g_Map.createTileClass();
54 var clForest = g_Map.createTileClass();
55 var clDirt = g_Map.createTileClass();
56 var clBaseResource = g_Map.createTileClass();
57 var clLand = g_Map.createTileClass();
58 var clWomen = g_Map.createTileClass();
60 g_Map.log("Creating central area");
61 createArea(
62         new ClumpPlacer(diskArea(fractionToTiles(0.15)), 0.7, 0.1, Infinity, mapCenter),
63         [
64                 new TerrainPainter(tMainTerrain),
65                 new SmoothElevationPainter(ELEVATION_SET, heightLand, 3),
66                 new TileClassPainter(clLand)
67         ]);
68 Engine.SetProgress(10);
70 var [playerIDs, playerPosition, playerAngle, startAngle] = playerPlacementCircle(fractionToTiles(0.3));
71 var halfway = distributePointsOnCircle(numPlayers, startAngle, fractionToTiles(0.375), mapCenter)[0].map(v => v.round());
72 var attacker = distributePointsOnCircle(numPlayers, startAngle, fractionToTiles(0.45), mapCenter)[0].map(v => v.round());
73 var passage = distributePointsOnCircle(numPlayers, startAngle + Math.PI / numPlayers, fractionToTiles(0.5), mapCenter)[0];
75 g_Map.log("Creating player bases, passages, treasure seeker woman and attacker points");
76 for (let  i = 0; i < numPlayers; ++i)
78         placeStartingEntities(playerPosition[i], playerIDs[i], getStartingEntities(playerIDs[i]).filter(ent =>
79                 ent.Template.indexOf("civil_centre") != -1 || ent.Template.indexOf("infantry") != -1));
81         placePlayerBaseDecoratives({
82                 "playerPosition": playerPosition[i],
83                 "template": aGrassShort,
84                 "BaseResourceClass": clBaseResource
85         });
87         // Passage between player and neighbor
88         createArea(
89                 new PathPlacer(mapCenter, passage[i], scaleByMapSize(14, 24), 0.4, scaleByMapSize(3, 9), 0.2, 0.05),
90                 [
91                         new TerrainPainter(tMainTerrain),
92                         new SmoothElevationPainter(ELEVATION_SET, heightLand, 4)
93                 ]);
95         // Treasure seeker woman
96         let femaleLocation = findLocationInDirectionBasedOnHeight(playerPosition[i], mapCenter, -3 , 3.5, 3).round();
97         clWomen.add(femaleLocation);
98         g_Map.placeEntityPassable(oTreasureSeeker, playerIDs[i], femaleLocation, playerAngle[i] + Math.PI);
100         // Attacker spawn point
101         g_Map.placeEntityAnywhere(aWaypointFlag, 0, attacker[i], Math.PI / 2);
102         g_Map.placeEntityPassable(triggerPointAttacker, playerIDs[i], attacker[i], Math.PI / 2);
104         // Preventing mountains in the area between player and attackers at player
105         addCivicCenterAreaToClass(playerPosition[i], clPlayer);
106         clPlayer.add(attacker[i]);
107         clPlayer.add(halfway[i]);
109 Engine.SetProgress(20);
111 paintTerrainBasedOnHeight(heightLand + 0.12, heightHill - 1, Elevation_IncludeMin_ExcludeMax, tCliff);
112 paintTileClassBasedOnHeight(heightLand + 0.12, heightHill - 1, Elevation_IncludeMin_ExcludeMax, clHill);
113 Engine.SetProgress(30);
115 var landConstraint = new StaticConstraint(stayClasses(clLand, 5));
117 for (let triggerPointTreasure of triggerPointTreasures)
118         createObjectGroupsDeprecated(
119                 new SimpleGroup([new SimpleObject(triggerPointTreasure, 1, 1, 0, 0)], true, clWomen),
120                 0,
121                 [avoidClasses(clPlayer, 5, clHill, 5), landConstraint],
122                 scaleByMapSize(40, 140),
123                 100);
124 Engine.SetProgress(35);
126 createBumps(landConstraint);
127 Engine.SetProgress(40);
129 var hillConstraint = new AndConstraint([avoidClasses(clHill, 5), new StaticConstraint(avoidClasses(clPlayer, 20, clBaseResource, 3, clWomen, 5))]);
130 if (randBool())
131         createHills([tMainTerrain, tCliff, tHill], [hillConstraint, landConstraint], clHill, scaleByMapSize(10, 60) * numPlayers);
132 else
133         createMountains(tCliff, [hillConstraint, landConstraint], clHill, scaleByMapSize(10, 60) * numPlayers);
134 Engine.SetProgress(45);
136 createHills(
137         [tCliff, tCliff, tHill],
138         [hillConstraint, avoidClasses(clLand, 5)],
139         clHill,
140         scaleByMapSize(15, 90) * numPlayers,
141         undefined,
142         undefined,
143         undefined,
144         undefined,
145         55);
146 Engine.SetProgress(50);
148 var [forestTrees, stragglerTrees] = getTreeCounts(...rBiomeTreeCount(1));
149 createForests(
150         [tMainTerrain, tForestFloor1, tForestFloor2, pForest1, pForest2],
151         [avoidClasses(clForest, 5), new StaticConstraint([avoidClasses(clPlayer, 20, clHill, 0, clBaseResource, 2, clWomen, 5), stayClasses(clLand, 4)])],
152         clForest,
153         forestTrees);
155 Engine.SetProgress(60);
157 g_Map.log("Creating dirt patches");
158 createLayeredPatches(
159         [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)],
160         [[tMainTerrain, tTier1Terrain], [tTier1Terrain, tTier2Terrain], [tTier2Terrain, tTier3Terrain]],
161         [1, 1],
162         [avoidClasses(clForest, 0, clHill, 0, clDirt, 5, clPlayer, 12, clWomen, 5), landConstraint],
163         scaleByMapSize(15, 45),
164         clDirt);
165 Engine.SetProgress(70);
167 g_Map.log("Creating grass patches");
168 createPatches(
169         [scaleByMapSize(2, 4), scaleByMapSize(3, 7), scaleByMapSize(5, 15)],
170         tTier4Terrain,
171         [avoidClasses(clForest, 0, clHill, 0, clDirt, 5, clPlayer, 12, clWomen, 5), landConstraint],
172         scaleByMapSize(15, 45),
173         clDirt);
174 Engine.SetProgress(80);
176 var planetm = 1;
177 if (currentBiome() == "generic/tropic")
178         planetm = 8;
180 createDecoration(
181         [
182                 [new SimpleObject(aRockMedium, 1, 3, 0, 1)],
183                 [new SimpleObject(aRockLarge, 1, 2, 0, 1), new SimpleObject(aRockMedium, 1, 3, 0, 2)],
184                 [new SimpleObject(aGrassShort, 1, 2, 0, 1)],
185                 [new SimpleObject(aGrass, 2,4, 0, 1.8), new SimpleObject(aGrassShort, 3, 6, 1.2, 2.5)],
186                 [new SimpleObject(aBushMedium, 1, 2, 0, 2), new SimpleObject(aBushSmall, 2, 4, 0, 2)]
187         ],
188         [
189                 scaleByMapSize(16, 262),
190                 scaleByMapSize(8, 131),
191                 planetm * scaleByMapSize(13, 200),
192                 planetm * scaleByMapSize(13, 200),
193                 planetm * scaleByMapSize(13, 200)
194         ],
195         [avoidClasses(clForest, 0, clPlayer, 0, clHill, 0), landConstraint]);
196 Engine.SetProgress(90);
198 createStragglerTrees(
199         [oTree1, oTree2, oTree4, oTree3],
200         [avoidClasses(clForest, 7, clHill, 1, clPlayer, 9), stayClasses(clLand, 7)],
201         clForest,
202         stragglerTrees);
204 Engine.SetProgress(95);
206 g_Map.ExportMap();