world.lua 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. local world = {}
  2. local WIND_SPREAD = 600
  3. local WIND_SCALE = 2
  4. local HEAT_SPREAD = 400
  5. local HEAT_SCALE = 0.3
  6. local HUMIDITY_SPREAD = 150
  7. local HUMIDITY_SCALE = 0.5
  8. local HUMIDITY_BASE_SPREAD = 800
  9. local HUMIDITY_BASE_SCALE = 40
  10. local nobj_wind_x
  11. local nobj_wind_z
  12. local nobj_heat
  13. local nobj_humidity
  14. local nobj_humidity_base
  15. local pn_wind_speed_x = {
  16. offset = 0,
  17. scale = WIND_SCALE * climate_mod.settings.time_spread,
  18. spread = {x = WIND_SPREAD, y = WIND_SPREAD, z = WIND_SPREAD},
  19. seed = 31441,
  20. octaves = 2,
  21. persist = 0.5,
  22. lacunarity = 2
  23. }
  24. local pn_wind_speed_z = {
  25. offset = 0,
  26. scale = WIND_SCALE * climate_mod.settings.time_spread,
  27. spread = {x = WIND_SPREAD, y = WIND_SPREAD, z = WIND_SPREAD},
  28. seed = 938402,
  29. octaves = 2,
  30. persist = 0.5,
  31. lacunarity = 2
  32. }
  33. local pn_heat = {
  34. offset = 1,
  35. scale = HEAT_SCALE * climate_mod.settings.time_spread,
  36. spread = {x = HEAT_SPREAD, y = HEAT_SPREAD, z = HEAT_SPREAD},
  37. seed = 24,
  38. octaves = 2,
  39. persist = 0.5,
  40. lacunarity = 2
  41. }
  42. local pn_humidity = {
  43. offset = 1,
  44. scale = HUMIDITY_SCALE * climate_mod.settings.time_spread,
  45. spread = {x = HUMIDITY_SPREAD, y = HUMIDITY_SPREAD, z = HUMIDITY_SPREAD},
  46. seed = 8374061,
  47. octaves = 3,
  48. persist = 0.5,
  49. lacunarity = 2
  50. }
  51. local pn_humidity_base = {
  52. offset = 50,
  53. scale = HUMIDITY_BASE_SCALE * climate_mod.settings.time_spread,
  54. spread = {x = HUMIDITY_BASE_SPREAD, y = HUMIDITY_BASE_SPREAD, z = HUMIDITY_BASE_SPREAD},
  55. seed = 3803465,
  56. octaves = 2,
  57. persist = 0.5,
  58. lacunarity = 2
  59. }
  60. local function update_wind(timer)
  61. nobj_wind_x = nobj_wind_x or minetest.get_perlin(pn_wind_speed_x)
  62. nobj_wind_z = nobj_wind_z or minetest.get_perlin(pn_wind_speed_z)
  63. local n_wind_x = nobj_wind_x:get_2d({x = timer, y = 0})
  64. local n_wind_z = nobj_wind_z:get_2d({x = timer, y = 0})
  65. climate_mod.state:set_float("wind_x", n_wind_x)
  66. climate_mod.state:set_float("wind_z", n_wind_z)
  67. end
  68. local function update_heat(timer)
  69. nobj_heat = nobj_heat or minetest.get_perlin(pn_heat)
  70. local n_heat = nobj_heat:get_2d({x = timer, y = 0})
  71. climate_mod.state:set_float("heat_random", n_heat)
  72. end
  73. local function update_humidity(timer)
  74. nobj_humidity = nobj_humidity or minetest.get_perlin(pn_humidity)
  75. local n_humidity = nobj_humidity:get_2d({x = timer, y = 0})
  76. climate_mod.state:set_float("humidity_random", n_humidity)
  77. nobj_humidity_base = nobj_humidity_base or minetest.get_perlin(pn_humidity_base)
  78. local n_humidity_base = nobj_humidity_base:get_2d({x = timer, y = 0})
  79. climate_mod.state:set_float("humidity_base", n_humidity_base)
  80. end
  81. function world.update_status(timer)
  82. update_wind(timer)
  83. update_heat(timer)
  84. update_humidity(timer)
  85. end
  86. return world