|
|
@ -42,8 +42,11 @@ import de.srsoftware.web4rail.tiles.Tile; |
|
|
|
public class Train extends BaseClass implements Comparable<Train> { |
|
|
|
public class Train extends BaseClass implements Comparable<Train> { |
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(Train.class); |
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(Train.class); |
|
|
|
|
|
|
|
|
|
|
|
public static final String HEAD = "train_head"; |
|
|
|
private static final String CAR_ID = "carId"; |
|
|
|
public static final String TAIL = "train_tile"; |
|
|
|
public static final String HEAD = "train_head"; |
|
|
|
|
|
|
|
public static final String LOCO_ID = "locoId"; |
|
|
|
|
|
|
|
public static final String TAIL = "train_tile"; |
|
|
|
|
|
|
|
private static final String TRACE = "trace"; |
|
|
|
private static final HashMap<Integer, Train> trains = new HashMap<>(); |
|
|
|
private static final HashMap<Integer, Train> trains = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
public static final String ID = "id"; |
|
|
|
public static final String ID = "id"; |
|
|
@ -96,9 +99,6 @@ public class Train extends BaseClass implements Comparable<Train> { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static final String LOCO_ID = "locoId"; |
|
|
|
|
|
|
|
private static final String CAR_ID = "carId"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int speed = 0; |
|
|
|
public int speed = 0; |
|
|
|
private Autopilot autopilot = null; |
|
|
|
private Autopilot autopilot = null; |
|
|
|
|
|
|
|
|
|
|
@ -164,7 +164,7 @@ public class Train extends BaseClass implements Comparable<Train> { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (!rt.isFree()) { // keine belegten Routen wählen
|
|
|
|
if (!rt.isFreeFor(this)) { // keine belegten Routen wählen
|
|
|
|
LOG.debug("{} is not free!",rt); |
|
|
|
LOG.debug("{} is not free!",rt); |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
@ -280,17 +280,25 @@ public class Train extends BaseClass implements Comparable<Train> { |
|
|
|
private JSONObject json() { |
|
|
|
private JSONObject json() { |
|
|
|
JSONObject json = new JSONObject(); |
|
|
|
JSONObject json = new JSONObject(); |
|
|
|
json.put(ID, id); |
|
|
|
json.put(ID, id); |
|
|
|
json.put(NAME,name); |
|
|
|
|
|
|
|
if (isSet(route)) json.put(ROUTE, route.id()); |
|
|
|
|
|
|
|
if (isSet(direction)) json.put(DIRECTION, direction); |
|
|
|
|
|
|
|
json.put(PUSH_PULL, pushPull); |
|
|
|
json.put(PUSH_PULL, pushPull); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isSet(block)) json.put(BLOCK, block.id()); |
|
|
|
if (isSet(name))json.put(NAME, name); |
|
|
|
if (isSet(name))json.put(NAME, name); |
|
|
|
|
|
|
|
if (isSet(route)) json.put(ROUTE, route.id()); |
|
|
|
|
|
|
|
if (isSet(direction)) json.put(DIRECTION, direction); |
|
|
|
|
|
|
|
|
|
|
|
Vector<Integer> locoIds = new Vector<Integer>(); |
|
|
|
Vector<Integer> locoIds = new Vector<Integer>(); |
|
|
|
for (Locomotive loco : locos) locoIds.add(loco.id()); |
|
|
|
for (Locomotive loco : locos) locoIds.add(loco.id()); |
|
|
|
json.put(LOCOS, locoIds); |
|
|
|
json.put(LOCOS, locoIds); |
|
|
|
|
|
|
|
|
|
|
|
Vector<Integer> carIds = new Vector<Integer>(); |
|
|
|
Vector<Integer> carIds = new Vector<Integer>(); |
|
|
|
for (Car car : cars) carIds.add(car.id()); |
|
|
|
for (Car car : cars) carIds.add(car.id()); |
|
|
|
json.put(CARS,carIds); |
|
|
|
json.put(CARS,carIds); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Vector<String> tileIds = new Vector<String>(); |
|
|
|
|
|
|
|
for (Tile tile : trace) tileIds.add(tile.id()); |
|
|
|
|
|
|
|
json.put(TRACE, tileIds); |
|
|
|
|
|
|
|
|
|
|
|
if (!tags.isEmpty()) json.put(TAGS, tags); |
|
|
|
if (!tags.isEmpty()) json.put(TAGS, tags); |
|
|
|
return json; |
|
|
|
return json; |
|
|
|
} |
|
|
|
} |
|
|
@ -319,7 +327,7 @@ public class Train extends BaseClass implements Comparable<Train> { |
|
|
|
int id = json.getInt(ID); |
|
|
|
int id = json.getInt(ID); |
|
|
|
|
|
|
|
|
|
|
|
Train train = new Train(null,id); |
|
|
|
Train train = new Train(null,id); |
|
|
|
train.load(json).plan(plan); |
|
|
|
train.plan(plan).load(json); |
|
|
|
|
|
|
|
|
|
|
|
line = file.readLine(); |
|
|
|
line = file.readLine(); |
|
|
|
} |
|
|
|
} |
|
|
@ -328,11 +336,14 @@ public class Train extends BaseClass implements Comparable<Train> { |
|
|
|
|
|
|
|
|
|
|
|
private Train load(JSONObject json) { |
|
|
|
private Train load(JSONObject json) { |
|
|
|
pushPull = json.getBoolean(PUSH_PULL); |
|
|
|
pushPull = json.getBoolean(PUSH_PULL); |
|
|
|
|
|
|
|
if (json.has(BLOCK)) block = (Block) plan.get(json.getString(BLOCK), false); |
|
|
|
|
|
|
|
if (json.has(DIRECTION)) direction = Direction.valueOf(json.getString(DIRECTION)); |
|
|
|
if (json.has(NAME)) name = json.getString(NAME); |
|
|
|
if (json.has(NAME)) name = json.getString(NAME); |
|
|
|
|
|
|
|
if (json.has(TAGS)) json.getJSONArray(TAGS ).forEach(elem -> { tags.add(elem.toString()); }); |
|
|
|
|
|
|
|
if (json.has(TRACE)) json.getJSONArray(TRACE).forEach(elem -> { trace.add(plan.get(elem.toString(), false).set(this)); }); |
|
|
|
for (Object id : json.getJSONArray(CARS)) add(Car.get(id)); |
|
|
|
for (Object id : json.getJSONArray(CARS)) add(Car.get(id)); |
|
|
|
for (Object id : json.getJSONArray(LOCOS)) add((Locomotive) Car.get(id)); |
|
|
|
for (Object id : json.getJSONArray(LOCOS)) add((Locomotive) Car.get(id)); |
|
|
|
if (json.has(TAGS)) json.getJSONArray(TAGS).forEach(elem -> { tags.add(elem.toString()); }); |
|
|
|
|
|
|
|
if (json.has(DIRECTION)) direction = Direction.valueOf(json.getString(DIRECTION)); |
|
|
|
|
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -523,7 +534,7 @@ public class Train extends BaseClass implements Comparable<Train> { |
|
|
|
private Object stopNow() { |
|
|
|
private Object stopNow() { |
|
|
|
quitAutopilot(); |
|
|
|
quitAutopilot(); |
|
|
|
setSpeed(0); |
|
|
|
setSpeed(0); |
|
|
|
route = null; |
|
|
|
if (isSet(route)) route.reset(); |
|
|
|
return t("Stopped {}.",this); |
|
|
|
return t("Stopped {}.",this); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|