OpenXcom  1.0
Open-source clone of the original X-Com
Public Member Functions | Static Public Member Functions | List of all members
OpenXcom::Craft Class Reference

Represents a craft stored in a base. More...

#include <Craft.h>

Inheritance diagram for OpenXcom::Craft:
OpenXcom::MovingTarget OpenXcom::Target

Public Member Functions

 Craft (RuleCraft *rules, Base *base, int id=0)
 Creates a craft of the specified type. More...
 
 ~Craft ()
 Cleans up the craft. More...
 
void load (const YAML::Node &node, const Mod *mod, SavedGame *save)
 Loads the craft from YAML. More...
 
YAML::Node save () const
 Saves the craft to YAML. More...
 
std::string getType () const
 Gets the craft's type. More...
 
RuleCraftgetRules () const
 Gets the craft's ruleset. More...
 
void changeRules (RuleCraft *rules)
 Sets the craft's ruleset. More...
 
std::string getDefaultName (Language *lang) const
 Gets the craft's default name. More...
 
int getMarker () const
 Gets the craft's marker sprite. More...
 
BasegetBase () const
 Gets the craft's base. More...
 
void setBase (Base *base, bool move=true)
 Sets the craft's base. More...
 
std::string getStatus () const
 Gets the craft's status. More...
 
void setStatus (const std::string &status)
 Sets the craft's status. More...
 
std::string getAltitude () const
 Gets the craft's altitude. More...
 
void setDestination (Target *dest)
 Sets the craft's destination. More...
 
int getNumWeapons () const
 Gets the craft's amount of weapons. More...
 
int getNumSoldiers () const
 Gets the craft's amount of soldiers. More...
 
int getNumEquipment () const
 Gets the craft's amount of equipment. More...
 
int getNumVehicles () const
 Gets the craft's amount of vehicles. More...
 
std::vector< CraftWeapon * > * getWeapons ()
 Gets the craft's weapons. More...
 
ItemContainergetItems ()
 Gets the craft's items. More...
 
std::vector< Vehicle * > * getVehicles ()
 Gets the craft's vehicles. More...
 
int getFuel () const
 Gets the craft's amount of fuel. More...
 
void setFuel (int fuel)
 Sets the craft's amount of fuel. More...
 
int getFuelPercentage () const
 Gets the craft's percentage of fuel. More...
 
int getDamage () const
 Gets the craft's amount of damage. More...
 
void setDamage (int damage)
 Sets the craft's amount of damage. More...
 
int getDamagePercentage () const
 Gets the craft's percentage of damage. More...
 
bool getLowFuel () const
 Gets whether the craft is running out of fuel. More...
 
void setLowFuel (bool low)
 Sets whether the craft is running out of fuel. More...
 
bool getMissionComplete () const
 Gets whether the craft has just finished a mission. More...
 
void setMissionComplete (bool mission)
 Sets whether the craft has just finished a mission. More...
 
double getDistanceFromBase () const
 Gets the craft's distance from its base. More...
 
int getFuelConsumption () const
 Gets the craft's fuel consumption. More...
 
int getFuelConsumption (int speed) const
 Gets the craft's fuel consumption at a certain speed. More...
 
int getFuelLimit () const
 Gets the craft's minimum fuel limit. More...
 
int getFuelLimit (Base *base) const
 Gets the craft's minimum fuel limit to go to a base. More...
 
double getBaseRange () const
 Returns the maximum range the craft can travel from its origin base on its current fuel. More...
 
void returnToBase ()
 Returns the craft to its base. More...
 
bool detect (Target *target) const
 Checks if a target is detected by the craft's radar. More...
 
bool insideRadarRange (Target *target) const
 Checks if a target is inside the craft's radar range. More...
 
void think ()
 Handles craft logic. More...
 
void checkup ()
 Does a craft full checkup. More...
 
void consumeFuel ()
 Consumes the craft's fuel. More...
 
void repair ()
 Repairs the craft. More...
 
void refuel ()
 Refuels the craft. More...
 
std::string rearm (const Mod *mod)
 Rearms the craft. More...
 
void setInBattlescape (bool inbattle)
 Sets the craft's battlescape status. More...
 
bool isInBattlescape () const
 Gets if the craft is in battlescape. More...
 
bool isDestroyed () const
 Gets if craft is destroyed during dogfights. More...
 
