2 * $Logfile: /Freespace2/code/Ship/ShipContrails.cpp $
7 * all sorts of cool stuff about ships
10 * Revision 1.1 2002/05/03 03:28:10 root
14 * 5 4/25/99 3:02p Dave
15 * Build defines for the E3 build.
17 * 4 4/20/99 6:39p Dave
18 * Almost done with artillery targeting. Added support for downloading
19 * images on the PXO screen.
21 * 3 4/12/99 11:03p Dave
22 * Removed contrails and muzzle flashes from MULTIPLAYER_BETA builds.
24 * 2 11/14/98 5:33p Dave
25 * Lots of nebula work. Put in ship contrails.
27 * 1 11/14/98 3:40p Dave
29 * 1 11/13/98 3:28p Dave
35 #include "shipcontrails.h"
40 #include "alphacolors.h"
43 #include "missionparse.h"
45 // ----------------------------------------------------------------------------------------------
46 // CONTRAIL DEFINES/VARS
49 // ----------------------------------------------------------------------------------------------
50 // CONTRAIL FORWARD DECLARATIONS
53 // if the object is below the limit for contrails
54 int ct_below_limit(object *objp);
56 // if an object has active contrails
57 int ct_has_contrails(ship *shipp);
59 // update active contrails - moving existing ones, adding new ones where necessary
60 void ct_update_contrails(ship *shipp);
62 // create new contrails
63 void ct_create_contrails(ship *shipp);
65 // ----------------------------------------------------------------------------------------------
69 // call during level initialization
74 // call during level shutdown
79 // call when a ship is created to initialize its contrail stuff
80 void ct_ship_create(ship *shipp)
83 Assert(shipp != NULL);
85 // null out the ct indices for this guy
86 for(idx=0; idx<MAX_SHIP_CONTRAILS; idx++){
87 shipp->trail_num[idx] = (short)-1;
91 // call when a ship is deleted to free up its contrail stuff
92 void ct_ship_delete(ship *shipp)
96 Assert(shipp != NULL);
97 // free up any contrails this guy may have had
98 for(idx=0; idx<MAX_SHIP_CONTRAILS; idx++){
99 if(shipp->trail_num[idx] >= 0){
100 trail_object_died(shipp->trail_num[idx]);
101 shipp->trail_num[idx] = (short)-1;
106 // call each frame for processing a ship's contrails
107 void ct_ship_process(ship *shipp)
109 #ifdef MULTIPLAYER_BETA_BUILD
115 Assert(shipp != NULL);
116 Assert(shipp->objnum >= 0);
117 objp = &Objects[shipp->objnum];
119 // if not a fullneb mission - do nothing
120 if(!(The_mission.flags & MISSION_FLAG_FULLNEB)){
124 // if this is not a ship, we don't care
125 if((objp->type != OBJ_SHIP) || (Ship_info[Ships[objp->instance].ship_info_index].ct_count <= 0)){
129 Assert(objp->instance >= 0);
130 shipp = &Ships[objp->instance];
132 // if the object is below the critical limit
133 if(ct_below_limit(objp)){
134 // kill any active trails he has
135 for(idx=0; idx<MAX_SHIP_CONTRAILS; idx++){
136 if(shipp->trail_num[idx] >= 0){
137 trail_object_died(shipp->trail_num[idx]);
138 shipp->trail_num[idx] = (short)-1;
146 // if the object already has contrails
147 if(ct_has_contrails(shipp)){
148 ct_update_contrails(shipp);
150 // otherwise add new ones
152 ct_create_contrails(shipp);
157 // ----------------------------------------------------------------------------------------------
158 // CONTRAIL FORWARD DEFINITIONS - test stuff
161 // if the object is below the limit for contrails
162 int ct_below_limit(object *objp)
164 return objp->phys_info.fspeed < 45.0f;
167 // if a ship has active contrails
168 int ct_has_contrails(ship *shipp)
172 for(idx=0; idx<MAX_SHIP_CONTRAILS; idx++){
173 if(shipp->trail_num[idx] >= 0){
182 // update active contrails - moving existing ones, adding new ones where necessary
183 void ct_update_contrails(ship *shipp)
185 #ifdef MULTIPLAYER_BETA_BUILD
194 // if not a fullneb mission - do nothing
195 if(!(The_mission.flags & MISSION_FLAG_FULLNEB)){
199 // get object and ship info
200 Assert(shipp != NULL);
201 Assert(shipp->objnum >= 0);
202 Assert(shipp->ship_info_index >= 0);
203 objp = &Objects[shipp->objnum];
204 sip = &Ship_info[shipp->ship_info_index];
206 // get the inverse rotation matrix
207 vm_copy_transpose_matrix(&m, &objp->orient);
209 // process each contrail
210 for(idx=0; idx<MAX_SHIP_CONTRAILS; idx++){
211 // if this is a valid contrail
212 if(shipp->trail_num[idx] >= 0){
213 // get the point for the contrail
214 vm_vec_rotate(&v1, &sip->ct_info[idx].pt, &m);
215 vm_vec_add2(&v1, &objp->pos);
217 // if the spew stamp has elapsed
218 if(trail_stamp_elapsed(shipp->trail_num[idx])){
219 trail_add_segment(shipp->trail_num[idx], &v1);
220 trail_set_stamp(shipp->trail_num[idx]);
222 trail_set_segment(shipp->trail_num[idx], &v1);
229 // create new contrails
230 void ct_create_contrails(ship *shipp)
232 #ifdef MULTIPLAYER_BETA_BUILD
241 // if not a fullneb mission - do nothing
242 if(!(The_mission.flags & MISSION_FLAG_FULLNEB)){
246 // get object and ship info
247 Assert(shipp != NULL);
248 Assert(shipp->objnum >= 0);
249 Assert(shipp->ship_info_index >= 0);
250 objp = &Objects[shipp->objnum];
251 sip = &Ship_info[shipp->ship_info_index];
253 // get the inverse rotation matrix
254 vm_copy_transpose_matrix(&m, &objp->orient);
256 for(idx=0; idx<sip->ct_count; idx++){
257 shipp->trail_num[idx] = (short)trail_create(sip->ct_info[idx]);
260 vm_vec_rotate(&v1, &sip->ct_info[idx].pt, &m);
261 vm_vec_add2(&v1, &objp->pos);
262 trail_add_segment(shipp->trail_num[idx], &v1);
263 trail_add_segment(shipp->trail_num[idx], &v1);