OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | List of all members
OpenXcom::AlienBAIState Class Reference

This class is used by the BattleUnit AI. More...

#include <AlienBAIState.h>

Inheritance diagram for OpenXcom::AlienBAIState:
OpenXcom::BattleAIState

Public Member Functions

 AlienBAIState (SavedBattleGame *save, BattleUnit *unit, Node *node)
 Creates a new AlienBAIState linked to the game and a certain unit. More...
 
 ~AlienBAIState ()
 Cleans up the AlienBAIState. More...
 
void load (const YAML::Node &node)
 Loads the AI state from YAML. More...
 
YAML::Node save () const
 Saves the AI state to YAML. More...
 
void enter ()
 Enters the state. More...
 
void exit ()
 Exits the state. More...
 
void think (BattleAction *action)
 Runs state functionality every AI cycle. More...
 
void setWasHit ()
 Sets the "unit was hit" flag true.
 
bool getWasHit () const
 Gets whether the unit was hit.
 
void setupPatrol ()
 setup a patrol objective.
 
void setupAmbush ()
 setup an ambush objective. More...
 
void setupAttack ()
 setup a combat objective. More...
 
void setupEscape ()
 setup an escape objective. More...
 
int countKnownTargets () const
 count how many xcom/civilian units are known to this unit. More...
 
int getSpottingUnits (Position pos) const
 count how many known XCom units are able to see this unit.
 
int selectNearestTarget ()
 Selects the nearest target we can see, and return the number of viable targets. More...
 
bool selectClosestKnownEnemy ()
 Selects the closest known xcom unit for ambushing. More...
 
bool selectRandomTarget ()
 Selects a random known target. More...
 
bool selectPointNearTarget (BattleUnit *target, int maxTUs) const
 Selects the nearest reachable point relative to a target. More...
 
void evaluateAIMode ()
 re-evaluate our situation, and make a decision from our available options. More...
 
bool findFirePoint ()
 Selects a suitable position from which to attack. More...
 
bool explosiveEfficacy (Position targetPos, BattleUnit *attackingUnit, int radius, int diff, bool grenade=false) const
 Decides if we should throw a grenade/launch a missile to this position. More...
 
void meleeAction ()
 Attempts to take a melee attack/charge an enemy we can see. More...
 
void wayPointAction ()
 Attempts to fire a waypoint projectile at an enemy we, or one of our teammates sees. More...
 
void projectileAction ()
 Attempts to fire at an enemy we can see. More...
 
void selectFireMethod ()
 Selects a fire method. More...
 
void grenadeAction ()
 Attempts to throw a grenade at an enemy (or group of enemies) we can see. More...
 
bool psiAction ()
 Performs a psionic attack. More...
 
void meleeAttack ()
 Performs a melee attack action.
 
- Public Member Functions inherited from OpenXcom::BattleAIState
 BattleAIState (SavedBattleGame *save, BattleUnit *unit)
 Creates a new BattleAIState linked to the game and a certain unit. More...
 
virtual ~BattleAIState ()
 Cleans up the BattleAIState. More...
 
void load (const YAML::Node &node)
 Loads the AI state from YAML. More...
 

Detailed Description

This class is used by the BattleUnit AI.

Constructor & Destructor Documentation

OpenXcom::AlienBAIState::AlienBAIState ( SavedBattleGame save,
BattleUnit unit,
Node node 
)

Creates a new AlienBAIState linked to the game and a certain unit.

Sets up a BattleAIState.

Parameters
savePointer to the battle game.
unitPointer to the unit.
nodePointer to the node the unit originates from.
OpenXcom::AlienBAIState::~AlienBAIState ( )

Cleans up the AlienBAIState.

Deletes the BattleAIState.

Member Function Documentation

int OpenXcom::AlienBAIState::countKnownTargets ( ) const

count how many xcom/civilian units are known to this unit.

Counts how many targets, both xcom and civilian are known to this unit.

Returns
how many targets are known to us.
void OpenXcom::AlienBAIState::enter ( )
virtual

Enters the state.

Enters the current AI state.

Reimplemented from OpenXcom::BattleAIState.

void OpenXcom::AlienBAIState::evaluateAIMode ( )

re-evaluate our situation, and make a decision from our available options.

Selects an AI mode based on a number of factors, some RNG and the results of the rest of the determinations.

void OpenXcom::AlienBAIState::exit ( )
virtual

Exits the state.

Exits the current AI state.

Reimplemented from OpenXcom::BattleAIState.

bool OpenXcom::AlienBAIState::explosiveEfficacy ( Position  targetPos,
BattleUnit attackingUnit,
int  radius,
int  diff,
bool  grenade = false 
) const

