UFO: Alien Invasion
Loading...
Searching...
No Matches
cp_radar.cpp File Reference

Radars / sensor stuff, to detect and track ufos. More...

#include "../../cl_shared.h"
#include "cp_campaign.h"
#include "cp_overlay.h"
#include "cp_geoscape.h"
#include "cp_ufo.h"
#include "cp_missions.h"
Include dependency graph for cp_radar.cpp:

Go to the source code of this file.

Functions

void RADAR_UpdateStaticRadarCoverage (void)
 Update every static radar drawing (radar that don't move: base and installation radar).
static void RADAR_DrawCoverage (const radar_t *radar, const vec2_t pos)
 Update map radar coverage with moving radar.
void RADAR_UpdateWholeRadarOverlay (void)
 Update radar overlay of base, installation and aircraft range.
void RADAR_DeactivateRadarOverlay (void)
 Deactivate Radar overlay if there is no more UFO on geoscape.
static bool RADAR_IsUFOSensored (const radar_t *radar, const aircraft_t *ufo)
 Check if UFO is in the sensored list.
static bool RADAR_AddUFO (radar_t *radar, const aircraft_t *ufo)
 Add a UFO in the list of sensored UFOs.
static void RADAR_RemoveUFO (radar_t *radar, const aircraft_t *ufo)
 UFO will no more be referenced by radar.
static void RADAR_NotifyUFORemovedFromOneRadar (radar_t *radar, const aircraft_t *ufo, bool destroyed)
 Notify that the specified ufo has been removed from geoscape to one radar.
void RADAR_NotifyUFORemoved (const aircraft_t *ufo, bool destroyed)
 Notify to every radar that the specified ufo has been removed from geoscape.
void RADAR_Initialise (radar_t *radar, float range, float trackingRange, float level, bool updateSourceRadarMap)
 Set radar range to new value.
void RADAR_InitialiseUFOs (radar_t *radar)
 Reset UFO sensored on radar.
void RADAR_UpdateBaseRadarCoverage_f (void)
 Update radar coverage when building/destroying new radar.
void RADAR_UpdateInstallationRadarCoverage (installation_t *installation, const float radarRange, const float trackingRadarRange)
 Update radar coverage when building/destroying new radar.
void RADAR_AddDetectedUFOToEveryRadar (const aircraft_t *ufo)
 Adds detected UFO to any radar in range (if not already detected).
bool RADAR_CheckRadarSensored (const vec2_t pos)
 Check if the specified position is within base radar range.
bool RADAR_CheckUFOSensored (radar_t *radar, const vec2_t posRadar, const aircraft_t *ufo, bool detected)
 Check if the specified UFO is inside the sensor range of the given radar.
void RADAR_SetRadarAfterLoading (void)
 Set radar to proper values after loading.

Variables

bool radarOverlayWasSet
const float RADAR_BASERANGE = 24.0f
const float RADAR_BASETRACKINGRANGE = 34.0f
const float RADAR_INSTALLATIONLEVEL = 1.0f
static const float RADAR_UPGRADE_MULTIPLIER = 0.4f
 this is the multiplier applied to the radar range when the radar levels up

Detailed Description

Radars / sensor stuff, to detect and track ufos.

Definition in file cp_radar.cpp.

Function Documentation

◆ RADAR_AddDetectedUFOToEveryRadar()

void RADAR_AddDetectedUFOToEveryRadar ( const aircraft_t * ufo)

Adds detected UFO to any radar in range (if not already detected).

Parameters
[in]ufoPointer to the UFO to check.

Definition at line 333 of file cp_radar.cpp.

References AIR_Foreach, AIR_IsAircraftOnGeoscape(), B_GetNext(), GetDistanceOnGlobe(), INS_Foreach, aircraft_t::pos, base_t::pos, base_t::radar, radar, RADAR_AddUFO(), and RADAR_IsUFOSensored().

Referenced by AIRFIGHT_ExecuteActions(), RADAR_CheckUFOSensored(), and RADAR_SetRadarAfterLoading().

◆ RADAR_AddUFO()

bool RADAR_AddUFO ( radar_t * radar,
const aircraft_t * ufo )
static

Add a UFO in the list of sensored UFOs.

Definition at line 150 of file cp_radar.cpp.

References cgi, MAX_UFOONGEOSCAPE, radar, and RADAR_IsUFOSensored().

Referenced by RADAR_AddDetectedUFOToEveryRadar(), and RADAR_CheckUFOSensored().

◆ RADAR_CheckRadarSensored()

bool RADAR_CheckRadarSensored ( const vec2_t pos)

Check if the specified position is within base radar range.

Note
aircraft radars are not checked (and this is intended)
Returns
true if the position is inside one of the base radar range

Definition at line 377 of file cp_radar.cpp.

References B_GetNext(), GetDistanceOnGlobe(), INS_Foreach, base_t::pos, and radar.

Referenced by AIRFIGHT_ExecuteActions(), CP_CheckMissionVisibleOnGeoscape(), and CP_UFORemoveFromGeoscape().

◆ RADAR_CheckUFOSensored()

bool RADAR_CheckUFOSensored ( radar_t * radar,
const vec2_t posRadar,
const aircraft_t * ufo,
bool detected )

Check if the specified UFO is inside the sensor range of the given radar.

Parameters
[in,out]radarradar that may detect the UFO.
[in]posRadarPosition of radar
[in,out]ufoaircraft that should be checked.
[in]detectedIs the UFO already detected by another radar? (Beware: this is not the same as ufo->detected)
Returns
true if the aircraft is inside sensor and was sensored
See also
UFO_CampaignCheckEvents
CP_CheckNewMissionDetectedOnGeoscape

Definition at line 408 of file cp_radar.cpp.

References frand(), GetDistanceOnGlobe(), aircraft_t::pos, radar, RADAR_AddDetectedUFOToEveryRadar(), RADAR_AddUFO(), RADAR_IsUFOSensored(), and RADAR_RemoveUFO().

Referenced by TEST_F(), and UFO_CampaignCheckEvents().

◆ RADAR_DeactivateRadarOverlay()

void RADAR_DeactivateRadarOverlay ( void )

Deactivate Radar overlay if there is no more UFO on geoscape.

Todo
Is aircraft->radar cleared for crashed aircraft?

Definition at line 106 of file cp_radar.cpp.

References AIR_Foreach, B_GetNext(), GEO_IsRadarOverlayActivated(), GEO_SetOverlay(), INS_Foreach, base_t::radar, and radarOverlayWasSet.

Referenced by RADAR_NotifyUFORemovedFromOneRadar(), RADAR_RemoveUFO(), and UFO_CampaignCheckEvents().

◆ RADAR_DrawCoverage()

void RADAR_DrawCoverage ( const radar_t * radar,
const vec2_t pos )
inlinestatic

Update map radar coverage with moving radar.

See also
RADAR_UpdateWholeRadarOverlay

Definition at line 80 of file cp_radar.cpp.

References CP_AddRadarCoverage(), and radar.

Referenced by RADAR_UpdateWholeRadarOverlay().

◆ RADAR_Initialise()

void RADAR_Initialise ( radar_t * radar,
float range,
float trackingRange,
float level,
bool updateSourceRadarMap )

Set radar range to new value.

Parameters
[in,out]radarThe radar to update/initialize
[in]rangeNew range of the radar
[in]trackingRangeNew tracking range of the radar
[in]levelThe tech level of the radar
[in]updateSourceRadarMapif the radar overlay should be updated.

Definition at line 239 of file cp_radar.cpp.

References DETECTION_INTERVAL, EQUAL, level, radar, RADAR_UpdateStaticRadarCoverage(), RADAR_UpdateWholeRadarOverlay(), and RADAR_UPGRADE_MULTIPLIER.

Referenced by AIR_LoadAircraftXML(), AIR_NewAircraft(), B_Build(), B_LoadXML(), INS_Build(), INS_LoadXML(), RADAR_UpdateBaseRadarCoverage_f(), and RADAR_UpdateInstallationRadarCoverage().

◆ RADAR_InitialiseUFOs()

void RADAR_InitialiseUFOs ( radar_t * radar)

Reset UFO sensored on radar.

Parameters
[out]radarThe radar to initialize.

Definition at line 265 of file cp_radar.cpp.

References OBJZERO, and radar.

Referenced by AIR_LoadAircraftXML(), AIR_ParseAircraft(), B_AircraftReturnedToHomeBase(), B_Build(), B_LoadXML(), and INS_LoadXML().

◆ RADAR_IsUFOSensored()

bool RADAR_IsUFOSensored ( const radar_t * radar,
const aircraft_t * ufo )
static

Check if UFO is in the sensored list.

Definition at line 138 of file cp_radar.cpp.

References i, and radar.

Referenced by RADAR_AddDetectedUFOToEveryRadar(), RADAR_AddUFO(), and RADAR_CheckUFOSensored().

◆ RADAR_NotifyUFORemoved()

void RADAR_NotifyUFORemoved ( const aircraft_t * ufo,
bool destroyed )

Notify to every radar that the specified ufo has been removed from geoscape.

Parameters
[in]ufoPointer to UFO to remove.
[in]destroyedTrue if the UFO has been destroyed, false if it's only landed.

Definition at line 213 of file cp_radar.cpp.

References AIR_ForeachFromBase, B_GetNext(), INS_Foreach, INSTALLATION_WORKING, base_t::radar, and RADAR_NotifyUFORemovedFromOneRadar().

Referenced by CP_UFORemoveFromGeoscape().

◆ RADAR_NotifyUFORemovedFromOneRadar()

void RADAR_NotifyUFORemovedFromOneRadar ( radar_t * radar,
const aircraft_t * ufo,
bool destroyed )
static

Notify that the specified ufo has been removed from geoscape to one radar.

Parameters
[in]radarPointer to the radar where ufo should be removed.
[in]ufoPointer to UFO to remove.
[in]destroyedTrue if the UFO has been destroyed, false if it's been only set invisible (landed)

Definition at line 195 of file cp_radar.cpp.

References i, radar, and RADAR_DeactivateRadarOverlay().

Referenced by RADAR_NotifyUFORemoved().

◆ RADAR_RemoveUFO()

void RADAR_RemoveUFO ( radar_t * radar,
const aircraft_t * ufo )
static

UFO will no more be referenced by radar.

Definition at line 171 of file cp_radar.cpp.

References i, MAX_UFOONGEOSCAPE, radar, RADAR_DeactivateRadarOverlay(), and REMOVE_ELEM.

Referenced by RADAR_CheckUFOSensored().

◆ RADAR_SetRadarAfterLoading()

void RADAR_SetRadarAfterLoading ( void )

Set radar to proper values after loading.

Note
numUFOs is not saved, so we must calculate it.
should be called after loading.

Definition at line 453 of file cp_radar.cpp.

References aircraft_t::detected, GEO_UpdateGeoscapeDock(), RADAR_AddDetectedUFOToEveryRadar(), and UFO_GetNext().

Referenced by SAV_GameActionsAfterLoad().

◆ RADAR_UpdateBaseRadarCoverage_f()

void RADAR_UpdateBaseRadarCoverage_f ( void )

Update radar coverage when building/destroying new radar.

Note
This must be called on each radar build/destruction because radar facilities may have different level.
This must also be called when radar installation become inactive or active (due to dependencies)
called with update_base_radar_coverage

Definition at line 277 of file cp_radar.cpp.

References B_GetFoundedBaseByIDX(), B_GetMaxBuildingLevel(), B_RADAR, cgi, CP_UpdateMissionVisibleOnGeoscape(), level, MAX_BASES, base_t::radar, RADAR_BASERANGE, RADAR_BASETRACKINGRANGE, and RADAR_Initialise().

◆ RADAR_UpdateInstallationRadarCoverage()

void RADAR_UpdateInstallationRadarCoverage ( installation_t * installation,
const float radarRange,
const float trackingRadarRange )

Update radar coverage when building/destroying new radar.

Parameters
[in,out]installationThe radartower to update
[in]radarRangeNew range of the radar
[in]trackingRadarRangeNew tracking range of the radar

Definition at line 311 of file cp_radar.cpp.

References cgi, CP_UpdateMissionVisibleOnGeoscape(), ERR_DROP, INSTALLATION_WORKING, installation_t::installationStatus, installation_t::installationTemplate, installation_t::radar, RADAR_Initialise(), RADAR_INSTALLATIONLEVEL, installationTemplate_t::radarRange, and installationTemplate_t::trackingRange.

Referenced by INS_DestroyInstallation(), INS_FinishInstallation(), and INS_LoadXML().

◆ RADAR_UpdateStaticRadarCoverage()

void RADAR_UpdateStaticRadarCoverage ( void )

Update every static radar drawing (radar that don't move: base and installation radar).

Note
This is only called when radar range of bases change.

Definition at line 49 of file cp_radar.cpp.

References B_GetNext(), CP_AddRadarCoverage(), CP_InitializeRadarOverlay(), CP_UploadRadarCoverage(), INS_Foreach, INSTALLATION_WORKING, base_t::pos, and base_t::radar.

Referenced by RADAR_Initialise().

◆ RADAR_UpdateWholeRadarOverlay()

void RADAR_UpdateWholeRadarOverlay ( void )

Update radar overlay of base, installation and aircraft range.

Definition at line 89 of file cp_radar.cpp.

References AIR_Foreach, AIR_IsAircraftOnGeoscape(), CP_InitializeRadarOverlay(), CP_UploadRadarCoverage(), and RADAR_DrawCoverage().

Referenced by AIR_CampaignRun(), AIR_DeleteAircraft(), GEO_SetOverlay(), and RADAR_Initialise().

Variable Documentation

◆ RADAR_BASERANGE

const float RADAR_BASERANGE = 24.0f

Definition at line 39 of file cp_radar.cpp.

Referenced by B_Build(), and RADAR_UpdateBaseRadarCoverage_f().

◆ RADAR_BASETRACKINGRANGE

const float RADAR_BASETRACKINGRANGE = 34.0f

Definition at line 40 of file cp_radar.cpp.

Referenced by B_Build(), and RADAR_UpdateBaseRadarCoverage_f().

◆ RADAR_INSTALLATIONLEVEL

const float RADAR_INSTALLATIONLEVEL = 1.0f

Definition at line 41 of file cp_radar.cpp.

Referenced by RADAR_UpdateInstallationRadarCoverage().

◆ RADAR_UPGRADE_MULTIPLIER

const float RADAR_UPGRADE_MULTIPLIER = 0.4f
static

this is the multiplier applied to the radar range when the radar levels up

Definition at line 43 of file cp_radar.cpp.

Referenced by RADAR_Initialise().

◆ radarOverlayWasSet

bool radarOverlayWasSet

used to store the previous configuration of overlay before radar is automatically turned on (e.g when creating base or when UFO appears)

Definition at line 36 of file cp_radar.cpp.

Referenced by CP_LoadXML(), CP_SaveXML(), GEO_ResetAction(), GEO_SetOverlay_f(), and RADAR_DeactivateRadarOverlay().