Began moving values to config.lua so they can be specified in the .conf file
parent
9cee177c65
commit
045e9641d2
|
@ -0,0 +1,24 @@
|
||||||
|
|
||||||
|
local CONFIG_FILE_PREFIX = "caverealms."
|
||||||
|
|
||||||
|
caverealms.config = {}
|
||||||
|
|
||||||
|
-- This function based on kaeza/minetest-irc/config.lua and used under the
|
||||||
|
-- terms of BSD 2-clause license.
|
||||||
|
local function setting(stype, name, default)
|
||||||
|
local value
|
||||||
|
if stype == "bool" then
|
||||||
|
value = minetest.setting_getbool(CONFIG_FILE_PREFIX..name)
|
||||||
|
elseif stype == "string" then
|
||||||
|
value = minetest.setting_get(CONFIG_FILE_PREFIX..name)
|
||||||
|
elseif stype == "number" then
|
||||||
|
value = tonumber(minetest.setting_get(CONFIG_FILE_PREFIX..name))
|
||||||
|
end
|
||||||
|
if value == nil then
|
||||||
|
value = default
|
||||||
|
end
|
||||||
|
caverealms.config[name] = value
|
||||||
|
end
|
||||||
|
|
||||||
|
setting("number", "ymin", -33000)
|
||||||
|
setting("number", "ymax", -700)
|
52
init.lua
52
init.lua
|
@ -3,10 +3,16 @@
|
||||||
-- Depends default
|
-- Depends default
|
||||||
-- License: code WTFPL
|
-- License: code WTFPL
|
||||||
|
|
||||||
-- Parameters
|
caverealms = {}
|
||||||
|
|
||||||
local YMIN = -33000 -- Approximate realm limits.
|
local modpath = minetest.get_modpath(minetest.get_current_modname())
|
||||||
local YMAX = -700
|
|
||||||
|
dofile(modpath.."/config.lua")
|
||||||
|
|
||||||
|
-- Parameters (see also config.lua)
|
||||||
|
|
||||||
|
local YMIN = caverealms.config.ymin -- Approximate realm limits.
|
||||||
|
local YMAX = caverealms.config.ymax
|
||||||
local XMIN = -33000
|
local XMIN = -33000
|
||||||
local XMAX = 33000
|
local XMAX = 33000
|
||||||
local ZMIN = -33000
|
local ZMIN = -33000
|
||||||
|
@ -64,10 +70,6 @@ local np_wave = {
|
||||||
persist = 0.5
|
persist = 0.5
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Stuff
|
|
||||||
|
|
||||||
caverealms = {}
|
|
||||||
|
|
||||||
-- Nodes
|
-- Nodes
|
||||||
|
|
||||||
--glowing crystal
|
--glowing crystal
|
||||||
|
@ -136,7 +138,7 @@ minetest.register_node("caverealms:stone_with_moss", {
|
||||||
function caverealms:stalagmite(x,y,z, area, data)
|
function caverealms:stalagmite(x,y,z, area, data)
|
||||||
--contest ids
|
--contest ids
|
||||||
local c_stone = minetest.get_content_id("default:stone")
|
local c_stone = minetest.get_content_id("default:stone")
|
||||||
|
|
||||||
local top = math.random(6,H_LAG) --grab a random height for the stalagmite
|
local top = math.random(6,H_LAG) --grab a random height for the stalagmite
|
||||||
for j = 0, top do --y
|
for j = 0, top do --y
|
||||||
for k = -3, 3 do
|
for k = -3, 3 do
|
||||||
|
@ -169,7 +171,7 @@ end
|
||||||
function caverealms:stalactite(x,y,z, area, data)
|
function caverealms:stalactite(x,y,z, area, data)
|
||||||
--contest ids
|
--contest ids
|
||||||
local c_stone = minetest.get_content_id("default:stone")--("caverealms:limestone")
|
local c_stone = minetest.get_content_id("default:stone")--("caverealms:limestone")
|
||||||
|
|
||||||
local bot = math.random(-H_LAC, -6) --grab a random height for the stalagmite
|
local bot = math.random(-H_LAC, -6) --grab a random height for the stalagmite
|
||||||
for j = bot, 0 do --y
|
for j = bot, 0 do --y
|
||||||
for k = -3, 3 do
|
for k = -3, 3 do
|
||||||
|
@ -204,7 +206,7 @@ function caverealms:crystal_stalagmite(x,y,z, area, data)
|
||||||
local c_stone = minetest.get_content_id("default:stone")
|
local c_stone = minetest.get_content_id("default:stone")
|
||||||
local c_crystal = minetest.get_content_id("caverealms:glow_crystal")
|
local c_crystal = minetest.get_content_id("caverealms:glow_crystal")
|
||||||
local c_crystore = minetest.get_content_id("caverealms:glow_ore")
|
local c_crystore = minetest.get_content_id("caverealms:glow_ore")
|
||||||
|
|
||||||
local top = math.random(5,H_CRY) --grab a random height for the stalagmite
|
local top = math.random(5,H_CRY) --grab a random height for the stalagmite
|
||||||
for j = 0, top do --y
|
for j = 0, top do --y
|
||||||
for k = -3, 3 do
|
for k = -3, 3 do
|
||||||
|
@ -243,13 +245,13 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||||
or minp.z < ZMIN or maxp.z > ZMAX then
|
or minp.z < ZMIN or maxp.z > ZMAX then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
--determine if there's enough spacing between layers to start a realm
|
--determine if there's enough spacing between layers to start a realm
|
||||||
local chulay = math.floor((minp.y + 32) / 80) -- chunk layer number, 0 = surface chunk
|
local chulay = math.floor((minp.y + 32) / 80) -- chunk layer number, 0 = surface chunk
|
||||||
if math.fmod(chulay, CHUINT) ~= 0 then -- if chulay / CHUINT has a remainder
|
if math.fmod(chulay, CHUINT) ~= 0 then -- if chulay / CHUINT has a remainder
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
--easy to reference variables for limits and time
|
--easy to reference variables for limits and time
|
||||||
local t1 = os.clock()
|
local t1 = os.clock()
|
||||||
local x1 = maxp.x
|
local x1 = maxp.x
|
||||||
|
@ -258,21 +260,21 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||||
local x0 = minp.x
|
local x0 = minp.x
|
||||||
local y0 = minp.y
|
local y0 = minp.y
|
||||||
local z0 = minp.z
|
local z0 = minp.z
|
||||||
|
|
||||||
--let people know you're generating a realm
|
--let people know you're generating a realm
|
||||||
print ("[caverealms] chunk minp ("..x0.." "..y0.." "..z0..")")
|
print ("[caverealms] chunk minp ("..x0.." "..y0.." "..z0..")")
|
||||||
|
|
||||||
--fire up the LVM
|
--fire up the LVM
|
||||||
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
||||||
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
|
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
|
||||||
local data = vm:get_data()
|
local data = vm:get_data()
|
||||||
|
|
||||||
--grab content IDs
|
--grab content IDs
|
||||||
local c_air = minetest.get_content_id("air")
|
local c_air = minetest.get_content_id("air")
|
||||||
local c_crystal = minetest.get_content_id("caverealms:glow_crystal")
|
local c_crystal = minetest.get_content_id("caverealms:glow_crystal")
|
||||||
local c_gem = minetest.get_content_id("caverealms:glow_gem")
|
local c_gem = minetest.get_content_id("caverealms:glow_gem")
|
||||||
local c_moss = minetest.get_content_id("caverealms:stone_with_moss")
|
local c_moss = minetest.get_content_id("caverealms:stone_with_moss")
|
||||||
|
|
||||||
--some mandatory values
|
--some mandatory values
|
||||||
local sidelen = x1 - x0 + 1 --usually equals 80 with default mapgen values. Always a multiple of 16.
|
local sidelen = x1 - x0 + 1 --usually equals 80 with default mapgen values. Always a multiple of 16.
|
||||||
local chulens = {x=sidelen, y=sidelen, z=sidelen} --position table to pass to get3dMap_flat
|
local chulens = {x=sidelen, y=sidelen, z=sidelen} --position table to pass to get3dMap_flat
|
||||||
|
@ -284,7 +286,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||||
local nvals_cluster = minetest.get_perlin_map(np_cluster, chulens):get3dMap_flat(minposxyz)
|
local nvals_cluster = minetest.get_perlin_map(np_cluster, chulens):get3dMap_flat(minposxyz)
|
||||||
|
|
||||||
local nvals_wave = minetest.get_perlin_map(np_wave, chulens):get2dMap_flat(minposxz)
|
local nvals_wave = minetest.get_perlin_map(np_wave, chulens):get2dMap_flat(minposxz)
|
||||||
|
|
||||||
--more values
|
--more values
|
||||||
local nixyz = 1 --short for node index xyz
|
local nixyz = 1 --short for node index xyz
|
||||||
local nixz = 1 --node index xz
|
local nixz = 1 --node index xz
|
||||||
|
@ -295,9 +297,9 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||||
local nixyz2 = 1
|
local nixyz2 = 1
|
||||||
local nixz2 = 1
|
local nixz2 = 1
|
||||||
local stable2 = {}
|
local stable2 = {}
|
||||||
|
|
||||||
for z = z0, z1 do --for each xy plane progressing northwards
|
for z = z0, z1 do --for each xy plane progressing northwards
|
||||||
for x = x0, x1 do
|
for x = x0, x1 do
|
||||||
local si = x - x0 + 1 --stability index
|
local si = x - x0 + 1 --stability index
|
||||||
dirt[si] = 0 --no dirt here... yet
|
dirt[si] = 0 --no dirt here... yet
|
||||||
roof[si] = 0
|
roof[si] = 0
|
||||||
|
@ -333,7 +335,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||||
else
|
else
|
||||||
stable[si] = stable[si] + 1
|
stable[si] = stable[si] + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif dirt[si] >= 1 then -- node above surface
|
elseif dirt[si] >= 1 then -- node above surface
|
||||||
--place dirt on floor, add plants
|
--place dirt on floor, add plants
|
||||||
data[vi] = c_moss
|
data[vi] = c_moss
|
||||||
|
@ -361,7 +363,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||||
nixz = nixz - sidelen --shift the 2D index down a layer
|
nixz = nixz - sidelen --shift the 2D index down a layer
|
||||||
end
|
end
|
||||||
nixz = nixz + sidelen --shift the 2D index up a layer
|
nixz = nixz + sidelen --shift the 2D index up a layer
|
||||||
|
|
||||||
--second loop to obtain ceiling
|
--second loop to obtain ceiling
|
||||||
for y = y0, y1 do -- for each x row progressing downwards
|
for y = y0, y1 do -- for each x row progressing downwards
|
||||||
local vi = area:index(x0, y, z) --grab the index of the node to edit
|
local vi = area:index(x0, y, z) --grab the index of the node to edit
|
||||||
|
@ -382,7 +384,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||||
else
|
else
|
||||||
stable2[si] = stable2[si] + 1
|
stable2[si] = stable2[si] + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif roof[si] >= 1 then --and stable2[si] >= 2 then -- node above surface
|
elseif roof[si] >= 1 then --and stable2[si] >= 2 then -- node above surface
|
||||||
if math.random() <= STALCHA then
|
if math.random() <= STALCHA then
|
||||||
local ai = area:index(x,y+1,z)
|
local ai = area:index(x,y+1,z)
|
||||||
|
@ -402,8 +404,8 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||||
end
|
end
|
||||||
nixz2 = nixz2 + sidelen
|
nixz2 = nixz2 + sidelen
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--write these changes to the world
|
--write these changes to the world
|
||||||
vm:set_data(data)
|
vm:set_data(data)
|
||||||
vm:set_lighting({day=0, night=0})
|
vm:set_lighting({day=0, night=0})
|
||||||
|
@ -411,4 +413,4 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||||
vm:write_to_map(data)
|
vm:write_to_map(data)
|
||||||
local chugent = math.ceil((os.clock() - t1) * 1000) --grab how long this took
|
local chugent = math.ceil((os.clock() - t1) * 1000) --grab how long this took
|
||||||
print ("[caverealms] "..chugent.." ms") --tell people how long it took
|
print ("[caverealms] "..chugent.." ms") --tell people how long it took
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Reference in New Issue