mapgen.lua 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. -- Content IDs used with the voxel manipulator.
  2. local c_rock = minetest.get_content_id("default:stone")
  3. local c_water = minetest.get_content_id("default:water_source")
  4. local c_silt = minetest.get_content_id("darkage:silt")
  5. local c_mud = minetest.get_content_id("darkage:mud")
  6. local c_ore1 = minetest.get_content_id("darkage:ors")
  7. local c_ore2 = minetest.get_content_id("darkage:shale")
  8. local c_ore3 = minetest.get_content_id("darkage:slate")
  9. local c_ore4 = minetest.get_content_id("darkage:basaltic")
  10. local c_ore5 = minetest.get_content_id("darkage:marble")
  11. local c_ore6 = minetest.get_content_id("darkage:gneiss")
  12. local c_ore7 = minetest.get_content_id("darkage:schist")
  13. local c_ore8 = minetest.get_content_id("darkage:chalk")
  14. local c_ore10 = minetest.get_content_id("darkage:rhyolitic_tuff")
  15. local c_ore11 = minetest.get_content_id("darkage:tuff")
  16. -- Both of these are craftable from existing rock types.
  17. -- darkage:rhyolitic_tuff
  18. -- darkage:tuff
  19. -- These generate at ocean bottoms.
  20. -- darkage:silt
  21. -- darkage:mud
  22. -- Already craftable.
  23. -- darkage:darkdirt
  24. -- Externally located tables for performance.
  25. local data = {}
  26. local noisemap1 = {}
  27. local noisemap2 = {}
  28. local noisemap3 = {}
  29. local noisemap4 = {}
  30. local noisemap5 = {}
  31. local noisemap6 = {}
  32. local noisemap7 = {}
  33. local noisemap8 = {}
  34. local noisemap9 = {}
  35. local noisemap10= {}
  36. local noisemap11= {}
  37. darkgen.generate_realm = function(minp, maxp, seed)
  38. local nstart = darkgen.SHEET_HEIGHT
  39. -- Don't run for out-of-bounds mapchunks.
  40. -- Need -100 in order to include ocean basins under the ice.
  41. if minp.y > (nstart + 200) or maxp.y < (nstart - 100) then return end
  42. -- Grab the voxel manipulator.
  43. local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
  44. vm:get_data(data) -- Read current map data.
  45. local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
  46. local area2 = VoxelArea:new{MinEdge=minp, MaxEdge=maxp}
  47. local pr = PseudoRandom(seed + 71)
  48. local x1 = maxp.x
  49. local y1 = maxp.y
  50. local z1 = maxp.z
  51. local x0 = minp.x
  52. local y0 = minp.y
  53. local z0 = minp.z
  54. -- Compute side lengths.
  55. local side_len_x = ((x1-x0)+1)
  56. local side_len_y = ((y1-y0)+1)
  57. local side_len_z = ((z1-z0)+1)
  58. local sides3D = {x=side_len_x, y=side_len_y, z=side_len_z}
  59. local sides2D = {x=side_len_x, y=side_len_z}
  60. local bp3d = {x=x0, y=y0, z=z0}
  61. local bp2d = {x=x0, y=z0}
  62. -- Get noisemaps.
  63. local perlin1 = minetest.get_perlin_map(darkgen.noise1param2d, sides2D)
  64. perlin1:get_2d_map_flat(bp2d, noisemap1)
  65. local perlin2 = minetest.get_perlin_map(darkgen.noise2param2d, sides2D)
  66. perlin2:get_2d_map_flat(bp2d, noisemap2)
  67. local perlin3 = minetest.get_perlin_map(darkgen.noise3param2d, sides2D)
  68. perlin3:get_2d_map_flat(bp2d, noisemap3)
  69. local perlin4 = minetest.get_perlin_map(darkgen.noise4param2d, sides2D)
  70. perlin4:get_2d_map_flat(bp2d, noisemap4)
  71. local perlin5 = minetest.get_perlin_map(darkgen.noise5param2d, sides2D)
  72. perlin5:get_2d_map_flat(bp2d, noisemap5)
  73. local perlin6 = minetest.get_perlin_map(darkgen.noise6param2d, sides2D)
  74. perlin6:get_2d_map_flat(bp2d, noisemap6)
  75. local perlin7 = minetest.get_perlin_map(darkgen.noise7param2d, sides2D)
  76. perlin7:get_2d_map_flat(bp2d, noisemap7)
  77. local perlin8 = minetest.get_perlin_map(darkgen.noise8param2d, sides2D)
  78. perlin8:get_2d_map_flat(bp2d, noisemap8)
  79. local perlin9 = minetest.get_perlin_map(darkgen.noise9param2d, sides2D)
  80. perlin9:get_2d_map_flat(bp2d, noisemap9)
  81. local perlin10 = minetest.get_perlin_map(darkgen.noise10param2d, sides2D)
  82. perlin10:get_2d_map_flat(bp2d, noisemap10)
  83. local perlin11 = minetest.get_perlin_map(darkgen.noise11param2d, sides2D)
  84. perlin11:get_2d_map_flat(bp2d, noisemap11)
  85. -- Localize commonly used functions.
  86. local floor = math.floor
  87. local ceil = math.ceil
  88. local abs = math.abs
  89. local function apply_ore(v, y, n, f, m, o)
  90. local bot = (nstart + f) - (n*m)
  91. local top = (nstart + f) + (n*m)
  92. if y >= bot and y <= top then
  93. if data[v] == c_rock then
  94. data[v] = o
  95. end
  96. end
  97. end
  98. -- First mapgen pass.
  99. for z = z0, z1 do
  100. for x = x0, x1 do
  101. -- Get index into 2D noise arrays.
  102. local nx = (x-x0)
  103. local nz = (z-z0)
  104. local ni2 = (side_len_z*nz+nx)
  105. ni2 = ni2 + 1 -- Lua arrays start indexing at 1, not 0. Urrrrgh. >:(
  106. local n1 = noisemap1[ni2]
  107. local n2 = noisemap2[ni2]
  108. local n3 = noisemap3[ni2]
  109. local n4 = noisemap4[ni2]
  110. local n5 = noisemap5[ni2]
  111. local n6 = noisemap6[ni2]
  112. local n7 = noisemap7[ni2]
  113. local n8 = noisemap8[ni2]
  114. local n9 = noisemap9[ni2]
  115. local n10= noisemap10[ni2]
  116. local n11= noisemap11[ni2]
  117. -- First pass through column.
  118. for y = y0, y1 do
  119. local vp = area:index(x, y, z)
  120. local vu = area:index(x, y+1, z)
  121. local vd = area:index(x, y-1, z)
  122. local vd2 = area:index(x, y-2, z)
  123. -- Layer silt at ocean bottoms.
  124. if data[vp] == c_rock and data[vu] == c_water then
  125. data[vp] = c_silt
  126. data[vd] = c_silt
  127. data[vd2] = c_mud
  128. end
  129. local mult = 40
  130. local off = n9 * 16
  131. for k = 1, 1, 1 do
  132. apply_ore(vp, y, n1, 0 + (k*mult) + off, 2, c_ore1)
  133. apply_ore(vp, y, n2, 4 + (k*mult) + off, 2, c_ore2)
  134. apply_ore(vp, y, n3, -4 + (k*mult) + off, 2, c_ore3)
  135. apply_ore(vp, y, n4, -8 + (k*mult) + off, 2, c_ore4)
  136. apply_ore(vp, y, n5, -12 + (k*mult) + off, 2, c_ore5)
  137. apply_ore(vp, y, n6, 8 + (k*mult) + off, 2, c_ore6)
  138. apply_ore(vp, y, n7, 12 + (k*mult) + off, 2, c_ore7)
  139. apply_ore(vp, y, n8, 18 + (k*mult) + off, 2, c_ore8)
  140. end
  141. apply_ore(vp, y, n10, 80 + off, 4, c_ore10)
  142. apply_ore(vp, y, n11, 90 + off, 4, c_ore11)
  143. end -- For all in Y coordinates.
  144. end -- For all in X coordinates.
  145. end -- For all in Z coordinates.
  146. -- Finalize voxel manipulator.
  147. vm:set_data(data)
  148. --vm:set_lighting({day=0, night=0})
  149. --vm:calc_lighting()
  150. --vm:update_liquids()
  151. vm:write_to_map()
  152. end