FS2_Open
Open source remastering of the Freespace 2 engine
beam.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) Volition, Inc. 1999. All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell
5  * or otherwise commercially exploit the source or things you created based on the
6  * source.
7  *
8 */
9 
10 
11 
12 #ifndef __FS2_BEAM_WEAPON_HEADER_FILE
13 #define __FS2_BEAM_WEAPON_HEADER_FILE
14 
15 // ------------------------------------------------------------------------------------------------
16 // BEAM WEAPON DEFINES/VARS
17 //
18 #include "globalincs/globals.h"
19 #include "model/model.h"
20 
21 // prototypes
22 class object;
23 class ship_subsys;
24 struct obj_pair;
25 struct beam_weapon_info;
26 struct vec3d;
27 
28 // beam types
29 // REMINDER : if you change the behavior of any of these beam types, make sure to update their "cones" of possible
30 // movement inside of the function beam_get_cone_dot(...) in beam.cpp Otherwise it could cause collisions to not
31 // function properly!!!!!!
32 #define BEAM_TYPE_A 0 // unidirectional beam
33 #define BEAM_TYPE_B 1 // "slash" in one direction
34 #define BEAM_TYPE_C 2 // targeting lasers (only lasts one frame)
35 #define BEAM_TYPE_D 3 // similar to the type A beams, but takes multiple shots and "chases" fighters around
36 #define BEAM_TYPE_E 4 // stupid beam. like type A, only it doesn't aim. it just shoots directly out of the turret
37 
38 // max # of "shots" an individual beam will take
39 #define MAX_BEAM_SHOTS 5
40 #define MAX_BEAMS 500
41 
42 // uses to define beam behavior ahead of time - needed for multiplayer
43 typedef struct beam_info {
44  vec3d dir_a, dir_b; // direction vectors for beams
45  float delta_ang; // angle between dir_a and dir_b
46  ubyte shot_count; // # of shots
47  float shot_aim[MAX_BEAM_SHOTS]; // accuracy. this is a constant multiple of radius. anything < 1.0 will guarantee a hit
48 } beam_info;
49 
50 #define BFIF_IS_FIGHTER_BEAM (1<<0)
51 #define BFIF_FORCE_FIRING (1<<1)
52 #define BFIF_TARGETING_COORDS (1<<2)
53 #define BFIF_FLOATING_BEAM (1<<3)
54 
55 // pass to beam fire
56 typedef struct beam_fire_info {
57  int beam_info_index; // weapon info index
58  object *shooter; // whos shooting
59  vec3d targeting_laser_offset; // offset from the center of the object (for targeting lasers only)
60  ship_subsys *turret; // where he's shooting from
61  float accuracy; // 0.0 to 1.0 (only really effects targeting on small ships)
62  object *target; // who's getting shot
63  ship_subsys *target_subsys; // (optional), specific subsystem to be targeted on the target
64  vec3d target_pos1; // if we're shooting off into space
65  vec3d target_pos2; // if we're shooting off into space (optional second point)
66  vec3d starting_pos; // starting positiong for floating beams -MageKing17
67  beam_info *beam_info_override; // (optional), pass this in to override all beam movement info (for multiplayer)
68  int num_shots; // (optional), only used for type D weapons
69  int bank; // for fighters, which bank of the primary weapons are they in
70  int point; // for fighters, which point on the bank it is from
71  int bfi_flags;
72  char team; // for floating beams, determines which team the beam is on
74 
75 typedef struct fighter_beam_fire_info {
76  int beam_info_index; // weapon info index
77  object *shooter; // whos shooting
78  vec3d targeting_laser_offset; // offset from the center of the object (for targeting lasers only)
79  ship_subsys *turret; // where he's shooting from
80  float accuracy; // 0.0 to 1.0 (only really effects targeting on small ships)
81  object *target; // whos getting shot
82  ship_subsys *target_subsys; // (optional), specific subsystem to be targeted on the target
83  beam_info *beam_info_override; // (optional), pass this in to override all beam movement info (for multiplayer)
84  int num_shots; // (optional), only used for type D weapons
85  int fighter_beam_loop_sound; //loop sound used by fighter beams -Bobboau
88  float life_left;
89  float life_total;
91 
92 // max # of collisions we'll allow per frame
93 #define MAX_FRAME_COLLISIONS 10
94 
95 // collision info
96 typedef struct beam_collision {
97  mc_info cinfo; // collision info
98  int c_objnum; // objnum of the guy we recently collided with
99  int c_sig; // object sig
100  int c_stamp; // when we should next apply damage
101  int quadrant; // shield quadrant this beam hits if any -Bobboau
102  int is_exit_collision; //does this occur when the beam is exiting the ship
104 
105 // beam flag defines
106 #define BF_SAFETY (1<<0) // if this is set, don't collide or render for this frame. lifetime still increases though
107 #define BF_SHRINK (1<<1) // if this is set, the beam is in the warmdown phase
108 #define BF_FORCE_FIRING (1<<2)
109 #define BF_IS_FIGHTER_BEAM (1<<3)
110 #define BF_TARGETING_COORDS (1<<4)
111 #define BF_FLOATING_BEAM (1<<5)
112 
113 // beam struct (the actual weapon/object)
114 typedef struct beam {
115  // low-level data
116  int objnum; // our own objnum
118  int sig; // signature for the shooting object
119  object *objp; // the shooting object (who owns the turret that I am being fired from)
120  object *target; // target object
121  ship_subsys *target_subsys; // targeted subsys
122  vec3d target_pos1; // if we're targeting a location in space
123  vec3d target_pos2; // if we're targeting a location in space (optional second point)
124  int target_sig; // target sig
125  ship_subsys *subsys; // subsys its being fired from
126  beam *next, *prev; // link list stuff
128  int framecount; // how many frames the beam has been active
129  int flags; // see BF_* defines
130  float shrink; // shrink factor
131 
132  // beam info
133  int warmup_stamp; // timestamp for "warming up"
134  int warmdown_stamp; // timestamp for "warming down"
135  int type; // see BEAM_TYPE_* defines in beam.h
136  float life_left; // in seconds
137  float life_total; // total life
138  // this vector has very special meaning. BEFORE performing collision checks, it basically implies a "direction". meaning
139  // the vector between it and last_start is where the beam will be aiming. AFTER performing collision checks, it is the
140  // literal world collision point on the object (or meaningless, if we hit nothing). The function beam_move_all_pre() is
141  // responsible for then setting it up pre-collision time
144  int shot_index; // for type D beam weapons
145  float beam_glow_frame; // what frame a beam glow animation is on
146  float beam_section_frame[MAX_BEAM_SECTIONS]; // what frame a beam section animation is on
147 
148  // recent collisions
150  int r_collision_count; // # of recent collisions
151 
152  // collision info for this frame
153  beam_collision f_collisions[MAX_FRAME_COLLISIONS]; // collisions for the current frame
154  int f_collision_count; // # of collisions we recorded this frame
155 
156  // looping sound info, HANDLE
157  int beam_sound_loop; // -1 if none
158 
159  // team
160  char team;
161 
162  float range;
164 
165  // exactly how the beam will behave. by passing this is multiplayer from server to client, we can ensure that
166  // everything looks the same
168  int bank;
169 
172 
173  float beam_width;
174 } beam;
175 
176 extern beam Beams[MAX_BEAMS]; // all beams
177 extern int Beam_count;
178 
179 // ------------------------------------------------------------------------------------------------
180 // BEAM WEAPON FUNCTIONS
181 //
182 
183 // ---------------
184 // the next functions are probably the only ones anyone should care about calling. the rest require somewhat detailed knowledge of beam weapons
185 
186 // fire a beam, returns objnum on success. the innards of the code handle all the rest, foo
187 int beam_fire(beam_fire_info *fire_info);
188 
189 // fire a targeting beam, returns objnum on success. a much much simplified version of a beam weapon
190 // targeting lasers last _one_ frame. For a continuous stream - they must be created every frame.
191 // this allows it to work smoothly in multiplayer (detect "trigger down". every frame just create a targeting laser firing straight out of the
192 // object. this way you get all the advantages of nice rendering and collisions).
193 // NOTE : only references beam_info_index and shooter
195 
196 // return an object index of the guy who's firing this beam
197 int beam_get_parent(object *bm);
198 
199 // return weapon_info_index of beam
200 int beam_get_weapon_info_index(object *bm);
201 
202 // given a beam object, get the # of collisions which happened during the last collision check (typically, last frame)
203 int beam_get_num_collisions(int objnum);
204 
205 // stuff collision info, returns 1 on success
206 int beam_get_collision(int objnum, int num, int *collision_objnum, mc_info **cinfo);
207 // ---------------
208 
209 // init at game startup
210 void beam_init();
211 
212 // initialize beam weapons for this level
213 void beam_level_init();
214 
215 // shutdown beam weapons for this level
216 void beam_level_close();
217 
218 // collide a beam with a ship, returns 1 if we can ignore all future collisions between the 2 objects
219 int beam_collide_ship(obj_pair *pair);
220 
221 // collide a beam with an asteroid, returns 1 if we can ignore all future collisions between the 2 objects
223 
224 // collide a beam with a missile, returns 1 if we can ignore all future collisions between the 2 objects
225 int beam_collide_missile(obj_pair *pair);
226 
227 // collide a beam with debris, returns 1 if we can ignore all future collisions between the 2 objects
228 int beam_collide_debris(obj_pair *pair);
229 
230 // pre-move (before collision checking - but AFTER ALL OTHER OBJECTS HAVE BEEN MOVED)
231 void beam_move_all_pre();
232 
233 // post-collision time processing for beams
234 void beam_move_all_post();
235 
236 // render all beam weapons
237 void beam_render_all();
238 
239 // early-out function for when adding object collision pairs, return 1 if the pair should be ignored
240 int beam_collide_early_out(object *a, object *b);
241 
242 // pause all looping beam sounds
243 void beam_pause_sounds();
244 
245 // unpause looping beam sounds
246 void beam_unpause_sounds();
247 
248 void beam_calc_facing_pts(vec3d *top, vec3d *bot, vec3d *fvec, vec3d *pos, float w, float z_add);
249 
250 // return the amount of damage which should be applied to a ship. basically, filters friendly fire damage
251 float beam_get_ship_damage(beam *b, object *objp);
252 
253 
254 
255 #endif
int framecount
Definition: beam.h:128
vec3d target_pos2
Definition: beam.h:65
int beam_get_num_collisions(int objnum)
Definition: beam.cpp:629
float range
Definition: beam.h:162
int flags
Definition: beam.h:129
void beam_move_all_post()
Definition: beam.cpp:986
beam * prev
Definition: beam.h:126
int warmup_stamp
Definition: beam.h:133
int beam_info_index
Definition: beam.h:57
#define MAX_BEAMS
Definition: beam.h:40
int f_collision_count
Definition: beam.h:154
object * target
Definition: beam.h:62
void beam_move_all_pre()
Definition: beam.cpp:906
void beam_calc_facing_pts(vec3d *top, vec3d *bot, vec3d *fvec, vec3d *pos, float w, float z_add)
Definition: beam.cpp:1603
int r_collision_count
Definition: beam.h:150
beam_info * beam_info_override
Definition: beam.h:83
int warmdown_stamp
Definition: beam.h:134
int type
Definition: beam.h:135
vec3d target_pos1
Definition: beam.h:64
void beam_level_close()
Definition: beam.cpp:273
float shrink
Definition: beam.h:130
int bfi_flags
Definition: beam.h:71
Definition: pstypes.h:88
float delta_ang
Definition: beam.h:45
struct beam_info beam_info
ship_subsys * turret
Definition: beam.h:60
int fighter_beam_loop_sound
Definition: beam.h:85
ship_subsys * target_subsys
Definition: beam.h:63
void beam_pause_sounds()
Definition: beam.cpp:682
int beam_collide_ship(obj_pair *pair)
Definition: beam.cpp:2397
ship_subsys * subsys
Definition: beam.h:125
object * target
Definition: beam.h:120
vec3d target_pos1
Definition: beam.h:122
vec3d starting_pos
Definition: beam.h:66
float shot_aim[MAX_BEAM_SHOTS]
Definition: beam.h:47
struct beam beam
object * objp
Definition: lua.cpp:3105
int beam_fire(beam_fire_info *fire_info)
Definition: beam.cpp:281
float beam_width
Definition: beam.h:173
beam Beams[MAX_BEAMS]
Definition: beam.cpp:60
mc_info cinfo
Definition: beam.h:97
int c_sig
Definition: beam.h:99
vec3d targeting_laser_offset
Definition: beam.h:127
int weapon_info_index
Definition: beam.h:117
void beam_render_all()
Definition: beam.cpp:1558
int Beam_muzzle_stamp
Definition: beam.h:170
ship_subsys * turret
Definition: beam.h:79
Definition: beam.h:114
int shot_index
Definition: beam.h:144
ubyte shot_count
Definition: beam.h:46
object * target
Definition: beam.h:81
int objnum
Definition: beam.h:116
GLboolean GLboolean GLboolean GLboolean a
Definition: Glext.h:5781
beam_collision r_collisions[MAX_FRAME_COLLISIONS]
Definition: beam.h:149
int target_sig
Definition: beam.h:124
int point
Definition: beam.h:70
Definition: beam.h:43
beam * next
Definition: beam.h:126
int is_exit_collision
Definition: beam.h:102
void beam_level_init()
Definition: beam.cpp:253
char team
Definition: beam.h:160
#define MAX_BEAM_SECTIONS
Definition: globals.h:89
float beam_get_ship_damage(beam *b, object *objp)
Definition: beam.cpp:3592
#define MAX_BEAM_SHOTS
Definition: beam.h:39
beam_info * beam_info_override
Definition: beam.h:67
beam_info binfo
Definition: beam.h:167
float damage_threshold
Definition: beam.h:163
int Beam_count
Definition: beam.cpp:63
float life_total
Definition: beam.h:137
struct beam_collision beam_collision
unsigned char ubyte
Definition: pstypes.h:62
Definition: object.h:141
vec3d targeting_laser_offset
Definition: beam.h:59
int beam_get_weapon_info_index(object *bm)
Definition: beam.cpp:608
object * objp
Definition: beam.h:119
int beam_sound_loop
Definition: beam.h:157
int beam_get_parent(object *bm)
Definition: beam.cpp:579
vec3d targeting_laser_offset
Definition: beam.h:78
ship_subsys * target_subsys
Definition: beam.h:82
GLboolean GLboolean GLboolean b
Definition: Glext.h:5781
int bank
Definition: beam.h:168
int firingpoint
Definition: beam.h:171
struct beam_fire_info beam_fire_info
int beam_get_collision(int objnum, int num, int *collision_objnum, mc_info **cinfo)
Definition: beam.cpp:655
GLuint GLuint num
Definition: Glext.h:9089
vec3d dir_b
Definition: beam.h:44
float beam_section_frame[MAX_BEAM_SECTIONS]
Definition: beam.h:146
int beam_collide_early_out(object *a, object *b)
Definition: beam.cpp:2906
int num_shots
Definition: beam.h:68
int c_objnum
Definition: beam.h:98
vec3d dir_a
Definition: beam.h:44
GLubyte GLubyte GLubyte GLubyte w
Definition: Glext.h:5679
ship_subsys * target_subsys
Definition: beam.h:121
vec3d target_pos2
Definition: beam.h:123
int c_stamp
Definition: beam.h:100
int beam_collide_asteroid(obj_pair *pair)
Definition: beam.cpp:2625
void beam_init()
Definition: beam.cpp:247
int quadrant
Definition: beam.h:101
#define MAX_FRAME_COLLISIONS
Definition: beam.h:93
object * shooter
Definition: beam.h:58
vec3d last_shot
Definition: beam.h:142
int beam_collide_missile(obj_pair *pair)
Definition: beam.cpp:2721
int bank
Definition: beam.h:69
hull_check pos
Definition: lua.cpp:5050
float accuracy
Definition: beam.h:61
beam_collision f_collisions[MAX_FRAME_COLLISIONS]
Definition: beam.h:153
void beam_unpause_sounds()
Definition: beam.cpp:703
int beam_collide_debris(obj_pair *pair)
Definition: beam.cpp:2814
vec3d last_start
Definition: beam.h:143
char team
Definition: beam.h:72
float life_left
Definition: beam.h:136
struct fighter_beam_fire_info fighter_beam_fire_info
GLdouble GLdouble GLdouble GLdouble top
Definition: Glext.h:10330
object * shooter
Definition: beam.h:77
float beam_glow_frame
Definition: beam.h:145
int sig
Definition: beam.h:118
int beam_fire_targeting(fighter_beam_fire_info *fire_info)
Definition: beam.cpp:476