wyvern.kernel.monsters
Class Generator

java.lang.Object
  extended bywyvern.kernel.properties.PList
      extended bywyvern.kernel.maps.MapObject
          extended bywyvern.kernel.monsters.Generator
All Implemented Interfaces:
Attackable, Broadcaster, Damageable, GameObject, HookCallback, Lair, MethodHookable, PropertyList, Timed

public class Generator
extends MapObject
implements Lair, Timed, Attackable, HookCallback

Generates monsters based on preset properties. Properties include:

Version:
1.0, Sep 25, 1997
Author:
Steve Yegge

Field Summary
protected  int curMonsters_
           
protected  java.util.HashSet monsters_
           
protected  int numMonsters_
           
protected  boolean reset_
           
protected  int resets_
           
protected  SuspendableTimer timer_
           
protected  java.util.ArrayList types_
           
 
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.Lair
DEFAULT_HP, DEFAULT_MAX, DEFAULT_MIN, DEFAULT_RESET_DELAY, DEFAULT_SPEED
 
Fields inherited from interface wyvern.lib.PropertyList
PROPERTY_PACKAGE
 
Constructor Summary
Generator()
           
 
Method Summary
protected  boolean addToMap(Monster m)
          Finds a place to put the monster.
 void adjustHP(int adjust)
          Adjusts the object's hit points upwards or downwards.
 void generate()
          Generates one monster.
 int getHP()
          Returns the object's current hit points.
 int getMaxHP()
          Returns the object's maximum hit points.
 int getMaximum()
          Returns the maximum monsters this lair will generate before stopping.
 int getMinimum()
          Returns the minimum number of monsters the lair will generate on each reset.
 int getResetDelay()
          Gets the time between resets for this lair object.
 int getSpeed()
          Returns the speed at which this object generates monsters.
 java.lang.String getType()
          If this generator is set to generate a specific type of monster, returns that type.
 java.lang.String getTypeList()
          Returns the path to the list of monster types that this lair generates, or null if it generates a single type.
 int getXPAward()
          Returns the experience award for killing this monster.
 void hookEvent(java.lang.String hookName, CommandEvent event)
          A monster died.
 void initialize()
          Initializes the object's default properties.
 boolean isAttackable()
          Returns true if this is an Attackable.
 void kill(GameObject attacker)
          Destroys the generator.
protected  void killTimer()
           
 void notifyAttacked(Commandable attacker)
          Someone attacked us.
 void remove()
          Removes this object from its map.
 void remove(GameObject obj)
          Removes a monster from the Lair's list.
 void reset()
          Resets the lair, removing all references to its monsters and starting over again.
 void setMap(GameMap map, int x, int y)
          Sets the parent map for this object, passing requested location at which to put the object.
 void setMaximum(int maximum)
          Sets the maximum number of monsters this lair will generate before stopping.
 void setMinimum(int min)
          Sets the minimum number of monsters to generate.
 void setResetDelay(int delay)
          Sets the time after the last monster croaks before the Lair will spew out more monsters.
 void setSpeed(int speed)
          Sets the speed at which this object generates monsters.
 void setType(java.lang.String type)
          Sets one specific monster type for this lair to produce.
 void setTypeList(java.lang.String path)
          Sets a list of monster types for this lair to generate.
 void setTypes(java.lang.String types)
          Sets a list of monsters to randomly choose from when generating.
 void start()
          Sets the initial timer; called by reset() and setMap().
 void stop()
          Stops the generator.
 void timerExpired()
          Called by TimerManager to notify object that timer has expired.
 
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, getTile, getValue, getWeight, groupString, inContainer, initLocs, inMapEditor, invalidate, invalidateImage, invalidateParent, invalidateText, isAnimated, isBlessed, isCommandable, isCursed, isDamned, isGroupable, isIdentified, isMonster, isMonsterOrPlayer, isPlayer, isTerrain, isUncursed, isUnpaid, isWizard, makeClone, markPaid, markUnpaid, move, occupies, positionAt, positionAtMap, 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, 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, canEnter, canEnterBlockedBy, canMove, canMove, canMoveBlockedBy, canMoveBlockedBy, canMoveTo, canMoveToBlockedBy, checkDrop, curse, cycleFrame, destroy, externalize, getAlpha, getAppearance, getArchetype, 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, inContainer, inMapEditor, invalidate, invalidateImage, invalidateParent, invalidateText, isAnimated, isBlessed, isCommandable, isCursed, isDamned, isGroupable, isIdentified, isMonster, isMonsterOrPlayer, isPlayer, isTerrain, isUncursed, isUnpaid, isWizard, makeClone, markPaid, markUnpaid, move, occupies, positionAt, positionAtMap, removeContainerChangeListener, removeMapChangeListener, removeMapMotionListener, removeMotionTracker, removeObjectTracker, removePrefix, removeSuffix, setAlpha, setAnimated, 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.MethodHookable
addMethodHook, removeMethodHook, runMethodHook
 
