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  FreeColClient freeColClient
           
private static java.io.FileFilter FSG_FILTER
           
private  GUI gui
           
private  java.io.File lastSaveGameFile
          The most recently saved game file, or null.
private static java.util.logging.Logger logger
           
private  java.util.HashMap<java.lang.String,java.lang.Integer> messagesToIgnore
           
private  int MODE_END_TURN
           
private  int MODE_EXECUTE_GOTO_ORDERS
           
private  int MODE_NEXT_ACTIVE_UNIT
           
private  int moveMode
           
private  int turnsPlayed
           
private  short UNIT_LAST_MOVE_DELAY
           
 
Fields inherited from interface net.sf.freecol.common.networking.NetworkConstants
NO_TRADE, NO_TRADE_GOODS, NO_TRADE_HAGGLE, NO_TRADE_HOSTILE, STEAL_LAND
 
Constructor Summary
InGameController(FreeColClient freeColClient, GUI gui)
          The constructor to use.
 
Method Summary
 void abandonColony(Colony colony)
          Abandon a colony with no units.
private  ServerAPI askServer()
          Meaningfully named access to the ServerAPI.
 void assignTeacher(Unit student, Unit teacher)
          Assigns a unit to a teacher Unit.
 void assignTradeRoute(Unit unit)
          Assigns a trade route to a unit using the trade route dialog.
 void assignTradeRoute(Unit unit, TradeRoute tradeRoute)
          Assigns a trade route to a unit.
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.
private  void autosave_game()
          Creates at least one autosave game file of the currently played game in the autosave directory.
 boolean boardShip(Unit unit, Unit carrier)
          Boards a specified unit onto a carrier.
 void buildColony()
          Use the active unit to build a colony.
private  boolean buildColonyShowWarnings(Tile tile, Unit unit)
          A colony is proposed to be built.
 boolean buyGoods(GoodsType type, int amount, Unit carrier)
          Buy goods in Europe.
 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.
 boolean claimLand(Tile tile, Colony colony, int offer)
          Claim a tile.
private  boolean claimTile(Player player, Tile tile, Colony colony, int price, int offer)
          Claim a tile.
 void clearGotoOrders(Unit unit)
          Clears the goto orders of the given unit by setting its destination to null.
 boolean clearOrders(Unit unit)
          Clears the orders of the given unit.
 void clearSpeciality(Unit unit)
          Clear the speciality of a Unit, making it a Free Colonist.
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 tile)
          Shows the pre-combat dialog if enabled, allowing the user to view the odds and possibly cancel the attack.
 void declareIndependence()
          Declares independence for the home country.
 void disbandActiveUnit()
          Disbands the active unit.
 void displayModelMessages(boolean allMessages)
          Displays pending ModelMessages.
 void displayModelMessages(boolean allMessages, boolean endOfTurn)
          Displays pending ModelMessages.
private  void doEndTurn()
          Really end the turn.
private  boolean doExecuteGotoOrders()
          Actually do the goto orders operation.
private  void emigrate(Player player, int slot)
          Emigrate a unit from Europe.
 void endTurn()
          End the turn command.
 void equipUnit(Unit unit, EquipmentType type, int amount)
          Change the amount of equipment a unit has.
 void executeGotoOrders()
          Execute goto orders command.
private  boolean followPath(Unit unit, PathNode path)
          Follow a path.
private  boolean followTradeRoute(Unit unit)
          Follows a trade route, doing load/unload actions, moving the unit, and updating the stop and destination.
 java.util.Map<java.lang.String,java.lang.String> getClientStatistics()
          Retrieves client statistics.
 java.util.List<HighScore> getHighScores()
          Retrieves high scores from server.
 java.io.File getLastSaveGameFile()
          Gets the most recently saved game file, or null.
private  ModelMessage getLoadGoodsMessage(Unit unit, GoodsType type, int amount, int present, int atStop, int toLoad)
          Gets a message describing a goods loading.
