@ -103,4 +104,5 @@ Was not able to assign {} to {}! : Konnte {} nicht an {} zuweisen!
@@ -103,4 +104,5 @@ Was not able to assign {} to {}! : Konnte {} nicht an {} zuweisen!
Was not able to lock {} : Konnte {} nicht reservieren
Was not able to set all signals! : Konnte nicht alle Signale stellen!
Was not able to set all turnouts! : Konnte nicht alle Weichen stellen!
@ -71,7 +73,7 @@ public class Train implements Comparable<Train>,Constants {
@@ -71,7 +73,7 @@ public class Train implements Comparable<Train>,Constants {
@ -81,7 +83,7 @@ public class Train implements Comparable<Train>,Constants {
@@ -81,7 +83,7 @@ public class Train implements Comparable<Train>,Constants {
try{
stop=false;
while(true){
if(route==null){
if(isNull(route)){
Thread.sleep(2000);
if(stop)return;
Train.this.start();
@ -107,7 +109,7 @@ public class Train implements Comparable<Train>,Constants {
@@ -107,7 +109,7 @@ public class Train implements Comparable<Train>,Constants {
}
publicTrain(Locomotiveloco,Integerid){
if(id==null)id=Application.createId();
if(isNull(id))id=Application.createId();
this.id=id;
add(loco);
trains.put(id,this);
@ -115,7 +117,7 @@ public class Train implements Comparable<Train>,Constants {
@@ -115,7 +117,7 @@ public class Train implements Comparable<Train>,Constants {
if(action==null)returnt("No action passed to Train.action!");
if(isNull(action))returnt("No action passed to Train.action!");
if(!params.containsKey(Train.ID)){
switch(action){
caseACTION_PROPS:
@ -127,7 +129,7 @@ public class Train implements Comparable<Train>,Constants {
@@ -127,7 +129,7 @@ public class Train implements Comparable<Train>,Constants {
}
intid=Integer.parseInt(params.get(Train.ID));
Traintrain=trains.get(id);
if(train==null)return(t("No train with id {}!",id));
if(isNull(train))return(t("No train with id {}!",id));
switch(action){
caseACTION_ADD:
returntrain.addCar(params);
@ -151,17 +153,18 @@ public class Train implements Comparable<Train>,Constants {
@@ -151,17 +153,18 @@ public class Train implements Comparable<Train>,Constants {
if(rt==route)continue;// andere Route als zuvor wählen
if(rt.path().firstElement()!=block)continue;// keine Route wählen, die nicht vom aktuellen Block des Zuges startet
if(direction!=null&&rt.startDirection!=direction){// Route ist entgegen der Startrichtung des Zuges
if(isSet(direction)&&rt.startDirection!=direction){// Route ist entgegen der Startrichtung des Zuges
if(!pushPull||!block.turnAllowed){// Zug ist kein Wendezug oder Block erlaubt kein Wenden
continue;
}
}
if(!rt.free()){// keine belegten Routen wählen
if(!rt.isFree()){// keine belegten Routen wählen
LOG.debug("{} is not free!",rt);
continue;
}
@ -180,7 +183,7 @@ public class Train implements Comparable<Train>,Constants {
@@ -180,7 +183,7 @@ public class Train implements Comparable<Train>,Constants {
publicStringdirectedName(){
Stringresult=name();
if(direction==null)returnresult;
if(isNull(direction))returnresult;
switch(direction){
caseNORTH:
caseWEST:
@ -194,9 +197,9 @@ public class Train implements Comparable<Train>,Constants {
@@ -194,9 +197,9 @@ public class Train implements Comparable<Train>,Constants {
@ -204,7 +207,7 @@ public class Train implements Comparable<Train>,Constants {
@@ -204,7 +207,7 @@ public class Train implements Comparable<Train>,Constants {
LOG.debug("addCar({})",params);
if(!params.containsKey(CAR_ID))returnt("No car id passed to Train.addCar!");
Carcar=Car.get(params.get(CAR_ID));
if(car==null)returnt("No car with id \"{}\" known!",params.get(CAR_ID));
if(isNull(car))returnt("No car with id \"{}\" known!",params.get(CAR_ID));
if(carinstanceofLocomotive){
locos.add((Locomotive)car);
}elsecars.add(car);
@ -212,7 +215,7 @@ public class Train implements Comparable<Train>,Constants {
@@ -212,7 +215,7 @@ public class Train implements Comparable<Train>,Constants {
}
publicvoidadd(Carcar){
if(car==null)return;
if(isNull(car))return;
if(carinstanceofLocomotive){
locos.add((Locomotive)car);
}elsecars.add(car);
@ -220,29 +223,13 @@ public class Train implements Comparable<Train>,Constants {
@@ -220,29 +223,13 @@ public class Train implements Comparable<Train>,Constants {
if(this.block==block)returnthis;// nothing to update
if(this.block!=null){
this.block.trailingTrain(this);
previousBlocks.add(this.block);
}
this.block=block;
block.trainHead(this);
if(resetPreviousBlocks)resetPreviousBlocks();
returnthis;
}
privateTagcarList(){
TaglocoProp=newTag("li").content(t("Cars:"));
TaglocoList=newTag("ul").clazz("carlist");
@ -273,7 +260,7 @@ public class Train implements Comparable<Train>,Constants {
@@ -273,7 +260,7 @@ public class Train implements Comparable<Train>,Constants {
@ -286,7 +273,7 @@ public class Train implements Comparable<Train>,Constants {
@@ -286,7 +273,7 @@ public class Train implements Comparable<Train>,Constants {
publicTrainheading(Directiondir){
direction=dir;
if(block!=null)plan.place(block);
if(isSet(block))plan.place(block);
returnthis;
}
@ -294,10 +281,10 @@ public class Train implements Comparable<Train>,Constants {
@@ -294,10 +281,10 @@ public class Train implements Comparable<Train>,Constants {
@ -326,7 +313,7 @@ public class Train implements Comparable<Train>,Constants {
@@ -326,7 +313,7 @@ public class Train implements Comparable<Train>,Constants {
@ -405,7 +392,7 @@ public class Train implements Comparable<Train>,Constants {
@@ -405,7 +392,7 @@ public class Train implements Comparable<Train>,Constants {
@ -441,11 +428,11 @@ public class Train implements Comparable<Train>,Constants {
@@ -441,11 +428,11 @@ public class Train implements Comparable<Train>,Constants {
@ -453,10 +440,10 @@ public class Train implements Comparable<Train>,Constants {
@@ -453,10 +440,10 @@ public class Train implements Comparable<Train>,Constants {
@ -474,26 +461,13 @@ public class Train implements Comparable<Train>,Constants {
@@ -474,26 +461,13 @@ public class Train implements Comparable<Train>,Constants {
@ -504,7 +478,7 @@ public class Train implements Comparable<Train>,Constants {
@@ -504,7 +478,7 @@ public class Train implements Comparable<Train>,Constants {
@ -522,21 +496,23 @@ public class Train implements Comparable<Train>,Constants {
@@ -522,21 +496,23 @@ public class Train implements Comparable<Train>,Constants {
if(isNull(route))returnt("No free routes from {}",block);
if(!route.lock())returnt("Was not able to lock {}",route);
if(direction!=route.startDirection)turn();
Stringerror=null;
if(!route.setTurnouts())error=t("Was not able to set all turnouts!");
if(error==null&&!route.fireSetupActions(context))error=t("Was not able to fire all setup actions of route!");
if(error==null&&!route.setSignals(null))error=t("Was not able to set all signals!");
if(error==null&&!route.train(this))error=t("Was not able to assign {} to {}!",this,route);
if(error!=null){
if(isNull(error)&&!route.fireSetupActions(context))error=t("Was not able to fire all setup actions of route!");
if(isNull(error)&&!route.setSignals(null))error=t("Was not able to set all signals!");
if(isNull(error)&&!route.train(this))error=t("Was not able to assign {} to {}!",this,route);
if(isSet(error)){
route.reset();
returnerror;
}
@ -547,13 +523,6 @@ public class Train implements Comparable<Train>,Constants {
@@ -547,13 +523,6 @@ public class Train implements Comparable<Train>,Constants {
privateObjectstopNow(){
quitAutopilot();
setSpeed(0);
if(route!=null)try{
route.unlock();
route.endBlock().trainHead(null);
route.startBlock().trainHead(this);
}catch(IOExceptione){
e.printStackTrace();
}
route=null;
returnt("Stopped {}.",this);
}
@ -564,16 +533,15 @@ public class Train implements Comparable<Train>,Constants {
@@ -564,16 +533,15 @@ public class Train implements Comparable<Train>,Constants {
@ -593,4 +561,48 @@ public class Train implements Comparable<Train>,Constants {
@@ -593,4 +561,48 @@ public class Train implements Comparable<Train>,Constants {
returnthis;
}
publicvoidset(BlocknewBlock){
block=newBlock;
if(isSet(block))block.set(this);
}
publicTileheadPos(){
returntrace.getFirst();
}
publicvoidaddToTrace(Vector<Tile>newTiles){
booleanactive=trace.isEmpty();
for(Tiletile:newTiles){
if(active){
trace.addFirst(tile);
System.err.println(trace);
}else{
Tiledummy=trace.getFirst();
if(dummy==tile){
active=true;
};
}
}
showTrace();
}
publicvoidshowTrace(){
intremainingLength=length();
for(inti=0;i<trace.size();i++){
Tiletile=trace.get(i);
if(remainingLength>0){
remainingLength-=tile.length();
tile.set(this);
}else{
tile.set(null);
trace.remove(i);
i--;// do not move to next index: remove shifted the next index towards us