wyvern.kernel.maps
Class AbstractGameMap

java.lang.Object
  extended bywyvern.kernel.properties.PList
      extended bywyvern.kernel.maps.AbstractGameMap
All Implemented Interfaces:
Container, GameMap, GameMap.UnloadMapConstants, Hookable, MethodHookable, wyvern.kernel.lighting.Obstructions, PropertyList, SelfExternalizable
Direct Known Subclasses:
DenseMap

public abstract class AbstractGameMap
extends PList
implements GameMap, GameMap.UnloadMapConstants, SelfExternalizable, wyvern.kernel.lighting.Obstructions

This class implements those common utility methods from the GameMap interface that can be implemented without needing to know the underlying representation. It is not a requirement for GameMap implementations to extend this class, but it's highly recommended - it handles a lot of stuff.

Version:
1.0, Nov 22, 1997
Author:
Steve Yegge

Nested Class Summary
 
Nested classes inherited from class wyvern.lib.GameMap
GameMap.UnloadMapConstants
 
Field Summary
protected  int ambient_
           
protected  BitMatrix changeList_
           
protected  MapCommandList commands_
           
protected  boolean dark_
           
protected  Terrain defaultTerrain_
           
protected  int dense_
           
protected  MapDirtyRegions dirtyRegions_
           
protected  wyvern.kernel.data.MultiHashMap lights_
           
protected  java.util.HashMap locals_
           
protected  HookList mapHooks_
           
protected  java.util.Set monsters_
           
protected  java.lang.String name_
           
protected  BitMatrix opaqueMap_
           
protected  java.lang.String path_
           
protected  java.lang.String perPlayer_
           
protected  java.util.Set players_
           
protected  ProximityHookList proxHooks_
           
protected  RoomHookList roomHooks_
           
protected  boolean suspended_
           
protected  int suspendTime_
           
protected  wyvern.kernel.maps.SuspendTimer suspendTimer_
           
protected  java.util.Set teleporters_
           
protected  boolean unloadImmediately_
           
protected  boolean unloading_
           
protected  boolean visUpdates_
           
protected  java.lang.String vpath_
           
 
Fields inherited from class wyvern.kernel.properties.PList
readOnly_
 
Fields inherited from interface wyvern.lib.GameMap
MAX_HEIGHT, MAX_SEARCH_RADIUS, MAX_WIDTH
 
Fields inherited from interface wyvern.lib.PropertyList
PROPERTY_PACKAGE
 
Fields inherited from interface wyvern.lib.GameMap.UnloadMapConstants
MAP_CONTAINS_PLAYERS, MAP_NOT_LOADED, SUCCESS
 
Constructor Summary
AbstractGameMap()
           
 
Method Summary
 void add(int x, int y, GameObject obj)
          Adds the specified object to the map at the specified location.
 void addHook(HookCallback callback, java.lang.String hookName)
          Registers a HookCallback object for the specified hook.
protected abstract  void addIntensityArray(int x, int y, int[][] array, boolean add)
          Calls the subclass to merge in (add or subtract) the contribution from a single LightSource into the subclass's internal lighting array.
 void addLight(int x, int y, LightSource light)
          Adds a light source to the map.
 void addLocalArchetype(Archetype arch)
          Adds a local archetype to this map.
 void addMapLifecycleListener(MapLifecycleListener l)
          Registers with the map to be notified whenever it loads, unloads, suspends, or resumes.
 void addMethodHook(MethodHookCallback callback, java.lang.String methodName)
          Registers for the specified method-hook.
protected  void addMonster(Monster mon)
          Called whenever a non-Player Monster is added to the map.
protected  void addPlayer(Player p)
          Called whenever a Player is added to the map.
 void addPlayerListener(MapPlayerListener listener)
          Registers with the map to be notified whenever players enter or leave the map, or move within the map.
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Adds a PropertyChangeListener to the listener list.
 void addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
          Adds a PropertyChangeListener for a specific property.
 void addProximityHook(ProximityCallback callback, java.lang.String hookName, GameObject target, Rectangle range)
          Registers for hook notifications for events occurring within a fixed range of a given object.
 void addRoomHook(RoomHookCallback callback, java.lang.String hookName, Rectangle room)
          Registers for a specific area of interest in the map.
protected  void addTeleporter(Teleporter t)
          Called whenever a teleporter is added to the map.
abstract  void adjustIntensity(int x, int y, int intensity)
          Manually adjusts the light intensity by a fixed amount at the passed (x, y) location.
 void broadcast(java.lang.String msg)
          Broadcasts a message to every player in the map.
 void broadcast(java.lang.String msg, byte style)
          Broadcasts a message to every player in the map.
 int dismantle()
          Do NOT call this method - use World.unloadMap(mapname) instead, unless you have created the map yourself without registering it with the World.
 void doneLoading()
          Notification from the MapLoader that we've finished adding objects to the map.
 void enableVisUpdates(boolean enable)
          While the map is being loaded; that is, while objects are initially being added to it, turning off visual updates will improve the load time.
 GameObject findAt(int x, int y, Predicate p)
          Looks for an object at the passed map location that passes the specified Predicate.
 GameObject findAt(int x, int y, java.lang.String name)
           
 GameObject findAt(Point loc, Predicate p)
           
 GameObject findAt(Point loc, java.lang.String name)
           
 GameObject findByName(int x, int y, java.lang.String name)
          Finds the first object at the specified location that matches the passed name, using a standard NameMatchPredicate.
 GameObject findByName(Point p, java.lang.String name)
          Returns the topmost visible object at the passed location.
 Point findFreeSpot(int x, int y, GameObject obj)
           
 Point findFreeSpot(Point request, GameObject obj)
          Tries to find a free spot to put this object in.
 GameObject findInRect(int x, int y, int w, int h, Predicate p)
          Searches the objects in the specified rectangle and returns the first one that satisfies the passed Predicate.
 GameObject findTop(int x, int y)
          Returns the "topmost" object at this location.
 GameObject findTop(int x, int y, Predicate p)
          Returns the topmost object at the specified location that passes a specified predicate.
 GameObject findTop(Point p)
           
 GameObject findUnder(GameObject obj, Predicate filter)
          Looks under the passed GameObject's locations for an object that matches the passed Predicate.
protected  void fireMapLoaded()
           
protected  void fireMapResumed()
           
protected  void fireMapSuspended()
           
protected  void fireMapUnloaded()
           
 void firePropertyChange(java.beans.PropertyChangeEvent evt)
          Fires an existing PropertyChangeEvent to any registered listeners.
 void firePropertyChange(java.lang.String propertyName, boolean oldValue, boolean newValue)
          Reports a boolean bound property update to any registered listeners.
 void firePropertyChange(java.lang.String propertyName, int oldValue, int newValue)
          Reports an int bound property update to any registered listeners.
 void firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
          Reports a bound property update to any registered listeners.
 Area getArea()
          Returns the parent Area for this map.
 Player getClaim()
          Returns the player currently claiming the map, if any.
 Command getCommand(CommandEvent event, Commandable agent)
          Checks the list of Commands who have registered this command with the map, and returns the first one whose rectangle of interest contains the agent issuing the command.
 int getDangerLevel()
          Returns the danger level for this map.
 Terrain getDefaultTerrain()
          Returns the default terrain for this map.
 java.util.Set getExits()
          Returns the set of all teleporters in this map that happen to have destinations - even if the teleporter's destination is to another point in this map.
 java.util.Map getFavorites()
          Returns the set of favorite archetypes for this map, for use in the map editor.
 HookList getHookList()
          Returns the HookList containing the registered hooks for this object.
 java.lang.String[] getHooks()
          Returns a list of custom hooks implemented by this object.
 int getLightingLevel()
          Returns the lighting level of this map.
 int getLightLevel(int x, int y)
          Returns the lighting level at the specified location.
 Archetype getLocalArchetype(java.lang.String name)
          Retrieves a local archetype from the map's cache.
 java.util.List getLocalArchetypes()
          Returns a list of the names of all local archetypes registered with this map.
 java.util.Set getMonsterList()
          Returns the set of monsters currently active in this map.
 Music getMusic()
          Returns the background music for this map.
 java.lang.String getName()
          Returns the name of this map.
 java.util.List getObjectsAt(int x, int y)
          Returns a list of the objects at a location.
 java.lang.String getPath()
          Returns the (relative) path to the map file this map was loaded from, e.g.
 java.util.Set getPlayerList()
          Returns the set of players currently playing in this map.