private  StringTemplate getNationAt(Tile tile, Map.Direction direction)
          Convenience function to find the nation controlling an adjacent settlement.
 NationSummary getNationSummary(Player player)
          Get the nation summary for a player.
 TradeRoute getNewTradeRoute(Player player)
          Gets a new trade route for a player.
 java.util.List<AbstractUnit> getREFUnits()
          Gathers information about the REF.
private  java.lang.String getSaveGameString(Turn turn)
          Returns a string representation of the given turn suitable for savegame files.
 java.util.Map<java.lang.String,java.lang.String> getServerStatistics()
          Retrieves the server statistics.
private  Settlement getSettlementAt(Tile tile, Map.Direction direction)
          Convenience function to find an adjacent settlement.
private  Specification getSpecification()
          Gets the specification for the current game.
private  java.lang.Integer getTurnForMessageIgnored(java.lang.String key)
           
private  ModelMessage getUnloadGoodsMessage(Unit unit, GoodsType type, int amount, int atStop, int present, int toUnload)
          Gets a message describing a goods unloading.
 void ignoreMessage(ModelMessage message, boolean flag)
          Ignore this ModelMessage from now on until it is not generated in a turn.
 boolean 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  boolean loadGoods(Goods goods, Unit carrier)
          Load some goods onto a carrier.
private  boolean loadUnitAtStop(Unit unit, java.util.List<ModelMessage> messages)
          Work out what goods to load onto a unit at a stop, and load them.
 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 moveAttack(Unit unit, Map.Direction direction)
          Confirm attack or demand a tribute from a native settlement, following an attacking move.
private  boolean moveDirection(Unit unit, Map.Direction direction, boolean interactive)
          Move a unit in a given direction.
private  boolean moveDisembark(Unit unit, Map.Direction direction)
          Check the carrier for passengers to disembark, possibly snatching a useful result from the jaws of a MOVE_NO_ACCESS_LAND failure.
private  void moveEmbark(Unit unit, Map.Direction direction)
          Embarks the specified unit onto a carrier in a specified direction following a move of MoveType.EMBARK.
private  void moveExplore(Unit unit, Map.Direction direction)
          Confirm exploration of a lost city rumour, following a move of MoveType.EXPLORE_LOST_CITY_RUMOUR.
private  boolean moveHighSeas(Unit unit, Map.Direction direction)
          Moves a unit onto the "high seas" in a specified direction following a move of MoveType.MOVE_HIGH_SEAS.
private  void moveLearnSkill(Unit unit, Map.Direction direction)
          Move a free colonist to a native settlement to learn a skill following a move of MoveType.ENTER_INDIAN_SETTLEMENT_WITH_FREE_COLONIST.
private  void moveMove(Unit unit, Map.Direction direction)
          Actually move a unit in a specified direction, following a move of MoveType.MOVE.
private  void moveScoutColony(Unit unit, Map.Direction direction)
          Move to a foreign colony and either attack, negotiate with the foreign power or spy on them.
private  void moveScoutIndianSettlement(Unit unit, Map.Direction direction)
          Move a scout into an Indian settlement to speak with the chief, or demand a tribute following a move of MoveType.ENTER_INDIAN_SETTLEMENT_WITH_SCOUT.
private  void moveSpy(Unit unit, Map.Direction direction)
          Spy on a foreign colony.
 void moveTo(Unit unit, Location destination)
          Moves the specified unit somewhere that requires crossing the high seas.
 boolean moveToDestination(Unit unit)
          Moves the given unit towards its destination/s if possible.
private  void moveTrade(Unit unit, Map.Direction direction)
          Arrive at a settlement with a laden carrier following a move of MoveType.ENTER_SETTLEMENT_WITH_CARRIER_AND_GOODS.
private  void moveTradeColony(Unit unit, Map.Direction direction)
          Initiates a negotiation with a foreign power.
private  void moveTradeIndianSettlement(Unit unit, Map.Direction direction)
          Trading with the natives, including buying, selling and delivering gifts.
private  void moveTribute(Unit unit, Map.Direction direction)
          Demand a tribute.
