de.adom.jade.world.maps
Class Map

java.lang.Object
  extended by de.adom.jade.world.maps.Map
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
OutdoorMap, UndergroundMap, WorldMap

public abstract class Map
extends java.lang.Object
implements java.io.Serializable

Defines a map. Maps can be either finite or infinite. Infinite maps wrap around the borders.

The map listener code is optimized for fast listener calls. Adding and removing listeners in turn is costly.

See Also:
Serialized Form

Constructor Summary
Map(Location theLocation, int theWidth, int theHeight, boolean finite, Tile initialBlockingMapTile, Tile initialMapTile)
          Creates a new map with a given width and height.
Map(Location theLocation, int theWidth, int theHeight, boolean finite, Tile initialBlockingMapTile, Tile initialMapTile, Tile openTile, int openTileRange)
          Creates a new map with a given width and height.
 
Method Summary
 void addArea(Area area)
          Adds an area to the map.
 void addMapListener(MapListener listener)
          Adds a new map listener to this map.
 void attach(int x, int y, Complex complex)
          Attaches a new complex in a given position to the location to which this map belongs.
 void buildConnections()
          Builds all undefined connections into the game when this map is created.
protected  void fireMapUpdated(int x, int y)
          Notifies all listeners of an update to the map.
 AreaList getAreas(int x, int y)
          Returns the area at a specified position.
 Being getBeing(int x, int y)
          Returns a being at a given position.
 int getDirectionalXModifier(int povX, int x)
          Returns the x modifier for two positions to be able to trace routes from a point of view.
 int getDirectionalYModifier(int povY, int y)
          Returns the y modifier for two positions to be able to trace routes from a point of view.
 int getDistance(int x1, int y1, int x2, int y2)
          Determines the distance between two positions.
 int getDX(int x1, int x2)
          Returns the horizontal distance between two points and takes wrapping into account.
 int getDY(int y1, int y2)
          Returns the vertical distance between two points and takes wrapping into account.
 int getHeight()
          Returns the height of the map.
 Location getLocation()
          Returns the location to which this map belongs.
 MapView getMapView()
          Returns the map view for this map.
protected  Tile getOpenBuilderTile()
          Returns the tile used for spaces open for other buildings.
 int getRandomX()
          Returns a random x coordinate within the boundaries of the map.
 int getRandomY()
          Returns a random y coordinate within the boundaries of the map.
 int getSightRange(Being being)
          Returns the sight range for a given being on this map.
 Tile getTile(int x, int y)
          Returns a tile at a specific position.
 int getVisibilityBlockadeLevel(int fromX, int fromY, int toX, int toY)
          Determines how much sight is blocked by the tiles between two positions.
 int getWidth()
          Returns the width of the map.
 int getWrappedX(int x)
          Returns the x coordinate in a normalized way.
 int getWrappedY(int y)
          Returns the y coordinate in a normalized way.
 boolean isDark(int x, int y)
          Determines whether a given position is shrouded in unnatural darkness.
 boolean isEmpty(int x1, int y1, int x2, int y2)
          Checks whether a map area is open to take up a building.
 boolean isFinite()
          Determines whether the map is finite or not.
 boolean isValidPosition(int x, int y)
          Determines whether a position is a valid map position or not.
protected  void placeAreas(AreaCreator areaCreator)
          Places a number of areas on the map.
 void removeBeing(Being being)
          Remove a being at a given position.
 void removeMapListener(MapListener listener)
          Removes a given map listener from this list.
 void setBeing(Being being)
          Sets a being at a given position.
 void setDark(int x, int y, boolean darkness)
          Marks the darkness status of a given position.
 void setPointOfView(Being being)
          Sets the point of view by using a being as the reference point.
 void setTile(int x, int y, Tile theTile)
          Sets a specific tile at a given position.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Map

public Map(Location theLocation,
           int theWidth,
           int theHeight,
           boolean finite,
           Tile initialBlockingMapTile,
           Tile initialMapTile)
