soc.game
Class SOCVillage

java.lang.Object
  extended by soc.game.SOCPlayingPiece
      extended by soc.game.SOCVillage
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class SOCVillage
extends SOCPlayingPiece

A village playing piece, used on the large sea board (SOCBoardLarge) with some scenarios. Villages are in a game only if scenario option SOCGameOption.K_SC_CLVI is set.

Villages belong to the game board, not to any player, and new villages cannot be built after the game starts. Trying to call village.getPlayer() will throw an exception.

Since:
2.0.00
Author:
Jeremy D Monin <jeremy@nand.net>
See Also:
Serialized Form

Field Summary
 int diceNum
          Village's dice number, for giving cloth to players who've established a trade route to here.
private  int numCloth
          How many cloth does this village have?
private static long serialVersionUID
           
static int STARTING_CLOTH
          Default starting amount of cloth for a village (5).
static int STARTING_GENERAL_CLOTH
          Default starting amount of cloth for the board general supply (10).
private  java.util.List<SOCPlayer> traders
          Players who have established trade with this village.
 
Fields inherited from class soc.game.SOCPlayingPiece
board, CITY, coord, FORTRESS, MAXPLUSONE, MIN, pieceType, player, ROAD, SETTLEMENT, SHIP, specialVP, specialVPEvent, VILLAGE
 
Constructor Summary
SOCVillage(int node, int dice, int cloth, SOCBoard board)
          Make a new village, which has a certain amount of cloth.
SOCVillage(int node, SOCBoard board)
           
 
Method Summary
 boolean addTradingPlayer(SOCPlayer pl)
          Add this player to the list of trading players.
 int[] distributeCloth(SOCGame game)
          Game action: Distribute cloth to players from this village and (if needed) from the board general supply.
 int getCloth()
          Get how many cloth this village currently has.
 void setCloth(int numCloth)
          Set how many cloth this village currently has.
 int takeCloth(int numTake)
          Take this many cloth, if available, from this village.
 
Methods inherited from class soc.game.SOCPlayingPiece
equals, getAdjacentEdges, getCoordinates, getPlayer, getPlayerNumber, getResourcesToBuild, getType, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

STARTING_GENERAL_CLOTH

public static final int STARTING_GENERAL_CLOTH
Default starting amount of cloth for the board general supply (10).

See Also:
STARTING_CLOTH, Constant Field Values

STARTING_CLOTH

public static final int STARTING_CLOTH
Default starting amount of cloth for a village (5).

See Also:
STARTING_GENERAL_CLOTH, Constant Field Values

diceNum

public final int diceNum
Village's dice number, for giving cloth to players who've established a trade route to here. To simplify cloth distribution when remaining cloth is low, no other village should share the same dice number.


numCloth

private int numCloth
How many cloth does this village have?


traders

private java.util.List<SOCPlayer> traders
Players who have established trade with this village.

Constructor Detail

SOCVillage

public SOCVillage(int node,
                  SOCBoard board)
           throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

SOCVillage

public SOCVillage(int node,
                  int dice,
                  int cloth,
                  SOCBoard board)
           throws java.lang.IllegalArgumentException
Make a new village, which has a certain amount of cloth.

Parameters:
node - node coordinate of village
dice - dice number for giving cloth to players. To simplify cloth distribution when remaining cloth is low, no other village should share the same dice number.
cloth - number of pieces of cloth, such as STARTING_CLOTH
board - board
Throws:
java.lang.IllegalArgumentException - if board null
Method Detail

getCloth

public int getCloth()
Get how many cloth this village currently has.

See Also:
takeCloth(int)

setCloth

public void setCloth(int numCloth)
Set how many cloth this village currently has. For use at client based on messages from server.

Parameters:
numCloth - Number of cloth

takeCloth

public int takeCloth(int numTake)
Take this many cloth, if available, from this village. Cloth should be given to players, and is worth 1 VP for every 2 cloth they have.

Parameters:
numTake - Number of cloth to try and take
Returns:
Number of cloth actually taken, a number from 0 to numTake. If > 0 but < numTake, the rest should be taken from the board's "general supply" of cloth.
See Also:
getCloth(), SOCBoardLarge.takeCloth(int)

addTradingPlayer

public boolean addTradingPlayer(SOCPlayer pl)
Add this player to the list of trading players. If the village has some getCloth() remaining, gives pl 1 cloth now (at server only).

Parameters:
pl - Player who's just established trade with this village
Returns:
True if pl received 1 cloth

distributeCloth

public int[] distributeCloth(SOCGame game)
Game action: Distribute cloth to players from this village and (if needed) from the board general supply. Each player from addTradingPlayer(SOCPlayer) gets at most 1 cloth. If the village has no cloth remaining, does nothing (returns null). Calls takeCloth(int), SOCBoardLarge.takeCloth(int), SOCPlayer.setCloth(int), etc.

If the village has some cloth, but not enough to distribute to all trading players (including from the general supply), then start with the current player if they're trading with this village. Then, the players with first pick are those who established trade first.

Parameters:
game - Game with this village
Returns:
null, or results as an array: [ Cloth amount taken from general supply, Matching village node coordinate, Cloth amount given to player 0, to player 1, ... to player n ].