/** * 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); } }