|
|
@ -152,6 +152,19 @@ public class Train extends BaseClass implements Comparable<Train> { |
|
|
|
} |
|
|
|
} |
|
|
|
return t("Unknown action: {}",params.get(ACTION)); |
|
|
|
return t("Unknown action: {}",params.get(ACTION)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void addToTrace(Vector<Tile> newTiles) { |
|
|
|
|
|
|
|
boolean active = trace.isEmpty(); |
|
|
|
|
|
|
|
for (Tile tile : newTiles) { |
|
|
|
|
|
|
|
if (active) { |
|
|
|
|
|
|
|
trace.addFirst(tile); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
Tile dummy = trace.getFirst(); |
|
|
|
|
|
|
|
if (dummy == tile) active = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
showTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Route chooseRoute(Context context) { |
|
|
|
private Route chooseRoute(Context context) { |
|
|
|
HashSet<Route> routes = block.routes(); |
|
|
|
HashSet<Route> routes = block.routes(); |
|
|
@ -270,10 +283,13 @@ public class Train extends BaseClass implements Comparable<Train> { |
|
|
|
return props(); |
|
|
|
return props(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void dropTrace() { |
|
|
|
|
|
|
|
while (!trace.isEmpty()) trace.removeFirst().set(null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static Train get(int id) { |
|
|
|
public static Train get(int id) { |
|
|
|
return trains.get(id); |
|
|
|
return trains.get(id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Train heading(Direction dir) { |
|
|
|
public Train heading(Direction dir) { |
|
|
|
direction = dir; |
|
|
|
direction = dir; |
|
|
@ -281,6 +297,10 @@ public class Train extends BaseClass implements Comparable<Train> { |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Tile headPos() { |
|
|
|
|
|
|
|
return trace.getFirst(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private JSONObject json() { |
|
|
|
private JSONObject json() { |
|
|
|
JSONObject json = new JSONObject(); |
|
|
|
JSONObject json = new JSONObject(); |
|
|
|
json.put(ID, id); |
|
|
|
json.put(ID, id); |
|
|
@ -480,13 +500,6 @@ public class Train extends BaseClass implements Comparable<Train> { |
|
|
|
return window; |
|
|
|
return window; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public SortedSet<String> tags() { |
|
|
|
|
|
|
|
TreeSet<String> list = new TreeSet<String>(tags); |
|
|
|
|
|
|
|
for (Locomotive loco : locos) list.addAll(loco.tags()); |
|
|
|
|
|
|
|
for (Car car:cars) list.addAll(car.tags()); |
|
|
|
|
|
|
|
return list; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Object quitAutopilot() { |
|
|
|
public Object quitAutopilot() { |
|
|
|
if (isSet(autopilot)) { |
|
|
|
if (isSet(autopilot)) { |
|
|
|
autopilot.stop = true; |
|
|
|
autopilot.stop = true; |
|
|
@ -495,6 +508,10 @@ public class Train extends BaseClass implements Comparable<Train> { |
|
|
|
} else return t("autopilot not active."); |
|
|
|
} else return t("autopilot not active."); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void reverseTrace() { |
|
|
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void saveAll(String filename) throws IOException { |
|
|
|
public static void saveAll(String filename) throws IOException { |
|
|
|
BufferedWriter file = new BufferedWriter(new FileWriter(filename)); |
|
|
|
BufferedWriter file = new BufferedWriter(new FileWriter(filename)); |
|
|
|
for (Entry<Integer, Train> entry:trains.entrySet()) { |
|
|
|
for (Entry<Integer, Train> entry:trains.entrySet()) { |
|
|
@ -516,12 +533,33 @@ public class Train extends BaseClass implements Comparable<Train> { |
|
|
|
return select; |
|
|
|
return select; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void set(Block newBlock) { |
|
|
|
|
|
|
|
block = newBlock; |
|
|
|
|
|
|
|
if (isSet(block)) block.set(this); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setSpeed(int v) { |
|
|
|
public void setSpeed(int v) { |
|
|
|
LOG.debug("Setting speed to {} kmh.",v); |
|
|
|
LOG.debug("Setting speed to {} kmh.",v); |
|
|
|
for (Locomotive loco : locos) loco.setSpeed(v); |
|
|
|
for (Locomotive loco : locos) loco.setSpeed(v); |
|
|
|
this.speed = v; |
|
|
|
this.speed = v; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void showTrace() { |
|
|
|
|
|
|
|
int remainingLength = length(); |
|
|
|
|
|
|
|
if (remainingLength<1) remainingLength=1; |
|
|
|
|
|
|
|
for (int i=0; i<trace.size(); i++) { |
|
|
|
|
|
|
|
Tile tile = 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
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String start() throws IOException { |
|
|
|
public String start() throws IOException { |
|
|
|
if (isNull(block)) return t("{} not in a block",this); |
|
|
|
if (isNull(block)) return t("{} not in a block",this); |
|
|
|
Context context = isSet(route) ? new Context( route ) : new Context( this); |
|
|
|
Context context = isSet(route) ? new Context( route ) : new Context( this); |
|
|
@ -558,6 +596,14 @@ public class Train extends BaseClass implements Comparable<Train> { |
|
|
|
return Translation.get(Application.class, message, fills); |
|
|
|
return Translation.get(Application.class, message, fills); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public SortedSet<String> tags() { |
|
|
|
|
|
|
|
TreeSet<String> list = new TreeSet<String>(tags); |
|
|
|
|
|
|
|
for (Locomotive loco : locos) list.addAll(loco.tags()); |
|
|
|
|
|
|
|
for (Car car:cars) list.addAll(car.tags()); |
|
|
|
|
|
|
|
return list; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String toString() { |
|
|
|
public String toString() { |
|
|
|
return isSet(name) ? name : locos.firstElement().name(); |
|
|
|
return isSet(name) ? name : locos.firstElement().name(); |
|
|
@ -567,12 +613,13 @@ public class Train extends BaseClass implements Comparable<Train> { |
|
|
|
LOG.debug("train.turn()"); |
|
|
|
LOG.debug("train.turn()"); |
|
|
|
if (isSet(direction)) { |
|
|
|
if (isSet(direction)) { |
|
|
|
direction = direction.inverse(); |
|
|
|
direction = direction.inverse(); |
|
|
|
for (Locomotive loco : locos) loco.turn(); |
|
|
|
for (Locomotive loco : locos) loco.turn(); |
|
|
|
|
|
|
|
reverseTrace(); |
|
|
|
|
|
|
|
if (isSet(block)) plan.place(block); |
|
|
|
} |
|
|
|
} |
|
|
|
return t("{} turned.",this); |
|
|
|
return t("{} turned.",this); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Train update(HashMap<String, String> params) { |
|
|
|
public Train update(HashMap<String, String> params) { |
|
|
|
LOG.debug("update({})",params); |
|
|
|
LOG.debug("update({})",params); |
|
|
|
pushPull = params.containsKey(PUSH_PULL) && params.get(PUSH_PULL).equals("on"); |
|
|
|
pushPull = params.containsKey(PUSH_PULL) && params.get(PUSH_PULL).equals("on"); |
|
|
@ -589,47 +636,8 @@ public class Train extends BaseClass implements Comparable<Train> { |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void set(Block newBlock) { |
|
|
|
|
|
|
|
block = newBlock; |
|
|
|
|
|
|
|
if (isSet(block)) block.set(this); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Tile headPos() { |
|
|
|
|
|
|
|
return trace.getFirst(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void addToTrace(Vector<Tile> newTiles) { |
|
|
|
|
|
|
|
boolean active = trace.isEmpty(); |
|
|
|
|
|
|
|
for (Tile tile : newTiles) { |
|
|
|
|
|
|
|
if (active) { |
|
|
|
|
|
|
|
trace.addFirst(tile); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
Tile dummy = trace.getFirst(); |
|
|
|
|
|
|
|
if (dummy == tile) active = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
showTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void showTrace() { |
|
|
|
|
|
|
|
int remainingLength = length(); |
|
|
|
|
|
|
|
if (remainingLength<1) remainingLength=1; |
|
|
|
|
|
|
|
for (int i=0; i<trace.size(); i++) { |
|
|
|
|
|
|
|
Tile tile = 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
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void dropTrace() { |
|
|
|
|
|
|
|
while (!trace.isEmpty()) trace.removeFirst().set(null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void removeFromTrace(Tile tile) { |
|
|
|
public void removeFromTrace(Tile tile) { |
|
|
|
trace.remove(tile); |
|
|
|
trace.remove(tile); |
|
|
|