aboutsummaryrefslogtreecommitdiff
path: root/advtrains/advtrains/helpers.lua
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains/advtrains/helpers.lua')
-rw-r--r--advtrains/advtrains/helpers.lua41
1 files changed, 20 insertions, 21 deletions
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)