Rework rail_dir_curve to significantly reduce code size
This commit is contained in:
parent
bb0f0747ae
commit
d12896c162
|
@ -45,47 +45,19 @@ local function rail_dir_sloped(pos, dir, node)
|
|||
return downhill
|
||||
end
|
||||
end
|
||||
-- Fourdir
|
||||
-- 0 = north
|
||||
-- 1 = east
|
||||
-- 2 = south
|
||||
-- 3 = west
|
||||
local CURVE_RAIL_DIRS = { [0] = 1, 1, 2, 2, }
|
||||
local function rail_dir_curve(pos, dir, node)
|
||||
dir = vector.new(dir.x, 0, dir.z)
|
||||
local dir_fourdir = minetest.dir_to_fourdir(dir)
|
||||
|
||||
-- Fourdir
|
||||
-- 0 = north
|
||||
-- 1 = east
|
||||
-- 2 = south
|
||||
-- 3 = west
|
||||
|
||||
local new_fourdir = 0
|
||||
if node.param2 == 0 then -- north
|
||||
-- South and East
|
||||
if dir_fourdir == 0 then new_fourdir = 1 end
|
||||
if dir_fourdir == 1 then new_fourdir = 1 end
|
||||
if dir_fourdir == 2 then new_fourdir = 2 end
|
||||
if dir_fourdir == 3 then new_fourdir = 2 end
|
||||
elseif node.param2 == 1 then -- east
|
||||
-- South and West
|
||||
if dir_fourdir == 1 then new_fourdir = 2 end
|
||||
if dir_fourdir == 2 then new_fourdir = 2 end
|
||||
if dir_fourdir == 3 then new_fourdir = 3 end
|
||||
if dir_fourdir == 0 then new_fourdir = 3 end
|
||||
elseif node.param2 == 2 then -- south
|
||||
-- North and West
|
||||
if dir_fourdir == 2 then new_fourdir = 3 end
|
||||
if dir_fourdir == 3 then new_fourdir = 3 end
|
||||
if dir_fourdir == 0 then new_fourdir = 0 end
|
||||
if dir_fourdir == 1 then new_fourdir = 0 end
|
||||
elseif node.param2 == 3 then -- west
|
||||
-- North and East
|
||||
if dir_fourdir == 3 then new_fourdir = 0 end
|
||||
if dir_fourdir == 0 then new_fourdir = 0 end
|
||||
if dir_fourdir == 1 then new_fourdir = 1 end
|
||||
if dir_fourdir == 2 then new_fourdir = 1 end
|
||||
end
|
||||
|
||||
local dir_fourdir = (minetest.dir_to_fourdir(dir) - node.param2 + 4) % 4
|
||||
local new_fourdir = (CURVE_RAIL_DIRS[dir_fourdir] + node.param2) % 4
|
||||
return minetest.fourdir_to_dir(new_fourdir)
|
||||
end
|
||||
|
||||
|
||||
local function rail_dir_tee_off(pos, dir, node)
|
||||
dir = vector.new(dir.x, 0, dir.z)
|
||||
|
||||
|
|
Loading…
Reference in New Issue