net.sf.freecol.server.ai
Class AIMessage

java.lang.Object
  extended by net.sf.freecol.server.ai.AIMessage

public class AIMessage
extends java.lang.Object

Wrapper class for AI message handling.


Field Summary
private static java.util.logging.Logger logger
           
 
Constructor Summary
AIMessage()
           
 
Method Summary
static boolean askAttack(AIUnit aiUnit, Map.Direction direction)
          An AIUnit attacks in the given direction.
static boolean askBuildColony(AIUnit aiUnit, java.lang.String name)
          An AIUnit builds a colony.
static boolean askBuyGoods(AIUnit aiUnit, GoodsType type, int amount)
          An AIUnit buys goods.
static boolean askCashInTreasureTrain(AIUnit aiUnit)
          An AIUnit cashes in.
static boolean askChangeState(AIUnit aiUnit, Unit.UnitState state)
          An AIUnit changes state.
static boolean askChangeWorkImprovementType(AIUnit aiUnit, TileImprovementType type)
          An AIUnit changes its work improvement type.
static boolean askChangeWorkType(AIUnit aiUnit, GoodsType type)
          An AIUnit changes its work type.
static boolean askClaimLand(Connection conn, Tile tile, Colony colony, int price)
          Claims a tile for a colony.
static boolean askClearSpeciality(AIUnit aiUnit)
          Clears the speciality of a unit.
static boolean askCloseTransaction(AIUnit aiUnit, Settlement settlement)
          An AIUnit closes a transaction.
static boolean askDeliverGift(AIUnit aiUnit, Settlement settlement, Goods goods)
          An AIUnit delivers a gift.
static boolean askDisembark(AIUnit aiUnit)
          An AIUnit disembarks.
static boolean askEmbark(AIUnit aiUnit, Unit unit, Map.Direction direction)
          An AIUnit embarks.
static boolean askEmigrate(Connection connection, int slot)
          A unit in Europe emigrates.
static boolean askEndTurn(Connection connection)
          Ends the player turn.
static boolean askEquipUnit(AIUnit aiUnit, EquipmentType type, int amount)
          Change the equipment of a unit.
static boolean askEstablishMission(AIUnit aiUnit, Map.Direction direction, boolean denounce)
          Establishes a mission in the given direction.
static boolean askGetTransaction(AIUnit aiUnit, Settlement settlement)
          An AIUnit gets a transaction.
static boolean askIndianDemand(AIUnit aiUnit, Colony colony, Goods goods, int gold)
          Makes demands to a colony.
static boolean askLoadCargo(AIUnit aiUnit, Goods goods)
          An AI unit loads some cargo.
static boolean askLoot(AIUnit aiUnit, java.lang.String defenderId, java.util.List<Goods> goods)
          An AI unit loots some cargo.
private static org.w3c.dom.Element askMessage(Connection connection, org.w3c.dom.Element request)
          Ask the server a question.
static boolean askMove(AIUnit aiUnit, Map.Direction direction)
          Moves an AIUnit in the given direction.
static boolean askMoveTo(AIUnit aiUnit, Location destination)
          Moves an AIUnit across the high seas.
static boolean askPutOutsideColony(AIUnit aiUnit)
          An AIUnit is put outside a colony.
static boolean askScoutIndianSettlement(AIUnit aiUnit, Map.Direction direction)
          An AI unit scouts a native settlement.
static boolean askSellGoods(AIUnit aiUnit, Goods goods)
          An AI unit sells some cargo.
static boolean askSetBuildQueue(AIColony aiColony, java.util.List<BuildableType> queue)
          Set the build queue in a colony.
static boolean askTrainUnitInEurope(Connection connection, UnitType type)
          Train unit in Europe.
static boolean askUnloadCargo(AIUnit aiUnit, Goods goods)
          An AI unit unloads some cargo.
static boolean askWork(AIUnit aiUnit, WorkLocation workLocation)
          Set a unit to work in a work location.
static org.w3c.dom.Element makeTrivial(java.lang.String tag, java.lang.String... attributes)
          Make a trivial message.
private static boolean sendMessage(Connection connection, DOMMessage message)
          Send a message to the server.
private static boolean sendMessage(Connection connection, org.w3c.dom.Element request)
          Sends a DOMMessage to the server.
static boolean sendTrivial(Connection connection, java.lang.String tag, java.lang.String... attributes)
          Send a trivial message.
 
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
Constructor Detail

AIMessage

public AIMessage()
Method Detail

askMessage

private static org.w3c.dom.Element askMessage(Connection connection,
                                              org.w3c.dom.Element request)
Ask the server a question.

Parameters:
connection - The Connection to use when communicating with the server.
request - The Element to send.
Returns:
The reply element.

sendMessage

private static boolean sendMessage(Connection connection,
                                   org.w3c.dom.Element request)
Sends a DOMMessage to the server.

Parameters:
connection - The Connection to use when communicating with the server.
request - The Element to send.
Returns:
True if the message was sent, and a non-null, non-error reply returned.

sendMessage

