soc.message
Class SOCBoardLayout2

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

public class SOCBoardLayout2
extends SOCMessage
implements SOCMessageForGame

This message contains the board's layout information and its encoding version. The layout is represented as a series of named integer arrays and named integer parameters. These contain the hex layout, the number layout, where the robber is, and possibly the port layout. This message does not contain information about where the player's pieces are on the board.

Typical parts of the board layout: (Not all layouts include all these parts)

Other Layout Parts:

A few game scenarios in jsettlers v2.0.00 may add other parts; see getAddedParts(). The "CE" and "VE" layout parts are lists of Special Edges on the board. During game play, these edges may change. The server announces each change with a SOCBoardSpecialEdge message. If you add a layout part which is a Special Edge type, be sure to update SOCBoardLarge.SPECIAL_EDGE_LAYOUT_PARTS and .SPECIAL_EDGE_TYPES so players joining during the game will get updated Special Edge data.

Board layout parts by board encoding version:

Unlike SOCBoardLayout, dice numbers here equal the actual rolled numbers. SOCBoardLayout required a mapping/unmapping step.

For backwards compatibility, the HL values for SOCBoard.WATER_HEX and SOCBoard.DESERT_HEX are changed to their pre-v2.0 values in the constructor before sending over the network, and changed back in getIntArrayPart("HL").

Since:
1.1.08
Author:
Jeremy D Monin
See Also:
SOCBoardLayout, Serialized Form

Field Summary
private  int boardEncodingFormat
          Board layout encoding version, from SOCBoard.getBoardEncodingFormat().
private  java.lang.String game
          Name of game
private  java.lang.String[] KNOWN_KEYS
          Known layout part keys.
private  java.util.Hashtable<java.lang.String,java.lang.Object> layoutParts
          Contents are int[] or String (which may be int).
private static int SENTLAND_DESERT
          Hex land type numbers sent over the network.
private static int SENTLAND_WATER
          Hex land type numbers sent over the network.
private static long serialVersionUID
           
static int VERSION_FOR_BOARDLAYOUT2
          Minimum version (1.1.08) of client/server which recognize and send VERSION_FOR_BOARDLAYOUT2.
 
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
SOCBoardLayout2(java.lang.String ga, int bef, java.util.Hashtable<java.lang.String,java.lang.Object> parts)
          Create a SOCBoardLayout2 message; see class javadoc for parts' meanings.
SOCBoardLayout2(java.lang.String ga, int bef, int[] hl, int[] nl, int[] pl, int rh)
          Create a SOCBoardLayout2 message for encoding format v1 or v2; see class javadoc for parameters' meanings.
SOCBoardLayout2(java.lang.String ga, int bef, int[] lh, int[] pl, int rh, int ph, int[] px, int[] rx, java.util.Map<java.lang.String,int[]> other)
          Create a SOCBoardLayout2 message for encoding format v3.
 
Method Summary
 java.util.HashMap<java.lang.String,int[]> getAddedParts()
          Some game scenarios may add other layout part keys and int[] values.
 int getBoardEncodingFormat()
          Game's board SOCBoard.getBoardEncodingFormat() version
 java.lang.String getGame()
          Game name
 int[] getIntArrayPart(java.lang.String pkey)
          Get a layout part of type int[].
 int getIntPart(java.lang.String pkey)
          Get a layout part of type int
 java.lang.String getStringPart(java.lang.String pkey)
          Get a layout part of type String
static SOCBoardLayout2 parseDataStr(java.lang.String s)
          Parse the command string into a BoardLayout2 message
 java.lang.String toCmd()
          Formatted string to send this BOARDLAYOUT2 over the network.
static java.lang.String toCmd(java.lang.String ga, int bef, java.util.Hashtable<java.lang.String,java.lang.Object> parts)
          Formatted string to send this BOARDLAYOUT2 over the network.
 java.lang.String toString()
          Render the SOCBoardLayout2 in human-readable form.
 
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

KNOWN_KEYS

private final java.lang.String[] KNOWN_KEYS
Known layout part keys. To be ignored by getAddedParts() because the client calls specific SOCBoardLarge methods for each of these, instead of generically calling SOCBoardLarge.setAddedLayoutParts(HashMap). See getAddedParts() javadoc for details.

Since:
2.0.00

VERSION_FOR_BOARDLAYOUT2

public static final int VERSION_FOR_BOARDLAYOUT2
Minimum version (1.1.08) of client/server which recognize and send VERSION_FOR_BOARDLAYOUT2.

See Also:
Constant Field Values

SENTLAND_WATER

private static final int SENTLAND_WATER
Hex land type numbers sent over the network. Compare to SOCBoard.WATER_HEX, SOCBoard.DESERT_HEX.

Since:
2.0.00
See Also:
Constant Field Values

SENTLAND_DESERT

private static final int SENTLAND_DESERT
Hex land type numbers sent over the network. Compare to SOCBoard.WATER_HEX, SOCBoard.DESERT_HEX.

Since:
2.0.00
See Also:
Constant Field Values

game

private final java.lang.String game
Name of game


boardEncodingFormat

private final int boardEncodingFormat
Board layout encoding version, from SOCBoard.getBoardEncodingFormat().


layoutParts

