Page 1 of 1

Which train(s) are blocking this train

Posted: Sat Nov 04, 2017 7:23 am
by dgnuff
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.

Re: Which train(s) are blocking this train

Posted: Sat Nov 04, 2017 9:27 am
by eradicator
Having not done anything with trains i still predict the operation you're describing is too expensive, especially when chain signals get involved. And rails don't even need to be continuous to form a block. Also a waiting train might actually be able to continue to drive after repathing if only it's original path is currently blocked.

What exactly is your usecase? Maybe there are better solutions.