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

The main server controller.


Nested Class Summary
private  class InGameController.DOMMessageCallable
           
private static interface InGameController.DOMMessageHandler
           
private  class InGameController.FutureQuery
           
 
Field Summary
static int ALARM_NEW_MISSIONARY
           
private  Monarch.MonarchAction debugMonarchAction
           
private  ServerPlayer debugMonarchPlayer
           
private  int debugOnlyAITurns
           
private  java.util.concurrent.ExecutorService executor
           
private static java.util.logging.Logger logger
           
private static java.util.List<InGameController.FutureQuery> outstandingQueries
           
private  java.util.Random random
           
static int SCORE_INDEPENDENCE_DECLARED
           
static int SCORE_INDEPENDENCE_GRANTED
           
 
Constructor Summary
InGameController(FreeColServer freeColServer, java.util.Random random)
          The constructor to use.
 
Method Summary
 org.w3c.dom.Element abandonSettlement(ServerPlayer serverPlayer, Settlement settlement)
          Abandon a settlement.
private  StringTemplate abstractUnitTemplate(java.lang.String base, java.util.List<AbstractUnit> units)
           
 void addFoundingFather(ServerPlayer serverPlayer, FoundingFather father)
          Public version of csAddFoundingFather so it can be used in the test code and DebugMenu.
private  org.w3c.dom.Element askElement(ServerPlayer serverPlayer, org.w3c.dom.Element request)
          Send an element to a specific player.
private  java.util.concurrent.Future<DOMMessage> askFuture(ServerPlayer serverPlayer, DOMMessage question, InGameController.DOMMessageHandler handler)
          Asks a question of a player in a Future.
 org.w3c.dom.Element askLearnSkill(ServerPlayer serverPlayer, Unit unit, IndianSettlement settlement)
          Ask about learning a skill at an IndianSettlement.
private  void askThisTurn(ServerPlayer serverPlayer, DOMMessage message, InGameController.DOMMessageHandler handler, java.lang.Runnable runnable)
          Asks a question that must be answered this turn.
private  DOMMessage askTimeout(ServerPlayer serverPlayer, DOMMessage request)
          Asks a question of a player with a timeout.
 org.w3c.dom.Element assignTeacher(ServerPlayer serverPlayer, Unit student, Unit teacher)
          Assign a student to a teacher.
 org.w3c.dom.Element assignTradeRoute(ServerPlayer serverPlayer, Unit unit, TradeRoute tradeRoute)
          Assign a trade route to a unit.
 org.w3c.dom.Element buildSettlement(ServerPlayer serverPlayer, Unit unit, java.lang.String name)
          Build a settlement.
 org.w3c.dom.Element buyFromSettlement(ServerPlayer serverPlayer, Unit unit, IndianSettlement settlement, Goods goods, int amount)
          Buy from a settlement.
 org.w3c.dom.Element buyGoods(ServerPlayer serverPlayer, Unit unit, GoodsType type, int amount)
          Buy goods in Europe.
 org.w3c.dom.Element buyProposition(ServerPlayer serverPlayer, Unit unit, Settlement settlement, Goods goods, int price)
          Price some goods for sale from a settlement.
 org.w3c.dom.Element cashInTreasureTrain(ServerPlayer serverPlayer, Unit unit)
          Cash in a treasure train.
 void changeStance(Player player, Player.Stance stance, Player otherPlayer, boolean symmetric)
          Public change stance and inform all routine.
 org.w3c.dom.Element changeState(ServerPlayer serverPlayer, Unit unit, Unit.UnitState state)
          Change a units state.
 org.w3c.dom.Element changeWorkImprovementType(ServerPlayer serverPlayer, Unit unit, TileImprovementType type)
          Change improvement work type.
 org.w3c.dom.Element changeWorkType(ServerPlayer serverPlayer, Unit unit, GoodsType type)
          Change work type.
 org.w3c.dom.Element chat(ServerPlayer serverPlayer, java.lang.String message, boolean pri)
          Chat.
 org.w3c.dom.Element checkHighScore(ServerPlayer serverPlayer)
          Check the high scores.
 org.w3c.dom.Element claimLand(ServerPlayer serverPlayer, Tile tile, Settlement settlement, int price)
          Claim land.
 org.w3c.dom.Element clearSpeciality(ServerPlayer serverPlayer, Unit unit)
          Clear the specialty of a unit.
 org.w3c.dom.Element closeTransaction(ServerPlayer serverPlayer, Unit unit, Settlement settlement)
          Close a transaction.
 org.w3c.dom.Element combat(ServerPlayer attackerPlayer, FreeColGameObject attacker, FreeColGameObject defender, java.util.List<CombatModel.CombatResult> crs)
          Combat.
 org.w3c.dom.Element continuePlaying(ServerPlayer serverPlayer)
          Continue playing after winning.
 ServerPlayer createREFPlayer(ServerPlayer serverPlayer)
          Create the Royal Expeditionary Force player corresponding to a given player that is about to rebel.
private  void csAcceptTrade(Unit unit, Settlement settlement, DiplomaticTrade agreement, ChangeSet cs)
          Accept a diplomatic trade.
private  void csGiveIndependence(ServerPlayer serverPlayer, ServerPlayer independent, ChangeSet cs)
          Give independence.
private  void csMonarchAction(ServerPlayer serverPlayer, Monarch.MonarchAction action, ChangeSet cs)
          Performs a monarch action.
