Package net.sf.mrailsim.rails

Examples of net.sf.mrailsim.rails.Track


    //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() );
      }
View Full Code Here


   * @param trackId       id of the track where the train should be put on
   * @param nodeIdAtBack  node id the back of the train is looking at
   */
  // TODO: change nodeIdAtBack by nodeItAtFront - where the front looks at
  public void putTrain( Train train, long trackId, long nodeIdAtBack ) {
    Track track = Game.trackManager.getTrack( trackId );
    Node node = Game.nodeManager.getNode( nodeIdAtBack );
   
    try {
      // TODO: remove this in final release and handle correct
      if ( train.getLength() > track.getLength() ) {
        throw new Exception( "train too long" );
      }
      // TODO: remove this in final release and handle correct
      if ( train.getTrainGroup() != null ) {
        throw new Exception( "train already in traingroup" );
      }
    } catch( Exception e ) {
      e.printStackTrace();
      System.exit( 2 );
    }
   
    TrainGroup trainGroup = allocateNewTrainGroup();
   
    trainGroup.add( train );
   
    Node headsNode = null;
    try {
      headsNode = track.getOutgoingNode( node );
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      System.exit( 2 );
    }
   
    train.setPositions(
        new TrackPosition( track, headsNode, 0 ),
        new TrackPosition( track, node, track.getLength() - train.getLength() ) );

    track.trainEnters( train, null );
  }
View Full Code Here

    }
   
    position.increaseDistance( distanceMoving );
   
    while ( position.getDistance() > position.getTrack().getLength() ) {
      Track nextTrack = null;
      Node nextNode = null;
      Track oldTrack = position.getTrack();
      Node oldNode = position.getNode();
     
      try {
        nextNode = position.getTrack().getOutgoingNode( position.getNode() );
        nextTrack = nextNode.getOtherTrack( position.getTrack() );
View Full Code Here

    }

    position.reduceDistance( distanceMoving );
   
    while ( position.getDistance() < 0 ) {
      Track nextTrack = null;
      Node nextNode = null;
      Track oldTrack = position.getTrack();
      Node oldNode = position.getNode();
     
      try {
        nextTrack = oldNode.getOtherTrack( position.getTrack() );
        nextNode = nextTrack.getOutgoingNode( position.getNode() );
View Full Code Here

      Set<Node> nodes = list.keySet();
      Iterator<Node> iterator = nodes.iterator();
     
      while ( iterator.hasNext() ) {
        Node node = iterator.next();
        Track track = list.get( node );
        addLookaheads( amount, track, node );
      }
    }
View Full Code Here

TOP

Related Classes of net.sf.mrailsim.rails.Track

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.