aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-assets/src/explosion_profile.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-assets/src/explosion_profile.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-assets/src/explosion_profile.rs')
-rw-r--r--crates/fparkan-assets/src/explosion_profile.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/crates/fparkan-assets/src/explosion_profile.rs b/crates/fparkan-assets/src/explosion_profile.rs
new file mode 100644
index 00000000..af9c5a3e
--- /dev/null
+++ b/crates/fparkan-assets/src/explosion_profile.rs
@@ -0,0 +1,37 @@
+//! Effect references carried by the version-1 explosion descriptor.
+
+/// Reads the initial effect archive and name from a version-1 EXPL payload.
+/// Other versions and malformed references require separate interpretation.
+pub fn decode_explosion_effect(bytes: &[u8]) -> Option<(&str, &str)> {
+ if bytes.len() != 792 || bytes[..4] != 1_u32.to_le_bytes() {
+ return None;
+ }
+ Some((
+ fixed_name(&bytes[0x18..0x38])?,
+ fixed_name(&bytes[0x38..0x58])?,
+ ))
+}
+
+fn fixed_name(bytes: &[u8]) -> Option<&str> {
+ let name = bytes.split(|&byte| byte == 0).next()?;
+ (name.is_ascii() && !name.is_empty())
+ .then(|| std::str::from_utf8(name).ok())
+ .flatten()
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn reads_version_one_reference_and_rejects_unknown_layouts() {
+ let mut bytes = [0; 792];
+ bytes[..4].copy_from_slice(&1_u32.to_le_bytes());
+ bytes[0x18..0x1d].copy_from_slice(b"a.rlb");
+ bytes[0x38..0x3d].copy_from_slice(b"burst");
+ assert_eq!(decode_explosion_effect(&bytes), Some(("a.rlb", "burst")));
+ assert_eq!(decode_explosion_effect(&bytes[..791]), None);
+ bytes[0] = 2;
+ assert_eq!(decode_explosion_effect(&bytes), None);
+ }
+}