Creates a new map with a given width and height. The tile representing open space is the initial map tile and a default distance of 1 to other buildings is assumed.

Parameters:
theLocation - the location to which this map belongs
theWidth - the width of the new map
theHeight - the height of the new map
isFinite - determines whether the map is finite or not
initialBlockingMapTile - the tile used for blocked spaces (usually the map boundaries for finite maps)
initialMapTile - the default map tile used for all map locations

Map

public Map(Location theLocation,
           int theWidth,
           int theHeight,
           boolean finite,
           Tile initialBlockingMapTile,
           Tile initialMapTile,
           Tile openTile,
           int openTileRange)
Creates a new map with a given width and height.

Parameters:
theLocation - the location to which this map belongs
theWidth - the width of the new map
theHeight - the height of the new map
isFinite - determines whether the map is finite or not
initialBlockingMapTile - the tile used for blocked spaces (usually the map boundaries for finite maps)
initialMapTile - the default map tile used for all map locations
openTile - the tile used to represent an open space for building purposes
openTileRange - the area that must be left open between two filled areas
Method Detail

addMapListener

public void addMapListener(MapListener listener)
Adds a new map listener to this map. There is no security check to prevent a listener from being added more than once. If this happens an error will happen when rying to remove that listener.

Parameters:
listener - the listener to add

removeMapListener

public void removeMapListener(MapListener listener)
Removes a given map listener from this list.

Parameters:
listener - the listener to remove
Throws:
java.lang.IllegalArgumentException - if the listener does not exist in the listener list
ArrayIndexOutOfBoundsException, - if trying to remove a listener that was added more than once

fireMapUpdated

protected void fireMapUpdated(int x,
                              int y)
Notifies all listeners of an update to the map.

Parameters:
x - the x coordinate for the tile
y - the y coordinate for the tile

setTile

public void setTile(int x,
                    int y,
                    Tile theTile)
Sets a specific tile at a given position.

Parameters:
x - the x coordinate for the tile
y - the y coordinate for the tile
theTile - the tile to set

getTile

public Tile getTile(int x,
                    int y)
Returns a tile at a specific position.

Parameters:
x - the x coordinate in question
y - the y coordinate in question
Returns:
the tile at the given position

getWrappedX

public final int getWrappedX(int x)
Returns the x coordinate in a normalized way.

Parameters:
x - the x coordinate
Returns:
the normalized x coordinate

getWrappedY

public final int getWrappedY(int y)
Returns the y coordinate in a normalized way.

Parameters:
y - the y coordinate
Returns:
the normalized y coordinate

isValidPosition

public boolean isValidPosition(int x,
                               int y)
Determines whether a position is a valid map position or not.

Parameters:
x - the x coordinate of the position
y - the y coordinate of the position
Returns:
a boolean value determining whether the position is valid or not

getDistance

public int getDistance(int x1,
                       int y1,
                       int x2,
                       int y2)
Determines the distance between two positions.

Parameters:
x1 - the x coordinate of the first position
y1 - the y coordinate of the first position
x2 - the x coordinate of the second position
y2 - the y coordinate of the second position
Returns:
the distance between the two points

getDX

public int getDX(int x1,
                 int x2)
Returns the horizontal distance between two points and takes wrapping into account.

Parameters:
x1 - the first point
x2 - the second point
Returns:
the horizontal distance

getDY

public int getDY(int y1,
                 int y2)
Returns the vertical distance between two points and takes wrapping into account.

Parameters:
y1 - the first point
y2 - the second point
Returns:
the vertical distance

isFinite

public boolean isFinite()
Determines whether the map is finite or not.

Returns:
a boolean value that determines whether the map is finite or not

getMapView

public MapView getMapView()
Returns the map view for this map.

Returns:
the map view for this map

getWidth

public int getWidth()
Returns the width of the map.

Returns:
the width of the map

getHeight

public int getHeight()
Returns the height of the map.

Returns:
the height of the map

getSightRange

public int getSightRange(Being being)
Returns the sight range for a given being on this map.

Parameters:
being - the being
Returns:
the sight rage for the being in question

isDark

public boolean isDark(int x,
                      int y)
Determines whether a given position is shrouded in unnatural darkness.

Parameters:
x - the x coordinate of the position
y - the y coordinate of the position
Returns:
a boolean value determining whether the given position is shrouded by darkness or not

setDark

public void setDark(int x,
                    int y,
                    boolean darkness)
Marks the darkness status of a given position.

Parameters:
x - the x coordinate of the position
y - the y coordinate of the position
darkness - a boolean value determining whether the given position is dark or not

getVisibilityBlockadeLevel

public int getVisibilityBlockadeLevel(int fromX,
                                      int fromY,
                                      int toX,
                                      int toY)
Determines how much sight is blocked by the tiles between two positions.

Parameters:
fromX - the x coordinate of the start position
fromY - the y coordinate of the start position
toX - the x coordinate of the target position
toY - the y coordinate of the target position

getDirectionalXModifier

public int getDirectionalXModifier(int povX,
                                   int x)
Returns the x modifier for two positions to be able to trace routes from a point of view.

Parameters:
povX - the x point of view
x - the x target point
Returns:
the x modifier

getDirectionalYModifier

public int getDirectionalYModifier(int povY,
                                   int y)
Returns the y modifier for two positions to be able to trace routes from a point of view.

Parameters:
povY - the y point of view
y - the y target point
Returns:
the y modifier

setPointOfView

public void setPointOfView(Being being)
Sets the point of view by using a being as the reference point.

Parameters:
being - the being to use as the reference being for the next map view

setBeing

public void setBeing(Being being)
Sets a being at a given position. Stacking is not allowed. This method does not change the internal data of the being.

Parameters:
being - the being itself

removeBeing

public void removeBeing(Being being)
Remove a being at a given position. Stacking is not allowed. This method does not change the internal data of the being.

Parameters:
being - the being itself

getBeing

public Being getBeing(int x,
                      int y)
Returns a being at a given position.

Parameters:
x - the x position to be examined
y - the y position to be examined
Returns:
the being or null

getLocation

public Location getLocation()
Returns the location to which this map belongs.

Returns:
the location to which this map belongs

attach

public void attach(int x,
                   int y,
                   Complex complex)
Attaches a new complex in a given position to the location to which this map belongs.

Parameters:
x - the x position of the new complex
y - the y position of the new complex
complex - the new complex

buildConnections

public void buildConnections()
Builds all undefined connections into the game when this map is created.


isEmpty

public boolean isEmpty(int x1,
                       int y1,
                       int x2,
                       int y2)
Checks whether a map area is open to take up a building. The area must only contain open tiles and must be empty within the predefine distance surrounding it.

Parameters:
x1 - the left x coordinate of the area
y1 - the left y coordinate of the area
x2 - the right x coordinate of the area
y2 - the right y coordinate of the area
Returns:
a boolean value indicating if the area is open

getOpenBuilderTile

protected Tile getOpenBuilderTile()
Returns the tile used for spaces open for other buildings.

Returns:
the tile used for spaces open for other buildings

addArea

public void addArea(Area area)
Adds an area to the map.

Parameters:
area - the area to add to the map

getAreas

public AreaList getAreas(int x,
                         int y)
Returns the area at a specified position.

Parameters:
x - the x position
y - the y position
Returns:
the area at the given position

getRandomX

public int getRandomX()
Returns a random x coordinate within the boundaries of the map.

Returns:
a random x coordinate

getRandomY

public int getRandomY()
Returns a random y coordinate within the boundaries of the map.

Returns:
a random y coordinate

placeAreas

protected void placeAreas(AreaCreator areaCreator)
Places a number of areas on the map.

Parameters:
areaCreator - the creator used to define the areas