private void checkNumnberOfEnginesNeeded() throws BuildFailedException {
  if (_reqNumEngines == 0 || !_train.isBuildConsistEnabled() || Setup.getHorsePowerPerTon() == 0) {
    return;
  }
  addLine(_buildReport,ONE,BLANK_LINE);
  addLine(_buildReport,ONE,MessageFormat.format(Bundle.getMessage("buildDetermineNeeds"),new Object[]{Setup.getHorsePowerPerTon()}));
  Route route=_train.getRoute();
  int hpAvailable=0;
  int extraHpNeeded=0;
  RouteLocation rlNeedHp=null;
  RouteLocation rlStart=_train.getTrainDepartsRouteLocation();
  RouteLocation rlEnd=_train.getTrainTerminatesRouteLocation();
  if (route != null) {
    boolean helper=false;
    for (    RouteLocation rl : route.getLocationsBySequenceList()) {
      if ((_train.getSecondLegOptions() == Train.HELPER_ENGINES && rl == _train.getSecondLegStartLocation()) || (_train.getThirdLegOptions() == Train.HELPER_ENGINES && rl == _train.getThirdLegStartLocation())) {
        addLine(_buildReport,FIVE,MessageFormat.format(Bundle.getMessage("AddHelpersAt"),new Object[]{rl.getName()}));
        helper=true;
      }
      if ((_train.getSecondLegOptions() == Train.HELPER_ENGINES && rl == _train.getSecondLegEndLocation()) || (_train.getThirdLegOptions() == Train.HELPER_ENGINES && rl == _train.getThirdLegEndLocation())) {
        addLine(_buildReport,FIVE,MessageFormat.format(Bundle.getMessage("RemoveHelpersAt"),new Object[]{rl.getName()}));
        helper=false;
      }
      if (helper) {
        continue;
      }
      if (((_train.getSecondLegOptions() & Train.CHANGE_ENGINES) == Train.CHANGE_ENGINES && rl == _train.getSecondLegStartLocation()) || ((_train.getThirdLegOptions() & Train.CHANGE_ENGINES) == Train.CHANGE_ENGINES && rl == _train.getThirdLegStartLocation())) {
        log.debug("Loco change at ({})",rl.getName());
        addLocos(hpAvailable,extraHpNeeded,rlNeedHp,rlStart,rl);
        addLine(_buildReport,THREE,BLANK_LINE);
        rlStart=rl;
        rlNeedHp=null;
        extraHpNeeded=0;
      }
      int weight=rl.getTrainWeight();
      if (weight > 0) {
        double hptMinimum=Setup.getHorsePowerPerTon();
        double hptGrade=(36 * rl.getGrade() / 12);
        int hp=_train.getTrainHorsePower(rl);
        int hpt=hp / weight;
        if (hptGrade > hptMinimum) {
          hptMinimum=hptGrade;
        }
        if (hptMinimum > hpt) {
          int addHp=(int)(hptMinimum * weight - hp);
          if (addHp > extraHpNeeded) {
            hpAvailable=hp;
            extraHpNeeded=addHp;
            rlNeedHp=rl;
          }
          addLine(_buildReport,SEVEN,MessageFormat.format(Bundle.getMessage("buildAddLocosStatus"),new Object[]{weight,hp,rl.getGrade(),hpt,hptMinimum,rl.getName(),rl.getId()}));
          addLine(_buildReport,FIVE,MessageFormat.format(Bundle.getMessage("buildTrainRequiresAddHp"),new Object[]{addHp,rl.getName(),hptMinimum}));
          addLine(_buildReport,SEVEN,BLANK_LINE);
        }
      }
    }
  }
  addLocos(hpAvailable,extraHpNeeded,rlNeedHp,rlStart,rlEnd);
  addLine(_buildReport,SEVEN,MessageFormat.format(Bundle.getMessage("buildDoneAssingEnginesTrain"),new Object[]{_train.getName()}));
  addLine(_buildReport,THREE,BLANK_LINE);
}

