FS2_Open
Open source remastering of the Freespace 2 engine
shipfx.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 _SHIPFX_H
13 #define _SHIPFX_H
14 
15 #include "globalincs/pstypes.h"
16 #include "graphics/grbatch.h"
17 #include "model/modelrender.h"
18 
19 class object;
20 class ship;
21 class ship_info;
22 class game_snd;
23 class ship_subsys;
25 struct vec3d;
26 struct matrix;
27 
28 // Make sparks fly off of ship n
29 // sn = spark number to spark, corrosponding to element in
30 // ship->hitpos array. If this isn't -1, it is a just
31 // got hit by weapon spark, otherwise pick one randomally.
32 void shipfx_emit_spark( int n, int sn );
33 
34 // Does the special effects to blow a subsystem off a ship
35 extern void shipfx_blow_off_subsystem(object *ship_obj,ship *ship_p,ship_subsys *subsys, vec3d *exp_center, bool no_explosion = false);
36 
37 
38 // Creates "ndebris" pieces of debris on random verts of the the "submodel" in the
39 // ship's model.
40 extern void shipfx_blow_up_model(object *obj,int model, int submodel, int ndebris, vec3d *exp_center);
41 
42 // put here for multiplayer purposes
43 void shipfx_blow_up_hull(object *obj,int model, vec3d *exp_center );
44 
45 
46 // =================================================
47 // SHIP WARP IN EFFECT STUFF
48 // =================================================
49 
50 // When a ship warps in, this gets called to start the effect
51 extern void shipfx_warpin_start( object *objp );
52 
53 // During a ship warp in, this gets called each frame to move the ship
54 extern void shipfx_warpin_frame( object *objp, float frametime );
55 
56 // When a ship warps out, this gets called to start the effect
57 extern void shipfx_warpout_start( object *objp );
58 
59 // During a ship warp out, this gets called each frame to move the ship
60 extern void shipfx_warpout_frame( object *objp, float frametime );
61 
62 // =================================================
63 // SHIP SHADOW EFFECT STUFF
64 // =================================================
65 
66 // Given point p0, in object's frame of reference, find if
67 // it can see the sun.
68 bool shipfx_point_in_shadow( vec3d *p0, matrix *src_orient, vec3d *src_pos, float radius );
69 
70 // Given an ship see if it is in a shadow.
71 bool shipfx_in_shadow( object * src_obj );
72 
73 // Given world point see if it is in a shadow.
74 bool shipfx_eye_in_shadow( vec3d *eye_pos, object *src_obj, int sun_n);
75 
76 
77 // =================================================
78 // SHIP GUN FLASH EFFECT STUFF
79 // =================================================
80 
81 // Resets the ship flash stuff. Call before
82 // each level.
83 void shipfx_flash_init();
84 
85 // Given that a ship fired a weapon, light up the model
86 // accordingly.
87 // Set is_primary to non-zero if this is a primary weapon.
88 // Gun_pos should be in object's frame of reference, not world!!!
89 void shipfx_flash_create(object *objp, int model_num, vec3d *gun_pos, vec3d *gun_dir, int is_primary, int weapon_info_index);
90 
91 // Sets the flash lights in the model used by this
92 // ship to the appropriate values. There might not
93 // be any flashes linked to this ship in which
94 // case this function does nothing.
95 void shipfx_flash_light_model(object *objp, int model_num);
96 
97 // Does whatever processing needs to be done each frame.
98 void shipfx_flash_do_frame(float frametime);
99 
100 
101 // =================================================
102 // LARGE SHIP EXPLOSION EFFECT STUFF
103 // =================================================
104 
105 // Call between levels
107 
108 // Returns 0 if couldn't init
110 
111 // Returns 1 when explosion is done
112 int shipfx_large_blowup_do_frame(ship *shipp, float frametime);
113 
115 
117 
118 void shipfx_debris_limit_speed(struct debris *db, ship *shipp);
119 
120 // sound manager fore big ship sub explosions sounds
121 void do_sub_expl_sound(float radius, vec3d* sound_pos, int* sound_handle);
122 
123 // do all shockwaves for a ship blowing up
125 
126 
127 // =================================================
128 // ELECTRICAL SPARKS ON DAMAGED SHIPS EFFECT STUFF
129 // =================================================
131 
132 
133 // =================================================
134 // NEBULA LIGHTNING.
135 // =================================================
137 
138 // engine wash level init
140 
141 // pause engine wash sounds
143 
144 // =====================================================
145 // CLOAKING
146 // =====================================================
147 
148 //translate the texture matrix some
149 void shipfx_cloak_frame(ship *shipp, float frametime);
150 void shipfx_start_cloak(ship *shipp, int warmup = 5000, int recalc_transform = 0, int device=0);
151 void shipfx_stop_cloak(ship *shipp, int warpdown = 5000);
152 float shipfx_calc_visibility(object *obj, vec3d *view_pt);
153 
154 #define WD_NONE 0
155 #define WD_WARP_IN 1
156 #define WD_WARP_OUT 2
157 float shipfx_calculate_warp_time(object *objp, int warp_dir);
158 float shipfx_calculate_warp_dist(object *objp);
159 
160 //********************-----CLASS: WarpEffect-----********************//
162 {
163 protected:
164  //core variables
165  object *objp;
167 
168  //variables provided for expediency
171 public:
172  WarpEffect();
173  WarpEffect(object *n_objp, int n_direction);
174  virtual ~WarpEffect() {}
175 
176  void clear();
177  bool isValid();
178 
179  virtual void pageIn();
180  virtual void pageOut();
181 
182  virtual int warpStart();
183  virtual int warpFrame(float frametime);
184  virtual int warpShipClip();
185  virtual int warpShipClip(model_render_params *render_info);
186  virtual int warpShipRender();
187  virtual int warpShipQueueRender(draw_list *scene);
188  virtual int warpEnd();
189 
190  //For VM_WARP_CHASE
191  virtual int getWarpPosition(vec3d *output);
192  virtual int getWarpOrientation(matrix *output);
193 };
194 
195 //********************-----CLASS: WE_Default-----********************//
196 #define WE_DEFAULT_NUM_STAGES 2
197 class WE_Default : public WarpEffect
198 {
199 private:
200  //portal object
201  object *portal_objp;
202 
203  //Total data
204  int total_time_start;
205  int total_time_end;
206  //Stage data
207  int stage_time_start;
208  int stage_time_end; // pops when ship is completely warped out or warped in. Used for both warp in and out.
209 
210  //Data "storage"
211  int stage_duration[WE_DEFAULT_NUM_STAGES+1];
212 
213  //sweeper polygon and clip effect
214  vec3d pos;
215  vec3d fvec;
216  float radius;
217 
218 public:
219  WE_Default(object *n_objp, int n_direction);
220 
221  int warpStart();
222  int warpFrame(float frametime);
223  int warpShipClip();
224  int warpShipClip(model_render_params *render_info);
225  int warpShipRender();
226 
227  int getWarpPosition(vec3d *output);
228  int getWarpOrientation(matrix *output);
229 };
230 
231 //********************-----CLASS: WE_BSG-----********************//
232 #define WE_BSG_NUM_STAGES 2
233 class WE_BSG : public WarpEffect
234 {
235 private:
236  //Total data
237  int total_time_start;
238  int total_time_end;
239  //Stage data
240  int stage;
241  int stage_time_start;
242  int stage_time_end; // pops when ship is completely warped out or warped in. Used for both warp in and out.
243 
244  //Data "storage"
245  int stage_duration[WE_BSG_NUM_STAGES];
246 
247  //anim
248  int anim;
249  int anim_nframes;
250  int anim_fps;
251  int anim_total_time;
252  int shockwave;
253  int shockwave_nframes;
254  int shockwave_fps;
255  int shockwave_total_time;
256 
257  geometry_batcher batcher;
258  vec3d autocenter;
259  float z_offset_max;
260  float z_offset_min;
261  float tube_radius;
262  float shockwave_radius;
263 
264  //*****Per-instance
265  vec3d pos;
266  //Sound
267  float snd_range_factor;
268  int snd_start;
269  game_snd *snd_start_gs;
270  int snd_end;
271  game_snd *snd_end_gs;
272 
273 public:
274  WE_BSG(object *n_objp, int n_direction);
275  ~WE_BSG();
276 
277  virtual void pageIn();
278 
279  virtual int warpStart();
280  virtual int warpFrame(float frametime);
281  virtual int warpShipClip();
282  virtual int warpShipClip(model_render_params *render_info);
283  virtual int warpShipRender();
284  virtual int warpEnd();
285 
286  virtual int getWarpPosition(vec3d *output);
287  virtual int getWarpOrientation(matrix *output);
288 };
289 
290 //********************-----CLASS: WE_Homeworld-----********************//
291 #define WE_HOMEWORLD_NUM_STAGES 6
292 class WE_Homeworld : public WarpEffect
293 {
294 private:
295  //Total data
296  int total_time_start;
297  int total_time_end;
298  //Stage data
299  int stage;
300  int stage_time_start;
301  int stage_time_end; // pops when ship is completely warped out or warped in. Used for both warp in and out.
302 
303  //Data "storage"
304  int stage_duration[WE_HOMEWORLD_NUM_STAGES];
305 
306  //anim
307  int anim;
308  int anim_nframes;
309  int anim_fps;
310 
311  //sound
312  int snd;
313  float snd_range_factor;
314  game_snd *snd_gs;
315 
316  //sweeper polygon and clip effect
317  vec3d pos;
318  vec3d fvec;
319  float width;
320  float width_full;
321  float height;
322  float height_full;
323  float z_offset_min;
324  float z_offset_max;
325 public:
326  WE_Homeworld(object *n_objp, int n_direction);
327  virtual ~WE_Homeworld();
328 
329  virtual int warpStart();
330  virtual int warpFrame(float frametime);
331  virtual int warpShipClip();
332  virtual int warpShipClip(model_render_params *render_info);
333  virtual int warpShipRender();
334  virtual int warpEnd();
335 
336  int getWarpPosition(vec3d *output);
337  int getWarpOrientation(matrix *output);
338 };
339 
340 //********************-----CLASS: WE_Hyperspace----********************//
341 class WE_Hyperspace : public WarpEffect
342 {
343 private:
344  //Total data
345  int total_time_start;
346  int total_duration;
347  int total_time_end;
348  float accel_exp;
349  float decel_exp;
350  float initial_velocity;
351 
352  //sweeper polygon and clip effect
353  vec3d pos_final;
354  float scale_factor;
355 public:
356  WE_Hyperspace(object *n_objp, int n_direction);
357 
358  virtual int warpStart();
359  virtual int warpFrame(float frametime);
360 };
361 
362 
363 #endif
virtual int warpStart()
Definition: shipfx.cpp:4478
virtual void pageIn()
Definition: shipfx.cpp:3466
int getWarpPosition(vec3d *output)
Definition: shipfx.cpp:3795
void shipfx_blow_up_model(object *obj, int model, int submodel, int ndebris, vec3d *exp_center)
Definition: shipfx.cpp:374
virtual int warpShipRender()
Definition: shipfx.cpp:4406
virtual int warpShipRender()
Definition: shipfx.cpp:4089
WE_Default(object *n_objp, int n_direction)
Definition: shipfx.cpp:3544
void shipfx_large_blowup_level_init()
Definition: shipfx.cpp:2009
WE_BSG(object *n_objp, int n_direction)
Definition: shipfx.cpp:3816
int warpShipClip()
Definition: shipfx.cpp:3771
virtual int warpStart()
Definition: shipfx.cpp:3473
Definition: pstypes.h:88
virtual int getWarpOrientation(matrix *output)
Definition: shipfx.cpp:3534
hull_check p0
Definition: lua.cpp:5051
void shipfx_large_blowup_queue_render(draw_list *scene, ship *shipp)
Definition: shipfx.cpp:2393
float shipfx_calculate_warp_time(object *objp, int warp_dir)
Definition: shipfx.cpp:474
void shipfx_large_blowup_init(ship *shipp)
Definition: shipfx.cpp:2019
int getWarpOrientation(matrix *output)
Definition: shipfx.cpp:3804
virtual void pageIn()
Definition: shipfx.cpp:3923
void shipfx_emit_spark(int n, int sn)
Definition: shipfx.cpp:1417
virtual int warpShipRender()
Definition: shipfx.cpp:3496
virtual int warpShipClip()
Definition: shipfx.cpp:3486
object * objp
Definition: lua.cpp:3105
void clear()
Definition: shipfx.cpp:3450
bool isValid()
Definition: shipfx.cpp:3458
void shipfx_blow_off_subsystem(object *ship_obj, ship *ship_p, ship_subsys *subsys, vec3d *exp_center, bool no_explosion=false)
Definition: shipfx.cpp:295
ship * shipp
Definition: lua.cpp:9162
virtual int warpEnd()
Definition: shipfx.cpp:3506
virtual int getWarpOrientation(matrix *output)
Definition: shipfx.cpp:4173
GLint GLsizei width
Definition: Gl.h:1505
~WE_BSG()
Definition: shipfx.cpp:3915
Definition: debris.h:23
void shipfx_flash_init()
Definition: shipfx.cpp:1216
void shipfx_flash_create(object *objp, int model_num, vec3d *gun_pos, vec3d *gun_dir, int is_primary, int weapon_info_index)
Definition: shipfx.cpp:1231
virtual int getWarpPosition(vec3d *output)
Definition: shipfx.cpp:3525
virtual int warpFrame(float frametime)
Definition: shipfx.cpp:3481
WE_Hyperspace(object *n_objp, int n_direction)
Definition: shipfx.cpp:4451
void shipfx_do_damaged_arcs_frame(ship *shipp)
Definition: shipfx.cpp:2417
virtual ~WE_Homeworld()
Definition: shipfx.cpp:4260
virtual int warpShipQueueRender(draw_list *scene)
Definition: shipfx.cpp:3501
void shipfx_start_cloak(ship *shipp, int warmup=5000, int recalc_transform=0, int device=0)
virtual int getWarpPosition(vec3d *output)
Definition: shipfx.cpp:4161
#define WE_BSG_NUM_STAGES
Definition: shipfx.h:232
virtual void pageOut()
Definition: shipfx.cpp:3469
virtual int warpFrame(float frametime)
Definition: shipfx.cpp:4507
virtual int warpShipClip()
Definition: shipfx.cpp:4059
int warpStart()
Definition: shipfx.cpp:3557
virtual ~WarpEffect()
Definition: shipfx.h:174
Definition: ship.h:534
vec3d eye_pos
Definition: fredrender.cpp:103
float shipfx_calc_visibility(object *obj, vec3d *view_pt)
object * objp
Definition: shipfx.h:165
#define WE_DEFAULT_NUM_STAGES
Definition: shipfx.h:196
ship_info * sip
Definition: shipfx.h:170
virtual int warpEnd()
Definition: shipfx.cpp:4149
GLclampd n
Definition: Glext.h:7286
bool shipfx_in_shadow(object *src_obj)
Definition: shipfx.cpp:926
Definition: object.h:141
int shipfx_large_blowup_do_frame(ship *shipp, float frametime)
Definition: shipfx.cpp:2325
int warpFrame(float frametime)
Definition: shipfx.cpp:3677
void shipfx_debris_limit_speed(struct debris *db, ship *shipp)
Definition: shipfx.cpp:2031
void shipfx_warpout_frame(object *objp, float frametime)
Definition: shipfx.cpp:848
float shipfx_calculate_warp_dist(object *objp)
Definition: shipfx.cpp:510
#define WE_HOMEWORLD_NUM_STAGES
Definition: shipfx.h:291
void shipfx_warpin_frame(object *objp, float frametime)
Definition: shipfx.cpp:605
void do_sub_expl_sound(float radius, vec3d *sound_pos, int *sound_handle)
Definition: shipfx.cpp:2190
virtual int warpFrame(float frametime)
Definition: shipfx.cpp:4013
void shipfx_warpout_start(object *objp)
Definition: shipfx.cpp:794
GLint GLsizei GLsizei height
Definition: Gl.h:1505
virtual int warpStart()
Definition: shipfx.cpp:4266
virtual int warpStart()
Definition: shipfx.cpp:3931
int submodel
Definition: lua.cpp:5007
void shipfx_large_blowup_render(ship *shipp)
Definition: shipfx.cpp:2374
void shipfx_do_lightning_frame(ship *shipp)
Definition: shipfx.cpp:2648
void shipfx_engine_wash_level_init()
Definition: shipfx.cpp:3106
WE_Homeworld(object *n_objp, int n_direction)
Definition: shipfx.cpp:4185
void shipfx_blow_up_hull(object *obj, int model, vec3d *exp_center)
Definition: shipfx.cpp:325
virtual int warpEnd()
Definition: shipfx.cpp:4423
virtual int warpFrame(float frametime)
Definition: shipfx.cpp:4322
bool shipfx_eye_in_shadow(vec3d *eye_pos, object *src_obj, int sun_n)
Definition: shipfx.cpp:977
GLsizei GLsizei GLuint * obj
Definition: Glext.h:5619
void shipfx_stop_engine_wash_sound()
Definition: shipfx.cpp:3114
ship * shipp
Definition: shipfx.h:169
void shipfx_warpin_start(object *objp)
Definition: shipfx.cpp:565
void shipfx_flash_do_frame(float frametime)
Definition: shipfx.cpp:1331
void shipfx_flash_light_model(object *objp, int model_num)
Definition: shipfx.cpp:1314
int warpShipRender()
Definition: shipfx.cpp:3790
Definition: shipfx.h:233
int model_num
Definition: lua.cpp:4996
void shipfx_cloak_frame(ship *shipp, float frametime)
int getWarpPosition(vec3d *output)
Definition: shipfx.cpp:4430
void shipfx_stop_cloak(ship *shipp, int warpdown=5000)
int direction
Definition: shipfx.h:166
virtual int warpShipClip()
Definition: shipfx.cpp:4388
bool shipfx_point_in_shadow(vec3d *p0, matrix *src_orient, vec3d *src_pos, float radius)
Definition: shipfx.cpp:874
void shipfx_do_shockwave_stuff(ship *shipp, shockwave_create_info *sci)
Definition: shipfx.cpp:2776
int getWarpOrientation(matrix *output)
Definition: shipfx.cpp:4439
Definition: sound.h:72