cp_airfight.c File Reference

Airfight related stuff. More...

#include "../cl_shared.h"
#include "cp_campaign.h"
#include "cp_mapfightequip.h"
#include "cp_map.h"
#include "cp_ufo.h"
#include "cp_missions.h"
#include "save/save_airfight.h"
Include dependency graph for cp_airfight.c:

Go to the source code of this file.

Functions

static qboolean AIRFIGHT_RemoveProjectile (aircraftProjectile_t *projectile)
 Remove a projectile from ccs.projectiles.
static qboolean AIRFIGHT_AddProjectile (const base_t *attackingBase, const installation_t *attackingInstallation, aircraft_t *attacker, aircraft_t *target, aircraftSlot_t *weaponSlot)
 Add a projectile in ccs.projectiles.
static void AIRFIGHT_MissTarget (aircraftProjectile_t *projectile, qboolean returnToBase)
 Change destination of projectile to an idle point of the map, close to its former target.
int AIRFIGHT_CheckWeapon (const aircraftSlot_t *slot, float distance)
 Check if the selected weapon can shoot.
int AIRFIGHT_ChooseWeapon (const aircraftSlot_t const *slot, int maxSlot, const vec3_t pos, const vec3_t targetPos)
 Choose the weapon an attacking aircraft will use to fire on a target.
static float AIRFIGHT_ProbabilityToHit (const aircraft_t *shooter, const aircraft_t *target, const aircraftSlot_t *slot)
 Calculate the probability to hit the enemy.
void AIRFIGHT_ExecuteActions (aircraft_t *shooter, aircraft_t *target)
 Decide what an attacking aircraft can do.
static void AIRFIGHT_RemoveProjectileAimingAircraft (const aircraft_t *aircraft)
 Set all projectile aiming a given aircraft to an idle destination.
static void AIRFIGHT_UpdateProjectileForDestroyedAircraft (const aircraft_t *aircraft)
 Set all projectile attackingAircraft pointers to NULL.
void AIRFIGHT_ActionsAfterAirfight (aircraft_t *shooter, aircraft_t *aircraft, qboolean phalanxWon)
 Actions to execute when a fight is done.
static qboolean AIRFIGHT_ProjectileReachedTarget (const aircraftProjectile_t *projectile, float movement)
 Check if some projectiles on geoscape reached their destination.
static int AIRFIGHT_GetDamage (const objDef_t *od, const aircraft_t *target)
 Calculates the damage value for the airfight.
static void AIRFIGHT_ProjectileHits (aircraftProjectile_t *projectile)
 Solve the result of one projectile hitting an aircraft.
static void AIRFIGHT_GetNextPointInPathFromVector (const float *movement, const vec2_t originalPoint, const vec3_t orthogonalVector, vec2_t finalPoint)
 Get the next point in the object path based on movement converting the positions from polar coordinates to vector for the calculation and back again to be returned.
static void AIRFIGHT_GetNextPointInPath (const float *movement, const vec2_t originalPoint, const vec2_t targetPoint, float *angle, vec2_t finalPoint, vec3_t orthogonalVector)
 Get the next point in the object path based on movement.
void AIRFIGHT_CampaignRunProjectiles (int dt)
 Update values of projectiles.
static void AIRFIGHT_BaseShoot (const base_t *base, baseWeapon_t *weapons, int maxWeapons)
 Check if one type of battery (missile or laser) can shoot now.
static void AIRFIGHT_InstallationShoot (const installation_t *installation, baseWeapon_t *weapons, int maxWeapons)
 Check if one type of battery (missile or laser) can shoot now.
void AIRFIGHT_CampaignRunBaseDefence (int dt)
 Run base defences.
qboolean AIRFIGHT_SaveXML (mxml_node_t *parent)
 Save callback for savegames in XML Format.
qboolean AIRFIGHT_LoadXML (mxml_node_t *parent)
 Load callback for savegames in XML Format.
