naev 0.10.4
Data Structures | Macros | Enumerations | Functions | Variables
weapon.c File Reference

Handles all the weapons in game. More...

#include "weapon.h"
#include "array.h"
#include "ai.h"
#include "camera.h"
#include "collision.h"
#include "explosion.h"
#include "gui.h"
#include "log.h"
#include "nstring.h"
#include "nlua_pilot.h"
#include "nlua_vec2.h"
#include "opengl.h"
#include "pilot.h"
#include "player.h"
#include "rng.h"
#include "spfx.h"

Go to the source code of this file.

Data Structures

struct  Weapon
 In-game representation of a weapon. More...
 

Macros

#define weapon_isSmart(w)   (w->think != NULL)
 
#define WEAPON_FLAG_DESTROYED   1
 
#define weapon_isFlag(w, f)   ((w)->flags & (f))
 
#define weapon_setFlag(w, f)   ((w)->flags |= (f))
 
#define weapon_rmFlag(w, f)   ((w)->flags &= ~(f))
 

Enumerations

enum  WeaponStatus {
  WEAPON_STATUS_LOCKING , WEAPON_STATUS_OK , WEAPON_STATUS_UNJAMMED , WEAPON_STATUS_JAMMED ,
  WEAPON_STATUS_JAMMED_SLOWED
}
 

Functions

static double weapon_aimTurret (const Outfit *outfit, const Pilot *parent, const Pilot *pilot_target, const vec2 *pos, const vec2 *vel, double dir, double swivel, double time)
 Gets the aim position of a turret weapon. More...
 
static void weapon_createBolt (Weapon *w, const Outfit *outfit, double T, const double dir, const vec2 *pos, const vec2 *vel, const Pilot *parent, double time, int aim)
 Creates the bolt specific properties of a weapon. More...
 
static void weapon_createAmmo (Weapon *w, const Outfit *outfit, double T, const double dir, const vec2 *pos, const vec2 *vel, const Pilot *parent, double time, int aim)
 Creates the ammo specific properties of a weapon. More...
 
static Weaponweapon_create (PilotOutfitSlot *po, double T, const double dir, const vec2 *pos, const vec2 *vel, const Pilot *parent, const unsigned int target, double time, int aim)
 Creates a new weapon. More...
 
static double weapon_computeTimes (double rdir, double rx, double ry, double dvx, double dvy, double pxv, double vmin, double acc, double *tt)
 Computes precisely interception times for propelled weapons (rockets). More...
 
static void weapon_render (Weapon *w, const double dt)
 Renders an individual weapon. More...
 
static void weapons_updateLayer (const double dt, const WeaponLayer layer)
 Updates all the weapons in the layer. More...
 
static void weapon_update (Weapon *w, const double dt, WeaponLayer layer)
 Updates an individual weapon. More...
 
static void weapon_sample_trail (Weapon *w)
 Updates the animated trail for a weapon. More...
 
static void weapon_destroy (Weapon *w)
 Destroys a weapon. More...
 
static void weapon_free (Weapon *w)
 Frees the weapon. More...
 
static void weapon_explodeLayer (WeaponLayer layer, double x, double y, double radius, const Pilot *parent, int mode)
 Explodes all the things on a layer. More...
 
static void weapons_purgeLayer (Weapon **layer)
 Purges weapons marked for deletion. More...
 
static int weapon_checkCanHit (const Weapon *w, const Pilot *p)
 Checks to see if the weapon can hit the pilot. More...
 
static void weapon_hit (Weapon *w, Pilot *p, vec2 *pos)
 Weapon hit the pilot. More...
 
static void weapon_miss (Weapon *w)
 Weapon missed and is due to be destroyed. More...
 
static void weapon_hitAst (Weapon *w, Asteroid *a, WeaponLayer layer, vec2 *pos)
 Weapon hit an asteroid. More...
 
static void weapon_hitBeam (Weapon *w, Pilot *p, WeaponLayer layer, vec2 pos[2], const double dt)
 Weapon hit the pilot. More...
 
