aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororwell96 <mono96.mml@gmail.com>2016-08-22 22:41:09 +0200
committerorwell96 <mono96.mml@gmail.com>2016-08-22 22:41:09 +0200
commit522a9ccd6818a14efe4886365e57b312d559d8db (patch)
treeee2ae877ea62944b8da34ccee0fe611a07d242d5
parent2593b1af1625f9cc3db879541f8425217646b652 (diff)
downloadadvtrains-522a9ccd6818a14efe4886365e57b312d559d8db.tar.gz
advtrains-522a9ccd6818a14efe4886365e57b312d559d8db.tar.bz2
advtrains-522a9ccd6818a14efe4886365e57b312d559d8db.zip
tidying up the tracks and trackworker/placer code and making rail registration a lot more modular
-rw-r--r--models/gleis/rail_my_rt_final_sw.blend1bin0 -> 824996 bytes
-rw-r--r--models/gleis/rail_my_rt_final_sw.blend11bin0 -> 843380 bytes
-rw-r--r--textures/advtrains_track_swlcr.png (renamed from textures/advtrains_track_swl_cr.png)bin33378 -> 33378 bytes
-rw-r--r--textures/advtrains_track_swlcr_45.png (renamed from textures/advtrains_track_swl_cr_45.png)bin45772 -> 45772 bytes
-rw-r--r--textures/advtrains_track_swlst.png (renamed from textures/advtrains_track_swl_st.png)bin32321 -> 32321 bytes
-rw-r--r--textures/advtrains_track_swlst_45.png (renamed from textures/advtrains_track_swl_st_45.png)bin46408 -> 46408 bytes
-rw-r--r--textures/advtrains_track_swrcr.png (renamed from textures/advtrains_track_swr_cr.png)bin33670 -> 33670 bytes
-rw-r--r--textures/advtrains_track_swrcr_45.png (renamed from textures/advtrains_track_swr_cr_45.png)bin46865 -> 46865 bytes
-rw-r--r--textures/advtrains_track_swrst.png (renamed from textures/advtrains_track_swr_st.png)bin32654 -> 32654 bytes
-rw-r--r--textures/advtrains_track_swrst_45.png (renamed from textures/advtrains_track_swr_st_45.png)bin47636 -> 47636 bytes
-rw-r--r--trackplacer.lua213
-rw-r--r--tracks.lua504
12 files changed, 336 insertions, 381 deletions
diff --git a/models/gleis/rail_my_rt_final_sw.blend1 b/models/gleis/rail_my_rt_final_sw.blend1
new file mode 100644
index 0000000..1d37fa7
--- /dev/null
+++ b/models/gleis/rail_my_rt_final_sw.blend1
Binary files differ
diff --git a/models/gleis/rail_my_rt_final_sw.blend11 b/models/gleis/rail_my_rt_final_sw.blend11
new file mode 100644
index 0000000..7372d51
--- /dev/null
+++ b/models/gleis/rail_my_rt_final_sw.blend11
Binary files differ
diff --git a/textures/advtrains_track_swl_cr.png b/textures/advtrains_track_swlcr.png
index d9b5c0b..d9b5c0b 100644
--- a/textures/advtrains_track_swl_cr.png
+++ b/textures/advtrains_track_swlcr.png
Binary files differ
diff --git a/textures/advtrains_track_swl_cr_45.png b/textures/advtrains_track_swlcr_45.png
index f098fc9..f098fc9 100644
--- a/textures/advtrains_track_swl_cr_45.png
+++ b/textures/advtrains_track_swlcr_45.png
Binary files differ
diff --git a/textures/advtrains_track_swl_st.png b/textures/advtrains_track_swlst.png
index 314bd2d..314bd2d 100644
--- a/textures/advtrains_track_swl_st.png
+++ b/textures/advtrains_track_swlst.png
Binary files differ
diff --git a/textures/advtrains_track_swl_st_45.png b/textures/advtrains_track_swlst_45.png
index 765d0ec..765d0ec 100644
--- a/textures/advtrains_track_swl_st_45.png
+++ b/textures/advtrains_track_swlst_45.png
Binary files differ
diff --git a/textures/advtrains_track_swr_cr.png b/textures/advtrains_track_swrcr.png
index f74e1bc..f74e1bc 100644
--- a/textures/advtrains_track_swr_cr.png
+++ b/textures/advtrains_track_swrcr.png
Binary files differ
diff --git a/textures/advtrains_track_swr_cr_45.png b/textures/advtrains_track_swrcr_45.png
index fa432aa..fa432aa 100644
--- a/textures/advtrains_track_swr_cr_45.png
+++ b/textures/advtrains_track_swrcr_45.png
Binary files differ
diff --git a/textures/advtrains_track_swr_st.png b/textures/advtrains_track_swrst.png
index 06ea29e..06ea29e 100644
--- a/textures/advtrains_track_swr_st.png
+++ b/textures/advtrains_track_swrst.png
Binary files differ
diff --git a/textures/advtrains_track_swr_st_45.png b/textures/advtrains_track_swrst_45.png
index be477b7..be477b7 100644
--- a/textures/advtrains_track_swr_st_45.png
+++ b/textures/advtrains_track_swrst_45.png
Binary files differ
diff --git a/trackplacer.lua b/trackplacer.lua
index e5b3f84..7f04f93 100644
--- a/trackplacer.lua
+++ b/trackplacer.lua
@@ -3,20 +3,47 @@
local print=function(t, ...) minetest.log("action", table.concat({t, ...}, " ")) minetest.chat_send_all(table.concat({t, ...}, " ")) end
---keys:conn1_conn2 (example:1_4)
---values:{name=x, param2=x}
-advtrains.trackplacer_dir_to_node_mapping={}
---keys are nodenames!
-advtrains.trackplacer_modified_rails={}
+--all new trackplacer code
+local tp={
+ tracks={}
+}
-function advtrains.trackplacer_register(nodename, conn1, conn2)
+function tp.register_tracktype(nnprefix, n_suffix)
+ tp.tracks[nnprefix]={
+ default=n_suffix,
+ single_conn={},
+ double_conn={},
+ --keys:conn1_conn2 (example:1_4)
+ --values:{name=x, param2=x}
+ twcycle={},
+ twrotate={},--indexed by suffix, list, tells order of rotations
+ modify={}
+ }
+end
+function tp.add_double_conn(nnprefix, suffix, rotation, conns)
+ local nodename=nnprefix.."_"..suffix..rotation
+ for i=0,3 do
+ tp.tracks[nnprefix].double_conn[((conns.conn1+4*i)%16).."_"..((conns.conn2+4*i)%16)]={name=nodename, param2=i}
+ tp.tracks[nnprefix].double_conn[((conns.conn2+4*i)%16).."_"..((conns.conn1+4*i)%16)]={name=nodename, param2=i}
+ end
+ tp.tracks[nnprefix].modify[nodename]=true
+end
+function tp.add_single_conn(nnprefix, suffix, rotation, conns)
+ local nodename=nnprefix.."_"..suffix..rotation
for i=0,3 do
- advtrains.trackplacer_dir_to_node_mapping[((conn1+2*i)%8).."_"..((conn2+2*i)%8)]={name=nodename, param2=i}
- advtrains.trackplacer_dir_to_node_mapping[((conn2+2*i)%8).."_"..((conn1+2*i)%8)]={name=nodename, param2=i}
+ tp.tracks[nnprefix].single_conn[((conns.conn1+4*i)%16)]={name=nodename, param2=i}
+ tp.tracks[nnprefix].single_conn[((conns.conn2+4*i)%16)]={name=nodename, param2=i}
end
- advtrains.trackplacer_modified_rails[nodename]=true
+ tp.tracks[nnprefix].modify[nodename]=true
end
-function advtrains.find_adjacent_tracks(pos)--TODO vertical calculations(check node below)
+
+function tp.add_worked(nnprefix, suffix, rotation, cycle_follows)
+ tp.tracks[nnprefix].twcycle[suffix]=cycle_follows
+ if not tp.tracks[nnprefix].twrotate[suffix] then tp.tracks[nnprefix].twrotate[suffix]={} end
+ table.insert(tp.tracks[nnprefix].twrotate[suffix], rotation)
+end
+
+function tp.find_adjacent_tracks(pos)--TODO vertical calculations(check node below)
local conn1=0
while conn1<16 and not advtrains.is_track_and_drives_on(minetest.get_node(advtrains.dirCoordSet(pos, conn1)).name, advtrains.all_tracktypes) do
conn1=conn1+1
@@ -33,89 +60,86 @@ function advtrains.find_adjacent_tracks(pos)--TODO vertical calculations(check n
end
return conn1, conn2
end
+function tp.find_already_connected(pos)--TODO vertical calculations(check node below)
+ local function istrackandbc(pos, conn)
+ local cnode=minetest.get_node(advtrains.dirCoordSet(pos, conn))
+ local bconn=(conn+8)%16
+ if advtrains.is_track_and_drives_on(cnode.name, advtrains.all_tracktypes) then
+ local cconn1, cconn2=advtrains.get_track_connections(cnode.name, cnode.param2)
+ return cconn1==bconn or cconn2==bconn
+ end
+ return false
+ end
+ local conn1=0
+ while conn1<16 and not istrackandbc(pos, conn1) do
+ conn1=conn1+1
+ end
+ if conn1>=16 then
+ return nil, nil
+ end
+ local conn2=0
+ while conn2<16 and not istrackandbc(pos, conn2) or conn2==conn1 do
+ conn2=conn2+1
+ end
+ if conn2>=16 then
+ return conn1, nil
+ end
+ return conn1, conn2
+end
-local modext={[0]="", "_30", "_45", "_60"}
-
-function advtrains.placetrack(pos, nnpref)
- local conn1, conn2=advtrains.find_adjacent_tracks(pos)
-
+function tp.placetrack(pos, nnpref)
+ local conn1, conn2=tp.find_adjacent_tracks(pos)
+ local tr=tp.tracks[nnpref]
if not conn1 and not conn2 then
- minetest.set_node(pos, {name=nnpref.."_st"})
+ minetest.set_node(pos, {name=nnpref.."_"..tr.default})
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+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+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+8)%16)] then
- minetest.set_node(advtrains.dirCoordSet(pos, conn1), advtrains.trackplacer_dir_to_node_mapping[node1_conn2.."_"..((conn1+8)%16)])
- end
- end
+ if tr.single_conn[conn1] then
+ tp.try_adjust_rail(tr, advtrains.dirCoordSet(pos, conn1), (conn1+8)%16)
+ minetest.set_node(pos, tr.single_conn[conn1])
+ else
+ minetest.set_node(pos, {name=nnpref.."_"..tr.default})
end
- --second end will be free. place standard rail
- local modulo=conn1%4
- minetest.set_node(pos, {name=nnpref.."_st"..modext[modulo], param2=(conn1-modulo)/4})
-
elseif conn1 and conn2 then
- if not advtrains.trackplacer_dir_to_node_mapping[conn1.."_"..conn2] then
- minetest.set_node(pos, {name=nnpref.."_st"})
- return
+ if tr.double_conn[conn1.."_"..conn2] then
+ tp.try_adjust_rail(tr, advtrains.dirCoordSet(pos, conn1), (conn1+8)%16)
+ tp.try_adjust_rail(tr, advtrains.dirCoordSet(pos, conn2), (conn1+8)%16)
+ minetest.set_node(pos, tr.double_conn[conn1.."_"..conn2])
+ elseif tr.single_conn[conn1] then --try at least one side
+ tp.try_adjust_rail(tr, advtrains.dirCoordSet(pos, conn1), (conn1+8)%16)
+ minetest.set_node(pos, tr.single_conn[conn1])
+ else
+ minetest.set_node(pos, {name=nnpref.."_"..tr.default})
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+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+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+8)%16)] then
- minetest.set_node(advtrains.dirCoordSet(pos, conn1), advtrains.trackplacer_dir_to_node_mapping[node1_conn2.."_"..((conn1+8)%16)])
- end
- end
+ end
+end
+function tp.try_adjust_rail(tr, pos, newdir)
+ --is rail already connected?
+ local node=minetest.get_node(pos)
+ local conn1, conn2=advtrains.get_track_connections(node.name, node.param2)
+ if newdir==conn1 or newdir==conn2 then
+ return
+ end
+ --rail at other end?
+ local adj1, adj2=tp.find_already_connected(pos)
+ if adj1 and adj2 then
+ return false--dont destroy existing track
+ elseif adj1 and not adj2 then
+ if tr.double_conn[adj1.."_"..newdir] then
+ minetest.set_node(pos, tr.double_conn[adj1.."_"..newdir])
+ return true--if exists, connect new rail and old 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+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+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+8)%16)] then
- minetest.set_node(advtrains.dirCoordSet(pos, conn2), advtrains.trackplacer_dir_to_node_mapping[node2_conn2.."_"..((conn2+8)%16)])
- end
- end
+ return false
+ else
+ if tr.single_conn[newdir] then--just rotate old rail to right orientation
+ minetest.set_node(pos, tr.single_conn[newdir])
+ return true
end
- minetest.set_node(pos, advtrains.trackplacer_dir_to_node_mapping[conn1.."_"..conn2])
+ return false
end
end
-advtrains.trackworker_cycle_nodes={
- ["swr_cr"]="st",
- ["swr_st"]="st",
- ["st"]="cr",
- ["cr"]="swl_st",
- ["swl_cr"]="swr_cr",
- ["swl_st"]="swr_st",
-}
-
-function advtrains.register_track_placer(nnprefix, imgprefix, dispname)
+function tp.register_track_placer(nnprefix, imgprefix, dispname)
minetest.register_craftitem(nnprefix.."_placer",{
description = dispname,
inventory_image = imgprefix.."_placer.png",
@@ -124,7 +148,7 @@ function advtrains.register_track_placer(nnprefix, imgprefix, dispname)
if pointed_thing.type=="node" then
local pos=pointed_thing.above
if minetest.registered_nodes[minetest.get_node(pos).name] and minetest.registered_nodes[minetest.get_node(pos).name].buildable_to then
- advtrains.placetrack(pos, nnprefix)
+ tp.placetrack(pos, nnprefix)
if not minetest.setting_getbool("creative_mode") then
itemstack:take_item()
end
@@ -150,14 +174,17 @@ minetest.register_craftitem("advtrains:trackworker",{
if not advtrains.is_track_and_drives_on(minetest.get_node(pos).name, advtrains.all_tracktypes) then return end
if advtrains.is_train_at_pos(pos) then return end
- local nodeprefix, railtype, rotation=string.match(node.name, "^([^_]+)_([^_]+)(_?.*)$")
+
+ local nnprefix, suffix, rotation=string.match(node.name, "^([^_]+)_([^_]+)(_?.*)$")
--print(node.name.."\npattern recognizes:"..nodeprefix.." / "..railtype.." / "..rotation)
- if not advtrains.trackworker_cycle_nodes[railtype] then
- print("[advtrains]rail not workable by trackworker")
+ if not tp.tracks[nnprefix] or not tp.tracks[nnprefix].twrotate[suffix] then
+ print("[advtrains]railtype not workable by trackworker")
return
end
+ local modext=tp.tracks[nnprefix].twrotate[suffix]
+
if rotation==modext[#modext] then --increase param2
- minetest.set_node(pos, {name=nodeprefix.."_"..railtype..modext[0], param2=(node.param2+1)%4})
+ minetest.set_node(pos, {name=nnprefix.."_"..suffix..modext[1], param2=(node.param2+1)%4})
return
else
local modpos
@@ -166,7 +193,7 @@ minetest.register_craftitem("advtrains:trackworker",{
print("[advtrains]rail not workable by trackworker")
return
end
- minetest.set_node(pos, {name=nodeprefix.."_"..railtype..modext[modpos+1], param2=node.param2})
+ minetest.set_node(pos, {name=nnprefix.."_"..suffix..modext[modpos+1], param2=node.param2})
end
advtrains.invalidate_all_paths()
end
@@ -178,15 +205,19 @@ minetest.register_craftitem("advtrains:trackworker",{
if not advtrains.is_track_and_drives_on(minetest.get_node(pos).name, advtrains.all_tracktypes) then return end
if advtrains.is_train_at_pos(pos) then return end
- local nodeprefix, railtype, rotation=string.match(node.name, "^([^_]+)_([^_]+)(_?.*)$")
+ local nnprefix, suffix, rotation=string.match(node.name, "^([^_]+)_([^_]+)(_?.*)$")
- if not advtrains.trackworker_cycle_nodes[railtype] then
- print("[advtrains]trackworker does not know what to set here...")
+ if not tp.tracks[nnprefix] or not tp.tracks[nnprefix].twcycle[suffix] then
+ print("[advtrains]railtype not workable by trackworker")
return
end
- minetest.set_node(pos, {name=nodeprefix.."_"..advtrains.trackworker_cycle_nodes[railtype]..rotation, param2=node.param2})
+ local nextsuffix=tp.tracks[nnprefix].twcycle[suffix]
+ minetest.set_node(pos, {name=nnprefix.."_"..nextsuffix..rotation, param2=node.param2})
--invalidate trains
advtrains.invalidate_all_paths()
end
end,
})
+
+--putting into right place
+advtrains.trackplacer=tp
diff --git a/tracks.lua b/tracks.lua
index 0f08e74..73d3033 100644
--- a/tracks.lua
+++ b/tracks.lua
@@ -26,7 +26,99 @@ vert2={
]]--
advtrains.all_tracktypes={}
-function advtrains.register_tracks(tracktype, def)
+--definition preparation
+local function conns(c1, c2, r1, r2, rh, rots) return {conn1=c1, conn2=c2, rely1=r1, rely2=r2, railheight=rh} end
+
+local t_30deg={
+ regstep=1,
+ variant={
+ st=conns(0,8),
+ cr=conns(0,7),
+ swlst=conns(0,8),
+ swlcr=conns(0,7),
+ swrst=conns(0,8),
+ swrcr=conns(0,9),
+ vst1=conns(8,0,0,0.5,0.25),
+ vst2=conns(8,0,0.5,1,0.75),
+ },
+ switch={
+ swlst="swlcr",
+ swlcr="swlst",
+ swrst="swrcr",
+ swrcr="swrst",
+ },
+ trackplacer={
+ st=true,
+ cr=true,
+ },
+ tpsingle={
+ st=true,
+ },
+ tpdefault="st",
+ trackworker={
+ ["swrcr"]="st",
+ ["swrst"]="st",
+ ["st"]="cr",
+ ["cr"]="swlst",
+ ["swlcr"]="swrcr",
+ ["swlst"]="swrst",
+ },
+ rotation={"", "_30", "_45", "_60"},
+ increativeinv={vst1=true, vst2=true}
+}
+local t_45deg={
+ regstep=2,
+ variant={
+ st=conns(0,8),
+ cr=conns(0,6),
+ swlst=conns(0,8),
+ swlcr=conns(0,6),
+ swrst=conns(0,8),
+ swrcr=conns(0,10),
+ vst1=conns(8,0,0,0.5,0.25),
+ vst2=conns(8,0,0.5,1,0.75),
+ },
+ switch={
+ swlst="swlcr",
+ swlcr="swlst",
+ swrst="swrcr",
+ swrcr="swrst",
+ },
+ trackplacer={
+ st=true,
+ cr=true,
+ },
+ tpsingle={
+ st=true,
+ },
+ tpdefault="st",
+ trackworker={
+ ["swrcr"]="st",
+ ["swrst"]="st",
+ ["st"]="cr",
+ ["cr"]="swlst",
+ ["swlcr"]="swrcr",
+ ["swlst"]="swrst",
+ },
+ rotation={"", "_45"},
+ increativeinv={vst1=true, vst2=true}
+}
+
+--definition format: ([] optional)
+--[[{
+ nodename_prefix
+ texture_prefix
+ [shared_texture]
+ models_prefix
+ models_suffix (with dot)
+ [shared_model]
+ formats={
+ st,cr,swlst,swlcr,swrst,swrcr,vst1,vst2
+ (each a table with indices 0-3, for if to register a rail with this 'rotation' table entry. nil is assumed as 'all', set {} to not register at all)
+ }
+ common={} change something on common rail appearance
+}]]
+function advtrains.register_tracks(tracktype, def, preset)
local function make_switchfunc(suffix_target)
return function(pos, node)
if advtrains.is_train_at_pos(pos) then return end
@@ -35,115 +127,33 @@ function advtrains.register_tracks(tracktype, def)
advtrains.reset_trackdb_position(pos)
end
end
- local function make_overdef(img_suffix, conn1, conn2, switchfunc)
+ local function make_overdef(img_suffix, conns, switchfunc)
return {
- tiles = {def.texture_prefix.."_"..img_suffix..".png"},
+ mesh = def.shared_model or (def.models_prefix.."_"..img_suffix..def.models_suffix),
+ tiles = {def.shared_texture or (def.texture_prefix.."_"..img_suffix..".png")},
inventory_image = def.texture_prefix.."_"..img_suffix..".png",
wield_image = def.texture_prefix.."_"..img_suffix..".png",
- connect1=conn1,
- connect2=conn2,
+ connect1=conns.conn1,
+ connect2=conns.conn2,
+ rely1=conns.rely1 or 0,
+ rely2=conns.rely2 or 0,
+ railheight=conns.railheight or 0,
on_rightclick=switchfunc,
}
end
- local common_def=advtrains.merge_tables({
- description = def.description,
- drawtype = "mesh",
- mesh = "trackplane.b3d",
- paramtype="light",
- paramtype2="facedir",
- walkable = false,
- selection_box = {
- type = "fixed",
- fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
- },
- groups = {
- attached_node=1,
- ["advtrains_track_"..tracktype]=1,
- dig_immediate=2,
- not_in_creative_inventory=1,
- },
- rely1=0,
- rely2=0,
- railheight=0,
- drop="advtrains:placetrack_"..tracktype,
- --on_rightclick=function(pos, node, clicker)
- -- minetest.set_node(pos, {name=node.name, param2=(node.param2+1)%4})
- --end
- can_dig=function(pos)
- return not advtrains.is_train_at_pos(pos)
- end,
- after_dig_node=function(pos)
- advtrains.invalidate_all_paths()
- advtrains.reset_trackdb_position(pos)
- end,
- after_place_node=function(pos)
- advtrains.reset_trackdb_position(pos)
- end,
- }, 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, 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, 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, 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, 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, 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, 8), {
- mesh = "trackvertical2.b3d",
- rely1=0.5,
- rely2=1,
- railheight=0.75,
- description = def.description.." (vertical track upper node)",
- },def.vert2 or {}))
-
- advtrains.register_track_placer(def.nodename_prefix, def.texture_prefix, def.description)
- table.insert(advtrains.all_tracktypes, tracktype)
-end
-
-function advtrains.register_tracks_finer(tracktype, def)
- local function make_switchfunc(suffix_target)
- return function(pos, node)
- if advtrains.is_train_at_pos(pos) then return end
- advtrains.invalidate_all_paths()
- minetest.set_node(pos, {name=def.nodename_prefix.."_"..suffix_target, param2=node.param2})
- advtrains.reset_trackdb_position(pos)
- end
- end
- local function make_overdef(img_suffix, conn1, conn2, switchfunc)
+ local function cycle_conns(conns, rotid)
+ local add=(rotid-1)*preset.regstep
return {
- tiles = {def.texture_prefix.."_"..img_suffix..".png"},
- inventory_image = def.texture_prefix.."_"..img_suffix..".png",
- wield_image = def.texture_prefix.."_"..img_suffix..".png",
- connect1=conn1,
- connect2=conn2,
- on_rightclick=switchfunc,
+ conn1=(conns.conn1+add)%16,
+ conn2=(conns.conn2+add)%16,
+ rely1=conns.rely1 or 0,
+ rely2=conns.rely2 or 0,
+ railheight=conns.railheight or 0,
}
end
local common_def=advtrains.merge_tables({
description = def.description,
drawtype = "mesh",
- mesh = "trackplane.b3d",
paramtype="light",
paramtype2="facedir",
walkable = false,
@@ -155,15 +165,12 @@ function advtrains.register_tracks_finer(tracktype, def)
attached_node=1,
["advtrains_track_"..tracktype]=1,
dig_immediate=2,
- --not_in_creative_inventory=1,
+ not_in_creative_inventory=1,--NOTE see below when changing groups
},
rely1=0,
rely2=0,
railheight=0,
drop="advtrains:placetrack_"..tracktype,
- --on_rightclick=function(pos, node, clicker)
- -- minetest.set_node(pos, {name=node.name, param2=(node.param2+1)%4})
- --end
can_dig=function(pos)
return not advtrains.is_train_at_pos(pos)
end,
@@ -175,200 +182,47 @@ function advtrains.register_tracks_finer(tracktype, def)
advtrains.reset_trackdb_position(pos)
end,
}, 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_30", advtrains.merge_tables(common_def, make_overdef("st_30", 1, 9), def.straight30 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.."_st_60", advtrains.merge_tables(common_def, make_overdef("st_60", 3, 11), def.straight60 or {}))
-
- minetest.register_node(def.nodename_prefix.."_cr", advtrains.merge_tables(common_def, make_overdef("cr", 0, 7), def.curve or {}))
- minetest.register_node(def.nodename_prefix.."_cr_30", advtrains.merge_tables(common_def, make_overdef("cr_30", 1, 8), def.curve45 or {}))
- minetest.register_node(def.nodename_prefix.."_cr_45", advtrains.merge_tables(common_def, make_overdef("cr_45", 2, 9), def.curve45 or {}))
- minetest.register_node(def.nodename_prefix.."_cr_60", advtrains.merge_tables(common_def, make_overdef("cr_60", 3, 10), def.curve45 or {}))
+ --make trackplacer base def
+ advtrains.trackplacer.register_tracktype(def.nodename_prefix, preset.tpdefault)
+ advtrains.trackplacer.register_track_placer(def.nodename_prefix, def.texture_prefix, def.description)
- --[[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, 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, 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, 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, 8), {
- mesh = "trackvertical2.b3d",
- rely1=0.5,
- rely2=1,
- railheight=0.75,
- description = def.description.." (vertical track upper node)",
- },def.vert2 or {}))
- ]]
-
- --we don't have texures yet
-
- advtrains.register_track_placer(def.nodename_prefix, def.texture_prefix, def.description)
- table.insert(advtrains.all_tracktypes, tracktype)
-end
-
---def must include: models_prefix, models_suffix(with dot)
--- def.shared_texture="full_name.png" if shared texture for all models is wanted
-function advtrains.register_tracks_modeled(tracktype, def)
- local function make_switchfunc(suffix_target)
- return function(pos, node)
- if advtrains.is_train_at_pos(pos) then return end
- advtrains.invalidate_all_paths()
- minetest.set_node(pos, {name=def.nodename_prefix.."_"..suffix_target, param2=node.param2})
- advtrains.reset_trackdb_position(pos)
+ for suffix, conns in pairs(preset.variant) do
+ for rotid, rotation in ipairs(preset.rotation) do
+ if not def.formats[suffix] or def.formats[suffix][rotid] then
+ local switchfunc
+ if preset.switch[suffix] then
+ switchfunc=make_switchfunc(preset.switch[suffix]..rotation)
+ end
+ minetest.register_node(def.nodename_prefix.."_"..suffix..rotation, advtrains.merge_tables(
+ common_def,
+ make_overdef(
+ suffix..rotation,
+ cycle_conns(conns, rotid),
+ switchfunc
+ )
+ ),
+ preset.increativeinv[suffix] and {
+ groups = {--NOTE change groups here too
+ attached_node=1,
+ ["advtrains_track_"..tracktype]=1,
+ dig_immediate=2,
+ },
+ } or {}
+ )
+ --trackplacer
+ if preset.trackplacer[suffix] then
+ advtrains.trackplacer.add_double_conn(def.nodename_prefix, suffix, rotation, cycle_conns(conns, rotid))
+ end
+ if preset.tpsingle[suffix] then
+ advtrains.trackplacer.add_single_conn(def.nodename_prefix, suffix, rotation, cycle_conns(conns, rotid))
+ end
+ advtrains.trackplacer.add_worked(def.nodename_prefix, suffix, rotation, preset.trackworker[suffix])
+ end
end
end
- local function make_overdef(img_suffix, conn1, conn2, switchfunc)
- return {
- mesh = def.models_prefix.."_"..img_suffix..def.models_suffix,
- tiles = {def.shared_texture or (def.texture_prefix.."_"..img_suffix..".png")},
- inventory_image = def.texture_prefix.."_"..img_suffix..".png",
- wield_image = def.texture_prefix.."_"..img_suffix..".png",
- connect1=conn1,
- connect2=conn2,
- on_rightclick=switchfunc,
- }
- end
- local common_def=advtrains.merge_tables({
- description = def.description,
- drawtype = "mesh",
- paramtype="light",
- paramtype2="facedir",
- walkable = false,
- selection_box = {
- type = "fixed",
- fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
- },
- groups = {
- attached_node=1,
- ["advtrains_track_"..tracktype]=1,
- dig_immediate=2,
- not_in_creative_inventory=1,
- },
- rely1=0,
- rely2=0,
- railheight=0,
- drop="advtrains:placetrack_"..tracktype,
- --on_rightclick=function(pos, node, clicker)
- -- minetest.set_node(pos, {name=node.name, param2=(node.param2+1)%4})
- --end
- can_dig=function(pos)
- return not advtrains.is_train_at_pos(pos)
- end,
- after_dig_node=function(pos)
- advtrains.invalidate_all_paths()
- advtrains.reset_trackdb_position(pos)
- end,
- after_place_node=function(pos)
- advtrains.reset_trackdb_position(pos)
- end,
- }, 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_30", advtrains.merge_tables(common_def, make_overdef("st_30", 1, 9), def.straight30 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.."_st_60", advtrains.merge_tables(common_def, make_overdef("st_60", 3, 11), def.straight60 or {}))
-
- minetest.register_node(def.nodename_prefix.."_cr", advtrains.merge_tables(common_def, make_overdef("cr", 0, 7), def.curve or {}))
- minetest.register_node(def.nodename_prefix.."_cr_30", advtrains.merge_tables(common_def, make_overdef("cr_30", 1, 8), def.curve30 or {}))
- minetest.register_node(def.nodename_prefix.."_cr_45", advtrains.merge_tables(common_def, make_overdef("cr_45", 2, 9), def.curve45 or {}))
- minetest.register_node(def.nodename_prefix.."_cr_60", advtrains.merge_tables(common_def, make_overdef("cr_60", 3, 10), def.curve60 or {}))
-
- minetest.register_node(def.nodename_prefix.."_vst1", advtrains.merge_tables(common_def, make_overdef("vst1", 8, 0),
- {
- rely1=0,
- rely2=0.5,
- railheight=0.25,
- },
- def.vst1 or {}))
- minetest.register_node(def.nodename_prefix.."_vst2", advtrains.merge_tables(common_def, make_overdef("vst2", 8, 0),
- {
- rely1=0.5,
- rely2=1,
- railheight=0.75,
- },
- def.vst2 or {}))
-
- advtrains.trackplacer_register(def.nodename_prefix.."_st", 0, 8)
- advtrains.trackplacer_register(def.nodename_prefix.."_st_30", 1, 9)
- advtrains.trackplacer_register(def.nodename_prefix.."_st_45", 2, 10)
- advtrains.trackplacer_register(def.nodename_prefix.."_st_60", 3, 11)
- advtrains.trackplacer_register(def.nodename_prefix.."_cr", 0, 7)
- advtrains.trackplacer_register(def.nodename_prefix.."_cr_30", 1, 8)
- advtrains.trackplacer_register(def.nodename_prefix.."_cr_45", 2, 9)
- advtrains.trackplacer_register(def.nodename_prefix.."_cr_60", 3, 10)
-
- --[[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, 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, 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, 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, 8), {
- mesh = "trackvertical2.b3d",
- rely1=0.5,
- rely2=1,
- railheight=0.75,
- description = def.description.." (vertical track upper node)",
- },def.vert2 or {}))
- ]]
-
- advtrains.register_track_placer(def.nodename_prefix, def.texture_prefix, def.description)
table.insert(advtrains.all_tracktypes, tracktype)
end
-advtrains.register_tracks("regular", {
- nodename_prefix="advtrains:track",
- texture_prefix="advtrains_track",
- description="Regular Train Track",
-})
-
-advtrains.register_tracks_finer("fineturns", {
- nodename_prefix="advtrains:olddtrack",
- texture_prefix="advtrains_dtrack",
- description="Fine Turn Train Track",
-})
-
-advtrains.register_tracks_modeled("default", {
- nodename_prefix="advtrains:dtrack",
- texture_prefix="advtrains_dtrack",
- models_prefix="advtrains_dtrack",
- models_suffix=".b3d",
- shared_texture="advtrains_dtrack_rail.png",
- description="New Default Train Track",
-})
function advtrains.is_track_and_drives_on(nodename, drives_on)
if not minetest.registered_nodes[nodename] then
@@ -393,6 +247,76 @@ function advtrains.get_track_connections(name, param2)
return (nodedef.connect1 + 4 * noderot)%16, (nodedef.connect2 + 4 * noderot)%16, nodedef.rely1 or 0, nodedef.rely2 or 0, nodedef.railheight or 0
end
+--END code, BEGIN definition
+--definition format: ([] optional)
+--[[{
+ nodename_prefix
+ texture_prefix
+ [shared_texture]
+ models_prefix
+ models_suffix (with dot)
+ [shared_model]
+ formats={
+ st,cr,swlst,swlcr,swrst,swrcr,vst1,vst2
+ (each a table with indices 0-3, for if to register a rail with this 'rotation' table entry. nil is assumed as 'all', set {} to not register at all)
+ }
+ common={} change something on common rail appearance
+}]]
+
+advtrains.register_tracks("regular", {
+ nodename_prefix="advtrains:track",
+ texture_prefix="advtrains_track",
+ shared_model="trackplane.b3d",
+ description="Regular Train Track",
+ formats={vst1={}, vst2={}},
+}, t_45deg)
+
+
+advtrains.register_tracks("default", {
+ nodename_prefix="advtrains:dtrack",
+ texture_prefix="advtrains_dtrack",
+ models_prefix="advtrains_dtrack",
+ models_suffix=".b3d",
+ shared_texture="advtrains_dtrack_rail.png",
+ description="New Default Train Track",
+ formats={vst1={true}, vst2={true}, swlcr={}, swlst={}, swrcr={}, swrst={}},
+}, t_30deg)
+
+--TODO legacy
+--I know lbms are better for this purpose
+for name,rep in pairs({swl_st="swlst", swr_st="swrst", swl_cr="swlcr", swr_cr="swrcr", }) do
+ minetest.register_abm({
+ -- In the following two fields, also group:groupname will work.
+ nodenames = {"advtrains:track_"..name},
+ interval = 1.0, -- Operation interval in seconds
+ chance = 1, -- Chance of trigger per-node per-interval is 1.0 / this
+ action = function(pos, node, active_object_count, active_object_count_wider) minetest.set_node(pos, {name="advtrains:track_"..rep, param2=node.param2}) end,
+ })
+ minetest.register_abm({
+ -- In the following two fields, also group:groupname will work.
+ nodenames = {"advtrains:track_"..name.."_45"},
+ interval = 1.0, -- Operation interval in seconds
+ chance = 1, -- Chance of trigger per-node per-interval is 1.0 / this
+ action = function(pos, node, active_object_count, active_object_count_wider) minetest.set_node(pos, {name="advtrains:track_"..rep.."_45", param2=node.param2}) end,
+ })
+end
+
+minetest.register_abm({
+-- In the following two fields, also group:groupname will work.
+ nodenames = {"advtrains:track_vert1"},
+ interval = 1.0, -- Operation interval in seconds
+ chance = 1, -- Chance of trigger per-node per-interval is 1.0 / this
+ action = function(pos, node, active_object_count, active_object_count_wider) minetest.set_node(pos, {name="advtrains:dtrack_vst1", param2=(node.param2+2)%4}) end,
+})
+minetest.register_abm({
+-- In the following two fields, also group:groupname will work.
+ nodenames = {"advtrains:track_vert2"},
+ interval = 1.0, -- Operation interval in seconds
+ chance = 1, -- Chance of trigger per-node per-interval is 1.0 / this
+ action = function(pos, node, active_object_count, active_object_count_wider) minetest.set_node(pos, {name="advtrains:dtrack_vst2", param2=(node.param2+2)%4}) end,
+})
+
+