net.sf.freecol.client.control
Class InGameController

java.lang.Object
  extended by net.sf.freecol.client.control.InGameController
All Implemented Interfaces:
NetworkConstants

public final class InGameController
extends java.lang.Object
implements NetworkConstants

The controller that will be used while the game is played.


Field Summary
private  java.util.ArrayList<java.io.File> allSaveGames
          A list of save game files.
private  boolean canAutoEndTurn
          If true, then at least one unit has been active and the turn may automatically be ended.
private  boolean endingTurn
          Sets that the turn will be ended when all going-to units have been moved.
private  boolean executeGoto
          Sets that all going-to orders should be executed.
private  FreeColClient freeColClient
           
private static java.util.logging.Logger logger
           
private  java.util.HashMap<java.lang.String,java.lang.Integer> messagesToIgnore
          A hash map of messages to be ignored.
private  short UNIT_LAST_MOVE_DELAY
           
 
Fields inherited from interface net.sf.freecol.common.networking.NetworkConstants
NO_NEED_FOR_THE_GOODS, NO_TRADE
 
Constructor Summary
InGameController(FreeColClient freeColClient)
          The constructor to use.
 
Method Summary
 void abandonColony(Colony colony)
          Abandon a colony with no units
private  org.w3c.dom.Element askExpecting(Client client, org.w3c.dom.Element element, java.lang.String tag)
          Sends the specified message to the server and returns the reply, if it has the specified tag.
 void assignTeacher(Unit student, Unit teacher)
          Assigns a unit to a teacher Unit.
 void assignTradeRoute(Unit unit)
          Assigns a trade route to a unit.
 void assignTradeRoute(Unit unit, TradeRoute tradeRoute)
           
private  void attack(Unit unit, Map.Direction direction)
          Ask for attack or demand a tribute when attacking an indian settlement, attack in other cases
private  void attemptBuyFromSettlement(Unit unit, Settlement settlement)
          User interaction for buying from the natives.
private  void attemptGiftToSettlement(Unit unit, Settlement settlement)
          User interaction for delivering a gift to the natives.
private  void attemptSellToSettlement(Unit unit, Settlement settlement)
          User interaction for selling to the natives.
 void autosaveGame()
           
 boolean boardShip(Unit unit, Unit carrier)
          Boards a specified unit onto a carrier.
 void buildColony()
          Uses the active unit to build a colony.
private  void buyFromSettlement(Unit unit, Settlement settlement, Goods goods, int gold)
          Buys the given goods from the natives.
 void buyGoods(GoodsType type, int amount, Unit carrier)
          Buys goods in Europe.
private  void buyTradeGoodsFromEurope(Unit unit)
           
 void centerActiveUnit()
          Centers the map on the selected tile.
 void centerOnUnit(Unit unit)
          Centers the map on the given unit location.
 void changeState(Unit unit, Unit.UnitState state)
          Changes the state of this Unit.
 void changeWorkImprovementType(Unit unit, TileImprovementType improvementType)
          Changes the work type of this Unit.
 void changeWorkType(Unit unit, GoodsType workType)
          Changes the work type of this Unit.
 boolean checkCashInTreasureTrain(Unit unit)
          Check if a unit is a treasure train, and if it should be cashed in.
private  void checkTradeRoutesInEurope()
           
 boolean claimLand(Tile tile, Colony colony, int offer)
          Claim a piece of land.
 void clearGotoOrders(Unit unit)
          Clears the orders of the given Unit.
 void clearOrders(Unit unit)
          Clears the orders of the given Unit The orders are cleared by making the unit Unit.UnitState.ACTIVE and setting a null destination
 void clearSpeciality(Unit unit)
          Clear the speciality of a Unit.
private  void closeTransactionSession(Unit unit, Settlement settlement)
          Close a transaction session.
private  boolean confirmHostileAction(Unit attacker, Tile target)
          Check if an attack results in a transition from peace or cease fire to war and, if so, warn the player.
private  boolean confirmPreCombat(Unit attacker, Tile target)
          If the client options include a pre-combat dialog, allow the user to view the odds and possibly cancel the attack.
 void debugForeignColony(Tile tile)
           
 void declareIndependence()
          Declares independence for the home country.
