data.lua 18 KB

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