soc.message
Class SOCPotentialSettlements

java.lang.Object
  extended by soc.message.SOCMessage
      extended by soc.message.SOCPotentialSettlements
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, SOCMessageForGame

public class SOCPotentialSettlements
extends SOCMessage
implements SOCMessageForGame

This message contains a list of potential settlements.

In version 2.0.00 and newer:

In scenario _SC_PIRI, after initial placement, each player can place not only at these potential locations, but also at their "lone settlement" node previously sent in SOCBoardLayout2 as layout part "LS".

Author:
Robert S Thomas
See Also:
Serialized Form

Field Summary
 int areaCount
          How many land areas are on this board? Always 1 before version 2.0.00.
private  java.lang.String game
          Name of game
 java.util.HashSet<java.lang.Integer>[] landAreasLegalNodes
          Each land area's legal node coordinates.
 int[][] legalSeaEdges
          Optional field, Legal sea edges per player for ships, if restricted.
private  int playerNumber
          Player number, or -1 for all players (version 2.0.00 or newer)
private  java.util.Vector<java.lang.Integer> psList
          List of potential settlements
private static long serialVersionUID
           
 int startingLandArea
          Which land area number is psList within landAreasLegalNodes? 0 if none, because the game has started.
static int VERSION_FOR_PLAYERNUM_ALL
          In version 2.0.00 and above, playerNumber can be -1 to indicate all players have these potential settlements.
 
Fields inherited from class soc.message.SOCMessage
ACCEPTOFFER, ADMINPING, ADMINRESET, AUTHREQUEST, BANKTRADE, BCASTTEXTMSG, BOARDLAYOUT, BOARDLAYOUT2, BOARDSPECIALEDGE, BUILDREQUEST, BUYCARDREQUEST, CANCELBUILDREQUEST, CHANGEFACE, CHANNELS, CHOOSEPLAYER, CHOOSEPLAYERREQUEST, CLEAROFFER, CLEARTRADEMSG, CREATEACCOUNT, DEBUGFREEPLACE, DELETECHANNEL, DELETEGAME, DEVCARDACTION, DEVCARDCOUNT, DICERESULT, DICERESULTRESOURCES, DISCARD, DISCARDREQUEST, DISCOVERYPICK, ENDTURN, FIRSTPLAYER, GAME_NONE, GAMEMEMBERS, GAMEOPTIONGETDEFAULTS, GAMEOPTIONGETINFOS, GAMEOPTIONINFO, GAMES, GAMESERVERTEXT, GAMESTATE, GAMESTATS, GAMESWITHOPTIONS, GAMETEXTMSG, IMAROBOT, INVENTORYITEMACTION, JOIN, JOINAUTH, JOINGAME, JOINGAMEAUTH, LARGESTARMY, LASTSETTLEMENT, LEAVE, LEAVEALL, LEAVEGAME, LEGALEDGES, LOCALIZEDSTRINGS, LONGESTROAD, MAKEOFFER, MEMBERS, messageType, MONOPOLYPICK, MOVEPIECE, MOVEPIECEREQUEST, MOVEROBBER, NEWCHANNEL, NEWGAME, NEWGAMEWITHOPTIONS, NEWGAMEWITHOPTIONSREQUEST, NULLMESSAGE, PICKRESOURCES, PICKRESOURCESREQUEST, PIECEVALUE, PLAYDEVCARDREQUEST, PLAYERELEMENT, PLAYERELEMENTS, PLAYERSTATS, POTENTIALSETTLEMENTS, PUTPIECE, REJECTCONNECTION, REJECTOFFER, REMOVEPIECE, RESETBOARDAUTH, RESETBOARDREJECT, RESETBOARDREQUEST, RESETBOARDVOTE, RESETBOARDVOTEREQUEST, RESOURCECOUNT, REVEALFOGHEX, ROBOTDISMISS, ROBOTJOINGAMEREQUEST, ROLLDICE, ROLLDICEPROMPT, ROLLDICEREQUEST, SCENARIOINFO, sep, sep_char, sep2, sep2_char, SERVERPING, SETPLAYEDDEVCARD, SETSEATLOCK, SETSPECIALITEM, SETTURN, SETUPDONE, SIMPLEACTION, SIMPLEREQUEST, SITDOWN, STARTGAME, STATUSMESSAGE, SVPTEXTMSG, TEXTMSG, TIMINGPING, TURN, UPDATEROBOTPARAMS, VERSION
 