private  void deliverGiftToSettlement(Unit unit, Settlement settlement, Goods goods)
          Give the given goods to the natives.
 void disbandActiveUnit()
          Disbands the active unit.
private  void disembark(Unit unit, Map.Direction direction)
          Disembarks the specified unit in a specified direction.
 void displayModelMessages(boolean allMessages)
           
private  void embark(Unit unit, Map.Direction direction)
          Embarks the specified unit in a specified direction.
private  void emigrateUnitInEurope(int slot)
          Request a unit to migrate from a specified "slot" in Europe.
 void endTurn()
          End the turn.
 void equipUnit(Unit unit, EquipmentType type, int amount)
          Equips or unequips a Unit with a certain type of Goods.
 void executeGotoOrders()
          Executes the units' goto orders.
private  void exploreLostCityRumour(Unit unit, Map.Direction direction)
          Confirm exploration of a lost city rumour, moving if accepted.
private  void followTradeRoute(Unit unit)
           
protected  org.w3c.dom.Element getChildElement(org.w3c.dom.Element element, java.lang.String tagName)
          Convenience method: returns the first child element with the specified tagname.
 org.w3c.dom.Element getForeignAffairsReport()
          Gathers information about opponents.
private  java.util.List<Goods> getGoodsForSaleInSettlement(Unit unit, Settlement settlement)
          Get a list of goods for sale from a settlement.
 org.w3c.dom.Element getHighScores()
          Retrieves high scores from server.
 java.util.List<AbstractUnit> getREFUnits()
          Gathers information about the REF.
 StatisticsMessage getServerStatistics()
          Retrieves server statistics
private  java.util.Map<java.lang.String,java.lang.Boolean> getTransactionSession(Unit unit, Settlement settlement)
          Get the transaction session for a trade.
private  java.lang.Integer getTurnForMessageIgnored(java.lang.String key)
           
 void ignoreMessage(ModelMessage message, boolean flag)
          Ignore this ModelMessage from now on until it is not generated in a turn.
private  boolean knownEnemyOnLastTile(PathNode path)
           
private  void learnSkillAtIndianSettlement(Unit unit, Map.Direction direction)
          Moves the specified free colonist into an Indian settlement to learn a skill.
 void leaveShip(Unit unit)
          Leave a ship.
 void loadCargo(Goods goods, Unit carrier)
          Loads a cargo onto a carrier.
 void loadGame()
          Opens a dialog where the user should specify the filename and loads the game.
private  void loadTradeGoodsFromColony(Unit unit)
           
 void move(Unit unit, Map.Direction direction)
          Moves the specified unit in a specified direction.
 void moveActiveUnit(Map.Direction direction)
          Moves the active unit in a specified direction.
private  void moveHighSeas(Unit unit, Map.Direction direction)
          Moves the specified unit in the "high seas" in a specified direction.
 void moveToAmerica(Unit unit)
          Moves the specified unit to America.
 void moveToDestination(Unit unit)
          Moves the given unit towards the destination given by Unit.getDestination().
 void moveToEurope(Unit unit)
          Moves the specified unit to Europe.
private  void negotiate(Unit unit, Map.Direction direction)
          Initiates a negotiation with a foreign power.
 void nextActiveUnit()
          Makes a new unit active.
 void nextActiveUnit(Tile tile)
          Makes a new unit active.
 void nextModelMessage()
          Displays the next ModelMessage.
 void payArrears(Goods goods)
          Pays the tax arrears on this type of goods.
 void payArrears(GoodsType type)
          Pays the tax arrears on this type of goods.
 void payForBuilding(Colony colony)
          Buys the remaining hammers and tools for the Building currently being built in the given Colony.
private  int proposeToBuyFromSettlement(Unit unit, Settlement settlement, Goods goods, int gold)
          Ask the natives if a purchase is acceptable.
private  int proposeToSellToSettlement(Unit unit, Settlement settlement, Goods goods, int gold)
          Ask the natives if a sale is acceptable.
 void purchaseUnitFromEurope(UnitType unitType)
          Purchases a unit of a specified type in Europe.
private  void purgeOldMessagesFromMessagesToIgnore(int thisTurn)
           
 boolean putOutsideColony(Unit unit)
          Puts the specified unit outside the colony.
