naev 0.12.6
pilot_weapon.c File Reference

Handles pilot weapon sets which server to manage and interface with active outfits.. More...

#include "array.h"
#include "escort.h"
#include "log.h"
#include "nlua_pilotoutfit.h"
#include "pilot.h"
#include "player.h"
#include "sound.h"
#include "spfx.h"
#include "weapon.h"
Include dependency graph for pilot_weapon.c:

Go to the source code of this file.

Functions

static void pilot_weapSetUpdateOutfits (Pilot *p, PilotWeaponSet *ws)
 Updates the outfits with their current weapon set level.
static int pilot_shootWeaponSetOutfit (Pilot *p, const Outfit *o, const Target *target, double time, int aim)
 Calculates and shoots the appropriate weapons in a weapon set matching an outfit.
static void pilot_weapSetUpdateRange (const Pilot *p, PilotWeaponSet *ws)
 Updates the weapon range for a pilot weapon set.
PilotWeaponSetpilot_weapSet (Pilot *p, int id)
 Gets a weapon set from id.
void pilot_weapSetAIClear (Pilot *p)
 Useful function for AI, clears activeness of all weapon sets.
static int pilot_weapSetPressToggle (Pilot *p, PilotWeaponSet *ws)
int pilot_weapSetPress (Pilot *p, int id, int type)
 Handles a weapon set press.
void pilot_weapSetUpdateOutfitState (Pilot *p)
 Updates the local state of all the pilot's outfits based on the weapon sets.
void pilot_weapSetUpdate (Pilot *p)
 Updates the pilot's weapon sets.
int pilot_weapSetTypeCheck (Pilot *p, int id)
 Checks the current weapon set type.
void pilot_weapSetType (Pilot *p, int id, WeaponSetType type)
 Changes the weapon sets mode.
int pilot_weapSetInrangeCheck (Pilot *p, int id)
 Checks the current weapon set inrange property.
void pilot_weapSetInrange (Pilot *p, int id, int inrange)
 Changes the weapon set inrange property.
int pilot_weapSetManualCheck (Pilot *p, int id)
 Checks the current weapon set manual property.
void pilot_weapSetManual (Pilot *p, int id, int manual)
 Changes the weapon set manual property.
int pilot_weapSetVolleyCheck (Pilot *p, int id)
 Checks the current weapon set volley property.
void pilot_weapSetVolley (Pilot *p, int id, int volley)
 Changes the weapon set volley property.
const char * pilot_weapSetName (Pilot *p, int id)
 Gets the name of a weapon set.
void pilot_weapSetAdd (Pilot *p, int id, const PilotOutfitSlot *o)
 Adds an outfit to a weapon set.
void pilot_weapSetRm (Pilot *p, int id, const PilotOutfitSlot *o)
 Removes a slot from a weapon set.
void pilot_weapSetClear (Pilot *p, int id)
 Clears a weapon set.
int pilot_weapSetInSet (Pilot *p, int id, const PilotOutfitSlot *o)
 Checks to see if a slot is in a weapon set.
int pilot_weapSetCheck (Pilot *p, int id, const PilotOutfitSlot *o)
 Checks to see if a slot is in a weapon set and usable.
void pilot_weapSetUpdateStats (Pilot *p)
 Update the weapon sets given pilot stat changes.
double pilot_weapSetRangeMin (Pilot *p, int id)
 Gets the minimum range of the current pilot weapon set.
double pilot_weapSetRange (Pilot *p, int id)
 Gets the range of the current pilot weapon set.
double pilot_weapSetSpeed (Pilot *p, int id)
 Gets the speed of the current pilot weapon set.
double pilot_weapSetAmmo (Pilot *p, int id)
 Gets the ammo of the current pilot weapon set.
void pilot_weapSetCleanup (Pilot *p, int id)
 Cleans up a weapon set.
void pilot_weapSetFree (Pilot *p)
 Frees a pilot's weapon sets.
PilotWeaponSetOutfitpilot_weapSetList (Pilot *p, int id)
 Lists the items in a pilot weapon set.
void pilot_stopBeam (const Pilot *p, PilotOutfitSlot *w)
 Stops a beam outfit and sets delay as appropriate.
