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

Go to the source code of this file.

Macros

#define UFO_GetGeoscapeIDX(ufo)   ((ufo) - ccs.ufos)
 

Enumerations

enum  { UFO_IS_NO_TARGET, UFO_IS_TARGET_OF_MISSILE, UFO_IS_TARGET_OF_LASER }
 

Functions

const char * UFO_TypeToName (const ufoType_t type)
 Translate UFO type to name. More...
 
const technology_tUFO_GetTechnologyFromType (const ufoType_t type)
 Get the technology for a given UFO type. More...
 
const aircraft_tUFO_GetByType (const ufoType_t type)
 Get the aircraft template for a given UFO type. More...
 
bool UFO_ShouldAppearOnGeoscape (const ufoType_t type)
 Some UFOs may only appear if after some interest level in the current running campaign is reached. More...
 
bool UFO_CanDoMission (const ufoType_t uType, const char *mType)
 Check if the UFO type is available for the given mission type. More...
 
int UFO_GetAvailableUFOsForMission (const interestCategory_t missionType, ufoType_t *ufoTypes, bool checkInterest=true)
 Fill an array with available UFOs for the mission type. More...
 
int UFO_GetOneAvailableUFOForMission (const interestCategory_t missionType, bool checkInterest=true)
 Get a suitable UFO for the mission type. More...
 
const char * UFO_GetName (const aircraft_t *ufocraft)
 Returns name of the UFO if UFO has been researched. More...
 
void UFO_SetRandomDest (aircraft_t *ufo)
 Give a random destination to the given UFO, and make him to move there. More...
 
void UFO_SetRandomDestAround (aircraft_t *ufocraft, const vec2_t pos)
 Give a random destination to the given UFO close to a position, and make him to move there. More...
 
void UFO_FleePhalanxAircraft (aircraft_t *ufo, const vec2_t v)
 
void UFO_CheckShootBack (const campaign_t *campaign, aircraft_t *ufo, aircraft_t *phalanxAircraft)
 Check if the ufo can shoot back at phalanx aircraft. More...
 
void UFO_CampaignRunUFOs (const campaign_t *campaign, int dt)
 Make the UFOs run. More...
 
void UFO_UpdateAlienInterestForAllBasesAndInstallations (void)
 Update alien interest for all PHALANX bases. More...
 
void UFO_DetectNewUFO (aircraft_t *ufocraft)
 Perform actions when a new UFO is detected. More...
 
bool UFO_CampaignCheckEvents (void)
 Check events for UFOs: Appears or disappears on radars. More...
 
aircraft_tUFO_AddToGeoscape (ufoType_t ufotype, const vec2_t destination, struct mission_s *mission)
 Add a UFO to geoscape. More...
 
void UFO_RemoveFromGeoscape (aircraft_t *ufo)
 Remove the specified ufo from geoscape. More...
 
void UFO_SendToDestination (aircraft_t *ufo, const vec2_t dest)
 Make the specified UFO go to destination. More...
 
bool UFO_SendPursuingAircraft (aircraft_t *ufo, aircraft_t *aircraft)
 Make the specified UFO pursue a phalanx aircraft. More...
 
void UFO_NotifyPhalanxAircraftRemoved (const aircraft_t *const aircraft)
 Notify to UFOs that a Phalanx aircraft has been destroyed. More...
 
bool UFO_IsUFOSeenOnGeoscape (const aircraft_t *ufo)
 Check if an aircraft should be seen on geoscape. More...
 
aircraft_tUFO_GetByIDX (const int idx)
 returns the UFO on the geoscape with a certain index More...
 
aircraft_tUFO_GetNext (aircraft_t *lastUFO)
 Iterates through the UFOs. More...
 
aircraft_tUFO_GetNextOnGeoscape (aircraft_t *lastUFO)
 
const aircraft_tUFO_GetTemplate (ufoType_t ufoType)
 Get the template data for the given ufo type. More...
 
aircraft_tUFO_CreateFromTemplate (const aircraft_t *ufoTemplate)
 Creates a new ufo on the geoscape from the given aircraft template. More...
 
void UFO_InitStartup (void)
 Init actions for ufo-subsystem. More...
 
void UFO_Shutdown (void)
 Closing actions for ufo-subsystem. More...
 

Macro Definition Documentation

#define UFO_GetGeoscapeIDX (   ufo)    ((ufo) - ccs.ufos)

Definition at line 33 of file cp_ufo.h.

Referenced by AIR_SaveAircraftXML(), AIRFIGHT_SaveXML(), GEO_Click(), and GEO_UpdateGeoscapeDock().

Enumeration Type Documentation

anonymous enum
Enumerator
UFO_IS_NO_TARGET 
UFO_IS_TARGET_OF_MISSILE 
UFO_IS_TARGET_OF_LASER 

