wyvern.kernel.motion
Class PushCommand

java.lang.Object
  extended bywyvern.kernel.motion.PushCommand
All Implemented Interfaces:
BuiltInCommand, Command

public class PushCommand
extends java.lang.Object
implements BuiltInCommand

This command implements pushing objects around. It shares some of the semantics of movement, including the complex checks for whether the agent can move into the destination square, which is why it's in the kernel.

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

Nested Class Summary
 class PushCommand.PushEvent
          Inner class for encapsulating a Push event.
 
Method Summary
 void addCommands(java.util.Map commands, CommandList list)
          Adds known commands.
 CommandEvent createEvent(CommandEvent initial)
          Creates a PushEvent from scratch.
 CommandEvent createFromMove(MoveEvent move, Point target, GameObject pushable, Predicate pp)
          Mogrifies a MoveEvent into a PushEvent.
 boolean execute(CommandEvent event)
          Executes the push.
static PushCommand getImpl()
           
 boolean knowsCommand(java.lang.String cmd)
          Returns 'true' for handling "push".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getImpl

public static PushCommand getImpl()

addCommands

public void addCommands(java.util.Map commands,
                        CommandList list)
Adds known commands.

Specified by:
addCommands in interface BuiltInCommand
Parameters:
commands - a Map whose keys are commands, and whose values are Commands that handle those commands.
list - the CommandList the Command is being added to.

knowsCommand

public boolean knowsCommand(java.lang.String cmd)
Returns 'true' for handling "push".

Specified by:
knowsCommand in interface Command
Parameters:
cmd - the entire command string, including arguments
Returns:
true if we want to handle the command

createEvent

public CommandEvent createEvent(CommandEvent initial)
Creates a PushEvent from scratch. Called when someone commanded a Commandable to "push {something}".

Specified by:
createEvent in interface Command
Parameters:
initial - the CommandEvent that started this push. It's a generic event used to hold the command arguments.
Returns:
a CommandEvent subclass encapsulating this command's execution parameters and state. It should copy in the fields from the passed-in event.

createFromMove

public CommandEvent createFromMove(MoveEvent move,
                                   Point target,
                                   GameObject pushable,
                                   Predicate pp)
Mogrifies a MoveEvent into a PushEvent. Called by the ContactManager when it discovers that something pushable is in the way of the move. This method was separated from the createEvent method because in 99+% of all pushes originate as moves, and we don't want to have to re-check all the preconditions.

Parameters:
move - the MoveEvent in whose destination list the ContactManager found a pushable object.
target - the map location of the pushable object
pushable - the pushable object we found
pp - a PropertyPredicate instance that checks for "pushable"

execute

public boolean execute(CommandEvent event)
Executes the push.

Specified by:
execute in interface Command
Parameters:
event - the PushEvent to execute
Returns:
true if push succeeded, else false