UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cp_aircraft.h File Reference

Header file for aircraft stuff. More...

#include "cp_capacity.h"
#include "cp_radar.h"

Go to the source code of this file.

Data Structures

struct  mapline_s
 A path on the map described by 2D points. More...
 
struct  aircraftSlot_s
 slot of aircraft More...
 
struct  aircraft_s
 An aircraft with all it's data. More...
 

Macros

#define MAX_AIRCRAFT   64
 
#define LINE_MAXSEG   64
 
#define LINE_MAXPTS   (LINE_MAXSEG + 2)
 
#define AIRCRAFT_REFUEL_FACTOR   16
 
#define MAX_AIRCRAFTSLOT   8
 
#define AIR_Foreach(var)   LIST_Foreach(ccs.aircraft, aircraft_t, var)
 iterates trough all aircraft More...
 
#define AIR_IsAircraftOfBase(aircraft, base)   ((aircraft)->homebase == (base) && (aircraft)->status != AIR_CRASHED)
 
#define AIR_ForeachFromBase(var, base)
 iterates trough all aircraft from a specific homebase More...
 
#define AIR_IsUFO(aircraft)   ((aircraft)->getUfoType() != UFO_NONE)
 

Typedefs

typedef struct mapline_s mapline_t
 A path on the map described by 2D points. More...
 
typedef struct aircraftSlot_s aircraftSlot_t
 slot of aircraft More...
 
typedef enum aircraftStatus_s aircraftStatus_t
 
typedef struct aircraft_s aircraft_t
 An aircraft with all it's data. More...
 

Enumerations

enum  itemWeight_t { ITEM_LIGHT, ITEM_MEDIUM, ITEM_HEAVY }
 different weight for aircraft items More...
 
enum  itemPos_t {
  AIR_NOSE_LEFT, AIR_NOSE_CENTER, AIR_NOSE_RIGHT, AIR_WING_LEFT,
  AIR_WING_RIGHT, AIR_REAR_LEFT, AIR_REAR_CENTER, AIR_REAR_RIGHT,
  AIR_POSITIONS_MAX
}
 different positions for aircraft items More...
 
enum  aircraft_notifications_t { AIR_CANNOT_REFUEL, MAX_AIR_NOTIFICATIONS }
 notification signals for aircraft events More...
 
enum  aircraftStatus_s {
  AIR_NONE, AIR_REFUEL, AIR_HOME, AIR_IDLE,
  AIR_TRANSIT, AIR_MISSION, AIR_UFO, AIR_DROP,
  AIR_INTERCEPT, AIR_TRANSFER, AIR_CRASHED, AIR_RETURNING
}
 

Functions

aircraft_tAIR_NewAircraft (struct base_s *base, const aircraft_t *aircraftTemplate)
 Places a new aircraft in the given base. More...
 
aircraft_tAIR_Add (struct base_s *base, const aircraft_t *aircraftTemplate)
 Adds a new aircraft from a given aircraft template to the base and sets the homebase for the new aircraft to the given base. More...
 
bool AIR_Delete (struct base_s *base, aircraft_t *aircraft)
 Will remove the given aircraft from the base. More...
 
void AIR_DeleteAircraft (aircraft_t *aircraft)
 Removes an aircraft from its base and the game. More...
 
void AIR_DestroyAircraft (aircraft_t *aircraft, bool killPilot=true)
 Removes an aircraft from its base and the game. More...
 
const aircraft_tAIR_GetAircraftSilent (const char *name)
 Searches the global array of aircraft types for a given aircraft. More...
 
const aircraft_tAIR_GetAircraft (const char *name)
 Searches the global array of aircraft types for a given aircraft. More...
 
aircraft_tAIR_GetFirstFromBase (const struct base_s *base)
 
bool AIR_BaseHasAircraft (const struct base_s *base)
 
int AIR_BaseCountAircraft (const struct base_s *base)
 
aircraft_tAIR_GetAircraftFromBaseByIDXSafe (const struct base_s *base, int index)
 
aircraft_tAIR_AircraftGetFromIDX (int idx)
 Returns aircraft for a given global index. More...
 
const char * AIR_AircraftStatusToName (const aircraft_t *aircraft)
 Translates the aircraft status id to a translatable string. More...
 
bool AIR_IsAircraftInBase (const aircraft_t *aircraft)
 Checks whether given aircraft is in its homebase. More...
 
bool AIR_IsAircraftOnGeoscape (const aircraft_t *aircraft)
 Checks whether given aircraft is on geoscape. More...
 
void AIR_ResetAircraftTeam (aircraft_t *aircraft)
 Resets team in given aircraft. More...
 
bool AIR_AddToAircraftTeam (aircraft_t *aircraft, class Employee *employee)
 Adds given employee to given aircraft. More...
 
bool AIR_IsInAircraftTeam (const aircraft_t *aircraft, const class Employee *employee)
 
int AIR_GetTeamSize (const aircraft_t *aircraft)
 Counts the number of soldiers in given aircraft. More...
 
void AIR_CampaignRun (const struct campaign_s *campaign, int dt, bool updateRadarOverlay)
 
bool AIR_AircraftMakeMove (int dt, aircraft_t *aircraft)
 Moves given aircraft. More...
 
void AIR_ParseAircraft (const char *name, const char **text, bool assignAircraftItems)
 Parses all aircraft that are defined in our UFO-scripts. More...
 
bool AIR_AircraftHasEnoughFuel (const aircraft_t *aircraft, const vec2_t destination)
 check if aircraft has enough fuel to go to destination, and then come back home More...
 
bool AIR_AircraftHasEnoughFuelOneWay (const aircraft_t *aircraft, const vec2_t destination)
 check if aircraft has enough fuel to go to destination More...
 
void AIR_AircraftReturnToBase (aircraft_t *aircraft)
 Calculates the way back to homebase for given aircraft and returns it. More...
 
bool AIR_SendAircraftToMission (aircraft_t *aircraft, struct mission_s *mission)
 Sends the specified aircraft to specified mission. More...
 
void AIR_AircraftsNotifyMissionRemoved (const struct mission_s *mission)
 
void AIR_AircraftsNotifyUFORemoved (const aircraft_t *const ufo, bool destroyed)
 Notify that a UFO has been removed. More...
 
void AIR_GetDestinationWhilePursuing (const aircraft_t *shooter, const aircraft_t *target, vec2_t dest)
 Calculates the point where aircraft should go to intecept a moving target. More...
 
bool AIR_SendAircraftPursuingUFO (aircraft_t *aircraft, aircraft_t *ufo)
 Make the specified aircraft purchasing a UFO. More...
 
void AIR_AircraftsUFODisappear (const aircraft_t *const ufo)
 Notify that a UFO disappear from radars. More...
 
bool AIR_ScriptSanityCheck (void)
 Checks the parsed aircraft for errors. More...
 
int AIR_AircraftMenuStatsValues (const int value, const int stat)
 Some of the aircraft values needs special calculations when they are shown in the menus. More...
 
int AIR_CountInBaseByTemplate (const struct base_s *base, const aircraft_t *aircraftTemplate)
 
int AIR_GetAircraftWeaponRanges (const aircraftSlot_t *slot, int maxSlot, float *weaponRanges)
 Get the all the unique weapon ranges of this aircraft. More...
 
baseCapacities_t AIR_GetHangarCapacityType (const aircraft_t *aircraft)
 Returns capacity type needed for an aircraft. More...
 
const char * AIR_CheckMoveIntoNewHomebase (const aircraft_t *aircraft, const struct base_s *base)
 
void AIR_MoveAircraftIntoNewHomebase (aircraft_t *aircraft, struct base_s *base)
 Moves a given aircraft to a new base (also the employees and inventory) More...
 
void AII_CollectItem (aircraft_t *aircraft, const objDef_t *item, int amount)
 Add an item to aircraft inventory. More...
 
void AII_CollectingItems (aircraft_t *aircraft, int won)
 Collect items from the battlefield. More...
 
bool AIR_SetPilot (aircraft_t *aircraft, class Employee *pilot)
 Assign a pilot to an aircraft. More...
 
EmployeeAIR_GetPilot (const aircraft_t *aircraft)
 Get pilot of an aircraft. More...
 
bool AIR_PilotSurvivedCrash (const aircraft_t *aircraft)
 Determine if an aircraft's pilot survived a crash, based on his piloting skill (and a bit of randomness) More...
 
bool AIR_AddEmployee (Employee *employee, aircraft_t *aircraft)
 Assigns a soldier to an aircraft. More...
 
void AIR_RemoveEmployees (aircraft_t &aircraft)
 Removes all soldiers from an aircraft. More...
 
bool AIR_RemoveEmployee (Employee *employee, aircraft_t *aircraft)
 Removes a soldier from an aircraft. More...
 
const aircraft_tAIR_IsEmployeeInAircraft (const class Employee *employee, const aircraft_t *aircraft)
 
void AIR_AutoAddPilotToAircraft (const struct base_s *base, class Employee *pilot)
 
void AIR_RemovePilotFromAssignedAircraft (const struct base_s *base, const class Employee *pilot)
 
void AIR_MoveEmployeeInventoryIntoStorage (const aircraft_t &aircraft, equipDef_t &equip)
 Move all the equipment carried by the team on the aircraft into the given equipment. More...
 
void AIR_AssignInitial (aircraft_t *aircraft)
 Assigns initial team of soldiers to aircraft. More...
 
bool AIR_CanIntercept (const aircraft_t *aircraft)
 
int AIR_GetOperationRange (const aircraft_t *aircraft)
 Calculates the range an aircraft can fly on the geoscape. More...
 
int AIR_GetRemainingRange (const aircraft_t *aircraft)
 Calculates the remaining range the aircraft can fly. More...
 
void AIR_InitStartup (void)
 Init actions for aircraft-subsystem. More...
 
void AIR_Shutdown (void)
 Closing actions for aircraft-subsystem. More...
 

Detailed Description

Header file for aircraft stuff.

Definition in file cp_aircraft.h.

Macro Definition Documentation

#define AIR_ForeachFromBase (   var,
  base 
)
Value:
if (!AIR_IsAircraftOfBase(var, (base))) continue; else
#define AIR_IsAircraftOfBase(aircraft, base)
Definition: cp_aircraft.h:194
#define AIR_Foreach(var)
iterates trough all aircraft
Definition: cp_aircraft.h:192

iterates trough all aircraft from a specific homebase

Parameters
[out]varvariable to point to the aircraft structure
[in]basepointer to the homebase structure

Definition at line 201 of file cp_aircraft.h.

