mirror of
https://gitlab.com/rautars/weather_pack.git
synced 2025-06-29 14:10:34 +02:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
61a265d7cc | |||
b2f32023f5 | |||
d51e0e28b0 | |||
34d9615c60 |
@ -15,6 +15,8 @@ requires `weather_manager` privilege.
|
||||
* `start_weather <weather_code>`
|
||||
* `stop_weather <weather_code>`
|
||||
|
||||
Be aware that weather may not be visible for player until player is in right biome.
|
||||
|
||||
Dependencies
|
||||
-----------------------
|
||||
Thunder weather requres [lightning](https://github.com/minetest-mods/lightning) mod.
|
||||
|
@ -12,6 +12,73 @@ happy_weather = {}
|
||||
local registered_weathers = {}
|
||||
local active_weathers = {}
|
||||
|
||||
------------------------------------
|
||||
-- Local helper / utility methods --
|
||||
------------------------------------
|
||||
|
||||
-- Adds weather to active_weathers table
|
||||
local add_active_weather = function(weather_obj)
|
||||
table.insert(active_weathers, weather_obj)
|
||||
end
|
||||
|
||||
-- Remove weather from active_weathers table
|
||||
local remove_active_weather = function(weather_code)
|
||||
if #active_weathers == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
for k, weather_ in ipairs(active_weathers) do
|
||||
if weather_.code == weather_code then
|
||||
table.remove(active_weathers, k)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Returns active weather
|
||||
local get_active_weather = function(weather_code)
|
||||
if #active_weathers == 0 then
|
||||
return nil
|
||||
end
|
||||
|
||||
for k, weather_ in ipairs(active_weathers) do
|
||||
if weather_.code == weather_code then
|
||||
return weather_
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- adds player to affected_players table
|
||||
local add_player = function(affected_players, player)
|
||||
table.insert(affected_players, player)
|
||||
end
|
||||
|
||||
-- remove player from affected_players table
|
||||
local remove_player = function(affected_players, player_name)
|
||||
if #affected_players == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
for k, player_ in ipairs(affected_players) do
|
||||
if player_:get_player_name() == player_name then
|
||||
table.remove(affected_players, k)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local is_player_affected = function(affected_players, player_name)
|
||||
if #affected_players == 0 then
|
||||
return false
|
||||
end
|
||||
|
||||
for k, player_ in ipairs(affected_players) do
|
||||
if player_:get_player_name() == player_name then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---------------------------
|
||||
-- Weather API functions --
|
||||
---------------------------
|
||||
@ -63,58 +130,17 @@ happy_weather.request_to_end = function(weather_code)
|
||||
end
|
||||
end
|
||||
|
||||
------------------------------------
|
||||
-- Local helper / utility methods --
|
||||
------------------------------------
|
||||
|
||||
-- Adds weather to active_weathers table
|
||||
local add_active_weather = function(weather_obj)
|
||||
table.insert(active_weathers, weather_obj)
|
||||
end
|
||||
|
||||
-- Remove weather from active_weathers table
|
||||
local remove_active_weather = function(weather_code)
|
||||
happy_weather.is_player_in_weather_area = function(player_name, weather_code)
|
||||
if #active_weathers == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
for k, weather_ in ipairs(active_weathers) do
|
||||
if weather_.code == weather_code then
|
||||
table.remove(active_weathers, k)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- adds player to affected_players table
|
||||
local add_player = function(affected_players, player)
|
||||
table.insert(affected_players, player)
|
||||
end
|
||||
|
||||
-- remove player from affected_players table
|
||||
local remove_player = function(affected_players, player_name)
|
||||
if #affected_players == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
for k, player_ in ipairs(affected_players) do
|
||||
if player_:get_player_name() == player_name then
|
||||
table.remove(affected_players, k)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local is_player_affected = function(affected_players, player_name)
|
||||
if #affected_players == 0 then
|
||||
return false
|
||||
end
|
||||
|
||||
for k, player_ in ipairs(affected_players) do
|
||||
if player_:get_player_name() == player_name then
|
||||
return true
|
||||
end
|
||||
local active_weather = get_active_weather(weather_code)
|
||||
if active_weather == nil then
|
||||
return false
|
||||
end
|
||||
|
||||
return is_player_affected(active_weather.affected_players, player_name)
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
@ -26,7 +26,7 @@ local SKYCOLOR_LAYER = "happy_weather_light_rain_sky"
|
||||
light_rain.is_starting = function(dtime, position)
|
||||
if light_rain.last_check + light_rain.check_interval < os.time() then
|
||||
light_rain.last_check = os.time()
|
||||
if math.random() < 0.2 then
|
||||
if math.random() < 0.15 then
|
||||
return true
|
||||
end
|
||||
end
|
||||
@ -42,7 +42,7 @@ end
|
||||
light_rain.is_ending = function(dtime)
|
||||
if light_rain.last_check + light_rain.check_interval < os.time() then
|
||||
light_rain.last_check = os.time()
|
||||
if math.random() < 0.4 then
|
||||
if math.random() < 0.5 then
|
||||
return true
|
||||
end
|
||||
end
|
||||
@ -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
|
||||
|
9
rain.lua
9
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"
|
||||
@ -44,7 +44,7 @@ end
|
||||
rain.is_ending = function(dtime)
|
||||
if rain.last_check + rain.check_interval < os.time() then
|
||||
rain.last_check = os.time()
|
||||
if math.random() < 0.3 then
|
||||
if math.random() < 0.6 then
|
||||
happy_weather.request_to_start("light_rain")
|
||||
return true
|
||||
end
|
||||
@ -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
|
||||
|
27
snow.lua
27
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
|
||||
|
@ -27,7 +27,6 @@ local thunder_weather_next_check = 0
|
||||
local thunder_weather_check_delay = 600 -- to avoid checks continuously
|
||||
|
||||
thunder.is_starting = function(dtime)
|
||||
checked = false
|
||||
thunder.next_strike = 0
|
||||
thunder.min_delay = 5
|
||||
thunder.max_delay = math.random(5, 45)
|
||||
@ -69,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()
|
||||
|
55
utils.lua
55
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
|
||||
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
|
||||
|
||||
|
Reference in New Issue
Block a user