aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororwell96 <mono96.mml@gmail.com>2017-01-08 21:10:02 +0100
committerorwell96 <mono96.mml@gmail.com>2017-01-08 21:10:02 +0100
commit0d2ec6f49a781f4539f934217ec8eb157f6a7796 (patch)
tree3bb12de6c0a9ae5f59aae409d8143219ff378c90
parenteae99812e95eb74d28a9f7d3ee20f792f7eb8c9e (diff)
Clean up debug message code
-rw-r--r--advtrains/advtrains/atc.lua4
-rw-r--r--advtrains/advtrains/helpers.lua29
-rw-r--r--advtrains/advtrains/init.lua34
-rw-r--r--advtrains/advtrains/misc_nodes.lua2
-rw-r--r--advtrains/advtrains/pseudoload.lua8
-rw-r--r--advtrains/advtrains/tracks.lua4
-rw-r--r--advtrains/advtrains/trainlogic.lua33
-rw-r--r--advtrains/advtrains/wagons.lua18
8 files changed, 82 insertions, 50 deletions
diff --git a/advtrains/advtrains/atc.lua b/advtrains/advtrains/atc.lua
index 2bc07be..bd02425 100644
--- a/advtrains/advtrains/atc.lua
+++ b/advtrains/advtrains/atc.lua
@@ -10,7 +10,7 @@ advtrains.fpath_atc=minetest.get_worldpath().."/advtrains_atc"
local file, err = io.open(advtrains.fpath_atc, "r")
if not file then
local er=err or "Unknown Error"
- atprint("[advtrains]Failed loading advtrains atc save file "..er)
+ atprint("Failed loading advtrains atc save file "..er)
else
local tbl = minetest.deserialize(file:read("*a"))
if type(tbl) == "table" then
@@ -22,7 +22,7 @@ function atc.save()
--leave space for more save data.
local datastr = minetest.serialize({controllers = atc.controllers})
if not datastr then
- minetest.log("error", "[advtrains] Failed to serialize trackdb data!")
+ minetest.log("error", " Failed to serialize trackdb data!")
return
end
local file, err = io.open(advtrains.fpath_atc, "w")
diff --git a/advtrains/advtrains/helpers.lua b/advtrains/advtrains/helpers.lua
index e29eaa5..cc7deb8 100644
--- a/advtrains/advtrains/helpers.lua
+++ b/advtrains/advtrains/helpers.lua
@@ -64,19 +64,19 @@ function advtrains.conway(midreal, prev, drives_on)--in order prev,mid,return
local next, chkdir, chkrely, y_offset
y_offset=0
- --atprint("[advtrains] in order mid1,mid2",middir1,middir2)
+ --atprint(" in order mid1,mid2",middir1,middir2)
--try if it is dir1
local cor1=advtrains.dirCoordSet(mid, middir2)--<<<<
if cor1.x==prev.x and cor1.z==prev.z then--this was previous
next=advtrains.dirCoordSet(mid, middir1)
if midrely1>=1 then
next.y=next.y+1
- --atprint("[advtrains]found midrely1 to be >=1: next is now "..(next and minetest.pos_to_string(next) or "nil"))
+ --atprint("found midrely1 to be >=1: next is now "..(next and minetest.pos_to_string(next) or "nil"))
y_offset=1
end
chkdir=middir1
chkrely=midrely1
- --atprint("[advtrains]dir2 applied next pos:",minetest.pos_to_string(next),"(chkdir is ",chkdir,")")
+ --atprint("dir2 applied next pos:",minetest.pos_to_string(next),"(chkdir is ",chkdir,")")
end
--dir2???
local cor2=advtrains.dirCoordSet(mid, middir1)--<<<<
@@ -84,17 +84,17 @@ function advtrains.conway(midreal, prev, drives_on)--in order prev,mid,return
next=advtrains.dirCoordSet(mid, middir2)--dir2 wird überprüft, alles gut.
if midrely2>=1 then
next.y=next.y+1
- --atprint("[advtrains]found midrely2 to be >=1: next is now "..(next and minetest.pos_to_string(next) or "nil"))
+ --atprint("found midrely2 to be >=1: next is now "..(next and minetest.pos_to_string(next) or "nil"))
y_offset=1
end
chkdir=middir2
chkrely=midrely2
- --atprint("[advtrains] dir2 applied next pos:",minetest.pos_to_string(next),"(chkdir is ",chkdir,")")
+ --atprint(" dir2 applied next pos:",minetest.pos_to_string(next),"(chkdir is ",chkdir,")")
end
- --atprint("[advtrains]dir applied next pos: "..(next and minetest.pos_to_string(next) or "nil").."(chkdir is "..(chkdir or "nil")..", y-offset "..y_offset..")")
+ --atprint("dir applied next pos: "..(next and minetest.pos_to_string(next) or "nil").."(chkdir is "..(chkdir or "nil")..", y-offset "..y_offset..")")
--is there a next
if not next then
- atprint("[advtrains]in conway: no next rail(nil), returning!")
+ atprint("in conway: no next rail(nil), returning!")
return nil
end
@@ -102,36 +102,36 @@ function advtrains.conway(midreal, prev, drives_on)--in order prev,mid,return
--is it a rail?
if(not nextnode_ok) then
- atprint("[advtrains]in conway: next "..minetest.pos_to_string(next).." not a rail, trying one node below!")
+ atprint("in conway: next "..minetest.pos_to_string(next).." not a rail, trying one node below!")
next.y=next.y-1
y_offset=y_offset-1
nextnode_ok, nextdir1, nextdir2, nextrely1, nextrely2, nextrailheight=advtrains.get_rail_info_at(advtrains.round_vector_floor_y(next), drives_on)
if(not nextnode_ok) then
- atprint("[advtrains]in conway: one below "..minetest.pos_to_string(next).." is not a rail either, returning!")
+ atprint("in conway: one below "..minetest.pos_to_string(next).." is not a rail either, returning!")
return nil
end
end
--is this next rail connecting to the mid?
if not ( (((nextdir1+8)%16)==chkdir and nextrely1==chkrely-y_offset) or (((nextdir2+8)%16)==chkdir and nextrely2==chkrely-y_offset) ) then
- atprint("[advtrains]in conway: next "..minetest.pos_to_string(next).." not connecting, trying one node below!")
+ atprint("in conway: next "..minetest.pos_to_string(next).." not connecting, trying one node below!")
next.y=next.y-1
y_offset=y_offset-1
nextnode_ok, nextdir1, nextdir2, nextrely1, nextrely2, nextrailheight=advtrains.get_rail_info_at(advtrains.round_vector_floor_y(next), drives_on)
if(not nextnode_ok) then
- atprint("[advtrains]in conway: (at connecting if check again) one below "..minetest.pos_to_string(next).." is not a rail either, returning!")
+ atprint("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+8)%16)==chkdir and nextrely1==chkrely) or (((nextdir2+8)%16)==chkdir and nextrely2==chkrely) ) then
- atprint("[advtrains]in conway: one below "..minetest.pos_to_string(next).." rail not connecting, returning!")
- atprint("[advtrains] in order mid1,2,next1,2,chkdir "..middir1.." "..middir2.." "..nextdir1.." "..nextdir2.." "..chkdir)
+ atprint("in conway: one below "..minetest.pos_to_string(next).." rail not connecting, returning!")
+ atprint(" in order mid1,2,next1,2,chkdir "..middir1.." "..middir2.." "..nextdir1.." "..nextdir2.." "..chkdir)
return nil
end
end
- --atprint("[advtrains]conway found rail.")
+ --atprint("conway found rail.")
return vector.add(advtrains.round_vector_floor_y(next), {x=0, y=nextrailheight, z=0}), chkdir
end
--TODO use this
@@ -241,3 +241,4 @@ function advtrains.deserialize_inventory(sers, inv)
end
return false
end
+
diff --git a/advtrains/advtrains/init.lua b/advtrains/advtrains/init.lua
index ce3cc9f..03ec553 100644
--- a/advtrains/advtrains/init.lua
+++ b/advtrains/advtrains/init.lua
@@ -4,8 +4,38 @@ advtrains={}
advtrains.modpath = minetest.get_modpath("advtrains")
-atprint=function() end
---atprint=function(t, ...) minetest.log("action", table.concat({t, ...}, " ")) minetest.chat_send_all(table.concat({t, ...}, " ")) end
+local function print_concat_table(a)
+ local str=""
+ local stra=""
+ for i=1,50 do
+ t=a[i]
+ if t==nil then
+ stra=stra.."nil "
+ else
+ str=str..stra
+ stra=""
+ if type(t)=="table" then
+ if t.x and t.y and t.z then
+ str=str..minetest.pos_to_string(t)
+ else
+ str=str..dump(t)
+ end
+ elseif type(t)=="boolean" then
+ if t then
+ str=str.."true"
+ else
+ str=str.."false"
+ end
+ else
+ str=str..t
+ end
+ str=str.." "
+ end
+ end
+ return str
+end
+--atprint=function() end
+atprint=function(t, ...) minetest.log("action", "[advtrains]"..print_concat_table({t, ...})) minetest.chat_send_all("[advtrains]"..print_concat_table({t, ...})) end
sid=function(id) return string.sub(id, -4) end
dofile(advtrains.modpath.."/helpers.lua");
diff --git a/advtrains/advtrains/misc_nodes.lua b/advtrains/advtrains/misc_nodes.lua
index 93829f0..70b18fb 100644
--- a/advtrains/advtrains/misc_nodes.lua
+++ b/advtrains/advtrains/misc_nodes.lua
@@ -3,7 +3,7 @@
function advtrains.register_platform(preset)
local ndef=minetest.registered_nodes[preset]
if not ndef then
- minetest.log("warning", "[advtrains] register_platform couldn't find preset node "..preset)
+ minetest.log("warning", " register_platform couldn't find preset node "..preset)
return
end
local btex=ndef.tiles
diff --git a/advtrains/advtrains/pseudoload.lua b/advtrains/advtrains/pseudoload.lua
index 0636d2e..5cbd2c6 100644
--- a/advtrains/advtrains/pseudoload.lua
+++ b/advtrains/advtrains/pseudoload.lua
@@ -20,7 +20,7 @@ for tt, _ in pairs(advtrains.all_traintypes) do
local file, err = io.open(pl_fpath, "r")
if not file then
local er=err or "Unknown Error"
- atprint("[advtrains]Failed loading advtrains trackdb save file "..er)
+ atprint("Failed loading advtrains trackdb save file "..er)
else
--custom format to save memory
while true do
@@ -74,7 +74,7 @@ function advtrains.save_trackdb()
local file, err = io.open(pl_fpath, "w")
if not file then
local er=err or "Unknown Error"
- atprint("[advtrains]Failed saving advtrains trackdb save file "..er)
+ atprint("Failed saving advtrains trackdb save file "..er)
else
--custom format to save memory
for y,tyl in pairs(advtrains.trackdb[tt]) do
@@ -103,7 +103,7 @@ advtrains.fpath_tdb=minetest.get_worldpath().."/advtrains_trackdb2"
local file, err = io.open(advtrains.fpath_tdb, "r")
if not file then
local er=err or "Unknown Error"
- atprint("[advtrains]Failed loading advtrains save file "..er)
+ atprint("Failed loading advtrains save file "..er)
else
local tbl = minetest.deserialize(file:read("*a"))
if type(tbl) == "table" then
@@ -114,7 +114,7 @@ end
function advtrains.save_trackdb()
local datastr = minetest.serialize(advtrains.trackdb)
if not datastr then
- minetest.log("error", "[advtrains] Failed to serialize trackdb data!")
+ minetest.log("error", " Failed to serialize trackdb data!")
return
end
local file, err = io.open(advtrains.fpath_tdb, "w")
diff --git a/advtrains/advtrains/tracks.lua b/advtrains/advtrains/tracks.lua
index 53f5ce7..9fc3a56 100644
--- a/advtrains/advtrains/tracks.lua
+++ b/advtrains/advtrains/tracks.lua
@@ -370,10 +370,10 @@ end
function advtrains.get_track_connections(name, param2)
local nodedef=minetest.registered_nodes[name]
- if not nodedef then atprint("[advtrains] get_track_connections couldn't find nodedef for nodename "..(name or "nil")) return 0, 8, 0, 0, 0 end
+ if not nodedef then atprint(" 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 atprint("[advtrains] get_track_connections: rail has invaild param2 of "..noderot) noderot=0 end
+ if noderot > 3 then atprint(" get_track_connections: rail has invaild param2 of "..noderot) noderot=0 end
local tracktype
for k,_ in pairs(nodedef.groups) do
diff --git a/advtrains/advtrains/trainlogic.lua b/advtrains/advtrains/trainlogic.lua
index ac870c0..07a48cc 100644
--- a/advtrains/advtrains/trainlogic.lua
+++ b/advtrains/advtrains/trainlogic.lua
@@ -47,7 +47,7 @@ advtrains.fpath=minetest.get_worldpath().."/advtrains"
local file, err = io.open(advtrains.fpath, "r")
if not file then
local er=err or "Unknown Error"
- atprint("[advtrains]Failed loading advtrains save file "..er)
+ atprint("Failed loading advtrains save file "..er)
else
local tbl = minetest.deserialize(file:read("*a"))
if type(tbl) == "table" then
@@ -59,7 +59,7 @@ advtrains.fpath_ws=minetest.get_worldpath().."/advtrains_wagon_save"
local file, err = io.open(advtrains.fpath_ws, "r")
if not file then
local er=err or "Unknown Error"
- atprint("[advtrains]Failed loading advtrains save file "..er)
+ atprint("Failed loading advtrains save file "..er)
else
local tbl = minetest.deserialize(file:read("*a"))
if type(tbl) == "table" then
@@ -70,11 +70,11 @@ end
advtrains.save = function()
- atprint("[advtrains]saving")
+ atprint("saving")
advtrains.invalidate_all_paths()
local datastr = minetest.serialize(advtrains.trains)
if not datastr then
- minetest.log("error", "[advtrains] Failed to serialize train data!")
+ minetest.log("error", " Failed to serialize train data!")
return
end
local file, err = io.open(advtrains.fpath, "w")
@@ -108,7 +108,7 @@ advtrains.save = function()
--atprint(dump(advtrains.wagon_save))
datastr = minetest.serialize(advtrains.wagon_save)
if not datastr then
- minetest.log("error", "[advtrains] Failed to serialize train data!")
+ minetest.log("error", " Failed to serialize train data!")
return
end
file, err = io.open(advtrains.fpath_ws, "w")
@@ -236,7 +236,7 @@ function advtrains.train_step(id, train, dtime)
--remove?
if #train.trainparts==0 then
- atprint("[advtrains][train "..sid(id).."] has empty trainparts, removing.")
+ atprint("[train "..sid(id).."] has empty trainparts, removing.")
advtrains.detector.leave_node(path[train.detector_old_index], id)
advtrains.trains[id]=nil
return
@@ -284,7 +284,7 @@ function advtrains.train_step(id, train, dtime)
local node_range=(math.max((minetest.setting_get("active_block_range") or 0),1)*16)
if train.check_trainpartload<=0 then
local ori_pos=advtrains.get_real_index_position(path, train.index) --not much to calculate
- --atprint("[advtrains][train "..id.."] at "..minetest.pos_to_string(vector.round(ori_pos)))
+ --atprint("[train "..id.."] at "..minetest.pos_to_string(vector.round(ori_pos)))
local should_check=false
for _,p in ipairs(minetest.get_connected_players()) do
@@ -417,7 +417,7 @@ function advtrains.pathpredict(id, train)
if not train.path or #train.path<2 then
if not train.last_pos then
--no chance to recover
- atprint("[advtrains]train hasn't saved last-pos, removing train.")
+ atprint("train hasn't saved last-pos, removing train.")
advtrains.train[id]=nil
return false
end
@@ -426,17 +426,17 @@ function advtrains.pathpredict(id, train)
if node_ok==nil then
--block not loaded, do nothing
- atprint("[advtrains]last_pos not available")
+ atprint("last_pos not available")
return nil
elseif node_ok==false then
- atprint("[advtrains]no track here, (fail) removing train.")
+ atprint("no track here, (fail) removing train.")
advtrains.trains[id]=nil
return false
end
if not train.last_pos_prev then
--no chance to recover
- atprint("[advtrains]train hasn't saved last-pos_prev, removing train.")
+ atprint("train hasn't saved last-pos_prev, removing train.")
advtrains.trains[id]=nil
return false
end
@@ -445,10 +445,10 @@ function advtrains.pathpredict(id, train)
if prevnode_ok==nil then
--block not loaded, do nothing
- atprint("[advtrains]prev not available")
+ atprint("prev not available")
return nil
elseif prevnode_ok==false then
- atprint("[advtrains]no track at prev, (fail) removing train.")
+ atprint("no track at prev, (fail) removing train.")
advtrains.trains[id]=nil
return false
end
@@ -476,7 +476,7 @@ function advtrains.pathpredict(id, train)
local maxn=train.max_index_on_track or 0
while (maxn-train.index) < pregen_front do--pregenerate
- --atprint("[advtrains]maxn conway for ",maxn,minetest.pos_to_string(path[maxn]),maxn-1,minetest.pos_to_string(path[maxn-1]))
+ --atprint("maxn conway for ",maxn,minetest.pos_to_string(path[maxn]),maxn-1,minetest.pos_to_string(path[maxn-1]))
local conway=advtrains.conway(train.path[maxn], train.path[maxn-1], train.drives_on)
if conway then
train.path[maxn+1]=conway
@@ -493,7 +493,7 @@ function advtrains.pathpredict(id, train)
local minn=train.min_index_on_track or 0
while (train.index-minn) < (train.trainlen or 0) + pregen_back do --post_generate. has to be at least trainlen. (we let go of the exact calculation here since this would be unuseful here)
- --atprint("[advtrains]minn conway for ",minn,minetest.pos_to_string(path[minn]),minn+1,minetest.pos_to_string(path[minn+1]))
+ --atprint("minn conway for ",minn,minetest.pos_to_string(path[minn]),minn+1,minetest.pos_to_string(path[minn+1]))
local conway=advtrains.conway(train.path[minn], train.path[minn+1], train.drives_on)
if conway then
train.path[minn-1]=conway
@@ -558,10 +558,11 @@ function advtrains.update_trainpart_properties(train_id, invert_flipstate)
local count_l=0
for i, w_id in ipairs(train.trainparts) do
local wagon=nil
- for _,iwagon in pairs(minetest.luaentities) do
+ for aoid,iwagon in pairs(minetest.luaentities) do
if iwagon.is_wagon and iwagon.initialized and iwagon.unique_id==w_id then
if wagon then
--duplicate
+ atprint("update_trainpart_properties: Removing duplicate wagon with id="..aoid)
iwagon.object:remove()
else
wagon=iwagon
diff --git a/advtrains/advtrains/wagons.lua b/advtrains/advtrains/wagons.lua
index 8c3cd0a..bedffda 100644
--- a/advtrains/advtrains/wagons.lua
+++ b/advtrains/advtrains/wagons.lua
@@ -47,7 +47,7 @@ end
wagon will save only uid in staticdata, no serialized table
]]
function wagon:on_activate(sd_uid, dtime_s)
- atprint("[advtrains][wagon "..((sd_uid and sd_uid~="" and sd_uid) or "no-id").."] activated")
+ atprint("[wagon "..((sd_uid and sd_uid~="" and sd_uid) or "no-id").."] activated")
self.object:set_armor_groups({immortal=1})
if sd_uid and sd_uid~="" then
--legacy
@@ -63,7 +63,7 @@ function wagon:on_activate(sd_uid, dtime_s)
--duplicates?
for ao_id,wagon in pairs(minetest.luaentities) do
if wagon.is_wagon and wagon.initialized and wagon.unique_id==self.unique_id and wagon~=self then--i am a duplicate!
- atprint("[advtrains][wagon "..((sd_uid and sd_uid~="" and sd_uid) or "no-id").."] duplicate found(ao_id:"..ao_id.."), removing")
+ atprint("[wagon "..((sd_uid and sd_uid~="" and sd_uid) or "no-id").."] duplicate found(ao_id:"..ao_id.."), removing")
self.object:remove()
minetest.after(0.5, function() advtrains.update_trainpart_properties(self.train_id) end)
return
@@ -77,7 +77,7 @@ end
function wagon:get_staticdata()
if not self:ensure_init() then return end
- atprint("[advtrains][wagon "..((self.unique_id and self.unique_id~="" and self.unique_id) or "no-id").."]: saving to wagon_save")
+ atprint("[wagon "..((self.unique_id and self.unique_id~="" and self.unique_id) or "no-id").."]: saving to wagon_save")
--serialize inventory, if it has one
if self.has_inventory then
local inv=minetest.get_inventory({type="detached", name="advtrains_wgn_"..self.unique_id})
@@ -209,7 +209,7 @@ function wagon:destroy()
self.custom_on_destroy(self, puncher, time_from_last_punch, tool_capabilities, direction)
end
- atprint("[advtrains][wagon "..((self.unique_id and self.unique_id~="" and self.unique_id) or "no-id").."]: destroying")
+ atprint("[wagon "..((self.unique_id and self.unique_id~="" and self.unique_id) or "no-id").."]: destroying")
self.object:remove()
@@ -236,7 +236,7 @@ function wagon:on_step(dtime)
--is my train still here
if not self.train_id or not self:train() then
- atprint("[advtrains][wagon "..self.unique_id.."] missing train_id, destroying")
+ atprint("[wagon "..self.unique_id.."] missing train_id, destroying")
self.object:remove()
return
elseif not self.initialized then
@@ -317,7 +317,7 @@ function wagon:on_step(dtime)
local first_pos=gp.path[math.floor(index)]
local second_pos=gp.path[math.floor(index)+1]
if not first_pos or not second_pos then
- --atprint("[advtrains] object "..self.unique_id.." path end reached!")
+ --atprint(" object "..self.unique_id.." path end reached!")
self.object:setvelocity({x=0,y=0,z=0})
return
end
@@ -533,10 +533,10 @@ function advtrains.register_wagon(sysname, prototype, desc, inv_img)
end
local node=minetest.env:get_node_or_nil(pointed_thing.under)
- if not node then atprint("[advtrains]Ignore at placer position") return itemstack end
+ if not node then atprint("Ignore at placer position") return itemstack end
local nodename=node.name
if(not advtrains.is_track_and_drives_on(nodename, prototype.drives_on)) then
- atprint("[advtrains]no track here, not placing.")
+ atprint("no track here, not placing.")
return itemstack
end
local conn1=advtrains.get_track_connections(node.name, node.param2)
@@ -544,7 +544,7 @@ function advtrains.register_wagon(sysname, prototype, desc, inv_img)
local ob=minetest.env:add_entity(pointed_thing.under, "advtrains:"..sysname)
if not ob then
- atprint("[advtrains]couldn't add_entity, aborting")
+ atprint("couldn't add_entity, aborting")
end
local le=ob:get_luaentity()
>, } }, regtp=true, tpdefault="l", rotation={"", "_30", "_45", "_60"}, } advtrains.ap.t_s3way={ regstep=1, variant={ l={ conns = { {c=0}, {c=7}, {c=8}, {c=9}, {c=0} }, desc = "3-way turnout (left)", switchalt = "s", switchst="l", switchprefix = "", }, s={ conns = { {c=0}, {c=8}, {c=7}, {c=9}, {c=0} }, desc = "3-way turnout (straight)", switchalt ="r", switchst = "s", switchprefix = "", }, r={ conns = { {c=0}, {c=9}, {c=8}, {c=7}, {c=0} }, desc = "3-way turnout (right)", switchalt = "l", switchst="r", switchprefix = "", } }, regtp=true, tpdefault="l", rotation={"", "_30", "_45", "_60"}, } advtrains.ap.t_30deg_slope={ regstep=1, variant={ vst1={conns = conns(8,0,0,0.5), rail_y = 0.25, desc = "steep uphill 1/2", slope=true}, vst2={conns = conns(8,0,0.5,1), rail_y = 0.75, desc = "steep uphill 2/2", slope=true}, vst31={conns = conns(8,0,0,0.33), rail_y = 0.16, desc = "uphill 1/3", slope=true}, vst32={conns = conns(8,0,0.33,0.66), rail_y = 0.5, desc = "uphill 2/3", slope=true}, vst33={conns = conns(8,0,0.66,1), rail_y = 0.83, desc = "uphill 3/3", slope=true}, }, regsp=true, slopeplacer={ [2]={"vst1", "vst2"}, [3]={"vst31", "vst32", "vst33"}, max=3,--highest entry }, slopeplacer_45={ [2]={"vst1_45", "vst2_45"}, max=2, }, rotation={"", "_30", "_45", "_60"}, trackworker={}, increativeinv={}, } advtrains.ap.t_30deg_straightonly={ regstep=1, variant={ st={ conns = conns(0,8), desc = "straight", tpdouble = true, tpsingle = true, trackworker = "st", }, }, regtp=true, tpdefault="st", rotation={"", "_30", "_45", "_60"}, } advtrains.ap.t_30deg_straightonly_noplacer={ regstep=1, variant={ st={ conns = conns(0,8), desc = "straight", tpdouble = true, tpsingle = true, trackworker = "st", }, }, tpdefault="st", rotation={"", "_30", "_45", "_60"}, } advtrains.ap.t_45deg={ regstep=2, variant={ st={ conns = conns(0,8), desc = "straight", tpdouble = true, tpsingle = true, trackworker = "cr", }, cr={ conns = conns(0,6), desc = "curve", tpdouble = true, trackworker = "swlst", }, swlst={ conns = conns3(0,8,6), desc = "left switch (straight)", trackworker = "swrst", switchalt = "cr", switchmc = "on", switchst = "st", }, swlcr={ conns = conns3(0,6,8), desc = "left switch (curve)", trackworker = "swrcr", switchalt = "st", switchmc = "off", switchst = "cr", }, swrst={ conns = conns3(0,8,10), desc = "right switch (straight)", trackworker = "st", switchalt = "cr", switchmc = "on", switchst = "st", }, swrcr={ conns = conns3(0,10,8), desc = "right switch (curve)", trackworker = "st", switchalt = "st", switchmc = "off", switchst = "cr", }, }, regtp=true, tpdefault="st", trackworker={ ["swrcr"]="st", ["swrst"]="st", ["cr"]="swlst", ["swlcr"]="swrcr", ["swlst"]="swrst", }, rotation={"", "_30", "_45", "_60"}, } advtrains.ap.t_perpcrossing={ regstep = 1, variant={ st={ conns = { {c=0}, {c=8}, {c=4}, {c=12} }, desc = "perpendicular crossing", tpdouble = true, tpsingle = true, trackworker = "st", }, }, regtp=true, tpdefault="st", rotation={"", "_30", "_45", "_60"}, } advtrains.ap.t_90plusx_crossing={ regstep = 1, variant={ ["30l"]={ conns = { {c=0}, {c=8}, {c=1}, {c=9} }, desc = "30/90 degree crossing (left)", tpdouble = true, tpsingle = true, trackworker = "45l" }, ["45l"]={ conns = { {c=0}, {c=8}, {c=2}, {c=10} }, desc = "45/90 degree crossing (left)", tpdouble = true, tpsingle = true, trackworker = "60l", }, ["60l"]={ conns = { {c=0}, {c=8}, {c=3}, {c=11}}, desc = "60/90 degree crossing (left)", tpdouble = true, tpsingle = true, trackworker = "60r", }, ["60r"]={ conns = { {c=0}, {c=8}, {c=5}, {c=13} }, desc = "60/90 degree crossing (right)", tpdouble = true, tpsingle = true, trackworker = "45r" }, ["45r"]={ conns = { {c=0}, {c=8}, {c=6}, {c=14} }, desc = "45/90 degree crossing (right)", tpdouble = true, tpsingle = true, trackworker = "30r", }, ["30r"]={ conns = { {c=0}, {c=8}, {c=7}, {c=15}}, desc = "30/90 degree crossing (right)", tpdouble = true, tpsingle = true, trackworker = "30l", }, }, regtp=true, tpdefault="30l", rotation={""}, trackworker = { ["30l"] = "45l", ["45l"] = "60l", ["60l"] = "60r", ["60r"] = "45r", ["45r"] = "30r", ["30r"] = "30l", } } advtrains.ap.t_diagonalcrossing = { regstep=1, variant={ ["30l45r"]={ conns = {{c=1}, {c=9}, {c=6}, {c=14}}, desc = "30left-45right diagonal crossing", tpdouble=true, tpsingle=true, trackworker="60l30l", }, ["60l30l"]={ conns = {{c=3}, {c=11}, {c=1}, {c=9}}, desc = "30left-60right diagonal crossing", tpdouble=true, tpsingle=true, trackworker="60l45r" }, ["60l45r"]={ conns = {{c=3}, {c=11}, {c=6}, {c=14}}, desc = "60left-45right diagonal crossing", tpdouble=true, tpsingle=true, trackworker="60l60r" }, ["60l60r"]={ conns = {{c=3}, {c=11}, {c=5}, {c=13}}, desc = "60left-60right diagonal crossing", tpdouble=true, tpsingle=true, trackworker="60r45l", }, --If 60l60r had a mirror image, it would be here, but it's symmetric. -- 60l60r is also equivalent to 30l30r but rotated 90 degrees. ["60r45l"]={ conns = {{c=5}, {c=13}, {c=2}, {c=10}}, desc = "60right-45left diagonal crossing", tpdouble=true, tpsingle=true, trackworker="60r30r", }, ["60r30r"]={ conns = {{c=5}, {c=13}, {c=7}, {c=15}}, desc = "60right-30right diagonal crossing", tpdouble=true, tpsingle=true, trackworker="30r45l", }, ["30r45l"]={ conns = {{c=7}, {c=15}, {c=2}, {c=10}}, desc = "30right-45left diagonal crossing", tpdouble=true, tpsingle=true, trackworker="30l45r", }, }, regtp=true, tpdefault="30l45r", rotation={""}, trackworker = { ["30l45r"] = "60l30l", ["60l30l"] = "60l45r", ["60l45r"] = "60l60r", ["60l60r"] = "60r45l", ["60r45l"] = "60r30r", ["60r30r"] = "30r45l", ["30r45l"] = "30l45r", } } advtrains.trackpresets = advtrains.ap --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 } [18.12.17] Note on new connection system: In order to support real rail crossing nodes and finally make the trackplacer respect switches, I changed the connection system. There can be a variable number of connections available. These are specified as tuples {c=<connection>, y=<rely>} The table "at_conns" consists of {<conn1>, <conn2>...} the "at_rail_y" property holds the value that was previously called "railheight" Depending on the number of connections: 2 conns: regular rail 3 conns: switch: - when train passes in at conn1, will move out of conn2 - when train passes in at conn2 or conn3, will move out of conn1 4 conns: cross (or cross switch, depending on arrangement of conns): - conn1 <> conn2 - conn3 <> conn4 ]] -- Notify the user if digging the rail is not allowed local function can_dig_callback(pos, player) local ok, reason = advtrains.can_dig_or_modify_track(pos) if not ok and player then minetest.chat_send_player(player:get_player_name(), attrans("This track can not be removed!") .. " " .. reason) end return ok end function advtrains.register_tracks(tracktype, def, preset) advtrains.trackplacer.register_tracktype(def.nodename_prefix, preset.tpdefault) if preset.regtp then advtrains.trackplacer.register_track_placer(def.nodename_prefix, def.texture_prefix, def.description, def) end if preset.regsp then advtrains.slope.register_placer(def, preset) end for suffix, var 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 img_suffix = suffix..rotation local ndef = advtrains.merge_tables({ description=def.description.."("..(var.desc or "any")..rotation..")", drawtype = "mesh", paramtype="light", paramtype2="facedir", use_texture_alpha = "blend", walkable = false, selection_box = { type = "fixed", fixed = {-1/2-1/16, -1/2, -1/2, 1/2+1/16, -1/2+2/16, 1/2}, }, mesh = def.shared_model or (def.models_prefix.."_"..img_suffix..def.models_suffix), tiles = {def.shared_texture or (def.texture_prefix.."_"..img_suffix..".png"), def.second_texture}, groups = { attached_node = advtrains.IGNORE_WORLD and 0 or 1, advtrains_track=1, ["advtrains_track_"..tracktype]=1, save_in_at_nodedb=1, dig_immediate=2, not_in_creative_inventory=1, not_blocking_trains=1, }, can_dig = can_dig_callback, after_dig_node=function(pos) advtrains.ndb.update(pos) end, after_place_node=function(pos) advtrains.ndb.update(pos) end, at_nnpref = def.nodename_prefix, at_suffix = suffix, at_rotation = rotation, at_rail_y = var.rail_y }, def.common or {}) if preset.regtp then ndef.drop = def.nodename_prefix.."_placer" end if preset.regsp and var.slope then ndef.drop = def.nodename_prefix.."_slopeplacer" end --connections ndef.at_conns = advtrains.rotate_conn_by(var.conns, (rotid-1)*preset.regstep) local ndef_avt_table if var.switchalt and var.switchst then local switchfunc=function(pos, node, newstate) newstate = newstate or var.switchalt -- support for 3 (or more) state switches -- this code is only called from the internal setstate function, which -- ensures that it is safe to switch the turnout if newstate~=var.switchst then advtrains.ndb.swap_node(pos, {name=def.nodename_prefix.."_"..(var.switchprefix or "")..newstate..rotation, param2=node.param2}) advtrains.invalidate_all_paths(pos) end end ndef.on_rightclick = function(pos, node, player) if advtrains.check_turnout_signal_protection(pos, player:get_player_name()) then advtrains.setstate(pos, nil, node) advtrains.log("Switch", player:get_player_name(), pos) end end if var.switchmc then ndef.mesecons = {effector = { ["action_"..var.switchmc] = function(pos, node) advtrains.setstate(pos, nil, node) end, rules=advtrains.meseconrules }} end ndef_avt_table = { getstate = var.switchst, setstate = switchfunc, } end local adef={} if def.get_additional_definiton then adef=def.get_additional_definiton(def, preset, suffix, rotation) end ndef = advtrains.merge_tables(ndef, adef) -- insert getstate/setstate functions after merging the additional definitions if ndef_avt_table then ndef.advtrains = advtrains.merge_tables(ndef.advtrains or {}, ndef_avt_table) end minetest.register_node(":"..def.nodename_prefix.."_"..suffix..rotation, ndef) --trackplacer if preset.regtp then local tpconns = {conn1=ndef.at_conns[1].c, conn2=ndef.at_conns[2].c} if var.tpdouble then advtrains.trackplacer.add_double_conn(def.nodename_prefix, suffix, rotation, tpconns) end if var.tpsingle then advtrains.trackplacer.add_single_conn(def.nodename_prefix, suffix, rotation, tpconns) end end advtrains.trackplacer.add_worked(def.nodename_prefix, suffix, rotation, var.trackworker) end end end advtrains.all_tracktypes[tracktype]=true end function advtrains.is_track_and_drives_on(nodename, drives_on_p) local drives_on = drives_on_p if not drives_on then drives_on = advtrains.all_tracktypes end local hasentry = false