//TODO: Really necessary?
}
private void newTrackEntered( Track newTrack, Node node ) {
// TODO Look more tracks ahead!
Track nextTrack = null;
Node nextNode = null;
try {
nextNode = newTrack.getOutgoingNode( node );
nextTrack = nextNode.getOtherTrack( newTrack );
} catch (Exception e) {
// TODO Handle right
e.printStackTrace();
System.exit( 2 );
}
if ( nextTrack == null ) {
// TODO: Handle better
System.err.println( "nextTrack is null in newTrackEntered(...), train #" + id + " track #" + newTrack.getId() + "." );
System.exit( 2 );
}
if ( nextNode == null ) {
// TODO: Handle better
System.err.println( "nextNode is null in newTrackEntered(...), train #" + id + " track #" + newTrack.getId() + "." );
System.exit( 2 );
}
// TODO: Only check for signals when train is the first one in train group or the last one!
// TODO: move code to method checkForSignalsInSight(...) ?
for ( PreSignal signal : nextTrack.getPreSignals() ) {
if ( signal.isBoundToNode( nextNode ) ) {
Logger.log( Logger.Component.TRAIN, Logger.Level.INFORMATION, "Train #" + id + " sees pre signal #" +
signal.getId() + " showing " + signal.getDisplay() + "." );
drivingControl.preSignalAhead( signal.getDisplay(), signal.getDistanceToMainSignal() );
}
}
for ( MainSignal signal : nextTrack.getMainSignals() ) {
if ( signal.isBoundToNode( nextNode ) ) {
Logger.log( Logger.Component.TRAIN, Logger.Level.INFORMATION, "Train #" + id + " sees main signal #" +
signal.getId() + " showing " + signal.getDisplay() + "." );
drivingControl.mainSignalAhead( signal.getDisplay() );
}