int getSpaceAvailable () const
 Gets the amount of space available inside a craft. More...
 
int getSpaceUsed () const
 Gets the amount of space used inside a craft. More...
 
int getVehicleCount (const std::string &vehicle) const
 Gets the craft's vehicles of a certain type. More...
 
void setInDogfight (const bool inDogfight)
 Sets the craft's dogfight status. More...
 
bool isInDogfight () const
 Gets if the craft is in dogfight. More...
 
void setInterceptionOrder (const int order)
 Sets interception order (first craft to leave the base gets 1, second 2, etc.). More...
 
int getInterceptionOrder () const
 Gets interception number. More...
 
CraftId getUniqueId () const
 Gets the craft's unique id. More...
 
void unload (const Mod *mod)
 Unloads the craft. More...
 
void reuseItem (const std::string &item)
 Reuses a base item. More...
 
- Public Member Functions inherited from OpenXcom::MovingTarget
virtual ~MovingTarget ()
 Cleans up the moving target. More...
 
virtual void load (const YAML::Node &node)
 Loads the moving target from YAML. More...
 
TargetgetDestination () const
 Gets the moving target's destination. More...
 
int getSpeed () const
 Gets the moving target's speed. More...
 
double getSpeedRadian () const
 Gets the moving target's radial speed. More...
 
void setSpeed (int speed)
 Sets the moving target's speed. More...
 
bool reachedDestination () const
 Has the moving target reached its destination? More...
 
void move ()
 Move towards the destination. More...
 
void calculateMeetPoint ()
 Calculate meeting point with the target.
 
double getMeetLatitude () const
 Returns the latitude of the meeting point. More...
 
double getMeetLongitude () const
 Returns the longitude of the meeting point. More...
 
void resetMeetPoint ()
 Reset meeting point calculation. More...
 
bool isMeetCalculated () const
 Returns if the meeting point was calculated.
 
- Public Member Functions inherited from OpenXcom::Target
virtual ~Target ()
 Cleans up the target. More...
 
YAML::Node saveId () const
 Saves the target's ID to YAML. More...
 
double getLongitude () const
 Gets the target's longitude. More...
 
void setLongitude (double lon)
 Sets the target's longitude. More...
 
double getLatitude () const
 Gets the target's latitude. More...
 
void setLatitude (double lat)
 Sets the target's latitude. More...
 
int getId () const
 Gets the target's ID. More...
 
void setId (int id)
 Sets the target's ID. More...
 
virtual std::string getName (Language *lang) const
 Gets the target's name. More...
 
void setName (const std::string &newName)
 Sets the target's name. More...
 
virtual std::string getMarkerName () const
 Gets the target's marker name. More...
 
std::vector< MovingTarget * > * getFollowers ()
 Gets the target's followers. More...
 
std::vector< Craft * > getCraftFollowers () const
 Gets the target's craft followers. More...
 
double getDistance (const Target *target) const
 Gets the distance to another target. More...
 

Static Public Member Functions

static CraftId loadId (const YAML::Node &node)
 Loads a craft ID from YAML. More...
 

Additional Inherited Members

- Protected Member Functions inherited from OpenXcom::MovingTarget
virtual void calculateSpeed ()
 Calculates a new speed vector to the destination. More...
 
 MovingTarget ()
 Creates a moving target. More...
 
- Protected Member Functions inherited from OpenXcom::Target
 Target ()
 Creates a target. More...
 
- Static Protected Member Functions inherited from OpenXcom::MovingTarget
static double calculateRadianSpeed (int speed)
 Converts a speed to radians. More...
 

Detailed Description

Represents a craft stored in a base.

Contains variable info about a craft like position, fuel, damage, etc.

See also
RuleCraft

Constructor & Destructor Documentation

◆ Craft()

OpenXcom::Craft::Craft ( RuleCraft rules,
Base base,
int  id = 0 
)

Creates a craft of the specified type.

Initializes a craft of the specified type and assigns it the latest craft ID available.

Parameters
rulesPointer to ruleset.
basePointer to base of origin.
idID to assign to the craft (0 to not assign).

◆ ~Craft()

OpenXcom::Craft::~Craft ( )

Cleans up the craft.

Delete the contents of the craft from memory.

Member Function Documentation

◆ changeRules()

void OpenXcom::Craft::changeRules ( RuleCraft rules)

