mdh.hephaestus2
Class Map

java.lang.Object
  |
  +--mdh.hephaestus2.Stuff
        |
        +--mdh.hephaestus2.Map
All Implemented Interfaces:
Serializable

public final class Map
extends Stuff

A 2D map of Grids.

Author:
Copyright © 2001 by Mark Hughes <kamikaze@kuoi.asui.uidaho.edu>
See Also:
Serialized Form

Constructor Summary
Map(String name, int xsize, int ysize)
          Creates a new map with the given name and size.
 
Method Summary
 void clear()
          Removes and destroys all contents of the map.
 void fill(int x0, int y0, HashMap define, String mapdata)
          Fills in the terrain of the Map starting at 'x','y'.
 String getBorderCallback()
          Returns the callback called when the player tries to enter the map border (the outermost grids on the map).
 Grid getGrid(int x, int y)
          Returns the Grid at a given coord.
 int getType()
          Returns the type constant for this object, one of Global.TYPE_*.
 boolean inBounds(int x, int y)
          Returns true if the coords are within 0..xsize-1,0..ysize-1
 boolean inCenter(int x, int y)
          Returns true if the coords are within 1..xsize-2,1..ysize-2
 boolean isType(int type)
          Returns true if this class or any of its superclasses is of 'type', one of Global.TYPE_*.
static Map loadMap(File file)
          Loads a Map from a file created by the map editor.
 void setBorderCallback(String b)
          Sets the callback called when the player tries to enter the map border.
 int xsize()
          Returns the width of the map.
 int ysize()
          Returns the height of the map.
 
Methods inherited from class mdh.hephaestus2.Stuff
destroy, getBlocking, getName, getTriggerCallback, id, setBlocking, setName, setTriggerCallback, toString, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Map

public Map(String name,
           int xsize,
           int ysize)
    throws HephaestusException
Creates a new map with the given name and size. This gives the Map a new unique ID and adds it to the database.

Parameters:
name - Human-readable name to show in descriptions. Names do not have to be unique, but should be kept fairly short so they can fit in menus. Null names are not allowed.
xsize - Width of the map in grid squares.
ysize - Height of the map in grid squares.
Method Detail

loadMap

public static Map loadMap(File file)
                   throws HephaestusException
Loads a Map from a file created by the map editor. The Map is stored in World and returned.

HephaestusException

clear

public void clear()
           throws HephaestusException
Removes and destroys all contents of the map. Use this with extreme caution!

HephaestusException

fill

public void fill(int x0,
                 int y0,
                 HashMap define,
                 String mapdata)
          throws HephaestusException
Fills in the terrain of the Map starting at 'x','y'. 'mapdata' is split up vertically by newlines, and each character represents one grid. Each character is looked up in 'define' to find the terrain id as an Integer. Spaces in 'mapdata' are ignored, and the terrain in those grids is unchanged, which allows you to fill non-rectangular regions. See the sample adventure for an example of using fill.

HephaestusException

getBorderCallback

public String getBorderCallback()
                         throws HephaestusException
Returns the callback called when the player tries to enter the map border (the outermost grids on the map).

HephaestusException

getGrid

public Grid getGrid(int x,
                    int y)
             throws HephaestusException
Returns the Grid at a given coord. No bounds-checking is done, so call inBounds(x,y) first if you have any doubts.

HephaestusException

getType

public int getType()
Description copied from class: Stuff
Returns the type constant for this object, one of Global.TYPE_*.

Specified by:
getType in class Stuff

isType

public boolean isType(int type)
Description copied from class: Stuff
Returns true if this class or any of its superclasses is of 'type', one of Global.TYPE_*.

Overrides:
isType in class Stuff

inBounds

public final boolean inBounds(int x,
                              int y)
                       throws HephaestusException
Returns true if the coords are within 0..xsize-1,0..ysize-1

HephaestusException

inCenter

public boolean inCenter(int x,
                        int y)
                 throws HephaestusException
Returns true if the coords are within 1..xsize-2,1..ysize-2

HephaestusException

setBorderCallback

public void setBorderCallback(String b)
                       throws HephaestusException
Sets the callback called when the player tries to enter the map border.

HephaestusException

xsize

public int xsize()
          throws HephaestusException
Returns the width of the map.

HephaestusException

ysize

public int ysize()
          throws HephaestusException
Returns the height of the map.

HephaestusException