be.saltwater.jaqel.scheduler
Class CreatureAction

java.lang.Object
  extended bybe.saltwater.jaqel.scheduler.CreatureAction
Direct Known Subclasses:
AttackAction, MoveAction

public abstract class CreatureAction
extends java.lang.Object

An action that a creature can execute. Subclasses implement the actual behavior of the action by overriding actionStarted and actionFinished. Subclasses should also specify the animation that are part of the action. They should do this by adding ScheduledBehavior's with the method addAnimation. If an action has no animations, it is not executed but skipped. The animations must be added at constructor time.

Author:
Bruno Windels
See Also:
CreatureActionScheduler, Creature

Constructor Summary
CreatureAction(CreatureActionScheduler scheduler, Creature actor)
          Constructor for subclasses.
 
Method Summary
 void actionFinished()
          Called by CreatureActionScheduler when the action is finished.
 void actionStarted()
          Called by CreatureActionScheduler when the action is started.
protected  void addAnimation(ScheduledBehavior animation)
          Subclasses must call this method to add their animations.
 void animationFinished(ScheduledBehavior animation)
          Called by CreatureActionScheduler when an animation of this action is finished.
 Creature getActorCreature()
           
protected  java.util.List getAnimations()
          Gets an unmodifiable, synchronized list containing all the animations (ScheduledBehavior), mainly used by CreatureActionScheduler.
abstract  int getCost()
          Subclasses should calculate the cost in actionpoints to complete this action in this method
 CreatureActionScheduler getCreatureActionScheduler()
          The creature action scheduler this action will be executed by.
 java.awt.Point getEndLocation()
          If this action modifies the location of the Creature, return the end location, default implementation returns null.
 int isAllowed(CreatureActionScheduler scheduler)
          Returns if this action can be executed.
abstract  int isValid()
          Subclasses should return a Creature.ORDER_* status code that indicates if this action is valid. return Creature.ORDER_OK if all is ok.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CreatureAction

public CreatureAction(CreatureActionScheduler scheduler,
                      Creature actor)
Constructor for subclasses. Every CreatureAction must have a reference to the Creature that is executing the action.

Parameters:
actor - The acting creature
Method Detail

isAllowed

public final int isAllowed(CreatureActionScheduler scheduler)
Returns if this action can be executed. This is true when the cost is lesser than or equal to the number of action points of the acting creature.

See Also:
getCost(), Creature.getActionPoints()

getCost

public abstract int getCost()
Subclasses should calculate the cost in actionpoints to complete this action in this method

See Also:
Creature.getActionPoints()

isValid

public abstract int isValid()
Subclasses should return a Creature.ORDER_* status code that indicates if this action is valid. return Creature.ORDER_OK if all is ok.


actionStarted

public void actionStarted()
Called by CreatureActionScheduler when the action is started. Not abstract because you may not need to know this.


actionFinished

public void actionFinished()
Called by CreatureActionScheduler when the action is finished. Not abstract because you may not need to know this.


animationFinished

public void animationFinished(ScheduledBehavior animation)
Called by CreatureActionScheduler when an animation of this action is finished. Not abstract because you may not need to know this. When this method is called, the ScheduledBehavior is not yet removed from the scene graph.

Parameters:
animation - The animation that is terminated.

getAnimations

protected java.util.List getAnimations()
Gets an unmodifiable, synchronized list containing all the animations (ScheduledBehavior), mainly used by CreatureActionScheduler.


addAnimation

protected void addAnimation(ScheduledBehavior animation)
Subclasses must call this method to add their animations. If a CreatureAction has no animations when it is passed to CreatureActionScheduler.execute, it will not be executed, so the animations should be added in the constructor.

Parameters:
animation - The animation that belongs to this animation
See Also:
getAnimations(), CreatureActionScheduler.execute(be.saltwater.jaqel.scheduler.CreatureAction)

getCreatureActionScheduler

public CreatureActionScheduler getCreatureActionScheduler()
The creature action scheduler this action will be executed by. Needed by subclasses to create ScheduledBehaviors.


getActorCreature

public Creature getActorCreature()

getEndLocation

public java.awt.Point getEndLocation()
If this action modifies the location of the Creature, return the end location, default implementation returns null.