Class TrainBuilderBase

    • Method Detail

      • showBuildReportInfo

        protected void showBuildReportInfo()
        Creates the build report header information lines. Build report date, JMRI version, train schedule, build report display levels, setup comment.
      • showTrainBuildOptions

        protected void showTrainBuildOptions()
        show train build options when in detailed mode
      • showTrainServices

        protected void showTrainServices()
        Adds to the build report what the train will service. Road and owner names, built dates, and engine types.
      • showAndInitializeTrainRoute

        protected void showAndInitializeTrainRoute()
                                            throws BuildFailedException
        Show and initialize the train's route. Determines the number of car moves requested for this train. Also adjust the number of car moves if the random car moves option was selected.
        Throws:
        BuildFailedException - if random variable isn't an integer
      • showTrainRequirements

        protected void showTrainRequirements()
        Show how many engines are required for this train, and if a certain road name for the engine is requested. Show if there are any engine changes in the route, or if helper engines are needed. There can be up to 2 engine changes or helper requests. Show if caboose or FRED is needed for train, and if there's a road name requested. There can be up to 2 caboose changes in the route.
      • setDepartureTrack

        protected void setDepartureTrack​(Track departStageTrack)
        Will also set the termination track if returning to staging
        Parameters:
        departStageTrack - departure track from staging
      • promptFromStagingDialog

        protected Track promptFromStagingDialog()
        Ask which staging track the train is to depart on.
        Returns:
        The departure track the user selected.
      • promptToStagingDialog

        protected Track promptToStagingDialog()
        Ask which staging track the train is to terminate on.
        Returns:
        The termination track selected by the user.
      • saveCarFinalDestinations

        protected void saveCarFinalDestinations()
        Save the car's final destination and schedule id in case of train reset
      • getLocationWithMaximumMoves

        protected RouteLocation getLocationWithMaximumMoves​(java.util.List<RouteLocation> blockRouteList,
                                                            java.lang.String blockId)
        Returns the routeLocation with the most available moves. Used for blocking a train out of staging.
        Parameters:
        blockRouteList - The route for this train, modified by deleting RouteLocations serviced
        blockId - Where these cars were originally picked up from.
        Returns:
        The location in the route with the most available moves.
      • makeAdjustmentsIfDepartingStaging

        protected void makeAdjustmentsIfDepartingStaging()
        Temporally remove cars from staging track if train returning to the same staging track to free up track space.
      • isCarStuckStaging

        protected boolean isCarStuckStaging()
        Used to determine if a car on a staging track doesn't have a destination or train
        Returns:
        true if at least one car doesn't have a destination or train. false if all cars have a destination.
      • 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
      • checkPickUpTrainDirection

        protected boolean checkPickUpTrainDirection​(RouteLocation rl)
        Used to report a problem picking up the rolling stock due to train direction.
        Parameters:
        rl - The route location
        Returns:
        true if there isn't a problem
      • checkTrainLength

        protected boolean checkTrainLength​(Car car,
                                           RouteLocation rl,
                                           RouteLocation rld)
        Checks to see if train length would be exceeded if this car was added to the train.
        Parameters:
        car - the car in question
        rl - the departure route location for this car
        rld - the destination route location for this car
        Returns:
        true if car can be added to train
      • checkTrainCanDrop

        protected boolean checkTrainCanDrop​(Car car,
                                            Track track)
        Determinate if car can be dropped by this train to the track specified.
        Parameters:
        car - the car.
        track - the destination track.
        Returns:
        true if able to drop.
      • checkDepartureStagingTrack

        protected boolean checkDepartureStagingTrack​(Track departStageTrack)
        Check departure staging track to see if engines and cars are available to a new train. Also confirms that the engine and car type, load, road, etc. are accepted by the train.
        Parameters:
        departStageTrack - The staging track
        Returns:
        true is there are engines and cars available.
      • checkStagingPool

        protected boolean checkStagingPool​(Track departStageTrack)
        Used to determine if staging track in a pool is the appropriated one for departure. Staging tracks in a pool can operate in one of two ways FIFO or LIFO. In FIFO mode (First in First out), the program selects a staging track from the pool that has cars with the earliest arrival date. In LIFO mode (Last in First out), the program selects a staging track from the pool that has cars with the latest arrival date.
        Parameters:
        departStageTrack - the track being tested
        Returns:
        true if departure on this staging track is possible
      • checkTerminateStagingTrack

        protected boolean checkTerminateStagingTrack​(Track terminateStageTrack)
        Checks to see if staging track can accept train.
        Parameters:
        terminateStageTrack - the staging track
        Returns:
        true if staging track is empty, not reserved, and accepts car and engine types, roads, and loads.
      • getTracksAtDestination

        protected java.util.List<TrackgetTracksAtDestination​(Car car,
                                                               RouteLocation rld)
        Returns a list containing two tracks. The 1st track found for the car, the 2nd track is the car's final destination if an alternate track was used for the car. 2nd track can be null.
        Parameters:
        car - The car needing a destination track
        rld - the RouteLocation destination
        Returns:
        List containing up to two tracks. No tracks if none found.
      • checkForEarlierDrop

        protected RouteLocation checkForEarlierDrop​(Car car,
                                                    Track trackTemp,
                                                    RouteLocation rld,
                                                    int start,
                                                    int routeEnd)
        Used to determine if car could be set out at earlier location in the train's route.
        Parameters:
        car - The car
        trackTemp - The destination track for this car
        rld - Where in the route the destination track was found
        start - Where to begin the check
        routeEnd - Where to stop the check
        Returns:
        The best RouteLocation to drop off the car
      • checkThroughCarsAllowed

        protected boolean checkThroughCarsAllowed​(Car car,
                                                  java.lang.String destinationName)
        Returns true is cars are allowed to travel from origin to terminal
        Parameters:
        car - The car
        destinationName - Destination name for this car
        Returns:
        true if through cars are allowed. false if not.
      • redirectCarsFromAlternateTrack

        protected boolean redirectCarsFromAlternateTrack()
                                                  throws BuildFailedException
        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
      • showCarsNotMoved

        protected void showCarsNotMoved​(RouteLocation rl)
        report any cars left at route location
        Parameters:
        rl - route location
      • showCarsNotRoutable

        protected void showCarsNotRoutable()
        Lists cars that couldn't be routed.
      • removeCarsFromStaging

        protected void removeCarsFromStaging()
        build has failed due to cars in staging not having destinations this routine removes those cars from the staging track by user request.
      • addEnginesBasedHPT

        protected void addEnginesBasedHPT​(int hpAvailable,
                                          int extraHpNeeded,
                                          RouteLocation rlNeedHp,
                                          RouteLocation rl,
                                          RouteLocation rld)
                                   throws BuildFailedException
        Adds engines to the train if needed based on HPT. Note that the engine additional weight isn't considered in this method so HP requirements can be lower compared to the original calculation which did include the weight of the engines.
        Parameters:
        hpAvailable - the engine hp already assigned to the train for this leg
        extraHpNeeded - the additional hp needed
        rlNeedHp - where in the route the additional hp is needed
        rl - the start of the leg
        rld - the end of the leg
        Throws:
        BuildFailedException - if unable to add engines to train
      • getNumberEngines

        protected int getNumberEngines​(java.lang.String requestEngines)
        Used to determine the number of engines requested by the user.
        Parameters:
        requestEngines - Can be a number, AUTO or AUTO HPT.
        Returns:
        the number of engines requested by user.
      • setEngineDestination

        protected boolean setEngineDestination​(Engine engine,
                                               RouteLocation rl,
                                               RouteLocation rld)
        Sets the destination track for an engine and assigns it to the train.
        Parameters:
        engine - The engine to be added to train
        rl - Departure route location
        rld - Destination route location
        Returns:
        true if destination track found and set
      • getEngines

        protected boolean getEngines​(java.lang.String requestedEngines,
                                     java.lang.String model,
                                     java.lang.String road,
                                     RouteLocation rl,
                                     RouteLocation rld,
                                     boolean useBunit)
                              throws BuildFailedException
        Get the engines for this train at a route location. If departing from staging engines must come from that track. Finds the required number of engines in a consist, or if the option to build from single locos, builds a consist for the user. When true, engines successfully added to train for the leg requested.
        Parameters:
        requestedEngines - Requested number of Engines, can be number, AUTO or AUTO HPT
        model - Optional model name for the engines
        road - Optional road name for the engines
        rl - Departure route location for the engines
        rld - Destination route location for the engines
        useBunit - true if B unit engine is allowed
        Returns:
        true if correct number of engines found.
        Throws:
        BuildFailedException - if coding issue
      • getNewEngine

        protected void getNewEngine​(int hpNeeded,
                                    Engine leadEngine,
                                    java.lang.String model,
                                    java.lang.String road)
                             throws BuildFailedException
        Removes engine from train and attempts to replace it with engine or consist that meets the HP requirements of the train.
        Parameters:
        hpNeeded - How much hp is needed
        leadEngine - The lead engine for this leg
        model - The engine's model
        road - The engine's road
        Throws:
        BuildFailedException - if new engine not found