//! 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) -> [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], ); } }