Decides if we should throw a grenade/launch a missile to this position.

Decides if it worth our while to create an explosion here.

Parameters
targetPosThe target's position.
attackingUnitThe attacking unit.
radiusHow big the explosion will be.
diffGame difficulty.
grenadeIs the explosion coming from a grenade?
Returns
True if it is worthwhile creating an explosion in the target position.
bool OpenXcom::AlienBAIState::findFirePoint ( )

Selects a suitable position from which to attack.

Find a position where we can see our target, and move there.

check the 11x11 grid for a position nearby where we can potentially target him.

Returns
True if a possible position was found.
void OpenXcom::AlienBAIState::grenadeAction ( )

Attempts to throw a grenade at an enemy (or group of enemies) we can see.

Evaluates whether to throw a grenade at an enemy (or group of enemies) we can see.

void OpenXcom::AlienBAIState::load ( const YAML::Node &  node)

Loads the AI state from YAML.

Loads the AI state from a YAML file.

Parameters
nodeYAML node.
void OpenXcom::AlienBAIState::meleeAction ( )

Attempts to take a melee attack/charge an enemy we can see.

Melee targetting: we can see an enemy, we can move to it so we're charging blindly toward an enemy.

void OpenXcom::AlienBAIState::projectileAction ( )

Attempts to fire at an enemy we can see.

Regular targeting: we can see an enemy, we have a gun, let's try to shoot.

bool OpenXcom::AlienBAIState::psiAction ( )

Performs a psionic attack.

Attempts a psionic attack on an enemy we "know of".

Psionic targetting: pick from any of the "exposed" units. Exposed means they have been previously spotted, and are therefore "known" to the AI, regardless of whether we can see them or not, because we're psychic.

Returns
True if a psionic attack is performed.
YAML::Node OpenXcom::AlienBAIState::save ( ) const
virtual

Saves the AI state to YAML.

Saves the AI state to a YAML file.

Returns
YAML node.

Reimplemented from OpenXcom::BattleAIState.

bool OpenXcom::AlienBAIState::selectClosestKnownEnemy ( )

Selects the closest known xcom unit for ambushing.

Selects the nearest known living Xcom unit.

used for ambush calculations

Returns
if we found one.
void OpenXcom::AlienBAIState::selectFireMethod ( )

Selects a fire method.

Selects a fire method based on range, time units, and time units reserved for cover.

int OpenXcom::AlienBAIState::selectNearestTarget ( )

Selects the nearest target we can see, and return the number of viable targets.

Selects the nearest known living target we can see/reach and returns the number of visible enemies.

This function includes civilians as viable targets.

Returns
viable targets.
bool OpenXcom::AlienBAIState::selectPointNearTarget ( BattleUnit target,
int  maxTUs 
) const

Selects the nearest reachable point relative to a target.

Selects a point near enough to our target to perform a melee attack.

Parameters
targetPointer to a target.
maxTUsMaximum time units the path to the target can cost.
Returns
True if a point was found.
bool OpenXcom::AlienBAIState::selectRandomTarget ( )

Selects a random known target.

Selects a random known living Xcom or civilian unit.

Returns
if we found one.
void OpenXcom::AlienBAIState::setupAmbush ( )

setup an ambush objective.

Try to set up an ambush action The idea is to check within a 11x11 tile square for a tile which is not seen by our aggroTarget, but that can be reached by him.

we then intuit where we will see the target first from our covered position, and set that as our final facing. Fills out the _ambushAction with useful data.

void OpenXcom::AlienBAIState::setupAttack ( )

setup a combat objective.

Try to set up a combat action This will either be a psionic, grenade, or weapon attack, or potentially just moving to get a line of sight to a target.

Fills out the _attackAction with useful data.

void OpenXcom::AlienBAIState::setupEscape ( )

setup an escape objective.

Attempts to find cover, and move toward it.

The idea is to check within a 11x11 tile square for a tile which is not seen by our aggroTarget. If there is no such tile, we run away from the target. Fills out the _escapeAction with useful data.

void OpenXcom::AlienBAIState::think ( BattleAction action)
virtual

Runs state functionality every AI cycle.

Runs any code the state needs to keep updating every AI cycle.

Parameters
action(possible) AI action to execute after thinking is done.

Reimplemented from OpenXcom::BattleAIState.

void OpenXcom::AlienBAIState::wayPointAction ( )

Attempts to fire a waypoint projectile at an enemy we, or one of our teammates sees.

Waypoint targeting: pick from any units currently spotted by our allies.


The documentation for this class was generated from the following files: