From dd73a0df17c530c2fdce92efde662da5fcad4839 Mon Sep 17 00:00:00 2001 From: Till Affeldt Date: Thu, 9 Apr 2020 20:25:02 +0200 Subject: [PATCH] Add lightning, fix cloud size --- init.lua | 1 - lib/commands.lua | 6 +++--- lib/environment.lua | 21 ++++++++++++++++++++- lib/lightning.lua | 3 --- lib/main.lua | 11 ++++++++++- lib/player.lua | 12 ++++++++++-- settingtypes.txt | 34 +++++++++++++++++----------------- 7 files changed, 60 insertions(+), 28 deletions(-) delete mode 100644 lib/lightning.lua diff --git a/init.lua b/init.lua index b754e72..7eb8a39 100644 --- a/init.lua +++ b/init.lua @@ -43,7 +43,6 @@ weather_mod.state = { dofile(weather_mod.modpath.."/lib/player.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/main.lua") dofile(weather_mod.modpath.."/lib/commands.lua") diff --git a/lib/commands.lua b/lib/commands.lua index 0503559..b0ce5b9 100644 --- a/lib/commands.lua +++ b/lib/commands.lua @@ -29,7 +29,7 @@ minetest.register_chatcommand("set_weather", { -- Set wind speed and direction minetest.register_chatcommand("set_wind", { - params = "", + params = "", description = "Set wind to the given x,z direction", -- full description privs = {weather = true}, func = function(name, param) @@ -50,7 +50,7 @@ minetest.register_chatcommand("set_wind", { -- Set base value of global heat level minetest.register_chatcommand("set_heat", { - params = "", + params = "", description = "Set base value of global heat level", -- full description privs = {weather = true}, func = function(name, param) @@ -69,7 +69,7 @@ minetest.register_chatcommand("set_heat", { -- Set base value of global humidity level minetest.register_chatcommand("set_humidity", { - params = "", + params = "", description = "Set base value of global humidity level", -- full description privs = {weather = true}, func = function(name, param) diff --git a/lib/environment.lua b/lib/environment.lua index cae21cd..dcef20e 100644 --- a/lib/environment.lua +++ b/lib/environment.lua @@ -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) local base = weather_mod.settings.heat; local biome = minetest.get_heat(pos) @@ -54,6 +61,18 @@ function weather_mod.get_effects(climate) table.insert(effects, name) ::continue:: end - minetest.log(dump2(effects, "effects")) return effects +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 \ No newline at end of file diff --git a/lib/lightning.lua b/lib/lightning.lua deleted file mode 100644 index b2c550a..0000000 --- a/lib/lightning.lua +++ /dev/null @@ -1,3 +0,0 @@ -if minetest.get_modpath("lightning") then - lightning.auto = false -end \ No newline at end of file diff --git a/lib/main.lua b/lib/main.lua index a14f56d..966984f 100644 --- a/lib/main.lua +++ b/lib/main.lua @@ -82,6 +82,7 @@ local function handle_weather_effects(player) local ppos = player:getpos() local climate = weather_mod.get_climate(ppos) local active_effects = weather_mod.get_effects(climate) + local environment_flags = {} local sounds = {} 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 spawn_particles(player, config.particles, wind) end - if type(config.sound) ~= nil and outdoors then + if type(config.sound) ~= "nil" and outdoors then sounds[effect] = config.sound 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 weather_mod.handle_sounds(player, sounds) + weather_mod.handle_events(player, environment_flags) end local timer = 0 diff --git a/lib/player.lua b/lib/player.lua index 757e748..1adc7a3 100644 --- a/lib/player.lua +++ b/lib/player.lua @@ -36,11 +36,11 @@ function weather_mod.set_clouds(player) return end local ppos = player:get_pos() - local humidity = weather_mod.get_humidity(ppos) / 200 + local humidity = weather_mod.get_humidity(ppos) / 100 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) + clouds.density = math.max(math.min(humidity, 0.8), 0.1) player:set_clouds(clouds) end @@ -81,4 +81,12 @@ function weather_mod.handle_sounds(player, sounds) 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 \ No newline at end of file diff --git a/settingtypes.txt b/settingtypes.txt index 398b4ee..2004cb8 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -1,17 +1,17 @@ -ultimate_weather_damage (Storms and hail cause damage) bool true -ultimate_weather_particles (Show particle effects) bool true -ultimate_weather_leaves (Leave color changes in autumn) bool true -ultimate_weather_snow_layers (Place snow layers on ground) bool true -ultimate_weather_puddles (Place rain puddles on ground) bool true -ultimate_weather_skybox (Darken sky during rain) bool true -ultimate_weather_raycasting (Use more accurate indoors check) bool false -ultimate_weather_wind (Allow wind to angle rainfall) bool true -ultimate_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 -ultimate_weather_fruit (Apples and other fruits will regrow) bool true -ultimate_weather_soil (Soil turns wet during rain) bool true -ultimate_weather_seasons (Use seasons instead of permanent summer) bool true -ultimate_weather_base_heat (Base temperature) float 0 -ultimate_weather_base_humidity (Base humidity) float 0 -ultimate_weather_max_height (Maximum height of weather effects) int 120 -ultimate_weather_min_height (Minimum height of weather effects) int -50 \ No newline at end of file +believable_weather_damage (Storms and hail cause damage) bool true +believable_weather_particles (Show particle effects) bool true +believable_weather_leaves (Leave color changes in autumn) bool true +believable_weather_snow_layers (Place snow layers on ground) bool true +believable_weather_puddles (Place rain puddles on ground) bool true +believable_weather_skybox (Darken sky during rain) bool true +believable_weather_raycasting (Use more accurate indoors check) bool false +believable_weather_wind (Allow wind to angle rainfall) bool true +believable_weather_wind_slow (Allow wind to impact movement speed) bool true +believable_weather_flowers (Flowers will respawn in spring and die in winter) bool true +believable_weather_fruit (Apples and other fruits will regrow) bool true +believable_weather_soil (Soil turns wet during rain) bool true +believable_weather_seasons (Use seasons instead of permanent summer) bool true +believable_weather_base_heat (Base temperature) float 0 +believable_weather_base_humidity (Base humidity) float 0 +believable_weather_max_height (Maximum height of weather effects) int 120 +believable_weather_min_height (Minimum height of weather effects) int -50 \ No newline at end of file