private  void csSpeakToChief(ServerPlayer serverPlayer, IndianSettlement is, boolean scout, ChangeSet cs)
          Speaks to a chief in a native settlement, but only if it is as a result of a scout actually asking to speak to the chief, or for other settlement-contacting events such as missionary actions, demanding tribute, learning skills and trading if the settlementActionsContactChief game option is enabled.
 org.w3c.dom.Element declareIndependence(ServerPlayer serverPlayer, java.lang.String nationName, java.lang.String countryName)
          Declare independence.
 org.w3c.dom.Element declineMounds(ServerPlayer serverPlayer, Tile tile)
          Decline to investigate strange mounds.
 org.w3c.dom.Element deliverGiftToSettlement(ServerPlayer serverPlayer, Unit unit, Settlement settlement, Goods goods)
          Deliver gift to settlement.
 org.w3c.dom.Element demandTribute(ServerPlayer serverPlayer, Unit unit, IndianSettlement settlement)
          Demand a tribute from a native settlement.
 org.w3c.dom.Element denounceMission(ServerPlayer serverPlayer, Unit unit, IndianSettlement settlement)
          Denounce an existing mission.
 org.w3c.dom.Element diplomaticTrade(ServerPlayer serverPlayer, Unit unit, Settlement settlement, DiplomaticTrade agreement)
          Diplomatic trades.
 org.w3c.dom.Element disbandUnit(ServerPlayer serverPlayer, Unit unit)
          Disband a unit.
 org.w3c.dom.Element disembarkUnit(ServerPlayer serverPlayer, Unit unit)
          Disembark unit from a carrier.
 org.w3c.dom.Element embarkUnit(ServerPlayer serverPlayer, Unit unit, Unit carrier)
          Embark a unit onto a carrier.
 org.w3c.dom.Element emigrate(ServerPlayer serverPlayer, int slot, Europe.MigrationType type)
          A unit migrates from Europe.
 org.w3c.dom.Element endTurn(ServerPlayer serverPlayer)
          Ends the turn of the given player.
 org.w3c.dom.Element enterRevengeMode(ServerPlayer serverPlayer)
          Enters revenge mode against those evil AIs.
 org.w3c.dom.Element equipUnit(ServerPlayer serverPlayer, Unit unit, EquipmentType type, int amount)
          Equip a unit.
 org.w3c.dom.Element establishMission(ServerPlayer serverPlayer, Unit unit, IndianSettlement settlement)
          Establish a new mission.
 org.w3c.dom.Element getGoodsForSale(ServerPlayer serverPlayer, Unit unit, Settlement settlement)
          Get the goods for sale in a settlement.
 org.w3c.dom.Element getHighScores(ServerPlayer serverPlayer)
          Gets the list of high scores.
 NationSummary getNationSummary(ServerPlayer serverPlayer, Player player)
          Gets a nation summary.
 org.w3c.dom.Element getNewTradeRoute(ServerPlayer serverPlayer)
          Get a new trade route for a player.
private  java.lang.String getNonPlayerNation()
           
private  java.util.List<ServerPlayer> getOtherPlayers(ServerPlayer... serverPlayers)
          Get a list of all server players, optionally excluding supplied ones.
 org.w3c.dom.Element getREFUnits(ServerPlayer serverPlayer)
          Get a list of abstract REF units for a player.
 int getSkippedTurns()
          Gets the number of AI turns to skip through.
 org.w3c.dom.Element getStatistics(ServerPlayer serverPlayer)
          Get the current game statistics.
 org.w3c.dom.Element getTransaction(ServerPlayer serverPlayer, Unit unit, Settlement settlement)
          Gets a settlement transaction session, either existing or newly opened.
 org.w3c.dom.Element incite(ServerPlayer serverPlayer, Unit unit, IndianSettlement settlement, Player enemy, int gold)
          Incite a settlement against an enemy.
 org.w3c.dom.Element indianDemand(ServerPlayer serverPlayer, Unit unit, Colony colony, Goods goods, int gold)
          Indians making demands of a colony.
 org.w3c.dom.Element joinColony(ServerPlayer serverPlayer, Unit unit, Colony colony)
          Join a colony.
 org.w3c.dom.Element learnFromIndianSettlement(ServerPlayer serverPlayer, Unit unit, IndianSettlement settlement)
          Learn a skill at an IndianSettlement.
 org.w3c.dom.Element loadCargo(ServerPlayer serverPlayer, Unit unit, Goods goods)
          Load cargo.
 org.w3c.dom.Element lootCargo(ServerPlayer serverPlayer, Unit winner, java.lang.String loserId, java.util.List<Goods> loot)
          Loot cargo.
 org.w3c.dom.Element move(ServerPlayer serverPlayer, Unit unit, Tile newTile)
          Move a unit.
 void moveGoods(Goods goods, Location loc)
          Move goods from current location to another.
 org.w3c.dom.Element moveTo(ServerPlayer serverPlayer, Unit unit, Location destination)
          Move a unit across the high seas.
private  void nextFoundingFather(ServerPlayer serverPlayer)
          Queries a player to choose their next founding father in a future.
 org.w3c.dom.Element payArrears(ServerPlayer serverPlayer, GoodsType type)
          Pay arrears.
 org.w3c.dom.Element payForBuilding(ServerPlayer serverPlayer, Colony colony)
          Pay for a building.
 org.w3c.dom.Element putOutsideColony(ServerPlayer serverPlayer, Unit unit)
          Put outside colony.
private  void raiseTax(ServerPlayer serverPlayer, int taxRaise, Goods goods, boolean result)
          Resolves a tax raise.
 org.w3c.dom.Element renameObject(ServerPlayer serverPlayer, Nameable object, java.lang.String newName)
          Rename an object.
 void resolveOutstandingQueries()
          Resolves and clears any outstanding queries.
 org.w3c.dom.Element retire(ServerPlayer serverPlayer)
          Handle a player retiring.
 org.w3c.dom.Element scoutIndianSettlement(ServerPlayer serverPlayer, Unit unit, IndianSettlement settlement)
          Scout a native settlement.
 org.w3c.dom.Element sellGoods(ServerPlayer serverPlayer, Unit unit, GoodsType type, int amount)
          Sell goods in Europe.
 org.w3c.dom.Element sellProposition(ServerPlayer serverPlayer, Unit unit, Settlement settlement, Goods goods, int price)
          Price some goods for sale to a settlement.
 org.w3c.dom.Element sellToSettlement(ServerPlayer serverPlayer, Unit unit, IndianSettlement settlement, Goods goods, int amount)
          Sell to a settlement.
private  void sendElement(ServerPlayer serverPlayer, ChangeSet cs)
          Send an element to a specific player.
private  void sendToAll(ChangeSet cs)
          Send a set of changes to all players.
