data.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. -- This file is reloadable.
  2. -- Localize for performance.
  3. local math_random = math.random
  4. -- Table of registered sounds. Algorithm intended for intermittent sounds only, continuous sounds need special treatment.
  5. -- Data includes what environment the sound needs to play, what time of day, what elevations, etc. This table is updated dynamically.
  6. ambiance.allsounds = {}
  7. ambiance.tmpsounds = {
  8. -- Dripping water: occurs in over-world caves at any time of day.
  9. -- Can also be heard in developed areas, underground.
  10. {
  11. name="drippingwater", mingain=0.2, maxgain = 1.0, miny=-25000, maxy=-30, time="", indoors=nil,
  12. noise_params = {
  13. offset = 0,
  14. scale = 1,
  15. spread = {x=256, y=256, z=256},
  16. seed = 2129394,
  17. octaves = 3,
  18. persist = 0.5,
  19. lacunarity = 1.5,
  20. flags = "",
  21. },
  22. noise_threshold = 0.0,
  23. },
  24. -- Cave bats: occurs in over-world caves, only at night.
  25. {
  26. name="cave_bats", gain=0.7, miny=-25000, maxy=-60, time="night", indoors=false, mintime=60, maxtime=120,
  27. noise_params = {
  28. offset = 0,
  29. scale = 1,
  30. spread = {x=256, y=256, z=256},
  31. seed = 577891,
  32. octaves = 2,
  33. persist = 0.5,
  34. lacunarity = 1.5,
  35. flags = "",
  36. },
  37. noise_threshold = -0.3,
  38. },
  39. -- Wind: surface sound only, any time of day (but more common at night).
  40. {name="wind1", gain=0.5, miny=-15, maxy=3300, time="day", indoors=false, },
  41. {name="wind2", gain=0.5, miny=-15, maxy=3300, time="day", indoors=false, },
  42. {name="desertwind", gain=0.5, miny=-15, maxy=3300, time="day", indoors=false, },
  43. {name="wind1", gain=1.0, miny=-15, maxy=3300, time="night", indoors=false, mintime=20, maxtime=50, },
  44. {name="wind2", gain=1.0, miny=-15, maxy=3300, time="night", indoors=false, mintime=20, maxtime=50, },
  45. {name="desertwind", gain=1.0, miny=-15, maxy=3300, time="night", indoors=false, mintime=20, maxtime=50, },
  46. -- Plays in caverealms.
  47. {
  48. name="cavewind", gain=1.0, miny=-31000, maxy=-256, time="", indoors=nil, mintime=25, maxtime=45,
  49. -- These parameters match the mapgen.
  50. noise_params = {
  51. flags = "defaults",
  52. lacunarity = 2,
  53. offset = 0,
  54. scale = 1,
  55. spread = {x=768, y=256, z=768},
  56. seed = 59033,
  57. octaves = 6,
  58. persistence = 0.63,
  59. },
  60. -- Mapgen threshold is 0.6.
  61. -- Use a slightly lower threshold so that the sound extends outside the caverns a bit.
  62. noise_threshold = 0.5,
  63. -- The world-seed is very large, causing integer overflow.
  64. -- So we need to get the engine to calculate it against the world seed,
  65. -- in order to ensure we use the same final seed the engine uses.
  66. include_world_seed = true,
  67. absvalue = true,
  68. },
  69. {
  70. name="cavedraft", gain=1.0, miny=-31000, maxy=-256, time="", indoors=nil, mintime=100, maxtime=400,
  71. -- These parameters match the mapgen.
  72. noise_params = {
  73. flags = "defaults",
  74. lacunarity = 2,
  75. offset = 0,
  76. scale = 1,
  77. spread = {x=768, y=256, z=768},
  78. seed = 59033,
  79. octaves = 6,
  80. persistence = 0.63,
  81. },
  82. -- Mapgen threshold is 0.6.
  83. -- Use a slightly lower threshold so that the sound extends outside the caverns a bit.
  84. noise_threshold = 0.5,
  85. -- The world-seed is very large, causing integer overflow.
  86. -- So we need to get the engine to calculate it against the world seed,
  87. -- in order to ensure we use the same final seed the engine uses.
  88. include_world_seed = true,
  89. absvalue = true,
  90. },
  91. {
  92. name="darkwind", gain=1.0, miny=-31000, maxy=-256, time="", indoors=nil, mintime=200, maxtime=500,
  93. -- These parameters match the mapgen.
  94. noise_params = {
  95. flags = "defaults",
  96. lacunarity = 2,
  97. offset = 0,
  98. scale = 1,
  99. spread = {x=768, y=256, z=768},
  100. seed = 59033,
  101. octaves = 6,
  102. persistence = 0.63,
  103. },
  104. -- Mapgen threshold is 0.6.
  105. -- Use a slightly lower threshold so that the sound extends outside the caverns a bit.
  106. noise_threshold = 0.5,
  107. -- The world-seed is very large, causing integer overflow.
  108. -- So we need to get the engine to calculate it against the world seed,
  109. -- in order to ensure we use the same final seed the engine uses.
  110. include_world_seed = true,
  111. absvalue = true,
  112. },
  113. -- This plays in both overworld and channelwood (jarkati has its own entry).
  114. -- Continuous quiet loop.
  115. {name="desertwind", mingain=0.1, maxgain=0.2, miny=-15,maxy=3300,time="", indoors=nil, mintime=6, maxtime=8, },
  116. -- Various animal sounds.
  117. {
  118. name="wolves", gain=1.0, miny=-10, maxy=1000, time="night", indoors=false,
  119. noise_params = {
  120. offset = 0,
  121. scale = 1,
  122. spread = {x=256, y=256, z=256},
  123. seed = 381783,
  124. octaves = 2,
  125. persist = 0.5,
  126. lacunarity = 1.5,
  127. flags = "",
  128. },
  129. noise_threshold = 0.5,
  130. },
  131. {
  132. name="coyote", gain=1.0, miny=-10, maxy=1000, time="night", indoors=false,
  133. noise_params = {
  134. offset = 0,
  135. scale = 1,
  136. spread = {x=256, y=256, z=256},
  137. seed = 6822034,
  138. octaves = 2,
  139. persist = 0.5,
  140. lacunarity = 1.5,
  141. flags = "",
  142. },
  143. noise_threshold = -0.3,
  144. },
  145. {name="craw", gain=1.0, miny=3000, maxy=3300, time="day" , indoors=false, },
  146. {name="hornedowl", gain=1.0, miny=3000, maxy=3300, time="night", indoors=false, },
  147. -- Owl in Overworld.
  148. {
  149. name="owl", gain=1.0, miny=-10, maxy=1000, time="night", indoors=false,
  150. noise_params = {
  151. offset = 0,
  152. scale = 1,
  153. spread = {x=256, y=256, z=256},
  154. seed = 589981,
  155. octaves = 2,
  156. persist = 0.5,
  157. lacunarity = 1.5,
  158. flags = "",
  159. },
  160. noise_threshold = -0.5,
  161. },
  162. -- Owl in Channelwood.
  163. {
  164. name="owl", gain=1.0, miny=3000, maxy=3300, time="night", indoors=false,
  165. noise_params = {
  166. offset = 0,
  167. scale = 1,
  168. spread = {x=256, y=256, z=256},
  169. seed = 2819294,
  170. octaves = 2,
  171. persist = 0.5,
  172. lacunarity = 1.5,
  173. flags = "",
  174. },
  175. noise_threshold = -0.2,
  176. },
  177. -- Continuous lava rumble in the nether.
  178. {name="lava", gain=0.8, miny=-31000, maxy=-25000, time="", indoors=nil, mintime=7, maxtime=7, },
  179. -- More animal sounds. These should play with less frequency.
  180. -- Only in Channelwood. Overworld nature bird/insect sounds use sound-beacons (due to scarcity of trees/water).
  181. {name="cricket", gain=1.0, miny=3000, maxy=3300, time="night", indoors=false, mintime=10, maxtime=30, },
  182. {name="jungle_night_1", gain=1.0, miny=3000, maxy=3300, time="night", indoors=false, mintime=10, maxtime=30, },
  183. {name="cardinal", gain=1.0, miny=3000, maxy=3300, time="day", indoors=false, mintime=20, maxtime=60, },
  184. {name="crestedlark", gain=1.0, miny=3000, maxy=3300, time="day", indoors=false, mintime=20, maxtime=60, },
  185. {name="deer", gain=1.0, miny=3000, maxy=3300, time="night", indoors=false, mintime=20, maxtime=120, },
  186. {name="frog", gain=0.7, miny=3000, maxy=3300, time="liminal", indoors=false, },
  187. {name="frog", gain=0.1, miny=3000, maxy=3070, time="night", indoors=false, mintime=5, maxtime=15},
  188. {name="robin", gain=1.0, miny=3000, maxy=3300, time="day", indoors=false, },
  189. {name="bluejay", gain=1.0, miny=3000, maxy=3300, time="liminal", indoors=false, },
  190. {name="gull", gain=1.0, miny=3000, maxy=3300, time="day", indoors=false, },
  191. {name="peacock", gain=1.0, miny=3000, maxy=3300, time="liminal", indoors=false, },
  192. {
  193. name="canadianloon1", gain=1.0, miny=3000, maxy=3300, time="night", indoors=false, mintime=120, maxtime=360,
  194. noise_params = {
  195. offset = 0,
  196. scale = 1,
  197. spread = {x=256, y=256, z=256},
  198. seed = 6582929,
  199. octaves = 2,
  200. persist = 0.5,
  201. lacunarity = 1.5,
  202. flags = "",
  203. },
  204. noise_threshold = -0.3,
  205. },
  206. -- Noise parameters match the spawning perlin for the moonheron mob.
  207. {
  208. name="night_master", gain=1.0, miny=3000, maxy=3300, time="", indoors=nil, mintime=180, maxtime=360,
  209. noise_params = {
  210. offset = 0,
  211. scale = 1,
  212. spread = {x=512, y=512, z=512},
  213. seed = 2852,
  214. octaves = 5,
  215. persist = 0.5,
  216. lacunarity = 1.5,
  217. flags = "",
  218. },
  219. noise_threshold = 0.4,
  220. },
  221. -- Rare deep cave sounds.
  222. {
  223. name="obsidianmonster_obsidianmonster", gain=1.0, miny=-31000, maxy=-128, time="", indoors=false, mintime=280, maxtime=560,
  224. noise_params = {
  225. offset = 0,
  226. scale = 1,
  227. spread = {x=256, y=256, z=256},
  228. seed = 589731,
  229. octaves = 2,
  230. persist = 0.5,
  231. lacunarity = 1.5,
  232. flags = "",
  233. },
  234. noise_threshold = -0.3,
  235. },
  236. {
  237. name="mobs_sandmonster", gain=1.0, miny=-31000, maxy=-128, time="", indoors=false, mintime=280, maxtime=560,
  238. noise_params = {
  239. offset = 0,
  240. scale = 1,
  241. spread = {x=256, y=256, z=256},
  242. seed = 57187382,
  243. octaves = 2,
  244. persist = 0.5,
  245. lacunarity = 1.5,
  246. flags = "",
  247. },
  248. noise_threshold = -0.3,
  249. },
  250. {
  251. name="mobs_spider", gain=1.0, miny=-31000, maxy=-128, time="", indoors=false, mintime=280, maxtime=560,
  252. noise_params = {
  253. offset = 0,
  254. scale = 1,
  255. spread = {x=256, y=256, z=256},
  256. seed = 5672824,
  257. octaves = 2,
  258. persist = 0.5,
  259. lacunarity = 1.5,
  260. flags = "",
  261. },
  262. noise_threshold = -0.3,
  263. },
  264. -- Nether yuck.
  265. {
  266. name="nether_extract_blood", gain=1.0, miny=-31000, maxy=-20000, time="", indoors=false, mintime=280, maxtime=860,
  267. noise_params = {
  268. offset = 0,
  269. scale = 1,
  270. spread = {x=256, y=256, z=256},
  271. seed = 282934,
  272. octaves = 2,
  273. persist = 0.5,
  274. lacunarity = 1.5,
  275. flags = "",
  276. },
  277. noise_threshold = -0.3,
  278. },
  279. -- Continuous wind on Jarkati surface.
  280. {name="wind1", gain=1.5, miny=3735, maxy=3900, time="", indoors=false, mintime=20, maxtime=40, },
  281. {name="wind2", gain=1.5, miny=3735, maxy=3900, time="", indoors=false, mintime=20, maxtime=40, },
  282. {name="desertwind", gain=1.5, miny=3735, maxy=3900, time="", indoors=false, mintime=20, maxtime=40, },
  283. {name="desertwind", mingain=0.2, maxgain=0.4, miny=3735, maxy=3900, time="", indoors=nil,mintime=6, maxtime=8, }, -- Continuous quiet loop.
  284. -- Continuous wind in the Outback.
  285. {name="wind1", gain=1.0, miny=4160, maxy=4200, time="", indoors=nil, mintime=20, maxtime=40, },
  286. {name="wind2", gain=1.0, miny=4160, maxy=4200, time="", indoors=nil, mintime=20, maxtime=40, },
  287. {name="desertwind", gain=1.0, miny=4160, maxy=4200, time="", indoors=nil, mintime=20, maxtime=40, },
  288. {name="desertwind", mingain=0.2, maxgain=0.4, miny=4160, maxy=4200, time="", indoors=nil,mintime=6, maxtime=8, }, -- Continuous quiet loop.
  289. -- Nighttime insects.
  290. {name="night_cicadas", mingain=0.2, maxgain=1.0, miny=4160, maxy=4200, time="night", indoors=nil,mintime=7, maxtime=11, }, -- Continuous quiet loop.
  291. {name="wolves", mingain=0.2, maxgain=1.3, miny=4160, maxy=4200, time="night", indoors=nil, mintime=20, maxtime=60, },
  292. {name="coyote", mingain=0.2, maxgain=1.3, miny=4160, maxy=4200, time="night", indoors=nil, mintime=10, maxtime=30, },
  293. }
  294. -- Initialize extra table parameters.
  295. minetest.after(0, function()
  296. for k, v in ipairs(ambiance.tmpsounds) do
  297. -- Mintime & maxtime are the min and max seconds a sound can play again after it has played.
  298. -- The timer is reset to a new random value between min and max every time the sound plays.
  299. v.mintime = v.mintime or 30
  300. v.maxtime = v.maxtime or 120
  301. if v.mintime < 0 then v.mintime = 0 end
  302. if v.maxtime < v.mintime then v.maxtime = v.mintime end
  303. -- If minimum or maximum gain are not specified, calculate min and max gain.
  304. v.mingain = v.mingain or (v.gain - 0.5)
  305. v.maxgain = v.maxgain or (v.gain + 0.1)
  306. if v.mingain < 0 then v.mingain = 0 end
  307. if v.maxgain < v.mingain then v.maxgain = v.mingain end
  308. -- Initialize timer to a random value between min and max time.
  309. -- This ensures all sounds start with random times on first run.
  310. v.timer = math_random(v.mintime, v.maxtime)
  311. -- Create perlin noise object if wanted.
  312. if v.noise_params then
  313. if v.include_world_seed then
  314. v.perlin = minetest.get_perlin(v.noise_params)
  315. assert(v.perlin)
  316. else
  317. v.perlin = PerlinNoise(v.noise_params)
  318. assert(v.perlin)
  319. end
  320. assert(v.perlin)
  321. end
  322. v.noise_threshold = v.noise_threshold or 0
  323. end
  324. ambiance.allsounds = ambiance.tmpsounds
  325. ambiance.tmpsounds = nil
  326. end)
  327. -- Lava & scuba sounds (or any special sound) must be handled differently.