es.upv.dsic.gti_ia.jgomas
Class CBasicTroop

java.lang.Object
  extended by jade.core.Agent
      extended by es.upv.dsic.gti_ia.jgomas.CJGomasAgent
          extended by es.upv.dsic.gti_ia.jgomas.CBasicTroop
All Implemented Interfaces:
jade.core.TimerListener, java.io.Serializable, java.lang.Runnable
Direct Known Subclasses:
CTroop

public abstract class CBasicTroop
extends CJGomasAgent

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class jade.core.Agent
jade.core.Agent.Interrupted
 
Field Summary
static int ARG_TEAM
           
static int CLASS_ENGINEER
           
static int CLASS_FIELDOPS
           
static int CLASS_MEDIC
           
static int CLASS_NONE
           
static int CLASS_SOLDIER
           
protected  CSight m_AimedAgent
          Current aimed enemy
protected  Vector3D[] m_AStarPath
          Array of points used in walking (a calculated) path task
protected  boolean m_bEscaping
          Variable indicating if agent is escaping at this moment
protected  boolean m_bFighting
          Variable indicating if agent is fighting at this moment
protected  boolean m_bObjectiveCarried
          Variable indicating if this agent is carrying the objective pack (flag)
protected  Vector3D[] m_ControlPoints
          Array of points used in patrolling task
protected  CTask m_CurrentTask
          Variable used to point the current task in execution
protected  int m_eClass
           
protected  int m_eTeam
           
protected  java.util.ArrayList m_FOVObjects
          List of objects in the agent's Field Of Vision
protected  int m_iAStarPathIndex
          Current position in array m_AStarPath
protected  int m_iControlPointsIndex
          Current position in array m_ControlPoints
protected  int m_iEngineersCount
           
protected  int m_iFieldOpsCount
           
protected  int m_iMedicsCount
           
protected  int m_iSoldiersCount
           
protected  int m_iTeamCount
           
protected  jade.core.AID m_Manager
          Variable used to store the AID of Manager
protected  CTerrainMap m_Map
          Current Map
protected  CMobile m_Movement
          Current position, direction, and so on...
protected  java.lang.String m_sAmmoService
           
protected  java.lang.String m_sBackupService
           
protected  java.lang.String m_sMedicService
           
protected  java.util.Hashtable m_TaskList
          List of prepared to execut tasks
protected  int[] m_TaskPriority
          Array of default values of priorities for each task
protected  es.upv.dsic.gti_ia.jgomas.CThreshold m_Threshold
          Limits of some variables (to trigger some events)
protected static int MV_CANNOT_GET_POSITION
           
protected static int MV_NOT_MOVED_BY_TIME
           
protected static int MV_OK
           
static int TEAM_ALLIED
           
static int TEAM_AXIS
           
static int TEAM_NONE
           
protected static int TRANSITION_DEFAULT
           
protected static int TRANSITION_TO_FIGHTING
           
protected static int TRANSITION_TO_GOTO_TARGET
           
protected static int TRANSITION_TO_STANDING
           
protected static int TRANSITION_TO_TARGET_REACHED
           
 
Fields inherited from class es.upv.dsic.gti_ia.jgomas.CJGomasAgent
m_ID, m_ServiceList
 
Fields inherited from class jade.core.Agent
AP_ACTIVE, AP_DELETED, AP_IDLE, AP_INITIATED, AP_MAX, AP_MIN, AP_SUSPENDED, AP_WAITING, D_ACTIVE, D_MAX, D_MIN, D_RETIRED, D_SUSPENDED, D_UNKNOWN
 
Constructor Summary
CBasicTroop()
           
 
Method Summary
protected  void AddServiceType(java.lang.String _sServiceType)
          Adds a type of service to the service type list.
protected  void AddTask(int _tTypeOfTask, jade.core.AID _Owner, java.lang.String _sContent)
          Adds a task to the task list.
protected  void AddTask(int _tTypeOfTask, jade.core.AID _Owner, java.lang.String _sContent, int _iPriority)
          Adds a task to the task list with a modified priority.
protected  void CallForAmmo()
          Request for ammunition.