static java.lang.String getProfilingInfo()
          Returns profiling string.
 java.beans.PropertyChangeListener[] getPropertyChangeListeners()
          Returns an array of all the PropertyChangeListeners added to this map with addPropertyChangeListener();
 java.beans.PropertyChangeListener[] getPropertyChangeListeners(java.lang.String propertyName)
          Returns an array of all the listeners which have been associated with the named property.
 ProximityHookList getProximityHookList()
          Returns the ProximityHookList containing the registered proximity-hooks for this map.
 Resource getResource()
          Returns the Resource for this map, so you can query if it's a wiz map, how big it is, what the relative file path is, and so on.
 Location getRestartLoc()
          Returns the restart-location for this map: where players teleport to when they die in this map.
 RoomHookList getRoomHookList()
          Returns the RoomHookList containing the registered room-hooks for this map.
 Point getStartLocation()
          Returns the default starting location for the map.
 int getSuspendTime()
          Returns the length of time, in milliseconds, since this map was suspended.
 int[][] getTerrainInfo(int x, int y, int w, int h)
          Returns enough information about the terrain in the passed rectangle to be able to draw the terrain (with borders) in a client program.
 int getTerrainRecord(int x, int y)
          Returns a packed record describing the terrain at (x, y), suitable for use in drawing terrain borders.
 int getTerrainRecord(int x, int y, boolean useCache)
          Retrieves a terrain record, either by going out and building it, or by looking in the cache.
 int getUnloadDelay()
          Returns the time, in milliseconds, that we'll wait, after we suspend, before unloading the map.
 MapDirtyRegions getUpdateList()
          Returns a list of updates that have occurred since the last query.
 java.lang.String getVirtualPath()
          This is exactly the same as getPath() normal maps, but returns "players/whoever/" + getPath() for per-player maps.
 boolean hasListeners(java.lang.String propertyName)
          Checks if there are any listeners for a specific property.
 boolean hasObstructions(int x, int y, int w, int h)
           
 void initCommon()
          Common initialization for construction & deserialization.
 boolean inMapEditor()
          Returns true if we're being loaded in the map editor.
 void invalidate(int x, int y, int width, int height)
          Forces the map to refresh a particular area.
 boolean isBag()
          Returns true if this container is a Bag (or Inventory, or other implementation of the Bag interface).
 boolean isEmpty(int x, int y)
          Returns true if there's nothing in the map at the passed location except terrain.
 boolean isEmpty(Point p)
           
 boolean isInventory()
          Returns true if this container is an Inventory.
 boolean isLit()
          Returns true if the map is completely lit, e.g. by daylight.
 boolean isMap()
          Returns true if this container is a GameMap.
 boolean isOpaque(int x, int y)
           
 boolean isPerPlayer()
          Returns true if this map is a per-player map, meaning it was loaded by a teleporter with the "per-player" property.
 boolean isSuspended()
          Returns true if the map is currently suspended.
 boolean isUnloaded()
          Returns true if the map has started the unload process.
protected abstract  java.util.Iterator iterator(int x, int y)
           
 void notifyPlayerListeners(int type, Player player, Point source)
          Don't call this.
protected abstract  java.util.List objectsAt(int x, int y)
           
protected abstract  java.util.Iterator objectsInRect(int x, int y, int w, int h)
           
 void readData(org.w3c.dom.Node bean)
          Tells the object to parse its externalized representation from a list of lines.
protected  void recomputeLights(int x, int y)
           
 void registerCommand(java.lang.String command, Command handler, Rectangle room)
          Whenever someone enters a command that isn't in their local command-list, the game engine passes the command to the agent's GameMap to see if anyone has registered the command with the map itself.
 void remove(int x, int y, GameObject obj)
          Removes an object reference at the specified map location (x, y).
 GameObject removeFirst(int x, int y, Predicate p)
          Removes and returns the first object that satisfies the passed Predicate.
 void removeHook(HookCallback callback, java.lang.String hookName)
          Removes a callback from a specified hook list.
 void removeLight(int x, int y, LightSource light)
          Removes a light source from the map.
 Archetype removeLocalArchetype(java.lang.String name)
          Removes a local archetype from the map's cache.
 void removeMapLifecycleListener(MapLifecycleListener l)
          Removes a MapLifecycleListener from this map.
 void removeMethodHook(MethodHookCallback callback, java.lang.String methodName)
          Unregisters for the specified method-hook.
protected  void removePlayer(Player player)
          Removes a reference to a player from the map.
 void removePlayerListener(MapPlayerListener listener)
          Removes an MapPlayerListener from this map.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Removes a PropertyChangeListener from the listener list.
 void removePropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener l)
          Removes a PropertyChangeListener for a specific property.
 void removeProximityHook(ProximityCallback callback, java.lang.String hookName, GameObject target, Rectangle range)
          Removes a callback from the specified proximity-hook.
 void removeRoomHook(RoomHookCallback callback, java.lang.String hookName, Rectangle room)
          Removes a callback from the specified room-hook.
protected  void removeTeleporter(Teleporter t)
          Called when a Teleporter is removed from a map.
 void resetOpaqueFlag(int x, int y)
          Tells the map to re-scan the specified location to see if there are any opaque objects there.
 void resetOpaqueFlag(Point p)
           
 void resume()
          Resumes the map (if it was suspended.)
 void runFailedPostHook(CommandEvent event)
          Notifies all the objects registered on this post-hook that the command failed (for whatever reason).
 void runMethodHook(java.lang.String methodName, java.lang.Object data)
          Runs the specific method hook.
 void runPostHook(CommandEvent event)
          Notifies all the objects registered on this post-hook that the event completed successfully.
 void runPreHook(CommandEvent event)
          Calls all objects registered for a particular event and gives them a chance to deal with the event before it happens.
 void setAutoload()
          Tells the map that it was autoloaded.
 void setDangerLevel(int level)
          Sets the danger level for this map.
 void setDefaultTerrain(java.lang.String terrain)
          Sets the default terrain for the map.
 void setDefaultTerrain(Terrain t)
          Sets the default terrain for the map: the terrain that will be returned if a query is made on a location where no terrain type has been set explicitly using setTerrain().
 void setFavorite(int index, Archetype arch)
          Adds a "favorite" archetype to the map, for use in the map editor.
 void setLightingLevel(int ambient)
          Sets the global, ambient lighting level for the map.
 void setLit(boolean lit)
          Marks the map as having lighting effects, or not.
 void setName(java.lang.String name)
          Sets the name of the map.
 void setPath(java.lang.String path)
          Sets the path to the map.
 void setPerPlayer(java.lang.String name)
          Marks the map as being a per-player map.
 void setStartLocation(Point start)
          Sets the location at which players start when they enter the map, if the teleporter asks the map where to start.
 void setTerrain(int x, int y, Terrain t)
          Sets (or removes) the terrain at the specified map location.
 void setTerrain(Point p, Terrain t)
           
 void setUnloadDelay(int delay)
          Sets the amount of time to wait (in millis) after suspending before the map is unloaded.
 boolean shouldWrite()
          Allows the object to determine whether it wants to be written out at all.
 void startSuspendTimer()
           
 void startUnloadTimer()
           
 void startUnloadTimer(int delay)
           
 void suspend()
          Tells the map to suspend itself.
 java.lang.String toString()
          Returns a string representation of this PropertyList.
protected  void trackSpecialRemoves(GameObject obj)
           
 void unload()
          Tells the map to unload.
 void unregisterCommand(java.lang.String command, Command handler, Rectangle room)
          Removes the specified Command from the map's command-list.
protected  void updateOpaque(int x, int y, boolean opaque)
           
 void updateTerrainCache(int x, int y, int w, int h)
          Call this whenever you change the appearance of a particular piece of terrain.
 void visitObjectsAt(int x, int y, Visitor v)
          Performs an operation on a set of objects at the specified location.
 void visUpdate(GameObject obj)
          Forces the map to refresh a particular area.
 void wakeAllMonsters()
          Wakes up all the monsters in the map, e.g. if a loud noise occurred.
 void wakeMonsters(Point loc, int range)
          Wakes up monsters near the specified point.
 boolean wasAutoloaded()
           
 java.util.List writeData()
          Tells the object to write its properties out to a text file.
 
Methods inherited from class wyvern.kernel.properties.PList
addProperty, addTransientProperty, adjustDoubleProperty, adjustIntProperty, adjustLongProperty, adjustTransientDoubleProperty, adjustTransientIntProperty, adjustTransientLongProperty, countLocalProperties, debugProperties, dismantlePropertyList, getDoubleProperty, getInheritedProperty, getInteger, getIntProperty, getLocalProperties, getLocalProperty, getLongProperty, getParent, getPersistentDoubleProperty, getPersistentIntProperty, getPersistentLocalProperties, getPersistentLongProperty, getPersistentProperty, getProperties, getProperties, getPropertiesIncludingTransients, getPropertiesIncludingTransients, getProperty, getSerializableProperties, getSerializableProperty, getStringProperty, getTransientDoubleProperty, getTransientIntProperty, getTransientLongProperty, getTransientProperties, getTransientProperty, hasLocalProperty, hasPersistentProperty, hasProperty, hasTransientProperty, inheritProperty, isReadOnly, isRemoved, isTransientlyRemoved, printLocalProperties, printProperties, printProperties, printTransientProperties, removeProperty, removeTransientProperty, setDoubleProperty, setIntProperty, setLongProperty, setParent, setProperty, setReadOnly, setTransientDoubleProperty, setTransientIntProperty, setTransientLongProperty, setTransientProperty, toString, transientlyRemoveProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface wyvern.lib.GameMap
add, getBounds, getObjectCount, getOutOfBoundsTerrain, getProperties, getPropertyList, getSize, initialize, initialize, isSparse, keySet, registerAddRemoveListener, remove, setOutOfBoundsTerrain, setSize, terrainAt, unregisterAddRemoveListener, visitRect
 
