mirror of
https://github.com/t-affeldt/climate_api.git
synced 2024-12-23 01:10:35 +01:00
Replace weather types with stackable effects
This commit is contained in:
parent
f16171cfd7
commit
3581ad71cb
@ -3,6 +3,6 @@
|
|||||||
- Thunder sound and puddle texture DWYWPL by Don, Nathan from mymonths at https://github.com/minetest-mods/mymonths
|
- Thunder sound and puddle texture DWYWPL by Don, Nathan from mymonths at https://github.com/minetest-mods/mymonths
|
||||||
- Snow cover texture WTFPL, taken from mymonths
|
- Snow cover texture WTFPL, taken from mymonths
|
||||||
- Rain texture CC-BY-SA 3.0 from TeddyDesTodes, taken from his weather branch at https://github.com/TeddyDesTodes/minetest/tree/weather
|
- Rain texture CC-BY-SA 3.0 from TeddyDesTodes, taken from his weather branch at https://github.com/TeddyDesTodes/minetest/tree/weather
|
||||||
- Snow flake textures CC BY-SA (3.0) by paramat, found in snowdrift mod at https://github.com/paramat/snowdrift
|
- Snow flake and rain drop textures CC BY-SA (3.0) by paramat, found in snowdrift mod at https://github.com/paramat/snowdrift
|
||||||
- Snow texture composited from individual snow flakes by paramat. CC-BY-SA (3.0)
|
- Snow texture composited from individual snow flakes by paramat. CC-BY-SA (3.0)
|
||||||
- Wind sound CC-BY (3.0) by InspectorJ from https://freesound.org/people/InspectorJ/sounds/376415/
|
- Wind sound CC-BY (3.0) by InspectorJ from https://freesound.org/people/InspectorJ/sounds/376415/
|
12
init.lua
12
init.lua
@ -34,21 +34,23 @@ weather_mod.settings = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
weather_mod.state = {
|
weather_mod.state = {
|
||||||
current_weather = weather_mod.modname .. ":snowstorm",
|
|
||||||
heat = 1,
|
heat = 1,
|
||||||
humidity = 1
|
humidity = 1,
|
||||||
|
wind = vector.new(0, 0, -0.25)
|
||||||
}
|
}
|
||||||
|
|
||||||
-- import core API
|
-- import core API
|
||||||
dofile(weather_mod.modpath.."/lib/player.lua")
|
dofile(weather_mod.modpath.."/lib/player.lua")
|
||||||
dofile(weather_mod.modpath.."/lib/environment.lua")
|
dofile(weather_mod.modpath.."/lib/environment.lua")
|
||||||
|
dofile(weather_mod.modpath.."/lib/wind.lua")
|
||||||
dofile(weather_mod.modpath.."/lib/lightning.lua")
|
dofile(weather_mod.modpath.."/lib/lightning.lua")
|
||||||
dofile(weather_mod.modpath.."/lib/main.lua")
|
dofile(weather_mod.modpath.."/lib/main.lua")
|
||||||
|
dofile(weather_mod.modpath.."/lib/commands.lua")
|
||||||
|
|
||||||
-- import individual weather types
|
-- import individual weather types
|
||||||
dofile(weather_mod.modpath.."/weathers/clear.lua")
|
|
||||||
dofile(weather_mod.modpath.."/weathers/rain.lua")
|
dofile(weather_mod.modpath.."/weathers/rain.lua")
|
||||||
dofile(weather_mod.modpath.."/weathers/rainstorm.lua")
|
dofile(weather_mod.modpath.."/weathers/rain_heavy.lua")
|
||||||
dofile(weather_mod.modpath.."/weathers/snow.lua")
|
dofile(weather_mod.modpath.."/weathers/snow.lua")
|
||||||
dofile(weather_mod.modpath.."/weathers/snowstorm.lua")
|
dofile(weather_mod.modpath.."/weathers/snow_heavy.lua")
|
||||||
|
dofile(weather_mod.modpath.."/weathers/storm.lua")
|
||||||
dofile(weather_mod.modpath.."/weathers/sandstorm.lua")
|
dofile(weather_mod.modpath.."/weathers/sandstorm.lua")
|
||||||
|
87
lib/commands.lua
Normal file
87
lib/commands.lua
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
minetest.register_privilege("weather", {
|
||||||
|
description = "Change the weather",
|
||||||
|
give_to_singleplayer = false
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Force a weather effect to override environment
|
||||||
|
minetest.register_chatcommand("set_weather", {
|
||||||
|
params = "<weather>",
|
||||||
|
description = "Set weather to a registered type of effect\
|
||||||
|
show all types when no parameters are given", -- full description
|
||||||
|
privs = {weather = true},
|
||||||
|
func = function(name, param)
|
||||||
|
if param == nil or param == "" or param == "?" then
|
||||||
|
local types="auto"
|
||||||
|
for i,_ in pairs(weather_mod.weathers) do
|
||||||
|
types=types..", "..i
|
||||||
|
end
|
||||||
|
minetest.chat_send_player(name, "avalible weather types: "..types)
|
||||||
|
else
|
||||||
|
if type(weather_mod.weathers[param]) == "nil" and param ~= "auto" then
|
||||||
|
minetest.chat_send_player(name, "This type of weather is not registered.\n"..
|
||||||
|
"To list all types of weather run the command without parameters.")
|
||||||
|
else
|
||||||
|
weather_mod.state.current_weather = param
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Set wind speed and direction
|
||||||
|
minetest.register_chatcommand("set_wind", {
|
||||||
|
params = "<weather>",
|
||||||
|
description = "Set wind to the given x,z direction", -- full description
|
||||||
|
privs = {weather = true},
|
||||||
|
func = function(name, param)
|
||||||
|
if param==nil or param=="" then
|
||||||
|
minetest.chat_send_player(name, "please provide two comma seperated numbers")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local x,z = string.match(param, "^([%d.-]+)[, ] *([%d.-]+)$")
|
||||||
|
x=tonumber(x)
|
||||||
|
z=tonumber(z)
|
||||||
|
if x and z then
|
||||||
|
weather_mod.state.wind = vector.new(x,0,z)
|
||||||
|
else
|
||||||
|
minetest.chat_send_player(name, param.." are not two comma seperated numbers")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Set base value of global heat level
|
||||||
|
minetest.register_chatcommand("set_heat", {
|
||||||
|
params = "<weather>",
|
||||||
|
description = "Set base value of global heat level", -- full description
|
||||||
|
privs = {weather = true},
|
||||||
|
func = function(name, param)
|
||||||
|
if param==nil or param=="" then
|
||||||
|
minetest.chat_send_player(name, "please provide a heat value")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
v = tonumber(param)
|
||||||
|
if v then
|
||||||
|
weather_mod.state.heat = v
|
||||||
|
else
|
||||||
|
minetest.chat_send_player(name, param.." is not a valid heat level")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Set base value of global humidity level
|
||||||
|
minetest.register_chatcommand("set_humidity", {
|
||||||
|
params = "<weather>",
|
||||||
|
description = "Set base value of global humidity level", -- full description
|
||||||
|
privs = {weather = true},
|
||||||
|
func = function(name, param)
|
||||||
|
if param==nil or param=="" then
|
||||||
|
minetest.chat_send_player(name, "please provide a humidity value")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
v = tonumber(param)
|
||||||
|
if v then
|
||||||
|
weather_mod.state.humidity = v
|
||||||
|
else
|
||||||
|
minetest.chat_send_player(name, param.." is not a valid humidity level")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
@ -13,50 +13,47 @@ function weather_mod.get_humidity(pos)
|
|||||||
return (base + biome) * random
|
return (base + biome) * random
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function weather_mod.get_climate(pos)
|
||||||
|
local climate = {pos = pos}
|
||||||
|
climate.heat = weather_mod.get_heat(pos)
|
||||||
|
climate.humidity = weather_mod.get_humidity(pos)
|
||||||
|
climate.windspeed = vector.length(weather_mod.state.wind)
|
||||||
|
return climate
|
||||||
|
end
|
||||||
|
|
||||||
local function is_acceptable_weather_param(value, attr, config)
|
local function is_acceptable_weather_param(value, attr, config)
|
||||||
local min = config.conditions["min_" .. attr] or -10000
|
local min = config.conditions["min_" .. attr] or -math.huge
|
||||||
local max = config.conditions["max_" .. attr] or math.huge
|
local max = config.conditions["max_" .. attr] or math.huge
|
||||||
minetest.log(attr .. ": " .. value .. " <=> " .. min .. "," .. max)
|
|
||||||
return value > min and value <= max
|
return value > min and value <= max
|
||||||
end
|
end
|
||||||
|
|
||||||
function weather_mod.get_weather(pos, wind)
|
function weather_mod.get_effects(climate)
|
||||||
|
local forced_weather = weather_mod.state.current_weather
|
||||||
|
if type(forced_weather) ~= nil and forced_weather ~= "auto" then
|
||||||
|
return { forced_weather }
|
||||||
|
end
|
||||||
local params = {}
|
local params = {}
|
||||||
params.heat = weather_mod.get_heat(pos)
|
params.heat = climate.heat
|
||||||
params.humidity = weather_mod.get_humidity(pos)
|
params.humidity = climate.humidity
|
||||||
params.windspeed = vector.length(wind)
|
params.windspeed = vector.length(weather_mod.state.wind)
|
||||||
minetest.log(params.heat .. ", " .. params.humidity .. ", " .. params.windspeed)
|
params.height = climate.pos.y
|
||||||
|
|
||||||
local weather
|
local effects = {}
|
||||||
local priority = -1
|
local attributes = { "heat", "humidity", "windspeed", "height" }
|
||||||
local attributes = { "heat", "humidity", "windspeed" }
|
for name, effect in pairs(weather_mod.weathers) do
|
||||||
for name, config in pairs(weather_mod.weathers) do
|
if type(effect.config.conditions) == "nil" then
|
||||||
minetest.log(dump2(priority, "p"))
|
table.insert(effects, name)
|
||||||
if type(priority) ~= "nil" and config.priority < priority then
|
goto continue
|
||||||
minetest.log("skipped " .. name)
|
end
|
||||||
|
|
||||||
elseif type(config.conditions) == "nil" then
|
|
||||||
weather = name
|
|
||||||
priority = config.priority
|
|
||||||
minetest.log("selected (nil) " .. name)
|
|
||||||
|
|
||||||
else
|
|
||||||
local check = true
|
|
||||||
for _, attr in ipairs(attributes) do
|
for _, attr in ipairs(attributes) do
|
||||||
if not is_acceptable_weather_param(params[attr], attr, config) then
|
if not is_acceptable_weather_param(params[attr], attr, effect.config) then
|
||||||
check = false
|
goto continue
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if check then
|
table.insert(effects, name)
|
||||||
weather = name
|
::continue::
|
||||||
priority = config.priority
|
|
||||||
minetest.log("selected " .. name)
|
|
||||||
end
|
end
|
||||||
end
|
minetest.log(dump2(effects, "effects"))
|
||||||
end
|
return effects
|
||||||
if type(weather) == "nil" then
|
|
||||||
minetest.log("error", "[Believable Weather] No default weather registered")
|
|
||||||
end
|
|
||||||
minetest.log(weather)
|
|
||||||
return weather
|
|
||||||
end
|
end
|
119
lib/main.lua
119
lib/main.lua
@ -1,28 +1,33 @@
|
|||||||
local GSCYCLE = 0
|
local GSCYCLE = 0.05
|
||||||
local temperature = 10
|
local RECALCCYCLE = 1
|
||||||
local humidity = 100
|
|
||||||
local wind = vector.new(10, 0, -0.25)
|
|
||||||
|
|
||||||
weather_mod.weathers = {}
|
weather_mod.weathers = {}
|
||||||
function weather_mod.register_weather(name, weather)
|
function weather_mod.register_effect(name, config, override)
|
||||||
-- TODO: check and sanitize
|
-- TODO: check and sanitize
|
||||||
weather_mod.weathers[name] = weather
|
weather_mod.weathers[name] = {
|
||||||
|
config = config,
|
||||||
|
override = override,
|
||||||
|
sound_handles = {},
|
||||||
|
sound_volumes = {}
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
function weather_mod.set_weather(name)
|
-- from https://stackoverflow.com/a/29133654
|
||||||
if type(weather_mod.weathers[name]) == nil then
|
local function merge(a, b)
|
||||||
minetest.log("warning", "[Believable Weather] Weather does not exist")
|
if type(a) == 'table' and type(b) == 'table' then
|
||||||
return
|
for k,v in pairs(b) do if type(v)=='table' and type(a[k] or false)=='table' then merge(a[k],v) else a[k]=v end end
|
||||||
end
|
end
|
||||||
weather_mod.state.current_weather = name
|
return a
|
||||||
end
|
end
|
||||||
|
|
||||||
local function is_outside(player, wind)
|
local function build_effect_config(weather, climate)
|
||||||
local ppos = player:getpos()
|
local config = weather.config
|
||||||
local wind_pos = vector.multiply(wind,-1)
|
local override = weather.override
|
||||||
local skylight_pos = vector.add(ppos, vector.new(0, 40, 0))
|
if type(override) == "nil" then
|
||||||
local downfall_origin = vector.add(skylight_pos,wind_pos)
|
return config
|
||||||
return weather_mod.is_outdoors(player, downfall_origin)
|
end
|
||||||
|
local dynamic_config = override(climate)
|
||||||
|
return merge(config, dynamic_config)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_texture(particles)
|
local function get_texture(particles)
|
||||||
@ -34,19 +39,23 @@ end
|
|||||||
|
|
||||||
local function spawn_particles(player, particles, wind)
|
local function spawn_particles(player, particles, wind)
|
||||||
local ppos = player:getpos()
|
local ppos = player:getpos()
|
||||||
local wind_pos = vector.multiply(wind,-1)
|
local wind_pos = vector.multiply(weather_mod.state.wind,-1)
|
||||||
local wind_speed = vector.length(wind)
|
local wind_speed = vector.length(weather_mod.state.wind)
|
||||||
|
|
||||||
local texture = get_texture(particles)
|
local texture = get_texture(particles)
|
||||||
|
|
||||||
local minp = vector.add(vector.add(ppos, particles.min_pos),wind_pos)
|
local minp = vector.add(vector.add(ppos, particles.min_pos),wind_pos)
|
||||||
local maxp = vector.add(vector.add(ppos, particles.max_pos),wind_pos)
|
local maxp = vector.add(vector.add(ppos, particles.max_pos),wind_pos)
|
||||||
|
|
||||||
local vel = {x=wind.x,y=-particles.falling_speed,z=wind.z}
|
local vel = vector.new({
|
||||||
local acc = {x=0, y=0, z=0}
|
x=weather_mod.state.wind.x,
|
||||||
|
y=-particles.falling_speed,
|
||||||
|
z=weather_mod.state.wind.z
|
||||||
|
})
|
||||||
|
local acc = vector.new({x=0, y=0, z=0})
|
||||||
|
|
||||||
local exp = particles.exptime
|
local exp = particles.exptime
|
||||||
local vertical = wind_speed < 3
|
local vertical = math.abs(vector.normalize(vel).y) >= 0.6
|
||||||
|
|
||||||
minetest.add_particlespawner({
|
minetest.add_particlespawner({
|
||||||
amount=particles.amount,
|
amount=particles.amount,
|
||||||
@ -69,62 +78,36 @@ local function spawn_particles(player, particles, wind)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
local sound_handles = {}
|
local function handle_weather_effects(player)
|
||||||
local function play_sound(player, sound)
|
|
||||||
local playername = player:get_player_name()
|
|
||||||
if not sound_handles[playername] then
|
|
||||||
local handle = minetest.sound_play(sound, {
|
|
||||||
to_player = playername,
|
|
||||||
loop = true
|
|
||||||
})
|
|
||||||
if handle then
|
|
||||||
sound_handles[playername] = handle
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function stop_sound(player)
|
|
||||||
local playername = player:get_player_name()
|
|
||||||
if sound_handles[playername] then
|
|
||||||
minetest.sound_stop(sound_handles[playername])
|
|
||||||
sound_handles[playername] = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function handle_weather()
|
|
||||||
for _, player in ipairs(minetest.get_connected_players()) do
|
|
||||||
local ppos = player:getpos()
|
local ppos = player:getpos()
|
||||||
weather_mod.set_weather(weather_mod.get_weather(ppos, wind))
|
local climate = weather_mod.get_climate(ppos)
|
||||||
|
local active_effects = weather_mod.get_effects(climate)
|
||||||
|
local sounds = {}
|
||||||
|
|
||||||
if ppos.y < weather_mod.settings.min_height or ppos.y > weather_mod.settings.max_height then
|
for _, effect in ipairs(active_effects) do
|
||||||
return
|
local weather = weather_mod.weathers[effect]
|
||||||
|
local config = build_effect_config(weather, climate)
|
||||||
|
|
||||||
|
local outdoors = weather_mod.is_outdoors(player)
|
||||||
|
if type(config.particles) ~= "nil" and outdoors then
|
||||||
|
spawn_particles(player, config.particles, wind)
|
||||||
end
|
end
|
||||||
|
if type(config.sound) ~= nil and outdoors then
|
||||||
local weather = weather_mod.weathers[weather_mod.state.current_weather]
|
sounds[effect] = config.sound
|
||||||
local clouds = weather.clouds
|
|
||||||
clouds.speed = vector.multiply(wind, 2)
|
|
||||||
player:set_clouds(clouds)
|
|
||||||
|
|
||||||
weather_mod.set_headwind(player, wind)
|
|
||||||
--player:set_clouds({ density = 0.6, color = "#a4a0b6e5", speed = wind })
|
|
||||||
|
|
||||||
local outdoors = is_outside(player, wind)
|
|
||||||
if type(weather.particles) ~= "nil" and outdoors then
|
|
||||||
spawn_particles(player, weather.particles, wind)
|
|
||||||
end
|
|
||||||
|
|
||||||
if type(weather.sound) ~= "nil" and outdoors then
|
|
||||||
play_sound(player, weather.sound)
|
|
||||||
else
|
|
||||||
stop_sound(player)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
weather_mod.handle_sounds(player, sounds)
|
||||||
end
|
end
|
||||||
|
|
||||||
local timer = 0
|
local timer = 0
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
timer = timer + dtime
|
timer = timer + dtime
|
||||||
if timer < GSCYCLE then return end
|
if timer < GSCYCLE then return end
|
||||||
|
for _, player in ipairs(minetest.get_connected_players()) do
|
||||||
|
handle_weather_effects(player)
|
||||||
|
if timer >= RECALCCYCLE then
|
||||||
|
weather_mod.set_clouds(player)
|
||||||
|
end
|
||||||
|
end
|
||||||
timer = 0
|
timer = 0
|
||||||
handle_weather()
|
|
||||||
end)
|
end)
|
@ -27,46 +27,58 @@ function weather_mod.remove_physics(player, effect)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- function taken from weather mod
|
function weather_mod.is_outdoors(player)
|
||||||
-- see https://github.com/theFox6/minetest_mod_weather/blob/master/weather/api.lua#L110
|
|
||||||
local function raycast(player, origin)
|
|
||||||
local hitpos = vector.add(player:get_pos(),vector.new(0,1,0))
|
|
||||||
local ray = minetest.raycast(origin,hitpos)
|
|
||||||
local o = ray:next()
|
|
||||||
if not o then return false end
|
|
||||||
if o.type~="object" then return false end -- hit node or something
|
|
||||||
if not o.ref:is_player() then return false end -- hit different object
|
|
||||||
if o.ref:get_player_name() ~= player:get_player_name() then
|
|
||||||
return false --hit other player
|
|
||||||
end
|
|
||||||
o = ray:next()
|
|
||||||
if o then
|
|
||||||
minetest.log("warning","[Believable Weather] raycast hit more after hitting the player\n"..
|
|
||||||
dump2(o,"o"))
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
local function check_light(player)
|
|
||||||
return minetest.get_node_light(player:getpos(), 0.5) == 15
|
return minetest.get_node_light(player:getpos(), 0.5) == 15
|
||||||
end
|
end
|
||||||
|
|
||||||
function weather_mod.is_outdoors(player, origin)
|
function weather_mod.set_clouds(player)
|
||||||
if weather_mod.settings.raycasting then
|
if not weather_mod.settings.skybox then
|
||||||
return raycast(player, origin)
|
return
|
||||||
else
|
end
|
||||||
return check_light(player)
|
local ppos = player:get_pos()
|
||||||
|
local humidity = weather_mod.get_humidity(ppos) / 200
|
||||||
|
local clouds = {}
|
||||||
|
clouds.speed = vector.multiply(weather_mod.state.wind, 2)
|
||||||
|
clouds.color = "#fff0f0c5"
|
||||||
|
clouds.density = math.max(math.min(humidity, 0.1), 0.9)
|
||||||
|
player:set_clouds(clouds)
|
||||||
|
end
|
||||||
|
|
||||||
|
function weather_mod.play_sound(player, effect)
|
||||||
|
local playername = player:get_player_name()
|
||||||
|
if not effect.sound_handles[playername] then
|
||||||
|
local handle = minetest.sound_play(effect.config.sound, {
|
||||||
|
to_player = playername,
|
||||||
|
loop = true
|
||||||
|
})
|
||||||
|
if handle then
|
||||||
|
effect.sound_handles[playername] = handle
|
||||||
|
effect.sound_volumes[playername] = effect.config.sound.gain or 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function weather_mod.set_headwind(player, wind)
|
function weather_mod.stop_sound(player, effect)
|
||||||
local movement = vector.normalize(player:get_player_velocity())
|
local playername = player:get_player_name()
|
||||||
local product = vector.dot(movement, wind)
|
if effect.sound_handles[playername] then
|
||||||
-- logistic function, scales between 0 and 2
|
minetest.sound_stop(effect.sound_handles[playername])
|
||||||
-- see https://en.wikipedia.org/wiki/Logistic_function
|
effect.sound_handles[playername] = nil
|
||||||
local L = 2 -- maximum value
|
effect.sound_volumes[playername] = nil
|
||||||
local k = 0.1 -- growth rate
|
end
|
||||||
local z = 1 -- midpoint
|
end
|
||||||
local factor = L / (1 + math.exp(-k * (product - z)))
|
|
||||||
weather_mod.add_physics(player, "speed", factor)
|
function weather_mod.handle_sounds(player, sounds)
|
||||||
|
local playername = player:get_player_name()
|
||||||
|
for name, effect in pairs(weather_mod.weathers) do
|
||||||
|
if type(effect.sound_handles[playername]) == "nil" and type(sounds[name]) ~= "nil" then
|
||||||
|
weather_mod.play_sound(player, effect)
|
||||||
|
elseif type(effect.sound_handles[playername]) ~= "nil" and type(sounds[name]) == "nil" then
|
||||||
|
weather_mod.stop_sound(player, effect)
|
||||||
|
elseif type(effect.sound_handles[playername]) ~= "nil" and type(sounds[name]) ~= "nil" then
|
||||||
|
local volume = sounds[name].gain or 1
|
||||||
|
if effect.sound_volumes[playername] ~= volume then
|
||||||
|
minetest.sound_fade(effect.sound_handles[playername], 1, volume)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
8
lib/wind.lua
Normal file
8
lib/wind.lua
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
function weather_mod.set_headwind(player, wind)
|
||||||
|
local movement = vector.normalize(player:get_player_velocity())
|
||||||
|
local product = vector.dot(movement, wind)
|
||||||
|
-- logistic function, scales between 0.5 and 1.5
|
||||||
|
-- see https://en.wikipedia.org/wiki/Logistic_function
|
||||||
|
local factor = 1 / (1 + math.exp(-0.1 * (product - 0.5))) + 0.5
|
||||||
|
weather_mod.add_physics(player, "speed", factor)
|
||||||
|
end
|
Binary file not shown.
BIN
textures/weather_raindrop.png
Normal file
BIN
textures/weather_raindrop.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 148 B |
@ -1,12 +0,0 @@
|
|||||||
local name = weather_mod.modname .. ":clear"
|
|
||||||
|
|
||||||
local weather = {
|
|
||||||
priority = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
weather.clouds = {
|
|
||||||
density = 0.3,
|
|
||||||
color = "#fff0f0c5"
|
|
||||||
}
|
|
||||||
|
|
||||||
weather_mod.register_weather(name, weather)
|
|
@ -1,30 +1,48 @@
|
|||||||
local name = weather_mod.modname .. ":rain"
|
local name = weather_mod.modname .. ":rain"
|
||||||
|
|
||||||
local weather = {
|
local config = {}
|
||||||
priority = 10,
|
|
||||||
|
config.environment = {
|
||||||
spawn_puddles = true,
|
spawn_puddles = true,
|
||||||
wetten_farmland = true,
|
wetten_farmland = true
|
||||||
sound = "weather_rain1"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
weather.particles = {
|
config.sound = {
|
||||||
|
name = "weather_rain",
|
||||||
|
gain = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
config.particles = {
|
||||||
min_pos = {x=-9, y=7, z=-9},
|
min_pos = {x=-9, y=7, z=-9},
|
||||||
max_pos = {x= 9, y=7, z= 9},
|
max_pos = {x= 9, y=7, z= 9},
|
||||||
falling_speed=10,
|
falling_speed=10,
|
||||||
amount=20,
|
amount=40,
|
||||||
exptime=0.8,
|
exptime=0.8,
|
||||||
size=25,
|
size=1,
|
||||||
texture="weather_rain.png"
|
texture = "weather_raindrop.png"
|
||||||
}
|
}
|
||||||
|
|
||||||
weather.clouds = {
|
config.conditions = {
|
||||||
density = 0.5,
|
min_height = weather_mod.settings.min_height,
|
||||||
color = "#a4a0b6e5"
|
max_height = weather_mod.settings.max_height,
|
||||||
}
|
|
||||||
|
|
||||||
weather.conditions = {
|
|
||||||
min_heat = 30,
|
min_heat = 30,
|
||||||
min_humidity = 40
|
min_humidity = 40,
|
||||||
|
max_humidity = 60
|
||||||
}
|
}
|
||||||
|
|
||||||
weather_mod.register_weather(name, weather)
|
local function override(params)
|
||||||
|
local avg_humidity = 40
|
||||||
|
local intensity = params.humidity / avg_humidity
|
||||||
|
local dynamic_config = {
|
||||||
|
sound = {
|
||||||
|
gain = math.min(intensity, 1.2)
|
||||||
|
},
|
||||||
|
particles = {
|
||||||
|
amount = 20 * math.min(intensity, 1.5),
|
||||||
|
falling_speed = 10 / math.min(intensity, 1.3)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dynamic_config
|
||||||
|
end
|
||||||
|
|
||||||
|
weather_mod.register_effect(name, config, override)
|
||||||
|
33
weathers/rain_heavy.lua
Normal file
33
weathers/rain_heavy.lua
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
local name = weather_mod.modname .. ":rain_heavy"
|
||||||
|
|
||||||
|
local config = {}
|
||||||
|
|
||||||
|
config.environment = {
|
||||||
|
spawn_puddles = true,
|
||||||
|
wetten_farmland = true,
|
||||||
|
lightning = true
|
||||||
|
}
|
||||||
|
|
||||||
|
config.sound = {
|
||||||
|
name = "weather_rain",
|
||||||
|
gain = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
config.particles = {
|
||||||
|
min_pos = {x=-9, y=7, z=-9},
|
||||||
|
max_pos = {x= 9, y=7, z= 9},
|
||||||
|
falling_speed=10,
|
||||||
|
amount=20,
|
||||||
|
exptime=0.8,
|
||||||
|
size=25,
|
||||||
|
texture="weather_rain.png"
|
||||||
|
}
|
||||||
|
|
||||||
|
config.conditions = {
|
||||||
|
min_height = weather_mod.settings.min_height,
|
||||||
|
max_height = weather_mod.settings.max_height,
|
||||||
|
min_heat = 30,
|
||||||
|
min_humidity = 60
|
||||||
|
}
|
||||||
|
|
||||||
|
weather_mod.register_effect(name, config)
|
@ -1,33 +0,0 @@
|
|||||||
local name = weather_mod.modname .. ":rainstorm"
|
|
||||||
|
|
||||||
local weather = {
|
|
||||||
priority = 30,
|
|
||||||
damage = true,
|
|
||||||
spawn_puddles = true,
|
|
||||||
wetten_farmland = true,
|
|
||||||
lightning = true,
|
|
||||||
sound = "weather_rain2"
|
|
||||||
}
|
|
||||||
|
|
||||||
weather.particles = {
|
|
||||||
min_pos = {x=-9, y=7, z=-9},
|
|
||||||
max_pos = {x= 9, y=7, z= 9},
|
|
||||||
falling_speed=10,
|
|
||||||
amount=25,
|
|
||||||
exptime=0.8,
|
|
||||||
size=25,
|
|
||||||
texture="weather_rain.png"
|
|
||||||
}
|
|
||||||
|
|
||||||
weather.clouds = {
|
|
||||||
density = 0.7,
|
|
||||||
color = "#a4a0b6f5"
|
|
||||||
}
|
|
||||||
|
|
||||||
weather.conditions = {
|
|
||||||
min_heat = 30,
|
|
||||||
min_humidity = 60,
|
|
||||||
min_windspeed = 5
|
|
||||||
}
|
|
||||||
|
|
||||||
weather_mod.register_weather(name, weather)
|
|
@ -1,12 +1,12 @@
|
|||||||
local name = weather_mod.modname .. ":sandstorm"
|
local name = weather_mod.modname .. ":sandstorm"
|
||||||
|
|
||||||
local weather = {
|
local config = {}
|
||||||
priority = 50,
|
|
||||||
damage = true,
|
config.environment = {
|
||||||
sound = "weather_wind"
|
damage = true
|
||||||
}
|
}
|
||||||
|
|
||||||
weather.particles = {
|
config.particles = {
|
||||||
min_pos = {x=-9, y=-5, z=-9},
|
min_pos = {x=-9, y=-5, z=-9},
|
||||||
max_pos = {x= 9, y= 5, z= 9},
|
max_pos = {x= 9, y= 5, z= 9},
|
||||||
falling_speed=1,
|
falling_speed=1,
|
||||||
@ -16,15 +16,12 @@ weather.particles = {
|
|||||||
texture="weather_sand.png"
|
texture="weather_sand.png"
|
||||||
}
|
}
|
||||||
|
|
||||||
weather.clouds = {
|
config.conditions = {
|
||||||
density = 0.3,
|
min_height = weather_mod.settings.min_height,
|
||||||
color = "#a4a0b685"
|
max_height = weather_mod.settings.max_height,
|
||||||
}
|
|
||||||
|
|
||||||
weather.conditions = {
|
|
||||||
min_heat = 50,
|
min_heat = 50,
|
||||||
max_humidity = 25,
|
max_humidity = 25,
|
||||||
min_windspeed = 6
|
min_windspeed = 6
|
||||||
}
|
}
|
||||||
|
|
||||||
weather_mod.register_weather(name, weather)
|
weather_mod.register_effect(name, config)
|
||||||
|
@ -1,32 +1,46 @@
|
|||||||
local name = weather_mod.modname .. ":snow"
|
local name = weather_mod.modname .. ":snow"
|
||||||
|
|
||||||
local weather = {
|
local config = {}
|
||||||
priority = 20,
|
|
||||||
|
config.environment = {
|
||||||
spawn_snow = true
|
spawn_snow = true
|
||||||
}
|
}
|
||||||
|
|
||||||
weather.particles = {
|
config.particles = {
|
||||||
min_pos = {x=-20, y= 3, z=-20},
|
min_pos = {x=-20, y= 3, z=-20},
|
||||||
max_pos = {x= 20, y=12, z= 20},
|
max_pos = {x= 20, y=12, z= 20},
|
||||||
falling_speed=1,
|
falling_speed=1,
|
||||||
amount=50,
|
amount=40,
|
||||||
exptime=15,
|
exptime=8,
|
||||||
size=1,
|
size=1,
|
||||||
textures = {}
|
textures = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
for i = 1,12,1 do
|
for i = 1,12,1 do
|
||||||
weather.particles.textures[i] = "weather_snowflake" .. i .. ".png"
|
config.particles.textures[i] = "weather_snowflake" .. i .. ".png"
|
||||||
end
|
end
|
||||||
|
|
||||||
weather.clouds = {
|
config.conditions = {
|
||||||
density = 0.5,
|
min_height = weather_mod.settings.min_height,
|
||||||
color = "#a4a0b6e5"
|
max_height = weather_mod.settings.max_height,
|
||||||
|
max_heat = 40,
|
||||||
|
min_humidity = 40,
|
||||||
|
max_humidity = 55
|
||||||
}
|
}
|
||||||
|
|
||||||
weather.conditions = {
|
local function override(params)
|
||||||
max_heat = 30,
|
local avg_humidity = 40
|
||||||
min_humidity = 40
|
local intensity = params.humidity / avg_humidity
|
||||||
|
local dynamic_config = {
|
||||||
|
sound = {
|
||||||
|
gain = math.min(intensity, 1.2)
|
||||||
|
},
|
||||||
|
particles = {
|
||||||
|
amount = 50 * math.min(intensity, 1.5),
|
||||||
|
falling_speed = 1 / math.min(intensity, 1.3)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return dynamic_config
|
||||||
|
end
|
||||||
|
|
||||||
weather_mod.register_weather(name, weather)
|
weather_mod.register_effect(name, config, override)
|
||||||
|
41
weathers/snow_heavy.lua
Normal file
41
weathers/snow_heavy.lua
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
local name = weather_mod.modname .. ":snow_heavy"
|
||||||
|
|
||||||
|
local config = {}
|
||||||
|
|
||||||
|
config.environment = {
|
||||||
|
spawn_snow = true
|
||||||
|
}
|
||||||
|
|
||||||
|
config.particles = {
|
||||||
|
min_pos = {x=-12, y= 5, z=-12},
|
||||||
|
max_pos = {x= 12, y=9, z= 12},
|
||||||
|
falling_speed=1,
|
||||||
|
amount=1,
|
||||||
|
exptime=8,
|
||||||
|
size=12,
|
||||||
|
texture="weather_snow.png"
|
||||||
|
}
|
||||||
|
|
||||||
|
config.conditions = {
|
||||||
|
min_height = weather_mod.settings.min_height,
|
||||||
|
max_height = weather_mod.settings.max_height,
|
||||||
|
max_heat = 40,
|
||||||
|
min_humidity = 55
|
||||||
|
}
|
||||||
|
|
||||||
|
local function override(params)
|
||||||
|
local avg_humidity = 55
|
||||||
|
local intensity = params.humidity / avg_humidity
|
||||||
|
local dynamic_config = {
|
||||||
|
sound = {
|
||||||
|
gain = math.min(intensity, 1.2)
|
||||||
|
},
|
||||||
|
particles = {
|
||||||
|
amount = 50 * math.min(intensity, 1.5),
|
||||||
|
falling_speed = 1 / math.min(intensity, 1.3)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dynamic_config
|
||||||
|
end
|
||||||
|
|
||||||
|
weather_mod.register_effect(name, config, override)
|
@ -1,36 +0,0 @@
|
|||||||
local name = weather_mod.modname .. ":snowstorm"
|
|
||||||
|
|
||||||
local weather = {
|
|
||||||
priority = 40,
|
|
||||||
damage = true,
|
|
||||||
lightning = true,
|
|
||||||
spawn_snow = true,
|
|
||||||
sound = "weather_wind"
|
|
||||||
}
|
|
||||||
|
|
||||||
weather.particles = {
|
|
||||||
min_pos = {x=-9, y=-5, z=-9},
|
|
||||||
max_pos = {x= 9, y= 5, z= 9},
|
|
||||||
falling_speed=1.5,
|
|
||||||
amount=70,
|
|
||||||
exptime=6,
|
|
||||||
size=1,
|
|
||||||
textures = {}
|
|
||||||
}
|
|
||||||
|
|
||||||
for i = 1,12,1 do
|
|
||||||
weather.particles.textures[i] = "weather_snowflake" .. i .. ".png"
|
|
||||||
end
|
|
||||||
|
|
||||||
weather.clouds = {
|
|
||||||
density = 0.7,
|
|
||||||
color = "#a4a0b6f5"
|
|
||||||
}
|
|
||||||
|
|
||||||
weather.conditions = {
|
|
||||||
max_heat = 30,
|
|
||||||
min_humidity = 60,
|
|
||||||
min_windspeed = 5
|
|
||||||
}
|
|
||||||
|
|
||||||
weather_mod.register_weather(name, weather)
|
|
27
weathers/storm.lua
Normal file
27
weathers/storm.lua
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
local name = weather_mod.modname .. ":storm"
|
||||||
|
|
||||||
|
local config = {}
|
||||||
|
|
||||||
|
config.sound = {
|
||||||
|
name = "weather_wind",
|
||||||
|
gain = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
config.conditions = {
|
||||||
|
min_height = weather_mod.settings.min_height,
|
||||||
|
max_height = weather_mod.settings.max_height,
|
||||||
|
min_windspeed = 5
|
||||||
|
}
|
||||||
|
|
||||||
|
local function override(params)
|
||||||
|
local avg_windspeed = 6
|
||||||
|
local intensity = params.windspeed / avg_windspeed
|
||||||
|
local dynamic_config = {
|
||||||
|
sound = {
|
||||||
|
gain = math.min(intensity, 1.2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dynamic_config
|
||||||
|
end
|
||||||
|
|
||||||
|
weather_mod.register_effect(name, config, override)
|
Loading…
Reference in New Issue
Block a user