void AIRFIGHT_InitStartup (void)

Detailed Description

Airfight related stuff.

Todo:
Somehow i need to know which alien race was in the ufo we shoot down I need this info for spawning the crash site
See also:
CP_CreateBattleParameters

Definition in file cp_airfight.c.


Function Documentation

void AIRFIGHT_ActionsAfterAirfight ( aircraft_t shooter,
aircraft_t aircraft,
qboolean  phalanxWon 
)

Actions to execute when a fight is done.

Parameters:
[in] shooter Pointer to the aircraft that fired the projectile.
[in] aircraft Pointer to the aircraft which was destroyed (alien or phalanx).
[in] phalanxWon qtrue if PHALANX won, qfalse if UFO won.
Note:
Some of these mission values are redone (and not reloaded) in CP_Load
shooter may be NULL
See also:
UFO_DestroyAllUFOsOnGeoscape_f
CP_Load
CP_SpawnCrashSiteMission

Definition at line 409 of file cp_airfight.c.

References _, AIR_DestroyAircraft(), AIRFIGHT_RemoveProjectileAimingAircraft(), AIRFIGHT_UpdateProjectileForDestroyedAircraft(), byte, Com_DPrintf(), CP_MissionIsOverByUFO(), CP_SpawnCrashSiteMission(), CP_SpawnRescueMission(), CP_UFOProceedMission(), DEBUG_CLIENT, MAP_GetColor(), MAP_GetTerrainType(), MapIsWater, MAPTYPE_TERRAIN, MS_AddNewMessage(), MSG_DEATH, MSG_STANDARD, aircraft_s::pos, qfalse, and UFO_NotifyPhalanxAircraftRemoved().

Referenced by AIRFIGHT_ProjectileHits().

static qboolean AIRFIGHT_AddProjectile ( const base_t attackingBase,
const installation_t attackingInstallation,
aircraft_t attacker,
aircraft_t target,
aircraftSlot_t weaponSlot 
) [static]

Add a projectile in ccs.projectiles.

Parameters:
[in] attackingBase the attacking base in ccs.bases[]. NULL is the attacker is an aircraft or a samsite.
[in] attackingInstallation the attacking samsite in ccs.installations[]. NULL is the attacker is an aircraft or a base.
[in] attacker Pointer to the attacking aircraft
[in] target Pointer to the target aircraft
[in] weaponSlot Pointer to the weapon slot that fires the projectile.
Note:
we already checked in AIRFIGHT_ChooseWeapon that the weapon has still ammo
See also:
AIRFIGHT_RemoveProjectile
AII_ReloadWeapon for the aircraft item reload code

Definition at line 59 of file cp_airfight.c.

References AII_ReloadWeapon(), aircraftProjectile_s::aimedAircraft, aircraftProjectile_s::aircraftItem, aircraftSlot_s::ammo, aircraftSlot_s::ammoLeft, aircraftProjectile_s::angle, aircraftProjectile_s::attackerPos, aircraftProjectile_s::attackingAircraft, craftitem_s::beam, aircraftProjectile_s::beam, craftitem_s::bullets, aircraftProjectile_s::bullets, ccs, Com_DPrintf(), Com_Printf(), objDef_s::craftitem, DEBUG_CLIENT, aircraftProjectile_s::idleTarget, aircraftSlot_s::item, MAX_PROJECTILESONGEOSCAPE, aircraftProjectile_s::numProjectiles, ccs_s::numProjectiles, aircraft_s::pos, installation_s::pos, base_s::pos, aircraftProjectile_s::pos, ccs_s::projectiles, qfalse, qtrue, aircraftProjectile_s::time, and VectorSet.

Referenced by AIRFIGHT_BaseShoot(), AIRFIGHT_ExecuteActions(), and AIRFIGHT_InstallationShoot().