Referenced by AB_UpdateStealthForAllBase(), AII_RepairAircraft(), AIM_PilotAssignedAircraft(), AIR_AircraftFillList_f(), AIR_AircraftSelect(), AIR_AutoAddPilotToAircraft(), AIR_BaseCountAircraft(), AIR_CountInBaseByTemplate(), AIR_GetAircraftFromBaseByIDXSafe(), AIR_GetFirstFromBase(), AIR_RemovePilotFromAssignedAircraft(), AIR_ShowAircraft_f(), B_Destroy(), B_MoveAircraftOnGeoscapeToOtherBases(), BS_FillMarket_f(), GEO_GetGeoscapeAngle(), RADAR_NotifyUFORemoved(), TEST_F(), and TR_FillAircraft().

#define AIR_IsAircraftOfBase (   aircraft,
  base 
)    ((aircraft)->homebase == (base) && (aircraft)->status != AIR_CRASHED)

Definition at line 194 of file cp_aircraft.h.

#define AIRCRAFT_REFUEL_FACTOR   16

factor to speed up refuelling

Definition at line 35 of file cp_aircraft.h.

Referenced by AIR_Refuel().

#define LINE_MAXPTS   (LINE_MAXSEG + 2)

Definition at line 32 of file cp_aircraft.h.

Referenced by AIR_LoadRouteXML(), GEO_3DMapDrawLine(), GEO_CalcLine(), and GEO_MapDrawLine().

#define LINE_MAXSEG   64

Definition at line 31 of file cp_aircraft.h.

Referenced by GEO_CalcLine().

#define MAX_AIRCRAFT   64

Definition at line 30 of file cp_aircraft.h.

Referenced by AIR_ParseAircraft().

#define MAX_AIRCRAFTSLOT   8

Typedef Documentation

typedef struct aircraft_s aircraft_t

An aircraft with all it's data.

slot of aircraft

possible aircraft states

typedef struct mapline_s mapline_t

A path on the map described by 2D points.

Enumeration Type Documentation

notification signals for aircraft events

Enumerator
AIR_CANNOT_REFUEL 
MAX_AIR_NOTIFICATIONS 

Definition at line 68 of file cp_aircraft.h.

possible aircraft states

Enumerator
AIR_NONE 
AIR_REFUEL 

refill fuel

AIR_HOME 

in homebase

AIR_IDLE 

just sit there on geoscape

AIR_TRANSIT 

moving

AIR_MISSION 

moving to a mission

AIR_UFO 

pursuing a UFO - also used for ufos that are pursuing an aircraft

AIR_DROP 

ready to drop down

AIR_INTERCEPT 

ready to intercept

AIR_TRANSFER 

being transferred

AIR_CRASHED 

crashed

AIR_RETURNING 

returning to homebase

Definition at line 98 of file cp_aircraft.h.

enum itemPos_t

different positions for aircraft items

Enumerator
AIR_NOSE_LEFT 
AIR_NOSE_CENTER 
AIR_NOSE_RIGHT 
AIR_WING_LEFT 
AIR_WING_RIGHT 
AIR_REAR_LEFT 
AIR_REAR_CENTER 
AIR_REAR_RIGHT 
AIR_POSITIONS_MAX 

Definition at line 54 of file cp_aircraft.h.

different weight for aircraft items

Note
values must go from the lightest to the heaviest item
Enumerator
ITEM_LIGHT 
ITEM_MEDIUM 
ITEM_HEAVY 

Definition at line 47 of file cp_aircraft.h.

Function Documentation

void AII_CollectingItems ( aircraft_t aircraft,
int  won 
)

Collect items from the battlefield.

Note
The way we are collecting items:
1. Grab everything from the floor and add it to the aircraft cargo here.
2. When collecting gun, collect it's remaining ammo as well
3. Sell everything or add to base storage when dropship lands in base.
4. Items carried by soldiers are processed nothing is being sold.
See also
CL_ParseResults
AII_CollectingAmmo
AII_CarriedItems
Todo:
Simplify this logic

Definition at line 293 of file cp_aircraft.cpp.

References ItemCargo::add(), AII_CarriedItems(), AII_CollectAmmo(), AII_CollectItem_(), cgi, DEBUG_CLIENT, ItemCargo::empty(), missionResults_s::itemAmount, aircraft_s::itemCargo, missionResults_s::itemTypes, ItemCargo::list(), LIST_Foreach, aircraft_s::mission, and mission_s::missionResults.

Referenced by GAME_CP_Results().

void AII_CollectItem ( aircraft_t aircraft,
const objDef_t item,
int  amount 
)

Add an item to aircraft inventory.

Parameters
[in,out]aircraftAircraft to load to
[in]itemItem to add
amountNumber of items to add
See also
AL_AddAliens
AII_CollectingItems

Definition at line 236 of file cp_aircraft.cpp.

References ItemCargo::add(), and aircraft_s::itemCargo.

Referenced by AII_CollectItem_(), and AM_MoveCharacterInventoryIntoItemCargo().

aircraft_t* AIR_Add ( base_t base,
const aircraft_t aircraftTemplate 
)

Adds a new aircraft from a given aircraft template to the base and sets the homebase for the new aircraft to the given base.

Parameters
[out]baseThe base to add the aircraft to
[in]aircraftTemplateThe template to create the new aircraft from
Returns
the newly added aircraft
See also
AIR_Delete

Definition at line 604 of file cp_aircraft.cpp.

References AIR_CRASHED, AIR_GetHangarCapacityType(), ccs_s::aircraft, CAP_AddCurrent(), ccs, aircraft_s::homebase, LIST_Add(), MAX_CAP, and aircraft_s::status.

