naev 0.11.5
pilot_weapon.c File Reference

Handles pilot weapon sets. More...

#include "array.h"
#include "escort.h"
#include "log.h"
#include "nxml.h"
#include "nlua_pilot.h"
#include "nlua_pilotoutfit.h"
#include "pilot.h"
#include "player.h"
#include "spfx.h"
#include "weapon.h"

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_weapSetFire (Pilot *p, PilotWeaponSet *ws, int level)
 Fires a weapon set.
 
static int pilot_shootWeaponSetOutfit (Pilot *p, PilotWeaponSet *ws, const Outfit *o, int level, 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.
 
unsigned int pilot_weaponSetShootStop (Pilot *p, PilotWeaponSet *ws, int level)
 Have pilot stop shooting a given weaponset.
 
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.
 
void pilot_weapSetPress (Pilot *p, int id, int type)
 Handles a weapon set press.
 
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, int level)
 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_weapSetRange (Pilot *p, int id, int level)
 Gets the range of the current pilot weapon set.
 
double pilot_weapSetSpeed (Pilot *p, int id, int level)
 Gets the speed of the current pilot weapon set.
 
double pilot_weapSetAmmo (Pilot *p, int id, int level)
 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.
 
int pilot_shoot (Pilot *p, int level)
 Makes the pilot shoot.
 
void pilot_shootStop (Pilot *p, int level)
 Have pilot stop shooting their weapon.
 
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_weaponSetDefault (Pilot *p)
 Gives the pilot a default weapon set.
 
void pilot_weaponSafe (Pilot *p)
 Sets the weapon set as safe.
 
int pilot_outfitOff (Pilot *p, PilotOutfitSlot *o)
 Disables a given active outfit.
 
int pilot_outfitOn (Pilot *p, PilotOutfitSlot *o)
 Enable a given active outfit.
 
int pilot_outfitOffAll (Pilot *p)
 Disables all active outfits for a pilot.
 
void 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.

Cheat sheet: how this works (it's complicated).

KEYPRESS 1) weapSetPress 2) weapSetFire 2.1) Modifications get turned on/off 2.2) Weapons go to shootWeaponSetOutfit

UPDATE 1) weapSetUpdate 2.1) fire set => weapSetFire 2.1.1) Modifications get turned on/off 2.1.2) Weapons go to shootWeaponSetOutfit 2.2) weapsetUpdateOutfits

So to actually modify stuff, chances are you want to go to pilot_weapSetFire.

Definition in file pilot_weapon.c.

Function Documentation

◆ pilot_afterburn()

void pilot_afterburn ( Pilot * p)

Activate the afterburner.

Todo
fancy effect?

Definition at line 1671 of file pilot_weapon.c.

◆ pilot_afterburnOver()

void pilot_afterburnOver ( Pilot * p)

Deactivates the afterburner.

Definition at line 1722 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 1367 of file pilot_weapon.c.

◆ pilot_outfitOff()

int pilot_outfitOff ( Pilot * p,
PilotOutfitSlot * o )

Disables a given active outfit.

Parameters
pPilot whose outfit we are disabling.
oOutfit to disable.
Returns
Whether the outfit was actually disabled.

Definition at line 1577 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 1654 of file pilot_weapon.c.

◆ pilot_outfitOn()

int pilot_outfitOn ( Pilot * p,
PilotOutfitSlot * o )

Enable a given active outfit.

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

Definition at line 1628 of file pilot_weapon.c.

◆ pilot_shoot()

int pilot_shoot ( Pilot * p,
int level )

Makes the pilot shoot.

Parameters
pThe pilot which is shooting.
levelLevel of the shot.
Returns
The number of shots fired.

Definition at line 877 of file pilot_weapon.c.

◆ pilot_shootStop()

void pilot_shootStop ( Pilot * p,
int level )

Have pilot stop shooting their weapon.

Only really deals with beam weapons.

Parameters
pPilot that was shooting.
levelLevel of the shot.

Definition at line 903 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 1189 of file pilot_weapon.c.

◆ pilot_shootWeaponSetOutfit()

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

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

Todo
Make beams not fire all at once.

Definition at line 1095 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 967 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 1008 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 1425 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 1405 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 1557 of file pilot_weapon.c.

◆ pilot_weaponSetDefault()

void pilot_weaponSetDefault ( Pilot * p)

Gives the pilot a default weapon set.

Definition at line 1516 of file pilot_weapon.c.

◆ pilot_weaponSetShootStop()

unsigned int pilot_weaponSetShootStop ( Pilot * p,
PilotWeaponSet * ws,
int level )

Have pilot stop shooting a given weaponset.

Only really deals with beam weapons.

Parameters
pPilot that was shooting.
levelLevel of the shot.
wsWeapon Set to stop shooting
Returns
1 if some outfit has been deactivated

Definition at line 922 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 1074 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 57 of file pilot_weapon.c.

◆ pilot_weapSetAdd()

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

Adds an outfit to a weapon set.

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

Definition at line 576 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 149 of file pilot_weapon.c.

◆ pilot_weapSetAmmo()

double pilot_weapSetAmmo ( Pilot * p,
int id,
int level )

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.
levelLevel of the weapons to get the speed of (-1 for all).

Definition at line 813 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 666 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 631 of file pilot_weapon.c.

◆ pilot_weapSetFire()

static int pilot_weapSetFire ( Pilot * p,
PilotWeaponSet * ws,
int level )
static

Fires a weapon set.

Parameters
pPilot firing weaponsets.
wsWeapon set to fire.
levelLevel of the firing weapon set.
Returns
Number of weapons shot.

Definition at line 70 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 428 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 415 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 645 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 454 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 441 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 489 of file pilot_weapon.c.

◆ pilot_weapSetPress()

void 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.

Definition at line 164 of file pilot_weapon.c.

◆ pilot_weapSetRange()

double pilot_weapSetRange ( Pilot * p,
int id,
int level )

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.
levelLevel of the weapons to get the range of (-1 for all).

Definition at line 769 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 612 of file pilot_weapon.c.

◆ pilot_weapSetSpeed()

double pilot_weapSetSpeed ( Pilot * p,
int id,
int level )

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.
levelLevel of the weapons to get the speed of (-1 for all).

Definition at line 791 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 400 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 387 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 303 of file pilot_weapon.c.

◆ pilot_weapSetUpdateOutfits()

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

Updates the outfits with their current weapon set level.

Definition at line 343 of file pilot_weapon.c.

◆ pilot_weapSetUpdateRange()

static 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 699 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 687 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 480 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 467 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 1743 of file pilot_weapon.c.

◆ ws_free()

void ws_free ( PilotWeaponSet ws[PILOT_WEAPON_SETS])

Frees a weapon set.

Definition at line 1754 of file pilot_weapon.c.