private static boolean sendMessage(Connection connection,
                                   DOMMessage message)
Send a message to the server.

Parameters:
connection - The Connection to use when communicating with the server.
message - The Message to send.
Returns:
True if the message was sent, and a non-null, non-error reply returned.

sendTrivial

public static boolean sendTrivial(Connection connection,
                                  java.lang.String tag,
                                  java.lang.String... attributes)
Send a trivial message.

Parameters:
connection - The Connection to send on.
tag - The tag of the message.
attributes - Attributes to add to the message.
Returns:
True if the message was sent, and a non-error reply returned.

makeTrivial

public static org.w3c.dom.Element makeTrivial(java.lang.String tag,
                                              java.lang.String... attributes)
Make a trivial message.

Parameters:
tag - The tag of the message.
attributes - Attributes to add to the message.
Returns:
The Element encapsulating the message.

askAttack

public static boolean askAttack(AIUnit aiUnit,
                                Map.Direction direction)
An AIUnit attacks in the given direction.

Parameters:
aiUnit - The AIUnit to attack with.
direction - The Direction to attack in.
Returns:
True if the message was sent, and a non-error reply returned.

askBuildColony

public static boolean askBuildColony(AIUnit aiUnit,
                                     java.lang.String name)
An AIUnit builds a colony.

Parameters:
aiUnit - The AIUnit to build the colony.
name - The name of the colony.
Returns:
True if the message was sent, and a non-error reply returned.

askBuyGoods

public static boolean askBuyGoods(AIUnit aiUnit,
                                  GoodsType type,
                                  int amount)
An AIUnit buys goods.

Parameters:
aiUnit - The AIUnit buys goods.
type - The GoodsType to buy.
amount - The amount of goods to buy.
Returns:
True if the message was sent, and a non-error reply returned.

askCashInTreasureTrain

public static boolean askCashInTreasureTrain(AIUnit aiUnit)
An AIUnit cashes in.

Parameters:
aiUnit - The AIUnit cashing in.
Returns:
True if the message was sent, and a non-error reply returned.

askChangeState

public static boolean askChangeState(AIUnit aiUnit,
                                     Unit.UnitState state)
An AIUnit changes state.

Parameters:
aiUnit - The AIUnit to change the state of.
state - The new UnitState.
Returns:
True if the message was sent, and a non-error reply returned.

askChangeWorkType

public static boolean askChangeWorkType(AIUnit aiUnit,
                                        GoodsType type)
An AIUnit changes its work type.

Parameters:
aiUnit - The AIUnit to change the work type of.
type - The GoodsType to produce.
Returns:
True if the message was sent, and a non-error reply returned.

askChangeWorkImprovementType

public static boolean askChangeWorkImprovementType(AIUnit aiUnit,
                                                   TileImprovementType type)
An AIUnit changes its work improvement type.

Parameters:
aiUnit - The AIUnit to change the work type of.
type - The TileImprovementType to produce.
Returns:
True if the message was sent, and a non-error reply returned.

askClaimLand

public static boolean askClaimLand(Connection conn,
                                   Tile tile,
                                   Colony colony,
                                   int price)
Claims a tile for a colony.

Parameters:
conn - The Connection to send on.
tile - The Tile to claim.
colony - The Colony claiming the tile.
price - The price to pay.
Returns:
True if the message was sent, and a non-error reply returned.

askClearSpeciality

public static boolean askClearSpeciality(AIUnit aiUnit)
Clears the speciality of a unit.

Parameters:
aiUnit - The AIUnit to clear.
Returns:
True if the message was sent, and a non-error reply returned.

askCloseTransaction

public static boolean askCloseTransaction(AIUnit aiUnit,
                                          Settlement settlement)
An AIUnit closes a transaction.

Parameters:
aiUnit - The AIUnit that closes the transaction.
settlement - The target Settlement.
Returns:
True if the message was sent, and a non-error reply returned.

askDeliverGift

public static boolean askDeliverGift(AIUnit aiUnit,
                                     Settlement settlement,
                                     Goods goods)
An AIUnit delivers a gift.

Parameters:
aiUnit - The AIUnit delivering the gift.
settlement - The Settlement to give to.
goods - The Goods to give.
Returns:
True if the message was sent, and a non-error reply returned.

askDisembark

public static boolean askDisembark(AIUnit aiUnit)
An AIUnit disembarks.

Parameters:
aiUnit - The AIUnit delivering the gift.
Returns:
True if the message was sent, and a non-error reply returned.

askEmbark

public static boolean askEmbark(AIUnit aiUnit,
                                Unit unit,
                                Map.Direction direction)
An AIUnit embarks.

Parameters:
aiUnit - The AIUnit carrier.
unit - The Unit that is embarking.
direction - The Direction to embark in (may be null).
Returns:
True if the message was sent, and a non-error reply returned.

askEmigrate

public static boolean askEmigrate(Connection connection,
                                  int slot)
A unit in Europe emigrates.

Parameters:
connection - The Connection to the server.
slot - The slot to emigrate from.
Returns:
True if the message was sent, and a non-error reply returned.

