aboutsummaryrefslogtreecommitdiff
path: root/advtrains/trainlogic.lua
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2020-06-10 20:56:35 +0200
committerorwell96 <orwell@bleipb.de>2020-06-10 20:56:35 +0200
commitb13c7259763aa5c150e25c894a621a59b7bd37d4 (patch)
treefac9cd110c969ba5ca427dd42f19296402643355 /advtrains/trainlogic.lua
parentd61c2145a0f28438b0f85345bc7808ce0b6161c6 (diff)
downloadadvtrains-b13c7259763aa5c150e25c894a621a59b7bd37d4.tar.gz
advtrains-b13c7259763aa5c150e25c894a621a59b7bd37d4.tar.bz2
advtrains-b13c7259763aa5c150e25c894a621a59b7bd37d4.zip
Workaround to handle split points (dt. aufgefahrene Weichen), fixing H#77
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)