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