Class TrainBuilderCars

Direct Known Subclasses:
TrainBuilder

Contains methods for cars when building a train.
  • Field Details

  • Constructor Details

  • Method Details

    • getCaboose

      protected void getCaboose(String roadCaboose, Engine leadEngine, RouteLocation rl, RouteLocation rld, boolean requiresCaboose) throws BuildFailedException
      Find a caboose if needed at the correct location and add it to the train. If departing staging, all cabooses are added to the train. If there isn't a road name required for the caboose, tries to find a caboose with the same road name as the lead engine.
      Parameters:
      roadCaboose - Optional road name for this car.
      leadEngine - The lead engine for this train. Used to find a caboose with the same road name as the engine.
      rl - Where in the route to pick up this car.
      rld - Where in the route to set out this car.
      requiresCaboose - When true, the train requires a caboose.
      Throws:
      BuildFailedException - If car not found.
    • getCarWithFred

      protected void getCarWithFred(String road, RouteLocation rl, RouteLocation rld) throws BuildFailedException
      Find a car with FRED if needed at the correct location and adds the car to the train. If departing staging, will make sure all cars with FRED are added to the train.
      Parameters:
      road - Optional road name for this car.
      rl - Where in the route to pick up this car.
      rld - Where in the route to set out this car.
      Throws:
      BuildFailedException - If car not found.
    • blockCarsFromStaging

      protected void blockCarsFromStaging() throws BuildFailedException
      Optionally block cars departing staging. No guarantee that cars departing staging can be blocked by destination. By using the pick up location id, this routine tries to find destinations that are willing to accepts all of the cars that were "blocked" together when they were picked up. Rules: The route must allow set outs at the destination. The route must allow the correct number of set outs. The destination must accept all cars in the pick up block.
      Throws:
      BuildFailedException - if blocking fails
    • findDestinationsForCarsFromLocation

      protected void findDestinationsForCarsFromLocation(RouteLocation rl, boolean isSecondPass) throws BuildFailedException
      Attempts to find a destinations for cars departing a specific route location.
      Parameters:
      rl - The route location where cars need destinations.
      isSecondPass - When true this is the second time we've looked at these cars. Used to perform local moves.
      Throws:
      BuildFailedException - if failure
    • addCarToTrain

      protected void addCarToTrain(Car car, RouteLocation rl, RouteLocation rld, Track track)
      Add car to train, and adjust train length and weight
      Parameters:
      car - the car being added to the train
      rl - the departure route location for this car
      rld - the destination route location for this car
      track - the destination track for this car
    • redirectCarsFromAlternateTrack

      Checks to see if cars that are already in the train can be redirected from the alternate track to the spur that really wants the car. Fixes the issue of having cars placed at the alternate when the spur's cars get pulled by this train, but cars were sent to the alternate because the spur was full at the time it was tested.
      Returns:
      true if one or more cars were redirected
      Throws:
      BuildFailedException - if coding issue