net.sf.freecol.server.control
Class InGameController

java.lang.Object
  extended by net.sf.freecol.server.control.FreeColServerHolder
      extended by net.sf.freecol.server.control.Controller
          extended by net.sf.freecol.server.control.InGameController

public final class InGameController
extends Controller

TODO: write class comment.


Field Summary
 int debugOnlyAITurns
           
private static java.util.logging.Logger logger
           
private  java.util.Random random
           
private  java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Object>>> transactionSessions
           
 
Constructor Summary
InGameController(FreeColServer freeColServer)
          The constructor to use.
 
Method Summary
private  void bombardEnemyShips(ServerPlayer currentPlayer)
           
 Player checkForWinner()
          Checks if anybody has won the game and returns that player.
private  void checkSpanishSuccession()
           
private  void chooseFoundingFather(ServerPlayer player)
           
 void closeTransactionSession(Unit unit, Settlement settlement)
           
 boolean createMission(IndianSettlement settlement, Unit missionary)
           
 ServerPlayer createREFPlayer(ServerPlayer player)
           
 java.util.List<Unit> createREFUnits(ServerPlayer player, ServerPlayer refPlayer)
           
private  void createUnits(java.util.List<AbstractUnit> units, org.w3c.dom.Element element, ServerPlayer nextPlayer)
           
 ModelMessage emigrate(ServerPlayer player, int slot, boolean fountain)
          A unit migrates from Europe.
 void endTurn(ServerPlayer player)
          Ends the turn of the given player.
 java.util.List<ServerPlayer> getOtherPlayers(ServerPlayer serverPlayer)
          Get a list of all server players, optionally excluding the supplied one.
private  java.util.List<FoundingFather> getRandomFoundingFathers(Player player)
          Returns a List of FoundingFathers, not including the founding fathers the player already has, one of each type, or null if no FoundingFather of that type is available.
 java.util.Map<java.lang.String,java.lang.Object> getTransactionSession(Unit unit, Settlement settlement)
           
private  boolean isHumanPlayersLeft()
           
 boolean isTransactionSessionOpen(Unit unit, Settlement settlement)
           
private  org.w3c.dom.Element killPlayerElement(ServerPlayer serverPlayer)
          Create an element to mark a player as dead, inform other players, and remove any leftover units.
private  void monarchAction(ServerPlayer player)
          Checks for monarch actions.
private  Player nextPlayer()
          Sets a new current player and notifies the clients.
 void sendRemoveUnitToAll(Unit unit, ServerPlayer serverPlayer)
          Tell all players to remove a unit, optionally excluding one player.
 void sendUpdatedTileToAll(Tile newTile, ServerPlayer serverPlayer)
          Tell all players to update a tile, optionally excluding one player.
 void sendUpdateToAll(FreeColGameObject obj, ServerPlayer serverPlayer)
          Unconditionally tell all players to update an object, optionally excluding one player.
 void unloadCargo(Player player, Goods goods)
           
 void yearlyGoodsRemoval(ServerPlayer player)
          Remove a standard yearly amount of storable goods, and a random extra amount of a random type.
 
Methods inherited from class net.sf.freecol.server.control.Controller
shutdown
 
Methods inherited from class net.sf.freecol.server.control.FreeColServerHolder
getFreeColServer, getGame
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static java.util.logging.Logger logger

random

private final java.util.Random random

debugOnlyAITurns

public int debugOnlyAITurns

transactionSessions

private java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Object>>> transactionSessions
Constructor Detail

InGameController

public InGameController(FreeColServer freeColServer)
The constructor to use.

Parameters:
freeColServer - The main server object.
Method Detail

getOtherPlayers

public java.util.List<ServerPlayer> getOtherPlayers(ServerPlayer serverPlayer)
Get a list of all server players, optionally excluding the supplied one.

Parameters:
serverPlayer - A ServerPlayer to exclude (may be null).
Returns:
A list of all connected server players except one.

sendRemoveUnitToAll

public void sendRemoveUnitToAll(Unit unit,
                                ServerPlayer serverPlayer)
Tell all players to remove a unit, optionally excluding one player. Only send if the unit is visible to the player.

Parameters:
unit - The Unit to remove.
serverPlayer - A ServerPlayer to exclude (may be null).

sendUpdateToAll

public void sendUpdateToAll(FreeColGameObject obj,
                            ServerPlayer serverPlayer)
Unconditionally tell all players to update an object, optionally excluding one player.

Parameters:
obj - The FreeColGameObject to update.
serverPlayer - A ServerPlayer to exclude (may be null).

sendUpdatedTileToAll

public void sendUpdatedTileToAll(Tile newTile,
                                 ServerPlayer serverPlayer)
Tell all players to update a tile, optionally excluding one player. Only send if the tile is visible.

Parameters:
newTile - The Tile to update.
serverPlayer - A ServerPlayer to exclude (may be null).

endTurn

public void endTurn(ServerPlayer player)
Ends the turn of the given player.

Parameters:
player - The player to end the turn of.

yearlyGoodsRemoval

public void yearlyGoodsRemoval(ServerPlayer player)
Remove a standard yearly amount of storable goods, and a random extra amount of a random type. Send the market and change messages to the player. This method is public so it can be use in the Market test code.

Parameters:
player - The player whose market is to be updated.

killPlayerElement

private org.w3c.dom.Element killPlayerElement(ServerPlayer serverPlayer)
Create an element to mark a player as dead, inform other players, and remove any leftover units.

Parameters:
serverPlayer - The player to kill.
Returns:
An element to kill the player.

nextPlayer

private Player nextPlayer()
Sets a new current player and notifies the clients.

Returns:
The new current player.

checkSpanishSuccession

private void checkSpanishSuccession()

isHumanPlayersLeft

private boolean isHumanPlayersLeft()

chooseFoundingFather

private void chooseFoundingFather(ServerPlayer player)

getRandomFoundingFathers

private java.util.List<FoundingFather> getRandomFoundingFathers(Player player)
Returns a List of FoundingFathers, not including the founding fathers the player already has, one of each type, or null if no FoundingFather of that type is available.

Parameters:
player - The Player that should pick a founding father from this list.

checkForWinner

public Player checkForWinner()
Checks if anybody has won the game and returns that player.

Returns:
The Player who have won the game or null if the game is not finished.

monarchAction

private void monarchAction(ServerPlayer player)
Checks for monarch actions.

Parameters:
player - The server player.

createREFPlayer

public ServerPlayer createREFPlayer(ServerPlayer player)

createUnits

private void createUnits(java.util.List<AbstractUnit> units,
                         org.w3c.dom.Element element,
                         ServerPlayer nextPlayer)

createREFUnits

public java.util.List<Unit> createREFUnits(ServerPlayer player,
                                           ServerPlayer refPlayer)

createMission

public boolean createMission(IndianSettlement settlement,
                             Unit missionary)

bombardEnemyShips

private void bombardEnemyShips(ServerPlayer currentPlayer)

getTransactionSession

public java.util.Map<java.lang.String,java.lang.Object> getTransactionSession(Unit unit,
                                                                              Settlement settlement)

closeTransactionSession

public void closeTransactionSession(Unit unit,
                                    Settlement settlement)

isTransactionSessionOpen

public boolean isTransactionSessionOpen(Unit unit,
                                        Settlement settlement)

emigrate

public ModelMessage emigrate(ServerPlayer player,
                             int slot,
                             boolean fountain)
A unit migrates from Europe.

Parameters:
player - The ServerPlayer whose unit it will be.
slot - The slot within Europe to select the unit from.
fountain - True if this occurs as a result of a Fountain of Youth.

unloadCargo

public void unloadCargo(Player player,
                        Goods goods)