aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/destruction.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-11-26 06:10:46 +0300
committerValentin Popov <valentin@popov.link>2026-11-26 06:10:46 +0300
commit8f1ba615bf1e393698eae7624073c1ad9f54c02b (patch)
tree2f3792c5070d4253472ee24d45d2d3dad3813e76 /crates/fparkan-runtime/src/destruction.rs
parent3dd13b710e1e559ef3f5cf15f3c6b50e8377d161 (diff)
downloadfparkan-8f1ba615bf1e393698eae7624073c1ad9f54c02b.tar.xz
fparkan-8f1ba615bf1e393698eae7624073c1ad9f54c02b.zip
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.
Diffstat (limited to 'crates/fparkan-runtime/src/destruction.rs')
-rw-r--r--crates/fparkan-runtime/src/destruction.rs80
1 files changed, 80 insertions, 0 deletions
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<UnitDestructionEffect> {
+ 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<Item = (String, String)> + '_ {
+ 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<UnitDestructionEffect> {
+ 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))
+}