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
 public static TrackTile createTrackTile(ReadOnlyWorld w, byte trackLayout, int trackType) {
   TrackRule tr = (TrackRule) w.get(KEY.TRACK_RULES, trackType, Player.AUTHORITATIVE);
   if (tr.isDoubleTrack()) {
     return new DoubleTrackTile(trackLayout, trackType);
   }
   return new SingleTrackTile(trackLayout, trackType);
 }
        /**
         * Cycle through train status in the following order: Priority express, standard, slow,
         * stopped
         */
        public void actionPerformed(ActionEvent e) {
          if (trainNumber == -1) return;

          TrainModel tm =
              (TrainModel) w.get(KEY.TRAINS, trainNumber, modelRoot.getPlayerPrincipal());

          int priority = tm.getPriority();
          int state = tm.getState();

          if (state == TrainModel.STATE_STOPPED) {
            state = TrainModel.STATE_RUNNABLE;
            priority = TrainModel.PRIORITY_EXPRESS;
          } else {
            switch (priority) {
              case TrainModel.PRIORITY_EXPRESS:
                priority = TrainModel.PRIORITY_NORMAL;
                break;
              case TrainModel.PRIORITY_NORMAL:
                priority = TrainModel.PRIORITY_SLOW;
                break;
              case TrainModel.PRIORITY_SLOW:
                state = TrainModel.STATE_STOPPED;
                break;
              default:
                throw new IllegalStateException();
            }
          }
          Move m;
          GameTime now = (GameTime) w.get(ITEM.TIME, Player.AUTHORITATIVE);
          if (tm.getState() != state) {
            m =
                ChangeTrainMove.generateMove(
                    trainNumber, modelRoot.getPlayerPrincipal(), tm, state, now);
            modelRoot.getReceiver().processMove(m);
            tm = (TrainModel) w.get(KEY.TRAINS, trainNumber, modelRoot.getPlayerPrincipal());
          }
          if (tm.getPriority() != priority) {
            m =
                ChangeTrainMove.generatePriorityMove(
                    trainNumber, modelRoot.getPlayerPrincipal(), tm, priority);
            modelRoot.getReceiver().processMove(m);
          }
        }