private  void moveUseMissionary(Unit unit, Map.Direction direction)
          Move a missionary into a native settlement, following a move of MoveType.ENTER_INDIAN_SETTLEMENT_WITH_MISSIONARY.
 void nextActiveUnit()
          Makes a new unit active.
 void nextActiveUnit(Tile tile)
          Makes a new unit active if any, or focus on a tile (useful if the current unit just died).
 void nextModelMessage()
          Displays the next ModelMessage.
 boolean 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.
 boolean putOutsideColony(Unit unit)
          Puts the specified unit outside the colony.
 boolean quickReload()
          Reloads a game state which was previously saved via quicksaveGame.
 boolean quicksaveGame()
          Saves the game to a fix-named file in the autosave directory, which may be used for quick-reload.
 void recruitUnitInEurope(int index)
          Recruit a unit from a specified index in Europe.
 void rename(Nameable object)
          Renames a Nameable.
private  boolean requireOurTurn()
          Require that it is this client's player's turn.
 boolean saveGame()
          Opens a dialog where the user should specify the filename and saves the game.
 boolean saveGame(java.io.File file)
          Saves the game to the given file.
 void selectDestination(Unit unit)
          Selects a destination for this unit.
 boolean sellGoods(Goods goods)
          Sells goods in Europe.
 void sendChat(java.lang.String chat)
          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 player)
          Set a player to be the new current player.
 boolean setDestination(Unit unit, Location destination)
          Set the destination of the given unit.
 void setGameConnected()
          Informs this controller that a game has been newly loaded.
 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  void showTradeFail(int fail, Settlement settlement, Goods goods)
          Displays an appropriate trade failure message.
 void skipActiveUnit()
          Skip a unit.
private  void startIgnoringMessage(java.lang.String key, int turn)
           
private  void stopIgnoringMessage(java.lang.String key)
           
 void trainUnitInEurope(UnitType unitType)
          Trains a unit of a specified type in Europe.
 void unload(Unit unit)
          Unload, including dumping cargo.
 void unloadCargo(Goods goods, boolean dump)
          Unload cargo.
private  boolean unloadGoods(Goods goods, Unit carrier, Colony colony)
          Unload some goods from a carrier.
private  boolean unloadUnitAtStop(Unit unit, java.util.List<ModelMessage> messages)
          Work out what goods to unload from a unit at a stop, and unload them.
 void updateTradeRoute(TradeRoute route)
          Updates a trade route.
 void waitActiveUnit()
          Tell a unit to wait.
 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

MODE_NEXT_ACTIVE_UNIT

private final int MODE_NEXT_ACTIVE_UNIT
See Also:
Constant Field Values

MODE_EXECUTE_GOTO_ORDERS

private final int MODE_EXECUTE_GOTO_ORDERS
See Also:
Constant Field Values

MODE_END_TURN

private final int MODE_END_TURN
See Also:
Constant Field Values

moveMode

private int moveMode

turnsPlayed

private int turnsPlayed

lastSaveGameFile

private java.io.File lastSaveGameFile
The most recently saved game file, or null.


FSG_FILTER

private static java.io.FileFilter FSG_FILTER

messagesToIgnore

private java.util.HashMap<java.lang.String,java.lang.Integer> messagesToIgnore

gui

private GUI gui
Constructor Detail

InGameController

public InGameController(FreeColClient freeColClient,
                        GUI gui)
The constructor to use.

Parameters:
freeColClient - The main controller.
Method Detail

setGameConnected

public void setGameConnected()
Informs this controller that a game has been newly loaded.


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 - Set to true to enable debug mode.

askServer

private ServerAPI askServer()
Meaningfully named access to the ServerAPI.

Returns:
The ServerAPI.

getSpecification

private Specification getSpecification()
Gets the specification for the current game.

Returns:
The current game specification.

requireOurTurn

private boolean requireOurTurn()
Require that it is this client's player's turn. Put up the notYourTurn message if not.

Returns:
True if it is our turn.

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 attacking Unit.
target - The target Tile.
Returns:
True to attack, false to abort.