double pilot_weapFlyTime (const Outfit *o, const Pilot *parent, const vec2 *pos, const vec2 *vel)
 Computes an estimation of ammo flying time.
Pilotpilot_weaponTarget (Pilot *p, Target *wt)
 Gets the weapon target of a pilot.
int pilot_shootWeapon (Pilot *p, PilotOutfitSlot *w, const Target *target, double time, int aim)
 Actually handles the shooting, how often the player.p can shoot and such.
void pilot_getRateMod (double *rate_mod, double *energy_mod, const Pilot *p, const Outfit *o)
 Gets applicable fire rate and energy modifications for a pilot's weapon.
void pilot_weaponClear (Pilot *p)
 Clears the pilots weapon settings.
void pilot_weaponAuto (Pilot *p)
 Tries to automatically set and create the pilot's weapon set.
void pilot_weaponSafe (Pilot *p)
 Sets the weapon set as safe.
int pilot_outfitOff (Pilot *p, PilotOutfitSlot *o, int natural)
 Disables a given active outfit.
int pilot_outfitOn (Pilot *p, PilotOutfitSlot *pos)
 Enable a given active outfit.
int pilot_outfitOffAll (Pilot *p)
 Disables all active outfits for a pilot.
int pilot_outfitOffAllStealth (Pilot *p)
 Disables all active outfits for a pilot.
int pilot_afterburn (Pilot *p)
 Activate the afterburner.
void pilot_afterburnOver (Pilot *p)
 Deactivates the afterburner.
void ws_copy (PilotWeaponSet dest[PILOT_WEAPON_SETS], const PilotWeaponSet src[PILOT_WEAPON_SETS])
 Copies a weapon set over.
void ws_free (PilotWeaponSet ws[PILOT_WEAPON_SETS])
 Frees a weapon set.

Detailed Description

Handles pilot weapon sets which server to manage and interface with active outfits..

The basic approach is a flag and sweep operation. Outfits are flagged based on what weapon sets they belong to when weapon sets change or weapons are fired. Afterwards, the weapons will be updated every iteration to fire or change states as necessary.

Definition in file pilot_weapon.c.

Function Documentation

◆ pilot_afterburn()

int pilot_afterburn ( Pilot * p)

Activate the afterburner.

Todo
fancy effect?

Definition at line 1622 of file pilot_weapon.c.

◆ pilot_afterburnOver()

void pilot_afterburnOver ( Pilot * p)

Deactivates the afterburner.

Definition at line 1680 of file pilot_weapon.c.

◆ pilot_getRateMod()

void pilot_getRateMod ( double * rate_mod,
double * energy_mod,
const Pilot * p,
const Outfit * o )

Gets applicable fire rate and energy modifications for a pilot's weapon.

Parameters
[out]rate_modFire rate multiplier.
[out]energy_modEnergy use multiplier.
pPilot who owns the outfit.
oPilot's outfit.

Definition at line 1283 of file pilot_weapon.c.

◆ pilot_outfitOff()

int pilot_outfitOff ( Pilot * p,
PilotOutfitSlot * o,
int natural )

Disables a given active outfit.

Parameters
pPilot whose outfit we are disabling.
oOutfit to disable.
naturalWhether a result of natural behaviour, or something automatic.
Returns
Whether the outfit was actually disabled.

Definition at line 1499 of file pilot_weapon.c.

◆ pilot_outfitOffAll()

int pilot_outfitOffAll ( Pilot * p)

Disables all active outfits for a pilot.

Parameters
pPilot whose outfits we are disabling.
Returns
Whether any outfits were actually disabled.

Definition at line 1583 of file pilot_weapon.c.

◆ pilot_outfitOffAllStealth()

int pilot_outfitOffAllStealth ( Pilot * p)

Disables all active outfits for a pilot.

Parameters
pPilot whose outfits we are disabling.
Returns
Whether any outfits were actually disabled.

Definition at line 1603 of file pilot_weapon.c.

◆ pilot_outfitOn()

int pilot_outfitOn ( Pilot * p,
PilotOutfitSlot * pos )

