2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
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
10 * $Logfile: /Freespace2/code/Ship/ShipContrails.cpp $
15 * all sorts of cool stuff about ships
18 * Revision 1.3 2002/06/09 04:41:26 relnev
19 * added copyright header
21 * Revision 1.2 2002/05/07 03:16:52 theoddone33
22 * The Great Newline Fix
24 * Revision 1.1.1.1 2002/05/03 03:28:10 root
28 * 5 4/25/99 3:02p Dave
29 * Build defines for the E3 build.
31 * 4 4/20/99 6:39p Dave
32 * Almost done with artillery targeting. Added support for downloading
33 * images on the PXO screen.
35 * 3 4/12/99 11:03p Dave
36 * Removed contrails and muzzle flashes from MULTIPLAYER_BETA builds.
38 * 2 11/14/98 5:33p Dave
39 * Lots of nebula work. Put in ship contrails.
41 * 1 11/14/98 3:40p Dave
43 * 1 11/13/98 3:28p Dave
49 #include "shipcontrails.h"
54 #include "alphacolors.h"
57 #include "missionparse.h"
59 // ----------------------------------------------------------------------------------------------
60 // CONTRAIL DEFINES/VARS
63 // ----------------------------------------------------------------------------------------------
64 // CONTRAIL FORWARD DECLARATIONS
67 // if the object is below the limit for contrails
68 int ct_below_limit(object *objp);
70 // if an object has active contrails
71 int ct_has_contrails(ship *shipp);
73 // update active contrails - moving existing ones, adding new ones where necessary
74 void ct_update_contrails(ship *shipp);
76 // create new contrails
77 void ct_create_contrails(ship *shipp);
79 // ----------------------------------------------------------------------------------------------
83 // call during level initialization
88 // call during level shutdown
93 // call when a ship is created to initialize its contrail stuff
94 void ct_ship_create(ship *shipp)
97 SDL_assert(shipp != NULL);
99 // null out the ct indices for this guy
100 for(idx=0; idx<MAX_SHIP_CONTRAILS; idx++){
101 shipp->trail_num[idx] = (short)-1;
105 // call when a ship is deleted to free up its contrail stuff
106 void ct_ship_delete(ship *shipp)
110 SDL_assert(shipp != NULL);
111 // free up any contrails this guy may have had
112 for(idx=0; idx<MAX_SHIP_CONTRAILS; idx++){
113 if(shipp->trail_num[idx] >= 0){
114 trail_object_died(shipp->trail_num[idx]);
115 shipp->trail_num[idx] = (short)-1;
120 // call each frame for processing a ship's contrails
121 void ct_ship_process(ship *shipp)
123 #ifdef MULTIPLAYER_BETA_BUILD
129 SDL_assert(shipp != NULL);
130 SDL_assert(shipp->objnum >= 0);
131 objp = &Objects[shipp->objnum];
133 // if not a fullneb mission - do nothing
134 if(!(The_mission.flags & MISSION_FLAG_FULLNEB)){
138 // if this is not a ship, we don't care
139 if((objp->type != OBJ_SHIP) || (Ship_info[Ships[objp->instance].ship_info_index].ct_count <= 0)){
143 SDL_assert(objp->instance >= 0);
144 shipp = &Ships[objp->instance];
146 // if the object is below the critical limit
147 if(ct_below_limit(objp)){
148 // kill any active trails he has
149 for(idx=0; idx<MAX_SHIP_CONTRAILS; idx++){
150 if(shipp->trail_num[idx] >= 0){
151 trail_object_died(shipp->trail_num[idx]);
152 shipp->trail_num[idx] = (short)-1;
160 // if the object already has contrails
161 if(ct_has_contrails(shipp)){
162 ct_update_contrails(shipp);
164 // otherwise add new ones
166 ct_create_contrails(shipp);
171 // ----------------------------------------------------------------------------------------------
172 // CONTRAIL FORWARD DEFINITIONS - test stuff
175 // if the object is below the limit for contrails
176 int ct_below_limit(object *objp)
178 return objp->phys_info.fspeed < 45.0f;
181 // if a ship has active contrails
182 int ct_has_contrails(ship *shipp)
186 for(idx=0; idx<MAX_SHIP_CONTRAILS; idx++){
187 if(shipp->trail_num[idx] >= 0){
196 // update active contrails - moving existing ones, adding new ones where necessary
197 void ct_update_contrails(ship *shipp)
199 #ifdef MULTIPLAYER_BETA_BUILD
208 // if not a fullneb mission - do nothing
209 if(!(The_mission.flags & MISSION_FLAG_FULLNEB)){
213 // get object and ship info
214 SDL_assert(shipp != NULL);
215 SDL_assert(shipp->objnum >= 0);
216 SDL_assert(shipp->ship_info_index >= 0);
217 objp = &Objects[shipp->objnum];
218 sip = &Ship_info[shipp->ship_info_index];
220 // get the inverse rotation matrix
221 vm_copy_transpose_matrix(&m, &objp->orient);
223 // process each contrail
224 for(idx=0; idx<MAX_SHIP_CONTRAILS; idx++){
225 // if this is a valid contrail
226 if(shipp->trail_num[idx] >= 0){
227 // get the point for the contrail
228 vm_vec_rotate(&v1, &sip->ct_info[idx].pt, &m);
229 vm_vec_add2(&v1, &objp->pos);
231 // if the spew stamp has elapsed
232 if(trail_stamp_elapsed(shipp->trail_num[idx])){
233 trail_add_segment(shipp->trail_num[idx], &v1);
234 trail_set_stamp(shipp->trail_num[idx]);
236 trail_set_segment(shipp->trail_num[idx], &v1);
243 // create new contrails
244 void ct_create_contrails(ship *shipp)
246 #ifdef MULTIPLAYER_BETA_BUILD
255 // if not a fullneb mission - do nothing
256 if(!(The_mission.flags & MISSION_FLAG_FULLNEB)){
260 // get object and ship info
261 SDL_assert(shipp != NULL);
262 SDL_assert(shipp->objnum >= 0);
263 SDL_assert(shipp->ship_info_index >= 0);
264 objp = &Objects[shipp->objnum];
265 sip = &Ship_info[shipp->ship_info_index];
267 // get the inverse rotation matrix
268 vm_copy_transpose_matrix(&m, &objp->orient);
270 for(idx=0; idx<sip->ct_count; idx++){
271 shipp->trail_num[idx] = (short)trail_create(sip->ct_info[idx]);
274 vm_vec_rotate(&v1, &sip->ct_info[idx].pt, &m);
275 vm_vec_add2(&v1, &objp->pos);
276 trail_add_segment(shipp->trail_num[idx], &v1);
277 trail_add_segment(shipp->trail_num[idx], &v1);