confirmPreCombat

private boolean confirmPreCombat(Unit attacker,
                                 Tile tile)
Shows the pre-combat dialog if enabled, allowing the user to view the odds and possibly cancel the attack.

Parameters:
attacker - The attacking Unit.
tile - The target Tile.
Returns:
True to attack, false to abort.

getSettlementAt

private Settlement getSettlementAt(Tile tile,
                                   Map.Direction direction)
Convenience function to find an adjacent settlement. Intended to be called in contexts where we are expecting a settlement to be there, such as when handling a particular move type.

Parameters:
tile - The Tile to start at.
direction - The Direction to step.
Returns:
A settlement on the adjacent tile if any.

getNationAt

private StringTemplate getNationAt(Tile tile,
                                   Map.Direction direction)
Convenience function to find the nation controlling an adjacent settlement. Intended to be called in contexts where we are expecting a settlement or unit to be there, such as when handling a particular move type.

Parameters:
tile - The Tile to start at.
direction - The Direction to step.
Returns:
The name of the nation controlling a settlement on the adjacent tile if any.

doExecuteGotoOrders

private boolean doExecuteGotoOrders()
Actually do the goto orders operation.

Returns:
True if all goto orders have been performed and no units reached their destination and are free to move again.

doEndTurn

private void doEndTurn()
Really end the turn.


followTradeRoute

private boolean followTradeRoute(Unit unit)
Follows a trade route, doing load/unload actions, moving the unit, and updating the stop and destination.

Parameters:
unit - The Unit on the route.
Returns:
True if the unit should keep moving, which can only happen if the trade route is found to be broken and the unit is thrown off it.

loadUnitAtStop

private boolean loadUnitAtStop(Unit unit,
                               java.util.List<ModelMessage> messages)
Work out what goods to load onto a unit at a stop, and load them.

Parameters:
unit - The Unit to load.
messages - An optional list of messages to update.
Returns:
True if goods were loaded.

getLoadGoodsMessage

private ModelMessage getLoadGoodsMessage(Unit unit,
                                         GoodsType type,
                                         int amount,
                                         int present,
                                         int atStop,
                                         int toLoad)
Gets a message describing a goods loading.

Parameters:
unit - The Unit that is loading.
type - The GoodsType the type of goods being loaded.
amount - The amount of goods loaded.
present - The amount of goods already at the location.
atStop - The amount of goods available to load.
toLoad - The amount of goods the unit could load.
Returns:
A model message describing the load.

unloadUnitAtStop

private boolean unloadUnitAtStop(Unit unit,
                                 java.util.List<ModelMessage> messages)
Work out what goods to unload from a unit at a stop, and unload them.

Parameters:
unit - The Unit to unload.
messages - A list of messages to update.
Returns:
True if something was unloaded.

getUnloadGoodsMessage

private ModelMessage getUnloadGoodsMessage(Unit unit,
                                           GoodsType type,
                                           int amount,
                                           int atStop,
                                           int present,
                                           int toUnload)
Gets a message describing a goods unloading.

Parameters:
unit - The Unit that is unloading.
type - The GoodsType the type of goods being unloaded.
amount - The amount of goods unloaded.
present - The amount of goods already carried by the unit.
atStop - The amount of goods available to unload.
toUnload - The amount of goods actually unloaded.
Returns:
A model message describing the unload.

claimTile

private boolean claimTile(Player player,
                          Tile tile,
                          Colony colony,
                          int price,
                          int offer)
Claim a tile.

Parameters:
player - The Player that is claiming.
tile - The Tile to claim.
colony - An optional Colony to own the tile.
price - The price required.
offer - An offer to pay.
Returns:
True if the claim succeeded.

emigrate

private void emigrate(Player player,
                      int slot)
Emigrate a unit from Europe.

Parameters:
player - The Player that owns the unit.
slot - The slot to emigrate from.

followPath

private boolean followPath(Unit unit,
                           PathNode path)
Follow a path.