private  void reallyAttack(Unit unit, Map.Direction direction)
          Performs an attack in a specified direction.
private  void reallyMove(Unit unit, Map.Direction direction)
          Actually moves a unit in a specified direction.
 void recruitUnitInEurope(int slot)
          Recruit a unit from a specified "slot" in Europe.
private  void removeUnitsOutsideLOS()
          Removes the units we cannot see anymore from the map.
 void rename(Nameable object)
          Renames a Nameable.
 void saveGame()
          Opens a dialog where the user should specify the filename and saves the game.
 void saveGame(java.io.File file)
          Saves the game to the given file.
private  void scoutForeignColony(Unit unit, Map.Direction direction)
          Ask for spy the foreign colony, negotiate with the foreign power or attack the colony
private  void scoutIndianSettlement(Unit unit, Map.Direction direction)
          Moves the specified scout into an Indian settlement to speak with the chief or demand a tribute etc.
 void selectDestination(Unit unit)
          Selects a destination for this unit.
 void sellGoods(Goods goods)
          Sells goods in Europe.
private  void sellToSettlement(Unit unit, Settlement settlement, Goods goods, int gold)
          Sells the given goods to the natives.
private  void sellTradeGoodsInEurope(Unit unit)
           
 void sendChat(java.lang.String message)
          Sends a public chat message.
 void setBuildQueue(Colony colony, java.util.List<BuildableType> buildQueue)
          Changes the current construction project of a Colony.
 void setCurrentPlayer(Player currentPlayer)
          Sets player as the new currentPlayer of the game.
 void setDestination(Unit unit, Location destination)
          Sets the destination of the given unit and send the server a message for this action.
 void setGoodsLevels(Colony colony, GoodsType goodsType)
          Sets the export settings of the custom house.
 void setInDebugMode(boolean debug)
          Sets the "debug mode" to be active or not.
 void setTradeRoutes(java.util.List<TradeRoute> routes)
          Sets the trade routes for this player
private  boolean shouldAllowMessage(ModelMessage message)
          Provides an opportunity to filter the messages delivered to the canvas.
private  boolean showColonyWarnings(Tile tile, Unit unit)
          A colony is proposed to be built.
private  void spy(Unit unit, Map.Direction direction)
          Spy on a foreign colony.
private  void startIgnoringMessage(java.lang.String key, int turn)
           
private  void stopIgnoringMessage(java.lang.String key)
           
private  void tradeWithSettlement(Unit unit, Map.Direction direction)
          Trading with the natives, including buying, selling and delivering gifts.
 void trainUnitInEurope(UnitType unitType)
          Trains a unit of a specified type in Europe.
 void unloadCargo(Goods goods)
          Unload cargo.
 void unloadCargo(Goods goods, boolean dump)
          Unload cargo.
private  void unloadTradeGoodsToColony(Unit unit)
           
 void updateTradeRoute(TradeRoute route)
          Updates a trade route.
private  void useMissionary(Unit unit, Map.Direction direction)
          Moves a missionary into an indian settlement.
 void work(Unit unit, WorkLocation workLocation)
          Moves a Unit to a WorkLocation.
 
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

freeColClient

private final FreeColClient freeColClient

UNIT_LAST_MOVE_DELAY

private final short UNIT_LAST_MOVE_DELAY
See Also:
Constant Field Values

endingTurn

private boolean endingTurn
Sets that the turn will be ended when all going-to units have been moved.


canAutoEndTurn

private boolean canAutoEndTurn
If true, then at least one unit has been active and the turn may automatically be ended.


executeGoto

private boolean executeGoto
Sets that all going-to orders should be executed.


messagesToIgnore

private java.util.HashMap<java.lang.String,java.lang.Integer> messagesToIgnore
A hash map of messages to be ignored.


allSaveGames

private java.util.ArrayList<java.io.File> allSaveGames
A list of save game files.

Constructor Detail

InGameController

public InGameController(FreeColClient freeColClient)
The constructor to use.

Parameters:
freeColClient - The main controller.
Method Detail

saveGame

public void saveGame()
Opens a dialog where the user should specify the filename and saves the game.


saveGame

public void saveGame(java.io.File file)
Saves the game to the given file.

Parameters:
file - The File.

loadGame

