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 | Public Attributes | List of all members
OpenXcom::BattleUnit Class Reference

Represents a moving unit in the battlescape, player controlled or AI controlled it holds info about it's position, items carrying, stats, etc. More...

#include <BattleUnit.h>

Public Member Functions

 BattleUnit (Soldier *soldier, UnitFaction faction)
 Creates a BattleUnit. More...
 
 BattleUnit (Unit *unit, UnitFaction faction, int id, Armor *armor, int diff)
 Initializes a BattleUnit from a Unit (non-player) object. More...
 
 ~BattleUnit ()
 Cleans up the BattleUnit.
 
void load (const YAML::Node &node)
 Loads the unit from YAML. More...
 
YAML::Node save () const
 Saves the unit to YAML. More...
 
int getId () const
 Gets the BattleUnit's ID. More...
 
void setPosition (const Position &pos, bool updateLastPos=true)
 Sets the unit's position. More...
 
const PositiongetPosition () const
 Gets the unit's position. More...
 
const PositiongetLastPosition () const
 Gets the unit's position. More...
 
void setDirection (int direction)
 Sets the unit's direction 0-7. More...
 
void setFaceDirection (int direction)
 Sets the unit's face direction (only used by strafing moves) More...
 
int getDirection () const
 Gets the unit's direction. More...
 
int getFaceDirection () const
 Gets the unit's face direction (only used by strafing moves) More...
 
int getTurretDirection () const
 Gets the unit's turret direction. More...
 
int getTurretToDirection () const
 Gets the unit's turret To direction. More...
 
int getVerticalDirection () const
 Gets the unit's vertical direction. More...
 
UnitStatus getStatus () const
 Gets the unit's status. More...
 
void startWalking (int direction, const Position &destination, Tile *tileBelowMe, bool cache)
 Start the walkingPhase. More...
 
void keepWalking (Tile *tileBelowMe, bool cache)
 Increase the walkingPhase. More...
 
int getWalkingPhase () const
 Gets the walking phase for animation and sound. More...
 
int getDiagonalWalkingPhase () const
 Gets the walking phase for diagonal walking. More...
 
const PositiongetDestination () const
 Gets the unit's destination when walking. More...
 
void lookAt (const Position &point, bool turret=false)
 Look at a certain point. More...
 
void lookAt (int direction, bool force=false)
 Look at a certain direction. More...
 
void turn (bool turret=false)
 Turn to the destination direction. More...
 
void abortTurn ()
 Abort turning. More...
 
SoldierGender getGender () const
 Gets the soldier's gender.
 
UnitFaction getFaction () const
 Gets the unit's faction. More...
 
void setCache (Surface *cache, int part=0)
 Set the cached flag. More...
 
SurfacegetCache (bool *invalid, int part=0) const
 If this unit is cached on the battlescape. More...
 
void kneel (bool kneeled)
 Kneel down. More...
 
bool isKneeled () const
 Is kneeled? More...
 
bool isFloating () const
 Is floating? More...
 
void aim (bool aiming)
 Aim. More...
 
int directionTo (const Position &point) const
 Get direction to a certain point. More...
 
int getTimeUnits () const
 Gets the unit's time units. More...
 
int getEnergy () const
 Gets the unit's stamina. More...
 
int getHealth () const
 Gets the unit's health. More...
 
int getMorale () const
 Gets the unit's bravery. More...
 
int damage (const Position &relative, int power, ItemDamageType type, bool ignoreArmor=false)
 Do damage to the unit. More...
 
void healStun (int power)
 Heal stun level of the unit. More...
 
int getStunlevel () const
 Gets the unit's stun level.
 
void knockOut (BattlescapeGame *battle)
 Knocks the unit out instantly. More...
 
void startFalling ()
 Start falling sequence. More...
 
void keepFalling ()
 Increment the falling sequence. More...
 
int getFallingPhase () const
 Get falling sequence. More...
 
bool isOut () const
 The unit is out - either dead or unconscious. More...
 
int getActionTUs (BattleActionType actionType, BattleItem *item)
 Get the number of time units a certain action takes. More...
 
bool spendTimeUnits (int tu)
 Spend time units if it can. More...
 
bool spendEnergy (int tu)
 Spend energy if it can. More...
 
void setTimeUnits (int tu)
 Set time units. More...
 
bool addToVisibleUnits (BattleUnit *unit)
 Add unit to visible units. More...
 
std::vector< BattleUnit * > * getVisibleUnits ()
 Get the list of visible units. More...
 
void clearVisibleUnits ()
 Clear visible units.
 
bool addToVisibleTiles (Tile *tile)
 Add unit to visible tiles. More...
 
std::vector< Tile * > * getVisibleTiles ()
 Get the list of visible tiles. More...
 
void clearVisibleTiles ()
 Clear visible tiles.
 
int getFiringAccuracy (BattleActionType actionType, BattleItem *item)
 Calculate firing accuracy. More...
 
