public void reset() { setScheduleItemId(getPreviousScheduleId()); // revert to previous setNextLoadName(NONE); setNextWait(0); setFinalDestination(getPreviousFinalDestination()); // revert to previous setFinalDestinationTrack(getPreviousFinalDestinationTrack()); // revert to previous if (isLoadGeneratedFromStaging()) { setLoadGeneratedFromStaging(false); setLoadName(CarLoads.instance().getDefaultEmptyName()); } super.reset(); }
/** * Updates all cars in a kernel. After the update, the cars will all have the same final * destination, load, and next load. */ public void updateKernel() { if (getKernel() != null && getKernel().isLead(this)) { for (Car car : getKernel().getCars()) { car.setFinalDestination(getFinalDestination()); car.setFinalDestinationTrack(getFinalDestinationTrack()); car.setLoadGeneratedFromStaging(isLoadGeneratedFromStaging()); if (CarLoads.instance().containsName(car.getTypeName(), getLoadName())) { car.setLoadName(getLoadName()); } if (CarLoads.instance().containsName(car.getTypeName(), getNextLoadName())) { car.setNextLoadName(getNextLoadName()); } } } }
public void loadNext(Track destTrack) { setLoadGeneratedFromStaging(false); // update wait count setWait(getNextWait()); setNextWait(0); // and the pickup day setPickupScheduleId(getNextPickupScheduleId()); setNextPickupScheduleId(NONE); // arrived at spur? if (destTrack != null && destTrack.getTrackType().equals(Track.SPUR)) { updateLoad(); } // update load optionally when car reaches staging else if (destTrack != null && destTrack.getTrackType().equals(Track.STAGING)) { if (destTrack.isLoadSwapEnabled() && getLoadName().equals(carLoads.getDefaultEmptyName())) { setLoadName(carLoads.getDefaultLoadName()); } else if (destTrack.isLoadSwapEnabled() && getLoadName().equals(carLoads.getDefaultLoadName())) { setLoadEmpty(); } else if (destTrack.isLoadEmptyEnabled() && getLoadName().equals(carLoads.getDefaultLoadName())) { setLoadEmpty(); } // empty car if it has a custom load else if (destTrack.isRemoveCustomLoadsEnabled() && !getLoadName().equals(carLoads.getDefaultEmptyName()) && !getLoadName().equals(carLoads.getDefaultLoadName())) { // remove this car's final destination if it has one setFinalDestination(null); setFinalDestinationTrack(null); // car arriving into staging with the RWE load? if (getLoadName().equals(getReturnWhenEmptyLoadName())) { setLoadName(carLoads.getDefaultEmptyName()); } else { setLoadEmpty(); // note that RWE sets the car's final destination } } } }
/** * Construct this Entry from XML. This member has to remain synchronized with the detailed DTD in * operations-cars.dtd * * @param e Car XML element */ public Car(org.jdom2.Element e) { super(e); loaded = true; org.jdom2.Attribute a; if ((a = e.getAttribute(Xml.PASSENGER)) != null) { _passenger = a.getValue().equals(Xml.TRUE); } if ((a = e.getAttribute(Xml.HAZARDOUS)) != null) { _hazardous = a.getValue().equals(Xml.TRUE); } if ((a = e.getAttribute(Xml.CABOOSE)) != null) { _caboose = a.getValue().equals(Xml.TRUE); } if ((a = e.getAttribute(Xml.FRED)) != null) { _fred = a.getValue().equals(Xml.TRUE); } if ((a = e.getAttribute(Xml.UTILITY)) != null) { _utility = a.getValue().equals(Xml.TRUE); } if ((a = e.getAttribute(Xml.KERNEL)) != null) { Kernel k = CarManager.instance().getKernelByName(a.getValue()); if (k != null) { setKernel(k); if ((a = e.getAttribute(Xml.LEAD_KERNEL)) != null && a.getValue().equals(Xml.TRUE)) { _kernel.setLead(this); } } else { log.error("Kernel " + a.getValue() + " does not exist"); } } if ((a = e.getAttribute(Xml.LOAD)) != null) { _loadName = a.getValue(); } if ((a = e.getAttribute(Xml.LOAD_FROM_STAGING)) != null && a.getValue().equals(Xml.TRUE)) { setLoadGeneratedFromStaging(true); } if ((a = e.getAttribute(Xml.WAIT)) != null) { try { _wait = Integer.parseInt(a.getValue()); } catch (NumberFormatException nfe) { log.error("Wait count ({}) for car ({}) isn't a valid number!", a.getValue(), toString()); } } if ((a = e.getAttribute(Xml.PICKUP_SCHEDULE_ID)) != null) { _pickupScheduleId = a.getValue(); } if ((a = e.getAttribute(Xml.SCHEDULE_ID)) != null) { _scheduleId = a.getValue(); } if ((a = e.getAttribute(Xml.NEXT_LOAD)) != null) { _nextLoadName = a.getValue(); } if ((a = e.getAttribute(Xml.NEXT_WAIT)) != null) { try { _nextWait = Integer.parseInt(a.getValue()); } catch (NumberFormatException nfe) { log.error( "Next wait count ({}) for car ({}) isn't a valid number!", a.getValue(), toString()); } } if ((a = e.getAttribute(Xml.NEXT_PICKUP_SCHEDULE_ID)) != null) { _nextPickupScheduleId = a.getValue(); } if ((a = e.getAttribute(Xml.NEXT_DEST_ID)) != null) { setFinalDestination(LocationManager.instance().getLocationById(a.getValue())); } if (getFinalDestination() != null && (a = e.getAttribute(Xml.NEXT_DEST_TRACK_ID)) != null) { setFinalDestinationTrack(getFinalDestination().getTrackById(a.getValue())); } if ((a = e.getAttribute(Xml.PREVIOUS_NEXT_DEST_ID)) != null) { setPreviousFinalDestination(LocationManager.instance().getLocationById(a.getValue())); } if (getPreviousFinalDestination() != null && (a = e.getAttribute(Xml.PREVIOUS_NEXT_DEST_TRACK_ID)) != null) { setPreviousFinalDestinationTrack(getPreviousFinalDestination().getTrackById(a.getValue())); } if ((a = e.getAttribute(Xml.PREVIOUS_SCHEDULE_ID)) != null) { setPreviousScheduleId(a.getValue()); } if ((a = e.getAttribute(Xml.RWE_DEST_ID)) != null) { _rweDestination = LocationManager.instance().getLocationById(a.getValue()); } if (_rweDestination != null && (a = e.getAttribute(Xml.RWE_DEST_TRACK_ID)) != null) { _rweDestTrack = _rweDestination.getTrackById(a.getValue()); } if ((a = e.getAttribute(Xml.RWE_LOAD)) != null) { _rweLoadName = a.getValue(); } addPropertyChangeListeners(); }