implemented pre-reservation of routes when autopilot is active
This commit is contained in:
@@ -40,7 +40,7 @@ public abstract class Action extends BaseClass {
|
||||
public Block block = null;
|
||||
public Direction direction = null;
|
||||
|
||||
private Context(Contact c, Route r, Train t, Block b, Direction d) {
|
||||
public Context(Contact c, Route r, Train t, Block b, Direction d) {
|
||||
contact = c;
|
||||
route = r;
|
||||
train = t;
|
||||
@@ -138,6 +138,7 @@ public abstract class Action extends BaseClass {
|
||||
DelayedAction.class,
|
||||
DetermineTrainInBlock.class,
|
||||
FinishRoute.class,
|
||||
PreserveRoute.class,
|
||||
SendCommand.class,
|
||||
SetDisplayText.class,
|
||||
SetPower.class,
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package de.srsoftware.web4rail.actions;
|
||||
|
||||
import de.srsoftware.web4rail.Range;
|
||||
import de.srsoftware.web4rail.Route;
|
||||
import de.srsoftware.web4rail.moving.Train;
|
||||
|
||||
public class PreserveRoute extends Action {
|
||||
|
||||
@Override
|
||||
public boolean fire(Context context) {
|
||||
Train train = context.train;
|
||||
Route route = context.route;
|
||||
// These are errors:
|
||||
if (isNull(train)) return false;
|
||||
if (isNull(route)) return false;
|
||||
|
||||
Range waitTime = context.route.endBlock().getWaitTime(context.train,context.route.endDirection);
|
||||
|
||||
// These are NOT errors:
|
||||
if (!context.train.usesAutopilot()) return true;
|
||||
if (waitTime.max > 0) return true; // train is expected to wait in next block.
|
||||
if (train.destination() == route.endBlock()) return true;
|
||||
|
||||
context.train.reserveNext();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user