Methods inherited from interface wyvern.lib.PropertyList
addProperty, addTransientProperty, adjustDoubleProperty, adjustIntProperty, adjustLongProperty, adjustTransientDoubleProperty, adjustTransientIntProperty, adjustTransientLongProperty, countLocalProperties, getDoubleProperty, getInheritedProperty, getIntProperty, getLocalProperties, getLocalProperty, getLongProperty, getParent, getPersistentDoubleProperty, getPersistentIntProperty, getPersistentLocalProperties, getPersistentLongProperty, getPersistentProperty, getProperties, getProperties, getPropertiesIncludingTransients, getPropertiesIncludingTransients, getProperty, getSerializableProperties, getSerializableProperty, getStringProperty, getTransientDoubleProperty, getTransientIntProperty, getTransientLongProperty, getTransientProperties, getTransientProperty, hasLocalProperty, hasPersistentProperty, hasProperty, hasTransientProperty, inheritProperty, isReadOnly, isRemoved, isTransientlyRemoved, printLocalProperties, printProperties, printProperties, printTransientProperties, removeProperty, removeTransientProperty, setDoubleProperty, setIntProperty, setLongProperty, setParent, setProperty, setReadOnly, setTransientDoubleProperty, setTransientIntProperty, setTransientLongProperty, setTransientProperty, toString, transientlyRemoveProperty
 

Field Detail

dense_

protected transient int dense_

mapHooks_

protected transient HookList mapHooks_

roomHooks_

protected transient RoomHookList roomHooks_

proxHooks_

protected transient ProximityHookList proxHooks_

changeList_

protected transient BitMatrix changeList_

dirtyRegions_

protected transient MapDirtyRegions dirtyRegions_

commands_

protected transient MapCommandList commands_

players_

protected transient java.util.Set players_

monsters_

protected transient java.util.Set monsters_

teleporters_

protected transient java.util.Set teleporters_

defaultTerrain_

protected transient Terrain defaultTerrain_

lights_

protected transient wyvern.kernel.data.MultiHashMap lights_

ambient_

protected transient int ambient_

locals_

protected transient java.util.HashMap locals_

opaqueMap_

protected transient BitMatrix opaqueMap_

visUpdates_

protected transient boolean visUpdates_

unloading_

protected transient boolean unloading_

suspended_

protected transient boolean suspended_

suspendTimer_

protected transient wyvern.kernel.maps.SuspendTimer suspendTimer_

suspendTime_

protected transient int suspendTime_

unloadImmediately_

protected transient boolean unloadImmediately_

name_

protected transient java.lang.String name_

path_

protected transient java.lang.String path_

vpath_

protected transient java.lang.String vpath_

dark_

protected transient boolean dark_

perPlayer_

protected transient java.lang.String perPlayer_
Constructor Detail

AbstractGameMap

public AbstractGameMap()
Method Detail

initCommon

public void initCommon()
Common initialization for construction & deserialization. Note: map properties have not yet been added in.


doneLoading

public void doneLoading()
Notification from the MapLoader that we've finished adding objects to the map. This method runs a method-hook called "done-loading", with no data object.

Specified by:
doneLoading in interface GameMap

objectsAt

protected abstract java.util.List objectsAt(int x,
                                            int y)

iterator

protected abstract java.util.Iterator iterator(int x,
                                               int y)

objectsInRect

protected abstract java.util.Iterator objectsInRect(int x,
                                                    int y,
                                                    int w,
                                                    int h)

setDefaultTerrain

public void setDefaultTerrain(Terrain t)
Description copied from interface: GameMap
Sets the default terrain for the map: the terrain that will be returned if a query is made on a location where no terrain type has been set explicitly using setTerrain().

Specified by:
setDefaultTerrain in interface GameMap
Parameters:
t - the Terrain object to use for the default locations.

setDefaultTerrain

public void setDefaultTerrain(java.lang.String terrain)
                       throws java.lang.Exception
Description copied from interface: GameMap
Sets the default terrain for the map. For dense maps, this is the terrain that will be returned inside the bounds of the map. DenseMaps have an additional method for setting the terrain that shows up outside the map's bounds.

For sparse maps, the default terrain is what's used anywhere the terrain hasn't been set explicitly.

Specified by:
setDefaultTerrain in interface GameMap
Parameters:
terrain - the archetype to use (e.g. "terrain/water")
Throws:
java.lang.Exception

getDefaultTerrain

public Terrain getDefaultTerrain()
Description copied from interface: GameMap
Returns the default terrain for this map.

Specified by:
getDefaultTerrain in interface GameMap
Returns:
the default terrain object

setStartLocation

public void setStartLocation(Point start)
Description copied from interface: GameMap
Sets the location at which players start when they enter the map, if the teleporter asks the map where to start.

Specified by:
setStartLocation in interface GameMap
Parameters:
start - the starting location

getStartLocation

public Point getStartLocation()
Description copied from interface: GameMap
Returns the default starting location for the map.

Specified by:
getStartLocation in interface GameMap
Returns:
the position at (or near) which to position players entering the map, if the teleporter doesn't specify where to start explicitly.

getName

public java.lang.String getName()
Description copied from interface: GameMap
Returns the name of this map. By default it gets set to the map's filename (minus the extension) but you can change it to something more descriptive, such as "underground lake".

Specified by:
getName in interface GameMap
Returns:
the name of the map, as shown to players

setName

public void setName(java.lang.String name)
Description copied from interface: GameMap
Sets the name of the map. Should only be called when creating or loading a map.

Specified by:
setName in interface GameMap

getPlayerList

public java.util.Set getPlayerList()
Description copied from interface: GameMap
Returns the set of players currently playing in this map. Don't modify it.

Specified by:
getPlayerList in interface GameMap
Returns:
a Set containing references to all players in the map. May be empty, but will never be null.

getMonsterList

public java.util.Set getMonsterList()
Description copied from interface: GameMap
Returns the set of monsters currently active in this map. Don't modify it.

Specified by:
getMonsterList in interface GameMap
Returns:
a Set containing references to all monsters in the map. May be empty, but will never be null.

getTerrainInfo

public int[][] getTerrainInfo(int x,
                              int y,
                              int w,
                              int h)
Description copied from interface: GameMap
Returns enough information about the terrain in the passed rectangle to be able to draw the terrain (with borders) in a client program.

Specified by:
getTerrainInfo in interface GameMap
Parameters:
x - map x
y - map y
w - rect width
h - rect height
Returns:
a 2D array with the passed dimensions (w,h). Each int in the array is a packed record, constructed as follows:
  • bits 0-15 are the (unsigned short) tile number.
  • bits 16-29 are a 14-bit 1's-complement layer priority.
  • bit 30 is set if the square lets borders in, else clear
  • bit 31 is set if the square lets borders out, else clear

setTerrain

public void setTerrain(Point p,
                       Terrain t)

setTerrain

public void setTerrain(int x,
                       int y,
                       Terrain t)
Description copied from interface: GameMap
Sets (or removes) the terrain at the specified map location.

Specified by:
setTerrain in interface GameMap
Parameters:
x - the map location x coordinate
y - the map location y coordinate
t - the Terrain object to place there. If null, sets the terrain at that location to the default terrain for the map.

updateTerrainCache

public void updateTerrainCache(int x,
                               int y,
                               int w,
                               int h)
Description copied from interface: GameMap
Call this whenever you change the appearance of a particular piece of terrain. You'll know when you need to call it, since the map view won't update properly with the terrain's new appearance. Called automatically when you do setTerrain(), so it's only required if you change a terrain's appearance, layer, priority, or whether it lets borders in/out.

Specified by:
updateTerrainCache in interface GameMap
Parameters:
x - map x coordinate where the terrain is located
y - map y coordinate where the terrain is located
w - the width of the rectangle to update (usually 1)
h - the height of the rectangle to update (usually 1)

getTerrainRecord

public int getTerrainRecord(int x,
                            int y)
Description copied from interface: GameMap
Returns a packed record describing the terrain at (x, y), suitable for use in drawing terrain borders.

Specified by:
getTerrainRecord in interface GameMap
Parameters:
x - the map x coordinate
y - the map y coordinate
Returns:
A bitfield describing the terrain. The low 16 bits are the terrain tile number. Bits 17-28 are the terrain priority, a signed number. (Bit 28 is the sign bit). Bit 29 is the "has-borders" flag; true if the terrain has borders. Bit 30 is the "lets-in" flag: set if the terrain permits borders to encroach into it, clear if the square disallows incoming borders even from higher-priority squares. Bit 31 is the "lets-out" flag: set if the square wants to extend borders (only meaningful if the terrain type actually has borders), clear if the square doesn't want to use any borders it might normally have.

Here's a picture of it:

          +-------------------------------+
          |1|1|1| 13 bits  |   16 bits    |
          +-------------------------------+
          /         |            |
      border      layer         tile
       flags     priority       number

 

getTerrainRecord

public int getTerrainRecord(int x,
                            int y,
                            boolean useCache)
Retrieves a terrain record, either by going out and building it, or by looking in the cache.

Parameters:
x - map x
y - map y
useCache - true to look in the cache, false to re-compute the terrain record (only used for updating the cache, of course)

findAt

public GameObject findAt(Point loc,
                         Predicate p)

findAt

public GameObject findAt(Point loc,
                         java.lang.String name)

findAt

public GameObject findAt(int x,
                         int y,
                         java.lang.String name)

findAt

public GameObject findAt(int x,
                         int y,
                         Predicate p)
Description copied from interface: GameMap
Looks for an object at the passed map location that passes the specified Predicate. It DOES check the terrain at the passed location, so it may return a terrain object if that's the first object that passes the predicate.

Specified by:
findAt in interface GameMap
Parameters:
x - map x
y - map y
p - a Predicate to filter the objects at (x, y)
Returns:
the first object at (x, y) for which the predicate returns true, or null if none returned true
See Also:
Predicate

findUnder

public GameObject findUnder(GameObject obj,
                            Predicate filter)
Description copied from interface: GameMap
Looks under the passed GameObject's locations for an object that matches the passed Predicate. Uses the same rules as findAt().

Specified by:
findUnder in interface GameMap
Parameters:
obj - the object to look under
filter - the Predicate for looking for a particular object
Returns:
the first GameObject under obj that matches the predicate, or null if none was found

isEmpty

public boolean isEmpty(Point p)

isEmpty

public boolean isEmpty(int x,
                       int y)
Description copied from interface: GameMap
Returns true if there's nothing in the map at the passed location except terrain.

Specified by:
isEmpty in interface GameMap
Parameters:
x - x location
y - y location
Returns:
true if there are no objects at this location

visitObjectsAt

public void visitObjectsAt(int x,
                           int y,
                           Visitor v)
Description copied from interface: GameMap
Performs an operation on a set of objects at the specified location. This is done by passing a Visitor object, which decides (for each object) whether to perform the operation. It visits the terrain at the passed location first, then the objects (if any).

Specified by:
visitObjectsAt in interface GameMap
Parameters:
x - x location
y - y location
v - the Visitor to send to each object at location (x, y)
See Also:
Visitor

findInRect

public GameObject findInRect(int x,
                             int y,
                             int w,
                             int h,
                             Predicate p)
Description copied from interface: GameMap
Searches the objects in the specified rectangle and returns the first one that satisfies the passed Predicate. Uses the same rules as findAt().

Specified by:
findInRect in interface GameMap
Parameters:
x - x (world coordinates)
y - y (world coordinates)
w - rectangle width
h - rectangle height
p - a Predicate filter to check each object in turn.
See Also:
Predicate

getObjectsAt

public java.util.List getObjectsAt(int x,
                                   int y)
Description copied from interface: GameMap
Returns a list of the objects at a location. Game code should *never* modify this list unless it has the implicit "map exclusive" (only obtained when the kernel calls a Command's handleEvent method).

Specified by:
getObjectsAt in interface GameMap
Parameters:
x - map x coordinate
y - map y coordinate
Returns:
null if there are no objects there. Might include the terrain at that location, if it's non-default. Callers should not perform mutative operations on this list, as other threads may have iterators on the list.

getMusic

public Music getMusic()
Description copied from interface: GameMap
Returns the background music for this map. Looks for a "music" property, and if that isn't present, looks for the map's parent Area to see if it specifies a "music" property.

Specified by:
getMusic in interface GameMap
Returns:
a Soundtrack object representing the music to play for this map. Can be null if the map hasn't specified any music to play.

getRestartLoc

public Location getRestartLoc()
Description copied from interface: GameMap
Returns the restart-location for this map: where players teleport to when they die in this map. It should specify a chapel or save haven, preferably one that's always loaded and never resets.

Specified by:
getRestartLoc in interface GameMap
Returns:
the restart location for this map. Looks in the parent Area if not specified in a "restart-loc" property on the map. Can be null, in which case the World object figures out a default restart location for the map.

getArea

public Area getArea()
Description copied from interface: GameMap
Returns the parent Area for this map. If you put a

Specified by:
getArea in interface GameMap
Returns:
the Area for this map. Always non-null, but if the "area.arch" file wasn't present, or didn't have any properties, then the Area won't either.

getResource

public Resource getResource()
Description copied from interface: GameMap
Returns the Resource for this map, so you can query if it's a wiz map, how big it is, what the relative file path is, and so on.

Specified by:
getResource in interface GameMap
Returns:
a Resource describing the file this map was loaded from. Always non-null. If the map was constructed dynamically, the Resource's exists() method will return false, since there's no corresponding disk file. It may have other accurate information, however.

add

public void add(int x,
                int y,
                GameObject obj)
Description copied from interface: GameMap
Adds the specified object to the map at the specified location.

Adding the same object to a position it already occupies is not recommended, but it's not explicitly prevented, either.

This method will attempt to add the object to *some* map, even if the requested position is out of this map's bounds. Typically this is handled by passing the request up to the map's parent, which finds the right place to put the object. If for some reason the object simply can't be placed at (x, y), an ArrayIndexOutOfBoundsException results.

This method will invalidate the map using the bounds of the passed object. It's the same as calling add(x, y, obj, true).

Specified by:
add in interface GameMap
Parameters:
x - the map location x coordinate
y - the map location y coordinate
obj - the GameObject to add to the map at (x, y)
See Also:
GameObject

addPlayer

protected void addPlayer(Player p)
Called whenever a Player is added to the map.


addMonster

protected void addMonster(Monster mon)
Called whenever a non-Player Monster is added to the map.


addTeleporter

protected void addTeleporter(Teleporter t)
Called whenever a teleporter is added to the map. Teleporter may or may not have a destination.


getExits

public java.util.Set getExits()
Description copied from interface: GameMap
Returns the set of all teleporters in this map that happen to have destinations - even if the teleporter's destination is to another point in this map.

Specified by:
getExits in interface GameMap
Returns:
a Set containing references to all the teleporters in this map. May be empty, but will never be null. The set is a *copy* of the map's internal teleporter set, so you are free to modify it if you wish - however, it will have no effect on the actual map.

remove

public void remove(int x,
                   int y,
                   GameObject obj)
Description copied from interface: GameMap
Removes an object reference at the specified map location (x, y).

Note: this is -not- the correct way to remove most objects from a map.

This method will remove the requested object no matter what kind of object it is (e.g. spell effect, static object), with one exception: it will not remove the default Terrain object at (x, y). You can try, but it won't work - there always has to be a Terrain object at each location, so if the location is empty, the game will use the default terrain for the map. This method automatically invalidates the map at each location the object occupies. If you want to remove it without invalidating the map (which would be weird, because everyone would think it was still there), you'd have to to call map.remove(x, y, obj, false).

Specified by:
remove in interface GameMap
Parameters:
x - the map location x coordinate
y - the map location y coordinate
obj - the object at (x, y) to remove.
See Also:
GameObject

trackSpecialRemoves

protected void trackSpecialRemoves(GameObject obj)

removePlayer

protected void removePlayer(Player player)
Removes a reference to a player from the map. Called once for each position the player occupies when the player is removed from the map (or moved/teleported). If the player is leaving the map, and it's the last player out, sets a suspend timer.

Parameters:
player - a reference to the Player being removed

removeTeleporter

protected void removeTeleporter(Teleporter t)
Called when a Teleporter is removed from a map.


removeFirst

public GameObject removeFirst(int x,
                              int y,
                              Predicate p)
Description copied from interface: GameMap
Removes and returns the first object that satisfies the passed Predicate.

Specified by:
removeFirst in interface GameMap
Parameters:
x - the map location x coordinate
y - the map location y coordinate
p - the Predicate to filter the object. Returns null if no objects at (x, y) satisfy the predicate.
See Also:
Predicate, GameObject

addPlayerListener

public void addPlayerListener(MapPlayerListener listener)
Description copied from interface: GameMap
Registers with the map to be notified whenever players enter or leave the map, or move within the map. This is faster and more specific than using registerAddRemoveListener(), if you're only interested in players moving around in the map.

Specified by:
addPlayerListener in interface GameMap
Parameters:
listener - the MapPlayerListener

removePlayerListener

public void removePlayerListener(MapPlayerListener listener)
Description copied from interface: GameMap
Removes an MapPlayerListener from this map.

Specified by:
removePlayerListener in interface GameMap
Parameters:
listener - the MapPlayerListener

notifyPlayerListeners

public void notifyPlayerListeners(int type,
                                  Player player,
                                  Point source)
Description copied from interface: GameMap
Don't call this. Used by game engine only.

Specified by:
notifyPlayerListeners in interface GameMap

addMapLifecycleListener

public void addMapLifecycleListener(MapLifecycleListener l)
Description copied from interface: GameMap
Registers with the map to be notified whenever it loads, unloads, suspends, or resumes. Normally you don't need to call this. Just have your object implement the MapLifecycleListener interface, and it'll automatically start receiving the events after it's added to the map.

Specified by:
addMapLifecycleListener in interface GameMap
Parameters:
l - the MapLifecycleListener

removeMapLifecycleListener

public void removeMapLifecycleListener(MapLifecycleListener l)
Description copied from interface: GameMap
Removes a MapLifecycleListener from this map. You don't normally need to call this. Simply removing/destroying the object will remove it from the listener list. However, if you have a MapLifecycleListener that's not a MapObject sitting in the map, you'll need to call this method when you want it to stop receiving the map events.

Specified by:
removeMapLifecycleListener in interface GameMap
Parameters:
l - the MapLifecycleListener

fireMapLoaded

protected void fireMapLoaded()

fireMapUnloaded

protected void fireMapUnloaded()

fireMapSuspended

protected void fireMapSuspended()

fireMapResumed

protected void fireMapResumed()

getHooks

public java.lang.String[] getHooks()
Description copied from interface: Hookable
Returns a list of custom hooks implemented by this object.

The list doesn't include names of default hooks for built-in commands.

Specified by:
getHooks in interface Hookable
Returns:
an array of names for custom hooks that the object defines. For example, if a Hookable had a Foo operation that it wanted to run pre- and post-hooks for, and no other hookable operations, this method would return an array of two strings:
  • "fooPreHook"
  • "fooPostHook"
Returns an empty string array if this object has no custom hooks.

getHookList

public HookList getHookList()
Description copied from interface: Hookable
Returns the HookList containing the registered hooks for this object.

Specified by:
getHookList in interface Hookable

getRoomHookList

public RoomHookList getRoomHookList()
Description copied from interface: GameMap
Returns the RoomHookList containing the registered room-hooks for this map.

Specified by:
getRoomHookList in interface GameMap
Returns:
the RoomHookList for room map hooks for this map, or null if no room hooks have been registered yet. The RoomHookList is instantiated lazily.

getProximityHookList

public ProximityHookList getProximityHookList()
Description copied from interface: GameMap
Returns the ProximityHookList containing the registered proximity-hooks for this map.

Specified by:
getProximityHookList in interface GameMap
Returns:
the ProximityHookList for proximity-hooks for this map, or null if no proximity-hooks have been registered. The ProximityHookList is instantiated lazily.

addHook

public void addHook(HookCallback callback,
                    java.lang.String hookName)
Description copied from interface: Hookable
Registers a HookCallback object for the specified hook.

The reserved pseudo-command "any" is reserved for callbacks that need to get every single command that comes through the queue. This should very rarely be necessary, and can hurt overall game performance considerably if abused.

Specified by:
addHook in interface Hookable
Parameters:
callback - the HookCallback to notify when the hook is run.
hookName - the name of the hook list to register on.

removeHook

public void removeHook(HookCallback callback,
                       java.lang.String hookName)
Description copied from interface: Hookable
Removes a callback from a specified hook list.

Specified by:
removeHook in interface Hookable
Parameters:
callback - the HookCallback to remove from the list
hookName - the name of the hook list to unregister from.

runPreHook

public void runPreHook(CommandEvent event)
Description copied from interface: Hookable
Calls all objects registered for a particular event and gives them a chance to deal with the event before it happens.

Callbacks may veto the event, but it's still passed to any other callbacks on the list, and eventually to the Command. For callbacks, it typically doesn't really matter if the flag has been set by a previous callback; callbacks should do the same thing they would have done even if it wasn't vetoed, because the Command (or any other callback downstream) may un-veto it.

The callbacks may modify any of the event parameters. Callbacks aren't required to do rigorous checking of the validity of their changes. For example, a simple callback registered on a player's preMoveHook might change the direction in the MoveEvent randomly.

To prevent callbacks from generating illegal event parameters, the Command handling the event is implicitly the last hook on the list. Before executing the command it re-checks the preconditions to make sure the move is still legal, and if it isn't, it vetoes it and issues an error message. The message, of course, is a modifiable parameter of the event.

If a HookCallback wants to force an "illegal" event, it has to change the game state (in the agent, the map, the Command, or whatever) to make the move legal. For example, if the hook wants to make sure the player moves over a wall, the hook can set a property on the player (or the wall) that allows this move, before returning control to this method.

Specified by:
runPreHook in interface Hookable
Parameters:
event - a CommandEvent that has already run. Calling getVerb() should return the canonical verb for this command, such as "move" or "get". The verb is used to construct the hook name, by appending "PreHook" to the verb.

runPostHook

public void runPostHook(CommandEvent event)
Description copied from interface: Hookable
Notifies all the objects registered on this post-hook that the event completed successfully. Changing the event params will have no effect at this point.

Specified by:
runPostHook in interface Hookable
Parameters:
event - a CommandEvent that has already run. Calling getVerb() should return the canonical verb for this command, such as "move" or "get". The verb is used to construct the hook name, by appending "PostHook" to the verb.

runFailedPostHook

public void runFailedPostHook(CommandEvent event)
Description copied from interface: Hookable
Notifies all the objects registered on this post-hook that the command failed (for whatever reason). It's up to the CommandEvent subclass to provide more detailed information as to why it failed.

Changing the event parameters will have no effect at this point.

Specified by:
runFailedPostHook in interface Hookable
Parameters:
event - a CommandEvent that has failed for some reason. getVerb() should return the canonical verb for this command, such as "move" or "get". The verb is used to construct the hook name, by appending "FailedPostHook" to the verb.

addMethodHook

public void addMethodHook(MethodHookCallback callback,
                          java.lang.String methodName)
Description copied from interface: MethodHookable
Registers for the specified method-hook. Only a select few methods actually have hooks, and there is no checking done to make sure the hook name matches a real method on the target. Be sure to check the documentation for a hookable method to see what the hook name for that method is defined to be.

Specified by:
addMethodHook in interface MethodHookable
Parameters:
methodName - the name of the method to hook into
callback - the MethodHookCallback object to notify on the hook

removeMethodHook

public void removeMethodHook(MethodHookCallback callback,
                             java.lang.String methodName)
Description copied from interface: MethodHookable
Unregisters for the specified method-hook.

Specified by:
removeMethodHook in interface MethodHookable
Parameters:
methodName - the name of the method
callback - the MethodHookCallback object to notify on the hook

runMethodHook

public void runMethodHook(java.lang.String methodName,
                          java.lang.Object data)
Description copied from interface: MethodHookable
Runs the specific method hook.

Specified by:
runMethodHook in interface MethodHookable
Parameters:
methodName - the name of the method, e.g. "add"
data - any data to pass to the callbacks; can be null

addRoomHook

public void addRoomHook(RoomHookCallback callback,
                        java.lang.String hookName,
                        Rectangle room)
Description copied from interface: GameMap
Registers for a specific area of interest in the map. A "room" is any rectangular area; it doesn't have anything to do with walls per se.

Specified by:
addRoomHook in interface GameMap
Parameters:
callback - the RoomHookCallback to notify when the hook is run.
hookName - the name of the hook list to register on
room - the rectangle to listen in. Events outside the rectangle are not passed to the callback object.

removeRoomHook

public void removeRoomHook(RoomHookCallback callback,
                           java.lang.String hookName,
                           Rectangle room)
Description copied from interface: GameMap
Removes a callback from the specified room-hook.

Specified by:
removeRoomHook in interface GameMap
Parameters:
callback - the RoomHookCallback to remove from the list
hookName - the name of the hook list to unregister from rectangle are not passed to the callback object.
room - the room which the callback was interested in. It is necessary to pass the room so that if the callback was registered for more than one room, the map will know which room to remove it from.

addProximityHook

public void addProximityHook(ProximityCallback callback,
                             java.lang.String hookName,
                             GameObject target,
                             Rectangle range)
Description copied from interface: GameMap
Registers for hook notifications for events occurring within a fixed range of a given object. This is useful for objects that move about in the map. For fixed objects it's faster to register on a room-hook.

A proximity-hook is implemented by placing the target object within the passed range rectangle. The rectangle is translated to the target's reference location, which for rectangular targets is almost always its upper-left corner.

For example, to register interest in the 8 squares surrounding a 1x1 monster, pass a range of (-1, -1, 3, 3). If the monster is currently at (5, 5), the proximity area will extend from (4, 4) to (6, 6).

Specified by:
addProximityHook in interface GameMap
Parameters:
callback - the HookCallback to notify when the hook is run.
hookName - the name of the hook list to register on
target - the roaming object at the center of the range. May be the same as the callback object.
range - the local coordinates around the target object that define the bounding box of interest.

removeProximityHook

public void removeProximityHook(ProximityCallback callback,
                                java.lang.String hookName,
                                GameObject target,
                                Rectangle range)
Description copied from interface: GameMap
Removes a callback from the specified proximity-hook.

Specified by:
removeProximityHook in interface GameMap
Parameters:
callback - the HookCallback to remove from the list
hookName - the name of the hook list to unregister from rectangle are not passed to the callback object.
target - the roaming object at the center of the range. May be the same as the callback object.
range - the local coordinates around the target object that define the bounding box of interest. The range needs to be passed in case the target was registered for hooks in more than one range.

registerCommand

public void registerCommand(java.lang.String command,
                            Command handler,
                            Rectangle room)
Description copied from interface: GameMap
Whenever someone enters a command that isn't in their local command-list, the game engine passes the command to the agent's GameMap to see if anyone has registered the command with the map itself.

For instance, the Shop object registers the "list" command with the map the Shop is in. Whenever a player types "list" in a Shop, and "list" isn't a command registered in their local command-list (usually it isn't), then the game engine checks whether someone has registered the command with the map the player is in, and if so, invokes that Command to handle it (via the Command's createEvent and execute methods).

Specified by:
registerCommand in interface GameMap
Parameters:
command - the command to handle
handler - the callback object to handle the command
room - the map sub-rectangle in which to register interest. It can be the entire map bounds if the handler wants to handle the command no matter where the agent is. The rectangle is clipped against the map bounds, so it's not an error if it specifies an area outside the map bounds. (Optionally, you can pass null to use the map bounds).

unregisterCommand

public void unregisterCommand(java.lang.String command,
                              Command handler,
                              Rectangle room)
Description copied from interface: GameMap
Removes the specified Command from the map's command-list. The Command may be registered for the command in multiple rectangles in the same map, so you need to pass in the rectangle that was passed to registerCommand().

Specified by:
unregisterCommand in interface GameMap
Parameters:
command - the command to unregister
handler - the handler to unregister
room - the map sub-rectangle to unregister (Optionally, you can pass null to use the entire map bounds).

getCommand

public Command getCommand(CommandEvent event,
                          Commandable agent)
Description copied from interface: GameMap
Checks the list of Commands who have registered this command with the map, and returns the first one whose rectangle of interest contains the agent issuing the command. Also checks the ground beneath the agent for a Command object that claims to know the command, even if it's not registered for it. (This is for the convenience of movable objects that don't want to have to register with the map every time they move).

Specified by:
getCommand in interface GameMap
Parameters:
event - the event to look for a handler for
agent - the agent doing the command
Returns:
a Command to handle the command, or null if no Command was registered for that command where the agent is at.

invalidate

public void invalidate(int x,
                       int y,
                       int width,
                       int height)
Description copied from interface: GameMap
Forces the map to refresh a particular area. Called automatically when an object is added, removed or moved in the map. Also called by GameObject.setBitmap(). Clients should call it whenever they cause part of the map to change its appearance using some mechanism the map isn't aware of.

Specified by:
invalidate in interface GameMap
Parameters:
x - the left side of the update rectangle
y - the right side of the update rectangle
width - the width of the update rect
height - the height of the update rect

enableVisUpdates

public void enableVisUpdates(boolean enable)
Description copied from interface: GameMap
While the map is being loaded; that is, while objects are initially being added to it, turning off visual updates will improve the load time. Normally you don't have to call this - the MapLoader will do it automatically for you. If you're creating a map on the fly, consider disabling updates after calling the constructor, and re-enabling them when you've added the initial set of objects to the map.

Caution: if you accidentally leave updates off, changes to the map won't get propagated to the cameras, and players in the map will have a "frozen" map display.

Specified by:
enableVisUpdates in interface GameMap
Parameters:
enable - true to turn on updates, false to turn them off

visUpdate

public void visUpdate(GameObject obj)
Description copied from interface: GameMap
Forces the map to refresh a particular area. Called automatically when an object is added, removed or moved in the map. Also called by GameObject.setBitmap(). Clients should call it whenever they cause part of the map to change its appearance using some mechanism that the map isn't aware of.

Specified by:
visUpdate in interface GameMap
Parameters:
obj - the GameObject whose appearance has changed. Its bounds (via getBounds()) will be used to determine the update region.

getUpdateList

public MapDirtyRegions getUpdateList()
Description copied from interface: GameMap
Returns a list of updates that have occurred since the last query.

Specified by:
getUpdateList in interface GameMap
Returns:
the update list, which is then set to a new, blank list

toString

public java.lang.String toString()
Description copied from class: PList
Returns a string representation of this PropertyList. Doesn't include any inherited properties. Uses transient values of properties - for int properties, adds transient value (if any) to persistent value before printing it.

Overrides:
toString in class PList
Returns:
a debugging string

getPath

public java.lang.String getPath()
Description copied from interface: GameMap
Returns the (relative) path to the map file this map was loaded from, e.g. "aston/town1/chapel". For maps that were constructed on the fly, it returns a name suitable for retrieving the map by calling World.getMap().

Specified by:
getPath in interface GameMap

getVirtualPath

public java.lang.String getVirtualPath()
Description copied from interface: GameMap
This is exactly the same as getPath() normal maps, but returns "players/whoever/" + getPath() for per-player maps.

Specified by:
getVirtualPath in interface GameMap
Returns:
the relative path for the map, with a prefix of "players/playername/" in front of the map path, if it's a per-player map.

setPerPlayer

public void setPerPlayer(java.lang.String name)
Description copied from interface: GameMap
Marks the map as being a per-player map. You should never have to call this function - it's invoked after a map is loaded using a per-player teleporter. It sets the virtual path to "players/" + name + "/" + getPath().

Specified by:
setPerPlayer in interface GameMap
Parameters:
name - the player name for whom this map is unique

isPerPlayer

public boolean isPerPlayer()
Description copied from interface: GameMap
Returns true if this map is a per-player map, meaning it was loaded by a teleporter with the "per-player" property. It means that each player winds up in his/her own copy of the map. For per-player maps, the path obtained from getPath() is the same as it is for global maps. The "virtual path", obtained via getVirtualPath(), has "players/{playername}/" prepended in front of the map path. Per-player map instances are stored in the World list by their virtual paths, so you could have, for example, "players/joe/village/tutorial" and "players/sheila/village/tutorial" in the World map list.

Specified by:
isPerPlayer in interface GameMap
Returns:
true if this is a per-player map

setPath

public void setPath(java.lang.String path)
Description copied from interface: GameMap
Sets the path to the map. For maps created dynamically with no map-file representation, this can be anything at all, such as the name of the map. It needs to be unique among all maps that can be loaded by a given server.

This method is typically only used for maps that are created dynamically by some other means than reading them from a map file.

Specified by:
setPath in interface GameMap
Parameters:
path - the new path to the map.

findTop

public GameObject findTop(int x,
                          int y)
Description copied from interface: GameMap
Returns the "topmost" object at this location. That is, it visits all the objects at the location and returns the one whose getLayer() returns the highest number. If there is a tie, it returns the object with the highest hashcode, which is consistent with the way objects are rendered in displays of the map.

Specified by:
findTop in interface GameMap
Parameters:
x - the map x location
y - the map y location
Returns:
the "top" object at that location

findTop

public GameObject findTop(Point p)

findTop

public GameObject findTop(int x,
                          int y,
                          Predicate p)
Description copied from interface: GameMap
Returns the topmost object at the specified location that passes a specified predicate. "Top" is defined as for the overloaded findTop() method that takes no predicate parameter.

Specified by:
findTop in interface GameMap
Parameters:
x - the map x location
y - the map y location
p - the predicate to use: returns true if it likes the object
Returns:
the "top" object at that location that passes the predicate, or null if no object there passes the predicate

findByName

public GameObject findByName(Point p,
                             java.lang.String name)
Description copied from interface: GameMap
Returns the topmost visible object at the passed location.

Specified by:
findByName in interface GameMap
Parameters:
p - the map (x, y) coordinates
name - the name to match
See Also:
GameMap.findByName(int, int, java.lang.String)

findByName

public GameObject findByName(int x,
                             int y,
                             java.lang.String name)
Description copied from interface: GameMap
Finds the first object at the specified location that matches the passed name, using a standard NameMatchPredicate.

Specified by:
findByName in interface GameMap
Parameters:
name - the name to match
x - the x location to look at
y - the y location to look at
Returns:
the first matching object at (x, y) or null if none found

getDangerLevel

public int getDangerLevel()
Description copied from interface: GameMap
Returns the danger level for this map. Danger level is stored in an int property on the map called "danger-level". However, the int property doesn't exist on all maps, for backwards-compatibility reasons, so a level of zero should be interpreted to mean danger level 1. If you call this function, it will return a value of 1 if the underlying property's value is zero or one.

Specified by:
getDangerLevel in interface GameMap
Returns:
the map's danger level (1-20)

setDangerLevel

public void setDangerLevel(int level)
Description copied from interface: GameMap
Sets the danger level for this map. You can set it to higher than 20, but some functions in the game will treat a number higher than 20 as equivalent to 20.

Specified by:
setDangerLevel in interface GameMap
Parameters:
level - the new danger level (1-20)

getClaim

public Player getClaim()
Description copied from interface: GameMap
Returns the player currently claiming the map, if any.

Specified by:
getClaim in interface GameMap
Returns:
a player claiming the map, or null if there's no claim on the map

findFreeSpot

public Point findFreeSpot(Point request,
                          GameObject obj)
Description copied from interface: GameMap
Tries to find a free spot to put this object in. Uses a standard BlockingPredicate to decide whether a spot is available.

Specified by:
findFreeSpot in interface GameMap
Parameters:
request - preferred map location
obj - the object to add to the map
Returns:
a free spot to put the object in, as near as possible to the requested location. Stops at max radius of 20 from requested location. Returns null if couldn't find a spot.

findFreeSpot

public Point findFreeSpot(int x,
                          int y,
                          GameObject obj)

addLight

public void addLight(int x,
                     int y,
                     LightSource light)
Description copied from interface: GameMap
Adds a light source to the map. The map will call the LightSource back to get its intensity array, so before calling this method, the LightSource should already have computed the array.

Specified by:
addLight in interface GameMap
Parameters:
x - the x location of the light source
y - the y location of the light source
light - the light source

removeLight

public void removeLight(int x,
                        int y,
                        LightSource light)
Description copied from interface: GameMap
Removes a light source from the map. The map will immediately call the LightSource back, asking for its intensity array, so that the map can subtract the intensity contribution of the LightSource from its global lighting array. Therefore it's important that the LightSource's intensity be valid when calling removeLight().

Specified by:
removeLight in interface GameMap
Parameters:
x - the x location of the light source
y - the y location of the light source
light - the light source

isLit

public boolean isLit()
Description copied from interface: GameMap
Returns true if the map is completely lit, e.g. by daylight. No lighting effects will be computed if the map is lit. By default, maps are lit. If a map has a property called "dark", then this method returns false.

Specified by:
isLit in interface GameMap
Returns:
true if the map is lit, so light sources have no effect

setLit

public void setLit(boolean lit)
Description copied from interface: GameMap
Marks the map as having lighting effects, or not.

Specified by:
setLit in interface GameMap
Parameters:
lit - true if the map is completely lit, false if it's dark

getLightingLevel

public int getLightingLevel()
Description copied from interface: GameMap
Returns the lighting level of this map. For lit maps, this returns the value for daylight. For darkened maps, it returns the value of the int property "ambient", which like all int properties defaults to zero if not present. A negative value will make the map extra-dark; e.g. a -1 will make a torch's illumination radius smaller by 1.

Specified by:
getLightingLevel in interface GameMap
Returns:
the ambient lighting level for the map

setLightingLevel

public void setLightingLevel(int ambient)
Description copied from interface: GameMap
Sets the global, ambient lighting level for the map. Not normally set directly (except by the night/day code), but it's possible that a spell might want to adjust the overall map lighting level, which is why this method is provided.

Specified by:
setLightingLevel in interface GameMap
Parameters:
ambient - the new ambient lighting level for the map

getLightLevel

public int getLightLevel(int x,
                         int y)
Description copied from interface: GameMap
Returns the lighting level at the specified location. Takes into account the ambient (overall) intensity, as well as contributions from any local light sources. This is used, for instance, by the camera system to decide how dark to draw the square.

Specified by:
getLightLevel in interface GameMap
Parameters:
x - map x location
y - map y location
Returns:
the cumulative lighting level at (x, y). If zero or negative, the square is completely dark.

resetOpaqueFlag

public void resetOpaqueFlag(Point p)

resetOpaqueFlag

public void resetOpaqueFlag(int x,
                            int y)
Description copied from interface: GameMap
Tells the map to re-scan the specified location to see if there are any opaque objects there. If it finds that the current state is different from its cached state, it updates the cached state and notifes all the cameras and light sources to redo their raycasting.

Specified by:
resetOpaqueFlag in interface GameMap
Parameters:
x - map x location to rescan
y - map y location to rescan

isOpaque

public boolean isOpaque(int x,
                        int y)
Specified by:
isOpaque in interface wyvern.kernel.lighting.Obstructions

hasObstructions

public boolean hasObstructions(int x,
                               int y,
                               int w,
                               int h)
Specified by:
hasObstructions in interface wyvern.kernel.lighting.Obstructions

updateOpaque

protected void updateOpaque(int x,
                            int y,
                            boolean opaque)

recomputeLights

protected void recomputeLights(int x,
                               int y)

addIntensityArray

protected abstract void addIntensityArray(int x,
                                          int y,
                                          int[][] array,
                                          boolean add)
Calls the subclass to merge in (add or subtract) the contribution from a single LightSource into the subclass's internal lighting array.

Parameters:
x - the x location at which to apply the array
y - the y location at which to apply the array
array - the array to apply. The light source is typically centered in the array, but this method doesn't do any coordinate translation. If you pass (x=3, y=3) and an array where (width=5, height=5), the lighting will be updated in the map from locations (3, 3) to (8, 8).
add - true to add the local array; false to subtract it

adjustIntensity

public abstract void adjustIntensity(int x,
                                     int y,
                                     int intensity)
Manually adjusts the light intensity by a fixed amount at the passed (x, y) location. Useful for objects that want to manage their own illumination, or for tweaking an area of a map to be brighter or darker than the ambient intensity.

Specified by:
adjustIntensity in interface GameMap
Parameters:
x - the x location to adjust
y - the y location to adjust
intensity - the +/- amount by which to adjust the lighting level

broadcast

public void broadcast(java.lang.String msg)
Description copied from interface: GameMap
Broadcasts a message to every player in the map.

Specified by:
broadcast in interface GameMap
Parameters:
msg - the message to broadcast.

broadcast

public void broadcast(java.lang.String msg,
                      byte style)
Description copied from interface: GameMap
Broadcasts a message to every player in the map.

Specified by:
broadcast in interface GameMap
Parameters:
msg - the message to broadcast.
style - the RPCConstants.TextStyle to use
See Also:
RPCConstants

wakeMonsters

public void wakeMonsters(Point loc,
                         int range)
Description copied from interface: GameMap
Wakes up monsters near the specified point.

Specified by:
wakeMonsters in interface GameMap
Parameters:
loc - the point near which to wake monsters
range - the radius within which to wake them

wakeAllMonsters

public void wakeAllMonsters()
Description copied from interface: GameMap
Wakes up all the monsters in the map, e.g. if a loud noise occurred.

Specified by:
wakeAllMonsters in interface GameMap

addLocalArchetype

public void addLocalArchetype(Archetype arch)
Description copied from interface: GameMap
Adds a local archetype to this map. Usually called by the MapLoader or map editor. Local archetypes are used in maps to share properties among many objects specific to that map. For instance, a cave.map might want every terrain square to have the short description "cave floor". Rather than add a new system archetype for cave_floor, or add the property "cave floor" to every square in the map, we can create a local archetype inside the map and have all the terrain square refer to it.

As useful as they are for cutting down map sizes (both on disk and in-memory), we're not sure yet how to handle an instance of a local archetype moving out of its map, so be careful only to use local archetypes for immovable objects like walls and terrain.

Specified by:
addLocalArchetype in interface GameMap
Parameters:
arch - the local archetype to add to the cache. The name must be set via setName() before calling this method. If another archetype was already registered under this name, the previous archetype will be replaced by the new one.

getLocalArchetype

public Archetype getLocalArchetype(java.lang.String name)
Retrieves a local archetype from the map's cache.

Specified by:
getLocalArchetype in interface GameMap
Parameters:
name - the name, in the form "local/whatever".
Returns:
the archetype stored under that name in the map, or null if not found.
See Also:
GameMap.getLocalArchetype(java.lang.String)

removeLocalArchetype

public Archetype removeLocalArchetype(java.lang.String name)
Removes a local archetype from the map's cache.

Specified by:
removeLocalArchetype in interface GameMap
Parameters:
name - the name, in the form "local/whatever"
Returns:
the Archetype that was stored under that name, or null if there was none.
See Also:
GameMap.removeLocalArchetype(java.lang.String)

getLocalArchetypes

public java.util.List getLocalArchetypes()
Description copied from interface: GameMap
Returns a list of the names of all local archetypes registered with this map.

Specified by:
getLocalArchetypes in interface GameMap
Returns:
a List of String objects, which will be empty if there are no map-local archetypes in this map.

setFavorite

public void setFavorite(int index,
                        Archetype arch)
Description copied from interface: GameMap
Adds a "favorite" archetype to the map, for use in the map editor. The archetype will be displayed in the map editor for easy access. Favorites are saved out with the map and restored when the map is reloaded in the editor. Not really useful for Wizards, since it's an editor-specific function.

Specified by:
setFavorite in interface GameMap
Parameters:
index - the index in the favorites list to set it at
arch - the archetype to set; null to clear it

getFavorites

public java.util.Map getFavorites()
Description copied from interface: GameMap
Returns the set of favorite archetypes for this map, for use in the map editor. Not really useful for Wizards, since it's an editor-specific function.

Favorites are stored in the map file as string properties, where the property name is "favorite-n" (n being the index), and the property value is the path to the archetype. This method enumerates over the map's properties and retrieves any of them that match "favorite-n", and puts them in the return map.

Specified by:
getFavorites in interface GameMap
Returns:
a map whose keys are Integers corresponding to the index of each favorite in the map. The values are the paths generated by calling arch.provideName() for each favorite archetype in the map. Returns null if the map has no favorites set. We don't currently support saving out favorites with local properties - a favorite is just a reference to an existing archetype, either a system archetype or a wizard archetype.


getUnloadDelay

public int getUnloadDelay()
Description copied from interface: GameMap
Returns the time, in milliseconds, that we'll wait, after we suspend, before unloading the map.

Specified by:
getUnloadDelay in interface GameMap
Returns:
the number of milliseconds to remain suspended before unloading

setUnloadDelay

public void setUnloadDelay(int delay)
Description copied from interface: GameMap
Sets the amount of time to wait (in millis) after suspending before the map is unloaded.

Specified by:
setUnloadDelay in interface GameMap
Parameters:
delay - the length of time (in millis) to remain suspended

inMapEditor

public boolean inMapEditor()
Description copied from interface: GameMap
Returns true if we're being loaded in the map editor.

Specified by:
inMapEditor in interface GameMap

setAutoload

public void setAutoload()
Description copied from interface: GameMap
Tells the map that it was autoloaded. This sets a shorter unload delay than normal, since it's statistically less likely that someone will actually enter the map.

Specified by:
setAutoload in interface GameMap

wasAutoloaded

public boolean wasAutoloaded()

readData

public void readData(org.w3c.dom.Node bean)
              throws java.lang.Exception
Description copied from interface: SelfExternalizable
Tells the object to parse its externalized representation from a list of lines.

Specified by:
readData in interface SelfExternalizable
Parameters:
bean - the XML DOM representation of the externalized bean object. Its child could be a text node, in which case the bean has to do all the parsing for the data. It could also wrap a series of elements (e.g. archetypes), in which case the bean may wish to leverage the XML parsing utilities that the game provides in the ArchetypeManager.

Throws:
java.lang.Exception

writeData

public java.util.List writeData()
                         throws java.lang.Exception
Description copied from interface: SelfExternalizable
Tells the object to write its properties out to a text file.

Specified by:
writeData in interface SelfExternalizable
Returns:
a list of lines to be written to the text file, formatted appropriately. The lines include everything except the and tags, which are constructed and written automatically.
Throws:
java.lang.Exception

shouldWrite

public boolean shouldWrite()
Description copied from interface: SelfExternalizable
Allows the object to determine whether it wants to be written out at all. If the object determines that it's the equivalent of a null value (e.g. an item list with no items in it), it can return false and it won't go into the output file.

Specified by:
shouldWrite in interface SelfExternalizable
Returns:
true to write the object, false to skip it

dismantle

public int dismantle()
Description copied from interface: GameMap
Do NOT call this method - use World.unloadMap(mapname) instead, unless you have created the map yourself without registering it with the World. (E.g. a vehicle interior). Make sure there are no players in the map before calling this method; otherwise it will fail.

This method runs the method-hook "unload" before unloading the map.

Specified by:
dismantle in interface GameMap
Returns:
an UnloadMapConstants return value

startSuspendTimer

public void startSuspendTimer()

startUnloadTimer

public void startUnloadTimer()

startUnloadTimer

public void startUnloadTimer(int delay)

suspend

public void suspend()
Description copied from interface: GameMap
Tells the map to suspend itself. You probably shouldn't call it yourself. It gets called by a timer that's set when the map is first loaded, and also when the last player leaves the map. A suspended map stops all the monsters and timers in the map, and when it's resumed, the monsters start up again. The map is automatically resumed if a player enters the map.

The map runs the "suspend" method-hook on this call.

Specified by:
suspend in interface GameMap

isSuspended

public boolean isSuspended()
Description copied from interface: GameMap
Returns true if the map is currently suspended.

Specified by:
isSuspended in interface GameMap
Returns:
true if map is suspended (i.e. monsters, timers stopped)

getSuspendTime

public int getSuspendTime()
Description copied from interface: GameMap
Returns the length of time, in milliseconds, since this map was suspended. Returns -1 if the map isn't suspended.

Specified by:
getSuspendTime in interface GameMap
Returns:
suspend time

resume

public void resume()
Description copied from interface: GameMap
Resumes the map (if it was suspended.) If it was suspended the map will un-suspend and run the "resume" method hook.

Specified by:
resume in interface GameMap

unload

public void unload()
Description copied from interface: GameMap
Tells the map to unload. The map will not be unloaded if it has players in it. After the map is successfully unloaded, it runs a method-hook called "unload", with no data parameter.

Specified by:
unload in interface GameMap

isUnloaded

public boolean isUnloaded()
Description copied from interface: GameMap
Returns true if the map has started the unload process. It could be partially or completely unloaded, but in either case you should treat it as if it has been unloaded.

Specified by:
isUnloaded in interface GameMap
Returns:
true if this map has been unloaded

isMap

public boolean isMap()
Description copied from interface: Container
Returns true if this container is a GameMap.

Specified by:
isMap in interface Container
Returns:
true for maps, false for anything else

isBag

public boolean isBag()
Description copied from interface: Container
Returns true if this container is a Bag (or Inventory, or other implementation of the Bag interface).

Specified by:
isBag in interface Container
Returns:
true for bags and inventories, false for maps

isInventory

public boolean isInventory()
Description copied from interface: Container
Returns true if this container is an Inventory.

Specified by:
isInventory in interface Container
Returns:
true if it's an Inventory (returns false for bags and maps)

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Description copied from interface: GameMap
Adds a PropertyChangeListener to the listener list.

Specified by:
addPropertyChangeListener in interface GameMap

addPropertyChangeListener

public void addPropertyChangeListener(java.lang.String propertyName,
                                      java.beans.PropertyChangeListener listener)
Description copied from interface: GameMap
Adds a PropertyChangeListener for a specific property.

Specified by:
addPropertyChangeListener in interface GameMap

firePropertyChange

public void firePropertyChange(java.beans.PropertyChangeEvent evt)
Description copied from interface: GameMap
Fires an existing PropertyChangeEvent to any registered listeners. No event is fired if the given event's old and new values are equal and non-null.

Specified by:
firePropertyChange in interface GameMap
Parameters:
evt - the PropertyChangeEvent object

firePropertyChange

public void firePropertyChange(java.lang.String propertyName,
                               boolean oldValue,
                               boolean newValue)
Description copied from interface: GameMap
Reports a boolean bound property update to any registered listeners.

Specified by:
firePropertyChange in interface GameMap

firePropertyChange

public void firePropertyChange(java.lang.String propertyName,
                               int oldValue,
                               int newValue)
Description copied from interface: GameMap
Reports an int bound property update to any registered listeners.

Specified by:
firePropertyChange in interface GameMap

firePropertyChange

public void firePropertyChange(java.lang.String propertyName,
                               java.lang.Object oldValue,
                               java.lang.Object newValue)
Description copied from interface: GameMap
Reports a bound property update to any registered listeners.

Specified by:
firePropertyChange in interface GameMap

getPropertyChangeListeners

public java.beans.PropertyChangeListener[] getPropertyChangeListeners()
Description copied from interface: GameMap
Returns an array of all the PropertyChangeListeners added to this map with addPropertyChangeListener();

Specified by:
getPropertyChangeListeners in interface GameMap

getPropertyChangeListeners

public java.beans.PropertyChangeListener[] getPropertyChangeListeners(java.lang.String propertyName)
Description copied from interface: GameMap
Returns an array of all the listeners which have been associated with the named property.

Specified by:
getPropertyChangeListeners in interface GameMap

hasListeners

public boolean hasListeners(java.lang.String propertyName)
Description copied from interface: GameMap
Checks if there are any listeners for a specific property.

Specified by:
hasListeners in interface GameMap

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Description copied from interface: GameMap
Removes a PropertyChangeListener from the listener list.

Specified by:
removePropertyChangeListener in interface GameMap

removePropertyChangeListener

public void removePropertyChangeListener(java.lang.String propertyName,
                                         java.beans.PropertyChangeListener l)
Description copied from interface: GameMap
Removes a PropertyChangeListener for a specific property.

Specified by:
removePropertyChangeListener in interface GameMap

getProfilingInfo

public static java.lang.String getProfilingInfo()
Returns profiling string.