aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororwell96 <mono96.mml@gmail.com>2016-07-04 13:08:25 +0200
committerorwell96 <mono96.mml@gmail.com>2016-07-04 13:08:25 +0200
commit0e869927299ccd9f720d0144c20dbde6a1054fe0 (patch)
treee002731dc3227fc136e77ce6c59eb07991e9d2d7
parenta6e19b76518000bae9ca163ce6855e56ee784267 (diff)
downloadadvtrains-0e869927299ccd9f720d0144c20dbde6a1054fe0.tar.gz
advtrains-0e869927299ccd9f720d0144c20dbde6a1054fe0.tar.bz2
advtrains-0e869927299ccd9f720d0144c20dbde6a1054fe0.zip
Screwing everything up in order to extend to 16 possible directions with 1/8 precision
-rw-r--r--helpers.lua55
-rw-r--r--models/advtrains_track_cr.b3dbin0 -> 8023 bytes
-rw-r--r--models/advtrains_track_st.b3dbin0 -> 15831 bytes
-rw-r--r--models/advtrains_track_st_45.b3dbin0 -> 8935 bytes
-rw-r--r--models/gleis/infos/Grafik_weiche.pngbin0 -> 361700 bytes
-rw-r--r--models/gleis/infos/breite1
-rw-r--r--models/gleis/licence.txt~0
-rw-r--r--models/gleis/rail_together.blendbin0 -> 1016920 bytes
-rw-r--r--models/gleis/rail_together.pngbin0 -> 233544 bytes
-rw-r--r--models/gleis/rail_together2.pngbin0 -> 312891 bytes
-rw-r--r--models/gleis/rail_together3.pngbin0 -> 309398 bytes
-rw-r--r--models/gleis/texturen/rail.pngbin0 -> 2616 bytes
-rw-r--r--models/gleis/texturen/uv.pngbin0 -> 2343 bytes
-rw-r--r--trackplacer.lua30
-rw-r--r--tracks.lua47
15 files changed, 68 insertions, 65 deletions
diff --git a/helpers.lua b/helpers.lua
index cd67aa9..ef3752a 100644
--- a/helpers.lua
+++ b/helpers.lua
@@ -1,35 +1,32 @@
--advtrains by orwell96, see readme.txt
local print=function(t) minetest.log("action", t) minetest.chat_send_all(t) end
+advtrains.dir_trans_tbl={
+ [0]={x=0, z=1},
+ [1]={x=1, z=2},
+ [2]={x=1, z=1},
+ [3]={x=2, z=1},
+ [4]={x=1, z=0},
+ [5]={x=2, z=-1},
+ [6]={x=1, z=-1},
+ [7]={x=1, z=-2},
+ [8]={x=0, z=-1},
+ [9]={x=-1, z=-2},
+ [10]={x=-1, z=-1},
+ [11]={x=-2, z=-1},
+ [12]={x=-1, z=0},
+ [13]={x=-2, z=1},
+ [14]={x=-1, z=1},
+ [15]={x=-1, z=2},
+}
+
function advtrains.dirCoordSet(coord, dir)
- local x=0
- local z=0
- --local dir=(dirx+2)%8
- if(dir==6) then
- x=-1
- elseif (dir==7) then
- x=-1
- z=1
- elseif (dir==0) then
- z=1
- elseif (dir==1) then
- z=1
- x=1
- elseif (dir==2) then
- x=1
- elseif (dir==3) then
- x=1
- z=-1
- elseif (dir==4) then
- z=-1
- elseif (dir==5) then
- z=-1
- x=-1
+ local x,z
+ if advtrains.dir_trans_tbl[dir] then
+ x,z=advtrains.dir_trans_tbl[dir].x, advtrains.dir_trans_tbl[dir].z
else
error("advtrains: in helpers.lua/dirCoordSet() given dir="..(dir or "nil"))
end
-
-
return {x=coord.x+x, y=coord.y, z=coord.z+z}
end
function advtrains.dirToCoord(dir)
@@ -123,7 +120,7 @@ function advtrains.conway(midreal, prev, traintype)--in order prev,mid,return
end
--is this next rail connecting to the mid?
- if not ( (((nextdir1+4)%8)==chkdir and nextrely1==chkrely-y_offset) or (((nextdir2+4)%8)==chkdir and nextrely2==chkrely-y_offset) ) then
+ if not ( (((nextdir1+8)%16)==chkdir and nextrely1==chkrely-y_offset) or (((nextdir2+8)%16)==chkdir and nextrely2==chkrely-y_offset) ) then
--print("[advtrains]in conway: next "..minetest.pos_to_string(next).." not connecting, trying one node below!")
next.y=next.y-1
y_offset=y_offset-1
@@ -133,7 +130,7 @@ function advtrains.conway(midreal, prev, traintype)--in order prev,mid,return
--print("[advtrains]in conway: (at connecting if check again) one below "..minetest.pos_to_string(next).." is not a rail either, returning!")
return nil
end
- if not ( (((nextdir1+4)%8)==chkdir and nextrely1==chkrely) or (((nextdir2+4)%8)==chkdir and nextrely2==chkrely) ) then
+ if not ( (((nextdir1+8)%16)==chkdir and nextrely1==chkrely) or (((nextdir2+8)%16)==chkdir and nextrely2==chkrely) ) then
--print("[advtrains]in conway: one below "..minetest.pos_to_string(next).." rail not connecting, returning!")
--print("[advtrains] in order mid1,2,next1,2,chkdir "..middir1.." "..middir2.." "..nextdir1.." "..nextdir2.." "..chkdir)
return nil
@@ -143,6 +140,10 @@ function advtrains.conway(midreal, prev, traintype)--in order prev,mid,return
--print("[advtrains]conway found rail.")
return vector.add(advtrains.round_vector_floor_y(next), {x=0, y=nextrailheight, z=0}), chkdir
end
+--TODO use this
+function advtrains.oppd(dir)
+ return ((dir+8)%16)
+end
function advtrains.round_vector_floor_y(vec)
return {x=math.floor(vec.x+0.5), y=math.floor(vec.y), z=math.floor(vec.z+0.5)}
diff --git a/models/advtrains_track_cr.b3d b/models/advtrains_track_cr.b3d
new file mode 100644
index 0000000..b0f5e4b
--- /dev/null
+++ b/models/advtrains_track_cr.b3d
Binary files differ
diff --git a/models/advtrains_track_st.b3d b/models/advtrains_track_st.b3d
new file mode 100644
index 0000000..10b5d90
--- /dev/null
+++ b/models/advtrains_track_st.b3d
Binary files differ
diff --git a/models/advtrains_track_st_45.b3d b/models/advtrains_track_st_45.b3d
new file mode 100644
index 0000000..32505a1
--- /dev/null
+++ b/models/advtrains_track_st_45.b3d
Binary files differ
diff --git a/models/gleis/infos/Grafik_weiche.png b/models/gleis/infos/Grafik_weiche.png
new file mode 100644
index 0000000..6674eb3
--- /dev/null
+++ b/models/gleis/infos/Grafik_weiche.png
Binary files differ
diff --git a/models/gleis/infos/breite b/models/gleis/infos/breite
new file mode 100644
index 0000000..b2862c6
--- /dev/null
+++ b/models/gleis/infos/breite
@@ -0,0 +1 @@
+1435mm
diff --git a/models/gleis/licence.txt~ b/models/gleis/licence.txt~
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/models/gleis/licence.txt~
diff --git a/models/gleis/rail_together.blend b/models/gleis/rail_together.blend
new file mode 100644
index 0000000..cff51ea
--- /dev/null
+++ b/models/gleis/rail_together.blend
Binary files differ
diff --git a/models/gleis/rail_together.png b/models/gleis/rail_together.png
new file mode 100644
index 0000000..386cd5c
--- /dev/null
+++ b/models/gleis/rail_together.png
Binary files differ
diff --git a/models/gleis/rail_together2.png b/models/gleis/rail_together2.png
new file mode 100644
index 0000000..3effe34
--- /dev/null
+++ b/models/gleis/rail_together2.png
Binary files differ
diff --git a/models/gleis/rail_together3.png b/models/gleis/rail_together3.png
new file mode 100644
index 0000000..4a183c1
--- /dev/null
+++ b/models/gleis/rail_together3.png
Binary files differ
diff --git a/models/gleis/texturen/rail.png b/models/gleis/texturen/rail.png
new file mode 100644
index 0000000..8478cf6
--- /dev/null
+++ b/models/gleis/texturen/rail.png
Binary files differ
diff --git a/models/gleis/texturen/uv.png b/models/gleis/texturen/uv.png
new file mode 100644
index 0000000..fb0af3e
--- /dev/null
+++ b/models/gleis/texturen/uv.png
Binary files differ
diff --git a/trackplacer.lua b/trackplacer.lua
index b1e57a5..2bba2ad 100644
--- a/trackplacer.lua
+++ b/trackplacer.lua
@@ -39,18 +39,18 @@ function advtrains.placetrack(pos)
elseif conn1 and not conn2 then
local node1=minetest.get_node(advtrains.dirCoordSet(pos, conn1))
local node1_conn1, node1_conn2=advtrains.get_track_connections(node1.name, node1.param2)
- local node1_backconnects=(conn1+4)%8==node1_conn1 or (conn1+4)%8==node1_conn2
+ local node1_backconnects=(conn1+8)%16==node1_conn1 or (conn1+8)%16==node1_conn2
if not node1_backconnects and advtrains.trackplacer_modified_rails[node1.name] then
--check if this rail has a dangling connection
--TODO possible problems on |- situation
if not advtrains.is_track_and_drives_on(minetest.get_node(advtrains.dirCoordSet(pos, node1_conn1)).name, advtrains.all_tracktypes) then
- if advtrains.trackplacer_dir_to_node_mapping[node1_conn1.."_"..((conn1+4)%8)] then
- minetest.set_node(advtrains.dirCoordSet(pos, conn1), advtrains.trackplacer_dir_to_node_mapping[node1_conn1.."_"..((conn1+4)%8)])
+ if advtrains.trackplacer_dir_to_node_mapping[node1_conn1.."_"..((conn1+8)%16)] then
+ minetest.set_node(advtrains.dirCoordSet(pos, conn1), advtrains.trackplacer_dir_to_node_mapping[node1_conn1.."_"..((conn1+8)%16)])
end
elseif not advtrains.is_track_and_drives_on(minetest.get_node(advtrains.dirCoordSet(pos, node1_conn2)).name, advtrains.all_tracktypes) then
- if advtrains.trackplacer_dir_to_node_mapping[node1_conn2.."_"..((conn1+4)%8)] then
- minetest.set_node(advtrains.dirCoordSet(pos, conn1), advtrains.trackplacer_dir_to_node_mapping[node1_conn2.."_"..((conn1+4)%8)])
+ if advtrains.trackplacer_dir_to_node_mapping[node1_conn2.."_"..((conn1+8)%16)] then
+ minetest.set_node(advtrains.dirCoordSet(pos, conn1), advtrains.trackplacer_dir_to_node_mapping[node1_conn2.."_"..((conn1+8)%16)])
end
end
end
@@ -67,34 +67,34 @@ function advtrains.placetrack(pos)
end
local node1=minetest.get_node(advtrains.dirCoordSet(pos, conn1))
local node1_conn1, node1_conn2=advtrains.get_track_connections(node1.name, node1.param2)
- local node1_backconnects=(conn1+4)%8==node1_conn1 or (conn1+4)%8==node1_conn2
+ local node1_backconnects=(conn1+8)%16==node1_conn1 or (conn1+8)%16==node1_conn2
if not node1_backconnects and advtrains.trackplacer_modified_rails[node1.name] then
--check if this rail has a dangling connection
--TODO possible problems on |- situation
if not advtrains.is_track_and_drives_on(minetest.get_node(advtrains.dirCoordSet(pos, node1_conn1)).name, advtrains.all_tracktypes) then
- if advtrains.trackplacer_dir_to_node_mapping[node1_conn1.."_"..((conn1+4)%8)] then
- minetest.set_node(advtrains.dirCoordSet(pos, conn1), advtrains.trackplacer_dir_to_node_mapping[node1_conn1.."_"..((conn1+4)%8)])
+ if advtrains.trackplacer_dir_to_node_mapping[node1_conn1.."_"..((conn1+8)%16)] then
+ minetest.set_node(advtrains.dirCoordSet(pos, conn1), advtrains.trackplacer_dir_to_node_mapping[node1_conn1.."_"..((conn1+8)%16)])
end
elseif not advtrains.is_track_and_drives_on(minetest.get_node(advtrains.dirCoordSet(pos, node1_conn2)).name, advtrains.all_tracktypes) then
- if advtrains.trackplacer_dir_to_node_mapping[node1_conn2.."_"..((conn1+4)%8)] then
- minetest.set_node(advtrains.dirCoordSet(pos, conn1), advtrains.trackplacer_dir_to_node_mapping[node1_conn2.."_"..((conn1+4)%8)])
+ if advtrains.trackplacer_dir_to_node_mapping[node1_conn2.."_"..((conn1+8)%16)] then
+ minetest.set_node(advtrains.dirCoordSet(pos, conn1), advtrains.trackplacer_dir_to_node_mapping[node1_conn2.."_"..((conn1+8)%16)])
end
end
end
local node2=minetest.get_node(advtrains.dirCoordSet(pos, conn2))
local node2_conn1, node2_conn2=advtrains.get_track_connections(node2.name, node2.param2)
- local node2_backconnects=(conn2+4)%8==node2_conn1 or (conn2+4)%8==node2_conn2
+ local node2_backconnects=(conn2+8)%16==node2_conn1 or (conn2+8)%16==node2_conn2
if not node2_backconnects and advtrains.trackplacer_modified_rails[node2.name] then
--check if this rail has a dangling connection
--TODO possible problems on |- situation
if not advtrains.is_track_and_drives_on(minetest.get_node(advtrains.dirCoordSet(pos, node2_conn1)).name, advtrains.all_tracktypes) then
- if advtrains.trackplacer_dir_to_node_mapping[node2_conn1.."_"..((conn2+4)%8)] then
- minetest.set_node(advtrains.dirCoordSet(pos, conn2), advtrains.trackplacer_dir_to_node_mapping[node2_conn1.."_"..((conn2+4)%8)])
+ if advtrains.trackplacer_dir_to_node_mapping[node2_conn1.."_"..((conn2+8)%16)] then
+ minetest.set_node(advtrains.dirCoordSet(pos, conn2), advtrains.trackplacer_dir_to_node_mapping[node2_conn1.."_"..((conn2+8)%16)])
end
elseif not advtrains.is_track_and_drives_on(minetest.get_node(advtrains.dirCoordSet(pos, node2_conn2)).name, advtrains.all_tracktypes) then
- if advtrains.trackplacer_dir_to_node_mapping[node2_conn2.."_"..((conn1+4)%8)] then
- minetest.set_node(advtrains.dirCoordSet(pos, conn2), advtrains.trackplacer_dir_to_node_mapping[node2_conn2.."_"..((conn2+4)%8)])
+ if advtrains.trackplacer_dir_to_node_mapping[node2_conn2.."_"..((conn1+8)%16)] then
+ minetest.set_node(advtrains.dirCoordSet(pos, conn2), advtrains.trackplacer_dir_to_node_mapping[node2_conn2.."_"..((conn2+8)%16)])
end
end
end
diff --git a/tracks.lua b/tracks.lua
index 1e7788f..8f405d2 100644
--- a/tracks.lua
+++ b/tracks.lua
@@ -4,6 +4,7 @@
nodename_prefix
texture_prefix
description
+common={}
straight={}
straight45={}
curve={}
@@ -44,7 +45,7 @@ function advtrains.register_tracks(tracktype, def)
on_rightclick=switchfunc,
}
end
- local common_def={
+ local common_def=advtrains.merge_tables({
description = def.description,
drawtype = "mesh",
mesh = "trackplane.b3d",
@@ -78,42 +79,42 @@ function advtrains.register_tracks(tracktype, def)
after_place_node=function(pos)
advtrains.reset_trackdb_position(pos)
end,
- }
- minetest.register_node(def.nodename_prefix.."_st", advtrains.merge_tables(common_def, make_overdef("st", 0, 4), def.straight or {}))
- minetest.register_node(def.nodename_prefix.."_st_45", advtrains.merge_tables(common_def, make_overdef("st_45", 1, 5), def.straight45 or {}))
+ }, def.common or {})
+ minetest.register_node(def.nodename_prefix.."_st", advtrains.merge_tables(common_def, make_overdef("st", 0, 8), def.straight or {}))
+ minetest.register_node(def.nodename_prefix.."_st_45", advtrains.merge_tables(common_def, make_overdef("st_45", 2, 10), def.straight45 or {}))
- minetest.register_node(def.nodename_prefix.."_cr", advtrains.merge_tables(common_def, make_overdef("cr", 0, 3), def.curve or {}))
- minetest.register_node(def.nodename_prefix.."_cr_45", advtrains.merge_tables(common_def, make_overdef("cr_45", 1, 4), def.curve45 or {}))
+ minetest.register_node(def.nodename_prefix.."_cr", advtrains.merge_tables(common_def, make_overdef("cr", 0, 6), def.curve or {}))
+ minetest.register_node(def.nodename_prefix.."_cr_45", advtrains.merge_tables(common_def, make_overdef("cr_45", 2, 8), def.curve45 or {}))
- advtrains.trackplacer_register(def.nodename_prefix.."_st", 0, 4)
- advtrains.trackplacer_register(def.nodename_prefix.."_st_45", 1, 5)
- advtrains.trackplacer_register(def.nodename_prefix.."_cr", 0, 3)
- advtrains.trackplacer_register(def.nodename_prefix.."_cr_45", 1, 4)
+ advtrains.trackplacer_register(def.nodename_prefix.."_st", 0, 8)
+ advtrains.trackplacer_register(def.nodename_prefix.."_st_45", 2, 10)
+ advtrains.trackplacer_register(def.nodename_prefix.."_cr", 0, 6)
+ advtrains.trackplacer_register(def.nodename_prefix.."_cr_45", 2, 8)
- minetest.register_node(def.nodename_prefix.."_swl_st", advtrains.merge_tables(common_def, make_overdef("swl_st", 0, 4, make_switchfunc("swl_cr")), def.lswitchst or {}))
- minetest.register_node(def.nodename_prefix.."_swl_st_45", advtrains.merge_tables(common_def, make_overdef("swl_st_45", 1, 5, make_switchfunc("swl_cr_45")), def.lswitchst45 or {}))
- minetest.register_node(def.nodename_prefix.."_swl_cr", advtrains.merge_tables(common_def, make_overdef("swl_cr", 0, 3, make_switchfunc("swl_st")), def.lswitchcr or {}))
- minetest.register_node(def.nodename_prefix.."_swl_cr_45", advtrains.merge_tables(common_def, make_overdef("swl_cr_45", 1, 4, make_switchfunc("swl_st_45")), def.lswitchcr45 or {}))
+ minetest.register_node(def.nodename_prefix.."_swl_st", advtrains.merge_tables(common_def, make_overdef("swl_st", 0, 8, make_switchfunc("swl_cr")), def.lswitchst or {}))
+ minetest.register_node(def.nodename_prefix.."_swl_st_45", advtrains.merge_tables(common_def, make_overdef("swl_st_45", 2, 10, make_switchfunc("swl_cr_45")), def.lswitchst45 or {}))
+ minetest.register_node(def.nodename_prefix.."_swl_cr", advtrains.merge_tables(common_def, make_overdef("swl_cr", 0, 6, make_switchfunc("swl_st")), def.lswitchcr or {}))
+ minetest.register_node(def.nodename_prefix.."_swl_cr_45", advtrains.merge_tables(common_def, make_overdef("swl_cr_45", 2, 8, make_switchfunc("swl_st_45")), def.lswitchcr45 or {}))
- minetest.register_node(def.nodename_prefix.."_swr_st", advtrains.merge_tables(common_def, make_overdef("swr_st", 0, 4, make_switchfunc("swr_cr")), def.rswitchst or {}))
- minetest.register_node(def.nodename_prefix.."_swr_st_45", advtrains.merge_tables(common_def, make_overdef("swr_st_45", 1, 5, make_switchfunc("swr_cr_45")), def.rswitchst45 or {}))
- minetest.register_node(def.nodename_prefix.."_swr_cr", advtrains.merge_tables(common_def, make_overdef("swr_cr", 0, 5, make_switchfunc("swr_st")), def.rswitchcr or {}))
- minetest.register_node(def.nodename_prefix.."_swr_cr_45", advtrains.merge_tables(common_def, make_overdef("swr_cr_45", 1, 6, make_switchfunc("swr_st_45")), def.rswitchcr45 or {}))
+ minetest.register_node(def.nodename_prefix.."_swr_st", advtrains.merge_tables(common_def, make_overdef("swr_st", 0, 8, make_switchfunc("swr_cr")), def.rswitchst or {}))
+ minetest.register_node(def.nodename_prefix.."_swr_st_45", advtrains.merge_tables(common_def, make_overdef("swr_st_45", 2, 10, make_switchfunc("swr_cr_45")), def.rswitchst45 or {}))
+ minetest.register_node(def.nodename_prefix.."_swr_cr", advtrains.merge_tables(common_def, make_overdef("swr_cr", 0, 10, make_switchfunc("swr_st")), def.rswitchcr or {}))
+ minetest.register_node(def.nodename_prefix.."_swr_cr_45", advtrains.merge_tables(common_def, make_overdef("swr_cr_45", 2, 12, make_switchfunc("swr_st_45")), def.rswitchcr45 or {}))
- minetest.register_node(def.nodename_prefix.."_vert1", advtrains.merge_tables(common_def, make_overdef("vert1", 0, 4), {
+ minetest.register_node(def.nodename_prefix.."_vert1", advtrains.merge_tables(common_def, make_overdef("vert1", 0, 8), {
mesh = "trackvertical1.b3d",
rely1=0,
rely2=0.5,
railheight=0.25,
description = def.description.." (vertical track lower node)",
}, def.vert1 or {}))
- minetest.register_node(def.nodename_prefix.."_vert2", advtrains.merge_tables(common_def, make_overdef("vert2", 0, 4), {
+ minetest.register_node(def.nodename_prefix.."_vert2", advtrains.merge_tables(common_def, make_overdef("vert2", 0, 8), {
mesh = "trackvertical2.b3d",
rely1=0.5,
rely2=1,
railheight=0.75,
- description = def.description.." (vertical track lower node)",
+ description = def.description.." (vertical track upper node)",
},def.vert2 or {}))
advtrains.register_track_placer(def.nodename_prefix, def.texture_prefix, def.description)
@@ -141,12 +142,12 @@ end
function advtrains.get_track_connections(name, param2)
local nodedef=minetest.registered_nodes[name]
- if not nodedef then print("[advtrains] get_track_connections couldn't find nodedef for nodename "..(name or "nil")) return 0, 4, 0, 0, 0 end
+ if not nodedef then print("[advtrains] get_track_connections couldn't find nodedef for nodename "..(name or "nil")) return 0, 8, 0, 0, 0 end
local noderot=param2
if not param2 then noderot=0 end
if noderot > 3 then print("[advtrains] get_track_connections: rail has invaild param2 of "..noderot) noderot=0 end
- return (nodedef.connect1 + 2 * noderot)%8, (nodedef.connect2 + 2 * noderot)%8, nodedef.rely1 or 0, nodedef.rely2 or 0, nodedef.railheight or 0
+ return (nodedef.connect1 + 4 * noderot)%16, (nodedef.connect2 + 4 * noderot)%16, nodedef.rely1 or 0, nodedef.rely2 or 0, nodedef.railheight or 0
end