Get TACAN and ILS data from pydcs.

This commit is contained in:
Dan Albert 2022-09-27 18:04:42 -07:00 committed by Raffson
parent e5074b57b8
commit 7c7d9f7066
No known key found for this signature in database
GPG Key ID: B0402B2C9B764D99
2 changed files with 13 additions and 41 deletions

View File

@ -16,7 +16,6 @@ from dcs.task import Modulation
from dcs.terrain import Airport
from game.radio.radios import RadioFrequency
from game.radio.tacan import TacanChannel
if TYPE_CHECKING:
from game.theater import ConflictTheater
@ -60,21 +59,12 @@ class AirfieldData:
#: Runway length (in ft).
runway_length: int = 0
#: TACAN channel for the airfield.
tacan: Optional[TacanChannel] = None
#: TACAN callsign
tacan_callsign: Optional[str] = None
#: VOR as a tuple of (callsign, frequency).
vor: Optional[Tuple[str, RadioFrequency]] = None
#: RSBN channel as a tuple of (callsign, channel).
rsbn: Optional[Tuple[str, int]] = None
#: Dict of runway heading -> ILS tuple of (callsign, frequency).
ils: Dict[str, Tuple[str, RadioFrequency]] = field(default_factory=dict)
#: Dict of runway heading -> PRMG tuple of (callsign, channel).
prmg: Dict[str, Tuple[str, int]] = field(default_factory=dict)
@ -86,23 +76,11 @@ class AirfieldData:
_airfields: ClassVar[dict[str, dict[int, AirfieldData]]] = {}
def ils_freq(self, runway: str) -> Optional[RadioFrequency]:
ils = self.ils.get(runway)
if ils is not None:
return ils[1]
return None
@classmethod
def from_file(cls, airfield_yaml: Path) -> AirfieldData:
with airfield_yaml.open() as yaml_file:
data = yaml.safe_load(yaml_file)
tacan_channel = None
tacan_callsign = None
if (tacan := data.get("tacan")) is not None:
tacan_channel = TacanChannel.parse(tacan["channel"])
tacan_callsign = tacan["callsign"]
vor = None
if (vor_data := data.get("vor")) is not None:
vor = (
@ -114,17 +92,10 @@ class AirfieldData:
if (rsbn_data := data.get("rsbn")) is not None:
rsbn = (rsbn_data["callsign"], rsbn_data["channel"])
ils = {}
prmg = {}
outer_ndb = {}
inner_ndb = {}
for name, runway_data in data.get("runways", {}).items():
if (ils_data := runway_data.get("ils")) is not None:
ils[name] = (
ils_data["callsign"],
RadioFrequency.parse(ils_data["frequency"], Modulation.FM),
)
if (prmg_data := runway_data.get("prmg")) is not None:
prmg[name] = (prmg_data["callsign"], prmg_data["channel"])
@ -146,11 +117,8 @@ class AirfieldData:
data.get("icao"),
data["elevation"],
data["runway_length"],
tacan_channel,
tacan_callsign,
vor,
rsbn,
ils,
prmg,
outer_ndb,
inner_ndb,

View File

@ -1,13 +1,13 @@
"""Runway information and selection."""
from __future__ import annotations
import logging
from dataclasses import dataclass
from typing import Iterator, Optional, TYPE_CHECKING
from dcs.terrain.terrain import Airport, RunwayApproach
from game.airfields import AirfieldData, AtcData
from game.airfields import AtcData
from game.dcs.beacons import BeaconType, Beacons
from game.radio.radios import RadioFrequency
from game.radio.tacan import TacanChannel
from game.utils import Heading
@ -50,13 +50,17 @@ class RunwayData:
if atc_radio is not None:
atc = atc_radio.uhf
try:
airfield = AirfieldData.for_airport(theater, airport)
tacan = airfield.tacan
tacan_callsign = airfield.tacan_callsign
ils = airfield.ils_freq(runway.name)
except KeyError:
logging.warning(f"No airfield data for {airport.name} ({airport.id}")
for beacon_data in airport.beacons:
beacon = Beacons.with_id(beacon_data.id, theater)
if beacon.is_tacan:
tacan = beacon.tacan_channel
tacan_callsign = beacon.callsign
for beacon_data in runway.beacons:
beacon = Beacons.with_id(beacon_data.id, theater)
if beacon.beacon_type is BeaconType.BEACON_TYPE_ILS_GLIDESLOPE:
ils = beacon.frequency
return cls(
airfield_name=airport.name,
runway_heading=Heading(runway.heading),