Ticket #4354: island_tropics.js

File island_tropics.js, 14.4 KB (added by FeXoR, 7 years ago)

Fixed version of island_tropics.js

Line 
1RMS.LoadLibrary("rmgen");
2
3// terrain textures
4const tOceanDepths = "tropic_ocean_depths";
5const tOceanRockDeep = "medit_sea_coral_deep";
6const tOceanRockShallow = "medit_rocks_wet";
7const tOceanCoral = "tropic_ocean_coral";
8const tBeachWet = "tropic_beach_wet";
9const tBeachDry = "tropic_beach_dry";
10const tBeachGrass = "medit_rocks_grass";
11const tBeach = ["medit_rocks_grass","tropic_beach_dry_plants", "tropic_dirt_a_plants"]
12const tBeachBlend = ["tropic_grass_c", "tropic_dirt_b_plants"];
13const tBeachCliff = "tropics_cliff_a";
14const tCity = "tropic_citytile_a";
15const tGrass = ["tropic_grass_c", "tropic_grass_plants", "tropic_dirt_b_plants"];
16const tGrassLush = ["tropic_plants", "tropic_plants_b"];
17const tGrassPlants = "tropic_grass_plants";
18const tCliffShrubs = ["tropic_cliff_a_plants", "tropic_cliff_grass","tropic_cliff_b"]
19const tDirt = "tropic_dirt_a";
20const tDirtGrass = "tropic_dirt_b_plants";
21const tDirtCliff = "tropic_cliff_a";
22const tGrassCliff = "tropic_cliff_grass";
23const tCliff = ["tropic_cliff_a", "tropic_cliff_a_plants", "tropic_cliff_grass"];
24const tForestFloor = "tropic_forestfloor_a";
25
26// gaia entities
27const oTree1 = "gaia/flora_tree_palm_tropic";
28const oBerryBush = "gaia/flora_bush_berry";
29const oTree2 = "gaia/flora_tree_palm_tropical";
30const oTree3 = "gaia/flora_tree_toona";
31const oChicken = "gaia/fauna_chicken";
32const oDeer = "gaia/fauna_deer";
33const oBoar = "gaia/fauna_boar";
34const oFish = "gaia/fauna_fish";
35const oWhale = "gaia/fauna_whale_humpback";
36const oStoneLarge = "gaia/geology_stonemine_tropic_quarry";
37const oStoneSmall = "gaia/geology_stone_tropic_a";
38const oMetalLarge = "gaia/geology_metal_tropic_slabs";
39
40// decorative props
41const aBush1 = "actor|props/flora/bush_tropic_a.xml";
42const aBush2 = "actor|props/flora/bush_tropic_b.xml";
43const aFerns = "actor|props/flora/bush_ferns.xml";
44const aGrass = "actor|props/flora/grass_soft_large_tall.xml";
45const aGrassDry = "actor|props/flora/grass_soft_dry_large_tall.xml";
46const aRockLarge = "actor|geology/stone_granite_large.xml";
47const aRockMed = "actor|geology/stone_granite_med.xml";
48const aRockSmall = "actor|geology/stone_granite_small.xml";
49
50
51// terrain + entity (for painting)
52const pForest1 = [tForestFloor+TERRAIN_SEPARATOR+oTree1, tGrass];
53const pForest2 = [tForestFloor+TERRAIN_SEPARATOR+oTree2, tGrass];
54const pForest3 = [tForestFloor+TERRAIN_SEPARATOR+oTree3, tGrass];
55const pForest4 = [tForestFloor, tForestFloor + TERRAIN_SEPARATOR + oTree1, tGrass, tForestFloor + TERRAIN_SEPARATOR + oTree2, tGrass, tForestFloor + TERRAIN_SEPARATOR + oTree3, tGrass];
56
57// initialize map
58
59log("Initializing map...");
60
61InitMap();
62
63const numPlayers = getNumPlayers();
64const mapSize = getMapSize();
65
66// create tile classes
67
68var clCoral = createTileClass();
69var clPlayer = createTileClass();
70var clIsland = createTileClass();
71var clCity = createTileClass();
72var clDirt = createTileClass();
73var clHill = createTileClass();
74var clForest = createTileClass();
75var clWater = createTileClass();
76var clRock = createTileClass();
77var clMetal = createTileClass();
78var clFood = createTileClass();
79var clBaseResource = createTileClass();
80
81// randomize player order
82var playerIDs = [];
83for (var i = 0; i < numPlayers; i++)
84{
85 playerIDs.push(i+1);
86}
87playerIDs = sortPlayers(playerIDs);
88
89//array holding starting islands based on number of players
90var startingPlaces=[[0],[0,3],[0,2,4],[0,1,3,4],[0,1,2,3,4],[0,1,2,3,4,5]];
91
92//figure out how many spoke islands
93var numIslands =6;
94if(numPlayers<6){
95 numIslands=6;
96}else{
97 numIslands=numPlayers;
98}
99
100//figure out coordinates of spoke islands
101var islandX = new Array(numIslands);
102var islandZ = new Array(numIslands);
103var islandAngle = new Array(numIslands);
104//holds all land areas
105var areas = [];
106
107var startAngle = randFloat() * 2 * PI;
108for (var i=0; i < numIslands; i++)
109{
110 islandAngle[i] = startAngle + i*2*PI/numIslands;
111 islandX[i] = 0.5 + 0.39*cos(islandAngle[i]);
112 islandZ[i] = 0.5 + 0.39*sin(islandAngle[i]);
113}
114
115
116for(var i=0;i<numIslands;i++){
117 var radius = scaleByMapSize(15,40);
118 var coral=scaleByMapSize(1,5);
119 var wet = 3;
120 var dry = 1;
121 var gbeach = 2;
122 var elevation = 3;
123
124 // get the x and z in tiles
125 var fx = fractionToTiles(islandX[i]);
126 var fz = fractionToTiles(islandZ[i]);
127 var ix = round(fx);
128 var iz = round(fz);
129
130 var islandSize = PI*radius*radius;
131 var islandBottom=PI*(radius+coral)*(radius+coral);
132
133 //create base
134 var placer = new ClumpPlacer(islandBottom, .7, .1, 10, ix, iz);
135 var terrainPainter = new LayeredPainter(
136 [tOceanRockDeep, tOceanCoral],
137 [5]
138 );
139 createArea(placer, [terrainPainter, paintClass(clCoral)],avoidClasses(clCoral,0));
140}
141
142
143//create spoke islands
144//put down base resources and animals but do not populate
145for (var i=0; i < numIslands; i++)
146{
147 log("Creating base Island " + (i + 1) + "...");
148
149 var radius = scaleByMapSize(15,40);
150 var coral=scaleByMapSize(2,5);
151 var wet = 3;
152 var dry = 1;
153 var gbeach = 2;
154 var elevation = 3;
155
156 // get the x and z in tiles
157 var fx = fractionToTiles(islandX[i]);
158 var fz = fractionToTiles(islandZ[i]);
159 var ix = round(fx);
160 var iz = round(fz);
161
162 var islandSize = PI*radius*radius;
163 var islandBottom=PI*(radius+coral)*(radius+coral);
164
165 // create island
166 var placer = new ClumpPlacer(islandSize, .7, .1, 10, ix, iz);
167 var terrainPainter = new LayeredPainter(
168 [tOceanCoral,tBeachWet, tBeachDry, tBeach, tBeachBlend, tGrass],
169 [1,wet,dry,1,gbeach]
170 );
171 var elevationPainter = new SmoothElevationPainter(
172 ELEVATION_SET,
173 elevation,
174 5
175 );
176 var temp = createArea(placer, [terrainPainter, paintClass(clPlayer), elevationPainter],avoidClasses(clPlayer,0));
177
178 areas.push(temp);
179
180 // create animals
181 var group;
182 for (var j = 0; j < 2; ++j)
183 {
184 var aAngle = randFloat(0, TWO_PI);
185 var aDist = 7;
186 var aX = round(fx + aDist * cos(aAngle));
187 var aZ = round(fz + aDist * sin(aAngle));
188 group = new SimpleGroup(
189 [new SimpleObject(oChicken, 5,5, 0,2)],
190 true, clBaseResource, aX, aZ
191 );
192 createObjectGroup(group, 0);
193 }
194
195 // create berry bushes
196 var bbAngle = randFloat(0, TWO_PI);
197 var bbDist = 10;
198 var bbX = round(fx + bbDist * cos(bbAngle));
199 var bbZ = round(fz + bbDist * sin(bbAngle));
200 group = new SimpleGroup(
201 [new SimpleObject(oBerryBush, 5,5, 0,3)],
202 true, clBaseResource, bbX, bbZ
203 );
204 createObjectGroup(group, 0);
205
206 // create metal mine
207 var mAngle = bbAngle;
208 while(abs(mAngle - bbAngle) < PI/3)
209 {
210 mAngle = randFloat(0, TWO_PI);
211 }
212 var mDist = 12;
213 var mX = round(fx + mDist * cos(mAngle));
214 var mZ = round(fz + mDist * sin(mAngle));
215 group = new SimpleGroup(
216 [new SimpleObject(oMetalLarge, 1,1, 0,0)],
217 true, clBaseResource, mX, mZ
218 );
219 createObjectGroup(group, 0);
220
221 // create stone mines
222 mAngle += randFloat(PI/8, PI/4);
223 mX = round(fx + mDist * cos(mAngle));
224 mZ = round(fz + mDist * sin(mAngle));
225 group = new SimpleGroup(
226 [new SimpleObject(oStoneLarge, 1,1, 0,2)],
227 true, clBaseResource, mX, mZ
228 );
229 createObjectGroup(group, 0);
230 var hillSize = PI * radius * radius;
231 // create starting trees
232 var num = 2;
233 var tAngle = randFloat(-PI/3, 4*PI/3);
234 var tDist = randFloat(12, 13);
235 var tX = round(fx + tDist * cos(tAngle));
236 var tZ = round(fz + tDist * sin(tAngle));
237 group = new SimpleGroup(
238 [new SimpleObject(oTree1, num, num, 0,3)],
239 false, clBaseResource, tX, tZ
240 );
241 createObjectGroup(group, 0, avoidClasses(clBaseResource,2));
242}
243
244
245//Populate the islands with the players
246log("Populating islands ...");
247
248//nPlayer is the player we are on i is the island we are on
249var nPlayer=0;
250for(var i=0;i<numIslands;i++)
251{
252if((numPlayers>=6)||(i==startingPlaces[numPlayers-1][nPlayer])){
253
254 var id = playerIDs[nPlayer];
255
256 // get the x and z in tiles
257 var fx = fractionToTiles(islandX[i]);
258 var fz = fractionToTiles(islandZ[i]);
259 var ix = round(fx);
260 var iz = round(fz);
261
262 //create city patch
263 var cityRadius = 6;
264 var placer = new ClumpPlacer(PI*cityRadius*cityRadius, 0.6, 0.3, 10, ix, iz);
265 var painter = new LayeredPainter([tGrass, tCity], [1]);
266 createArea(placer, [painter,paintClass(clCity)], null);
267
268 // create starting units
269 placeCivDefaultEntities(fx, fz, id, {'iberWall' : 'towers'});
270
271 nPlayer++;
272}
273}
274
275
276RMS.SetProgress(15);
277
278
279// get the x and z in tiles
280
281var nCenter=floor(scaleByMapSize(1,4))
282var startAngle = randFloat() * 2 * PI;
283for (var i=0; i < nCenter; i++)
284{
285 var fx=.5;
286 var fz=.5;
287 if(nCenter==1){
288 fx=.5;
289 fz=.5;
290 }else{
291 var isangle = startAngle + i*2*PI/nCenter+randFloat(-PI/8,PI/8);
292 var dRadius = randFloat(.1,.16);
293 fx = 0.5 + dRadius*cos(isangle);
294 fz = 0.5 + dRadius*sin(isangle);
295 }
296 var ix = round(fractionToTiles(fx));
297 var iz = round(fractionToTiles(fz));
298
299 var radius = scaleByMapSize(15,30);
300 var coral= 2;
301 var wet = 3;
302 var dry = 1;
303 var gbeach = 2;
304 var elevation = 3;
305
306 var islandSize = PI*radius*radius;
307 var islandBottom=PI*(radius+coral)*(radius+coral);
308
309 //create base
310 var placer = new ClumpPlacer(islandBottom, .7, .1, 10, ix, iz);
311 var terrainPainter = new LayeredPainter(
312 [tOceanRockDeep, tOceanCoral],
313 [5]
314 );
315 createArea(placer, [terrainPainter, paintClass(clCoral)],avoidClasses(clCoral,0,clPlayer,0));
316
317 // create island
318 var placer = new ClumpPlacer(islandSize, .7, .1, 10, ix, iz);
319 var terrainPainter = new LayeredPainter(
320 [tOceanCoral,tBeachWet, tBeachDry, tBeach, tBeachBlend, tGrass],
321 [1,wet,dry,1,gbeach]
322 );
323 var elevationPainter = new SmoothElevationPainter(
324 ELEVATION_SET,
325 elevation,
326 5
327 );
328 var temp = createArea(placer, [terrainPainter, paintClass(clIsland), elevationPainter],avoidClasses(clPlayer,0));
329
330 areas.push(temp);
331}
332RMS.SetProgress(30);
333
334// create bumps
335log("Creating bumps...");
336placer = new ClumpPlacer(scaleByMapSize(20, 60), 0.3, 0.06, 1);
337painter = new SmoothElevationPainter(ELEVATION_MODIFY, 2, 3);
338createAreasInAreas(
339 placer,
340 painter,
341 avoidClasses(clCity, 0),
342 scaleByMapSize(25, 75),15,
343 areas
344);
345
346
347RMS.SetProgress(40);
348//find all water
349for (var ix = 0; ix < mapSize; ix++)
350{
351 for (var iz = 0; iz < mapSize; iz++)
352 {
353 if(getHeight(ix,iz)<0){
354 addToClass(ix,iz,clWater);
355 }
356 }
357}
358
359// create forests
360log("Creating forests...");
361var types = [
362 [[tForestFloor, tGrass, pForest1], [tForestFloor, pForest1]],
363 [[tForestFloor, tGrass, pForest2], [tForestFloor, pForest2]],
364 [[tForestFloor, tGrass, pForest3], [tForestFloor, pForest3]],
365 [[tForestFloor, tGrass, pForest4], [tForestFloor, pForest4]]
366]; // some variation
367var size = 5; //size
368var num = scaleByMapSize(10, 64); //number
369for (var i = 0; i < types.length; ++i)
370{
371 placer = new ClumpPlacer(6+randInt(12), 0.1, 0.1, 1);
372 painter = new LayeredPainter(
373 types[i], // terrains
374 [2] // widths
375 );
376 createAreasInAreas(
377 placer,
378 [painter, paintClass(clForest)],
379 avoidClasses(clCity, 1, clWater, 3, clForest, 3, clHill, 1),
380 num, 20, areas
381 );
382}
383
384RMS.SetProgress(60);
385
386log("Creating stone mines...");
387// create large stone quarries
388group = new SimpleGroup([new SimpleObject(oStoneSmall, 0,2, 0,4), new SimpleObject(oStoneLarge, 1,1, 0,4)], true, clRock);
389createObjectGroupsByAreas(group, 0,
390 [avoidClasses(clWater, 1, clForest, 1, clHill, 1, clPlayer, 5, clRock, 1)],
391 scaleByMapSize(4,16), 200, areas
392);
393
394// create small stone quarries
395group = new SimpleGroup([new SimpleObject(oStoneSmall, 2,5, 1,3)], true, clRock);
396createObjectGroupsByAreas(group, 0,
397 [avoidClasses(clWater, 1, clForest, 1, clHill, 1, clPlayer, 5, clRock, 2)],
398 scaleByMapSize(4,16), 200, areas
399);
400RMS.SetProgress(70);
401
402log("Creating metal mines...");
403// create large metal quarries
404group = new SimpleGroup([new SimpleObject(oMetalLarge, 1,1, 0,4)], true, clMetal);
405createObjectGroupsByAreas(group, 0,
406 [avoidClasses(clWater, 1, clForest, 1, clHill, 1, clPlayer, 5, clMetal, 2, clRock, 1)],
407 scaleByMapSize(4,16), 200, areas
408);
409
410RMS.SetProgress(80);
411
412
413
414//create shrub patches
415log("Creating shrub patches...");
416var sizes = [scaleByMapSize(2, 32), scaleByMapSize(3, 48), scaleByMapSize(5, 80)];
417for (var i = 0; i < sizes.length; i++)
418{
419 placer = new ClumpPlacer(sizes[i], 0.3, 0.06, 0.5);
420 painter = new LayeredPainter([tBeachBlend,tGrassPlants],[1]);
421 createAreasInAreas(
422 placer,
423 [painter, paintClass(clDirt)],
424 avoidClasses(clWater, 3, clHill, 0, clDirt, 6, clCity, 0),
425 scaleByMapSize(4, 16), 20, areas
426 );
427}
428
429//create grass patches
430log("Creating grass patches...");
431var sizes = [scaleByMapSize(2, 32), scaleByMapSize(3, 48), scaleByMapSize(5, 80)];
432for (var i = 0; i < sizes.length; i++)
433{
434 placer = new ClumpPlacer(sizes[i], 0.3, 0.06, 0.5);
435 painter = new LayeredPainter([tGrassLush],[]);
436 createAreasInAreas(
437 placer,
438 [painter, paintClass(clDirt)],
439 avoidClasses(clWater, 3, clHill, 0, clDirt, 6, clCity, 0),
440 scaleByMapSize(4, 16), 20, areas
441 );
442}
443
444RMS.SetProgress(90);
445
446log("Creating straggler trees...");
447// create straggler trees
448var trees = [oTree1, oTree2];
449for (var t in trees)
450{
451 group = new SimpleGroup([new SimpleObject(trees[t], 1,1, 0,1)], true, clForest);
452 createObjectGroupsByAreas(group, 0,
453 avoidClasses(clWater, 2, clForest, 2, clCity, 3, clBaseResource, 1, clRock, 1, clMetal, 1, clPlayer, 1, clHill, 1),
454 scaleByMapSize(2, 38), 50, areas
455 );
456}
457
458
459
460log("Creating rocks...");
461// create rocks
462group = new SimpleGroup(
463 [new SimpleObject(aRockSmall, 0,3, 0,2), new SimpleObject(aRockMed, 0,2, 0,2),
464 new SimpleObject(aRockLarge, 0,1, 0,2)]
465);
466createObjectGroups(group, 0,
467 avoidClasses(clWater, 0, clCity, 0),
468 scaleByMapSize(30, 180), 50
469);
470
471// create deer
472log("Creating deer...");
473group = new SimpleGroup(
474 [new SimpleObject(oDeer, 5,7, 0,4)],
475 true, clFood
476);
477createObjectGroups(group, 0,
478 avoidClasses(clWater, 5, clForest, 1, clHill, 1, clCity, 10, clMetal, 2, clRock, 2, clFood, 8),
479 3 * numPlayers, 50
480);
481
482RMS.SetProgress(95);
483
484log("Creating berry bushes...");
485// create berry bushes
486group = new SimpleGroup([new SimpleObject(oBerryBush, 5,7, 0,3)], true, clFood);
487createObjectGroups(group, 0,
488 avoidClasses(clWater, 2, clForest, 1, clHill, 1, clCity, 10, clMetal, 2, clRock, 2, clFood, 8),
489 1.5 * numPlayers, 100
490);
491
492log("Creating Fish...");
493// create Fish
494group = new SimpleGroup([new SimpleObject(oFish, 1,1, 0,3)], true, clFood);
495createObjectGroups(group, 0,
496 [stayClasses(clWater,1),avoidClasses(clFood, 8)],
497 scaleByMapSize(40,200), 100
498);
499
500log("Creating Whales...");
501// create Whales
502group = new SimpleGroup([new SimpleObject(oWhale, 1,1, 0,3)], true, clFood);
503createObjectGroups(group, 0,
504 [stayClasses(clWater,1),avoidClasses(clFood, 8, clPlayer,4,clIsland,4)],
505 scaleByMapSize(10,40), 100
506);
507
508// Adjust environment
509setSkySet("sunny");
510setWaterColor(0.2,0.294,0.49);
511setWaterTint(0.208, 0.659, 0.925);
512setWaterMurkiness(0.72);
513setWaterWaviness(3.0);
514setWaterType("ocean");
515
516// Export map data
517ExportMap();