Referenced by AIR_LoadXML(), and AIR_NewAircraft().

bool AIR_AddEmployee ( Employee employee,
aircraft_t aircraft 
)

Assigns a soldier to an aircraft.

Parameters
[in]employeeThe employee to be assigned to the aircraft.
[in]aircraftWhat aircraft to assign employee to.
Returns
returns true if a soldier could be assigned to the aircraft.
See also
AIR_RemoveEmployee
AIR_AddToAircraftTeam

Definition at line 2849 of file cp_aircraft.cpp.

References AIR_AddToAircraftTeam(), AIR_GetTeamSize(), AIR_IsEmployeeInAircraft(), and aircraft_s::maxTeamSize.

Referenced by AIR_AssignInitial().

bool AIR_AddToAircraftTeam ( aircraft_t aircraft,
Employee employee 
)

Adds given employee to given aircraft.

Parameters
[in]aircraftPointer to an aircraft, to which we will add employee.
[in]employeeThe employee to add to the aircraft.
Note
this is responsible for adding soldiers to a team in dropship

Definition at line 1944 of file cp_aircraft.cpp.

References aircraft_s::acTeam, AIR_GetTeamSize(), cgi, and aircraft_s::maxTeamSize.

Referenced by AIR_AddEmployee(), and CP_TEAM_AssignSoldierByUCN_f().

aircraft_t* AIR_AircraftGetFromIDX ( int  aircraftIdx)

Returns aircraft for a given global index.

Parameters
[in]aircraftIdxGlobal aircraft index.
Returns
An aircraft pointer (to a struct in a base) that has the given index or nullptr if no aircraft found.

Definition at line 1131 of file cp_aircraft.cpp.

References AIR_Foreach, cgi, and DEBUG_CLIENT.

Referenced by AIM_AircraftReturnToBase_f(), AIR_GeoSelectAircraft_f(), AIR_LoadAircraftXML(), AIR_SendAircraftToMission_f(), AIR_ShowChangeHomebaseAircraft_f(), AIR_StopAircraft_f(), AIRFIGHT_LoadXML(), BS_Buy_f(), BS_ShowInfo_f(), CP_TEAM_FillEmployeeList_f(), CP_TEAM_FillEquipSoldierList_f(), MIS_LoadXML(), TR_Add_f(), TR_LoadXML(), and TR_TransferStart().

bool AIR_AircraftHasEnoughFuel ( const aircraft_t aircraft,
const vec2_t  destination 
)

check if aircraft has enough fuel to go to destination, and then come back home

Parameters
[in]aircraftPointer to the aircraft
[in]destinationPointer to the position the aircraft should go to
See also
GEO_CalcLine
Returns
true if the aircraft can go to the position, false else

Definition at line 471 of file cp_aircraft.cpp.

References AIR_GetRemainingRange(), GetDistanceOnGlobe(), aircraft_s::homebase, base_s::pos, aircraft_s::pos, and SECONDS_PER_HOUR.

Referenced by AIR_CampaignRun(), AIR_GeoSelectAircraft_f(), AIR_SendAircraftPursuingUFO(), AIR_SendAircraftToMission(), CL_DisplayPopupInterceptUFO(), and GEO_Click().

bool AIR_AircraftHasEnoughFuelOneWay ( const aircraft_t aircraft,
const vec2_t  destination 
)

check if aircraft has enough fuel to go to destination

Parameters
[in]aircraftPointer to the aircraft
[in]destinationPointer to the position the aircraft should go to
See also
GEO_CalcLine
Returns
true if the aircraft can go to the position, false else

Definition at line 497 of file cp_aircraft.cpp.

References AIR_GetRemainingRange(), GetDistanceOnGlobe(), aircraft_s::pos, and SECONDS_PER_HOUR.

Referenced by AIR_CheckMoveIntoNewHomebase().

bool AIR_AircraftMakeMove ( int  dt,
aircraft_t aircraft 
)

Moves given aircraft.

Parameters
[in]dttime delta
[in]aircraftPointer to aircraft on its way.
Returns
true if the aircraft reached its destination.

Definition at line 925 of file cp_aircraft.cpp.

References AIR_STATS_SPEED, mapline_s::distance, aircraft_s::fuel, GEO_CheckPositionBoundaries(), int(), mapline_s::numPoints, mapline_s::point, aircraft_s::point, aircraft_s::pos, aircraft_s::projectedPos, aircraft_s::route, SECONDS_PER_HOUR, aircraft_s::stats, aircraft_s::time, and VectorSet.

Referenced by AIR_Move(), and UFO_CampaignRunUFOs().

int AIR_AircraftMenuStatsValues ( const int  value,
const int  stat 
)

Some of the aircraft values needs special calculations when they are shown in the menus.

See also
UP_AircraftStatToName

Definition at line 428 of file cp_aircraft.cpp.

References AIR_STATS_FUELSIZE, AIR_STATS_MAXSPEED, AIR_STATS_SPEED, f, and int().

Referenced by AIR_AircraftSelect(), GEO_GetAircraftText(), GEO_GetUFOText(), UP_AircraftDescription(), and UP_AircraftItemDescription().

void AIR_AircraftsNotifyMissionRemoved ( const struct mission_s mission)
void AIR_AircraftsNotifyUFORemoved ( const aircraft_t *const  ufo,
bool  destroyed 
)

Notify that a UFO has been removed.

