1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-02 16:38:41 +00:00

Biomes: Add 'get heat', 'get humidity', 'get biome data' APIs

'get biome data' returns biome id, heat and humidity.
Clean up nearby lines in lua_api.txt.
This commit is contained in:
paramat 2017-09-22 12:38:55 +01:00 committed by paramat
parent 4c0d4e4105
commit d45e5da8ca
5 changed files with 302 additions and 39 deletions

View file

@ -84,8 +84,66 @@ void BiomeManager::clear()
m_objects.resize(1);
}
////////////////////////////////////////////////////////////////////////////////
// For BiomeGen type 'BiomeGenOriginal'
float BiomeManager::getHeatAtPosOriginal(v3s16 pos, NoiseParams &np_heat,
NoiseParams &np_heat_blend, u64 seed)
{
return
NoisePerlin2D(&np_heat, pos.X, pos.Z, seed) +
NoisePerlin2D(&np_heat_blend, pos.X, pos.Z, seed);
}
// For BiomeGen type 'BiomeGenOriginal'
float BiomeManager::getHumidityAtPosOriginal(v3s16 pos, NoiseParams &np_humidity,
NoiseParams &np_humidity_blend, u64 seed)
{
return
NoisePerlin2D(&np_humidity, pos.X, pos.Z, seed) +
NoisePerlin2D(&np_humidity_blend, pos.X, pos.Z, seed);
}
// For BiomeGen type 'BiomeGenOriginal'
Biome *BiomeManager::getBiomeFromNoiseOriginal(float heat, float humidity, s16 y)
{
Biome *biome_closest = nullptr;
Biome *biome_closest_blend = nullptr;
float dist_min = FLT_MAX;
float dist_min_blend = FLT_MAX;
for (size_t i = 1; i < getNumObjects(); i++) {
Biome *b = (Biome *)getRaw(i);
if (!b || y > b->y_max + b->vertical_blend || y < b->y_min)
continue;
float d_heat = heat - b->heat_point;
float d_humidity = humidity - b->humidity_point;
float dist = (d_heat * d_heat) + (d_humidity * d_humidity);
if (y <= b->y_max) { // Within y limits of biome b
if (dist < dist_min) {
dist_min = dist;
biome_closest = b;
}
} else if (dist < dist_min_blend) { // Blend area above biome b
dist_min_blend = dist;
biome_closest_blend = b;
}
}
mysrand(y + (heat - humidity) * 2);
if (biome_closest_blend &&
myrand_range(0, biome_closest_blend->vertical_blend) >=
y - biome_closest_blend->y_max)
return biome_closest_blend;
return (biome_closest) ? biome_closest : (Biome *)getRaw(BIOME_NONE);
}
////////////////////////////////////////////////////////////////////////////////
void BiomeParamsOriginal::readParams(const Settings *settings)
{