private void checkNumnberOfEnginesNeeded ( ) throws BuildFailedException { if ( _reqNumEngines == 0 || ! _train . isBuildConsistEnabled ( ) || Setup . getHorsePowerPerTon ( ) == 0 ) { return ; } addLine ( _buildReport , ONE , BLANK_LINE ) ; addLine ( _buildReport , ONE , MessageFormat . format ( Bundle . getMessage ( "buildDetermineNeeds" ) , new Object [ ] { Setup . getHorsePowerPerTon ( ) } ) ) ; Route route = _train . getRoute ( ) ; int hpAvailable = 0 ; int extraHpNeeded = 0 ; RouteLocation rlNeedHp = null ; RouteLocation rlStart = _train . getTrainDepartsRouteLocation ( ) ; RouteLocation rlEnd = _train . getTrainTerminatesRouteLocation ( ) ; if ( route != null ) { boolean helper = false ; for ( RouteLocation rl : route . getLocationsBySequenceList ( ) ) { if ( ( _train . getSecondLegOptions ( ) == Train . HELPER_ENGINES && rl == _train . getSecondLegStartLocation ( ) ) || ( _train . getThirdLegOptions ( ) == Train . HELPER_ENGINES && rl == _train . getThirdLegStartLocation ( ) ) ) { addLine ( _buildReport , FIVE , MessageFormat . format ( Bundle . getMessage ( "AddHelpersAt" ) , new Object [ ] { rl . getName ( ) } ) ) ; helper = true ; } if ( ( _train . getSecondLegOptions ( ) == Train . HELPER_ENGINES && rl == _train . getSecondLegEndLocation ( ) ) || ( _train . getThirdLegOptions ( ) == Train . HELPER_ENGINES && rl == _train . getThirdLegEndLocation ( ) ) ) { addLine ( _buildReport , FIVE , MessageFormat . format ( Bundle . getMessage ( "RemoveHelpersAt" ) , new Object [ ] { rl . getName ( ) } ) ) ; helper = false ; } if ( helper ) { continue ; } if ( ( ( _train . getSecondLegOptions ( ) & Train . CHANGE_ENGINES ) == Train . CHANGE_ENGINES && rl == _train . getSecondLegStartLocation ( ) ) || ( ( _train . getThirdLegOptions ( ) & Train . CHANGE_ENGINES ) == Train . CHANGE_ENGINES && rl == _train . getThirdLegStartLocation ( ) ) ) { log . debug ( "Loco change at ({})" , rl . getName ( ) ) ; addLocos ( hpAvailable , extraHpNeeded , rlNeedHp , rlStart , rl ) ; addLine ( _buildReport , THREE , BLANK_LINE ) ; rlStart = rl ; rlNeedHp = null ; extraHpNeeded = 0 ; } int weight = rl . getTrainWeight ( ) ; if ( weight > 0 ) { double hptMinimum = Setup . getHorsePowerPerTon ( ) ; double hptGrade = ( 36 * rl . getGrade ( ) / 12 ) ; int hp = _train . getTrainHorsePower ( rl ) ; int hpt = hp / weight ; if ( hptGrade > hptMinimum ) { hptMinimum = hptGrade ; } if ( hptMinimum > hpt ) { int addHp = ( int ) ( hptMinimum * weight - hp ) ; if ( addHp > extraHpNeeded ) { hpAvailable = hp ; extraHpNeeded = addHp ; rlNeedHp = rl ; } addLine ( _buildReport , SEVEN , MessageFormat . format ( Bundle . getMessage ( "buildAddLocosStatus" ) , new Object [ ] { weight , hp , rl . getGrade ( ) , hpt , hptMinimum , rl . getName ( ) , rl . getId ( ) } ) ) ; addLine ( _buildReport , FIVE , MessageFormat . format ( Bundle . getMessage ( "buildTrainRequiresAddHp" ) , new Object [ ] { addHp , rl . getName ( ) , hptMinimum } ) ) ; addLine ( _buildReport , SEVEN , BLANK_LINE ) ; } } } } addLocos ( hpAvailable , extraHpNeeded , rlNeedHp , rlStart , rlEnd ) ; addLine ( _buildReport , SEVEN , MessageFormat . format ( Bundle . getMessage ( "buildDoneAssingEnginesTrain" ) , new Object [ ] { _train . getName ( ) } ) ) ; addLine ( _buildReport , THREE , BLANK_LINE ) ; }
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 .
