aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2021-01-02 19:57:10 +0100
committerorwell96 <orwell@bleipb.de>2021-02-10 16:39:46 +0100
commit41568a3e2ef438baa90c8d41045b81cf7bb15e17 (patch)
treeaaad725623349ea1d4152ee49b49fbca091603ab
parent0cef88ba7fec8d3ffefcd48671923b15255500f5 (diff)
downloadadvtrains-41568a3e2ef438baa90c8d41045b81cf7bb15e17.tar.gz
advtrains-41568a3e2ef438baa90c8d41045b81cf7bb15e17.tar.bz2
advtrains-41568a3e2ef438baa90c8d41045b81cf7bb15e17.zip
luaatc: don't fail train event when train has already passed the rail at event time
-rw-r--r--advtrains_luaautomation/atc_rail.lua7
1 files changed, 6 insertions, 1 deletions
diff --git a/advtrains_luaautomation/atc_rail.lua b/advtrains_luaautomation/atc_rail.lua
index 6ce323d..bdb4bcf 100644
--- a/advtrains_luaautomation/atc_rail.lua
+++ b/advtrains_luaautomation/atc_rail.lua
@@ -28,6 +28,11 @@ function r.fire_event(pos, evtdata, appr_internal)
--prepare ingame API for ATC. Regenerate each time since pos needs to be known
--If no train, then return false.
local train_id=advtrains.get_train_at_pos(pos)
+ -- try to get the train from the event data
+ -- This workaround is required because the callback is one step delayed, and a fast train may have already left the node.
+ if not train_id then
+ train_id = evtdata._train_id
+ end
local train, atc_arrow, tvel
if train_id then train=advtrains.trains[train_id] end
@@ -197,7 +202,7 @@ advtrains.register_tracks("default", {
advtrains = {
on_train_enter = function(pos, train_id)
--do async. Event is fired in train steps
- atlatc.interrupt.add(0, pos, {type="train", train=true, id=train_id})
+ atlatc.interrupt.add(0, pos, {type="train", train=true, id=train_id, _train_id = train_id})
end,
on_train_approach = function(pos, train_id, train, index, has_entered, lzbdata)
-- Insert an event only if the rail indicated that it supports approach callbacks