diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-02 14:48:26 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-02 14:48:26 +0300 |
| commit | e631882baadc7a9cb05a56f21ef8de78aa7627aa (patch) | |
| tree | 9528e070fa08521cb03fc19c61211f9b4929f002 /crates/fparkan-runtime | |
| parent | e565346f002a685b5527f7d52792bad3eb8933a2 (diff) | |
| download | fparkan-e631882baadc7a9cb05a56f21ef8de78aa7627aa.tar.xz fparkan-e631882baadc7a9cb05a56f21ef8de78aa7627aa.zip | |
feat(ui): show live strategic toolbar button states
Diffstat (limited to 'crates/fparkan-runtime')
| -rw-r--r-- | crates/fparkan-runtime/src/lib.rs | 1 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/strategic_toolbar.rs | 68 |
2 files changed, 69 insertions, 0 deletions
diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs index 86d0b1f2..84f1050b 100644 --- a/crates/fparkan-runtime/src/lib.rs +++ b/crates/fparkan-runtime/src/lib.rs @@ -76,6 +76,7 @@ pub mod strategic_balance; pub mod strategic_map_readout; pub mod strategic_orders; pub mod strategic_roster; +pub mod strategic_toolbar; pub mod strategic_view; pub mod warbot_stats; pub use clan_clock::note_mission_pause_elapsed; diff --git a/crates/fparkan-runtime/src/strategic_toolbar.rs b/crates/fparkan-runtime/src/strategic_toolbar.rs new file mode 100644 index 00000000..e35c19b0 --- /dev/null +++ b/crates/fparkan-runtime/src/strategic_toolbar.rs @@ -0,0 +1,68 @@ +//! Clan membership queries for the strategic toolbar sections. + +use crate::{Engine, StartingCockpit}; +use fparkan_world::{identity_metadata, registration_sequence}; + +// Masks in screen order, as queried by iron3d+0x84040 for the eight lists. +const SECTION_MASKS: [u32; 8] = [ + 0x0101_8000, + 0x0100_4000, + 0x0100_2000, + 0x8000_0400, + 0x8000_0010, + 0x8030_0000, + 0x8007_0000, + 0x8000_044e, +]; + +/// Availability for warbots, builders, transports, labs, factories, towers, +/// bunkers, and other buildings, based on live objects of the cockpit's clan. +#[must_use] +pub fn available_sections(engine: &Engine, cockpit: StartingCockpit) -> [bool; 8] { + let Some((mission, owner)) = engine.loaded.as_ref().zip( + identity_metadata(&engine.world, cockpit.handle) + .ok() + .and_then(|identity| identity.owner_id), + ) else { + return [false; 8]; + }; + let classes = mission.control_device_tables.iter().filter_map(|table| { + let handle = table.handle; + if table.node_provider_depletion_marked + || identity_metadata(&engine.world, handle).ok()?.owner_id != Some(owner) + || registration_sequence(&engine.world, handle).ok()?.is_none() + { + return None; + } + mission + .object_drafts + .get(table.original_id?.0 as usize)? + .unit_dat_header_flags + }); + sections_for_classes(classes) +} + +fn sections_for_classes(classes: impl Iterator<Item = u32>) -> [bool; 8] { + let mut available = [false; 8]; + for class in classes.filter(|&class| class != 0) { + for (slot, mask) in available.iter_mut().zip(SECTION_MASKS) { + *slot |= class & mask == class; + } + } + available +} + +#[cfg(test)] +mod tests { + use super::sections_for_classes; + + #[test] + fn command_warbot_and_laboratory_enable_native_sections() { + assert_eq!( + sections_for_classes( + [0, 0x0101_0000, 0x0100_4000, 0x8000_0400, 0x8004_0000].into_iter() + ), + [true, true, false, true, false, false, true, true], + ); + } +} |