private  void sendToList(java.util.List<ServerPlayer> serverPlayers, ChangeSet cs)
          Send an update to a list of players.
private  void sendToList(java.util.List<ServerPlayer> serverPlayers, org.w3c.dom.Element element)
          Send an element to a list of players.
private  void sendToOthers(ServerPlayer serverPlayer, ChangeSet cs)
          Send an update to all players except one.
private  void sendToOthers(ServerPlayer serverPlayer, org.w3c.dom.Element element)
          Send an element to all players except one.
 org.w3c.dom.Element setBuildQueue(ServerPlayer serverPlayer, Colony colony, java.util.List<BuildableType> queue)
          Set build queue.
 org.w3c.dom.Element setDestination(ServerPlayer serverPlayer, Unit unit, Location destination)
          Set a unit destination.
 org.w3c.dom.Element setGoodsLevels(ServerPlayer serverPlayer, Colony colony, ExportData exportData)
          Set goods levels.
 void setMonarchAction(Player player, Monarch.MonarchAction action)
          Sets a monarch action to debug/test.
 org.w3c.dom.Element setNewLandName(ServerPlayer serverPlayer, Unit unit, java.lang.String name, ServerPlayer welcomer, int camps, boolean accept)
          Set land name.
 org.w3c.dom.Element setNewRegionName(ServerPlayer serverPlayer, Region region, java.lang.String name)
          Set region name.
 void setSkippedTurns(int turns)
          Sets the number of AI turns to skip through as a debug helper.
 org.w3c.dom.Element setTradeRoutes(ServerPlayer serverPlayer, java.util.List<TradeRoute> routes)
          Set trade routes for a player.
 org.w3c.dom.Element spySettlement(ServerPlayer serverPlayer, Unit unit, Settlement settlement)
          Spy on a settlement.
 int stepRandom()
          Debug convenience to step the random number generator.
 org.w3c.dom.Element trainUnitInEurope(ServerPlayer serverPlayer, UnitType type)
          Train a unit in Europe.
private  StringTemplate unitTemplate(java.lang.String base, java.util.List<Unit> units)
           
 org.w3c.dom.Element unloadCargo(ServerPlayer serverPlayer, Unit unit, Goods goods)
          Unload cargo.
 org.w3c.dom.Element updateCurrentStop(ServerPlayer serverPlayer, Unit unit)
          Set current stop of a unit to the next valid stop if any.
 org.w3c.dom.Element work(ServerPlayer serverPlayer, Unit unit, WorkLocation workLocation)
          Change work location.
 void yearlyGoodsAdjust(ServerPlayer serverPlayer)
          Public version of the yearly goods adjust (public so it can be use in the Market test code).
 
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

ALARM_NEW_MISSIONARY

public static final int ALARM_NEW_MISSIONARY
See Also:
Constant Field Values

SCORE_INDEPENDENCE_DECLARED

public static final int SCORE_INDEPENDENCE_DECLARED
See Also:
Constant Field Values

SCORE_INDEPENDENCE_GRANTED

public static final int SCORE_INDEPENDENCE_GRANTED
See Also:
Constant Field Values

random

private final java.util.Random random

debugOnlyAITurns

private int debugOnlyAITurns

debugMonarchAction

private Monarch.MonarchAction debugMonarchAction

debugMonarchPlayer

private ServerPlayer debugMonarchPlayer

executor

private final java.util.concurrent.ExecutorService executor

outstandingQueries

private static final java.util.List<InGameController.FutureQuery> outstandingQueries
Constructor Detail

InGameController

public InGameController(FreeColServer freeColServer,
                        java.util.Random random)
The constructor to use.

Parameters:
freeColServer - The main server object.
random - The pseudo-random number source to use.
Method Detail

getSkippedTurns

public int getSkippedTurns()
Gets the number of AI turns to skip through.

Returns:
The number of terms to skip.

setSkippedTurns

public void setSkippedTurns(int turns)
Sets the number of AI turns to skip through as a debug helper.

Parameters:
turns - The number of turns to skip through.

setMonarchAction

public void setMonarchAction(Player player,
                             Monarch.MonarchAction action)
Sets a monarch action to debug/test.

Parameters:
player - The Player whose monarch should act.
action - The MonarchAction to be taken.

stepRandom

public int stepRandom()
Debug convenience to step the random number generator.

Returns:
The next random number in series, in the range 0-99.

yearlyGoodsAdjust

public void yearlyGoodsAdjust(ServerPlayer serverPlayer)
Public version of the yearly goods adjust (public so it can be use in the Market test code). Sends the market and change messages to the player.

Parameters:
serverPlayer - The ServerPlayer whose market is to be updated.

addFoundingFather

public void addFoundingFather(ServerPlayer serverPlayer,
                              FoundingFather father)
Public version of csAddFoundingFather so it can be used in the test code and DebugMenu.

Parameters:
serverPlayer - The ServerPlayer who gains a father.
father - The FoundingFather to add.

changeStance

public void changeStance(Player player,
                         Player.Stance stance,
                         Player otherPlayer,
                         boolean symmetric)
Public change stance and inform all routine. Mostly used in the test suite, but the AIs also call it.

Parameters:
player - The originating Player.
stance - The new Stance.
otherPlayer - The Player wrt which the stance changes.
symmetric - If true, change the otherPlayer stance as well.

getNationSummary

public NationSummary getNationSummary(ServerPlayer serverPlayer,
                                      Player player)
Gets a nation summary.

Parameters:
serverPlayer - The ServerPlayer that is querying.
player - The Player to summarize.
Returns:
An Element encapsulating this action.

moveGoods

public void moveGoods(Goods goods,
                      Location loc)
               throws java.lang.IllegalStateException
Move goods from current location to another.

Parameters:
goods - The Goods to move.
loc - The new Location.
Throws:
java.lang.IllegalStateException

createREFPlayer

public ServerPlayer createREFPlayer(ServerPlayer serverPlayer)
Create the Royal Expeditionary Force player corresponding to a given player that is about to rebel. Public for the test suite.

Parameters:
serverPlayer - The ServerPlayer about to rebel.
Returns:
The REF player.

askFuture

