public void afterGameChanged(MoveUnit moveUnit) {
process(moveUnit, false, true);
}
private void process(MoveUnit moveUnit, boolean before, boolean after) {
MapData mapData = Game.getMapData();
Long unitID = moveUnit.getUnitID();
Long ownerID = mapData.getUnit(unitID).getOwnerID();
Coordinate from = moveUnit.getFrom();
Coordinate to = moveUnit.getTo();
if (manager.getNationID().equals(ownerID)) {
if (after) {
manager.unitMoved(from, to);
}
moveUnit.notify(manager.getRestrictedToNation(), before, after);
} else {
if (manager.isCompleteVisible(from)) {
if (manager.isCompleteVisible(to)) {
moveUnit.notify(manager.getRestrictedToNation(), before, after);
} else {
RemoveUnit removeUnit = new RemoveUnit(manager.getRestrictedToNation(),
unitID);
removeUnit.notify(before, after);
if (before) {
manager.removeForeignUnit(unitID);
}
}
} else {
if (manager.isCompleteVisible(to)) {
if (after) {
manager.addForeignUnit(unitID);
}
ConstructUnit constructUnit
= new ConstructUnit(manager.getRestrictedToNation(),
mapData.getMapObjectPosition(unitID),
mapData.getMapObjectOwner(unitID));
constructUnit.notify(before, after);
} else {
// do nothing, nothing is visible
}
}