protected  void CallForBackup()
          Request for backup.
protected  void CallForMedic()
          Request for medicine.
protected  boolean CheckStaticPosition()
          Checks our position on the static map.
protected  boolean CheckStaticPosition(double _x, double _z)
          Checks a position on the static map.
protected  void CreateControlPoints()
          Calculates an array of positions for patrolling.
protected  void GenerateEscapePosition()
          Calculates a new destiny position to escape.
protected  boolean GeneratePath()
          Calculates a new destiny position to walk.
protected  boolean GetAgentToAim()
          Calculates if there is an enemy at sight.
protected  int GetAmmo()
          Get the current ammunition of the agent.
protected  int GetHealth()
          Get the current health of the agent.
protected  int GetPower()
          Get the current power of the agent.
protected  int GetStamina()
          Get the current stamina of the agent.
protected  boolean HaveAgentToShot()
          To know if an enemy is aimed.
protected  void Look()
          The agent looks in the direction he is walking.
protected  int Move(long _dt)
           
protected  void ObjectivePackTaken()
          The agent has got the objective pack.
protected  void PerformAimAction()
          Action to do when agent has an enemy at sight.
protected  void PerformInjuryAction()
          Action to do when an agent is being shot.
protected  void PerformLookAction()
          Action to do when the agent is looking at.
protected  void PerformNoAmmoAction()
          Action to do if this agent cannot shoot.
protected  void PerformTargetReached(CTask _CurrentTask)
          Action to do when this agent reaches the target of current task.
protected  void PerformThresholdAction()
          Action to do when ammo or health values exceed the threshold allowed.
protected  void setup()
          'setup' method of jade agents.
protected  void SetUpPriorities()
          Definition of priorities for each kind of task.
protected  boolean Shot(int _iShotNum)
          The agent shoots in the direction which he is aiming.
protected  boolean ShouldUpdateTargets()
          Should we update now all 'prepared (to execute)' tasks?
protected  void takeDown()
          'takeDown' method of jade agents.
protected  void UpdateTargets()
          Update priority of all 'prepared (to execute)' tasks.
protected  void UsePower()
          Use power from the power bar if possible (there is at least 25 units).
protected  void UseStamina()
          Use stamina from the stamina bar if possible (there is at least 5 units).
 
Methods inherited from class es.upv.dsic.gti_ia.jgomas.CJGomasAgent
AddService
 
Methods inherited from class jade.core.Agent
addBehaviour, afterClone, afterMove, beforeClone, beforeMove, blockingReceive, blockingReceive, blockingReceive, blockingReceive, changeStateTo, clean, doActivate, doClone, doDelete, doMove, doSuspend, doTimeOut, doWait, doWait, doWake, getAgentState, getAID, getAMS, getArguments, getContainerController, getContentManager, getCurQueueSize, getDefaultDF, getHap, getHelper, getLocalName, getName, getO2AObject, getProperty, getQueueSize, getState, here, notifyChangeBehaviourState, notifyRestarted, postMessage, putBack, putO2AObject, receive, receive, removeBehaviour, restartLater, restore, restoreBufferedState, run, send, setArguments, setEnabledO2ACommunication, setGenerateBehaviourEvents, setQueueSize, waitUntilStarted, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_Manager

protected jade.core.AID m_Manager
Variable used to store the AID of Manager


m_TaskList

protected java.util.Hashtable m_TaskList
List of prepared to execut tasks


m_CurrentTask

protected CTask m_CurrentTask
Variable used to point the current task in execution


m_bObjectiveCarried

protected boolean m_bObjectiveCarried
Variable indicating if this agent is carrying the objective pack (flag)


m_TaskPriority

protected int[] m_TaskPriority
Array of default values of priorities for each task


m_ControlPoints

protected Vector3D[] m_ControlPoints
Array of points used in patrolling task


m_iControlPointsIndex

protected int m_iControlPointsIndex
Current position in array m_ControlPoints


m_AStarPath

protected Vector3D[] m_AStarPath
Array of points used in walking (a calculated) path task


m_iAStarPathIndex

