]> icculus.org git repositories - taylor/freespace2.git/blob - src/weapon/muzzleflash.cpp
silence various MSVC warnings
[taylor/freespace2.git] / src / weapon / muzzleflash.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/Weapon/MuzzleFlash.cpp $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * all sorts of cool stuff about ships
16  *
17  * $Log$
18  * Revision 1.4  2005/10/01 22:04:58  taylor
19  * fix FS1 (de)briefing voices, the directory names are different in FS1
20  * hard code the table values so that the fs1.vp file isn't needed
21  * hard code a mission fix for sm2-08a since a have no idea how to fix it otherwise
22  * generally cleanup some FS1 code
23  * fix volume sliders in the options screen that never went all the way up
24  *
25  * Revision 1.3  2002/06/09 04:41:29  relnev
26  * added copyright header
27  *
28  * Revision 1.2  2002/05/07 03:16:53  theoddone33
29  * The Great Newline Fix
30  *
31  * Revision 1.1.1.1  2002/05/03 03:28:11  root
32  * Initial import.
33  *
34  * 
35  * 7     7/08/99 10:53a Dave
36  * New multiplayer interpolation scheme. Not 100% done yet, but still
37  * better than the old way.
38  * 
39  * 6     5/18/99 1:30p Dave
40  * Added muzzle flash table stuff.
41  * 
42  * 5     4/25/99 3:02p Dave
43  * Build defines for the E3 build.
44  * 
45  * 4     4/12/99 11:03p Dave
46  * Removed contrails and muzzle flashes from MULTIPLAYER_BETA builds.
47  * 
48  * 3     3/19/99 9:52a Dave
49  * Checkin to repair massive source safe crash. Also added support for
50  * pof-style nebulae, and some new weapons code.
51  * 
52  * 2     1/08/99 2:08p Dave
53  * Fixed software rendering for pofview. Super early support for AWACS and
54  * beam weapons.
55  * 
56  * 
57  * $NoKeywords: $
58  */
59
60 #include "object.h"
61 #include "timer.h"
62 #include "systemvars.h"
63 #include "linklist.h"
64 #include "parselo.h"
65 #include "muzzleflash.h"
66 #include "bmpman.h"
67 #include "particle.h"
68
69 // ---------------------------------------------------------------------------------------------------------------------
70 // MUZZLE FLASH DEFINES/VARS
71 // 
72
73 // muzzle flash info - read from a table
74 #define MAX_MFLASH_NAME_LEN             32
75 #define MAX_MFLASH_BLOBS                        5
76 typedef struct mflash_info {
77         char            name[MAX_MFLASH_NAME_LEN+1];
78         char            blob_names[MAX_MFLASH_BLOBS][MAX_MFLASH_NAME_LEN+1];                    // blob anim name
79         int             blob_anims[MAX_MFLASH_BLOBS];                                                                                   // blob anim
80         float           blob_offset[MAX_MFLASH_BLOBS];                                                                          // blob offset from muzzle
81         float           blob_radius[MAX_MFLASH_BLOBS];                                                                          // blob radius
82         int             num_blobs;                                                                                                                                      // # of blobs
83 } mflash_info;
84 mflash_info Mflash_info[MAX_MUZZLE_FLASH_TYPES];
85 int Num_mflash_types = 0;
86
87 #define MAX_MFLASH                              50
88
89 // Stuff for missile trails doesn't need to be saved or restored... or does it?
90 /*
91 typedef struct mflash { 
92         struct  mflash * prev;
93         struct  mflash * next;
94
95         ubyte           type;                                                                                                                                                   // muzzle flash type
96         int             blobs[MAX_MFLASH_BLOBS];                                                                                                // blobs
97 } mflash;
98
99 int Num_mflash = 0;
100 mflash Mflash[MAX_MFLASH];
101
102 mflash Mflash_free_list;
103 mflash Mflash_used_list;
104 */
105
106 // ---------------------------------------------------------------------------------------------------------------------
107 // MUZZLE FLASH FUNCTIONS
108 // 
109
110 // initialize muzzle flash stuff for the whole game
111 void mflash_game_init()
112 {
113 #ifndef MAKE_FS1
114         mflash_info bogus;
115         mflash_info *m; 
116         char name[MAX_MFLASH_NAME_LEN];
117         float offset, radius;
118         int idx;
119
120         read_file_text("mflash.tbl");
121         reset_parse();
122
123         // header
124         required_string("#Muzzle flash types");
125
126         // read em in
127         Num_mflash_types = 0;   
128         while(optional_string("$Mflash:")){
129                 if(Num_mflash_types < MAX_MUZZLE_FLASH_TYPES){
130                         m = &Mflash_info[Num_mflash_types++];
131                 } else {
132                         m = &bogus;
133                 }
134                 memset(m, 0, sizeof(mflash_info));
135                 for(idx=0; idx<MAX_MFLASH_BLOBS; idx++){
136                         m->blob_anims[idx] = -1;
137                 }
138
139                 required_string("+name:");
140                 stuff_string(m->name, F_NAME, NULL);
141
142                 // read in all blobs
143                 m->num_blobs = 0;
144                 while(optional_string("+blob_name:")){
145                         stuff_string(name, F_NAME, NULL, MAX_MFLASH_NAME_LEN);
146
147                         required_string("+blob_offset:");
148                         stuff_float(&offset);
149
150                         required_string("+blob_radius:");
151                         stuff_float(&radius);
152
153                         // if we have room left
154                         if(m->num_blobs < MAX_MFLASH_BLOBS){
155                                 SDL_strlcpy(m->blob_names[m->num_blobs], name, MAX_MFLASH_NAME_LEN);
156                                 m->blob_offset[m->num_blobs] = offset;
157                                 m->blob_radius[m->num_blobs] = radius;                          
158
159                                 m->num_blobs++;
160                         }
161                 }
162         }
163
164         // close
165         required_string("#end");
166 #else
167         // hardcoded FS1 values
168         int idx;
169         mflash_info *m;
170
171         Num_mflash_types = 0;
172         m = &Mflash_info[Num_mflash_types++];
173
174         memset(m, 0, sizeof(mflash_info));
175
176         for (idx=0; idx<MAX_MFLASH_BLOBS; idx++) {
177                 m->blob_anims[idx] = -1;
178         }
179
180         SDL_strlcpy(m->name, "mflash_small", MAX_MFLASH_NAME_LEN);
181
182         m->num_blobs = 4;
183         SDL_assert(m->num_blobs <= MAX_MFLASH_BLOBS);
184
185         idx = 0;
186         SDL_strlcpy(m->blob_names[idx], "expmissilehit1", MAX_MFLASH_NAME_LEN);
187         m->blob_offset[idx] = 1.0f;
188         m->blob_radius[idx] = 6.0f;
189
190         idx++;
191         SDL_strlcpy(m->blob_names[idx], "expmissilehit1", MAX_MFLASH_NAME_LEN);
192         m->blob_offset[idx] = 4.5f;
193         m->blob_radius[idx] = 4.0f;
194
195         idx++;
196         SDL_strlcpy(m->blob_names[idx], "expmissilehit1", MAX_MFLASH_NAME_LEN);
197         m->blob_offset[idx] = 6.0f;
198         m->blob_radius[idx] = 3.0f;
199
200         idx++;
201         SDL_strlcpy(m->blob_names[idx], "expmissilehit1", MAX_MFLASH_NAME_LEN);
202         m->blob_offset[idx] = 8.5f;
203         m->blob_radius[idx] = 3.0f;
204 #endif
205 }
206
207 // initialize muzzle flash stuff for the level
208 void mflash_level_init()
209 {
210         int i, idx;
211         int num_frames, fps;
212
213         /*
214         Num_mflash = 0;
215         list_init( &Mflash_free_list );
216         list_init( &Mflash_used_list );
217
218         // Link all object slots into the free list
219         for (i=0; i<MAX_MFLASH; i++)    {
220                 memset(&Mflash[i], 0, sizeof(mflash));
221                 list_append(&Mflash_free_list, &Mflash[i] );
222         }
223         */
224
225         // load up all anims
226         for(i=0; i<Num_mflash_types; i++){
227                 // blobs
228                 for(idx=0; idx<Mflash_info[i].num_blobs; idx++){
229                         Mflash_info[i].blob_anims[idx] = -1;
230                         Mflash_info[i].blob_anims[idx] = bm_load_animation(Mflash_info[i].blob_names[idx], &num_frames, &fps, 1);
231                         SDL_assert(Mflash_info[i].blob_anims[idx] >= 0);
232                 }
233         }
234 }
235
236 // shutdown stuff for the level
237 void mflash_level_close()
238 {
239 }
240
241 // create a muzzle flash on the guy
242 void mflash_create(vector *gun_pos, vector *gun_dir, int mflash_type)
243 {       
244         // mflash *mflashp;
245         mflash_info *mi;
246         particle_info p;
247         int idx;
248
249         // standalone server should never create trails
250         if(Game_mode & GM_STANDALONE_SERVER){
251                 return;
252         }
253
254         // illegal value
255         if((mflash_type >= Num_mflash_types) || (mflash_type < 0)){
256                 return;
257         }
258
259         /*
260         if (Num_mflash >= MAX_MFLASH ) {
261                 #ifndef NDEBUG
262                 mprintf(("Muzzle flash creation failed - too many trails!\n" ));
263                 #endif
264                 return;
265         }
266
267         // Find next available trail
268         mflashp = GET_FIRST(&Mflash_free_list);
269         SDL_assert( mflashp != &Mflash_free_list );             // shouldn't have the dummy element
270
271         // remove trailp from the free list
272         list_remove( &Mflash_free_list, mflashp );
273         
274         // insert trailp onto the end of used list
275         list_append( &Mflash_used_list, mflashp );
276
277         // store some stuff
278         mflashp->type = (ubyte)mflash_type;     
279         */
280
281         // create the actual animations 
282         mi = &Mflash_info[mflash_type];
283         for(idx=0; idx<mi->num_blobs; idx++){           
284
285                 // bogus anim
286                 if(mi->blob_anims[idx] < 0){
287                         continue;
288                 }
289                 
290                 // fire it up
291                 memset(&p, 0, sizeof(particle_info));
292                 vm_vec_scale_add(&p.pos, gun_pos, gun_dir, mi->blob_offset[idx]);
293                 p.vel = vmd_zero_vector;                
294                 p.rad = mi->blob_radius[idx];
295                 p.type = PARTICLE_BITMAP;
296                 p.optional_data = mi->blob_anims[idx];
297                 p.attached_objnum = -1;
298                 p.attached_sig = 0;
299                 particle_create(&p);
300         }
301
302         // increment counter
303         // Num_mflash++;                
304 }
305
306 // process muzzle flash stuff
307 void mflash_process_all()
308 {
309         /*
310         mflash *mflashp;
311
312         // if the timestamp has elapsed recycle it
313         mflashp = GET_FIRST(&Mflash_used_list);
314
315         while ( mflashp!=END_OF_LIST(&Mflash_used_list) )       {                       
316                 if((mflashp->stamp == -1) || timestamp_elapsed(mflashp->stamp)){
317                         // delete it from the list!
318                         mflash *next_one = GET_NEXT(mflashp);
319
320                         // remove objp from the used list
321                         list_remove( &Mflash_used_list, mflashp );
322
323                         // add objp to the end of the free
324                         list_append( &Mflash_free_list, mflashp );
325
326                         // decrement counter
327                         Num_mflash--;
328
329                         SDL_assert(Num_mflash >= 0);
330                         
331                         mflashp = next_one;                     
332                 } else {        
333                         mflashp = GET_NEXT(mflashp);
334                 }
335         }
336         */
337 }
338
339 void mflash_render_all()
340 {
341 }
342
343 // lookup type by name
344 int mflash_lookup(char *name)
345 {       
346         int idx;
347
348         // look it up
349         for(idx=0; idx<Num_mflash_types; idx++){
350                 if(!SDL_strcasecmp(name, Mflash_info[idx].name)){
351                         return idx;
352                 }
353         }
354
355         // couldn't find it
356         return -1;      
357 }