Parameters
[in]ufoPointer to UFO that has been removed.
[in]destroyedTrue if the UFO has been destroyed, false if it only landed.
Todo:
this should be in a BDEF_NotifyUFORemoved callback

Definition at line 1608 of file cp_aircraft.cpp.

References AIR_AircraftReturnToBase(), AIR_Foreach, aircraft_s::aircraftTarget, B_GetNext(), base_s::batteries, i, base_s::lasers, base_s::numBatteries, base_s::numLasers, and baseWeapon_s::target.

Referenced by CP_UFORemoveFromGeoscape().

const char* AIR_AircraftStatusToName ( const aircraft_t aircraft)

Translates the aircraft status id to a translatable string.

Parameters
[in]aircraftAircraft to translate the status of
Returns
Translation string of given status.

Definition at line 327 of file cp_aircraft.cpp.

References _, AIR_CRASHED, AIR_DROP, AIR_HOME, AIR_IDLE, AIR_INTERCEPT, AIR_IsAircraftInBase(), AIR_MISSION, AIR_NONE, AIR_REFUEL, AIR_RETURNING, AIR_TRANSFER, AIR_TRANSIT, AIR_UFO, B_IsUnderAttack, cgi, ERR_DROP, aircraft_s::homebase, base_s::name, aircraft_s::status, and va().

Referenced by AIR_AircraftFillList_f(), AIR_ShowAircraft_f(), CL_DisplayPopupInterceptMission(), CL_DisplayPopupInterceptUFO(), and GEO_GetAircraftText().

void AIR_AircraftsUFODisappear ( const aircraft_t *const  ufo)

Notify that a UFO disappear from radars.

Parameters
[in]ufoPointer to a UFO that has disappeared.
Note
Aircraft currently pursuing the specified UFO will be redirected to base

Definition at line 1650 of file cp_aircraft.cpp.

References AIR_AircraftReturnToBase(), AIR_Foreach, AIR_UFO, and aircraft_s::aircraftTarget.

Referenced by UFO_CampaignCheckEvents().

void AIR_AssignInitial ( aircraft_t aircraft)

Assigns initial team of soldiers to aircraft.

Parameters
[in,out]aircraftsoldiers to add to

Definition at line 2869 of file cp_aircraft.cpp.

References AIR_AddEmployee(), cgi, count, E_Foreach, EMPL_SOLDIER, aircraft_s::homebase, and aircraft_s::maxTeamSize.

Referenced by B_SetUpFirstBase().

void AIR_AutoAddPilotToAircraft ( const struct base_s base,
class Employee pilot 
)
int AIR_BaseCountAircraft ( const struct base_s base)
bool AIR_BaseHasAircraft ( const struct base_s base)
void AIR_CampaignRun ( const struct campaign_s campaign,
int  dt,
bool  updateRadarOverlay 
)
bool AIR_CanIntercept ( const aircraft_t aircraft)
Parameters
aircraftThe aircraft to check
Returns
true if the given aircraft can go on interceptions

Definition at line 2646 of file cp_aircraft.cpp.

References AIR_CRASHED, AIR_GetPilot(), AIR_NONE, B_GetBuildingStatus(), B_GetBuildingTemplateSilent(), aircraft_s::building, building_s::buildingType, aircraft_s::homebase, and aircraft_s::status.

Referenced by CL_DisplayPopupInterceptMission(), and CL_DisplayPopupInterceptUFO().

const char* AIR_CheckMoveIntoNewHomebase ( const aircraft_t aircraft,
const struct base_s base 
)
int AIR_CountInBaseByTemplate ( const struct base_s base,
const aircraft_t aircraftTemplate 
)
bool AIR_Delete ( base_t base,
aircraft_t aircraft 
)

Will remove the given aircraft from the base.

Parameters
[out]baseThe base to remove the aircraft from
aircraftThe aircraft to remove
Returns
true if the aircraft was removed, false otherwise
See also
AIR_Add

Definition at line 621 of file cp_aircraft.cpp.

References AIR_CRASHED, AIR_GetHangarCapacityType(), ccs_s::aircraft, aircraft_s::alienCargo, CAP_AddCurrent(), ccs, cgi, MAX_CAP, and aircraft_s::status.

Referenced by AIR_DeleteAircraft(), and CP_ResetCampaignData().

void AIR_DeleteAircraft ( aircraft_t aircraft)

Removes an aircraft from its base and the game.

Parameters
[in]aircraftPointer to aircraft that should be removed.
Note
The assigned soldiers (if any) are unassinged from the aircraft - not fired.
See also
AIR_DestroyAircraft
Note
If you want to do something different (kill, fire, etc...) do it before calling this function.
Todo:
Return status of deletion for better error handling.

Definition at line 836 of file cp_aircraft.cpp.

References AII_RemoveItemFromSlot(), AIR_BaseHasAircraft(), AIR_Delete(), AIR_GetFirstFromBase(), AIR_IsAircraftOnGeoscape(), AIR_RemoveEmployees(), base_s::aircraftCurrent, cgi, cgame_import_s::Cvar_Set(), aircraft_s::electronics, GEO_NotifyAircraftRemoved(), aircraft_s::homebase, i, base_s::idx, MAX_AIRCRAFTSLOT, RADAR_UpdateWholeRadarOverlay(), aircraft_s::shield, TR_NotifyAircraftRemoved(), and aircraft_s::weapons.