Parameters:
unit - The Unit to move.
path - The path to follow.
Returns:
True if the unit has completed the path and can move further.

loadGoods

private boolean loadGoods(Goods goods,
                          Unit carrier)
Load some goods onto a carrier.

Parameters:
goods - The Goods to load.
carrier - The Unit to load onto.
Returns:
True if the load succeeded.

unloadGoods

private boolean unloadGoods(Goods goods,
                            Unit carrier,
                            Colony colony)
Unload some goods from a carrier.

Parameters:
goods - The Goods to unload.
carrier - The Unit carrying the goods.
colony - The Colony to unload to, or null if unloading in Europe.
Returns:
True if the unload succeeded.

autosave_game

private void autosave_game()
Creates at least one autosave game file of the currently played game in the autosave directory. Does nothing if there is no game running.


getSaveGameString

private java.lang.String getSaveGameString(Turn turn)
Returns a string representation of the given turn suitable for savegame files.

Parameters:
turn - a Turn value
Returns:
A string with the format: "[season] year". Examples: "1602_1_Spring", "1503"...

getLastSaveGameFile

public java.io.File getLastSaveGameFile()
Gets the most recently saved game file, or null. (This may be either from a recent arbitrary user operation or an autosave function.)

Returns:
The recent save game file

loadGame

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


quickReload

public boolean quickReload()
Reloads a game state which was previously saved via quicksaveGame.

Returns:
boolean true if and only if a game was loaded

saveGame

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

Returns:
True if the game was saved.

saveGame

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

Parameters:
file - The File.
Returns:
True if the game was saved.

quicksaveGame

public boolean quicksaveGame()
Saves the game to a fix-named file in the autosave directory, which may be used for quick-reload.

Returns:
boolean true if and only if the game was saved

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

startIgnoringMessage

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

stopIgnoringMessage

private void stopIgnoringMessage(java.lang.String key)

getTurnForMessageIgnored

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

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

displayModelMessages

public void displayModelMessages(boolean allMessages)
Displays pending ModelMessages.

Parameters:
allMessages - Display all messages or just the undisplayed ones.

displayModelMessages

public void displayModelMessages(boolean allMessages,
                                 boolean endOfTurn)
Displays pending ModelMessages.

Parameters:
allMessages - Display all messages or just the undisplayed ones.
endOfTurn - Use a turn report panel if necessary.

nextModelMessage

public void nextModelMessage()
Displays the next ModelMessage.


abandonColony

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

Parameters:
colony - The Colony to be abandoned.

assignTeacher

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

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

assignTradeRoute

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

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

assignTradeRoute

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

Parameters:
unit - The Unit to assign a trade route to.
tradeRoute - The TradeRoute to assign.

boardShip

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

Parameters:
unit - The Unit which is to board the carrier.
carrier - The carrier to board.
Returns:
True if the unit boards the carrier.

buildColony

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


buildColonyShowWarnings

private boolean buildColonyShowWarnings(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.

buyGoods

public boolean buyGoods(GoodsType type,
                        int amount,
                        Unit carrier)
Buy goods in Europe. The amount of goods is adjusted to the space in the carrier.

Parameters:
type - The type of goods to buy.
amount - The amount of goods to buy.
carrier - The Unit acting as carrier.
Returns:
True if the purchase succeeds.

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.

changeWorkImprovementType

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

Parameters:
unit - The Unit
improvementType - a TileImprovementType value

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.

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).

claimLand

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

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

clearGotoOrders

public void clearGotoOrders(Unit unit)
Clears the goto orders of the given unit by setting its destination to null.

Parameters:
unit - The Unit to clear the destination for.

clearOrders

public boolean clearOrders(Unit unit)
Clears the orders of the given unit. Make the unit active and set a null destination and trade route.

Parameters:
unit - The Unit to clear the orders of
Returns:
boolean true if the orders were cleared

clearSpeciality

public void clearSpeciality(Unit unit)
Clear the speciality of a Unit, making it a Free Colonist.

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

declareIndependence

public void declareIndependence()
Declares independence for the home country.


disbandActiveUnit

