wyvern.lib.classes
Class Lamp

java.lang.Object
  extended bywyvern.kernel.properties.PList
      extended bywyvern.kernel.maps.MapObject
          extended bywyvern.lib.classes.Lamp
All Implemented Interfaces:
Applyable, Broadcaster, Command, GameObject, MethodHookable, PropertyList, Timed

public class Lamp
extends MapObject
implements Timed, Command, Applyable

Superclass of all "standard" light sources: torches, lanterns, campfires, etc. Basically anything whose sole purpose in life is to be a light source can extend from this class to get features like turning on & off, modifying its description, having fuel types and being refuelable, etc. All this behavior is controlled by properties examined by Lamp.class.

Note: the code for emitting light is in wyvern.lib.properties.MovableLightSource.class. MovableLightSource is an intelligent property that you can add to any GameObject to make it emit light. However, MovableLightSource doesn't give you the ability to turn its target object on & off, and it doesn't consume any fuel. To get that behavior you have to use Lamp.class. If you can't extend Lamp (e.g. you want a refuelable magical sword), you'll have to cut & paste the Lamp code. Eventually we'd like to encapsulate fuel consumption into another intelligent property.

Properties for configuring Lamps:


  can-turn-on:  lamp can be turned on (default "light ")
  can-turn-off:  lamp can be turned off (default ("extinguish ")

  turn-on-cmd:  command to use to light it, e.g. "light", "ignite"
  turn-off-cmd: command to use to extinguish it, e.g. "extinguish", "snuff"

  fuel-type:  a string indicating the type of fuel the light
	takes, e.g. "wood".  Default:  none - the source has
	no fuel supply and never runs out.

  burn-rate:  an integer specifying how frequently (in millis)
		to deduct fuel-units from the lamp's fuel supply.

  fuel-units:  how many units to deduct each time the burn-rate
		 timer expires.  Default:  1.

  fuel-level:  how much fuel the source currently has in it.

  max-fuel:  the maximum number of fuel units the lamp can hold.

  low-msg:  a message to display when the lamp is low on fuel.
	      Default:  no message is displayed.
  out-msg:  a message to display when the lamp runs out of fuel.
	      Default:  no message is displayed.
  dead-msg: a message to display when you try to light it when out of fuel.
	      Default:  no message is displayed.

  low-level: specifies the low-level threshold where a warning
  	       is issued and the intensity may be reduced.

  low-fuel-int:  the intensity level to give the lamp's light
  source when the fuel reaches the "low" point, if specified.
  When the lamp is out of fuel, intensity is always zero.

  on:	specifies that the lamp is initially ON.  If fuel-level
  is zero, the lamp will turn off when it's constructed.

  off: specifies that the lamp is initially OFF.  This is
  the default, unless the lamp can't be turned off.

  intensity:  base intensity of the light source - this property
 		is transferred to the LightSource property.

  light: the LightSource property to use.  If none is specified,
	   a MovableLightSource will be used.

  on-image:  image to use when the lamp is turned on.  If not
             specified, doesn't change image when turned on.

  off-image:  image to use when the lamp is turned off.  If not
              specified, doesn't change image when turned off.

  on-animated:  if true, sets the lamp animated when it's on
 
Any object in the game can be used as fuel; it simply has to have the "fuel-source" property. For instance, a flask of oil would have "fuel-source oil" set, making it match any lamp that requires "oil" as its fuel-type. A fuel source object also has to have a "fuel-amount" int property (default: 0), and fueling a lamp with the fuel source deducts up to the maximum amount the lamp can take from the fuel source's amount.

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

Field Summary
static int DEFAULT_FUEL_BURN_RATE
           
protected  Timer fuelTimer_
           
protected  long time_
          Marks when our last timer was set - used when the source is turned off to compute how much fuel to consume, to prevent people from turning it off & on between timer intervals to keep the fuel from being consumed.
protected  boolean warnedLowFuel_
           
 
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
Lamp()
           
 
Method Summary
 void apply(Commandable agent)
          Called by the ApplyCommand when the agent performs "apply".
 boolean belowLowFuelThreshold()
          Returns true if our fuel-level is currently below the int "low-level" threshold property, such that the lamp's intensity will be diminished.
 boolean canTurnOff()
          Returns true if it has the "can-turn-off" property.
 boolean canTurnOn()
          Returns true if it has the "can-turn-on" property.
 CommandEvent createEvent(CommandEvent initial)
          Create a command-event to light the lamp, turn off the lamp, or add fuel.
 void destroy()
          Destroys the lamp.
 boolean execute(CommandEvent event)
          Executes the event.
 int getBurnRate()
          Returns burn-rate for this object.
 int getFuelLevel()
          Returns the current "fuel-level" value.
 int getFuelUnits()
          Returns the number of units to eat on each timer tick.
 int getIntensity()
          Returns int "intensity" property value.
 int getLowFuelIntensity()
          Returns the intensity to use if we're low on fuel.
 java.lang.String getLowFuelMessage()
          Returns the "low-msg", e.g.
 int getLowLevelThreshold()
          Returns "low-level" int property.
 java.lang.String getOffImage()
          Returns value of the "off-image" property, if present.
 java.lang.String getOnImage()
          Returns the "on-image" string property, if present.
 java.lang.String getOutOfFuelMessage()
          Returns the "dead-msg" property, or null if not present.
 java.lang.String getRanOutMessage()
          Returns the "out-msg", e.g.
 java.lang.String getTurnOffVerb()
          Returns verb stored in "turn-off-cmd" property, or "light" by default.
 java.lang.String getTurnOnVerb()
          Returns verb stored in "turn-on-cmd" property, or "light" by default.
 void initialize()
          Adds class-default properties.
 boolean isAnimatedWhenOn()
          Returns the value of the "on-animated" boolean property.
 boolean isMarkedOff()
          Returns true if it's marked "off".
 boolean isMarkedOn()
          Returns true if it's marked "on".
 boolean isRefuelCommand(java.lang.String command)
          Returns true if refuel command.
 boolean knowsCommand(java.lang.String command)
          Returns true if we want to handle the command.
 boolean outOfFuel()
          Returns true if this lamp requires fuel, and its fuel-level is zero (or negative).
 void refill()
          Refills the lamp completely, setting the "fuel-level" int property to the value of the "max-fuel" property.
 boolean refuel(CommandEvent event)
          Player is trying to refuel the lamp.
 void setFuelLevel(int amt)
          Sets the new fuel-level of the lamp.
protected  void setInitialState()
          Figure out whether we're on or off initially.
 void startFuelTimer()
          Sets the fuel timer to the lamp's burn-rate.
 void timerExpired()
          Timer went off - eat some fuel.
 void toggleState()
          Turn from on to off, or off to on, provided this is possible.
 void turnOff()
          Turns the light off.
 void turnOn()
          Tries to turn the lamp on.
 boolean usesFuel()
          Returns true if it has a "fuel-type" property.
 
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, 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, getTile, getValue, getWeight, groupString, inContainer, initLocs, inMapEditor, invalidate, invalidateImage, invalidateParent, invalidateText, isAnimated, isAttackable, isBlessed, isCommandable, isCursed, isDamned, isGroupable, isIdentified, isMonster, isMonsterOrPlayer, isPlayer, isTerrain, 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

DEFAULT_FUEL_BURN_RATE

public static final int DEFAULT_FUEL_BURN_RATE
See Also:
Constant Field Values

fuelTimer_

protected Timer fuelTimer_

warnedLowFuel_

protected boolean warnedLowFuel_

time_

protected long time_
Marks when our last timer was set - used when the source is turned off to compute how much fuel to consume, to prevent people from turning it off & on between timer intervals to keep the fuel from being consumed.

Constructor Detail

Lamp

public Lamp()
Method Detail

initialize

public void initialize()
Adds class-default properties. Our archetype properties have already been added by now, so we can check them to see what the user expects of us. (Fuel, on/off, etc.)

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

setInitialState

protected void setInitialState()
Figure out whether we're on or off initially. If we burn fuel, start a fuel timer.

The logic for determining if we're on is as follows:

If we're ON and we have fuel, start fuel timer.
If we're ON, make sure we have a LightSource property to make us radiate. (Both of these are handled by turnOn()).


toggleState

public void toggleState()
Turn from on to off, or off to on, provided this is possible.


turnOn

public void turnOn()
Tries to turn the lamp on.


turnOff

public void turnOff()
Turns the light off.


timerExpired

public void timerExpired()
Timer went off - eat some fuel.

Specified by:
timerExpired in interface Timed

knowsCommand

public boolean knowsCommand(java.lang.String command)
Returns true if we want to handle the command. We have to check the arguments carefully to make sure we're not accidentally handling something that's not for us.

Specified by:
knowsCommand in interface Command
Parameters:
command - the command and args to check
Returns:
true if we want to handle the command

isRefuelCommand

public boolean isRefuelCommand(java.lang.String command)
Returns true if refuel command.


createEvent

public CommandEvent createEvent(CommandEvent initial)
Create a command-event to light the lamp, turn off the lamp, or add fuel.

Specified by:
createEvent in interface Command
Parameters:
initial - an event encapsulating the initial command
Returns:
a CommandEvent with all the properties of the event.

The first property is "type", whose value is a string with one of the following values: "turn-on" if the lamp is being turned on, "turn-off" if the lamp is being extinguished, or "refuel" if the lamp is being refueled.

The next property is "cmd", whose value is a string set to the full text of the command for lighting, extinguishing or refueling the lamp. Examples: "light", "turn on", "turn off".


execute

public boolean execute(CommandEvent event)
Executes the event.

Specified by:
execute in interface Command
Parameters:
event - the event to execute (turn on/turn off/add fuel)
Returns:
true if we handled it successfully

refuel

public boolean refuel(CommandEvent event)
Player is trying to refuel the lamp.


getTurnOnVerb

public java.lang.String getTurnOnVerb()
Returns verb stored in "turn-on-cmd" property, or "light" by default.


getTurnOffVerb

public java.lang.String getTurnOffVerb()
Returns verb stored in "turn-off-cmd" property, or "light" by default.


canTurnOn

public boolean canTurnOn()
Returns true if it has the "can-turn-on" property.


canTurnOff

public boolean canTurnOff()
Returns true if it has the "can-turn-off" property.


getFuelLevel

public int getFuelLevel()
Returns the current "fuel-level" value.


getFuelUnits

public int getFuelUnits()
Returns the number of units to eat on each timer tick.

Returns:
value of the "fuel-units" property, or 1 if not found.

usesFuel

public boolean usesFuel()
Returns true if it has a "fuel-type" property.


isMarkedOn

public boolean isMarkedOn()
Returns true if it's marked "on".


isMarkedOff

public boolean isMarkedOff()
Returns true if it's marked "off".


outOfFuel

public boolean outOfFuel()
Returns true if this lamp requires fuel, and its fuel-level is zero (or negative).


getBurnRate

public int getBurnRate()
Returns burn-rate for this object. Sets burn-rate to default value if not present.


getIntensity

public int getIntensity()
Returns int "intensity" property value.


getOutOfFuelMessage

public java.lang.String getOutOfFuelMessage()
Returns the "dead-msg" property, or null if not present.


getRanOutMessage

public java.lang.String getRanOutMessage()
Returns the "out-msg", e.g. "Your torch just burned out."

Returns:
"out-msg" prop, or null if not found

getLowFuelMessage

public java.lang.String getLowFuelMessage()
Returns the "low-msg", e.g. "Your torch is burning low."


getOnImage

public java.lang.String getOnImage()
Returns the "on-image" string property, if present.


getOffImage

public java.lang.String getOffImage()
Returns value of the "off-image" property, if present.


isAnimatedWhenOn

public boolean isAnimatedWhenOn()
Returns the value of the "on-animated" boolean property.

Returns:
the "on-animated" property, or false if not present.

getLowLevelThreshold

public int getLowLevelThreshold()
Returns "low-level" int property.

Returns:
"low-level" int property, if set, or zero if not. Below this level, the intensity will be reduced.

belowLowFuelThreshold

public boolean belowLowFuelThreshold()
Returns true if our fuel-level is currently below the int "low-level" threshold property, such that the lamp's intensity will be diminished.


getLowFuelIntensity

public int getLowFuelIntensity()
Returns the intensity to use if we're low on fuel.

Returns:
the "low-fuel-int" property, or (current intensity - 1) if not specified.

refill

public void refill()
Refills the lamp completely, setting the "fuel-level" int property to the value of the "max-fuel" property.


startFuelTimer

public void startFuelTimer()
Sets the fuel timer to the lamp's burn-rate.


setFuelLevel

public void setFuelLevel(int amt)
Sets the new fuel-level of the lamp.

Parameters:
amt - the new value for the "fuel-level" int property

apply

public void apply(Commandable agent)
Called by the ApplyCommand when the agent performs "apply".

Specified by:
apply in interface Applyable
Parameters:
agent - the person applying the object

destroy

public void destroy()
Destroys the lamp.

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