View Issue Details

IDProjectCategoryView StatusLast Update
0002451FSSCPsoundpublic2011-06-10 04:58
ReporterHalleck Assigned ToSushi_CW  
PrioritynormalSeverityfeatureReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.6.13 
Summary0002451: One-shot sounds to be played at the beginning of a firing event (patch attached)
DescriptionThis is a feature request that Karajorma had for Diaspora so there might be a duplicate of this ticket somewhere.

The feature is for the ability to specify a one-shot sound that will play at the beginning of a stream firing weapon, and will not repeat until firing is ceased and then resumed again.

I have added an optional field to entries in weapons.tbl called $PreFireSnd which allows you to assign a sound to this event based on it's numeric index in sounds.tbl. In terms of strict file order, it goes after the "$Disarmed ImpactSnd" field and before the "$FlyBySnd" field. An example of a weapon with this field is given in the additional information below.

The code patch is attached as a TortoiseSVN-compatible UDiff.

Feedback/code review is welcome!
Additional Information; ----------------------------------------------------------------------------------
; Sidearm
;
$Name: @Subach HL-7
+Title: XSTR("GTW Subach HL-7", 3243)
+Description:
XSTR(
"Standard Issue
Level 3 Hull Damage
Level 2 Shield Damage", 3244)
$end_multi_text
+Tech Title: XSTR("Subach HL-7", 146)
+Tech Anim: Tech_Subach_HL-7
+Tech Description:
XSTR(
"The Subach-Innes HL-7 is a xaser weapon, firing an intense, highly focused beam of x-ray emissions. Until the Shivans appeared with their shield technology, these weapons were considered an unnecessary and costly extravagance. But Great War dogfights against Shivan craft quickly taught the Allies that their ships didn't stand a chance unless they could punch through shields. The HL-7 works superbly against shields of all varieties and has become the standard issue Primary weapon for all Terran fighters and bombers.", 3245)
$end_multi_text
$Model File: none
; The following fields (preceded by @) are only required for laser
; rendering, which requires that "Model File:" be none.
; These are the same values that used to be hard-coded:
@Laser Bitmap: newglo9
@Laser Glow: 2_laserglow03
@Laser Color: 250, 0, 0
@Laser Color2: 0, 0, 250
@Laser Length: 10.0
@Laser Head Radius: 0.90
@Laser Tail Radius: 0.90
$Mass: 0.2
$Velocity: 450.0 ;; speed of the weapon (initially) -- may or may not change
$Fire Wait: 0.2 ;; in seconds
$Damage: 15
$Armor Factor: 0.9
$Shield Factor: 0.7
$Subsystem Factor: 0.3
$Lifetime: 2.0 ;; How long this thing lives
$Energy Consumed: 0.20 ;; Energy used when fired
$Cargo Size: 0.0 ;; Amount of space taken up in weapon cargo
$Homing: NO
$LaunchSnd: 76 ;; The sound it makes when fired
$ImpactSnd: 85 ;; The sound it makes when it hits something
$PreFireSnd: 49 ;; One-shot sound to play at the beginning of a firing stream
+Weapon Range: 100000 ;; Limit to range at which weapon will actively target object
$Flags: ("in tech database" "player allowed" "stream")
$Icon: iconSD4
$Anim: SD4
$Impact Explosion: none
TagsNo tags attached.

Activities

2011-06-09 12:00

 

PreFireSnd.patch (2,420 bytes)   
Index: code/ship/ship.cpp
===================================================================
--- code/ship/ship.cpp    (revision 7235)
+++ code/ship/ship.cpp    (working copy)
@@ -10287,13 +10287,18 @@ int ship_fire_primary(object * obj, int stream_weapons, int force)
 						weapon_info *wip;
 						ship_weapon *sw_pl;
 
-						// HACK
-						if(winfo_p->launch_snd == SND_AUTOCANNON_SHOT){
-							snd_play( &Snds[winfo_p->launch_snd], 0.0f, 1.0f, SND_PRIORITY_TRIPLE_INSTANCE );
+						if ( (shipp->was_firing_last_frame[bank_to_fire] == 0)
+							&& (winfo_p->pre_fire_snd != NULL)) { //If this weapon type has a pre-fire sound and we are at the beginning of a firing stream, play it.
+							snd_play( &Snds[winfo_p->pre_fire_snd], 0.0f, 1.0f, SND_PRIORITY_MUST_PLAY);
 						} else {
-							snd_play( &Snds[winfo_p->launch_snd], 0.0f, 1.0f, SND_PRIORITY_MUST_PLAY );
+							// HACK
+							if(winfo_p->launch_snd == SND_AUTOCANNON_SHOT){
+								snd_play( &Snds[winfo_p->launch_snd], 0.0f, 1.0f, SND_PRIORITY_TRIPLE_INSTANCE );
+							} else {
+								snd_play( &Snds[winfo_p->launch_snd], 0.0f, 1.0f, SND_PRIORITY_MUST_PLAY );
+							}
+			//				snd_play( &Snds[winfo_p->launch_snd] );
 						}
-		//				snd_play( &Snds[winfo_p->launch_snd] );
 	
 						sw_pl = &Player_ship->weapons;
 						if (sw_pl->current_primary_bank >= 0)
Index: code/weapon/weapon.h
===================================================================
--- code/weapon/weapon.h    (revision 7235)
+++ code/weapon/weapon.h    (working copy)
@@ -369,6 +369,7 @@ typedef struct weapon_info {
 	int	launch_snd;
 	int	impact_snd;
 	int disarmed_impact_snd;
+	int pre_fire_snd;
 	int	flyby_snd;							//	whizz-by sound, transmitted through weapon's portable atmosphere.
 	
 	// Specific to weapons with TRAILS:
Index: code/weapon/weapons.cpp
===================================================================
--- code/weapon/weapons.cpp    (revision 7235)
+++ code/weapon/weapons.cpp    (working copy)
@@ -1605,6 +1605,9 @@ int parse_weapon(int subtype, bool replace)
 	//Disarmed impact sound
 	parse_sound("$Disarmed ImpactSnd:", &wip->impact_snd, wip->name);
 
+	//Optional one-shot sound to play at the beginning of firing
+	parse_sound("$PreFireSnd:", &wip->pre_fire_snd, wip->name);
+
 	if (subtype == WP_MISSILE)
 	{
 		parse_sound("$FlyBySnd:", &wip->flyby_snd, wip->name);
PreFireSnd.patch (2,420 bytes)   

Halleck

2011-06-09 12:29

reporter   ~0012705

In retrospect it might make sense to move $PreFireSnd to above $LaunchSnd, and rename it to $PreLaunchSnd. In the future we might also want to add a $PostLaunchSnd which could go immediately after $LaunchSnd.

2011-06-09 14:39

 

PreLaunchSnd.patch (2,310 bytes)   
Index: code/ship/ship.cpp
===================================================================
--- code/ship/ship.cpp    (revision 7235)
+++ code/ship/ship.cpp    (working copy)
@@ -10287,13 +10287,18 @@ int ship_fire_primary(object * obj, int stream_weapons, int force)
 						weapon_info *wip;
 						ship_weapon *sw_pl;
 
-						// HACK
-						if(winfo_p->launch_snd == SND_AUTOCANNON_SHOT){
-							snd_play( &Snds[winfo_p->launch_snd], 0.0f, 1.0f, SND_PRIORITY_TRIPLE_INSTANCE );
+						if ( (shipp->was_firing_last_frame[bank_to_fire] == 0)
+							&& (winfo_p->pre_launch_snd != NULL)) { //If this weapon type has a pre-fire sound and we are at the beginning of a firing stream, play it.
+							snd_play( &Snds[winfo_p->pre_launch_snd], 0.0f, 1.0f, SND_PRIORITY_MUST_PLAY);
 						} else {
-							snd_play( &Snds[winfo_p->launch_snd], 0.0f, 1.0f, SND_PRIORITY_MUST_PLAY );
+							// HACK
+							if(winfo_p->launch_snd == SND_AUTOCANNON_SHOT){
+								snd_play( &Snds[winfo_p->launch_snd], 0.0f, 1.0f, SND_PRIORITY_TRIPLE_INSTANCE );
+							} else {
+								snd_play( &Snds[winfo_p->launch_snd], 0.0f, 1.0f, SND_PRIORITY_MUST_PLAY );
+							}
+			//				snd_play( &Snds[winfo_p->launch_snd] );
 						}
-		//				snd_play( &Snds[winfo_p->launch_snd] );
 	
 						sw_pl = &Player_ship->weapons;
 						if (sw_pl->current_primary_bank >= 0)
Index: code/weapon/weapon.h
===================================================================
--- code/weapon/weapon.h    (revision 7235)
+++ code/weapon/weapon.h    (working copy)
@@ -366,6 +366,7 @@ typedef struct weapon_info {
 	// Seeker strength - for countermeasures overhaul.
 	float seeker_strength;
 
+	int pre_launch_snd;
 	int	launch_snd;
 	int	impact_snd;
 	int disarmed_impact_snd;
Index: code/weapon/weapons.cpp
===================================================================
--- code/weapon/weapons.cpp    (revision 7235)
+++ code/weapon/weapons.cpp    (working copy)
@@ -1595,6 +1595,8 @@ int parse_weapon(int subtype, bool replace)
 			wip->free_flight_speed = 0.25f;
 		}
 	}
+	//Optional one-shot sound to play at the beginning of firing
+	parse_sound("$PreLaunchSnd:", &wip->pre_launch_snd, wip->name);
 
 	//Launch sound
 	parse_sound("$LaunchSnd:", &wip->launch_snd, wip->name);
PreLaunchSnd.patch (2,310 bytes)   

Halleck

2011-06-09 14:40

reporter   ~0012706

After discussing this with Sushi on IRC I decided to go make the changes I was thinking about above. New patch is uploaded here and called "PreLaunchSnd.patch."

2011-06-09 17:07

 

PreLaunchSnd_v2.patch (4,824 bytes)   
Index: code/ship/ship.cpp
===================================================================
--- code/ship/ship.cpp    (revision 7235)
+++ code/ship/ship.cpp    (working copy)
@@ -4779,6 +4779,7 @@ void ship_set(int ship_index, int objnum, int ship_type)
 		swp->next_primary_fire_stamp[i] = timestamp(0);	
 		swp->last_primary_fire_stamp[i] = -1;	
 		swp->primary_bank_rearm_time[i] = timestamp(0);		// added by Goober5000
+		swp->last_primary_fire_sound_stamp[i] = timestamp(0); // added by Halleck
 
 		swp->primary_animation_position[i] = MA_POS_NOT_SET;
 		swp->secondary_animation_position[i] = MA_POS_NOT_SET;
@@ -8449,6 +8450,7 @@ void ship_set_default_weapons(ship *shipp, ship_info *sip)
 		swp->next_primary_fire_stamp[i] = timestamp(0);
 		swp->last_primary_fire_stamp[i] = -1;
 		swp->burst_counter[i] = 0;
+		swp->last_primary_fire_sound_stamp[i] = timestamp(0);
 	}
 
 	for ( i = 0; i < MAX_SHIP_SECONDARY_BANKS; i++ ){
@@ -10287,13 +10289,26 @@ int ship_fire_primary(object * obj, int stream_weapons, int force)
 						weapon_info *wip;
 						ship_weapon *sw_pl;
 
-						// HACK
-						if(winfo_p->launch_snd == SND_AUTOCANNON_SHOT){
-							snd_play( &Snds[winfo_p->launch_snd], 0.0f, 1.0f, SND_PRIORITY_TRIPLE_INSTANCE );
-						} else {
-							snd_play( &Snds[winfo_p->launch_snd], 0.0f, 1.0f, SND_PRIORITY_MUST_PLAY );
+						//Update the last timestamp until continous fire is over, so we have the timestamp of the cease-fire.
+						if (shipp->was_firing_last_frame[bank_to_fire] == 1) {
+							swp->last_primary_fire_sound_stamp[bank_to_fire] = timestamp();
+						}
+
+						//Check for pre-launch sound and play if relevant
+						if( (winfo_p->pre_launch_snd != NULL)									//If this weapon type has a pre-fire sound
+							&& ((timestamp() - swp->last_primary_fire_sound_stamp[bank_to_fire]) >= winfo_p->pre_launch_snd_min_interval)	//and if we're past our minimum delay from the last cease-fire
+							&& (shipp->was_firing_last_frame[bank_to_fire] == 0)				//and if we are at the beginning of a firing stream
+						){ 
+							snd_play( &Snds[winfo_p->pre_launch_snd], 0.0f, 1.0f, SND_PRIORITY_MUST_PLAY); //play it 
+						} else { //Otherwise, play normal firing sounds
+							// HACK
+							if(winfo_p->launch_snd == SND_AUTOCANNON_SHOT){
+								snd_play( &Snds[winfo_p->launch_snd], 0.0f, 1.0f, SND_PRIORITY_TRIPLE_INSTANCE );
+							} else {
+								snd_play( &Snds[winfo_p->launch_snd], 0.0f, 1.0f, SND_PRIORITY_MUST_PLAY );
+							}
+			//				snd_play( &Snds[winfo_p->launch_snd] );
 						}
-		//				snd_play( &Snds[winfo_p->launch_snd] );
 	
 						sw_pl = &Player_ship->weapons;
 						if (sw_pl->current_primary_bank >= 0)
Index: code/ship/ship.h
===================================================================
--- code/ship/ship.h    (revision 7235)
+++ code/ship/ship.h    (working copy)
@@ -114,6 +114,7 @@ typedef struct ship_weapon {
 	int next_secondary_fire_stamp[MAX_SHIP_SECONDARY_BANKS];		// next time this secondary bank can fire
 	int last_secondary_fire_stamp[MAX_SHIP_SECONDARY_BANKS];		// last time this secondary bank fired (mostly used by SEXPs)
 	int next_tertiary_fire_stamp;
+	int last_primary_fire_sound_stamp[MAX_SHIP_PRIMARY_BANKS];		// trailing end of the last time this primary bank was fired, for purposes of timing the pre-launch sound
 
 	// ballistic primary support - by Goober5000
 	int primary_bank_ammo[MAX_SHIP_PRIMARY_BANKS];			// Number of missiles left in primary bank
Index: code/weapon/weapon.h
===================================================================
--- code/weapon/weapon.h    (revision 7235)
+++ code/weapon/weapon.h    (working copy)
@@ -366,6 +366,8 @@ typedef struct weapon_info {
 	// Seeker strength - for countermeasures overhaul.
 	float seeker_strength;
 
+	int pre_launch_snd;
+	int	pre_launch_snd_min_interval;	//Minimum interval in ms between the last time the pre-launch sound was played and the next time it can play, as a limiter in case the player is pumping the trigger
 	int	launch_snd;
 	int	impact_snd;
 	int disarmed_impact_snd;
Index: code/weapon/weapons.cpp
===================================================================
--- code/weapon/weapons.cpp    (revision 7235)
+++ code/weapon/weapons.cpp    (working copy)
@@ -1595,6 +1595,14 @@ int parse_weapon(int subtype, bool replace)
 			wip->free_flight_speed = 0.25f;
 		}
 	}
+	//Optional one-shot sound to play at the beginning of firing
+	parse_sound("$PreLaunchSnd:", &wip->pre_launch_snd, wip->name);
+
+	//Optional delay for Pre-Launch sound
+	if(optional_string("+PreLaunchSnd Min Interval:"))
+	{
+		stuff_int(&wip->pre_launch_snd_min_interval);
+	}
 
 	//Launch sound
 	parse_sound("$LaunchSnd:", &wip->launch_snd, wip->name);
PreLaunchSnd_v2.patch (4,824 bytes)   

Halleck

2011-06-09 17:15

reporter   ~0012707

PreLaunchSnd_v2.patch uploaded, now supports an optional interval setting in milliseconds between the end of the last fire/stream fire and the next time you will hear the pre-launch sound.

Settings are made like so, immediately before $LaunchSnd:

$PreLaunchSnd: 49 ;; One-shot sound to play at the beginning of a firing stream
    +PreLaunchSnd Min Interval: 2000 ;; Minimum interval in ms between when the player stops firing and the next time the pre-launch sound can play, as a limiter in case the player is pumping the trigger
$LaunchSnd: 76 ;; The sound it makes when fired

Caveat: This currently only works for Primary weapons since that's what Diaspora needs, but it should be pretty straightforward to add support for secondaries if somebody wants it.

Sushi_CW

2011-06-10 04:58

developer   ~0012708

Committed to trunk in r7237

Issue History

Date Modified Username Field Change
2011-06-09 12:00 Halleck New Issue
2011-06-09 12:00 Halleck File Added: PreFireSnd.patch
2011-06-09 12:29 Halleck Note Added: 0012705
2011-06-09 14:39 Halleck File Added: PreLaunchSnd.patch
2011-06-09 14:40 Halleck Note Added: 0012706
2011-06-09 17:07 Halleck File Added: PreLaunchSnd_v2.patch
2011-06-09 17:15 Halleck Note Added: 0012707
2011-06-10 04:58 Sushi_CW Note Added: 0012708
2011-06-10 04:58 Sushi_CW Status new => resolved
2011-06-10 04:58 Sushi_CW Resolution open => fixed
2011-06-10 04:58 Sushi_CW Assigned To => Sushi_CW