gecco.server.core
Class Action

java.lang.Object
  |
  +--gecco.server.core.Action
Direct Known Subclasses:
AttackAction, Fly, FlyAction, InstantAttackAction, Move, Move, MoveAction, MoveFastAction, Refuel, Rescue, SetOnFire, Transfer, Water

public abstract class Action
extends Object

This class represents an Action that a unit can execute, and every real action should be a subclass of this class. There are several kinds of actions. First, there is normal actions, that are executed one after another in a queue, only one at a time, and there are instantaneous actions, that are executed at once, even if there are some other normal action ongoing. The normal actions typically span some interval in time, like movement of units, and the instantaneous don't, they are just instantaneous. :) Second, actions can have different arguments. At the moment, the arguments can be a unit, a point on the map, or nothing. Normal actions are executed over a time interval, and at some points in time the action has checkpoints when the method with the same name is called by the game engine. That method is where most of the code of the action is placed, for example code to check if the action is completed, and code to update any status of the unit executing the action, and so on.

Author:
Henrik Bäärnhielm, Karl Hasselström, Henrik Hägerström

Field Summary
private  int actionHandle
          The unique handle of the action.
private  Unit argUnit
          The unit that is the target of the action, if appropriate.
private  double argX
          The coordinates of the point that is the target of this action, if appropriate.
private  double argY
          Description of the Field
private  boolean isInstantaneous
          Flag to indicate if this action is instantaneous.
private  Unit unit
          The unit that executes the action.
 
Constructor Summary
Action()
          Constructor for the Action object
 
Method Summary
protected  boolean canSeePosition(double x, double y)
          Determines if the unit that executes the action can see a certain position, that is, if the position is inside the units visibility range.
abstract  ActionReturn checkPoint()
          This method is called periodically by the game engine.
 int getActionHandle()
          Gets the handle of the Action object
 Unit getArgumentUnit()
          Gets the unit that is the target of this action.
 double getArgumentX()
          Gets the x coordinate of the point that is the target of this action.
 double getArgumentY()
          Gets the y coordinate of the point that is the target of this action.
protected  int getAutomatonState(int x, int y)
          Gets the state of the given automaton.
 Unit getUnit()
          Gets the unit that executes this action
 int getUnitHandle()
          Gets the handle of the unit that executes this action
 void initiate(int _actionHandle, int _unitHandle)
          Initialise the action without any arguments.
 void initiate(int _actionHandle, int _unitHandle, double _argX, double _argY)
          Initialise the action with a point as argument.
 void initiate(int _actionHandle, int _unitHandle, int _argUnitHandle)
          Initialise the action with a unit as argument.
 boolean isInstantaneous()
          Gets the Instantaneous flag of the Action object
protected  void sendEventToAutomaton(int x, int y, String eventName, int factor)
          Sends an event to a given automaton.
protected  void sendEventToUnit(Unit unit, String eventName, int factor)
          Sends an event to a given unit.
 void setInstantaneous(boolean b)
          Sets the Instantaneous flag of the Action object
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

actionHandle

private int actionHandle
The unique handle of the action.

unit

private Unit unit
The unit that executes the action.

argUnit

private Unit argUnit
The unit that is the target of the action, if appropriate.

argX

private double argX
The coordinates of the point that is the target of this action, if appropriate.

argY

private double argY
Description of the Field

isInstantaneous

private boolean isInstantaneous
Flag to indicate if this action is instantaneous.
Constructor Detail

Action

public Action()
Constructor for the Action object
Method Detail

setInstantaneous

public void setInstantaneous(boolean b)
Sets the Instantaneous flag of the Action object
Parameters:
b - The new Instantaneous value

isInstantaneous

public boolean isInstantaneous()
Gets the Instantaneous flag of the Action object
Returns:
The Instantaneous flag

getActionHandle

public int getActionHandle()
Gets the handle of the Action object
Returns:
The handle

getUnitHandle

public int getUnitHandle()
Gets the handle of the unit that executes this action
Returns:
The unit handle

getUnit

public Unit getUnit()
Gets the unit that executes this action
Returns:
The unit

getArgumentUnit

public Unit getArgumentUnit()
Gets the unit that is the target of this action.
Returns:
The target unit, or null if there is no target unit.

getArgumentX

public double getArgumentX()
Gets the x coordinate of the point that is the target of this action.
Returns:
The x coordinate of the target point, or -1 if there is no target point.

getArgumentY

public double getArgumentY()
Gets the y coordinate of the point that is the target of this action.
Returns:
The y coordinate of the target point, or -1 if there is no target point.

initiate

public void initiate(int _actionHandle,
                     int _unitHandle)
Initialise the action without any arguments.
Parameters:
_actionHandle - A unique handle that should identify this action.
_unitHandle - The handle of the executing unit.

initiate

public void initiate(int _actionHandle,
                     int _unitHandle,
                     double _argX,
                     double _argY)
Initialise the action with a point as argument.
Parameters:
_actionHandle - A unique handle that should identify this action.
_unitHandle - The handle of the executing unit.
_argX - The x coordinate of the target point.
_argY - The y coordinate of the target point.

initiate

public void initiate(int _actionHandle,
                     int _unitHandle,
                     int _argUnitHandle)
Initialise the action with a unit as argument.
Parameters:
_actionHandle - A unique handle that should identify this action.
_unitHandle - The handle of the executing unit.
_argUnitHandle - The handle of the target unit.

checkPoint

public abstract ActionReturn checkPoint()
This method is called periodically by the game engine.
Returns:
An object of type ActionReturn, which encapsulates data about the status of the action after the checkpoint. Different instances of the class ActionReturn should be returned depending on whether the action is completed, aborted, or if the action should be requeued and the checkpoint method called again at some time later.

getAutomatonState

protected int getAutomatonState(int x,
                                int y)
Gets the state of the given automaton.
Parameters:
x - The x coordinate of the automaton.
y - The y coordinate of the automaton.
Returns:
The state of the given automaton.

sendEventToAutomaton

protected void sendEventToAutomaton(int x,
                                    int y,
                                    String eventName,
                                    int factor)
Sends an event to a given automaton.
Parameters:
x - The x coordinate of the automaton.
y - The y coordinate of the automaton.
eventName - The name of the event.
factor - The factor of the event.

sendEventToUnit

protected void sendEventToUnit(Unit unit,
                               String eventName,
                               int factor)
Sends an event to a given unit.
Parameters:
unit - The unit that should recieve the event.
eventName - The name of the event.
factor - The factor of the event.

canSeePosition

protected boolean canSeePosition(double x,
                                 double y)
Determines if the unit that executes the action can see a certain position, that is, if the position is inside the units visibility range.
Parameters:
x - The x coordinate of the position.
y - The y coordinate of the position.
Returns:
true if the unit can see the position, false otherwise.