int getAccuracyModifier (BattleItem *item=0)
 Calculate accuracy modifier. More...
 
double getThrowingAccuracy ()
 Calculate throwing accuracy. More...
 
void setArmor (int armor, UnitSide side)
 Set armor value. More...
 
int getArmor (UnitSide side) const
 Get armor value. More...
 
int getFatalWounds () const
 Get total number of fatal wounds. More...
 
double getReactionScore ()
 Get the current reaction score. More...
 
void prepareNewTurn ()
 Prepare for a new turn.
 
void moraleChange (int change)
 Morale change. More...
 
void dontReselect ()
 Don't reselect this unit. More...
 
void allowReselect ()
 Reselect this unit. More...
 
bool reselectAllowed () const
 Check whether reselecting this unit is allowed. More...
 
void setFire (int fire)
 Set fire. More...
 
int getFire () const
 Get fire. More...
 
std::vector< BattleItem * > * getInventory ()
 Get the list of items in the inventory. More...
 
void think (BattleAction *action)
 Let AI do their thing. More...
 
BattleAIStategetCurrentAIState () const
 Get current AI state. More...
 
void setAIState (BattleAIState *aiState)
 Set next AI State. More...
 
void setVisible (bool flag)
 Set whether this unit is visible. More...
 
bool getVisible () const
 Get whether this unit is visible. More...
 
void setTile (Tile *tile, Tile *tileBelow=0)
 Sets the unit's tile it's standing on. More...
 
TilegetTile () const
 Gets the unit's tile. More...
 
BattleItemgetItem (RuleInventory *slot, int x=0, int y=0) const
 Gets the item in the specified slot. More...
 
BattleItemgetItem (const std::string &slot, int x=0, int y=0) const
 Gets the item in the specified slot. More...
 
BattleItemgetMainHandWeapon (bool quickest=true) const
 Gets the item in the main hand. More...
 
BattleItemgetGrenadeFromBelt () const
 Gets a grenade from the belt, if any. More...
 
bool checkAmmo ()
 Reloads righthand weapon if needed. More...
 
bool isInExitArea (SpecialTileType stt=START_POINT) const
 Check if this unit is in the exit area. More...
 
int getHeight () const
 Gets the unit height taking into account kneeling/standing. More...
 
int getFloatHeight () const
 Gets the unit floating elevation. More...
 
void addReactionExp ()
 Adds one to the reaction exp counter.
 
void addFiringExp ()
 Adds one to the firing exp counter.
 
void addThrowingExp ()
 Adds one to the throwing exp counter. More...
 
void addPsiExp ()
 Adds one to the psi exp counter. More...
 
void addMeleeExp ()
 Adds one to the melee exp counter. More...
 
void updateGeoscapeStats (Soldier *soldier)
 Updates the stats of a Geoscape soldier.
 
bool postMissionProcedures (SavedGame *geoscape)
 Check if unit eligible for squaddie promotion. More...
 
int getMiniMapSpriteIndex () const
 Get the sprite index for the minimap. More...
 
void setTurretType (int turretType)
 Set the turret type. -1 is no turret. More...
 
int getTurretType () const
 Get the turret type. -1 is no turret. More...
 
int getFatalWound (int part) const
 Get fatal wound amount of a body part. More...
 
void heal (int part, int woundAmount, int healthAmount)
 Heal one fatal wound. More...
 
void painKillers ()
 Give pain killers to this unit. More...
 
void stimulant (int energy, int stun)
 Give stimulant to this unit. More...
 
int getMotionPoints () const
 Get motion points for the motion scanner. More...
 
ArmorgetArmor () const
 Gets the unit's armor. More...
 
std::wstring getName (Language *lang, bool debugAppendId=false) const
 Gets the unit's name. More...
 
UnitStatsgetStats ()
 Gets the unit's stats. More...
 
int getStandHeight () const
 Get the unit's stand height. More...
 
int getKneelHeight () const
 Get the unit's kneel height. More...
 
int getLoftemps (int entry=0) const
 Get the unit's loft ID. More...
 
int getValue () const
 Get the unit's value. More...
 
int getDeathSound () const
 Get the unit's death sound. More...
 
int getMoveSound () const
 Get the unit's move sound. More...
 
bool isWoundable () const
 Get whether the unit is affected by fatal wounds. More...
 
bool isFearable () const
 Get whether the unit is affected by fear. More...
 
int getIntelligence () const
 Get the unit's intelligence. More...
 
int getAggression () const
 Get the unit's aggression. More...
 
int getSpecialAbility () const
 Get the units's special ability. More...
 
void setSpecialAbility (SpecialAbility specab)
 Set the units's special ability. More...
 
std::string getRankString () const
 Get the units's rank string. More...
 
SoldiergetGeoscapeSoldier () const
 Get the geoscape-soldier object. More...
 
void addKillCount ()
 Add a kill to the counter.
 
std::string getType () const
 Get unit type. More...
 
void setActiveHand (const std::string &slot)
 Set the hand this unit is using;. More...
 