private java.util.Hashtable<java.lang.String,java.lang.Object> layoutParts
Contents are int[] or String (which may be int). Some are optional depending on game options and scenario; see class javadoc, getAddedParts(), KNOWN_KEYS, SOCBoardLarge.getAddedLayoutParts(), and soc.server.SOCBoardLargeAtServer.setAddedLayoutPart(String, int[]).

Constructor Detail

SOCBoardLayout2

public SOCBoardLayout2(java.lang.String ga,
                       int bef,
                       java.util.Hashtable<java.lang.String,java.lang.Object> parts)
Create a SOCBoardLayout2 message; see class javadoc for parts' meanings.

Parameters:
ga - the name of the game
bef - the board encoding format number, from SOCBoard.getBoardEncodingFormat()
parts - the parts of the layout: int[] arrays or Strings or Integers. contents are not validated here, but improper contents may cause a ClassCastException later.

SOCBoardLayout2

public SOCBoardLayout2(java.lang.String ga,
                       int bef,
                       int[] hl,
                       int[] nl,
                       int[] pl,
                       int rh)
Create a SOCBoardLayout2 message for encoding format v1 or v2; see class javadoc for parameters' meanings. (SOCBoard.BOARD_ENCODING_ORIGINAL or SOCBoard.BOARD_ENCODING_6PLAYER.)

Parameters:
ga - the name of the game
bef - the board encoding format number, from SOCBoard.getBoardEncodingFormat()
hl - the hex layout; not mapped yet, so the constructor will map it from the SOCBoard.getHexLayout() value range to the BOARDLAYOUT2 message's value range.
nl - the number layout
pl - the port layout, or null
rh - the robber hex

SOCBoardLayout2

public SOCBoardLayout2(java.lang.String ga,
                       int bef,
                       int[] lh,
                       int[] pl,
                       int rh,
                       int ph,
                       int[] px,
                       int[] rx,
                       java.util.Map<java.lang.String,int[]> other)
Create a SOCBoardLayout2 message for encoding format v3. (SOCBoardLarge, SOCBoard.BOARD_ENCODING_LARGE.)

Parameters:
ga - the name of the game
bef - the board encoding format number, from SOCBoard.getBoardEncodingFormat()
lh - the land hex layout, or null if all water (before makeNewBoard is called)
pl - the port layout, or null
rh - the robber hex, or -1
ph - the pirate hex, or 0
px - the player exclusion land areas, or null, from SOCBoardLarge.getPlayerExcludedLandAreas()
rx - the robber exclusion land areas, or null, from SOCBoardLarge.getRobberExcludedLandAreas()
other - any other layout parts to add, or null; see getAddedParts(). Please make sure that new keys don't conflict with ones already listed in the class javadoc.
Method Detail

getGame

public java.lang.String getGame()
Game name

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

getBoardEncodingFormat

public int getBoardEncodingFormat()
Game's board SOCBoard.getBoardEncodingFormat() version

Returns:
the encoding format version

getIntArrayPart

public int[] getIntArrayPart(java.lang.String pkey)
Get a layout part of type int[].

As a special case, when pkey is "HL", desert and water hexes will be mapped from the sent values to the SOCBoard values before returning the array.

Parameters:
pkey - the part's key name
Returns:
the component, or null if no part named pkey.

getIntPart

public int getIntPart(java.lang.String pkey)
Get a layout part of type int

Parameters:
pkey - the part's key name
Returns:
the part's value, or 0 if no part named pkey, or if it's not integer.

getStringPart

public java.lang.String getStringPart(java.lang.String pkey)
Get a layout part of type String

Parameters:
pkey - the part's key name
Returns:
the part's value, or null if no part named pkey.

getAddedParts

public java.util.HashMap<java.lang.String,int[]> getAddedParts()
Some game scenarios may add other layout part keys and int[] values. For example, scenario SC_PIRI adds "PP" = { 0x..., 0x... } for the fixed Pirate Path. This is a generic mechanism for adding to layout information without continually changing SOCBoardLayout2 or SOCBoardLarge.

The returned keys of those parts will be none of the ones in the "typical parts of the board layout" listed in this class javadoc, unlike SOCBoardLarge.getAddedLayoutParts() which includes any key added by the options or scenario. The difference is that the client calls SOCBoardLarge.setAddedLayoutParts(HashMap) once for all the parts returned here. For the keys listed in the class javadoc, such as "CV", the client calls part-specific methods such as SOCBoardLarge.setVillageAndClothLayout(int[]) to set up the board when the server sends its layout.

Returns:
Other added parts' keys and values, or null if none
Since:
2.0.00

toCmd

public java.lang.String toCmd()
Formatted string to send this BOARDLAYOUT2 over the network. BOARDLAYOUT2 sep game sep2 encoding {item}

Each item's format is either:

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

toCmd

public static java.lang.String toCmd(java.lang.String ga,
                                     int bef,
                                     java.util.Hashtable<java.lang.String,java.lang.Object> parts)
Formatted string to send this BOARDLAYOUT2 over the network. See toCmd() for details.

Returns:
the command string

parseDataStr

public static SOCBoardLayout2 parseDataStr(java.lang.String s)
Parse the command string into a BoardLayout2 message

Parameters:
s - the String to parse
Returns:
a BoardLayout2 message

toString

public java.lang.String toString()
Render the SOCBoardLayout2 in human-readable form. In version 2.0.00 and later, the land hexes and port layout (LH, PL) are in hexadecimal instead of base-10.

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