diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-01 08:39:16 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-01 08:39:16 +0300 |
| commit | af281721b24a4c80d4c640c3d79a293dba2bee61 (patch) | |
| tree | db70c0501e871171eef66516fc958ee42a256af0 /crates/fparkan-runtime/src | |
| parent | 590c8f39b935f34fc6a4f9c033520c2c0359253d (diff) | |
| download | fparkan-af281721b24a4c80d4c640c3d79a293dba2bee61.tar.xz fparkan-af281721b24a4c80d4c640c3d79a293dba2bee61.zip | |
fix(render): show building damage stages after projectile hits
Update the contacted provider with the native stage rule. Upload the authored variants with their original material and pose, and draw the active stage only. The Two Fortresses plant switches in a validated before/after capture.
Diffstat (limited to 'crates/fparkan-runtime/src')
| -rw-r--r-- | crates/fparkan-runtime/src/node_stage.rs | 17 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/projectile.rs | 52 |
2 files changed, 60 insertions, 9 deletions
diff --git a/crates/fparkan-runtime/src/node_stage.rs b/crates/fparkan-runtime/src/node_stage.rs index 40c3850c..d7b833bf 100644 --- a/crates/fparkan-runtime/src/node_stage.rs +++ b/crates/fparkan-runtime/src/node_stage.rs @@ -9,7 +9,7 @@ use super::{ #[derive(Clone, Copy)] enum StageUpdate { Explicit { effects: bool }, - ChassisDamage, + LiveDamage, } pub(super) fn update_control_node_stage( @@ -167,7 +167,7 @@ pub(super) fn propagate_chassis_damage( key: u32, ) -> Result<bool, ControlResourceAccessError> { let mut updated = table.clone(); - match propagate_stage(&mut updated, key, StageUpdate::ChassisDamage) { + match propagate_stage(&mut updated, key, StageUpdate::LiveDamage) { Ok(()) => { *table = updated; Ok(false) @@ -183,6 +183,19 @@ pub(super) fn propagate_chassis_damage( } } +pub(super) fn update_building_impact_stage( + table: &mut MissionControlDeviceTableState, + key: u32, +) -> Result<(), ControlResourceAccessError> { + if control_node_provider_row(table, key)? + .initial_mesh_state + .is_some_and(|state| state.stage_count > 1) + { + update_stage(table, key, StageUpdate::LiveDamage)?; + } + Ok(()) +} + fn propagate_stage( table: &mut MissionControlDeviceTableState, key: u32, diff --git a/crates/fparkan-runtime/src/projectile.rs b/crates/fparkan-runtime/src/projectile.rs index b5da26b8..51adc045 100644 --- a/crates/fparkan-runtime/src/projectile.rs +++ b/crates/fparkan-runtime/src/projectile.rs @@ -400,7 +400,8 @@ fn apply_contact_damage( if updated.is_none() { return Ok(None); } - if volume >= remaining && warbot_part { + let building_part = matches!(contact.node, Some(ProjectileNode::Building(_))); + if building_part || volume >= remaining && warbot_part { let table = engine .loaded .as_mut() @@ -411,13 +412,19 @@ fn apply_contact_damage( .find(|table| table.handle == contact.handle) }) .expect("successful damage updated the target table"); - match super::node_stage::propagate_chassis_damage(table, key) { - Ok(true) => { - super::destruction::destroy(engine, contact.handle)?; - return Ok(Some((0.0, true))); + if building_part { + if let Err(reason) = super::node_stage::update_building_impact_stage(table, key) { + eprintln!("sim_coverage building_damage_stage_stub=1 object={} node={key} reason={reason:?}", contact.handle.slot); + } + } else { + match super::node_stage::propagate_chassis_damage(table, key) { + Ok(true) => { + super::destruction::destroy(engine, contact.handle)?; + return Ok(Some((0.0, true))); + } + Ok(false) => {} + Err(reason) => eprintln!("sim_coverage chassis_depletion_cascade_stub=1 object={} node={key} reason={reason:?}", contact.handle.slot), } - Ok(false) => {} - Err(reason) => eprintln!("sim_coverage chassis_depletion_cascade_stub=1 object={} node={key} reason={reason:?}", contact.handle.slot), } } if let (Some(effect), Some(events)) = (effect, engine.destruction_effects.as_mut()) { @@ -695,6 +702,37 @@ mod tests { device.class9_values_bits = Some([0; 6]); } } + let stage_contact = ProjectileContact { + handle: plant, + fraction: 0.5, + position: [1300.0, 627.0, 84.0], + node: Some(ProjectileNode::Building(1)), + }; + assert_eq!( + apply_projectile_contact(&mut engine, stage_contact, 30_000.0).unwrap(), + Some((20_000.0, false)) + ); + let table = crate::loaded_mission_control_device_tables(&engine) + .unwrap() + .iter() + .find(|table| table.handle == plant) + .unwrap(); + assert_eq!( + crate::control_node_provider_row(table, 1) + .unwrap() + .mesh_state + .unwrap() + .visible_stage, + 1 + ); + assert_eq!( + crate::control_node_provider_row(table, 3) + .unwrap() + .mesh_state + .unwrap() + .visible_stage, + 0 + ); let contact = ProjectileContact { handle: plant, fraction: 0.5, |
