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.4 2005/10/01 22:04:58 taylor
19 * fix FS1 (de)briefing voices, the directory names are different in FS1
20 * hard code the table values so that the fs1.vp file isn't needed
21 * hard code a mission fix for sm2-08a since a have no idea how to fix it otherwise
22 * generally cleanup some FS1 code
23 * fix volume sliders in the options screen that never went all the way up
25 * Revision 1.3 2002/06/09 04:41:29 relnev
26 * added copyright header
28 * Revision 1.2 2002/05/07 03:16:53 theoddone33
29 * The Great Newline Fix
31 * Revision 1.1.1.1 2002/05/03 03:28:11 root
35 * 7 7/08/99 10:53a Dave
36 * New multiplayer interpolation scheme. Not 100% done yet, but still
37 * better than the old way.
39 * 6 5/18/99 1:30p Dave
40 * Added muzzle flash table stuff.
42 * 5 4/25/99 3:02p Dave
43 * Build defines for the E3 build.
45 * 4 4/12/99 11:03p Dave
46 * Removed contrails and muzzle flashes from MULTIPLAYER_BETA builds.
48 * 3 3/19/99 9:52a Dave
49 * Checkin to repair massive source safe crash. Also added support for
50 * pof-style nebulae, and some new weapons code.
52 * 2 1/08/99 2:08p Dave
53 * Fixed software rendering for pofview. Super early support for AWACS and
62 #include "systemvars.h"
65 #include "muzzleflash.h"
69 // ---------------------------------------------------------------------------------------------------------------------
70 // MUZZLE FLASH DEFINES/VARS
73 // muzzle flash info - read from a table
74 #define MAX_MFLASH_NAME_LEN 32
75 #define MAX_MFLASH_BLOBS 5
76 typedef struct mflash_info {
77 char name[MAX_MFLASH_NAME_LEN+1];
78 char blob_names[MAX_MFLASH_BLOBS][MAX_MFLASH_NAME_LEN+1]; // blob anim name
79 int blob_anims[MAX_MFLASH_BLOBS]; // blob anim
80 float blob_offset[MAX_MFLASH_BLOBS]; // blob offset from muzzle
81 float blob_radius[MAX_MFLASH_BLOBS]; // blob radius
82 int num_blobs; // # of blobs
84 mflash_info Mflash_info[MAX_MUZZLE_FLASH_TYPES];
85 int Num_mflash_types = 0;
89 // Stuff for missile trails doesn't need to be saved or restored... or does it?
91 typedef struct mflash {
95 ubyte type; // muzzle flash type
96 int blobs[MAX_MFLASH_BLOBS]; // blobs
100 mflash Mflash[MAX_MFLASH];
102 mflash Mflash_free_list;
103 mflash Mflash_used_list;
106 // ---------------------------------------------------------------------------------------------------------------------
107 // MUZZLE FLASH FUNCTIONS
110 // initialize muzzle flash stuff for the whole game
111 void mflash_game_init()
116 char name[MAX_MFLASH_NAME_LEN];
117 float offset, radius;
120 read_file_text("mflash.tbl");
124 required_string("#Muzzle flash types");
127 Num_mflash_types = 0;
128 while(optional_string("$Mflash:")){
129 if(Num_mflash_types < MAX_MUZZLE_FLASH_TYPES){
130 m = &Mflash_info[Num_mflash_types++];
134 memset(m, 0, sizeof(mflash_info));
135 for(idx=0; idx<MAX_MFLASH_BLOBS; idx++){
136 m->blob_anims[idx] = -1;
139 required_string("+name:");
140 stuff_string(m->name, F_NAME, NULL);
144 while(optional_string("+blob_name:")){
145 stuff_string(name, F_NAME, NULL, MAX_MFLASH_NAME_LEN);
147 required_string("+blob_offset:");
148 stuff_float(&offset);
150 required_string("+blob_radius:");
151 stuff_float(&radius);
153 // if we have room left
154 if(m->num_blobs < MAX_MFLASH_BLOBS){
155 strcpy(m->blob_names[m->num_blobs], name);
156 m->blob_offset[m->num_blobs] = offset;
157 m->blob_radius[m->num_blobs] = radius;
165 required_string("#end");
167 // hardcoded FS1 values
171 Num_mflash_types = 0;
172 m = &Mflash_info[Num_mflash_types++];
174 memset(m, 0, sizeof(mflash_info));
176 for (idx=0; idx<MAX_MFLASH_BLOBS; idx++) {
177 m->blob_anims[idx] = -1;
180 strncpy(m->name, "mflash_small", MAX_MFLASH_NAME_LEN);
183 Assert(m->num_blobs <= MAX_MFLASH_BLOBS);
186 strncpy(m->blob_names[idx], "expmissilehit1", MAX_MFLASH_NAME_LEN);
187 m->blob_offset[idx] = 1.0f;
188 m->blob_radius[idx] = 6.0f;
191 strncpy(m->blob_names[idx], "expmissilehit1", MAX_MFLASH_NAME_LEN);
192 m->blob_offset[idx] = 4.5f;
193 m->blob_radius[idx] = 4.0f;
196 strncpy(m->blob_names[idx], "expmissilehit1", MAX_MFLASH_NAME_LEN);
197 m->blob_offset[idx] = 6.0f;
198 m->blob_radius[idx] = 3.0f;
201 strncpy(m->blob_names[idx], "expmissilehit1", MAX_MFLASH_NAME_LEN);
202 m->blob_offset[idx] = 8.5f;
203 m->blob_radius[idx] = 3.0f;
207 // initialize muzzle flash stuff for the level
208 void mflash_level_init()
215 list_init( &Mflash_free_list );
216 list_init( &Mflash_used_list );
218 // Link all object slots into the free list
219 for (i=0; i<MAX_MFLASH; i++) {
220 memset(&Mflash[i], 0, sizeof(mflash));
221 list_append(&Mflash_free_list, &Mflash[i] );
226 for(i=0; i<Num_mflash_types; i++){
228 for(idx=0; idx<Mflash_info[i].num_blobs; idx++){
229 Mflash_info[i].blob_anims[idx] = -1;
230 Mflash_info[i].blob_anims[idx] = bm_load_animation(Mflash_info[i].blob_names[idx], &num_frames, &fps, 1);
231 Assert(Mflash_info[i].blob_anims[idx] >= 0);
236 // shutdown stuff for the level
237 void mflash_level_close()
241 // create a muzzle flash on the guy
242 void mflash_create(vector *gun_pos, vector *gun_dir, int mflash_type)
249 // standalone server should never create trails
250 if(Game_mode & GM_STANDALONE_SERVER){
255 if((mflash_type >= Num_mflash_types) || (mflash_type < 0)){
260 if (Num_mflash >= MAX_MFLASH ) {
262 mprintf(("Muzzle flash creation failed - too many trails!\n" ));
267 // Find next available trail
268 mflashp = GET_FIRST(&Mflash_free_list);
269 Assert( mflashp != &Mflash_free_list ); // shouldn't have the dummy element
271 // remove trailp from the free list
272 list_remove( &Mflash_free_list, mflashp );
274 // insert trailp onto the end of used list
275 list_append( &Mflash_used_list, mflashp );
278 mflashp->type = (ubyte)mflash_type;
281 // create the actual animations
282 mi = &Mflash_info[mflash_type];
283 for(idx=0; idx<mi->num_blobs; idx++){
286 if(mi->blob_anims[idx] < 0){
291 memset(&p, 0, sizeof(particle_info));
292 vm_vec_scale_add(&p.pos, gun_pos, gun_dir, mi->blob_offset[idx]);
293 p.vel = vmd_zero_vector;
294 p.rad = mi->blob_radius[idx];
295 p.type = PARTICLE_BITMAP;
296 p.optional_data = mi->blob_anims[idx];
297 p.attached_objnum = -1;
306 // process muzzle flash stuff
307 void mflash_process_all()
312 // if the timestamp has elapsed recycle it
313 mflashp = GET_FIRST(&Mflash_used_list);
315 while ( mflashp!=END_OF_LIST(&Mflash_used_list) ) {
316 if((mflashp->stamp == -1) || timestamp_elapsed(mflashp->stamp)){
317 // delete it from the list!
318 mflash *next_one = GET_NEXT(mflashp);
320 // remove objp from the used list
321 list_remove( &Mflash_used_list, mflashp );
323 // add objp to the end of the free
324 list_append( &Mflash_free_list, mflashp );
329 Assert(Num_mflash >= 0);
333 mflashp = GET_NEXT(mflashp);
339 void mflash_render_all()
343 // lookup type by name
344 int mflash_lookup(char *name)
349 for(idx=0; idx<Num_mflash_types; idx++){
350 if(!stricmp(name, Mflash_info[idx].name)){