Package megamek.common.board
Record Class BoardLocation
java.lang.Object
java.lang.Record
megamek.common.board.BoardLocation
- All Implemented Interfaces:
Serializable
public record BoardLocation(Coords coords, int boardId, boolean isNoLocation)
extends Record
implements Serializable
Represents a location (i.e. Coords) on the game board of a specific ID. With a game having multiple maps, this class
needs to replace Coords in many methods to identify a specific position of an Entity or event. The coords cannot be
null.
BoardLocation is immutable.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final BoardLocationThis location represents a location that has null coords or a negative board ID, i.e. -
Constructor Summary
ConstructorsConstructorDescriptionBoardLocation(Coords coords, int boardId, boolean isNoLocation) Creates an instance of aBoardLocationrecord class. -
Method Summary
Modifier and TypeMethodDescriptionReturns a list of all six adjacent coordinates (distance = 1).allAtDistance(int dist) Returns a list of all coordinates at the given distance dist.allAtDistanceOrLess(int dist) Returns a list of all coordinates at the given distance dist and anything less than dist as well.allAtDistances(int minimumDistance, int maximumDistance) Returns a list of all coordinates at the given distance dist and anything less than dist as well.intboardId()Returns the value of theboardIdrecord component.coords()Returns the value of thecoordsrecord component.booleanTwo BoardLocations are equal when their board ID and coords are equal.intgetX()intgetY()inthashCode()Returns a hash code value for this object.booleanDeprecated, for removal: This API element is subject to removal in a future version.booleanReturns the value of theisNoLocationrecord component.booleanisOn(int boardId) booleanisSameBoardAs(BoardLocation other) static BoardLocationReturns a BoardLocation with the given data.toString()Returns a string representation of this record class.translated(int dir) Returns the coordinate 1 unit in the specified direction dir.
-
Field Details
-
NO_LOCATION
This location represents a location that has null coords or a negative board ID, i.e. is obviously invalid. This location, when checked, will return false for comparisons and empty results for adjacent hexes and the like. Note that a BoardLocation that is not a NO_LOCATION does not necessarily exist either, its board ID may still be invalid or its coords outside any board.The coords or board ID of NO_LOCATION should not be used directly but if used the coords are at Integer .MIN_VALUE and the board ID is Board.BOARD_NONE.
-
-
Constructor Details
-
BoardLocation
Creates an instance of aBoardLocationrecord class.- Parameters:
coords- the value for thecoordsrecord componentboardId- the value for theboardIdrecord componentisNoLocation- the value for theisNoLocationrecord component
-
-
Method Details
-
of
Returns a BoardLocation with the given data. When coords are null or the boardId negative, NO_LOCATION is returned. This means that the created BoardLocation never has null coords. Still, the returned BoardLocation may not represent a valid location, as the board ID and coords are not checked against existing boards.- Parameters:
coords- The coordsboardId- The board ID- Returns:
- A BoardLocation representing the given position or NO_LOCATION
-
isOn
public boolean isOn(int boardId) - Parameters:
boardId- The board ID to test- Returns:
- True when this location's board ID is equal to the given board ID, i.e. when this location is on the given board. If this location is a non-location, this will always return false.
- See Also:
-
isAt
Deprecated, for removal: This API element is subject to removal in a future version.- Parameters:
coords- The coords to test- Returns:
- True when this location's coords are equal to the given coords.
-
allAdjacent
Returns a list of all six adjacent coordinates (distance = 1). Does not check if those are on the board or if the board of the present boardId exists. This is equivalent toCoords.allAdjacent()with the boardId of the present BoardLocation added in. This is also equivalent to calling allAtDistance(1).- Returns:
- A list of adjacent BoardLocations
-
allAtDistance
Returns a list of all coordinates at the given distance dist. Does not check if those are on the board or if the board of the present boardId exists. Returns an empty list for dist of less than 0 and the calling BoardLocation itself for dist == 0. This is equivalent toCoords.allAtDistance(int)with the boardId of the present BoardLocation added in.- Returns:
- A list of BoardLocations centered on this BoardLocation and at the given distance
-
allAtDistanceOrLess
Returns a list of all coordinates at the given distance dist and anything less than dist as well. -
allAtDistances
Returns a list of all coordinates at the given distance dist and anything less than dist as well. -
translated
Returns the coordinate 1 unit in the specified direction dir. -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
getBoardNum
-
toFriendlyString
-
isSameBoardAs
-
equals
Two BoardLocations are equal when their board ID and coords are equal. Two NO_LOCATION's are equal. -
hashCode
public int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
getX
public int getX() -
getY
public int getY() -
coords
Returns the value of thecoordsrecord component.- Returns:
- the value of the
coordsrecord component
-
boardId
public int boardId()Returns the value of theboardIdrecord component.- Returns:
- the value of the
boardIdrecord component
-
isNoLocation
public boolean isNoLocation()Returns the value of theisNoLocationrecord component.- Returns:
- the value of the
isNoLocationrecord component
-