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

UFOs on geoscape. More...

#include "../../cl_shared.h"
#include "cp_campaign.h"
#include "cp_geoscape.h"
#include "cp_ufo.h"
#include "cp_aircraft.h"
#include "cp_mapfightequip.h"
#include "cp_missions.h"
#include "cp_ufo_callbacks.h"

Go to the source code of this file.

Functions

aircraft_tUFO_GetNext (aircraft_t *lastUFO)
 Iterates through the UFOs. More...
 
aircraft_tUFO_GetNextOnGeoscape (aircraft_t *lastUFO)
 
aircraft_tUFO_GetByIDX (const int idx)
 returns the UFO on the geoscape with a certain index 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)
 Fill an array with available UFOs for the mission type. More...
 
int UFO_GetOneAvailableUFOForMission (const interestCategory_t missionType, bool checkInterest)
 Get a suitable UFO for the mission type. More...
 
const char * UFO_TypeToName (const ufoType_t type)
 Translate UFO type to name. 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 *ufocraft)
 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...
 
static void UFO_SetRandomPos (aircraft_t *ufocraft)
 Give a random position to the given UFO. More...
 
static int UFO_IsTargetOfBase (const aircraft_t *ufo, const base_t *base)
 Check if a UFO is the target of a base. More...
 
static int UFO_IsTargetOfInstallation (const aircraft_t *ufo, const installation_t *installation)
 Check if a UFO is the target of an installation. More...
 
static void UFO_UpdateAlienInterestForOneBase (const aircraft_t *ufo, base_t *base)
 Update alien interest for one PHALANX base. More...
 
static void UFO_UpdateAlienInterestForOneInstallation (const aircraft_t *ufo, installation_t *installation)
 Update alien interest for one PHALANX installation (radar tower, SAM, ...) More...
 
void UFO_UpdateAlienInterestForAllBasesAndInstallations (void)
 Update alien interest for all PHALANX bases. More...
 
static void UFO_SearchAircraftTarget (const campaign_t *campaign, aircraft_t *ufo, float maxDetectionRange=MAX_DETECTING_RANGE)
 Check if the ufo can shoot at a PHALANX aircraft and whether it should follow another ufo. More...
 
bool UFO_SendPursuingAircraft (aircraft_t *ufo, aircraft_t *aircraft)
 Make the specified UFO pursue a phalanx aircraft. More...
 
void UFO_SendToDestination (aircraft_t *ufo, const vec2_t dest)
 Make the specified UFO go to destination. More...
 
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 deltaTime)
 Make the UFOs run. More...
 
const aircraft_tUFO_GetTemplate (ufoType_t ufoType)
 Get the template data for the given ufo type. More...
 
