]> icculus.org git repositories - taylor/freespace2.git/blob - src/ship/shipcontrails.cpp
The Great Newline Fix
[taylor/freespace2.git] / src / ship / shipcontrails.cpp
1 /*
2  * $Logfile: /Freespace2/code/Ship/ShipContrails.cpp $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * all sorts of cool stuff about ships
8  *
9  * $Log$
10  * Revision 1.2  2002/05/07 03:16:52  theoddone33
11  * The Great Newline Fix
12  *
13  * Revision 1.1.1.1  2002/05/03 03:28:10  root
14  * Initial import.
15  *
16  * 
17  * 5     4/25/99 3:02p Dave
18  * Build defines for the E3 build.
19  * 
20  * 4     4/20/99 6:39p Dave
21  * Almost done with artillery targeting. Added support for downloading
22  * images on the PXO screen.
23  * 
24  * 3     4/12/99 11:03p Dave
25  * Removed contrails and muzzle flashes from MULTIPLAYER_BETA builds.
26  * 
27  * 2     11/14/98 5:33p Dave
28  * Lots of nebula work. Put in ship contrails.
29  * 
30  * 1     11/14/98 3:40p Dave
31  * 
32  * 1     11/13/98 3:28p Dave
33  * 
34  * 
35  * $NoKeywords: $
36  */
37
38 #include "shipcontrails.h"
39 #include "object.h"
40 #include "ship.h"
41 #include "linklist.h"
42 #include "3d.h"
43 #include "alphacolors.h"
44 #include "trails.h"
45 #include "bmpman.h"
46 #include "missionparse.h"
47
48 // ----------------------------------------------------------------------------------------------
49 // CONTRAIL DEFINES/VARS
50 //
51
52 // ----------------------------------------------------------------------------------------------
53 // CONTRAIL FORWARD DECLARATIONS
54 //
55
56 // if the object is below the limit for contrails
57 int ct_below_limit(object *objp);
58
59 // if an object has active contrails
60 int ct_has_contrails(ship *shipp);
61
62 // update active contrails - moving existing ones, adding new ones where necessary
63 void ct_update_contrails(ship *shipp);
64
65 // create new contrails
66 void ct_create_contrails(ship *shipp);
67
68 // ----------------------------------------------------------------------------------------------
69 // CONTRAIL FUNCTIONS
70 //
71
72 // call during level initialization
73 void ct_level_init()
74 {       
75 }
76
77 // call during level shutdown
78 void ct_level_close()
79 {       
80 }
81
82 // call when a ship is created to initialize its contrail stuff
83 void ct_ship_create(ship *shipp)
84 {
85         int idx;
86         Assert(shipp != NULL);
87
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;
91         }
92 }
93
94 // call when a ship is deleted to free up its contrail stuff
95 void ct_ship_delete(ship *shipp)
96 {
97         int idx;                
98
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;
105                 }
106         }
107 }
108
109 // call each frame for processing a ship's contrails
110 void ct_ship_process(ship *shipp)
111 {
112 #ifdef MULTIPLAYER_BETA_BUILD
113         return;
114 #else
115         int idx;                
116         object *objp;
117
118         Assert(shipp != NULL);
119         Assert(shipp->objnum >= 0);
120         objp = &Objects[shipp->objnum];
121
122         // if not a fullneb mission - do nothing
123         if(!(The_mission.flags & MISSION_FLAG_FULLNEB)){
124                 return;
125         }
126
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)){
129                 return;
130         }
131
132         Assert(objp->instance >= 0);
133         shipp = &Ships[objp->instance];
134
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;
142                         }
143                 }
144
145                 // were done
146                 return;
147         }       
148
149         // if the object already has contrails
150         if(ct_has_contrails(shipp)){
151                 ct_update_contrails(shipp);
152         }
153         // otherwise add new ones
154         else {
155                 ct_create_contrails(shipp);
156         }
157 #endif
158 }
159
160 // ----------------------------------------------------------------------------------------------
161 // CONTRAIL FORWARD DEFINITIONS - test stuff
162 //
163
164 // if the object is below the limit for contrails
165 int ct_below_limit(object *objp)
166 {
167         return objp->phys_info.fspeed < 45.0f;
168 }
169
170 // if a ship has active contrails
171 int ct_has_contrails(ship *shipp)
172 {
173         int idx;
174
175         for(idx=0; idx<MAX_SHIP_CONTRAILS; idx++){
176                 if(shipp->trail_num[idx] >= 0){
177                         return 1;
178                 }
179         }
180
181         // no contrails
182         return 0;
183 }
184
185 // update active contrails - moving existing ones, adding new ones where necessary
186 void ct_update_contrails(ship *shipp)
187 {
188 #ifdef MULTIPLAYER_BETA_BUILD
189         return;
190 #else
191         vector v1;
192         matrix m;
193         int idx;
194         ship_info *sip;
195         object *objp;
196
197         // if not a fullneb mission - do nothing
198         if(!(The_mission.flags & MISSION_FLAG_FULLNEB)){
199                 return;
200         }
201
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];
208
209         // get the inverse rotation matrix
210         vm_copy_transpose_matrix(&m, &objp->orient);
211
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);
219                 
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]);
224                         } else {
225                                 trail_set_segment(shipp->trail_num[idx], &v1);
226                         }                       
227                 }
228         }       
229 #endif
230 }
231
232 // create new contrails
233 void ct_create_contrails(ship *shipp)
234 {
235 #ifdef MULTIPLAYER_BETA_BUILD
236         return;
237 #else
238         vector v1;
239         int idx;
240         matrix m;
241         ship_info *sip;
242         object *objp;
243
244         // if not a fullneb mission - do nothing
245         if(!(The_mission.flags & MISSION_FLAG_FULLNEB)){
246                 return;
247         }
248
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];
255
256         // get the inverse rotation matrix
257         vm_copy_transpose_matrix(&m, &objp->orient);
258
259         for(idx=0; idx<sip->ct_count; idx++){
260                 shipp->trail_num[idx] = (short)trail_create(sip->ct_info[idx]); 
261
262                 // add the point                
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);
267         }
268 #endif
269 }
270