aboutsummaryrefslogtreecommitdiff
path: root/src/mapgen
diff options
context:
space:
mode:
authorparamat <paramat@users.noreply.github.com>2017-09-22 12:38:55 +0100
committerparamat <mat.gregory@virginmedia.com>2018-01-16 08:47:07 +0000
commitd45e5da8ca808e552123bcd94e76b0b435a6ea79 (patch)
tree356623d2625c8e2aab94de35f7b1790dfe998d71 /src/mapgen
parent4c0d4e4105d2f2e63b9a43bb83fecf92288f63b3 (diff)
downloadminetest-d45e5da8ca808e552123bcd94e76b0b435a6ea79.tar.gz
minetest-d45e5da8ca808e552123bcd94e76b0b435a6ea79.tar.bz2
minetest-d45e5da8ca808e552123bcd94e76b0b435a6ea79.zip
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.
Diffstat (limited to 'src/mapgen')
-rw-r--r--src/mapgen/mg_biome.cpp60
-rw-r--r--src/mapgen/mg_biome.h7
2 files changed, 66 insertions, 1 deletions
diff --git a/src/mapgen/mg_biome.cpp b/src/mapgen/mg_biome.cpp
index b562084e3..2273be280 100644
--- a/src/mapgen/mg_biome.cpp
+++ b/src/mapgen/mg_biome.cpp
@@ -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)
{
diff --git a/src/mapgen/mg_biome.h b/src/mapgen/mg_biome.h
index ac606e935..a2bfaf5b9 100644
--- a/src/mapgen/mg_biome.h
+++ b/src/mapgen/mg_biome.h
@@ -225,6 +225,13 @@ public:
virtual void clear();
+ // For BiomeGen type 'BiomeGenOriginal'
+ float getHeatAtPosOriginal(v3s16 pos, NoiseParams &np_heat,
+ NoiseParams &np_heat_blend, u64 seed);
+ float getHumidityAtPosOriginal(v3s16 pos, NoiseParams &np_humidity,
+ NoiseParams &np_humidity_blend, u64 seed);
+ Biome *getBiomeFromNoiseOriginal(float heat, float humidity, s16 y);
+
private:
Server *m_server;