Referenced by AIR_DestroyAircraft(), B_Destroy(), BS_SellAircraft(), TEST_F(), and TR_EmptyTransferCargo().

void AIR_DestroyAircraft ( aircraft_t aircraft,
bool  killPilot 
)

Removes an aircraft from its base and the game.

Parameters
[in]aircraftPointer to aircraft that should be removed.
[in]killPilotShould pilot be removed from game or not?
Note
aircraft and assigned soldiers (if any) are removed from game.
Todo:
Return status of deletion for better error handling.

Definition at line 888 of file cp_aircraft.cpp.

References aircraft_s::acTeam, AIR_CRASHED, AIR_DeleteAircraft(), AIR_GetPilot(), AIR_SetPilot(), cgi, Employee::chr, E_DeleteEmployee(), E_RemoveInventoryFromStorage(), ERR_DROP, aircraft_s::id, LIST_Foreach, character_s::name, aircraft_s::status, and character_s::ucn.

Referenced by AIRFIGHT_ActionsAfterAirfight(), B_MoveAircraftOnGeoscapeToOtherBases(), CP_EndRescueMission(), and CP_SpawnRescueMission().

const aircraft_t* AIR_GetAircraft ( const char *  name)

Searches the global array of aircraft types for a given aircraft.

Parameters
[in]nameAircraft id.
Returns
aircraft_t pointer or errors out (ERR_DROP)

Definition at line 571 of file cp_aircraft.cpp.

References AIR_GetAircraftSilent(), cgi, ERR_DROP, and Q_strnull().

Referenced by AIR_LoadAircraftXML(), B_SetUpFirstBase(), BS_InitMarket(), CP_CampaignRunMarket(), PR_LoadXML(), RS_AssignTechLinks(), TEST_F(), UP_AircraftDescription(), UR_DialogInitSell_f(), and US_LoadXML().

aircraft_t* AIR_GetAircraftFromBaseByIDXSafe ( const struct base_s base,
int  index 
)
const aircraft_t* AIR_GetAircraftSilent ( const char *  name)

Searches the global array of aircraft types for a given aircraft.

Parameters
[in]nameAircraft id.
Returns
aircraft_t pointer or nullptr if not found.
Note
This function gives no warning on null name or if no aircraft found

Definition at line 554 of file cp_aircraft.cpp.

References ccs_s::aircraftTemplates, ccs, i, aircraft_s::id, ccs_s::numAircraftTemplates, and Q_streq.

Referenced by AIR_GetAircraft(), AIR_ParseAircraft(), BS_Buy_f(), BS_SetAutosell_f(), BS_ShowInfo_f(), GAME_CP_GetItemModel(), and UR_DialogStartStore_f().

int AIR_GetAircraftWeaponRanges ( const aircraftSlot_t slot,
int  maxSlot,
float *  weaponRanges 
)

Get the all the unique weapon ranges of this aircraft.

Parameters
[in]slotPointer to the aircrafts weapon slot list.
[in]maxSlotmaximum number of weapon slots in aircraft.
[out]weaponRangesAn array containing a unique list of weapons ranges.
Returns
Number of unique weapons ranges.

Definition at line 2084 of file cp_aircraft.cpp.

References AIR_STATS_WRANGE, aircraftSlot_s::ammo, objDef_s::craftitem, MAX_AIRCRAFTSLOT, Q_FloatSort(), and craftitem_s::stats.

void AIR_GetDestinationWhilePursuing ( const aircraft_t shooter,
const aircraft_t target,
vec2_t  dest 
)

Calculates the point where aircraft should go to intecept a moving target.

Parameters
[in]shooterPointer to shooting aircraft.
[in]targetPointer to target aircraft.
[out]destDestination that shooting aircraft should aim to intercept target aircraft.
Todo:
only compute this calculation every time target changes destination, or one of the aircraft speed changes.
See also
AIR_SendAircraftPursuingUFO
UFO_SendPursuingAircraft

In the following, we note S the position of the shooter, T the position of the target, D the destination of the target and I the interception point where shooter should reach target O is the center of earth. A, B and C are the angles TSI, STI and SIT a, b, and c are the angles TOI, SOI and SOT

According to geometry on a sphere, the values defined above must be solutions of both equations: sin(A) / sin(a) = sin(B) / sin(b) cos(a) = cos(b) * cos(c) + sin(b) * sin(c) * cos(A) And we have another equation, given by the fact that shooter and target must reach I at the same time: shooterSpeed * a = targetSpeed * b We the want to find and equation linking a, c and B (we know the last 2 values). We therefore eliminate b, then A, to get the equation we need to solve: pow(cos(a) - cos(speedRatio * a) * cos(c), 2.)

  • sin(c) * sin(c) * (sin(speedRatio * a) * sin(speedRatio * a) - sin(a) * sin(a) * sin(B) * sin(B)) = 0
Todo:
add EQUAL_EPSILON here?

Definition at line 1805 of file cp_aircraft.cpp.

References AIR_GetDestinationFindRoot(), AIR_STATS_SPEED, cgi, CrossProduct(), DEBUG_CLIENT, DotProduct, f, GetDistanceOnGlobe(), mapline_s::numPoints, mapline_s::point, PolarToVec(), aircraft_s::pos, RotatePointAroundVector(), aircraft_s::route, aircraft_s::stats, todeg, torad, VecToPolar(), Vector2Copy, and VectorNormalize().

Referenced by AIR_SendAircraftPursuingUFO(), UFO_SearchAircraftTarget(), and UFO_SendPursuingAircraft().

