aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/lib.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-02 10:40:01 +0300
committerValentin Popov <valentin@popov.link>2026-12-02 10:40:01 +0300
commit20161fbf4fab9080a2d0d6ceedbf1344435cfda0 (patch)
tree174be0827089abc4407af7289142d66d9f995ae7 /crates/fparkan-runtime/src/lib.rs
parent5f0b8c076b40f8eca67e2745367c731f803914f4 (diff)
downloadfparkan-20161fbf4fab9080a2d0d6ceedbf1344435cfda0.tar.xz
fparkan-20161fbf4fab9080a2d0d6ceedbf1344435cfda0.zip
feat(ui): show live Control stats in the warbot card
Diffstat (limited to 'crates/fparkan-runtime/src/lib.rs')
-rw-r--r--crates/fparkan-runtime/src/lib.rs80
1 files changed, 27 insertions, 53 deletions
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<R: ResourceRepository>(
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<R: ResourceRepository>(
@@ -630,19 +635,6 @@ fn factory2_fx_resource_is_representable<R: ResourceRepository>(
}))
}
-fn factory2_node_data_maximum_bits(
- rows: &[PreparedControlNodeDataRow],
-) -> Result<u32, &'static str> {
- 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<MissionControlNodeInitialMeshState>,
/// Current model-node fields, when its global ordinal was resolved.
pub mesh_state: Option<MissionControlNodeMeshState>,
+ /// Visible stages whose LOD-0 mesh slot has a nonzero AniMesh selector 0x0f.
+ pub armored_mesh_stages: Option<u8>,
}
/// 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<u8> {
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();