Make wind dependent on height, add additional control commands, improve docu

This commit is contained in:
Till Affeldt
2020-05-13 16:03:28 +02:00
parent f42b4183e5
commit d4e00db432
14 changed files with 142 additions and 55 deletions

View File

@ -55,6 +55,22 @@ minetest.register_chatcommand("weather", {
})
-- set base heat to increase or decrease global climate temperatures
minetest.register_chatcommand("set_base_heat", {
params = "<heat>",
description = "Override the weather algorithm's base heat",
privs = { weather = true },
func = function(playername, param)
if param == nil or param == "" then
minetest.chat_send_player(playername, "Provide a number to modify the base heat")
return
end
if param == "auto" then param = 0 end
climate_mod.settings.heat = tonumber(param)
minetest.chat_send_player(playername, "Base heat changed")
end
})
-- override global heat levels with given value
minetest.register_chatcommand("set_heat", {
params = "<heat>",
description = "Override the weather algorithm's base heat",
@ -64,12 +80,33 @@ minetest.register_chatcommand("set_heat", {
minetest.chat_send_player(playername, "Provide a number to modify the base heat")
return
end
climate_mod.settings.heat = tonumber(param)
minetest.chat_send_player(playername, "Heat changed")
if param == "auto" then
climate_mod.forced_enviroment.heat = nil
minetest.chat_send_player(playername, "Heat value reset")
else
climate_mod.forced_enviroment.heat = tonumber(param)
minetest.chat_send_player(playername, "Heat value changed")
end
end
})
-- set base heat to increase or decrease global climate humidity
minetest.register_chatcommand("set_base_humidity", {
params = "<humidity>",
description = "Override the weather algorithm's base humidity",
privs = { weather = true },
func = function(playername, param)
if param == nil or param == "" then
minetest.chat_send_player(playername, "Provide a number to modify the base humidity")
return
end
if param == "auto" then param = 0 end
climate_mod.settings.humidity = tonumber(param)
minetest.chat_send_player(playername, "Base humidity changed")
end
})
-- override global humidity with given value
minetest.register_chatcommand("set_humidity", {
params = "<humidity>",
description = "Override the weather algorithm's base humidity",
@ -79,8 +116,13 @@ minetest.register_chatcommand("set_humidity", {
minetest.chat_send_player(playername, "Provide a number to modify the base humidity")
return
end
climate_mod.settings.humidity = tonumber(param)
minetest.chat_send_player(playername, "Humidity changed")
if param == "auto" then
climate_mod.forced_enviroment.humidity = nil
minetest.chat_send_player(playername, "Humidity value reset")
else
climate_mod.forced_enviroment.humidity = tonumber(param)
minetest.chat_send_player(playername, "Humidity value changed")
end
end
})
@ -99,9 +141,11 @@ minetest.register_chatcommand("set_wind", {
local wind_x = arguments[1]
local wind_z = arguments[2]
if wind_x == "auto" then
climate_mod.forced_wind = nil
climate_mod.forced_enviroment.wind = nil
elseif wind_x == nil or wind_z == nil then
minetest.chat_send_player(playername, "Invalid wind configuration")
else
climate_mod.forced_wind = vector.new({
climate_mod.forced_enviroment.wind = vector.new({
x = tonumber(wind_x),
y = 0,
z = tonumber(wind_z)
@ -131,11 +175,14 @@ minetest.register_chatcommand("set_weather", {
local arguments = {}
for w in param:gmatch("%S+") do table.insert(arguments, w) end
local weather = arguments[1]
if climate_mod.weathers[weather] == nil then
if weather == nil or climate_mod.weathers[weather] == nil then
minetest.chat_send_player(playername, "Unknown weather preset")
return
end
local status
if arguments[2] == nil or arguments[2] == "" then
arguments[2] = "on"
end
if arguments[2] == "on" then
status = true
elseif arguments[2] == "off" then

View File

@ -1,24 +1,21 @@
local environment = {}
local function get_heat_time()
local time = minetest.get_timeofday()
return climate_api.utility.normalized_cycle(time) * 0.6 + 0.7
end
local function get_heat_height(y)
return climate_api.utility.rangelim((-y + 10) / 15, -10, 10)
end
function environment.get_heat(pos)
if climate_mod.forced_enviroment.heat ~= nil then
return climate_mod.forced_enviroment.heat
end
local base = climate_mod.settings.heat
local biome = minetest.get_heat(pos)
local height = get_heat_height(pos.y)
local time = get_heat_time()
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
end
function environment.get_humidity(pos)
if climate_mod.forced_enviroment.humidity ~= nil then
return climate_mod.forced_enviroment.humidity
end
local base = climate_mod.settings.humidity
local biome = minetest.get_humidity(pos)
local random = climate_mod.state:get_float("humidity_random");
@ -26,13 +23,15 @@ function environment.get_humidity(pos)
return (base + biome * 0.7 + random_base * 0.3) * random
end
function environment.get_wind()
if climate_mod.forced_wind ~= nil then
return climate_mod.forced_wind
function environment.get_wind(pos)
if climate_mod.forced_enviroment.wind ~= nil then
return climate_mod.forced_enviroment.wind
end
local wind_x = climate_mod.state:get_float("wind_x")
local wind_z = climate_mod.state:get_float("wind_z")
return vector.new({ x = wind_x, y = 0, z = wind_z })
local base_wind = vector.new({ x = wind_x, y = 0, z = wind_z })
local height_modifier = climate_api.utility.sigmoid(pos.y, 2, 0.02, 1)
return vector.multiply(base_wind, height_modifier)
end
function environment.get_weather_presets(player)

View File

@ -33,13 +33,13 @@ climate_api.register_influence("biome", function(pos)
return biome
end)
climate_api.register_global_influence("windspeed", function()
local wind = climate_api.environment.get_wind()
climate_api.register_influence("windspeed", function(pos)
local wind = climate_api.environment.get_wind(pos)
return vector.length(wind)
end)
climate_api.register_global_influence("wind_yaw", function()
local wind = climate_api.environment.get_wind()
local wind = climate_api.environment.get_wind({x = 0, y = 0, z = 0})
if vector.length(wind) == 0 then return 0 end
return minetest.dir_to_yaw(wind)
end)

View File

@ -49,7 +49,6 @@ elseif mod_pova then
-- fallback to vanilla override as last resort
else
local physics = {}
local function apply_physics(player)
local playername = player:get_player_name()
local override = { speed = 1, jump = 1, gravity = 1 }

View File

@ -37,7 +37,7 @@ function trigger.test_condition(condition, env, goal)
return false
else
value = env[condition]
return type(value) ~= "nil" and goal == value
return type(value) == "nil" or goal == value
end
end