added biome check based on noice parameters

This commit is contained in:
Arturas Norkus 2017-05-28 09:49:37 +03:00
parent d51e0e28b0
commit b2f32023f5
6 changed files with 114 additions and 6 deletions

View File

@ -8,7 +8,7 @@
local heavy_rain = {} local heavy_rain = {}
heavy_rain.last_check = 0 heavy_rain.last_check = 0
heavy_rain.check_interval = 600 heavy_rain.check_interval = 200
-- Weather identification code -- Weather identification code
heavy_rain.code = "heavy_rain" heavy_rain.code = "heavy_rain"
@ -26,7 +26,12 @@ local SKYCOLOR_LAYER = "happy_weather_heavy_rain_sky"
heavy_rain.is_starting = function(dtime, position) heavy_rain.is_starting = function(dtime, position)
if heavy_rain.last_check + heavy_rain.check_interval < os.time() then if heavy_rain.last_check + heavy_rain.check_interval < os.time() then
heavy_rain.last_check = os.time() 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("light_rain")
happy_weather.request_to_end("rain") happy_weather.request_to_end("rain")
return true return true
@ -45,7 +50,9 @@ heavy_rain.is_ending = function(dtime)
if heavy_rain.last_check + heavy_rain.check_interval < os.time() then if heavy_rain.last_check + heavy_rain.check_interval < os.time() then
heavy_rain.last_check = os.time() heavy_rain.last_check = os.time()
if math.random() < 0.7 then 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 return true
end end
end end
@ -146,6 +153,7 @@ local add_wide_range_rain_particle = function(player)
collisiondetection = true, collisiondetection = true,
collision_removal = true, collision_removal = true,
vertical = true, vertical = true,
texture = rain_drop_texture, texture = rain_drop_texture,
playername = player:get_player_name() playername = player:get_player_name()
}) })
@ -178,6 +186,11 @@ heavy_rain.stop = function()
end end
heavy_rain.in_area = function(position) 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 if position.y > -10 then
return true return true
end end

View File

@ -8,7 +8,7 @@
local light_rain = {} local light_rain = {}
light_rain.last_check = 0 light_rain.last_check = 0
light_rain.check_interval = 300 light_rain.check_interval = 200
-- Weather identification code -- Weather identification code
light_rain.code = "light_rain" light_rain.code = "light_rain"
@ -144,6 +144,11 @@ local display_rain_particles = function(player)
end end
light_rain.in_area = function(position) 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 if position.y > -10 then
return true return true
end end

View File

@ -8,7 +8,7 @@
local rain = {} local rain = {}
rain.last_check = 0 rain.last_check = 0
rain.check_interval = 400 rain.check_interval = 300
-- Weather identification code -- Weather identification code
rain.code = "rain" rain.code = "rain"
@ -147,6 +147,11 @@ local display_rain_particles = function(player)
end end
rain.in_area = function(position) 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 if position.y > -10 then
return true return true
end end

View File

@ -7,6 +7,8 @@
------------------------------ ------------------------------
local snow = {} local snow = {}
snow.last_check = 0
snow.check_interval = 200
-- Weather identification code -- Weather identification code
snow.code = "snow" snow.code = "snow"
@ -19,6 +21,13 @@ local manual_trigger_end = false
local SKYCOLOR_LAYER = "happy_weather_snow_sky" local SKYCOLOR_LAYER = "happy_weather_snow_sky"
snow.is_starting = function(dtime, position) 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 if manual_trigger_start then
manual_trigger_start = false manual_trigger_start = false
return true return true
@ -28,6 +37,13 @@ snow.is_starting = function(dtime, position)
end end
snow.is_ending = function(dtime) 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 if manual_trigger_end then
manual_trigger_end = false manual_trigger_end = false
return true return true
@ -111,6 +127,17 @@ snow.render = function(dtime, player)
end end
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() snow.start = function()
manual_trigger_start = true manual_trigger_start = true
end end

View File

@ -68,6 +68,11 @@ local calculate_thunder_strike_delay = function()
end end
thunder.render = function(dtime, player) 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 if thunder.next_strike <= os.time() then
lightning.strike() lightning.strike()
calculate_thunder_strike_delay() calculate_thunder_strike_delay()

View File

@ -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} 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