net.sf.freecol.server.control
Class ServerModelController

java.lang.Object
  extended by net.sf.freecol.server.control.ServerModelController
All Implemented Interfaces:
java.beans.PropertyChangeListener, java.util.EventListener, ModelController

public class ServerModelController
extends java.lang.Object
implements ModelController, java.beans.PropertyChangeListener

A server-side implementation of the ModelController interface.


Constructor Summary
ServerModelController(FreeColServer freeColServer)
          Creates a new ServerModelController.
 
Method Summary
 void clearTaskRegister()
          Removes any entries older than TaskEntry#TASK_ENTRY_TIME_OUT.
 Building createBuilding(java.lang.String taskID, Colony colony, BuildingType type)
          Creates a new building.
 Building createBuilding(java.lang.String taskID, Colony colony, BuildingType type, boolean secure, Connection connection)
          Creates a new building.
 Unit createUnit(java.lang.String taskID, Location location, Player owner, UnitType type)
          Creates a new unit.
 Unit createUnit(java.lang.String taskID, Location location, Player owner, UnitType type, boolean secure, Connection connection)
          Creates a new unit.
 void exploreTiles(Player player, java.util.ArrayList<Tile> tiles)
          Explores the given tiles for the given player.
 TradeRoute getNewTradeRoute(Player player)
          Returns a new TradeRoute object.
 int getRandom(java.lang.String taskID, int n)
          Returns a pseudo-random int, uniformly distributed between 0 (inclusive) and the specified value (exclusive).
 void propertyChange(java.beans.PropertyChangeEvent e)
           
 void setStance(Player first, Player second, Player.Stance stance)
          Updates stances.
 Location setToVacantEntryLocation(Unit unit)
          Puts the specified Unit in America.
 void tileImprovementFinished(Unit unit, TileImprovement improvement)
          Tells the ModelController that a tile improvement was finished
 void update(Tile tile)
          Sends an update of the given Tile to all the players.
 void update(Tile newTile, Player p)
          Sends an update of the given Tile to the other players.
 void update(Unit unit, Player p)
          Sends an update of the unit to the other players.
 void updateModelListening()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServerModelController

public ServerModelController(FreeColServer freeColServer)
Creates a new ServerModelController.

Parameters:
freeColServer - The main controller.
Method Detail

getRandom

public int getRandom(java.lang.String taskID,
                     int n)
Returns a pseudo-random int, uniformly distributed between 0 (inclusive) and the specified value (exclusive).

Specified by:
getRandom in interface ModelController
Parameters:
taskID - The taskID should be a unique identifier. One method to make a unique taskID:

getId() + "methodName:taskDescription"

As long as the "taskDescription" is unique within the method ("methodName"), you get a unique identifier.
n - The specified value.
Returns:
The generated number.

clearTaskRegister

public void clearTaskRegister()
Removes any entries older than TaskEntry#TASK_ENTRY_TIME_OUT.


createUnit

public Unit createUnit(java.lang.String taskID,
                       Location location,
                       Player owner,
                       UnitType type)
Creates a new unit. This method is the same as running createUnit(String, Location, Player, UnitType, boolean, Connection) with secure = true and connection = null.

Specified by:
createUnit in interface ModelController
Parameters:
taskID - The taskID should be a unique identifier. One method to make a unique taskID:

getId() + "methodName:taskDescription"
br> As long as the "taskDescription" is unique within the method ("methodName"), you get a unique identifier.
location - The Location where the Unit will be created.
owner - The Player owning the Unit.
type - The type of unit (Unit.FREE_COLONIST...).
Returns:
A reference to the Unit which has been created.

createUnit

public Unit createUnit(java.lang.String taskID,
                       Location location,
                       Player owner,
                       UnitType type,
                       boolean secure,
                       Connection connection)
Creates a new unit.

Parameters:
taskID - The taskID should be a unique identifier. One method to make a unique taskID:

getId() + "methodName:taskDescription"
br> As long as the "taskDescription" is unique within the method ("methodName"), you get a unique identifier.
location - The Location where the Unit will be created.
owner - The Player owning the Unit.
type - The type of unit (Unit.FREE_COLONIST...).
secure - This variable should be set to false in case this method is called when serving a client. Setting this variable to false signals that the request might be illegal.
connection - The connection that has requested to create the unit, or null if this request is internal to the server.
Returns:
A reference to the Unit which has been created.

createBuilding

public Building createBuilding(java.lang.String taskID,
                               Colony colony,
                               BuildingType type)
Creates a new building. This method is the same as running createBuilding(String, Colony, BuildingType, boolean, Connection) with secure = true and connection = null.

Specified by:
createBuilding in interface ModelController
Parameters:
taskID - The taskID should be a unique identifier. One method to make a unique taskID:

getId() + "methodName:taskDescription"

As long as the "taskDescription" is unique within the method ("methodName"), you get a unique identifier.
colony - The Colony where the Building will be created.
type - The type of building.
Returns:
A reference to the Building which has been created.

createBuilding

public Building createBuilding(java.lang.String taskID,
                               Colony colony,
                               BuildingType type,
                               boolean secure,
                               Connection connection)
Creates a new building.

Parameters:
taskID - The taskID should be a unique identifier. One method to make a unique taskID:

getId() + "methodName:taskDescription"

As long as the "taskDescription" is unique within the method ("methodName"), you get a unique identifier.
colony - The Colony where the Building will be created.
type - The type of building.
secure - This variable should be set to false in case this method is called when serving a client. Setting this variable to false signals that the request might be illegal.
connection - The connection that has requested to create the building, or null if this request is internal to the server.
Returns:
A reference to the Building which has been created.

setToVacantEntryLocation

public Location setToVacantEntryLocation(Unit unit)
Puts the specified Unit in America.

Specified by:
setToVacantEntryLocation in interface ModelController
Parameters:
unit - The Unit.
Returns:
The Location where the Unit appears.

update

public void update(Tile tile)
Sends an update of the given Tile to all the players.

Parameters:
tile - The Tile to be updated.

tileImprovementFinished

public void tileImprovementFinished(Unit unit,
                                    TileImprovement improvement)
Tells the ModelController that a tile improvement was finished

Specified by:
tileImprovementFinished in interface ModelController
Parameters:
unit - an Unit value
improvement - a TileImprovement value

exploreTiles

public void exploreTiles(Player player,
                         java.util.ArrayList<Tile> tiles)
Explores the given tiles for the given player.

Specified by:
exploreTiles in interface ModelController
Parameters:
player - The Player that should see more tiles.
tiles - The tiles to explore.

setStance

public void setStance(Player first,
                      Player second,
                      Player.Stance stance)
Updates stances.

Specified by:
setStance in interface ModelController
Parameters:
first - The first Player.
second - The second Player.
stance - The new stance.

update

public void update(Tile newTile,
                   Player p)
Sends an update of the given Tile to the other players.

Parameters:
newTile - The Tile to be updated.
p - The player which should not receive an update (the source of the change).

update

public void update(Unit unit,
                   Player p)
Sends an update of the unit to the other players.

Parameters:
unit - The Unit to be updated.
p - The player which should not receive an update (the source of the change).

getNewTradeRoute

public TradeRoute getNewTradeRoute(Player player)
Returns a new TradeRoute object.

Specified by:
getNewTradeRoute in interface ModelController
Returns:
a new TradeRoute object.

updateModelListening

public void updateModelListening()

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent e)
Specified by:
propertyChange in interface java.beans.PropertyChangeListener