diff options
| author | Valentin Popov <valentin@popov.link> | 2026-11-26 07:56:02 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-11-26 07:56:02 +0300 |
| commit | 5cd0954cbc50c31ce55de2503f79d8650681794d (patch) | |
| tree | ddd0c731c5757445cc141fc1afb3b663aa39b133 | |
| parent | cc3c6bcb3b8d5ed2f6bb09ca3ee423d3d5d8716a (diff) | |
| download | fparkan-5cd0954cbc50c31ce55de2503f79d8650681794d.tar.xz fparkan-5cd0954cbc50c31ce55de2503f79d8650681794d.zip | |
feat(combat): play explosions for depleted building parts
Use the EXPL referenced by the struck NDP row once the part runs out of capacity. Queue the blast at contact and keep the rest of the structure alive. The renderer shows the stock bunker effect in the Vulkan damage fixture.
| -rw-r--r-- | crates/fparkan-runtime/src/destruction.rs | 69 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/projectile.rs | 72 | ||||
| -rw-r--r-- | docs/appendices/knowledge-boundaries.md | 2 | ||||
| -rw-r--r-- | docs/tomes/06-behavior.md | 7 |
4 files changed, 132 insertions, 18 deletions
diff --git a/crates/fparkan-runtime/src/destruction.rs b/crates/fparkan-runtime/src/destruction.rs index 89688de5..50f307fa 100644 --- a/crates/fparkan-runtime/src/destruction.rs +++ b/crates/fparkan-runtime/src/destruction.rs @@ -1,13 +1,16 @@ //! Presentation events for projectile damage that destroys a unit. -use crate::{autodemo::MOBILE_UNIT, Engine, MissionControlDeviceTableState, ObjectHandle}; +use crate::{ + autodemo::MOBILE_UNIT, Engine, MissionControlDeviceTableState, MissionControlNodeProviderRow, + MissionControlNodeProviderTableStatus, ObjectHandle, UNIT_DAT_CONTROL_CLASS_HIGH_BIT, +}; use fparkan_world::{identity_metadata, transform_state}; -/// Position and attached EXPL resource of a chassis at lethal contact. +/// Position and attached EXPL resource of a destroyed chassis or building part. pub struct UnitDestructionEffect { /// Prepared draft index for the destroyed actor when it has an authored layout. pub object_index: Option<usize>, - /// World-space origin of the destroyed chassis. + /// World-space origin of the effect. pub position: [f32; 3], /// Archive containing the explosion description. pub archive: String, @@ -29,25 +32,48 @@ pub fn take_unit_destruction_effects(engine: &mut Engine) -> Vec<UnitDestruction .unwrap_or_default() } -/// One explosion descriptor per prepared mobile chassis, including reserves. +/// Explosion descriptors for prepared mobile chassis and damageable building parts. 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) - }) + mission + .object_drafts + .iter() + .filter_map(|draft| { + let class = draft.unit_dat_header_flags?; + let id = draft.original_id?; + let table = mission + .control_device_tables + .iter() + .find(|table| table.original_id == Some(id))?; + let MissionControlNodeProviderTableStatus::Available(rows) = + &table.node_provider_status + else { + return None; + }; + Some(if class & UNIT_DAT_CONTROL_CLASS_HIGH_BIT != 0 { + rows.as_slice() + } else if class & MOBILE_UNIT != 0 { + rows.get(..1).unwrap_or_default() + } else { + &[] + }) + }) + .flat_map(|rows| rows.iter().filter_map(node_effect)) + }) +} + +pub(super) fn building_part_effect( + row: &MissionControlNodeProviderRow, + position: [f32; 3], +) -> Option<UnitDestructionEffect> { + let (archive, name) = node_effect(row)?; + Some(UnitDestructionEffect { + object_index: None, + position, + archive, + name, }) } @@ -85,6 +111,13 @@ pub(super) fn pending_effect( fn root_effect(table: &MissionControlDeviceTableState) -> Option<(String, String)> { let row = crate::control_node_provider_row(table, 0).ok()?; + node_effect(row) +} + +fn node_effect(row: &MissionControlNodeProviderRow) -> Option<(String, String)> { + if f32::from_bits(row.initial_amount_bits) <= 0.0 { + return None; + } let effect = &row.source_row.effect; let archive = crate::bounded_ascii_c_string(&effect.archive)?; let name = crate::bounded_ascii_c_string(&effect.name)?; diff --git a/crates/fparkan-runtime/src/projectile.rs b/crates/fparkan-runtime/src/projectile.rs index e2203fe2..3e9b7088 100644 --- a/crates/fparkan-runtime/src/projectile.rs +++ b/crates/fparkan-runtime/src/projectile.rs @@ -176,6 +176,8 @@ pub fn projectile_terrain_hit( pub struct ProjectileContact { pub handle: ObjectHandle, pub fraction: f32, + /// World point on the segment at the detected contact. + pub position: [f32; 3], /// Provider row identified by a building triangle hit. pub building_node: Option<u32>, } @@ -217,6 +219,9 @@ pub fn projectile_unit_hit( Some(ProjectileContact { handle, fraction, + position: std::array::from_fn(|axis| { + segment[0][axis] + (segment[1][axis] - segment[0][axis]) * fraction + }), building_node, }) }) @@ -330,7 +335,15 @@ pub fn apply_projectile_contact( return Ok(None); } // shortcut: keep per-node damage using the projectile NDP volume while armor and splash are open. + let effect = (volume >= remaining && engine.destruction_effects.is_some()) + .then(|| super::destruction::building_part_effect(row, contact.position)) + .flatten(); let updated = apply_loaded_mission_control_node_delta(engine, contact.handle, key, -volume)?; + if updated.is_some() { + if let (Some(effect), Some(events)) = (effect, engine.destruction_effects.as_mut()) { + events.push(effect); + } + } Ok(updated.map(|_| ((remaining - volume).max(0.0), false))) } @@ -399,6 +412,65 @@ mod tests { #[test] #[ignore = "requires licensed corpus"] + fn licensed_factory_part_explodes_once_on_depletion() { + use crate::{ + collect_unit_destruction_effects, create, load_gameplay_mission, + take_unit_destruction_effects, unit_destruction_effect_sources, EngineServices, + MissionMode, MissionRequest, MissionStartupInput, + }; + use fparkan_vfs::DirectoryVfs; + use fparkan_world::OriginalObjectId; + + let root = std::env::var_os("FPARKAN_CORPUS_PART1_ROOT").expect("licensed corpus"); + let mut engine = create(EngineServices::new(Arc::new(DirectoryVfs::new(root)))).unwrap(); + load_gameplay_mission( + &mut engine, + MissionRequest { + key: "MISSIONS/Single.01/data.tma".into(), + mode: MissionMode::SingleMission, + }, + MissionStartupInput { + queue_time_ms: 0, + research_creation_gate: false, + }, + None, + ) + .unwrap(); + let plant = handle_by_original_id(&engine.world, OriginalObjectId(5)).unwrap(); + let contact = ProjectileContact { + handle: plant, + fraction: 0.5, + position: [1300.0, 627.0, 84.0], + building_node: Some(3), + }; + collect_unit_destruction_effects(&mut engine); + assert_eq!( + apply_projectile_contact(&mut engine, contact, 5_000.0).unwrap(), + Some((5_000.0, false)) + ); + assert!(take_unit_destruction_effects(&mut engine).is_empty()); + assert_eq!( + apply_projectile_contact(&mut engine, contact, 5_000.0).unwrap(), + Some((0.0, false)) + ); + let events = take_unit_destruction_effects(&mut engine); + let [effect] = events.as_slice() else { + panic!("expected one EXPL at the failed part"); + }; + assert_eq!(effect.position, contact.position); + assert_eq!(effect.object_index, None); + assert_eq!(effect.name, "explode_frt_b.exp"); + assert!(unit_destruction_effect_sources(&engine) + .any(|source| source == (effect.archive.clone(), effect.name.clone()))); + assert!(apply_projectile_contact(&mut engine, contact, 5_000.0) + .unwrap() + .is_none()); + assert!(take_unit_destruction_effects(&mut engine).is_empty()); + assert!(transform_state(&engine.world, plant).is_ok()); + } + + #[test] + #[ignore = "requires licensed corpus"] fn licensed_constructor_animal_takes_projectile_damage() { use crate::{ create, load_gameplay_mission, starting_cockpit, EngineServices, MissionMode, diff --git a/docs/appendices/knowledge-boundaries.md b/docs/appendices/knowledge-boundaries.md index 1597f545..f75c6c2e 100644 --- a/docs/appendices/knowledge-boundaries.md +++ b/docs/appendices/knowledge-boundaries.md @@ -151,6 +151,8 @@ authoring API без динамического подтверждения. из `EXPL` версии 1. Остальные версии и неподдержанные источники отмечает `unit_destruction_effect_stub`. При `Op10` с пустой ссылкой навесные модели летят по приближённой баллистике после гибели корпуса. +Узел строения запускает `EXPL` при исчерпании запаса. Промежуточные стадии, +позиция по матрице узла и переход к модели руин остаются открытыми. Параметры `Op10`, частицы и отстрел отдельных узлов открыты. `player_projectile_hull_stub` и `player_weapon_fx_stub` отмечают проверку по сфере вместо узлов у машин и открытые эффекты выстрела. `projectile_trail_approx` отмечает слои следа `Op5` с одной лентой на слой. diff --git a/docs/tomes/06-behavior.md b/docs/tomes/06-behavior.md index 2c0edc9d..a23f9f7f 100644 --- a/docs/tomes/06-behavior.md +++ b/docs/tomes/06-behavior.md @@ -2737,6 +2737,13 @@ Simulation читает подготовленный input snapshot. Renderer н `0x10f30`. Заголовок окна FParkan показывает оставшуюся долю общего запаса заводов клана после первого повреждения. +При полном истощении узла FParkan запускает его `EXPL` в точке попадания. +У узла 3 малого завода `splant01.dat` запас составляет 10 000 +единиц, а `explode_frt_b.exp` ссылается на трёхсекундный `exp_frt_b`. +В оригинале `Control.dll+0x11220` запрашивает эффект, когда стадия узла +повышается, и берёт матрицу узла. Промежуточные стадии и смещение эффекта +ещё открыты. + ### Захват нейтральной машины В таблице управления оригинала из `README/readme.htm` захват назначен |