Definition at line 27 of file cp_ufo.h.

Function Documentation

aircraft_t* UFO_AddToGeoscape ( ufoType_t  ufoType,
const vec2_t  destination,
mission_t mission 
)

Add a UFO to geoscape.

Parameters
[in]ufoTypeThe type of ufo (fighter, scout, ...).
[in]destinationPosition where the ufo should go. nullptr is randomly chosen
[in]missionPointer to the mission the UFO is involved in
See also
UFO_RemoveFromGeoscape
UFO_RemoveFromGeoscape_f

Definition at line 773 of file cp_ufo.cpp.

References AII_ReloadAircraftWeapons(), AII_UpdateAircraftStats(), AIR_STATS_DAMAGE, aircraft_s::damage, aircraft_s::detected, aircraft_s::landed, aircraft_s::mission, aircraft_s::stats, UFO_CreateFromTemplate(), UFO_GetTemplateForGeoscape(), UFO_SendToDestination(), UFO_SetRandomDest(), and UFO_SetRandomPos().

Referenced by CP_MissionBegin(), CP_SupplyMissionCreate(), and TEST_F().

bool UFO_CampaignCheckEvents ( void  )
bool UFO_CanDoMission ( const ufoType_t  uType,
const char *  mType 
)

Check if the UFO type is available for the given mission type.

Parameters
uTypeThe UFO type to check
mTypeThe mission type to check

Definition at line 137 of file cp_ufo.cpp.

References cgi, cgame_import_s::LIST_ContainsString(), aircraft_s::missionTypes, and UFO_GetByType().

Referenced by CP_InterceptMissionSet(), and UFO_GetAvailableUFOsForMission().

void UFO_CheckShootBack ( const campaign_t campaign,
aircraft_t ufo,
aircraft_t phalanxAircraft 
)

Check if the ufo can shoot back at phalanx aircraft.

Parameters
[in]campaignThe campaign data structure
[in,out]ufoThe ufo to check the shotting for
[in,out]phalanxAircraftThe possible target

Definition at line 578 of file cp_ufo.cpp.

References AIR_IsAircraftOnGeoscape(), aircraft_s::aircraftTarget, AIRFIGHT_ExecuteActions(), CP_UFOProceedMission(), and UFO_SendPursuingAircraft().

Referenced by AIRFIGHT_ExecuteActions(), TEST_F(), and UFO_SearchAircraftTarget().

aircraft_t* UFO_CreateFromTemplate ( const aircraft_t ufoTemplate)

Creates a new ufo on the geoscape from the given aircraft template.

Parameters
ufoTemplateThe aircraft template to create the ufo from.
Returns
nullptr if the max allowed amount of ufos are already on the geoscape, otherwise the newly created ufo pointer

Definition at line 741 of file cp_ufo.cpp.

References AIR_IsUFO, ccs, aircraft_s::idx, MAX_UFOONGEOSCAPE, ccs_s::numUFOs, and UFO_GetByIDX().

Referenced by CP_AttackUFOCarrier_f(), and UFO_AddToGeoscape().

void UFO_FleePhalanxAircraft ( aircraft_t ufo,
const vec2_t  v 
)
int UFO_GetAvailableUFOsForMission ( const interestCategory_t  missionType,
ufoType_t ufoTypes,
bool  checkInterest 
)

Fill an array with available UFOs for the mission type.

Parameters
[in]missionTypeThe kind ofmission we are currently creating.
[out]ufoTypesArray of ufoType_t that may be used for this mission.
[in]checkInterestDo a UFO_ShouldAppearOnGeoscape check if true (default)
Returns
number of elements written in ufoTypes

Definition at line 153 of file cp_ufo.cpp.

References cgi, i, INTERESTCATEGORY_BASE_ATTACK, INTERESTCATEGORY_BUILDING, INTERESTCATEGORY_HARVEST, INTERESTCATEGORY_INTERCEPT, INTERESTCATEGORY_INTERCEPTBOMBING, INTERESTCATEGORY_RECON, INTERESTCATEGORY_SUBVERT, INTERESTCATEGORY_SUPPLY, INTERESTCATEGORY_TERROR_ATTACK, INTERESTCATEGORY_XVI, UFO_CanDoMission(), and UFO_ShouldAppearOnGeoscape().

Referenced by CP_MissionChooseUFO(), NAT_ScriptSanityCheck(), TEST_F(), and UFO_GetOneAvailableUFOForMission().

aircraft_t* UFO_GetByIDX ( const int  idx)

returns the UFO on the geoscape with a certain index

Parameters
[in]idxIndex of the UFO

Definition at line 85 of file cp_ufo.cpp.

References ccs, MAX_UFOONGEOSCAPE, and ccs_s::ufos.

Referenced by AIR_LoadXML(), AIR_SaveXML(), AIRFIGHT_LoadXML(), B_LoadBaseSlotsXML(), UFO_CampaignRunUFOs(), UFO_CreateFromTemplate(), UFO_GeoSelectUFO_f(), and UFO_NotifyPhalanxAircraftRemoved().

const aircraft_t* UFO_GetByType ( const ufoType_t  type)

Get the aircraft template for a given UFO type.

Parameters
typeThe UFO type to get the template for
Returns
The aircraft template of the UFO - always returns a value

Definition at line 109 of file cp_ufo.cpp.

References ccs_s::aircraftTemplates, ccs, cgi, ERR_DROP, aircraft_s::getUfoType(), i, ccs_s::numAircraftTemplates, and type.

Referenced by TEST_F(), UFO_CanDoMission(), and UFO_ShouldAppearOnGeoscape().

const char* UFO_GetName ( const aircraft_t ufocraft)
aircraft_t* UFO_GetNext ( aircraft_t lastUFO)

Iterates through the UFOs.

Parameters
[in]lastUFOPointer of the aircraft to iterate from. call with nullptr to get the first one.

Definition at line 41 of file cp_ufo.cpp.

References ccs, ccs_s::numUFOs, and ccs_s::ufos.

Referenced by AIR_PostLoadInitMissions(), RADAR_SetRadarAfterLoading(), UFO_CampaignCheckEvents(), UFO_GetNextOnGeoscape(), and UFO_UpdateAlienInterestForAllBasesAndInstallations().

int UFO_GetOneAvailableUFOForMission ( const interestCategory_t  missionType,
bool  checkInterest 
)

Get a suitable UFO for the mission type.

Parameters
[in]missionTypeThe kind of mission we are currently creating.
[in]checkInterestDo a UFO_ShouldAppearOnGeoscape check if true (default)
Returns
the first ufo found

Definition at line 217 of file cp_ufo.cpp.

References UFO_GetAvailableUFOsForMission(), UFO_MAX, and UFO_NONE.

const technology_t* UFO_GetTechnologyFromType ( const ufoType_t  type)

Get the technology for a given UFO type.

Parameters
typeUFO type to get the technology for
Returns
The technology for the given UFO. If no technology was found for the UFO id this might return nullptr.

Definition at line 97 of file cp_ufo.cpp.

References cgi, cgame_import_s::Com_UFOTypeToShortName(), and RS_GetTechByProvided().

Referenced by UFO_TypeToName().

const aircraft_t* UFO_GetTemplate ( ufoType_t  ufoType)

Get the template data for the given ufo type.

Parameters
ufoTypeThe ufo type to search the template for.
Returns
nullptr in case the ufoType wasn't found, or the pointer to the ufo template.

Definition at line 695 of file cp_ufo.cpp.

References AIR_IsUFO, ccs_s::aircraftTemplates, ccs, aircraft_s::getUfoType(), and ccs_s::numAircraftTemplates.

Referenced by CP_AttackUFOCarrier_f().

void UFO_InitStartup ( void  )

Init actions for ufo-subsystem.

Definition at line 1011 of file cp_ufo.cpp.

References cgi, CVAR_DEVELOPER, cgame_import_s::Cvar_Get(), and UFO_InitCallbacks().

Referenced by CP_InitStartup().

bool UFO_IsUFOSeenOnGeoscape ( const aircraft_t ufo)

Check if an aircraft should be seen on geoscape.

Returns
true or false whether UFO should be seen or not on geoscape.
See also
AIR_IsAircraftOnGeoscape

Definition at line 989 of file cp_ufo.cpp.

References cgi, aircraft_s::detected, ERR_DROP, aircraft_s::id, aircraft_s::landed, and aircraft_s::notOnGeoscape.

Referenced by AIRFIGHT_BaseShoot(), AIRFIGHT_InstallationShoot(), GEO_DrawRadarInMap(), UFO_GetNextOnGeoscape(), and UFO_SearchAircraftTarget().

void UFO_NotifyPhalanxAircraftRemoved ( const aircraft_t *const  aircraft)

Notify to UFOs that a Phalanx aircraft has been destroyed.

Parameters
[in]aircraftPointer to the Phalanx aircraft that has been removed.

Definition at line 972 of file cp_ufo.cpp.

References aircraft_s::aircraftTarget, ccs, ccs_s::numUFOs, and UFO_GetByIDX().

Referenced by AIRFIGHT_ActionsAfterAirfight(), and B_MoveAircraftOnGeoscapeToOtherBases().

void UFO_RemoveFromGeoscape ( aircraft_t ufo)

Remove the specified ufo from geoscape.