public void loadGame()
Opens a dialog where the user should specify the filename and loads the game.


setInDebugMode

public void setInDebugMode(boolean debug)
Sets the "debug mode" to be active or not. Calls FreeCol.setInDebugMode(boolean) and reinitialize the FreeColMenuBar.

Parameters:
debug - Should be set to true in order to enable debug mode.

askExpecting

private org.w3c.dom.Element askExpecting(Client client,
                                         org.w3c.dom.Element element,
                                         java.lang.String tag)
Sends the specified message to the server and returns the reply, if it has the specified tag. Handle "error" replies if they have a messageID or when in debug mode. This routine allows code simplification in much of the following client-server communication.

Parameters:
client - a Client value
element - The Element (root element in a DOM-parsed XML tree) that holds all the information
tag - The expected tag
Returns:
The answer from the server if it has the specified tag, otherwise null.

declareIndependence

public void declareIndependence()
Declares independence for the home country. TODO: Move magic 50% number to the spec.


sendChat

public void sendChat(java.lang.String message)
Sends a public chat message.

Parameters:
message - The text of the message.

setCurrentPlayer

public void setCurrentPlayer(Player currentPlayer)
Sets player as the new currentPlayer of the game.

Parameters:
currentPlayer - The player.

autosaveGame

public void autosaveGame()

rename

public void rename(Nameable object)
Renames a Nameable.

Parameters:
object - The object to rename.

removeUnitsOutsideLOS

private void removeUnitsOutsideLOS()
Removes the units we cannot see anymore from the map.


buildColony

public void buildColony()
Uses the active unit to build a colony.


showColonyWarnings

private boolean showColonyWarnings(Tile tile,
                                   Unit unit)
A colony is proposed to be built. Show warnings if this has disadvantages.

Parameters:
tile - The Tile on which the colony is to be built.
unit - The Unit which is to build the colony.

moveActiveUnit

public void moveActiveUnit(Map.Direction direction)
Moves the active unit in a specified direction. This may result in an attack, move... action.

Parameters:
direction - The direction in which to move the active unit.

selectDestination

public void selectDestination(Unit unit)
Selects a destination for this unit. Europe and the player's colonies are valid destinations.

Parameters:
unit - The unit for which to select a destination.

setDestination

public void setDestination(Unit unit,
                           Location destination)
Sets the destination of the given unit and send the server a message for this action.

Parameters:
unit - The Unit to direct.
destination - The destination Location.
See Also:
Unit.setDestination(Location)

moveToDestination

public void moveToDestination(Unit unit)
Moves the given unit towards the destination given by Unit.getDestination().

Parameters:
unit - The Unit to move.

knownEnemyOnLastTile

private boolean knownEnemyOnLastTile(PathNode path)

checkTradeRoutesInEurope

private void checkTradeRoutesInEurope()

followTradeRoute

private void followTradeRoute(Unit unit)

loadTradeGoodsFromColony

private void loadTradeGoodsFromColony(Unit unit)

unloadTradeGoodsToColony

private void unloadTradeGoodsToColony(Unit unit)

sellTradeGoodsInEurope

private void sellTradeGoodsInEurope(Unit unit)

buyTradeGoodsFromEurope

private void buyTradeGoodsFromEurope(Unit unit)

move

public void move(Unit unit,
                 Map.Direction direction)
Moves the specified unit in a specified direction. This may result in an attack, move... action.

Parameters:
unit - The unit to be moved.
direction - The direction in which to move the Unit.

negotiate

private void negotiate(Unit unit,
                       Map.Direction direction)
Initiates a negotiation with a foreign power. The player creates a DiplomaticTrade with the NegotiationDialog. The DiplomaticTrade is sent to the other player. If the other player accepts the offer, the trade is concluded. If not, this method returns, since the next offer must come from the other player.

Parameters:
unit - The Unit negotiating.
direction - The direction of a settlement to negotiate with.

spy

private void spy(Unit unit,
                 Map.Direction direction)
Spy on a foreign colony.

Parameters:
unit - The Unit that is spying.
direction - The direction of a colony to spy on.

debugForeignColony

public void debugForeignColony(Tile tile)

exploreLostCityRumour

private void exploreLostCityRumour(Unit unit,
                                   Map.Direction direction)
