Correctly handle placing already placed trains and correctly handle small trains on larger rails

This commit is contained in:
Arne Keller 2020-02-17 09:43:54 +01:00
parent 9191028934
commit 2746b9e7cf
2 changed files with 3 additions and 3 deletions

View File

@ -320,7 +320,7 @@ public class ModelRailwaySimulation {
*/
public boolean putTrain(final int trainId, final Vector2D position, final Vector2D direction) {
Train train = getTrain(trainId);
if (train == null || !train.isProperTrain()) {
if (train == null || !train.isProperTrain() || train.isPlaced()) {
return false;
}

View File

@ -290,7 +290,7 @@ public final class Train {
// we are really leaving this rail
occupiedRails.remove(leavingRail);
} // else: we are still on the rail
} else if (getLength() == 1) {
} else if (getLength() == 1 && railNetwork.findContainingRail(secondToLastPosition) == null) {
// we evidently just moved into another rail
occupiedRails.clear();
} // else: only touched rail
@ -298,7 +298,7 @@ public final class Train {
Rail nextRail = railNetwork.findContainingRail(nextPosition);
if (nextRail != null) {
occupiedRails.add(nextRail);
} else if (getLength() == 1) {
} else if (getLength() == 1 && railNetwork.findContainingRail(secondToLastPosition) == null) {
// we evidently just moved into another rail
Rail[] nextTouchingRails = railNetwork.findTouchingRails(nextPosition);
Rail[] alreadyTouchingRails = railNetwork.findTouchingRails(secondToLastPosition);