java.lang.Object com.realtime.crossfire.jxclient.map.CfMap
public class CfMap
Represents a map (as seen by the client). A map is a grid in which CfMapSquare
s can be stored.
Field Summary | |
---|---|
private java.util.Set<CfMapSquare> |
dirtyMapSquares
The "dirty" map squares that have been modified. |
private int |
maxPx
The right edge of the defined patches in patch . |
private int |
maxPy
The bottom edge of the defined patches in patch . |
private int |
maxX
The right edge of the defined tiles. |
private int |
maxY
The bottom edge of the defined tiles. |
private int |
minPx
The left edge of the defined patches in patch . |
private int |
minPy
The top edge of the defined patches in patch . |
private int |
minX
The left edge of the defined tiles. |
private int |
minY
The top edge of the defined tiles. |
private int |
ox
Result values for getMapPatch(int,int) and expandTo(int,int) . |
private int |
oy
Result values for getMapPatch(int,int) and expandTo(int,int) . |
private CfMapPatch[][] |
patch
Array of (possibly) defined squares. |
private int |
patchX
Left edge of viewable area. |
private int |
patchY
Top edge of viewable area. |
Constructor Summary | |
---|---|
CfMap()
|
Method Summary | |
---|---|
void |
clearSquare(int x,
int y)
Clears the content of one square. |
private CfMapPatch[][] |
copyPatches(int newWidth,
int newHeight,
int offsetX,
int offsetY,
int height,
int width)
Returns a copy of a rectangular area of patch . |
void |
dirty(int x,
int y)
Marks a single square as dirty. |
private void |
dirtyFace(int x,
int y,
int layer,
Face face)
Marks one face as "dirty". |
private void |
expandFace(int x,
int y,
int layer,
Face face,
CfMapSquare oldMapSquare,
CfMapSquare newMapSquare)
Adds or removes "head" pointer to/from tail-parts of a face. |
private CfMapPatch |
expandTo(int x,
int y)
(Possibly) expands the defined area of the map to a given position. |
int |
getColor(int x,
int y)
Returns the magic map color value of one square. |
int |
getDarkness(int x,
int y)
Returns the darkness value of one square. |
java.util.Set<CfMapSquare> |
getDirtyMapSquares()
Returns the dirty map squares. |
Face |
getFace(int x,
int y,
int layer)
Determines the face of one square. |
CfMapSquare |
getHeadMapSquare(int x,
int y,
int layer)
Returns the map square of the head of a multi-square object. |
private CfMapPatch |
getMapPatch(int x,
int y)
Checks if a given position is within the defined map area. |
CfMapSquare |
getMapSquare(int x,
int y)
Returns a map square. |
CfMapSquare |
getMapSquareUnlessDirty(int x,
int y)
Returns a map square. |
int |
getOffsetX()
Returns the offset to convert an absolute x-coordinate of a map square ( CfMapSquare.getX() to a relative x-coordinate. |
int |
getOffsetY()
Returns the offset to convert an absolute y-coordinate of a map square ( CfMapSquare.getY() to a relative y-coordinate. |
private void |
increase(int dx,
int dy)
Increases the defined area of the map. |
boolean |
isDirty(CfMapSquare mapSquare)
Returns whether a CfMapSquare is dirty. |
boolean |
isFogOfWar(int x,
int y)
Determines if the tile is not up-to-date. |
void |
scroll(int dx,
int dy)
Scrolls the map. |
void |
setColor(int x,
int y,
int color)
Sets the magic map color of one square. |
void |
setDarkness(int x,
int y,
int darkness)
Sets the darkness value of one square. |
void |
setFace(int x,
int y,
int layer,
Face face)
Sets the face of one square. |
private void |
setFaceInternal(int x,
int y,
int layer,
Face face)
Sets the face of one square. |
private void |
setHeadMapSquare(int x,
int y,
int layer,
CfMapSquare mapSquare,
boolean setAlways)
Sets the map square containing the head face for a layer. |
private static int |
size(int min,
int max)
Calculates the number of patches needed to hold tiles between two patch coordinates. |
void |
squareModified(CfMapSquare mapSquare)
Marks a CfMapSquare as dirty. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
@NotNull private final java.util.Set<CfMapSquare> dirtyMapSquares
private int maxPx
patch
.
private int maxPy
patch
.
private int maxX
private int maxY
private int minPx
patch
.
private int minPy
patch
.
private int minX
private int minY
private int ox
getMapPatch(int,int)
and expandTo(int,int)
.
private int oy
getMapPatch(int,int)
and expandTo(int,int)
.
@Nullable private CfMapPatch[][] patch
private int patchX
private int patchY
Constructor Detail |
---|
public CfMap()
Method Detail |
---|
public void clearSquare(int x, int y)
x
- the x-coordinate of the squarey
- the y-coordinate of the square@NotNull private CfMapPatch[][] copyPatches(int newWidth, int newHeight, int offsetX, int offsetY, int height, int width)
patch
.
newWidth
- the width of the new areanewHeight
- the height of the new areaoffsetX
- the x-offset into the new areaoffsetY
- the y-offset into the new areaheight
- the height of the area to copywidth
- the width of the area to copy
public void dirty(int x, int y)
x
- the x-coordinate of the squarey
- the y-coordinate of the squareprivate void dirtyFace(int x, int y, int layer, @NotNull Face face)
x
- the x-coordinate of the tail part of the facey
- the y-coordinate of the tail part of the facelayer
- the layer of the faceface
- the face to mark dirtyprivate void expandFace(int x, int y, int layer, @NotNull Face face, @NotNull CfMapSquare oldMapSquare, @Nullable CfMapSquare newMapSquare)
x
- the x-coordinate of the tail part to expandy
- the y-coordinate of the tail part to expandlayer
- the layer to expandface
- the face to expandoldMapSquare
- the map square of the tail partnewMapSquare
- the map square of the tail part to add pointers, or
null
to remove pointers@NotNull private CfMapPatch expandTo(int x, int y)
x
- the x-coordinate to expand the defined area toy
- the y-coordinate to expand the defined area to
null
if the coordinates are out of
map boundspublic int getColor(int x, int y)
x
- the x-coordinate of the squarey
- the y-coordinate of the square
public int getDarkness(int x, int y)
x
- the x-coordinate of the squarey
- the y-coordinate of the square
@NotNull public java.util.Set<CfMapSquare> getDirtyMapSquares()
@Nullable public Face getFace(int x, int y, int layer)
x
- the x-coordinate of the squarey
- the y-coordinate of the squarelayer
- the layer of the face
null
@Nullable public CfMapSquare getHeadMapSquare(int x, int y, int layer)
x
- the x-coordinate of the squarey
- the y-coordinate of the squarelayer
- the layer to return the head for
null
if this square does not
contain a multi-tail@Nullable private CfMapPatch getMapPatch(int x, int y)
Returns
additional information in ox
and oy
.
x
- the x-coordinate to checky
- the y-coordinate to check
null
if the coordinates are out of
map bounds@NotNull public CfMapSquare getMapSquare(int x, int y)
x
- the x-coordinatey
- the y-coordinate
@Nullable public CfMapSquare getMapSquareUnlessDirty(int x, int y)
x
- the x-coordinatey
- the y-coordinate
null
if it would be dirtypublic int getOffsetX()
CfMapSquare.getX()
to a relative x-coordinate.
public int getOffsetY()
CfMapSquare.getY()
to a relative y-coordinate.
private void increase(int dx, int dy)
dx
- the increase in x-direction; dx<0 means "expand (-dx) tiles
to the left", dx>0 means "expand (dx) tiles to the right"dy
- the increase in y-direction; dy<0 means "expand (-dy) tiles
to the top", dy>0 means "expand (dy) tiles to the bottom"public boolean isDirty(@NotNull CfMapSquare mapSquare)
CfMapSquare
is dirty.
mapSquare
- the map square
public boolean isFogOfWar(int x, int y)
x
- the x-coordinate of the squarey
- the y-coordinate of the square
public void scroll(int dx, int dy)
dx
- the x-difference to scrolldy
- the y-difference to scrollpublic void setColor(int x, int y, int color)
x
- the x-coordinate of the squarey
- the y-coordinate of the squarecolor
- the color to setpublic void setDarkness(int x, int y, int darkness)
x
- the x-coordinate of the squarey
- the y-coordinate of the squaredarkness
- the darkness value to set; 0=dark, 255=full brightpublic void setFace(int x, int y, int layer, @Nullable Face face)
x
- the x-coordinate of the squarey
- the y-coordinate of the squarelayer
- the layer to setface
- the face to set; may be null
to remove the faceprivate void setFaceInternal(int x, int y, int layer, @Nullable Face face)
x
- the x-coordinate of the squarey
- the y-coordinate of the squarelayer
- the layer to setface
- the face to set; may be null
to remove the faceprivate void setHeadMapSquare(int x, int y, int layer, @Nullable CfMapSquare mapSquare, boolean setAlways)
x
- the x-coordinate of the squarey
- the y-coordinate of the squarelayer
- the layer for the new head face between 0
and
LAYERS-1
mapSquare
- the map square containing the head face; may be
null
setAlways
- if set, always update the face; if unset, only update
when fog-of-warprivate static int size(int min, int max)
min
- the minimum coordinatemax
- the maximum coordinate
public void squareModified(@NotNull CfMapSquare mapSquare)
CfMapSquare
as dirty.
mapSquare
- the map square