Line data Source code
1 : import { addElements, allAmounts, allMixes, allSizes } from "maps/random/rmgen2/setup.js";
2 :
3 0 : var g_Props = {
4 : "barrels": "actor|props/special/eyecandy/barrels_buried.xml",
5 : "crate": "actor|props/special/eyecandy/crate_a.xml",
6 : "cart": "actor|props/special/eyecandy/handcart_1_broken.xml",
7 : "well": "actor|props/special/eyecandy/well_1_c.xml",
8 : "skeleton": "actor|props/special/eyecandy/skeleton.xml",
9 : };
10 :
11 : /**
12 : * Prevent circular patterns around the CC by marking a random chain of circles there to be ignored by bluffs.
13 : */
14 : export function markPlayerAvoidanceArea(playerPosition, radius)
15 : {
16 0 : for (const position of playerPosition)
17 0 : createArea(
18 : new ChainPlacer(3, 6, scaleByMapSize(25, 60), Infinity, position, radius),
19 : new TileClassPainter(g_TileClasses.bluffIgnore),
20 : undefined,
21 : scaleByMapSize(7, 14));
22 :
23 0 : createArea(
24 : new MapBoundsPlacer(),
25 : new TileClassPainter(g_TileClasses.bluffIgnore),
26 : new NearTileClassConstraint(g_TileClasses.baseResource, 5));
27 : }
28 :
29 : /**
30 : * Paints a ramp from the given positions to t
31 : * Bluffs might surround playerbases either entirely or unfairly.
32 : */
33 : export function createBluffsPassages(playerPosition)
34 : {
35 0 : g_Map.log("Creating passages towards the center");
36 0 : for (const position of playerPosition)
37 : {
38 0 : const successful = true;
39 0 : for (let tryCount = 0; tryCount < 80; ++tryCount)
40 : {
41 0 : const angle = position.angleTo(g_Map.getCenter()) + randFloat(-1, 1) * Math.PI / 2;
42 0 : const start = Vector2D.add(position, new Vector2D(defaultPlayerBaseRadius() * 0.7, 0).rotate(angle).perpendicular()).round();
43 0 : const end = Vector2D.add(position, new Vector2D(defaultPlayerBaseRadius() * randFloat(1.7, 2), 0).rotate(angle).perpendicular()).round();
44 :
45 0 : if (g_TileClasses.forest.has(end) || !stayClasses(g_TileClasses.bluff, 12).allows(end))
46 0 : continue;
47 :
48 0 : if ((g_Map.getHeight(end.clone().floor()) - g_Map.getHeight(start.clone().floor())) / start.distanceTo(end) > 1.5)
49 0 : continue;
50 :
51 0 : const area = createPassage({
52 : "start": start,
53 : "end": end,
54 : "startWidth": scaleByMapSize(10, 20),
55 : "endWidth": scaleByMapSize(10, 14),
56 : "smoothWidth": 3,
57 : "terrain": g_Terrains.mainTerrain,
58 : "tileClass": g_TileClasses.bluffsPassage
59 : });
60 :
61 0 : for (const point of area.getPoints())
62 0 : g_Map.deleteTerrainEntity(point);
63 :
64 0 : createArea(
65 : new MapBoundsPlacer(),
66 : new TerrainPainter(g_Terrains.cliff),
67 : [
68 : new StayAreasConstraint([area]),
69 : new SlopeConstraint(2, Infinity)
70 : ]);
71 :
72 0 : break;
73 : }
74 : }
75 : }
76 :
77 : /**
78 : * Create bluffs, i.e. a slope hill reachable from ground level.
79 : * Fill it with wood, mines, animals and decoratives.
80 : *
81 : * @param {Array} constraint - where to place them
82 : * @param {number} size - size of the bluffs (1.2 would be 120% of normal)
83 : * @param {number} deviation - degree of deviation from the defined size (0.2 would be 20% plus/minus)
84 : * @param {number} fill - size of map to fill (1.5 would be 150% of normal)
85 : * @param {number} baseHeight - elevation of the floor, making the bluff reachable
86 : */
87 : export function addBluffs(constraint, size, deviation, fill, baseHeight)
88 : {
89 0 : g_Map.log("Creating bluffs");
90 :
91 0 : const elevation = 30;
92 :
93 : // Percent of the length of the bluff determining the entrance area
94 0 : const margin = 0.08;
95 :
96 0 : let constrastTerrain = g_Terrains.tier2Terrain;
97 :
98 0 : if (currentBiome() == "generic/india")
99 0 : constrastTerrain = g_Terrains.dirt;
100 :
101 0 : if (currentBiome() == "generic/autumn")
102 0 : constrastTerrain = g_Terrains.tier3Terrain;
103 :
104 0 : for (let i = 0; i < fill * 15; ++i)
105 : {
106 0 : const bluffDeviation = getRandomDeviation(size, deviation);
107 :
108 : // Pick a random bluff location and shape
109 0 : const areasBluff = createAreas(
110 : new ChainPlacer(5 * bluffDeviation, 7 * bluffDeviation, 100 * bluffDeviation, 0.5),
111 : undefined,
112 : constraint,
113 : 1);
114 :
115 0 : if (!areasBluff.length || !areasBluff[0].getPoints().length)
116 0 : continue;
117 :
118 : // Get a random starting position for the baseline and the endline
119 0 : let angle = randIntInclusive(0, 3);
120 0 : let opposingAngle = (angle + 2) % 4;
121 :
122 : // Find the edges of the bluff
123 : let baseLine;
124 : let endLine;
125 :
126 : // If we can't access the bluff, try different angles
127 0 : let retries = 0;
128 0 : let bluffPassable = false;
129 0 : while (!bluffPassable && retries++ < 4)
130 : {
131 0 : baseLine = findClearLine(areasBluff[0], angle);
132 0 : endLine = findClearLine(areasBluff[0], opposingAngle);
133 0 : bluffPassable = isBluffPassable(areasBluff[0], baseLine, endLine);
134 :
135 0 : angle = (angle + 1) % 4;
136 0 : opposingAngle = (angle + 2) % 4;
137 : }
138 :
139 0 : if (!bluffPassable)
140 0 : continue;
141 :
142 : // Paint bluff texture and elevation
143 0 : createArea(
144 : new MapBoundsPlacer(),
145 : [
146 : new LayeredPainter([g_Terrains.mainTerrain, constrastTerrain], [5]),
147 : new SmoothElevationPainter(ELEVATION_MODIFY, elevation * bluffDeviation, 2),
148 : new TileClassPainter(g_TileClasses.bluff)
149 : ],
150 : new StayAreasConstraint(areasBluff));
151 :
152 0 : const slopeLength = (1 - margin) * Vector2D.average([baseLine.start, baseLine.end]).distanceTo(Vector2D.average([endLine.start, endLine.end]));
153 :
154 : // Adjust the height of each point in the bluff
155 0 : for (const point of areasBluff[0].getPoints())
156 : {
157 0 : const dist = Math.abs(distanceOfPointFromLine(baseLine.start, baseLine.end, point));
158 0 : g_Map.setHeight(point, Math.max(g_Map.getHeight(point) * (1 - dist / slopeLength) - 2, baseHeight));
159 : }
160 :
161 : // Flatten all points adjacent to but not on the bluff
162 0 : createArea(
163 : new MapBoundsPlacer(),
164 : [
165 : new SmoothingPainter(1, 1, 1),
166 : new TerrainPainter(g_Terrains.mainTerrain)
167 : ],
168 : new AdjacentToAreaConstraint(areasBluff));
169 :
170 : // Paint cliffs
171 0 : createArea(
172 : new MapBoundsPlacer(),
173 : new TerrainPainter(g_Terrains.cliff),
174 : [
175 : new StayAreasConstraint(areasBluff),
176 : new SlopeConstraint(2, Infinity)
177 : ]);
178 :
179 : // Performance improvement
180 0 : createArea(
181 : new MapBoundsPlacer(),
182 : new TileClassPainter(g_TileClasses.bluffIgnore),
183 : new NearTileClassConstraint(g_TileClasses.bluff, 8));
184 : }
185 :
186 0 : addElements([
187 : {
188 : "func": addHills,
189 : "avoid": [
190 : g_TileClasses.hill, 3,
191 : g_TileClasses.player, 20,
192 : g_TileClasses.valley, 2,
193 : g_TileClasses.water, 2
194 : ],
195 : "stay": [g_TileClasses.bluff, 3],
196 : "sizes": allSizes,
197 : "mixes": allMixes,
198 : "amounts": allAmounts
199 : }
200 : ]);
201 :
202 0 : addElements([
203 : {
204 : "func": addLayeredPatches,
205 : "avoid": [
206 : g_TileClasses.dirt, 5,
207 : g_TileClasses.forest, 2,
208 : g_TileClasses.mountain, 2,
209 : g_TileClasses.player, 12,
210 : g_TileClasses.water, 3
211 : ],
212 : "stay": [g_TileClasses.bluff, 5],
213 : "sizes": ["normal"],
214 : "mixes": ["normal"],
215 : "amounts": ["normal"]
216 : }
217 : ]);
218 :
219 0 : addElements([
220 : {
221 : "func": addDecoration,
222 : "avoid": [
223 : g_TileClasses.forest, 2,
224 : g_TileClasses.player, 12,
225 : g_TileClasses.water, 3
226 : ],
227 : "stay": [g_TileClasses.bluff, 5],
228 : "sizes": ["normal"],
229 : "mixes": ["normal"],
230 : "amounts": ["normal"]
231 : }
232 : ]);
233 :
234 0 : addElements([
235 : {
236 : "func": addProps,
237 : "avoid": [
238 : g_TileClasses.forest, 2,
239 : g_TileClasses.player, 12,
240 : g_TileClasses.prop, 40,
241 : g_TileClasses.water, 3
242 : ],
243 : "stay": [
244 : g_TileClasses.bluff, 7,
245 : g_TileClasses.mountain, 7
246 : ],
247 : "sizes": ["normal"],
248 : "mixes": ["normal"],
249 : "amounts": ["scarce"]
250 : }
251 : ]);
252 :
253 0 : addElements(shuffleArray([
254 : {
255 : "func": addForests,
256 : "avoid": [
257 : g_TileClasses.berries, 5,
258 : g_TileClasses.forest, 18,
259 : g_TileClasses.metal, 5,
260 : g_TileClasses.mountain, 5,
261 : g_TileClasses.player, 20,
262 : g_TileClasses.rock, 5,
263 : g_TileClasses.water, 2
264 : ],
265 : "stay": [g_TileClasses.bluff, 6],
266 : "sizes": allSizes,
267 : "mixes": allMixes,
268 : "amounts": ["normal", "many", "tons"]
269 : },
270 : {
271 : "func": addMetal,
272 : "avoid": [
273 : g_TileClasses.berries, 5,
274 : g_TileClasses.forest, 5,
275 : g_TileClasses.mountain, 2,
276 : g_TileClasses.player, 50,
277 : g_TileClasses.rock, 15,
278 : g_TileClasses.metal, 40,
279 : g_TileClasses.water, 3
280 : ],
281 : "stay": [g_TileClasses.bluff, 6],
282 : "sizes": ["normal"],
283 : "mixes": ["same"],
284 : "amounts": ["normal"]
285 : },
286 : {
287 : "func": addStone,
288 : "avoid": [
289 : g_TileClasses.berries, 5,
290 : g_TileClasses.forest, 5,
291 : g_TileClasses.mountain, 2,
292 : g_TileClasses.player, 50,
293 : g_TileClasses.rock, 40,
294 : g_TileClasses.metal, 15,
295 : g_TileClasses.water, 3
296 : ],
297 : "stay": [g_TileClasses.bluff, 6],
298 : "sizes": ["normal"],
299 : "mixes": ["same"],
300 : "amounts": ["normal"]
301 : }
302 : ]));
303 :
304 0 : const savanna = currentBiome() == "generic/savanna";
305 0 : addElements(shuffleArray([
306 : {
307 : "func": addStragglerTrees,
308 : "avoid": [
309 : g_TileClasses.berries, 5,
310 : g_TileClasses.forest, 10,
311 : g_TileClasses.metal, 5,
312 : g_TileClasses.mountain, 1,
313 : g_TileClasses.player, 12,
314 : g_TileClasses.rock, 5,
315 : g_TileClasses.water, 5
316 : ],
317 : "stay": [g_TileClasses.bluff, 6],
318 : "sizes": savanna ? ["big"] : allSizes,
319 : "mixes": savanna ? ["varied"] : allMixes,
320 : "amounts": savanna ? ["tons"] : ["normal", "many", "tons"]
321 : },
322 : {
323 : "func": addAnimals,
324 : "avoid": [
325 : g_TileClasses.animals, 20,
326 : g_TileClasses.forest, 5,
327 : g_TileClasses.mountain, 1,
328 : g_TileClasses.player, 20,
329 : g_TileClasses.rock, 5,
330 : g_TileClasses.metal, 5,
331 : g_TileClasses.water, 3
332 : ],
333 : "stay": [g_TileClasses.bluff, 6],
334 : "sizes": allSizes,
335 : "mixes": allMixes,
336 : "amounts": ["normal", "many", "tons"]
337 : },
338 : {
339 : "func": addBerries,
340 : "avoid": [
341 : g_TileClasses.berries, 50,
342 : g_TileClasses.forest, 5,
343 : g_TileClasses.metal, 10,
344 : g_TileClasses.mountain, 2,
345 : g_TileClasses.player, 20,
346 : g_TileClasses.rock, 10,
347 : g_TileClasses.water, 3
348 : ],
349 : "stay": [g_TileClasses.bluff, 6],
350 : "sizes": allSizes,
351 : "mixes": allMixes,
352 : "amounts": ["normal", "many", "tons"]
353 : }
354 : ]));
355 : }
356 :
357 : /**
358 : * Add grass, rocks and bushes.
359 : */
360 : export function addDecoration(constraint, size, deviation, fill)
361 : {
362 0 : g_Map.log("Creating decoration");
363 :
364 0 : const offset = getRandomDeviation(size, deviation);
365 0 : const decorations = [
366 : [
367 : new SimpleObject(g_Decoratives.rockMedium, offset, 3 * offset, 0, offset)
368 : ],
369 : [
370 : new SimpleObject(g_Decoratives.rockLarge, offset, 2 * offset, 0, offset),
371 : new SimpleObject(g_Decoratives.rockMedium, offset, 3 * offset, 0, 2 * offset)
372 : ],
373 : [
374 : new SimpleObject(g_Decoratives.grassShort, offset, 2 * offset, 0, offset)
375 : ],
376 : [
377 : new SimpleObject(g_Decoratives.grass, 2 * offset, 4 * offset, 0, 1.8 * offset),
378 : new SimpleObject(g_Decoratives.grassShort, 3 * offset, 6 * offset, 1.2 * offset, 2.5 * offset)
379 : ],
380 : [
381 : new SimpleObject(g_Decoratives.bushMedium, offset, 2 * offset, 0, 2 * offset),
382 : new SimpleObject(g_Decoratives.bushSmall, 2 * offset, 4 * offset, 0, 2 * offset)
383 : ]
384 : ];
385 :
386 0 : let baseCount = 1;
387 0 : if (currentBiome() == "generic/india")
388 0 : baseCount = 8;
389 :
390 0 : const counts = [
391 : scaleByMapSize(16, 262),
392 : scaleByMapSize(8, 131),
393 : baseCount * scaleByMapSize(13, 200),
394 : baseCount * scaleByMapSize(13, 200),
395 : baseCount * scaleByMapSize(13, 200)
396 : ];
397 :
398 0 : for (let i = 0; i < decorations.length; ++i)
399 : {
400 0 : const decorCount = Math.floor(counts[i] * fill);
401 0 : const group = new SimpleGroup(decorations[i], true);
402 0 : createObjectGroupsDeprecated(group, 0, constraint, decorCount, 5);
403 : }
404 : }
405 :
406 : /**
407 : * Create varying elevations.
408 : *
409 : * @param {Array} constraint - avoid/stay-classes
410 : *
411 : * @param {Object} el - the element to be rendered, for example:
412 : * "class": g_TileClasses.hill,
413 : * "painter": [g_Terrains.mainTerrain, g_Terrains.mainTerrain],
414 : * "size": 1,
415 : * "deviation": 0.2,
416 : * "fill": 1,
417 : * "count": scaleByMapSize(4, 8),
418 : * "minSize": Math.floor(scaleByMapSize(3, 8)),
419 : * "maxSize": Math.floor(scaleByMapSize(5, 10)),
420 : * "spread": Math.floor(scaleByMapSize(10, 20)),
421 : * "minElevation": 6,
422 : * "maxElevation": 12,
423 : * "steepness": 1.5
424 : */
425 :
426 : function addElevation(constraint, el)
427 : {
428 0 : const count = el.fill * el.count;
429 0 : const minSize = el.minSize;
430 0 : const maxSize = el.maxSize;
431 0 : const spread = el.spread;
432 :
433 0 : let elType = ELEVATION_MODIFY;
434 0 : if (el.class == g_TileClasses.water)
435 0 : elType = ELEVATION_SET;
436 :
437 0 : const widths = [];
438 :
439 : // Allow for shore and cliff rendering
440 0 : for (let s = el.painter.length; s > 2; --s)
441 0 : widths.push(1);
442 :
443 0 : for (let i = 0; i < count; ++i)
444 : {
445 0 : const elevation = randIntExclusive(el.minElevation, el.maxElevation);
446 0 : const smooth = Math.floor(elevation / el.steepness);
447 :
448 0 : const offset = getRandomDeviation(el.size, el.deviation);
449 0 : let pMaxSize = Math.floor(maxSize * offset);
450 0 : const pSpread = Math.floor(spread * offset);
451 0 : let pSmooth = Math.abs(Math.floor(smooth * offset));
452 0 : let pElevation = Math.floor(elevation * offset);
453 :
454 0 : pElevation = Math.max(el.minElevation, Math.min(pElevation, el.maxElevation));
455 0 : pMaxSize = Math.min(pMaxSize, el.maxSize);
456 0 : const pMinSize = Math.max(pMaxSize, el.minSize);
457 0 : pSmooth = Math.max(pSmooth, 1);
458 :
459 0 : createAreas(
460 : new ChainPlacer(pMinSize, pMaxSize, pSpread, 0.5),
461 : [
462 : new LayeredPainter(el.painter, [widths.concat(pSmooth)]),
463 : new SmoothElevationPainter(elType, pElevation, pSmooth),
464 : new TileClassPainter(el.class)
465 : ],
466 : constraint,
467 : 1);
468 : }
469 : }
470 :
471 : /**
472 : * Create rolling hills.
473 : */
474 : export function addHills(constraint, size, deviation, fill)
475 : {
476 0 : g_Map.log("Creating hills");
477 :
478 0 : addElevation(constraint, {
479 : "class": g_TileClasses.hill,
480 : "painter": [g_Terrains.mainTerrain, g_Terrains.mainTerrain],
481 : "size": size,
482 : "deviation": deviation,
483 : "fill": fill,
484 : "count": 8,
485 : "minSize": 5,
486 : "maxSize": 8,
487 : "spread": 20,
488 : "minElevation": 6,
489 : "maxElevation": 12,
490 : "steepness": 1.5
491 : });
492 :
493 0 : createArea(
494 : new MapBoundsPlacer(),
495 : new TileClassPainter(g_TileClasses.bluffIgnore),
496 : new NearTileClassConstraint(g_TileClasses.hill, 6));
497 : }
498 :
499 : /**
500 : * Create random lakes with fish in it.
501 : */
502 : export function addLakes(constraint, size, deviation, fill)
503 : {
504 0 : g_Map.log("Creating lakes");
505 :
506 0 : let lakeTile = g_Terrains.water;
507 :
508 0 : if (currentBiome() == "generic/temperate" || currentBiome() == "generic/india")
509 0 : lakeTile = g_Terrains.dirt;
510 :
511 0 : if (currentBiome() == "generic/aegean")
512 0 : lakeTile = g_Terrains.tier2Terrain;
513 :
514 0 : if (currentBiome() == "generic/autumn")
515 0 : lakeTile = g_Terrains.shore;
516 :
517 0 : addElevation(constraint, {
518 : "class": g_TileClasses.water,
519 : "painter": [lakeTile, lakeTile],
520 : "size": size,
521 : "deviation": deviation,
522 : "fill": fill,
523 : "count": 6,
524 : "minSize": 7,
525 : "maxSize": 9,
526 : "spread": 70,
527 : "minElevation": -15,
528 : "maxElevation": -2,
529 : "steepness": 1.5
530 : });
531 :
532 0 : addElements([
533 : {
534 : "func": addFish,
535 : "avoid": [
536 : g_TileClasses.fish, 12,
537 : g_TileClasses.hill, 8,
538 : g_TileClasses.mountain, 8,
539 : g_TileClasses.player, 8
540 : ],
541 : "stay": [g_TileClasses.water, 7],
542 : "sizes": allSizes,
543 : "mixes": allMixes,
544 : "amounts": ["normal", "many", "tons"]
545 : }
546 : ]);
547 :
548 0 : let group = new SimpleGroup([new SimpleObject(g_Decoratives.rockMedium, 1, 3, 1, 3)], true, g_TileClasses.dirt);
549 0 : createObjectGroupsDeprecated(group, 0, [stayClasses(g_TileClasses.water, 1), borderClasses(g_TileClasses.water, 4, 3)], 1000, 100);
550 :
551 0 : group = new SimpleGroup([new SimpleObject(g_Decoratives.reeds, 10, 15, 1, 3), new SimpleObject(g_Decoratives.rockMedium, 1, 3, 1, 3)], true, g_TileClasses.dirt);
552 0 : createObjectGroupsDeprecated(group, 0, [stayClasses(g_TileClasses.water, 2), borderClasses(g_TileClasses.water, 4, 3)], 1000, 100);
553 : }
554 :
555 : /**
556 : * Universal function to create layered patches.
557 : */
558 : export function addLayeredPatches(constraint, size, deviation, fill)
559 : {
560 0 : g_Map.log("Creating layered patches");
561 :
562 0 : const minRadius = 1;
563 0 : const maxRadius = Math.floor(scaleByMapSize(3, 5));
564 0 : const count = fill * scaleByMapSize(15, 45);
565 :
566 0 : const patchSizes = [
567 : scaleByMapSize(3, 6),
568 : scaleByMapSize(5, 10),
569 : scaleByMapSize(8, 21)
570 : ];
571 :
572 0 : for (const patchSize of patchSizes)
573 : {
574 0 : const offset = getRandomDeviation(size, deviation);
575 0 : const patchMinRadius = Math.floor(minRadius * offset);
576 0 : const patchMaxRadius = Math.floor(maxRadius * offset);
577 :
578 0 : createAreas(
579 : new ChainPlacer(Math.min(patchMinRadius, patchMaxRadius), patchMaxRadius, Math.floor(patchSize * offset), 0.5),
580 : [
581 : new LayeredPainter(
582 : [
583 : [g_Terrains.mainTerrain, g_Terrains.tier1Terrain],
584 : [g_Terrains.tier1Terrain, g_Terrains.tier2Terrain],
585 : [g_Terrains.tier2Terrain, g_Terrains.tier3Terrain],
586 : [g_Terrains.tier4Terrain]
587 : ],
588 : [1, 1]),
589 : new TileClassPainter(g_TileClasses.dirt)
590 : ],
591 : constraint,
592 : count * offset);
593 : }
594 : }
595 :
596 : /**
597 : * Create steep mountains.
598 : */
599 : export function addMountains(constraint, size, deviation, fill)
600 : {
601 0 : g_Map.log("Creating mountains");
602 :
603 0 : addElevation(constraint, {
604 : "class": g_TileClasses.mountain,
605 : "painter": [g_Terrains.cliff, g_Terrains.hill],
606 : "size": size,
607 : "deviation": deviation,
608 : "fill": fill,
609 : "count": 8,
610 : "minSize": 2,
611 : "maxSize": 4,
612 : "spread": 100,
613 : "minElevation": 100,
614 : "maxElevation": 120,
615 : "steepness": 4
616 : });
617 : }
618 :
619 : /**
620 : * Create plateaus.
621 : */
622 : export function addPlateaus(constraint, size, deviation, fill)
623 : {
624 0 : g_Map.log("Creating plateaus");
625 :
626 0 : let plateauTile = g_Terrains.dirt;
627 :
628 0 : if (currentBiome() == "generic/arctic")
629 0 : plateauTile = g_Terrains.tier1Terrain;
630 :
631 0 : if (currentBiome() == "generic/alpine" || currentBiome() == "generic/savanna")
632 0 : plateauTile = g_Terrains.tier2Terrain;
633 :
634 0 : if (currentBiome() == "generic/autumn")
635 0 : plateauTile = g_Terrains.tier4Terrain;
636 :
637 0 : addElevation(constraint, {
638 : "class": g_TileClasses.plateau,
639 : "painter": [g_Terrains.cliff, plateauTile],
640 : "size": size,
641 : "deviation": deviation,
642 : "fill": fill,
643 : "count": 15,
644 : "minSize": 2,
645 : "maxSize": 4,
646 : "spread": 200,
647 : "minElevation": 20,
648 : "maxElevation": 30,
649 : "steepness": 8
650 : });
651 :
652 0 : for (let i = 0; i < 40; ++i)
653 : {
654 0 : const hillElevation = randIntInclusive(4, 18);
655 0 : createAreas(
656 : new ChainPlacer(3, 15, 1, 0.5),
657 : [
658 : new LayeredPainter([plateauTile, plateauTile], [3]),
659 : new SmoothElevationPainter(ELEVATION_MODIFY, hillElevation, hillElevation - 2),
660 : new TileClassPainter(g_TileClasses.hill)
661 : ],
662 : [
663 : avoidClasses(g_TileClasses.hill, 7),
664 : stayClasses(g_TileClasses.plateau, 7)
665 : ],
666 : 1);
667 : }
668 :
669 0 : addElements([
670 : {
671 : "func": addDecoration,
672 : "avoid": [
673 : g_TileClasses.dirt, 15,
674 : g_TileClasses.forest, 2,
675 : g_TileClasses.player, 12,
676 : g_TileClasses.water, 3
677 : ],
678 : "stay": [g_TileClasses.plateau, 8],
679 : "sizes": ["normal"],
680 : "mixes": ["normal"],
681 : "amounts": ["tons"]
682 : },
683 : {
684 : "func": addProps,
685 : "avoid": [
686 : g_TileClasses.forest, 2,
687 : g_TileClasses.player, 12,
688 : g_TileClasses.prop, 40,
689 : g_TileClasses.water, 3
690 : ],
691 : "stay": [g_TileClasses.plateau, 8],
692 : "sizes": ["normal"],
693 : "mixes": ["normal"],
694 : "amounts": ["scarce"]
695 : }
696 : ]);
697 : }
698 :
699 : /**
700 : * Place less usual decoratives like barrels or crates.
701 : */
702 : export function addProps(constraint, size, deviation, fill)
703 : {
704 0 : g_Map.log("Creating rare actors");
705 :
706 0 : const offset = getRandomDeviation(size, deviation);
707 :
708 0 : const props = [
709 : [
710 : new SimpleObject(g_Props.skeleton, offset, 5 * offset, 0, 3 * offset + 2),
711 : ],
712 : [
713 : new SimpleObject(g_Props.barrels, offset, 2 * offset, 2, 3 * offset + 2),
714 : new SimpleObject(g_Props.cart, 0, offset, 5, 2.5 * offset + 5),
715 : new SimpleObject(g_Props.crate, offset, 2 * offset, 2, 2 * offset + 2),
716 : new SimpleObject(g_Props.well, 0, 1, 2, 2 * offset + 2)
717 : ]
718 : ];
719 :
720 0 : const baseCount = 1;
721 :
722 0 : const counts = [
723 : scaleByMapSize(16, 262),
724 : scaleByMapSize(8, 131),
725 : baseCount * scaleByMapSize(13, 200),
726 : baseCount * scaleByMapSize(13, 200),
727 : baseCount * scaleByMapSize(13, 200)
728 : ];
729 :
730 : // Add small props
731 0 : for (let i = 0; i < props.length; ++i)
732 : {
733 0 : const propCount = Math.floor(counts[i] * fill);
734 0 : const group = new SimpleGroup(props[i], true);
735 0 : createObjectGroupsDeprecated(group, 0, constraint, propCount, 5);
736 : }
737 :
738 : // Add decorative trees
739 0 : const trees = new SimpleObject(g_Decoratives.tree, 5 * offset, 30 * offset, 2, 3 * offset + 10);
740 0 : createObjectGroupsDeprecated(new SimpleGroup([trees], true), 0, constraint, counts[0] * 5 * fill, 5);
741 : }
742 :
743 : export function addValleys(constraint, size, deviation, fill, baseHeight)
744 : {
745 0 : if (baseHeight < 6)
746 0 : return;
747 :
748 0 : g_Map.log("Creating valleys");
749 :
750 0 : const minElevation = Math.max(-baseHeight, 1 - baseHeight / (size * (deviation + 1)));
751 :
752 0 : let valleySlope = g_Terrains.tier1Terrain;
753 0 : let valleyFloor = g_Terrains.tier4Terrain;
754 :
755 0 : if (currentBiome() == "generic/sahara")
756 : {
757 0 : valleySlope = g_Terrains.tier3Terrain;
758 0 : valleyFloor = g_Terrains.dirt;
759 : }
760 :
761 0 : if (currentBiome() == "generic/aegean")
762 : {
763 0 : valleySlope = g_Terrains.tier2Terrain;
764 0 : valleyFloor = g_Terrains.dirt;
765 : }
766 :
767 0 : if (currentBiome() == "generic/alpine" || currentBiome() == "generic/savanna")
768 0 : valleyFloor = g_Terrains.tier2Terrain;
769 :
770 0 : if (currentBiome() == "generic/india")
771 0 : valleySlope = g_Terrains.dirt;
772 :
773 0 : if (currentBiome() == "generic/autumn")
774 0 : valleyFloor = g_Terrains.tier3Terrain;
775 :
776 0 : addElevation(constraint, {
777 : "class": g_TileClasses.valley,
778 : "painter": [valleySlope, valleyFloor],
779 : "size": size,
780 : "deviation": deviation,
781 : "fill": fill,
782 : "count": 8,
783 : "minSize": 5,
784 : "maxSize": 8,
785 : "spread": 30,
786 : "minElevation": minElevation,
787 : "maxElevation": -2,
788 : "steepness": 4
789 : });
790 : }
791 :
792 : /**
793 : * Create huntable animals.
794 : */
795 : export function addAnimals(constraint, size, deviation, fill)
796 : {
797 0 : g_Map.log("Creating animals");
798 :
799 0 : const groupOffset = getRandomDeviation(size, deviation);
800 :
801 0 : const animals = [
802 : [new SimpleObject(g_Gaia.mainHuntableAnimal, 5 * groupOffset, 7 * groupOffset, 0, 4 * groupOffset)],
803 : [new SimpleObject(g_Gaia.secondaryHuntableAnimal, 2 * groupOffset, 3 * groupOffset, 0, 2 * groupOffset)]
804 : ];
805 :
806 0 : for (const animal of animals)
807 0 : createObjectGroupsDeprecated(
808 : new SimpleGroup(animal, true, g_TileClasses.animals),
809 : 0,
810 : constraint,
811 : Math.floor(30 * fill),
812 : 50);
813 : }
814 :
815 : export function addBerries(constraint, size, deviation, fill)
816 : {
817 0 : g_Map.log("Creating berries");
818 :
819 0 : const groupOffset = getRandomDeviation(size, deviation);
820 :
821 0 : createObjectGroupsDeprecated(
822 : new SimpleGroup([new SimpleObject(g_Gaia.fruitBush, 5 * groupOffset, 5 * groupOffset, 0, 3 * groupOffset)], true, g_TileClasses.berries),
823 : 0,
824 : constraint,
825 : Math.floor(50 * fill),
826 : 40);
827 : }
828 :
829 : export function addFish(constraint, size, deviation, fill)
830 : {
831 0 : g_Map.log("Creating fish");
832 :
833 0 : const groupOffset = getRandomDeviation(size, deviation);
834 :
835 0 : const fishes = [
836 : [new SimpleObject(g_Gaia.fish, groupOffset, 2 * groupOffset, 0, 2 * groupOffset)],
837 : [new SimpleObject(g_Gaia.fish, 2 * groupOffset, 4 * groupOffset, 10 * groupOffset, 20 * groupOffset)]
838 : ];
839 :
840 0 : for (const fish of fishes)
841 0 : createObjectGroupsDeprecated(
842 : new SimpleGroup(fish, true, g_TileClasses.fish),
843 : 0,
844 : constraint,
845 : Math.floor(40 * fill),
846 : 50);
847 : }
848 :
849 : export function addForests(constraint, size, deviation, fill)
850 : {
851 0 : if (currentBiome() == "generic/savanna")
852 0 : return;
853 :
854 0 : g_Map.log("Creating forests");
855 :
856 0 : const treeTypes = [
857 : [
858 : g_Terrains.forestFloor2 + TERRAIN_SEPARATOR + g_Gaia.tree1,
859 : g_Terrains.forestFloor2 + TERRAIN_SEPARATOR + g_Gaia.tree2,
860 : g_Terrains.forestFloor2
861 : ],
862 : [
863 : g_Terrains.forestFloor1 + TERRAIN_SEPARATOR + g_Gaia.tree4,
864 : g_Terrains.forestFloor1 + TERRAIN_SEPARATOR + g_Gaia.tree5,
865 : g_Terrains.forestFloor1
866 : ]
867 : ];
868 :
869 0 : const forestTypes = [
870 : [
871 : [g_Terrains.forestFloor2, g_Terrains.mainTerrain, treeTypes[0]],
872 : [g_Terrains.forestFloor2, treeTypes[0]]
873 : ],
874 : [
875 : [g_Terrains.forestFloor2, g_Terrains.mainTerrain, treeTypes[1]],
876 : [g_Terrains.forestFloor1, treeTypes[1]]],
877 : [
878 : [g_Terrains.forestFloor1, g_Terrains.mainTerrain, treeTypes[0]],
879 : [g_Terrains.forestFloor2, treeTypes[0]]],
880 : [
881 : [g_Terrains.forestFloor1, g_Terrains.mainTerrain, treeTypes[1]],
882 : [g_Terrains.forestFloor1, treeTypes[1]]
883 : ]
884 : ];
885 :
886 0 : for (const forestType of forestTypes)
887 : {
888 0 : const offset = getRandomDeviation(size, deviation);
889 0 : createAreas(
890 : new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5) * offset), Math.floor(50 * offset), 0.5),
891 : [
892 : new LayeredPainter(forestType, [2]),
893 : new TileClassPainter(g_TileClasses.forest)
894 : ],
895 : constraint,
896 : 10 * fill);
897 : }
898 : }
899 :
900 : export function addMetal(constraint, size, deviation, fill)
901 : {
902 0 : g_Map.log("Creating metal mines");
903 :
904 0 : const offset = getRandomDeviation(size, deviation);
905 0 : createObjectGroupsDeprecated(
906 : new SimpleGroup([new SimpleObject(g_Gaia.metalLarge, offset, offset, 0, 4 * offset)], true, g_TileClasses.metal),
907 : 0,
908 : constraint,
909 : 1 + 20 * fill,
910 : 100);
911 : }
912 :
913 : export function addSmallMetal(constraint, size, mixes, amounts)
914 : {
915 0 : g_Map.log("Creating small metal mines");
916 :
917 0 : const deviation = getRandomDeviation(size, mixes);
918 0 : createObjectGroupsDeprecated(
919 : new SimpleGroup([new SimpleObject(g_Gaia.metalSmall, 2 * deviation, 5 * deviation, deviation, 3 * deviation)], true, g_TileClasses.metal),
920 : 0,
921 : constraint,
922 : 1 + 20 * amounts,
923 : 100);
924 : }
925 :
926 : /**
927 : * Create stone mines.
928 : */
929 : export function addStone(constraint, size, deviation, fill)
930 : {
931 0 : g_Map.log("Creating stone mines");
932 :
933 0 : const offset = getRandomDeviation(size, deviation);
934 :
935 0 : const mines = [
936 : [
937 : new SimpleObject(g_Gaia.stoneSmall, 0, 2 * offset, 0, 4 * offset),
938 : new SimpleObject(g_Gaia.stoneLarge, offset, offset, 0, 4 * offset)
939 : ],
940 : [
941 : new SimpleObject(g_Gaia.stoneSmall, 2 * offset, 5 * offset, offset, 3 * offset)
942 : ]
943 : ];
944 :
945 0 : for (const mine of mines)
946 0 : createObjectGroupsDeprecated(
947 : new SimpleGroup(mine, true, g_TileClasses.rock),
948 : 0,
949 : constraint,
950 : 1 + 20 * fill,
951 : 100);
952 : }
953 :
954 : /**
955 : * Create straggler trees.
956 : */
957 : export function addStragglerTrees(constraint, size, deviation, fill)
958 : {
959 0 : g_Map.log("Creating straggler trees");
960 :
961 : // Ensure minimum distribution on african biome
962 0 : if (currentBiome() == "generic/savanna")
963 : {
964 0 : fill = Math.max(fill, 2);
965 0 : size = Math.max(size, 1);
966 : }
967 :
968 0 : const trees = [g_Gaia.tree1, g_Gaia.tree2, g_Gaia.tree3, g_Gaia.tree4];
969 :
970 0 : const treesPerPlayer = 40;
971 0 : const playerBonus = Math.max(1, (getNumPlayers() - 3) / 2);
972 :
973 0 : const offset = getRandomDeviation(size, deviation);
974 0 : const treeCount = treesPerPlayer * playerBonus * fill;
975 0 : const totalTrees = scaleByMapSize(treeCount, treeCount);
976 :
977 0 : const count = Math.floor(totalTrees / trees.length) * fill;
978 0 : let min = offset;
979 0 : let max = 4 * offset;
980 0 : let minDist = offset;
981 0 : let maxDist = 5 * offset;
982 :
983 : // More trees for the african biome
984 0 : if (currentBiome() == "generic/savanna")
985 : {
986 0 : min = 3 * offset;
987 0 : max = 5 * offset;
988 0 : minDist = 2 * offset + 1;
989 0 : maxDist = 3 * offset + 2;
990 : }
991 :
992 0 : for (let i = 0; i < trees.length; ++i)
993 : {
994 0 : let treesMax = max;
995 :
996 : // Don't clump fruit trees
997 0 : if (i == 2 && (currentBiome() == "generic/sahara" || currentBiome() == "generic/aegean"))
998 0 : treesMax = 1;
999 :
1000 0 : min = Math.min(min, treesMax);
1001 :
1002 0 : const group = new SimpleGroup([new SimpleObject(trees[i], min, treesMax, minDist, maxDist)], true, g_TileClasses.forest);
1003 0 : createObjectGroupsDeprecated(group, 0, constraint, count);
1004 : }
1005 : }
1006 :
1007 : /**
1008 : * Determine if the endline of the bluff is within the tilemap.
1009 : */
1010 : function isBluffPassable(bluffArea, baseLine, endLine)
1011 : {
1012 0 : if (!baseLine ||
1013 : !endLine ||
1014 : !g_Map.validTilePassable(endLine.start) &&
1015 : !g_Map.validTilePassable(endLine.end))
1016 0 : return false;
1017 :
1018 0 : const minTilesInGroup = 2;
1019 0 : let insideBluff = false;
1020 0 : let outsideBluff = false;
1021 :
1022 : // If there aren't enough points in each row
1023 0 : const corners = getBoundingBox(bluffArea.getPoints());
1024 0 : for (let x = corners.min.x; x <= corners.max.x; ++x)
1025 : {
1026 0 : let count = 0;
1027 0 : for (let y = corners.min.y; y <= corners.max.y; ++y)
1028 : {
1029 0 : const pos = new Vector2D(x, y);
1030 0 : if (!bluffArea.contains(pos))
1031 0 : continue;
1032 :
1033 0 : const valid = g_Map.validTilePassable(pos);
1034 0 : if (valid)
1035 0 : ++count;
1036 :
1037 0 : if (valid)
1038 0 : insideBluff = true;
1039 :
1040 0 : if (outsideBluff && valid)
1041 0 : return false;
1042 : }
1043 :
1044 : // We're expecting the end of the bluff
1045 0 : if (insideBluff && count < minTilesInGroup)
1046 0 : outsideBluff = true;
1047 : }
1048 :
1049 0 : insideBluff = false;
1050 0 : outsideBluff = false;
1051 :
1052 : // If there aren't enough points in each column
1053 0 : for (let y = corners.min.y; y <= corners.max.y; ++y)
1054 : {
1055 0 : let count = 0;
1056 0 : for (let x = corners.min.x; x <= corners.max.x; ++x)
1057 : {
1058 0 : const pos = new Vector2D(x, y);
1059 0 : if (!bluffArea.contains(pos))
1060 0 : continue;
1061 :
1062 0 : const valid = g_Map.validTilePassable(pos.add(corners.min));
1063 0 : if (valid)
1064 0 : ++count;
1065 :
1066 0 : if (valid)
1067 0 : insideBluff = true;
1068 :
1069 0 : if (outsideBluff && valid)
1070 0 : return false;
1071 : }
1072 :
1073 : // We're expecting the end of the bluff
1074 0 : if (insideBluff && count < minTilesInGroup)
1075 0 : outsideBluff = true;
1076 : }
1077 :
1078 0 : return true;
1079 : }
1080 :
1081 : /**
1082 : * Find a 45 degree line that does not intersect with the bluff.
1083 : */
1084 : function findClearLine(bluffArea, angle)
1085 : {
1086 0 : const corners = getBoundingBox(bluffArea.getPoints());
1087 :
1088 : // Angle - 0: northwest; 1: northeast; 2: southeast; 3: southwest
1089 : let offset;
1090 : let y;
1091 0 : switch (angle)
1092 : {
1093 : case 0:
1094 0 : offset = new Vector2D(-1, -1);
1095 0 : y = corners.max.y;
1096 0 : break;
1097 : case 1:
1098 0 : offset = new Vector2D(1, -1);
1099 0 : y = corners.max.y;
1100 0 : break;
1101 : case 2:
1102 0 : offset = new Vector2D(1, 1);
1103 0 : y = corners.min.y;
1104 0 : break;
1105 : case 3:
1106 0 : offset = new Vector2D(-1, 1);
1107 0 : y = corners.min.y;
1108 0 : break;
1109 : default:
1110 0 : throw new Error("Unknown angle " + angle);
1111 : }
1112 :
1113 : let clearLine;
1114 0 : for (let x = corners.min.x; x <= corners.max.x; ++x)
1115 : {
1116 0 : const start = new Vector2D(x, y);
1117 :
1118 0 : let intersectsBluff = false;
1119 0 : const end = start.clone();
1120 :
1121 0 : while (end.x >= corners.min.x && end.x <= corners.max.x && end.y >= corners.min.y && end.y <= corners.max.y)
1122 : {
1123 0 : if (bluffArea.contains(end) && g_Map.validTilePassable(end))
1124 : {
1125 0 : intersectsBluff = true;
1126 0 : break;
1127 : }
1128 0 : end.add(offset);
1129 : }
1130 :
1131 0 : if (!intersectsBluff)
1132 0 : clearLine = {
1133 : "start": start,
1134 : "end": end.sub(offset)
1135 : };
1136 :
1137 0 : if (intersectsBluff ? (angle == 0 || angle == 3) : (angle == 1 || angle == 2))
1138 0 : break;
1139 : }
1140 :
1141 0 : return clearLine;
1142 : }
1143 :
1144 : /**
1145 : * Returns a number within a random deviation of a base number.
1146 : */
1147 : function getRandomDeviation(base, deviation)
1148 : {
1149 0 : return base + randFloat(-1, 1) * Math.min(base, deviation);
1150 : }
|