2014-11-09 20:32:21 +01:00
|
|
|
|
2017-10-09 13:19:58 +02:00
|
|
|
--= Ambience lite by TenPlus1
|
2014-11-09 20:32:21 +01:00
|
|
|
|
2015-01-14 15:50:19 +01:00
|
|
|
local max_frequency_all = 1000 -- larger number means more frequent sounds (100-2000)
|
2016-12-24 12:43:38 +01:00
|
|
|
local SOUNDVOLUME = 1.0
|
2014-11-09 20:32:21 +01:00
|
|
|
local ambiences
|
|
|
|
|
2016-12-23 20:35:59 +01:00
|
|
|
-- override default water sounds
|
|
|
|
minetest.override_item("default:water_source", { sounds = {} })
|
|
|
|
minetest.override_item("default:water_flowing", { sounds = {} })
|
|
|
|
minetest.override_item("default:river_water_source", { sounds = {} })
|
|
|
|
minetest.override_item("default:river_water_flowing", { sounds = {} })
|
|
|
|
|
2017-07-06 13:29:23 +02:00
|
|
|
-- music settings
|
|
|
|
local music_handler = nil
|
|
|
|
local MUSICVOLUME = 1
|
2017-10-09 13:19:58 +02:00
|
|
|
local play_music = minetest.settings:get_bool("ambience_music") ~= false
|
2017-07-06 13:29:23 +02:00
|
|
|
|
2018-03-24 10:43:55 +01:00
|
|
|
-- is playerplus running?
|
|
|
|
local pplus = minetest.get_modpath("playerplus")
|
|
|
|
|
2016-12-24 12:43:38 +01:00
|
|
|
-- sound sets (gain defaults to 0.3 unless specifically set)
|
2016-06-06 11:32:09 +02:00
|
|
|
|
2014-11-09 20:32:21 +01:00
|
|
|
local night = {
|
2015-09-30 12:47:52 +02:00
|
|
|
handler = {}, frequency = 40,
|
2016-04-01 18:06:29 +02:00
|
|
|
{name = "hornedowl", length = 2},
|
2016-12-24 12:43:38 +01:00
|
|
|
{name = "wolves", length = 4, gain = 0.4},
|
2016-04-01 18:06:29 +02:00
|
|
|
{name = "cricket", length = 6},
|
|
|
|
{name = "deer", length = 7},
|
|
|
|
{name = "frog", length = 1},
|
2014-11-09 20:32:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
local day = {
|
2015-09-30 12:47:52 +02:00
|
|
|
handler = {}, frequency = 40,
|
2016-04-01 18:06:29 +02:00
|
|
|
{name = "cardinal", length = 3},
|
|
|
|
{name = "craw", length = 3},
|
|
|
|
{name = "bluejay", length = 6},
|
|
|
|
{name = "robin", length = 4},
|
|
|
|
{name = "bird1", length = 11},
|
|
|
|
{name = "bird2", length = 6},
|
|
|
|
{name = "crestedlark", length = 6},
|
|
|
|
{name = "peacock", length = 2},
|
|
|
|
{name = "wind", length = 9},
|
2014-11-09 20:32:21 +01:00
|
|
|
}
|
|
|
|
|
2015-03-06 10:24:33 +01:00
|
|
|
local high_up = {
|
2015-09-30 12:47:52 +02:00
|
|
|
handler = {}, frequency = 40,
|
2016-04-01 18:06:29 +02:00
|
|
|
{name = "desertwind", length = 8},
|
|
|
|
{name = "wind", length = 9},
|
2015-03-06 10:24:33 +01:00
|
|
|
}
|
|
|
|
|
2014-11-09 20:32:21 +01:00
|
|
|
local cave = {
|
2015-09-30 12:47:52 +02:00
|
|
|
handler = {}, frequency = 60,
|
2016-04-01 18:06:29 +02:00
|
|
|
{name = "drippingwater1", length = 1.5},
|
|
|
|
{name = "drippingwater2", length = 1.5}
|
2014-11-09 20:32:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
local beach = {
|
2015-09-30 12:47:52 +02:00
|
|
|
handler = {}, frequency = 40,
|
2016-04-01 18:06:29 +02:00
|
|
|
{name = "seagull", length = 4.5},
|
|
|
|
{name = "beach", length = 13},
|
2016-06-06 11:32:09 +02:00
|
|
|
{name = "gull", length = 1},
|
|
|
|
{name = "beach_2", length = 6},
|
2014-11-09 20:32:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
local desert = {
|
2015-09-30 12:47:52 +02:00
|
|
|
handler = {}, frequency = 20,
|
2016-04-01 18:06:29 +02:00
|
|
|
{name = "coyote", length = 2.5},
|
2018-03-24 10:43:55 +01:00
|
|
|
{name = "wind", length = 9},
|
2016-04-01 18:06:29 +02:00
|
|
|
{name = "desertwind", length = 8}
|
2014-11-09 20:32:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
local flowing_water = {
|
2015-09-30 12:47:52 +02:00
|
|
|
handler = {}, frequency = 1000,
|
2016-04-01 18:06:29 +02:00
|
|
|
{name = "waterfall", length = 6}
|
2014-11-09 20:32:21 +01:00
|
|
|
}
|
2015-02-04 19:30:43 +01:00
|
|
|
|
2015-01-14 15:50:19 +01:00
|
|
|
local underwater = {
|
2015-09-30 12:47:52 +02:00
|
|
|
handler = {}, frequency = 1000,
|
2016-04-01 18:06:29 +02:00
|
|
|
{name = "scuba", length = 8}
|
2015-02-04 19:30:43 +01:00
|
|
|
}
|
2014-11-09 20:32:21 +01:00
|
|
|
|
|
|
|
local splash = {
|
2015-09-30 12:47:52 +02:00
|
|
|
handler = {}, frequency = 1000,
|
2016-12-24 12:43:38 +01:00
|
|
|
{name = "swim_splashing", length = 3},
|
2014-11-09 20:32:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
local lava = {
|
2015-09-30 12:47:52 +02:00
|
|
|
handler = {}, frequency = 1000,
|
2016-04-01 18:06:29 +02:00
|
|
|
{name = "lava", length = 7}
|
2014-11-09 20:32:21 +01:00
|
|
|
}
|
|
|
|
|
2016-06-17 22:29:18 +02:00
|
|
|
local river = {
|
|
|
|
handler = {}, frequency = 1000,
|
2018-03-24 11:36:25 +01:00
|
|
|
{name = "river", length = 4, gain = 0.1}
|
2016-06-17 22:29:18 +02:00
|
|
|
}
|
|
|
|
|
2015-02-04 19:30:43 +01:00
|
|
|
local smallfire = {
|
2015-09-30 12:47:52 +02:00
|
|
|
handler = {}, frequency = 1000,
|
2018-03-24 11:36:25 +01:00
|
|
|
{name = "fire_small", length = 6, gain = 0.1}
|
2015-02-04 19:30:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
local largefire = {
|
2015-09-30 12:47:52 +02:00
|
|
|
handler = {}, frequency = 1000,
|
2018-03-24 11:39:22 +01:00
|
|
|
{name = "fire_large", length = 8, gain = 0.4}
|
2015-02-04 19:30:43 +01:00
|
|
|
}
|
|
|
|
|
2016-04-01 18:06:29 +02:00
|
|
|
local jungle = {
|
2016-06-06 11:32:09 +02:00
|
|
|
handler = {}, frequency = 200,
|
|
|
|
{name = "jungle_day_1", length = 7},
|
2016-04-01 18:06:29 +02:00
|
|
|
{name = "deer", length = 7},
|
|
|
|
{name = "canadianloon2", length = 14},
|
|
|
|
{name = "bird1", length = 11},
|
|
|
|
{name = "peacock", length = 2},
|
2016-06-06 11:32:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
local jungle_night = {
|
|
|
|
handler = {}, frequency = 200,
|
|
|
|
{name = "jungle_night_1", length = 4},
|
|
|
|
{name = "jungle_night_2", length = 4},
|
|
|
|
{name = "deer", length = 7},
|
|
|
|
{name = "frog", length = 1},
|
2016-04-01 18:06:29 +02:00
|
|
|
}
|
2016-02-26 22:40:53 +01:00
|
|
|
|
2017-08-23 11:15:53 +02:00
|
|
|
local ice = {
|
|
|
|
handler = {}, frequency = 250,
|
|
|
|
{name = "icecrack", length = 23},
|
2018-03-24 10:43:55 +01:00
|
|
|
{name = "desertwind", length = 8},
|
|
|
|
{name = "wind", length = 9},
|
2017-08-23 11:15:53 +02:00
|
|
|
}
|
|
|
|
|
2016-04-01 18:06:29 +02:00
|
|
|
local radius = 6
|
2017-01-24 22:30:57 +01:00
|
|
|
local num_fire, num_lava, num_water_flowing, num_water_source, num_air,
|
2017-08-23 11:15:53 +02:00
|
|
|
num_desert, num_snow, num_jungletree, num_river, num_ice
|
2016-02-26 22:40:53 +01:00
|
|
|
|
2014-11-09 20:32:21 +01:00
|
|
|
-- check where player is and which sounds are played
|
|
|
|
local get_ambience = function(player)
|
|
|
|
|
2018-03-24 10:43:55 +01:00
|
|
|
-- where am I?
|
2016-06-06 11:32:09 +02:00
|
|
|
--local player_name = player:get_player_name()
|
2017-10-09 16:07:02 +02:00
|
|
|
local pos = player:get_pos()
|
2014-11-09 20:32:21 +01:00
|
|
|
|
2015-02-04 19:30:43 +01:00
|
|
|
-- what is around me?
|
2018-03-24 10:43:55 +01:00
|
|
|
local nod_head, nod_feet
|
|
|
|
|
|
|
|
-- is playerplus in use?
|
|
|
|
if pplus then
|
|
|
|
|
|
|
|
local name = player:get_player_name()
|
|
|
|
|
|
|
|
nod_head = playerplus[name].nod_head
|
|
|
|
nod_feet = playerplus[name].nod_feet
|
|
|
|
else
|
|
|
|
|
|
|
|
pos.y = pos.y + 1.4 -- head level
|
2018-03-25 13:25:58 +02:00
|
|
|
nod_head = minetest.get_node(pos).name
|
2015-02-16 16:46:59 +01:00
|
|
|
|
2018-03-24 10:43:55 +01:00
|
|
|
pos.y = pos.y - 1.2 -- foot level
|
2018-03-25 13:25:58 +02:00
|
|
|
nod_feet = minetest.get_node(pos).name
|
2015-02-16 16:46:59 +01:00
|
|
|
|
2018-03-24 10:43:55 +01:00
|
|
|
pos.y = pos.y - 0.2 -- reset pos
|
|
|
|
end
|
2015-02-04 19:30:43 +01:00
|
|
|
|
2017-07-06 13:29:23 +02:00
|
|
|
local tod = minetest.get_timeofday()
|
|
|
|
|
|
|
|
-- play server or local music if available
|
|
|
|
if play_music then
|
|
|
|
|
|
|
|
-- print ("-- tod", tod, music_handler)
|
|
|
|
|
|
|
|
if tod > 0.01 and tod < 0.02 then
|
|
|
|
music_handler = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
-- play at midnight
|
|
|
|
if tod >= 0.0 and tod <= 0.01 and not music_handler then
|
|
|
|
|
2018-06-11 22:39:51 +02:00
|
|
|
music_handler = minetest.sound_play("ambience_music", {
|
2017-07-06 13:29:23 +02:00
|
|
|
to_player = player:get_player_name(),
|
|
|
|
gain = MUSICVOLUME
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-26 22:40:53 +01:00
|
|
|
--= START Ambiance
|
2015-01-14 15:50:19 +01:00
|
|
|
|
2017-08-23 11:15:53 +02:00
|
|
|
-- head underwater
|
2016-06-06 11:32:09 +02:00
|
|
|
if minetest.registered_nodes[nod_head]
|
|
|
|
and minetest.registered_nodes[nod_head].groups.water then
|
2015-09-30 12:47:52 +02:00
|
|
|
return {underwater = underwater}
|
2015-01-14 15:50:19 +01:00
|
|
|
end
|
|
|
|
|
2017-08-23 11:15:53 +02:00
|
|
|
-- wading through water
|
2018-01-26 16:48:09 +01:00
|
|
|
if minetest.registered_nodes[nod_feet]
|
|
|
|
and minetest.registered_nodes[nod_feet].groups.water then
|
2016-06-13 11:56:24 +02:00
|
|
|
|
|
|
|
local control = player:get_player_control()
|
|
|
|
|
|
|
|
if control.up or control.down or control.left or control.right then
|
|
|
|
return {splash = splash}
|
|
|
|
end
|
2014-11-09 20:32:21 +01:00
|
|
|
end
|
|
|
|
|
2016-02-26 22:40:53 +01:00
|
|
|
local ps, cn = minetest.find_nodes_in_area(
|
|
|
|
{x = pos.x - radius, y = pos.y - radius, z = pos.z - radius},
|
|
|
|
{x = pos.x + radius, y = pos.y + radius, z = pos.z + radius},
|
|
|
|
{
|
|
|
|
"fire:basic_flame", "fire:permanent_flame",
|
2016-04-01 18:06:29 +02:00
|
|
|
"default:lava_flowing", "default:lava_source", "default:jungletree",
|
2017-08-23 11:15:53 +02:00
|
|
|
"default:water_flowing", "default:water_source", "default:ice",
|
2017-09-20 21:13:43 +02:00
|
|
|
"default:river_water_flowing",
|
2017-01-25 21:21:40 +01:00
|
|
|
"default:desert_sand", "default:desert_stone", "default:snowblock"
|
2016-02-26 22:40:53 +01:00
|
|
|
})
|
|
|
|
|
2016-04-01 18:06:29 +02:00
|
|
|
num_fire = (cn["fire:basic_flame"] or 0) + (cn["fire:permanent_flame"] or 0)
|
|
|
|
num_lava = (cn["default:lava_flowing"] or 0) + (cn["default:lava_source"] or 0)
|
2016-06-17 22:29:18 +02:00
|
|
|
num_water_flowing = (cn["default:water_flowing"] or 0)
|
|
|
|
num_water_source = (cn["default:water_source"] or 0)
|
2016-04-01 18:06:29 +02:00
|
|
|
num_desert = (cn["default:desert_sand"] or 0) + (cn["default:desert_stone"] or 0)
|
|
|
|
num_snow = (cn["default:snowblock"] or 0)
|
|
|
|
num_jungletree = (cn["default:jungletree"] or 0)
|
2017-09-20 21:13:43 +02:00
|
|
|
num_river = (cn["default:river_water_flowing"] or 0)
|
2017-08-23 11:15:53 +02:00
|
|
|
num_ice = (cn["default:ice"] or 0)
|
2016-03-03 12:13:08 +01:00
|
|
|
--[[
|
|
|
|
print (
|
2016-02-26 22:40:53 +01:00
|
|
|
"fr:" .. num_fire,
|
|
|
|
"lv:" .. num_lava,
|
|
|
|
"wf:" .. num_water_flowing,
|
|
|
|
"ws:" .. num_water_source,
|
2018-03-24 11:36:25 +01:00
|
|
|
"rv:" .. num_river,
|
2016-02-26 22:40:53 +01:00
|
|
|
"ds:" .. num_desert,
|
2016-04-01 18:06:29 +02:00
|
|
|
"sn:" .. num_snow,
|
2017-08-23 11:15:53 +02:00
|
|
|
"ic:" .. num_ice,
|
2016-04-01 18:06:29 +02:00
|
|
|
"jt:" .. num_jungletree
|
2016-03-03 12:13:08 +01:00
|
|
|
)
|
|
|
|
]]
|
2015-02-16 16:46:59 +01:00
|
|
|
-- is fire redo mod active?
|
2015-04-16 10:22:29 +02:00
|
|
|
if fire and fire.mod and fire.mod == "redo" then
|
2016-02-26 22:40:53 +01:00
|
|
|
|
2018-03-24 11:39:22 +01:00
|
|
|
if num_fire > 16 then
|
|
|
|
return {largefire = largefire}, 0.4
|
|
|
|
|
|
|
|
elseif num_fire > 8 then
|
2015-09-30 12:47:52 +02:00
|
|
|
return {largefire = largefire}
|
2016-02-26 22:40:53 +01:00
|
|
|
|
2018-03-24 11:36:25 +01:00
|
|
|
elseif num_fire > 3 then
|
|
|
|
return {smallfire = smallfire}, 0.2
|
|
|
|
|
2015-02-16 16:46:59 +01:00
|
|
|
elseif num_fire > 0 then
|
2015-09-30 12:47:52 +02:00
|
|
|
return {smallfire = smallfire}
|
2015-02-04 19:30:43 +01:00
|
|
|
end
|
|
|
|
end
|
2014-11-09 20:32:21 +01:00
|
|
|
|
2017-08-23 11:15:53 +02:00
|
|
|
-- lava
|
2018-03-24 11:36:25 +01:00
|
|
|
if num_lava > 50 then
|
|
|
|
return {lava = lava}, 0.5
|
|
|
|
elseif num_lava > 5 then
|
2015-09-30 12:47:52 +02:00
|
|
|
return {lava = lava}
|
2014-11-09 20:32:21 +01:00
|
|
|
end
|
2015-02-16 16:46:59 +01:00
|
|
|
|
2017-08-23 11:15:53 +02:00
|
|
|
-- flowing water
|
2018-03-24 11:36:25 +01:00
|
|
|
if num_water_flowing > 50 then
|
|
|
|
return {flowing_water = flowing_water}, 0.5
|
|
|
|
elseif num_water_flowing > 20 then
|
2015-09-30 12:47:52 +02:00
|
|
|
return {flowing_water = flowing_water}
|
2014-11-09 20:32:21 +01:00
|
|
|
end
|
2015-02-16 16:46:59 +01:00
|
|
|
|
2017-08-23 11:15:53 +02:00
|
|
|
-- flowing river
|
2018-03-24 11:36:25 +01:00
|
|
|
if num_river > 20 then
|
|
|
|
return {river = river}, 0.4
|
|
|
|
elseif num_river > 5 then
|
2016-06-17 22:29:18 +02:00
|
|
|
return {river = river}
|
|
|
|
end
|
|
|
|
|
2017-08-23 11:15:53 +02:00
|
|
|
-- sea level beach
|
2016-02-26 22:40:53 +01:00
|
|
|
if pos.y < 7 and pos.y > 0
|
|
|
|
and num_water_source > 100 then
|
2015-09-30 12:47:52 +02:00
|
|
|
return {beach = beach}
|
2014-11-09 20:32:21 +01:00
|
|
|
end
|
2015-02-16 16:46:59 +01:00
|
|
|
|
2017-08-23 11:15:53 +02:00
|
|
|
-- ice flows
|
|
|
|
if num_ice > 100 and num_snow > 100 then
|
|
|
|
return {ice = ice}
|
|
|
|
end
|
|
|
|
|
|
|
|
-- desert
|
2015-02-24 21:33:49 +01:00
|
|
|
if num_desert > 150 then
|
2015-09-30 12:47:52 +02:00
|
|
|
return {desert = desert}
|
2014-11-09 20:32:21 +01:00
|
|
|
end
|
2015-09-30 12:47:52 +02:00
|
|
|
|
2017-08-23 11:15:53 +02:00
|
|
|
-- high up or surrounded by snow
|
2015-09-30 12:47:52 +02:00
|
|
|
if pos.y > 60
|
|
|
|
or num_snow > 150 then
|
|
|
|
return {high_up = high_up}
|
2015-03-06 10:24:33 +01:00
|
|
|
end
|
2015-02-16 16:46:59 +01:00
|
|
|
|
2017-08-23 11:15:53 +02:00
|
|
|
-- underground
|
|
|
|
if pos.y < -15 then
|
2015-09-30 12:47:52 +02:00
|
|
|
return {cave = cave}
|
2014-11-09 20:32:21 +01:00
|
|
|
end
|
2015-02-16 16:46:59 +01:00
|
|
|
|
2016-02-26 22:40:53 +01:00
|
|
|
if tod > 0.2
|
|
|
|
and tod < 0.8 then
|
2016-04-01 18:06:29 +02:00
|
|
|
|
2017-08-23 11:15:53 +02:00
|
|
|
-- jungle day time
|
2016-06-06 11:49:50 +02:00
|
|
|
if num_jungletree > 90 then
|
2016-04-01 18:06:29 +02:00
|
|
|
return {jungle = jungle}
|
|
|
|
end
|
|
|
|
|
2017-08-23 11:15:53 +02:00
|
|
|
-- normal day time
|
2015-09-30 12:47:52 +02:00
|
|
|
return {day = day}
|
2014-11-09 20:32:21 +01:00
|
|
|
else
|
2016-06-06 11:32:09 +02:00
|
|
|
|
2017-08-23 11:15:53 +02:00
|
|
|
-- jungle night time
|
2016-06-06 11:49:50 +02:00
|
|
|
if num_jungletree > 90 then
|
2016-06-06 11:32:09 +02:00
|
|
|
return {jungle_night = jungle_night}
|
|
|
|
end
|
|
|
|
|
2017-08-23 11:15:53 +02:00
|
|
|
-- normal night time
|
2015-09-30 12:47:52 +02:00
|
|
|
return {night = night}
|
2014-11-09 20:32:21 +01:00
|
|
|
end
|
2015-02-04 19:30:43 +01:00
|
|
|
|
|
|
|
-- END Ambiance
|
2014-11-09 20:32:21 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- play sound, set handler then delete handler when sound finished
|
2018-03-24 11:36:25 +01:00
|
|
|
local play_sound = function(player_name, list, number, MORE_GAIN)
|
2014-11-09 20:32:21 +01:00
|
|
|
|
|
|
|
if list.handler[player_name] == nil then
|
|
|
|
|
2016-06-06 11:32:09 +02:00
|
|
|
local handler = minetest.sound_play(list[number].name, {
|
|
|
|
to_player = player_name,
|
2018-03-24 11:36:25 +01:00
|
|
|
gain = ((list[number].gain or 0.3) + (MORE_GAIN or 0)) * SOUNDVOLUME
|
2016-06-06 11:32:09 +02:00
|
|
|
})
|
2014-11-09 20:32:21 +01:00
|
|
|
|
|
|
|
if handler then
|
2016-02-26 22:40:53 +01:00
|
|
|
|
2014-11-09 20:32:21 +01:00
|
|
|
list.handler[player_name] = handler
|
|
|
|
|
|
|
|
minetest.after(list[number].length, function(args)
|
2016-02-26 22:40:53 +01:00
|
|
|
|
2014-11-09 20:32:21 +01:00
|
|
|
local list = args[1]
|
|
|
|
local player_name = args[2]
|
|
|
|
|
|
|
|
if list.handler[player_name] then
|
2016-02-26 22:40:53 +01:00
|
|
|
|
2014-11-09 20:32:21 +01:00
|
|
|
minetest.sound_stop(list.handler[player_name])
|
2016-02-26 22:40:53 +01:00
|
|
|
|
2014-11-09 20:32:21 +01:00
|
|
|
list.handler[player_name] = nil
|
|
|
|
end
|
2016-02-26 22:40:53 +01:00
|
|
|
|
2014-11-09 20:32:21 +01:00
|
|
|
end, {list, player_name})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-16 16:46:59 +01:00
|
|
|
-- stop sound in still_playing
|
2016-02-26 22:40:53 +01:00
|
|
|
local stop_sound = function (list, player_name)
|
2014-11-09 20:32:21 +01:00
|
|
|
|
2015-02-16 16:46:59 +01:00
|
|
|
if list.handler[player_name] then
|
2016-02-26 22:40:53 +01:00
|
|
|
|
2015-02-16 16:46:59 +01:00
|
|
|
minetest.sound_stop(list.handler[player_name])
|
2016-02-26 22:40:53 +01:00
|
|
|
|
2015-02-16 16:46:59 +01:00
|
|
|
list.handler[player_name] = nil
|
2014-11-09 20:32:21 +01:00
|
|
|
end
|
2015-02-16 16:46:59 +01:00
|
|
|
end
|
2015-02-04 19:30:43 +01:00
|
|
|
|
2015-02-16 16:46:59 +01:00
|
|
|
-- check sounds that are not in still_playing
|
2016-02-26 22:40:53 +01:00
|
|
|
local still_playing = function(still_playing, player_name)
|
2017-07-06 13:29:23 +02:00
|
|
|
|
2016-06-17 22:29:18 +02:00
|
|
|
if not still_playing.cave then stop_sound(cave, player_name) end
|
2016-02-26 22:40:53 +01:00
|
|
|
if not still_playing.high_up then stop_sound(high_up, player_name) end
|
|
|
|
if not still_playing.beach then stop_sound(beach, player_name) end
|
|
|
|
if not still_playing.desert then stop_sound(desert, player_name) end
|
|
|
|
if not still_playing.night then stop_sound(night, player_name) end
|
|
|
|
if not still_playing.day then stop_sound(day, player_name) end
|
|
|
|
if not still_playing.flowing_water then stop_sound(flowing_water, player_name) end
|
|
|
|
if not still_playing.splash then stop_sound(splash, player_name) end
|
|
|
|
if not still_playing.underwater then stop_sound(underwater, player_name) end
|
2016-06-17 22:29:18 +02:00
|
|
|
if not still_playing.river then stop_sound(river, player_name) end
|
2016-02-26 22:40:53 +01:00
|
|
|
if not still_playing.lava then stop_sound(lava, player_name) end
|
|
|
|
if not still_playing.smallfire then stop_sound(smallfire, player_name) end
|
|
|
|
if not still_playing.largefire then stop_sound(largefire, player_name) end
|
2016-04-01 18:06:29 +02:00
|
|
|
if not still_playing.jungle then stop_sound(jungle, player_name) end
|
2016-06-06 11:32:09 +02:00
|
|
|
if not still_playing.jungle_night then stop_sound(jungle_night, player_name) end
|
2017-08-23 11:15:53 +02:00
|
|
|
if not still_playing.ice then stop_sound(ice, player_name) end
|
2014-11-09 20:32:21 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- player routine
|
2016-06-17 22:29:18 +02:00
|
|
|
|
2014-11-09 20:32:21 +01:00
|
|
|
local timer = 0
|
2016-06-17 22:29:18 +02:00
|
|
|
|
2014-11-09 20:32:21 +01:00
|
|
|
minetest.register_globalstep(function(dtime)
|
2015-02-16 16:46:59 +01:00
|
|
|
|
2015-02-04 19:30:43 +01:00
|
|
|
-- every 1 second
|
2016-02-26 22:40:53 +01:00
|
|
|
timer = timer + dtime
|
2015-02-04 19:30:43 +01:00
|
|
|
if timer < 1 then return end
|
2014-11-09 20:32:21 +01:00
|
|
|
timer = 0
|
2015-02-04 19:30:43 +01:00
|
|
|
|
2016-06-06 11:32:09 +02:00
|
|
|
local players = minetest.get_connected_players()
|
2018-03-24 11:36:25 +01:00
|
|
|
local MORE_GAIN
|
2016-06-06 11:32:09 +02:00
|
|
|
|
|
|
|
for n = 1, #players do
|
2016-02-26 22:40:53 +01:00
|
|
|
|
2016-06-06 11:32:09 +02:00
|
|
|
local player_name = players[n]:get_player_name()
|
2016-02-26 22:40:53 +01:00
|
|
|
|
2017-01-25 21:21:40 +01:00
|
|
|
--local t1 = os.clock()
|
2016-02-26 22:40:53 +01:00
|
|
|
|
2018-03-24 11:36:25 +01:00
|
|
|
ambiences, MORE_GAIN = get_ambience(players[n])
|
2016-02-26 22:40:53 +01:00
|
|
|
|
2017-01-25 21:21:40 +01:00
|
|
|
--print(string.format("elapsed time: %.4f\n", os.clock() - t1))
|
2016-02-26 22:40:53 +01:00
|
|
|
|
|
|
|
still_playing(ambiences, player_name)
|
2014-11-09 20:32:21 +01:00
|
|
|
|
|
|
|
for _,ambience in pairs(ambiences) do
|
2015-09-30 12:47:52 +02:00
|
|
|
|
|
|
|
if math.random(1, 1000) <= ambience.frequency then
|
2016-02-26 22:40:53 +01:00
|
|
|
|
2018-03-24 11:36:25 +01:00
|
|
|
play_sound(player_name, ambience, math.random(1, #ambience), MORE_GAIN)
|
2014-11-09 20:32:21 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2017-07-06 13:29:23 +02:00
|
|
|
-- set volume commands
|
2014-11-09 20:32:21 +01:00
|
|
|
minetest.register_chatcommand("svol", {
|
|
|
|
params = "<svol>",
|
|
|
|
description = "set sound volume (0.1 to 1.0)",
|
2015-09-30 12:47:52 +02:00
|
|
|
privs = {server = true},
|
2016-06-17 22:29:18 +02:00
|
|
|
|
2014-11-09 20:32:21 +01:00
|
|
|
func = function(name, param)
|
2016-06-17 22:29:18 +02:00
|
|
|
|
|
|
|
SOUNDVOLUME = tonumber(param) or SOUNDVOLUME
|
|
|
|
|
|
|
|
if SOUNDVOLUME < 0.1 then SOUNDVOLUME = 0.1 end
|
|
|
|
if SOUNDVOLUME > 1.0 then SOUNDVOLUME = 1.0 end
|
|
|
|
|
|
|
|
return true, "Sound volume set to " .. SOUNDVOLUME
|
2014-11-09 20:32:21 +01:00
|
|
|
end,
|
2016-02-26 22:40:53 +01:00
|
|
|
})
|
2017-07-06 13:29:23 +02:00
|
|
|
|
|
|
|
minetest.register_chatcommand("mvol", {
|
|
|
|
params = "<mvol>",
|
|
|
|
description = "set music volume (0.1 to 1.0)",
|
|
|
|
privs = {server = true},
|
|
|
|
|
|
|
|
func = function(name, param)
|
|
|
|
|
|
|
|
MUSICVOLUME = tonumber(param) or MUSICVOLUME
|
|
|
|
|
|
|
|
if MUSICVOLUME < 0.1 then MUSICVOLUME = 0.1 end
|
|
|
|
if MUSICVOLUME > 1.0 then MUSICVOLUME = 1.0 end
|
|
|
|
|
|
|
|
return true, "Music volume set to " .. MUSICVOLUME
|
|
|
|
end,
|
|
|
|
})
|