From 41568a3e2ef438baa90c8d41045b81cf7bb15e17 Mon Sep 17 00:00:00 2001 From: orwell96 Date: Sat, 2 Jan 2021 19:57:10 +0100 Subject: luaatc: don't fail train event when train has already passed the rail at event time --- advtrains_luaautomation/atc_rail.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'advtrains_luaautomation') 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 -- cgit v1.2.3