diff options
author | paramat <paramat@users.noreply.github.com> | 2017-09-22 12:38:55 +0100 |
---|---|---|
committer | paramat <mat.gregory@virginmedia.com> | 2018-01-16 08:47:07 +0000 |
commit | d45e5da8ca808e552123bcd94e76b0b435a6ea79 (patch) | |
tree | 356623d2625c8e2aab94de35f7b1790dfe998d71 /src/script/lua_api/l_mapgen.cpp | |
parent | 4c0d4e4105d2f2e63b9a43bb83fecf92288f63b3 (diff) | |
download | minetest-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/script/lua_api/l_mapgen.cpp')
-rw-r--r-- | src/script/lua_api/l_mapgen.cpp | 153 |
1 files changed, 152 insertions, 1 deletions
diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index b526111d4..db517b942 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -463,7 +463,7 @@ size_t get_biome_list(lua_State *L, int index, /////////////////////////////////////////////////////////////////////////////// // get_biome_id(biomename) -// returns the biome id used in biomemap +// returns the biome id as used in biomemap and returned by 'get_biome_data()' int ModApiMapgen::l_get_biome_id(lua_State *L) { NO_MAP_LOCK_REQUIRED; @@ -488,6 +488,154 @@ int ModApiMapgen::l_get_biome_id(lua_State *L) } +// get_heat(pos) +// returns the heat at the position +int ModApiMapgen::l_get_heat(lua_State *L) +{ + NO_MAP_LOCK_REQUIRED; + + v3s16 pos = read_v3s16(L, 1); + + NoiseParams np_heat; + NoiseParams np_heat_blend; + + MapSettingsManager *settingsmgr = + getServer(L)->getEmergeManager()->map_settings_mgr; + + if (!settingsmgr->getMapSettingNoiseParams("mg_biome_np_heat", + &np_heat) || + !settingsmgr->getMapSettingNoiseParams("mg_biome_np_heat_blend", + &np_heat_blend)) + return 0; + + std::string value; + if (!settingsmgr->getMapSetting("seed", &value)) + return 0; + std::istringstream ss(value); + u64 seed; + ss >> seed; + + BiomeManager *bmgr = getServer(L)->getEmergeManager()->biomemgr; + if (!bmgr) + return 0; + + float heat = bmgr->getHeatAtPosOriginal(pos, np_heat, np_heat_blend, seed); + if (!heat) + return 0; + + lua_pushnumber(L, heat); + + return 1; +} + + +// get_humidity(pos) +// returns the humidity at the position +int ModApiMapgen::l_get_humidity(lua_State *L) +{ + NO_MAP_LOCK_REQUIRED; + + v3s16 pos = read_v3s16(L, 1); + + NoiseParams np_humidity; + NoiseParams np_humidity_blend; + + MapSettingsManager *settingsmgr = + getServer(L)->getEmergeManager()->map_settings_mgr; + + if (!settingsmgr->getMapSettingNoiseParams("mg_biome_np_humidity", + &np_humidity) || + !settingsmgr->getMapSettingNoiseParams("mg_biome_np_humidity_blend", + &np_humidity_blend)) + return 0; + + std::string value; + if (!settingsmgr->getMapSetting("seed", &value)) + return 0; + std::istringstream ss(value); + u64 seed; + ss >> seed; + + BiomeManager *bmgr = getServer(L)->getEmergeManager()->biomemgr; + if (!bmgr) + return 0; + + float humidity = bmgr->getHumidityAtPosOriginal(pos, np_humidity, + np_humidity_blend, seed); + if (!humidity) + return 0; + + lua_pushnumber(L, humidity); + + return 1; +} + + +// get_biome_data(pos) +// returns a table containing the biome id, heat and humidity at the position +int ModApiMapgen::l_get_biome_data(lua_State *L) +{ + NO_MAP_LOCK_REQUIRED; + + v3s16 pos = read_v3s16(L, 1); + + NoiseParams np_heat; + NoiseParams np_heat_blend; + NoiseParams np_humidity; + NoiseParams np_humidity_blend; + + MapSettingsManager *settingsmgr = + getServer(L)->getEmergeManager()->map_settings_mgr; + + if (!settingsmgr->getMapSettingNoiseParams("mg_biome_np_heat", + &np_heat) || + !settingsmgr->getMapSettingNoiseParams("mg_biome_np_heat_blend", + &np_heat_blend) || + !settingsmgr->getMapSettingNoiseParams("mg_biome_np_humidity", + &np_humidity) || + !settingsmgr->getMapSettingNoiseParams("mg_biome_np_humidity_blend", + &np_humidity_blend)) + return 0; + + std::string value; + if (!settingsmgr->getMapSetting("seed", &value)) + return 0; + std::istringstream ss(value); + u64 seed; + ss >> seed; + + BiomeManager *bmgr = getServer(L)->getEmergeManager()->biomemgr; + if (!bmgr) + return 0; + + float heat = bmgr->getHeatAtPosOriginal(pos, np_heat, np_heat_blend, seed); + if (!heat) + return 0; + + float humidity = bmgr->getHumidityAtPosOriginal(pos, np_humidity, + np_humidity_blend, seed); + if (!humidity) + return 0; + + Biome *biome = (Biome *)bmgr->getBiomeFromNoiseOriginal(heat, humidity, pos.Y); + if (!biome || biome->index == OBJDEF_INVALID_INDEX) + return 0; + + lua_newtable(L); + + lua_pushinteger(L, biome->index); + lua_setfield(L, -2, "biome"); + + lua_pushnumber(L, heat); + lua_setfield(L, -2, "heat"); + + lua_pushnumber(L, humidity); + lua_setfield(L, -2, "humidity"); + + return 1; +} + + // get_mapgen_object(objectname) // returns the requested object used during map generation int ModApiMapgen::l_get_mapgen_object(lua_State *L) @@ -1520,6 +1668,9 @@ int ModApiMapgen::l_serialize_schematic(lua_State *L) void ModApiMapgen::Initialize(lua_State *L, int top) { API_FCT(get_biome_id); + API_FCT(get_heat); + API_FCT(get_humidity); + API_FCT(get_biome_data); API_FCT(get_mapgen_object); API_FCT(get_mapgen_params); |