private java.util.concurrent.Future<DOMMessage> askFuture(ServerPlayer serverPlayer,
                                                          DOMMessage question,
                                                          InGameController.DOMMessageHandler handler)
Asks a question of a player in a Future.

Parameters:
serverPlayer - The ServerPlayer to ask.
question - The DOMMessage question.
handler - The DOMMessageHandler handler to process the reply with.
Returns:
A future encapsulating the result.

resolveOutstandingQueries

public void resolveOutstandingQueries()
Resolves and clears any outstanding queries.


askThisTurn

private void askThisTurn(ServerPlayer serverPlayer,
                         DOMMessage message,
                         InGameController.DOMMessageHandler handler,
                         java.lang.Runnable runnable)
Asks a question that must be answered this turn.

Parameters:
serverPlayer - The ServerPlayer to ask.
question - The DOMMessage question.
handler - The DOMMessageHandler handler to process the reply with.
runnable - An optional Runnable to run if the question was not answered.

askTimeout

private DOMMessage askTimeout(ServerPlayer serverPlayer,
                              DOMMessage request)
Asks a question of a player with a timeout.

Parameters:
serverPlayer - The ServerPlayer to ask.
question - The DOMMessage question.
Returns:
The response to the question, or null if none.

getOtherPlayers

private java.util.List<ServerPlayer> getOtherPlayers(ServerPlayer... serverPlayers)
Get a list of all server players, optionally excluding supplied ones.

Parameters:
serverPlayers - The ServerPlayers to exclude.
Returns:
A list of all connected server players, with exclusions.

sendToAll

private void sendToAll(ChangeSet cs)
Send a set of changes to all players.

Parameters:
cs - The ChangeSet to send.

sendToOthers

private void sendToOthers(ServerPlayer serverPlayer,
                          ChangeSet cs)
Send an update to all players except one.

Parameters:
serverPlayer - A ServerPlayer to exclude.
cs - The ChangeSet encapsulating the update.

sendToOthers

private void sendToOthers(ServerPlayer serverPlayer,
                          org.w3c.dom.Element element)
Send an element to all players except one. Deprecated, please avoid if possible.

Parameters:
serverPlayer - A ServerPlayer to exclude.
element - An Element to send.

sendToList

private void sendToList(java.util.List<ServerPlayer> serverPlayers,
                        ChangeSet cs)
Send an update to a list of players.

Parameters:
serverPlayers - The ServerPlayers to send to.
cs - The ChangeSet encapsulating the update.

sendToList

private void sendToList(java.util.List<ServerPlayer> serverPlayers,
                        org.w3c.dom.Element element)
Send an element to a list of players. Deprecated, please avoid if possible.

Parameters:
serverPlayers - The ServerPlayers to send to.
element - An Element to send.

sendElement

private void sendElement(ServerPlayer serverPlayer,
                         ChangeSet cs)
Send an element to a specific player.

Parameters:
serverPlayer - The ServerPlayer to update.
cs - A ChangeSet to build an Element with.

askElement

private org.w3c.dom.Element askElement(ServerPlayer serverPlayer,
                                       org.w3c.dom.Element request)
Send an element to a specific player. Deprecated, please avoid if possible.

Parameters:
serverPlayer - The ServerPlayer to update.
request - An Element containing the update.

csSpeakToChief

private void csSpeakToChief(ServerPlayer serverPlayer,
                            IndianSettlement is,
                            boolean scout,
                            ChangeSet cs)
Speaks to a chief in a native settlement, but only if it is as a result of a scout actually asking to speak to the chief, or for other settlement-contacting events such as missionary actions, demanding tribute, learning skills and trading if the settlementActionsContactChief game option is enabled. It is still unclear what Col1 did here.

Parameters:
serverPlayer - The ServerPlayer that is contacting the settlement.
is - The IndianSettlement to contact.
scout - True if this contact is due to a scout asking to speak to the chief.
cs - A ChangeSet to update.

endTurn

public org.w3c.dom.Element endTurn(ServerPlayer serverPlayer)
Ends the turn of the given player.

Parameters:
serverPlayer - The ServerPlayer to end the turn of.
Returns:
Null.

nextFoundingFather

private void nextFoundingFather(ServerPlayer serverPlayer)
Queries a player to choose their next founding father in a future.

Parameters:
serverPlayer - The ServerPlayer to ask.

csGiveIndependence

private void csGiveIndependence(ServerPlayer serverPlayer,
                                ServerPlayer independent,
                                ChangeSet cs)
Give independence. Note that the REF player is granting, but most of the changes happen to the newly independent player. hence the special handling.

Parameters:
serverPlayer - The REF ServerPlayer that is granting.
independent - The newly independent ServerPlayer.
cs - A ChangeSet to update.

unitTemplate

private StringTemplate unitTemplate(java.lang.String base,
                                    java.util.List<Unit> units)

abstractUnitTemplate

private StringTemplate abstractUnitTemplate(java.lang.String base,
                                            java.util.List<AbstractUnit> units)

getNonPlayerNation

private java.lang.String getNonPlayerNation()

raiseTax

private void raiseTax(ServerPlayer serverPlayer,
                      int taxRaise,
                      Goods goods,
                      boolean result)
Resolves a tax raise.

Parameters:
serverPlayer - The ServerPlayer whose tax is rising.
taxRaise - The amount of tax raise.
goods - The Goods for a goods party.
result - Whether the tax was accepted or not.

csMonarchAction

private void csMonarchAction(ServerPlayer serverPlayer,
                             Monarch.MonarchAction action,
                             ChangeSet cs)
Performs a monarch action. Note that CHANGE_LATE is used so that these actions follow setting the current player, so that it is the players turn when they respond to a monarch action.

Parameters:
serverPlayer - The ServerPlayer being acted upon.
action - The monarch action.
cs - A ChangeSet to update.

checkHighScore

public org.w3c.dom.Element checkHighScore(ServerPlayer serverPlayer)
Check the high scores.

Parameters:
serverPlayer - The ServerPlayer that is retiring.
Returns:
An element indicating the players high score state.

retire

