wyvern.lib.properties
Class MovableLightSource

java.lang.Object
  extended bywyvern.lib.properties.SimpleLightSource
      extended bywyvern.lib.properties.MovableLightSource
All Implemented Interfaces:
AddRemoveNotify, ContainerChangeListener, java.util.EventListener, LightingConstants, LightSource, MapChangeListener, MapMotionListener, MutableProperty, ObjectTracker, java.beans.PropertyChangeListener, SelfExternalizable

public class MovableLightSource
extends SimpleLightSource
implements AddRemoveNotify, ObjectTracker, java.beans.PropertyChangeListener, MutableProperty, SelfExternalizable

This property makes an object glow in the dark.

You can add one to any GameObject to turn it into a glowing object. The MovableLightSource will follow the target object around, moving the light with the object.

Wyvern's laws of physics are such that:

So the MovableLightSource has to track not only the target object, but anyone carrying the target, and anyone carrying the carrier, and so on. So it automatically supports, for example, a wizard carrying a pirate with a parrot on his shoulder with a torch in its mouth. The wizard will glow, and the light follows the wizard. If the parrot puts the torch in a bag, the light shuts off.

Version:
1.0, Feb 06, 1999
Author:
Steve Yegge

Field Summary
 
Fields inherited from class wyvern.lib.properties.SimpleLightSource
caster_, DEFAULT_LIGHT_SOURCE_INTENSITY, intensity_, localIntensity_, location_, map_, matrix_
 
Fields inherited from interface wyvern.lib.properties.LightingConstants
DARKNESS, DAYLIGHT, DIM, DUSK, GLOOM, NUM_SHADES, SHADED, TWILIGHT
 
Constructor Summary
MovableLightSource()
          Constructs a new MovableLightSource
MovableLightSource(int intensity)
          Constructs a new MovableLightSource with the specified intensity.
 
Method Summary
protected  void addToChain(GameObject obj)
          Starts tracking someone who picked up the top object in our tracking chain.
protected  void createChain()
          Creates the list for holding a carrier (or chain of carriers).
 java.lang.Object createClone()
          Clones the property so that instances get their own copy.
protected  GameObject getBaseObject()
          Returns the first object in the chain, e.g. the glowstones, or fire elemental, or lighting bolt spell piece, which contains this MovableLightSource in its property list.
protected  GameObject getCarrier(GameObject obj)
          Returns the carrier of a given object.
protected  GameObject getHeadObject()
          Returns the top (outermost) object in the chain.
protected  boolean isBeingCarried(GameObject obj)
          Returns true if the passed GameObject is currently in someone's inventory.
 void notifyAdd(PropertyList list)
          We've been added to a target object's property list.
 void notifyRemove(PropertyList list)
          Notifies the property that it's being removed from some GameObject's property-list.
protected  java.lang.String printChain()
          Returns a printout of the objects in the chain, from first (base) to last (head/top/outermost).
 void propertyChange(java.beans.PropertyChangeEvent event)
          Map lighting model turned on or off.
 void readData(org.w3c.dom.Node bean)
          We don't do anything.
protected  void removeFromChain(GameObject obj)
          Removes an object from the tracking chain, along with all of its parents going up the chain.
 boolean shouldWrite()
          Don't write the object out.
protected  void startTracking(GameObject obj)
          Adds motion and container listeners to the passed object.
protected  void stopTracking(GameObject obj)
          Removes motion/container listeners from the passed object.
 void targetEnteredContainer(ContainerChangeEvent event)
          An object we're tracking was added to a container.
 void targetEnteredMap(MapChangeEvent event)
          An object we're tracking entered a new map.
 void targetLeftContainer(ContainerChangeEvent event)
          A tracked object was removed from a container.
 void targetLeftMap(MapChangeEvent event)
          Notification that the target object has left its map.
 void targetMoved(MapMotionEvent event)
          Target object moved or teleported in its map.
 java.lang.String toString()
          Prints String representation.
 java.util.List writeData()
          Don't write anything out.
 