Methods inherited from interface wyvern.lib.Broadcaster
broadcast, broadcast, broadcast, broadcast, broadcast
 

Field Detail

reset_

protected boolean reset_

numMonsters_

protected int numMonsters_

curMonsters_

protected int curMonsters_

monsters_

protected java.util.HashSet monsters_

timer_

protected SuspendableTimer timer_

types_

protected java.util.ArrayList types_

resets_

protected int resets_
Constructor Detail

Generator

public Generator()
Method Detail

initialize

public void initialize()
Description copied from interface: GameObject
Initializes the object's default properties. Any GameObject implementation that wishes to initialize itself should do so here, rather than in the constructor. This is because nearly all game objects inherit from an archetype, and the archetype parent pointer isn't set until the object's constructor finishes. This is a good place to add any class-default properties for an object - properties that the object gets regardless of which archetype it inherits from. WARNING: don't forget to call the superclass' initialize() method, or the object may not function properly. For instance, it won't become animated even if it specifies animation parameters in the archetype.

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

setType

public void setType(java.lang.String type)
Description copied from interface: Lair
Sets one specific monster type for this lair to produce. The type is specified in a property called "type".

Specified by:
setType in interface Lair
Parameters:
type - a path to an archetype, or a fully-qualified java classname.

setTypes

public void setTypes(java.lang.String types)
Sets a list of monsters to randomly choose from when generating. Stored in a property called "types".

Specified by:
setTypes in interface Lair
Parameters:
types - a whitespace-delimited list of archetypes, e.g. "monsters/goblin/kobold monsters/goblin/kobold_lord"

getType

public java.lang.String getType()
Description copied from interface: Lair
If this generator is set to generate a specific type of monster, returns that type. If the generator is set to generate a list of monsters, returns null. The type is specified in a property called "type".

Specified by:
getType in interface Lair
Returns:
the archetype path or fully-qualified java class, or null if we generate a list of monsters.

setTypeList

public void setTypeList(java.lang.String path)
Sets a list of monster types for this lair to generate. The list is specified in a property called "type-list".

Specified by:
setTypeList in interface Lair
Parameters:
path - the relative path to a list of archetypes, e.g. "generator/kobold" (if under world/lists) or "wiz/foobar/mylists/bugbear" if under a wizard directory.

getTypeList

public java.lang.String getTypeList()
Description copied from interface: Lair
Returns the path to the list of monster types that this lair generates, or null if it generates a single type. The list is specified in a property called "type-list".

Specified by:
getTypeList in interface Lair
Returns:
the path to the type list

setSpeed

public void setSpeed(int speed)
Description copied from interface: Lair
Sets the speed at which this object generates monsters.

Specified by:
setSpeed in interface Lair
Parameters:
speed - the number of seconds between each monster generated in a particular batch.

getSpeed

public int getSpeed()
Description copied from interface: Lair
Returns the speed at which this object generates monsters.

Specified by:
getSpeed in interface Lair
Returns:
the speed (in seconds) between generating monsters in a batch.

setResetDelay

public void setResetDelay(int delay)
Description copied from interface: Lair
Sets the time after the last monster croaks before the Lair will spew out more monsters.

Specified by:
setResetDelay in interface Lair
Parameters:
delay - the delay (in seconds) between resets. Setting this to zero will cause the lair to start a new batch as soon as the old one is finished.

getResetDelay

public int getResetDelay()
Description copied from interface: Lair
Gets the time between resets for this lair object.