Confirm exploration of a lost city rumour, moving if accepted.

Parameters:
unit - The Unit that is exploring.
direction - The direction of a rumour.

claimLand

public boolean claimLand(Tile tile,
                         Colony colony,
                         int offer)
Claim a piece of land.

Parameters:
tile - The land to claim.
colony - An optional Colony to own the land.
offer - An offer to pay.
Returns:
True if the claim succeeded.

getTransactionSession

private java.util.Map<java.lang.String,java.lang.Boolean> getTransactionSession(Unit unit,
                                                                                Settlement settlement)
Get the transaction session for a trade.

Parameters:
unit - The Unit that is trading.
settlement - The Settlement that is trading.
Returns:
The transaction session.

closeTransactionSession

private void closeTransactionSession(Unit unit,
                                     Settlement settlement)
Close a transaction session.

Parameters:
unit - The Unit that is trading.
settlement - The Settlement that is trading.

getGoodsForSaleInSettlement

private java.util.List<Goods> getGoodsForSaleInSettlement(Unit unit,
                                                          Settlement settlement)
Get a list of goods for sale from a settlement.

Parameters:
unit - The Unit that is trading.
settlement - The Settlement that is trading.
Returns:
The list of goods for sale, or null if there is a problem.

tradeWithSettlement

private void tradeWithSettlement(Unit unit,
                                 Map.Direction direction)
Trading with the natives, including buying, selling and delivering gifts. (Deliberate use of Settlement rather than IndianSettlement throughout these routines as some unification with colony trading is anticipated, and the native AI already uses the same DeliverGiftMessage to deliver gifts to Colonies).

Parameters:
unit - The Unit that is a carrier containing goods.
direction - The direction the unit could move in order to enter a Settlement.
Throws:
java.lang.IllegalArgumentException - if the unit is not a carrier, or if there is no Settlement in the given direction.
See Also:
Settlement

attemptBuyFromSettlement

private void attemptBuyFromSettlement(Unit unit,
                                      Settlement settlement)
User interaction for buying from the natives.

Parameters:
unit - The Unit that is trading.
settlement - The Settlement that is trading.

proposeToBuyFromSettlement

private int proposeToBuyFromSettlement(Unit unit,
                                       Settlement settlement,
                                       Goods goods,
                                       int gold)
Ask the natives if a purchase is acceptable.

Parameters:
unit - The Unit that is trading.
settlement - The Settlement that is trading.
goods - The Goods to trade.
gold - The proposed price (including query on negative).
Returns:
The asking price, or NO_TRADE if the trade is outright refused, or NO_TRADE-1 on error.

buyFromSettlement

private void buyFromSettlement(Unit unit,
                               Settlement settlement,
                               Goods goods,
                               int gold)
Buys the given goods from the natives.

Parameters:
unit - The Unit that is trading.
settlement - The Settlement that is trading.
goods - The Goods to buy.
gold - The agreed price.

attemptSellToSettlement

private void attemptSellToSettlement(Unit unit,
                                     Settlement settlement)
User interaction for selling to the natives.

Parameters:
unit - The Unit that is trading.
settlement - The Settlement that is trading.

proposeToSellToSettlement

private int proposeToSellToSettlement(Unit unit,
                                      Settlement settlement,
                                      Goods goods,
                                      int gold)
Ask the natives if a sale is acceptable.

Parameters:
unit - The Unit that is trading.
settlement - The Settlement that is trading.
goods - The Goods to trade.
gold - The proposed price (including query on negative).
Returns:
The asking price, or NO_NEED_FOR_GOODS if they do not want them, NO_TRADE if the trade is outright refused, or NO_TRADE-1 on error.

sellToSettlement

private void sellToSettlement(Unit unit,
                              Settlement settlement,
                              Goods goods,
                              int gold)
Sells the given goods to the natives.

Parameters:
unit - The Unit that is trading.
settlement - The Settlement that is trading.
goods - The Goods to sell.
gold - The agreed price.

attemptGiftToSettlement

private void attemptGiftToSettlement(Unit unit,
                                     Settlement settlement)
User interaction for delivering a gift to the natives.

Parameters:
unit - The Unit that is trading.
settlement - The Settlement that is trading.

deliverGiftToSettlement

