naev 0.11.5
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 "quadtree.h"
10#include "target.h"
11
18typedef enum {
19 WEAPON_LAYER_BG,
20 WEAPON_LAYER_FG
21} WeaponLayer;
22
23/* Weapon status */
24typedef enum WeaponStatus_ {
25 WEAPON_STATUS_LOCKING,
26 WEAPON_STATUS_OK,
27 WEAPON_STATUS_UNJAMMED,
28 WEAPON_STATUS_JAMMED,
29 WEAPON_STATUS_JAMMED_SLOWED,
30} WeaponStatus;
31
32/* Weapon flags. */
33#define WEAPON_FLAG_DESTROYED (1<<0)
34#define WEAPON_FLAG_HITTABLE (1<<1)
35#define WEAPON_FLAG_ONLYHITTARGET (1<<2)
36#define WEAPON_FLAG_AIM (1<<3)
37#define weapon_isFlag(w,f) ((w)->flags & (f))
38#define weapon_setFlag(w,f) ((w)->flags |= (f))
39#define weapon_rmFlag(w,f) ((w)->flags &= ~(f))
40#define weapon_isSmart(w) (outfit_isSeeker(w->outfit))
47typedef struct Weapon_ {
48 WeaponLayer layer;
49 unsigned int flags;
51 unsigned int id;
53 int faction;
54 unsigned int parent;
56 const Outfit* outfit;
58 double real_vel;
59 double dam_mod;
61 int voice;
62 double timer2;
63 double paramf;
64 double life;
65 double timer;
66 double anim;
67 GLfloat r;
68 int sprite;
70 int lua_mem;
71 double falloff;
72 double strength;
74 int sx;
75 int sy;
78 double armour;
80 void (*think)(struct Weapon_*, double);
82 WeaponStatus status;
83} Weapon;
84
86Weapon *weapon_getID( unsigned int id );
87
88/* Addition. */
89Weapon *weapon_add( PilotOutfitSlot *po, const Outfit *ref,
90 double dir, const vec2* pos, const vec2* vel,
91 const Pilot *parent, const Target *target, double time, int aim );
92
93/* Targetting. */
94int weapon_inArc( const Outfit *o, const Pilot *parent, const Target *target, const vec2 *pos, const vec2 *vel, double dir, double time );
95double weapon_targetFlyTime( const Outfit *o, const Pilot *p, const Target *t );
96
97/* Beam weapons. */
98unsigned int beam_start( PilotOutfitSlot *po,
99 double dir, const vec2* pos, const vec2* vel,
100 const Pilot *parent, const Target *target, int aim );
101void beam_end( unsigned int beam );
102
103/* Misc stuff. */
104void weapon_hitAI( Pilot *p, const Pilot *shooter, double dmg );
105const IntList *weapon_collideQuery( int x1, int y1, int x2, int y2 );
106void weapon_collideQueryIL( IntList *il, int x1, int y1, int x2, int y2 );
107
108/* Update. */
109void weapons_updatePurge (void);
110void weapons_updateCollide( double dt );
111void weapons_update( double dt );
112void weapons_render( const WeaponLayer layer, double dt );
113
114/* Clean. */
115void weapon_init (void);
116void weapon_newSystem (void);
117void weapon_clear (void);
118void weapon_exit (void);
A ship outfit, depends radically on the type.
Definition outfit.h:328
Stores an outfit the pilot has.
Definition pilot.h:108
The representation of an in-game pilot.
Definition pilot.h:217
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:64
In-game representation of a weapon.
Definition weapon.h:47
int sx
Definition weapon.h:74
unsigned int id
Definition weapon.h:51
Trail_spfx * trail
Definition weapon.h:76
int sy
Definition weapon.h:75
PilotOutfitSlot * mount
Definition weapon.h:69
int voice
Definition weapon.h:61
double paramf
Definition weapon.h:63
double timer2
Definition weapon.h:62
double life
Definition weapon.h:64
double armour
Definition weapon.h:78
int faction
Definition weapon.h:53
WeaponLayer layer
Definition weapon.h:48
double dam_as_dis_mod
Definition weapon.h:60
const Outfit * outfit
Definition weapon.h:56
double real_vel
Definition weapon.h:58
double anim
Definition weapon.h:66
WeaponStatus status
Definition weapon.h:82
double dam_mod
Definition weapon.h:59
unsigned int flags
Definition weapon.h:49
double strength_base
Definition weapon.h:73
unsigned int parent
Definition weapon.h:54
int lua_mem
Definition weapon.h:70
GLfloat r
Definition weapon.h:67
Target target
Definition weapon.h:55
double strength
Definition weapon.h:72
int sprite
Definition weapon.h:68
Solid solid
Definition weapon.h:50
double timer
Definition weapon.h:65
double falloff
Definition weapon.h:71
Represents a 2d vector.
Definition vec2.h:32
void weapons_update(double dt)
Updates all the weapons.
Definition weapon.c:696
double weapon_targetFlyTime(const Outfit *o, const Pilot *p, const Target *t)
Gets the fly time for a weapon target.
Definition weapon.c:2538
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:2584
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:2511
Weapon * weapon_getID(unsigned int id)
Gets a weapon by ID.
Definition weapon.c:174
void weapons_updatePurge(void)
Purges unnecessary weapons.
Definition weapon.c:585
void weapon_clear(void)
Clears all the weapons, does NOT free the layers.
Definition weapon.c:2680
void weapons_updateCollide(double dt)
Handles weapon collisions.
Definition weapon.c:629
void weapon_hitAI(Pilot *p, const Pilot *shooter, double dmg)
Informs the AI if needed that it's been hit.
Definition weapon.c:1429
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:1888
Weapon * weapon_getStack(void)
Gets the weapon stack. Do not manipulate directly.
Definition weapon.c:138
void weapon_exit(void)
Destroys all the weapons and frees it all.
Definition weapon.c:2696
void weapons_render(const WeaponLayer layer, double dt)
Renders all the weapons in a layer.
Definition weapon.c:712
void weapon_init(void)
Initializes the weapon stuff.
Definition weapon.c:128
void weapon_newSystem(void)
Sets up collision stuff for a new system.
Definition weapon.c:186
void beam_end(unsigned int beam)
Ends a beam weapon.
Definition weapon.c:2608