games.strategy.triplea.delegate
Class AbstractPlaceDelegate

java.lang.Object
  extended by games.strategy.triplea.delegate.AbstractPlaceDelegate
All Implemented Interfaces:
IDelegate, IRemote, IAbstractPlaceDelegate
Direct Known Subclasses:
BidPlaceDelegate, PlaceDelegate, PlaceDelegate

public abstract class AbstractPlaceDelegate
extends java.lang.Object
implements IDelegate, IAbstractPlaceDelegate

Logic for placing units.

Version:
1.0 Known limitations. Doesnt take into account limits on number of factories that can be produced. The situation where one has two non original factories a,b each with production 2. If sea zone e neighbors a,b and sea zone f neighbors b. Then producing 2 in e could make it such that you cannot produce in f. The reason is that the production in e could be assigned to the factory in b, leaving no capacity to produce in f. If anyone ever accidently runs into this situation then they can undo the production, produce in f first, and then produce in e.
Author:
Sean Bridges

Field Summary
protected  GameData m_data
           
protected  java.util.Map<Territory,java.util.Collection<Unit>> m_produced
           
 
Constructor Summary
AbstractPlaceDelegate()
           
 
Method Summary
protected  java.lang.String canProduce(Territory to, java.util.Collection<Unit> units, PlayerID player)
          Test whether or not the territory has the factory resources to support the placement.
 java.lang.String canUnitsBePlaced(Territory to, java.util.Collection<Unit> units, PlayerID player)
           
protected  java.lang.String checkProduction(Territory to, java.util.Collection<Unit> units, PlayerID player)
          Test whether or not the territory has the factory resources to support the placement.
 void end()
          Called before the delegate will stop running.
protected  GameData getData()
           
 java.lang.String getDisplayName()
           
protected  int getMaxUnitsToBePlaced(java.util.Collection<Unit> units, Territory to, PlayerID player)
           
 java.lang.String getName()
           
 PlaceableUnits getPlaceableUnits(java.util.Collection<Unit> units, Territory to)
          Query what units can be produced in a given territory.
 int getPlacementsMade()
           
protected  int getProduction(Territory territory)
           
 java.lang.Class<? extends IRemote> getRemoteType()
          Get the remote type of this delegate for use by a RemoteMessenger.
 java.util.Collection<Territory> getTerritoriesWhereAirCantLand()
          Get what air units must move before the end of the players turn
protected  java.util.Collection<Unit> getUnitsToBePlacedLand(Territory to, java.util.Collection<Unit> units, PlayerID player)
           
protected  java.util.Collection<Unit> getUnitsToBePlacedSea(Territory to, java.util.Collection<Unit> units, PlayerID player)
           
 void initialize(java.lang.String name)
           
 void initialize(java.lang.String name, java.lang.String displayName)
           
protected  boolean isUnitPlacementInEnemySeas()
           
protected  java.lang.String isValidPlacement(java.util.Collection<Unit> units, Territory at, PlayerID player)
          Subclasses can over ride this to change the way placements are made.
protected  boolean isWW2V2()
           
 void loadState(java.io.Serializable aState)
          Loads the delegates state
 java.lang.String placeUnits(java.util.Collection<Unit> units, Territory at)
          Place units.
 java.io.Serializable saveState()
          Returns the state of the Delegate.
 void start(IDelegateBridge aBridge, GameData gameData)
          Called before the delegate will run.
 void undoLastPlacement()
          Undoes the last placement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_produced

protected java.util.Map<Territory,java.util.Collection<Unit>> m_produced

m_data

protected GameData m_data
Constructor Detail

AbstractPlaceDelegate

public AbstractPlaceDelegate()
Method Detail

initialize

public void initialize(java.lang.String name)

initialize

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

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

getPlacementsMade

public int getPlacementsMade()
Specified by:
getPlacementsMade in interface IAbstractPlaceDelegate
Returns:
the number of placements made so far. this is not the number of units placed, but the number of times we have made succesful placements

undoLastPlacement

public void undoLastPlacement()
Description copied from interface: IAbstractPlaceDelegate
Undoes the last placement.

Specified by:
undoLastPlacement in interface IAbstractPlaceDelegate

placeUnits

public java.lang.String placeUnits(java.util.Collection<Unit> units,
                                   Territory at)
Description copied from interface: IAbstractPlaceDelegate
Place units. The return value is used to return an error code if the placement was not successful

Specified by:
placeUnits in interface IAbstractPlaceDelegate

getPlaceableUnits

public PlaceableUnits getPlaceableUnits(java.util.Collection<Unit> units,
                                        Territory to)
Description copied from interface: IAbstractPlaceDelegate
Query what units can be produced in a given territory. ProductionResponse may indicate an error string that there can be no units placed in a given territory

Specified by:
getPlaceableUnits in interface IAbstractPlaceDelegate
Returns:

isValidPlacement

protected java.lang.String isValidPlacement(java.util.Collection<Unit> units,
                                            Territory at,
                                            PlayerID player)
Subclasses can over ride this to change the way placements are made.

Returns:
null if placement is valid

canUnitsBePlaced

public java.lang.String canUnitsBePlaced(Territory to,
                                         java.util.Collection<Unit> units,
                                         PlayerID player)

getUnitsToBePlacedSea

protected java.util.Collection<Unit> getUnitsToBePlacedSea(Territory to,
                                                           java.util.Collection<Unit> units,
                                                           PlayerID player)

getUnitsToBePlacedLand

protected java.util.Collection<Unit> getUnitsToBePlacedLand(Territory to,
                                                            java.util.Collection<Unit> units,
                                                            PlayerID player)

getMaxUnitsToBePlaced

protected int getMaxUnitsToBePlaced(java.util.Collection<Unit> units,
                                    Territory to,
                                    PlayerID player)

getProduction

protected int getProduction(Territory territory)
Returns:
gets the production of the territory, ignores wether the territory was an original factory

canProduce

protected java.lang.String canProduce(Territory to,
                                      java.util.Collection<Unit> units,
                                      PlayerID player)
Test whether or not the territory has the factory resources to support the placement. AlreadyProduced maps territory->units already produced this turn by that territory.


checkProduction

protected java.lang.String checkProduction(Territory to,
                                           java.util.Collection<Unit> units,
                                           PlayerID player)
Test whether or not the territory has the factory resources to support the placement. AlreadyProduced maps territory->units already produced this turn by that territory.


isWW2V2

protected boolean isWW2V2()

isUnitPlacementInEnemySeas

protected boolean isUnitPlacementInEnemySeas()

end

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

Specified by:
end in interface IDelegate

getTerritoriesWhereAirCantLand

public java.util.Collection<Territory> getTerritoriesWhereAirCantLand()
Get what air units must move before the end of the players turn

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

saveState

public final java.io.Serializable saveState()
Returns the state of the Delegate.

Specified by:
saveState in interface IDelegate

getRemoteType

public java.lang.Class<? extends IRemote> 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 final void loadState(java.io.Serializable aState)
Loads the delegates state

Specified by:
loadState in interface IDelegate

getData

protected GameData getData()