aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime
diff options
context:
space:
mode:
Diffstat (limited to 'crates/fparkan-runtime')
-rw-r--r--crates/fparkan-runtime/src/radar.rs32
1 files changed, 24 insertions, 8 deletions
diff --git a/crates/fparkan-runtime/src/radar.rs b/crates/fparkan-runtime/src/radar.rs
index a6cb9f78..677c3348 100644
--- a/crates/fparkan-runtime/src/radar.rs
+++ b/crates/fparkan-runtime/src/radar.rs
@@ -41,14 +41,30 @@ pub struct CockpitContact {
/// The range printed on the cockpit dial, even when the antenna is unpowered.
#[must_use]
pub fn cockpit_range_readout(engine: &Engine, cockpit: StartingCockpit) -> i32 {
- let range = engine.loaded.as_ref().and_then(|mission| {
- let table = mission
- .control_device_tables
- .iter()
- .find(|table| table.handle == cockpit.handle)?;
- Some(f32::from_bits(radar_device(table)?.coefficient_bits?[3]))
- });
- range_readout(range)
+ range_readout(cockpit_radar_coefficient(engine, cockpit, 3))
+}
+
+/// The installed radar's period for the HUD sweep, from Control selector 0xa9.
+#[must_use]
+pub fn cockpit_radar_period(engine: &Engine, cockpit: StartingCockpit) -> Option<f32> {
+ cockpit_radar_coefficient(engine, cockpit, 4)
+ .filter(|period| period.is_finite() && *period > 0.0)
+}
+
+fn cockpit_radar_coefficient(
+ engine: &Engine,
+ cockpit: StartingCockpit,
+ index: usize,
+) -> Option<f32> {
+ let table = engine
+ .loaded
+ .as_ref()?
+ .control_device_tables
+ .iter()
+ .find(|table| table.handle == cockpit.handle)?;
+ Some(f32::from_bits(
+ radar_device(table)?.coefficient_bits?[index],
+ ))
}
fn range_readout(range: Option<f32>) -> i32 {