java.lang.Object
com.realtime.crossfire.jxclient.map.CfMap

public class CfMap extends Object
Represents a map (as seen by the client). A map is a grid in which CfMapSquares can be stored.

The map will be automatically enlarged by accesses to new squares. Not yet set squares are considered dark.

All accesses must be synchronized on the map instance.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    clearSquare(int x, int y)
    Clears the content of one square.
    void
    dirty(int x, int y)
    Marks a single square as dirty.
    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.
    @NotNull Set<CfMapSquare>
    Returns the dirty map squares.
    @Nullable Face
    getFace(int x, int y, int layer)
    Determines the face of one square.
    @Nullable CfMapSquare
    getHeadMapSquare(int x, int y, int layer)
    Returns the map square of the head of a multi-square object.
    @NotNull CfMapSquare
    getMapSquare(int x, int y)
    Returns a map square.
    @Nullable CfMapSquare
    getMapSquareUnlessDirty(int x, int y)
    Returns a map square.
    int
    Returns the offset to convert an absolute x-coordinate of a map square (CfMapSquare.getX() to a relative x-coordinate.
    int
    Returns the offset to convert an absolute y-coordinate of a map square (CfMapSquare.getY() to a relative y-coordinate.
    int
    getSmooth(int x, int y, int layer)
    Returns the smooth value of one square.
    boolean
    isFogOfWar(int x, int y)
    Determines if the tile is not up-to-date.
    boolean
    processMapScroll(int dx, int dy, int width, int height)
    Processes a map scroll command.
    void
    reset(int mapWidth, int mapHeight)
    Clears the map contents.
    void
    setDarkness(int x, int y, int darkness)
    Sets the darkness value of one square.
    void
    setFace(int x, int y, int layer, @Nullable Face face)
    Sets the face of one square.
    void
    setMagicMap(int x0, int y0, byte @NotNull [] @NotNull [] data)
    Sets the magic map color of one square.
    void
    setSmooth(int x, int y, int layer, int smooth)
    Sets the smooth value of one square.
    void
    squareModified(@NotNull CfMapSquare mapSquare)
    Marks a CfMapSquare as dirty.
    void
    squarePendingFace(int x, int y, int faceNum)
    Marks a CfMapSquare as containing a pending face.
    void
    updateFace(int faceNum, int width, int height)
    Processes an updated face image.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CfMap

      public CfMap()
  • Method Details

    • reset

      public void reset(int mapWidth, int mapHeight)
      Clears the map contents.
      Parameters:
      mapWidth - the width of the visible map area
      mapHeight - the height of the visible map area
    • setDarkness

      public void setDarkness(int x, int y, int darkness)
      Sets the darkness value of one square.
      Parameters:
      x - the x-coordinate of the square
      y - the y-coordinate of the square
      darkness - the darkness value to set; 0=dark, 255=full bright
    • getDarkness

      public int getDarkness(int x, int y)
      Returns the darkness value of one square.
      Parameters:
      x - the x-coordinate of the square
      y - the y-coordinate of the square
      Returns:
      the darkness value of the square; 0=dark, 255=full bright; not yet set faces return 0
    • setSmooth

      public void setSmooth(int x, int y, int layer, int smooth)
      Sets the smooth value of one square.
      Parameters:
      x - the x-coordinate of the square
      y - the y-coordinate of the square
      layer - the layer to set
      smooth - the smooth value to set
    • getSmooth

      public int getSmooth(int x, int y, int layer)
      Returns the smooth value of one square.
      Parameters:
      x - the x-coordinate of the square
      y - the y-coordinate of the square
      layer - the layer of the square
      Returns:
      the smooth value of the square
    • setMagicMap

      public void setMagicMap(int x0, int y0, byte @NotNull [] @NotNull [] data)
      Sets the magic map color of one square.
      Parameters:
      x0 - the x-coordinate of the square
      y0 - the y-coordinate of the square
      data - the magic map data (y, x); will not be changed
    • getColor

      public int getColor(int x, int y)
      Returns the magic map color value of one square.
      Parameters:
      x - the x-coordinate of the square
      y - the y-coordinate of the square
      Returns:
      the color
    • setFace

      public void setFace(int x, int y, int layer, @Nullable @Nullable Face face)
      Sets the face of one square. This function clears fog-of-war state if necessary.
      Parameters:
      x - the x-coordinate of the square
      y - the y-coordinate of the square
      layer - the layer to set
      face - the face to set; may be null to remove the face
    • getFace

      @Nullable public @Nullable Face getFace(int x, int y, int layer)
      Determines the face of one square.
      Parameters:
      x - the x-coordinate of the square
      y - the y-coordinate of the square
      layer - the layer of the face
      Returns:
      the face; dark (i.e. not yet set) faces return null
    • getHeadMapSquare

      @Nullable public @Nullable CfMapSquare getHeadMapSquare(int x, int y, int layer)
      Returns the map square of the head of a multi-square object.
      Parameters:
      x - the x-coordinate of the square
      y - the y-coordinate of the square
      layer - the layer to return the head for
      Returns:
      the head map square, or null if this square does not contain a multi-tail
    • clearSquare

      public void clearSquare(int x, int y)
      Clears the content of one square. Note: the old square content remains available until at least one value will be changed ("fog of war").
      Parameters:
      x - the x-coordinate of the square
      y - the y-coordinate of the square
    • dirty

      public void dirty(int x, int y)
      Marks a single square as dirty.
      Parameters:
      x - the x-coordinate of the square
      y - the y-coordinate of the square
    • isFogOfWar

      public boolean isFogOfWar(int x, int y)
      Determines if the tile is not up-to-date.
      Parameters:
      x - the x-coordinate of the square
      y - the y-coordinate of the square
      Returns:
      whether the tile contains fog-of-war data
    • getMapSquare

      @NotNull public @NotNull CfMapSquare getMapSquare(int x, int y)
      Returns a map square.
      Parameters:
      x - the x-coordinate
      y - the y-coordinate
      Returns:
      the map square
    • getMapSquareUnlessDirty

      @Nullable public @Nullable CfMapSquare getMapSquareUnlessDirty(int x, int y)
      Returns a map square.
      Parameters:
      x - the x-coordinate
      y - the y-coordinate
      Returns:
      the map square or null if it would be dirty
    • getOffsetX

      public int getOffsetX()
      Returns the offset to convert an absolute x-coordinate of a map square (CfMapSquare.getX() to a relative x-coordinate.
      Returns:
      the x offset
    • getOffsetY

      public int getOffsetY()
      Returns the offset to convert an absolute y-coordinate of a map square (CfMapSquare.getY() to a relative y-coordinate.
      Returns:
      the y offset
    • squareModified

      public void squareModified(@NotNull @NotNull CfMapSquare mapSquare)
      Marks a CfMapSquare as dirty.
      Parameters:
      mapSquare - the map square
    • squarePendingFace

      public void squarePendingFace(int x, int y, int faceNum)
      Marks a CfMapSquare as containing a pending face.
      Parameters:
      x - the x coordinate of the map square
      y - the y coordinate of the map square
      faceNum - the pending face
    • getDirtyMapSquares

      @NotNull public @NotNull Set<CfMapSquare> getDirtyMapSquares()
      Returns the dirty map squares. The result may be modified by the caller.
      Returns:
      the dirty map squares
    • updateFace

      public void updateFace(int faceNum, int width, int height)
      Processes an updated face image.
      Parameters:
      faceNum - the face that has changed
      width - the width of the visible map area
      height - the height of the visible map area
    • processMapScroll

      public boolean processMapScroll(int dx, int dy, int width, int height)
      Processes a map scroll command.
      Parameters:
      dx - the distance to scroll in x-direction in squares
      dy - the distance to scroll in y-direction in squares
      width - the width of the visible map area in map squares
      height - the height of the visible map area in map squares
      Returns:
      whether scrolling did clear the whole visible map area