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