static void weapon_hitAstBeam (Weapon *w, Asteroid *a, WeaponLayer layer, vec2 pos[2], const double dt)
 Weapon hit an asteroid. More...
 
static void think_seeker (Weapon *w, const double dt)
 The AI of seeker missiles. More...
 
static void think_beam (Weapon *w, const double dt)
 The pseudo-ai of the beam weapons. More...
 
void weapon_minimap (const double res, const double w, const double h, const RadarShape shape, double alpha)
 Draws the minimap weapons (used in player.c). More...
 
static void weapon_setThrust (Weapon *w, double thrust)
 Sets the weapon's thrust. More...
 
static void weapon_setTurn (Weapon *w, double turn)
 Sets the weapon's turn. More...
 
void weapon_init (void)
 Initializes the weapon stuff. More...
 
void weapons_update (const double dt)
 Updates all the weapon layers. More...
 
void weapons_render (const WeaponLayer layer, const double dt)
 Renders all the weapons in a layer. More...
 
static void weapon_renderBeam (Weapon *w, const double dt)
 
void weapon_hitAI (Pilot *p, const Pilot *shooter, double dmg)
 Informs the AI if needed that it's been hit. More...
 
void weapon_add (PilotOutfitSlot *po, const double T, const double dir, const vec2 *pos, const vec2 *vel, const Pilot *parent, unsigned int target, double time, int aim)
 Creates a new weapon. More...
 
unsigned int beam_start (PilotOutfitSlot *po, const double dir, const vec2 *pos, const vec2 *vel, const Pilot *parent, const unsigned int target, int aim)
 Starts a beam weapon. More...
 
void beam_end (const unsigned int parent, unsigned int beam)
 Ends a beam weapon. More...
 
void weapon_clear (void)
 Clears all the weapons, does NOT free the layers. More...
 
void weapon_exit (void)
 Destroys all the weapons and frees it all. More...
 
void weapon_explode (double x, double y, double radius, int dtype, double damage, const Pilot *parent, int mode)
 Clears possible exploded weapons. More...
 

Variables

static Weapon ** wbackLayer = NULL
 
static Weapon ** wfrontLayer = NULL
 
static gl_vbo * weapon_vbo = NULL
 
static GLfloat * weapon_vboData = NULL
 
static size_t weapon_vboSize = 0
 
static unsigned int beam_idgen = 0
 

Detailed Description

Handles all the weapons in game.

Weapons are what gets created when a pilot shoots. They are based on the outfit that created them.

Definition in file weapon.c.

Macro Definition Documentation

◆ WEAPON_FLAG_DESTROYED

#define WEAPON_FLAG_DESTROYED   1

Definition at line 49 of file weapon.c.

◆ weapon_isFlag

#define weapon_isFlag (   w,
 
)    ((w)->flags & (f))

Definition at line 50 of file weapon.c.

◆ weapon_isSmart

#define weapon_isSmart (   w)    (w->think != NULL)

Checks if the weapon w is smart.

Definition at line 37 of file weapon.c.

◆ weapon_rmFlag

#define weapon_rmFlag (   w,
 
)    ((w)->flags &= ~(f))

Definition at line 52 of file weapon.c.

◆ weapon_setFlag

#define weapon_setFlag (   w,
 
)    ((w)->flags |= (f))

Definition at line 51 of file weapon.c.

Enumeration Type Documentation

◆ WeaponStatus

Enumerator
WEAPON_STATUS_LOCKING 

Weapon is locking on.

WEAPON_STATUS_OK 

Weapon is fine

WEAPON_STATUS_UNJAMMED 

Survived jamming

WEAPON_STATUS_JAMMED 

Got jammed

WEAPON_STATUS_JAMMED_SLOWED 

Jammed and is now slower.

Definition at line 40 of file weapon.c.

Function Documentation

◆ beam_end()

void beam_end ( const unsigned int  parent,
unsigned int  beam 
)

Ends a beam weapon.

Parameters
parentID of the parent of the beam.
beamID of the beam to destroy.

