Rework humidity system, fix bug regarding global influences not registering

This commit is contained in:
Till Affeldt 2023-02-24 08:22:53 +01:00
parent bf2d4e09ca
commit 7d299edb5b
5 changed files with 25 additions and 22 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.code-workspace

View File

@ -229,4 +229,19 @@ minetest.register_chatcommand("weather_influences", {
minetest.chat_send_player(playername, dump2(value, influence))
end
end
})
-- used to debug downfall
minetest.register_chatcommand("explain_humidity", {
description = "Explains how the humidity value got calculated",
func = function(playername)
local base = climate_mod.settings.humidity
local biome = minetest.get_humidity((minetest.get_player_by_name(playername)):get_pos())
local random = climate_mod.state:get_float("humidity_random");
local random_base = climate_mod.state:get_float("humidity_base");
minetest.chat_send_player(playername, dump2(base, "base"))
minetest.chat_send_player(playername, dump2(biome, "biome"))
minetest.chat_send_player(playername, dump2(random, "random"))
minetest.chat_send_player(playername, dump2(random_base, "random_base"))
end
})

View File

@ -9,7 +9,7 @@ function environment.get_heat(pos)
local height = climate_api.utility.rangelim((-pos.y + 10) / 15, -10, 10)
local time = climate_api.utility.normalized_cycle(minetest.get_timeofday()) * 0.6 + 0.7
local random = climate_mod.state:get_float("heat_random");
return (base + biome + height) * time * random
return base + ((biome + height) * time * random)
end
function environment.get_humidity(pos)
@ -19,8 +19,7 @@ function environment.get_humidity(pos)
local base = climate_mod.settings.humidity
local biome = minetest.get_humidity(pos)
local random = climate_mod.state:get_float("humidity_random");
local random_base = climate_mod.state:get_float("humidity_base");
return (base + biome * 0.7 + random_base * 0.3) * random
return base + (((biome + 40) / 2) * random)
end
function environment.get_wind(pos)

View File

@ -9,7 +9,7 @@ function trigger.get_global_environment()
end
function trigger.get_position_environment(pos)
local env = table.copy(climate_mod.global_environment)
local env = trigger.get_global_environment()
for influence, func in pairs(climate_mod.influences) do
env[influence] = func(pos)
end

View File

@ -6,9 +6,9 @@ local WIND_SCALE = 2
local HEAT_SPREAD = 400
local HEAT_SCALE = 0.3
local HUMIDITY_SPREAD = 150
local HUMIDITY_SCALE = 0.5
local HUMIDITY_SCALE = 1
local HUMIDITY_BASE_SPREAD = 800
local HUMIDITY_BASE_SCALE = 40
local HUMIDITY_BASE_SCALE = 20
local nobj_wind_x
local nobj_wind_z
@ -47,23 +47,14 @@ local pn_heat = {
}
local pn_humidity = {
offset = 0,
offset = 1,
scale = HUMIDITY_SCALE,
spread = {x = HUMIDITY_SPREAD, y = HUMIDITY_SPREAD, z = HUMIDITY_SPREAD},
seed = 8374061,
octaves = 2,
persist = 0.5,
lacunarity = 2
}
local pn_humidity_base = {
offset = 50,
scale = HUMIDITY_BASE_SCALE,
spread = {x = HUMIDITY_BASE_SPREAD, y = HUMIDITY_BASE_SPREAD, z = HUMIDITY_BASE_SPREAD},
seed = 3803465,
octaves = 2,
persist = 0.5,
lacunarity = 2
lacunarity = 2,
flags = "noeased"
}
local function update_wind(timer)
@ -83,11 +74,8 @@ end
local function update_humidity(timer)
nobj_humidity = nobj_humidity or minetest.get_perlin(pn_humidity)
local n_humidity = nobj_humidity:get_2d({x = timer, y = 0})
local n_humidity = nobj_humidity:get_2d({x = timer * 3, y = 0})
climate_mod.state:set_float("humidity_random", n_humidity)
nobj_humidity_base = nobj_humidity_base or minetest.get_perlin(pn_humidity_base)
local n_humidity_base = nobj_humidity_base:get_2d({x = timer, y = 0})
climate_mod.state:set_float("humidity_base", n_humidity_base)
end
function world.update_status(timer)