aboutsummaryrefslogtreecommitdiff
path: root/advtrains/tracks.lua
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains/tracks.lua')
-rw-r--r--advtrains/tracks.lua94
1 files changed, 0 insertions, 94 deletions
diff --git a/advtrains/tracks.lua b/advtrains/tracks.lua
index f31fef6..eefff66 100644
--- a/advtrains/tracks.lua
+++ b/advtrains/tracks.lua
@@ -389,100 +389,6 @@ function advtrains.get_track_connections(name, param2)
return advtrains.rotate_conn_by(nodedef.at_conns, noderot*AT_CMAX/4), (nodedef.at_rail_y or 0), tracktype
end
---detector code
---holds a table with nodes on which trains are on.
-
-advtrains.detector = {}
-advtrains.detector.on_node = {}
-
---Returns true when position is occupied by a train other than train_id, false when occupied by the same train as train_id and nil in case there's no train at all
-function advtrains.detector.occupied(pos, train_id)
- local ppos=advtrains.round_vector_floor_y(pos)
- local pts=minetest.pos_to_string(ppos)
- local s=advtrains.detector.on_node[pts]
- if not s then return nil end
- if s==train_id then return false end
- --in case s is a table, it's always occupied by another train
- return true
-end
--- If given a train id as second argument, this is considered as 'not there'.
--- Returns the train id of (one of, nondeterministic) the trains at this position
-function advtrains.detector.get(pos, train_id)
- local ppos=advtrains.round_vector_floor_y(pos)
- local pts=minetest.pos_to_string(ppos)
- local s=advtrains.detector.on_node[pts]
- if not s then return nil end
- if type(s)=="table" then
- for _,t in ipairs(s) do
- if t~=train_id then return t end
- end
- return nil
- end
- return s
-end
-
-function advtrains.detector.enter_node(pos, train_id)
- advtrains.detector.stay_node(pos, train_id)
- local ppos=advtrains.round_vector_floor_y(pos)
- advtrains.detector.call_enter_callback(ppos, train_id)
-end
-function advtrains.detector.leave_node(pos, train_id)
- local ppos=advtrains.round_vector_floor_y(pos)
- local pts=minetest.pos_to_string(ppos)
- local s=advtrains.detector.on_node[pts]
- if type(s)=="table" then
- local i
- for j,t in ipairs(s) do
- if t==train_id then i=j end
- end
- if not i then return end
- s=table.remove(s,i)
- if #s==0 then
- s=nil
- elseif #s==1 then
- s=s[1]
- end
- advtrains.detector.on_node[pts]=s
- else
- advtrains.detector.on_node[pts]=nil
- end
- advtrains.detector.call_leave_callback(ppos, train_id)
-end
-function advtrains.detector.stay_node(pos, train_id)
- local ppos=advtrains.round_vector_floor_y(pos)
- local pts=minetest.pos_to_string(ppos)
-
- local s=advtrains.detector.on_node[pts]
- if not s then
- advtrains.detector.on_node[pts]=train_id
- elseif type(s)=="string" then
- advtrains.detector.on_node[pts]={s, train_id}
- elseif type(s)=="table" then
- advtrains.detector.on_node[pts]=table.insert(s, train_id)
- end
-end
-
-
-
-function advtrains.detector.call_enter_callback(pos, train_id)
- --atprint("instructed to call enter calback")
-
- local node = advtrains.ndb.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]
- if mregnode and mregnode.advtrains and mregnode.advtrains.on_train_enter then
- mregnode.advtrains.on_train_enter(pos, train_id)
- end
-end
-function advtrains.detector.call_leave_callback(pos, train_id)
- --atprint("instructed to call leave calback")
-
- local node = advtrains.ndb.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]
- if mregnode and mregnode.advtrains and mregnode.advtrains.on_train_leave then
- mregnode.advtrains.on_train_leave(pos, train_id)
- end
-end
-
-- slope placer. Defined in register_tracks.
--crafted with rail and gravel
local sl={}