Definition at line 2067 of file weapon.c.

◆ beam_start()

unsigned int beam_start ( PilotOutfitSlot po,
const double  dir,
const vec2 pos,
const vec2 vel,
const Pilot parent,
const unsigned int  target,
int  aim 
)

Starts a beam weapon.

Parameters
poOutfit slot which spawns the weapon.
dirDirection of the shooter.
posPosition of the slot (absolute).
velVelocity of the slot (absolute).
parentPilot shooter.
targetTarget ID that is getting shot.
aimWhether or not to aim.
Returns
The identifier of the beam weapon.
See also
beam_end

Definition at line 2012 of file weapon.c.

◆ think_beam()

static void think_beam ( Weapon w,
const double  dt 
)
static

The pseudo-ai of the beam weapons.

Parameters
wWeapon to do the thinking.
dtCurrent delta tick.

Definition at line 439 of file weapon.c.

◆ think_seeker()

static void think_seeker ( Weapon w,
const double  dt 
)
static

The AI of seeker missiles.

Parameters
wWeapon to do the thinking.
dtCurrent delta tick.

Definition at line 321 of file weapon.c.

◆ weapon_add()

void weapon_add ( PilotOutfitSlot po,
const double  T,
const double  dir,
const vec2 pos,
const vec2 vel,
const Pilot parent,
unsigned int  target,
double  time,
int  aim 
)

Creates a new weapon.

Parameters
poOutfit slot which spawns the weapon.
TTemperature of the shooter.
dirDirection of the shooter.
posPosition of the slot (absolute).
velVelocity of the slot (absolute).
parentPilot ID of the shooter.
targetTarget ID that is getting shot.
timeExpected flight time.
aimWhether or not to aim.

Definition at line 1953 of file weapon.c.

◆ weapon_aimTurret()

static double weapon_aimTurret ( const Outfit outfit,
const Pilot parent,
const Pilot pilot_target,
const vec2 pos,
const vec2 vel,
double  dir,
double  swivel,
double  time 
)
static

Gets the aim position of a turret weapon.

Parameters
outfitWeapon outfit.
parentParent of the weapon.
pilot_targetTarget of the weapon.
posPosition of the turret.
velVelocity of the turret.
dirDirection facing parent ship and turret.
timeExpected flight time.
swivelMaximum angle between weapon and straight ahead.

Definition at line 1498 of file weapon.c.

◆ weapon_checkCanHit()

static int weapon_checkCanHit ( const Weapon w,
const Pilot p 
)
static

Checks to see if the weapon can hit the pilot.

Parameters
wWeapon to check if hits pilot.
pPilot to check if is hit by weapon.
Returns
1 if can be hit, 0 if can't.

Definition at line 882 of file weapon.c.

◆ weapon_clear()

void weapon_clear ( void  )

Clears all the weapons, does NOT free the layers.

Definition at line 2161 of file weapon.c.

◆ weapon_computeTimes()

static double weapon_computeTimes ( double  rdir,
double  rx,
double  ry,
double  dvx,
double  dvy,
double  pxv,
double  vmin,
double  acc,
double *  tt 
)
static

Computes precisely interception times for propelled weapons (rockets).

Parameters
rdirtried shooting angle.
rxRelative position x.
ryRelative position y.
dvxRelative velocity x.
dvyRelative velocity y.
pxvCross product between relative position and relative velocity
vminmin ammo velocity.
accammo acceleration.
[out]ttTime for the target to reach the interception point.

Definition at line 1616 of file weapon.c.

◆ weapon_create()

static Weapon * weapon_create ( PilotOutfitSlot po,
double  T,
const double  dir,
const vec2 pos,
const vec2 vel,
const Pilot parent,
const unsigned int  target,
double  time,
int  aim 
)
static

Creates a new weapon.

Parameters
poOutfit slot which spawned the weapon.
Ttemperature of the shooter.
dirDirection the shooter is facing.
posPosition of the slot (absolute).
velVelocity of the slot (absolute).
parentShooter.
targetTarget ID of the shooter.
timeExpected flight time.
aimWhether or not to aim.
Returns
A pointer to the newly created weapon.

