games.strategy.triplea.delegate
Class MoveDelegate

java.lang.Object
  extended by games.strategy.triplea.delegate.MoveDelegate
All Implemented Interfaces:
IDelegate, IRemote, IMoveDelegate

public class MoveDelegate
extends java.lang.Object
implements IDelegate, IMoveDelegate

Responsible for moving units on the board.

Responible for checking the validity of a move, and for moving the units.

Version:
1.0
Author:
Sean Bridges

Constructor Summary
MoveDelegate()
          Creates new MoveDelegate
 
Method Summary
 void end()
          Called before the delegate will stop running.
 Change ensureCanMoveOneSpaceChange(Unit unit)
           
static BattleTracker getBattleTracker(GameData data)
           
 java.lang.String getDisplayName()
           
static java.util.Collection<Territory> getEmptyNeutral(Route route)
           
 java.util.List<UndoableMove> getMovesMade()
          Get the moves already made
 java.lang.String getName()
           
 java.lang.Class<IMoveDelegate> getRemoteType()
          Get the remote type of this delegate for use by a RemoteMessenger.
static Route getRouteUsedToMoveInto(java.util.List<UndoableMove> undoableMoves, Unit unit, Territory end)
          Find the route that a unit used to move into the given territory.
 Route getRouteUsedToMoveInto(Unit unit, Territory end)
          Find the route that a unit used to move into the given territory.
 java.util.Collection<Territory> getTerritoriesWhereAirCantLand()
          Get what air units must move before the end of the players turn
 java.util.Collection<Territory> getTerritoriesWhereUnitsCantFight()
          Get what units must have combat ability
 TransportTracker getTransportTracker()
           
 void initialize(java.lang.String name, java.lang.String displayName)
           
static boolean isNonCombat(IDelegateBridge aBridge)
           
 java.lang.String loadBombers(java.util.Collection<Unit> units, Route route, java.util.Collection<Unit> transportsThatCanBeLoaded)
           
 void loadState(java.io.Serializable aState)
          Loads the delegates state
static java.util.Map<Unit,Unit> mapBombers(Route route, java.util.Collection<Unit> units, java.util.Collection<Unit> bombersToLoad)
          returns a map of unit -> bomber. returns null if no mapping can be done either because there is not sufficient transport capacity or because a unit is not with its transport This method is static so it can be called from the client side.
static java.util.Map<Unit,Unit> mapTransports(Route route, java.util.Collection<Unit> units, java.util.Collection<Unit> transportsToLoad)
          returns a map of unit -> transport. returns null if no mapping can be done either because there is not sufficient transport capacity or because a unit is not with its transport This method is static so it can be called from the client side.
static java.util.Map<Unit,Unit> mapTransports(Route route, java.util.Collection<Unit> units, java.util.Collection<Unit> transportsToLoad, boolean isload, PlayerID player)
          returns a map of unit -> transport. returns null if no mapping can be done either because there is not sufficient transport capacity or because a unit is not with its transport This method is static so it can be called from the client side.
 Change markNoMovementChange(java.util.Collection<Unit> units)
          Mark units as having no movement.
 java.lang.String move(java.util.Collection<Unit> units, Route route)
          equivalent to move(units, route, Collections.EMPTY_LIST)
 java.lang.String move(java.util.Collection<Unit> units, Route route, java.util.Collection<Unit> transportsThatCanBeLoaded)
           
 int PUsAlreadyLost(Territory t)
          Return the number of PUs that have been lost by bombing, rockets, etc.
 void PUsLost(Territory t, int amt)
          Add more PUs lost to a territory due to bombing, rockets, etc.
 java.io.Serializable saveState()
          Returns the state of the Delegate.
 void start(IDelegateBridge aBridge, GameData gameData)
          Called before the delegate will run.
 java.lang.String undoMove(int moveIndex)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MoveDelegate

public MoveDelegate()
Creates new MoveDelegate

Method Detail

initialize

public void initialize(java.lang.String name,
                       java.lang.String displayName)
Specified by:
initialize in interface IDelegate

isNonCombat

public static boolean isNonCombat(IDelegateBridge aBridge)

start

public void start(IDelegateBridge aBridge,
                  GameData gameData)
Called before the delegate will run.

Specified by:
start in interface IDelegate

getName

public java.lang.String getName()
Specified by:
getName in interface IDelegate

getDisplayName

public java.lang.String getDisplayName()
Specified by:
getDisplayName in interface IDelegate

getMovesMade

public java.util.List<UndoableMove> getMovesMade()
Description copied from interface: IMoveDelegate
Get the moves already made

Specified by:
getMovesMade in interface IMoveDelegate
Returns:
a list of UndoableMoves

undoMove

public java.lang.String undoMove(int moveIndex)
Specified by:
undoMove in interface IMoveDelegate
Parameters:
moveIndex - - an index in the list getMovesMade
Returns:
an error string if the move could not be undone, null otherwise