aircraft_t* AIR_GetFirstFromBase ( const struct base_s base)
int AIR_GetOperationRange ( const aircraft_t aircraft)

Calculates the range an aircraft can fly on the geoscape.

Parameters
aircraftThe aircraft to calculate the range for
Returns
The range

Definition at line 447 of file cp_aircraft.cpp.

References AIR_STATS_FUELSIZE, AIR_STATS_SPEED, f, int(), KILOMETER_PER_DEGREE, SECONDS_PER_HOUR, and aircraft_s::stats.

Referenced by AIR_AircraftSelect(), and UP_AircraftDescription().

int AIR_GetRemainingRange ( const aircraft_t aircraft)

Calculates the remaining range the aircraft can fly.

Parameters
aircraftThe aircraft to calculate the remaining range for
Returns
The remaining range

Definition at line 459 of file cp_aircraft.cpp.

References AIR_STATS_SPEED, aircraft_s::fuel, and aircraft_s::stats.

Referenced by AIR_AircraftHasEnoughFuel(), and AIR_AircraftHasEnoughFuelOneWay().

void AIR_InitStartup ( void  )

Init actions for aircraft-subsystem.

Definition at line 2905 of file cp_aircraft.cpp.

References AIR_InitCallbacks(), and cgi.

Referenced by CP_InitStartup().

bool AIR_IsAircraftInBase ( const aircraft_t aircraft)

Checks whether given aircraft is in its homebase.

Parameters
[in]aircraftPointer to an aircraft.
Returns
true if given aircraft is in its homebase.
false if given aircraft is not in its homebase.

Definition at line 371 of file cp_aircraft.cpp.

References AIR_HOME, AIR_REFUEL, and aircraft_s::status.

Referenced by AII_AutoAddAmmo(), AII_ReloadWeapon(), AII_RepairAircraft(), AII_UpdateInstallationDelay(), AIM_AircraftStart_f(), AIR_AircraftFillList_f(), AIR_AircraftSelect(), AIR_AircraftStatusToName(), AIR_SendAircraftPursuingUFO(), AIR_SendAircraftToMission(), AIR_ShowAircraft_f(), AIRFIGHT_ProjectileHits(), BS_FillMarket_f(), BS_SellAircraft(), GEO_Draw(), Employee::isAwayFromBase(), TR_AircraftListSelect(), and TR_FillAircraft().

bool AIR_IsAircraftOnGeoscape ( const aircraft_t aircraft)

Checks whether given aircraft is on geoscape.