Specified by:
getResetDelay in interface Lair
Returns:
the delay, in seconds, between resets

setMaximum

public void setMaximum(int maximum)
Description copied from interface: Lair
Sets the maximum number of monsters this lair will generate before stopping.

Specified by:
setMaximum in interface Lair
Parameters:
maximum - the maximum monsters to generate on each reset.

getMaximum

public int getMaximum()
Description copied from interface: Lair
Returns the maximum monsters this lair will generate before stopping.

Specified by:
getMaximum in interface Lair
Returns:
the max number (NO_LIMIT if it just generates forever)

setMinimum

public void setMinimum(int min)
Description copied from interface: Lair
Sets the minimum number of monsters to generate. The generator will choose a random number between min and max to generate on this reset. If min and max are the same, it generates that exact number of monsters each time.

Specified by:
setMinimum in interface Lair
Parameters:
min - the fewest monsters to create; defaults to 1.

getMinimum

public int getMinimum()
Description copied from interface: Lair
Returns the minimum number of monsters the lair will generate on each reset.

Specified by:
getMinimum in interface Lair
Returns:
the low end of the range (setLimit() sets the high end).

remove

public void remove(GameObject obj)
Description copied from interface: Lair
Removes a monster from the Lair's list. Called by a monster AI when a monster dies, but can be used by any code to make the lair object "forget" about a particular monster.

Specified by:
remove in interface Lair

reset

public void reset()
Description copied from interface: Lair
Resets the lair, removing all references to its monsters and starting over again.

Specified by:
reset in interface Lair

setMap

public void setMap(GameMap map,
                   int x,
                   int y)
Description copied from interface: GameObject
Sets the parent map for this object, passing requested location at which to put the object. If the object is large (i.e. bigger than 1x1), then its "reference location", defined as the first location in its location-list, is placed at the requested location, and the remaining locations are placed relative to the reference location.

For example, if a 2x2 object is placed at (10,10), then the object's upper-left corner is its reference loc, so a reference to the object is placed at (10,10). The remaining three locations are placed at (11,10), (10,11) and (11,11).

For objects that wish to subclass this method, it does the following:

A method-hook is available for this method; it's called "add", and it's called whenever an object is added to a map. This happens whenever an object moves within a map (because of the current way in which physical object movement is implemented), so currently it's sufficient to have "add" and "remove" method hooks, but no "move" method hook.

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

remove

public void remove()
Description copied from interface: GameObject
Removes this object from its map. This is the correct way take an object out of a map - you shouldn't invoke the map's remove() method on the object.

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

start

public void start()
Sets the initial timer; called by reset() and setMap().

Specified by:
start in interface Lair

stop

public void stop()
Stops the generator.


generate

public void generate()
Generates one monster. Called by timer.


addToMap

protected boolean addToMap(Monster m)
Finds a place to put the monster.

Parameters:
m - the monster
Returns:
true if successful

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

getHP

public int getHP()
Description copied from interface: Damageable
Returns the object's current hit points.

Specified by:
getHP in interface Damageable

getMaxHP

public int getMaxHP()
Description copied from interface: Damageable
Returns the object's maximum hit points.

Specified by:
getMaxHP in interface Damageable

adjustHP

public void adjustHP(int adjust)
Description copied from interface: Damageable
Adjusts the object's hit points upwards or downwards.

Specified by:
adjustHP in interface Damageable
Parameters:
adjust - a number (usually negative) to add to the object's hp

kill

public void kill(GameObject attacker)
Destroys the generator.

Specified by:
kill in interface Damageable
Parameters:
attacker - the player/monster/iron-gate/whatever that did the final blow. Can be null.

hookEvent

public void hookEvent(java.lang.String hookName,
                      CommandEvent event)
A monster died.

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

notifyAttacked

public void notifyAttacked(Commandable attacker)
Someone attacked us. Does nothing.

Specified by:
notifyAttacked in interface Attackable

getXPAward

public int getXPAward()
Description copied from interface: Attackable
Returns the experience award for killing this monster.

Specified by:
getXPAward in interface Attackable
Returns:
the number of experience points to distribute among the agents that killed the monster.

killTimer

protected void killTimer()

isAttackable

public boolean isAttackable()
Description copied from interface: GameObject
Returns true if this is an Attackable.

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