From 20161fbf4fab9080a2d0d6ceedbf1344435cfda0 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 2 Dec 2026 11:40:01 +0400 Subject: feat(ui): show live Control stats in the warbot card --- crates/fparkan-runtime/src/lib.rs | 80 +++++++++++++-------------------------- 1 file changed, 27 insertions(+), 53 deletions(-) (limited to 'crates/fparkan-runtime/src/lib.rs') diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs index 96a39732..0cc96e6f 100644 --- a/crates/fparkan-runtime/src/lib.rs +++ b/crates/fparkan-runtime/src/lib.rs @@ -70,10 +70,12 @@ mod control_resources; mod mobile_budget; mod node_amount; mod node_stage; +mod projectile_capacity; pub mod satellite_contacts; pub mod strategic_balance; pub mod strategic_roster; pub mod strategic_view; +pub mod warbot_stats; pub use clan_clock::note_mission_pause_elapsed; use control_profile::project_initial as project_control_owner_profile_fca0; pub use control_profile::{ControlProfileReport, ControlProfileScalars}; @@ -502,10 +504,13 @@ fn resolve_factory2_pair_from_assets( if !factory2_selected_fx_resources_are_representable(asset_manager, control, &opcodes)? { return Ok(Factory2PairOutcome::Unrepresentable); } - match factory2_node_data_maximum_bits(&node_data.rows) { - Ok(bits) => Ok(Factory2PairOutcome::Value(bits)), - Err(_) => Ok(Factory2PairOutcome::Unrepresentable), - } + Ok( + projectile_capacity::projectile_capacity_bits(asset_manager.repository(), &node_data.rows)? + .map_or( + Factory2PairOutcome::Unrepresentable, + Factory2PairOutcome::Value, + ), + ) } fn factory2_selected_fx_resources_are_representable( @@ -630,19 +635,6 @@ fn factory2_fx_resource_is_representable( })) } -fn factory2_node_data_maximum_bits( - rows: &[PreparedControlNodeDataRow], -) -> Result { - let mut maximum = 0.0_f32; - for row in rows { - let value = checked_control_float(2, "factory-2 NDP Max", row.max_volume) - .map_err(|_| "NDP Max float")?; - maximum = checked_control_sum(2, "factory-2 NDP Max sum", maximum, value) - .map_err(|_| "NDP Max sum")?; - } - Ok(maximum.to_bits()) -} - /// Common fields known for one row in a host object's Control device table. /// /// The row index is its position in the containing `Vec`. This stores the @@ -745,6 +737,8 @@ pub struct MissionControlNodeProviderRow { pub initial_mesh_state: Option, /// Current model-node fields, when its global ordinal was resolved. pub mesh_state: Option, + /// Visible stages whose LOD-0 mesh slot has a nonzero AniMesh selector 0x0f. + pub armored_mesh_stages: Option, } /// Node-property publication applied to CPU model state after an amount change. @@ -6959,6 +6953,7 @@ fn build_control_device_projection_with_class( } let mut global_mesh_states = Vec::new(); + let mut global_mesh_armor = Vec::new(); let mut global_control_profile_slots = Vec::new(); let mut global_mesh_component_ids = Vec::new(); let mut root_control_profile_model_known = false; @@ -7010,6 +7005,9 @@ fn build_control_device_projection_with_class( global_mesh_states.push(model.and_then(|model| { initial_control_mesh_state(model, source_node_index, parent_base, mount_node) })); + global_mesh_armor.push(model.and_then(|model| { + warbot_stats::armored_stages(model, source_node_index, draft.scale) + })); global_control_profile_slots.push( model.and_then(|model| initial_control_profile_slot(model, source_node_index)), ); @@ -7211,6 +7209,9 @@ fn build_control_device_projection_with_class( } if let MissionControlNodeProviderTableStatus::Available(rows) = &mut node_provider_status { attach_initial_mesh_states_by_global_ordinal(rows, &global_mesh_states); + for (row, stages) in rows.iter_mut().zip(global_mesh_armor) { + row.armored_mesh_stages = stages; + } } let owner_profile = owner_profile.map( |(source, unit_component_index, native_component_id, original_words)| { @@ -7313,6 +7314,7 @@ fn append_control_node_provider_rows( current_stage: 0, initial_mesh_state: None, mesh_state: None, + armored_mesh_stages: None, }); } } @@ -8220,35 +8222,6 @@ mod tests { assert_eq!(upper.cache_key(), lower.cache_key()); } - #[test] - fn factory2_ndp_maximum_uses_ordered_f32_sum_and_accepts_empty_tables() { - let mut rows = [0.0_f32; 3].map(|max_volume| PreparedControlNodeDataRow { - raw_flags: 0, - max_volume, - mobility_per_volume: 0.0, - effect: PreparedControlResourcePair { - archive: [0; 32], - name: [0; 32], - }, - }); - rows[0].max_volume = 16_777_216.0; - rows[1].max_volume = 1.0; - rows[2].max_volume = -16_777_216.0; - - assert_eq!( - factory2_node_data_maximum_bits(&rows), - Ok(0.0_f32.to_bits()) - ); - assert_eq!(factory2_node_data_maximum_bits(&[]), Ok(0.0_f32.to_bits())); - assert_eq!( - factory2_node_data_maximum_bits(&[PreparedControlNodeDataRow { - max_volume: f32::from_bits(1), - ..rows[0].clone() - }]), - Err("NDP Max float") - ); - } - fn factory2_test_nres(entries: &[(&[u8], u32, u32, &[u8])]) -> Vec { let mut bytes = vec![0; 16]; let mut offsets = Vec::with_capacity(entries.len()); @@ -9098,6 +9071,7 @@ mod tests { current_stage: 0, initial_mesh_state: None, mesh_state: None, + armored_mesh_stages: None, } } @@ -16658,13 +16632,13 @@ mod tests { }); let expected_vectors = [ - ("bb_m_01", 0x43f9_8000), - ("bm_m_01", 0x4422_8000), - ("bl_l_01", 0x436a_0000), - ("br_b_01", 0x44c8_0000), - ("bf_b_01", 0x443b_8000), - ("bl_m_01", 0x443b_4000), - ("bm_l_01", 0x4334_0000), + ("bb_m_01", 0x43fa_0000), + ("bm_m_01", 0x444a_8000), + ("bl_l_01", 0x436b_0000), + ("br_b_01", 0x44ed_8000), + ("bf_b_01", 0x4445_8000), + ("bl_m_01", 0x443b_8000), + ("bm_l_01", 0x43aa_0000), ]; let tables = loaded_mission_control_device_tables(&engine).expect("Control tables"); let mut observed = Vec::new(); -- cgit v1.2.3