Fix a lot of whitespace and localize some more variables.
This commit is contained in:
parent
09bb938a4a
commit
9d082c701a
129
init.lua
129
init.lua
@ -1,12 +1,15 @@
|
||||
mg = {}
|
||||
|
||||
local ENABLE_SNOW = false
|
||||
local DEBUG = false
|
||||
|
||||
local DMAX = 20
|
||||
local AREA_SIZE = 80
|
||||
|
||||
dofile(minetest.get_modpath(minetest.get_current_modname()).."/nodes.lua")
|
||||
c_air = minetest.get_content_id("air")
|
||||
c_air = minetest.get_content_id("air")
|
||||
c_ignore = minetest.get_content_id("ignore")
|
||||
c_water = minetest.get_content_id("default:water_source")
|
||||
c_grass = minetest.get_content_id("default:dirt_with_grass")
|
||||
c_dry_grass = minetest.get_content_id("mg:dirt_with_dry_grass")
|
||||
c_dirt_snow = minetest.get_content_id("default:dirt_with_snow")
|
||||
@ -114,6 +117,7 @@ function inside_village(x, z, village, vnoise)
|
||||
return get_vn(x, z, vnoise:get2d({x = x, y = z}), village) <= 40
|
||||
end
|
||||
|
||||
local wseed
|
||||
minetest.register_on_mapgen_init(function(mgparams)
|
||||
wseed = math.floor(mgparams.seed/10000000000)
|
||||
end)
|
||||
@ -125,10 +129,6 @@ function get_bseed2(minp)
|
||||
return wseed + math.floor(87*minp.x/47) + math.floor(73*minp.z/91) + math.floor(31*minp.y/12)
|
||||
end
|
||||
|
||||
c_air = minetest.get_content_id("air")
|
||||
c_ignore = minetest.get_content_id("ignore")
|
||||
c_water = minetest.get_content_id("default:water_source")
|
||||
|
||||
local function add_leaves(data, vi, c_leaves, c_snow)
|
||||
if data[vi]==c_air or data[vi]==c_ignore or data[vi] == c_snow then
|
||||
data[vi] = c_leaves
|
||||
@ -439,48 +439,42 @@ local function mg_generate(minp, maxp, emin, emax, vm)
|
||||
local data = vm:get_data()
|
||||
local param2_data = vm:get_param2_data()
|
||||
|
||||
local ni = 1
|
||||
local above_top
|
||||
local liquid_top
|
||||
local top
|
||||
local top_layer
|
||||
local second_layer
|
||||
local humidity
|
||||
local temperature
|
||||
local villages_to_grow = {}
|
||||
local ni = 0
|
||||
for z = minp.z, maxp.z do
|
||||
for x = minp.x, maxp.x do
|
||||
ni = ni + 1
|
||||
local y = math.floor(surface_at_point(x, z, village_noise_map, villages, ni, noise1, noise2, noise3, noise4))
|
||||
humidity = noise_humidity[ni]
|
||||
temperature = noise_temperature[ni] - math.max(y, 0)/50
|
||||
biome = get_nearest_biome(biome_table, x, z)
|
||||
biome_humidity = biome.h
|
||||
biome_temperature = biome.t
|
||||
if biome_temperature<-0.4 then
|
||||
local humidity = noise_humidity[ni]
|
||||
local temperature = noise_temperature[ni] - math.max(y, 0) / 50
|
||||
local biome = get_nearest_biome(biome_table, x, z)
|
||||
local biome_humidity = biome.h
|
||||
local biome_temperature = biome.t
|
||||
local liquid_top
|
||||
if biome_temperature < -0.4 then
|
||||
liquid_top = c_ice
|
||||
else
|
||||
liquid_top = c_water
|
||||
end
|
||||
local above_top, top, top_layer, second_layer
|
||||
if y < -1 then
|
||||
above_top = c_air
|
||||
top = c_dirt
|
||||
top_layer = c_dirt
|
||||
second_layer = c_stone
|
||||
elseif y < 3 and noise_beach[ni]<0.2 then
|
||||
elseif y < 3 and noise_beach[ni] < 0.2 then
|
||||
above_top = c_air
|
||||
top = c_sand
|
||||
top_layer = c_sand
|
||||
second_layer = c_sandstone
|
||||
else
|
||||
above_top = c_air
|
||||
if biome_temperature>0.4 then
|
||||
if biome_humidity<-0.4 then
|
||||
if biome_temperature > 0.4 then
|
||||
if biome_humidity < -0.4 then
|
||||
top = c_desert_sand
|
||||
top_layer = c_desert_sand
|
||||
second_layer = c_desert_stone
|
||||
elseif biome_humidity<0.4 then
|
||||
elseif biome_humidity < 0.4 then
|
||||
top = c_dry_grass
|
||||
top_layer = c_dirt
|
||||
second_layer = c_stone
|
||||
@ -489,7 +483,7 @@ local function mg_generate(minp, maxp, emin, emax, vm)
|
||||
top_layer = c_dirt
|
||||
second_layer = c_stone
|
||||
end
|
||||
elseif biome_temperature<-0.4 then
|
||||
elseif biome_temperature < -0.4 then
|
||||
above_top = c_snow
|
||||
top = c_dirt_snow
|
||||
top_layer = c_dirt
|
||||
@ -500,15 +494,15 @@ local function mg_generate(minp, maxp, emin, emax, vm)
|
||||
second_layer = c_stone
|
||||
end
|
||||
end
|
||||
if y>=100 then
|
||||
if y >= 100 then
|
||||
above_top = c_air
|
||||
top = c_snow
|
||||
top_layer = c_snowblock
|
||||
end
|
||||
if y<0 then
|
||||
if y < 0 then
|
||||
above_top = c_air
|
||||
end
|
||||
if y<=maxp.y and y>=minp.y then
|
||||
if y <= maxp.y and y >= minp.y then
|
||||
local vi = a:index(x, y, z)
|
||||
if y >= 0 then
|
||||
data[vi] = top
|
||||
@ -522,7 +516,7 @@ local function mg_generate(minp, maxp, emin, emax, vm)
|
||||
and tree.min_temperature <= temperature and temperature <= tree.max_temperature
|
||||
and tree.min_biome_humidity <= biome_humidity and biome_humidity <= tree.max_biome_humidity
|
||||
and tree.min_biome_temperature <= biome_temperature and biome_temperature <= tree.max_biome_temperature
|
||||
and tree.min_height <= y+1 and y+1 <= tree.max_height
|
||||
and tree.min_height <= y + 1 and y + 1 <= tree.max_height
|
||||
and ((not tree.grows_on) or tree.grows_on == top)
|
||||
and pr:next(1, tree.chance) == 1 then
|
||||
local in_village = false
|
||||
@ -534,41 +528,41 @@ local function mg_generate(minp, maxp, emin, emax, vm)
|
||||
end
|
||||
end
|
||||
if not in_village then
|
||||
tree.grow(data, a, x, y+1, z, minp, maxp, pr)
|
||||
tree.grow(data, a, x, y + 1, z, minp, maxp, pr)
|
||||
end
|
||||
add_above_top = false
|
||||
break
|
||||
end
|
||||
end
|
||||
if add_above_top and y+1<=maxp.y and y+1>=minp.y then
|
||||
local vi = a:index(x, y+1, z)
|
||||
if add_above_top and y + 1 <= maxp.y and y + 1 >= minp.y then
|
||||
local vi = a:index(x, y + 1, z)
|
||||
data[vi] = above_top
|
||||
end
|
||||
if y<0 and minp.y<=0 and maxp.y>y then
|
||||
for yy = math.max(y+1, minp.y), math.min(0, maxp.y) do
|
||||
if y < 0 and minp.y <= 0 and maxp.y > y then
|
||||
for yy = math.max(y + 1, minp.y), math.min(0, maxp.y) do
|
||||
local vi = a:index(x, yy, z)
|
||||
data[vi] = c_water
|
||||
end
|
||||
if maxp.y>=0 then
|
||||
if maxp.y >= 0 then
|
||||
data[a:index(x, 0, z)] = liquid_top
|
||||
end
|
||||
end
|
||||
local tl = math.floor((noise_top_layer[ni]+2.5)*2)
|
||||
if y-tl-1<=maxp.y and y-1>=minp.y then
|
||||
for yy = math.max(y-tl-1, minp.y), math.min(y-1, maxp.y) do
|
||||
local tl = math.floor((noise_top_layer[ni] + 2.5) * 2)
|
||||
if y - tl - 1 <= maxp.y and y - 1 >= minp.y then
|
||||
for yy = math.max(y - tl - 1, minp.y), math.min(y - 1, maxp.y) do
|
||||
local vi = a:index(x, yy, z)
|
||||
data[vi] = top_layer
|
||||
end
|
||||
end
|
||||
local sl = math.floor((noise_second_layer[ni]+5)*3)
|
||||
if y-sl-1<=maxp.y and y-tl-2>=minp.y then
|
||||
for yy = math.max(y-sl-1, minp.y), math.min(y-tl-2, maxp.y) do
|
||||
local sl = math.floor((noise_second_layer[ni] + 5) * 3)
|
||||
if y - sl - 1 <= maxp.y and y - tl - 2 >= minp.y then
|
||||
for yy = math.max(y - sl - 1, minp.y), math.min(y - tl - 2, maxp.y) do
|
||||
local vi = a:index(x, yy, z)
|
||||
data[vi] = second_layer
|
||||
end
|
||||
end
|
||||
if y-sl-2>=minp.y then
|
||||
for yy = minp.y, math.min(y-sl-2, maxp.y) do
|
||||
if y - sl - 2 >= minp.y then
|
||||
for yy = minp.y, math.min(y - sl - 2, maxp.y) do
|
||||
local vi = a:index(x, yy, z)
|
||||
data[vi] = c_stone
|
||||
end
|
||||
@ -582,7 +576,7 @@ local function mg_generate(minp, maxp, emin, emax, vm)
|
||||
local sidelen = maxp.x - minp.x + 1
|
||||
local np = copytable(ore_sheet.noise_params)
|
||||
np.seed = np.seed + minp.y
|
||||
local pm = minetest.get_perlin_map(np, {x=sidelen, y=sidelen, z=1})
|
||||
local pm = minetest.get_perlin_map(np, {x = sidelen, y = sidelen, z = 1})
|
||||
local map = pm:get2dMap_flat({x = minp.x, y = minp.z})
|
||||
local ni = 0
|
||||
local trh = ore_sheet.threshhold
|
||||
@ -594,12 +588,12 @@ local function mg_generate(minp, maxp, emin, emax, vm)
|
||||
local tmax = ore_sheet.tmax
|
||||
for z = minp.z, maxp.z do
|
||||
for x = minp.x, maxp.x do
|
||||
ni = ni+1
|
||||
ni = ni + 1
|
||||
local noise = map[ni]
|
||||
if noise > trh then
|
||||
local thickness = pr:next(tmin, tmax)
|
||||
local y0 = math.floor(minp.y + (noise-trh)*4)
|
||||
for y = math.max(y0, hmin), math.min(y0+thickness-1, hmax) do
|
||||
local y0 = math.floor(minp.y + (noise - trh) * 4)
|
||||
for y = math.max(y0, hmin), math.min(y0 + thickness - 1, hmax) do
|
||||
local vi = a:index(x, y, z)
|
||||
if data[vi] == wherein or wherein == c_ignore then
|
||||
data[vi] = ore
|
||||
@ -621,8 +615,8 @@ local function mg_generate(minp, maxp, emin, emax, vm)
|
||||
vm:set_param2_data(param2_data)
|
||||
|
||||
vm:calc_lighting(
|
||||
{x=minp.x-16, y=minp.y, z=minp.z-16},
|
||||
{x=maxp.x+16, y=maxp.y, z=maxp.z+16}
|
||||
{x = minp.x - 16, y = minp.y, z = minp.z - 16},
|
||||
{x = maxp.x + 16, y = maxp.y, z = maxp.z + 16}
|
||||
)
|
||||
|
||||
vm:write_to_map(data)
|
||||
@ -637,18 +631,23 @@ local function mg_generate(minp, maxp, emin, emax, vm)
|
||||
if n.node.name == "default:chest" then
|
||||
local inv = meta:get_inventory()
|
||||
local items = inv:get_list("main")
|
||||
for i=1, inv:get_size("main") do
|
||||
for i = 1, inv:get_size("main") do
|
||||
inv:set_stack("main", i, ItemStack(""))
|
||||
end
|
||||
local numitems = pr:next(3, 20)
|
||||
for i=1,numitems do
|
||||
for i = 1, numitems do
|
||||
local ii = pr:next(1, #items)
|
||||
local prob = items[ii]:get_count() % 2 ^ 8
|
||||
local stacksz = math.floor(items[ii]:get_count() / 2 ^ 8)
|
||||
if pr:next(0, prob) == 0 and stacksz>0 then
|
||||
stk = ItemStack({name=items[ii]:get_name(), count=pr:next(1, stacksz), wear=items[ii]:get_wear(), metadata=items[ii]:get_metadata()})
|
||||
local stk = ItemStack({
|
||||
name = items[ii]:get_name(),
|
||||
count = pr:next(1, stacksz),
|
||||
wear = items[ii]:get_wear(),
|
||||
metadata = items[ii]:get_metadata()
|
||||
})
|
||||
local ind = pr:next(1, inv:get_size("main"))
|
||||
while not inv:get_stack("main",ind):is_empty() do
|
||||
while not inv:get_stack("main", ind):is_empty() do
|
||||
ind = pr:next(1, inv:get_size("main"))
|
||||
end
|
||||
inv:set_stack("main", ind, stk)
|
||||
@ -666,14 +665,14 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
end)
|
||||
|
||||
local function mg_regenerate(pos, name)
|
||||
local minp = {x = 80*math.floor((pos.x+32)/80)-32,
|
||||
y = 80*math.floor((pos.y+32)/80)-32,
|
||||
z = 80*math.floor((pos.z+32)/80)-32}
|
||||
local maxp = {x = minp.x+79, y = minp.y+79, z = minp.z+79}
|
||||
local minp = {x = 80 * math.floor((pos.x + 32) / 80) - 32,
|
||||
y = 80 * math.floor((pos.y + 32) / 80) - 32,
|
||||
z = 80 * math.floor((pos.z + 32) / 80) - 32}
|
||||
local maxp = {x = minp.x + 79, y = minp.y + 79, z = minp.z + 79}
|
||||
local vm = minetest.get_voxel_manip()
|
||||
local emin, emax = vm:read_from_map(minp, maxp)
|
||||
local data = {}
|
||||
for i = 1, (maxp.x-minp.x+1)*(maxp.y-minp.y+1)*(maxp.z-minp.z+1) do
|
||||
for i = 1, (maxp.x - minp.x + 1) * (maxp.y - minp.y + 1) * (maxp.z - minp.z + 1) do
|
||||
data[i] = c_air
|
||||
end
|
||||
vm:set_data(data)
|
||||
@ -684,12 +683,12 @@ local function mg_regenerate(pos, name)
|
||||
-- Fix lighting
|
||||
local nodes = minetest.find_nodes_in_area(minp, maxp, "air")
|
||||
local nnodes = #nodes
|
||||
local p = math.floor(nnodes/5)
|
||||
local p = math.floor(nnodes / 5)
|
||||
local dig_node = minetest.dig_node
|
||||
for _, pos in ipairs(nodes) do
|
||||
for i, pos in ipairs(nodes) do
|
||||
dig_node(pos)
|
||||
if _%p == 0 then
|
||||
minetest.chat_send_player(name, math.floor(_/nnodes*100).."%")
|
||||
if i % p == 0 then
|
||||
minetest.chat_send_player(name, math.floor(i / nnodes * 100).."%")
|
||||
end
|
||||
end
|
||||
minetest.chat_send_player(name, "Done")
|
||||
@ -704,8 +703,8 @@ minetest.register_chatcommand("mg_regenerate", {
|
||||
local pos = player:getpos()
|
||||
local minp, maxp = mg_regenerate(pos, name)
|
||||
if minetest.get_modpath("plants_lib") and minp and maxp then
|
||||
plantslib.blocklist_aircheck[#plantslib.blocklist_aircheck + 1] = { minp, maxp }
|
||||
plantslib.blocklist_no_aircheck[#plantslib.blocklist_no_aircheck + 1] = { minp, maxp }
|
||||
plantslib.blocklist_aircheck[#plantslib.blocklist_aircheck + 1] = {minp, maxp}
|
||||
plantslib.blocklist_no_aircheck[#plantslib.blocklist_no_aircheck + 1] = {minp, maxp}
|
||||
end
|
||||
end
|
||||
end,
|
||||
@ -760,7 +759,7 @@ function mg.register_ore_sheet(oredef)
|
||||
oredef.wherein = "ignore"
|
||||
oredef.height_max = 31000
|
||||
end
|
||||
mg.registered_ore_sheets[#mg.registered_ore_sheets+1] = oredef
|
||||
mg.registered_ore_sheets[#mg.registered_ore_sheets + 1] = oredef
|
||||
end
|
||||
|
||||
mg.registered_trees = {}
|
||||
@ -789,7 +788,7 @@ function mg.register_tree(treedef)
|
||||
if treedef.max_biome_temperature == nil then
|
||||
treedef.max_biome_temperature = 2
|
||||
end
|
||||
mg.registered_trees[#mg.registered_trees+1] = treedef
|
||||
mg.registered_trees[#mg.registered_trees + 1] = treedef
|
||||
end
|
||||
|
||||
dofile(minetest.get_modpath(minetest.get_current_modname()).."/oredesc.lua")
|
||||
|
204
ores.lua
204
ores.lua
@ -7,16 +7,18 @@ function round_pos(p)
|
||||
end
|
||||
|
||||
function draw_sphere(name, wherein, center, radius, data, a, insideva)
|
||||
local rad2=radius*radius
|
||||
local rad2 = radius * radius
|
||||
radius = math.ceil(radius)
|
||||
pos0={}
|
||||
for x=-radius, radius do
|
||||
pos0.x=center.x+x
|
||||
for y=-radius, radius do
|
||||
pos0.y=center.y+y
|
||||
for z=-radius, radius do
|
||||
pos0.z=center.z+z
|
||||
if x*x+y*y+z*z<=rad2 and insideva:containsp(pos0) and ((wherein == c_ignore and data[a:indexp(pos0)] ~= c_water) or data[a:indexp(pos0)] == wherein) then
|
||||
local pos0 = {}
|
||||
for x = -radius, radius do
|
||||
pos0.x = center.x + x
|
||||
for y = -radius, radius do
|
||||
pos0.y = center.y + y
|
||||
for z = -radius, radius do
|
||||
pos0.z = center.z + z
|
||||
if x*x + y*y + z*z <= rad2 and insideva:containsp(pos0) and
|
||||
((wherein == c_ignore and data[a:indexp(pos0)] ~= c_water) or
|
||||
data[a:indexp(pos0)] == wherein) then
|
||||
data[a:indexp(pos0)] = name
|
||||
end
|
||||
end
|
||||
@ -25,74 +27,74 @@ function draw_sphere(name, wherein, center, radius, data, a, insideva)
|
||||
end
|
||||
|
||||
function place_segment(name, wherein, pos1, pos2, minp, maxp, radius, data, a, insideva)
|
||||
local d={x=pos2.x-pos1.x, y=pos2.y-pos1.y, z=pos2.z-pos1.z}
|
||||
local N=math.max(math.abs(d.x),math.abs(d.y),math.abs(d.z))
|
||||
local s={x=d.x/N,y=d.y/N,z=d.z/N}
|
||||
local p=pos1
|
||||
draw_sphere(name,wherein,pos1,radius, data, a, insideva)
|
||||
for i=1,N do
|
||||
p={x=p.x+s.x,y=p.y+s.y,z=p.z+s.z}
|
||||
p0=round_pos(p)
|
||||
local d = {x = pos2.x - pos1.x, y = pos2.y - pos1.y, z = pos2.z - pos1.z}
|
||||
local N = math.max(math.abs(d.x), math.abs(d.y), math.abs(d.z))
|
||||
local s = {x = d.x / N, y = d.y / N, z = d.z / N}
|
||||
local p = pos1
|
||||
draw_sphere(name, wherein, pos1, radius, data, a, insideva)
|
||||
for i = 1, N do
|
||||
p = {x = p.x + s.x, y = p.y + s.y, z = p.z + s.z}
|
||||
local p0 = round_pos(p)
|
||||
if not in_cuboid(p0, minp, maxp) then return end
|
||||
draw_sphere(name,wherein,p0,radius, data, a, insideva)
|
||||
draw_sphere(name, wherein, p0, radius, data, a, insideva)
|
||||
end
|
||||
end
|
||||
|
||||
function generate_vein_segment(name, wherein, minp, maxp, pr, pos, angle, rem_size, options, data, a, insideva)
|
||||
if rem_size<=0 then return end
|
||||
local Ln=options.seglenghtn
|
||||
local Ldev=options.seglenghtdev
|
||||
local L=pr:next(Ln-Ldev,Ln+Ldev)
|
||||
local incln=options.segincln*100
|
||||
local incldev=options.segincldev*100
|
||||
local incl=pr:next(incln-incldev,incln+incldev)/100
|
||||
local turnangle=options.turnangle
|
||||
local forkturnangle=options.forkturnangle
|
||||
local fork_chance=options.fork_chance*100
|
||||
local forkmultn=options.forkmultn*100
|
||||
local forkmultdev=options.forkmultdev*100
|
||||
local radius=options.radius
|
||||
if rem_size <= 0 then return end
|
||||
local Ln = options.seglenghtn
|
||||
local Ldev = options.seglenghtdev
|
||||
local L = pr:next(Ln - Ldev, Ln + Ldev)
|
||||
local incln = options.segincln * 100
|
||||
local incldev = options.segincldev * 100
|
||||
local incl = pr:next(incln - incldev, incln + incldev) / 100
|
||||
local turnangle = options.turnangle
|
||||
local forkturnangle = options.forkturnangle
|
||||
local fork_chance = options.fork_chance * 100
|
||||
local forkmultn = options.forkmultn * 100
|
||||
local forkmultdev = options.forkmultdev * 100
|
||||
local radius = options.radius
|
||||
|
||||
local end_pos={x=pos.x+L*math.cos(angle), y=pos.y-L*incl, z=pos.z+L*math.sin(angle)}
|
||||
local end_pos = {x = pos.x + L * math.cos(angle), y = pos.y - L * incl, z = pos.z + L * math.sin(angle)}
|
||||
place_segment(name, wherein, round_pos(pos), round_pos(end_pos), minp, maxp, radius, data, a, insideva)
|
||||
if not in_cuboid(end_pos, minp, maxp) then return end
|
||||
local new_angle=(math.pi*pr:next(-turnangle,turnangle)/180)+angle
|
||||
generate_vein_segment(name, wherein, minp, maxp, pr, end_pos, new_angle, rem_size-L, options, data, a, insideva)
|
||||
local numforks=math.floor(fork_chance/100)+1
|
||||
fork_chance=fork_chance/numforks
|
||||
if pr:next(1,100)<=fork_chance then
|
||||
for f=1,numforks do
|
||||
local new_angle=(math.pi*pr:next(-forkturnangle,forkturnangle)/180)+angle
|
||||
local forkmult=pr:next(forkmultn-forkmultdev, forkmultn+forkmultdev)/100
|
||||
if forkmult>1 then forkmult=1 end
|
||||
generate_vein_segment(name, wherein, minp, maxp, pr, end_pos, new_angle, forkmult*(rem_size-L), options, data, a, insideva)
|
||||
local new_angle=(math.pi * pr:next(-turnangle, turnangle) / 180) + angle
|
||||
generate_vein_segment(name, wherein, minp, maxp, pr, end_pos, new_angle, rem_size - L, options, data, a, insideva)
|
||||
local numforks = math.floor(fork_chance / 100) + 1
|
||||
fork_chance = fork_chance / numforks
|
||||
if pr:next(1, 100) <= fork_chance then
|
||||
for f = 1, numforks do
|
||||
local new_angle = (math.pi * pr:next(-forkturnangle, forkturnangle) / 180) + angle
|
||||
local forkmult = pr:next(forkmultn - forkmultdev, forkmultn + forkmultdev) / 100
|
||||
if forkmult > 1 then forkmult = 1 end
|
||||
generate_vein_segment(name, wherein, minp, maxp, pr, end_pos, new_angle, forkmult * (rem_size - L), options, data, a, insideva)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function generate_vein(name, wherein, minp, maxp, seeddiff, options, data, a, insideva, second_call)
|
||||
local seed = get_bseed2(minp)+seeddiff
|
||||
options=get_or_default(options)
|
||||
local seed = get_bseed2(minp) + seeddiff
|
||||
options = get_or_default(options)
|
||||
|
||||
local numperblock=options.numperblock*1000
|
||||
local maxhdistance=options.maxhdistance
|
||||
local maxvdistance=options.maxvdistance
|
||||
local numbranchesn=options.numbranchesn
|
||||
local numbranchesdev=options.numbranchesdev
|
||||
local mothersizen=options.mothersizen*10
|
||||
local mothersizedev=options.mothersizedev*10
|
||||
local sizen=options.sizen
|
||||
local sizedev=options.sizedev
|
||||
local numperblock = options.numperblock * 1000
|
||||
local maxhdistance = options.maxhdistance
|
||||
local maxvdistance = options.maxvdistance
|
||||
local numbranchesn = options.numbranchesn
|
||||
local numbranchesdev = options.numbranchesdev
|
||||
local mothersizen = options.mothersizen * 10
|
||||
local mothersizedev = options.mothersizedev * 10
|
||||
local sizen = options.sizen
|
||||
local sizedev = options.sizedev
|
||||
|
||||
if second_call==nil then
|
||||
local hblocks=math.floor(maxhdistance/80)+1
|
||||
local vblocks=math.floor(maxvdistance/80)+1
|
||||
for xblocksdiff=-hblocks,hblocks do
|
||||
for yblocksdiff=-vblocks,vblocks do
|
||||
for zblocksdiff=-hblocks,hblocks do
|
||||
if xblocksdiff~=0 or yblocksdiff~=0 or zblocksdiff~=0 then
|
||||
new_minp={x=minp.x+xblocksdiff*80,y=minp.y+yblocksdiff*80,z=minp.z+zblocksdiff*80}
|
||||
new_maxp={x=maxp.x+xblocksdiff*80,y=maxp.y+yblocksdiff*80,z=maxp.z+zblocksdiff*80}
|
||||
if second_call == nil then
|
||||
local hblocks = math.floor(maxhdistance / 80) + 1
|
||||
local vblocks = math.floor(maxvdistance / 80) + 1
|
||||
for xblocksdiff = -hblocks, hblocks do
|
||||
for yblocksdiff = -vblocks, vblocks do
|
||||
for zblocksdiff = -hblocks, hblocks do
|
||||
if xblocksdiff ~= 0 or yblocksdiff ~= 0 or zblocksdiff ~= 0 then
|
||||
local new_minp = {x = minp.x + xblocksdiff * 80, y = minp.y + yblocksdiff * 80, z = minp.z + zblocksdiff * 80}
|
||||
local new_maxp = {x = maxp.x + xblocksdiff * 80, y = maxp.y + yblocksdiff * 80, z = maxp.z + zblocksdiff * 80}
|
||||
generate_vein(name, wherein, new_minp, new_maxp, seeddiff, options, data, a, insideva, true)
|
||||
end
|
||||
end
|
||||
@ -102,29 +104,29 @@ function generate_vein(name, wherein, minp, maxp, seeddiff, options, data, a, in
|
||||
|
||||
local pr = PseudoRandom(seed)
|
||||
|
||||
local numveins=math.floor(numperblock/1000)
|
||||
numperblock=numperblock-1000*numveins
|
||||
if pr:next(1,1000)<=numperblock then
|
||||
numveins=numveins+1
|
||||
local numveins = math.floor(numperblock / 1000)
|
||||
numperblock = numperblock - 1000 * numveins
|
||||
if pr:next(1,1000) <= numperblock then
|
||||
numveins = numveins + 1
|
||||
end
|
||||
if numveins>0 then
|
||||
local min_y=math.max(options.minheight,minp.y)
|
||||
local max_y=math.min(options.maxheight,maxp.y)
|
||||
if min_y>max_y then return end
|
||||
for v=1,numveins do
|
||||
local vein_pos={x=pr:next(minp.x,maxp.x),y=pr:next(min_y,max_y),z=pr:next(minp.z,maxp.z)}
|
||||
local numbranches=pr:next(numbranchesn-numbranchesdev,numbranchesn+numbranchesdev)
|
||||
local mothersize=pr:next(mothersizen-mothersizedev,mothersizen+mothersizedev)/10
|
||||
if numveins > 0 then
|
||||
local min_y = math.max(options.minheight, minp.y)
|
||||
local max_y = math.min(options.maxheight, maxp.y)
|
||||
if min_y > max_y then return end
|
||||
for v = 1, numveins do
|
||||
local vein_pos = {x = pr:next(minp.x, maxp.x), y = pr:next(min_y, max_y), z = pr:next(minp.z, maxp.z)}
|
||||
local numbranches = pr:next(numbranchesn - numbranchesdev, numbranchesn + numbranchesdev)
|
||||
local mothersize = pr:next(mothersizen - mothersizedev, mothersizen + mothersizedev) / 10
|
||||
|
||||
if mothersize>=0 then
|
||||
if mothersize >= 0 then
|
||||
draw_sphere(name, wherein,vein_pos, mothersize, data, a, insideva)
|
||||
end
|
||||
|
||||
local minpos = {x=vein_pos.x-maxhdistance,y=vein_pos.y-maxvdistance,z=vein_pos.z-maxhdistance}
|
||||
local maxpos = {x=vein_pos.x+maxhdistance,y=vein_pos.y+maxvdistance,z=vein_pos.z+maxhdistance}
|
||||
for i=1,numbranches do
|
||||
local start_angle=math.pi*pr:next(0,359)/180
|
||||
local size=pr:next(sizen-sizedev,sizen+sizedev)
|
||||
local minpos = {x = vein_pos.x - maxhdistance, y = vein_pos.y - maxvdistance, z = vein_pos.z - maxhdistance}
|
||||
local maxpos = {x = vein_pos.x + maxhdistance, y = vein_pos.y + maxvdistance, z = vein_pos.z + maxhdistance}
|
||||
for i = 1, numbranches do
|
||||
local start_angle = math.pi * pr:next(0, 359) / 180
|
||||
local size = pr:next(sizen - sizedev, sizen + sizedev)
|
||||
generate_vein_segment(name, wherein, minpos, maxpos, pr, vein_pos, start_angle, size, options, data, a, insideva)
|
||||
end
|
||||
end
|
||||
@ -132,26 +134,26 @@ function generate_vein(name, wherein, minp, maxp, seeddiff, options, data, a, in
|
||||
end
|
||||
|
||||
function get_or_default(options)
|
||||
if options.numperblock==nil then options.numperblock=0.3 end
|
||||
if options.maxhdistance==nil then options.maxhdistance=32 end
|
||||
if options.maxvdistance==nil then options.maxvdistance=32 end
|
||||
if options.numbranchesn==nil then options.numbranchesn=3 end
|
||||
if options.numbranchesdev==nil then options.numbranchesdev=2 end
|
||||
if options.mothersizen==nil then options.mothersizen=1 end
|
||||
if options.mothersizedev==nil then options.mothersizedev=0.5 end
|
||||
if options.sizen==nil then options.sizen=120 end
|
||||
if options.sizedev==nil then options.sizedev=60 end
|
||||
if options.seglenghtn==nil then options.seglenghtn=6 end
|
||||
if options.seglenghtdev==nil then options.seglenghtdev=2 end
|
||||
if options.segincln==nil then options.segincln=0.2 end
|
||||
if options.segincldev==nil then options.segincldev=0.1 end
|
||||
if options.turnangle==nil then options.turnangle=20 end
|
||||
if options.forkturnangle==nil then options.forkturnangle=90 end
|
||||
if options.fork_chance==nil then options.fork_chance=0.2 end
|
||||
if options.forkmultn==nil then options.forkmultn=0.75 end
|
||||
if options.forkmultdev==nil then options.forkmultdev=0.25 end
|
||||
if options.minheight==nil then options.minheight=-31000 end
|
||||
if options.maxheight==nil then options.maxheight=31000 end
|
||||
if options.radius==nil then options.radius=0 end
|
||||
if options.numperblock == nil then options.numperblock = 0.3 end
|
||||
if options.maxhdistance == nil then options.maxhdistance = 32 end
|
||||
if options.maxvdistance == nil then options.maxvdistance = 32 end
|
||||
if options.numbranchesn == nil then options.numbranchesn = 3 end
|
||||
if options.numbranchesdev == nil then options.numbranchesdev = 2 end
|
||||
if options.mothersizen == nil then options.mothersizen = 1 end
|
||||
if options.mothersizedev == nil then options.mothersizedev = 0.5 end
|
||||
if options.sizen == nil then options.sizen = 120 end
|
||||
if options.sizedev == nil then options.sizedev = 60 end
|
||||
if options.seglenghtn == nil then options.seglenghtn = 6 end
|
||||
if options.seglenghtdev == nil then options.seglenghtdev = 2 end
|
||||
if options.segincln == nil then options.segincln = 0.2 end
|
||||
if options.segincldev == nil then options.segincldev = 0.1 end
|
||||
if options.turnangle == nil then options.turnangle = 20 end
|
||||
if options.forkturnangle == nil then options.forkturnangle = 90 end
|
||||
if options.fork_chance == nil then options.fork_chance = 0.2 end
|
||||
if options.forkmultn == nil then options.forkmultn = 0.75 end
|
||||
if options.forkmultdev == nil then options.forkmultdev = 0.25 end
|
||||
if options.minheight == nil then options.minheight = -31000 end
|
||||
if options.maxheight == nil then options.maxheight = 31000 end
|
||||
if options.radius == nil then options.radius = 0 end
|
||||
return options
|
||||
end
|
||||
|
@ -19,7 +19,7 @@ function rotate_scm(scm)
|
||||
local ysize = #scm
|
||||
local xsize = #scm[1]
|
||||
local zsize = #scm[1][1]
|
||||
new_scm = {}
|
||||
local new_scm = {}
|
||||
for i=1, ysize do
|
||||
new_scm[i] = {}
|
||||
for j=1, zsize do
|
||||
@ -36,11 +36,11 @@ function rotate_scm(scm)
|
||||
if type(old) ~= "table" or old.rotation == nil then
|
||||
new_scm[y][newx][newz] = old
|
||||
elseif old.rotation == "wallmounted" then
|
||||
new = deepcopy(old)
|
||||
local new = deepcopy(old)
|
||||
new.node.param2 = rotate_wallmounted(new.node.param2)
|
||||
new_scm[y][newx][newz] = new
|
||||
elseif old.rotation == "facedir" then
|
||||
new = deepcopy(old)
|
||||
local new = deepcopy(old)
|
||||
new.node.param2 = rotate_facedir(new.node.param2)
|
||||
new_scm[y][newx][newz] = new
|
||||
end
|
||||
@ -51,7 +51,7 @@ function rotate_scm(scm)
|
||||
end
|
||||
|
||||
function rotate(scm, times)
|
||||
for i=1, times do
|
||||
for i = 1, times do
|
||||
scm = rotate_scm(scm)
|
||||
end
|
||||
return scm
|
||||
|
56
villages.lua
56
villages.lua
@ -126,6 +126,7 @@ local function when(a, b, c)
|
||||
if a then return b else return c end
|
||||
end
|
||||
|
||||
local calls
|
||||
local function generate_road(village, l, pr, roadsize, rx, rz, rdx, rdz, vnoise)
|
||||
local vx, vz, vh, vs = village.vx, village.vz, village.vh, village.vs
|
||||
local calls_to_do = {}
|
||||
@ -153,17 +154,17 @@ local function generate_road(village, l, pr, roadsize, rx, rz, rdx, rdz, vnoise)
|
||||
--else
|
||||
--::loop::
|
||||
local exitloop = false
|
||||
local bx
|
||||
local bz
|
||||
local tries = 0
|
||||
local btype, rotation, bsizex, bsizez
|
||||
local bx, bz
|
||||
while true do
|
||||
if not inside_village(rx, rz, village, vnoise) or road_in_building(rx, rz, rdx, rdz, roadsize, l) then
|
||||
exitloop = true
|
||||
break
|
||||
end
|
||||
btype, rotation, bsizex, bsizez = choose_building_rot(l, pr, orient1)
|
||||
bx = rx + math.abs(rdz)*(roadsize+1) - when(rdx==-1, bsizex-1, 0)
|
||||
bz = rz + math.abs(rdx)*(roadsize+1) - when(rdz==-1, bsizez-1, 0)
|
||||
bx = rx + math.abs(rdz) * (roadsize + 1) - when(rdx == -1, bsizex - 1, 0)
|
||||
bz = rz + math.abs(rdx) * (roadsize + 1) - when(rdz == -1, bsizez - 1, 0)
|
||||
if placeable(bx, bz, bsizex, bsizez, l) and inside_village2(bx, bsizex, bz, bsizez, village, vnoise) then
|
||||
break
|
||||
end
|
||||
@ -177,11 +178,11 @@ local function generate_road(village, l, pr, roadsize, rx, rz, rdx, rdz, vnoise)
|
||||
--goto loop
|
||||
end
|
||||
if exitloop then break end
|
||||
rx = rx + (bsizex+1)*rdx
|
||||
rz = rz + (bsizez+1)*rdz
|
||||
mx = rx - 2*rdx
|
||||
mz = rz - 2*rdz
|
||||
l[#l+1] = {x=bx, y=vh, z=bz, btype=btype, bsizex=bsizex, bsizez=bsizez, brotate = rotation}
|
||||
rx = rx + (bsizex + 1) * rdx
|
||||
rz = rz + (bsizez + 1) * rdz
|
||||
mx = rx - 2 * rdx
|
||||
mz = rz - 2 * rdz
|
||||
l[#l + 1] = {x = bx, y = vh, z = bz, btype = btype, bsizex = bsizex, bsizez = bsizez, brotate = rotation}
|
||||
--end
|
||||
end
|
||||
rx = rxx
|
||||
@ -198,17 +199,17 @@ local function generate_road(village, l, pr, roadsize, rx, rz, rdx, rdz, vnoise)
|
||||
--else
|
||||
--::loop::
|
||||
local exitloop = false
|
||||
local bx
|
||||
local bz
|
||||
local tries = 0
|
||||
local btype, rotation, bsizex, bsizez
|
||||
local bx, bz
|
||||
while true do
|
||||
if not inside_village(rx, rz, village, vnoise) or road_in_building(rx, rz, rdx, rdz, roadsize, l) then
|
||||
exitloop = true
|
||||
break
|
||||
end
|
||||
btype, rotation, bsizex, bsizez = choose_building_rot(l, pr, orient2)
|
||||
bx = rx - math.abs(rdz)*(bsizex+roadsize) - when(rdx==-1, bsizex-1, 0)
|
||||
bz = rz - math.abs(rdx)*(bsizez+roadsize) - when(rdz==-1, bsizez-1, 0)
|
||||
bx = rx - math.abs(rdz) * (bsizex + roadsize) - when(rdx == -1, bsizex - 1, 0)
|
||||
bz = rz - math.abs(rdx) * (bsizez + roadsize) - when(rdz == -1, bsizez - 1, 0)
|
||||
if placeable(bx, bz, bsizex, bsizez, l) and inside_village2(bx, bsizex, bz, bsizez, village, vnoise) then
|
||||
break
|
||||
end
|
||||
@ -222,11 +223,11 @@ local function generate_road(village, l, pr, roadsize, rx, rz, rdx, rdz, vnoise)
|
||||
--goto loop
|
||||
end
|
||||
if exitloop then break end
|
||||
rx = rx + (bsizex+1)*rdx
|
||||
rz = rz + (bsizez+1)*rdz
|
||||
m2x = rx - 2*rdx
|
||||
m2z = rz - 2*rdz
|
||||
l[#l+1] = {x=bx, y=vh, z=bz, btype=btype, bsizex=bsizex, bsizez=bsizez, brotate = rotation}
|
||||
rx = rx + (bsizex + 1) * rdx
|
||||
rz = rz + (bsizez + 1) * rdz
|
||||
m2x = rx - 2 * rdx
|
||||
m2z = rz - 2 * rdz
|
||||
l[#l + 1] = {x = bx, y = vh, z = bz, btype = btype, bsizex = bsizex, bsizez = bsizez, brotate = rotation}
|
||||
--end
|
||||
end
|
||||
if road_in_building(rx, rz, rdx, rdz, roadsize, l) then
|
||||
@ -235,6 +236,7 @@ local function generate_road(village, l, pr, roadsize, rx, rz, rdx, rdz, vnoise)
|
||||
end
|
||||
mx = mmx or rdx*math.max(rdx*mx, rdx*m2x)
|
||||
mz = mmz or rdz*math.max(rdz*mz, rdz*m2z)
|
||||
local rxmin, rxmax, rzmin, rzmax
|
||||
if rdx == 0 then
|
||||
rxmin = rx - roadsize + 1
|
||||
rxmax = rx + roadsize - 1
|
||||
@ -246,7 +248,7 @@ local function generate_road(village, l, pr, roadsize, rx, rz, rdx, rdz, vnoise)
|
||||
rxmin = math.min(rxx, mx)
|
||||
rxmax = math.max(rxx, mx)
|
||||
end
|
||||
l[#l+1] = {x = rxmin, y = vh, z = rzmin, btype = "road",
|
||||
l[#l + 1] = {x = rxmin, y = vh, z = rzmin, btype = "road",
|
||||
bsizex = rxmax - rxmin + 1, bsizez = rzmax - rzmin + 1, brotate = 0}
|
||||
for _, i in ipairs(calls_to_do) do
|
||||
local new_roadsize = roadsize - 1
|
||||
@ -269,10 +271,10 @@ local function generate_bpos(village, pr, vnoise)
|
||||
rx = rx + 5
|
||||
calls = {index = 1}
|
||||
generate_road(village, l, pr, FIRST_ROADSIZE, rx, rz, 1, 0, vnoise)
|
||||
i = 1
|
||||
local i = 1
|
||||
while i < calls.index do
|
||||
generate_road(unpack(calls[i]))
|
||||
i = i+1
|
||||
i = i + 1
|
||||
end
|
||||
return l
|
||||
end
|
||||
@ -286,14 +288,12 @@ local function generate_building(pos, minp, maxp, data, param2_data, a, pr, extr
|
||||
scm = binfo.scm
|
||||
end
|
||||
scm = rotate(scm, pos.brotate)
|
||||
local c_ignore = minetest.get_content_id("ignore")
|
||||
local c_air = minetest.get_content_id("air")
|
||||
for x = 0, pos.bsizex-1 do
|
||||
for y = 0, binfo.ysize-1 do
|
||||
for z = 0, pos.bsizez-1 do
|
||||
ax, ay, az = pos.x+x, pos.y+y+binfo.yoff, pos.z+z
|
||||
for x = 0, pos.bsizex - 1 do
|
||||
for y = 0, binfo.ysize - 1 do
|
||||
for z = 0, pos.bsizez - 1 do
|
||||
local ax, ay, az = pos.x + x, pos.y + y + binfo.yoff, pos.z + z
|
||||
if (ax >= minp.x and ax <= maxp.x) and (ay >= minp.y and ay <= maxp.y) and (az >= minp.z and az <= maxp.z) then
|
||||
local t = scm[y+1][x+1][z+1]
|
||||
local t = scm[y +1][x +1][z + 1]
|
||||
if type(t) == "table" then
|
||||
if t.extranode then
|
||||
table.insert(extranodes, {node = t.node, meta = t.meta, pos = {x = ax, y = ay, z = az}})
|
||||
|
2
we.lua
2
we.lua
@ -12,7 +12,7 @@ function import_scm(scm)
|
||||
if not f then
|
||||
error("Could not open schematic '" .. scm .. ".we': " .. err)
|
||||
end
|
||||
value = f:read("*a")
|
||||
local value = f:read("*a")
|
||||
f:close()
|
||||
value = value:gsub("return%s*{", "", 1):gsub("}%s*$", "", 1)
|
||||
local escaped = value:gsub("\\\\", "@@"):gsub("\\\"", "@@"):gsub("(\"[^\"]*\")", function(s) return string.rep("@", #s) end)
|
||||
|
Loading…
x
Reference in New Issue
Block a user