1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2025-01-12 02:50:25 +01:00

improve ambience mod

This commit is contained in:
crabman77 2015-10-25 11:53:46 +01:00
parent 36e3c44430
commit d16517a655

View File

@ -3,9 +3,6 @@
local max_frequency_all = 1000 -- larger number means more frequent sounds (100-2000) local max_frequency_all = 1000 -- larger number means more frequent sounds (100-2000)
local SOUNDVOLUME = 1 local SOUNDVOLUME = 1
local ambiences
local played_on_start = false
local tempy = {}
-- compatibility with soundset mod -- compatibility with soundset mod
local get_volume local get_volume
@ -108,6 +105,14 @@ local largefire = {
{name="fire_large", length=8} {name="fire_large", length=8}
} }
local get_num_nodes = function(pos, nodes)
return #minetest.find_nodes_in_area(
{x=pos.x-6,y=pos.y-2, z=pos.z-6},
{x=pos.x+6,y=pos.y+3, z=pos.z+6},
nodes
)
end
-- check where player is and which sounds are played -- check where player is and which sounds are played
local get_ambience = function(player) local get_ambience = function(player)
@ -115,46 +120,21 @@ local get_ambience = function(player)
local pos = player:getpos() local pos = player:getpos()
-- what is around me? -- what is around me?
pos.y = pos.y + 1.4 -- head level local nod_head = minetest.get_node({x=pos.x,y=pos.y+1.4, z=pos.z}).name
local nod_head = minetest.get_node(pos).name if string.find(nod_head, "water_") then
pos.y = pos.y - 1.2 -- feet level
local nod_feet = minetest.get_node(pos).name
pos.y = pos.y - 0.2 -- reset pos
--= START Ambiance
if nod_head == "default:water_source"
or nod_head == "default:water_flowing" then
return {underwater=underwater} return {underwater=underwater}
end end
local nod_feet = minetest.get_node({x=pos.x,y=pos.y+0.2, z=pos.z}).name
if nod_feet == "default:water_source" if string.find(nod_feet, "water_") then
or nod_feet == "default:water_flowing" then
return {splash=splash} return {splash=splash}
end end
local num_fire, num_lava, num_water_source, num_water_flowing, num_desert = 0,0,0,0,0 --= START Ambiance
-- get block of nodes we need to check
tempy = minetest.find_nodes_in_area({x=pos.x-6,y=pos.y-2, z=pos.z-6},
{x=pos.x+6,y=pos.y+2, z=pos.z+6},
{"fire:basic_flame", "bakedclay:safe_fire", "default:lava_flowing", "default:lava_source",
"default:water_flowing", "default:water_source", "default:desert_sand", "default:desert_stone",})
-- count separate instances in block
for _, npos in ipairs(tempy) do
local node = minetest.get_node(npos).name
if node == "fire:basic_flame" or node == "bakedclay:safe_fire" then num_fire = num_fire + 1 end
if node == "default:lava_flowing" or node == "default:lava_source" then num_lava = num_lava + 1 end
if node == "default:water_flowing" then num_water_flowing = num_water_flowing + 1 end
if node == "default:water_source" then num_water_source = num_water_source + 1 end
if node == "default:desert_sand" or node == "default:desert_stone" then num_desert = num_desert + 1 end
end ; --print (num_fire, num_lava, num_water_flowing, num_water_source, num_desert)
-- is fire redo mod active? -- is fire redo mod active?
if fire and fire.mod and fire.mod == "redo" then if fire and fire.mod and fire.mod == "redo" then
local num_fire = get_num_nodes(pos, {"fire:basic_flame", "bakedclay:safe_fire"})
--print("num_fire:"..dump(num_fire))
if num_fire > 8 then if num_fire > 8 then
return {largefire=largefire} return {largefire=largefire}
elseif num_fire > 0 then elseif num_fire > 0 then
@ -162,18 +142,28 @@ local get_ambience = function(player)
end end
end end
local num_lava = get_num_nodes(pos, {"default:lava_flowing", "default:lava_source"})
--print("num_lava:"..dump(num_lava))
if num_lava > 5 then if num_lava > 5 then
return {lava=lava} return {lava=lava}
end end
local num_water_flowing = get_num_nodes(pos, {"default:water_flowing", "default:river_water_flowing"})
--print("num_water_flowing:"..dump(num_water_flowing))
if num_water_flowing > 30 then if num_water_flowing > 30 then
return {flowing_water=flowing_water} return {flowing_water=flowing_water}
end end
if pos.y < 7 and pos.y > 0 and num_water_source > 100 then if pos.y < 7 and pos.y > 0 then
local num_water_source = get_num_nodes(pos, {"default:water_source", "default:river_water_source"})
--print("num_water_source:"..dump(num_water_source))
if num_water_source > 100 then
return {beach=beach} return {beach=beach}
end end
end
local num_desert = get_num_nodes(pos, {"default:desert_sand", "default:desert_stone"})
--print("num_desert:"..dump(num_desert))
if num_desert > 150 then if num_desert > 150 then
return {desert=desert} return {desert=desert}
end end
@ -253,21 +243,18 @@ local still_playing = function(still_playing, player)
if not still_playing.largefire then stop_sound(largefire, player) end if not still_playing.largefire then stop_sound(largefire, player) end
end end
local function tick() local function tick()
for _,player in ipairs(minetest.get_connected_players()) do for _,player in ipairs(minetest.get_connected_players()) do
local playername = player:get_player_name()
local gain = get_volume(playername, "ambience")
if gain > 0 then
--local t1 = os.clock() --local t1 = os.clock()
ambiences = get_ambience(player) local ambiences = get_ambience(player)
--print ("[AMBIENCE] "..math.ceil((os.clock() - t1) * 1000).." ms") --print ("[AMBIENCE] "..math.ceil((os.clock() - t1) * 1000).." ms")
still_playing(ambiences, player) still_playing(ambiences, player)
if get_volume(player:get_player_name(), "ambience") > 0 then
for _,ambience in pairs(ambiences) do for _,ambience in pairs(ambiences) do
if math.random(1, 1000) <= ambience.frequency then if math.random(1, 1000) <= ambience.frequency then
if ambience.on_start and played_on_start == false then
played_on_start = true
minetest.sound_play(ambience.on_start,
{to_player=player:get_player_name(),gain=get_volume(player:get_player_name(), "ambience")})
end
play_sound(player, ambience, math.random(1, #ambience)) play_sound(player, ambience, math.random(1, #ambience))
end end
end end