diff --git a/game/airfields.py b/game/airfields.py index 2f14575f..b58ad77d 100644 --- a/game/airfields.py +++ b/game/airfields.py @@ -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, diff --git a/game/runways.py b/game/runways.py index 8576ee7e..ff6131b4 100644 --- a/game/runways.py +++ b/game/runways.py @@ -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),