diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-02 21:14:34 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-02 21:14:34 +0300 |
| commit | 31d770f66c89ce23ca0a9510aa1259e8505179dd (patch) | |
| tree | a856d0a66cb507ad1c3e51d4ad6554a1fad918c1 /crates/fparkan-runtime | |
| parent | bd3fbb71cdef1cda0e4db5efa14c632ae72859d6 (diff) | |
| download | fparkan-31d770f66c89ce23ca0a9510aa1259e8505179dd.tar.xz fparkan-31d770f66c89ce23ca0a9510aa1259e8505179dd.zip | |
fix(ui): show live damage stages in cockpit miniatures
Diffstat (limited to 'crates/fparkan-runtime')
| -rw-r--r-- | crates/fparkan-runtime/src/cockpit_instruments.rs | 39 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/projectile.rs | 8 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/projectile_parts.rs | 10 |
3 files changed, 53 insertions, 4 deletions
diff --git a/crates/fparkan-runtime/src/cockpit_instruments.rs b/crates/fparkan-runtime/src/cockpit_instruments.rs index 88ea8df5..9911d52e 100644 --- a/crates/fparkan-runtime/src/cockpit_instruments.rs +++ b/crates/fparkan-runtime/src/cockpit_instruments.rs @@ -3,11 +3,13 @@ use crate::{ control_device_provider_value, control_device_selector_zero, projectile::unit_sphere, + projectile_parts::warbot_node_is_depleted, projectile_shield::{enclosing_sphere, world_sphere}, query_control_device_table_selector, strategic_map_readout::{contact_readout, ContactReadout}, weapon_pose::WeaponPoses, - Engine, MissionControlDeviceTableStatus, StartingCockpit, HERO_UNIT_CLASS, + Engine, MissionControlDeviceTableStatus, MissionControlNodeProviderTableStatus, + StartingCockpit, HERO_UNIT_CLASS, }; use fparkan_world::{identity_metadata, transform_state, ObjectHandle}; @@ -97,6 +99,41 @@ pub fn instrument_bounds(engine: &Engine, object_index: usize) -> Option<([f32; enclosing_sphere(&poses.instrument_node_spheres(&mission.mission_assets, object_index)) } +/// Current MSH state by component and local node. A detached warbot part has +/// no visible state. A node with no Control provider uses its initial slot. +pub fn instrument_node_states( + engine: &Engine, + subject: ObjectHandle, +) -> impl Iterator<Item = ((usize, usize), Option<u32>)> + '_ { + engine + .loaded + .iter() + .filter_map(move |mission| { + let table = mission + .control_device_tables + .iter() + .find(|table| table.handle == subject)?; + let MissionControlNodeProviderTableStatus::Available(rows) = + &table.node_provider_status + else { + return None; + }; + let draft = mission.object_drafts.get(table.original_id?.0 as usize)?; + let warbot = draft.unit_dat_header_flags == Some(crate::boarding::WARBOT_CLASS); + Some((rows.as_slice(), warbot)) + }) + .flat_map(|(rows, warbot)| { + rows.iter().enumerate().map(move |(index, row)| { + let state = if warbot && index != 0 && warbot_node_is_depleted(row) { + None + } else { + Some(row.mesh_state.map_or(0, |state| state.visible_stage)) + }; + ((row.unit_component_index, row.source_row_index), state) + }) + }) +} + /// Places the sphere in the object's current world pose. pub fn instrument_sphere( engine: &Engine, diff --git a/crates/fparkan-runtime/src/projectile.rs b/crates/fparkan-runtime/src/projectile.rs index 5681ad4f..66cdbc8b 100644 --- a/crates/fparkan-runtime/src/projectile.rs +++ b/crates/fparkan-runtime/src/projectile.rs @@ -698,6 +698,10 @@ mod tests { assert_eq!(amount(&engine, node), 0.0_f32.to_bits()); assert_eq!(amount(&engine, 0), root_before); assert!(crate::depleted_chassis_nodes(&engine).any(|item| item == (14, node as usize))); + assert!( + crate::cockpit_instruments::instrument_node_states(&engine, target) + .any(|state| state == ((0, node as usize), None)) + ); assert!(transform_state(&engine.world, target).is_ok()); let effects = take_unit_destruction_effects(&mut engine); assert_eq!(effects.len(), 1); @@ -786,6 +790,10 @@ mod tests { .visible_stage, 1 ); + assert!( + crate::cockpit_instruments::instrument_node_states(&engine, plant) + .any(|state| state == ((0, 1), Some(1))) + ); assert_eq!( crate::control_node_provider_row(table, 3) .unwrap() diff --git a/crates/fparkan-runtime/src/projectile_parts.rs b/crates/fparkan-runtime/src/projectile_parts.rs index eef5422f..d322d5ff 100644 --- a/crates/fparkan-runtime/src/projectile_parts.rs +++ b/crates/fparkan-runtime/src/projectile_parts.rs @@ -4,8 +4,8 @@ use crate::{ projectile::{segment_sphere_fraction, ProjectileNode}, turret_aim::hull_local_point, weapon_pose::WeaponPoses, - Engine, LoadedMissionState, MissionAssets, MissionControlNodeProviderTableStatus, ObjectHandle, - TransformState, + Engine, LoadedMissionState, MissionAssets, MissionControlNodeProviderRow, + MissionControlNodeProviderTableStatus, ObjectHandle, TransformState, }; use fparkan_animation::NodePoseBuffer; use fparkan_assets::PreparedModel; @@ -45,12 +45,16 @@ pub fn depleted_warbot_nodes(engine: &Engine) -> impl Iterator<Item = (usize, us .flat_map(|(index, rows)| { rows.iter() .skip(1) - .filter(|row| row.current_flags.is_some_and(|flags| flags & 0x12 == 0x10)) + .filter(|row| warbot_node_is_depleted(row)) .map(move |row| (index, row.unit_component_index, row.source_row_index)) }) }) } +pub(super) fn warbot_node_is_depleted(row: &MissionControlNodeProviderRow) -> bool { + row.current_flags.is_some_and(|flags| flags & 0x12 == 0x10) +} + pub(super) fn chassis_part_contact( mission: &LoadedMissionState, index: usize, |
