be.saltwater.jaqel.scheduler
Class CreatureActionScheduler

java.lang.Object
  extended bybe.saltwater.jaqel.scheduler.CreatureActionScheduler

public class CreatureActionScheduler
extends java.lang.Object

Every Level has one CreatureActionScheduler. It takes care of approving and executing all actions (CreatureAction) that are passed to it. Actions consist of animations that are implemented by ScheduledBehavior objects. These are Java3D behaviors that can call back to the scheduler when they are finished. An action is concidered finished if all animations are finished or if the action is force-finished with finishAction(). When the action has finished, the next action in the queue is started in the same way. Action get in the queue by passing them to execute (if they are allowed, see CreatureAction.isAllowed()).

Author:
Bruno Windels
See Also:
CreatureAction, ScheduledBehavior, CreatureAction.isAllowed(be.saltwater.jaqel.scheduler.CreatureActionScheduler), execute(be.saltwater.jaqel.scheduler.CreatureAction)

Field Summary
static javax.media.j3d.Bounds BEHAVIOR_BOUNDS
           
 
Constructor Summary
CreatureActionScheduler()
          Only a Level should construct a new CreatureActionScheduler
 
Method Summary
 int attack(Weapon weapon, Creature attacking_creature, Creature attacked_creature, int times)
          Convenience method for creating a new AttackAction and passing it to execute().
 int drink(Potion potion, Creature creature)
          Convenience method for creating a new DrinkAction and passing it to execute().
 int execute(CreatureAction action)
          When the action is allowed, the given action is executed either direct (when the queue is empty) or differed.
protected  void finishAction()
          Should only be called by ScheduledBehavior.finishAction() and finishAnimation().
protected  void finishAnimation(ScheduledBehavior animation)
          Should only be called by ScheduledBehavior.finishAnimation().
 javax.media.j3d.BranchGroup getBranchGroup()
          Returns the BranchGroup to which all the ScheduledBehavior objects are attached (and detached).
 java.awt.Point getEndLocation(Creature c)
          Returns the ending location of the given creature.
 int getQueueSize()
           
 int move(java.util.List path, Creature creature)
          Convenience method for creating a new MoveAction and passing it to execute().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BEHAVIOR_BOUNDS

public static final javax.media.j3d.Bounds BEHAVIOR_BOUNDS
Constructor Detail

CreatureActionScheduler

public CreatureActionScheduler()
Only a Level should construct a new CreatureActionScheduler

Method Detail

execute

public int execute(CreatureAction action)
When the action is allowed, the given action is executed either direct (when the queue is empty) or differed.

Parameters:
action - The action to be executed
See Also:
CreatureAction.isAllowed(be.saltwater.jaqel.scheduler.CreatureActionScheduler)

move

public int move(java.util.List path,
                Creature creature)
Convenience method for creating a new MoveAction and passing it to execute().

See Also:
execute(be.saltwater.jaqel.scheduler.CreatureAction), MoveAction

attack

public int attack(Weapon weapon,
                  Creature attacking_creature,
                  Creature attacked_creature,
                  int times)
Convenience method for creating a new AttackAction and passing it to execute().

See Also:
execute(be.saltwater.jaqel.scheduler.CreatureAction), AttackAction

drink

public int drink(Potion potion,
                 Creature creature)
Convenience method for creating a new DrinkAction and passing it to execute().

See Also:
execute(be.saltwater.jaqel.scheduler.CreatureAction), DrinkAction

getBranchGroup

public javax.media.j3d.BranchGroup getBranchGroup()
Returns the BranchGroup to which all the ScheduledBehavior objects are attached (and detached). This should be attached to the scene graph (probably by Level) or no animation will occur.


finishAnimation

protected void finishAnimation(ScheduledBehavior animation)
Should only be called by ScheduledBehavior.finishAnimation(). Internal use only.


finishAction

protected void finishAction()
Should only be called by ScheduledBehavior.finishAction() and finishAnimation(). Internal use only.


getQueueSize

public int getQueueSize()

getEndLocation

public java.awt.Point getEndLocation(Creature c)
Returns the ending location of the given creature. This is equal to the end position of the last MoveAction(). This point is used as the start of the path of the new MoveAction