Purge all debug messages and change 'print' function name to 'atprint'
authororwell96 <mono96.mml@gmail.com>
Wed, 4 Jan 2017 20:34:18 +0000 (21:34 +0100)
committerorwell96 <mono96.mml@gmail.com>
Wed, 4 Jan 2017 20:34:18 +0000 (21:34 +0100)
Ready for 2.0 release.

advtrains.zip
advtrains/advtrains/atc.lua
advtrains/advtrains/couple.lua
advtrains/advtrains/helpers.lua
advtrains/advtrains/init.lua
advtrains/advtrains/pseudoload.lua
advtrains/advtrains/trackplacer.lua
advtrains/advtrains/tracks.lua
advtrains/advtrains/trainlogic.lua
advtrains/advtrains/wagons.lua

index 91b52ba..b934318 100644 (file)
Binary files a/advtrains.zip and b/advtrains.zip differ
index f070b20..1b7ba5a 100644 (file)
@@ -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"
-       print("[advtrains]Failed loading advtrains atc save file "..er)
+       atprint("[advtrains]Failed loading advtrains atc save file "..er)
 else
        local tbl = minetest.deserialize(file:read("*a"))
        if type(tbl) == "table" then
@@ -44,11 +44,11 @@ end
 function atc.send_command(pos)
        local pts=minetest.pos_to_string(pos)
        if atc.controllers[pts] then
-               print("Called send_command at "..pts)
+               atprint("Called send_command at "..pts)
                local train_id = advtrains.detector.on_node[pts]
                if train_id then
                        if advtrains.trains[train_id] then
-                               print("send_command inside if: "..sid(train_id))
+                               atprint("send_command inside if: "..sid(train_id))
                                atc.train_reset_command(train_id)
                                local arrowconn=atc.controllers[pts].arrowconn
                                local train=advtrains.trains[train_id]
@@ -60,7 +60,7 @@ function atc.send_command(pos)
                                                                                advtrains.round_vector_floor_y(train.path[index+train.movedir])
                                                                )
                                                advtrains.trains[train_id].atc_command=atc.controllers[pts].command
-                                               print("Sending ATC Command: "..atc.controllers[pts].command)
+                                               atprint("Sending ATC Command: "..atc.controllers[pts].command)
                                        end
                                end
                        end