Sets the craft's ruleset.

Changes the ruleset for the craft's type.

Parameters
rulesPointer to ruleset.
Warning
ONLY FOR NEW BATTLE USE!

◆ checkup()

void OpenXcom::Craft::checkup ( )

Does a craft full checkup.

Checks the condition of all the craft's systems to define its new status (eg.

when arriving at base).

◆ consumeFuel()

void OpenXcom::Craft::consumeFuel ( )

Consumes the craft's fuel.

Consumes the craft's fuel every 10 minutes while it's on the air.

◆ detect()

bool OpenXcom::Craft::detect ( Target target) const

Checks if a target is detected by the craft's radar.

Returns if a certain target is detected by the craft's radar, taking in account the range and chance.

Parameters
targetPointer to target to compare.
Returns
True if it's detected, False otherwise.

◆ getAltitude()

std::string OpenXcom::Craft::getAltitude ( ) const

Gets the craft's altitude.

Returns the current altitude of the craft.

Returns
Altitude.

◆ getBase()

Base * OpenXcom::Craft::getBase ( ) const

Gets the craft's base.

Returns the base the craft belongs to.

Returns
Pointer to base.

◆ getBaseRange()

double OpenXcom::Craft::getBaseRange ( ) const

Returns the maximum range the craft can travel from its origin base on its current fuel.

Returns
Range in radians.

◆ getDamage()

int OpenXcom::Craft::getDamage ( ) const

Gets the craft's amount of damage.

Returns the amount of damage this craft has taken.

Returns
Amount of damage.

◆ getDamagePercentage()

int OpenXcom::Craft::getDamagePercentage ( ) const

Gets the craft's percentage of damage.

Returns the ratio between the amount of damage this craft can take and the total it can take before it's destroyed.

Returns
Percentage of damage.

◆ getDefaultName()

std::string OpenXcom::Craft::getDefaultName ( Language lang) const
virtual

Gets the craft's default name.

Returns the craft's unique default name.

Parameters
langLanguage to get strings from.
Returns
Full name.

Reimplemented from OpenXcom::Target.

◆ getDistanceFromBase()

double OpenXcom::Craft::getDistanceFromBase ( ) const

Gets the craft's distance from its base.

Returns the current distance between the craft and the base it belongs to.

Returns
Distance in radian.

◆ getFuel()

int OpenXcom::Craft::getFuel ( ) const

Gets the craft's amount of fuel.

Returns the amount of fuel currently contained in this craft.

Returns
Amount of fuel.

◆ getFuelConsumption() [1/2]

int OpenXcom::Craft::getFuelConsumption ( ) const

Gets the craft's fuel consumption.

Returns the amount of fuel the craft uses up while it's on the air, based on its current speed.

Returns
Fuel amount.

◆ getFuelConsumption() [2/2]

int OpenXcom::Craft::getFuelConsumption ( int  speed) const

Gets the craft's fuel consumption at a certain speed.

Returns the amount of fuel the craft uses up while it's on the air.

Parameters
speedCraft speed for estimation.
Returns
Fuel amount.

◆ getFuelLimit() [1/2]

int OpenXcom::Craft::getFuelLimit ( ) const

Gets the craft's minimum fuel limit.

Returns the minimum required fuel for the craft to make it back to base.

Returns
Fuel amount.

◆ getFuelLimit() [2/2]

int OpenXcom::Craft::getFuelLimit ( Base base) const

Gets the craft's minimum fuel limit to go to a base.

Returns the minimum required fuel for the craft to go to a base.

Parameters
basePointer to target base.
Returns
Fuel amount.

◆ getFuelPercentage()

int OpenXcom::Craft::getFuelPercentage ( ) const

Gets the craft's percentage of fuel.

Returns the ratio between the amount of fuel currently contained in this craft and the total it can carry.

Returns
Percentage of fuel.

◆ getInterceptionOrder()

int OpenXcom::Craft::getInterceptionOrder ( ) const

Gets interception number.

Gets interception order.

Returns
Interception order.

◆ getItems()

ItemContainer * OpenXcom::Craft::getItems ( )

Gets the craft's items.

Returns the list of items in the craft.

Returns
Pointer to the item list.

◆ getLowFuel()

bool OpenXcom::Craft::getLowFuel ( ) const

Gets whether the craft is running out of fuel.

Returns whether the craft is currently low on fuel (only has enough to head back to base).

