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