Enable a given active outfit.

Parameters
pPilot whose outfit we are enabling.
posOutfit to enable.
Returns
Whether the outfit was actually enabled.

Definition at line 1555 of file pilot_weapon.c.

◆ pilot_shootWeapon()

int pilot_shootWeapon ( Pilot * p,
PilotOutfitSlot * w,
const Target * target,
double time,
int aim )

Actually handles the shooting, how often the player.p can shoot and such.

Parameters
pPilot that is shooting.
wPilot's outfit to shoot.
targetTarget shooting at.
timeExpected flight time.
aimWhether or not to aim, if negative, indicates that it is automatically shot.
Returns
0 if nothing was shot and 1 if something was shot.
Todo
Handle warmup stage.

Definition at line 1103 of file pilot_weapon.c.

◆ pilot_shootWeaponSetOutfit()

int pilot_shootWeaponSetOutfit ( Pilot * p,
const Outfit * o,
const Target * target,
double time,
int aim )
static

Calculates and shoots the appropriate weapons in a weapon set matching an outfit.

Definition at line 1023 of file pilot_weapon.c.

◆ pilot_stopBeam()

void pilot_stopBeam ( const Pilot * p,
PilotOutfitSlot * w )

Stops a beam outfit and sets delay as appropriate.

Parameters
pPilot that is firing.
wPilot's beam outfit.

Definition at line 876 of file pilot_weapon.c.

◆ pilot_weapFlyTime()

double pilot_weapFlyTime ( const Outfit * o,
const Pilot * parent,
const vec2 * pos,
const vec2 * vel )

Computes an estimation of ammo flying time.

Parameters
othe weapon to shoot.
parentParent of the weapon.
posTarget's position.
velTarget's velocity.

Definition at line 920 of file pilot_weapon.c.

◆ pilot_weaponAuto()

void pilot_weaponAuto ( Pilot * p)

Tries to automatically set and create the pilot's weapon set.

Weapon set 0 is for all weapons.
Weapon set 1 is for forward weapons. Ammo using weapons are secondaries.
Weapon set 2 is for turret weapons. Ammo using weapons are secondaries.
Weapon set 3 is for all weapons. Forwards are primaries and turrets are secondaries.
Weapon set 4 is for seeking weapons. High payload variants are secondaries.
Weapon set 5 is for fighter bays.

Parameters
pPilot to automagically generate weapon lists.

Definition at line 1345 of file pilot_weapon.c.

◆ pilot_weaponClear()

void pilot_weaponClear ( Pilot * p)

Clears the pilots weapon settings.

Parameters
pPilot whose weapons we're clearing.

Definition at line 1324 of file pilot_weapon.c.

◆ pilot_weaponSafe()

void pilot_weaponSafe ( Pilot * p)

Sets the weapon set as safe.

Parameters
pPilot to set weapons as safe.

Definition at line 1481 of file pilot_weapon.c.

◆ pilot_weaponTarget()

Pilot * pilot_weaponTarget ( Pilot * p,
Target * wt )

Gets the weapon target of a pilot.

Parameters
pPilot to get weapon targot of.
[out]wtWeapon target structure set up.
Returns
The pilot pointer if applicable.

Definition at line 1002 of file pilot_weapon.c.

◆ pilot_weapSet()

PilotWeaponSet * pilot_weapSet ( Pilot * p,
int id )

Gets a weapon set from id.

Parameters
pPilot to get weapon set from.
idID of the weapon set.
Returns
The weapon set matching id.

Definition at line 46 of file pilot_weapon.c.

◆ pilot_weapSetAdd()

void pilot_weapSetAdd ( Pilot * p,
int id,
const PilotOutfitSlot * o )

Adds an outfit to a weapon set.

Parameters
pPilot to manipulate.
idID of the weapon set.
oOutfit to add.

Definition at line 598 of file pilot_weapon.c.

◆ pilot_weapSetAIClear()

void pilot_weapSetAIClear ( Pilot * p)

Useful function for AI, clears activeness of all weapon sets.

Definition at line 54 of file pilot_weapon.c.

◆ pilot_weapSetAmmo()

