diff options
Diffstat (limited to 'crates/fparkan-runtime')
| -rw-r--r-- | crates/fparkan-runtime/src/cockpit_indicators.rs | 51 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/lib.rs | 1 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/repair_system.rs | 12 |
3 files changed, 60 insertions, 4 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, + }) +} diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs index 6081fe98..7170b78f 100644 --- a/crates/fparkan-runtime/src/lib.rs +++ b/crates/fparkan-runtime/src/lib.rs @@ -112,6 +112,7 @@ pub use destruction::{ unit_destruction_effect_sources, DestroyedMesh, UnitDestructionEffect, }; pub mod cockpit_altimeter; +pub mod cockpit_indicators; pub mod cockpit_instruments; pub mod cockpit_speedometer; mod flight_altitude; diff --git a/crates/fparkan-runtime/src/repair_system.rs b/crates/fparkan-runtime/src/repair_system.rs index 8fa6c09a..6d94a093 100644 --- a/crates/fparkan-runtime/src/repair_system.rs +++ b/crates/fparkan-runtime/src/repair_system.rs @@ -1,6 +1,10 @@ //! State switch for the controlled unit's Control repair device. -use crate::{Engine, MissionControlDeviceTableStatus, StartingCockpit}; +use crate::{EffectiveControlDevice, Engine, MissionControlDeviceTableStatus, StartingCockpit}; + +pub(super) fn is_self_repair_device(device: &EffectiveControlDevice) -> bool { + device.key == 0 && device.descriptor.tag == 15 && device.factory_tag == 15 +} /// Switches the selected unit's self-repair device when it is present. pub fn toggle_self_repair(engine: &mut Engine, cockpit: StartingCockpit) -> Option<bool> { @@ -12,9 +16,9 @@ pub fn toggle_self_repair(engine: &mut Engine, cockpit: StartingCockpit) -> Opti let MissionControlDeviceTableStatus::Available(devices) = &mut table.status else { return None; }; - let device = devices.iter_mut().find(|device| { - device.key == 0 && device.descriptor.tag == 15 && device.factory_tag == 15 - })?; + let device = devices + .iter_mut() + .find(|device| is_self_repair_device(device))?; // Control+0x22c90 handles the inverse switch command 0x40. let enabled = device.native_word_50_bits? != 0x20; device.native_word_50_bits = Some(if enabled { 0x20 } else { 0 }); |
