From 2b696144e31a03c3842a1e3d880313db2bc76bec Mon Sep 17 00:00:00 2001 From: Magnus Wolffelt Date: Fri, 16 Jul 2021 00:34:58 +0200 Subject: [PATCH] Add QNH and temperature to the kneeboard. --- gen/environmentgen.py | 4 ++-- gen/kneeboard.py | 17 +++++++++++++++++ gen/units.py | 12 +++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/gen/environmentgen.py b/gen/environmentgen.py index a431abe9..2bc9da84 100644 --- a/gen/environmentgen.py +++ b/gen/environmentgen.py @@ -3,6 +3,7 @@ from typing import Optional from dcs.mission import Mission from game.weather import Clouds, Fog, Conditions, WindConditions, AtmosphericConditions +from .units import inches_hg_to_mm_hg class EnvironmentGenerator: @@ -11,8 +12,7 @@ class EnvironmentGenerator: self.conditions = conditions def set_atmospheric(self, atmospheric: AtmosphericConditions) -> None: - inch_to_mm = 25.400002776728 - self.mission.weather.qnh = atmospheric.qnh_inches_mercury * inch_to_mm + self.mission.weather.qnh = inches_hg_to_mm_hg(atmospheric.qnh_inches_mercury) self.mission.weather.season_temperature = atmospheric.temperature_celsius def set_clouds(self, clouds: Optional[Clouds]) -> None: diff --git a/gen/kneeboard.py b/gen/kneeboard.py index 110dff55..35aac4e3 100644 --- a/gen/kneeboard.py +++ b/gen/kneeboard.py @@ -39,6 +39,7 @@ from game.db import unit_type_from_name from game.dcs.aircrafttype import AircraftType from game.theater import ConflictTheater, TheaterGroundObject, LatLon from game.theater.bullseye import Bullseye +from game.weather import Weather from game.utils import meters from .aircraft import FlightData from .airsupportgen import AwacsInfo, TankerInfo @@ -46,6 +47,7 @@ from .briefinggen import CommInfo, JtacInfo, MissionInfoGenerator from .flights.flight import FlightWaypoint, FlightWaypointType, FlightType from .radios import RadioFrequency from .runways import RunwayData +from .units import inches_hg_to_mm_hg, inches_hg_to_hpa if TYPE_CHECKING: from game import Game @@ -265,12 +267,14 @@ class BriefingPage(KneeboardPage): flight: FlightData, bullseye: Bullseye, theater: ConflictTheater, + weather: Weather, start_time: datetime.datetime, dark_kneeboard: bool, ) -> None: self.flight = flight self.bullseye = bullseye self.theater = theater + self.weather = weather self.start_time = start_time self.dark_kneeboard = dark_kneeboard @@ -304,6 +308,18 @@ class BriefingPage(KneeboardPage): writer.text(f"Bullseye: {self.bullseye.to_lat_lon(self.theater).format_dms()}") + qnh_in_hg = "{:.2f}".format(self.weather.atmospheric.qnh_inches_mercury) + qnh_mm_hg = "{:.1f}".format( + inches_hg_to_mm_hg(self.weather.atmospheric.qnh_inches_mercury) + ) + qnh_hpa = "{:.1f}".format( + inches_hg_to_hpa(self.weather.atmospheric.qnh_inches_mercury) + ) + writer.text( + f"Temperature: {round(self.weather.atmospheric.temperature_celsius)} °C at sea level" + ) + writer.text(f"QNH: {qnh_in_hg} inHg / {qnh_mm_hg} mmHg / {qnh_hpa} hPa") + writer.table( [ [ @@ -634,6 +650,7 @@ class KneeboardGenerator(MissionInfoGenerator): flight, self.game.bullseye_for(flight.friendly), self.game.theater, + self.game.conditions.weather, self.mission.start_time, self.dark_kneeboard, ), diff --git a/gen/units.py b/gen/units.py index cfd16ab8..9aec8348 100644 --- a/gen/units.py +++ b/gen/units.py @@ -2,5 +2,15 @@ def meters_to_feet(meters: float) -> float: - """Convers meters to feet.""" + """Converts meters to feet.""" return meters * 3.28084 + + +def inches_hg_to_mm_hg(inches_hg: float) -> float: + """Converts inches mercury to millimeters mercury.""" + return inches_hg * 25.400002776728 + + +def inches_hg_to_hpa(inches_hg: float) -> float: + """Converts inches mercury to hectopascal.""" + return inches_hg * 33.86389