public void displayTrain(int trainNumber) {
    this.trainNumber = trainNumber;

    trainViewJPanel1.display(trainNumber);
    String s;
    String destination = "";
    int priority = TrainModel.PRIORITY_NORMAL;
    int state = TrainModel.STATE_STOPPED;
    if (trainNumber >= 0) {
      TrainModel train =
          (TrainModel) w.get(KEY.TRAINS, trainNumber, modelRoot.getPlayerPrincipal());

      trainCargoBundleKey = train.getCargoBundle();
      CargoBundle cb = (CargoBundle) w.get(train.getCargoBundle());
      s = "Train #" + trainNumber + ": ";
      ScheduleIterator si = train.getScheduleIterator();
      TrainOrdersModel tom = si.getCurrentOrder(w);
      if (tom != null) {
        ObjectKey2 ok = tom.getStation();
        StationModel station = (StationModel) w.get(ok);
        destination = station.getStationName();
      }
      priority = train.getPriority();
      state = train.getState();
      setStatusLabel(train);
    } else {
      s = "No trains to display";
      setStatusLabel(null);
    }
    setStatusButton(priority, state);
    nameJLabel.setText(s);
    destinationJLabel.setText(destination);
  }
예제 #2
0
  /**
   * @return the ObjectKey2 in the STATIONS table of the station owned by player p within the city
   *     radius, or -1 if there is no station
   */
  public ObjectKey2 hasStation(FreerailsPrincipal p) {
    int xmin = cityModel.getCityX() - cityModel.getCityRadius();
    int xmax = cityModel.getCityX() + cityModel.getCityRadius();
    int ymin = cityModel.getCityY() - cityModel.getCityRadius();
    int ymax = cityModel.getCityY() + cityModel.getCityRadius();

    xmin = xmin < 0 ? 0 : xmin;
    ymin = ymin < 0 ? 0 : ymin;
    xmax = xmax >= world.getMapWidth() ? world.getMapWidth() - 1 : xmax;
    ymax = ymax >= world.getMapHeight() ? world.getMapHeight() - 1 : ymax;

    Iterator i = world.getIterator(KEY.STATIONS, p);
    while (i.hasNext()) {
      StationModel sm = (StationModel) i.next();
      int x = sm.getStationX();
      int y = sm.getStationY();
      if (x >= xmin && x <= xmax && y >= ymin && y <= ymax) {
        return new ObjectKey2(KEY.STATIONS, p, sm.getUUID());
      }
    }
    return null;
  }