- When powered rail is placed, create a hidden electric pole at the same position.
- Store rail and pole in a table in global, indexed by the rail's unit_number.
- Use pole.disconnect_neighbour() to remove all connections from the pole -- they shouldn't connect to random poles in the vicinity.
- Check for powered rails going left, straight, or right on the rail tracks back side. If there is another powered rail, get its hidden pole and make a connection.
- Do the same thing for the front side of the current rail.
Now I've noticed that this does not always work: The screenshot (with hidden poles revealed for debugging) shows that the two vertical tracks are isolated networks (ID 11 and 12). The lower horizontal track (ID 10) crosses both vertical tracks without making a connection. However, the upper horizontal track (ID 11 as well) somehow connects to the left vertical track (but is isolated from the right vertical track).
I suppose I don't quite understand how electric connections really work. The hidden poles have an empty collision mask, so they can be placed in the same position. Also, I make connections to distinct entities, even though these entities may be in the same spot. Is that correct, or will two wires that end at the same position (even if on different poles) be automatically connected? Or is there anything else that I've just overlooked so far?