From 571a5cd19b5f9ea1feebbfdef678865039b71370 Mon Sep 17 00:00:00 2001 From: orwell96 Date: Sun, 25 Apr 2021 22:07:44 +0200 Subject: Prevent splitting trains when they're off track (fixes #178) --- advtrains/trainlogic.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua index c812ff7..499144b 100644 --- a/advtrains/trainlogic.lua +++ b/advtrains/trainlogic.lua @@ -1079,6 +1079,12 @@ function advtrains.split_train_at_index(train, index) atwarn("Train",train_id,"is not initialized! Operation aborted!") return end + + -- make sure that the train is fully on track before splitting. May cause problems otherwise + if train.index > train.path_trk_f or train.end_index < train.path_trk_b then + atwarn("Train",train_id,": cannot split train because it is off track!") + return + end local p_index=advtrains.path_get_index_by_offset(train, train.index, - data.pos_in_train + wagon.wagon_span) local pos, connid, frac = advtrains.path_getrestore(train, p_index) -- cgit v1.2.3