< Needs a mass.

Definition at line 1836 of file weapon.c.

◆ weapon_createAmmo()

static void weapon_createAmmo ( Weapon w,
const Outfit outfit,
double  T,
const double  dir,
const vec2 pos,
const vec2 vel,
const Pilot parent,
double  time,
int  aim 
)
static

Creates the ammo specific properties of a weapon.

Parameters
wWeapon to create ammo specific properties of.
outfitOutfit which spawned the weapon.
Ttemperature of the shooter.
dirDirection the shooter is facing.
posPosition of the slot (absolute).
velVelocity of the slot (absolute).
parentShooter.
timeExpected flight time.
aimWhether or not to aim.

Definition at line 1729 of file weapon.c.

◆ weapon_createBolt()

static void weapon_createBolt ( Weapon w,
const Outfit outfit,
double  T,
const double  dir,
const vec2 pos,
const vec2 vel,
const Pilot parent,
double  time,
int  aim 
)
static

Creates the bolt specific properties of a weapon.

Parameters
wWeapon to create bolt specific properties of.
outfitOutfit which spawned the weapon.
Ttemperature of the shooter.
dirDirection the shooter is facing.
posPosition of the slot (absolute).
velVelocity of the slot (absolute).
parentShooter.
timeExpected flight time.
aimWhether or not to aim.

Definition at line 1649 of file weapon.c.

◆ weapon_destroy()

static void weapon_destroy ( Weapon w)
static

Destroys a weapon.

Parameters
wWeapon to destroy.

Definition at line 2109 of file weapon.c.

◆ weapon_exit()

void weapon_exit ( void  )

Destroys all the weapons and frees it all.

Definition at line 2179 of file weapon.c.

◆ weapon_explode()

void weapon_explode ( double  x,
double  y,
double  radius,
int  dtype,
double  damage,
const Pilot parent,
int  mode 
)

Clears possible exploded weapons.

Definition at line 2199 of file weapon.c.

◆ weapon_explodeLayer()

static void weapon_explodeLayer ( WeaponLayer  layer,
double  x,
double  y,
double  radius,
const Pilot parent,
int  mode 
)
static

Explodes all the things on a layer.

Definition at line 2212 of file weapon.c.

◆ weapon_free()

static void weapon_free ( Weapon w)
static

Frees the weapon.

Parameters
wWeapon to free.

Definition at line 2120 of file weapon.c.

◆ weapon_hit()

static void weapon_hit ( Weapon w,
Pilot p,
vec2 pos 
)
static

Weapon hit the pilot.

Parameters
wWeapon involved in the collision.
pPilot that got hit.
posPosition of the hit.

Definition at line 1270 of file weapon.c.

◆ weapon_hitAI()

void weapon_hitAI ( Pilot p,
const Pilot shooter,
double  dmg 
)

Informs the AI if needed that it's been hit.

Parameters
pPilot being hit.
shooterPilot that shot.
dmgDamage done to p.

Definition at line 1227 of file weapon.c.

◆ weapon_hitAst()

static void weapon_hitAst ( Weapon w,
Asteroid a,
WeaponLayer  layer,
vec2 pos 
)
static

Weapon hit an asteroid.

Parameters
wWeapon involved in the collision.
aAsteroid that got hit.
layerLayer to which the weapon belongs.
posPosition of the hit.

Definition at line 1354 of file weapon.c.

◆ weapon_hitAstBeam()

static void weapon_hitAstBeam ( Weapon w,
Asteroid a,
WeaponLayer  layer,
vec2  pos[2],
const double  dt 
)
static

Weapon hit an asteroid.

Parameters
wWeapon involved in the collision.
aAsteroid that got hit.
layerLayer to which the weapon belongs.
posPosition of the hit.
dtCurrent delta tick.

Definition at line 1453 of file weapon.c.

◆ weapon_hitBeam()

static void weapon_hitBeam ( Weapon w,
Pilot p,
WeaponLayer  layer,
vec2  pos[2],
const double  dt 
)
static