Parameters
[in]aircraftPointer to an aircraft.
Note
aircraft may be neither on geoscape, nor in base (like when it's transferred)
Returns
false if given aircraft is not on geoscape, true if given aircraft is on geoscape.
See also
UFO_IsUFOSeenOnGeoscape

Definition at line 385 of file cp_aircraft.cpp.

References AIR_CRASHED, AIR_DROP, AIR_HOME, AIR_IDLE, AIR_INTERCEPT, AIR_MISSION, AIR_NONE, AIR_REFUEL, AIR_RETURNING, AIR_TRANSFER, AIR_TRANSIT, AIR_UFO, cgi, ERR_FATAL, and aircraft_s::status.

Referenced by AB_UpdateStealthForAllBase(), AIR_AircraftReturnToBase(), AIR_CampaignRun(), AIR_DeleteAircraft(), B_MoveAircraftOnGeoscapeToOtherBases(), GEO_Click(), GEO_DrawMarkers(), GEO_GetGeoscapeAngle(), RADAR_AddDetectedUFOToEveryRadar(), RADAR_UpdateWholeRadarOverlay(), TEST_F(), UFO_CampaignCheckEvents(), UFO_CheckShootBack(), and UFO_SearchAircraftTarget().

const aircraft_t* AIR_IsEmployeeInAircraft ( const class Employee employee,
const aircraft_t aircraft 
)
bool AIR_IsInAircraftTeam ( const aircraft_t aircraft,
const class Employee employee 
)
void AIR_MoveAircraftIntoNewHomebase ( aircraft_t aircraft,
base_t base 
)

Moves a given aircraft to a new base (also the employees and inventory)

Parameters
[in]aircraftThe aircraft to move into a new base
[in]baseThe base to move the aircraft into

Definition at line 785 of file cp_aircraft.cpp.

References aircraft_s::acTeam, AIR_AircraftReturnToBase(), AIR_GetFirstFromBase(), AIR_GetHangarCapacityType(), AIR_GetPilot(), AIR_RETURNING, AIR_TransferItemsCarriedByCharacterToBase(), base_s::aircraftCurrent, CAP_AddCurrent(), cgi, DEBUG_CLIENT, E_MoveIntoNewBase(), GEO_SelectAircraft(), aircraft_s::homebase, aircraft_s::id, LIST_Foreach, base_s::name, and aircraft_s::status.

Referenced by B_MoveAircraftOnGeoscapeToOtherBases(), and CL_PopupChangeHomebase_f().

void AIR_MoveEmployeeInventoryIntoStorage ( const aircraft_t aircraft,
equipDef_t ed 
)

Move all the equipment carried by the team on the aircraft into the given equipment.

Parameters
[in]aircraftThe craft with the team (and thus equipment) onboard.
[out]edThe equipment definition which will receive all the stuff from the aircraft-team.

Definition at line 2813 of file cp_aircraft.cpp.

References aircraft_s::acTeam, equipDef_s::addClip(), AIR_GetTeamSize(), Item::ammoDef(), cgi, DEBUG_CLIENT, Item::def(), Item::getAmmoLeft(), Item::getNext(), Container::getNextItem(), objDef_s::idx, objDef_s::isReloadable(), LIST_Foreach, equipDef_s::numItems, and type.

Referenced by B_InitialEquipment().

bool AIR_PilotSurvivedCrash ( const aircraft_t aircraft)

Determine if an aircraft's pilot survived a crash, based on his piloting skill (and a bit of randomness)

Parameters
[in]aircraftPointer to crashed aircraft
Returns
true if survived, false if not

Definition at line 2022 of file cp_aircraft.cpp.

References cgi, Employee::chr, crand(), cgame_import_s::csi, f, GEO_GetColor(), TerrainDefs::getSurvivalChance(), MAPTYPE_TERRAIN, aircraft_s::pilot, aircraft_s::pos, character_s::score, SKILL_PILOTING, chrScoreGlobal_s::skills, and csi_s::terrainDefs.

Referenced by AIRFIGHT_ActionsAfterAirfight(), and CP_SpawnRescueMission().

bool AIR_RemoveEmployee ( Employee employee,
aircraft_t aircraft 
)

Removes a soldier from an aircraft.

Parameters
[in,out]employeeThe soldier to be removed from the aircraft.
[in,out]aircraftThe aircraft to remove the soldier from. Use nullptr to remove the soldier from any aircraft.
See also
AIR_AddEmployee

Definition at line 2720 of file cp_aircraft.cpp.

References aircraft_s::acTeam, AIR_Foreach, AIR_GetPilot(), AIR_IsEmployeeInAircraft(), AIR_SetPilot(), cgi, Employee::chr, DEBUG_CLIENT, EMPL_PILOT, Employee::getType(), aircraft_s::homebase, base_s::idx, aircraft_s::idx, and character_s::ucn.

Referenced by AIR_RemoveEmployees(), CP_EndRescueMission(), CP_TEAM_AssignSoldierByUCN_f(), TR_TransferStart(), and Employee::unassign().

void AIR_RemoveEmployees ( aircraft_t aircraft)

Removes all soldiers from an aircraft.

Parameters
[in,out]aircraftThe aircraft to remove the soldiers from.
See also
AIR_RemoveEmployee

Definition at line 2793 of file cp_aircraft.cpp.

References aircraft_s::acTeam, AIR_GetTeamSize(), AIR_RemoveEmployee(), AIR_SetPilot(), cgi, ERR_DROP, and LIST_Foreach.

Referenced by AIR_DeleteAircraft(), and BS_Buy_f().

void AIR_RemovePilotFromAssignedAircraft ( const struct base_s base,
const class Employee pilot 
)
void AIR_ResetAircraftTeam ( aircraft_t aircraft)

Resets team in given aircraft.

Parameters
[in]aircraftPointer to an aircraft, where the team will be reset.

Definition at line 1933 of file cp_aircraft.cpp.

References aircraft_s::acTeam, and cgi.

Referenced by AIR_NewAircraft(), and AIR_Shutdown().

bool AIR_SendAircraftPursuingUFO ( aircraft_t aircraft,
aircraft_t ufo 
)
bool AIR_SendAircraftToMission ( aircraft_t aircraft,
mission_t mission 
)

Sends the specified aircraft to specified mission.

Parameters
[in]aircraftPointer to aircraft to send to mission.
[in]missionPointer to given mission.
Returns
true if sending an aircraft to specified mission is possible.

Definition at line 1149 of file cp_aircraft.cpp.

References _, mission_s::active, AII_ReloadAircraftWeapons(), AIR_AircraftHasEnoughFuel(), AIR_GetTeamSize(), AIR_IsAircraftInBase(), AIR_MISSION, B_IsUnderAttack, cgi, CP_Popup(), GEO_CalcLine(), GEO_SetInterceptorAircraft, aircraft_s::homebase, aircraft_s::mission, MS_AddNewMessage(), aircraft_s::point, mission_s::pos, aircraft_s::pos, aircraft_s::route, aircraft_s::status, and aircraft_s::time.

Referenced by AIR_SendAircraftToMission_f(), and CL_PopupInterceptClick_f().

bool AIR_SetPilot ( aircraft_t aircraft,
Employee pilot 
)

Assign a pilot to an aircraft.

Parameters
[out]aircraftPointer to the aircraft to add pilot to
[in]pilotPointer to the pilot to add
Returns
true if the assignment was successful (there wasn't a pilot assigned), false if there was already a pilot assigned and we tried to assign a new one (pilot isn't nullptr).

Definition at line 1992 of file cp_aircraft.cpp.

References aircraft_s::pilot.

Referenced by AIR_AutoAddPilotToAircraft(), AIR_DestroyAircraft(), AIR_LoadAircraftXML(), AIR_RemoveEmployee(), AIR_RemoveEmployees(), AIR_RemovePilotFromAssignedAircraft(), and CP_TEAM_AssignSoldierByUCN_f().

void AIR_Shutdown ( void  )

Closing actions for aircraft-subsystem.

Definition at line 2914 of file cp_aircraft.cpp.

References AIR_Foreach, AIR_ResetAircraftTeam(), AIR_ShutdownCallbacks(), ccs_s::aircraft, ccs, and cgi.

Referenced by CP_Shutdown().