public org.w3c.dom.Element retire(ServerPlayer serverPlayer)
Handle a player retiring.

Parameters:
serverPlayer - The ServerPlayer that is retiring.
Returns:
An element cleaning up the player.

continuePlaying

public org.w3c.dom.Element continuePlaying(ServerPlayer serverPlayer)
Continue playing after winning.

Parameters:
serverPlayer - The ServerPlayer that plays on.
Returns:
Null.

cashInTreasureTrain

public org.w3c.dom.Element cashInTreasureTrain(ServerPlayer serverPlayer,
                                               Unit unit)
Cash in a treasure train.

Parameters:
serverPlayer - The ServerPlayer that is cashing in.
unit - The treasure train Unit to cash in.
Returns:
An Element encapsulating this action.

declareIndependence

public org.w3c.dom.Element declareIndependence(ServerPlayer serverPlayer,
                                               java.lang.String nationName,
                                               java.lang.String countryName)
Declare independence.

Parameters:
serverPlayer - The ServerPlayer that is naming.
nationName - The new name for the independent nation.
countryName - The new name for its residents.
Returns:
An Element encapsulating this action.

renameObject

public org.w3c.dom.Element renameObject(ServerPlayer serverPlayer,
                                        Nameable object,
                                        java.lang.String newName)
Rename an object.

Parameters:
serverPlayer - The ServerPlayer that is naming.
object - The Nameable to rename.
newName - The new name.
Returns:
An Element encapsulating this action.

getTransaction

public org.w3c.dom.Element getTransaction(ServerPlayer serverPlayer,
                                          Unit unit,
                                          Settlement settlement)
Gets a settlement transaction session, either existing or newly opened.

Parameters:
serverPlayer - The ServerPlayer that is trading.
unit - The Unit that is trading.
settlement - The Settlement that is trading.
Returns:
An Element encapsulating this action.

closeTransaction

public org.w3c.dom.Element closeTransaction(ServerPlayer serverPlayer,
                                            Unit unit,
                                            Settlement settlement)
Close a transaction.

Parameters:
serverPlayer - The ServerPlayer that is trading.
unit - The Unit that is trading.
settlement - The Settlement that is trading.
Returns:
An Element encapsulating this action.

getGoodsForSale

public org.w3c.dom.Element getGoodsForSale(ServerPlayer serverPlayer,
                                           Unit unit,
                                           Settlement settlement)
Get the goods for sale in a settlement.

Parameters:
serverPlayer - The ServerPlayer that is enquiring.
unit - The Unit that is trading.
settlement - The Settlement that is trading.
Returns:
An Element encapsulating this action.

buyProposition

public org.w3c.dom.Element buyProposition(ServerPlayer serverPlayer,
                                          Unit unit,
                                          Settlement settlement,
                                          Goods goods,
                                          int price)
Price some goods for sale from a settlement.

Parameters:
serverPlayer - The ServerPlayer that is buying.
unit - The Unit that is trading.
settlement - The Settlement that is trading.
goods - The Goods to buy.
price - The buyers proposed price for the goods.
Returns:
An Element encapsulating this action.

sellProposition

public org.w3c.dom.Element sellProposition(ServerPlayer serverPlayer,
                                           Unit unit,
                                           Settlement settlement,
                                           Goods goods,
                                           int price)
Price some goods for sale to a settlement.

Parameters:
serverPlayer - The ServerPlayer that is buying.
unit - The Unit that is trading.
settlement - The Settlement that is trading.
goods - The Goods to sell.
price - The sellers proposed price for the goods.
Returns:
An Element encapsulating this action.

buyGoods

public org.w3c.dom.Element buyGoods(ServerPlayer serverPlayer,
                                    Unit unit,
                                    GoodsType type,
                                    int amount)
Buy goods in Europe.

Parameters:
serverPlayer - The ServerPlayer that is buying.
unit - The Unit to carry the goods.
type - The GoodsType to buy.
amount - The amount of goods to buy.
Returns:
An Element encapsulating this action.

sellGoods

public org.w3c.dom.Element sellGoods(ServerPlayer serverPlayer,
                                     Unit unit,
                                     GoodsType type,
                                     int amount)
Sell goods in Europe.

Parameters:
serverPlayer - The ServerPlayer that is selling.
unit - The Unit carrying the goods.
type - The GoodsType to sell.
amount - The amount of goods to sell.
Returns:
An Element encapsulating this action.

emigrate

public org.w3c.dom.Element emigrate(ServerPlayer serverPlayer,
                                    int slot,
                                    Europe.MigrationType type)
A unit migrates from Europe.

Parameters:
serverPlayer - The ServerPlayer whose unit it will be.
slot - The slot within Europe to select the unit from.
type - The type of migration occurring.
Returns:
An Element encapsulating this action.

move

public org.w3c.dom.Element move(ServerPlayer serverPlayer,
                                Unit unit,
                                Tile newTile)
Move a unit.

Parameters:
serverPlayer - The ServerPlayer that is moving.
unit - The Unit to move.
newTile - The Tile to move to.
Returns:
An Element encapsulating this action.

declineMounds

public org.w3c.dom.Element declineMounds(ServerPlayer serverPlayer,
                                         Tile tile)
Decline to investigate strange mounds.

Parameters:
serverPlayer - The ServerPlayer that owns the unit.
tile - The Tile where the mounds are.
Returns:
An Element encapsulating this action.

setNewLandName

public org.w3c.dom.Element setNewLandName(ServerPlayer serverPlayer,
                                          Unit unit,
                                          java.lang.String name,
                                          ServerPlayer welcomer,
                                          int camps,
                                          boolean accept)
Set land name.

Parameters:
serverPlayer - The ServerPlayer who landed.
unit - The Unit that has come ashore.
name - The new land name.
welcomer - An optional ServerPlayer that has offered a treaty.
camps - An optional number of camps for the welcome message.
accept - True if the treaty has been accepted.
Returns:
An Element encapsulating this action.

setNewRegionName

public org.w3c.dom.Element setNewRegionName(ServerPlayer serverPlayer,
                                            Region region,
                                            java.lang.String name)
Set region name.

Parameters:
serverPlayer - The ServerPlayer discovering.
region - The Region to discover.
name - The new region name.
Returns:
An Element encapsulating this action.

moveTo

public org.w3c.dom.Element moveTo(ServerPlayer serverPlayer,
                                  Unit unit,
                                  Location destination)
Move a unit across the high seas.

Parameters:
serverPlayer - The ServerPlayer that owns the unit.
unit - The Unit to move.
destination - The Location to move to.
Returns:
An Element encapsulating this action.

embarkUnit

public org.w3c.dom.Element embarkUnit(ServerPlayer serverPlayer,
                                      Unit unit,
                                      Unit carrier)
Embark a unit onto a carrier. Checking that the locations are appropriate is not done here.

Parameters:
serverPlayer - The ServerPlayer embarking.
unit - The Unit that is embarking.
carrier - The Unit to embark onto.
Returns:
An Element encapsulating this action.

disembarkUnit

public org.w3c.dom.Element disembarkUnit(ServerPlayer serverPlayer,
                                         Unit unit)
Disembark unit from a carrier.

Parameters:
serverPlayer - The ServerPlayer whose unit is embarking.
unit - The Unit that is disembarking.
Returns:
An Element encapsulating this action.

combat

public org.w3c.dom.Element combat(ServerPlayer attackerPlayer,
                                  FreeColGameObject attacker,
                                  FreeColGameObject defender,
                                  java.util.List<CombatModel.CombatResult> crs)
Combat.

Parameters:
attackerPlayer - The ServerPlayer who is attacking.
attacker - The FreeColGameObject that is attacking.
defender - The FreeColGameObject that is defending.
crs - A list of CombatResults defining the result.
Returns:
An Element encapsulating this action.

askLearnSkill

public org.w3c.dom.Element askLearnSkill(ServerPlayer serverPlayer,
                                         Unit unit,
                                         IndianSettlement settlement)
Ask about learning a skill at an IndianSettlement.

Parameters:
serverPlayer - The ServerPlayer that is learning.
unit - The Unit that is learning.
settlement - The Settlement to learn from.
Returns:
An Element encapsulating this action.

learnFromIndianSettlement

public org.w3c.dom.Element learnFromIndianSettlement(ServerPlayer serverPlayer,
                                                     Unit unit,
                                                     IndianSettlement settlement)
Learn a skill at an IndianSettlement.

Parameters:
serverPlayer - The ServerPlayer that is learning.
unit - The Unit that is learning.
settlement - The Settlement to learn from.
Returns:
An Element encapsulating this action.

demandTribute

public org.w3c.dom.Element demandTribute(ServerPlayer serverPlayer,
                                         Unit unit,
                                         IndianSettlement settlement)
Demand a tribute from a native settlement.

Parameters:
serverPlayer - The ServerPlayer demanding the tribute.
unit - The Unit that is demanding the tribute.
settlement - The IndianSettlement demanded of.
Returns:
An Element encapsulating this action. TODO: Move TURNS_PER_TRIBUTE magic number to the spec.

scoutIndianSettlement

public org.w3c.dom.Element scoutIndianSettlement(ServerPlayer serverPlayer,
                                                 Unit unit,
                                                 IndianSettlement settlement)
Scout a native settlement.

Parameters:
serverPlayer - The ServerPlayer that is scouting.
unit - The scout Unit.
settlement - The IndianSettlement to scout.
Returns:
An Element encapsulating this action.

denounceMission

public org.w3c.dom.Element denounceMission(ServerPlayer serverPlayer,
                                           Unit unit,
                                           IndianSettlement settlement)
Denounce an existing mission.

Parameters:
serverPlayer - The ServerPlayer that is denouncing.
unit - The Unit denouncing.
settlement - The IndianSettlement containing the mission to denounce.
Returns:
An Element encapsulating this action.

establishMission

public org.w3c.dom.Element establishMission(ServerPlayer serverPlayer,
                                            Unit unit,
                                            IndianSettlement settlement)
Establish a new mission.

Parameters:
serverPlayer - The ServerPlayer that is establishing.
unit - The missionary Unit.
settlement - The IndianSettlement to establish at.
Returns:
An Element encapsulating this action.

incite

public org.w3c.dom.Element incite(ServerPlayer serverPlayer,
                                  Unit unit,
                                  IndianSettlement settlement,
                                  Player enemy,
                                  int gold)
Incite a settlement against an enemy.

Parameters:
serverPlayer - The ServerPlayer that is inciting.
unit - The missionary Unit inciting.
settlement - The IndianSettlement to incite.
enemy - The Player to be incited against.
gold - The amount of gold in the bribe.
Returns:
An Element encapsulating this action.

setDestination

public org.w3c.dom.Element setDestination(ServerPlayer serverPlayer,
                                          Unit unit,
                                          Location destination)
Set a unit destination.

Parameters:
serverPlayer - The ServerPlayer that owns the unit.
unit - The Unit to set the destination for.
destination - The Location to set as destination.
Returns:
An Element encapsulating this action.

updateCurrentStop

public org.w3c.dom.Element updateCurrentStop(ServerPlayer serverPlayer,
                                             Unit unit)
Set current stop of a unit to the next valid stop if any.

Parameters:
serverPlayer - The ServerPlayer the unit belongs to.
unit - The Unit to update.
Returns:
An Element encapsulating this action.

buyFromSettlement

public org.w3c.dom.Element buyFromSettlement(ServerPlayer serverPlayer,
                                             Unit unit,
                                             IndianSettlement settlement,
                                             Goods goods,
                                             int amount)
Buy from a settlement.

Parameters:
serverPlayer - The ServerPlayer that is buying.
unit - The Unit that will carry the goods.
settlement - The IndianSettlement to buy from.
goods - The Goods to buy.
amount - How much gold to pay.
Returns:
An Element encapsulating this action.

sellToSettlement

public org.w3c.dom.Element sellToSettlement(ServerPlayer serverPlayer,
                                            Unit unit,
                                            IndianSettlement settlement,
                                            Goods goods,
                                            int amount)
Sell to a settlement.

