Add lightning, fix cloud size

This commit is contained in:
Till Affeldt 2020-04-09 20:25:02 +02:00
parent 3581ad71cb
commit dd73a0df17
7 changed files with 60 additions and 28 deletions

View File

@ -43,7 +43,6 @@ weather_mod.state = {
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/wind.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") dofile(weather_mod.modpath.."/lib/commands.lua")

View File

@ -29,7 +29,7 @@ minetest.register_chatcommand("set_weather", {
-- Set wind speed and direction -- Set wind speed and direction
minetest.register_chatcommand("set_wind", { minetest.register_chatcommand("set_wind", {
params = "<weather>", params = "<wind>",
description = "Set wind to the given x,z direction", -- full description description = "Set wind to the given x,z direction", -- full description
privs = {weather = true}, privs = {weather = true},
func = function(name, param) func = function(name, param)
@ -50,7 +50,7 @@ minetest.register_chatcommand("set_wind", {
-- Set base value of global heat level -- Set base value of global heat level
minetest.register_chatcommand("set_heat", { minetest.register_chatcommand("set_heat", {
params = "<weather>", params = "<heat>",
description = "Set base value of global heat level", -- full description description = "Set base value of global heat level", -- full description
privs = {weather = true}, privs = {weather = true},
func = function(name, param) func = function(name, param)
@ -69,7 +69,7 @@ minetest.register_chatcommand("set_heat", {
-- Set base value of global humidity level -- Set base value of global humidity level
minetest.register_chatcommand("set_humidity", { minetest.register_chatcommand("set_humidity", {
params = "<weather>", params = "<humidity>",
description = "Set base value of global humidity level", -- full description description = "Set base value of global humidity level", -- full description
privs = {weather = true}, privs = {weather = true},
func = function(name, param) func = function(name, param)

View File

@ -1,3 +1,10 @@
local mod_lightning = minetest.get_modpath("lightning")
local LIGHTNING_CHANCE = 1000
if mod_lightning then
lightning.auto = false
end
function weather_mod.get_heat(pos) function weather_mod.get_heat(pos)
local base = weather_mod.settings.heat; local base = weather_mod.settings.heat;
local biome = minetest.get_heat(pos) local biome = minetest.get_heat(pos)
@ -54,6 +61,18 @@ function weather_mod.get_effects(climate)
table.insert(effects, name) table.insert(effects, name)
::continue:: ::continue::
end end
minetest.log(dump2(effects, "effects"))
return effects return effects
end end
function weather_mod.handle_events(player, flags)
local ppos = player:get_pos()
if mod_lightning and weather_mod.settings.lightning and type(flags["lightning"]) ~= "nil" then
local random = rng:next(1, LIGHTNING_CHANCE)
if random == 1 then
lightning.strike(ppos)
end
end
if type(flags["damage"]) ~= "nil" then
weather_mod.damage_player(player, 1)
end
end

View File

@ -1,3 +0,0 @@
if minetest.get_modpath("lightning") then
lightning.auto = false
end

View File

@ -82,6 +82,7 @@ local function handle_weather_effects(player)
local ppos = player:getpos() local ppos = player:getpos()
local climate = weather_mod.get_climate(ppos) local climate = weather_mod.get_climate(ppos)
local active_effects = weather_mod.get_effects(climate) local active_effects = weather_mod.get_effects(climate)
local environment_flags = {}
local sounds = {} local sounds = {}
for _, effect in ipairs(active_effects) do for _, effect in ipairs(active_effects) do
@ -92,11 +93,19 @@ local function handle_weather_effects(player)
if type(config.particles) ~= "nil" and outdoors then if type(config.particles) ~= "nil" and outdoors then
spawn_particles(player, config.particles, wind) spawn_particles(player, config.particles, wind)
end end
if type(config.sound) ~= nil and outdoors then if type(config.sound) ~= "nil" and outdoors then
sounds[effect] = config.sound sounds[effect] = config.sound
end end
if type(config.environment) ~= "nil" and outdoors then
for flag, value in pairs(config.environment) do
if value ~= false then
environment_flags[flag] = value
end
end
end
end end
weather_mod.handle_sounds(player, sounds) weather_mod.handle_sounds(player, sounds)
weather_mod.handle_events(player, environment_flags)
end end
local timer = 0 local timer = 0

View File

@ -36,11 +36,11 @@ function weather_mod.set_clouds(player)
return return
end end
local ppos = player:get_pos() local ppos = player:get_pos()
local humidity = weather_mod.get_humidity(ppos) / 200 local humidity = weather_mod.get_humidity(ppos) / 100
local clouds = {} local clouds = {}
clouds.speed = vector.multiply(weather_mod.state.wind, 2) clouds.speed = vector.multiply(weather_mod.state.wind, 2)
clouds.color = "#fff0f0c5" clouds.color = "#fff0f0c5"
clouds.density = math.max(math.min(humidity, 0.1), 0.9) clouds.density = math.max(math.min(humidity, 0.8), 0.1)
player:set_clouds(clouds) player:set_clouds(clouds)
end end
@ -82,3 +82,11 @@ function weather_mod.handle_sounds(player, sounds)
end end
end end
end end
function weather_mod.damage_player(player, amount, reason)
if not weather_mod.settings.damage then
return
end
local hp = player:get_hp()
player:set_hp(current_hp - amount, reason)
end

View File

@ -1,17 +1,17 @@
ultimate_weather_damage (Storms and hail cause damage) bool true believable_weather_damage (Storms and hail cause damage) bool true
ultimate_weather_particles (Show particle effects) bool true believable_weather_particles (Show particle effects) bool true
ultimate_weather_leaves (Leave color changes in autumn) bool true believable_weather_leaves (Leave color changes in autumn) bool true
ultimate_weather_snow_layers (Place snow layers on ground) bool true believable_weather_snow_layers (Place snow layers on ground) bool true
ultimate_weather_puddles (Place rain puddles on ground) bool true believable_weather_puddles (Place rain puddles on ground) bool true
ultimate_weather_skybox (Darken sky during rain) bool true believable_weather_skybox (Darken sky during rain) bool true
ultimate_weather_raycasting (Use more accurate indoors check) bool false believable_weather_raycasting (Use more accurate indoors check) bool false
ultimate_weather_wind (Allow wind to angle rainfall) bool true believable_weather_wind (Allow wind to angle rainfall) bool true
ultimate_weather_wind_slow (Allow wind to impact movement speed) bool true believable_weather_wind_slow (Allow wind to impact movement speed) bool true
ultimate_weather_flowers (Flowers will respawn in spring and die in winter) bool true believable_weather_flowers (Flowers will respawn in spring and die in winter) bool true
ultimate_weather_fruit (Apples and other fruits will regrow) bool true believable_weather_fruit (Apples and other fruits will regrow) bool true
ultimate_weather_soil (Soil turns wet during rain) bool true believable_weather_soil (Soil turns wet during rain) bool true
ultimate_weather_seasons (Use seasons instead of permanent summer) bool true believable_weather_seasons (Use seasons instead of permanent summer) bool true
ultimate_weather_base_heat (Base temperature) float 0 believable_weather_base_heat (Base temperature) float 0
ultimate_weather_base_humidity (Base humidity) float 0 believable_weather_base_humidity (Base humidity) float 0
ultimate_weather_max_height (Maximum height of weather effects) int 120 believable_weather_max_height (Maximum height of weather effects) int 120
ultimate_weather_min_height (Minimum height of weather effects) int -50 believable_weather_min_height (Minimum height of weather effects) int -50