Class TrainBuilderEngines

Direct Known Subclasses:
TrainBuilderCars

Contains methods for engines when building a train.
  • Constructor Details

  • Method Details

    • getAndRemoveEnginesFromList

      protected void getAndRemoveEnginesFromList()
      Builds a list of possible engines for this train.
    • getEngines

      protected boolean getEngines(String requestedEngines, String model, String road, RouteLocation rl, RouteLocation rld) throws BuildFailedException
      Throws:
      BuildFailedException
    • getEngines

      protected boolean getEngines(String requestedEngines, String model, 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
    • addEnginesToTrain

      protected void addEnginesToTrain() throws BuildFailedException
      Adds engines to the train starting at the first location in the train's route. Note that engines from staging are already part of the train. There can be up to two engine swaps in a train's route.
      Throws:
      BuildFailedException - if required engines can't be added to train.
    • getConsist

      protected boolean getConsist(String reqNumEngines, String model, String road, RouteLocation rl, RouteLocation rld) throws BuildFailedException
      Throws:
      BuildFailedException
    • showEnginesByLocation

      protected void showEnginesByLocation()
    • 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
    • checkEngineHP

      protected void checkEngineHP() throws BuildFailedException
      Checks to see if the engine or consist assigned to the train has the appropriate HP. If the train's HP requirements are significantly higher or lower than the engine that was assigned, the program will search for a more appropriate engine or consist, and assign that engine or consist to the train. The HP calculation is based on a minimum train speed of 36 MPH. The formula HPT x 12 / % Grade = Speed, is used to determine the horsepower required. Speed is fixed at 36 MPH. For example a 1% grade requires a minimum of 3 HPT. Disabled for trains departing staging.
      Throws:
      BuildFailedException - if coding error.
    • getNewEngine

      protected void getNewEngine(int hpNeeded, Engine leadEngine, String model, 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
    • 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
    • checkNumnberOfEnginesNeededHPT

      Checks to see if additional engines are needed for the train based on the train's calculated tonnage. Minimum speed for the train is fixed at 36 MPH. The formula HPT x 12 / % Grade = Speed, is used to determine the horsepower needed. For example a 1% grade requires a minimum of 3 HPT. Ignored when departing staging
      Throws:
      BuildFailedException - if build failure
    • removeEngineFromTrain

      protected void removeEngineFromTrain(Engine engine)