protected int m_iAStarPathIndex
Current position in array m_AStarPath


m_FOVObjects

protected java.util.ArrayList m_FOVObjects
List of objects in the agent's Field Of Vision


m_AimedAgent

protected CSight m_AimedAgent
Current aimed enemy


ARG_TEAM

public static final int ARG_TEAM
See Also:
Constant Field Values

TEAM_NONE

public static final int TEAM_NONE
See Also:
Constant Field Values

TEAM_ALLIED

public static final int TEAM_ALLIED
See Also:
Constant Field Values

TEAM_AXIS

public static final int TEAM_AXIS
See Also:
Constant Field Values

CLASS_NONE

public static final int CLASS_NONE
See Also:
Constant Field Values

CLASS_SOLDIER

public static final int CLASS_SOLDIER
See Also:
Constant Field Values

CLASS_MEDIC

public static final int CLASS_MEDIC
See Also:
Constant Field Values

CLASS_ENGINEER

public static final int CLASS_ENGINEER
See Also:
Constant Field Values

CLASS_FIELDOPS

public static final int CLASS_FIELDOPS
See Also:
Constant Field Values

TRANSITION_DEFAULT

protected static final int TRANSITION_DEFAULT
See Also:
Constant Field Values

TRANSITION_TO_STANDING

protected static final int TRANSITION_TO_STANDING
See Also:
Constant Field Values

TRANSITION_TO_GOTO_TARGET

protected static final int TRANSITION_TO_GOTO_TARGET
See Also:
Constant Field Values

TRANSITION_TO_TARGET_REACHED

protected static final int TRANSITION_TO_TARGET_REACHED
See Also:
Constant Field Values

TRANSITION_TO_FIGHTING

protected static final int TRANSITION_TO_FIGHTING
See Also:
Constant Field Values

MV_OK

protected static final int MV_OK
See Also:
Constant Field Values

MV_CANNOT_GET_POSITION

protected static final int MV_CANNOT_GET_POSITION
See Also:
Constant Field Values

MV_NOT_MOVED_BY_TIME

protected static final int MV_NOT_MOVED_BY_TIME
See Also:
Constant Field Values

m_eTeam

protected int m_eTeam

m_eClass

protected int m_eClass

m_bFighting

protected boolean m_bFighting
Variable indicating if agent is fighting at this moment


m_bEscaping

protected boolean m_bEscaping
Variable indicating if agent is escaping at this moment


m_Movement

protected CMobile m_Movement
Current position, direction, and so on...


m_iSoldiersCount

protected int m_iSoldiersCount

m_iMedicsCount

protected int m_iMedicsCount

m_iEngineersCount

protected int m_iEngineersCount

m_iFieldOpsCount

protected int m_iFieldOpsCount

m_iTeamCount

protected int m_iTeamCount

m_Threshold

protected es.upv.dsic.gti_ia.jgomas.CThreshold m_Threshold
Limits of some variables (to trigger some events)


m_Map

protected CTerrainMap m_Map
Current Map


m_sMedicService

protected java.lang.String m_sMedicService

m_sAmmoService

protected java.lang.String m_sAmmoService

m_sBackupService

protected java.lang.String m_sBackupService
Constructor Detail

CBasicTroop

public CBasicTroop()
Method Detail

setup

protected void setup()
'setup' method of jade agents. This method perform actions in common to CBasicTroop agents (and derived classes) and calls parent's setup.

Overrides:
setup in class CJGomasAgent

takeDown

protected void takeDown()
'takeDown' method of jade agents. This method calls parent's setup.

Overrides:
takeDown in class CJGomasAgent

Move

protected final int Move(long _dt)

GetHealth

protected final int GetHealth()
Get the current health of the agent.

Returns:
m_iHealth: current value for health

GetAmmo

protected final int GetAmmo()
Get the current ammunition of the agent.

Returns:
m_iAmmo: current value for ammo

GetStamina

protected final int GetStamina()
Get the current stamina of the agent.

Returns:
m_iStamina: current value for stamina bar

UseStamina

protected final void UseStamina()
Use stamina from the stamina bar if possible (there is at least 5 units).


