From 8f1ba615bf1e393698eae7624073c1ad9f54c02b Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 26 Nov 2026 07:10:46 +0400 Subject: feat(combat): play the referenced explosion on chassis destruction Read the version-one EXPL reference from the depleted NDP root. Retain the death position across slot reuse and show the authored billboard, light and sound after the mesh is removed. Verified the explosion sprite after a stock AutoDemo kill, with Vulkan validation clean. Node detachment, debris particles and building destruction remain open. --- crates/fparkan-runtime/src/destruction.rs | 80 +++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 crates/fparkan-runtime/src/destruction.rs (limited to 'crates/fparkan-runtime/src/destruction.rs') diff --git a/crates/fparkan-runtime/src/destruction.rs b/crates/fparkan-runtime/src/destruction.rs new file mode 100644 index 00000000..38a4e38f --- /dev/null +++ b/crates/fparkan-runtime/src/destruction.rs @@ -0,0 +1,80 @@ +//! Presentation events for projectile damage that destroys a unit. + +use crate::{autodemo::MOBILE_UNIT, Engine, MissionControlDeviceTableState, ObjectHandle}; +use fparkan_world::transform_state; + +/// Position and attached EXPL resource of a chassis at lethal contact. +pub struct UnitDestructionEffect { + /// World-space origin of the destroyed chassis. + pub position: [f32; 3], + /// Archive containing the explosion description. + pub archive: String, + /// Name of the explosion description. + pub name: String, +} + +/// Collect lethal projectile events when a scene is presenting the mission. +pub fn collect_unit_destruction_effects(engine: &mut Engine) { + engine.destruction_effects.get_or_insert_with(Vec::new); +} + +/// Takes each newly destroyed unit once, after both player and AI damage. +pub fn take_unit_destruction_effects(engine: &mut Engine) -> Vec { + engine + .destruction_effects + .as_mut() + .map(std::mem::take) + .unwrap_or_default() +} + +/// One explosion descriptor per prepared mobile chassis, including reserves. +pub fn unit_destruction_effect_sources( + engine: &Engine, +) -> impl Iterator + '_ { + engine.loaded.iter().flat_map(|mission| { + mission.object_drafts.iter().filter_map(|draft| { + if !draft + .unit_dat_header_flags + .is_some_and(|class| class & MOBILE_UNIT != 0) + { + return None; + } + let id = draft.original_id?; + let table = mission + .control_device_tables + .iter() + .find(|table| table.original_id == Some(id))?; + root_effect(table) + }) + }) +} + +pub(super) fn pending_effect( + engine: &Engine, + handle: ObjectHandle, +) -> Option { + engine.destruction_effects.as_ref()?; + let mission = engine.loaded.as_ref()?; + let table = mission + .control_device_tables + .iter() + .find(|table| table.handle == handle)?; + let (archive, name) = root_effect(table)?; + let position = transform_state(&engine.world, handle) + .ok()? + .position + .map(f32::from_bits); + Some(UnitDestructionEffect { + position, + archive, + name, + }) +} + +fn root_effect(table: &MissionControlDeviceTableState) -> Option<(String, String)> { + let row = crate::control_node_provider_row(table, 0).ok()?; + let effect = &row.source_row.effect; + let archive = crate::bounded_ascii_c_string(&effect.archive)?; + let name = crate::bounded_ascii_c_string(&effect.name)?; + (!archive.is_empty() && !name.is_empty()).then_some((archive, name)) +} -- cgit v1.2.3