aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/cockpit_indicators.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/fparkan-runtime/src/cockpit_indicators.rs')
-rw-r--r--crates/fparkan-runtime/src/cockpit_indicators.rs51
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,
+ })
+}