Added code for removing units on the non-visible parts of the client map.

This commit is contained in:
Stian Grenborgen 2004-06-07 14:02:55 +00:00
parent 71ab7ab6c1
commit 36a2fbcc81
3 changed files with 35 additions and 5 deletions

View File

@ -230,6 +230,7 @@ public final class InGameInputHandler implements MessageHandler {
game.setCurrentPlayer(currentPlayer);
if (freeColClient.getMyPlayer().equals(currentPlayer)) {
removeUnitsOutsideLOS();
freeColClient.getCanvas().setEnabled(true);
freeColClient.getCanvas().closeMenus();
freeColClient.getInGameController().nextActiveUnit();
@ -241,6 +242,21 @@ public final class InGameInputHandler implements MessageHandler {
return null;
}
private void removeUnitsOutsideLOS() {
Player player = freeColClient.getMyPlayer();
Map map = freeColClient.getGame().getMap();
Iterator tileIterator = map.getWholeMapIterator();
while (tileIterator.hasNext()) {
Tile t = map.getTile((Map.Position) tileIterator.next());
if (t != null && !player.canSee(t) && t.getFirstUnit() != null) {
t.disposeAllUnits();
}
}
}
/**
* Handles an "emigrateUnitInEuropeConfirmed"-message.
*

View File

@ -187,6 +187,14 @@ public final class Tile extends FreeColGameObject implements Location {
}
/**
* Disposes all units on this <code>Tile</code>.
*/
public void disposeAllUnits() {
unitContainer.disposeAllUnits();
}
/**
* Gets the first <code>Unit</code> on this tile.
* @return The first <code>Unit</code> on this tile.

View File

@ -193,15 +193,21 @@ public class UnitContainer extends FreeColGameObject {
* Removes all references to this object.
*/
public void dispose() {
Iterator i = getUnitIterator();
while (i.hasNext()) {
((Unit) i.next()).dispose();
}
disposeAllUnits();
super.dispose();
}
/**
* Disposes all units in this <code>UnitContainer</code>.
*/
public void disposeAllUnits() {
for (int i=units.size()-1; i>=0; i--) {
((Unit) units.get(i)).dispose();
}
}
/**
* Prepares this <code>UnitContainer</code> for a new turn.
*/