|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object wyvern.kernel.motion.MoveCommand
This class implements movement. It also serves as the main switchboard for converting moves into pushes, attacks and other types of events, depending on context.
Field Summary | |
protected java.util.HashMap |
dirs_
|
Method Summary | |
void |
addCommands(java.util.Map commands,
CommandList list)
Tells the Command to add the commands that it wants to implement into the passed data structure. |
protected void |
checkLegalMove(MoveEvent event,
GameObject agent)
Checks every proposed destination location for the move to see if the agent can actually move there. |
static java.util.List |
computeDestination(GameObject agent,
int dir,
Point offsets)
Given an agent to move and a direction to move it, figures out what the resulting locations would be upon completion of the move. |
protected void |
createDirectionTable()
Establishes all the direction commands we recognize, for checking the arguments to "move" or "go". |
CommandEvent |
createEvent(CommandEvent e)
Creates a MoveEvent from the command "move" or "go". |
boolean |
doMove(GameObject agent,
Point offsets,
int dir)
Moves an object in the specified direction. |
void |
ensureFacingNewDirection(MoveEvent e)
Turns the agent in the direction of the move, even if it was vetoed, to show their intent. |
boolean |
execute(CommandEvent e)
Executes the passed MoveEvent by moving the agent in the map. |
static MoveCommand |
getImpl()
|
boolean |
knowsCommand(java.lang.String command)
Returns true if this Command wants to handle the command. |
MoveEvent |
makeMoveEvent(java.lang.String command,
Commandable agent,
int dir,
java.lang.String fail)
Creates a standard MoveEvent and stuffs the event parameters. |
protected int |
parseMoveArgs(CommandEvent e)
Gets the direction to move from the command and arguments. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.util.HashMap dirs_
Method Detail |
public static MoveCommand getImpl()
protected void createDirectionTable()
public void addCommands(java.util.Map commands, CommandList list)
BuiltInCommand
addCommands
in interface BuiltInCommand
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.public boolean knowsCommand(java.lang.String command)
Command
This method exists to allow more than one game object to implement the same command verb, but with different expected arguments.
If two objects register for the same command and the same arguments, the object that was registered most recently gets to handle at the command.
knowsCommand
in interface Command
command
- the entire command string, including arguments
public CommandEvent createEvent(CommandEvent e)
createEvent
in interface Command
e
- an event with the original command text and agent
protected int parseMoveArgs(CommandEvent e)
public MoveEvent makeMoveEvent(java.lang.String command, Commandable agent, int dir, java.lang.String fail)
command
- the original command text (e.g. "move e" or "n")agent
- the agent that's movingdir
- the Direction to movefail
- any failure message to use
public static java.util.List computeDestination(GameObject agent, int dir, Point offsets)
agent
- the object to move; doesn't have to be Commandabledir
- the direction to moveoffsets
- the result of calling Direction.getXYOffsets(dir).
protected void checkLegalMove(MoveEvent event, GameObject agent)
This method has side effects. It can set parameters in the event: the failure message, the movement speed and the veto flag. It's broken into its own method precisely to make the public methods of MoveCommand free of side-effects, so they can be shared by the PushCommand and AttackCommand code.
event
- the eventagent
- the agentpublic boolean execute(CommandEvent e)
execute
in interface Command
e
- the CommandEvent to execute
public void ensureFacingNewDirection(MoveEvent e)
public boolean doMove(GameObject agent, Point offsets, int dir)
agent
- the object to moveoffsets
- the x & y offsets to move itdir
- the Direction constant matching the (x,y) offsets
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |