working on train movements

This commit is contained in:
Stephan Richter
2020-09-20 14:43:33 +02:00
parent a6090b4cf9
commit 9e36d5c0c8
16 changed files with 228 additions and 22 deletions

View File

@@ -75,12 +75,22 @@ public abstract class Block extends StretchableTile{
return this;
}
public void train(Train train) {
public void train(Train train) throws IOException {
this.train = train;
train.block(this);
if (train != null) train.block(this);
plan.stream("place "+tag(null));
}
public Train train() {
return train;
}
public void unlock() {
route = null;
classes.remove("locked");
if (train != null) {
classes.remove("occupied");
plan.stream("dropclass tile-"+x+"-"+y+" locked");
} else plan.stream("dropclass tile-"+x+"-"+y+" locked occupied");
}
}

View File

@@ -21,6 +21,11 @@ public abstract class Contact extends Tile{
} catch (Exception e) {}
}
}.start();
if (route == null) {
plan.warn(this);
} else {
route.contact(this);
}
}

View File

@@ -21,7 +21,6 @@ import de.srsoftware.web4rail.Plan;
import de.srsoftware.web4rail.Plan.Direction;
import de.srsoftware.web4rail.Route;
import de.srsoftware.web4rail.Window;
import de.srsoftware.web4rail.moving.Train;
import de.srsoftware.web4rail.tags.Form;
public abstract class Tile {
@@ -31,7 +30,7 @@ public abstract class Tile {
protected HashSet<Shadow> shadows = new HashSet<>();
private HashSet<Route> routes = new HashSet<>();
protected Plan plan;
protected Train lockedBy;
protected Route route;
protected static Logger LOG = LoggerFactory.getLogger(Tile.class);
@@ -71,12 +70,19 @@ public abstract class Tile {
return 1;
}
public void lock(Train train) {
lockedBy = train;
public void lock(Route route) {
this.route = route;
classes.add("locked");
plan.stream("addclass tile-"+x+"-"+y+" locked");
}
public void occupy(Route route) {
this.route = route;
classes.add("occupied");
plan.stream("addclass tile-"+x+"-"+y+" occupied");
}
public void plan(Plan plan) {
this.plan = plan;
}
@@ -194,9 +200,10 @@ public abstract class Tile {
}
public void unlock() {
lockedBy = null;
route = null;
classes.remove("locked");
plan.stream("dropclass tile-"+x+"-"+y+" locked");
classes.remove("occupied");
plan.stream("dropclass tile-"+x+"-"+y+" locked occupied");
}
public Tile update(HashMap<String, String> params) {

View File

@@ -5,8 +5,8 @@ import java.io.IOException;
public class TurnoutL extends Turnout {
@Override
public Object click() throws IOException {
if (lockedBy != null) {
plan.stream(t("{} is locked by {}!",this,lockedBy));
if (route != null) {
plan.stream(t("{} is locked by {}!",this,route));
} else {
state = (state == State.STRAIGHT) ? State.LEFT : State.STRAIGHT;
plan.stream("place "+tag(null));

View File

@@ -5,8 +5,8 @@ import java.io.IOException;
public class TurnoutR extends Turnout {
@Override
public Object click() throws IOException {
if (lockedBy != null) {
plan.stream(t("{} is locked by {}!",this,lockedBy));
if (route != null) {
plan.stream(t("{} is locked by {}!",this,route));
} else {
state = (state == State.STRAIGHT) ? State.RIGHT : State.STRAIGHT;
plan.stream("place "+tag(null));