aboutsummaryrefslogtreecommitdiff
path: root/advtrains/trainlogic.lua
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2019-04-16 09:16:44 +0200
committerorwell96 <orwell@bleipb.de>2019-04-16 09:16:44 +0200
commitea33ad9de0a77887f0181d8581568fe79d14255e (patch)
tree7c2fa83878777c921ace816a1954d316c7f84a1e /advtrains/trainlogic.lua
parentc50224e05cfc7a37b9181565024c972446a720ca (diff)
downloadadvtrains-ea33ad9de0a77887f0181d8581568fe79d14255e.tar.gz
advtrains-ea33ad9de0a77887f0181d8581568fe79d14255e.tar.bz2
advtrains-ea33ad9de0a77887f0181d8581568fe79d14255e.zip
Move LZB system to core and unify approach callback mechanism
Diffstat (limited to 'advtrains/trainlogic.lua')
-rw-r--r--advtrains/trainlogic.lua24
1 files changed, 22 insertions, 2 deletions
diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua
index 523e51d..ce9ec8b 100644
--- a/advtrains/trainlogic.lua
+++ b/advtrains/trainlogic.lua
@@ -585,9 +585,9 @@ local function mknodecallback(name)
table.insert(callt, func)
end
end
- return callt, function(pos, id, train, index)
+ return callt, function(pos, id, train, index, paramx1, paramx2, paramx3)
for _,f in ipairs(callt) do
- f(pos, id, train, index)
+ f(pos, id, train, index, paramx1, paramx2, paramx3)
end
end
end
@@ -597,6 +597,14 @@ end
local callbacks_enter_node, run_callbacks_enter_node = mknodecallback("enter")
local callbacks_leave_node, run_callbacks_leave_node = mknodecallback("leave")
+-- Node callback for approaching
+-- Might be called multiple times, whenever path is recalculated
+-- signature is function(pos, id, train, index, lzbdata)
+-- lzbdata: arbitrary data (shared between all callbacks), deleted when LZB is restarted.
+-- These callbacks are called in order of distance as train progresses along tracks, so lzbdata can be used to
+-- keep track of a train's state once it passes this point
+local callbacks_approach_node, run_callbacks_approach_node = mknodecallback("approach")
+
local function tnc_call_enter_callback(pos, train_id, train, index)
--atdebug("tnc enter",pos,train_id)
@@ -621,6 +629,18 @@ local function tnc_call_leave_callback(pos, train_id, train, index)
run_callbacks_leave_node(pos, train_id, train, index)
end
+function advtrains.tnc_call_approach_callback(pos, train_id, train, index, lzbdata)
+ --atdebug("tnc approach",pos,train_id, lzbdata)
+ 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_approach then
+ mregnode.advtrains.on_train_approach(pos, train_id, train, index, lzbdata)
+ end
+
+ -- call other registered callbacks
+ run_callbacks_approach_node(pos, train_id, train, index, lzbdata)
+end
+
advtrains.te_register_on_new_path(function(id, train)
train.tnc = {