askEndTurn

public static boolean askEndTurn(Connection connection)
Ends the player turn.

Parameters:
connection - The Connection to the server.
Returns:
True if the message was sent, and a non-error reply returned.

askEquipUnit

public static boolean askEquipUnit(AIUnit aiUnit,
                                   EquipmentType type,
                                   int amount)
Change the equipment of a unit.

Parameters:
aiUnit - The AIUnit to equip.
type - The EquipmentType to equip with.
amount - The amount to change the equipment by.
Returns:
True if the message was sent, and a non-error reply returned.

askEstablishMission

public static boolean askEstablishMission(AIUnit aiUnit,
                                          Map.Direction direction,
                                          boolean denounce)
Establishes a mission in the given direction.

Parameters:
aiUnit - The AIUnit establishing the mission.
direction - The Direction to move the unit.
denounce - Is this a denunciation?
Returns:
True if the message was sent, and a non-error reply returned.

askGetTransaction

public static boolean askGetTransaction(AIUnit aiUnit,
                                        Settlement settlement)
An AIUnit gets a transaction.

Parameters:
aiUnit - The AIUnit that gets a transaction.
settlement - The target Settlement.
Returns:
True if the message was sent, and a non-error reply returned.

askIndianDemand

public static boolean askIndianDemand(AIUnit aiUnit,
                                      Colony colony,
                                      Goods goods,
                                      int gold)
Makes demands to a colony. One and only one of goods or gold is valid.

Parameters:
aiUnit - The AIUnit that is demanding.
colony - The Colony to demand of.
goods - The Goods to demand.
gold - The amount of gold to demand.
Returns:
True if the message was sent, a non-error reply returned, and the demand was accepted.

askLoadCargo

public static boolean askLoadCargo(AIUnit aiUnit,
                                   Goods goods)
An AI unit loads some cargo.

Parameters:
aiUnit - The AIUnit that is loading.
goods - The Goods to load.
Returns:
True if the message was sent, and a non-error reply returned.

askLoot

public static boolean askLoot(AIUnit aiUnit,
                              java.lang.String defenderId,
                              java.util.List<Goods> goods)
An AI unit loots some cargo.

Parameters:
aiUnit - The AIUnit that is looting.
defenderId - The id of the defending unit.
goods - A list of Goods to loot.
Returns:
True if the message was sent, and a non-error reply returned.

askMove

public static boolean askMove(AIUnit aiUnit,
                              Map.Direction direction)
Moves an AIUnit in the given direction.

Parameters:
aiUnit - The AIUnit to move.
direction - The Direction to move the unit.
Returns:
True if the message was sent, and a non-error reply returned.

askMoveTo

public static boolean askMoveTo(AIUnit aiUnit,
                                Location destination)
Moves an AIUnit across the high seas.

Parameters:
aiUnit - The AIUnit to move.
destination - The Location to move to.
Returns:
True if the message was sent, and a non-error reply returned.

askPutOutsideColony

public static boolean askPutOutsideColony(AIUnit aiUnit)
An AIUnit is put outside a colony.

Parameters:
aiUnit - The AIUnit to put out.
Returns:
True if the message was sent, and a non-error reply returned.

askScoutIndianSettlement

public static boolean askScoutIndianSettlement(AIUnit aiUnit,
                                               Map.Direction direction)
An AI unit scouts a native settlement.

Parameters:
aiUnit - The AIUnit that is scouting.
direction - The Direction to move.
Returns:
True if the message was sent, and a non-error reply returned.

askSellGoods

public static boolean askSellGoods(AIUnit aiUnit,
                                   Goods goods)
An AI unit sells some cargo.

Parameters:
aiUnit - The AIUnit that is selling.
goods - The Goods to sell.
Returns:
True if the message was sent, and a non-error reply returned.

askSetBuildQueue

public static boolean askSetBuildQueue(AIColony aiColony,
                                       java.util.List<BuildableType> queue)
Set the build queue in a colony.

Parameters:
aiColony - The AIColony that is building.
queue - The list of BuildableTypes to build.
Returns:
True if the message was sent, and a non-error reply returned.

askTrainUnitInEurope

public static boolean askTrainUnitInEurope(Connection connection,
                                           UnitType type)
Train unit in Europe.

Parameters:
connection - The Connection to the server.
type - The UnitType to train.
Returns:
True if the message was sent, and a non-error reply returned.

askUnloadCargo

public static boolean askUnloadCargo(AIUnit aiUnit,
                                     Goods goods)
An AI unit unloads some cargo.

Parameters:
aiUnit - The AIUnit that is unloading.
goods - The Goods to unload.
Returns:
True if the message was sent, and a non-error reply returned.

askWork

public static boolean askWork(AIUnit aiUnit,
                              WorkLocation workLocation)
Set a unit to work in a work location.

Parameters:
aiUnit - The AIUnit to work.
workLocation - The WorkLocation to work in.
Returns:
True if the message was sent, and a non-error reply returned.