std::string getActiveHand () const
 Get unit's active hand. More...
 
void convertToFaction (UnitFaction f)
 Convert's unit to a faction. More...
 
void instaKill ()
 Set health to 0 and set status dead. More...
 
std::string getSpawnUnit () const
 Gets the unit's spawn unit. More...
 
void setSpawnUnit (std::string spawnUnit)
 Sets the unit's spawn unit. More...
 
int getAggroSound () const
 Gets the unit's aggro sound. More...
 
void setEnergy (int energy)
 Sets the unit's energy level. More...
 
void halveArmor ()
 Halve the unit's armor values. More...
 
UnitFaction killedBy () const
 Get the faction that killed this unit. More...
 
void killedBy (UnitFaction f)
 Set the faction that killed this unit. More...
 
void setCharging (BattleUnit *chargeTarget)
 Set the units we are charging towards. More...
 
BattleUnitgetCharging ()
 Get the units we are charging towards. More...
 
int getCarriedWeight (BattleItem *draggingItem=0) const
 Get the carried weight in strength units. More...
 
void setTurnsSinceSpotted (int turns)
 Set how many turns this unit will be exposed for. More...
 
int getTurnsSinceSpotted () const
 Set how many turns this unit will be exposed for. More...
 
UnitFaction getOriginalFaction () const
 Get this unit's original faction. More...
 
void invalidateCache ()
 call this after the default copy constructor deletes the cache? More...
 
std::vector< BattleUnit * > & getUnitsSpottedThisTurn ()
 get the vector of units we've seen this turn. More...
 
void setRankInt (int rank)
 set the rank integer More...
 
int getRankInt () const
 get the rank integer More...
 
void deriveRank ()
 derive a rank integer based on rank string (for xcom soldiers ONLY) More...
 
bool checkViewSector (Position pos) const
 this function checks if a tile is visible, using maths. More...
 
void adjustStats (const int diff)
 adjust this unit's stats according to difficulty. More...
 
bool tookFireDamage () const
 did this unit already take fire damage this turn? (used to avoid damaging large units multiple times.) More...
 
void toggleFireDamage ()
 switch the state of the fire damage tracker. More...
 
void setCoverReserve (int reserve)
 Changes the amount of TUs reserved for cover. More...
 
int getCoverReserve () const
 Returns the amount of TUs reserved for cover. More...
 
bool isSelectable (UnitFaction faction, bool checkReselect, bool checkInventory) const
 Is this unit selectable? More...
 
bool hasInventory () const
 Does this unit have an inventory? More...
 

Public Attributes

bool _hidingForTurn
 scratch value for AI's left hand to tell its right hand what's up...
 

Detailed Description

Represents a moving unit in the battlescape, player controlled or AI controlled it holds info about it's position, items carrying, stats, etc.

Constructor & Destructor Documentation

OpenXcom::BattleUnit::BattleUnit ( Soldier soldier,
UnitFaction  faction 
)

Creates a BattleUnit.

Initializes a BattleUnit from a Soldier.

Parameters
soldierPointer to the Soldier.
factionWhich faction the units belongs to.
OpenXcom::BattleUnit::BattleUnit ( Unit unit,
UnitFaction  faction,
int  id,
Armor armor,
int  diff 
)

Initializes a BattleUnit from a Unit (non-player) object.

Parameters
unitPointer to Unit object.
factionWhich faction the units belongs to.
idUnique unit ID.
armorPointer to unit Armor.
diffdifficulty level (for stat adjustement).

Member Function Documentation

void OpenXcom::BattleUnit::abortTurn ( )

Abort turning.

Stops the turning towards the target direction.

void OpenXcom::BattleUnit::addMeleeExp ( )

Adds one to the melee exp counter.

Adds one to the firing exp counter.

void OpenXcom::BattleUnit::addPsiExp ( )

Adds one to the psi exp counter.

Adds one to the firing exp counter.

void OpenXcom::BattleUnit::addThrowingExp ( )

Adds one to the throwing exp counter.

Adds one to the firing exp counter.

bool OpenXcom::BattleUnit::addToVisibleTiles ( Tile tile)

Add unit to visible tiles.

Add this unit to the list of visible tiles.

Returns true if this is a new one.

Parameters
tile
Returns
bool OpenXcom::BattleUnit::addToVisibleUnits ( BattleUnit unit)

Add unit to visible units.

Add this unit to the list of visible units.

Returns true if this is a new one.

Parameters
unit
Returns
void OpenXcom::BattleUnit::adjustStats ( const int  diff)

adjust this unit's stats according to difficulty.

common function to adjust a unit's stats according to difficulty setting.

Parameters
diffdifficulty level (for stat adjustement).
void OpenXcom::BattleUnit::aim ( bool  aiming)

Aim.

(shows the right hand sprite and weapon holding)

Parameters
aimingtrue/false
void OpenXcom::BattleUnit::allowReselect ( )

Reselect this unit.

Mark this unit as reselectable.

