From 06df070ba0d7bd2435b8b1313019278090889d09 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Tue, 1 Dec 2026 15:12:24 +0400 Subject: 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. --- crates/fparkan-assets/src/control_weapon_sound.rs | 31 +++++++++ crates/fparkan-assets/src/lib.rs | 1 + crates/fparkan-runtime/src/player_weapon.rs | 82 ++++++++++++++++++----- 3 files changed, 97 insertions(+), 17 deletions(-) create mode 100644 crates/fparkan-assets/src/control_weapon_sound.rs (limited to 'crates') diff --git a/crates/fparkan-assets/src/control_weapon_sound.rs b/crates/fparkan-assets/src/control_weapon_sound.rs new file mode 100644 index 00000000..1d8a6bd1 --- /dev/null +++ b/crates/fparkan-assets/src/control_weapon_sound.rs @@ -0,0 +1,31 @@ +use crate::{PreparedComponentControl, PreparedControlEffectRow, PreparedControlEffectSection}; + +impl PreparedComponentControl { + /// Initial node-attached sound rows driven by a weapon's timeline. + pub fn weapon_node_sound_rows(&self) -> impl Iterator { + let rows = match &self.effect_section { + PreparedControlEffectSection::Parsed(rows) => rows.as_slice(), + _ => &[], + }; + rows.iter().filter(|row| { + row.opcode == 3 + && self.initial_effect_group == Some(row.table_index) + && row.raw_condition[0] & 0xf000_0000 == 0 + && !self.typed_records.iter().any(|record| { + self.weapon_windup_sound_rows(record) + .any(|windup| windup.row_index == row.row_index) + }) + && self.typed_records.iter().any(|record| { + record.tag == 2 + && record.values.iter().any(|&index| { + self.timeline_rows + .get(index as usize) + .is_some_and(|timeline| { + timeline.flags & 0x44 == 0 + && timeline.node_index == row.point_offsets[0] as usize + }) + }) + }) + }) + } +} diff --git a/crates/fparkan-assets/src/lib.rs b/crates/fparkan-assets/src/lib.rs index 88c3b193..4d2f7366 100644 --- a/crates/fparkan-assets/src/lib.rs +++ b/crates/fparkan-assets/src/lib.rs @@ -32,6 +32,7 @@ pub use fparkan_texm::{PageRect, RgbaImage}; use fparkan_vfs::DirectoryVfs; mod behavior_profile_values; mod chassis_profile; +mod control_weapon_sound; mod explosion_profile; mod turret_elevation; pub use behavior_profile_values::{ 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, + node_sound_rows: Vec<(usize, usize, usize)>, windup_sound_rows: Vec<(usize, usize)>, windup_started: bool, deployment: Option, @@ -106,24 +107,32 @@ impl PlayerWeapons { &self, object_index: usize, ) -> impl Iterator + '_ { - 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 + '_ { + self.node_sound_bindings(object_index) + .map(|(effect, _)| effect) + } + + fn node_sound_bindings( + &self, + object_index: usize, + ) -> impl Iterator + '_ { + 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 { 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, -- cgit v1.2.3