gecco.server.core
Class Action

java.lang.Object
  extended bygecco.server.core.Action
Direct Known Subclasses:
AttackAction, DelayAction, IndirectFireAction, MoveAction, UpdateStatusAction

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

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, or rather if the units commander can.
abstract  ActionReturn checkPoint()
          This method is called periodically by the game engine.
 ActionDefinition getActionDefinition()
          Gets the definition of the Action object
 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[] getCooperativeUnits()
           
 String getId()
          Gets the id of the Action object
static int getNewActionHandle()
          Returns a increasing nuber each time
 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.
 void initiate(int _actionHandle, int _unitHandle, int _argUnitHandle, int[] _argCooperativeUnitsHandle)
          Initialise the action with a unit and cooperative units as arguments.
 boolean isInstantaneous()
          Gets the Instantaneous flag of the Action object
protected static boolean isOutsideMap(double x, double y)
          Determines whether or not a given point is outside the map or not.
 void prepareAbortion()
          Called from ActionProcessor when Action is aborted, lets Action abort gracefully
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 setActionDefinition(ActionDefinition def)
          Sets the definition of the Action object
protected  void setArgumentUnit(Unit u)
           
protected  void setArgumentX(double x)
           
protected  void setArgumentY(double y)
           
 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, toString, wait, wait, wait
 

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

getActionDefinition

public ActionDefinition getActionDefinition()
Gets the definition of the Action object

Returns:
The definition

getId

public String getId()
Gets the id of the Action object

Returns:
The id

setActionDefinition

public void setActionDefinition(ActionDefinition def)
Sets the definition of the Action object

Parameters:
def - The definition

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.

setArgumentUnit

protected void setArgumentUnit(Unit u)

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.

setArgumentX

protected void setArgumentX(double x)

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.

setArgumentY

protected void setArgumentY(double y)

getCooperativeUnits

public Unit[] getCooperativeUnits()

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.

initiate

public void initiate(int _actionHandle,
                     int _unitHandle,
                     int _argUnitHandle,
                     int[] _argCooperativeUnitsHandle)
Initialise the action with a unit and cooperative units as arguments.

Parameters:
_actionHandle - A unique handle that should identify this action.
_unitHandle - The handle of the executing unit.
_argUnitHandle - The handle of the target unit.
_argCooperativeUnitsHandle -

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.

isOutsideMap

protected static boolean isOutsideMap(double x,
                                      double y)
Determines whether or not a given point is outside the map or not. Use this if your action moves the piece to make sure it stays on the map.

Parameters:
x - X coordinate.
y - Y coordinate.
Returns:
true if the position id outside the map, false otherwise.

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, or rather if the units commander can.

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.

prepareAbortion

public void prepareAbortion()
Called from ActionProcessor when Action is aborted, lets Action abort gracefully


getNewActionHandle

public static int getNewActionHandle()
Returns a increasing nuber each time