See also
CP_MissionRemove
Note
Keep in mind that you have to update the ufo pointers after you called this function

Definition at line 817 of file cp_ufo.cpp.

References ccs, cgi, DEBUG_CLIENT, aircraft_s::id, ccs_s::numUFOs, REMOVE_ELEM_ADJUST_IDX, and ccs_s::ufos.

Referenced by AIR_LoadXML(), AIR_PostLoadInitMissions(), CP_UFORemoveFromGeoscape(), and TEST_F().

bool UFO_SendPursuingAircraft ( aircraft_t ufo,
aircraft_t aircraft 
)

Make the specified UFO pursue a phalanx aircraft.

Parameters
[in,out]ufoPointer to the UFO.
[in,out]aircraftPointer to the target aircraft.
See also
UFO_SendAttackBase

Definition at line 532 of file cp_ufo.cpp.

References AIR_GetDestinationWhilePursuing(), AIR_TRANSIT, AIR_UFO, aircraft_s::aircraftTarget, AIRFIGHT_ChooseWeapon(), AIRFIGHT_WEAPON_CAN_NEVER_SHOOT, dest, GEO_CalcLine(), aircraft_s::maxWeapons, aircraft_s::point, aircraft_s::pos, aircraft_s::route, aircraft_s::status, aircraft_s::time, and aircraft_s::weapons.

Referenced by AIRFIGHT_ExecuteActions(), UFO_CheckShootBack(), and UFO_SearchAircraftTarget().

void UFO_SendToDestination ( aircraft_t ufo,
const vec2_t  dest 
)
void UFO_SetRandomDest ( aircraft_t ufocraft)

Give a random destination to the given UFO, and make him to move there.

Parameters
[in]ufocraftPointer to the UFO which destination will be changed.
See also
UFO_SetRandomPos

Definition at line 259 of file cp_ufo.cpp.

References CP_GetRandomPosOnGeoscape(), and UFO_SendToDestination().

Referenced by CP_BaseAttackMissionLeave(), CP_BuildBaseGovernmentLeave(), CP_BuildBaseMissionLeave(), CP_InterceptMissionLeave(), CP_LeaveRescueMission(), CP_ReconMissionLeave(), CP_SupplyMissionLeave(), CP_UFOProceedMission(), UFO_AddToGeoscape(), and UFO_CampaignRunUFOs().

void UFO_SetRandomDestAround ( aircraft_t ufocraft,
const vec2_t  pos 
)

Give a random destination to the given UFO close to a position, and make him to move there.

Parameters
[in]ufocraftPointer to the UFO which destination will be changed.
[in]posThe position the UFO should around.
See also
UFO_SetRandomPos

Definition at line 274 of file cp_ufo.cpp.

References dest, gaussrand(), UFO_SendToDestination(), and Vector2Set.

Referenced by CP_InterceptAttackInstallation(), and UFO_CampaignRunUFOs().

bool UFO_ShouldAppearOnGeoscape ( const ufoType_t  type)

Some UFOs may only appear if after some interest level in the current running campaign is reached.

Parameters
typeThe UFO type to check the interest level for
Returns
true if the UFO may appear on geoscape, false otherwise

Definition at line 125 of file cp_ufo.cpp.

References ccs, ccs_s::overallInterest, UFO_GetByType(), and aircraft_s::ufoInterestOnGeoscape.

Referenced by UFO_GetAvailableUFOsForMission().

void UFO_Shutdown ( void  )

Closing actions for ufo-subsystem.

Definition at line 1023 of file cp_ufo.cpp.

References cgi, and UFO_ShutdownCallbacks().

Referenced by CP_Shutdown().

const char* UFO_TypeToName ( const ufoType_t  type)

Translate UFO type to name.

Parameters
[in]typeUFO type in ufoType_t.
Returns
Translated UFO name.
See also
cgi->Com_UFOTypeToShortName
cgi->Com_UFOShortNameToID

Definition at line 231 of file cp_ufo.cpp.

References _, cgi, ERR_DROP, technology_s::name, and UFO_GetTechnologyFromType().

Referenced by PR_DisassemblyInfo(), PR_FinishDisassembly(), PR_GetName(), and PR_UpdateProductionList().

void UFO_UpdateAlienInterestForAllBasesAndInstallations ( void  )

Update alien interest for all PHALANX bases.

Note
called every DETECTION_INTERVAL
See also
UFO_UpdateAlienInterestForOneBase
CP_CampaignRun

Definition at line 437 of file cp_ufo.cpp.

References B_GetNext(), INS_Foreach, aircraft_s::landed, UFO_GetNext(), UFO_UpdateAlienInterestForOneBase(), and UFO_UpdateAlienInterestForOneInstallation().

Referenced by CP_CampaignFunctionPeriodicCall().