aboutsummaryrefslogtreecommitdiff
path: root/advtrains
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains')
-rw-r--r--advtrains/advtrains/atc.lua26
-rw-r--r--advtrains/advtrains/couple.lua6
-rw-r--r--advtrains/advtrains/helpers.lua41
-rw-r--r--advtrains/advtrains/init.lua3
-rw-r--r--advtrains/advtrains/pseudoload.lua12
-rw-r--r--advtrains/advtrains/trackplacer.lua6
-rw-r--r--advtrains/advtrains/tracks.lua24
-rw-r--r--advtrains/advtrains/trainlogic.lua90
-rw-r--r--advtrains/advtrains/wagons.lua32
9 files changed, 118 insertions, 122 deletions
diff --git a/advtrains/advtrains/atc.lua b/advtrains/advtrains/atc.lua
index f070b20..1b7ba5a 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"
- 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
diff --git a/advtrains/advtrains/couple.lua b/advtrains/advtrains/couple.lua
index 974f450..c0dea84 100644
--- a/advtrains/advtrains/couple.lua
+++ b/advtrains/advtrains/couple.lua
@@ -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,
})
diff --git a/advtrains/advtrains/helpers.lua b/advtrains/advtrains/helpers.lua
index 7ee7e71..e29eaa5 100644
--- a/advtrains/advtrains/helpers.lua
+++ b/advtrains/advtrains/helpers.lua
@@ -1,5 +1,4 @@
--advtrains by orwell96, see readme.txt
-local print=function(t) minetest.log("action", t) minetest.chat_send_all(t) end
advtrains.dir_trans_tbl={
[0]={x=0, z=1},
@@ -65,19 +64,19 @@ function advtrains.conway(midreal, prev, drives_on)--in order prev,mid,return
local next, chkdir, chkrely, y_offset
y_offset=0
- --print("[advtrains] in order mid1,mid2",middir1,middir2)
+ --atprint("[advtrains] 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
- --print("[advtrains]found midrely1 to be >=1: next is now "..(next and minetest.pos_to_string(next) or "nil"))
+ --atprint("[advtrains]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
- --print("[advtrains]dir2 applied next pos:",minetest.pos_to_string(next),"(chkdir is ",chkdir,")")
+ --atprint("[advtrains]dir2 applied next pos:",minetest.pos_to_string(next),"(chkdir is ",chkdir,")")
end
--dir2???
local cor2=advtrains.dirCoordSet(mid, middir1)--<<<<
@@ -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.
if midrely2>=1 then
next.y=next.y+1
- --print("[advtrains]found midrely2 to be >=1: next is now "..(next and minetest.pos_to_string(next) or "nil"))
+ --atprint("[advtrains]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
- --print("[advtrains] dir2 applied next pos:",minetest.pos_to_string(next),"(chkdir is ",chkdir,")")
+ --atprint("[advtrains] dir2 applied next pos:",minetest.pos_to_string(next),"(chkdir is ",chkdir,")")
end
- --print("[advtrains]dir applied next pos: "..(next and minetest.pos_to_string(next) or "nil").."(chkdir is "..(chkdir or "nil")..", y-offset "..y_offset..")")
+ --atprint("[advtrains]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
- print("[advtrains]in conway: no next rail(nil), returning!")
+ atprint("[advtrains]in conway: no next rail(nil), returning!")
return nil
end
@@ -103,36 +102,36 @@ function advtrains.conway(midreal, prev, drives_on)--in order prev,mid,return
--is it a rail?
if(not nextnode_ok) then
- print("[advtrains]in conway: next "..minetest.pos_to_string(next).." not a rail, trying one node below!")
+ atprint("[advtrains]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
- print("[advtrains]in conway: one below "..minetest.pos_to_string(next).." is not a rail either, returning!")
+ atprint("[advtrains]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
- print("[advtrains]in conway: next "..minetest.pos_to_string(next).." not connecting, trying one node below!")
+ atprint("[advtrains]in conway: next "..minetest.pos_to_string(next).." not connecting, trying one node below!")
next.y=next.y-1
y_offset=y_offset-1
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
- print("[advtrains]in conway: (at connecting if check again) one below "..minetest.pos_to_string(next).." is not a rail either, returning!")
+ atprint("[advtrains]in conway: (at connecting if check again) one below "..minetest.pos_to_string(next).." is not a rail either, returning!")
return nil
end
if not ( (((nextdir1+8)%16)==chkdir and nextrely1==chkrely) or (((nextdir2+8)%16)==chkdir and nextrely2==chkrely) ) then
- print("[advtrains]in conway: one below "..minetest.pos_to_string(next).." rail not connecting, returning!")
- print("[advtrains] in order mid1,2,next1,2,chkdir "..middir1.." "..middir2.." "..nextdir1.." "..nextdir2.." "..chkdir)
+ 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)
return nil
end
end
- --print("[advtrains]conway found rail.")
+ --atprint("[advtrains]conway found rail.")
return vector.add(advtrains.round_vector_floor_y(next), {x=0, y=nextrailheight, z=0}), chkdir
end
--TODO use this
@@ -172,10 +171,10 @@ function advtrains.minAngleDiffRad(r1, r2)
end
end
function advtrains.dumppath(path)
- if not path then print("dumppath: no path(nil)") return end
+ if not path then atprint("dumppath: no path(nil)") return end
local min=advtrains.minN(path)
local max=advtrains.maxN(path)
- for i=min, max do print("["..i.."] "..(path[i] and minetest.pos_to_string(path[i]) or "nil")) end
+ for i=min, max do atprint("["..i.."] "..(path[i] and minetest.pos_to_string(path[i]) or "nil")) end
end
function advtrains.merge_tables(a, ...)
@@ -187,18 +186,18 @@ function advtrains.merge_tables(a, ...)
end
function advtrains.yaw_from_3_positions(prev, curr, next)
local pts=minetest.pos_to_string
- --print("p3 "..pts(prev)..pts(curr)..pts(next))
+ --atprint("p3 "..pts(prev)..pts(curr)..pts(next))
local prev2curr=math.atan2((curr.x-prev.x), (prev.z-curr.z))
local curr2next=math.atan2((next.x-curr.x), (curr.z-next.z))
- --print("y3 "..(prev2curr*360/(2*math.pi)).." "..(curr2next*360/(2*math.pi)))
+ --atprint("y3 "..(prev2curr*360/(2*math.pi)).." "..(curr2next*360/(2*math.pi)))
return prev2curr+(advtrains.minAngleDiffRad(prev2curr, curr2next)/2)
end
function advtrains.get_wagon_yaw(front, first, second, back, pct)
local pts=minetest.pos_to_string
- --print("p "..pts(front)..pts(first)..pts(second)..pts(back))
+ --atprint("p "..pts(front)..pts(first)..pts(second)..pts(back))
local y2=advtrains.yaw_from_3_positions(second, first, front)
local y1=advtrains.yaw_from_3_positions(back, second, first)
- --print("y "..(y1*360/(2*math.pi)).." "..(y2*360/(2*math.pi)))
+ --atprint("y "..(y1*360/(2*math.pi)).." "..(y2*360/(2*math.pi)))
return y1+advtrains.minAngleDiffRad(y1, y2)*pct
end
function advtrains.get_real_index_position(path, index)
diff --git a/advtrains/advtrains/init.lua b/advtrains/advtrains/init.lua
index 33aa962..ce3cc9f 100644
--- a/advtrains/advtrains/init.lua
+++ b/advtrains/advtrains/init.lua
@@ -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");
diff --git a/advtrains/advtrains/pseudoload.lua b/advtrains/advtrains/pseudoload.lua
index 14db58f..0636d2e 100644
--- a/advtrains/advtrains/pseudoload.lua
+++ b/advtrains/advtrains/pseudoload.lua
@@ -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
diff --git a/advtrains/advtrains/trackplacer.lua b/advtrains/advtrains/trackplacer.lua
index b24103a..e40cb59 100644
--- a/advtrains/advtrains/trackplacer.lua
+++ b/advtrains/advtrains/trackplacer.lua
@@ -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,
})
diff --git a/advtrains/advtrains/tracks.lua b/advtrains/advtrains/tracks.lua
index c20be70..53f5ce7 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 print("[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("[advtrains] get_track_connections couldn't find nodedef for nodename "..(name or "nil")) return 0, 8, 0, 0, 0 end
local noderot=param2
if not param2 then noderot=0 end
- if noderot > 3 then print("[advtrains] get_track_connections: rail has invaild param2 of "..noderot) noderot=0 end
+ if noderot > 3 then atprint("[advtrains] get_track_connections: rail has invaild param2 of "..noderot) noderot=0 end
local tracktype
for k,_ in pairs(nodedef.groups) do
@@ -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).
function advtrains.detector.enter_node(pos, train_id)
local pts = minetest.pos_to_string(advtrains.round_vector_floor_y(pos))
- --print("enterNode "..pts.." "..sid(train_id))
+ --atprint("enterNode "..pts.." "..sid(train_id))
if advtrains.detector.on_node[pts] then
if advtrains.trains[advtrains.detector.on_node[pts]] then
- --print(""..pts.." already occupied")
+ --atprint(""..pts.." already occupied")
return false
else
advtrains.detector.leave_node(pos, advtrains.detector.on_node[pts])
@@ -417,9 +417,9 @@ function advtrains.detector.enter_node(pos, train_id)
end
function advtrains.detector.leave_node(pos, train_id)
local pts = minetest.pos_to_string(advtrains.round_vector_floor_y(pos))
- --print("leaveNode "..pts.." "..sid(train_id))
+ --atprint("leaveNode "..pts.." "..sid(train_id))
if not advtrains.detector.on_node[pts] then
- --print(""..pts.." leave: nothing here")
+ --atprint(""..pts.." leave: nothing here")
return false
end
if advtrains.detector.on_node[pts]==train_id then
@@ -427,7 +427,7 @@ function advtrains.detector.leave_node(pos, train_id)
advtrains.detector.on_node[pts]=nil
else
if advtrains.trains[advtrains.detector.on_node[pts]] then
- --print(""..pts.." occupied by another train")
+ --atprint(""..pts.." occupied by another train")
return false
else
advtrains.detector.leave_node(pos, advtrains.detector.on_node[pts])
@@ -438,21 +438,21 @@ function advtrains.detector.leave_node(pos, train_id)
end
--called immediately before invalidating paths
function advtrains.detector.setup_restore()
- --print("setup_restore")
+ --atprint("setup_restore")
advtrains.detector.on_node_restore = advtrains.detector.on_node
advtrains.detector.on_node = {}
end
--called one step after invalidating paths, when all trains have restored their path and called enter_node for their contents.
function advtrains.detector.finalize_restore()
- --print("finalize_restore")
+ --atprint("finalize_restore")
for pts, train_id in pairs(advtrains.detector.on_node_restore) do
- --print("called leave callback "..pts.." "..train_id)
+ --atprint("called leave callback "..pts.." "..train_id)
advtrains.detector.call_leave_callback(minetest.string_to_pos(pts), train_id)
end
advtrains.detector.on_node_restore = {}
end
function advtrains.detector.call_enter_callback(pos, train_id)
- --print("instructed to call enter calback")
+ --atprint("instructed to call enter calback")
local node = minetest.get_node(pos) --this spares the check if node is nil, it has a name in any case
local mregnode=minetest.registered_nodes[node.name]
@@ -464,7 +464,7 @@ function advtrains.detector.call_enter_callback(pos, train_id)
advtrains.atc.trigger_controller_train_enter(pos, train_id)
end
function advtrains.detector.call_leave_callback(pos, train_id)
- --print("instructed to call leave calback")
+ --atprint("instructed to call leave calback")
local node = minetest.get_node(pos) --this spares the check if node is nil, it has a name in any case
local mregnode=minetest.registered_nodes[node.name]
diff --git a/advtrains/advtrains/trainlogic.lua b/advtrains/advtrains/trainlogic.lua
index 0ad7874..ac870c0 100644
--- a/advtrains/advtrains/trainlogic.lua
+++ b/advtrains/advtrains/trainlogic.lua
@@ -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)
diff --git a/advtrains/advtrains/wagons.lua b/advtrains/advtrains/wagons.lua
index 495f914..8c3cd0a 100644
--- a/advtrains/advtrains/wagons.lua
+++ b/advtrains/advtrains/wagons.lua
@@ -1,6 +1,4 @@
--atan2 counts angles clockwise, minetest does counterclockwise
---local print=function(t) minetest.log("action", t) minetest.chat_send_all(t) end
-local print=function() end
local wagon={
collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
@@ -49,7 +47,7 @@ end
wagon will save only uid in staticdata, no serialized table
]]
function wagon:on_activate(sd_uid, dtime_s)
- print("[advtrains][wagon "..((sd_uid and sd_uid~="" and sd_uid) or "no-id").."] activated")
+ atprint("[advtrains][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
@@ -65,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!
- print("[advtrains][wagon "..((sd_uid and sd_uid~="" and sd_uid) or "no-id").."] duplicate found(ao_id:"..ao_id.."), removing")
+ atprint("[advtrains][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
@@ -79,7 +77,7 @@ end
function wagon:get_staticdata()
if not self:ensure_init() then return end
- print("[advtrains][wagon "..((self.unique_id and self.unique_id~="" and self.unique_id) or "no-id").."]: saving to wagon_save")
+ atprint("[advtrains][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})
@@ -103,7 +101,7 @@ function wagon:init_new_instance(train_id, properties)
end
self:init_shared()
self.initialized=true
- print("init_new_instance "..self.unique_id.." ("..self.train_id..")")
+ atprint("init_new_instance "..self.unique_id.." ("..self.train_id..")")
return self.unique_id
end
function wagon:init_from_wagon_save(uid)
@@ -124,7 +122,7 @@ function wagon:init_from_wagon_save(uid)
self:init_shared()
self.initialized=true
minetest.after(1, function() self:reattach_all() end)
- print("init_from_wagon_save "..self.unique_id.." ("..self.train_id..")")
+ atprint("init_from_wagon_save "..self.unique_id.." ("..self.train_id..")")
advtrains.update_trainpart_properties(self.train_id)
end
function wagon:init_shared()
@@ -211,7 +209,7 @@ function wagon:destroy()
self.custom_on_destroy(self, puncher, time_from_last_punch, tool_capabilities, direction)
end
- print("[advtrains][wagon "..((self.unique_id and self.unique_id~="" and self.unique_id) or "no-id").."]: destroying")
+ atprint("[advtrains][wagon "..((self.unique_id and self.unique_id~="" and self.unique_id) or "no-id").."]: destroying")
self.object:remove()
@@ -230,7 +228,7 @@ function wagon:on_step(dtime)
local pos = self.object:getpos()
if not pos then
- print("["..self.unique_id.."][fatal] missing position (object:getpos() returned nil)")
+ atprint("["..self.unique_id.."][fatal] missing position (object:getpos() returned nil)")
return
end
@@ -238,7 +236,7 @@ function wagon:on_step(dtime)
--is my train still here
if not self.train_id or not self:train() then
- print("[advtrains][wagon "..self.unique_id.."] missing train_id, destroying")
+ atprint("[advtrains][wagon "..self.unique_id.."] missing train_id, destroying")
self.object:remove()
return
elseif not self.initialized then
@@ -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})
self.discouple=le
else
- print("Couldn't spawn DisCouple")
+ atprint("Couldn't spawn DisCouple")
end
end
else
@@ -313,13 +311,13 @@ function wagon:on_step(dtime)
end
local index=advtrains.get_real_path_index(self:train(), self.pos_in_train)
- --print("trainindex "..gp.index.." wagonindex "..index)
+ --atprint("trainindex "..gp.index.." wagonindex "..index)
--position recalculation
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
- --print("[advtrains] object "..self.unique_id.." path end reached!")
+ --atprint("[advtrains] object "..self.unique_id.." path end reached!")
self.object:setvelocity({x=0,y=0,z=0})
return
end
@@ -387,7 +385,7 @@ function wagon:on_step(dtime)
self.old_velocity_vector=velocityvec
self.old_acceleration_vector=accelerationvec
self.old_yaw=yaw
- printbm("wagon step", t)
+ atprintbm("wagon step", t)
end
function advtrains.get_real_path_index(train, pit)
@@ -535,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 print("[advtrains]Ignore at placer position") return itemstack end
+ if not node then atprint("[advtrains]Ignore at placer position") return itemstack end
local nodename=node.name
if(not advtrains.is_track_and_drives_on(nodename, prototype.drives_on)) then
- print("[advtrains]no track here, not placing.")
+ atprint("[advtrains]no track here, not placing.")
return itemstack
end
local conn1=advtrains.get_track_connections(node.name, node.param2)
@@ -546,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
- print("[advtrains]couldn't add_entity, aborting")
+ atprint("[advtrains]couldn't add_entity, aborting")
end
local le=ob:get_luaentity()