diff --git a/heavy_rain.lua b/heavy_rain.lua index 53d59a0..67068fa 100644 --- a/heavy_rain.lua +++ b/heavy_rain.lua @@ -8,7 +8,7 @@ local heavy_rain = {} heavy_rain.last_check = 0 -heavy_rain.check_interval = 600 +heavy_rain.check_interval = 200 -- Weather identification code heavy_rain.code = "heavy_rain" @@ -26,7 +26,12 @@ local SKYCOLOR_LAYER = "happy_weather_heavy_rain_sky" heavy_rain.is_starting = function(dtime, position) if heavy_rain.last_check + heavy_rain.check_interval < os.time() then heavy_rain.last_check = os.time() - if math.random() < 0.05 then + local heavy_rain_chance = 0.06 + if hw_utils.is_biome_tropic(position) then + heavy_rain_chance = 0.4 + end + + if math.random() < heavy_rain_chance then happy_weather.request_to_end("light_rain") happy_weather.request_to_end("rain") return true @@ -45,7 +50,9 @@ heavy_rain.is_ending = function(dtime) if heavy_rain.last_check + heavy_rain.check_interval < os.time() then heavy_rain.last_check = os.time() if math.random() < 0.7 then - happy_weather.request_to_start("rain") + if math.random() < 0.4 then + happy_weather.request_to_start("rain") + end return true end end @@ -146,6 +153,7 @@ local add_wide_range_rain_particle = function(player) collisiondetection = true, collision_removal = true, vertical = true, + texture = rain_drop_texture, playername = player:get_player_name() }) @@ -178,6 +186,11 @@ heavy_rain.stop = function() end heavy_rain.in_area = function(position) + if hw_utils.is_biome_frozen(position) or + hw_utils.is_biome_dry(position) then + return false + end + if position.y > -10 then return true end diff --git a/light_rain.lua b/light_rain.lua index 284636f..7135c8b 100644 --- a/light_rain.lua +++ b/light_rain.lua @@ -8,7 +8,7 @@ local light_rain = {} light_rain.last_check = 0 -light_rain.check_interval = 300 +light_rain.check_interval = 200 -- Weather identification code light_rain.code = "light_rain" @@ -144,6 +144,11 @@ local display_rain_particles = function(player) end light_rain.in_area = function(position) + if hw_utils.is_biome_frozen(position) or + hw_utils.is_biome_dry(position) then + return false + end + if position.y > -10 then return true end diff --git a/rain.lua b/rain.lua index e9c008a..298e275 100644 --- a/rain.lua +++ b/rain.lua @@ -8,7 +8,7 @@ local rain = {} rain.last_check = 0 -rain.check_interval = 400 +rain.check_interval = 300 -- Weather identification code rain.code = "rain" @@ -147,6 +147,11 @@ local display_rain_particles = function(player) end rain.in_area = function(position) + if hw_utils.is_biome_frozen(position) or + hw_utils.is_biome_dry(position) then + return false + end + if position.y > -10 then return true end diff --git a/snow.lua b/snow.lua index 25e56df..0b9b978 100644 --- a/snow.lua +++ b/snow.lua @@ -7,6 +7,8 @@ ------------------------------ local snow = {} +snow.last_check = 0 +snow.check_interval = 200 -- Weather identification code snow.code = "snow" @@ -19,6 +21,13 @@ local manual_trigger_end = false local SKYCOLOR_LAYER = "happy_weather_snow_sky" snow.is_starting = function(dtime, position) + if snow.last_check + snow.check_interval < os.time() then + snow.last_check = os.time() + if math.random() < 0.2 then + return true + end + end + if manual_trigger_start then manual_trigger_start = false return true @@ -28,6 +37,13 @@ snow.is_starting = function(dtime, position) end snow.is_ending = function(dtime) + if snow.last_check + snow.check_interval < os.time() then + snow.last_check = os.time() + if math.random() < 0.5 then + return true + end + end + if manual_trigger_end then manual_trigger_end = false return true @@ -111,6 +127,17 @@ snow.render = function(dtime, player) end end +snow.in_area = function(position) + if hw_utils.is_biome_frozen(position) == false then + return false + end + + if position.y > -10 then + return true + end + return false +end + snow.start = function() manual_trigger_start = true end diff --git a/thunder.lua b/thunder.lua index 62a1953..8dd5256 100644 --- a/thunder.lua +++ b/thunder.lua @@ -68,6 +68,11 @@ local calculate_thunder_strike_delay = function() end thunder.render = function(dtime, player) + if happy_weather.is_player_in_weather_area(player:get_player_name(), + "heavy_rain") == false then + return + end + if thunder.next_strike <= os.time() then lightning.strike() calculate_thunder_strike_delay() diff --git a/utils.lua b/utils.lua index 02ff509..95fe706 100644 --- a/utils.lua +++ b/utils.lua @@ -73,4 +73,57 @@ hw_utils.get_random_pos = function(player, offset) return {x=random_pos_x, y=random_pos_y, z=random_pos_z} -end \ No newline at end of file +end + +local np_temp = { + offset = 50, + scale = 50, + spread = {x = 1000, y = 1000, z = 1000}, + seed = 5349, + octaves = 3, + persist = 0.5, + lacunarity = 2.0 +} + +local np_humid = { + offset = 50, + scale = 50, + spread = {x = 1000, y = 1000, z = 1000}, + seed = 842, + octaves = 3, + persist = 0.5, + lacunarity = 2.0 +} + +hw_utils.is_biome_frozen = function(position) + local posx = math.floor(position.x) + local posz = math.floor(position.z) + local noise_obj = minetest.get_perlin(np_temp) + local noise_temp = noise_obj:get2d({x = posx, y = posz}) + + -- below 35 heat biome considered to be frozen type + return noise_temp < 35 +end + +hw_utils.is_biome_dry = function(position) + local posx = math.floor(position.x) + local posz = math.floor(position.z) + local noise_obj = minetest.get_perlin(np_humid) + local noise_humid = noise_obj:get2d({x = posx, y = posz}) + + -- below 50 humid biome considered to be dry type (at least by this mod) + return noise_humid < 50 +end + +hw_utils.is_biome_tropic = function(position) + local posx = math.floor(position.x) + local posz = math.floor(position.z) + local noise_obj = minetest.get_perlin(np_humid) + local noise_humid = noise_obj:get2d({x = posx, y = posz}) + noise_obj = minetest.get_perlin(np_temp) + local noise_temp = noise_obj:get2d({x = posx, y = posz}) + + -- humid and temp values are taked by testing flying around world (not sure actually) + return noise_humid > 55 and noise_temp > 80 +end +