private void deliverGiftToSettlement(Unit unit,
                                     Settlement settlement,
                                     Goods goods)
Give the given goods to the natives.

Parameters:
unit - The Unit that is trading.
settlement - The Settlement that is trading.
goods - The Goods to give.

checkCashInTreasureTrain

public boolean checkCashInTreasureTrain(Unit unit)
Check if a unit is a treasure train, and if it should be cashed in. Transfers the gold carried by this unit to the owner.

Parameters:
unit - The Unit to be checked.
Returns:
True if the unit was cashed in (and disposed).

reallyMove

private void reallyMove(Unit unit,
                        Map.Direction direction)
Actually moves a unit in a specified direction.

Parameters:
unit - The unit to be moved.
direction - The direction in which to move the Unit.

attack

private void attack(Unit unit,
                    Map.Direction direction)
Ask for attack or demand a tribute when attacking an indian settlement, attack in other cases

Parameters:
unit - The unit to perform the attack.
direction - The direction in which to attack.

confirmHostileAction

private boolean confirmHostileAction(Unit attacker,
                                     Tile target)
Check if an attack results in a transition from peace or cease fire to war and, if so, warn the player.

Parameters:
attacker - The potential attacker.
target - The target tile.
Returns:
true to attack, false to abort.

confirmPreCombat

private boolean confirmPreCombat(Unit attacker,
                                 Tile target)
If the client options include a pre-combat dialog, allow the user to view the odds and possibly cancel the attack.

Parameters:
attacker - The attacker.
target - The target tile.
Returns:
true to attack, false to abort.

reallyAttack

private void reallyAttack(Unit unit,
                          Map.Direction direction)
Performs an attack in a specified direction. Note that the server handles the attack calculations here.

Parameters:
unit - The unit to perform the attack.
direction - The direction in which to attack.

disembark

private void disembark(Unit unit,
                       Map.Direction direction)
Disembarks the specified unit in a specified direction.

Parameters:
unit - The unit to be disembarked.
direction - The direction in which to disembark the Unit.

embark

private void embark(Unit unit,
                    Map.Direction direction)
Embarks the specified unit in a specified direction.

Parameters:
unit - The unit to be embarked.
direction - The direction in which to embark the Unit.

boardShip

public boolean boardShip(Unit unit,
                         Unit carrier)
Boards a specified unit onto a carrier. The carrier should be at the same tile as the boarding unit.

Parameters:
unit - The unit who is going to board the carrier.
carrier - The carrier.
Returns:
true if the unit actually gets on the carrier.

clearSpeciality

public void clearSpeciality(Unit unit)
Clear the speciality of a Unit. That is, makes it a Unit.FREE_COLONIST.

Parameters:
unit - The Unit to clear the speciality of.

leaveShip

public void leaveShip(Unit unit)
Leave a ship. This method should only be invoked if the ship is in a harbour.

Parameters:
unit - The unit who is going to leave the ship where it is located.

loadCargo

public void loadCargo(Goods goods,
                      Unit carrier)
Loads a cargo onto a carrier.

Parameters:
goods - The goods which are going aboard the carrier.
carrier - The carrier.

unloadCargo

public void unloadCargo(Goods goods)
Unload cargo. If the unit carrying the cargo is not in a harbour, the goods will be dumped.

Parameters:
goods - The goods which are going to leave the ship where it is located.

unloadCargo

public void unloadCargo(Goods goods,
                        boolean dump)
Unload cargo. If the unit carrying the cargo is not in a harbour, or if the given boolean is true, the goods will be dumped.

Parameters:
goods - The goods which are going to leave the ship where it is located.
dump - a boolean value

buyGoods

public void buyGoods(GoodsType type,
                     int amount,
                     Unit carrier)
Buys goods in Europe. The amount of goods is adjusted if there is lack of space in the carrier.

Parameters:
type - The type of goods to buy.
amount - The amount of goods to buy.
carrier - The carrier.

sellGoods

public void sellGoods(Goods goods)
Sells goods in Europe.

Parameters:
goods - The goods to be sold.

setGoodsLevels

public void setGoodsLevels(Colony colony,
                           GoodsType goodsType)
Sets the export settings of the custom house.