static void AIRFIGHT_BaseShoot ( const base_t base,
baseWeapon_t weapons,
int  maxWeapons 
) [static]
void AIRFIGHT_CampaignRunBaseDefence ( int  dt  ) 
void AIRFIGHT_CampaignRunProjectiles ( int  dt  ) 
int AIRFIGHT_CheckWeapon ( const aircraftSlot_t slot,
float  distance 
)

Check if the selected weapon can shoot.

Parameters:
[in] slot Pointer to the weapon slot to shoot with.
[in] distance distance between the weapon and the target.
Returns:
0 AIRFIGHT_WEAPON_CAN_SHOOT if the weapon can shoot, -1 AIRFIGHT_WEAPON_CAN_NOT_SHOOT_AT_THE_MOMENT if it can't shoot atm, -2 AIRFIGHT_WEAPON_CAN_NEVER_SHOOT if it will never be able to shoot.

Definition at line 194 of file cp_airfight.c.

References AIR_STATS_WRANGE, AIRFIGHT_WEAPON_CAN_NEVER_SHOOT, AIRFIGHT_WEAPON_CAN_NOT_SHOOT_AT_THE_MOMENT, AIRFIGHT_WEAPON_CAN_SHOOT, aircraftSlot_s::ammo, aircraftSlot_s::ammoLeft, objDef_s::craftitem, aircraftSlot_s::delayNextShot, aircraftSlot_s::installationTime, aircraftSlot_s::item, and craftitem_s::stats.

Referenced by AII_WeaponsCanShoot(), AIRFIGHT_BaseShoot(), AIRFIGHT_ChooseWeapon(), AIRFIGHT_InstallationShoot(), and BDEF_AutoTarget().

int AIRFIGHT_ChooseWeapon ( const aircraftSlot_t const *  slot,
int  maxSlot,
const vec3_t  pos,
const vec3_t  targetPos 
)

Choose the weapon an attacking aircraft will use to fire on a target.

Parameters:
[in] slot Pointer to the first weapon slot of attacking base or aircraft.
[in] maxSlot maximum number of weapon slots in attacking base or aircraft.
[in] pos position of attacking base or aircraft.
[in] targetPos Pointer to the aimed aircraft.
Returns:
indice of the slot to use (in array weapons[]), -1 AIRFIGHT_WEAPON_CAN_NOT_SHOOT_AT_THE_MOMENT no weapon to use atm, -2 AIRFIGHT_WEAPON_CAN_NEVER_SHOOT if no weapon to use at all.
See also:
AIRFIGHT_CheckWeapon

Definition at line 228 of file cp_airfight.c.

References AIRFIGHT_CheckWeapon(), AIRFIGHT_WEAPON_CAN_NEVER_SHOOT, AIRFIGHT_WEAPON_CAN_NOT_SHOOT_AT_THE_MOMENT, AIRFIGHT_WEAPON_CAN_SHOOT, and GetDistanceOnGlobe().

Referenced by AIRFIGHT_ExecuteActions(), CL_DisplayPopupInterceptUFO(), CP_InterceptNextStage(), CP_UFOProceedMission(), and UFO_SendPursuingAircraft().

void AIRFIGHT_ExecuteActions ( aircraft_t shooter,
aircraft_t target 
)
static int AIRFIGHT_GetDamage ( const objDef_t od,
const aircraft_t target 
) [static]

Calculates the damage value for the airfight.

Parameters:
[in] od The ammo object definition of the craft item
[in] target The aircraft the ammo hits
Returns:
the damage the hit causes
See also:
AII_UpdateAircraftStats
Note:
ECM is handled in AIRFIGHT_ProbabilityToHit

Definition at line 505 of file cp_airfight.c.

References AIR_STATS_SHIELD, objDef_s::craftitem, aircraft_s::damage, aircraft_s::stats, and craftitem_s::weaponDamage.

Referenced by AIRFIGHT_ProjectileHits().