bool OpenXcom::BattleUnit::checkAmmo ( )

Reloads righthand weapon if needed.

Check if we have ammo and reload if needed (used for AI).

Returns
Do we have ammo?
bool OpenXcom::BattleUnit::checkViewSector ( Position  pos) const

this function checks if a tile is visible, using maths.

Parameters
posthe position to check against
Returns
what the maths decide
void OpenXcom::BattleUnit::convertToFaction ( UnitFaction  f)

Convert's unit to a faction.

Converts unit to another faction (original faction is still stored).

Parameters
ffaction.
int OpenXcom::BattleUnit::damage ( const Position relative,
int  power,
ItemDamageType  type,
bool  ignoreArmor = false 
)

Do damage to the unit.

Do an amount of damage.

Parameters
relativeThe relative position of which part of armor and/or bodypart is hit.
powerThe amount of damage to inflict.
typeThe type of damage being inflicted.
ignoreArmorShould the damage ignore armor resistance?
Returns
damage done after adjustment
void OpenXcom::BattleUnit::deriveRank ( )

derive a rank integer based on rank string (for xcom soldiers ONLY)

Derive the numeric unit rank from the string rank (for soldier units).

int OpenXcom::BattleUnit::directionTo ( const Position point) const

Get direction to a certain point.

Returns the direction from this unit to a given point.

Parameters
pointgiven position.
Returns
direction.
void OpenXcom::BattleUnit::dontReselect ( )

Don't reselect this unit.

Mark this unit as not reselectable.

int OpenXcom::BattleUnit::getAccuracyModifier ( BattleItem item = 0)

Calculate accuracy modifier.

To calculate firing accuracy.

Takes health and fatal wounds into account. Formula = accuracyStat * woundsPenalty(% health) * critWoundsPenalty (-10%/wound)

Parameters
itemthe item we are shooting right now.
Returns
modifier
int OpenXcom::BattleUnit::getActionTUs ( BattleActionType  actionType,
BattleItem item 
)

Get the number of time units a certain action takes.

Parameters
actionType
item
Returns
TUs
std::string OpenXcom::BattleUnit::getActiveHand ( ) const

Get unit's active hand.

Returns
active hand.
int OpenXcom::BattleUnit::getAggression ( ) const

Get the unit's aggression.

Returns
aggression.
int OpenXcom::BattleUnit::getAggroSound ( ) const

Gets the unit's aggro sound.

Get sound to play when unit aggros.

Returns
sound
int OpenXcom::BattleUnit::getArmor ( UnitSide  side) const

Get armor value.

Get the armor value of a certain armor side.

Parameters
sideThe side of the armor.
Returns
Amount of armor.
Armor * OpenXcom::BattleUnit::getArmor ( ) const

Gets the unit's armor.

Returns
Pointer to armor.
Surface * OpenXcom::BattleUnit::getCache ( bool *  invalid,
int  part = 0 
) const

If this unit is cached on the battlescape.

Check if the unit is still cached in the Map cache.

When the unit changes it needs to be re-cached.

Parameters
invalidGet if the cache is invalid.
partUnit part to check.
Returns
Pointer to cache surface used.
int OpenXcom::BattleUnit::getCarriedWeight ( BattleItem draggingItem = 0) const

Get the carried weight in strength units.

Get the units carried weight in strength units.

Parameters
draggingItemitem to ignore
Returns
weight
BattleUnit * OpenXcom::BattleUnit::getCharging ( )

Get the units we are charging towards.

Returns
Charge Target
int OpenXcom::BattleUnit::getCoverReserve ( ) const

Returns the amount of TUs reserved for cover.

Returns
time units.
BattleAIState * OpenXcom::BattleUnit::getCurrentAIState ( ) const

Get current AI state.

Returns the current AI state.

Returns
Pointer to AI state.
int OpenXcom::BattleUnit::getDeathSound ( ) const

Get the unit's death sound.

Returns
id.
const Position & OpenXcom::BattleUnit::getDestination ( ) const

Gets the unit's destination when walking.

Gets the BattleUnit's destination.

Returns
destination
int OpenXcom::BattleUnit::getDiagonalWalkingPhase ( ) const

Gets the walking phase for diagonal walking.

Returns
phase this will be 0 or 8
int OpenXcom::BattleUnit::getDirection ( ) const

Gets the unit's direction.

Gets the BattleUnit's (horizontal) direction.

Returns
horizontal direction
int OpenXcom::BattleUnit::getEnergy ( ) const

Gets the unit's stamina.

Returns the soldier's amount of energy.

Returns
Energy.
int OpenXcom::BattleUnit::getFaceDirection ( ) const

Gets the unit's face direction (only used by strafing moves)

Gets the BattleUnit's (horizontal) face direction.

Used only during strafing moves.

Returns
face direction
UnitFaction OpenXcom::BattleUnit::getFaction ( ) const

Gets the unit's faction.

Returns the unit's faction.

Returns
Faction. (player, hostile or neutral)
int OpenXcom::BattleUnit::getFallingPhase ( ) const

