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
 
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
 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)
           
 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.
 void buyGoods(GoodsType type, int amount, Unit carrier)
          Buys goods in Europe.
 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.
 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.
 void debugForeignColony(Tile tile)
           
 void declareIndependence()
          Declares independence for the home country.
 void disbandActiveUnit()
          Disbands the active unit.
 void displayModelMessages(boolean allMessages)
           
 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.
 org.w3c.dom.Element getForeignAffairsReport()
          Gathers information about opponents.
 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
 void ignoreMessage(ModelMessage message, boolean flag)
          Ignore this ModelMessage from now on until it is not generated in a turn.
 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.
 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.
 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.
 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.
 void purchaseUnitFromEurope(UnitType unitType)
          Purchases a unit of a specified type in Europe.
 boolean putOutsideColony(Unit unit)
          Puts the specified unit outside the colony.
 void recruitUnitInEurope(int slot)
          Recruit a unit from a specified "slot" in Europe.
 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.
 void selectDestination(Unit unit)
          Selects a destination for this unit.
 void sellGoods(Goods goods)
          Sells goods in Europe.
 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
 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.
 void updateTradeRoute(TradeRoute route)
          Updates a trade route.
 void work(Unit unit, WorkLocation workLocation)
          Moves a Unit to a WorkLocation.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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.

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.

buildColony

public void buildColony()
Uses the active unit to build a 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.

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.

debugForeignColony

public void debugForeignColony(Tile tile)

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.

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

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.

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.

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)

endTurn

public void endTurn()
End the turn.


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