2 * $Logfile: /Freespace2/code/Weapon/MuzzleFlash.cpp $
7 * all sorts of cool stuff about ships
10 * Revision 1.1 2002/05/03 03:28:11 root
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.
18 * 6 5/18/99 1:30p Dave
19 * Added muzzle flash table stuff.
21 * 5 4/25/99 3:02p Dave
22 * Build defines for the E3 build.
24 * 4 4/12/99 11:03p Dave
25 * Removed contrails and muzzle flashes from MULTIPLAYER_BETA builds.
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.
31 * 2 1/08/99 2:08p Dave
32 * Fixed software rendering for pofview. Super early support for AWACS and
41 #include "systemvars.h"
44 #include "muzzleflash.h"
48 // ---------------------------------------------------------------------------------------------------------------------
49 // MUZZLE FLASH DEFINES/VARS
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
63 mflash_info Mflash_info[MAX_MUZZLE_FLASH_TYPES];
64 int Num_mflash_types = 0;
68 // Stuff for missile trails doesn't need to be saved or restored... or does it?
70 typedef struct mflash {
74 ubyte type; // muzzle flash type
75 int blobs[MAX_MFLASH_BLOBS]; // blobs
79 mflash Mflash[MAX_MFLASH];
81 mflash Mflash_free_list;
82 mflash Mflash_used_list;
85 // ---------------------------------------------------------------------------------------------------------------------
86 // MUZZLE FLASH FUNCTIONS
89 // initialize muzzle flash stuff for the whole game
90 void mflash_game_init()
94 char name[MAX_MFLASH_NAME_LEN];
98 read_file_text("mflash.tbl");
102 required_string("#Muzzle flash types");
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++];
112 memset(m, 0, sizeof(mflash_info));
113 for(idx=0; idx<MAX_MFLASH_BLOBS; idx++){
114 m->blob_anims[idx] = -1;
117 required_string("+name:");
118 stuff_string(m->name, F_NAME, NULL);
122 while(optional_string("+blob_name:")){
123 stuff_string(name, F_NAME, NULL, MAX_MFLASH_NAME_LEN);
125 required_string("+blob_offset:");
126 stuff_float(&offset);
128 required_string("+blob_radius:");
129 stuff_float(&radius);
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;
143 required_string("#end");
146 // initialize muzzle flash stuff for the level
147 void mflash_level_init()
154 list_init( &Mflash_free_list );
155 list_init( &Mflash_used_list );
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] );
165 for(i=0; i<Num_mflash_types; i++){
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);
175 // shutdown stuff for the level
176 void mflash_level_close()
180 // create a muzzle flash on the guy
181 void mflash_create(vector *gun_pos, vector *gun_dir, int mflash_type)
188 // standalone server should never create trails
189 if(Game_mode & GM_STANDALONE_SERVER){
194 if((mflash_type >= Num_mflash_types) || (mflash_type < 0)){
199 if (Num_mflash >= MAX_MFLASH ) {
201 mprintf(("Muzzle flash creation failed - too many trails!\n" ));
206 // Find next available trail
207 mflashp = GET_FIRST(&Mflash_free_list);
208 Assert( mflashp != &Mflash_free_list ); // shouldn't have the dummy element
210 // remove trailp from the free list
211 list_remove( &Mflash_free_list, mflashp );
213 // insert trailp onto the end of used list
214 list_append( &Mflash_used_list, mflashp );
217 mflashp->type = (ubyte)mflash_type;
220 // create the actual animations
221 mi = &Mflash_info[mflash_type];
222 for(idx=0; idx<mi->num_blobs; idx++){
225 if(mi->blob_anims[idx] < 0){
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;
245 // process muzzle flash stuff
246 void mflash_process_all()
251 // if the timestamp has elapsed recycle it
252 mflashp = GET_FIRST(&Mflash_used_list);
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);
259 // remove objp from the used list
260 list_remove( &Mflash_used_list, mflashp );
262 // add objp to the end of the free
263 list_append( &Mflash_free_list, mflashp );
268 Assert(Num_mflash >= 0);
272 mflashp = GET_NEXT(mflashp);
278 void mflash_render_all()
282 // lookup type by name
283 int mflash_lookup(char *name)
288 for(idx=0; idx<Num_mflash_types; idx++){
289 if(!stricmp(name, Mflash_info[idx].name)){