FS2_Open
Open source remastering of the Freespace 2 engine
shipcontrails.cpp
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 #include "mission/missionparse.h"
13 #include "ship/ship.h"
14 #include "ship/shipcontrails.h"
15 
16 
17 
18 // ----------------------------------------------------------------------------------------------
19 // CONTRAIL DEFINES/VARS
20 //
21 
22 // ----------------------------------------------------------------------------------------------
23 // CONTRAIL FORWARD DECLARATIONS
24 //
25 
26 // if the object is below the limit for contrails
27 int ct_below_limit(object *objp);
28 
29 // Goober0500
31 
32 // if an object has active contrails
34 
35 // update active contrails - moving existing ones, adding new ones where necessary
37 
38 // create new contrails
40 
41 
42 // determine if the ship has AB trails
44 
45 // update active ABtrails - moving existing ones, adding new ones where necessary
47 
48 // create new ABtrails
50 
52 
53 // ----------------------------------------------------------------------------------------------
54 // CONTRAIL FUNCTIONS
55 //
56 
57 // call during level initialization
59 {
60 }
61 
62 // call during level shutdown
64 {
65 }
66 
67 // call when a ship is created to initialize its contrail stuff
69 {
70  int idx;
71  Assert(shipp != NULL);
72 
73  // null out the ct indices for this guy
74  for(idx=0; idx<MAX_SHIP_CONTRAILS; idx++){
75  shipp->trail_ptr[idx] = NULL;
76  }
77 
78  for(idx=0; idx<MAX_SHIP_CONTRAILS; idx++){
79  shipp->ABtrail_ptr[idx] = NULL;
80  }
81 
82 
83 }
84 
85 // call when a ship is deleted to free up its contrail stuff
87 {
88  int idx;
89 
90  Assert(shipp != NULL);
91  // free up any contrails this guy may have had
92  for(idx=0; idx<MAX_SHIP_CONTRAILS; idx++){
93  if(shipp->trail_ptr[idx] != NULL){
94  trail_object_died(shipp->trail_ptr[idx]);
95  shipp->trail_ptr[idx] = NULL;
96  }
97  if(shipp->ABtrail_ptr[idx] != NULL){
98  trail_object_died(shipp->ABtrail_ptr[idx]);
99  shipp->ABtrail_ptr[idx] = NULL;
100  }
101  }
102 }
103 
104 // call each frame for processing a ship's contrails
106 {
107  // seems like as good a place as any -Bobboau
108  if (shipp->ab_info[0].texture.bitmap_id != -1)
110 
111  Assert(shipp != NULL);
112  Assert(shipp->objnum >= 0);
113 
114  // if trails aren't enabled, return
115  if (!ct_display_contrails()) {
116  return;
117  }
118 
119  int idx;
120  object *objp;
121  objp = &Objects[shipp->objnum];
122 
123  // if this is not a ship, we don't care
124  if((objp->type != OBJ_SHIP) || (Ship_info[Ships[objp->instance].ship_info_index].ct_count <= 0)){
125  return;
126  }
127 
128  Assert(objp->instance >= 0);
129  shipp = &Ships[objp->instance];
130 
131  // if the object is below the critical limit
132  if(ct_below_limit(objp)){
133  // kill any active trails he has
134  for(idx=0; idx<MAX_SHIP_CONTRAILS; idx++){
135  if(shipp->trail_ptr[idx] != NULL){
136  trail_object_died(shipp->trail_ptr[idx]);
137  shipp->trail_ptr[idx] = NULL;
138  }
139  }
140 
141  // don't create or update trails if we're not moving fast enough
142  return;
143  }
144 
145 
146  // if the object already has contrails
147  if(ct_has_contrails(shipp)){
148  ct_update_contrails(shipp);
149  }
150  // otherwise add new ones
151  else {
152  ct_create_contrails(shipp);
153  }
154 }
155 
156 // ----------------------------------------------------------------------------------------------
157 // CONTRAIL FORWARD DEFINITIONS - test stuff
158 //
159 
160 // if the object is below the limit for contrails
161 int ct_below_limit(object *objp)
162 {
164 }
165 
166 // if a ship has active contrails
168 {
169  int idx;
170 
171  for(idx=0; idx<MAX_SHIP_CONTRAILS; idx++){
172  if(shipp->trail_ptr[idx] != NULL){
173  return 1;
174  }
175  }
176 
177  // no contrails
178  return 0;
179 }
180 
181 // update active contrails - moving existing ones, adding new ones where necessary
183 {
184  // if trails aren't enabled, return
185  if (!ct_display_contrails()) {
186  return;
187  }
188 
189  vec3d v1;
190  int idx;
191  ship_info *sip;
192  object *objp;
193 
194  // get object and ship info
195  Assert(shipp != NULL);
196  Assert(shipp->objnum >= 0);
197  Assert(shipp->ship_info_index >= 0);
198  objp = &Objects[shipp->objnum];
199  sip = &Ship_info[shipp->ship_info_index];
200 
201  // process each contrail
202  for(idx=0; idx<MAX_SHIP_CONTRAILS; idx++){
203  // if this is a valid contrail
204  if(shipp->trail_ptr[idx] != NULL){
205  // get the point for the contrail
206  vm_vec_unrotate(&v1, &sip->ct_info[idx].pt, &objp->orient);
207  vm_vec_add2(&v1, &objp->pos);
208 
209  // if the spew stamp has elapsed
210  if(trail_stamp_elapsed(shipp->trail_ptr[idx])){
211  trail_add_segment(shipp->trail_ptr[idx], &v1);
212  trail_set_stamp(shipp->trail_ptr[idx]);
213  } else {
214  trail_set_segment(shipp->trail_ptr[idx], &v1);
215  }
216  }
217  }
218 }
219 
220 // create new contrails
222 {
223 #ifdef MULTIPLAYER_BETA_BUILD
224  return;
225 #else
226 
227  // if trails aren't enabled, return
228  if (!ct_display_contrails()) {
229  return;
230  }
231 
232  vec3d v1;
233  int idx;
234  ship_info *sip;
235  object *objp;
236 
237  // get object and ship info
238  Assert(shipp != NULL);
239  Assert(shipp->objnum >= 0);
240  Assert(shipp->ship_info_index >= 0);
241  objp = &Objects[shipp->objnum];
242  sip = &Ship_info[shipp->ship_info_index];
243 
244 
245  for(idx=0; idx<sip->ct_count; idx++)
246  {
247  //if (this is a neb mision and this is a neb trail) or an ABtrail -Bobboau
248  shipp->trail_ptr[idx] = trail_create(&sip->ct_info[idx]);
249 
250  if(shipp->trail_ptr[idx] != NULL)
251  {
252  // add the point
253  vm_vec_unrotate(&v1, &sip->ct_info[idx].pt, &objp->orient);
254  vm_vec_add2(&v1, &objp->pos);
255  trail_add_segment(shipp->trail_ptr[idx], &v1);
256  trail_add_segment(shipp->trail_ptr[idx], &v1);
257  }
258  }
259 
260 #endif
261 }
262 
263 
264 // call each frame for processing a ship's ABtrails
266 {
267  int idx;
268  object *objp;
269  ship_info* sip;
270 
271  Assert(shipp != NULL);
272  Assert(shipp->objnum >= 0);
273  objp = &Objects[shipp->objnum];
274  sip=&Ship_info[shipp->ship_info_index];
275 
276  // if this is not a ship, we don't care
277  if((objp->type != OBJ_SHIP) || (Ships[objp->instance].ab_count <= 0)){
278  return;
279  }
280 
281  // if the ship has no afterburner trail bitmap, don't bother with anything
282  if (sip->afterburner_trail.bitmap_id < 0)
283  return;
284 
285 
286  Assert(objp->instance >= 0);
287  shipp = &Ships[objp->instance];
288 
289 
290  if(!(objp->phys_info.flags & PF_AFTERBURNER_ON)){ //if the after burners aren't on -Bobboau
291  for(idx=0; idx<MAX_SHIP_CONTRAILS; idx++){
292  if(shipp->ABtrail_ptr[idx] != NULL)
293  {
294  trail_object_died(shipp->ABtrail_ptr[idx]);
295  shipp->ABtrail_ptr[idx] = NULL;
296  }
297  }
298 
299  //No more abtrails
300  return;
301  }
302 
303  // if the object already has ABtrails
304  if(ct_has_ABtrails(shipp)){
305  ct_update_ABtrails(shipp);
306  }
307  // otherwise add new ones
308  else {
309  ct_create_ABtrails(shipp);
310  }
311 
312 /* if(shipp->ab_info->stamp > timestamp( (int)(shipp->ab_info->max_life * 1000) ) ){
313  for(idx=0; idx<MAX_SHIP_CONTRAILS; idx++){
314  if(shipp->ABtrail_num[idx] >= 0){
315  trail_object_died(shipp->ABtrail_num[idx]);
316  shipp->ABtrail_num[idx] = (short)-1;
317  }
318  }
319  }
320 */
321 }
322 
323 
324 
325 // create new ABtrails
327 {
328  vec3d v1;
329  int idx;
330  ship_info *sip;
331  object *objp;
332 
333  // get object and ship info
334  Assert(shipp != NULL);
335  Assert(shipp->objnum >= 0);
336  Assert(shipp->ship_info_index >= 0);
337  objp = &Objects[shipp->objnum];
338  sip = &Ship_info[shipp->ship_info_index];
339 
340  // if the ship has no afterburner trail bitmap, don't bother with anything
341  if (sip->afterburner_trail.bitmap_id < 0)
342  return;
343 
344  if(objp->phys_info.flags & PF_AFTERBURNER_ON){//AB trails-Bobboau
345 
346  for(idx=0; idx<shipp->ab_count; idx++)
347  {
348 
349  shipp->ABtrail_ptr[idx] = trail_create(&shipp->ab_info[idx]);
350  if(shipp->ABtrail_ptr[idx] != NULL)
351  {
352  // get the point for the contrail
353  vm_vec_unrotate(&v1, &shipp->ab_info[idx].pt, &objp->orient);
354  vm_vec_add2(&v1, &objp->pos);
355  // if the spew stamp has elapsed
356  if(trail_stamp_elapsed(shipp->ABtrail_ptr[idx])){
357  trail_add_segment(shipp->ABtrail_ptr[idx], &v1);
358  trail_set_stamp(shipp->ABtrail_ptr[idx]);
359  } else {
360  trail_set_segment(shipp->ABtrail_ptr[idx], &v1);
361  }
362  }
363  }
364 /* if( objp == Player_obj){
365  HUD_printf("trailnum %d", shipp->ABtrail_num[0]);
366  }
367 */
368 
369  }
370 }
371 
372 // update active ABtrails - moving existing ones, adding new ones where necessary
374 {
375  vec3d v1;
376  int idx;
377  ship_info *sip;
378  object *objp;
379 
380  // get object and ship info
381  Assert(shipp != NULL);
382  Assert(shipp->objnum >= 0);
383  Assert(shipp->ship_info_index >= 0);
384  objp = &Objects[shipp->objnum];
385  sip = &Ship_info[shipp->ship_info_index];
386 
387  // if the ship has no afterburner trail bitmap, don't bother with anything
388  if (sip->afterburner_trail.bitmap_id < 0)
389  return;
390 
391  for(idx=0; idx<MAX_SHIP_CONTRAILS; idx++){
392  if(objp->phys_info.flags & PF_AFTERBURNER_ON){//ABtrails
393  if(shipp->ABtrail_ptr[idx] != NULL){
394  // get the point for the contrail
395  vm_vec_unrotate(&v1, &shipp->ab_info[idx].pt, &objp->orient);
396  vm_vec_add2(&v1, &objp->pos);
397 
398  // if the spew stamp has elapsed
399  if(trail_stamp_elapsed(shipp->ABtrail_ptr[idx])){
400  trail_add_segment(shipp->ABtrail_ptr[idx], &v1);
401  trail_set_stamp(shipp->ABtrail_ptr[idx]);
402  } else {
403  trail_set_segment(shipp->ABtrail_ptr[idx], &v1);
404  }
405  }
406  }
407 
408  }
409 }
410 
411 
412 // if a ship has active ABtrails
414 {
415  int idx;
416  ship_info* sip=&Ship_info[shipp->ship_info_index];
417 
418  // if the ship has no afterburner trail bitmap, don't bother with anything
419  if (sip->afterburner_trail.bitmap_id < 0)
420  return 0;
421 
422  for(idx=0; idx<MAX_SHIP_CONTRAILS; idx++){
423  if(shipp->ABtrail_ptr[idx] != NULL){
424  return 1;
425  }
426  }
427 
428 
429  // no contrails
430  return 0;
431 }
432 
434 {
435  bool display;
436 
437  // normally display trails in a full nebula environment
438  display = (The_mission.flags & MISSION_FLAG_FULLNEB) ? true : false;
439 
440  // toggle according to flag
442  display = !display;
443 
444  return display;
445 }
void ct_ship_process(ship *shipp)
int objnum
Definition: ship.h:537
#define MISSION_FLAG_FULLNEB
Definition: missionparse.h:70
physics_info phys_info
Definition: object.h:157
int trail_stamp_elapsed(trail *trailp)
Definition: trails.cpp:572
void ct_ship_create(ship *shipp)
Assert(pm!=NULL)
int ct_count
Definition: ship.h:1355
Definition: pstypes.h:88
void ct_level_close()
void trail_object_died(trail *trailp)
Definition: trails.cpp:551
int bitmap_id
Definition: generic.h:53
object * objp
Definition: lua.cpp:3105
ship * shipp
Definition: lua.cpp:9162
vec3d pos
Definition: object.h:152
int instance
Definition: object.h:150
void vm_vec_add2(vec3d *dest, const vec3d *src)
Definition: vecmat.cpp:178
trail_info ab_info[MAX_SHIP_CONTRAILS]
Definition: ship.h:759
generic_bitmap afterburner_trail
Definition: ship.h:1369
trail * ABtrail_ptr[MAX_SHIP_CONTRAILS]
Definition: ship.h:758
vec3d pt
Definition: trails.h:23
int ct_below_limit(object *objp)
Definition: ship.h:534
int idx
Definition: multiui.cpp:761
trail_info ct_info[MAX_SHIP_CONTRAILS]
Definition: ship.h:1354
trail * trail_ptr[MAX_SHIP_CONTRAILS]
Definition: ship.h:721
vec3d * vm_vec_unrotate(vec3d *dest, const vec3d *src, const matrix *m)
Definition: vecmat.cpp:959
object Objects[MAX_OBJECTS]
Definition: object.cpp:62
uint flags
Definition: physics.h:37
void trail_add_segment(trail *trailp, vec3d *pos)
Definition: trails.cpp:480
void ct_ship_process_ABtrails(ship *shipp)
matrix orient
Definition: object.h:153
void ct_update_ABtrails(ship *shipp)
#define OBJ_SHIP
Definition: object.h:32
GLfloat GLfloat v1
Definition: Glext.h:5639
int ct_has_contrails(ship *shipp)
trail * trail_create(trail_info *info)
Definition: trails.cpp:52
float fspeed
Definition: physics.h:80
ship Ships[MAX_SHIPS]
Definition: ship.cpp:122
typedef float(SCP_EXT_CALLCONV *SCPTRACKIR_PFFLOATVOID)()
void ct_create_contrails(ship *shipp)
#define MISSION_FLAG_TOGGLE_SHIP_TRAILS
Definition: missionparse.h:73
void ct_update_contrails(ship *shipp)
void trail_set_stamp(trail *trailp)
Definition: trails.cpp:577
int ship_info_index
Definition: ship.h:539
SCP_vector< ship_info > Ship_info
Definition: ship.cpp:164
void ct_level_init()
int ab_count
Definition: ship.h:760
int ct_has_ABtrails(ship *shipp)
void trail_set_segment(trail *trailp, vec3d *pos)
Definition: trails.cpp:498
#define MAX_SHIP_CONTRAILS
Definition: ship.h:520
#define PF_AFTERBURNER_ON
Definition: physics.h:20
int contrail_threshold
Definition: missionparse.h:151
mission The_mission
void ct_ship_delete(ship *shipp)
char type
Definition: object.h:146
generic_bitmap texture
Definition: trails.h:30
bool ct_display_contrails()
void ct_create_ABtrails(ship *shipp)