Parameters:
colony - The colony with the custom house.
goodsType - The goods for which to set the settings.

equipUnit

public void equipUnit(Unit unit,
                      EquipmentType type,
                      int amount)
Equips or unequips a Unit with a certain type of Goods.

Parameters:
unit - The Unit.
type - an EquipmentType value
amount - How many of these goods the unit should have.

work

public void work(Unit unit,
                 WorkLocation workLocation)
Moves a Unit to a WorkLocation.

Parameters:
unit - The Unit.
workLocation - The WorkLocation.

putOutsideColony

public boolean putOutsideColony(Unit unit)
Puts the specified unit outside the colony.

Parameters:
unit - The Unit
Returns:
true if the unit was successfully put outside the colony.

changeWorkType

public void changeWorkType(Unit unit,
                           GoodsType workType)
Changes the work type of this Unit.

Parameters:
unit - The Unit
workType - The new GoodsType to produce.

changeWorkImprovementType

public void changeWorkImprovementType(Unit unit,
                                      TileImprovementType improvementType)
Changes the work type of this Unit.

Parameters:
unit - The Unit
improvementType - a TileImprovementType value

assignTeacher

public void assignTeacher(Unit student,
                          Unit teacher)
Assigns a unit to a teacher Unit.

Parameters:
student - an Unit value
teacher - an Unit value

setBuildQueue

public void setBuildQueue(Colony colony,
                          java.util.List<BuildableType> buildQueue)
Changes the current construction project of a Colony.

Parameters:
colony - The Colony

changeState

public void changeState(Unit unit,
                        Unit.UnitState state)
Changes the state of this Unit.

Parameters:
unit - The Unit
state - The state of the unit.

clearOrders

public void clearOrders(Unit unit)
Clears the orders of the given Unit The orders are cleared by making the unit Unit.UnitState.ACTIVE and setting a null destination

Parameters:
unit - The Unit.

clearGotoOrders

public void clearGotoOrders(Unit unit)
Clears the orders of the given Unit. The orders are cleared by making the unit Unit.UnitState.ACTIVE.

Parameters:
unit - The Unit.

moveHighSeas

private void moveHighSeas(Unit unit,
                          Map.Direction direction)
Moves the specified unit in the "high seas" in a specified direction. This may result in an ordinary move, no move or a move to europe.

Parameters:
unit - The unit to be moved.
direction - The direction in which to move the Unit.

learnSkillAtIndianSettlement

private void learnSkillAtIndianSettlement(Unit unit,
                                          Map.Direction direction)
Moves the specified free colonist into an Indian settlement to learn a skill. Of course, the colonist won't physically get into the village, it will just stay where it is and gain the skill.

Parameters:
unit - The unit to learn the skill.
direction - The direction in which the Indian settlement lies.

scoutForeignColony

private void scoutForeignColony(Unit unit,
                                Map.Direction direction)
Ask for spy the foreign colony, negotiate with the foreign power or attack the colony

Parameters:
unit - The unit that will spy, negotiate or attack.
direction - The direction in which the foreign colony lies.

scoutIndianSettlement

private void scoutIndianSettlement(Unit unit,
                                   Map.Direction direction)
Moves the specified scout into an Indian settlement to speak with the chief or demand a tribute etc. Of course, the scout won't physically get into the village, it will just stay where it is.

Parameters:
unit - The unit that will speak, attack or ask tribute.
direction - The direction in which the Indian settlement lies.

useMissionary

private void useMissionary(Unit unit,
                           Map.Direction direction)
Moves a missionary into an indian settlement.

Parameters:
unit - The unit that will enter the settlement.
direction - The direction in which the Indian settlement lies.

moveToEurope

public void moveToEurope(Unit unit)
Moves the specified unit to Europe.

Parameters:
unit - The unit to be moved to Europe.

moveToAmerica

public void moveToAmerica(Unit unit)
Moves the specified unit to America.

Parameters:
unit - The unit to be moved to America.

trainUnitInEurope

public void trainUnitInEurope(UnitType unitType)
Trains a unit of a specified type in Europe.

Parameters:
unitType - The type of unit to be trained.

payForBuilding

public void payForBuilding(Colony colony)
Buys the remaining hammers and tools for the Building currently being built in the given Colony.