Get falling sequence.

Returns the phase of the falling sequence.

Returns
phase
int OpenXcom::BattleUnit::getFatalWound ( int  part) const

Get fatal wound amount of a body part.

Get the amount of fatal wound for a body part.

Parameters
partThe body part (in the range 0-5)
Returns
The amount of fatal wound of a body part
int OpenXcom::BattleUnit::getFatalWounds ( ) const

Get total number of fatal wounds.

Get total amount of fatal wounds this unit has.

Returns
Number of fatal wounds.
int OpenXcom::BattleUnit::getFire ( ) const

Get fire.

Get the amount of turns this unit is on fire.

0 = no fire.

Returns
fire : amount of turns this tile is on fire.
int OpenXcom::BattleUnit::getFiringAccuracy ( BattleActionType  actionType,
BattleItem item 
)

Calculate firing accuracy.

Formula = accuracyStat * weaponAccuracy * kneelingbonus(1.15) * one-handPenalty(0.8) * woundsPenalty(% health) * critWoundsPenalty (-10%/wound)

Parameters
actionType
item
Returns
firing Accuracy
int OpenXcom::BattleUnit::getFloatHeight ( ) const

Gets the unit floating elevation.

Get the unit's floating elevation.

Returns
The unit's elevation over the ground in voxels, when flying.
Soldier * OpenXcom::BattleUnit::getGeoscapeSoldier ( ) const

Get the geoscape-soldier object.

Returns
soldier.
BattleItem * OpenXcom::BattleUnit::getGrenadeFromBelt ( ) const

Gets a grenade from the belt, if any.

Get a grenade from the belt (used for AI)

Returns
Pointer to item.
int OpenXcom::BattleUnit::getHealth ( ) const

Gets the unit's health.

Returns the soldier's amount of health.

Returns
Health.
int OpenXcom::BattleUnit::getHeight ( ) const

Gets the unit height taking into account kneeling/standing.

Returns
Unit's height.
int OpenXcom::BattleUnit::getId ( ) const

Gets the BattleUnit's ID.

Returns the BattleUnit's unique ID.

Returns
Unique ID.
int OpenXcom::BattleUnit::getIntelligence ( ) const

Get the unit's intelligence.

Get the number of turns an AI unit remembers a soldier's position.

Returns
intelligence.
std::vector< BattleItem * > * OpenXcom::BattleUnit::getInventory ( )

Get the list of items in the inventory.

Get the pointer to the vector of inventory items.

Returns
pointer to vector.
BattleItem * OpenXcom::BattleUnit::getItem ( RuleInventory slot,
int  x = 0,
int  y = 0 
) const

Gets the item in the specified slot.

Checks if there's an inventory item in the specified inventory position.

Parameters
slotInventory slot.
xX position in slot.
yY position in slot.
Returns
Item in the slot, or NULL if none.
BattleItem * OpenXcom::BattleUnit::getItem ( const std::string &  slot,
int  x = 0,
int  y = 0 
) const

Gets the item in the specified slot.

Checks if there's an inventory item in the specified inventory position.

Parameters
slotInventory slot.
xX position in slot.
yY position in slot.
Returns
Item in the slot, or NULL if none.
int OpenXcom::BattleUnit::getKneelHeight ( ) const

Get the unit's kneel height.

Returns
The unit's height in voxels, when kneeling.
const Position & OpenXcom::BattleUnit::getLastPosition ( ) const

Gets the unit's position.

Gets the BattleUnit's position.

Returns
position
int OpenXcom::BattleUnit::getLoftemps ( int  entry = 0) const

Get the unit's loft ID.

Get the unit's loft ID, one per unit tile.

Each tile only has one loft, as it is repeated over the entire height of the unit.

Parameters
entryUnit tile
Returns
The unit's line of fire template ID.
BattleItem * OpenXcom::BattleUnit::getMainHandWeapon ( bool  quickest = true) const

Gets the item in the main hand.

Get the "main hand weapon" from the unit.

Parameters
quickestWhether to get the quickest weapon, default true
Returns
Pointer to item.
int OpenXcom::BattleUnit::getMiniMapSpriteIndex ( ) const

Get the sprite index for the minimap.

Get the unit's minimap sprite index.

Used to display the unit on the minimap

Returns
the unit minimap index
int OpenXcom::BattleUnit::getMorale ( ) const

Gets the unit's bravery.

Returns the soldier's amount of morale.

Returns
Morale.
int OpenXcom::BattleUnit::getMotionPoints ( ) const

Get motion points for the motion scanner.

More points is a larger blip on the scanner.

Returns
points.
int OpenXcom::BattleUnit::getMoveSound ( ) const

Get the unit's move sound.

Returns
id.
std::wstring OpenXcom::BattleUnit::getName ( Language lang,
bool  debugAppendId = false 
) const

Gets the unit's name.

Get unit's name.

An aliens name is the translation of it's race and rank. hence the language pointer needed.

