soc.game
Class SOCPlayingPiece

java.lang.Object
  extended by soc.game.SOCPlayingPiece
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
SOCCity, SOCFortress, SOCRoad, SOCSettlement, SOCVillage

public abstract class SOCPlayingPiece
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

Playing pieces for Settlers of Catan. For the resources needed to build a piece type, see getResourcesToBuild(int). See also soc.robot.SOCPossiblePiece.

See Also:
Serialized Form

Field Summary
protected  SOCBoard board
          Board, for coordinate-related operations.
static int CITY
          Types of playing pieces: City.
protected  int coord
          Coordinates on the board for this piece.
static int FORTRESS
          Types of playing pieces: Fortress.
static int MAXPLUSONE
          One past the maximum type number of playing piece.
static int MIN
          Minimum type number of playing piece (currently Road).
protected  int pieceType
          The type of this playing piece, within range MIN to (MAXPLUSONE - 1)
protected  SOCPlayer player
          The player who owns this piece, if any.
static int ROAD
          Types of playing pieces: Road.
static int SETTLEMENT
          Types of playing pieces: Settlement.
static int SHIP
          Types of playing pieces: Ship.
(package private)  int specialVP
          Special Victory Points (SVP) awarded for placing this piece, if any.
(package private)  SOCScenarioPlayerEvent specialVPEvent
          If specialVP != 0, the event for which the SVP was awarded.
static int VILLAGE
          Types of playing pieces: Village.
 
Constructor Summary
protected SOCPlayingPiece(int ptype, int co, SOCBoard pboard)
          Make a new piece, which belongs to the board and never to players.
protected SOCPlayingPiece(int ptype, SOCPlayer pl, int co, SOCBoard pboard)
          Make a new piece, which is owned by a player.
 
Method Summary
 boolean equals(java.lang.Object other)
          Compare this SOCPlayingPiece to another SOCPlayingPiece, or another object.
 java.util.Vector<java.lang.Integer> getAdjacentEdges()
          Which edges touch this piece's node on the board? Should not be called for roads, because they aren't placed at a node.
 int getCoordinates()
           
 SOCPlayer getPlayer()
          Get the player who owns this piece, if any.
 int getPlayerNumber()
          Get the owner's player number.
static SOCResourceSet getResourcesToBuild(int pieceType)
          the set of resources a player needs to build a playing piece.
 int getType()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ROAD

public static final int ROAD
Types of playing pieces: Road.

See Also:
getResourcesToBuild(int), Constant Field Values

SETTLEMENT

public static final int SETTLEMENT
Types of playing pieces: Settlement.

See Also:
getResourcesToBuild(int), Constant Field Values

CITY

public static final int CITY
Types of playing pieces: City.

See Also:
getResourcesToBuild(int), Constant Field Values

SHIP

public static final int SHIP
Types of playing pieces: Ship. Used only when SOCGame.hasSeaBoard. Requires client and server version 2.0.00 or newer.

Since:
2.0.00
See Also:
getResourcesToBuild(int), Constant Field Values

FORTRESS

public static final int FORTRESS
Types of playing pieces: Fortress. Used only when SOCGame.hasSeaBoard and scenario option _SC_PIRI. Requires client and server version 2.0.00 or newer. New fortresses cannot be built after the game starts.

Since:
2.0.00
See Also:
Constant Field Values

VILLAGE

public static final int VILLAGE
Types of playing pieces: Village. Used only when SOCGame.hasSeaBoard. Requires client and server version 2.0.00 or newer. Villages belong to the game board, not to any player, and new villages cannot be built after the game starts.

Since:
2.0.00
See Also:
Constant Field Values

MIN

public static final int MIN
Minimum type number of playing piece (currently Road).

See Also:
Constant Field Values

MAXPLUSONE

public static final int MAXPLUSONE
One past the maximum type number of playing piece. MAXPLUSONE == 3 up through all 1.1.xx versions. MAXPLUSONE == 6 in v2.0.00.

See Also:
Constant Field Values

pieceType

protected int pieceType
The type of this playing piece, within range MIN to (MAXPLUSONE - 1)


player

protected SOCPlayer player
The player who owns this piece, if any. Will be null for certain piece types such as SOCVillage which belong to the board and not to players. Player is from same game as board.


coord

protected int coord
Coordinates on the board for this piece. An edge or a node, depending on piece type.


board

protected SOCBoard board
Board, for coordinate-related operations. Should be from same game as player.

Since:
1.1.08

specialVP

int specialVP
Special Victory Points (SVP) awarded for placing this piece, if any. Used with the large sea board game scenarios. When specialVP != 0, the source is specialVPEvent.

Note: This is set when the piece was placed, so it's always accurate at server. At client it may be 0 if the client joined the game after this piece was placed.

Package access for SOCPlayer's benefit.

Since:
2.0.00

specialVPEvent

SOCScenarioPlayerEvent specialVPEvent
If specialVP != 0, the event for which the SVP was awarded. Otherwise null.

Note: This is set when the piece was placed, so it's always accurate at server. At client it may be null if the client joined the game after this piece was placed.

Package access for SOCPlayer's benefit.

Since:
2.0.00
Constructor Detail

SOCPlayingPiece

protected SOCPlayingPiece(int ptype,
                          SOCPlayer pl,
                          int co,
                          SOCBoard pboard)
                   throws java.lang.IllegalArgumentException
Make a new piece, which is owned by a player.

Parameters:
ptype - the type of piece, such as SETTLEMENT
pl - player who owns the piece
co - coordinates
pboard - board if known; otherwise will extract from pl. Board should be from same game as pl.
Throws:
java.lang.IllegalArgumentException - if pl null, or board null and pl.board also null
Since:
1.1.08
See Also:
SOCPlayingPiece(int, int, SOCBoard)

SOCPlayingPiece

protected SOCPlayingPiece(int ptype,
                          int co,
                          SOCBoard pboard)
                   throws java.lang.IllegalArgumentException
Make a new piece, which belongs to the board and never to players.

Throws:
java.lang.IllegalArgumentException - if board null
Since:
2.0.00
See Also:
SOCPlayingPiece(int, SOCPlayer, int, SOCBoard)
Method Detail

getAdjacentEdges

public java.util.Vector<java.lang.Integer> getAdjacentEdges()
Which edges touch this piece's node on the board? Should not be called for roads, because they aren't placed at a node.

Returns:
edges touching this piece, same format as SOCBoard.getAdjacentEdgesToNode(int)

getType

public int getType()
Returns:
the type of piece, such as ROAD

getPlayer

public SOCPlayer getPlayer()
                    throws java.lang.UnsupportedOperationException
Get the player who owns this piece, if any. Certain piece types such as SOCVillage belong to the board and not to players.

Returns:
the owner of the piece
Throws:
java.lang.UnsupportedOperationException - if this piece type has no player and is owned by the board
See Also:
getPlayerNumber()

getPlayerNumber

public int getPlayerNumber()
                    throws java.lang.UnsupportedOperationException
Get the owner's player number.

Returns:
getPlayer().getPlayerNumber()
Throws:
java.lang.UnsupportedOperationException - if this piece type has no player and is owned by the board
Since:
2.0.00

getCoordinates

public int getCoordinates()
Returns:
the node or edge coordinate for this piece

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
a human readable form of this object

equals

public boolean equals(java.lang.Object other)
Compare this SOCPlayingPiece to another SOCPlayingPiece, or another object. Comparison method:

Overrides:
equals in class java.lang.Object
Parameters:
other - The object to compare with, or null.

getResourcesToBuild

public static SOCResourceSet getResourcesToBuild(int pieceType)
                                          throws java.lang.IllegalArgumentException
the set of resources a player needs to build a playing piece.

Parameters:
pieceType - The type of this playing piece, in range MIN to (MAXPLUSONE - 1). ROAD, CITY, etc. For convenience, can also pass -2 or MAXPLUSONE for SOCGame.CARD_SET.
Returns:
the set, such as SOCGame.SETTLEMENT_SET
Throws:
java.lang.IllegalArgumentException - if pieceType is out of range, or can never be built by players
Since:
1.1.08