diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-01 14:12:24 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-01 14:12:24 +0300 |
| commit | 06df070ba0d7bd2435b8b1313019278090889d09 (patch) | |
| tree | e1e282bccf51fa7a24b42cb4bbab2d8971060820 /crates/fparkan-runtime/src | |
| parent | 85082a1c829050f375ad688d9ed563d753b3727b (diff) | |
| download | fparkan-06df070ba0d7bd2435b8b1313019278090889d09.tar.xz fparkan-06df070ba0d7bd2435b8b1313019278090889d09.zip | |
fix(audio): play flamer sound from the firing node
Feed initial node-attached Op2 rows from the same Control blends as their firing nodes. Keep them separate from projectile one-shots and opcode 10 wind-up sounds. The original Effect.dll confirmed the strict 0.01 threshold. The Constructor replay ordered and boarded the stock warbot, played the heavy flamer before projectile release, and captured the hangar.
Diffstat (limited to 'crates/fparkan-runtime/src')
| -rw-r--r-- | crates/fparkan-runtime/src/player_weapon.rs | 82 |
1 files changed, 65 insertions, 17 deletions
diff --git a/crates/fparkan-runtime/src/player_weapon.rs b/crates/fparkan-runtime/src/player_weapon.rs index d46c0943..f0b73401 100644 --- a/crates/fparkan-runtime/src/player_weapon.rs +++ b/crates/fparkan-runtime/src/player_weapon.rs @@ -39,6 +39,7 @@ pub struct PlayerWeapon { pub effect: Option<(String, String)>, effect_row: Option<(usize, usize)>, effect_node: Option<usize>, + node_sound_rows: Vec<(usize, usize, usize)>, windup_sound_rows: Vec<(usize, usize)>, windup_started: bool, deployment: Option<WeaponDeployment>, @@ -106,24 +107,32 @@ impl PlayerWeapons { &self, object_index: usize, ) -> impl Iterator<Item = (FiringEffectInstance, f32)> + '_ { - self.weapons.iter().filter_map(move |weapon| { - if weapon.destroyed { - return None; - } - let node = weapon.effect_node?; - let blend = self - .weapons - .iter() - .rev() - .filter(|track| !track.destroyed && track.component_index == weapon.component_index) - .find_map(|track| { - let index = track.barrels.iter().rposition(|barrel| { - barrel.row.node_index == node && barrel.row.flags & 4 == 0 + self.weapons + .iter() + .filter(|weapon| !weapon.destroyed) + .flat_map(move |weapon| { + weapon + .firing_effect(object_index) + .zip(weapon.effect_node) + .into_iter() + .chain(weapon.node_sound_bindings(object_index)) + }) + .filter_map(move |(effect, node)| { + let blend = self + .weapons + .iter() + .rev() + .filter(|track| { + !track.destroyed && track.component_index == effect.component_index + }) + .find_map(|track| { + let index = track.barrels.iter().rposition(|barrel| { + barrel.row.node_index == node && barrel.row.flags & 4 == 0 + })?; + Some(track.barrel_blend(index, self.clock_ms)) })?; - Some(track.barrel_blend(index, self.clock_ms)) - })?; - Some((weapon.firing_effect(object_index)?, blend)) - }) + Some((effect, blend)) + }) } /// Samples the weapon mount and barrel tracks after advancing the bank. @@ -320,6 +329,34 @@ impl PlayerWeapon { }) } + /// Prepared sounds linked directly to a firing node's current phase. + pub fn node_sounds( + &self, + object_index: usize, + ) -> impl Iterator<Item = FiringEffectInstance> + '_ { + self.node_sound_bindings(object_index) + .map(|(effect, _)| effect) + } + + fn node_sound_bindings( + &self, + object_index: usize, + ) -> impl Iterator<Item = (FiringEffectInstance, usize)> + '_ { + self.node_sound_rows + .iter() + .map(move |&(table_index, row_index, node)| { + ( + FiringEffectInstance { + object_index, + component_index: self.component_index, + table_index, + row_index, + }, + node, + ) + }) + } + /// Remaining shots, or `None` for an unlimited weapon. pub fn rounds_remaining(&self) -> Option<u32> { self.rounds_remaining @@ -513,6 +550,16 @@ fn prepare_weapons( effect, effect_row: effect_row.map(|row| (row.table_index, row.row_index)), effect_node, + node_sound_rows: control + .weapon_node_sound_rows() + .filter_map(|row| { + let node = row.point_offsets[0] as usize; + barrels + .iter() + .any(|barrel| barrel.row.node_index == node) + .then_some((row.table_index, row.row_index, node)) + }) + .collect(), windup_sound_rows: control .weapon_windup_sound_rows(record) .map(|row| (row.table_index, row.row_index)) @@ -793,6 +840,7 @@ mod tests { effect: None, effect_row: Some((2, 3)), effect_node: Some(0), + node_sound_rows: Vec::new(), windup_sound_rows: vec![(0, 1)], windup_started: false, deployment: None, |
