|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object soc.game.SOCPlayer
public class SOCPlayer
A class for holding and manipulating player data. The player exists within one SOCGame, not persistent between games like SOCPlayerClient or SOCClientData.
At the start of each player's turn, SOCGame.updateAtTurn()
will call updateAtTurn()
,
then call the current player's updateAtOurTurn()
.
The player's hand holds resource cards, unplayed building pieces, and an inventory of development cards and sometimes scenario-specific items.
For more information about the "legal" and "potential" road/settlement/city terms,
see page 61 of Robert S Thomas' dissertation. Briefly:
"Legal" locations are where pieces can be placed, according to the game rules.
"Potential" locations are where pieces can be placed soon, based on the
current state of the game board. For example, every legal settlement location is
also a potential settlement during initial placement (game state START1A
through START3A
. Once the player's final initial settlement is placed,
all potential settlement locations are cleared. Only when they build 2 connected road
segments, will another potential settlement location be set.
If the board layout changes from game to game, as with SOCBoardLarge
/
SOCBoard.BOARD_ENCODING_LARGE
, use these methods to update the player's board data
after SOCBoard.makeNewBoard(Map)
, in this order:
getPlayerNumber()
.setLandHexCoordinates(int[])
setPotentialAndLegalSettlements(Collection, boolean, HashSet[])
setRestrictedLegalShips(int[])
On the large sea board
, our list of the player's roads also
contains their ships. They are otherwise treated separately.
Nested Class Summary | |
---|---|
static class |
SOCPlayer.SpecialVPInfo
Holds details of getSpecialVP() . |
Field Summary | |
---|---|
private int |
addedLegalSettlement
The most recently added node from addLegalSettlement(int, boolean) , or 0. |
private boolean |
askedSpecialBuild
In 6-player mode, is the player asking to build during the Special Building Phase? |
private boolean |
boardResetAskedThisTurn
this is true if the player asked to reset the board this turn |
private int |
buildingVP
the number of victory points for settlements and cities |
private boolean |
builtInRobotFlag
Is this robot connection the built-in robot (not a 3rd-party), with the original AI? |
private java.util.Vector<SOCCity> |
cities
a list of this player's cities in play |
private SOCTradeOffer |
currentOffer
this is the current trade offer that this player is making, or null if none |
private int |
faceId
which face image this player is using |
private int |
finalTotalVP
the final total score (pushed from server at end of game), or 0 if no score has been forced. |
private SOCFortress |
fortress
For scenario option _SC_PIRI ,
the "pirate fortress" that this player must defeat to win. |
private SOCGame |
game
the game that this player is in |
private boolean |
hasSpecialBuiltThisTurn
In 6-player mode, has the player already built during the Special Building Phase? |
private SOCInventory |
inventory
The development card s this player holds,
along with occasional scenario-specific items. |
private SOCVillage |
isTradeRouteFarEndClosed_foundVillage
Set by isTradeRouteFarEndClosed(SOCShip, int, HashSet, List)
if it finds a village at any far end. |
(package private) SOCResourceSet |
lastActionBankTrade_get
For use at server by SOCGame, if the player's previous action this turn was a bank trade, the resources involved. |
(package private) SOCResourceSet |
lastActionBankTrade_give
For use at server by SOCGame, if the player's previous action this turn was a bank trade, the resources involved. |
protected int |
lastRoadCoord
The edge coordinate of our most recent road or ship. |
protected int |
lastSettlementCoord
The node coordinate of our most recent settlement. |
private java.util.HashSet<java.lang.Integer> |
legalRoads
a list of edges where it is legal to place a road. |
private java.util.HashSet<java.lang.Integer> |
legalSettlements
a set of nodes where it is legal to place a settlement. |
private java.util.HashSet<java.lang.Integer> |
legalShips
a list of edges where it is legal to place a ship. |
private java.util.HashSet<java.lang.Integer> |
legalShipsRestricted
A list of edges if the legal sea edges for ships are restricted by the game's scenario ( _SC_PIRI ),
or null if all sea edges are legal for ships. |
private int |
longestRoadLength
length of the longest road for this player |
private java.util.Vector<SOCLRPathData> |
lrPaths
list of longest road / longest trade-route paths |
private java.lang.String |
name
the name of the player |
private boolean |
needToDiscard
this flag is true if the player needs to discard and must pick which resources to lose. |
private int |
needToPickGoldHexResources
If nonzero, waiting for player to pick this many gold-hex resources, after a dice roll or placing their final initial settlement. |
private int |
numCloth
For some game scenarios, how many cloth does this player have? Every 2 pieces of cloth is worth 1 VP. |
private int |
numKnights
how many knights this player has in play |
private int[] |
numPieces
the number of pieces not in play. |
private int |
numWarships
For scenario option _SC_PIRI ,
the number of SOCShip s that are converted to warships. |
private SOCPlayerNumbers |
ourNumbers
the numbers that our settlements are touching |
private java.util.Vector<SOCPlayingPiece> |
pieces
a list of this player's pieces in play (does not include any fortress ). |
private boolean |
playedDevCard
this is true if the player played a development card this turn |
private int |
playerNumber
The integer id for this player (0 to n-1). |
private boolean[] |
ports
a boolean array stating wheather this player is touching a particular kind of port. |
private java.util.HashSet<java.lang.Integer> |
potentialCities
a set of nodes where a city could be placed on the next turn. |
private java.util.HashSet<java.lang.Integer> |
potentialRoads
a set of edges where a road could be placed on the next turn. |
private java.util.HashSet<java.lang.Integer> |
potentialSettlements
a set of nodes where a settlement could be placed on the next turn. |
private java.util.HashSet<java.lang.Integer> |
potentialShips
a set of edges where a ship could be placed on the next turn. |
private SOCResourceSet |
resources
how many of each resource this player has |
private int[] |
resourceStats
server-only total count of how many of each known resource the player has received this game from dice rolls. |
private java.util.Hashtable<java.lang.Integer,int[]> |
roadNodeGraph
A graph of what adjacent nodes are connected by this player's roads and ships. |
private java.util.Vector<java.lang.Integer> |
roadNodes
all of the nodes that this player's roads and ships touch; this is used to calculate longest road / longest trade route. |
private java.util.Vector<SOCRoad> |
roads
a list of this player's roads and ships in play. |
private boolean |
robotFlag
this is true if this player is a robot |
private SOCResourceSet |
rolledResources
Resources gained from dice roll of the current turn. |
private int |
scenario_playerEvents_bitmask
Track one-time player events for scenarios on the large sea board . |
private int |
scenario_svpFromEachLandArea_bitmask
For some scenarios on the large sea board ,
bitmask: true if the player has been given a Special Victory Point for placing
a settlement in a given new land area. |
private java.util.Vector<SOCSettlement> |
settlements
a list of this player's settlements in play |
static int |
SHIP_COUNT
Number of ships a player can build (15) if SOCGame.hasSeaBoard . |
private int |
specialVP
The number of Special Victory Points (SVPs), which are awarded in certain game scenarios on the large sea board. |
private java.util.HashMap<java.lang.String,java.util.ArrayList<SOCSpecialItem>> |
spItems
Player's SOCSpecialItem s, if any, by type. |
private int |
startingLandArea1
The land area(s) of the player's initial settlements, if SOCGame.hasSeaBoard and the board defines Land Areas
(null != SOCBoardLarge.getLandAreasLegalNodes() ). |
private int |
startingLandArea2
The land area(s) of the player's initial settlements, if SOCGame.hasSeaBoard and the board defines Land Areas
(null != SOCBoardLarge.getLandAreasLegalNodes() ). |
private java.util.ArrayList<SOCPlayer.SpecialVPInfo> |
svpInfo
The details behind the total SVP count in specialVP , or null if none. |
Fields inherited from interface soc.game.SOCDevCardConstants |
---|
CAP, DESTROY, DISC, KNIGHT, KNIGHT_FOR_VERS_1_X, LIB, MAXPLUSONE, MIN, MIN_KNOWN, MONO, ROADS, SWAP, TEMP, TOW, UNIV, UNKNOWN, UNKNOWN_FOR_VERS_1_X, VERSION_FOR_NEW_TYPES |
Constructor Summary | |
---|---|
SOCPlayer(int pn,
SOCGame ga)
Create a new player for a new empty board. |
|
SOCPlayer(SOCPlayer player)
create a copy of the player |
Method Summary | |
---|---|
void |
addLegalSettlement(int node,
boolean checkAdjacents)
Add this node to the player's legal settlement coordinates, for future possible placement. |
void |
addRolledResources(SOCResourceSet rolled)
Add to this player's resources and resource-roll totals. |
void |
addSpecialVPInfo(int svp,
java.lang.String desc)
Add details on Special Victory Points (SVP) just awarded. |
int |
calcLongestRoad2()
Calculates the longest road / longest trade route for this player |
boolean |
canBuildInitialPieceType(int pieceType)
Can this player build this piece type now, based on their pieces so far? Initial placement order is Settlement, Road/Ship, Settlement, Road/Ship. |
boolean |
canMoveShip(SOCShip sh)
Can we move this ship, based on our trade routes and settlements/cities near its current location? |
boolean |
canPlaceSettlement(int node)
Can a settlement be placed at this node? Calls isPotentialSettlement(int) . |
private java.util.Vector<SOCShip> |
checkTradeRouteFarEndClosed(SOCShip newShipEdge,
int edgeFarNode)
Follow a trade route (a line of SOCShip s) away from a newly closed end, to
determine if the other end is closed or still open, and close this route if
necessary. |
void |
clearPotentialCity(int node)
Set this node to not be a potential city. |
void |
clearPotentialRoad(int edge)
Set this edge to not be a potential road. |
void |
clearPotentialSettlement(int node)
Set this node to not be a potential settlement. |
void |
clearPotentialSettlements()
At start of normal game play, set all nodes to not be potential settlements. |
void |
clearPotentialShip(int edge)
Set this edge to not be a potential ship. |
private void |
clearScenarioPlayerEvent(SOCScenarioPlayerEvent spe)
Clear a certain scenario player event flag. |
void |
destroyPlayer()
set vars to null so gc can clean up |
private boolean |
doesTradeRouteContinuePastEdge(int edge,
boolean wantShip)
For road/ship building, does this edge have a piece of ours adjacent to it (settlement, city, or same road/ship type as wantShip )? |
private boolean |
doesTradeRouteContinuePastNode(SOCBoard board,
boolean wantShip,
int rsEdge,
int ignoreEdge,
int node)
Does this trade route (ships only, or roads only) continue past an unoccupied node? |
void |
forceFinalVP(int score)
If game is over, server can push the final score for each player to the client. |
int |
getAddedLegalSettlement()
Get the legal-settlement location, if any, added by addLegalSettlement(int, boolean) . |
java.util.Vector<SOCCity> |
getCities()
|
int |
getCloth()
For some game scenarios, get how many cloth this player currently has. |
SOCTradeOffer |
getCurrentOffer()
|
int |
getFaceId()
get the face image id. |
SOCFortress |
getFortress()
For scenario option _SC_PIRI ,
the "pirate fortress" that this player must defeat to win. |
SOCGame |
getGame()
|
SOCInventory |
getInventory()
Get the player's inventory of SOCDevCard s and other occasional items. |
int |
getLastRoadCoord()
Get the location of this player's most recent road or ship. |
int |
getLastSettlementCoord()
Get the location of this player's most recent settlement. |
int |
getLongestRoadLength()
Get the length of this player's longest road or trade route, as calculated by the most recent call to calcLongestRoad2() . |
java.util.Vector<SOCLRPathData> |
getLRPaths()
Get our longest road paths. |
SOCShip |
getMostRecentShip()
Get this player's most recently placed ship, if any. |
java.lang.String |
getName()
|
boolean |
getNeedToDiscard()
|
int |
getNeedToPickGoldHexResources()
Get the number of gold-hex resources this player must now pick, after a dice roll or placing their 2nd initial settlement. |
SOCPlayerNumbers |
getNumbers()
|
int |
getNumKnights()
|
int |
getNumPieces(int ptype)
Get the number of one piece type not in play and available to place. |
int |
getNumWarships()
For scenario option _SC_PIRI ,
the number of SOCShip s that have been converted to warships
to defend against the pirate fleet and attack the SOCFortress . |
java.util.Vector<SOCPlayingPiece> |
getPieces()
Get this player's pieces on the board. |
int |
getPlayerNumber()
Get the player's seat number in the game . |
boolean |
getPortFlag(int portType)
|
boolean[] |
getPortFlags()
|
java.util.List<java.lang.Integer> |
getPortMovePotentialLocations(boolean all)
For scenario option _SC_FTRI ,
calculate if the player has any coastal settlement or city where
they can place a moved "gift" port without it being adjacent to another port,
and the edges where it could be placed next to such settlements or cities. |
int[] |
getPotentialSettlements_arr()
Get this player's current potential settlement nodes. |
java.util.HashSet<java.lang.Integer> |
getPotentialSettlements()
Get this player's current potential settlement nodes. |
int |
getPublicVP()
This player's number of publicly known victory points. |
int[] |
getResourceRollStats()
On server, get the current totals of resources received by dice rolls by this player. |
SOCResourceSet |
getResources()
Get the resources currently held in the player's hand. |
java.util.HashSet<java.lang.Integer> |
getRestrictedLegalShips()
A list of edges where the player can build ships, if the legal sea edges for ships are restricted by the game's scenario ( _SC_PIRI ),
or null if all sea edges are legal for ships. |
java.util.Vector<java.lang.Integer> |
getRoadNodes()
|
SOCRoad |
getRoadOrShip(int edge)
Get this player's road or ship on an edge. |
java.util.Vector<SOCRoad> |
getRoads()
Get this player's roads and ships on the board. |
SOCResourceSet |
getRolledResources()
Resources gained from dice roll of the current turn. |
int |
getScenarioPlayerEvents()
Gets one-time player events for scenarios on the large sea board . |
int |
getScenarioSVPLandAreas()
For scenarios on the large sea board , get
this player's bitmask of land areas for tracking Special Victory Points (SVP). |
java.util.Vector<SOCSettlement> |
getSettlements()
|
SOCSpecialItem |
getSpecialItem(java.lang.String typeKey,
int idx)
Get a special item of a given type, by index within the list of all items of that type held by the player. |
java.util.ArrayList<SOCSpecialItem> |
getSpecialItems(java.lang.String typeKey)
Get a list of all special items of a given type held by the player. |
int |
getSpecialVP()
Get the number of Special Victory Points (SVPs) awarded to this player. |
java.util.ArrayList<SOCPlayer.SpecialVPInfo> |
getSpecialVPInfo()
Get the details, if known, behind this player's getSpecialVP() total. |
int |
getStartingLandAreasEncoded()
For scenarios on the large sea board , get
this player's starting settlement land areas, encoded to send over the network
from server to client. |
int |
getTotalVP()
|
boolean |
hasAskedBoardReset()
|
boolean |
hasAskedSpecialBuild()
In 6-player mode's Special Building Phase, this player has asked to build. |
boolean |
hasLargestArmy()
|
boolean |
hasLongestRoad()
|
boolean |
hasPlayedDevCard()
|
boolean |
hasPotentialCity()
|
boolean |
hasPotentialRoad()
|
boolean |
hasPotentialSettlement()
|
boolean |
hasPotentialShip()
Does this player have a potential edge to place a ship on, in a game using the large sea board? |
boolean |
hasScenarioPlayerEvent(SOCScenarioPlayerEvent spe)
Does this player have a certain scenario player event flag? Flag bits are set as per-player events occur during a game. |
boolean |
hasSpecialBuilt()
In 6-player mode's Special Building Phase, this player has already built this turn. |
boolean |
hasUnplayedDevCards()
|
void |
incrementNumKnights()
increment the number of knights in play |
boolean |
isBuiltInRobot()
Is this robot player the built-in robot (not a 3rd-party), with the original AI? False if unknown. |
boolean |
isConnectedByRoad(int node1,
int node2)
Are these two adjacent nodes connected by this player's road/ship? |
boolean |
isLegalRoad(int edge)
|
boolean |
isLegalSettlement(int node)
Is this node to a legal settlement? |
boolean |
isLegalShip(int edge)
Is this edge a legal ship placement? |
boolean |
isPotentialCity(int node)
Is this node a potential city? True if we currently have a settlement there. |
boolean |
isPotentialRoad(int edge)
Is this edge a potential road? True if the location is legal, currently not occupied, and we have an adjacent road, settlement, or city. |
boolean |
isPotentialSettlement(int node)
Is this node a potential settlement? True if the location is legal, currently not occupied, no settlement is currently on an adjacent node, and we have an adjacent road or ship. |
boolean |
isPotentialShip(int edge)
Is this edge a potential ship? True if the location is legal, currently not occupied, we have an adjacent ship, settlement, or city, and SOCGame.hasSeaBoard ,
Does not check getNumPieces(SHIP) . |
boolean |
isPotentialShipMoveTo(int toEdge,
int fromEdge)
Is this edge coordinate a potential place to move a ship, even if another ship edge was not? Used by SOCGame.canMoveShip(int, int, int)
to check the ship's requested new location. |
boolean |
isRobot()
Is this player a robot AI (built-in or 3rd-party)? |
private java.util.Vector<SOCShip> |
isTradeRouteFarEndClosed(SOCShip edgeFirstShip,
int edgeFarNode,
java.util.HashSet<java.lang.Integer> alreadyVisited,
java.util.List<java.util.Vector<java.lang.Object>> encounteredSelf)
Recursive call for checkTradeRouteFarEndClosed(SOCShip, int) . |
java.lang.StringBuffer |
numpieces(java.lang.StringBuffer sb)
for debug prints; appends to sb or creates it, returns it |
private void |
putPiece_roadOrShip_checkNewShipTradeRouteAndSpecialEdges(SOCShip newShip,
SOCBoardLarge board,
boolean isTempPiece)
Check this new ship for adjacent settlements/cities/villages, to see if its trade route will be closed. |
private void |
putPiece_roadOrShip(SOCRoad piece,
SOCBoard board,
boolean isTempPiece)
For putPiece , update road/ship-related info,
roadNodes , roadNodeGraph and lastRoadCoord . |
private void |
putPiece_settlement_checkScenarioSVPs(SOCSettlement newSettle,
int newSettleArea,
boolean isTempPiece)
Does the player get a Special Victory Point (SVP) for reaching a new land area? Call when a settlement has been placed in a land area different from startingLandArea1 and startingLandArea2 . |
private void |
putPiece_settlement_checkTradeRoutes(SOCSettlement newSettle,
SOCBoard board)
Check this new settlement for adjacent open ships, to see their its trade route will be closed. |
void |
putPiece(SOCPlayingPiece piece,
boolean isTempPiece)
Put a piece into play. |
void |
removePiece(SOCPlayingPiece piece,
SOCPlayingPiece replacementPiece)
remove a player's piece from the board, and put it back in the player's hand. |
private void |
removePieceUpdateSpecialVP(SOCPlayingPiece p)
As part of removePiece(SOCPlayingPiece, null) ,
update player's specialVP and related fields. |
void |
setAskedBoardReset(boolean value)
set the flag indicating if the player asked to reset the board this turn |
void |
setAskedSpecialBuild(boolean set)
In 6-player mode's Special Building Phase, set or clear the flag for this player asking to build. |
void |
setCloth(int numCloth)
Set how many cloth this player currently has. |
void |
setCurrentOffer(SOCTradeOffer of)
set the current offer for this player |
void |
setFaceId(int id)
set the face image id |
void |
setLongestRoadLength(int len)
set the longest road / longest trade route length |
void |
setLRPaths(java.util.Vector<SOCLRPathData> vec)
set the longest paths vector |
void |
setName(java.lang.String na)
set the name of the player |
void |
setNeedToDiscard(boolean value)
set the "need to discard" flag |
void |
setNeedToPickGoldHexResources(int numRes)
Set the number of gold-hex resources this player must now pick, after a dice roll or placing their 2nd initial settlement. |
void |
setNumKnights(int nk)
set the number of knights in play |
void |
setNumPieces(int ptype,
int amt)
set the amount of pieces not in play for a particular type of piece |
void |
setNumWarships(int count)
For scenario option _SC_PIRI ,
set the player's number of warships. |
void |
setPlayedDevCard(boolean value)
set the playedDevCard flag |
void |
setPortFlag(int portType,
boolean value)
set a port flag |
void |
setPotentialAndLegalSettlements(java.util.Collection<java.lang.Integer> psList,
boolean setLegalsToo,
java.util.HashSet<java.lang.Integer>[] legalLandAreaNodes)
Set which nodes are potential settlements. |
void |
setRestrictedLegalShips(int[] edgeList)
Set the list of edges where the player can build ships, when the legal sea edges for ships are restricted by the game's scenario ( _SC_PIRI ). |
void |
setRobotFlag(boolean isRobot,
boolean isBuiltIn)
set the robot flags. |
private void |
setScenarioPlayerEvent(SOCScenarioPlayerEvent spe)
Set a certain scenario player event flag. |
void |
setScenarioPlayerEvents(int events)
At client, set the player's getScenarioPlayerEvents() based on a server message. |
void |
setScenarioSVPLandAreas(int las)
At client, set the player's getScenarioPlayerEvents() based on a server message. |
void |
setSpecialBuilt(boolean set)
In 6-player mode's Special Building Phase, set or clear the flag for this player already built this turn. |
SOCSpecialItem |
setSpecialItem(java.lang.String typeKey,
int idx,
SOCSpecialItem itm)
Add or replace a special item in the player's list of items of that type. |
void |
setSpecialVP(int svp)
Set the number of Special Victory Points (SVPs) awarded to this player. |
void |
setStartingLandAreasEncoded(int slas)
At client, set the player's getStartingLandAreasEncoded() based on a server message. |
java.lang.String |
toString()
|
void |
undoPutPiece(SOCPlayingPiece piece)
undo the putting of a piece. |
protected void |
undoPutPieceAuxSettlement(int settlementNode)
Auxiliary function for undoing settlement placement |
(package private) void |
updateAtOurTurn()
Update game state as needed when this player begins their turn (before dice are rolled). |
(package private) void |
updateAtTurn()
Update player's state as needed when any player begins their turn (before dice are rolled). |
(package private) void |
updateLegalShipsAddHex(int hexCoord)
When a SOCBoardLarge.FOG_HEX is revealed to be water,
or a land hex at the board's margin ,
update the set of edges used by isLegalShip(int) . |
(package private) void |
updatePortFlagsAfterRemove(int portType,
boolean removedPort)
After removing a player's piece at a port, or removing the port, check to see if we still have a port of that type. |
void |
updatePotentials(SOCPlayingPiece piece)
update the arrays that keep track of where this player can play further pieces, after a piece has just been played, or after another player's adjacent piece has been removed. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int SHIP_COUNT
SOCGame.hasSeaBoard
.
getNumPieces(int)
,
Constant Field Valuesprivate java.lang.String name
private int playerNumber
private SOCGame game
private int[] numPieces
SOCPlayingPiece.ROAD
,
SOCPlayingPiece.SETTLEMENT
,
SOCPlayingPiece.CITY
,
SOCPlayingPiece.SHIP
.
private int numWarships
_SC_PIRI
,
the number of SOCShip
s that are converted to warships.
See getNumWarships()
for details.
private java.util.Vector<SOCPlayingPiece> pieces
fortress
).
private java.util.Vector<SOCRoad> roads
numPieces
[] they're counted separately.
getRoadOrShip(int)
private java.util.Vector<SOCSettlement> settlements
private java.util.Vector<SOCCity> cities
private SOCFortress fortress
_SC_PIRI
,
the "pirate fortress" that this player must defeat to win.
The player's warships are used to defeat the fortress; see getNumWarships()
.
Null if fortress has been defeated and converted to a settlement.
Null unless game has that scenario option.
There is no setFortress method; use putPiece. For details see getFortress()
.
private java.util.HashMap<java.lang.String,java.util.ArrayList<SOCSpecialItem>> spItems
SOCSpecialItem
s, if any, by type.
See getter/setter javadocs for details on type keys and
rationale for lack of synchronization.
ArrayList is used to guarantee we can store null items.
protected int lastSettlementCoord
protected int lastRoadCoord
private int longestRoadLength
private java.util.Vector<SOCLRPathData> lrPaths
private SOCResourceSet resources
private SOCResourceSet rolledResources
addRolledResources(SOCResourceSet)
,
cleared in updateAtTurn()
.
SOCResourceSet lastActionBankTrade_give
Ignore unless SOCGame.canUndoBankTrade(SOCResourceSet, SOCResourceSet)
is true.
SOCResourceSet lastActionBankTrade_get
Ignore unless SOCGame.canUndoBankTrade(SOCResourceSet, SOCResourceSet)
is true.
private int[] resourceStats
SOCResourceConstants.CLAY
- SOCResourceConstants.WOOD
,
and also (in v2.0.00+) SOCResourceConstants.GOLD_LOCAL
.
See getResourceRollStats()
for details.
private SOCInventory inventory
development card
s this player holds,
along with occasional scenario-specific items.
private int numKnights
private int buildingVP
private int specialVP
numCloth
, cloth is part of getTotalVP()
.
When updating this value, if the SVP came from a piece, also set or check SOCPlayingPiece.specialVP
and SOCPlayingPiece.specialVPEvent
.
svpInfo
private java.util.ArrayList<SOCPlayer.SpecialVPInfo> svpInfo
specialVP
, or null if none.
This is filled at the server (because it has the text strings) when
SOCGame.scenarioEventListener
!= null, and sent out to clients.
addSpecialVPInfo(int, String)
private int finalTotalVP
forceFinalVP(int)
private int numCloth
specialVP
private boolean needToDiscard
needToPickGoldHexResources
private int needToPickGoldHexResources
When setting this field, also increment resourceStats
[GOLD_LOCAL
].
Game state SOCGame.WAITING_FOR_PICK_GOLD_RESOURCE
or SOCGame.STARTS_WAITING_FOR_PICK_GOLD_RESOURCE
.
needToDiscard
private java.util.Vector<java.lang.Integer> roadNodes
private java.util.Hashtable<java.lang.Integer,int[]> roadNodeGraph
Implementation:
Key = node1's coordinate Integer
.
Value = int[] array of length 3, for the 3 adjacent nodes.
If an element of the array is 0, no connection.
A non-zero element is node2's coordinate
at the other end of the road connecting them.
isConnectedByRoad(int, int)
private java.util.HashSet<java.lang.Integer> legalRoads
If not SOCGame.hasSeaBoard
, initialized in constructor
from SOCBoard.initPlayerLegalRoads()
.
If SOCGame.hasSeaBoard
, empty until SOCBoard.makeNewBoard(Map)
and SOCGame.startGame()
, because the board layout and legal settlements
vary from game to game.
private java.util.HashSet<java.lang.Integer> legalSettlements
Key = node coordinate, as Integer
.
If legalSettlements.contains(new Integer(nodeCoord))
,
then nodeCoord is a legal settlement.
If not SOCGame.hasSeaBoard
, initialized in constructor
from SOCBoard.initPlayerLegalAndPotentialSettlements()
.
If SOCGame.hasSeaBoard
: Empty at server until SOCBoardLarge.makeNewBoard(Map)
and SOCGame.startGame()
, because the board layout and legal settlements vary
from game to game. Empty at client until
setPotentialAndLegalSettlements(Collection, boolean, HashSet[])
is called.
potentialSettlements
,
SOCBoard.nodesOnLand
private int addedLegalSettlement
addLegalSettlement(int, boolean)
, or 0.
private java.util.HashSet<java.lang.Integer> legalShips
If the game doesn't use the large sea board (! SOCGame.hasSeaBoard
),
this set is empty but non-null.
May be updated during game play by updateLegalShipsAddHex(int)
.
legalShipsRestricted
private java.util.HashSet<java.lang.Integer> legalShipsRestricted
_SC_PIRI
),
or null
if all sea edges are legal for ships.
If the player has no legal ship edges, this list is empty (not null).
This list, separate from legalShips
, is necessary because some methods
change legalShips
by removing or adding edges.
private java.util.HashSet<java.lang.Integer> potentialRoads
updatePotentials(SOCPlayingPiece)
.
Elements are set false when a road or ship is placed on their edge.
private java.util.HashSet<java.lang.Integer> potentialSettlements
legalSettlements
are also potential.
When the second settlement is placed, potentialSettlements is cleared,
and then re-set via updatePotentials(SOCRoad)
.
Placing a settlement will clear its node and adjacent nodes.
Key = node coordinate, as Integer
.
If potentialSettlements.contains(new Integer(nodeCoord))
,
then this is a potential settlement.
legalSettlements
,
setPotentialAndLegalSettlements(Collection, boolean, HashSet[])
,
SOCBoard.nodesOnLand
private java.util.HashSet<java.lang.Integer> potentialCities
updatePotentials(SOCPlayingPiece)
.
Elements are set false when cities are placed.
Unlike other piece types, there is no "legalCities" set,
because we use legalSettlements
before placing a settlement,
and settlements can always become cities.
private java.util.HashSet<java.lang.Integer> potentialShips
updatePotentials(SOCPlayingPiece)
.
Elements are set false when a road or ship is placed on their edge.
If the game doesn't use the large sea board (! SOCGame.hasSeaBoard
),
this set is empty but non-null.
private boolean[] ports
SOCBoard.MISC_PORT
to SOCBoard.WOOD_PORT
private SOCTradeOffer currentOffer
private boolean playedDevCard
private boolean boardResetAskedThisTurn
private boolean askedSpecialBuild
hasSpecialBuiltThisTurn
private boolean hasSpecialBuiltThisTurn
askedSpecialBuild
private int scenario_playerEvents_bitmask
large sea board
.
As events occur during a game, each one's SOCScenarioPlayerEvent.flagValue
bit is set here.
Example events: SOCScenarioPlayerEvent.SVP_SETTLED_ANY_NEW_LANDAREA
,
SOCScenarioPlayerEvent.CLOTH_TRADE_ESTABLISHED_VILLAGE
.
Bits are kept here, not in separate boolean fields, to keep them together and send over the network.
Not all player events are here; some can't be represented in a single flag bit,
such as scenario_svpFromEachLandArea_bitmask
.
getScenarioPlayerEvents()
private int scenario_svpFromEachLandArea_bitmask
large sea board
,
bitmask: true if the player has been given a Special Victory Point for placing
a settlement in a given new land area.
The bit value is (1 << (landAreaNumber - 1)).
SOCScenarioPlayerEvent.SVP_SETTLED_EACH_NEW_LANDAREA
,
scenario_playerEvents_bitmask
,
getScenarioSVPLandAreas()
private int startingLandArea1
SOCGame.hasSeaBoard
and the board defines Land Areas
(null != SOCBoardLarge.getLandAreasLegalNodes()
).
Used for Special Victory Points in some scenarios.
0 otherwise.
If both initial settlements are in the same land area,
then startingLandArea2
is 0.
Also: If SOCBoardLarge.getStartingLandArea()
!= 0,
the players must start in that land area. This is enforced
at the server during makeNewBoard, by using that land area
for the only initial potential/legal settlement locations.
private int startingLandArea2
SOCGame.hasSeaBoard
and the board defines Land Areas
(null != SOCBoardLarge.getLandAreasLegalNodes()
).
Used for Special Victory Points in some scenarios.
0 otherwise.
If both initial settlements are in the same land area,
then startingLandArea2
is 0.
Also: If SOCBoardLarge.getStartingLandArea()
!= 0,
the players must start in that land area. This is enforced
at the server during makeNewBoard, by using that land area
for the only initial potential/legal settlement locations.
private boolean robotFlag
private boolean builtInRobotFlag
SOCImARobot
private int faceId
private SOCPlayerNumbers ourNumbers
private SOCVillage isTradeRouteFarEndClosed_foundVillage
isTradeRouteFarEndClosed(SOCShip, int, HashSet, List)
if it finds a village at any far end.
Not set unless SOCGame.hasSeaBoard
and SOCGameOption.K_SC_CLVI
are set.
Constructor Detail |
---|
public SOCPlayer(SOCPlayer player) throws java.lang.IllegalStateException
player
- the player to copy
java.lang.IllegalStateException
- if player's dev cards can't be cloned (internal error); should not possibly occurpublic SOCPlayer(int pn, SOCGame ga)
Unless SOCGame.hasSeaBoard
,
the player's possible placement locations will be
set from SOCBoard.initPlayerLegalRoads()
and
SOCBoard.initPlayerLegalAndPotentialSettlements()
.
Once the game board is set up, be sure to call
setPotentialAndLegalSettlements(Collection, boolean, HashSet[])
to update our data.
pn
- the player numberga
- the game that the player is inMethod Detail |
---|
public void clearPotentialSettlements()
SOCGame.updateAtGameFirstTurn()
in state SOCGame.START2A
or SOCGame.START3A
after final initial settlement placement.
Once they have placed another road, that road's
putPiece(SOCPlayingPiece, boolean)
call will call
updatePotentials(SOCPlayingPiece)
, which
will set potentialSettlements at the road's new end node.
void updateAtTurn()
SOCGame.updateAtTurn()
.
Called for each player, just before calling the current player's updateAtOurTurn()
.
getRolledResources()
void updateAtOurTurn()
SOCGame.updateAtTurn()
.
Called just after calling each player's updateAtTurn()
.
May be called during initial placement.
Is called at the end of initial placement, before the first player's first roll.
On the 6-player board, is called at the start of
the player's Special Building Phase
.
getNeedToPickGoldHexResources()
to 0
game.canUndoBankTrade
public void setName(java.lang.String na) throws java.lang.IllegalArgumentException
na
- the player's new name, or null.
For network message safety, must not contain
control characters, SOCMessage.sep_char
, or SOCMessage.sep2_char
.
This is enforced by calling SOCMessage.isSingleLineAndSafe(String)
.
java.lang.IllegalArgumentException
- if a non-null name fails
SOCMessage.isSingleLineAndSafe(String)
.
This exception was added in 1.1.07.public java.lang.String getName()
public int getPlayerNumber()
game
.
public SOCGame getGame()
public boolean hasPlayedDevCard()
public void setPlayedDevCard(boolean value)
value
- the value of the flagpublic boolean hasAskedBoardReset()
public void setAskedBoardReset(boolean value)
value
- true to set, false to clearpublic boolean hasAskedSpecialBuild()
setAskedSpecialBuild(boolean)
.
hasSpecialBuilt()
public void setAskedSpecialBuild(boolean set)
SOCGame.canAskSpecialBuild(int, boolean)
for that.
To read this flag, use hasAskedSpecialBuild()
.
set
- if the player has asked to buildSOCGame.askSpecialBuild(int, boolean)
public boolean hasSpecialBuilt()
setSpecialBuilt(boolean)
.
hasAskedSpecialBuild()
public void setSpecialBuilt(boolean set)
hasSpecialBuilt()
.
set
- if the player special-built this turnpublic void setNeedToDiscard(boolean value)
value
- the value of the flagpublic boolean getNeedToDiscard()
getNeedToPickGoldHexResources()
public void setNeedToPickGoldHexResources(int numRes)
SOCGame.hasSeaBoard
and player is adjacent
to a SOCBoardLarge.GOLD_HEX
.
Game state SOCGame.WAITING_FOR_PICK_GOLD_RESOURCE
.
Once the player has picked their resources, returns to 0.
numRes
- Number of resources to pick, or 0 for no pickpublic int getNeedToPickGoldHexResources()
SOCGame.hasSeaBoard
and player is adjacent
to a SOCBoardLarge.GOLD_HEX
.
Game state SOCGame.WAITING_FOR_PICK_GOLD_RESOURCE
.
Once the player has picked their resources, returns to 0.
getNeedToDiscard()
public void setRobotFlag(boolean isRobot, boolean isBuiltIn)
isRobot
- Is this player a robot?isBuiltIn
- Is this player the built-in robot type?
Assume false if unknown, such as in SITDOWN message received at other clients.public boolean isRobot()
isBuiltInRobot()
public boolean isBuiltInRobot()
isRobot()
,
SOCImARobot
public void setFaceId(int id)
id
- the image id. 1 is the first human face image; 0 is the robot.public int getFaceId()
public SOCPlayerNumbers getNumbers()
public int getNumPieces(int ptype) throws java.lang.ArrayIndexOutOfBoundsException
SOCPlayingPiece.CITY
) == 4.
On the sea board, each player starts with SHIP_COUNT
ships.
ptype
- the type of piece; matches SOCPlayingPiece constants,
such as SOCPlayingPiece.ROAD
, SOCPlayingPiece.SETTLEMENT
.
java.lang.ArrayIndexOutOfBoundsException
- if piece type is invalidgetPieces()
,
getNumWarships()
public void setNumPieces(int ptype, int amt)
ptype
- the type of piece; matches SOCPlayingPiece constants,
such as SOCPlayingPiece.ROAD
, SOCPlayingPiece.SETTLEMENT
.amt
- the amountsetNumWarships(int)
public int getNumWarships()
_SC_PIRI
,
the number of SOCShip
s that have been converted to warships
to defend against the pirate fleet and attack the SOCFortress
.
SOCShip
has no "isWarship" field; the player's first numWarships
ships within getRoads()
are the warships, because those are the ships
heading out to sea starting at the player's settlement, placed chronologically.
See SOCGame.isShipWarship(SOCShip)
for details.
public void setNumWarships(int count)
_SC_PIRI
,
set the player's number of warships. See getNumWarships()
for details.
count
- New number of warshipspublic java.util.Vector<SOCPlayingPiece> getPieces()
getFortress()
, if any,
because the player doesn't control that piece.
getNumPieces(int)
public java.util.Vector<SOCRoad> getRoads()
getRoadOrShip(int)
,
getMostRecentShip()
public SOCRoad getRoadOrShip(int edge)
edge
- Edge coordinate of the road or ship
getMostRecentShip()
public SOCShip getMostRecentShip()
getRoads()
, or null
if that list contains no SOCShip
sgetRoads()
public java.util.Vector<SOCSettlement> getSettlements()
public java.util.Vector<SOCCity> getCities()
public java.util.ArrayList<SOCSpecialItem> getSpecialItems(java.lang.String typeKey)
Locks: This getter is not synchronized: It's assumed that the structure of Special Item lists is set up at game creation time, and not often changed. If a specific item type or access pattern requires synchronization, do so outside this class and document the details.
typeKey
- Special item type. Typically a SOCGameOption
keyname; see the SOCSpecialItem
class javadoc for details.
null
if none; will never return an empty list.
Some list items may be null
depending on the list structure created by the scenario or expansion.SOCGame.getSpecialItems(String)
,
SOCGame.getSpecialItemTypes()
public SOCSpecialItem getSpecialItem(java.lang.String typeKey, int idx)
Locks: This getter is not synchronized: It's assumed that the structure of Special Item lists is set up at game creation time, and not often changed. If a specific item type or access pattern requires synchronization, do so outside this class and document the details.
typeKey
- Special item type. Typically a SOCGameOption
keyname; see the SOCSpecialItem
class javadoc for details.idx
- Index within the list of special items of that type; must be within the list's current size
null
if none of that type, or if that index is null
within the list
or is beyond the size of the listSOCGame.getSpecialItem(String, int)
,
SOCGame.getSpecialItem(String, int, int, int)
,
SOCSpecialItem.playerPickItem(String, SOCGame, SOCPlayer, int, int)
,
SOCSpecialItem.playerSetItem(String, SOCGame, SOCPlayer, int, int, boolean)
public SOCSpecialItem setSpecialItem(java.lang.String typeKey, int idx, SOCSpecialItem itm) throws java.lang.IndexOutOfBoundsException
typeKey
- Special item type. Typically a SOCGameOption
keyname; see the SOCSpecialItem
class javadoc for details. If no list with this key exists, it will be created here.idx
- Index within the list of special items of that type; if this is past the list's current size,
null
elements will be inserted as needed until idx
is a valid index
If idx
is within the list, the current element at that index will be replaced.itm
- Item object to set within the list
null
if none
java.lang.IndexOutOfBoundsException
- if idx
< 0SOCGame.setSpecialItem(String, int, SOCSpecialItem)
public SOCFortress getFortress()
_SC_PIRI
,
the "pirate fortress" that this player must defeat to win.
Null if fortress has already been defeated and converted to a settlement.
Null unless game has that scenario option.
There is no setFortress method; instead call
game.putPiece(SOCFortress)
to set, or
game.putPiece(SOCSettlement)
to clear.
public int getCloth()
public void setCloth(int numCloth)
getPublicVP()
.
For use at client based on messages from server.
numCloth
- Number of clothpublic boolean canMoveShip(SOCShip sh)
Only the ship at the newer end of an open trade route can be moved.
So, to move a ship, one of its end nodes must be clear of this
player's pieces: No settlement or city, and no other adjacent ship on
the other side of the node. Other players' pieces are ignored.
The ship must be part of an open trade route;
sh.isClosed()
must be false.
Does not check game state, only this player's pieces.
Trade routes can branch, so it may be that more than one ship
could be moved. The game limits players to one move per turn.
That limit isn't checked here.
After the player picks the ship's requested new location,
SOCGame.canMoveShip(int, int, int)
checks that limit,
the other game conditions, and calls this method to check the
player's piece conditions.
Once the player picks the ship's requested new location,
that edge will be checked with isPotentialShipMoveTo(int, int)
.
sh
- One of our shipsprivate final boolean doesTradeRouteContinuePastEdge(int edge, boolean wantShip)
wantShip
)?
edge
- Check adjacents of this edgewantShip
- True to look for ships only, false for roads only
private final boolean doesTradeRouteContinuePastNode(SOCBoard board, boolean wantShip, int rsEdge, int ignoreEdge, int node)
board
- game boardwantShip
- True to look for ships only, false for roads onlyrsEdge
- Edge adjacent to node
with a road/ship on the trade routeignoreEdge
- Edge to ignore our pieces on, or -9; used
during the check before moving one of our ships
to ignore the ship's current position (its fromEdge
).
Not necessarily adjacent to node
or rsEdge
.
In scenario _SC_PIRI
, moving a ship must not create a new
branch in the existing ship route. When not -9 in that scenario,
this method checks that by counting our ships/roads adjacent to node
besides rsEdge
and ignoreEdge
.
node
- Node at one end of rsEdge
,
which does not have a settlement or city;
check this node's other 2 edges for roads/ships
continuing the trade route
node
along one or both of the node's 2 other edgesprivate java.util.Vector<SOCShip> checkTradeRouteFarEndClosed(SOCShip newShipEdge, int edgeFarNode) throws java.lang.IllegalStateException
SOCShip
s) away from a newly closed end, to
determine if the other end is closed or still open, and close this route if
necessary.
We check the route in one direction towards edgeFarNode, because we assume that the other end of newShipEdge has a settlement, or that it branches from an already-closed trade route.
The route and its segments may end at a settlement/city/village, a branch where 3 ships meet at a node (and 2 of the 3 ships are closed), or may end "open" with no further pieces.
Settlements and cities owned by other players won't close the trade route.
Villages
are present only with scenario game option SOCGameOption.K_SC_CLVI
.
If this route becomes closed and is the player's first Cloth Trade route with a village,
this method sets that player event flag and fires
SOCScenarioPlayerEvent.CLOTH_TRADE_ESTABLISHED_VILLAGE
.
Valid only when SOCGame.hasSeaBoard
.
newShipEdge
- A ship in a currently-open trade route, either newly placed
or adjacent to a newly placed settlement.
If the ship is newly placed, it should not yet be in roads
.
If the settlement is newly placed, it should not yet be in settlements
.edgeFarNode
- The unvisited node at the far end of fromEdge.
We'll examine this node and then continue to move along edges past it.
SOCShip
s
java.lang.IllegalStateException
- if not SOCGame.hasSeaBoard
private java.util.Vector<SOCShip> isTradeRouteFarEndClosed(SOCShip edgeFirstShip, int edgeFarNode, java.util.HashSet<java.lang.Integer> alreadyVisited, java.util.List<java.util.Vector<java.lang.Object>> encounteredSelf) throws java.lang.ClassCastException, java.lang.IllegalArgumentException
checkTradeRouteFarEndClosed(SOCShip, int)
.
See that method for more information.
This method checks one segment of the trade route going from a branch.
The segment may end at a settlement/city/village, another branch, or end with no further pieces.
If recursion ends at a SOCVillage
, isTradeRouteFarEndClosed_foundVillage
will be set to it. If you're looking for villages, clear that field before calling this method.
Valid only when SOCGame.hasSeaBoard
.
edgeFirstShip
- First edge along the segment; an open ship required here.
All edges, including this first edge, are checked against encounteredSelf.edgeFarNode
- The unvisited node at the far end of fromEdge.
We'll examine this node and then continue to move along edges past it.
If the "facing direction" we're moving in is called "moveDir",
then edgeFarNode =
board.getAdjacentNodeToEdge(edgeFirstShip.getCoordinates(), moveDir)
.alreadyVisited
- contains Integer edge coordinates as the segment is built;
added to in this methodencounteredSelf
- contains Vectors, each with a node coord Integer and SOCShips;
might be added to in this method.
Node is the "far end" of the segment from edgeFirstShip,
just past the ship that was re-encountered.
The SOCShips are ordered starting with edgeFirstShip and moving
out to the node just past (farther than) the encounter ship.
(That ship is not in the Vector.)
The very first vector in the list is the one farthest from the original
starting ship, and the following list entries will overall move closer
to the start.
SOCShip
or null, from fromEdge to far end;
may also add to alreadyVisited and encounteredSelf
java.lang.ClassCastException
- if not SOCGame.hasSeaBoard
.
java.lang.IllegalArgumentException
- if edgeFirstShip.isClosed()
public int getLastSettlementCoord()
public int getLastRoadCoord()
public int getLongestRoadLength()
calcLongestRoad2()
.
public java.util.Vector<SOCLRPathData> getLRPaths()
SOCGameOption.K_SC_0RVP
is set.
public void setLRPaths(java.util.Vector<SOCLRPathData> vec)
vec
- the vectorpublic void setLongestRoadLength(int len)
len
- the lengthpublic SOCResourceSet getResources()
public int[] getResourceRollStats()
SOCBoardLarge.GOLD_HEX
.
For the Fog Scenario
, includes resources picked when building
a road or ship revealed gold from a SOCBoardLarge.FOG_HEX
.
Please treat this as read-only.
Not currently tracked at client.
SOCResourceConstants.CLAY
- SOCResourceConstants.WOOD
.
Index 0 is unused.
In v2.0.00 and newer, index SOCResourceConstants.GOLD_LOCAL
tracks how many
resource picks the player has received from gold hexes.public void addRolledResources(SOCResourceSet rolled)
If SOCGame.hasSeaBoard
, treat SOCResourceConstants.GOLD_LOCAL
as the gold-hex resources they must pick, and set
getNeedToPickGoldHexResources()
to that amount.
This method updates getResourceRollStats()
[GOLD_LOCAL
].
Once the resources from gold from a dice roll are picked, the
game should update this player's getResourceRollStats()
.
Otherwise ignores rolled SOCResourceConstants.UNKNOWN
resources.
rolled
- The resources gained by this roll, as determined
by SOCGame.rollDice()
public SOCResourceSet getRolledResources()
SOCGame.rollDice()
.public SOCInventory getInventory()
SOCDevCard
s and other occasional items.
Before v2.0.00, this method was getDevCards()
.
public boolean hasUnplayedDevCards()
getInventory()
public int getNumKnights()
public void setNumKnights(int nk)
nk
- the number of knightspublic void incrementNumKnights()
public boolean hasLongestRoad()
public boolean hasLargestArmy()
public int getSpecialVP()
getSpecialVPInfo()
public void setSpecialVP(int svp)
svp
- the number of SVPs, or 0addSpecialVPInfo(int, String)
public int getPublicVP()
cloth
.
getTotalVP()
,
getSpecialVP()
,
forceFinalVP(int)
public int getTotalVP()
getPublicVP()
,
forceFinalVP(int)
public void forceFinalVP(int score)
score
- Total score for the player, or 0 for no forced total.public void addSpecialVPInfo(int svp, java.lang.String desc)
SOCGame.scenarioEventListener
!= null, and sent out to clients.
Clients call it from the network message handler.
svp
- Number of SVPdesc
- Description of player's action that led to the SVP.
At the server this is an I18N string key, at the client it's
localized text sent from the server.getSpecialVPInfo()
public java.util.ArrayList<SOCPlayer.SpecialVPInfo> getSpecialVPInfo()
getSpecialVP()
total.
In chronological order during game play.
public int getScenarioPlayerEvents()
large sea board
.
As events occur during a game, each one's SOCScenarioPlayerEvent.flagValue
bit is set.
Example events: SOCScenarioPlayerEvent.SVP_SETTLED_ANY_NEW_LANDAREA
,
SOCScenarioPlayerEvent.CLOTH_TRADE_ESTABLISHED_VILLAGE
.
Not all player events are returned here; some can't be represented in a single flag bit.
hasScenarioPlayerEvent(SOCScenarioPlayerEvent)
public void setScenarioPlayerEvents(int events)
getScenarioPlayerEvents()
based on a server message.
events
- Player event flags to set; all others will be cleared.public final boolean hasScenarioPlayerEvent(SOCScenarioPlayerEvent spe)
spe
- Player event, such as SOCScenarioPlayerEvent.SVP_SETTLED_ANY_NEW_LANDAREA
getScenarioPlayerEvents()
private final void setScenarioPlayerEvent(SOCScenarioPlayerEvent spe) throws java.lang.IllegalStateException
spe
- Player event, such as SOCScenarioPlayerEvent.SVP_SETTLED_ANY_NEW_LANDAREA
java.lang.IllegalStateException
- if this flag is already set.
This is checked at server, not client, due to message timing:
Game events happen at the server before they happen at the client.clearScenarioPlayerEvent(SOCScenarioPlayerEvent)
private final void clearScenarioPlayerEvent(SOCScenarioPlayerEvent spe)
spe
- Player event, such as SOCScenarioPlayerEvent.SVP_SETTLED_ANY_NEW_LANDAREA
setScenarioPlayerEvent(SOCScenarioPlayerEvent)
public int getScenarioSVPLandAreas()
large sea board
, get
this player's bitmask of land areas for tracking Special Victory Points (SVP).
Used with scenario game option _SC_SEAC
.
public void setScenarioSVPLandAreas(int las)
getScenarioPlayerEvents()
based on a server message.
las
- Land areas to set in player's bitmask; all others will be cleared.public int getStartingLandAreasEncoded()
large sea board
, get
this player's starting settlement land areas, encoded to send over the network
from server to client. 0 otherwise.
SOCPlayerElement.STARTING_LANDAREAS
public void setStartingLandAreasEncoded(int slas)
getStartingLandAreasEncoded()
based on a server message.
slas
- Starting land areas to set for playerpublic java.util.Vector<java.lang.Integer> getRoadNodes()
public SOCTradeOffer getCurrentOffer()
public void setCurrentOffer(SOCTradeOffer of)
of
- the offer, or null to clearpublic boolean isConnectedByRoad(int node1, int node2)
node1
- coordinates of first nodenode2
- coordinates of second node
public void putPiece(SOCPlayingPiece piece, boolean isTempPiece) throws java.lang.IllegalArgumentException
Update potential
piece lists.
For roads, update roadNodes
and roadNodeGraph
.
Does not update longest road; instead, SOCGame.putPiece(SOCPlayingPiece)
calls calcLongestRoad2()
.
Note: Placing a city automatically removes the settlement there
via SOCGame.putPiece(SOCPlayingPiece)
calling
removePiece(SOCPlayingPiece, SOCPlayingPiece)
.
Call this before calling SOCBoard.putPiece(SOCPlayingPiece)
.
For some scenarios on the large sea board
, placing
a settlement in a new Land Area may award the player a Special Victory Point (SVP).
This method will increment specialVP
and set the SOCScenarioPlayerEvent.SVP_SETTLED_ANY_NEW_LANDAREA
flag.
For scenario option _SC_PIRI
,
call with piece = SOCFortress
to set the single "pirate fortress"
that this player must defeat to win. When the fortress is defeated, it is
converted to a settlement; call with piece = SOCSettlement
at the
fortress location.
isTempPiece must be false to set or clear the fortress.
piece
- The piece to be put into play; coordinates are not checked for validity.isTempPiece
- Is this a temporary piece? If so, do not call the
game's SOCScenarioEventListener
.
java.lang.IllegalArgumentException
- only if piece is a SOCFortress
, and either
isTempPiece, or player already has a fortress set.private void putPiece_roadOrShip(SOCRoad piece, SOCBoard board, boolean isTempPiece)
putPiece
, update road/ship-related info,
roadNodes
, roadNodeGraph
and lastRoadCoord
.
Call only when the piece is ours.
Does not update potentialRoads
/potentialShips
; see updatePotentials(SOCPlayingPiece)
.
piece
- The road or shipboard
- The boardisTempPiece
- Is this a temporary piece? If so, do not check special edges or "gift" ports.private void putPiece_roadOrShip_checkNewShipTradeRouteAndSpecialEdges(SOCShip newShip, SOCBoardLarge board, boolean isTempPiece)
If the route becomes closed and is the player's first Cloth Trade route with a SOCVillage
,
this method sets that player flag and fires SOCScenarioPlayerEvent.CLOTH_TRADE_ESTABLISHED_VILLAGE
.
If the board layout has Special Edges, check if the new ship has reached one, and if so
reward the player and fire an event like SOCScenarioPlayerEvent.SVP_REACHED_SPECIAL_EDGE
or SOCScenarioPlayerEvent.DEV_CARD_REACHED_SPECIAL_EDGE
.
In scenario _SC_FTRI
, checks for a "gift" trade port at new ship edge. If found,
calls SOCGame.removePort(SOCPlayer, int)
and fires SOCScenarioPlayerEvent.REMOVED_TRADE_PORT
.
newShip
- Our new ship being placed in putPiece(SOCPlayingPiece, boolean)
;
should not yet be added to roads
board
- game boardisTempPiece
- Is this a temporary piece? If so, do not check special edges or "gift" ports.private void putPiece_settlement_checkTradeRoutes(SOCSettlement newSettle, SOCBoard board)
newSettle
- Our new settlement being placed in putPiece(SOCPlayingPiece, boolean)
;
should not yet be added to settlements
board
- game boardprivate final void putPiece_settlement_checkScenarioSVPs(SOCSettlement newSettle, int newSettleArea, boolean isTempPiece)
startingLandArea1
and startingLandArea2
.
Used with game options _SC_SANY
and _SC_SEAC
.
newSettle
- Newly placed settlementnewSettleArea
- Land area number of new settlement's locationisTempPiece
- Is this a temporary piece? If so, do not call the
game's SOCScenarioEventListener
.public void undoPutPiece(SOCPlayingPiece piece)
Among other actions, Updates the potential building lists for removing settlements or cities. Updates port flags, this player's dice resource numbers, etc.
Call this only after calling SOCBoard.removePiece(SOCPlayingPiece)
.
If the piece is ours, calls removePiece(piece, null)
.
For roads, does not update longest road; if you need to,
call calcLongestRoad2()
after this call.
For removing second initial settlement (state START2B), will zero the player's resource cards.
piece
- the piece placement to be undone.protected void undoPutPieceAuxSettlement(int settlementNode)
settlementNode
- the node we want to considerpublic void removePiece(SOCPlayingPiece piece, SOCPlayingPiece replacementPiece)
Most callers will want to instead call undoPutPiece(SOCPlayingPiece)
which calls removePiece and does more.
Don't call removePiece for a SOCFortress
; see getFortress()
javadoc.
Note: removePiece does NOT update the potential building lists
for removing settlements or cities.
It does update potential road lists.
For roads, updates roadNodes
and roadNodeGraph
.
If a ship is removed in scenario _SC_PIRI
, makes sure our getNumWarships()
is never more than the number of ships on the board.
piece
- Our player's piece, to be removed from the boardreplacementPiece
- Piece that's replacing this piece; usually null unless player is upgrading to a city.
If not null, and same player as piece, the removed piece's SOCPlayingPiece.specialVP
and SOCPlayingPiece.specialVPEvent
are copied to replacementPiece
instead of being subtracted from the player's getSpecialVP()
count.undoPutPiece(SOCPlayingPiece)
private final void removePieceUpdateSpecialVP(SOCPlayingPiece p)
removePiece(SOCPlayingPiece, null)
,
update player's specialVP
and related fields.
Not called if the removed piece is being replaced by another one (settlement upgrade to city).
p
- Our piece being removed, which has SOCPlayingPiece.specialVP
!= 0void updatePortFlagsAfterRemove(int portType, boolean removedPort)
portType
- The type of port removed (in range MISC_PORT
to WOOD_PORT
)removedPort
- If true, the port was removed, not our piece there; affects port-counting logicvoid updateLegalShipsAddHex(int hexCoord)
SOCBoardLarge.FOG_HEX
is revealed to be water,
or a land hex at the board's margin
,
update the set of edges used by isLegalShip(int)
.
The revealed hex's edges previously weren't part of the set,
because we didn't know if the fog hid land or water.
Called by SOCGame.revealFogHiddenHex(int, int, int)
.
If the hex type isn't SOCBoard.WATER_HEX
and ! board.isHexAtBoardMargin(hexCoord)
,
does nothing.
Call only if SOCGame.hasSeaBoard
.
hexCoord
- Coordinate of hex to add if waterpublic void updatePotentials(SOCPlayingPiece piece)
Special case: In game scenario _SC_PIRI
,
ship routes can't branch in different directions, only extend from their ends.
So when a ship is placed to extend a sea route, this method will remove
nearby potential ships which would now be side branches.
piece
- a piece that has just been played
or our piece adjacent to another player's
removed piecepublic java.util.HashSet<java.lang.Integer> getPotentialSettlements()
Please make no changes, treat the returned set as read-only.
Integer
potential-settlement node coordinatesgetPotentialSettlements_arr()
public int[] getPotentialSettlements_arr()
This variant returns them as an array, for ease of use when traversing all potential settlements.
getPotentialSettlements()
public void setPotentialAndLegalSettlements(java.util.Collection<java.lang.Integer> psList, boolean setLegalsToo, java.util.HashSet<java.lang.Integer>[] legalLandAreaNodes)
SOCGame.hasSeaBoard
,
the potentials list is instead copied at start
of game from legalSettlements.
If our game uses the large sea board (SOCGame.hasSeaBoard
),
and setLegalsToo, and psList is not empty,
then also update the player's legal settlements
and legal road sets, since they aren't constant
on that type of board; don't call this method before calling
SOCBoardLarge.setLegalAndPotentialSettlements(Collection, int, HashSet[])
,
or the road sets won't be complete.
Call this method before, not after, calling setRestrictedLegalShips(int[])
.
However, if the player already has a restricted legal ship edge list, this method won't clear it.
This method is called at the server only when game.hasSeaBoard,
just after makeNewBoard in SOCGame.startGame()
.
Before v2.0.00, this method was called setPotentialSettlements.
psList
- the list of potential settlements,
a Vector
or HashSet
of
Integer
node coordinatessetLegalsToo
- If true, also update legal settlements/roads/ships
if we're using the large board layout. [Parameter added in v2.0.00]
In scenario _SC_PIRI
, for efficiency, the legal ships list will remain
empty until setRestrictedLegalShips(int[])
is called.
legalLandAreaNodes
- If non-null and setLegalsToo,
all Land Areas' legal (but not currently potential) node coordinates.
Index 0 is ignored; land area numbers start at 1.addLegalSettlement(int, boolean)
public void addLegalSettlement(int node, boolean checkAdjacents)
SOCGame.hasSeaBoard
to add a location
after calling setPotentialAndLegalSettlements(Collection, boolean, HashSet[])
.
This would be a lone location beyond the usual starting/legal LandAreas on the scenario's board.
node
- A node coordinate to add, or 0 to do nothingcheckAdjacents
- If true, check adjacent nodes before adding.
If node
is adjacent to a settlement, it won't be added and getAddedLegalSettlement()
won't be updated to node
.isLegalSettlement(int)
,
getAddedLegalSettlement()
public boolean canPlaceSettlement(int node)
isPotentialSettlement(int)
.
Does not check getNumPieces(SETTLEMENT)
.
On the large board, checks against SOCBoardLarge.getPlayerExcludedLandAreas()
.
node
- node coordinate
SOCGame.couldBuildSettlement(int)
public boolean isPotentialSettlement(int node)
getNumPieces(SETTLEMENT)
.
node
- the coordinates of a node on the board
canPlaceSettlement(int)
public void clearPotentialSettlement(int node)
node
- coordinates of a node on the boardisPotentialSettlement(int)
public boolean isLegalSettlement(int node)
node
- the coordinates of a node on the board
getAddedLegalSettlement()
public int getAddedLegalSettlement()
addLegalSettlement(int, boolean)
.
That method could be called multiple times, but only the most recently added node is returned by this method.
addLegalSettlement(int, boolean)
, or 0public boolean isPotentialCity(int node)
getNumPieces(CITY)
.
node
- the coordinates of a node on the board
public void clearPotentialCity(int node)
node
- coordinates of a node on the boardisPotentialCity(int)
public boolean isPotentialRoad(int edge)
getNumPieces(ROAD)
.
edge
- the coordinates of an edge on the board. Accepts -1 for edge 0x00.
public void clearPotentialRoad(int edge)
edge
- coordinates of an edge on the board. Accepts -1 for edge 0x00.isPotentialRoad(int)
public boolean isLegalRoad(int edge)
edge
- the coordinates of an edge on the board.
Accepts -1 for edge 0x00; any other negative value returns false.
public boolean isPotentialShipMoveTo(int toEdge, int fromEdge)
SOCGame.canMoveShip(int, int, int)
to check the ship's requested new location.
First, toEdge
must be a potential ship* now.
Then, we check to see if even without the ship at fromEdge
,
toEdge is still potential:
If either end node of toEdge
has a settlement/city of ours,
or has an adjacent edge with a ship of ours
(except fromEdge
), then toEdge
is potential.
*In scenario _SC_PIRI
, we check more carefully because
after ship placement, nearby potential ships are removed to prevent
any branching of the ship route. This would make it impossible to
move the route's newest ship to its other potential direction from
the previous node.
toEdge
- the coordinates of an edge on the board;
isPotentialShip(toEdge)
must currently be true.fromEdge
- the ship's current edge coordinate, to
ignore when determining if toEdge
is still potential.
isPotentialShip(int)
public boolean isPotentialShip(int edge)
SOCGame.hasSeaBoard
,
Does not check getNumPieces(SHIP)
.
edge
- the coordinates of an edge on the board
SOCGame.hasSeaBoard
, always returns false
because the player has no potential ship locations.isPotentialShipMoveTo(int, int)
,
SOCGame.canPlaceShip(SOCPlayer, int)
public void clearPotentialShip(int edge)
edge
- coordinates of an edge on the boardisPotentialRoad(int)
public boolean isLegalShip(int edge)
edge
- the coordinates of an edge on the board
public java.util.HashSet<java.lang.Integer> getRestrictedLegalShips()
_SC_PIRI
),
or null
if all sea edges are legal for ships.
If the player has no legal ship edges, this list is empty (not null).
Please treat the returned HashSet as read-only.
null
public void setRestrictedLegalShips(int[] edgeList)
_SC_PIRI
).
edgeList
- List of edges, same format as one player's array from
SOCBoardLargeAtServer.getLegalSeaEdges(SOCGame, int)
;
or an empty array (length 0) for vacant players with no legal ship edges;
or null
for unrestricted ship placement.
If edgeList
is null
and the player previously had a restricted
ship edge list, will call SOCBoardLarge.initPlayerLegalShips()
to
unrestrict the player's legal ship positions. If the game is already in progress,
this naive call will include any no-longer-legal ships due to placed pieces.
public boolean hasPotentialRoad()
public boolean hasPotentialSettlement()
public boolean hasPotentialCity()
public boolean hasPotentialShip()
public boolean canBuildInitialPieceType(int pieceType) throws java.lang.IllegalStateException
Ignores the specific gameState (any initial state is OK).
Ships are allowed only when SOCGame.hasSeaBoard
.
pieceType
- Piece type, such as SOCPlayingPiece.SETTLEMENT
java.lang.IllegalStateException
- if gameState is past initial placement (> SOCGame.START3B
)public int calcLongestRoad2()
public java.util.List<java.lang.Integer> getPortMovePotentialLocations(boolean all)
_SC_FTRI
,
calculate if the player has any coastal settlement or city where
they can place a moved "gift" port without it being adjacent to another port,
and the edges where it could be placed next to such settlements or cities.
all
- Return all such edges (for placement browsing), or just one (to see if they have any)?
null
if noneSOCGame.canPlacePort(SOCPlayer, int)
public void setPortFlag(int portType, boolean value)
portType
- the type of port; in range SOCBoard.MISC_PORT
to SOCBoard.WOOD_PORT
value
- true or falsepublic boolean getPortFlag(int portType)
portType
- the type of port; in range SOCBoard.MISC_PORT
to SOCBoard.WOOD_PORT
public boolean[] getPortFlags()
public java.lang.StringBuffer numpieces(java.lang.StringBuffer sb)
public void destroyPlayer()
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |