//! Control device flags and control mode shown at the base of the cockpit dial. use crate::{ camouflage, repair_system::is_self_repair_device, Engine, MissionControlDeviceTableStatus, RemoteWarbotControl, StartingCockpit, }; /// The live device flags and control mode of an active cockpit. #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub struct CockpitIndicators { pub self_repair: bool, pub camouflage: bool, pub onsite: bool, pub control: RemoteWarbotControl, } /// Reads the occupied cockpit instead of the hero left at a remote console. pub fn cockpit_indicators(engine: &Engine, cockpit: StartingCockpit) -> Option { let mission = engine.loaded.as_ref()?; let (onsite, control) = match mission.boarding { Some(board) if board.cockpit.handle == cockpit.handle => { (!board.remote, board.control_mode) } None if mission.local_hero == Some(cockpit.handle) => (true, RemoteWarbotControl::Manual), _ => return None, }; let devices = mission .control_device_tables .iter() .find(|table| table.handle == cockpit.handle) .and_then(|table| match &table.status { MissionControlDeviceTableStatus::Available(devices) => Some(devices.as_slice()), _ => None, }) .unwrap_or_default(); let self_repair = devices .iter() .find(|device| is_self_repair_device(device)) .is_some_and(|device| device.native_word_50_bits == Some(0x20)); let camouflage = devices .iter() .find(|device| camouflage::is_controlled_device(device)) .is_some_and(camouflage::is_enabled); Some(CockpitIndicators { self_repair, camouflage, onsite, control, }) }