2020-05-29 21:52:45 +02:00
|
|
|
local S = climate_mod.i18n
|
|
|
|
|
2020-04-26 18:11:38 +02:00
|
|
|
-- parse heat values into readable format
|
|
|
|
-- also convert to Celsius if configured
|
2020-04-14 05:44:46 +02:00
|
|
|
local function parse_heat(heat)
|
|
|
|
local indicator = "°F"
|
|
|
|
if not climate_mod.settings.fahrenheit then
|
|
|
|
heat = (heat - 32) * 5 / 9
|
|
|
|
indicator = "°C"
|
|
|
|
end
|
|
|
|
heat = math.floor(heat * 100) / 100
|
|
|
|
return heat .. indicator
|
|
|
|
end
|
|
|
|
|
2020-04-26 18:11:38 +02:00
|
|
|
|
|
|
|
-- register weather privilege in order to modify the weather status
|
2020-04-14 05:44:46 +02:00
|
|
|
minetest.register_privilege("weather", {
|
2020-05-29 21:52:45 +02:00
|
|
|
description = S("Make changes to the current weather"),
|
2020-04-14 05:44:46 +02:00
|
|
|
give_to_singleplayer = false
|
|
|
|
})
|
|
|
|
|
2020-04-26 18:11:38 +02:00
|
|
|
-- display general information on current weather
|
2020-04-14 05:44:46 +02:00
|
|
|
minetest.register_chatcommand("weather", {
|
2020-05-29 21:52:45 +02:00
|
|
|
description = S("Display weather information"),
|
2020-04-14 05:44:46 +02:00
|
|
|
func = function(playername)
|
|
|
|
local player = minetest.get_player_by_name(playername)
|
|
|
|
local ppos = player:get_pos()
|
|
|
|
local weathers = climate_api.environment.get_weather_presets(player)
|
|
|
|
local effects = climate_api.environment.get_effects(player)
|
|
|
|
local heat = climate_api.environment.get_heat(ppos)
|
|
|
|
local humidity = math.floor(climate_api.environment.get_humidity(ppos) * 100) / 100
|
|
|
|
local msg = ""
|
|
|
|
if #weathers > 0 then
|
2020-05-29 21:52:45 +02:00
|
|
|
msg = msg .. S("The following weather presets are active for you:") .. " "
|
2020-04-14 05:44:46 +02:00
|
|
|
for _, weather in ipairs(weathers) do
|
|
|
|
msg = msg .. weather .. ", "
|
|
|
|
end
|
|
|
|
msg = msg:sub(1, #msg-2) .. "\n"
|
|
|
|
else
|
2020-05-29 21:52:45 +02:00
|
|
|
msg = msg .. S("Your sky is clear. No weather presets are currently active.") .. "\n"
|
2020-04-14 05:44:46 +02:00
|
|
|
end
|
|
|
|
if #effects > 0 then
|
2020-05-29 21:52:45 +02:00
|
|
|
msg = msg .. S("As a result, the following environment effects are applied:") .. " "
|
2020-04-14 05:44:46 +02:00
|
|
|
for _, effect in ipairs(effects) do
|
|
|
|
msg = msg .. effect .. ", "
|
|
|
|
end
|
|
|
|
msg = msg:sub(1, #msg-2) .. "\n"
|
|
|
|
end
|
|
|
|
local heat_desc
|
2020-05-29 21:52:45 +02:00
|
|
|
if heat > 80 then heat_desc = S("scorching")
|
|
|
|
elseif heat > 50 then heat_desc = S("pleasant")
|
|
|
|
else heat_desc = S("chilly") end
|
|
|
|
msg = msg .. S("It is a @1 @2 right now and humidity is at @3%.", heat_desc, parse_heat(heat), humidity) .. "\n"
|
2020-04-14 05:44:46 +02:00
|
|
|
minetest.chat_send_player(playername, msg)
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2020-04-26 18:11:38 +02:00
|
|
|
-- set base heat to increase or decrease global climate temperatures
|
2020-05-13 16:03:28 +02:00
|
|
|
minetest.register_chatcommand("set_base_heat", {
|
2023-10-19 04:54:02 +02:00
|
|
|
params = S("<heat>"),
|
2020-05-29 21:52:45 +02:00
|
|
|
description = S("Override the weather algorithm's base heat"),
|
2020-04-14 05:44:46 +02:00
|
|
|
privs = { weather = true },
|
|
|
|
func = function(playername, param)
|
|
|
|
if param == nil or param == "" then
|
2020-05-29 21:52:45 +02:00
|
|
|
minetest.chat_send_player(playername, S("Provide a number to modify the base heat"))
|
2020-04-14 05:44:46 +02:00
|
|
|
return
|
|
|
|
end
|
2020-05-13 16:03:28 +02:00
|
|
|
if param == "auto" then param = 0 end
|
2020-05-16 16:19:28 +02:00
|
|
|
climate_mod.settings.heat = tonumber(param) or 0
|
2020-05-29 21:52:45 +02:00
|
|
|
minetest.chat_send_player(playername, S("Base heat changed"))
|
2020-05-13 16:03:28 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
-- override global heat levels with given value
|
|
|
|
minetest.register_chatcommand("set_heat", {
|
2023-10-19 04:54:02 +02:00
|
|
|
params = S("<heat>"),
|
2020-05-29 21:52:45 +02:00
|
|
|
description = S("Override the weather algorithm's heat"),
|
2020-05-13 16:03:28 +02:00
|
|
|
privs = { weather = true },
|
|
|
|
func = function(playername, param)
|
|
|
|
if param == nil or param == "" then
|
2020-05-29 21:52:45 +02:00
|
|
|
minetest.chat_send_player(playername, S("Provide a number to modify the heat"))
|
2020-05-13 16:03:28 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
if param == "auto" then
|
|
|
|
climate_mod.forced_enviroment.heat = nil
|
2020-05-29 21:52:45 +02:00
|
|
|
minetest.chat_send_player(playername, S("Heat value reset"))
|
2020-05-13 16:03:28 +02:00
|
|
|
else
|
2020-05-16 16:19:28 +02:00
|
|
|
climate_mod.forced_enviroment.heat = tonumber(param) or 0
|
2020-05-29 21:52:45 +02:00
|
|
|
minetest.chat_send_player(playername, S("Heat value changed"))
|
2020-05-13 16:03:28 +02:00
|
|
|
end
|
2020-04-14 05:44:46 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2020-04-26 18:11:38 +02:00
|
|
|
-- set base heat to increase or decrease global climate humidity
|
2020-05-13 16:03:28 +02:00
|
|
|
minetest.register_chatcommand("set_base_humidity", {
|
2023-10-19 04:54:02 +02:00
|
|
|
params = S("<humidity>"),
|
2020-05-29 21:52:45 +02:00
|
|
|
description = S("Override the weather algorithm's base humidity"),
|
2020-04-14 05:44:46 +02:00
|
|
|
privs = { weather = true },
|
|
|
|
func = function(playername, param)
|
2020-05-16 16:19:28 +02:00
|
|
|
if param == "auto" then param = 0 end
|
2020-04-14 05:44:46 +02:00
|
|
|
if param == nil or param == "" then
|
2020-05-29 21:52:45 +02:00
|
|
|
minetest.chat_send_player(playername, S("Provide a number to modify the base humidity"))
|
2020-04-14 05:44:46 +02:00
|
|
|
return
|
|
|
|
end
|
2020-05-16 16:19:28 +02:00
|
|
|
climate_mod.settings.humidity = tonumber(param) or 0
|
2020-05-29 21:52:45 +02:00
|
|
|
minetest.chat_send_player(playername, S("Base humidity changed"))
|
2020-05-13 16:03:28 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
-- override global humidity with given value
|
|
|
|
minetest.register_chatcommand("set_humidity", {
|
2023-10-19 04:54:02 +02:00
|
|
|
params = S("<humidity>"),
|
2020-05-29 21:52:45 +02:00
|
|
|
description = S("Override the weather algorithm's humidity"),
|
2020-05-13 16:03:28 +02:00
|
|
|
privs = { weather = true },
|
|
|
|
func = function(playername, param)
|
|
|
|
if param == nil or param == "" then
|
2020-05-29 21:52:45 +02:00
|
|
|
minetest.chat_send_player(playername, S("Provide a number to modify the humidity"))
|
2020-05-13 16:03:28 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
if param == "auto" then
|
|
|
|
climate_mod.forced_enviroment.humidity = nil
|
2020-05-29 21:52:45 +02:00
|
|
|
minetest.chat_send_player(playername, S("Humidity value reset"))
|
2020-05-13 16:03:28 +02:00
|
|
|
else
|
2020-05-16 16:19:28 +02:00
|
|
|
climate_mod.forced_enviroment.humidity = tonumber(param) or 0
|
2020-05-29 21:52:45 +02:00
|
|
|
minetest.chat_send_player(playername, S("Humidity value changed"))
|
2020-05-13 16:03:28 +02:00
|
|
|
end
|
2020-04-14 05:44:46 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2020-04-26 18:11:38 +02:00
|
|
|
-- override wind direction and speed with given values
|
2020-04-18 11:12:47 +02:00
|
|
|
minetest.register_chatcommand("set_wind", {
|
2023-10-19 04:54:02 +02:00
|
|
|
params = S("<wind>"),
|
2020-05-29 21:52:45 +02:00
|
|
|
description = S("Override the weather algorithm's windspeed"),
|
2020-04-18 11:12:47 +02:00
|
|
|
privs = { weather = true },
|
|
|
|
func = function(playername, param)
|
|
|
|
if param == nil or param == "" then
|
2020-05-29 21:52:45 +02:00
|
|
|
minetest.chat_send_player(playername, S("Provide a vector of two numbers to modify the wind"))
|
2020-04-18 11:12:47 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
local arguments = {}
|
|
|
|
for w in param:gmatch("%S+") do table.insert(arguments, w) end
|
2020-05-16 16:19:28 +02:00
|
|
|
local arg1 = arguments[1]
|
|
|
|
local wind_x = tonumber(arguments[1])
|
|
|
|
local wind_z = tonumber(arguments[2])
|
|
|
|
if arg1 == "auto" then
|
2020-05-13 16:03:28 +02:00
|
|
|
climate_mod.forced_enviroment.wind = nil
|
2020-05-29 21:52:45 +02:00
|
|
|
minetest.chat_send_player(playername, S("Wind reset"))
|
2020-05-13 16:03:28 +02:00
|
|
|
elseif wind_x == nil or wind_z == nil then
|
2020-05-29 21:52:45 +02:00
|
|
|
minetest.chat_send_player(playername, S("Invalid wind configuration"))
|
2020-04-18 11:12:47 +02:00
|
|
|
else
|
2020-05-13 16:03:28 +02:00
|
|
|
climate_mod.forced_enviroment.wind = vector.new({
|
2020-05-16 16:19:28 +02:00
|
|
|
x = wind_x,
|
2020-04-18 11:12:47 +02:00
|
|
|
y = 0,
|
2020-05-16 16:19:28 +02:00
|
|
|
z = wind_z
|
2020-04-18 11:12:47 +02:00
|
|
|
})
|
2020-05-29 21:52:45 +02:00
|
|
|
minetest.chat_send_player(playername, S("Wind changed"))
|
2020-04-18 11:12:47 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2020-04-26 18:11:38 +02:00
|
|
|
-- display current mod config
|
2020-04-14 05:44:46 +02:00
|
|
|
minetest.register_chatcommand("weather_settings", {
|
2020-05-29 21:52:45 +02:00
|
|
|
description = S("Print the active Climate API configuration"),
|
2020-04-14 05:44:46 +02:00
|
|
|
func = function(playername)
|
2020-05-29 21:52:45 +02:00
|
|
|
minetest.chat_send_player(playername, S("Current Settings") .. "\n================")
|
2020-04-14 05:44:46 +02:00
|
|
|
for setting, value in pairs(climate_mod.settings) do
|
|
|
|
minetest.chat_send_player(playername, dump2(value, setting))
|
|
|
|
end
|
|
|
|
end
|
2020-04-15 00:12:44 +02:00
|
|
|
})
|
|
|
|
|
2020-04-26 18:11:38 +02:00
|
|
|
-- force a weather preset or disable it
|
2020-04-15 00:12:44 +02:00
|
|
|
minetest.register_chatcommand("set_weather", {
|
2023-10-19 04:54:02 +02:00
|
|
|
params = S("<weather> <status>"),
|
2020-05-29 21:52:45 +02:00
|
|
|
description = S("Turn the specified weather preset on or off for all players or reset it to automatic"),
|
2020-04-15 00:12:44 +02:00
|
|
|
privs = { weather = true },
|
|
|
|
func = function(playername, param)
|
|
|
|
local arguments = {}
|
|
|
|
for w in param:gmatch("%S+") do table.insert(arguments, w) end
|
|
|
|
local weather = arguments[1]
|
2020-05-13 16:03:28 +02:00
|
|
|
if weather == nil or climate_mod.weathers[weather] == nil then
|
2020-05-29 21:52:45 +02:00
|
|
|
minetest.chat_send_player(playername, S("Unknown weather preset"))
|
2020-04-15 00:12:44 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
local status
|
2020-05-13 16:03:28 +02:00
|
|
|
if arguments[2] == nil or arguments[2] == "" then
|
|
|
|
arguments[2] = "on"
|
|
|
|
end
|
2020-04-15 00:12:44 +02:00
|
|
|
if arguments[2] == "on" then
|
|
|
|
status = true
|
|
|
|
elseif arguments[2] == "off" then
|
|
|
|
status = false
|
|
|
|
elseif arguments[2] == "auto" then
|
|
|
|
status = nil
|
|
|
|
else
|
2020-05-29 21:52:45 +02:00
|
|
|
minetest.chat_send_player(playername, S("Invalid weather status. Set the preset to either on, off or auto."))
|
2020-04-15 00:12:44 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
climate_mod.forced_weather[weather] = status
|
2020-05-31 23:15:37 +02:00
|
|
|
minetest.chat_send_player(playername, S("Weather @1 successfully set to @2", weather, arguments[2]))
|
2020-04-15 00:12:44 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2020-04-26 18:11:38 +02:00
|
|
|
-- list all weather presets and whether they have been forced or disabled
|
2020-04-15 00:12:44 +02:00
|
|
|
minetest.register_chatcommand("weather_status", {
|
2020-05-29 21:52:45 +02:00
|
|
|
description = S("Prints which weather presets are enforced or disabled"),
|
2020-04-15 00:12:44 +02:00
|
|
|
func = function(playername)
|
2020-05-29 21:52:45 +02:00
|
|
|
minetest.chat_send_player(playername, S("Current activation rules:") .. "\n================")
|
2020-04-15 00:12:44 +02:00
|
|
|
for weather, _ in pairs(climate_mod.weathers) do
|
|
|
|
local status = "auto"
|
|
|
|
if climate_mod.forced_weather[weather] == true then
|
|
|
|
status = "on"
|
|
|
|
elseif climate_mod.forced_weather[weather] == false then
|
|
|
|
status = "off"
|
|
|
|
end
|
|
|
|
minetest.chat_send_player(playername, dump2(status, weather))
|
|
|
|
end
|
|
|
|
end
|
2020-04-16 08:05:16 +02:00
|
|
|
})
|
2020-04-22 00:56:34 +02:00
|
|
|
|
2020-04-26 18:11:38 +02:00
|
|
|
-- show all environment influences and their values for the executing player
|
2020-04-22 00:56:34 +02:00
|
|
|
minetest.register_chatcommand("weather_influences", {
|
2020-05-29 21:52:45 +02:00
|
|
|
description = S("Prints which weather influences cause your current weather"),
|
2020-04-22 00:56:34 +02:00
|
|
|
func = function(playername)
|
2020-05-29 21:52:45 +02:00
|
|
|
minetest.chat_send_player(playername, S("Current influences rules:") .. "\n================")
|
2020-04-22 00:56:34 +02:00
|
|
|
local player = minetest.get_player_by_name(playername)
|
|
|
|
local influences = climate_mod.trigger.get_player_environment(player)
|
|
|
|
for influence, value in pairs(influences) do
|
|
|
|
minetest.chat_send_player(playername, dump2(value, influence))
|
|
|
|
end
|
|
|
|
end
|
2023-02-24 08:22:53 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
-- used to debug downfall
|
|
|
|
minetest.register_chatcommand("explain_humidity", {
|
2023-10-19 04:54:02 +02:00
|
|
|
description = S("Explains how the humidity value got calculated"),
|
2023-02-24 08:22:53 +01:00
|
|
|
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"))
|
|
|
|
end
|
2023-10-19 04:54:02 +02:00
|
|
|
})
|