Which train(s) are blocking this train
Posted: Sat Nov 04, 2017 7:23 am
Suppose I have a LuaTrain, and its train.state == defines.train_state.wait_signal. This means that there are one or more other LuaTrains that are blocking it. Is there a way in a mod to find those LuaTrains. For my use case, finding any one of them would be sufficient, but the more general solution would be to get them all in an array of LuaTrain objects.
The best I can come up with is walking up the track starting from LuaTrain.front_track but I cannot find a way to determine if a rail section I encounter on this walk is occupied by another LuaTrain.
I realize that crossing intersections make this complex. If my train is blocked at a signal because the track it wants to travel on is clear, but there is a train on a crossing that is prevrnting it from moving, should that train be part of the returned array? Again for my use case that will never happen, but it is an issue to consider for the general case.
The best I can come up with is walking up the track starting from LuaTrain.front_track but I cannot find a way to determine if a rail section I encounter on this walk is occupied by another LuaTrain.
I realize that crossing intersections make this complex. If my train is blocked at a signal because the track it wants to travel on is clear, but there is a train on a crossing that is prevrnting it from moving, should that train be part of the returned array? Again for my use case that will never happen, but it is an issue to consider for the general case.