minor improvements

* when a train in shunting mode is directed to an occupied block, the train there is moved to the parking list of that block
* some null pointer checks
This commit is contained in:
Stephan Richter
2021-05-06 09:24:58 +02:00
parent acb23d4434
commit d08eda142f
6 changed files with 17 additions and 5 deletions

View File

@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.srsoftware</groupId>
<artifactId>web4rail</artifactId>
<version>1.4.28</version>
<version>1.4.29</version>
<name>Web4Rail</name>
<packaging>jar</packaging>
<description>Java Model Railway Control</description>

View File

@@ -401,6 +401,7 @@ public class Route extends BaseClass {
}
private void freeIgnoring(Vector<Tile> skipTiles) {
if (isNull(context)) return;
Train train = context.train();
Vector<Tile> reversedPath = reverse(path());
if (isSet(skipTiles)) reversedPath.removeAll(skipTiles);

View File

@@ -432,10 +432,11 @@ public class Train extends BaseClass implements Comparable<Train> {
}
public void dropTrace(boolean dropStuck) {
public Train dropTrace(boolean dropStuck) {
while (!trace.isEmpty()) trace.stream().findFirst().get().free(this);
trace.clear();
if (dropStuck) stuckTrace = null;
return this;
}
private BrakeProcess endBrake() {
@@ -453,7 +454,6 @@ public class Train extends BaseClass implements Comparable<Train> {
direction = endedRoute.endDirection; // muss vor der Auswertung des Destination-Tags stehen!
Block endBlock = endedRoute.endBlock();
Block startBlock = endedRoute.startBlock();
shunting = false;
if (endBlock == destination) {
destination = null;
@@ -504,6 +504,7 @@ public class Train extends BaseClass implements Comparable<Train> {
if ((!autopilot) || isNull(nextPreparedRoute) || (isSet(waitTime) && waitTime > 0)) setSpeed(0);
route = null;
endBlock.setTrain(this);
shunting = false; // wird in setTrain verwendet, muss also danach stehen
currentBlock = endBlock;
trace.add(endBlock);
if (!trace.contains(startBlock)) startBlock.dropTrain(this);

View File

@@ -85,6 +85,7 @@ public class BrakeProcess extends BaseClass implements Runnable{
updateDistance();
LOG.debug("updateTime(): start speed was {} {}.",startSpeed,BaseClass.speedUnit);
Integer newTimeStep = timeStep;
if (isNull(newTimeStep)) return;
long calculated;
int step = 32*newTimeStep;
for (int i=0; i<20; i++) {

View File

@@ -453,6 +453,15 @@ public abstract class Block extends StretchableTile{
internalContacts.remove(blockContact);
}
@Override
public boolean setTrain(Train newTrain) {
if (isDisabled()) return false;
if (isNull(newTrain)) return false;
Train occupyingTrain = occupyingTrain();
if (isSet(occupyingTrain) && newTrain != occupyingTrain && newTrain.isShunting()) parkedTrains.add(occupyingTrain.dropTrace(false));
return super.setTrain(newTrain);
}
public abstract List<Connector> startPoints();
@Override

View File

@@ -465,10 +465,10 @@ public abstract class Tile extends BaseClass implements Comparable<Tile> {
if (isNull(newTrain)) return false;
if (isSet(reservingTrain) && newTrain != reservingTrain) return false;
if (isSet(lockingTrain) && newTrain != lockingTrain) return false;
if (isSet(occupyingTrain) && newTrain != occupyingTrain) return false;
if (isSet(occupyingTrain) && (newTrain != occupyingTrain) && !newTrain.isShunting()) return false;
reservingTrain = lockingTrain = null;
if (occupyingTrain == newTrain) return true;
occupyingTrain = newTrain;
reservingTrain = lockingTrain = null;
plan.place(this);
return true;
}