Parameters
langPointer to language.
debugAppendIdAppend unit ID to name for debug purposes.
Returns
name Widecharstring of the unit's name.
UnitFaction OpenXcom::BattleUnit::getOriginalFaction ( ) const

Get this unit's original faction.

Get this unit's original Faction.

Returns
original faction
const Position & OpenXcom::BattleUnit::getPosition ( ) const

Gets the unit's position.

Gets the BattleUnit's position.

Returns
position
int OpenXcom::BattleUnit::getRankInt ( ) const

get the rank integer

Return the numeric version of the unit's rank.

Returns
unit rank, 0 = lowest
std::string OpenXcom::BattleUnit::getRankString ( ) const

Get the units's rank string.

Returns
rank.
double OpenXcom::BattleUnit::getReactionScore ( )

Get the current reaction score.

Little formula to calculate reaction score.

Returns
Reaction score.
std::string OpenXcom::BattleUnit::getSpawnUnit ( ) const

Gets the unit's spawn unit.

Get the unit that is spawned when this one dies.

Returns
unit.
int OpenXcom::BattleUnit::getSpecialAbility ( ) const

Get the units's special ability.

Returns the unit's special ability.

Returns
special ability.
int OpenXcom::BattleUnit::getStandHeight ( ) const

Get the unit's stand height.

Returns
The unit's height in voxels, when standing up.
UnitStats * OpenXcom::BattleUnit::getStats ( )

Gets the unit's stats.

Gets pointer to the unit's stats.

Returns
stats Pointer to the unit's stats.
UnitStatus OpenXcom::BattleUnit::getStatus ( ) const

Gets the unit's status.

Returns
the unit's status
double OpenXcom::BattleUnit::getThrowingAccuracy ( )

Calculate throwing accuracy.

Returns
throwing Accuracy
Tile * OpenXcom::BattleUnit::getTile ( ) const

Gets the unit's tile.

Returns
Tile
int OpenXcom::BattleUnit::getTimeUnits ( ) const

Gets the unit's time units.

Returns the soldier's amount of time units.

Returns
Time units.
int OpenXcom::BattleUnit::getTurnsSinceSpotted ( ) const

Set how many turns this unit will be exposed for.

Get how long since this unit was exposed.

Returns
number of turns
int OpenXcom::BattleUnit::getTurretDirection ( ) const

Gets the unit's turret direction.

Gets the BattleUnit's turret direction.

Returns
direction
int OpenXcom::BattleUnit::getTurretToDirection ( ) const

Gets the unit's turret To direction.

Gets the BattleUnit's turret To direction.

Returns
toDirectionTurret
int OpenXcom::BattleUnit::getTurretType ( ) const

Get the turret type. -1 is no turret.

Get the turret type.

-1 is no turret.

Returns
type
std::string OpenXcom::BattleUnit::getType ( ) const

Get unit type.

Returns
unit type.
std::vector< BattleUnit * > & OpenXcom::BattleUnit::getUnitsSpottedThisTurn ( )

get the vector of units we've seen this turn.

Get the list of units spotted this turn.

Returns
List of units.
int OpenXcom::BattleUnit::getValue ( ) const

Get the unit's value.

Used for score at debriefing.

Returns
value score
int OpenXcom::BattleUnit::getVerticalDirection ( ) const

Gets the unit's vertical direction.

Gets the BattleUnit's vertical direction.

This is when going up or down.

Returns
direction
bool OpenXcom::BattleUnit::getVisible ( ) const

Get whether this unit is visible.

Returns
flag
std::vector< Tile * > * OpenXcom::BattleUnit::getVisibleTiles ( )

Get the list of visible tiles.

Get the pointer to the vector of visible tiles.

Returns
pointer to vector.
std::vector< BattleUnit * > * OpenXcom::BattleUnit::getVisibleUnits ( )

Get the list of visible units.

Get the pointer to the vector of visible units.

Returns
pointer to vector.
int OpenXcom::BattleUnit::getWalkingPhase ( ) const

Gets the walking phase for animation and sound.

Returns
phase will always go from 0-7
void OpenXcom::BattleUnit::halveArmor ( )

Halve the unit's armor values.

Halve this unit's armor values (for beginner mode)

bool OpenXcom::BattleUnit::hasInventory ( ) const

Does this unit have an inventory?

Checks if this unit has an inventory.

Large units and/or terror units don't have inventories.

Returns
True if an inventory is available, false otherwise.
void OpenXcom::BattleUnit::heal ( int  part,
int  woundAmount,
int  healthAmount 
)

Heal one fatal wound.

Heal a fatal wound of the soldier.

Parameters
partthe body part to heal
woundAmountthe amount of fatal wound healed
healthAmountThe amount of health to add to soldier health
void OpenXcom::BattleUnit::healStun ( int  power)

Heal stun level of the unit.

Do an amount of stun recovery.

Parameters
power
void OpenXcom::BattleUnit::instaKill ( )

Set health to 0 and set status dead.