GetPower

protected final int GetPower()
Get the current power of the agent.

Returns:
m_iPower: current value for power bar

UsePower

protected final void UsePower()
Use power from the power bar if possible (there is at least 25 units). Power bar is reduced in 25 units.


AddServiceType

protected final void AddServiceType(java.lang.String _sServiceType)
Adds a type of service to the service type list. This method registers all types of services to offer in a list, excluding repeated services.

Parameters:
_sServiceType -

CheckStaticPosition

protected final boolean CheckStaticPosition()
Checks our position on the static map. This method checks if our position on the static map is valid to walk on, and returns the result. It must be called before to update variables.

Returns:
TRUE (agent can walk on) | FALSE (agent cannot walk on)

CheckStaticPosition

protected final boolean CheckStaticPosition(double _x,
                                            double _z)
Checks a position on the static map. This method checks if a position on the static map is valid to walk on, and returns the result.

Parameters:
_x -
_z -
Returns:
TRUE (agent can walk on) | FALSE (agent cannot walk on)

AddTask

protected final void AddTask(int _tTypeOfTask,
                             jade.core.AID _Owner,
                             java.lang.String _sContent)
Adds a task to the task list. This method adds a task to the task list with the default priority in agreement to the type of task. If there is a task of same type and same owner, it doesn't create a new task: simply substitutes some attributes with newer values.

Parameters:
_tTypeOfTask - one of the defined types of tasks.
_Owner - the agent that induces the creation of the task.
_sContent - is a position: ( x , y , z ) .

AddTask

protected final void AddTask(int _tTypeOfTask,
                             jade.core.AID _Owner,
                             java.lang.String _sContent,
                             int _iPriority)
Adds a task to the task list with a modified priority. This method adds a task to the task list with the priority passed as parameter, non the standard priority. If there is a task of same type and same owner, it doesn't create a new task: simply substitutes some attributes with newer values.

Parameters:
_tTypeOfTask - one of the defined types of tasks.
_Owner - the agent that induces the creation of the task.
_sContent - is a position: ( x , y , z ) .
_iPriority - priority of task

Look

protected final void Look()
The agent looks in the direction he is walking. This method sends a FIPA INFORM message to Manager. Once message is sent, agent will be blocked waiting a response message from Manager. The content of received message is stored in the variable m_FOVObjects.


Shot

protected final boolean Shot(int _iShotNum)
The agent shoots in the direction which he is aiming. This method sends a FIPA INFORM message to Manager. Once message is sent, the variable m_iAmmo is decremented.

Parameters:
_iShotNum -
Returns:
TRUE (shot done) | FALSE (cannot shoot, has no ammo)

PerformAimAction

protected final void PerformAimAction()
Action to do when agent has an enemy at sight. This method is called when agent has looked and has found an enemy, calculating (in agreement to the enemy position) the new direction where is aiming.


HaveAgentToShot

protected final boolean HaveAgentToShot()
To know if an enemy is aimed. This method is called just before agent can shoot. If an enemy is aimed, a value of TRUE is returned. Otherwise, the return value is FALSE. The result is used to decide if agent must shoot.

Returns:
TRUE (aimed enemy) | FALSE (no aimed enemy)

CallForMedic

protected void CallForMedic()
Request for medicine. This method sends a FIPA REQUEST message to all agents who offers the m_sMedicService service. The content of message is: ( x , y , z ) ( health ) . Variable m_iMedicsCount is updated. It's very useful to overload this method.


CallForAmmo

protected void CallForAmmo()
Request for ammunition. This method sends a FIPA REQUEST message to all agents who offers the m_sAmmoService service. The content of message is: ( x , y , z ) ( ammo ) . Variable m_iFieldOpsCount is updated. It's very useful to overload this method.


CallForBackup

protected void CallForBackup()
Request for backup. This method sends a FIPA REQUEST message to all agents who offers the m_sBackupService service. The content of message is: ( x , y , z ) ( SoldiersCount ) . Variable m_iSoldiersCount is updated. It's very useful to overload this method.


UpdateTargets

