wyvern.lib.classes.magic
Class ConeSpell

java.lang.Object
  extended bywyvern.kernel.properties.PList
      extended bywyvern.kernel.maps.MapObject
          extended bywyvern.kernel.commands.AbstractCommandable
              extended bywyvern.lib.classes.magic.Spell
                  extended bywyvern.lib.classes.magic.ConeSpell
All Implemented Interfaces:
Broadcaster, Commandable, Dispellable, GameObject, Hookable, HookCallback, MethodHookable, PropertyList, RemoteAudio, Targetable, Timed
Direct Known Subclasses:
CurseStorm, Excavation, Fear, Paralysis, PoisonBreath, Sandstorm, SirenSong, Slow, Stonewind

public abstract class ConeSpell
extends Spell
implements Timed, HookCallback

The class used for all spells that propagate in a cone-shape.

Cones may be aimed in any of 8 directions (NSEW + diagonals), and may have any angular spread up to a practical maximum of perhaps 150 degrees.

A cone makes an isoceles triangle whose apex is the origin of the spell. The length of the cone is the length of the line segment that bisects it, from apex to base. The ratio of the base length to the cone length determines how "fat" the cone is (i.e. its angle). A cone spell has the following properties to parameterize its behavior:

The cone also accepts standard spell properties: damage_type, damage_range, appearance, and so on.

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

Nested Class Summary
 
Nested classes inherited from class wyvern.lib.classes.magic.Spell
Spell.DamageVisitor, Spell.UsableReagentPredicate
 
Field Summary
static int DEFAULT_CONE_FANOUT
          A cone makes an isoceles triangle.
static int DEFAULT_CONE_LENGTH
          This is equal to the height of the isoceles triangle made by the cone, or the distance from the apex to the base side.
static int DEFAULT_CONE_SPEED
          This is the rate (in millis) at which the cone propagates.
static int DEFAULT_DURATION
          This is the length of the rays that emanate from the cone apex.
 
Fields inherited from class wyvern.lib.classes.magic.Spell
AIR, AIR_AND_DEATH, AIR_AND_LIFE, AIR_AND_MIND, AIR_AND_SPIRIT, ART_MANA_REDUCTIONS, bitmaps_, CONJURATION, damager_, DEATH, DEATH_AND_MIND, DEATH_AND_SPIRIT, EARTH, EARTH_AND_AIR, EARTH_AND_DEATH, EARTH_AND_LIFE, EARTH_AND_MIND, EARTH_AND_SPIRIT, ENCHANTMENT, EVOCATION, FIRE, FIRE_AND_AIR, FIRE_AND_DEATH, FIRE_AND_EARTH, FIRE_AND_LIFE, FIRE_AND_MIND, FIRE_AND_SPIRIT, FIRE_AND_WATER, INCANTATION, LIFE, LIFE_AND_DEATH, LIFE_AND_MIND, LIFE_AND_SPIRIT, MIND, MIND_AND_SPIRIT, SELF_DAMAGE_CHANCE, SPIRIT, WATER, WATER_AND_AIR, WATER_AND_DEATH, WATER_AND_EARTH, WATER_AND_LIFE, WATER_AND_MIND, WATER_AND_SPIRIT
 
Fields inherited from class wyvern.kernel.commands.AbstractCommandable
hookList_, queue_, started_
 
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
 
Fields inherited from interface wyvern.common.net.RemoteAudio
DEFAULT_ALERT_GAIN, DEFAULT_ALERT_REPEAT_DELAY, DEFAULT_ALERT_REPEATS, DEFAULT_GAIN, DEFAULT_REPEAT_DELAY, DEFAULT_REPEATS
 
Constructor Summary
ConeSpell()
           
 
Method Summary
protected  void clearDamageCache()
          Resets the cache of monsters we've damaged this turn.
