I've managed to work out logic for how to walk along railways and -- with an excessive amount of hard-coding -- where signals might be for any given chunk of rail. Since the presence of junctions that aren't even related to the same piece of track can affect legal signal placement without creating a collision, this particular case is hard to code for without more repeated get_connected_rail calls.
It would be handy to -- given a particular section of a single rail-entity -- get all of the legal positions for a signal. For my purpose I only really need a position, but something like this would be a useful format:
Code: Select all
{
[defines.rail_direction_front] = { -- Signals for trains moving towards the 'front' of the track -- i.e. eastbound for horizontal straight rail
{ index=1, position={...}, direction=... }
-- no entries for signals that can't currently be placed due to rail limitations.
-- (I'm placing ghosts though, so trees/rocks shouldn't prevent an entry from being present
}