static const aircraft_tUFO_GetTemplateForGeoscape (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...
 
aircraft_tUFO_AddToGeoscape (ufoType_t ufoType, const vec2_t destination, mission_t *mission)
 Add a UFO to geoscape. More...
 
void UFO_RemoveFromGeoscape (aircraft_t *ufo)
 Remove the specified ufo from geoscape. 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...
 
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...
 
void UFO_InitStartup (void)
 Init actions for ufo-subsystem. More...
 
void UFO_Shutdown (void)
 Closing actions for ufo-subsystem. More...
 

Variables

static const float MAX_DETECTING_RANGE = 25.0f
 
static const cmdList_t ufoDebugCallbacks []
 

Detailed Description

UFOs on geoscape.

Definition in file cp_ufo.cpp.

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().

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().

static const aircraft_t* UFO_GetTemplateForGeoscape ( ufoType_t  ufoType)
static

Get the template data for the given ufo type.

Parameters
ufoTypeThe ufo type to search the template for.
Note
This function will only return those templates that may appear on the geoscape!
Returns
nullptr in case the ufoType wasn't found, or the pointer to the ufo template.

Definition at line 718 of file cp_ufo.cpp.

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

Referenced by UFO_AddToGeoscape().

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().

static int UFO_IsTargetOfBase ( const aircraft_t ufo,
const base_t base 
)
static

Check if a UFO is the target of a base.

Parameters
[in]ufoThe UFO to check
[in]basePointer to the base
Returns
0 if ufo is not a target, 1 if target of a missile, 2 if target of a laser

Definition at line 309 of file cp_ufo.cpp.

References base_s::batteries, i, base_s::lasers, base_s::numBatteries, base_s::numLasers, baseWeapon_s::target, UFO_IS_NO_TARGET, UFO_IS_TARGET_OF_LASER, and UFO_IS_TARGET_OF_MISSILE.

Referenced by UFO_UpdateAlienInterestForOneBase().

static int UFO_IsTargetOfInstallation ( const aircraft_t ufo,
const installation_t installation 
)
static

Check if a UFO is the target of an installation.

Parameters
[in]ufoThe UFO to check
[in]installationPointer to the installation
Returns
UFO_IS_NO_TARGET if ufo is not a target, UFO_IS_TARGET_OF_MISSILE if target of a missile

Definition at line 332 of file cp_ufo.cpp.

References installation_s::batteries, i, installation_s::numBatteries, baseWeapon_s::target, UFO_IS_NO_TARGET, and UFO_IS_TARGET_OF_MISSILE.

Referenced by UFO_UpdateAlienInterestForOneInstallation().

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().

static void UFO_SearchAircraftTarget ( const campaign_t campaign,
aircraft_t ufo,
float  maxDetectionRange = MAX_DETECTING_RANGE 
)
static
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().

static void UFO_SetRandomPos ( aircraft_t ufocraft)
static

Give a random position to the given UFO.

Parameters
[in]ufocraftPointer to the UFO which position will be changed.
See also
UFO_SetRandomDest

Definition at line 294 of file cp_ufo.cpp.

References CP_GetRandomPosOnGeoscape(), aircraft_s::pos, and Vector2Copy.

Referenced by UFO_AddToGeoscape().

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().

static void UFO_UpdateAlienInterestForOneBase ( const aircraft_t ufo,
base_t base 
)
static

Update alien interest for one PHALANX base.

Parameters
[in]ufoPointer to the aircraft_t
[in]basePointer to the base
Note
This function will be called quite often (every DETECTION_INTERVAL), so it must stay simple. it must not depend on dt , otherwise alien interest will depend on time scale.
this function will only be used to determine WHICH base will be attacked, and not IF a base will be attacked.
See also
UFO_UpdateAlienInterestForAllBases
AB_UpdateStealthForOneBase

< above this distance, probability to detect base will decrease by decreasingFactor

Definition at line 353 of file cp_ufo.cpp.

References base_s::alienInterest, DETECTION_INTERVAL, GetDistanceOnGlobe(), MAX_DETECTING_RANGE, base_s::pos, aircraft_s::pos, UFO_IS_TARGET_OF_LASER, UFO_IS_TARGET_OF_MISSILE, and UFO_IsTargetOfBase().

Referenced by UFO_UpdateAlienInterestForAllBasesAndInstallations().

static void UFO_UpdateAlienInterestForOneInstallation ( const aircraft_t ufo,
installation_t installation 
)
static

Update alien interest for one PHALANX installation (radar tower, SAM, ...)

Parameters
[in]ufoPointer to the aircraft_t
[in]installationPointer to the installation
See also
UFO_UpdateAlienInterestForOneBase

< above this distance, probability to detect base will decrease by decreasingFactor

Definition at line 395 of file cp_ufo.cpp.

References installation_s::alienInterest, DETECTION_INTERVAL, GetDistanceOnGlobe(), MAX_DETECTING_RANGE, installation_s::pos, aircraft_s::pos, UFO_IS_TARGET_OF_LASER, UFO_IS_TARGET_OF_MISSILE, and UFO_IsTargetOfInstallation().

Referenced by UFO_UpdateAlienInterestForAllBasesAndInstallations().

Variable Documentation

const float MAX_DETECTING_RANGE = 25.0f
static

range to detect and fire at phalanx aircraft

Definition at line 34 of file cp_ufo.cpp.

Referenced by UFO_UpdateAlienInterestForOneBase(), and UFO_UpdateAlienInterestForOneInstallation().

const cmdList_t ufoDebugCallbacks[]
static
Initial value:
= {
{nullptr, nullptr, nullptr}
}

Definition at line 999 of file cp_ufo.cpp.