This commit is contained in:
Stephan Richter
2020-12-21 20:18:46 +01:00
parent f3fcdb6a0e
commit 92923aec30
10 changed files with 51 additions and 28 deletions

View File

@@ -49,7 +49,7 @@ public class Contact extends Tile{
@Override
public void run() {
try {
for (int ticks = 0; ticks<10; ticks++) {
for (int ticks = 0; ticks<50; ticks++) {
if (!aborted) sleep(10);
}
timer = null;
@@ -210,7 +210,7 @@ public class Contact extends Tile{
}
public void stream() {
try {
try {
Tag tag = tag(null);
if (state) tag.clazz(tag.get("class")+" active");
plan.stream("place "+tag);

View File

@@ -21,6 +21,7 @@ import org.slf4j.LoggerFactory;
import de.srsoftware.tools.Tag;
import de.srsoftware.web4rail.BaseClass;
import de.srsoftware.web4rail.Connector;
import de.srsoftware.web4rail.PathFinder;
import de.srsoftware.web4rail.Plan;
import de.srsoftware.web4rail.Plan.Direction;
import de.srsoftware.web4rail.Route;
@@ -113,18 +114,18 @@ public abstract class Tile extends BaseClass implements Comparable<Tile>{
}
public boolean isFreeFor(Context context) {
LOG.debug("{}.isFreeFor({})",this,context);
PathFinder.LOG.debug("{}.isFreeFor({})",this,context);
if (disabled) {
LOG.debug("{} is disabled!",this);
PathFinder.LOG.debug("{} is disabled!",this);
return false;
}
if (isNull(context)) {
if (isSet(train)) {
LOG.debug("{} is occupied by {}",this,train);
PathFinder.LOG.debug("{} is occupied by {}",this,train);
return false;
}
if (isSet(route)) {
LOG.debug("{} is occupied by {}",this,route);
PathFinder.LOG.debug("{} is occupied by {}",this,route);
return false;
}
@@ -132,26 +133,26 @@ public abstract class Tile extends BaseClass implements Comparable<Tile>{
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!
if (free) {
LOG.debug("already reserved by {} → true",train);
PathFinder.LOG.debug("already reserved by {} → true",train);
} else {
LOG.debug("occupied by {} → false",train);
PathFinder.LOG.debug("occupied by {} → false",train);
}
return free;
}
// if we get here, the tile is not occupied by a train, but reserved by a route, yet. thus, the tile is not available for another route
if (isSet(route) && route != context.route()) {
LOG.debug("reserved by other route: {}",route);
PathFinder.LOG.debug("reserved by other route: {}",route);
if (isSet(route.train())) {
if (route.train() == context.train()) {
LOG.debug("that route is used by {}, which is also requesting this tile → true",route.train());
PathFinder.LOG.debug("that route is used by {}, which is also requesting this tile → true",route.train());
return true;
}
}
LOG.debug("{}.route.train = {} → false",this,route.train());
PathFinder.LOG.debug("{}.route.train = {} → false",this,route.train());
return false;
}
LOG.debug("free");
PathFinder.LOG.debug("free");
return true;
}
@@ -359,14 +360,14 @@ public abstract class Tile extends BaseClass implements Comparable<Tile>{
}
public Tile setTrain(Train newTrain) {
LOG.debug("{}.set({})",this,newTrain);
Route.LOG.debug("{}.setTrain({})",this,newTrain);
if (newTrain == train) return this; // nothing to update
this.train = newTrain;
return plan.place(this);
}
public Tile setRoute(Route lockingRoute) {
LOG.debug("{}.setRoute({})",this,lockingRoute);
Route.LOG.debug("{}.setRoute({})",this,lockingRoute);
if (isNull(lockingRoute)) throw new NullPointerException();
if (isSet(route)) {
if (route == lockingRoute) return this; // nothing changed