Constructor Summary
SOCPotentialSettlements(java.lang.String ga, int pn, int pan, java.util.HashSet<java.lang.Integer>[] lan, int[][] lse)
          Create a SOCPotentialSettlements message with multiple land areas, each of which have a set of legal settlements, but only one of which has potential settlements at this time.
SOCPotentialSettlements(java.lang.String ga, int pn, java.util.Vector<java.lang.Integer> ps)
          Create a SOCPotentialSettlements message.
 
Method Summary
 java.lang.String getGame()
          Name of game this message is for.
 int getPlayerNumber()
           
 java.util.Vector<java.lang.Integer> getPotentialSettlements()
           
static SOCPotentialSettlements parseDataStr(java.lang.String s)
          Parse the command String into a PotentialSettlements message
 java.lang.String toCmd()
          POTENTIALSETTLEMENTS formatted command, for a message with 1 or multiple land areas.
static java.lang.String toCmd(java.lang.String ga, int pn, int pan, java.util.HashSet<java.lang.Integer>[] lan, int[][] lse)
          toCmd for a SOCPotentialSettlements message with multiple land areas, each of which have a set of legal settlements, but only one of which has potential settlements at this time.
static java.lang.String toCmd(java.lang.String ga, int pn, java.util.Vector<java.lang.Integer> ps)
          toCmd for a SOCPotentialSettlements message with 1 land area.
 java.lang.String toString()
          Simple human-readable representation, used for debug purposes.
 
Methods inherited from class soc.message.SOCMessage
arrayIntoStringBuf, enumIntoStringBuf, getClassNameShort, getMaximumVersion, getMinimumVersion, getType, isSingleLineAndSafe, isSingleLineAndSafe, toMsg
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface soc.message.SOCMessageForGame
getType
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

VERSION_FOR_PLAYERNUM_ALL

public static final int VERSION_FOR_PLAYERNUM_ALL
In version 2.0.00 and above, playerNumber can be -1 to indicate all players have these potential settlements.

Since:
2.0.00
See Also:
Constant Field Values

game

private java.lang.String game
Name of game


playerNumber

private int playerNumber
Player number, or -1 for all players (version 2.0.00 or newer)


psList

private java.util.Vector<java.lang.Integer> psList
List of potential settlements


areaCount

public final int areaCount
How many land areas are on this board? Always 1 before version 2.0.00.

Since:
2.0.00

startingLandArea

public final int startingLandArea
Which land area number is psList within landAreasLegalNodes? 0 if none, because the game has started. 0 if none when game starting and players can place anywhere.

Not used if areaCount == 1.

Since:
2.0.00

landAreasLegalNodes

public final java.util.HashSet<java.lang.Integer>[] landAreasLegalNodes
Each land area's legal node coordinates. Index 0 is unused.

Null if areaCount == 1.

Since:
2.0.00
See Also:
startingLandArea

legalSeaEdges

public int[][] legalSeaEdges
Optional field, Legal sea edges per player for ships, if restricted. Usually null because all sea edges are legal. Legal sea edges are currently restricted only in scenario _SC_PIRI.

If playerNumber != -1, legalSeaEdges contains 1 array, the legal sea edges for that player. Otherwise, will contain 1 array for each player position (total 4 or 6 arrays).

Each per-player array is the same format as in SOCBoardLargeAtServer.PIR_ISL_SEA_EDGES: A list of individual sea edge coordinates and/or ranges. Ranges are designated by a pair of positive,negative numbers: 0xC04, -0xC0D is a range of the valid edges from C04 through C0D inclusive. If a player position is vacant, their subarray may be empty (length 0).

Since:
2.0.00
Constructor Detail

SOCPotentialSettlements

public SOCPotentialSettlements(java.lang.String ga,
                               int pn,
                               java.util.Vector<java.lang.Integer> ps)
Create a SOCPotentialSettlements message.

Parameters:
ga - name of the game
pn - the player number, or -1 for all players in v2.0.00 or newer (see ps for implications)
ps - the list of potential settlement nodes; if pn == -1 and the client and server are at least version 2.0.00 (VERSION_FOR_PLAYERNUM_ALL), ps also is the list of legal settlements.