public void disbandActiveUnit()
Disbands the active unit.


endTurn

public void endTurn()
End the turn command.


equipUnit

public void equipUnit(Unit unit,
                      EquipmentType type,
                      int amount)
Change the amount of equipment a unit has.

Parameters:
unit - The Unit.
type - The EquipmentType to equip with.
amount - How to change the amount of equipment the unit has.

executeGotoOrders

public void executeGotoOrders()
Execute goto orders command.


getClientStatistics

public java.util.Map<java.lang.String,java.lang.String> getClientStatistics()
Retrieves client statistics.

Returns:
A Map containing the client statistics.

getHighScores

public java.util.List<HighScore> getHighScores()
Retrieves high scores from server.

Returns:
The list of high scores.

getNationSummary

public NationSummary getNationSummary(Player player)
Get the nation summary for a player.

Parameters:
player - The Player to summarize.
Returns:
A summary of that nation, or null on error.

getNewTradeRoute

public TradeRoute getNewTradeRoute(Player player)
Gets a new trade route for a player.

Parameters:
player - The Player to get a new trade route for.
Returns:
A new TradeRoute.

getREFUnits

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

Returns:
a List value

getServerStatistics

public java.util.Map<java.lang.String,java.lang.String> getServerStatistics()
Retrieves the server statistics.

Returns:
A Map containing the server statistics.

leaveShip

public boolean leaveShip(Unit unit)
Leave a ship. The ship must be in harbour.

Parameters:
unit - The Unit which is to leave the ship.
Returns:
boolean

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 Unit acting as carrier.

moveTo

public void moveTo(Unit unit,
                   Location destination)
Moves the specified unit somewhere that requires crossing the high seas. Public because this is called from the TilePopup and the Europe panel.

Parameters:
unit - The Unit to be moved.
destination - The Location to be moved to.
Throws:
java.lang.IllegalArgumentException - if destination or unit are null.

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.

move

public void move(Unit unit,
                 Map.Direction direction)
Moves the specified unit in a specified direction. This may result in many different types of action.

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

moveToDestination

public boolean moveToDestination(Unit unit)
Moves the given unit towards its destination/s if possible.

Parameters:
unit - The Unit to move.
Returns:
True if the unit reached its destination and has more moves to make.

moveDirection

private boolean moveDirection(Unit unit,
                              Map.Direction direction,
                              boolean interactive)
Move a unit in a given direction.

Parameters:
unit - The Unit to move.
direction - The Direction to move in.
interactive - Interactive mode: play sounds and emit errors.
Returns:
True if the unit can possibly move further.

moveAttack

private void moveAttack(Unit unit,
                        Map.Direction direction)
Confirm attack or demand a tribute from a native settlement, following an attacking move.

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

moveDisembark

private boolean moveDisembark(Unit unit,
                              Map.Direction direction)
Check the carrier for passengers to disembark, possibly snatching a useful result from the jaws of a MOVE_NO_ACCESS_LAND failure.

Parameters:
unit - The carrier containing the unit to disembark.
direction - The direction in which to disembark the unit.
Returns:
True if the disembark "succeeds" (which deliberately includes declined disembarks).

moveEmbark

private void moveEmbark(Unit unit,
                        Map.Direction direction)
Embarks the specified unit onto a carrier in a specified direction following a move of MoveType.EMBARK.

Parameters:
unit - The Unit that wishes to embark.
direction - The direction in which to embark.

moveExplore

private void moveExplore(Unit unit,
                         Map.Direction direction)
Confirm exploration of a lost city rumour, following a move of MoveType.EXPLORE_LOST_CITY_RUMOUR.

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

moveHighSeas

private boolean moveHighSeas(Unit unit,
                             Map.Direction direction)
Moves a unit onto the "high seas" in a specified direction following a move of MoveType.MOVE_HIGH_SEAS. This may result in a move to Europe, no move, or an ordinary move.

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

moveLearnSkill

private void moveLearnSkill(Unit unit,
                            Map.Direction direction)
