games.strategy.triplea.delegate
Class PurchaseDelegate

java.lang.Object
  extended by games.strategy.triplea.delegate.PurchaseDelegate
All Implemented Interfaces:
IDelegate, IRemote, IPurchaseDelegate
Direct Known Subclasses:
BidPurchaseDelegate, NoPUPurchaseDelegate

public class PurchaseDelegate
extends java.lang.Object
implements IDelegate, IPurchaseDelegate

Logic for purchasing units. Subclasses can override canAfford(...) to test if a purchase can be made Subclasses can over ride addToPlayer(...) and removeFromPlayer(...) to change how the adding or removing of resources is done.

Version:
1.0
Author:
Sean Bridges

Constructor Summary
PurchaseDelegate()
           
 
Method Summary
protected  boolean canAfford(IntegerMap<Resource> costs, PlayerID player)
          subclasses can over ride this method to use different restrictions as to what a player can buy
 void end()
          Called before the delegate will stop running.
protected  GameData getData()
           
 java.lang.String getDisplayName()
           
 java.lang.String getName()
           
 java.lang.Class<? extends IRemote> getRemoteType()
          Get the remote type of this delegate for use by a RemoteMessenger.
 void initialize(java.lang.String name, java.lang.String displayName)
           
 void loadState(java.io.Serializable state)
          Loads the delegates state
 java.lang.String purchase(IntegerMap<ProductionRule> productionRules)
          Returns an error code, or null if all is good.
 java.lang.String purchaseRepair(java.util.Map<Territory,IntegerMap<RepairRule>> repairRules)
          Returns an error code, or null if all is good.
protected  java.lang.String removeFromPlayer(PlayerID player, IntegerMap<Resource> costs, CompositeChange changes, java.util.Collection<Unit> totalUnits)
           
 java.io.Serializable saveState()
          Returns the state of the Delegate.
 void start(IDelegateBridge aBridge, GameData gameData)
          Called before the delegate will run.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PurchaseDelegate

public PurchaseDelegate()
Method Detail

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

getData

protected GameData getData()

canAfford

protected boolean canAfford(IntegerMap<Resource> costs,
                            PlayerID player)
subclasses can over ride this method to use different restrictions as to what a player can buy


purchase

public java.lang.String purchase(IntegerMap<ProductionRule> productionRules)
Returns an error code, or null if all is good.

Specified by:
purchase in interface IPurchaseDelegate
Parameters:
productionRules - - units maps ProductionRule -> count
Returns:
null if units bought, otherwise an error message

purchaseRepair

public java.lang.String purchaseRepair(java.util.Map<Territory,IntegerMap<RepairRule>> repairRules)
Returns an error code, or null if all is good.

Specified by:
purchaseRepair in interface IPurchaseDelegate

saveState

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

Specified by:
saveState in interface IDelegate

loadState

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

Specified by:
loadState in interface IDelegate

end

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

Specified by:
end 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

removeFromPlayer

protected java.lang.String removeFromPlayer(PlayerID player,
                                            IntegerMap<Resource> costs,
                                            CompositeChange changes,
                                            java.util.Collection<Unit> totalUnits)