Parameters:
colony - The Colony where the building should be bought.

recruitUnitInEurope

public void recruitUnitInEurope(int slot)
Recruit a unit from a specified "slot" in Europe.

Parameters:
slot - The slot to recruit the unit from. Either 1, 2 or 3.

emigrateUnitInEurope

private void emigrateUnitInEurope(int slot)
Request a unit to migrate from a specified "slot" in Europe.

Parameters:
slot - The slot from which the unit migrates, 1-3 selects a specific one, otherwise the server will choose one.

updateTradeRoute

public void updateTradeRoute(TradeRoute route)
Updates a trade route.

Parameters:
route - The trade route to update.

setTradeRoutes

public void setTradeRoutes(java.util.List<TradeRoute> routes)
Sets the trade routes for this player

Parameters:
routes - The trade routes to set.

assignTradeRoute

public void assignTradeRoute(Unit unit)
Assigns a trade route to a unit.

Parameters:
unit - The unit to assign a trade route to.

assignTradeRoute

public void assignTradeRoute(Unit unit,
                             TradeRoute tradeRoute)

payArrears

public void payArrears(Goods goods)
Pays the tax arrears on this type of goods.

Parameters:
goods - The goods for which to pay arrears.

payArrears

public void payArrears(GoodsType type)
Pays the tax arrears on this type of goods.

Parameters:
type - The type of goods for which to pay arrears.

purchaseUnitFromEurope

public void purchaseUnitFromEurope(UnitType unitType)
Purchases a unit of a specified type in Europe.

Parameters:
unitType - The type of unit to be purchased.

getForeignAffairsReport

public org.w3c.dom.Element getForeignAffairsReport()
Gathers information about opponents.


getHighScores

public org.w3c.dom.Element getHighScores()
Retrieves high scores from server.


getREFUnits

public java.util.List<AbstractUnit> getREFUnits()
Gathers information about the REF.

Returns:
a List value

disbandActiveUnit

public void disbandActiveUnit()
Disbands the active unit.


centerActiveUnit

public void centerActiveUnit()
Centers the map on the selected tile.


centerOnUnit

public void centerOnUnit(Unit unit)
Centers the map on the given unit location.


executeGotoOrders

public void executeGotoOrders()
Executes the units' goto orders.


nextActiveUnit

public void nextActiveUnit()
Makes a new unit active.


nextActiveUnit

public void nextActiveUnit(Tile tile)
Makes a new unit active. Displays any new ModelMessages (uses nextModelMessage()).

Parameters:
tile - The tile to select if no new unit can be made active.

ignoreMessage

public void ignoreMessage(ModelMessage message,
                          boolean flag)
Ignore this ModelMessage from now on until it is not generated in a turn.

Parameters:
message - a ModelMessage value
flag - whether to ignore the ModelMessage or not

nextModelMessage

public void nextModelMessage()
Displays the next ModelMessage.

See Also:
ModelMessage

displayModelMessages

public void displayModelMessages(boolean allMessages)

getTurnForMessageIgnored

private java.lang.Integer getTurnForMessageIgnored(java.lang.String key)

startIgnoringMessage

private void startIgnoringMessage(java.lang.String key,
                                  int turn)

stopIgnoringMessage

private void stopIgnoringMessage(java.lang.String key)

purgeOldMessagesFromMessagesToIgnore

private void purgeOldMessagesFromMessagesToIgnore(int thisTurn)

shouldAllowMessage

private boolean shouldAllowMessage(ModelMessage message)
Provides an opportunity to filter the messages delivered to the canvas.

Parameters:
message - the message that is candidate for delivery to the canvas
Returns:
true if the message should be delivered

endTurn

public void endTurn()
End the turn.


getChildElement

protected org.w3c.dom.Element getChildElement(org.w3c.dom.Element element,
                                              java.lang.String tagName)
Convenience method: returns the first child element with the specified tagname.

Parameters:
element - The Element to search for the child element.
tagName - The tag name of the child element to be found.
Returns:
The child of the given Element with the given tagName or null if no such child exists.

abandonColony

public void abandonColony(Colony colony)
Abandon a colony with no units

Parameters:
colony - The colony to be abandoned

getServerStatistics

public StatisticsMessage getServerStatistics()
Retrieves server statistics