Set health to 0 and set status dead - used when getting zombified.

void OpenXcom::BattleUnit::invalidateCache ( )

call this after the default copy constructor deletes the cache?

invalidate cache; call after copying object :(

bool OpenXcom::BattleUnit::isFearable ( ) const

Get whether the unit is affected by fear.

Get whether the unit is affected by morale loss.

Normally only small units are affected by morale loss.

Returns
Is the unit affected by morale?
bool OpenXcom::BattleUnit::isFloating ( ) const

Is floating?

Is floating? A unit is floating when there is no ground under him/her.

Returns
true/false
bool OpenXcom::BattleUnit::isInExitArea ( SpecialTileType  stt = START_POINT) const

Check if this unit is in the exit area.

Parameters
sttType of exit tile to check for.
Returns
Is in the exit area?
bool OpenXcom::BattleUnit::isKneeled ( ) const

Is kneeled?

Is kneeled down?

Returns
true/false
bool OpenXcom::BattleUnit::isOut ( ) const

The unit is out - either dead or unconscious.

Returns whether the soldier is out of combat, dead or unconscious.

A soldier that is out, cannot perform any actions, cannot be selected, but it's still a unit.

Returns
flag if out or not.
bool OpenXcom::BattleUnit::isSelectable ( UnitFaction  faction,
bool  checkReselect,
bool  checkInventory 
) const

Is this unit selectable?

Checks if this unit can be selected.

Only alive units belonging to the faction can be selected.

Parameters
factionThe faction to compare with.
checkReselectCheck if the unit is reselectable.
checkInventoryCheck if the unit has an inventory.
Returns
True if the unit can be selected, false otherwise.
bool OpenXcom::BattleUnit::isWoundable ( ) const

Get whether the unit is affected by fatal wounds.

Normally only soldiers are affected by fatal wounds.

Returns
Is the unit affected by wounds?
void OpenXcom::BattleUnit::keepFalling ( )

Increment the falling sequence.

Advances the phase of falling sequence.

void OpenXcom::BattleUnit::keepWalking ( Tile tileBelowMe,
bool  cache 
)

Increase the walkingPhase.

This will increment the walking phase.

Parameters
tileBelowMePointer to tile currently below the unit.
cacheRefresh the unit cache.
UnitFaction OpenXcom::BattleUnit::killedBy ( ) const

Get the faction that killed this unit.

Get the faction the unit was killed by.

Returns
faction
void OpenXcom::BattleUnit::killedBy ( UnitFaction  f)

Set the faction that killed this unit.

Set the faction the unit was killed by.

Parameters
ffaction
void OpenXcom::BattleUnit::kneel ( bool  kneeled)

Kneel down.

Parameters
kneeledto kneel or to stand up
void OpenXcom::BattleUnit::knockOut ( BattlescapeGame battle)

Knocks the unit out instantly.

Raises a unit's stun level sufficiently so that the unit is ready to become unconscious.

Used when another unit falls on top of this unit. Zombified units first convert to their spawn unit.

Parameters
battlePointer to the battlescape game.
void OpenXcom::BattleUnit::load ( const YAML::Node &  node)

Loads the unit from YAML.

Loads the unit from a YAML file.

Parameters
nodeYAML node.
void OpenXcom::BattleUnit::lookAt ( const Position point,
bool  turret = false 
)

Look at a certain point.

Look at a point.

Parameters
pointPosition to look at.
turretTrue to turn the turret, false to turn the unit.
void OpenXcom::BattleUnit::lookAt ( int  direction,
bool  force = false 
)

Look at a certain direction.

Look at a direction.

Parameters
directionDirection to look at.
forceTrue to reset the direction, false to animate to it.
void OpenXcom::BattleUnit::moraleChange ( int  change)

Morale change.

Morale change with bounds check.

Parameters
changecan be positive or negative
void OpenXcom::BattleUnit::painKillers ( )

Give pain killers to this unit.

Restore soldier morale.

bool OpenXcom::BattleUnit::postMissionProcedures ( SavedGame geoscape)

Check if unit eligible for squaddie promotion.

If yes, promote the unit. Increase the mission counter. Calculate the experience increases.

Parameters
geoscapePointer to geoscape save.
Returns
True if the soldier was eligible for squaddie promotion.
bool OpenXcom::BattleUnit::reselectAllowed ( ) const

Check whether reselecting this unit is allowed.

Returns
bool
YAML::Node OpenXcom::BattleUnit::save ( ) const

Saves the unit to YAML.

Saves the soldier to a YAML file.

Returns
YAML node.
void OpenXcom::BattleUnit::setActiveHand ( const std::string &  hand)

Set the hand this unit is using;.

Set unit's active hand.

Parameters
handactive hand.
void OpenXcom::BattleUnit::setAIState ( BattleAIState aiState)

Set next AI State.

Changes the current AI state.

Parameters
aiStatePointer to AI state.
void OpenXcom::BattleUnit::setArmor ( int  armor,
UnitSide  side 
)

Set armor value.

Set the armor value of a certain armor side.

Parameters
armorAmount of armor.
sideThe side of the armor.
void OpenXcom::BattleUnit::setCache ( Surface cache,
int  part = 0 
)

Set the cached flag.

Sets the unit's cache flag.

Parameters
cachePointer to cache surface to use, NULL to redraw from scratch.
partUnit part to cache.
void OpenXcom::BattleUnit::setCharging ( BattleUnit chargeTarget)

Set the units we are charging towards.

Parameters
chargeTargetCharge Target
void OpenXcom::BattleUnit::setCoverReserve ( int  reserve)

Changes the amount of TUs reserved for cover.

Parameters
reservetime units.
void OpenXcom::BattleUnit::setDirection ( int  direction)

Sets the unit's direction 0-7.

Changes the BattleUnit's (horizontal) direction.

Only used for initial unit placement.

Parameters
directionnew horizontal direction
void OpenXcom::BattleUnit::setEnergy ( int  energy)

Sets the unit's energy level.

Set a specific number of energy.

Parameters
energyenergy.
void OpenXcom::BattleUnit::setFaceDirection ( int  direction)

Sets the unit's face direction (only used by strafing moves)

Changes the BattleUnit's (horizontal) face direction.

Only used for strafing moves.

Parameters
directionnew face direction
void OpenXcom::BattleUnit::setFire ( int  fire)

Set fire.

Set the amount of turns this unit is on fire.

0 = no fire.

Parameters
fire: amount of turns this tile is on fire.
void OpenXcom::BattleUnit::setPosition ( const Position pos,
bool  updateLastPos = true 
)

Sets the unit's position.

Changes the BattleUnit's position.

Parameters
posposition
updateLastPosrefresh last stored position
void OpenXcom::BattleUnit::setRankInt ( int  rank)

set the rank integer

Change the numeric version of the unit's rank.

Parameters
rankunit rank, 0 = lowest
void OpenXcom::BattleUnit::setSpawnUnit ( std::string  spawnUnit)

Sets the unit's spawn unit.

Set the unit that is spawned when this one dies.

Parameters
spawnUnitunit.
void OpenXcom::BattleUnit::setSpecialAbility ( SpecialAbility  specab)

Set the units's special ability.

Changes the unit's special ability.

Parameters
specabspecial ability.
void OpenXcom::BattleUnit::setTile ( Tile tile,
Tile tileBelow = 0 
)

Sets the unit's tile it's standing on.

Parameters
tilePointer to tile.
tileBelowPointer to tile below.
void OpenXcom::BattleUnit::setTimeUnits ( int  tu)

Set time units.

Set a specific number of timeunits.

Parameters
tu
void OpenXcom::BattleUnit::setTurnsSinceSpotted ( int  turns)

Set how many turns this unit will be exposed for.

Set how long since this unit was last exposed.

Parameters
turnsnumber of turns
void OpenXcom::BattleUnit::setTurretType ( int  turretType)

Set the turret type. -1 is no turret.

Set the turret type.

-1 is no turret.

Parameters
turretType
void OpenXcom::BattleUnit::setVisible ( bool  flag)

Set whether this unit is visible.

Parameters
flag
bool OpenXcom::BattleUnit::spendEnergy ( int  tu)

Spend energy if it can.

Return false if it can't.

Parameters
tu
Returns
flag if it could spend the time units or not.
bool OpenXcom::BattleUnit::spendTimeUnits ( int  tu)

Spend time units if it can.

Return false if it can't.

Parameters
tu
Returns
flag if it could spend the time units or not.
void OpenXcom::BattleUnit::startFalling ( )

Start falling sequence.

Intialises the falling sequence.

Occurs after death or stunned.

void OpenXcom::BattleUnit::startWalking ( int  direction,
const Position destination,
Tile tileBelowMe,
bool  cache 
)

Start the walkingPhase.

Initialises variables to start walking.

Parameters
directionWhich way to walk.
destinationThe position we should end up on.
tileBelowMeWhich tile is currently below the unit.
cacheUpdate cache?
void OpenXcom::BattleUnit::stimulant ( int  energy,
int  s 
)

Give stimulant to this unit.

Restore soldier energy and reduce stun level.

Parameters
energyThe amount of energy to add
sThe amount of stun level to reduce
void OpenXcom::BattleUnit::think ( BattleAction action)

Let AI do their thing.

Parameters
actionAI action.
void OpenXcom::BattleUnit::toggleFireDamage ( )

switch the state of the fire damage tracker.

toggle the state of the fire damage tracking boolean.

bool OpenXcom::BattleUnit::tookFireDamage ( ) const

did this unit already take fire damage this turn? (used to avoid damaging large units multiple times.)

Returns
ow it burns
void OpenXcom::BattleUnit::turn ( bool  turret = false)

Turn to the destination direction.

Advances the turning towards the target direction.

Parameters
turretTrue to turn the turret, false to turn the unit.

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