1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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,
})
}
|