Refactor variable names
parent
431a04625a
commit
2c9658b805
67
init.lua
67
init.lua
|
@ -528,12 +528,12 @@ local function WoodSupport(p, wood, post, torches, dir, torchdir)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Corridors with rails
|
-- Dig out a single corridor section and place wooden structures and torches
|
||||||
|
|
||||||
-- Returns <success>, <segments>
|
-- Returns <success>, <segments>
|
||||||
-- success: true if corridor could be placed entirely
|
-- success: true if corridor could be placed entirely
|
||||||
-- segments: Number of segments successfully placed
|
-- segments: Number of segments successfully placed
|
||||||
local function corridor_part(start_point, segment_vector, segment_count, wood, post, up_or_down_prev)
|
local function dig_corridor_section(start_point, segment_vector, segment_count, wood, post, up_or_down_prev)
|
||||||
local p = {x=start_point.x, y=start_point.y, z=start_point.z}
|
local p = {x=start_point.x, y=start_point.y, z=start_point.z}
|
||||||
local torches = pr:next() < probability_torches_in_segment
|
local torches = pr:next() < probability_torches_in_segment
|
||||||
local dir = {0, 0}
|
local dir = {0, 0}
|
||||||
|
@ -589,7 +589,11 @@ local function corridor_part(start_point, segment_vector, segment_count, wood, p
|
||||||
return true, segment_count
|
return true, segment_count
|
||||||
end
|
end
|
||||||
|
|
||||||
local function corridor_func(waypoint, coord, sign, up_or_down, up_or_down_next, up_or_down_prev, up, wood, post, first_or_final, damage, no_spawner)
|
-- Generate a corridor section. Corridor sections are part of a corridor line.
|
||||||
|
-- This is one short part of a corridor line. It can be one straight section or it goes up or down.
|
||||||
|
-- It digs out the corridor and places wood structs and torches using the helper function dig_corridor_function,
|
||||||
|
-- then it places rails, chests, and other goodies.
|
||||||
|
local function create_corridor_section(waypoint, axis, sign, up_or_down, up_or_down_next, up_or_down_prev, up, wood, post, first_or_final, damage, no_spawner)
|
||||||
local segamount = 3
|
local segamount = 3
|
||||||
if up_or_down then
|
if up_or_down then
|
||||||
segamount = 1
|
segamount = 1
|
||||||
|
@ -599,12 +603,12 @@ local function corridor_func(waypoint, coord, sign, up_or_down, up_or_down_next,
|
||||||
end
|
end
|
||||||
local vek = {x=0,y=0,z=0};
|
local vek = {x=0,y=0,z=0};
|
||||||
local start = table.copy(waypoint)
|
local start = table.copy(waypoint)
|
||||||
if coord == "x" then
|
if axis == "x" then
|
||||||
vek.x=segamount
|
vek.x=segamount
|
||||||
if up_or_down and up == false then
|
if up_or_down and up == false then
|
||||||
start.x=start.x+segamount
|
start.x=start.x+segamount
|
||||||
end
|
end
|
||||||
elseif coord == "z" then
|
elseif axis == "z" then
|
||||||
vek.z=segamount
|
vek.z=segamount
|
||||||
if up_or_down and up == false then
|
if up_or_down and up == false then
|
||||||
start.z=start.z+segamount
|
start.z=start.z+segamount
|
||||||
|
@ -621,7 +625,7 @@ local function corridor_func(waypoint, coord, sign, up_or_down, up_or_down_next,
|
||||||
if up_or_down and up == false then
|
if up_or_down and up == false then
|
||||||
Cube(waypoint, 1, {name="air"}, false)
|
Cube(waypoint, 1, {name="air"}, false)
|
||||||
end
|
end
|
||||||
local corridor_dug, corridor_segments_dug = corridor_part(start, vek, segcount, wood, post, up_or_down_prev)
|
local corridor_dug, corridor_segments_dug = dig_corridor_section(start, vek, segcount, wood, post, up_or_down_prev)
|
||||||
local corridor_vek = {x=vek.x*segcount, y=vek.y*segcount, z=vek.z*segcount}
|
local corridor_vek = {x=vek.x*segcount, y=vek.y*segcount, z=vek.z*segcount}
|
||||||
|
|
||||||
-- After this: rails
|
-- After this: rails
|
||||||
|
@ -629,9 +633,9 @@ local function corridor_func(waypoint, coord, sign, up_or_down, up_or_down_next,
|
||||||
if sign then
|
if sign then
|
||||||
segamount = 0-segamount
|
segamount = 0-segamount
|
||||||
end
|
end
|
||||||
if coord == "x" then
|
if axis == "x" then
|
||||||
vek.x=segamount
|
vek.x=segamount
|
||||||
elseif coord == "z" then
|
elseif axis == "z" then
|
||||||
vek.z=segamount
|
vek.z=segamount
|
||||||
end
|
end
|
||||||
if up_or_down then
|
if up_or_down then
|
||||||
|
@ -786,7 +790,7 @@ local function corridor_func(waypoint, coord, sign, up_or_down, up_or_down_next,
|
||||||
offset.y = offset.y - 1
|
offset.y = offset.y - 1
|
||||||
final_point = vector.add(waypoint, offset)
|
final_point = vector.add(waypoint, offset)
|
||||||
else
|
else
|
||||||
offset[coord] = offset[coord] + segamount
|
offset[axis] = offset[axis] + segamount
|
||||||
final_point = vector.add(waypoint, offset)
|
final_point = vector.add(waypoint, offset)
|
||||||
-- After going up or down, 1 missing rail piece must be added
|
-- After going up or down, 1 missing rail piece must be added
|
||||||
if IsRailSurface({x=final_point.x,y=final_point.y-2,z=final_point.z}) then
|
if IsRailSurface({x=final_point.x,y=final_point.y-2,z=final_point.z}) then
|
||||||
|
@ -801,9 +805,11 @@ local function corridor_func(waypoint, coord, sign, up_or_down, up_or_down_next,
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function start_corridor(waypoint, coord, sign, length, wood, post, damage, no_spawner)
|
-- Generate a line of corridors.
|
||||||
|
-- The corridor can go up/down, take turns and it can branch off, creating more corridor lines.
|
||||||
|
local function create_corridor_line(waypoint, axis, sign, length, wood, post, damage, no_spawner)
|
||||||
local wp = waypoint
|
local wp = waypoint
|
||||||
local c = coord
|
local a = axis
|
||||||
local s = sign
|
local s = sign
|
||||||
local ud = false -- Up or down
|
local ud = false -- Up or down
|
||||||
local udn = false -- Up or down is next
|
local udn = false -- Up or down is next
|
||||||
|
@ -858,9 +864,9 @@ local function start_corridor(waypoint, coord, sign, length, wood, post, damage,
|
||||||
elseif i == 1 then
|
elseif i == 1 then
|
||||||
first_or_final = "first"
|
first_or_final = "first"
|
||||||
end
|
end
|
||||||
wp, no_spawner = corridor_func(wp,c,s, ud, udn, udp, up, wood, post, first_or_final, damage, no_spawner)
|
wp, no_spawner = create_corridor_section(wp,a,s, ud, udn, udp, up, wood, post, first_or_final, damage, no_spawner)
|
||||||
if wp == false then return end
|
if wp == false then return end
|
||||||
-- Fork in the road? If so, starts 2-3 new corridors
|
-- Fork in the road? If so, starts 2-3 new corridor lines and terminates the current one.
|
||||||
if pr:next() < probability_fork then
|
if pr:next() < probability_fork then
|
||||||
-- 75% chance to fork off in 3 directions (making a crossing)
|
-- 75% chance to fork off in 3 directions (making a crossing)
|
||||||
-- 25% chance to fork off in 2 directions (making a t-junction)
|
-- 25% chance to fork off in 2 directions (making a t-junction)
|
||||||
|
@ -870,20 +876,20 @@ local function start_corridor(waypoint, coord, sign, length, wood, post, damage,
|
||||||
forks = 3
|
forks = 3
|
||||||
end
|
end
|
||||||
local p = {x=wp.x, y=wp.y, z=wp.z}
|
local p = {x=wp.x, y=wp.y, z=wp.z}
|
||||||
local c2
|
local a2
|
||||||
if c == "x" then
|
if a == "x" then
|
||||||
c2="z"
|
a2="z"
|
||||||
else
|
else
|
||||||
c2="x"
|
a2="x"
|
||||||
end
|
end
|
||||||
local fork_dirs = {
|
local fork_dirs = {
|
||||||
{c2, s}, -- to the side
|
{a2, s}, -- to the side
|
||||||
{c2, not s}, -- to the other side
|
{a2, not s}, -- to the other side
|
||||||
{c, s}, -- straight ahead
|
{a, s}, -- straight ahead
|
||||||
}
|
}
|
||||||
for f=1, forks do
|
for f=1, forks do
|
||||||
local r = pr:next(1, #fork_dirs)
|
local r = pr:next(1, #fork_dirs)
|
||||||
start_corridor(wp, fork_dirs[r][1], fork_dirs[r][2], pr:next(way_min,way_max), wood, post, damage, no_spawner)
|
create_corridor_line(wp, fork_dirs[r][1], fork_dirs[r][2], pr:next(way_min,way_max), wood, post, damage, no_spawner)
|
||||||
table.remove(fork_dirs, r)
|
table.remove(fork_dirs, r)
|
||||||
end
|
end
|
||||||
if is_crossing then
|
if is_crossing then
|
||||||
|
@ -892,11 +898,12 @@ local function start_corridor(waypoint, coord, sign, length, wood, post, damage,
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- Randomly change sign and coord
|
-- Randomly change sign, toggle axis.
|
||||||
if c=="x" then
|
-- In other words, take a turn.
|
||||||
c="z"
|
if a=="x" then
|
||||||
elseif c=="z" then
|
a="z"
|
||||||
c="x"
|
elseif a=="z" then
|
||||||
|
a="x"
|
||||||
end;
|
end;
|
||||||
s = pr:next(0, 2) < 1
|
s = pr:next(0, 2) < 1
|
||||||
end
|
end
|
||||||
|
@ -928,7 +935,7 @@ end
|
||||||
-- Start generation of a rail corridor system
|
-- Start generation of a rail corridor system
|
||||||
-- main_cave_coords is the center of the floor of the dirt room, from which
|
-- main_cave_coords is the center of the floor of the dirt room, from which
|
||||||
-- all corridors expand.
|
-- all corridors expand.
|
||||||
local function start_corridor_system(main_cave_coords)
|
local function create_corridor_system(main_cave_coords)
|
||||||
--[[ Start building in the ground. Prevents corridors starting
|
--[[ Start building in the ground. Prevents corridors starting
|
||||||
in mid-air or in liquids. ]]
|
in mid-air or in liquids. ]]
|
||||||
if not IsGround(main_cave_coords) then
|
if not IsGround(main_cave_coords) then
|
||||||
|
@ -1036,12 +1043,12 @@ local function start_corridor_system(main_cave_coords)
|
||||||
first_corridor = {sign=dir.sign, axis=dir.axis, axis2=dir.axis2, side_offset=side_offset, from_center=from_center}
|
first_corridor = {sign=dir.sign, axis=dir.axis, axis2=dir.axis2, side_offset=side_offset, from_center=from_center}
|
||||||
end
|
end
|
||||||
local coords = vector.add(main_cave_coords, {[dir.axis] = from_center, y=0, [dir.axis2] = side_offset})
|
local coords = vector.add(main_cave_coords, {[dir.axis] = from_center, y=0, [dir.axis2] = side_offset})
|
||||||
start_corridor(coords, dir.axis, dir.sign, pr:next(way_min,way_max), wood, post, damage, false)
|
create_corridor_line(coords, dir.axis, dir.sign, pr:next(way_min,way_max), wood, post, damage, false)
|
||||||
table.remove(dirs, d)
|
table.remove(dirs, d)
|
||||||
end
|
end
|
||||||
if corridors == 5 then
|
if corridors == 5 then
|
||||||
local special_coords = vector.add(main_cave_coords, {[first_corridor.axis2] = -first_corridor.side_offset, y=0, [first_corridor.axis] = first_corridor.from_center})
|
local special_coords = vector.add(main_cave_coords, {[first_corridor.axis2] = -first_corridor.side_offset, y=0, [first_corridor.axis] = first_corridor.from_center})
|
||||||
start_corridor(special_coords, first_corridor.axis, first_corridor.sign, pr:next(way_min,way_max), wood, post, damage, false)
|
create_corridor_line(special_coords, first_corridor.axis, first_corridor.sign, pr:next(way_min,way_max), wood, post, damage, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- At this point, all corridors were generated and all nodes were set.
|
-- At this point, all corridors were generated and all nodes were set.
|
||||||
|
@ -1070,7 +1077,7 @@ minetest.register_on_generated(function(minp, maxp, blockseed)
|
||||||
local p = {x=minp.x+math.floor((maxp.x-minp.x)/2), y=y, z=minp.z+math.floor((maxp.z-minp.z)/2)}
|
local p = {x=minp.x+math.floor((maxp.x-minp.x)/2), y=y, z=minp.z+math.floor((maxp.z-minp.z)/2)}
|
||||||
-- Start corridor system at p. Might fail if p is in open air
|
-- Start corridor system at p. Might fail if p is in open air
|
||||||
minetest.log("verbose", "[tsm_railcorridors] Attempting to start rail corridor system at "..minetest.pos_to_string(p))
|
minetest.log("verbose", "[tsm_railcorridors] Attempting to start rail corridor system at "..minetest.pos_to_string(p))
|
||||||
if start_corridor_system(p, pr) then
|
if create_corridor_system(p, pr) then
|
||||||
minetest.log("info", "[tsm_railcorridors] Generated rail corridor system at "..minetest.pos_to_string(p))
|
minetest.log("info", "[tsm_railcorridors] Generated rail corridor system at "..minetest.pos_to_string(p))
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue