wyvern.lib.classes
Class Terrain

java.lang.Object
  extended bywyvern.kernel.properties.PList
      extended bywyvern.kernel.maps.MapObject
          extended bywyvern.lib.classes.Terrain
All Implemented Interfaces:
Broadcaster, GameObject, MethodHookable, PropertyList
Direct Known Subclasses:
CheckerTile, Lava, RandomTerrain, TerrainRoad, Water

public class Terrain
extends MapObject

Common superclass for all Terrain objects.

If no bitmap is specified, a "color" property may store an int value from 0-255, corresponding to a Wyvern color palette entry. This color will be drawn for the terrain on the client. It's an easy way to produce solid-colored terrain in any of the available game colors. (Only works for 1x1 terrain).

Version:
1.0, Aug 20, 1997
Author:
Steve Yegge

Nested Class Summary
static interface Terrain.NoFlyweight
          Tagging interface that tells the MapLoader not to make this Terrain type a "flyweight".
 
Field Summary
protected  Appearance appearance_
           
protected  boolean hasBorders_
           
protected  boolean letsBordersIn_
           
protected  boolean letsBordersOut_
           
protected  boolean opaque_
          This is cached for performance - we don't support terrain changing from opaque to non-opaque at runtime; you'd have to write a subclass to handle this.
protected  int priority_
           
static java.util.HashMap terrainCache_
          The game-wide cache of flyweight terrain objects.
 
Fields inherited from class wyvern.kernel.maps.MapObject
IN_MAP_EDITOR, listenerList_
 
Fields inherited from class wyvern.kernel.properties.PList
readOnly_
 
Fields inherited from interface wyvern.lib.PropertyList
PROPERTY_PACKAGE
 
Constructor Summary
Terrain()
           
 
Method Summary
static Terrain getCachedTerrain(Archetype arch)
          Caches the passed Terrain-based archetype, if necessary, and returns the cached version.
 int getPriority()
          Returns the terrain priority for this object.
 int getTile(int xloc, int yloc)
          Returns the tile number for this object at this location.
 boolean hasBorders()
          Returns true if this terrain type has borders.
 void initialize()
          Adds those properties that make Terrain terrain.
 boolean isCached()
          Returns true if this terrain is cached (i.e. shared by multiple maps).
 boolean isOpaque()
          Returns whether this terrain is opaque.
 boolean isTerrain()
          This class (and its subclasses) are the only classes that return true for this method.
 boolean letsBordersIn()
          Returns true if this terrain type allows borders to encroach within its square.
 boolean letsBordersOut()
          Returns true if this terrain type has borders that extend outside its square.
 void setAppearance(java.lang.String path)
          The Appearance property ("image") is cached for Terrain, for performance reasons.
 void setHasBorders(boolean borders)
          Sets whether this terrain object uses borders or not.
 void setLetsBordersIn(boolean allow)
          Tells this terrain object to allow borders into its square.
 void setLetsBordersOut(boolean allow)
          Tells this terrain object to allow borders into its square.
 void setPriority(int priority)
          Sets the terrain-priority for this object.
 
Methods inherited from class wyvern.kernel.maps.MapObject
addContainerChangeListener, addDefaultProperty, addMapChangeListener, addMapMotionListener, addMethodHook, addMotionTracker, addObjectTracker, addPrefix, addSuffix, addToMap, bless, broadcast, broadcast, broadcast, broadcast, broadcast, canEnter, canEnterBlockedBy, canMove, canMove, canMoveBlockedBy, canMoveBlockedBy, canMoveTo, canMoveToBlockedBy, checkDrop, curse, cycleFrame, destroy, ensureListenerList, ensureWeight, externalize, fireContainerEntered, fireContainerExited, fireEnteredMap, fireExitedMap, fireMovedInMap, getAlpha, getAppearance, getArchetype, getBaseName, getBaseWeight, getBitmap, getBounds, getCanonicalClassName, getCategory, getContainer, getCreator, getDamagedDescription, getDescription, getDirection, getGenderPossessive, getGenderPronoun, getImage, getImageDescriptor, getImageDescriptors, getLayer, getLocations, getMap, getMapLink, getMaterial, getMaterialDescription, getMover, getOwningPlayer, getParentMap, getPrefixes, getQuantity, getReferenceLoc, getRelativeLocs, getShortDesc, getSuffixes, getTile, getValue, getWeight, groupString, inContainer, initLocs, inMapEditor, invalidate, invalidateImage, invalidateParent, invalidateText, isAnimated, isAttackable, isBlessed, isCommandable, isCursed, isDamned, isGroupable, isIdentified, isMonster, isMonsterOrPlayer, isPlayer, isUncursed, isUnpaid, isWizard, makeClone, markPaid, markUnpaid, move, occupies, positionAt, positionAtMap, remove, removeContainerChangeListener, removeFromMap, removeMapChangeListener, removeMapMotionListener, removeMethodHook, removeMotionTracker, removeObjectTracker, removePrefix, removeSuffix, runMethodHook, setAlpha, setAnimated, setBitmap, setCategory, setContainer, setDefaultBitmap, setDefaultCategory, setDefaultDesc, setDefaultImage, setDefaultIntProperty, setDefaultLayer, setDefaultMaterial, setDefaultProperty, setDefaultShortDesc, setDirection, setImage, setImage, setLayer, setLocations, setMap, setMapLink, setQuantity, setShape, setSize, setTransientSize, setWeight, setWeight, teleport, toString, updateMapLocation
 
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, getProfilingInfo, 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.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

opaque_

protected boolean opaque_
This is cached for performance - we don't support terrain changing from opaque to non-opaque at runtime; you'd have to write a subclass to handle this.


letsBordersIn_

protected boolean letsBordersIn_

letsBordersOut_

protected boolean letsBordersOut_

hasBorders_

protected boolean hasBorders_

priority_

protected int priority_

appearance_

protected Appearance appearance_

terrainCache_

public static java.util.HashMap terrainCache_
The game-wide cache of flyweight terrain objects.

Constructor Detail

Terrain

public Terrain()
Method Detail

initialize

public void initialize()
Adds those properties that make Terrain terrain.

Specified by:
initialize in interface GameObject
Overrides:
initialize in class MapObject

getCachedTerrain

public static Terrain getCachedTerrain(Archetype arch)
Caches the passed Terrain-based archetype, if necessary, and returns the cached version.

Parameters:
arch - an archetype that returns Terrain.class from loadClass()
Returns:
a flyweight Terrain object

setAppearance

public void setAppearance(java.lang.String path)
The Appearance property ("image") is cached for Terrain, for performance reasons. If you want to change a Terrain object's appearance at runtime, you have to call this method

Parameters:
path - the image path

getTile

public int getTile(int xloc,
                   int yloc)
Returns the tile number for this object at this location. We override the MapObject implementation because our position is (or at least can be) without meaning.

Specified by:
getTile in interface GameObject
Overrides:
getTile in class MapObject
Parameters:
xloc - the x position to query (ignored)
yloc - the y position to query (ignored)
Returns:
the tile number to draw

getPriority

public int getPriority()
Returns the terrain priority for this object.

The priority is used by the terrain-border code to figure out, given 2 adjacent, unlike terrain squares A and B, whether A should extend borders into B or vice-versa. The one with the higher priority gets to extend borders into the other.

In general, terrain archetypes are assigned a priority that starts at 0 for sea-level and goes up as the ground gets higher, so mountains tend to have the highest priority.

Negative priorities are allowed. The standard priority range is -1000 to 1000; anything outside this range will *probably* result in the terrain always or never extending borders, unless its neighbors also have priorities outside the range. All the standard game terrain archetypes have a priority in the standard range.

Returns:
the terrain priority

setPriority

public void setPriority(int priority)
Sets the terrain-priority for this object.

Parameters:
priority - the new terrain priority

letsBordersIn

public boolean letsBordersIn()
Returns true if this terrain type allows borders to encroach within its square.

Returns:
true if we let borders in

setLetsBordersIn

public void setLetsBordersIn(boolean allow)
Tells this terrain object to allow borders into its square.

Parameters:
allow - true to allow borders in, false to prevent them

letsBordersOut

public boolean letsBordersOut()
Returns true if this terrain type has borders that extend outside its square. Usually terrain with borders has this, but it can be overridden on an object-by-object basis.

Returns:
true if we let borders out

setLetsBordersOut

public void setLetsBordersOut(boolean allow)
Tells this terrain object to allow borders into its square.

Parameters:
allow - true to allow borders out, false to prevent them

hasBorders

public boolean hasBorders()
Returns true if this terrain type has borders.


setHasBorders

public void setHasBorders(boolean borders)
Sets whether this terrain object uses borders or not.

Parameters:
borders - true to use them, false not to. If there are no border images created for this terrain type, the setting has no effect.

isOpaque

public boolean isOpaque()
Returns whether this terrain is opaque.


isTerrain

public final boolean isTerrain()
This class (and its subclasses) are the only classes that return true for this method.

Specified by:
isTerrain in interface GameObject
Overrides:
isTerrain in class MapObject
Returns:
true

isCached

public final boolean isCached()
Returns true if this terrain is cached (i.e. shared by multiple maps). Cached terrain's getMap() method always returns null.