aboutsummaryrefslogtreecommitdiff
path: root/advtrains/trainlogic.lua
diff options
context:
space:
mode:
authorGabriel Pérez-Cerezo <gabriel@gpcf.eu>2020-06-14 12:04:13 +0200
committerGabriel Pérez-Cerezo <gabriel@gpcf.eu>2020-06-14 12:04:13 +0200
commit51c0920bc0f35b8406dc3f635d8ae9bed7dfe5d5 (patch)
treef9e5eccbc0005647067d0ca8c4a9813412427c69 /advtrains/trainlogic.lua
parentae79af604cf2209f0630a9613ce10cd198afa569 (diff)
parentb13c7259763aa5c150e25c894a621a59b7bd37d4 (diff)
downloadadvtrains-51c0920bc0f35b8406dc3f635d8ae9bed7dfe5d5.tar.gz
advtrains-51c0920bc0f35b8406dc3f635d8ae9bed7dfe5d5.tar.bz2
advtrains-51c0920bc0f35b8406dc3f635d8ae9bed7dfe5d5.zip
Merge branch 'master' of bananach.space:advtrains
Diffstat (limited to 'advtrains/trainlogic.lua')
-rw-r--r--advtrains/trainlogic.lua24
1 files changed, 24 insertions, 0 deletions
diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua
index 6198c18..1ae96bd 100644
--- a/advtrains/trainlogic.lua
+++ b/advtrains/trainlogic.lua
@@ -627,6 +627,16 @@ local function tnc_call_enter_callback(pos, train_id, train, index)
-- call other registered callbacks
run_callbacks_enter_node(pos, train_id, train, index)
+
+ -- check for split points
+ if mregnode and mregnode.at_conns and #mregnode.at_conns == 3 and train.path_cp[index] == 3 then
+ -- train came from connection 3 of a switch, so it split points.
+ if not train.points_split then
+ train.points_split = {}
+ end
+ train.points_split[advtrains.encode_pos(pos)] = true
+ --atdebug(train_id,"split points at",pos)
+ end
end
local function tnc_call_leave_callback(pos, train_id, train, index)
--atdebug("tnc leave",pos,train_id)
@@ -638,6 +648,20 @@ local function tnc_call_leave_callback(pos, train_id, train, index)
-- call other registered callbacks
run_callbacks_leave_node(pos, train_id, train, index)
+
+ -- split points do not matter anymore. clear them
+ if train.points_split then
+ if train.points_split[advtrains.encode_pos(pos)] then
+ train.points_split[advtrains.encode_pos(pos)] = nil
+ --atdebug(train_id,"has passed split points at",pos)
+ end
+ -- any entries left?
+ for _,_ in pairs(train.points_split) do
+ return
+ end
+ train.points_split = nil
+ end
+ -- WARNING possibly unreachable place!
end
function advtrains.tnc_call_approach_callback(pos, train_id, train, index, lzbdata)