Methods inherited from class wyvern.lib.properties.SimpleLightSource
computeLocalIntensity, computeMatrix, getAlphaForLightLevel, getDistance, getIntensity, getLightMatrix, getLocation, getMap, getMatrixLocation, getShadingTile, main, recompute, remove, setIntensity, setLocation, setMap, setMap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MovableLightSource

public MovableLightSource()
Constructs a new MovableLightSource


MovableLightSource

public MovableLightSource(int intensity)
Constructs a new MovableLightSource with the specified intensity.

Parameters:
intensity - the intensity (radius) for the light source
Method Detail

notifyAdd

public void notifyAdd(PropertyList list)
We've been added to a target object's property list. We'll follow it around until we're removed again.

Specified by:
notifyAdd in interface AddRemoveNotify
Parameters:
list - the GameObject whose property list we're being added to

notifyRemove

public void notifyRemove(PropertyList list)
Notifies the property that it's being removed from some GameObject's property-list.

Specified by:
notifyRemove in interface AddRemoveNotify
Parameters:
list - the GameObject whose property list we're being removed from

targetEnteredContainer

public void targetEnteredContainer(ContainerChangeEvent event)
An object we're tracking was added to a container. If it's an inventory, start tracking the inv owner.

Specified by:
targetEnteredContainer in interface ContainerChangeListener

targetLeftContainer

public void targetLeftContainer(ContainerChangeEvent event)
A tracked object was removed from a container. Calls targetLeftBag() or targetLeftInv(), depending on the container type.

Specified by:
targetLeftContainer in interface ContainerChangeListener

targetEnteredMap

public void targetEnteredMap(MapChangeEvent event)
An object we're tracking entered a new map.

Specified by:
targetEnteredMap in interface MapChangeListener

targetLeftMap

public void targetLeftMap(MapChangeEvent event)
Notification that the target object has left its map. Called at the end of the object's remove() function.

Specified by:
targetLeftMap in interface MapChangeListener

targetMoved

public void targetMoved(MapMotionEvent event)
Target object moved or teleported in its map.

Specified by:
targetMoved in interface MapMotionListener

startTracking

protected void startTracking(GameObject obj)
Adds motion and container listeners to the passed object. Tracks any carrier(s) of the object as well.


stopTracking

protected void stopTracking(GameObject obj)
Removes motion/container listeners from the passed object.


createChain

protected void createChain()
Creates the list for holding a carrier (or chain of carriers). Returns if list already created.


addToChain

protected void addToChain(GameObject obj)
Starts tracking someone who picked up the top object in our tracking chain.


removeFromChain

protected void removeFromChain(GameObject obj)
Removes an object from the tracking chain, along with all of its parents going up the chain.


isBeingCarried

protected boolean isBeingCarried(GameObject obj)
Returns true if the passed GameObject is currently in someone's inventory.


getCarrier

protected GameObject getCarrier(GameObject obj)
Returns the carrier of a given object. You should call isBeingCarried() first.


getHeadObject

protected GameObject getHeadObject()
Returns the top (outermost) object in the chain.


getBaseObject

protected GameObject getBaseObject()
Returns the first object in the chain, e.g. the glowstones, or fire elemental, or lighting bolt spell piece, which contains this MovableLightSource in its property list.


propertyChange

public void propertyChange(java.beans.PropertyChangeEvent event)
Map lighting model turned on or off.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener

readData

public void readData(org.w3c.dom.Node bean)
              throws java.lang.Exception
We don't do anything. The MapObject class converts a "luminous" int property into an instance of MovableLightSource for us.

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
Don't write anything out.

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()
Don't write the object out. Change the "luminous" int property if you want to change the persistent representation of this object.

Specified by:
shouldWrite in interface SelfExternalizable
Returns:
false

createClone

public java.lang.Object createClone()
Clones the property so that instances get their own copy.

Specified by:
createClone in interface MutableProperty
Returns:
a new, uninitialized MovableLightSource

toString

public java.lang.String toString()
Prints String representation.

Overrides:
toString in class SimpleLightSource
Returns:
a String describing the light source

printChain

protected java.lang.String printChain()
Returns a printout of the objects in the chain, from first (base) to last (head/top/outermost).