mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Get TACAN and ILS data from pydcs.
This commit is contained in:
parent
08abe36443
commit
e0160ac876
@ -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,
|
||||
|
||||
@ -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),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user