static void AIRFIGHT_GetNextPointInPath ( const float *  movement,
const vec2_t  originalPoint,
const vec2_t  targetPoint,
float *  angle,
vec2_t  finalPoint,
vec3_t  orthogonalVector 
) [static]

Get the next point in the object path based on movement.

Parameters:
[in] movement The distance that the object needs to move.
[in] originalPoint The point from which the object is moving.
[in] targetPoint The final point to which the object is moving.
[out] angle The direction that the object moving in.
[out] finalPoint The next point from the original point + movement in "angle" direction.
[out] orthogonalVector The orthogonal vector.

Definition at line 582 of file cp_airfight.c.

References AIRFIGHT_GetNextPointInPathFromVector(), and MAP_AngleOfPath().

Referenced by AIRFIGHT_CampaignRunProjectiles().

static void AIRFIGHT_GetNextPointInPathFromVector ( const float *  movement,
const vec2_t  originalPoint,
const vec3_t  orthogonalVector,
vec2_t  finalPoint 
) [static]

Get the next point in the object path based on movement converting the positions from polar coordinates to vector for the calculation and back again to be returned.

Parameters:
[in] movement The distance that the object needs to move.
[in] originalPoint The point from which the object is moving.
[in] orthogonalVector The orthogonal vector.
[out] finalPoint The next point from the original point + movement in "angle" direction.

Definition at line 564 of file cp_airfight.c.

References PolarToVec(), RotatePointAroundVector(), and VecToPolar().

Referenced by AIRFIGHT_GetNextPointInPath().

void AIRFIGHT_InitStartup ( void   ) 
See also:
UI_InitStartup

Definition at line 923 of file cp_airfight.c.

References Cmd_AddCommand().

Referenced by CP_InitStartup().

static void AIRFIGHT_InstallationShoot ( const installation_t installation,
baseWeapon_t weapons,
int  maxWeapons 
) [static]
qboolean AIRFIGHT_LoadXML ( mxml_node_t parent  ) 
static void AIRFIGHT_MissTarget ( aircraftProjectile_t projectile,
qboolean  returnToBase 
) [static]

Change destination of projectile to an idle point of the map, close to its former target.

Parameters:
[in] projectile The projectile to update
[in] returnToBase 

Definition at line 145 of file cp_airfight.c.

References aircraftProjectile_s::aimedAircraft, AIR_AircraftReturnToBase(), AIR_IsUFO, aircraftProjectile_s::attackingAircraft, f, frand(), GetDistanceOnGlobe(), aircraft_s::homebase, aircraftProjectile_s::idleTarget, aircraftProjectile_s::pos, aircraft_s::pos, and VectorCopy.

Referenced by AIRFIGHT_BaseShoot(), AIRFIGHT_ExecuteActions(), AIRFIGHT_InstallationShoot(), and AIRFIGHT_RemoveProjectileAimingAircraft().

static float AIRFIGHT_ProbabilityToHit ( const aircraft_t shooter,
const aircraft_t target,
const aircraftSlot_t slot 
) [static]

Calculate the probability to hit the enemy.

Parameters:
[in] shooter Pointer to the attacking aircraft (may be NULL if a base fires the projectile).
[in] target Pointer to the aimed aircraft (may be NULL if a target is a base).
[in] slot Slot containing the weapon firing.
Returns:
Probability to hit the target (0 when you don't have a chance, 1 (or more) when you're sure to hit).
Note:
that modifiers due to electronics, weapons, and shield are already taken into account in AII_UpdateAircraftStats
See also:
AII_UpdateAircraftStats
AIRFIGHT_ExecuteActions
AIRFIGHT_ChooseWeapon
Precondition:
slotIdx must have a weapon installed, with ammo available (see AIRFIGHT_ChooseWeapon)
Todo:
This probability should also depend on the pilot skills, when they will be implemented.

Definition at line 268 of file cp_airfight.c.