Parameters:
serverPlayer - The ServerPlayer that is selling.
unit - The Unit carrying the goods.
settlement - The IndianSettlement to sell to.
goods - The Goods to sell.
amount - How much gold to expect.
Returns:
An Element encapsulating this action.

deliverGiftToSettlement

public org.w3c.dom.Element deliverGiftToSettlement(ServerPlayer serverPlayer,
                                                   Unit unit,
                                                   Settlement settlement,
                                                   Goods goods)
Deliver gift to settlement. Note that this includes both European and native gifts.

Parameters:
serverPlayer - The ServerPlayer that is delivering.
unit - The Unit that is delivering.
goods - The Goods to deliver.
Returns:
An Element encapsulating this action.

loadCargo

public org.w3c.dom.Element loadCargo(ServerPlayer serverPlayer,
                                     Unit unit,
                                     Goods goods)
Load cargo.

Parameters:
serverPlayer - The ServerPlayer that is loading.
unit - The Unit to load.
goods - The Goods to load.
Returns:
An Element encapsulating this action.

unloadCargo

public org.w3c.dom.Element unloadCargo(ServerPlayer serverPlayer,
                                       Unit unit,
                                       Goods goods)
Unload cargo.

Parameters:
serverPlayer - The ServerPlayer that is unloading.
unit - The Unit to unload.
goods - The Goods to unload.
Returns:
An Element encapsulating this action.

clearSpeciality

public org.w3c.dom.Element clearSpeciality(ServerPlayer serverPlayer,
                                           Unit unit)
Clear the specialty of a unit.

Parameters:
serverPlayer - The owner of the unit.
unit - The Unit to clear the speciality of.
Returns:
An Element encapsulating this action.

disbandUnit

public org.w3c.dom.Element disbandUnit(ServerPlayer serverPlayer,
                                       Unit unit)
Disband a unit.

Parameters:
serverPlayer - The owner of the unit.
unit - The Unit to disband.
Returns:
An Element encapsulating this action.

buildSettlement

public org.w3c.dom.Element buildSettlement(ServerPlayer serverPlayer,
                                           Unit unit,
                                           java.lang.String name)
Build a settlement.

Parameters:
serverPlayer - The ServerPlayer that is building.
unit - The Unit that is building.
name - The new settlement name.
Returns:
An Element encapsulating this action.

joinColony

public org.w3c.dom.Element joinColony(ServerPlayer serverPlayer,
                                      Unit unit,
                                      Colony colony)
Join a colony.

Parameters:
serverPlayer - The ServerPlayer that owns the unit.
unit - The Unit that is joining.
colony - The Colony to join.
Returns:
An Element encapsulating this action.

abandonSettlement

public org.w3c.dom.Element abandonSettlement(ServerPlayer serverPlayer,
                                             Settlement settlement)
Abandon a settlement.

Parameters:
serverPlayer - The ServerPlayer that is abandoning.
settlement - The Settlement to abandon.
Returns:
An Element encapsulating this action.

claimLand

public org.w3c.dom.Element claimLand(ServerPlayer serverPlayer,
                                     Tile tile,
                                     Settlement settlement,
                                     int price)
Claim land.

Parameters:
serverPlayer - The ServerPlayer claiming.
tile - The Tile to claim.
settlement - The Settlement to claim for.
price - The price to pay for the land, which must agree with the owner valuation, unless negative which denotes stealing.
Returns:
An Element encapsulating this action.

csAcceptTrade

private void csAcceptTrade(Unit unit,
                           Settlement settlement,
                           DiplomaticTrade agreement,
                           ChangeSet cs)
Accept a diplomatic trade. Handles the transfers of TradeItems.

Parameters:
unit - The Unit that is trading.
settlement - The Settlement to trade with.
agreement - The DiplomacyTrade agreement.
cs - A ChangeSet to update.

diplomaticTrade

public org.w3c.dom.Element diplomaticTrade(ServerPlayer serverPlayer,
                                           Unit unit,
                                           Settlement settlement,
                                           DiplomaticTrade agreement)
Diplomatic trades. Note that when an agreement is accepted we always process the agreement that was sent, not what was returned, cutting off a possibility for cheating.

Parameters:
serverPlayer - The ServerPlayer that is trading.
unit - The Unit that is trading.
settlement - The Settlement to trade with.
agreement - The DiplomaticTrade to consider.
Returns:
An Element encapsulating this action.

spySettlement

public org.w3c.dom.Element spySettlement(ServerPlayer serverPlayer,
                                         Unit unit,
                                         Settlement settlement)
Spy on a settlement.

Parameters:
serverPlayer - The ServerPlayer that is spying.
unit - The Unit that is spying.
settlement - The Settlement to spy on.
Returns:
An Element encapsulating this action.

work

public org.w3c.dom.Element work(ServerPlayer serverPlayer,
                                Unit unit,
                                WorkLocation workLocation)
Change work location.

Parameters:
serverPlayer - The ServerPlayer that owns the unit.
unit - The Unit to change the work location of.
workLocation - The WorkLocation to change to.
Returns:
An Element encapsulating this action.

lootCargo

public org.w3c.dom.Element lootCargo(ServerPlayer serverPlayer,
                                     Unit winner,
                                     java.lang.String loserId,
                                     java.util.List<Goods> loot)
Loot cargo. Note loser is passed by id, as by the time we get here the unit may have been sunk.

Parameters:
serverPlayer - The ServerPlayer that owns the winner.
winner - The Unit that looting.
loserId - The id of the Unit that is looted.
loot - The Goods to loot.
Returns:
An Element encapsulating this action.

payArrears

public org.w3c.dom.Element payArrears(ServerPlayer serverPlayer,
                                      GoodsType type)
Pay arrears.

Parameters:
serverPlayer - The ServerPlayer that owns the unit.
type - The GoodsType to pay the arrears for.
Returns:
An Element encapsulating this action.

equipUnit

public org.w3c.dom.Element equipUnit(ServerPlayer serverPlayer,
                                     Unit unit,
                                     EquipmentType type,
                                     int amount)
Equip a unit. Currently the unit is either in Europe or in a settlement. Might one day allow the unit to be on a tile co-located with an equipment-bearing wagon.

