From 31d770f66c89ce23ca0a9510aa1259e8505179dd Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 2 Dec 2026 22:14:34 +0400 Subject: fix(ui): show live damage stages in cockpit miniatures --- crates/fparkan-runtime/src/cockpit_instruments.rs | 39 ++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'crates/fparkan-runtime/src/cockpit_instruments.rs') 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)> + '_ { + 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, -- cgit v1.2.3