@@ -190,7 +190,7 @@ local matchptn={
                        train.movedir=train.movedir*-1
                        train.atc_arrow = not train.atc_arrow
                else
-                       print("ATC Reverse command warning: didn't reverse train!")
+                       atprint("ATC Reverse command warning: didn't reverse train!")
                end
                return 1
        end,
@@ -235,15 +235,15 @@ function atc.execute_atc_command(id, train)
                end
        end     
        if is_cond then
-               print("Evaluating if statement: "..command)
-               print("Cond: "..(cond or "nil"))
-               print("Applies: "..(cond_applies and "true" or "false"))
-               print("Rest: "..rest)
+               atprint("Evaluating if statement: "..command)
+               atprint("Cond: "..(cond or "nil"))
+               atprint("Applies: "..(cond_applies and "true" or "false"))
+               atprint("Rest: "..rest)
                --find end of conditional statement
                local nest, pos, elsepos=0, 1
                while nest>=0 do
                        if pos>#rest then
-                               print("ATC command syntax error: I statement not closed: "..command)
+                               minetest.chat_send_all("ATC command syntax error: I statement not closed: "..command)
                                atc.train_reset_command(id)
                                return
                        end
@@ -265,7 +265,7 @@ function atc.execute_atc_command(id, train)
                else
                        command=string.sub(rest, elsepos+1, pos-2)..string.sub(rest, pos)
                end
-               print("Result: "..command)
+               atprint("Result: "..command)
                train.atc_command=command
                atc.execute_atc_command(id, train)
                return
@@ -275,7 +275,7 @@ function atc.execute_atc_command(id, train)
                        if match then
                                local patlen=func(id, train, match)
                                
-                               print("Executing: "..string.sub(command, 1, patlen))
+                               atprint("Executing: "..string.sub(command, 1, patlen))
                                
                                train.atc_command=string.sub(command, patlen+1)
                                if train.atc_delay<=0 and not train.atc_wait_finish then
@@ -286,7 +286,7 @@ function atc.execute_atc_command(id, train)
                        end
                end
        end
-       print("ATC command parse error: "..command)
+       minetest.chat_send_all("ATC command parse error: "..command)
        atc.train_reset_command(id)
 end
 
index 974f450..c0dea84 100644 (file)
@@ -69,7 +69,7 @@ minetest.register_entity("advtrains:discouple", {
                        self.object:setvelocity(velocityvec)
                        self.updatepct_timer=2
                end
-               printbm("discouple_step", t)
+               atprintbm("discouple_step", t)
        end,
 })
 
@@ -122,7 +122,7 @@ minetest.register_entity("advtrains:couple", {
        end,
        on_step=function(self, dtime)
                local t=os.clock()
-               if not self.train_id_1 or not self.train_id_2 then print("wtf no train ids?")return end
+               if not self.train_id_1 or not self.train_id_2 then atprint("wtf no train ids?")return end
                local train1=advtrains.trains[self.train_id_1]
                local train2=advtrains.trains[self.train_id_2]
                if not train1 or not train2 or not train1.path or not train2.path or not train1.index or not train2.index then
@@ -151,6 +151,6 @@ minetest.register_entity("advtrains:couple", {
                                self.object:setpos(pos_median)
                        end
                end
-               printbm("couple step", t)
+               atprintbm("couple step", t)
        end,
 }) 
index 7ee7e71..e29eaa5 100644 (file)
@@ -1,5 +1,4 @@
 --advtrains by orwell96, see readme.txt\r
-local print=function(t) minetest.log("action", t) minetest.chat_send_all(t) end\r
 \r
 advtrains.dir_trans_tbl={\r
        [0]={x=0, z=1},\r
@@ -65,19 +64,19 @@ function advtrains.conway(midreal, prev, drives_on)--in order prev,mid,return
        \r
        local next, chkdir, chkrely, y_offset\r
        y_offset=0\r
-       --print("[advtrains] in order mid1,mid2",middir1,middir2)\r
+       --atprint("[advtrains] in order mid1,mid2",middir1,middir2)\r
        --try if it is dir1\r
        local cor1=advtrains.dirCoordSet(mid, middir2)--<<<<\r
        if cor1.x==prev.x and cor1.z==prev.z then--this was previous\r
                next=advtrains.dirCoordSet(mid, middir1)\r
                if midrely1>=1 then\r
                        next.y=next.y+1\r
-                       --print("[advtrains]found midrely1 to be >=1: next is now "..(next and minetest.pos_to_string(next) or "nil"))\r
+                       --atprint("[advtrains]found midrely1 to be >=1: next is now "..(next and minetest.pos_to_string(next) or "nil"))\r
                        y_offset=1\r
                end\r
                chkdir=middir1\r
                chkrely=midrely1\r
-               --print("[advtrains]dir2 applied next pos:",minetest.pos_to_string(next),"(chkdir is ",chkdir,")")\r
+               --atprint("[advtrains]dir2 applied next pos:",minetest.pos_to_string(next),"(chkdir is ",chkdir,")")\r
        end\r
        --dir2???\r
        local cor2=advtrains.dirCoordSet(mid, middir1)--<<<<\r
@@ -85,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.\r
                if midrely2>=1 then\r
                        next.y=next.y+1\r
-                       --print("[advtrains]found midrely2 to be >=1: next is now "..(next and minetest.pos_to_string(next) or "nil"))\r
+                       --atprint("[advtrains]found midrely2 to be >=1: next is now "..(next and minetest.pos_to_string(next) or "nil"))\r
                        y_offset=1\r
                end\r
                chkdir=middir2\r
                chkrely=midrely2\r
-               --print("[advtrains] dir2 applied next pos:",minetest.pos_to_string(next),"(chkdir is ",chkdir,")")\r
+               --atprint("[advtrains] dir2 applied next pos:",minetest.pos_to_string(next),"(chkdir is ",chkdir,")")\r
        end\r
-       --print("[advtrains]dir applied next pos: "..(next and minetest.pos_to_string(next) or "nil").."(chkdir is "..(chkdir or "nil")..", y-offset "..y_offset..")")\r
+       --atprint("[advtrains]dir applied next pos: "..(next and minetest.pos_to_string(next) or "nil").."(chkdir is "..(chkdir or "nil")..", y-offset "..y_offset..")")\r
        --is there a next\r
        if not next then\r
-               print("[advtrains]in conway: no next rail(nil), returning!")\r
+               atprint("[advtrains]in conway: no next rail(nil), returning!")\r
                return nil\r
        end\r
        \r
@@ -103,36 +102,36 @@ function advtrains.conway(midreal, prev, drives_on)--in order prev,mid,return
        \r
        --is it a rail?\r
        if(not nextnode_ok) then\r
-               print("[advtrains]in conway: next "..minetest.pos_to_string(next).." not a rail, trying one node below!")\r
+               atprint("[advtrains]in conway: next "..minetest.pos_to_string(next).." not a rail, trying one node below!")\r
                next.y=next.y-1\r
                y_offset=y_offset-1\r
                \r
                nextnode_ok, nextdir1, nextdir2, nextrely1, nextrely2, nextrailheight=advtrains.get_rail_info_at(advtrains.round_vector_floor_y(next), drives_on)\r
                if(not nextnode_ok) then\r
-                       print("[advtrains]in conway: one below "..minetest.pos_to_string(next).." is not a rail either, returning!")\r
+                       atprint("[advtrains]in conway: one below "..minetest.pos_to_string(next).." is not a rail either, returning!")\r
                        return nil\r
                end\r
        end\r
        \r
        --is this next rail connecting to the mid?\r
        if not ( (((nextdir1+8)%16)==chkdir and nextrely1==chkrely-y_offset) or (((nextdir2+8)%16)==chkdir and nextrely2==chkrely-y_offset) ) then\r
-               print("[advtrains]in conway: next "..minetest.pos_to_string(next).." not connecting, trying one node below!")\r
+               atprint("[advtrains]in conway: next "..minetest.pos_to_string(next).." not connecting, trying one node below!")\r
                next.y=next.y-1\r
                y_offset=y_offset-1\r
                \r
                nextnode_ok, nextdir1, nextdir2, nextrely1, nextrely2, nextrailheight=advtrains.get_rail_info_at(advtrains.round_vector_floor_y(next), drives_on)\r
                if(not nextnode_ok) then\r
-                       print("[advtrains]in conway: (at connecting if check again) one below "..minetest.pos_to_string(next).." is not a rail either, returning!")\r
+                       atprint("[advtrains]in conway: (at connecting if check again) one below "..minetest.pos_to_string(next).." is not a rail either, returning!")\r
                        return nil\r
                end\r
                if not ( (((nextdir1+8)%16)==chkdir and nextrely1==chkrely) or (((nextdir2+8)%16)==chkdir and nextrely2==chkrely) ) then\r
-                       print("[advtrains]in conway: one below "..minetest.pos_to_string(next).." rail not connecting, returning!")\r
-                       print("[advtrains] in order mid1,2,next1,2,chkdir "..middir1.." "..middir2.." "..nextdir1.." "..nextdir2.." "..chkdir)\r
+                       atprint("[advtrains]in conway: one below "..minetest.pos_to_string(next).." rail not connecting, returning!")\r
+                       atprint("[advtrains] in order mid1,2,next1,2,chkdir "..middir1.." "..middir2.." "..nextdir1.." "..nextdir2.." "..chkdir)\r
                        return nil\r
                end\r
        end\r
        \r
-       --print("[advtrains]conway found rail.")\r
+       --atprint("[advtrains]conway found rail.")\r
        return vector.add(advtrains.round_vector_floor_y(next), {x=0, y=nextrailheight, z=0}), chkdir\r
 end\r
 --TODO use this\r
@@ -172,10 +171,10 @@ function advtrains.minAngleDiffRad(r1, r2)
        end\r
 end\r
 function advtrains.dumppath(path)\r
-       if not path then print("dumppath: no path(nil)") return end\r
+       if not path then atprint("dumppath: no path(nil)") return end\r
        local min=advtrains.minN(path)\r
        local max=advtrains.maxN(path)\r
-       for i=min, max do print("["..i.."] "..(path[i] and minetest.pos_to_string(path[i]) or "nil")) end\r
+       for i=min, max do atprint("["..i.."] "..(path[i] and minetest.pos_to_string(path[i]) or "nil")) end\r
 end\r
 \r
 function advtrains.merge_tables(a, ...)\r
@@ -187,18 +186,18 @@ function advtrains.merge_tables(a, ...)
 end\r
 function advtrains.yaw_from_3_positions(prev, curr, next)\r
        local pts=minetest.pos_to_string\r
-       --print("p3 "..pts(prev)..pts(curr)..pts(next))\r
+       --atprint("p3 "..pts(prev)..pts(curr)..pts(next))\r
        local prev2curr=math.atan2((curr.x-prev.x), (prev.z-curr.z))\r
        local curr2next=math.atan2((next.x-curr.x), (curr.z-next.z))\r
-       --print("y3 "..(prev2curr*360/(2*math.pi)).." "..(curr2next*360/(2*math.pi)))\r
+       --atprint("y3 "..(prev2curr*360/(2*math.pi)).." "..(curr2next*360/(2*math.pi)))\r
        return prev2curr+(advtrains.minAngleDiffRad(prev2curr, curr2next)/2)\r
 end\r
 function advtrains.get_wagon_yaw(front, first, second, back, pct)\r
        local pts=minetest.pos_to_string\r
-       --print("p "..pts(front)..pts(first)..pts(second)..pts(back))\r
+       --atprint("p "..pts(front)..pts(first)..pts(second)..pts(back))\r
        local y2=advtrains.yaw_from_3_positions(second, first, front)\r
        local y1=advtrains.yaw_from_3_positions(back, second, first)\r
-       --print("y "..(y1*360/(2*math.pi)).." "..(y2*360/(2*math.pi)))\r
+       --atprint("y "..(y1*360/(2*math.pi)).." "..(y2*360/(2*math.pi)))\r
        return y1+advtrains.minAngleDiffRad(y1, y2)*pct\r
 end\r
 function advtrains.get_real_index_position(path, index)\r
index 33aa962..ce3cc9f 100644 (file)
@@ -4,7 +4,8 @@ advtrains={}
 
 advtrains.modpath = minetest.get_modpath("advtrains")
 
-print=function(t, ...) minetest.log("action", table.concat({t, ...}, " ")) minetest.chat_send_all(table.concat({t, ...}, " ")) end
+atprint=function() end
+--atprint=function(t, ...) minetest.log("action", table.concat({t, ...}, " ")) minetest.chat_send_all(table.concat({t, ...}, " ")) end
 sid=function(id) return string.sub(id, -4) end
 
 dofile(advtrains.modpath.."/helpers.lua");
index 14db58f..0636d2e 100644 (file)
@@ -1,5 +1,3 @@
-local print=function(t) minetest.log("action", t) minetest.chat_send_all(t) end
-
 --pseudoload.lua
 --responsible for keeping up a database of all rail nodes existant in the world, regardless of whether the mapchunk is loaded.
 
@@ -22,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"
-               print("[advtrains]Failed loading advtrains trackdb save file "..er)
+               atprint("[advtrains]Failed loading advtrains trackdb save file "..er)
        else
                --custom format to save memory
                while true do
@@ -30,7 +28,7 @@ for tt, _ in pairs(advtrains.all_traintypes) do
                        if not xbytes or #xbytes<2 then
                                break --eof reached
                        end
-                       print(xbytes)
+                       atprint(xbytes)
                        local ybytes=file:read(2)
                        local zbytes=file:read(2)
                        local x=(string.byte(xbytes[1])-128)*256+(string.byte(xbytes[2]))
@@ -76,13 +74,13 @@ function advtrains.save_trackdb()
                local file, err = io.open(pl_fpath, "w")
                if not file then
                        local er=err or "Unknown Error"
-                       print("[advtrains]Failed saving advtrains trackdb save file "..er)
+                       atprint("[advtrains]Failed saving advtrains trackdb save file "..er)
                else
                        --custom format to save memory
                        for y,tyl in pairs(advtrains.trackdb[tt]) do
                                for x,txl in pairs(tyl) do
                                        for z,rail in pairs(txl) do
-                                               print("write "..x.." "..y.." "..z.." "..minetest.serialize(rail))
+                                               atprint("write "..x.." "..y.." "..z.." "..minetest.serialize(rail))
                                                file:write(string.char(math.floor(x/256)+128)..string.char((x%256)))
                                                file:write(string.char(math.floor(y/256)+128)..string.char((y%256)))
                                                file:write(string.char(math.floor(z/256)+128)..string.char((z%256)))
@@ -105,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"
-       print("[advtrains]Failed loading advtrains save file "..er)
+       atprint("[advtrains]Failed loading advtrains save file "..er)
 else
        local tbl = minetest.deserialize(file:read("*a"))
        if type(tbl) == "table" then
index b24103a..e40cb59 100644 (file)
@@ -233,7 +233,7 @@ minetest.register_craftitem("advtrains:trackworker",{
                        if advtrains.is_train_at_pos(pos) then return end
 
                        local nnprefix, suffix, rotation=string.match(node.name, "^(.+)_([^_]+)(_[^_]+)$")
-                       --print(node.name.."\npattern recognizes:"..nodeprefix.." / "..railtype.." / "..rotation)
+                       --atprint(node.name.."\npattern recognizes:"..nodeprefix.." / "..railtype.." / "..rotation)
                        if not tp.tracks[nnprefix] or not tp.tracks[nnprefix].twrotate[suffix] then
                                nnprefix, suffix=string.match(node.name, "^(.+)_([^_]+)$")
                                rotation = ""
@@ -274,7 +274,7 @@ 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 nnprefix, suffix, rotation=string.match(node.name, "^(.+)_([^_]+)(_[^_]+)$")
-               --print(node.name.."\npattern recognizes:"..nodeprefix.." / "..railtype.." / "..rotation)
+               --atprint(node.name.."\npattern recognizes:"..nodeprefix.." / "..railtype.." / "..rotation)
                    if not tp.tracks[nnprefix] or not tp.tracks[nnprefix].twcycle[suffix] then
                          nnprefix, suffix=string.match(node.name, "^(.+)_([^_]+)$")
                          rotation = ""
@@ -288,7 +288,7 @@ minetest.register_craftitem("advtrains:trackworker",{
                        --invalidate trains
                        advtrains.invalidate_all_paths()
                else
-                       print(name, dump(tp.tracks))
+                       atprint(name, dump(tp.tracks))
                end
        end,
 })
index c20be70..53f5ce7 100644 (file)
@@ -370,10 +370,10 @@ end
 \r
 function advtrains.get_track_connections(name, param2)\r
        local nodedef=minetest.registered_nodes[name]\r
-       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\r
+       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\r
        local noderot=param2\r
        if not param2 then noderot=0 end\r
-       if noderot > 3 then print("[advtrains] get_track_connections: rail has invaild param2 of "..noderot) noderot=0 end\r
+       if noderot > 3 then atprint("[advtrains] get_track_connections: rail has invaild param2 of "..noderot) noderot=0 end\r
        \r
        local tracktype\r
        for k,_ in pairs(nodedef.groups) do\r
@@ -398,10 +398,10 @@ advtrains.detector.clean_step_before = false
 --The entry already being contained in advtrains.detector.on_node_restore will not trigger an on_train_enter event on the node.  (when path is reset, this is saved).\r
 function advtrains.detector.enter_node(pos, train_id)\r
        local pts = minetest.pos_to_string(advtrains.round_vector_floor_y(pos))\r
-       --print("enterNode "..pts.." "..sid(train_id))\r
+       --atprint("enterNode "..pts.." "..sid(train_id))\r
        if advtrains.detector.on_node[pts] then\r
                if advtrains.trains[advtrains.detector.on_node[pts]] then\r
-                       --print(""..pts.." already occupied")\r
+                       --atprint(""..pts.." already occupied")\r
                        return false\r
                else\r
                        advtrains.detector.leave_node(pos, advtrains.detector.on_node[pts])\r
@@ -417,9 +417,9 @@ function advtrains.detector.enter_node(pos, train_id)
 end\r
 function advtrains.detector.leave_node(pos, train_id)\r
        local pts = minetest.pos_to_string(advtrains.round_vector_floor_y(pos))\r
-       --print("leaveNode "..pts.." "..sid(train_id))\r
+       --atprint("leaveNode "..pts.." "..sid(train_id))\r
        if not advtrains.detector.on_node[pts] then\r
-               --print(""..pts.." leave: nothing here")\r
+               --atprint(""..pts.." leave: nothing here")\r
                return false\r
        end\r
        if advtrains.detector.on_node[pts]==train_id then\r
@@ -427,7 +427,7 @@ function advtrains.detector.leave_node(pos, train_id)
                advtrains.detector.on_node[pts]=nil\r
        else\r
                if advtrains.trains[advtrains.detector.on_node[pts]] then\r
-                       --print(""..pts.." occupied by another train")\r
+                       --atprint(""..pts.." occupied by another train")\r
                        return false\r
                else\r
                        advtrains.detector.leave_node(pos, advtrains.detector.on_node[pts])\r
@@ -438,21 +438,21 @@ function advtrains.detector.leave_node(pos, train_id)
 end\r
 --called immediately before invalidating paths\r
 function advtrains.detector.setup_restore()\r
-       --print("setup_restore")\r
+       --atprint("setup_restore")\r
        advtrains.detector.on_node_restore = advtrains.detector.on_node\r
        advtrains.detector.on_node = {}\r
 end\r
 --called one step after invalidating paths, when all trains have restored their path and called enter_node for their contents.\r
 function advtrains.detector.finalize_restore()\r
-       --print("finalize_restore")\r
+       --atprint("finalize_restore")\r
        for pts, train_id in pairs(advtrains.detector.on_node_restore) do\r
-               --print("called leave callback "..pts.." "..train_id)\r
+               --atprint("called leave callback "..pts.." "..train_id)\r
                advtrains.detector.call_leave_callback(minetest.string_to_pos(pts), train_id)\r
        end\r
        advtrains.detector.on_node_restore = {}\r
 end\r
 function advtrains.detector.call_enter_callback(pos, train_id)\r
-       --print("instructed to call enter calback")\r
+       --atprint("instructed to call enter calback")\r
 \r
        local node = minetest.get_node(pos) --this spares the check if node is nil, it has a name in any case\r
        local mregnode=minetest.registered_nodes[node.name]\r
@@ -464,7 +464,7 @@ function advtrains.detector.call_enter_callback(pos, train_id)
        advtrains.atc.trigger_controller_train_enter(pos, train_id)\r
 end\r
 function advtrains.detector.call_leave_callback(pos, train_id)\r
-       --print("instructed to call leave calback")\r
+       --atprint("instructed to call leave calback")\r
 \r
        local node = minetest.get_node(pos) --this spares the check if node is nil, it has a name in any case\r
        local mregnode=minetest.registered_nodes[node.name]\r
index 0ad7874..ac870c0 100644 (file)
@@ -7,7 +7,7 @@ local bm={}
 local bmlt=0
 local bmsteps=0
 local bmstepint=200
-printbm=function(action, ta)
+atprintbm=function(action, ta)
        if not benchmark then return end
        local t=(os.clock()-ta)*1000
        if not bm[action] then
@@ -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"
-       print("[advtrains]Failed loading advtrains save file "..er)
+       atprint("[advtrains]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"
-       print("[advtrains]Failed loading advtrains save file "..er)
+       atprint("[advtrains]Failed loading advtrains save file "..er)
 else
        local tbl = minetest.deserialize(file:read("*a"))
        if type(tbl) == "table" then
@@ -70,7 +70,7 @@ end
 
 
 advtrains.save = function()
-       print("[advtrains]saving")
+       atprint("[advtrains]saving")
        advtrains.invalidate_all_paths()
        local datastr = minetest.serialize(advtrains.trains)
        if not datastr then
@@ -105,7 +105,7 @@ advtrains.save = function()
                        data.discouple=nil
                end
        end
-       --print(dump(advtrains.wagon_save))
+       --atprint(dump(advtrains.wagon_save))
        datastr = minetest.serialize(advtrains.wagon_save)
        if not datastr then
                minetest.log("error", "[advtrains] Failed to serialize train data!")
@@ -132,7 +132,7 @@ minetest.register_globalstep(function(dtime)
                --save
                advtrains.save()
                advtrains.save_and_audit_timer=advtrains.audit_interval
-               printbm("saving", t)
+               atprintbm("saving", t)
        end
        --regular train step
        local t=os.clock()
@@ -145,7 +145,7 @@ minetest.register_globalstep(function(dtime)
                advtrains.detector.finalize_restore()
        end
        
-       printbm("trainsteps", t)
+       atprintbm("trainsteps", t)
        endstep()
 end)
 
@@ -171,7 +171,7 @@ function advtrains.train_step(id, train, dtime)
        --if not train.last_pos then advtrains.trains[id]=nil return end
        
        if not advtrains.pathpredict(id, train) then 
-               print("pathpredict failed(returned false)")
+               atprint("pathpredict failed(returned false)")
                train.velocity=0
                train.tarvelocity=0
                return
@@ -181,7 +181,7 @@ function advtrains.train_step(id, train, dtime)
        if not path then
                train.velocity=0
                train.tarvelocity=0
-               print("train has no path for whatever reason")
+               atprint("train has no path for whatever reason")
                return 
        end
        
@@ -236,7 +236,7 @@ function advtrains.train_step(id, train, dtime)
        
        --remove?
        if #train.trainparts==0 then
-               print("[advtrains][train "..sid(id).."] has empty trainparts, removing.")
+               atprint("[advtrains][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
-               --print("[advtrains][train "..id.."] at "..minetest.pos_to_string(vector.round(ori_pos)))
+               --atprint("[advtrains][train "..id.."] at "..minetest.pos_to_string(vector.round(ori_pos)))
                
                local should_check=false
                for _,p in ipairs(minetest.get_connected_players()) do
@@ -335,19 +335,19 @@ function advtrains.train_step(id, train, dtime)
                local mass=#train.trainparts
                local diff=train.tarvelocity-train.velocity
                if diff>0 then--accelerating, force will be brought on only by locomotives.
-                       --print("accelerating with default force")
+                       --atprint("accelerating with default force")
                        applydiff=(math.min((advtrains.train_accel_force*train.locomotives_in_train*dtime)/mass, math.abs(diff)))
                else--decelerating
                        if front_off_track or back_off_track or train.recently_collided_with_env then --every wagon has a brake, so not divided by mass.
-                               --print("braking with emergency force")
+                               --atprint("braking with emergency force")
                                applydiff= -(math.min((advtrains.train_emerg_force*dtime), math.abs(diff)))
                        elseif train.brake or (train.atc_brake_target and train.atc_brake_target<train.velocity) then
-                               --print("braking with default force")
+                               --atprint("braking with default force")
                                --no math.min, because it can grow beyond tarvelocity, see up there
                                --dont worry, it will never fall below zero.
                                applydiff= -((advtrains.train_brake_force*dtime))
                        else
-                               --print("roll")
+                               --atprint("roll")
                                applydiff= -(math.min((advtrains.train_roll_force*dtime), math.abs(diff)))
                        end
                end
@@ -411,13 +411,13 @@ end
 --returns false on failure. handle this case!
 function advtrains.pathpredict(id, train)
        
-       --print("pos ",x,y,z)
+       --atprint("pos ",x,y,z)
        --::rerun::
        if not train.index then train.index=0 end
        if not train.path or #train.path<2 then
                if not train.last_pos then
                        --no chance to recover
-                       print("[advtrains]train hasn't saved last-pos, removing train.")
+                       atprint("[advtrains]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
-                       print("[advtrains]last_pos not available")
+                       atprint("[advtrains]last_pos not available")
                        return nil
                elseif node_ok==false then
-                       print("[advtrains]no track here, (fail) removing train.")
+                       atprint("[advtrains]no track here, (fail) removing train.")
                        advtrains.trains[id]=nil
                        return false
                end
                
                if not train.last_pos_prev then
                        --no chance to recover
-                       print("[advtrains]train hasn't saved last-pos_prev, removing train.")
+                       atprint("[advtrains]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
-                       print("[advtrains]prev not available")
+                       atprint("[advtrains]prev not available")
                        return nil
                elseif prevnode_ok==false then
-                       print("[advtrains]no track at prev, (fail) removing train.")
+                       atprint("[advtrains]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
-               --print("[advtrains]maxn conway for ",maxn,minetest.pos_to_string(path[maxn]),maxn-1,minetest.pos_to_string(path[maxn-1]))
+               --atprint("[advtrains]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
@@ -484,7 +484,7 @@ function advtrains.pathpredict(id, train)
                else
                        --do as if nothing has happened and preceed with path
                        --but do not update max_index_on_track
-                       print("over-generating path max to index "..(maxn+1).." (position "..minetest.pos_to_string(train.path[maxn]).." )")
+                       atprint("over-generating path max to index "..(maxn+1).." (position "..minetest.pos_to_string(train.path[maxn]).." )")
                        train.path[maxn+1]=vector.add(train.path[maxn], vector.subtract(train.path[maxn], train.path[maxn-1]))
                end
                train.path_dist[maxn]=vector.distance(train.path[maxn+1], train.path[maxn])
@@ -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)
-               --print("[advtrains]minn conway for ",minn,minetest.pos_to_string(path[minn]),minn+1,minetest.pos_to_string(path[minn+1]))
+               --atprint("[advtrains]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
@@ -501,7 +501,7 @@ function advtrains.pathpredict(id, train)
                else
                        --do as if nothing has happened and preceed with path
                        --but do not update min_index_on_track
-                       print("over-generating path min to index "..(minn-1).." (position "..minetest.pos_to_string(train.path[minn]).." )")
+                       atprint("over-generating path min to index "..(minn-1).." (position "..minetest.pos_to_string(train.path[minn]).." )")
                        train.path[minn-1]=vector.add(train.path[minn], vector.subtract(train.path[minn], train.path[minn+1]))
                end
                train.path_dist[minn-1]=vector.distance(train.path[minn], train.path[minn-1])
@@ -515,12 +515,12 @@ function advtrains.pathpredict(id, train)
                train.savedpos_off_track_index_offset=train.index-train.max_index_on_track
                train.last_pos=train.path[train.max_index_on_track]
                train.last_pos_prev=train.path[train.max_index_on_track-1]
-               print("train is off-track (front), last positions kept at "..minetest.pos_to_string(train.last_pos).." / "..minetest.pos_to_string(train.last_pos_prev))
+               atprint("train is off-track (front), last positions kept at "..minetest.pos_to_string(train.last_pos).." / "..minetest.pos_to_string(train.last_pos_prev))
        elseif train.min_index_on_track+1>train.index then --whoops, train went even more far. same behavior
                train.savedpos_off_track_index_offset=train.index-train.min_index_on_track
                train.last_pos=train.path[train.min_index_on_track+1]
                train.last_pos_prev=train.path[train.min_index_on_track]
-               print("train is off-track (back), last positions kept at "..minetest.pos_to_string(train.last_pos).." / "..minetest.pos_to_string(train.last_pos_prev))
+               atprint("train is off-track (back), last positions kept at "..minetest.pos_to_string(train.last_pos).." / "..minetest.pos_to_string(train.last_pos_prev))
        else --regular case
                train.savedpos_off_track_index_offset=nil
                train.last_pos=train.path[math.floor(train.index+0.5)]
@@ -599,7 +599,7 @@ function advtrains.update_trainpart_properties(train_id, invert_flipstate)
                        end
                        train.max_speed=math.min(train.max_speed, wagon.max_speed)
                else
-                       print(w_id.." not loaded and no save available")
+                       atprint(w_id.." not loaded and no save available")
                        --what the hell...
                        table.remove(train.trainparts, pit)
                end
@@ -617,23 +617,23 @@ function advtrains.split_train_at_wagon(wagon)
        
        --before doing anything, check if both are rails. else do not allow
        if not pos_for_new_train then
-               print("split_train: pos_for_new_train not set")
+               atprint("split_train: pos_for_new_train not set")
                return false
        end
        local node_ok=advtrains.get_rail_info_at(advtrains.round_vector_floor_y(pos_for_new_train), train.drives_on)
        if not node_ok then
-               print("split_train: pos_for_new_train "..minetest.pos_to_string(advtrains.round_vector_floor_y(pos_for_new_train_prev)).." not loaded or is not a rail")
+               atprint("split_train: pos_for_new_train "..minetest.pos_to_string(advtrains.round_vector_floor_y(pos_for_new_train_prev)).." not loaded or is not a rail")
                return false
        end
        
        if not train.last_pos_prev then
-               print("split_train: pos_for_new_train_prev not set")
+               atprint("split_train: pos_for_new_train_prev not set")
                return false
        end
        
        local prevnode_ok=advtrains.get_rail_info_at(advtrains.round_vector_floor_y(pos_for_new_train), train.drives_on)
        if not prevnode_ok then
-               print("split_train: pos_for_new_train_prev "..minetest.pos_to_string(advtrains.round_vector_floor_y(pos_for_new_train_prev)).." not loaded or is not a rail")
+               atprint("split_train: pos_for_new_train_prev "..minetest.pos_to_string(advtrains.round_vector_floor_y(pos_for_new_train_prev)).." not loaded or is not a rail")
                return false
        end
        
@@ -681,7 +681,7 @@ function advtrains.trains_facing(train1, train2)
 end
 
 function advtrains.spawn_couple_on_collide(id1, pos, id2, t1_is_backpos)
-       print("COLLISION: "..sid(id1).." and "..sid(id2).." at "..minetest.pos_to_string(pos)..", t1_is_backpos="..(t1_is_backpos and "true" or "false"))
+       atprint("COLLISION: "..sid(id1).." and "..sid(id2).." at "..minetest.pos_to_string(pos)..", t1_is_backpos="..(t1_is_backpos and "true" or "false"))
        --TODO:
        local train1=advtrains.trains[id1]
        local train2=advtrains.trains[id2]
@@ -695,24 +695,24 @@ function advtrains.spawn_couple_on_collide(id1, pos, id2, t1_is_backpos)
                end
        end
        if not found then
-               print("Err: pos not in path")
+               atprint("Err: pos not in path")
                return 
        end
        
        local frontpos2=train2.path[math.floor(train2.detector_old_index)]
        local backpos2=train2.path[math.floor(train2.detector_old_end_index)]
        local t2_is_backpos
-       print("End positions: "..minetest.pos_to_string(frontpos2)..minetest.pos_to_string(backpos2))
+       atprint("End positions: "..minetest.pos_to_string(frontpos2)..minetest.pos_to_string(backpos2))
        
        if vector.distance(frontpos2, pos)<2 then
                t2_is_backpos=false
        elseif vector.distance(backpos2, pos)<2 then
                t2_is_backpos=true
        else
-               print("Err: not a endpos")
+               atprint("Err: not a endpos")
                return --the collision position is not the end position.
        end
-       print("t2_is_backpos="..(t2_is_backpos and "true" or "false"))
+       atprint("t2_is_backpos="..(t2_is_backpos and "true" or "false"))
        
        local t1_has_couple
        if t1_is_backpos then
@@ -734,7 +734,7 @@ function advtrains.spawn_couple_on_collide(id1, pos, id2, t1_is_backpos)
                if minetest.object_refs[t2_has_couple] then minetest.object_refs[t2_has_couple]:remove() end
        end
        local obj=minetest.add_entity(pos, "advtrains:couple")
-       if not obj then print("failed creating object") return end
+       if not obj then atprint("failed creating object") return end
        local le=obj:get_luaentity()
        le.train_id_1=id1
        le.train_id_2=id2
@@ -755,7 +755,7 @@ function advtrains.spawn_couple_on_collide(id1, pos, id2, t1_is_backpos)
                        end
                end
        end
-       print("Couple entity:"..dump(le))
+       atprint("Couple entity:"..dump(le))
        
        --also TODO: integrate check_trainpartload into update_trainpart_properties. 
 end
@@ -798,20 +798,20 @@ function advtrains.invert_train(train_id)
 end
 
 function advtrains.is_train_at_pos(pos)
-       --print("istrainat: pos "..minetest.pos_to_string(pos))
+       --atprint("istrainat: pos "..minetest.pos_to_string(pos))
        local checked_trains={}
        local objrefs=minetest.get_objects_inside_radius(pos, 2)
        for _,v in pairs(objrefs) do
                local le=v:get_luaentity()
                if le and le.is_wagon and le.initialized and le.train_id and not checked_trains[le.train_id] then
-                       --print("istrainat: checking "..le.train_id)
+                       --atprint("istrainat: checking "..le.train_id)
                        checked_trains[le.train_id]=true
                        local path=advtrains.get_or_create_path(le.train_id, le:train())
                        if path then
-                               --print("has path")
+                               --atprint("has path")
                                for i=math.floor(advtrains.get_train_end_index(le:train())+0.5),math.floor(le:train().index+0.5) do
                                        if path[i] then
-                                               --print("has pathitem "..i.." "..minetest.pos_to_string(path[i]))
+                                               --atprint("has pathitem "..i.." "..minetest.pos_to_string(path[i]))
                                                if vector.equals(advtrains.round_vector_floor_y(path[i]), pos) then
                                                        return true
                                                end
@@ -823,7 +823,7 @@ function advtrains.is_train_at_pos(pos)
        return false
 end
 function advtrains.invalidate_all_paths()
-       --print("invalidating all paths")
+       --atprint("invalidating all paths")
        for k,v in pairs(advtrains.trains) do
                if v.index then
                        v.restore_add_index=v.index-math.floor(v.index+0.5)
index 495f914..8c3cd0a 100644 (file)
@@ -1,6 +1,4 @@
 --atan2 counts angles clockwise, minetest does counterclockwise\r
---local print=function(t) minetest.log("action", t) minetest.chat_send_all(t) end\r
-local print=function() end\r
 \r
 local wagon={\r
        collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},\r
@@ -49,7 +47,7 @@ end
        wagon will save only uid in staticdata, no serialized table\r
 ]]\r
 function wagon:on_activate(sd_uid, dtime_s)\r
-       print("[advtrains][wagon "..((sd_uid and sd_uid~="" and sd_uid) or "no-id").."] activated")\r
+       atprint("[advtrains][wagon "..((sd_uid and sd_uid~="" and sd_uid) or "no-id").."] activated")\r
        self.object:set_armor_groups({immortal=1})\r
        if sd_uid and sd_uid~="" then\r
                --legacy\r
@@ -65,7 +63,7 @@ function wagon:on_activate(sd_uid, dtime_s)
        --duplicates?\r
        for ao_id,wagon in pairs(minetest.luaentities) do\r
                if wagon.is_wagon and wagon.initialized and wagon.unique_id==self.unique_id and wagon~=self then--i am a duplicate!\r
-                       print("[advtrains][wagon "..((sd_uid and sd_uid~="" and sd_uid) or "no-id").."] duplicate found(ao_id:"..ao_id.."), removing")\r
+                       atprint("[advtrains][wagon "..((sd_uid and sd_uid~="" and sd_uid) or "no-id").."] duplicate found(ao_id:"..ao_id.."), removing")\r
                        self.object:remove()\r
                        minetest.after(0.5, function() advtrains.update_trainpart_properties(self.train_id) end)\r
                        return\r
@@ -79,7 +77,7 @@ end
 \r
 function wagon:get_staticdata()\r
        if not self:ensure_init() then return end\r
-       print("[advtrains][wagon "..((self.unique_id and self.unique_id~="" and self.unique_id) or "no-id").."]: saving to wagon_save")\r
+       atprint("[advtrains][wagon "..((self.unique_id and self.unique_id~="" and self.unique_id) or "no-id").."]: saving to wagon_save")\r
        --serialize inventory, if it has one\r
        if self.has_inventory then\r
                local inv=minetest.get_inventory({type="detached", name="advtrains_wgn_"..self.unique_id})\r
@@ -103,7 +101,7 @@ function wagon:init_new_instance(train_id, properties)
        end\r
        self:init_shared()\r
        self.initialized=true\r
-       print("init_new_instance "..self.unique_id.." ("..self.train_id..")")\r
+       atprint("init_new_instance "..self.unique_id.." ("..self.train_id..")")\r
        return self.unique_id\r
 end\r
 function wagon:init_from_wagon_save(uid)\r
@@ -124,7 +122,7 @@ function wagon:init_from_wagon_save(uid)
        self:init_shared()\r
        self.initialized=true\r
        minetest.after(1, function() self:reattach_all() end)\r
-       print("init_from_wagon_save "..self.unique_id.." ("..self.train_id..")")\r
+       atprint("init_from_wagon_save "..self.unique_id.." ("..self.train_id..")")\r
        advtrains.update_trainpart_properties(self.train_id)\r
 end\r
 function wagon:init_shared()\r
@@ -211,7 +209,7 @@ function wagon:destroy()
                self.custom_on_destroy(self, puncher, time_from_last_punch, tool_capabilities, direction)\r
        end\r
        \r
-       print("[advtrains][wagon "..((self.unique_id and self.unique_id~="" and self.unique_id) or "no-id").."]: destroying")\r
+       atprint("[advtrains][wagon "..((self.unique_id and self.unique_id~="" and self.unique_id) or "no-id").."]: destroying")\r
        \r
        self.object:remove()\r
 \r
@@ -230,7 +228,7 @@ function wagon:on_step(dtime)
        local pos = self.object:getpos()\r
        \r
        if not pos then\r
-               print("["..self.unique_id.."][fatal] missing position (object:getpos() returned nil)")\r
+               atprint("["..self.unique_id.."][fatal] missing position (object:getpos() returned nil)")\r
                return\r
        end\r
 \r
@@ -238,7 +236,7 @@ function wagon:on_step(dtime)
        \r
        --is my train still here\r
        if not self.train_id or not self:train() then\r
-               print("[advtrains][wagon "..self.unique_id.."] missing train_id, destroying")\r
+               atprint("[advtrains][wagon "..self.unique_id.."] missing train_id, destroying")\r
                self.object:remove()\r
                return\r
        elseif not self.initialized then\r
@@ -292,7 +290,7 @@ function wagon:on_step(dtime)
                                        --object:set_attach(self.object, "", {x=0, y=0, z=self.wagon_span*10}, {x=0, y=0, z=0})\r
                                        self.discouple=le\r
                                else\r
-                                       print("Couldn't spawn DisCouple")\r
+                                       atprint("Couldn't spawn DisCouple")\r
                                end\r
                        end\r
                else\r
@@ -313,13 +311,13 @@ function wagon:on_step(dtime)
        end\r
        \r
        local index=advtrains.get_real_path_index(self:train(), self.pos_in_train)\r
-       --print("trainindex "..gp.index.." wagonindex "..index)\r
+       --atprint("trainindex "..gp.index.." wagonindex "..index)\r
        \r
        --position recalculation\r
        local first_pos=gp.path[math.floor(index)]\r
        local second_pos=gp.path[math.floor(index)+1]\r
        if not first_pos or not second_pos then\r
-               --print("[advtrains] object "..self.unique_id.." path end reached!")\r
+               --atprint("[advtrains] object "..self.unique_id.." path end reached!")\r
                self.object:setvelocity({x=0,y=0,z=0})\r
                return\r
        end\r
@@ -387,7 +385,7 @@ function wagon:on_step(dtime)
        self.old_velocity_vector=velocityvec\r
        self.old_acceleration_vector=accelerationvec\r
        self.old_yaw=yaw\r
-       printbm("wagon step", t)\r
+       atprintbm("wagon step", t)\r
 end\r
 \r
 function advtrains.get_real_path_index(train, pit)\r
@@ -535,10 +533,10 @@ function advtrains.register_wagon(sysname, prototype, desc, inv_img)
                        end\r
                        \r
                        local node=minetest.env:get_node_or_nil(pointed_thing.under)\r
-                       if not node then print("[advtrains]Ignore at placer position") return itemstack end\r
+                       if not node then atprint("[advtrains]Ignore at placer position") return itemstack end\r
                        local nodename=node.name\r
                        if(not advtrains.is_track_and_drives_on(nodename, prototype.drives_on)) then\r
-                               print("[advtrains]no track here, not placing.")\r
+                               atprint("[advtrains]no track here, not placing.")\r
                                return itemstack\r
                        end\r
                        local conn1=advtrains.get_track_connections(node.name, node.param2)\r
@@ -546,7 +544,7 @@ function advtrains.register_wagon(sysname, prototype, desc, inv_img)
                        \r
                        local ob=minetest.env:add_entity(pointed_thing.under, "advtrains:"..sysname)\r
                        if not ob then\r
-                               print("[advtrains]couldn't add_entity, aborting")\r
+                               atprint("[advtrains]couldn't add_entity, aborting")\r
                        end\r
                        local le=ob:get_luaentity()\r
                        \r