If this is in development please reply and disregard!
(TL:DR look at how factorio or Chris Sawyers Locomotion does it and you know what i'm suggesting here)
Trains should be changed so that they can't pass through eachother and require block sectioning if they are using the same stretch of track.
How it would work:
If a train collides with another train the easiest action would be that of the anti derail feature. (train stopping dead at the end of a rail regardless of speed) where the colliding train would have its speed zeroed and couldn't continue for 10-15 seconds. This makes it so trains can't pass through eachother and would eliminate allot of bugs associated with this feature. (As well... the feature of train ghosting would not exist anymore)
Add Block Section lights.
Okay TL:DR go a paragraph down please.
Explaining what block sectioning is, If Multiple trains share a same expanse of rail, Block sectioning would prohibit train AI from accessing a stretch of track between two lights (This is called a Block) if the block a train is approaching is full it would halt at the light and wait for the block to clear before proceeding into the block. Only one train can occupy a block section at a time. Block sections Depending on which way the light is facing allows for either omni directional track (Their would be two lights facing on opposite directions in the same place) Or Single Direction track (Their would be only one light facing in the direction the track is configured to like a one way street) This would allow multiple trains to share the same line without crashing into one another.
Adding block sectioning would solve the problem of trains crashing into eachother and trains getting jumbled and messed up by rogue track switching as the train is in mid transition on the switch. As the switch would only operate for the train Entering the block section. As well as solve the problem of weird bugs as one train ghosts through another.
-Block sectioning would only work for AI and players may choose to ignore the lights and proceed into the block section that may have another train within (and face any potential consequence that may transpire as a result.)
-Players will have to place the lights along the track (The same mechanic that permits splitters to be placed on belts could be applied here. Also using the same sprite the train switches use but instead a light post can be placed on either side) placing a single light in the direction you wish trains to travel on will make the track one direction. Where placing a second light on the same part will allow trains approaching from both sides to pass through.
-The Lights would be the standard RED, GREEN format, red being the block is occupied and the train may not proceed, and green being the block is empty and a train may enter the block, if two trains want to enter the block at the same time have it work as a round robin system, first to the post, or both, permitting one train to proceed while the other waits.