rmgen cleanup.
[0ad.git] / binaries / data / mods / public / maps / random / polar_sea.js
blob2f854daa13456ee11efb07827002b9b4c67abe76
1 RMS.LoadLibrary("rmgen");
3 var tPrimary = ["polar_snow_a"];
4 var tCliff = ["polar_cliff_a", "polar_cliff_b", "polar_cliff_snow"];
5 var tSecondary = "polar_snow_glacial";
6 var tHalfSnow = ["ice_01", "ice_dirt"];
7 var tSnowLimited = ["polar_snow_b", "polar_ice"];
8 var tDirt = "ice_dirt";
9 var tRoad = "polar_ice_b";
10 var tRoadWild = "polar_ice_cracked";
11 var tShore = "polar_ice_snow";
12 var tWater = "polar_ice_c";
14 var oArcticFox = "gaia/fauna_fox_arctic";
15 var oWolf = "trigger/fauna_wolf_snow_attack";
16 var oMuskox = "gaia/fauna_muskox";
17 var oWalrus = "gaia/fauna_walrus";
18 var oWhaleFin = "gaia/fauna_whale_fin";
19 var oWhaleHumpback = "gaia/fauna_whale_humpback";
20 var oFish = "gaia/fauna_fish";
21 var oStoneLarge = "gaia/geology_stonemine_medit_quarry";
22 var oStoneSmall = "gaia/geology_stone_alpine_a";
23 var oMetalLarge = "gaia/geology_metal_desert_badlands_slabs";
24 var oWood = "gaia/special_treasure_wood";
26 var aRockLarge = "actor|geology/stone_granite_med.xml";
27 var aRockMedium = "actor|geology/stone_granite_med.xml";
28 var aIceberg = "actor|props/special/eyecandy/iceberg.xml";
30 InitMap();
32 const numPlayers = getNumPlayers();
33 const mapSize = getMapSize();
35 var clPlayer = createTileClass();
36 var clWater = createTileClass();
37 var clDirt = createTileClass();
38 var clRock = createTileClass();
39 var clMetal = createTileClass();
40 var clHill = createTileClass();
41 var clFood = createTileClass();
42 var clBaseResource = createTileClass();
43 var clWolf = createTileClass();
45 // Expected by rmgen1
46 var clForest = createTileClass();
48 var [playerIDs, playerX, playerZ] = radialPlayerPlacement();
50 RMS.SetProgress(20);
52 for (let i = 0; i < numPlayers; ++i)
54         let id = playerIDs[i];
55         log("Creating base for player " + id + "...");
57         let fx = fractionToTiles(playerX[i]);
58         let fz = fractionToTiles(playerZ[i]);
59         let ix = Math.round(fx);
60         let iz = Math.round(fz);
62         addCivicCenterAreaToClass(ix, iz, clPlayer);
64         // Create the city patch
65         let cityRadius = scaleByMapSize(15,25)/3;
66         let placer = new ClumpPlacer(PI*cityRadius*cityRadius, 0.6, 0.3, 10, ix, iz);
67         let painter = new LayeredPainter([tRoadWild, tRoad], [1]);
68         createArea(placer, painter, null);
70         placeCivDefaultEntities(fx, fz, id, { 'iberWall': 'towers' });
72         placeDefaultChicken(fx, fz, clBaseResource, undefined, oMuskox);
74         // Create metal mine
75         let mAngle = randFloat(0, TWO_PI);
76         let mDist = 12;
77         let mX = Math.round(fx + mDist * Math.cos(mAngle));
78         let mZ = Math.round(fz + mDist * Math.sin(mAngle));
79         let group = new SimpleGroup(
80                 [new SimpleObject(oMetalLarge, 1, 1, 0, 0)],
81                 true, clBaseResource, mX, mZ
82         );
83         createObjectGroup(group, 0);
85         // Create stone mines
86         mAngle += randFloat(PI/8, PI/4);
87         mX = Math.round(fx + mDist * Math.cos(mAngle));
88         mZ = Math.round(fz + mDist * Math.sin(mAngle));
89         group = new SimpleGroup(
90                 [new SimpleObject(oStoneLarge, 1, 1, 0, 2)],
91                 true, clBaseResource, mX, mZ
92         );
93         createObjectGroup(group, 0);
95         // Create wood treasure
96         mAngle += PI/4;
97         let bbX = Math.round(fx + mDist * Math.cos(mAngle));
98         let bbZ = Math.round(fz + mDist * Math.sin(mAngle));
99         createObjectGroup(
100                 new SimpleGroup(
101                         [new SimpleObject(oWood, 14,14, 0,3)],
102                         true, clBaseResource, bbX, bbZ,
103                         avoidClasses(clBaseResource, 4)
104                 ), 0);
106         // Create market
107         mAngle += PI/4;
108         placeObject(
109                 Math.round(fx + mDist * Math.cos(mAngle)),
110                 Math.round(fz + mDist * Math.sin(mAngle)),
111                 "structures/" + getCivCode(id-1) + "_market",
112                 id,
113                 BUILDING_ORIENTATION);
115 RMS.SetProgress(30);
117 log("Creating central lake...");
118 createArea(
119         new ChainPlacer(
120                 2,
121                 Math.floor(scaleByMapSize(5, 16)),
122                 Math.floor(scaleByMapSize(35, 200)),
123                 1,
124                 Math.round(fractionToTiles(0.5)),
125                 Math.round(fractionToTiles(0.5)),
126                 0,
127                 [Math.floor(mapSize * 0.17)]),
128         [
129                 new LayeredPainter([tShore, tWater, tWater, tWater], [1, 4, 2]),
130                 new SmoothElevationPainter(ELEVATION_SET, -4, 4),
131                 paintClass(clWater)
132         ],
133         avoidClasses(clPlayer, 20));
135 paintTerrainBasedOnHeight(3, Math.floor(scaleByMapSize(20, 40)), 0, tCliff);
136 paintTerrainBasedOnHeight(Math.floor(scaleByMapSize(20, 40)), 100, 3, tSnowLimited);
137 RMS.SetProgress(40);
139 log("Creating small lakes...");
140 var lakeAreas = [];
141 var playerConstraint = new AvoidTileClassConstraint(clPlayer, 20);
142 var waterConstraint = new AvoidTileClassConstraint(clWater, 8);
143 for (let x = 0; x < mapSize; ++x)
144         for (let z = 0; z < mapSize; ++z)
145                 if (playerConstraint.allows(x, z) && waterConstraint.allows(x, z))
146                         lakeAreas.push([x, z]);
148 var numLakes = scaleByMapSize(10, 16);
149 for (let i = 0; i < numLakes ; ++i)
151         let chosenPoint = pickRandom(lakeAreas);
152         if (!chosenPoint)
153                 break;
155         createAreas(
156                 new ChainPlacer(
157                         1,
158                         Math.floor(scaleByMapSize(2, 4)),
159                         Math.floor(scaleByMapSize(20, 140)),
160                         0.7,
161                         chosenPoint[0],
162                         chosenPoint[1]),
163                 [
164                         new LayeredPainter([tShore, tWater, tWater], [1, 3]),
165                         new SmoothElevationPainter(ELEVATION_SET, -5, 5),
166                         paintClass(clWater)
167                 ],
168                 avoidClasses(clPlayer, 20),
169                 1,
170                 1);
172 RMS.SetProgress(50);
174 createBumps(avoidClasses(clWater, 2, clPlayer, 20));
175 RMS.SetProgress(60);
177 log("Creating hills...");
178 createHills(
179         [tPrimary, tPrimary, tSecondary],
180         avoidClasses(clPlayer, 20, clHill, 35),
181         clHill, scaleByMapSize(20, 240));
182 RMS.SetProgress(65);
184 log("Creating dirt patches...");
185 createLayeredPatches(
186         [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)],
187         [[tDirt,tHalfSnow], [tHalfSnow,tSnowLimited]],
188         [2],
189         avoidClasses(clWater, 3, clDirt, 5, clPlayer, 12));
191 log("Creating glacier patches...");
192 createPatches(
193         [scaleByMapSize(2, 4), scaleByMapSize(3, 7), scaleByMapSize(5, 15)],
194         tSecondary,
195         avoidClasses(clWater, 3, clDirt, 5, clPlayer, 12));
196 RMS.SetProgress(70);
198 log("Creating stone mines...");
199         createMines(
200         [
201                 [new SimpleObject(oStoneSmall, 0,2, 0,4), new SimpleObject(oStoneLarge, 1,1, 0,4)],
202                 [new SimpleObject(oStoneSmall, 2,5, 1,3)]
203         ],
204         avoidClasses(clWater, 3, clPlayer, 20, clRock, 18, clHill, 2)
207 log("Creating metal mines...");
208 createMines(
209         [
210                 [new SimpleObject(oMetalLarge, 1,1, 0,4)]
211         ],
212         avoidClasses(clWater, 3, clPlayer, 20, clMetal, 18, clRock, 5, clHill, 2),
213         clMetal);
214 RMS.SetProgress(75);
216 createDecoration(
217         [
218                 [new SimpleObject(aRockMedium, 1,3, 0,1)],
219                 [
220                         new SimpleObject(aRockLarge, 1,2, 0,1),
221                         new SimpleObject(aRockMedium, 1,3, 0,2)
222                 ]
223         ],
224         [
225                 scaleByMapSize(16, 262),
226                 scaleByMapSize(8, 131),
227         ],
228         avoidClasses(clWater, 0, clPlayer, 0));
230 createDecoration(
231         [
232                 [new SimpleObject(aIceberg, 1, 1, 1, 1)]
233         ],
234         [
235                 scaleByMapSize(8, 131)
236         ],
237         [stayClasses(clWater, 4), avoidClasses(clHill, 2)]);
238 RMS.SetProgress(80);
240 createFood(
241         [
242                 [new SimpleObject(oArcticFox, 1,2, 0,3)],
243                 [new SimpleObject(oWolf, 4,6, 0,4)],
244                 [new SimpleObject(oWalrus, 2,3, 0,2)],
245                 [new SimpleObject(oMuskox, 2,3, 0,2)]
246         ],
247         [
248                 3 * numPlayers,
249                 5 * numPlayers,
250                 5 * numPlayers,
251                 12 * numPlayers
252         ],
253         avoidClasses(clPlayer, 35, clFood, 16, clWater, 2, clMetal, 4, clRock, 4, clHill, 2)
256 createFood(
257         [
258                 [new SimpleObject(oWhaleFin, 1,2, 0,2)],
259                 [new SimpleObject(oWhaleHumpback, 1,2, 0,2)]
260         ],
261         [
262                 scaleByMapSize(1, 6) * 3,
263                 scaleByMapSize(1, 6) * 3,
264         ],
265         [avoidClasses(clFood, 20, clHill, 5), stayClasses(clWater, 6)]
268 createFood(
269         [
270                 [new SimpleObject(oFish, 2,3, 0,2)]
271         ],
272         [
273                 100
274         ],
275         [avoidClasses(clFood, 12, clHill, 5), stayClasses(clWater, 6)]
277 RMS.SetProgress(85);
279 // Create trigger points where wolves spawn
280 createObjectGroupsDeprecated(
281         new SimpleGroup([new SimpleObject("trigger/trigger_point_A", 1, 1, 0, 0)], true, clWolf),
282         0,
283         avoidClasses(clWater, 2, clMetal, 4, clRock, 4, clPlayer, 15, clHill, 2, clWolf, 20),
284         1000,
285         100);
286 RMS.SetProgress(95);
288 if (randBool(1/3))
290         setSkySet("sunset 1");
291         setSunColor(0.8, 0.7, 0.6);
292         setTerrainAmbientColor(0.7, 0.6, 0.7);
293         setUnitsAmbientColor(0.6, 0.5, 0.6);
294         setSunElevation(randFloat(PI/24, PI/7));
296 else
298         setSkySet(pickRandom(["cumulus", "rain", "mountainous", "overcast", "rain", "stratus"]));
299         setSunElevation(randFloat(PI/9, PI/7));
302 setSunRotation(randFloat(0, TWO_PI));
304 setWaterColor(0.3, 0.3, 0.4);
305 setWaterTint(0.75, 0.75, 0.75);
306 setWaterMurkiness(0.92);
307 setWaterWaviness(0.5);
308 setWaterType("clap");
310 setFogThickness(0.76);
311 setFogFactor(0.7);
313 setPPEffect("hdr");
314 setPPContrast(0.6);
315 setPPSaturation(0.45);
316 setPPBloom(0.4);
318 ExportMap();