protected void UpdateTargets()
Update priority of all 'prepared (to execute)' tasks. This method is invoked in the state STANDING, and it's used to re-calculate the priority of all tasks (targets) int the task list of the agent. The reason is because JGOMAS kernel always execute the highest priority task. It's very useful to overload this method.


ShouldUpdateTargets

protected boolean ShouldUpdateTargets()
Should we update now all 'prepared (to execute)' tasks? This method is a decision function invoked in the state GOTO_TARGET. A value of TRUE break out the inner loop, making possible to JGOMAS kernel extract the highest priority task, or update some attributes of the current task. By default, the return value is FALSE, so we execute the current task until it finalizes. It's very useful to overload this method.

Returns:
FALSE

ObjectivePackTaken

protected void ObjectivePackTaken()
The agent has got the objective pack. This method is called when this agent walks on the objective pack, getting it. It's very useful to overload this method.


SetUpPriorities

protected void SetUpPriorities()
Definition of priorities for each kind of task. This method can be implemented in CBasicTroop's derived classes to define the task's priorities in agreement to the role of the new class. Priorities must be defined in the array m_TaskPriority. It's very useful to overload this method.


PerformNoAmmoAction

protected void PerformNoAmmoAction()
Action to do if this agent cannot shoot. This method is called when the agent try to shoot, but has no ammo. The agent will spit enemies out. :-) It's very useful to overload this method.


PerformTargetReached

protected void PerformTargetReached(CTask _CurrentTask)
Action to do when this agent reaches the target of current task. This method is called when the agent goes to state TARGET_REACHED. In agreement to current task, agent must realize some actions (for example, to get next point to walk from patrolling path). The actions in common to all roles are implemented at this level of hierarchy: TASK_PATROLLING, TASK_WALKING_PATH, TASK_RUN_AWAY. It's very useful to overload this method.

Parameters:
_CurrentTask -

GenerateEscapePosition

protected void GenerateEscapePosition()
Calculates a new destiny position to escape. This method is called before the agent creates a task for escaping. It generates a valid random point in a radius of 50 units. Once position is calculated, agent updates its destiny to the new position, and automatically calculates the new direction. It's very useful to overload this method.


GeneratePath

protected boolean GeneratePath()
Calculates a new destiny position to walk. This method is called before the agent creates a TASK_GOTO_POSITION task. It will try (for 5 attempts) to generate a valid random point in a radius of 20 units. If it doesn't generate a valid position in this cycle, it will try it in next cycle. Once a position is calculated, agent updates its destination to the new position, and automatically calculates the new direction. It's very useful to overload this method.

Returns:
TRUE: valid position generated / FALSE cannot generate a valid position

CreateControlPoints

protected void CreateControlPoints()
Calculates an array of positions for patrolling. When this method is called, it creates an array of n random positions. For medics and fieldops, the rank of n is [1..1]. For soldiers, the rank of n is [5..10]. It's very useful to overload this method.


PerformInjuryAction

protected void PerformInjuryAction()
Action to do when an agent is being shot. This method is called every time this agent receives a messager from agent Manager informing it is being shot. It's very useful to overload this method.


PerformThresholdAction

protected void PerformThresholdAction()
Action to do when ammo or health values exceed the threshold allowed. This method is called when current values of ammo and health exceed the threshold allowed. These values are checked by Launch_MedicAmmo_RequestBehaviour behaviour, every ten seconds. Perhaps it is convenient to create a TASK_RUN_AWAY task. It's very useful to overload this method.


GetAgentToAim

protected boolean GetAgentToAim()
Calculates if there is an enemy at sight. This method scans the list m_FOVObjects (objects in the Field Of View of the agent) looking for an enemy. If an enemy agent is found, a value of TRUE is returned and variable m_AimedAgent is updated. Note that there is no criterion (proximity, etc.) for the enemy found. Otherwise, the return value is FALSE. It's very useful to overload this method.

Returns:
TRUE: enemy found / FALSE enemy not found

PerformLookAction

protected void PerformLookAction()
Action to do when the agent is looking at. This method is called just after Look method has ended. It's very useful to overload this method.