implemented shunting trains
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.srsoftware</groupId>
|
||||
<artifactId>web4rail</artifactId>
|
||||
<version>1.3.19</version>
|
||||
<version>1.3.20</version>
|
||||
<name>Web4Rail</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>Java Model Railway Control</description>
|
||||
|
||||
@@ -262,6 +262,7 @@ Set speed to : Geschwindigkeit setzen
|
||||
SetTurnout : Weiche stellen
|
||||
Setup actions : Vorbereitung-Aktionen
|
||||
ShowText : Text anzeigen
|
||||
Shunting : Rangieren
|
||||
Signals : Signale
|
||||
simplify name : Name vereinfachen
|
||||
Simulating movement of {}... : Simuliere Fahrt von {}...
|
||||
@@ -307,7 +308,10 @@ train is a push-pull train : Zug ist ein Wendezug
|
||||
train is faster than {} {} : Zug ist schneller als {} {}
|
||||
train is longer than {} {} : Zug ist länger als {} {}
|
||||
train is not a push-pull train : Zug ist kein Wendezug
|
||||
train is not shunting : Zug rangiert nicht
|
||||
train is shorter than {} {} : Zug ist kürzer als {} {}
|
||||
TrainIsShunting : Zug rangiert
|
||||
train is shunting : Zug rangiert
|
||||
train is slower than {} {} : Zug ist langsamer als {} {}
|
||||
TrainLength : Zug-Länge
|
||||
Train manager : Zug-Verwaltung
|
||||
|
||||
@@ -17,11 +17,12 @@ public class PathFinder extends BaseClass{
|
||||
public static final Logger LOG = LoggerFactory.getLogger(PathFinder.class);
|
||||
|
||||
private static TreeMap<Integer,List<Route>> availableRoutes(Context context,HashSet<Route> visitedRoutes){
|
||||
LOG.debug("PathFinder.availableRoutes({})",context);
|
||||
TreeMap<Integer,List<Route>> availableRoutes = new TreeMap<Integer, List<Route>>();
|
||||
|
||||
String inset = "";
|
||||
for (int i=0; i<visitedRoutes.size(); i++) inset+=" ";
|
||||
|
||||
LOG.debug(inset+"PathFinder.availableRoutes({})",context);
|
||||
TreeMap<Integer,List<Route>> availableRoutes = new TreeMap<Integer, List<Route>>();
|
||||
|
||||
|
||||
boolean error = false;
|
||||
Block block = context.block();
|
||||
@@ -38,11 +39,11 @@ public class PathFinder extends BaseClass{
|
||||
|
||||
Block destination = train.destination();
|
||||
Direction direction = context.direction();
|
||||
/* if (isSet(direction)) {
|
||||
if (isSet(direction)) {
|
||||
LOG.debug("{}Looking for {}-bound routes from {}",inset,direction,block);
|
||||
} else {
|
||||
LOG.debug("{}Looking for all routes from {}",inset,block);
|
||||
}*/
|
||||
}//*/
|
||||
if (isSet(destination) && visitedRoutes.isEmpty()) LOG.debug("{}- Destination: {}",inset,destination);
|
||||
|
||||
Route currentRoute = context.route();
|
||||
|
||||
@@ -126,7 +126,7 @@ public class Route extends BaseClass {
|
||||
public void finish() {
|
||||
LOG.debug("BrakeProcessor.finish(){}",aborted?" got aborted":"");
|
||||
if (aborted) return;
|
||||
long runtime = BaseClass.timestamp() - timestamp;
|
||||
long runtime = 2+BaseClass.timestamp() - timestamp;
|
||||
estimatedDistance += train.speed * runtime;
|
||||
train.setSpeed(0);
|
||||
LOG.debug("Estimated distance: {}",estimatedDistance);
|
||||
@@ -509,7 +509,7 @@ public class Route extends BaseClass {
|
||||
} else {
|
||||
train.setWaitTime(endBlock.getWaitTime(train,train.direction()));
|
||||
}
|
||||
if (train.route == this) train.route = null;
|
||||
if (train.route() == this) train.route(null);
|
||||
if (startBlock.train() == train && !train.onTrace(startBlock)) startBlock.setTrain(null); // withdraw train from start block only if trace does not go back there
|
||||
}
|
||||
train = null;
|
||||
@@ -888,7 +888,7 @@ public class Route extends BaseClass {
|
||||
if (isSet(train)) {
|
||||
train.set(startBlock);
|
||||
train.heading(startDirection);
|
||||
if (train.route == this) train.route = null;
|
||||
if (train.route() == this) train.route(null);
|
||||
train = null;
|
||||
}
|
||||
LOG.debug("chlearing triggeredContacts of {}",this);
|
||||
@@ -1021,6 +1021,7 @@ public class Route extends BaseClass {
|
||||
condition.parent(this);
|
||||
conditions.add(condition);
|
||||
}
|
||||
super.update(params);
|
||||
return properties();
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ public class DetermineTrainInBlock extends Action {
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return isSet(block) ? t("Determine, which train is in {}",block) : t("[Click here to select block!]");
|
||||
return isSet(block) ? t("Determine, which train is in {}",block) : "["+t("Click here to select block!")+"]";
|
||||
};
|
||||
|
||||
@Override
|
||||
|
||||
@@ -123,6 +123,7 @@ public abstract class Condition extends BaseClass {
|
||||
PushPullTrain.class,
|
||||
RouteEndBlock.class,
|
||||
TrainHasTag.class,
|
||||
TrainIsShunting.class,
|
||||
TrainLength.class,
|
||||
TrainSelect.class,
|
||||
TrainSpeed.class,
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package de.srsoftware.web4rail.conditions;
|
||||
|
||||
public class TrainIsShunting extends Condition {
|
||||
|
||||
@Override
|
||||
public boolean fulfilledBy(Context context) {
|
||||
return context.train().isShunting() != inverted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return t(inverted ? "train is not shunting":"train is shunting") ;
|
||||
}
|
||||
}
|
||||
@@ -127,7 +127,7 @@ public class Locomotive extends Car implements Constants,Device{
|
||||
if (isSet(train)) {
|
||||
Block currentBlock = train.currentBlock();
|
||||
if (isSet(currentBlock)) {
|
||||
if (isNull(train.route)) {
|
||||
if (isNull(train.route())) {
|
||||
params.put(ACTION, ACTION_START);
|
||||
new Button(t("start"),params).addTo(direction);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
|
||||
|
||||
private static final String ROUTE = "route";
|
||||
public Route route;
|
||||
private Route route;
|
||||
|
||||
private static final String DIRECTION = "direction";
|
||||
private Direction direction;
|
||||
@@ -82,6 +82,8 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
public int speed = 0;
|
||||
private Autopilot autopilot = null;
|
||||
private Route nextRoute;
|
||||
private static final String SHUNTING = "shunting";
|
||||
private boolean shunting = false;
|
||||
|
||||
|
||||
private class Autopilot extends Thread{
|
||||
@@ -362,6 +364,10 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
cars.remove(car);
|
||||
car.train(null);
|
||||
}
|
||||
if (cars.isEmpty()) {
|
||||
this.remove();
|
||||
return t("Removed train \"{}\"",this);
|
||||
}
|
||||
return properties();
|
||||
}
|
||||
|
||||
@@ -373,6 +379,13 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
setSpeed(speed+steps);
|
||||
return properties();
|
||||
}
|
||||
|
||||
private boolean hasLoco() {
|
||||
for (Car c:cars) {
|
||||
if (c instanceof Locomotive) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Train heading(Direction dir) {
|
||||
LOG.debug("{}.heading({})",this,dir);
|
||||
@@ -385,6 +398,11 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
return trace.getFirst();
|
||||
}
|
||||
|
||||
public boolean isShunting() {
|
||||
return shunting;
|
||||
}
|
||||
|
||||
|
||||
public JSONObject json() {
|
||||
JSONObject json = super.json();
|
||||
json.put(PUSH_PULL, pushPull);
|
||||
@@ -592,11 +610,12 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
|
||||
propList.addTo(otherTrainProps);
|
||||
|
||||
formInputs.add(t("Name"), new Input(NAME,name));
|
||||
formInputs.add(t("Name"), new Input(NAME,name()));
|
||||
formInputs.add(t("Shunting"),new Checkbox(SHUNTING, t("train is shunting"), shunting));
|
||||
formInputs.add(t("Push-pull train"),new Checkbox(PUSH_PULL, t("Push-pull train"), pushPull));
|
||||
formInputs.add(t("Tags"), new Input(TAGS,String.join(", ", tags)));
|
||||
|
||||
preForm.add(Locomotive.cockpit(this));
|
||||
if (this.hasLoco()) preForm.add(Locomotive.cockpit(this));
|
||||
postForm.add(otherTrainProps);
|
||||
postForm.add(brakeTimes());
|
||||
postForm.add(blockHistory());
|
||||
@@ -680,6 +699,18 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
trace = reversed;
|
||||
LOG.debug("reversed: {}",trace);
|
||||
}
|
||||
|
||||
public Route route() {
|
||||
return route;
|
||||
}
|
||||
|
||||
public Train route(Route newRoute) {
|
||||
route = newRoute;
|
||||
if (isNull(route)) shunting = false; // quit shunting on finish route
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void saveAll(String filename) throws IOException {
|
||||
BufferedWriter file = new BufferedWriter(new FileWriter(filename));
|
||||
@@ -704,6 +735,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
|
||||
public void set(Block newBlock) {
|
||||
LOG.debug("{}.set({})",this,newBlock);
|
||||
if (isSet(currentBlock)) currentBlock.setTrain(null);
|
||||
currentBlock = newBlock;
|
||||
if (isSet(currentBlock)) {
|
||||
currentBlock.setTrain(this);
|
||||
@@ -927,6 +959,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
protected Train update(HashMap<String, String> params) {
|
||||
LOG.debug("update({})",params);
|
||||
pushPull = params.containsKey(PUSH_PULL) && params.get(PUSH_PULL).equals("on");
|
||||
shunting = params.containsKey(SHUNTING) && params.get(SHUNTING).equals("on");
|
||||
if (params.containsKey(NAME)) name = params.get(NAME);
|
||||
if (params.containsKey(TAGS)) {
|
||||
String[] parts = params.get(TAGS).replace(",", " ").split(" ");
|
||||
|
||||
@@ -127,16 +127,19 @@ public abstract class Tile extends BaseClass implements Comparable<Tile>{
|
||||
}
|
||||
if (isSet(route)) {
|
||||
PathFinder.LOG.debug("{} is occupied by {}",this,route);
|
||||
return false;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (isSet(train)) {
|
||||
boolean free = train == context.train(); // during train.reserveNext, we may encounter, parts, that are already reserved by the respective train, but having another route. do not compare routes in that case!
|
||||
Train contextTrain = context.train();
|
||||
boolean free = train == contextTrain; // during train.reserveNext, we may encounter, parts, that are already reserved by the respective train, but having another route. do not compare routes in that case!
|
||||
if (free) {
|
||||
PathFinder.LOG.debug("already reserved by {} → true",train);
|
||||
} else {
|
||||
PathFinder.LOG.debug("occupied by {} → false",train);
|
||||
if (isSet(contextTrain) && contextTrain.isShunting()) {
|
||||
PathFinder.LOG.debug("occupied by {}. Allowed for shunting {}",train,contextTrain);
|
||||
free = true;
|
||||
} else PathFinder.LOG.debug("occupied by {} → false",train);
|
||||
}
|
||||
return free;
|
||||
}
|
||||
@@ -262,7 +265,7 @@ public abstract class Tile extends BaseClass implements Comparable<Tile>{
|
||||
fieldset.children().firstElement().content(" / "+t("Train"));
|
||||
} else fieldset = new Fieldset(t("Train"));
|
||||
train.link("span", t("Train")+":"+NBSP+train+NBSP).addTo(fieldset);
|
||||
if (isSet(train.route)) {
|
||||
if (isSet(train.route())) {
|
||||
train.button(t("stop"), Map.of(ACTION,ACTION_STOP)).addTo(fieldset);
|
||||
} else {
|
||||
train.button(t("start"), Map.of(ACTION,ACTION_START)).addTo(fieldset);
|
||||
|
||||
Reference in New Issue
Block a user