OpenXcom
1.0
Open-source clone of the original X-Com
|
This class is used by the BattleUnit AI. More...
#include <AlienBAIState.h>
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... | |
This class is used by the BattleUnit AI.
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.
save | Pointer to the battle game. |
unit | Pointer to the unit. |
node | Pointer to the node the unit originates from. |
OpenXcom::AlienBAIState::~AlienBAIState | ( | ) |
Cleans up the AlienBAIState.
Deletes the BattleAIState.
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.
|
virtual |
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.
|
virtual |
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.
targetPos | The target's position. |
attackingUnit | The attacking unit. |
radius | How big the explosion will be. |
diff | Game difficulty. |
grenade | Is the explosion coming from a grenade? |
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.
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.
node | YAML 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.
|
virtual |
Saves the AI state to YAML.
Saves the AI state to a YAML file.
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
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.
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.
target | Pointer to a target. |
maxTUs | Maximum time units the path to the target can cost. |
bool OpenXcom::AlienBAIState::selectRandomTarget | ( | ) |
Selects a random known target.
Selects a random known living Xcom or civilian unit.
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.
|
virtual |
Runs state functionality every AI cycle.
Runs any code the state needs to keep updating every AI cycle.
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.