protected  void computeEndpoints()
          Figures out the endpoints of the cone's base, using the cone's direction and fanout.
 void damageMonster(Damageable obj, Spell spell)
          Damages the monster, but only if we haven't
 void damageMonsters()
          Damages all monsters in areas we occupy.
 void dispel()
          Shuts off the spell.
 Art getArt()
          ConeSpells are all Evocations.
protected  GameObject getBlocker(Point p)
          Returns the blocking object or null
 Predicate getBlockingPredicate()
          Gets the Predicate to use for determining what objects block the spell propagation.
 int getConeLength()
          Returns the total length of the cone.
 java.lang.String getDamageType()
          Return the damage type specifier for this spell.
 int getFanout()
          Returns the amount of "fanout" from the center of the base.
 int[] getImageDescriptors()
          Returns the appearance of the spell, for drawing it to the client.
 GameMap getMap()
          Return the map we're active in.
 int getMaxSwaths()
          Returns the total swaths that should be produced for this cone.
 int getNumSwaths()
          Returns the number of swaths that have been produced so far.
 java.util.Set getPoints()
          Returns the set of all the points the spell currently occupies.
 int getSpeed()
          Returns the propagation speed (in millis) of the spell.
 java.util.LinkedList getSwaths()
          Returns the list of our current swaths.
 int getTile(int xloc, int yloc)
          Overrides MapObject.getTile().
 void hookEvent(java.lang.String hookname, CommandEvent event)
          Caster has broken concentration, so stop adding swaths.
protected  void initCone(Point apex)
          Sets up initial cone parameters.
protected  void initEdgeLists()
          Sets up the 2 edges of the triangle.
 void initialize()
          Sets the default properties for this kind of spell.
protected  boolean isBlocked(Point p)
          Returns true if the specified point blocks our advance.
protected  void moveCone()
          Propagates the cone by another "turn".
 void newSwath()
          Creates a new swath at the apex.
 void removeFromMap(Point p)
          Removes a reference to the cone spell from the map.
 void setAnimated(boolean animate)
          Overrides MapObject.setAnimated and doesn't put on the heartbeat list.
 void setConeLength(int length)
          Sets the cone-length for the spell.
 void setDuration(int duration)
          Sets the duration for the spell - i.e., the number of "swaths" to generate.
 void setFanout(int fanout)
          Sets the fanout for the spell.
 void setMap(GameMap map, int x, int y)
          Sets the start location.
 void setMaxSwaths(int x)
          Change the maximum number of swaths in mid-spell.
 void setSpeed(int speed)
          Sets the propagation speed for the spell, in millis.
 void start()
          Starts the spell.
protected  void startConcentrationHooks()
          Adds hooks to stop spell if caster breaks concentration.
protected  void startTimer()
          Starts the propagation timer.
 void stop()
          "Stops" the monster by destroying its event queue.
protected  void stopConcentrationHooks()
          Removes hooks to stop spell if caster breaks concentration.
 void stopTimer()
          Stops the current propagation timer.
 void timerExpired()
          Called by TimerManager to notify object that timer has expired.
 
Methods inherited from class wyvern.lib.classes.magic.Spell
addReagent, canDamageSelf, canEnter, canEnter, castingOnSelf, cloneSpell, consumeReagents, destroy, ensureAI, ensureDirection, ensureReagents, findTargetObject, findTargetObject, fireDirection, fireLocation, getAgent, getAnimationFrames, getCastingDelay, getCommand, getDescString, getElement, getLevel, getLoreCost, getMagicItem, getReagents, getRequiredMana, getSpellArgs, getSpellDescription, getSpellName, getTarget, getTargetName, getTargetPoint, isBlessed, isConjuration, isCursed, isEnchantment, isEvocation, isIncantation, isPotion, logUsage, makeDispellable, reloadSpells, removeFromActiveListIfPresent, setAgent, setLevel, setMagicItem, setSpellArgs, setTarget, setTargetName, setTargetPoint, tellCaster
 
Methods inherited from class wyvern.kernel.commands.AbstractCommandable
addAttack, addHook, addMessageListener, addMethodHook, checkAnimated, command, command, commandNow, ensureEventQueue, fireMessageReceived, getAI, getCapName, getCombatQueue, getEncumbrance, getFiringPoint, getHookList, getHooks, getInventory, getName, getQueue, isCommandable, isStarted, isTelnet, message, message, message, pauseSound, playAlert, playAlert, playDefaultMusic, playPriorityMusic, playPriorityMusic, playSound, playSound, registerCommand, removeAttack, removeHook, removeMessageListener, removeMethodHook, resumeSound, runFailedPostHook, runMethodHook, runPostHook, runPreHook, sendPicture, sendPicture, setAI, setEncumbrance, setMusicGain, setName, setSoundGain, stopAllSounds, stopMusic, stopSound, unregisterCommand
 
Methods inherited from class wyvern.kernel.maps.MapObject
addContainerChangeListener, addDefaultProperty, addMapChangeListener, addMapMotionListener, addMotionTracker, addObjectTracker, addPrefix, addSuffix, addToMap, bless, broadcast, broadcast, broadcast, broadcast, broadcast, 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, getLayer, getLocations, 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, isDamned, isGroupable, isIdentified, isMonster, isMonsterOrPlayer, isPlayer, isTerrain, isUncursed, isUnpaid, isWizard, makeClone, markPaid, markUnpaid, move, occupies, positionAt, positionAtMap, remove, removeContainerChangeListener, removeFromMap, removeMapChangeListener, removeMapMotionListener, removeMotionTracker, removeObjectTracker, removePrefix, removeSuffix, setAlpha, setBitmap, setCategory, setContainer, setDefaultBitmap, setDefaultCategory, setDefaultDesc, setDefaultImage, setDefaultIntProperty, setDefaultLayer, setDefaultMaterial, setDefaultProperty, setDefaultShortDesc, setDirection, setImage, setImage, setLayer, setLocations, 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.GameObject
addContainerChangeListener, addMapChangeListener, addMapMotionListener, addMotionTracker, addObjectTracker, addPrefix, addSuffix, bless, canEnterBlockedBy, canMove, canMove, canMoveBlockedBy, canMoveBlockedBy, canMoveTo, canMoveToBlockedBy, checkDrop, curse, cycleFrame, externalize, getAlpha, getAppearance, getArchetype, getBaseWeight, getBitmap, getBounds, getCanonicalClassName, getCategory, getContainer, getCreator, getDamagedDescription, getDescription, getDirection, getGenderPossessive, getGenderPronoun, getImage, getImageDescriptor, getLayer, getLocations, getMapLink, getMaterial, getMaterialDescription, getMover, getOwningPlayer, getParentMap, getPrefixes, getQuantity, getReferenceLoc, getRelativeLocs, getShortDesc, getSuffixes, getTile, getValue, getWeight, inContainer, inMapEditor, invalidate, invalidateImage, invalidateParent, invalidateText, isAnimated, isAttackable, isDamned, isGroupable, isIdentified, isMonster, isMonsterOrPlayer, isPlayer, isTerrain, isUncursed, isUnpaid, isWizard, makeClone, markPaid, markUnpaid, move, occupies, positionAt, positionAtMap, remove, removeContainerChangeListener, removeMapChangeListener, removeMapMotionListener, removeMotionTracker, removeObjectTracker, removePrefix, removeSuffix, setAlpha, setBitmap, setCategory, setContainer, setDirection, setImage, setImage, setLayer, setLocations, setMapLink, setQuantity, setShape, setSize, setTransientSize, setWeight, setWeight, teleport
 
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
 
Methods inherited from interface wyvern.lib.Broadcaster
broadcast, broadcast, broadcast, broadcast, broadcast
 

Field Detail

DEFAULT_CONE_FANOUT

public static final int DEFAULT_CONE_FANOUT
A cone makes an isoceles triangle. This constant determines how "wide" the triangle is. The base of the triangle (which is the side furthest from the apex where the cone originates) is obtained by multiplying this constant by 2 and adding 1.

The property name for this value is "fanout".

See Also:
Constant Field Values

DEFAULT_CONE_LENGTH

public static final int DEFAULT_CONE_LENGTH
This is equal to the height of the isoceles triangle made by the cone, or the distance from the apex to the base side.

The property name for this value is "cone-length".

See Also:
Constant Field Values

DEFAULT_CONE_SPEED

public static final int DEFAULT_CONE_SPEED
This is the rate (in millis) at which the cone propagates.

The property name for this value is "speed".

See Also:
Constant Field Values

DEFAULT_DURATION

public static final int DEFAULT_DURATION
This is the length of the rays that emanate from the cone apex. If equal to the cone length, then when the rays reach the base, they begin to recede away from the apex. If less than the cone length, the cone will expand to a "depth" equal to to the ray length, creating a "wall" that travels the length of the cone. A ray length of 1 will cause a 1-tile cross-section to travel the length of the cone. A ray length greater than the cone length will cause the entire cone to be visible for as many "turns" as the ray length exceeds the cone length.

The property name for this value is "duration".

See Also:
Constant Field Values
Constructor Detail

ConeSpell

public ConeSpell()
Method Detail

getArt

public Art getArt()
ConeSpells are all Evocations.

Overrides:
getArt in class Spell

initialize

public void initialize()
Sets the default properties for this kind of spell.

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

setMap

public void setMap(GameMap map,
                   int x,
                   int y)
Sets the start location.

Specified by:
setMap in interface GameObject
Overrides:
setMap in class MapObject
Parameters:
map - the map
x - x map location
y - y map location

getMap

public GameMap getMap()
Return the map we're active in.

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

getImageDescriptors

public int[] getImageDescriptors()
Returns the appearance of the spell, for drawing it to the client.