Weapon hit the pilot.

Parameters
wWeapon involved in the collision.
pPilot that got hit.
layerLayer to which the weapon belongs.
posPosition of the hit.
dtCurrent delta tick.

Definition at line 1398 of file weapon.c.

◆ weapon_init()

void weapon_init ( void  )

Initializes the weapon stuff.

Definition at line 157 of file weapon.c.

◆ weapon_minimap()

void weapon_minimap ( const double  res,
const double  w,
const double  h,
const RadarShape  shape,
double  alpha 
)

Draws the minimap weapons (used in player.c).

Parameters
resMinimap resolution.
wWidth of minimap.
hHeight of minimap.
shapeShape of the minimap.
alphaAlpha to draw points at.

Definition at line 172 of file weapon.c.

◆ weapon_miss()

static void weapon_miss ( Weapon w)
static

Weapon missed and is due to be destroyed.

Parameters
wWeapon that missed.

Definition at line 1323 of file weapon.c.

◆ weapon_render()

static void weapon_render ( Weapon w,
const double  dt 
)
static

Renders an individual weapon.

Parameters
wWeapon to render.
dtCurrent delta tick.

Definition at line 792 of file weapon.c.

◆ weapon_renderBeam()

static void weapon_renderBeam ( Weapon w,
const double  dt 
)
static

Definition at line 736 of file weapon.c.

◆ weapon_sample_trail()

static void weapon_sample_trail ( Weapon w)
static

Updates the animated trail for a weapon.

Definition at line 1194 of file weapon.c.

◆ weapon_setThrust()

static void weapon_setThrust ( Weapon w,
double  thrust 
)
static

Sets the weapon's thrust.

Definition at line 302 of file weapon.c.

◆ weapon_setTurn()

static void weapon_setTurn ( Weapon w,
double  turn 
)
static

Sets the weapon's turn.

Definition at line 310 of file weapon.c.

◆ weapon_update()

static void weapon_update ( Weapon w,
const double  dt,
WeaponLayer  layer 
)
static

Updates an individual weapon.

Parameters
wWeapon to update.
dtCurrent delta tick.
layerLayer to which the weapon belongs.

Definition at line 951 of file weapon.c.

◆ weapons_purgeLayer()

static void weapons_purgeLayer ( Weapon **  layer)
static

Purges weapons marked for deletion.

Parameters
layerLayer to purge weapons from.

Definition at line 698 of file weapon.c.

◆ weapons_render()

void weapons_render ( const WeaponLayer  layer,
const double  dt 
)

Renders all the weapons in a layer.

Parameters
layerLayer to render.
dtCurrent delta tick.

Definition at line 715 of file weapon.c.

◆ weapons_update()

void weapons_update ( const double  dt)

Updates all the weapon layers.

Parameters
dtCurrent delta tick.

Definition at line 548 of file weapon.c.

◆ weapons_updateLayer()

static void weapons_updateLayer ( const double  dt,
const WeaponLayer  layer 
)
static

Updates all the weapons in the layer.

Parameters
dtCurrent delta tick.
layerLayer to update.

Definition at line 565 of file weapon.c.

Variable Documentation

◆ beam_idgen

unsigned int beam_idgen = 0
static

Beam identifier generator.

Definition at line 105 of file weapon.c.

◆ wbackLayer

Weapon** wbackLayer = NULL
static

behind pilots

Definition at line 96 of file weapon.c.

◆ weapon_vbo

gl_vbo* weapon_vbo = NULL
static

Weapon VBO.

Definition at line 100 of file weapon.c.

◆ weapon_vboData

GLfloat* weapon_vboData = NULL
static

Data of weapon VBO.

Definition at line 101 of file weapon.c.

◆ weapon_vboSize

size_t weapon_vboSize = 0
static

Size of the VBO.

Definition at line 102 of file weapon.c.

◆ wfrontLayer

Weapon** wfrontLayer = NULL
static

in front of pilots, behind player

Definition at line 97 of file weapon.c.