aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-02 00:14:54 +0300
committerValentin Popov <valentin@popov.link>2026-12-02 00:14:54 +0300
commit3efc5ba5d3389da168b00f8fe47d3478821e5d7f (patch)
tree8b222a05c28944eb05e815198872ae5f514db3b0 /crates
parent752d34af83acf9a818e22c621fb034913079acff (diff)
downloadfparkan-3efc5ba5d3389da168b00f8fe47d3478821e5d7f.tar.xz
fparkan-3efc5ba5d3389da168b00f8fe47d3478821e5d7f.zip
feat(ui): restore the original cockpit radar dial
Use the mirrored source atlas halves and show the installed sensor range with the original font. The stock Fireline cockpit reads 300 and the Two Fortresses cockpit reads 400. The range query agrees with the original libraries for both inactive and missing devices.
Diffstat (limited to 'crates')
-rw-r--r--crates/fparkan-runtime/src/radar.rs46
1 files changed, 39 insertions, 7 deletions
diff --git a/crates/fparkan-runtime/src/radar.rs b/crates/fparkan-runtime/src/radar.rs
index bdd34811..a6cb9f78 100644
--- a/crates/fparkan-runtime/src/radar.rs
+++ b/crates/fparkan-runtime/src/radar.rs
@@ -2,7 +2,7 @@
use crate::satellite_contacts::{clan_tint, OWN_TINT};
use crate::{
- control_device_provider_value, Engine, MissionControlDeviceTableState,
+ control_device_provider_value, EffectiveControlDevice, Engine, MissionControlDeviceTableState,
MissionControlDeviceTableStatus, StartingCockpit, HERO_UNIT_CLASS,
UNIT_DAT_CONTROL_CLASS_HIGH_BIT,
};
@@ -38,6 +38,27 @@ pub struct CockpitContact {
pub selected: bool,
}
+/// 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)
+}
+
+fn range_readout(range: Option<f32>) -> i32 {
+ // iron3d+0x91d80 substitutes 1 before the text's x87 integer conversion.
+ range
+ .filter(|range| range.is_finite() && *range > 0.0)
+ .unwrap_or(1.0)
+ .round_ties_even() as i32
+}
+
/// Range in world units and the contacts from this cockpit's scan.
pub fn cockpit_contacts(
engine: &Engine,
@@ -217,15 +238,16 @@ struct Antenna {
channels: [f64; 3],
}
-fn antenna(table: &MissionControlDeviceTableState) -> Option<Antenna> {
+fn radar_device(table: &MissionControlDeviceTableState) -> Option<&EffectiveControlDevice> {
let MissionControlDeviceTableStatus::Available(devices) = &table.status else {
return None;
};
// Control+0x2d5cb stores the last device created by factory 8.
- let device = devices
- .iter()
- .rev()
- .find(|device| device.factory_tag == 8)?;
+ devices.iter().rev().find(|device| device.factory_tag == 8)
+}
+
+fn antenna(table: &MissionControlDeviceTableState) -> Option<Antenna> {
+ let device = radar_device(table)?;
let provider = control_device_provider_value(table, device).ok()?;
if device.native_word_50_bits? == 0 || provider == 0.0 {
return None;
@@ -300,7 +322,17 @@ fn received(falloff: f32, gains: [f64; 3], signal: [f32; 3]) -> bool {
#[cfg(test)]
mod tests {
- use super::{falloff, received};
+ use super::{falloff, range_readout, received};
+
+ #[test]
+ fn cockpit_range_uses_native_fallback_and_nearest_even_rounding() {
+ assert_eq!(range_readout(None), 1);
+ assert_eq!(range_readout(Some(0.0)), 1);
+ assert_eq!(range_readout(Some(-1.0)), 1);
+ assert_eq!(range_readout(Some(299.5)), 300);
+ assert_eq!(range_readout(Some(300.5)), 300);
+ assert_eq!(range_readout(Some(301.5)), 302);
+ }
#[test]
fn native_scan_uses_strict_3d_range_and_an_independent_threshold_per_channel() {