2 * $Logfile: /Freespace2/code/Ship/ShipContrails.cpp $
7 * all sorts of cool stuff about ships
10 * Revision 1.2 2002/05/07 03:16:52 theoddone33
11 * The Great Newline Fix
13 * Revision 1.1.1.1 2002/05/03 03:28:10 root
17 * 5 4/25/99 3:02p Dave
18 * Build defines for the E3 build.
20 * 4 4/20/99 6:39p Dave
21 * Almost done with artillery targeting. Added support for downloading
22 * images on the PXO screen.
24 * 3 4/12/99 11:03p Dave
25 * Removed contrails and muzzle flashes from MULTIPLAYER_BETA builds.
27 * 2 11/14/98 5:33p Dave
28 * Lots of nebula work. Put in ship contrails.
30 * 1 11/14/98 3:40p Dave
32 * 1 11/13/98 3:28p Dave
38 #include "shipcontrails.h"
43 #include "alphacolors.h"
46 #include "missionparse.h"
48 // ----------------------------------------------------------------------------------------------
49 // CONTRAIL DEFINES/VARS
52 // ----------------------------------------------------------------------------------------------
53 // CONTRAIL FORWARD DECLARATIONS
56 // if the object is below the limit for contrails
57 int ct_below_limit(object *objp);
59 // if an object has active contrails
60 int ct_has_contrails(ship *shipp);
62 // update active contrails - moving existing ones, adding new ones where necessary
63 void ct_update_contrails(ship *shipp);
65 // create new contrails
66 void ct_create_contrails(ship *shipp);
68 // ----------------------------------------------------------------------------------------------
72 // call during level initialization
77 // call during level shutdown
82 // call when a ship is created to initialize its contrail stuff
83 void ct_ship_create(ship *shipp)
86 Assert(shipp != NULL);
88 // null out the ct indices for this guy
89 for(idx=0; idx<MAX_SHIP_CONTRAILS; idx++){
90 shipp->trail_num[idx] = (short)-1;
94 // call when a ship is deleted to free up its contrail stuff
95 void ct_ship_delete(ship *shipp)
99 Assert(shipp != NULL);
100 // free up any contrails this guy may have had
101 for(idx=0; idx<MAX_SHIP_CONTRAILS; idx++){
102 if(shipp->trail_num[idx] >= 0){
103 trail_object_died(shipp->trail_num[idx]);
104 shipp->trail_num[idx] = (short)-1;
109 // call each frame for processing a ship's contrails
110 void ct_ship_process(ship *shipp)
112 #ifdef MULTIPLAYER_BETA_BUILD
118 Assert(shipp != NULL);
119 Assert(shipp->objnum >= 0);
120 objp = &Objects[shipp->objnum];
122 // if not a fullneb mission - do nothing
123 if(!(The_mission.flags & MISSION_FLAG_FULLNEB)){
127 // if this is not a ship, we don't care
128 if((objp->type != OBJ_SHIP) || (Ship_info[Ships[objp->instance].ship_info_index].ct_count <= 0)){
132 Assert(objp->instance >= 0);
133 shipp = &Ships[objp->instance];
135 // if the object is below the critical limit
136 if(ct_below_limit(objp)){
137 // kill any active trails he has
138 for(idx=0; idx<MAX_SHIP_CONTRAILS; idx++){
139 if(shipp->trail_num[idx] >= 0){
140 trail_object_died(shipp->trail_num[idx]);
141 shipp->trail_num[idx] = (short)-1;
149 // if the object already has contrails
150 if(ct_has_contrails(shipp)){
151 ct_update_contrails(shipp);
153 // otherwise add new ones
155 ct_create_contrails(shipp);
160 // ----------------------------------------------------------------------------------------------
161 // CONTRAIL FORWARD DEFINITIONS - test stuff
164 // if the object is below the limit for contrails
165 int ct_below_limit(object *objp)
167 return objp->phys_info.fspeed < 45.0f;
170 // if a ship has active contrails
171 int ct_has_contrails(ship *shipp)
175 for(idx=0; idx<MAX_SHIP_CONTRAILS; idx++){
176 if(shipp->trail_num[idx] >= 0){
185 // update active contrails - moving existing ones, adding new ones where necessary
186 void ct_update_contrails(ship *shipp)
188 #ifdef MULTIPLAYER_BETA_BUILD
197 // if not a fullneb mission - do nothing
198 if(!(The_mission.flags & MISSION_FLAG_FULLNEB)){
202 // get object and ship info
203 Assert(shipp != NULL);
204 Assert(shipp->objnum >= 0);
205 Assert(shipp->ship_info_index >= 0);
206 objp = &Objects[shipp->objnum];
207 sip = &Ship_info[shipp->ship_info_index];
209 // get the inverse rotation matrix
210 vm_copy_transpose_matrix(&m, &objp->orient);
212 // process each contrail
213 for(idx=0; idx<MAX_SHIP_CONTRAILS; idx++){
214 // if this is a valid contrail
215 if(shipp->trail_num[idx] >= 0){
216 // get the point for the contrail
217 vm_vec_rotate(&v1, &sip->ct_info[idx].pt, &m);
218 vm_vec_add2(&v1, &objp->pos);
220 // if the spew stamp has elapsed
221 if(trail_stamp_elapsed(shipp->trail_num[idx])){
222 trail_add_segment(shipp->trail_num[idx], &v1);
223 trail_set_stamp(shipp->trail_num[idx]);
225 trail_set_segment(shipp->trail_num[idx], &v1);
232 // create new contrails
233 void ct_create_contrails(ship *shipp)
235 #ifdef MULTIPLAYER_BETA_BUILD
244 // if not a fullneb mission - do nothing
245 if(!(The_mission.flags & MISSION_FLAG_FULLNEB)){
249 // get object and ship info
250 Assert(shipp != NULL);
251 Assert(shipp->objnum >= 0);
252 Assert(shipp->ship_info_index >= 0);
253 objp = &Objects[shipp->objnum];
254 sip = &Ship_info[shipp->ship_info_index];
256 // get the inverse rotation matrix
257 vm_copy_transpose_matrix(&m, &objp->orient);
259 for(idx=0; idx<sip->ct_count; idx++){
260 shipp->trail_num[idx] = (short)trail_create(sip->ct_info[idx]);
263 vm_vec_rotate(&v1, &sip->ct_info[idx].pt, &m);
264 vm_vec_add2(&v1, &objp->pos);
265 trail_add_segment(shipp->trail_num[idx], &v1);
266 trail_add_segment(shipp->trail_num[idx], &v1);