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.
Which train(s) are blocking this train
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Which train(s) are blocking this train
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.
What exactly is your usecase? Maybe there are better solutions.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.