double pilot_weapSetAmmo ( Pilot * p,
int id )

Gets the ammo of the current pilot weapon set.

Parameters
pPilot to get the speed of.
idID of weapon set to get the speed of.

Definition at line 815 of file pilot_weapon.c.

◆ pilot_weapSetCheck()

int pilot_weapSetCheck ( Pilot * p,
int id,
const PilotOutfitSlot * o )

Checks to see if a slot is in a weapon set and usable.

Parameters
pPilot to check.
idID of the weapon set.
oOutfit slot to check.
Returns
The level to which it belongs (or -1 if it isn't set).

Definition at line 686 of file pilot_weapon.c.

◆ pilot_weapSetCleanup()

void pilot_weapSetCleanup ( Pilot * p,
int id )

Cleans up a weapon set.

Parameters
pPilot who owns the weapon set.
idID of the weapon set to clean up.

Definition at line 838 of file pilot_weapon.c.

◆ pilot_weapSetClear()

void pilot_weapSetClear ( Pilot * p,
int id )

Clears a weapon set.

Parameters
pPilot to clear weapon set.
idWeapon set to clear.

Definition at line 650 of file pilot_weapon.c.

◆ pilot_weapSetFree()

void pilot_weapSetFree ( Pilot * p)

Frees a pilot's weapon sets.

Definition at line 852 of file pilot_weapon.c.

◆ pilot_weapSetInrange()

void pilot_weapSetInrange ( Pilot * p,
int id,
int inrange )

Changes the weapon set inrange property.

Parameters
pPilot to manipulate.
idID of the weapon set.
inrangeWhether or not to only fire at stuff in range.

Definition at line 451 of file pilot_weapon.c.

◆ pilot_weapSetInrangeCheck()

int pilot_weapSetInrangeCheck ( Pilot * p,
int id )

Checks the current weapon set inrange property.

Parameters
pPilot to manipulate.
idID of the weapon set to check.
Returns
The inrange mode of the weapon set.

Definition at line 438 of file pilot_weapon.c.

◆ pilot_weapSetInSet()

int pilot_weapSetInSet ( Pilot * p,
int id,
const PilotOutfitSlot * o )

Checks to see if a slot is in a weapon set.

Definition at line 665 of file pilot_weapon.c.

◆ pilot_weapSetList()

PilotWeaponSetOutfit * pilot_weapSetList ( Pilot * p,
int id )

Lists the items in a pilot weapon set.

Parameters
pPilot who owns the weapon set.
idID of the weapon set.
Returns
The array (array.h) of pilot weaponset outfits.

Definition at line 865 of file pilot_weapon.c.

◆ pilot_weapSetManual()

void pilot_weapSetManual ( Pilot * p,
int id,
int manual )

Changes the weapon set manual property.

Parameters
pPilot to manipulate.
idID of the weapon set.
manualWhether or not to have manual aiming.

Definition at line 478 of file pilot_weapon.c.

◆ pilot_weapSetManualCheck()

int pilot_weapSetManualCheck ( Pilot * p,
int id )

Checks the current weapon set manual property.

Parameters
pPilot to manipulate.
idID of the weapon set to check.
Returns
The manual mode of the weapon set.

Definition at line 465 of file pilot_weapon.c.

◆ pilot_weapSetName()

const char * pilot_weapSetName ( Pilot * p,
int id )

Gets the name of a weapon set.

Definition at line 515 of file pilot_weapon.c.

◆ pilot_weapSetPress()

int pilot_weapSetPress ( Pilot * p,
int id,
int type )

Handles a weapon set press.

Parameters
pPilot the weapon set belongs to.
idID of the weapon set.
typeIs +1 if it's a press or -1 if it's a release.
Returns
Whether or not something changed.

Definition at line 101 of file pilot_weapon.c.

◆ pilot_weapSetPressToggle()

int pilot_weapSetPressToggle ( Pilot * p,
PilotWeaponSet * ws )
static

Definition at line 62 of file pilot_weapon.c.

◆ pilot_weapSetRange()

double pilot_weapSetRange ( Pilot * p,
int id )

Gets the range of the current pilot weapon set.

Parameters
pPilot to get the range of.
idID of weapon set to get the range of.

Definition at line 791 of file pilot_weapon.c.

◆ pilot_weapSetRangeMin()

double pilot_weapSetRangeMin ( Pilot * p,
int id )

Gets the minimum range of the current pilot weapon set.

Parameters
pPilot to get the minimum range of.
idID of weapon set to get the minimun range of.

Definition at line 779 of file pilot_weapon.c.

◆ pilot_weapSetRm()

void pilot_weapSetRm ( Pilot * p,
int id,
const PilotOutfitSlot * o )

Removes a slot from a weapon set.

Parameters
pPilot who owns the weapon set.
idID of the weapon set.
oOutfit to remove.

Definition at line 631 of file pilot_weapon.c.

◆ pilot_weapSetSpeed()

double pilot_weapSetSpeed ( Pilot * p,
int id )

Gets the speed of the current pilot weapon set.

Parameters
pPilot to get the speed of.
idID of weapon set to get the speed of.

Definition at line 803 of file pilot_weapon.c.

◆ pilot_weapSetType()

void pilot_weapSetType ( Pilot * p,
int id,
WeaponSetType type )

Changes the weapon sets mode.

Parameters
pPilot to manipulate.
idID of the weapon set.
typeThe mode (a WEAPSET_TYPE constant).

Definition at line 422 of file pilot_weapon.c.

◆ pilot_weapSetTypeCheck()

int pilot_weapSetTypeCheck ( Pilot * p,
int id )

Checks the current weapon set type.

Parameters
pPilot to manipulate.
idID of the weapon set to check.
Returns
The type of the weapon set.

Definition at line 409 of file pilot_weapon.c.

◆ pilot_weapSetUpdate()

void pilot_weapSetUpdate ( Pilot * p)

Updates the pilot's weapon sets.

Parameters
pPilot to update.

Definition at line 267 of file pilot_weapon.c.

◆ pilot_weapSetUpdateOutfits()

void pilot_weapSetUpdateOutfits ( Pilot * p,
PilotWeaponSet * ws )
static

Updates the outfits with their current weapon set level.

Definition at line 384 of file pilot_weapon.c.

◆ pilot_weapSetUpdateOutfitState()

void pilot_weapSetUpdateOutfitState ( Pilot * p)

Updates the local state of all the pilot's outfits based on the weapon sets.

Definition at line 172 of file pilot_weapon.c.

◆ pilot_weapSetUpdateRange()

void pilot_weapSetUpdateRange ( const Pilot * p,
PilotWeaponSet * ws )
static

Updates the weapon range for a pilot weapon set.

Parameters
pPilot whos weapon set is being updated.
wsWeapon Set to update range for.

Definition at line 716 of file pilot_weapon.c.

◆ pilot_weapSetUpdateStats()

void pilot_weapSetUpdateStats ( Pilot * p)

Update the weapon sets given pilot stat changes.

Parameters
pPilot to update.

Definition at line 704 of file pilot_weapon.c.

◆ pilot_weapSetVolley()

void pilot_weapSetVolley ( Pilot * p,
int id,
int volley )

Changes the weapon set volley property.

Parameters
pPilot to manipulate.
idID of the weapon set.
volleyWhether or not to have volley aiming.

Definition at line 505 of file pilot_weapon.c.

◆ pilot_weapSetVolleyCheck()

int pilot_weapSetVolleyCheck ( Pilot * p,
int id )

Checks the current weapon set volley property.

Parameters
pPilot to manipulate.
idID of the weapon set to check.
Returns
The volley mode of the weapon set.

Definition at line 492 of file pilot_weapon.c.

◆ ws_copy()

void ws_copy ( PilotWeaponSet dest[PILOT_WEAPON_SETS],
const PilotWeaponSet src[PILOT_WEAPON_SETS] )

Copies a weapon set over.

Definition at line 1702 of file pilot_weapon.c.

◆ ws_free()

void ws_free ( PilotWeaponSet ws[PILOT_WEAPON_SETS])

Frees a weapon set.

Definition at line 1714 of file pilot_weapon.c.