2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
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
10 * $Logfile: /Freespace2/code/Weapon/MuzzleFlash.cpp $
15 * all sorts of cool stuff about ships
18 * Revision 1.3 2002/06/09 04:41:29 relnev
19 * added copyright header
21 * Revision 1.2 2002/05/07 03:16:53 theoddone33
22 * The Great Newline Fix
24 * Revision 1.1.1.1 2002/05/03 03:28:11 root
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.
32 * 6 5/18/99 1:30p Dave
33 * Added muzzle flash table stuff.
35 * 5 4/25/99 3:02p Dave
36 * Build defines for the E3 build.
38 * 4 4/12/99 11:03p Dave
39 * Removed contrails and muzzle flashes from MULTIPLAYER_BETA builds.
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.
45 * 2 1/08/99 2:08p Dave
46 * Fixed software rendering for pofview. Super early support for AWACS and
55 #include "systemvars.h"
58 #include "muzzleflash.h"
62 // ---------------------------------------------------------------------------------------------------------------------
63 // MUZZLE FLASH DEFINES/VARS
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
77 mflash_info Mflash_info[MAX_MUZZLE_FLASH_TYPES];
78 int Num_mflash_types = 0;
82 // Stuff for missile trails doesn't need to be saved or restored... or does it?
84 typedef struct mflash {
88 ubyte type; // muzzle flash type
89 int blobs[MAX_MFLASH_BLOBS]; // blobs
93 mflash Mflash[MAX_MFLASH];
95 mflash Mflash_free_list;
96 mflash Mflash_used_list;
99 // ---------------------------------------------------------------------------------------------------------------------
100 // MUZZLE FLASH FUNCTIONS
103 // initialize muzzle flash stuff for the whole game
104 void mflash_game_init()
108 char name[MAX_MFLASH_NAME_LEN];
109 float offset, radius;
112 read_file_text("mflash.tbl");
116 required_string("#Muzzle flash types");
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++];
126 memset(m, 0, sizeof(mflash_info));
127 for(idx=0; idx<MAX_MFLASH_BLOBS; idx++){
128 m->blob_anims[idx] = -1;
131 required_string("+name:");
132 stuff_string(m->name, F_NAME, NULL);
136 while(optional_string("+blob_name:")){
137 stuff_string(name, F_NAME, NULL, MAX_MFLASH_NAME_LEN);
139 required_string("+blob_offset:");
140 stuff_float(&offset);
142 required_string("+blob_radius:");
143 stuff_float(&radius);
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;
157 required_string("#end");
160 // initialize muzzle flash stuff for the level
161 void mflash_level_init()
168 list_init( &Mflash_free_list );
169 list_init( &Mflash_used_list );
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] );
179 for(i=0; i<Num_mflash_types; i++){
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);
189 // shutdown stuff for the level
190 void mflash_level_close()
194 // create a muzzle flash on the guy
195 void mflash_create(vector *gun_pos, vector *gun_dir, int mflash_type)
202 // standalone server should never create trails
203 if(Game_mode & GM_STANDALONE_SERVER){
208 if((mflash_type >= Num_mflash_types) || (mflash_type < 0)){
213 if (Num_mflash >= MAX_MFLASH ) {
215 mprintf(("Muzzle flash creation failed - too many trails!\n" ));
220 // Find next available trail
221 mflashp = GET_FIRST(&Mflash_free_list);
222 Assert( mflashp != &Mflash_free_list ); // shouldn't have the dummy element
224 // remove trailp from the free list
225 list_remove( &Mflash_free_list, mflashp );
227 // insert trailp onto the end of used list
228 list_append( &Mflash_used_list, mflashp );
231 mflashp->type = (ubyte)mflash_type;
234 // create the actual animations
235 mi = &Mflash_info[mflash_type];
236 for(idx=0; idx<mi->num_blobs; idx++){
239 if(mi->blob_anims[idx] < 0){
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;
259 // process muzzle flash stuff
260 void mflash_process_all()
265 // if the timestamp has elapsed recycle it
266 mflashp = GET_FIRST(&Mflash_used_list);
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);
273 // remove objp from the used list
274 list_remove( &Mflash_used_list, mflashp );
276 // add objp to the end of the free
277 list_append( &Mflash_free_list, mflashp );
282 Assert(Num_mflash >= 0);
286 mflashp = GET_NEXT(mflashp);
292 void mflash_render_all()
296 // lookup type by name
297 int mflash_lookup(char *name)
302 for(idx=0; idx<Num_mflash_types; idx++){
303 if(!stricmp(name, Mflash_info[idx].name)){