naev 0.12.6
weapon.h
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
4#pragma once
5
6#include "outfit.h"
7#include "physics.h"
8#include "pilot.h"
9#include "target.h"
10
17typedef enum {
18 WEAPON_LAYER_BG,
19 WEAPON_LAYER_FG,
20} WeaponLayer;
21
22/* Weapon status */
23typedef enum WeaponStatus_ {
24 WEAPON_STATUS_LOCKING,
25 WEAPON_STATUS_OK,
26 WEAPON_STATUS_UNJAMMED,
27 WEAPON_STATUS_JAMMED,
28 WEAPON_STATUS_JAMMED_SLOWED,
29} WeaponStatus;
30
31/* Weapon flags. */
32#define WEAPON_FLAG_DESTROYED ( 1 << 0 )
33#define WEAPON_FLAG_HITTABLE ( 1 << 1 )
34#define WEAPON_FLAG_ONLYHITTARGET \
35 ( 1 << 2 )
36#define WEAPON_FLAG_AIM \
37 ( 1 << 3 )
39#define weapon_isFlag( w, f ) ( ( w )->flags & ( f ) )
40#define weapon_setFlag( w, f ) ( ( w )->flags |= ( f ) )
41#define weapon_rmFlag( w, f ) ( ( w )->flags &= ~( f ) )
42
48typedef struct Weapon_ {
49 WeaponLayer layer;
50 unsigned int flags;
52 unsigned int id;
53
54 int faction;
55 unsigned int parent;
57 const Outfit *outfit;
58
59 /* We want to snapshot shistats during creation here. */
60 double range_mod;
61 double dam_mod;
63 double accel_mod;
64 double speed_mod;
65 double turn_mod;
66
67 double real_vel;
68 int voice;
69 double timer2;
70 double paramf;
71 double life;
72 double timer;
73 double anim;
74 GLfloat r;
75 int sprite;
77 int lua_mem;
78 double falloff;
80 double strength;
82 int sx;
83 int sy;
85
86 double armour;
87
88 void ( *think )( struct Weapon_ *, double );
89
90 WeaponStatus status;
91} Weapon;
92
93Weapon *weapon_getStack( void );
94Weapon *weapon_getID( unsigned int id );
95
96/* Addition. */
97Weapon *weapon_add( PilotOutfitSlot *po, const Outfit *ref, double dir,
98 const vec2 *pos, const vec2 *vel, const Pilot *parent,
99 const Target *target, double time, int aim );
100
101/* Targetting. */
102int weapon_inArc( const Outfit *o, const Pilot *parent, const Target *target,
103 const vec2 *pos, const vec2 *vel, double dir, double time );
104double weapon_targetFlyTime( const Outfit *o, const Pilot *p, const Target *t );
105
106/* Beam weapons. */
107unsigned int beam_start( PilotOutfitSlot *po, double dir, const vec2 *pos,
108 const vec2 *vel, const Pilot *parent,
109 const Target *target, int aim );
110void beam_end( unsigned int beam );
111
112/* Misc stuff. */
113void weapon_hitAI( Pilot *p, const Pilot *shooter, double dmg );
114const IntList *weapon_collideQuery( int x1, int y1, int x2, int y2 );
115void weapon_collideQueryIL( IntList *il, int x1, int y1, int x2, int y2 );
116
117/* Update. */
118void weapons_updatePurge( void );
119void weapons_updateCollide( double dt );
120void weapons_update( double dt );
121void weapons_render( const WeaponLayer layer, double dt );
122
123/* Clean. */
124void weapon_init( void );
125void weapon_newSystem( void );
126void weapon_clear( void );
127void weapon_exit( void );
A ship outfit, depends radically on the type.
Definition outfit.h:372
Stores an outfit the pilot has.
Definition pilot.h:145
The representation of an in-game pilot.
Definition pilot.h:263
Represents a solid in the game.
Definition physics.h:44
Represents a weapon target.
Definition target.h:19
A trail generated by a ship or an ammo.
Definition spfx.h:93
In-game representation of a weapon.
Definition weapon.h:48
int sx
Definition weapon.h:82
double range_mod
Definition weapon.h:60
unsigned int id
Definition weapon.h:52
Trail_spfx * trail
Definition weapon.h:84
int sy
Definition weapon.h:83
double accel_mod
Definition weapon.h:63
PilotOutfitSlot * mount
Definition weapon.h:76
int voice
Definition weapon.h:68
double paramf
Definition weapon.h:70
double timer2
Definition weapon.h:69
double life
Definition weapon.h:71
double armour
Definition weapon.h:86
int faction
Definition weapon.h:54
void(* think)(struct Weapon_ *, double)
Definition weapon.h:88
WeaponLayer layer
Definition weapon.h:49
double dam_as_dis_mod
Definition weapon.h:62
const Outfit * outfit
Definition weapon.h:57
double real_vel
Definition weapon.h:67
double anim
Definition weapon.h:73
double turn_mod
Definition weapon.h:65
WeaponStatus status
Definition weapon.h:90
double dam_mod
Definition weapon.h:61
unsigned int flags
Definition weapon.h:50
double strength_base
Definition weapon.h:81
unsigned int parent
Definition weapon.h:55
int lua_mem
Definition weapon.h:77
GLfloat r
Definition weapon.h:74
Target target
Definition weapon.h:56
double speed_mod
Definition weapon.h:64
double strength
Definition weapon.h:80
int sprite
Definition weapon.h:75
Solid solid
Definition weapon.h:51
double timer
Definition weapon.h:72
double falloff
Definition weapon.h:78
Represents a 2d vector.
Definition vec2.h:45
void weapons_update(double dt)
Updates all the weapons.
Definition weapon.c:742
double weapon_targetFlyTime(const Outfit *o, const Pilot *p, const Target *t)
Gets the fly time for a weapon target.
Definition weapon.c:2715
unsigned int beam_start(PilotOutfitSlot *po, double dir, const vec2 *pos, const vec2 *vel, const Pilot *parent, const Target *target, int aim)
Starts a beam weapon.
Definition weapon.c:2755
Weapon * weapon_add(PilotOutfitSlot *po, const Outfit *ref, double dir, const vec2 *pos, const vec2 *vel, const Pilot *parent, const Target *target, double time, int aim)
Creates a new weapon.
Definition weapon.c:2689
Weapon * weapon_getID(unsigned int id)
Gets a weapon by ID.
Definition weapon.c:190
void weapons_updatePurge(void)
Purges unnecessary weapons.
Definition weapon.c:609
void weapon_clear(void)
Clears all the weapons, does NOT free the layers.
Definition weapon.c:2849
void weapons_updateCollide(double dt)
Handles weapon collisions.
Definition weapon.c:658
void weapon_hitAI(Pilot *p, const Pilot *shooter, double dmg)
Informs the AI if needed that it's been hit.
Definition weapon.c:1522
int weapon_inArc(const Outfit *o, const Pilot *parent, const Target *target, const vec2 *pos, const vec2 *vel, double dir, double time)
Gets the aim position of a turret weapon.
Definition weapon.c:2051
Weapon * weapon_getStack(void)
Gets the weapon stack. Do not manipulate directly.
Definition weapon.c:154
void weapon_exit(void)
Destroys all the weapons and frees it all.
Definition weapon.c:2870
void weapons_render(const WeaponLayer layer, double dt)
Renders all the weapons in a layer.
Definition weapon.c:762
void weapon_init(void)
Initializes the weapon stuff.
Definition weapon.c:144
void weapon_newSystem(void)
Sets up collision stuff for a new system.
Definition weapon.c:203
void beam_end(unsigned int beam)
Ends a beam weapon.
Definition weapon.c:2779