Desert road climbs hills, places halfslabs. Remove tunnels
This commit is contained in:
parent
d0bd2f7c56
commit
8ea8598146
@ -1,4 +1,4 @@
|
|||||||
path 0.1.6 by paramat
|
path 0.2.0 by paramat
|
||||||
For latest stable Minetest back to 0.4.8
|
For latest stable Minetest back to 0.4.8
|
||||||
Depends default
|
Depends default
|
||||||
Licenses: code WTFPL
|
Licenses: code WTFPL
|
||||||
|
188
init.lua
188
init.lua
@ -1,34 +1,27 @@
|
|||||||
-- path 0.1.6 by paramat
|
-- path 0.2.0 by paramat
|
||||||
-- For latest stable Minetest and back to 0.4.8
|
-- For latest stable Minetest and back to 0.4.8
|
||||||
-- Depends default
|
-- Depends default
|
||||||
-- License: code WTFPL
|
-- License: code WTFPL
|
||||||
|
|
||||||
-- nodeupdate(pos) for light spread
|
|
||||||
-- 2 lines of lights
|
|
||||||
-- add desert stone, red concrete
|
|
||||||
|
|
||||||
-- Parameters
|
-- Parameters
|
||||||
|
|
||||||
local YFLAT = 1 -- Flat area elevation
|
local TERSCA = 32 -- Vertical terrain scale
|
||||||
local TERSCA = 64 -- Vertical terrain scale
|
|
||||||
local TFLAT = 0.2 -- Flat area width
|
|
||||||
local WID = 3 -- Road lane width
|
|
||||||
local CACCHA = 1 / 192 ^ 2 -- Cactus chance per node
|
local CACCHA = 1 / 192 ^ 2 -- Cactus chance per node
|
||||||
|
|
||||||
-- 2D noise for path and terrain
|
-- 2D noise for terrain
|
||||||
|
|
||||||
local np_base = {
|
local np_terrain = {
|
||||||
offset = 0,
|
offset = 0,
|
||||||
scale = 1,
|
scale = 1,
|
||||||
spread = {x=1024, y=1024, z=1024},
|
spread = {x=512, y=512, z=512},
|
||||||
seed = -9111,
|
seed = -9111,
|
||||||
octaves = 4,
|
octaves = 4,
|
||||||
persist = 0.4
|
persist = 0.4
|
||||||
}
|
}
|
||||||
|
|
||||||
-- 2D noise for alt path and tunnels
|
-- 2D noise for path
|
||||||
|
|
||||||
local np_alt = {
|
local np_path = {
|
||||||
offset = 0,
|
offset = 0,
|
||||||
scale = 1,
|
scale = 1,
|
||||||
spread = {x=1024, y=1024, z=1024},
|
spread = {x=1024, y=1024, z=1024},
|
||||||
@ -41,7 +34,27 @@ local np_alt = {
|
|||||||
|
|
||||||
minetest.register_node("path:roadblack", {
|
minetest.register_node("path:roadblack", {
|
||||||
description = "Road Black",
|
description = "Road Black",
|
||||||
tiles = {"path_roadblack.png"},
|
tiles = {"default_obsidian.png"},
|
||||||
|
groups = {cracky=2},
|
||||||
|
sounds = default.node_sound_stone_defaults(),
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_node("path:roadslab", {
|
||||||
|
description = "Road Slab",
|
||||||
|
tiles = {"default_obsidian.png"},
|
||||||
|
drawtype = "nodebox",
|
||||||
|
paramtype = "light",
|
||||||
|
is_ground_content = false,
|
||||||
|
sunlight_propagates = true,
|
||||||
|
buildable_to = false,
|
||||||
|
node_box = {
|
||||||
|
type = "fixed",
|
||||||
|
fixed = {{-0.5, -0.5, -0.5, 0.5, 0, 0.5}},
|
||||||
|
},
|
||||||
|
selection_box = {
|
||||||
|
type = "fixed",
|
||||||
|
fixed = {{-0.5, -0.5, -0.5, 0.5, 0, 0.5}},
|
||||||
|
},
|
||||||
groups = {cracky=2},
|
groups = {cracky=2},
|
||||||
sounds = default.node_sound_stone_defaults(),
|
sounds = default.node_sound_stone_defaults(),
|
||||||
})
|
})
|
||||||
@ -53,22 +66,6 @@ minetest.register_node("path:roadwhite", {
|
|||||||
sounds = default.node_sound_stone_defaults(),
|
sounds = default.node_sound_stone_defaults(),
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node("path:lightoff", {
|
|
||||||
description = "Light",
|
|
||||||
tiles = {"path_light.png"},
|
|
||||||
light_source = 12,
|
|
||||||
groups = {cracky=3,oddly_breakable_by_hand=3},
|
|
||||||
sounds = default.node_sound_glass_defaults(),
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_node("path:lighton", {
|
|
||||||
description = "Light",
|
|
||||||
tiles = {"path_light.png"},
|
|
||||||
light_source = 12,
|
|
||||||
groups = {cracky=3,oddly_breakable_by_hand=3},
|
|
||||||
sounds = default.node_sound_glass_defaults(),
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_node("path:cactus", {
|
minetest.register_node("path:cactus", {
|
||||||
description = "Cactus",
|
description = "Cactus",
|
||||||
tiles = {"default_cactus_top.png", "default_cactus_top.png", "default_cactus_side.png"},
|
tiles = {"default_cactus_top.png", "default_cactus_top.png", "default_cactus_side.png"},
|
||||||
@ -80,29 +77,20 @@ minetest.register_node("path:cactus", {
|
|||||||
on_place = minetest.rotate_node
|
on_place = minetest.rotate_node
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node("path:redcrete", {
|
|
||||||
description = "Red Concrete",
|
|
||||||
tiles = {"path_redcrete.png"},
|
|
||||||
groups = {cracky=2},
|
|
||||||
sounds = default.node_sound_stone_defaults(),
|
|
||||||
})
|
|
||||||
|
|
||||||
-- Stuff
|
-- Stuff
|
||||||
|
|
||||||
path = {}
|
path = {}
|
||||||
|
|
||||||
local rad = WID ^ 2 + 4
|
|
||||||
|
|
||||||
-- Set mapgen parameters
|
-- Set mapgen parameters
|
||||||
|
|
||||||
minetest.register_on_mapgen_init(function(mgparams)
|
minetest.register_on_mapgen_init(function(mgparams)
|
||||||
minetest.set_mapgen_params({mgname="singlenode"})
|
minetest.set_mapgen_params({mgname="singlenode", water_level=-32})
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Spawn player
|
-- Spawn player
|
||||||
|
|
||||||
function spawnplayer(player)
|
function spawnplayer(player)
|
||||||
player:setpos({x=0, y=2, z=0})
|
player:setpos({x=0, y=48, z=0})
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_on_newplayer(function(player)
|
minetest.register_on_newplayer(function(player)
|
||||||
@ -128,18 +116,6 @@ function path_cactus(x, y, z, area, data)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ABM
|
|
||||||
|
|
||||||
minetest.register_abm({
|
|
||||||
nodenames = {"path:lightoff"},
|
|
||||||
interval = 5,
|
|
||||||
chance = 8,
|
|
||||||
action = function(pos, node)
|
|
||||||
minetest.add_node(pos, {name="path:lighton"})
|
|
||||||
nodeupdate(pos)
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
-- On generated function
|
-- On generated function
|
||||||
|
|
||||||
minetest.register_on_generated(function(minp, maxp, seed)
|
minetest.register_on_generated(function(minp, maxp, seed)
|
||||||
@ -162,103 +138,93 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
local data = vm:get_data()
|
local data = vm:get_data()
|
||||||
|
|
||||||
local c_air = minetest.get_content_id("air")
|
local c_air = minetest.get_content_id("air")
|
||||||
|
local c_ignore = minetest.get_content_id("ignore")
|
||||||
local c_desand = minetest.get_content_id("default:desert_sand")
|
local c_desand = minetest.get_content_id("default:desert_sand")
|
||||||
local c_destone = minetest.get_content_id("default:desert_stone")
|
local c_destone = minetest.get_content_id("default:desert_stone")
|
||||||
local c_redcrete = minetest.get_content_id("path:redcrete")
|
|
||||||
local c_roadblack = minetest.get_content_id("path:roadblack")
|
local c_roadblack = minetest.get_content_id("path:roadblack")
|
||||||
|
local c_roadslab = minetest.get_content_id("path:roadslab")
|
||||||
local c_roadwhite = minetest.get_content_id("path:roadwhite")
|
local c_roadwhite = minetest.get_content_id("path:roadwhite")
|
||||||
local c_light = minetest.get_content_id("path:lightoff")
|
|
||||||
|
|
||||||
local sidelen = x1 - x0 + 1
|
local sidelen = x1 - x0 + 1
|
||||||
local chulens = {x=sidelen+1, y=sidelen+1, z=sidelen} -- x = coord x, y = coord z
|
local chulens = {x=sidelen+1, y=sidelen+1, z=sidelen} -- x = coord x, y = coord z
|
||||||
local minposxz = {x=x0-1, y=z0-1}
|
local minposxz = {x=x0-1, y=z0-1}
|
||||||
|
|
||||||
local nvals_base = minetest.get_perlin_map(np_base, chulens):get2dMap_flat(minposxz)
|
local nvals_terrain = minetest.get_perlin_map(np_terrain, chulens):get2dMap_flat(minposxz)
|
||||||
local nvals_alt = minetest.get_perlin_map(np_alt, chulens):get2dMap_flat(minposxz)
|
local nvals_path = minetest.get_perlin_map(np_path, chulens):get2dMap_flat(minposxz)
|
||||||
|
|
||||||
local nixz = 1
|
local nixz = 1
|
||||||
for z = z0-1, z1 do
|
for z = z0-1, z1 do
|
||||||
for y = y0, y1 do
|
for y = y0, y1 do
|
||||||
local vi = area:index(x0-1, y, z)
|
local vi = area:index(x0-1, y, z)
|
||||||
local n_xprebase = false
|
local viu = area:index(x0-1, y-1, z)
|
||||||
local n_xprealt = false
|
local n_xprepath = false
|
||||||
for x = x0-1, x1 do
|
for x = x0-1, x1 do
|
||||||
local nodid = data[vi]
|
local nodid = data[vi]
|
||||||
local ysurf
|
local nodidu = data[viu]
|
||||||
local flat = false
|
local n_zprepath = nvals_path[(nixz - 81)]
|
||||||
local n_zprebase = nvals_base[(nixz - 81)]
|
|
||||||
local n_zprealt = nvals_alt[(nixz - 81)]
|
|
||||||
local chunk = (x >= x0 and z >= z0)
|
local chunk = (x >= x0 and z >= z0)
|
||||||
|
|
||||||
local n_alt = nvals_alt[nixz]
|
local n_path = nvals_path[nixz]
|
||||||
local n_absalt = math.abs(n_alt)
|
local n_abspath = math.abs(n_path)
|
||||||
local n_base = nvals_base[nixz]
|
local n_terrain = nvals_terrain[nixz]
|
||||||
local n_absbase = math.abs(n_base)
|
local ysurf = math.floor(n_terrain * TERSCA)
|
||||||
if n_absbase > TFLAT then
|
|
||||||
ysurf = YFLAT + math.floor((n_absbase - TFLAT) * TERSCA)
|
|
||||||
else
|
|
||||||
ysurf = YFLAT
|
|
||||||
flat = true
|
|
||||||
end
|
|
||||||
|
|
||||||
if chunk then
|
if chunk then
|
||||||
if y == YFLAT
|
if y == ysurf then
|
||||||
and (((n_alt >= 0 and n_xprealt < 0)
|
if ((n_path >= 0 and n_xprepath < 0)
|
||||||
or (n_alt < 0 and n_xprealt >= 0))
|
or (n_path < 0 and n_xprepath >= 0))
|
||||||
or ((n_alt >= 0 and n_zprealt < 0)
|
or ((n_path >= 0 and n_zprepath < 0)
|
||||||
or (n_alt < 0 and n_zprealt >= 0))) then
|
or (n_path < 0 and n_zprepath >= 0)) then
|
||||||
data[vi] = c_roadwhite
|
|
||||||
for i = -WID, WID do
|
|
||||||
for k = -WID, WID do
|
|
||||||
if (math.abs(i)) ^ 2 + (math.abs(k)) ^ 2 <= rad then
|
|
||||||
local vi = area:index(x+i, y, z+k)
|
|
||||||
local nodid = data[vi]
|
|
||||||
if nodid ~= c_roadwhite then
|
|
||||||
data[vi] = c_roadblack
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
elseif y >= YFLAT + 1 and y <= YFLAT + 4 and n_absalt < 0.025 then
|
|
||||||
data[vi] = c_air
|
|
||||||
elseif y <= ysurf - 1 and y == YFLAT + 5 and n_absalt > 0.003 and n_absalt < 0.007 then
|
|
||||||
data[vi] = c_light
|
|
||||||
elseif y <= ysurf and y >= YFLAT and y <= YFLAT + 5
|
|
||||||
and n_absalt < 0.035 and n_absbase > TFLAT and nodid ~= c_roadblack then
|
|
||||||
data[vi] = c_redcrete
|
|
||||||
elseif y == ysurf then
|
|
||||||
if ((n_base >= 0 and n_xprebase < 0)
|
|
||||||
or (n_base < 0 and n_xprebase >= 0))
|
|
||||||
or ((n_base >= 0 and n_zprebase < 0)
|
|
||||||
or (n_base < 0 and n_zprebase >= 0)) then
|
|
||||||
data[vi] = c_roadwhite
|
data[vi] = c_roadwhite
|
||||||
for i = -WID, WID do
|
for i = -4, 4 do
|
||||||
for k = -WID, WID do
|
for k = -4, 4 do
|
||||||
if (math.abs(i)) ^ 2 + (math.abs(k)) ^ 2 <= rad then
|
local radsq = (math.abs(i)) ^ 2 + (math.abs(k)) ^ 2
|
||||||
|
if radsq <= 13 then
|
||||||
local vi = area:index(x+i, y, z+k)
|
local vi = area:index(x+i, y, z+k)
|
||||||
|
local via = area:index(x+i, y+1, z+k)
|
||||||
local nodid = data[vi]
|
local nodid = data[vi]
|
||||||
|
local nodida = data[via]
|
||||||
if nodid ~= c_roadwhite then
|
if nodid ~= c_roadwhite then
|
||||||
data[vi] = c_roadblack
|
data[vi] = c_roadblack
|
||||||
|
if nodida == c_desand then
|
||||||
|
data[via] = c_air
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif radsq <= 20 then
|
||||||
|
local vi = area:index(x+i, y, z+k)
|
||||||
|
local via = area:index(x+i, y+1, z+k)
|
||||||
|
local nodid = data[vi]
|
||||||
|
local nodida = data[via]
|
||||||
|
if nodid ~= c_roadblack
|
||||||
|
and nodid ~= c_roadwhite
|
||||||
|
and nodid ~= c_desand then
|
||||||
|
data[vi] = c_roadslab
|
||||||
|
if nodida == c_desand then
|
||||||
|
data[via] = c_air
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif nodid ~= c_roadblack and nodid ~= c_roadwhite then
|
elseif nodid ~= c_roadblack
|
||||||
|
and nodid ~= c_roadwhite
|
||||||
|
and nodidu ~= c_roadblack
|
||||||
|
and nodidu ~= c_roadslab then
|
||||||
data[vi] = c_desand
|
data[vi] = c_desand
|
||||||
if math.random() < CACCHA then
|
if math.random() < CACCHA then
|
||||||
path_cactus(x, y+1, z, area, data)
|
path_cactus(x, y+1, z, area, data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif y <= ysurf - 8 and nodid ~= c_roadblack then
|
elseif y <= ysurf - 8 then
|
||||||
data[vi] = c_destone
|
data[vi] = c_destone
|
||||||
elseif y < ysurf and nodid ~= c_roadblack then
|
elseif y < ysurf and nodid ~= c_roadblack then
|
||||||
data[vi] = c_desand
|
data[vi] = c_desand
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
n_xprebase = n_base
|
n_xprepath = n_path
|
||||||
n_xprealt = n_alt
|
|
||||||
nixz = nixz + 1
|
nixz = nixz + 1
|
||||||
vi = vi + 1
|
vi = vi + 1
|
||||||
|
viu = viu + 1
|
||||||
end
|
end
|
||||||
nixz = nixz - 81
|
nixz = nixz - 81
|
||||||
end
|
end
|
||||||
@ -271,4 +237,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)
|
local chugent = math.ceil((os.clock() - t1) * 1000)
|
||||||
print ("[path] "..chugent.." ms")
|
print ("[path] "..chugent.." ms")
|
||||||
end)
|
end)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user