References AIR_STATS_ACCURACY, AIR_STATS_ECM, aircraftSlot_s::ammo, Com_DPrintf(), Com_Printf(), objDef_s::craftitem, DEBUG_CLIENT, aircraftSlot_s::item, aircraft_s::stats, and craftitem_s::stats.

Referenced by AIRFIGHT_BaseShoot(), AIRFIGHT_ExecuteActions(), and AIRFIGHT_InstallationShoot().

static void AIRFIGHT_ProjectileHits ( aircraftProjectile_t projectile  )  [static]

Solve the result of one projectile hitting an aircraft.

Parameters:
[in] projectile Pointer to the projectile.
Note:
the target loose (base damage - shield of target) hit points

Definition at line 529 of file cp_airfight.c.

References aircraftProjectile_s::aimedAircraft, AIR_IsAircraftInBase(), AIRCRAFT_UFO, aircraftProjectile_s::aircraftItem, AIRFIGHT_ActionsAfterAirfight(), AIRFIGHT_GetDamage(), aircraftProjectile_s::attackingAircraft, aircraft_s::damage, and aircraft_s::type.

Referenced by AIRFIGHT_CampaignRunProjectiles().

static qboolean AIRFIGHT_ProjectileReachedTarget ( const aircraftProjectile_t projectile,
float  movement 
) [static]

Check if some projectiles on geoscape reached their destination.

Note:
Destination is not necessarily an aircraft, in case the projectile missed its initial target.
Parameters:
[in] projectile Pointer to the projectile
[in] movement distance that the projectile will do up to next draw of geoscape
See also:
AIRFIGHT_CampaignRunProjectiles

Definition at line 471 of file cp_airfight.c.

References aircraftProjectile_s::aimedAircraft, AIR_STATS_WRANGE, aircraftProjectile_s::aircraftItem, objDef_s::craftitem, GetDistanceOnGlobe(), aircraftProjectile_s::idleTarget, aircraft_s::pos, aircraftProjectile_s::pos, qfalse, qtrue, SECONDS_PER_HOUR, craftitem_s::stats, aircraftProjectile_s::time, and craftitem_s::weaponSpeed.

Referenced by AIRFIGHT_CampaignRunProjectiles().

static qboolean AIRFIGHT_RemoveProjectile ( aircraftProjectile_t projectile  )  [static]

Remove a projectile from ccs.projectiles.

Parameters:
[in] projectile The projectile to remove
See also:
AIRFIGHT_AddProjectile

Definition at line 41 of file cp_airfight.c.

References ccs, ccs_s::numProjectiles, ccs_s::projectiles, qtrue, and REMOVE_ELEM_ADJUST_IDX.

Referenced by AIRFIGHT_CampaignRunProjectiles().

static void AIRFIGHT_RemoveProjectileAimingAircraft ( const aircraft_t aircraft  )  [static]

Set all projectile aiming a given aircraft to an idle destination.

Parameters:
[in] aircraft Pointer to the aimed aircraft.
Note:
This function is called when aircraft is destroyed.
See also:
AIRFIGHT_ActionsAfterAirfight

Definition at line 366 of file cp_airfight.c.

References aircraftProjectile_s::aimedAircraft, AIRFIGHT_MissTarget(), ccs, ccs_s::numProjectiles, ccs_s::projectiles, and qtrue.

Referenced by AIRFIGHT_ActionsAfterAirfight().

qboolean AIRFIGHT_SaveXML ( mxml_node_t parent  ) 
static void AIRFIGHT_UpdateProjectileForDestroyedAircraft ( const aircraft_t aircraft  )  [static]

Set all projectile attackingAircraft pointers to NULL.

Parameters:
[in] aircraft Pointer to the destroyed aircraft.
Note:
This function is called when aircraft is destroyed.

Definition at line 385 of file cp_airfight.c.

References aircraftProjectile_s::attackingAircraft, ccs, ccs_s::numProjectiles, and ccs_s::projectiles.

Referenced by AIRFIGHT_ActionsAfterAirfight().


Generated by  doxygen 1.6.2