From 777358e8aeea09350813af417e0adefc366bc0f8 Mon Sep 17 00:00:00 2001 From: yuni Date: Thu, 28 Nov 2024 01:53:56 +0100 Subject: [PATCH] atmosphere: implement correct altitude gauge --- src/actor.rs | 2 +- src/nature.rs | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/actor.rs b/src/actor.rs index 7f2601d..c8e3f61 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -1167,7 +1167,7 @@ fn handle_atmosphere( if player.is_some() { settings.atmo_pressure = Some(pressure); - settings.atmo_altitude = Some(height); + settings.atmo_altitude = Some(distance - nature::JUPITER_RADIUS); reset_player_gauges = false; } diff --git a/src/nature.rs b/src/nature.rs index 5350d48..f3f4b83 100644 --- a/src/nature.rs +++ b/src/nature.rs @@ -156,15 +156,16 @@ pub fn readable_speed(speed: f64) -> String { } pub fn readable_si(value: f64) -> String { - if value > 1e10 { + let abs = value.abs(); + if abs > 1e10 { return format!("{:.1} G", value / 1e9); - } else if value > 1e7 { + } else if abs > 1e7 { return format!("{:.1} M", value / 1e6); - } else if value > 1e4 { + } else if abs > 1e4 { return format!("{:.1} k", value / 1e3); - } else if value < 1e-2 { + } else if abs < 1e-2 { return format!("{:.1} m", value * 1e3); - } else if value < 1e-5 { + } else if abs < 1e-5 { return format!("{:.1} ยต", value * 1e3); } return format!("{:.1} ", value); @@ -299,5 +300,5 @@ pub fn jupiter_altitude_to_pressure(altitude: f64) -> f64 { } else if x >= 0.0 { return (-0.0020248515 - 0.0000454102 * x).exp(); } - return -(1.45773e-16) * x.powf(3.0) + 1; + return -(1.45773e-16) * x.powf(3.0) + 1.0; }