move

public java.lang.String move(java.util.Collection<Unit> units,
                             Route route)
Description copied from interface: IMoveDelegate
equivalent to move(units, route, Collections.EMPTY_LIST)

Specified by:
move in interface IMoveDelegate
Parameters:
units - - the units to move
route - - the route to move along
Returns:
an error message if the move cant be made, null otherwise

move

public java.lang.String move(java.util.Collection<Unit> units,
                             Route route,
                             java.util.Collection<Unit> transportsThatCanBeLoaded)
Specified by:
move in interface IMoveDelegate
Parameters:
units - - the units to move
route - - the route to move along
transportsThatCanBeLoaded - - transports that can be loaded while moving, must be non null
Returns:
an error message if the move cant be made, null otherwise

loadBombers

public java.lang.String loadBombers(java.util.Collection<Unit> units,
                                    Route route,
                                    java.util.Collection<Unit> transportsThatCanBeLoaded)
Specified by:
loadBombers in interface IMoveDelegate
Parameters:
units - - the units to move
route - - the route to move along
transportsThatCanBeLoaded - - bombers that can be loaded while moving, must be non null
Returns:
an error message if the move cant be made, null otherwise

getBattleTracker

public static BattleTracker getBattleTracker(GameData data)

getEmptyNeutral

public static java.util.Collection<Territory> getEmptyNeutral(Route route)

markNoMovementChange

public Change markNoMovementChange(java.util.Collection<Unit> units)
Mark units as having no movement.


ensureCanMoveOneSpaceChange

public Change ensureCanMoveOneSpaceChange(Unit unit)

end

public void end()
Called before the delegate will stop running.

Specified by:
end in interface IDelegate

mapTransports

public static java.util.Map<Unit,Unit> mapTransports(Route route,
                                                     java.util.Collection<Unit> units,
                                                     java.util.Collection<Unit> transportsToLoad)
returns a map of unit -> transport. returns null if no mapping can be done either because there is not sufficient transport capacity or because a unit is not with its transport This method is static so it can be called from the client side.


mapTransports

public static java.util.Map<Unit,Unit> mapTransports(Route route,
                                                     java.util.Collection<Unit> units,
                                                     java.util.Collection<Unit> transportsToLoad,
                                                     boolean isload,
                                                     PlayerID player)
returns a map of unit -> transport. returns null if no mapping can be done either because there is not sufficient transport capacity or because a unit is not with its transport This method is static so it can be called from the client side.


mapBombers

public static java.util.Map<Unit,Unit> mapBombers(Route route,
                                                  java.util.Collection<Unit> units,
                                                  java.util.Collection<Unit> bombersToLoad)
returns a map of unit -> bomber. returns null if no mapping can be done either because there is not sufficient transport capacity or because a unit is not with its transport This method is static so it can be called from the client side.


getTerritoriesWhereAirCantLand

public java.util.Collection<Territory> getTerritoriesWhereAirCantLand()
Description copied from interface: IMoveDelegate
Get what air units must move before the end of the players turn

Specified by:
getTerritoriesWhereAirCantLand in interface IMoveDelegate
Returns:
a list of Territories with air units that must move

getTerritoriesWhereUnitsCantFight

public java.util.Collection<Territory> getTerritoriesWhereUnitsCantFight()
Description copied from interface: IMoveDelegate
Get what units must have combat ability

Specified by:
getTerritoriesWhereUnitsCantFight in interface IMoveDelegate
Returns:
a list of Territories with units that can't fight

getRouteUsedToMoveInto

public Route getRouteUsedToMoveInto(Unit unit,
                                    Territory end)
Find the route that a unit used to move into the given territory.


getRouteUsedToMoveInto

public static Route getRouteUsedToMoveInto(java.util.List<UndoableMove> undoableMoves,
                                           Unit unit,
                                           Territory end)
Find the route that a unit used to move into the given territory. This method is static so it can be called from the client side.


PUsAlreadyLost

public int PUsAlreadyLost(Territory t)
Return the number of PUs that have been lost by bombing, rockets, etc.


PUsLost

public void PUsLost(Territory t,
                    int amt)
Add more PUs lost to a territory due to bombing, rockets, etc.


getTransportTracker

public TransportTracker getTransportTracker()

saveState

public java.io.Serializable saveState()
Description copied from interface: IDelegate
Returns the state of the Delegate.

Specified by:
saveState in interface IDelegate

getRemoteType

public java.lang.Class<IMoveDelegate> getRemoteType()
Description copied from interface: IDelegate
Get the remote type of this delegate for use by a RemoteMessenger. Class must be an interface that extends IRemote If the return value is null, then it indicates that this delegate should not be used as in IRemote.

Specified by:
getRemoteType in interface IDelegate

loadState

public void loadState(java.io.Serializable aState)
Loads the delegates state

Specified by:
loadState in interface IDelegate