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