Returns
True if it's low, false otherwise.

◆ getMarker()

int OpenXcom::Craft::getMarker ( ) const
virtual

Gets the craft's marker sprite.

Returns the globe marker for the craft.

Returns
Marker sprite, -1 if none.

Implements OpenXcom::Target.

◆ getMissionComplete()

bool OpenXcom::Craft::getMissionComplete ( ) const

Gets whether the craft has just finished a mission.

Returns whether the craft has just done a ground mission, and is forced to return to base.

Returns
True if it's returning, false otherwise.

◆ getNumEquipment()

int OpenXcom::Craft::getNumEquipment ( ) const

Gets the craft's amount of equipment.

Returns the amount of equipment currently equipped on this craft.

Returns
Number of items.

◆ getNumSoldiers()

int OpenXcom::Craft::getNumSoldiers ( ) const

Gets the craft's amount of soldiers.

Returns the amount of soldiers from a list that are currently attached to this craft.

Returns
Number of soldiers.

◆ getNumVehicles()

int OpenXcom::Craft::getNumVehicles ( ) const

Gets the craft's amount of vehicles.

Returns the amount of vehicles currently contained in this craft.

Returns
Number of vehicles.

◆ getNumWeapons()

int OpenXcom::Craft::getNumWeapons ( ) const

Gets the craft's amount of weapons.

Returns the amount of weapons currently equipped on this craft.

Returns
Number of weapons.

◆ getRules()

RuleCraft * OpenXcom::Craft::getRules ( ) const

Gets the craft's ruleset.

Returns the ruleset for the craft's type.

Returns
Pointer to ruleset.

◆ getSpaceAvailable()

int OpenXcom::Craft::getSpaceAvailable ( ) const

Gets the amount of space available inside a craft.

Returns the amount of space available for soldiers and vehicles.

Returns
Space available.

◆ getSpaceUsed()

int OpenXcom::Craft::getSpaceUsed ( ) const

Gets the amount of space used inside a craft.

Returns the amount of space in use by soldiers and vehicles.

Returns
Space used.

◆ getStatus()

std::string OpenXcom::Craft::getStatus ( ) const

Gets the craft's status.

Returns the current status of the craft.

Returns
Status string.

◆ getType()

std::string OpenXcom::Craft::getType ( ) const
virtual

Gets the craft's type.

Returns the craft's unique type used for savegame purposes.

Returns
ID.

Implements OpenXcom::Target.

◆ getUniqueId()

CraftId OpenXcom::Craft::getUniqueId ( ) const

Gets the craft's unique id.

Returns
A tuple of the craft's type and per-type id.

◆ getVehicleCount()

int OpenXcom::Craft::getVehicleCount ( const std::string &  vehicle) const

Gets the craft's vehicles of a certain type.

Returns the total amount of vehicles of a certain type stored in the craft.

Parameters
vehicleVehicle type.
Returns
Number of vehicles.

◆ getVehicles()

std::vector< Vehicle * > * OpenXcom::Craft::getVehicles ( )

Gets the craft's vehicles.

Returns the list of vehicles currently equipped in the craft.

Returns
Pointer to vehicle list.

◆ getWeapons()

std::vector< CraftWeapon * > * OpenXcom::Craft::getWeapons ( )

Gets the craft's weapons.

Returns the list of weapons currently equipped in the craft.

Returns
Pointer to weapon list.

◆ insideRadarRange()

bool OpenXcom::Craft::insideRadarRange ( Target target) const

Checks if a target is inside the craft's radar range.

Returns if a certain target is inside the craft's radar range, taking in account the positions of both.

Parameters
targetPointer to target to compare.
Returns
True if inside radar range.

◆ isDestroyed()

bool OpenXcom::Craft::isDestroyed ( ) const

Gets if craft is destroyed during dogfights.

Returns the craft destroyed status.

If the amount of damage the craft take is more than it's health it will be destroyed.

Returns
Is the craft destroyed?

◆ isInBattlescape()

bool OpenXcom::Craft::isInBattlescape ( ) const

Gets if the craft is in battlescape.

Returns the craft's battlescape status.

Returns
Is the craft currently in battle?

◆ isInDogfight()

bool OpenXcom::Craft::isInDogfight ( ) const

Gets if the craft is in dogfight.

Returns the craft's dogfight status.