SOCPotentialSettlements

public SOCPotentialSettlements(java.lang.String ga,
                               int pn,
                               int pan,
                               java.util.HashSet<java.lang.Integer>[] lan,
                               int[][] lse)
                        throws java.lang.IllegalArgumentException
Create a SOCPotentialSettlements message with multiple land areas, each of which have a set of legal settlements, but only one of which has potential settlements at this time.

Parameters:
ga - name of the game
pn - the player number, or -1 for all players
pan - Potential settlements' land area number, or 0 if the game has started, so none of the land areas equals the list of potential settlements. In that case use lan[0] to hold the potential settlements node list.

If the game is just starting and the player can start anywhere (pan == 0), then lan[0] should be null.

lan - Each land area's legal node lists. List number pan will be sent as the list of potential settlements. If none of the land areas equals the list of potential settlements, because the game has started, use index 0 for that potentials list. Otherwise index 0 is unused (null).

If the game is just starting and the player can start anywhere (pan == 0), then lan[0] should be null, and the getPotentialSettlements() list will be formed by combining lan[1] .. lan[n-1].

lse - Legal sea edges for ships if restricted, or null; see legalSeaEdges field for format
Throws:
java.lang.IllegalArgumentException - if ln[pan] == null, or if ln[i] == null for any i > 0
Method Detail

getGame

public java.lang.String getGame()
Description copied from interface: SOCMessageForGame
Name of game this message is for. Must not be null if message is in per-game structures or code.

At the server, the message treater dispatches incoming SOCMessageForGames based on their getGame():

Specified by:
getGame in interface SOCMessageForGame
Returns:
the game name
See Also:
SOCMessage.GAME_NONE

getPlayerNumber

public int getPlayerNumber()
Returns:
the player number

getPotentialSettlements

public java.util.Vector<java.lang.Integer> getPotentialSettlements()
Returns:
the list of potential settlements

toCmd

public java.lang.String toCmd()
POTENTIALSETTLEMENTS formatted command, for a message with 1 or multiple land areas. Format will be either toCmd(String, int, Vector) or toCmd(String, int, int, HashSet[], int[][]).

Specified by:
toCmd in class SOCMessage
Returns:
the command String

toCmd

public static java.lang.String toCmd(java.lang.String ga,
                                     int pn,
                                     java.util.Vector<java.lang.Integer> ps)
toCmd for a SOCPotentialSettlements message with 1 land area.

POTENTIALSETTLEMENTS sep game sep2 playerNumber sep2 psList

Parameters:
ga - the game name
pn - the player number
ps - the list of potential settlements
Returns:
the command string

toCmd

public static java.lang.String toCmd(java.lang.String ga,
                                     int pn,
                                     int pan,
                                     java.util.HashSet<java.lang.Integer>[] lan,
                                     int[][] lse)
toCmd for a SOCPotentialSettlements message with multiple land areas, each of which have a set of legal settlements, but only one of which has potential settlements at this time.

POTENTIALSETTLEMENTS sep game sep2 playerNumber sep2 psList sep2 NA sep2 (number of areas) sep2 PAN sep2 (pan) { sep2 LA# sep2 legalNodesList }+ { sep2 SE { sep2 (legalSeaEdgesList | 0) } }* LA# is the land area number "LA1" or "LA2". None of the LA#s will be PAN's (pan) number.

Parameters:
ga - name of the game
pn - the player number, or -1 for all players
pan - Potential settlements' land area number, or 0 if the game has started, so none of the land areas equals the list of potential settlements. In that case use lan[0] to hold the potential settlements node list.
lan - Each land area's legal node lists. List number pan will be sent as the list of potential settlements. If none of the land areas equals the list of potential settlements, because the game has started, use index 0 for that potentials list. Otherwise index 0 is unused (null).
lse - Legal sea edges for ships if restricted, or null; see legalSeaEdges field for format
Returns:
the command string

parseDataStr

public static SOCPotentialSettlements parseDataStr(java.lang.String s)
Parse the command String into a PotentialSettlements message

Parameters:
s - the String to parse
Returns:
a PotentialSettlements message, or null of the data is garbled

toString

public java.lang.String toString()
Description copied from class: SOCMessage
Simple human-readable representation, used for debug purposes.

Specified by:
toString in class SOCMessage
Returns:
a human readable form of the message