net.sf.freecol.server.ai
Class NativeAIPlayer

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColObject
      extended by net.sf.freecol.server.ai.AIObject
          extended by net.sf.freecol.server.ai.AIPlayer
              extended by net.sf.freecol.server.ai.NativeAIPlayer

public class NativeAIPlayer
extends AIPlayer

Objects of this class contains AI-information for a single Player and is used for controlling this player. The method startWorking() gets called by the AIInGameInputHandler when it is this player's turn.


Field Summary
private static java.util.logging.Logger logger
           
private static java.lang.String MISSIONARY_TRADE_BONUS
          The modifier to apply when to trade with a settlement with a missionary if the enhancedMissionaries option is enabled.
private  java.util.HashMap<java.lang.String,java.lang.Integer> sessionRegister
          Stores temporary information for sessions (trading with another player etc).
private static java.lang.String SHIP_TRADE_PENALTY
          The modifier to apply when a ship is trading.
 
Fields inherited from class net.sf.freecol.server.ai.AIPlayer
MAX_DISTANCE_TO_BRING_GIFT, MAX_DISTANCE_TO_MAKE_DEMANDS, MAX_NUMBER_OF_DEMANDS, MAX_NUMBER_OF_GIFTS_BEING_DELIVERED
 
Fields inherited from class net.sf.freecol.server.ai.AIObject
uninitialized
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, INFINITY, NO_ID, PARTIAL_ATTRIBUTE, UNDEFINED, VALUE_TAG
 
Constructor Summary
NativeAIPlayer(AIMain aiMain, org.w3c.dom.Element element)
          Creates a new AIPlayer and reads the information from the given Element.
NativeAIPlayer(AIMain aiMain, ServerPlayer player)
          Creates a new AIPlayer.
NativeAIPlayer(AIMain aiMain, javax.xml.stream.XMLStreamReader in)
          Creates a new AIPlayer.
 
Method Summary
 boolean acceptDiplomaticTrade(DiplomaticTrade agreement)
           
private  void bringGifts()
          Brings gifts to nice players with nearby colonies.
 int buyProposition(Unit unit, Settlement settlement, Goods goods, int gold)
          Called when another Player proposes to buy.
private  void demandTribute()
          Demands goods from players with nearby colonies.
 void equipBraves(IndianSettlement is)
          Greedily equips braves with horses and muskets.
private  AIUnit getBraveForSeekAndDestroy(IndianSettlement indianSettlement)
           
private  java.util.Set<Modifier> getMissionaryTradeBonuses(Unit missionary, boolean sense)
          Gets the appropriate missionary trade bonuses.
private  java.util.Set<Modifier> getShipTradePenalties(boolean sense)
          Gets the appropriate ship trade penalties.
(package private)  int getUnitSeekAndDestroyMissionValue(Unit unit, Tile newTile, int turns)
          Evaluate a potential seek and destroy mission for a given unit to a given tile.
 void giveMilitaryMission(AIUnit aiUnit)
          Gives a military mission to the given unit.
private  void giveNormalMissions()
          Gives a mission to non-naval units.
 void registerSellGoods(Goods goods)
          Called after another Player sends a trade message.
(package private)  void secureIndianSettlement(IndianSettlement is)
          Takes the necessary actions to secure an indian settlement TODO: Package for access by a test only - necessary?
private  void secureSettlements()
          Takes the necessary actions to secure the settlements.
 int sellProposition(Unit unit, Settlement settlement, Goods goods, int gold)
          Called when another Player proposes a sale.
 void startWorking()
          Tells this AIPlayer to make decisions.
 
Methods inherited from class net.sf.freecol.server.ai.AIPlayer
abortInvalidAndOneTimeMissions, abortInvalidMissions, acceptMercenaries, acceptTax, clearAIUnits, determineStance, determineStances, doMissions, getAIAdvantage, getAIColonies, getAIColony, getAIRandom, getAIUnit, getAIUnitIterator, getAIUnits, getConnection, getId, getPlayer, getXMLElementTagName, indianDemand, isTargetValidForSeekAndDestroy, readFromXMLImpl, selectFoundingFather, setDebuggingConnection, setPlayer, toXMLImpl
 
Methods inherited from class net.sf.freecol.server.ai.AIObject
dispose, getAIMain, getGame, getSpecification, isUninitialized, readFromXML
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getPropertyChangeListeners, getPropertyChangeListeners, hasAbility, hasAttribute, hasListeners, readAttributes, readAttributes, readChild, readChild, readChildren, readChildren, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXMLElement, readFromXMLImpl, readFromXMLPartialImpl, removePropertyChangeListener, removePropertyChangeListener, save, save, setId, setSpecification, toXML, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, toXMLPartialImpl, writeAttribute, writeAttributes, writeChildren
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static final java.util.logging.Logger logger

SHIP_TRADE_PENALTY

private static final java.lang.String SHIP_TRADE_PENALTY
The modifier to apply when a ship is trading.

See Also:
Constant Field Values

MISSIONARY_TRADE_BONUS

private static final java.lang.String MISSIONARY_TRADE_BONUS
The modifier to apply when to trade with a settlement with a missionary if the enhancedMissionaries option is enabled.

See Also:
Constant Field Values

sessionRegister

private java.util.HashMap<java.lang.String,java.lang.Integer> sessionRegister
Stores temporary information for sessions (trading with another player etc).

Constructor Detail

NativeAIPlayer

public NativeAIPlayer(AIMain aiMain,
                      ServerPlayer player)
Creates a new AIPlayer.

Parameters:
aiMain - The main AI-class.
player - The player that should be associated with this AIPlayer.

NativeAIPlayer

public NativeAIPlayer(AIMain aiMain,
                      org.w3c.dom.Element element)
Creates a new AIPlayer and reads the information from the given Element.

Parameters:
aiMain - The main AI-class.
element - The XML-element containing information.

NativeAIPlayer

public NativeAIPlayer(AIMain aiMain,
                      javax.xml.stream.XMLStreamReader in)
               throws javax.xml.stream.XMLStreamException
Creates a new AIPlayer.

Parameters:
aiMain - The main AI-object.
in - The input stream containing the XML.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.
Method Detail

startWorking

public void startWorking()
Tells this AIPlayer to make decisions. The AIPlayer is done doing work this turn when this method returns.

Specified by:
startWorking in class AIPlayer

acceptDiplomaticTrade

public boolean acceptDiplomaticTrade(DiplomaticTrade agreement)
Specified by:
acceptDiplomaticTrade in class AIPlayer

registerSellGoods

public void registerSellGoods(Goods goods)
Called after another Player sends a trade message.

Specified by:
registerSellGoods in class AIPlayer
Parameters:
goods - The goods which we are going to offer

getMissionaryTradeBonuses

private java.util.Set<Modifier> getMissionaryTradeBonuses(Unit missionary,
                                                          boolean sense)
Gets the appropriate missionary trade bonuses.

Parameters:
missionary - The missionary Unit.
sense - The sense to apply the modifiers.
Returns:
The missionary trade bonuses.

getShipTradePenalties

private java.util.Set<Modifier> getShipTradePenalties(boolean sense)
Gets the appropriate ship trade penalties.

Parameters:
sense - The sense to apply the modifiers.
Returns:
The ship trade penalties.

buyProposition

public int buyProposition(Unit unit,
                          Settlement settlement,
                          Goods goods,
                          int gold)
Called when another Player proposes to buy.

Specified by:
buyProposition in class AIPlayer
Parameters:
unit - The foreign Unit trying to trade.
settlement - The Settlement this player owns and which the given Unit is trading.
goods - The goods the given Unit is trying to sell.
gold - The suggested price.
Returns:
The price this AIPlayer suggests or NetworkConstants.NO_TRADE.

sellProposition

public int sellProposition(Unit unit,
                           Settlement settlement,
                           Goods goods,
                           int gold)
Called when another Player proposes a sale.

Specified by:
sellProposition in class AIPlayer
Parameters:
unit - The foreign Unit trying to trade.
settlement - The Settlement this player owns and which the given Unit if trying to sell goods.
goods - The goods the given Unit is trying to sell.
gold - The suggested price.
Returns:
The price this AIPlayer suggests or NetworkConstants#NO_TRADE*.

secureSettlements

private void secureSettlements()
Takes the necessary actions to secure the settlements. This is done by making new military units or to give existing units new missions.


equipBraves

public void equipBraves(IndianSettlement is)
Greedily equips braves with horses and muskets.

Parameters:
is - The IndianSettlement where the equipping occurs.

secureIndianSettlement

void secureIndianSettlement(IndianSettlement is)
Takes the necessary actions to secure an indian settlement TODO: Package for access by a test only - necessary?


getBraveForSeekAndDestroy

private AIUnit getBraveForSeekAndDestroy(IndianSettlement indianSettlement)

giveNormalMissions

private void giveNormalMissions()
Gives a mission to non-naval units.


bringGifts

private void bringGifts()
Brings gifts to nice players with nearby colonies.


demandTribute

private void demandTribute()
Demands goods from players with nearby colonies.


getUnitSeekAndDestroyMissionValue

int getUnitSeekAndDestroyMissionValue(Unit unit,
                                      Tile newTile,
                                      int turns)
Evaluate a potential seek and destroy mission for a given unit to a given tile. TODO: revisit and rebalance the mass of magic numbers.

Parameters:
unit - The Unit to do the mission.
newTile - The Tile to go to.
turns - How long to travel to the tile.
Returns:
A score for the proposed mission.

giveMilitaryMission

public void giveMilitaryMission(AIUnit aiUnit)
Gives a military mission to the given unit. Old comment: Temporary method for giving a military mission. This method will be removed when "MilitaryStrategy" and the "Tactic"-classes has been implemented.

Parameters:
aiUnit - The AIUnit to give a mission to.