Returns
Is the craft ion a dogfight?

◆ load()

void OpenXcom::Craft::load ( const YAML::Node &  node,
const Mod mod,
SavedGame save 
)

Loads the craft from YAML.

Loads the craft from a YAML file.

Parameters
nodeYAML node.
modMod for the saved game.
savePointer to the saved game.

◆ loadId()

CraftId OpenXcom::Craft::loadId ( const YAML::Node &  node)
static

Loads a craft ID from YAML.

Loads a craft unique identifier from a YAML file.

Parameters
nodeYAML node.
Returns
Unique craft id.

◆ rearm()

std::string OpenXcom::Craft::rearm ( const Mod mod)

Rearms the craft.

Rearms the craft's weapons by adding ammo every hour while it's docked in the base.

Parameters
modPointer to mod.
Returns
The ammo ID missing for rearming, or "" if none.

◆ refuel()

void OpenXcom::Craft::refuel ( )

Refuels the craft.

Refuels the craft every 30 minutes while it's docked in the base.

◆ repair()

void OpenXcom::Craft::repair ( )

Repairs the craft.

Repairs the craft's damage every hour while it's docked in the base.

◆ returnToBase()

void OpenXcom::Craft::returnToBase ( )

Returns the craft to its base.

Sends the craft back to its origin base.

◆ reuseItem()

void OpenXcom::Craft::reuseItem ( const std::string &  item)

Reuses a base item.

Checks if an item can be reused by the craft and updates its status appropriately.

Parameters
itemItem ID.

◆ save()

YAML::Node OpenXcom::Craft::save ( ) const
virtual

Saves the craft to YAML.

Saves the craft to a YAML file.

Returns
YAML node.

Reimplemented from OpenXcom::MovingTarget.

◆ setBase()

void OpenXcom::Craft::setBase ( Base base,
bool  move = true 
)

Sets the craft's base.

Changes the base the craft belongs to.

Parameters
basePointer to base.
moveMove the craft to the base coordinates.

◆ setDamage()

void OpenXcom::Craft::setDamage ( int  damage)

Sets the craft's amount of damage.

Changes the amount of damage this craft has taken.

Parameters
damageAmount of damage.

◆ setDestination()

void OpenXcom::Craft::setDestination ( Target dest)
virtual

Sets the craft's destination.

Changes the destination the craft is heading to.

Parameters
destPointer to new destination.

Reimplemented from OpenXcom::MovingTarget.

◆ setFuel()

void OpenXcom::Craft::setFuel ( int  fuel)

Sets the craft's amount of fuel.

Changes the amount of fuel currently contained in this craft.

Parameters
fuelAmount of fuel.

◆ setInBattlescape()

void OpenXcom::Craft::setInBattlescape ( bool  inbattle)

Sets the craft's battlescape status.

Changes the craft's battlescape status.

Parameters
inbattleTrue if it's in battle, False otherwise.

◆ setInDogfight()

void OpenXcom::Craft::setInDogfight ( const bool  inDogfight)

Sets the craft's dogfight status.

Changes the craft's dogfight status.

Parameters
inDogfightTrue if it's in dogfight, False otherwise.

◆ setInterceptionOrder()

void OpenXcom::Craft::setInterceptionOrder ( const int  order)

Sets interception order (first craft to leave the base gets 1, second 2, etc.).

Parameters
orderInterception order.

◆ setLowFuel()

void OpenXcom::Craft::setLowFuel ( bool  low)

Sets whether the craft is running out of fuel.

Changes whether the craft is currently low on fuel (only has enough to head back to base).

Parameters
lowTrue if it's low, false otherwise.

◆ setMissionComplete()

void OpenXcom::Craft::setMissionComplete ( bool  mission)

Sets whether the craft has just finished a mission.

Changes whether the craft has just done a ground mission, and is forced to return to base.

Parameters
missionTrue if it's returning, false otherwise.

◆ setStatus()

void OpenXcom::Craft::setStatus ( const std::string &  status)

Sets the craft's status.

Changes the current status of the craft.

Parameters
statusStatus string.

◆ think()

void OpenXcom::Craft::think ( )

Handles craft logic.

Moves the craft to its destination.

◆ unload()

void OpenXcom::Craft::unload ( const Mod mod)

Unloads the craft.

Unloads all the craft contents to the base.

Parameters
modPointer to mod.

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