Parameters:
serverPlayer - The ServerPlayer that owns the unit.
unit - The Unit to equip.
type - The EquipmentType to equip with.
amount - The change in the amount of equipment.
Returns:
An Element encapsulating this action.

payForBuilding

public org.w3c.dom.Element payForBuilding(ServerPlayer serverPlayer,
                                          Colony colony)
Pay for a building.

Parameters:
serverPlayer - The ServerPlayer that owns the colony.
colony - The Colony that is building.
Returns:
An Element encapsulating this action.

indianDemand

public org.w3c.dom.Element indianDemand(ServerPlayer serverPlayer,
                                        Unit unit,
                                        Colony colony,
                                        Goods goods,
                                        int gold)
Indians making demands of a colony.

Parameters:
serverPlayer - The ServerPlayer that is demanding.
unit - The Unit making the demands.
colony - The Colony that is demanded of.
goods - The Goods being demanded.
gold - The amount of gold being demanded.
Returns:
An Element encapsulating this action.

trainUnitInEurope

public org.w3c.dom.Element trainUnitInEurope(ServerPlayer serverPlayer,
                                             UnitType type)
Train a unit in Europe.

Parameters:
serverPlayer - The ServerPlayer that is demanding.
type - The UnitType to train.
Returns:
An Element encapsulating this action.

setBuildQueue

public org.w3c.dom.Element setBuildQueue(ServerPlayer serverPlayer,
                                         Colony colony,
                                         java.util.List<BuildableType> queue)
Set build queue.

Parameters:
serverPlayer - The ServerPlayer that owns the colony.
colony - The Colony to set the queue of.
queue - The new build queue.
Returns:
An Element encapsulating this action.

setGoodsLevels

public org.w3c.dom.Element setGoodsLevels(ServerPlayer serverPlayer,
                                          Colony colony,
                                          ExportData exportData)
Set goods levels.

Parameters:
serverPlayer - The ServerPlayer that owns the colony.
colony - The Colony to set the goods levels in.
exportData - The new ExportData.
Returns:
An Element encapsulating this action.

putOutsideColony

public org.w3c.dom.Element putOutsideColony(ServerPlayer serverPlayer,
                                            Unit unit)
Put outside colony.

Parameters:
serverPlayer - The ServerPlayer that owns the unit.
unit - The Unit to be put out.
Returns:
An Element encapsulating this action.

changeWorkType

public org.w3c.dom.Element changeWorkType(ServerPlayer serverPlayer,
                                          Unit unit,
                                          GoodsType type)
Change work type.

Parameters:
serverPlayer - The ServerPlayer that owns the unit.
unit - The Unit to change the work type of.
type - The new GoodsType to produce.
Returns:
An Element encapsulating this action.

changeWorkImprovementType

public org.w3c.dom.Element changeWorkImprovementType(ServerPlayer serverPlayer,
                                                     Unit unit,
                                                     TileImprovementType type)
Change improvement work type.

Parameters:
serverPlayer - The ServerPlayer that owns the unit.
unit - The Unit to change the work type of.
type - The new TileImprovementType to produce.
Returns:
An Element encapsulating this action.

changeState

public org.w3c.dom.Element changeState(ServerPlayer serverPlayer,
                                       Unit unit,
                                       Unit.UnitState state)
Change a units state.

Parameters:
serverPlayer - The ServerPlayer that owns the unit.
unit - The Unit to change the state of.
state - The new UnitState.
Returns:
An Element encapsulating this action.

assignTeacher

public org.w3c.dom.Element assignTeacher(ServerPlayer serverPlayer,
                                         Unit student,
                                         Unit teacher)
Assign a student to a teacher.

Parameters:
serverPlayer - The ServerPlayer that owns the unit.
student - The student Unit.
teacher - The teacher Unit.
Returns:
An Element encapsulating this action.

assignTradeRoute

public org.w3c.dom.Element assignTradeRoute(ServerPlayer serverPlayer,
                                            Unit unit,
                                            TradeRoute tradeRoute)
Assign a trade route to a unit.

Parameters:
serverPlayer - The ServerPlayer that owns the unit.
unit - The unit Unit to assign to.
tradeRoute - The TradeRoute to assign.
Returns:
An Element encapsulating this action.

setTradeRoutes

public org.w3c.dom.Element setTradeRoutes(ServerPlayer serverPlayer,
                                          java.util.List<TradeRoute> routes)
Set trade routes for a player.

Parameters:
serverPlayer - The ServerPlayer to set trade routes for.
routes - The new list of TradeRoutes.
Returns:
An Element encapsulating this action.

getNewTradeRoute

public org.w3c.dom.Element getNewTradeRoute(ServerPlayer serverPlayer)
Get a new trade route for a player.

Parameters:
serverPlayer - The ServerPlayer to get a trade route for.
Returns:
An Element encapsulating this action.

getREFUnits

public org.w3c.dom.Element getREFUnits(ServerPlayer serverPlayer)
Get a list of abstract REF units for a player.

Parameters:
serverPlayer - The ServerPlayer to query the REF of.
Returns:
An Element encapsulating this action.

getHighScores

public org.w3c.dom.Element getHighScores(ServerPlayer serverPlayer)
Gets the list of high scores.

Parameters:
serverPlayer - The ServerPlayer that is querying.
Returns:
An Element encapsulating this action.

chat

public org.w3c.dom.Element chat(ServerPlayer serverPlayer,
                                java.lang.String message,
                                boolean pri)
Chat.

Parameters:
serverPlayer - The ServerPlayer that is chatting.
message - The chat message.
pri - A privacy setting, currently a noop.
Returns:
An Element encapsulating this action.

getStatistics

public org.w3c.dom.Element getStatistics(ServerPlayer serverPlayer)
Get the current game statistics.

Returns:
An Element encapsulating this action.

enterRevengeMode

public org.w3c.dom.Element enterRevengeMode(ServerPlayer serverPlayer)
Enters revenge mode against those evil AIs.

Parameters:
serverPlayer - The ServerPlayer entering revenge mode.
Returns:
An Element encapsulating this action.