Move a free colonist to a native settlement to learn a skill following a move of MoveType.ENTER_INDIAN_SETTLEMENT_WITH_FREE_COLONIST. The colonist does not 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.

moveMove

private void moveMove(Unit unit,
                      Map.Direction direction)
Actually move a unit in a specified direction, following a move of MoveType.MOVE.

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

moveScoutColony

private void moveScoutColony(Unit unit,
                             Map.Direction direction)
Move to a foreign colony and either attack, negotiate with the foreign power or spy on them. Follows a move of MoveType.ENTER_FOREIGN_COLONY_WITH_SCOUT. TODO: Unify trade and negotiation.

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

moveScoutIndianSettlement

private void moveScoutIndianSettlement(Unit unit,
                                       Map.Direction direction)
Move a scout into an Indian settlement to speak with the chief, or demand a tribute following a move of MoveType.ENTER_INDIAN_SETTLEMENT_WITH_SCOUT. The scout does not physically get into the village, it will just stay where it is.

Parameters:
unit - The Unit that is scouting.
direction - The direction in which the Indian settlement lies.

moveSpy

private void moveSpy(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.

moveTrade

private void moveTrade(Unit unit,
                       Map.Direction direction)
Arrive at a settlement with a laden carrier following a move of MoveType.ENTER_SETTLEMENT_WITH_CARRIER_AND_GOODS.

Parameters:
unit - The carrier.
direction - The direction to the settlement.

moveTradeColony

private void moveTradeColony(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.

moveTradeIndianSettlement

private void moveTradeIndianSettlement(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

showTradeFail

private void showTradeFail(int fail,
                           Settlement settlement,
                           Goods goods)
Displays an appropriate trade failure message.

Parameters:
fail - The failure state.
settlement - The Settlement that failed to trade.
goods - The Goods that failed to trade.

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.

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.

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.

moveTribute

private void moveTribute(Unit unit,
                         Map.Direction direction)
Demand a tribute.

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

moveUseMissionary

private void moveUseMissionary(Unit unit,
                               Map.Direction direction)
Move a missionary into a native settlement, following a move of MoveType.ENTER_INDIAN_SETTLEMENT_WITH_MISSIONARY.

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

nextActiveUnit

public void nextActiveUnit()
Makes a new unit active.


nextActiveUnit

public void nextActiveUnit(Tile tile)
Makes a new unit active if any, or focus on a tile (useful if the current unit just died). Displays any new ModelMessages with nextModelMessage().

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

payArrears

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

Parameters:
type - The type of goods for which to pay arrears.
Returns:
True if the arrears were paid.

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.

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.

recruitUnitInEurope

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

Parameters:
index - The index in Europe to recruit from ([0..2]).

rename

public void rename(Nameable object)
Renames a Nameable. Apparently this can be done while it is not your turn.

Parameters:
object - The object to rename.

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.

sellGoods

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

Parameters:
goods - The goods to be sold.
Returns:
True if the sale succeeds.

sendChat

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

Parameters:
chat - The text of the message.

setBuildQueue

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

Parameters:
colony - The Colony
buildQueue - List of BuildableType

setCurrentPlayer

public void setCurrentPlayer(Player player)
Set a player to be the new current player.

Parameters:
player - The Player to be the new current player.

setDestination

public boolean setDestination(Unit unit,
                              Location destination)
Set the destination of the given unit.

Parameters:
unit - The Unit to direct.
destination - The destination Location.
Returns:
True if the destination was set.
See Also:
Unit.setDestination(Location)

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.

setTradeRoutes

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

Parameters:
routes - The trade routes to set.

skipActiveUnit

public void skipActiveUnit()
Skip a unit.


trainUnitInEurope

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

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

unload

public void unload(Unit unit)
Unload, including dumping cargo.

Parameters:
unit - The Unit that is dumping.

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 to unload.
dump - If true, dump the goods.

updateTradeRoute

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

Parameters:
route - The trade route to update.

waitActiveUnit

public void waitActiveUnit()
Tell a unit to wait.


work

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

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