Many of the objects in the game are rectangular and have a single bitmap that covers all the map locations they occupy. For this reason, MapObject.getImageDescriptors() assumes the object is rectangular (to save most objects a bunch of work), but spells and the like need to override it. If exploding, we return a list of bitmaps to draw, one for each location the spell occupies. (Every object is asked only once for its appearance, NOT once for every time it's found in the map. This is part of the design for making it easy in the general case).

Specified by:
getImageDescriptors in interface GameObject
Overrides:
getImageDescriptors in class MapObject
Returns:
an int array of (x, y, database bitmap number) triples.

getTile

public int getTile(int xloc,
                   int yloc)
Overrides MapObject.getTile(). Required for all disjoint objects.

Specified by:
getTile in interface GameObject
Overrides:
getTile in class MapObject
Parameters:
xloc - map x location
yloc - map y location
Returns:
the tile number at (xloc, yloc)

start

public void start()
Starts the spell. Ensures we have a valid direction and map, and aborts the spell if we can't get both.

The spell registers hooks with the caster for move, fire, cast, and some others. If you put a "no-conc" property on the spell before starting it, it'll skip adding the hooks.

Specified by:
start in interface Commandable
Overrides:
start in class Spell

stop

public void stop()
Description copied from interface: Commandable
"Stops" the monster by destroying its event queue. The monster can be restarted via another call to start().

Specified by:
stop in interface Commandable
Overrides:
stop in class AbstractCommandable

startConcentrationHooks

protected void startConcentrationHooks()
Adds hooks to stop spell if caster breaks concentration.


stopConcentrationHooks

protected void stopConcentrationHooks()
Removes hooks to stop spell if caster breaks concentration.


hookEvent

public void hookEvent(java.lang.String hookname,
                      CommandEvent event)
Caster has broken concentration, so stop adding swaths.

Specified by:
hookEvent in interface HookCallback
Parameters:
hookname - the name of the hook, such as "movePreHook".
event - the CommandEvent encapsulating the event parameters

dispel

public void dispel()
Shuts off the spell.

Specified by:
dispel in interface Dispellable
Overrides:
dispel in class Spell

startTimer

protected void startTimer()
Starts the propagation timer.


stopTimer

public void stopTimer()
Stops the current propagation timer.


timerExpired

public void timerExpired()
Description copied from interface: Timed
Called by TimerManager to notify object that timer has expired.

Specified by:
timerExpired in interface Timed

moveCone

protected void moveCone()
Propagates the cone by another "turn". Called by propagation timer.


initCone

protected void initCone(Point apex)
Sets up initial cone parameters. Call only once!

Parameters:
apex - the point where the cone originates

computeEndpoints

protected void computeEndpoints()
Figures out the endpoints of the cone's base, using the cone's direction and fanout. Stores them in instance variables.


initEdgeLists

protected void initEdgeLists()
Sets up the 2 edges of the triangle. We use Bresenham to compute the lines, then store each line as an edge list. The edge lists have equal lengths.


removeFromMap

public void removeFromMap(Point p)
Removes a reference to the cone spell from the map.

Parameters:
p - the point at which we need to remove the reference

getBlocker

protected GameObject getBlocker(Point p)
Returns the blocking object or null


isBlocked

protected boolean isBlocked(Point p)
Returns true if the specified point blocks our advance.


newSwath

public void newSwath()
Creates a new swath at the apex.


damageMonsters

public void damageMonsters()
Damages all monsters in areas we occupy.

Overrides:
damageMonsters in class Spell

clearDamageCache

protected void clearDamageCache()
Resets the cache of monsters we've damaged this turn.


damageMonster

public void damageMonster(Damageable obj,
                          Spell spell)
Damages the monster, but only if we haven't

Overrides:
damageMonster in class Spell
Parameters:
obj - the monster to damage
spell - the spell doing the damage (in case this needs to be used as a utility by another spell). If the spell has the property "show-defender-msg", the DamageEvent generated will show normal damage-messages (depending on the damage type) to the monster; otherwise it will be silent.

setMaxSwaths

public void setMaxSwaths(int x)
Change the maximum number of swaths in mid-spell.


getDamageType

public java.lang.String getDamageType()
Return the damage type specifier for this spell.


getSpeed

public int getSpeed()
Returns the propagation speed (in millis) of the spell. The speed is dependent on the spell's state.

Overrides:
getSpeed in class Spell
Returns:
the propagation speed, in millis

getBlockingPredicate

public Predicate getBlockingPredicate()
Gets the Predicate to use for determining what objects block the spell propagation.

Overrides:
getBlockingPredicate in class Spell
Returns:
a wyvern.lib.Predicate object
See Also:
BlocksSpellPredicate

getConeLength

public int getConeLength()
Returns the total length of the cone.

Returns:
cone length

setConeLength

public void setConeLength(int length)
Sets the cone-length for the spell.


setSpeed

public void setSpeed(int speed)
Sets the propagation speed for the spell, in millis.

Overrides:
setSpeed in class Spell
Parameters:
speed - the new speed in millis

setDuration

public void setDuration(int duration)
Sets the duration for the spell - i.e., the number of "swaths" to generate.


setFanout

public void setFanout(int fanout)
Sets the fanout for the spell.


getFanout

public int getFanout()
Returns the amount of "fanout" from the center of the base. Equal to 1/2 (base length - 1).

Returns:
fanout

getNumSwaths

public int getNumSwaths()
Returns the number of swaths that have been produced so far.

Returns:
num swaths so far

getMaxSwaths

public int getMaxSwaths()
Returns the total swaths that should be produced for this cone.

Returns:
max swaths for cone

getSwaths

public java.util.LinkedList getSwaths()
Returns the list of our current swaths.

Returns:
active swath list

getPoints

public java.util.Set getPoints()
Returns the set of all the points the spell currently occupies.

Overrides:
getPoints in class Spell
Returns:
all points we occupy; null if the spell is undetonated.

setAnimated

public void setAnimated(boolean animate)
Overrides MapObject.setAnimated and doesn't put on the heartbeat list.

Specified by:
setAnimated in interface GameObject
Overrides:
setAnimated in class MapObject
Parameters:
animate - true to animate