Invincible women on survival of the fittest to prevent women fights and cheap tower...
[0ad.git] / binaries / data / mods / public / maps / random / fortress.js
blob402ef8eb639140b5436d7959abe30fe00d9f7f42
1 RMS.LoadLibrary("rmgen");
3 // terrain textures
4 const tGrass = ["temp_grass_aut", "temp_grass_aut", "temp_grass_d_aut"];
5 const tForestFloor = "temp_grass_aut";
6 const tGrassA = "temp_grass_plants_aut";
7 const tGrassB = "temp_grass_b_aut";
8 const tGrassC = "temp_grass_c_aut";
9 const tDirt = ["temp_plants_bog_aut", "temp_mud_a"];
10 const tHill = ["temp_highlands_aut", "temp_grass_long_b_aut"];
11 const tCliff = ["temp_cliff_a", "temp_cliff_b"];
12 const tRoad = "temp_road_aut";
13 const tRoadWild = "temp_road_overgrown_aut";
14 const tGrassPatch = "temp_grass_plants_aut";
15 const tShoreBlend = "temp_grass_plants_aut";
16 const tShore = "temp_plants_bog_aut";
17 const tWater = "temp_mud_a";
19 // gaia entities
20 const oBeech = "gaia/flora_tree_euro_beech_aut";
21 const oOak = "gaia/flora_tree_oak_aut";
22 const oPine = "gaia/flora_tree_pine";
23 const oDeer = "gaia/fauna_deer";
24 const oFish = "gaia/fauna_fish";
25 const oSheep = "gaia/fauna_rabbit";
26 const oBerryBush = "gaia/flora_bush_berry";
27 const oStoneLarge = "gaia/geology_stonemine_temperate_quarry";
28 const oStoneSmall = "gaia/geology_stone_temperate";
29 const oMetalLarge = "gaia/geology_metal_temperate_slabs";
30 const oWood = "gaia/special_treasure_wood";
31 const oFood = "gaia/special_treasure_food_bin";
32 const oMetal = "gaia/special_treasure_metal";
33 const oStone = "gaia/special_treasure_stone";
35 // decorative props
36 const aGrass = "actor|props/flora/grass_soft_dry_small_tall.xml";
37 const aGrassShort = "actor|props/flora/grass_soft_dry_large.xml";
38 const aRockLarge = "actor|geology/stone_granite_med.xml";
39 const aRockMedium = "actor|geology/stone_granite_med.xml";
40 const aReeds = "actor|props/flora/reeds_pond_dry.xml";
41 const aLillies = "actor|props/flora/water_lillies.xml";
42 const aBushMedium = "actor|props/flora/bush_medit_me_dry.xml";
43 const aBushSmall = "actor|props/flora/bush_medit_sm_dry.xml";
45 const pForestD = [tForestFloor + TERRAIN_SEPARATOR + oBeech, tForestFloor];
46 const pForestO = [tForestFloor + TERRAIN_SEPARATOR + oOak, tForestFloor];
47 const pForestP = [tForestFloor + TERRAIN_SEPARATOR + oPine, tForestFloor];
49 log("Initializing map...");
50 InitMap();
52 const numPlayers = getNumPlayers();
53 const mapSize = getMapSize();
54 const mapArea = mapSize*mapSize;
56 var clPlayer = createTileClass();
57 var clHill = createTileClass();
58 var clForest = createTileClass();
59 var clWater = createTileClass();
60 var clDirt = createTileClass();
61 var clRock = createTileClass();
62 var clMetal = createTileClass();
63 var clFood = createTileClass();
64 var clBaseResource = createTileClass();
65 var clSettlement = createTileClass();
67 // randomize player order
68 var playerIDs = [];
69 for (var i = 0; i < numPlayers; i++)
70         playerIDs.push(i+1);
72 playerIDs = sortPlayers(playerIDs);
74 // place players
75 var playerX = new Array(numPlayers);
76 var playerZ = new Array(numPlayers);
77 var playerAngle = new Array(numPlayers);
78 var baseRadius = 30;
80 var startAngle = randFloat(0, TWO_PI);
81 for (var i = 0; i < numPlayers; i++)
83         playerAngle[i] = startAngle + i*TWO_PI/numPlayers;
84         playerX[i] = mapSize*(0.5 + 0.35*cos(playerAngle[i]));
85         playerZ[i] = mapSize*(0.5 + 0.35*sin(playerAngle[i]));
88 for (var i=0; i < numPlayers; i++)
90         var startEntities = getStartingEntities(i);
91         // Place starting entities
92         createStartingPlayerEntities(playerX[i], playerZ[i], i+1, startEntities);
93         var uDist = 8;
94         var uSpace = 2;
95         for (var j = 1; j < startEntities.length - 1; ++j)
96         {
97                 var uAngle = BUILDING_ORIENTATION - PI * (2-j) / 2;
98                 var count = (startEntities[j].Count !== undefined ? startEntities[j].Count : 1);
99                 for (var numberofentities = 0; numberofentities < count; numberofentities++)
100                 {
101                         var ux = playerX[i] + uDist * cos(uAngle) + numberofentities * uSpace * cos(uAngle + PI/2) - (0.75 * uSpace * floor(count / 2) * cos(uAngle + PI/2));
102                         var uz = playerZ[i] + uDist * sin(uAngle) + numberofentities * uSpace * sin(uAngle + PI/2) - (0.75 * uSpace * floor(count / 2) * sin(uAngle + PI/2));
103                         placeObject(ux, uz, startEntities[j].Template, i+1, uAngle);
104                 }
105         }
107         // Create treasure
108         var bbAngle = BUILDING_ORIENTATION;
109         var bbDist = 10;
110         var bbX = round(playerX[i] + bbDist * cos(bbAngle));
111         var bbZ = round(playerZ[i] + bbDist * sin(bbAngle));
112         var group = new SimpleGroup(
113                 [new SimpleObject(oFood, 5,5, 0,2)],
114                 true, clBaseResource, bbX, bbZ
115         );
116         createObjectGroup(group, 0);
118         bbAngle += PI/2;
119         var bbX = round(playerX[i] + bbDist * cos(bbAngle));
120         var bbZ = round(playerZ[i] + bbDist * sin(bbAngle));
121         group = new SimpleGroup(
122                 [new SimpleObject(oWood, 5,5, 0,2)],
123                 true, clBaseResource, bbX, bbZ
124         );
125         createObjectGroup(group, 0);
127         bbAngle += PI/2;
128         var bbX = round(playerX[i] + bbDist * cos(bbAngle));
129         var bbZ = round(playerZ[i] + bbDist * sin(bbAngle));
130         group = new SimpleGroup(
131                 [new SimpleObject(oMetal, 3,3, 0,2)],
132                 true, clBaseResource, bbX, bbZ
133         );
134         createObjectGroup(group, 0);
136         bbAngle += PI/2;
137         var bbX = round(playerX[i] + bbDist * cos(bbAngle));
138         var bbZ = round(playerZ[i] + bbDist * sin(bbAngle));
139         group = new SimpleGroup(
140                 [new SimpleObject(oStone, 2,2, 0,2)],
141                 true, clBaseResource, bbX, bbZ
142         );
143         createObjectGroup(group, 0);
145         // Base texture
146         var civ = getCivCode(i);
147         var tilesSize = civ == "cart" ? 27 : 22;
149         const minBoundX = (playerX[i] > tilesSize ? playerX[i] - tilesSize : 0);
150         const minBoundY = (playerZ[i] > tilesSize ? playerZ[i] - tilesSize : 0);
151         const maxBoundX = (playerX[i] < mapSize - tilesSize ? playerX[i] + tilesSize : mapSize);
152         const maxBoundY = (playerZ[i] < mapSize - tilesSize ? playerZ[i] + tilesSize : mapSize);
154         for (var tx = minBoundX; tx < maxBoundX; ++tx)
155                 for (var ty = minBoundY; ty < maxBoundY; ++ty)
156                 {
157                         var unboundSumOfXY = tx + ty - minBoundX - minBoundY;
158                         if ((unboundSumOfXY > tilesSize) && (unboundSumOfXY < 3 * tilesSize) && (tx - ty + minBoundY - minBoundX < tilesSize) && (ty - tx - minBoundY + minBoundX < tilesSize))
159                         {
160                                 placeTerrain(floor(tx), floor(ty), tRoad);
161                                 addToClass(floor(tx), floor(ty), clPlayer);
162                         }
163                 }
165         // Place custom fortress
166         if (civ == "brit" || civ == "gaul" || civ == "iber")
167         {
168                 var wall = ["gate", "tower", "wallLong",
169                         "cornerIn", "wallLong", "barracks", "tower", "wallLong", "tower", "house", "wallLong",
170                         "cornerIn", "wallLong", "house", "tower", "gate", "tower", "house", "wallLong",
171                         "cornerIn", "wallLong", "house", "tower", "wallLong", "tower", "house", "wallLong",
172                         "cornerIn", "wallLong", "house", "tower"];
173         }
174         else
175         {
176                 var wall = ["gate", "tower", "wallLong",
177                         "cornerIn", "wallLong", "barracks", "tower", "wallLong", "tower", "wallLong",
178                         "cornerIn", "wallLong", "house", "tower", "gate", "tower", "wallLong",
179                         "cornerIn", "wallLong", "house", "tower", "wallLong", "tower", "wallLong",
180                         "cornerIn", "wallLong", "house", "tower"];
181         }
182         placeCustomFortress(playerX[i], playerZ[i], new Fortress("Spahbod", wall), civ, i+1);
185 log("Creating lakes...");
186 var numLakes = round(scaleByMapSize(1,4) * numPlayers);
187 var placer = new ClumpPlacer(scaleByMapSize(100,250), 0.8, 0.1, 10);
188 var terrainPainter = new LayeredPainter(
189         [tShore, tWater, tWater],               // terrains
190         [1,1]                                                   // widths
192 var elevationPainter = new SmoothElevationPainter(ELEVATION_SET, -4, 3);
193 var waterAreas = createAreas(
194         placer,
195         [terrainPainter, elevationPainter, paintClass(clWater)],
196         avoidClasses(clPlayer, 7, clWater, 20),
197         numLakes
199 RMS.SetProgress(15);
201 log("Creating reeds...");
202 group = new SimpleGroup(
203         [new SimpleObject(aReeds, 5,10, 0,4), new SimpleObject(aLillies, 0,1, 0,4)], true
205 createObjectGroupsByAreas(group, 0,
206         [borderClasses(clWater, 3, 0), stayClasses(clWater, 1)],
207         numLakes, 100,
208         waterAreas
210 RMS.SetProgress(25);
212 log("Creating fish...");
213 createObjectGroupsByAreas(
214         new SimpleGroup(
215                 [new SimpleObject(oFish, 1,1, 0,1)],
216                 true, clFood
217         ),
218         0,
219         [stayClasses(clWater, 4),  avoidClasses(clFood, 8)],
220         numLakes / 4,
221         50,
222         waterAreas
224 RMS.SetProgress(30);
226 createBumps(avoidClasses(clWater, 2, clPlayer, 5));
227 RMS.SetProgress(35);
229 log("Creating hills...");
230 createHills([tCliff, tCliff, tHill], avoidClasses(clPlayer, 5, clWater, 5, clHill, 15), clHill, scaleByMapSize(1, 4) * numPlayers);
231 RMS.SetProgress(40);
233 // calculate desired number of trees for map (based on size)
234 const MIN_TREES = 500;
235 const MAX_TREES = 2500;
236 const P_FOREST = 0.7;
238 var totalTrees = scaleByMapSize(MIN_TREES, MAX_TREES);
239 var numForest = totalTrees * P_FOREST;
240 g_numStragglerTrees = totalTrees * (1.0 - P_FOREST);
242 log("Creating forests...");
243 var types = [
244         [[tForestFloor, tGrass, pForestD], [tForestFloor, pForestD]],
245         [[tForestFloor, tGrass, pForestO], [tForestFloor, pForestO]],
246         [[tForestFloor, tGrass, pForestP], [tForestFloor, pForestP]]
247 ];      // some variation
248 var size = numForest / (scaleByMapSize(3,6) * numPlayers);
249 var num = floor(size / types.length);
250 for (var i = 0; i < types.length; ++i)
252         placer = new ChainPlacer(1, floor(scaleByMapSize(3, 5)), numForest / num, 0.5);
253         var painter = new LayeredPainter(
254                 types[i],               // terrains
255                 [2]                                                                                     // widths
256                 );
257         createAreas(
258                 placer,
259                 [painter, paintClass(clForest)],
260                 avoidClasses(clPlayer, 5, clWater, 3, clForest, 15, clHill, 1),
261                 num
262         );
264 RMS.SetProgress(50);
266 log("Creating dirt patches...");
267 createLayeredPatches(
268  [scaleByMapSize(3, 6), scaleByMapSize(5, 10), scaleByMapSize(8, 21)],
269  [[tGrass,tGrassA],[tGrassA,tGrassB], [tGrassB,tGrassC]],
270  [1,1],
271  avoidClasses(clWater, 1, clForest, 0, clHill, 0, clDirt, 5, clPlayer, 1)
273 RMS.SetProgress(55);
275 log("Creating grass patches...");
276 createPatches(
277  [scaleByMapSize(2, 4), scaleByMapSize(3, 7), scaleByMapSize(5, 15)],
278  tGrassPatch,
279  avoidClasses(clWater, 1, clForest, 0, clHill, 0, clDirt, 5, clPlayer, 1)
281 RMS.SetProgress(60);
283 log("Creating stone mines...");
284 createMines(
286   [new SimpleObject(oStoneSmall, 0,2, 0,4), new SimpleObject(oStoneLarge, 1,1, 0,4)],
287   [new SimpleObject(oStoneSmall, 2,5, 1,3)]
288  ],
289  avoidClasses(clWater, 0, clForest, 1, clPlayer, 5, clRock, 10, clHill, 1)
291 RMS.SetProgress(65);
293 log("Creating metal mines...");
294 createMines(
296   [new SimpleObject(oMetalLarge, 1,1, 0,4)]
297  ],
298  avoidClasses(clWater, 0, clForest, 1, clPlayer, 5, clMetal, 10, clRock, 5, clHill, 1),
299  clMetal
301 RMS.SetProgress(70);
303 createDecoration
305  [[new SimpleObject(aRockMedium, 1,3, 0,1)],
306   [new SimpleObject(aRockLarge, 1,2, 0,1), new SimpleObject(aRockMedium, 1,3, 0,2)],
307   [new SimpleObject(aGrassShort, 1,2, 0,1, -PI/8,PI/8)],
308   [new SimpleObject(aGrass, 2,4, 0,1.8, -PI/8,PI/8), new SimpleObject(aGrassShort, 3,6, 1.2,2.5, -PI/8,PI/8)],
309   [new SimpleObject(aBushMedium, 1,2, 0,2), new SimpleObject(aBushSmall, 2,4, 0,2)]
310  ],
312   scaleByMapSize(16, 262),
313   scaleByMapSize(8, 131),
314   scaleByMapSize(13, 200),
315   scaleByMapSize(13, 200),
316   scaleByMapSize(13, 200)
317  ],
318  avoidClasses(clWater, 0, clForest, 0, clPlayer, 1, clHill, 0)
320 RMS.SetProgress(80);
322 // create animals
323 createFood
326   [new SimpleObject(oSheep, 2,3, 0,2)],
327   [new SimpleObject(oDeer, 5,7, 0,4)]
328  ],
330   3 * numPlayers,
331   3 * numPlayers
332  ],
333  avoidClasses(clWater, 0, clForest, 0, clPlayer, 6, clHill, 1, clFood, 20)
335 RMS.SetProgress(85);
337 // create fruits
338 createFood
341   [new SimpleObject(oBerryBush, 5,7, 0,4)]
342  ],
344   randInt(1, 4) * numPlayers + 2
345  ],
346  avoidClasses(clWater, 2, clForest, 0, clPlayer, 6, clHill, 1, clFood, 10)
349 RMS.SetProgress(90);
351 log("Creating straggler trees...");
352 var types = [oOak, oBeech, oPine];      // some variation
353 createStragglerTrees(types, avoidClasses(clWater, 1, clForest, 1, clHill, 1, clPlayer, 1, clMetal, 1, clRock, 1));
354 RMS.SetProgress(95);
356 setSkySet("sunny");
357 setWaterColor(0.157, 0.149, 0.443);
358 setWaterTint(0.443,0.42,0.824);
359 setWaterWaviness(2.0);
360 setWaterType("lake");
361 setWaterMurkiness(0.83);
363 setFogFactor(0.35);
364 setFogThickness(0.22);
365 setFogColor(0.82,0.82, 0.73);
366 setPPSaturation(0.56);
367 setPPContrast(0.56);
368 setPPBloom(0.38);
369 setPPEffect("hdr");
371 ExportMap();