Search in sources :

Example 51 with RouteLocation

use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.

the class Train method getTrainLength.

/**
     * Gets the train's length at the route location specified
     *
     * @param routeLocation The route location
     * @return The train length at the route location
     */
public int getTrainLength(RouteLocation routeLocation) {
    int length = 0;
    Route route = getRoute();
    if (route != null) {
        for (RouteLocation rl : route.getLocationsBySequenceList()) {
            for (RollingStock rs : EngineManager.instance().getList(this)) {
                if (rs.getRouteLocation() == rl) {
                    length += rs.getTotalLength();
                }
                if (rs.getRouteDestination() == rl) {
                    length += -rs.getTotalLength();
                }
            }
            for (RollingStock rs : CarManager.instance().getList(this)) {
                if (rs.getRouteLocation() == rl) {
                    length += rs.getTotalLength();
                }
                if (rs.getRouteDestination() == rl) {
                    length += -rs.getTotalLength();
                }
            }
            if (rl == routeLocation) {
                break;
            }
        }
    }
    return length;
}
Also used : RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Route(jmri.jmrit.operations.routes.Route) RollingStock(jmri.jmrit.operations.rollingstock.RollingStock)

Example 52 with RouteLocation

use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.

the class TrainBuilder method blockByLocationMoves.

/**
     * Blocks cars out of staging by assigning the largest blocks of cars to
     * locations requesting the most moves.
     */
private void blockByLocationMoves() throws BuildFailedException {
    List<RouteLocation> routeList = _train.getRoute().getLocationsBySequenceList();
    for (RouteLocation rl : routeList) {
        // start at the second location in the route to begin blocking
        if (rl == _train.getTrainDepartsRouteLocation()) {
            continue;
        }
        int possibleMoves = rl.getMaxCarMoves() - rl.getCarMoves();
        if (rl.isDropAllowed() && possibleMoves > 0) {
            addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("blockLocationHasMoves"), new Object[] { rl.getName(), possibleMoves }));
        }
    }
    // now block out cars, send the largest block of cars to the locations requesting the greatest number of moves
    RouteLocation rl = _train.getTrainDepartsRouteLocation();
    while (true) {
        // get the id of the largest block of cars
        String blockId = getLargestBlock();
        if (blockId.equals("") || _numOfBlocks.get(blockId) == 1) {
            // done
            break;
        }
        // get the location with the greatest number of moves
        RouteLocation rld = getLocationWithMaximumMoves(routeList, blockId);
        if (rld == null) {
            // done
            break;
        }
        // check to see if there are enough moves for all of the cars departing staging
        if (rld.getMaxCarMoves() > _numOfBlocks.get(blockId)) {
            // remove the largest block and maximum moves RouteLocation from the lists
            _numOfBlocks.remove(blockId);
            // block 0 cars have never left staging.
            if (blockId.equals("0")) {
                continue;
            }
            routeList.remove(rld);
            Location loc = locationManager.getLocationById(blockId);
            Location setOutLoc = rld.getLocation();
            if (loc != null && setOutLoc != null && checkDropTrainDirection(rld)) {
                for (_carIndex = 0; _carIndex < _carList.size(); _carIndex++) {
                    Car car = _carList.get(_carIndex);
                    if (car.getTrack() == _departStageTrack && car.getLastLocationId().equals(blockId)) {
                        if (car.getDestination() != null) {
                            addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("blockNotAbleDest"), new Object[] { car.toString(), car.getDestinationName() }));
                            // can't block this car
                            continue;
                        }
                        if (car.getFinalDestination() != null) {
                            addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("blockNotAbleFinalDest"), new Object[] { car.toString(), car.getFinalDestination().getName() }));
                            // can't block this car
                            continue;
                        }
                        if (!car.getLoadName().equals(CarLoads.instance().getDefaultEmptyName()) && !car.getLoadName().equals(CarLoads.instance().getDefaultLoadName())) {
                            addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("blockNotAbleCustomLoad"), new Object[] { car.toString(), car.getLoadName() }));
                            // can't block this car
                            continue;
                        }
                        if (car.getLoadName().equals(CarLoads.instance().getDefaultEmptyName()) && (_departStageTrack.isAddCustomLoadsEnabled() || _departStageTrack.isAddCustomLoadsAnySpurEnabled() || _departStageTrack.isAddCustomLoadsAnyStagingTrackEnabled())) {
                            addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("blockNotAbleCarTypeGenerate"), new Object[] { car.toString(), car.getLoadName() }));
                            // can't block this car
                            continue;
                        }
                        addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("blockingCar"), new Object[] { car.toString(), loc.getName(), rld.getName() }));
                        if (!findDestinationAndTrack(car, rl, rld)) {
                            addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("blockNotAbleCarType"), new Object[] { car.toString(), rld.getName(), car.getTypeName() }));
                        }
                    }
                }
            }
        } else {
            addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("blockDestNotEnoughMoves"), new Object[] { rld.getName(), blockId }));
            // block is too large for any stop along this train's route
            _numOfBlocks.remove(blockId);
        }
    }
}
Also used : Car(jmri.jmrit.operations.rollingstock.cars.Car) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 53 with RouteLocation

