data.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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. },
  68. {
  69. name="cavedraft", gain=1.0, miny=-31000, maxy=-256, time="", indoors=nil, mintime=100, maxtime=400,
  70. -- These parameters match the mapgen.
  71. noise_params = {
  72. flags = "defaults",
  73. lacunarity = 2,
  74. offset = 0,
  75. scale = 1,
  76. spread = {x=768, y=256, z=768},
  77. seed = 59033,
  78. octaves = 6,
  79. persistence = 0.63,
  80. },
  81. -- Mapgen threshold is 0.6.
  82. -- Use a slightly lower threshold so that the sound extends outside the caverns a bit.
  83. noise_threshold = 0.5,
  84. -- The world-seed is very large, causing integer overflow.
  85. -- So we need to get the engine to calculate it against the world seed,
  86. -- in order to ensure we use the same final seed the engine uses.
  87. include_world_seed = true,
  88. },
  89. {
  90. name="darkwind", gain=1.0, miny=-31000, maxy=-256, time="", indoors=nil, mintime=200, maxtime=500,
  91. -- These parameters match the mapgen.
  92. noise_params = {
  93. flags = "defaults",
  94. lacunarity = 2,
  95. offset = 0,
  96. scale = 1,
  97. spread = {x=768, y=256, z=768},
  98. seed = 59033,
  99. octaves = 6,
  100. persistence = 0.63,
  101. },
  102. -- Mapgen threshold is 0.6.
  103. -- Use a slightly lower threshold so that the sound extends outside the caverns a bit.
  104. noise_threshold = 0.5,
  105. -- The world-seed is very large, causing integer overflow.
  106. -- So we need to get the engine to calculate it against the world seed,
  107. -- in order to ensure we use the same final seed the engine uses.
  108. include_world_seed = true,
  109. },
  110. -- This plays in both overworld and channelwood (jarkati has its own entry).
  111. {name="desertwind", mingain=0.2, maxgain=0.4, miny=-15,maxy=3300,time="", indoors=nil, mintime=6, maxtime=8, }, -- Continuous quiet loop.
  112. -- Various animal sounds.
  113. {
  114. name="wolves", gain=1.0, miny=-10, maxy=1000, time="night", indoors=false,
  115. noise_params = {
  116. offset = 0,
  117. scale = 1,
  118. spread = {x=256, y=256, z=256},
  119. seed = 381783,
  120. octaves = 2,
  121. persist = 0.5,
  122. lacunarity = 1.5,
  123. flags = "",
  124. },
  125. noise_threshold = 0.3,
  126. },
  127. {
  128. name="coyote", gain=1.0, miny=-10, maxy=1000, time="night", indoors=false,
  129. noise_params = {
  130. offset = 0,
  131. scale = 1,
  132. spread = {x=256, y=256, z=256},
  133. seed = 6822034,
  134. octaves = 2,
  135. persist = 0.5,
  136. lacunarity = 1.5,
  137. flags = "",
  138. },
  139. noise_threshold = 0.3,
  140. },
  141. {name="craw", gain=1.0, miny=3000, maxy=3300, time="day" , indoors=false, },
  142. {name="hornedowl", gain=1.0, miny=3000, maxy=3300, time="night", indoors=false, },
  143. -- Owl in Overworld.
  144. {
  145. name="owl", gain=1.0, miny=-10, maxy=1000, time="night", indoors=false,
  146. noise_params = {
  147. offset = 0,
  148. scale = 1,
  149. spread = {x=256, y=256, z=256},
  150. seed = 589981,
  151. octaves = 2,
  152. persist = 0.5,
  153. lacunarity = 1.5,
  154. flags = "",
  155. },
  156. noise_threshold = 0.5,
  157. },
  158. -- Owl in Channelwood.
  159. {
  160. name="owl", gain=1.0, miny=3000, maxy=3300, time="night", indoors=false,
  161. noise_params = {
  162. offset = 0,
  163. scale = 1,
  164. spread = {x=256, y=256, z=256},
  165. seed = 2819294,
  166. octaves = 2,
  167. persist = 0.5,
  168. lacunarity = 1.5,
  169. flags = "",
  170. },
  171. noise_threshold = 0.2,
  172. },
  173. -- Continuous lava rumble in the nether.
  174. {name="lava", gain=0.8, miny=-31000, maxy=-25000, time="", indoors=nil, mintime=7, maxtime=7, },
  175. -- More animal sounds. These should play with less frequency.
  176. -- Only in Channelwood. Overworld nature bird/insect sounds use sound-beacons (due to scarcity of trees/water).
  177. {name="cricket", gain=1.0, miny=3000, maxy=3300, time="night", indoors=false, mintime=10, maxtime=30, },
  178. {name="jungle_night_1", gain=1.0, miny=3000, maxy=3300, time="night", indoors=false, mintime=10, maxtime=30, },
  179. {name="cardinal", gain=1.0, miny=3000, maxy=3300, time="day", indoors=false, mintime=20, maxtime=60, },
  180. {name="crestedlark", gain=1.0, miny=3000, maxy=3300, time="day", indoors=false, mintime=20, maxtime=60, },
  181. {name="deer", gain=1.0, miny=3000, maxy=3300, time="night", indoors=false, mintime=20, maxtime=120, },
  182. {name="frog", gain=0.7, miny=3000, maxy=3300, time="liminal", indoors=false, },
  183. {name="robin", gain=1.0, miny=3000, maxy=3300, time="day", indoors=false, },
  184. {name="bluejay", gain=1.0, miny=3000, maxy=3300, time="liminal", indoors=false, },
  185. {name="gull", gain=1.0, miny=3000, maxy=3300, time="day", indoors=false, },
  186. {name="peacock", gain=1.0, miny=3000, maxy=3300, time="liminal", indoors=false, },
  187. {
  188. name="canadianloon1", gain=1.0, miny=3000, maxy=3300, time="night", indoors=false, mintime=120, maxtime=360,
  189. noise_params = {
  190. offset = 0,
  191. scale = 1,
  192. spread = {x=256, y=256, z=256},
  193. seed = 6582929,
  194. octaves = 2,
  195. persist = 0.5,
  196. lacunarity = 1.5,
  197. flags = "",
  198. },
  199. noise_threshold = 0.3,
  200. },
  201. -- Rare deep cave sounds.
  202. {
  203. name="obsidianmonster_obsidianmonster", gain=1.0, miny=-31000, maxy=-128, time="", indoors=false, mintime=280, maxtime=560,
  204. noise_params = {
  205. offset = 0,
  206. scale = 1,
  207. spread = {x=256, y=256, z=256},
  208. seed = 589731,
  209. octaves = 2,
  210. persist = 0.5,
  211. lacunarity = 1.5,
  212. flags = "",
  213. },
  214. noise_threshold = 0.3,
  215. },
  216. {
  217. name="mobs_sandmonster", gain=1.0, miny=-31000, maxy=-128, time="", indoors=false, mintime=280, maxtime=560,
  218. noise_params = {
  219. offset = 0,
  220. scale = 1,
  221. spread = {x=256, y=256, z=256},
  222. seed = 57187382,
  223. octaves = 2,
  224. persist = 0.5,
  225. lacunarity = 1.5,
  226. flags = "",
  227. },
  228. noise_threshold = 0.3,
  229. },
  230. {
  231. name="mobs_spider", gain=1.0, miny=-31000, maxy=-128, time="", indoors=false, mintime=280, maxtime=560,
  232. noise_params = {
  233. offset = 0,
  234. scale = 1,
  235. spread = {x=256, y=256, z=256},
  236. seed = 5672824,
  237. octaves = 2,
  238. persist = 0.5,
  239. lacunarity = 1.5,
  240. flags = "",
  241. },
  242. noise_threshold = 0.3,
  243. },
  244. -- Nether yuck.
  245. {
  246. name="nether_extract_blood", gain=1.0, miny=-31000, maxy=-20000, time="", indoors=false, mintime=280, maxtime=860,
  247. noise_params = {
  248. offset = 0,
  249. scale = 1,
  250. spread = {x=256, y=256, z=256},
  251. seed = 282934,
  252. octaves = 2,
  253. persist = 0.5,
  254. lacunarity = 1.5,
  255. flags = "",
  256. },
  257. noise_threshold = 0.3,
  258. },
  259. -- Continuous wind on Jarkati surface.
  260. {name="wind1", gain=1.5, miny=3735, maxy=3900, time="", indoors=false, mintime=20, maxtime=40, },
  261. {name="wind2", gain=1.5, miny=3735, maxy=3900, time="", indoors=false, mintime=20, maxtime=40, },
  262. {name="desertwind", gain=1.5, miny=3735, maxy=3900, time="", indoors=false, mintime=20, maxtime=40, },
  263. {name="desertwind", mingain=0.2, maxgain=0.4, miny=3735, maxy=3900, time="", indoors=nil,mintime=6, maxtime=8, }, -- Continuous quiet loop.
  264. -- Continuous wind in the Outback.
  265. {name="wind1", gain=1.0, miny=4160, maxy=4200, time="", indoors=nil, mintime=20, maxtime=40, },
  266. {name="wind2", gain=1.0, miny=4160, maxy=4200, time="", indoors=nil, mintime=20, maxtime=40, },
  267. {name="desertwind", gain=1.0, miny=4160, maxy=4200, time="", indoors=nil, mintime=20, maxtime=40, },
  268. {name="desertwind", mingain=0.2, maxgain=0.4, miny=4160, maxy=4200, time="", indoors=nil,mintime=6, maxtime=8, }, -- Continuous quiet loop.
  269. -- Nighttime insects.
  270. {name="night_cicadas", mingain=0.2, maxgain=1.0, miny=4160, maxy=4200, time="night", indoors=nil,mintime=7, maxtime=11, }, -- Continuous quiet loop.
  271. {name="wolves", mingain=0.2, maxgain=1.3, miny=4160, maxy=4200, time="night", indoors=nil, mintime=20, maxtime=60, },
  272. {name="coyote", mingain=0.2, maxgain=1.3, miny=4160, maxy=4200, time="night", indoors=nil, mintime=10, maxtime=30, },
  273. }
  274. -- Initialize extra table parameters.
  275. minetest.after(0, function()
  276. for k, v in ipairs(ambiance.tmpsounds) do
  277. -- Mintime & maxtime are the min and max seconds a sound can play again after it has played.
  278. -- The timer is reset to a new random value between min and max every time the sound plays.
  279. v.mintime = v.mintime or 30
  280. v.maxtime = v.maxtime or 120
  281. if v.mintime < 0 then v.mintime = 0 end
  282. if v.maxtime < v.mintime then v.maxtime = v.mintime end
  283. -- If minimum or maximum gain are not specified, calculate min and max gain.
  284. v.mingain = v.mingain or (v.gain - 0.5)
  285. v.maxgain = v.maxgain or (v.gain + 0.1)
  286. if v.mingain < 0 then v.mingain = 0 end
  287. if v.maxgain < v.mingain then v.maxgain = v.mingain end
  288. -- Initialize timer to a random value between min and max time.
  289. -- This ensures all sounds start with random times on first run.
  290. v.timer = math_random(v.mintime, v.maxtime)
  291. -- Create perlin noise object if wanted.
  292. if v.noise_params then
  293. if v.include_world_seed then
  294. v.perlin = minetest.get_perlin(v.noise_params)
  295. assert(v.perlin)
  296. else
  297. v.perlin = PerlinNoise(v.noise_params)
  298. assert(v.perlin)
  299. end
  300. assert(v.perlin)
  301. end
  302. v.noise_threshold = v.noise_threshold or 0
  303. end
  304. ambiance.allsounds = ambiance.tmpsounds
  305. ambiance.tmpsounds = nil
  306. end)
  307. -- Lava & scuba sounds (or any special sound) must be handled differently.