diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-03 17:14:49 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-03 17:14:49 +0300 |
| commit | 1776dd8007169ef4f04969f0a5edcc423b6d67bc (patch) | |
| tree | d6bf261f4ecf07ddb79026130448f5aa937d49a1 /crates/fparkan-runtime/src/cockpit_indicators.rs | |
| parent | ca66e64b3995229ca7c8771b75ca26a60c3e344f (diff) | |
| download | fparkan-1776dd8007169ef4f04969f0a5edcc423b6d67bc.tar.xz fparkan-1776dd8007169ef4f04969f0a5edcc423b6d67bc.zip | |
feat(ui): restore cockpit status indicators
Diffstat (limited to 'crates/fparkan-runtime/src/cockpit_indicators.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/cockpit_indicators.rs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/crates/fparkan-runtime/src/cockpit_indicators.rs b/crates/fparkan-runtime/src/cockpit_indicators.rs new file mode 100644 index 00000000..e51e00bb --- /dev/null +++ b/crates/fparkan-runtime/src/cockpit_indicators.rs @@ -0,0 +1,51 @@ +//! Control device flags and control mode shown at the base of the cockpit dial. + +use crate::{ + 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<CockpitIndicators> { + let mission = engine.loaded.as_ref()?; + let (onsite, control) = match mission.boarding { + Some(board) if board.cockpit.handle == cockpit.handle => ( + board.remote.is_none(), + board.remote.unwrap_or(RemoteWarbotControl::Manual), + ), + 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| device.key == 0 && device.descriptor.tag == 10 && device.factory_tag == 10) + .is_some_and(|device| device.native_word_50_bits == Some(0x1000)); + Some(CockpitIndicators { + self_repair, + camouflage, + onsite, + control, + }) +} |