use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.

the class TrainBuilder method findNewEngine.

/*
     * Removes engine from train and attempts to replace it with one that meets
     * the HP requirements of the train.
     */
private void findNewEngine(int hpNeeded, Engine leadEngine) throws BuildFailedException {
    // save lead engine's rl, and rld
    RouteLocation rl = leadEngine.getRouteLocation();
    RouteLocation rld = leadEngine.getRouteDestination();
    removeRollingStockFromTrain(leadEngine);
    // put engine back into the pool
    _engineList.add(0, leadEngine);
    _train.setLeadEngine(null);
    if (hpNeeded <= 0) {
        // the minimum HP
        hpNeeded = 50;
    }
    int hpMax = hpNeeded;
    // largest single engine HP known today is less than 15,000
    hpLoop: while (hpMax < 20000) {
        // start off looking for an engine with no more than 50% extra HP
        hpMax += hpNeeded / 2;
        log.debug("Max hp {}", hpMax);
        for (Engine engine : _engineList) {
            if (engine.getLocation() != _train.getTrainDepartsRouteLocation().getLocation())
                continue;
            int engineHp = engine.getHpInteger();
            if (engineHp > hpNeeded && engineHp <= hpMax) {
                addLine(_buildReport, FIVE, MessageFormat.format(Bundle.getMessage("buildLocoHasRequiredHp"), new Object[] { engine.toString(), engine.getHp(), hpNeeded }));
                if (setLocoDestination(engine, rl, rld, null)) {
                    break hpLoop;
                }
            }
        }
    }
    if (_train.getLeadEngine() == null && !_train.isBuildConsistEnabled()) {
        throw new BuildFailedException(Bundle.getMessage("buildErrorEngHp"));
    }
}
Also used : RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Engine(jmri.jmrit.operations.rollingstock.engines.Engine)

Example 54 with RouteLocation

use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.

the class Train method move.

/**
     * Moves the train to the specified route location
     * 
     * @param rl route location
     * @return true if successful
     */
public boolean move(RouteLocation rl) {
    if (rl == null) {
        return false;
    }
    log.debug("Move train ({}) to location ({})", getName(), rl.getName());
    if (getRoute() == null || getCurrentLocation() == null) {
        return false;
    }
    boolean foundCurrent = false;
    for (RouteLocation xrl : getRoute().getLocationsBySequenceList()) {
        if (getCurrentLocation() == xrl) {
            foundCurrent = true;
        }
        if (xrl == rl) {
            if (foundCurrent) {
                // done
                return true;
            } else {
                // train passed this location
                break;
            }
        }
        if (foundCurrent) {
            move();
        }
    }
    return false;
}
Also used : RouteLocation(jmri.jmrit.operations.routes.RouteLocation)

Example 55 with RouteLocation

use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.

the class Train method isLocalSwitcher.

/**
     * Used to determine if train is a local switcher serving one location. Note
     * the the train can have more than location in its route, but all location
     * names must be "same". See TrainCommon.splitString(String name) for the
     * definition of the "same" name.
     *
     * @return true if local switcher
     */
public boolean isLocalSwitcher() {
    String departureName = TrainCommon.splitString(getTrainDepartsName());
    Route route = getRoute();
    if (route != null) {
        for (RouteLocation rl : route.getLocationsBySequenceList()) {
            String name = TrainCommon.splitString(rl.getName());
            if (!departureName.equals(name)) {
                // not a local switcher
                return false;
            }
        }
    }
    return true;
}
Also used : RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Route(jmri.jmrit.operations.routes.Route)

Aggregations

RouteLocation (jmri.jmrit.operations.routes.RouteLocation)118 Route (jmri.jmrit.operations.routes.Route)64 Location (jmri.jmrit.operations.locations.Location)55 Track (jmri.jmrit.operations.locations.Track)52 Car (jmri.jmrit.operations.rollingstock.cars.Car)48 Engine (jmri.jmrit.operations.rollingstock.engines.Engine)33 LocationManager (jmri.jmrit.operations.locations.LocationManager)21 RouteManager (jmri.jmrit.operations.routes.RouteManager)20 Consist (jmri.jmrit.operations.rollingstock.engines.Consist)17 Train (jmri.jmrit.operations.trains.Train)16 CarManager (jmri.jmrit.operations.rollingstock.cars.CarManager)13 ArrayList (java.util.ArrayList)12 CarTypes (jmri.jmrit.operations.rollingstock.cars.CarTypes)12 EngineManager (jmri.jmrit.operations.rollingstock.engines.EngineManager)12 RollingStock (jmri.jmrit.operations.rollingstock.RollingStock)11 EngineTypes (jmri.jmrit.operations.rollingstock.engines.EngineTypes)8 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)6 IOException (java.io.IOException)6 TrainManager (jmri.jmrit.operations.trains.TrainManager)6 JCheckBox (javax.swing.JCheckBox)5