-
Notifications
You must be signed in to change notification settings - Fork 64
/
biomes.js
107 lines (97 loc) · 3.13 KB
/
biomes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* From http://www.redblobgames.com/maps/mapgen2/
* Copyright 2017 Red Blob Games <[email protected]>
* License: Apache v2.0 <http://www.apache.org/licenses/LICENSE-2.0.html>
*/
'use strict';
const util = require('./util');
function biome(ocean, water, coast, temperature, moisture) {
if (ocean) {
return 'OCEAN';
} else if (water) {
if (temperature > 0.9) return 'MARSH';
if (temperature < 0.2) return 'ICE';
return 'LAKE';
} else if (coast) {
return 'BEACH';
} else if (temperature < 0.2) {
if (moisture > 0.50) return 'SNOW';
else if (moisture > 0.33) return 'TUNDRA';
else if (moisture > 0.16) return 'BARE';
else return 'SCORCHED';
} else if (temperature < 0.4) {
if (moisture > 0.66) return 'TAIGA';
else if (moisture > 0.33) return 'SHRUBLAND';
else return 'TEMPERATE_DESERT';
} else if (temperature < 0.7) {
if (moisture > 0.83) return 'TEMPERATE_RAIN_FOREST';
else if (moisture > 0.50) return 'TEMPERATE_DECIDUOUS_FOREST';
else if (moisture > 0.16) return 'GRASSLAND';
else return 'TEMPERATE_DESERT';
} else {
if (moisture > 0.66) return 'TROPICAL_RAIN_FOREST';
else if (moisture > 0.33) return 'TROPICAL_SEASONAL_FOREST';
else if (moisture > 0.16) return 'GRASSLAND';
else return 'SUBTROPICAL_DESERT';
}
}
/**
* A coast region is land that has an ocean neighbor
*/
exports.assign_r_coast = function(r_coast, mesh, r_ocean) {
r_coast.length = mesh.numRegions;
r_coast.fill(false);
let out_r = [];
for (let r1 = 0; r1 < mesh.numRegions; r1++) {
mesh.r_circulate_r(out_r, r1);
if (!r_ocean[r1]) {
for (let r2 of out_r) {
if (r_ocean[r2]) {
r_coast[r1] = true;
break;
}
}
}
}
return r_coast;
};
/**
* Temperature assignment
*
* Temperature is based on elevation and latitude.
* The normal range is 0.0=cold, 1.0=hot, but it is not
* limited to that range, especially when using temperature bias.
*
* The northernmost parts of the map get bias_north added to them;
* the southernmost get bias_south added; in between it's a blend.
*/
exports.assign_r_temperature = function(
r_temperature,
mesh,
r_ocean, r_water,
r_elevation, r_moisture,
bias_north, bias_south
) {
r_temperature.length = mesh.numRegions;
for (let r = 0; r < mesh.numRegions; r++) {
let latitude = mesh.r_y(r) / 1000; /* 0.0 - 1.0 */
let d_temperature = util.mix(bias_north, bias_south, latitude);
r_temperature[r] = 1.0 - r_elevation[r] + d_temperature;
}
return r_temperature;
};
/**
* Biomes assignment -- see the biome() function above
*/
exports.assign_r_biome = function(
r_biome,
mesh,
r_ocean, r_water, r_coast, r_temperature, r_moisture
) {
r_biome.length = mesh.numRegions;
for (let r = 0; r < mesh.numRegions; r++) {
r_biome[r] = biome(r_ocean[r], r_water[r], r_coast[r],
r_temperature[r], r_moisture[r]);
}
return r_biome;
};