Update pydcs.

This update includes expanded runway data that lets us clean up some
code. It also include beacon IDs for runways and airfields that will let
us get ILS and TACAN info from pydcs, but that's a bigger change that
I'll land separately.
This commit is contained in:
Dan Albert 2022-09-22 01:51:06 -07:00 committed by Raffson
parent 46eed54705
commit c7705fd545
No known key found for this signature in database
GPG Key ID: B0402B2C9B764D99
2 changed files with 17 additions and 23 deletions

View File

@ -5,7 +5,7 @@ import logging
from dataclasses import dataclass from dataclasses import dataclass
from typing import Iterator, Optional, TYPE_CHECKING from typing import Iterator, Optional, TYPE_CHECKING
from dcs.terrain.terrain import Airport from dcs.terrain.terrain import Airport, RunwayApproach
from game.airfields import AirfieldData, AtcData from game.airfields import AirfieldData, AtcData
from game.radio.radios import RadioFrequency from game.radio.radios import RadioFrequency
@ -29,20 +29,18 @@ class RunwayData:
icls: Optional[int] = None icls: Optional[int] = None
@classmethod @classmethod
def for_airfield( def for_pydcs_runway_runway(
cls, cls,
theater: ConflictTheater, theater: ConflictTheater,
airport: Airport, airport: Airport,
runway_heading: Heading, runway: RunwayApproach,
runway_name: str,
) -> RunwayData: ) -> RunwayData:
"""Creates RunwayData for the given runway of an airfield. """Creates RunwayData for the given runway of an airfield.
Args: Args:
theater: The theater the airport is in. theater: The theater the airport is in.
airport: The airfield the runway belongs to. airport: The airfield the runway belongs to.
runway_heading: Heading of the runway. runway: The pydcs runway.
runway_name: Identifier of the runway to use. e.g. "03" or "20L".
""" """
atc: Optional[RadioFrequency] = None atc: Optional[RadioFrequency] = None
tacan: Optional[TacanChannel] = None tacan: Optional[TacanChannel] = None
@ -56,13 +54,13 @@ class RunwayData:
airfield = AirfieldData.for_airport(theater, airport) airfield = AirfieldData.for_airport(theater, airport)
tacan = airfield.tacan tacan = airfield.tacan
tacan_callsign = airfield.tacan_callsign tacan_callsign = airfield.tacan_callsign
ils = airfield.ils_freq(runway_name) ils = airfield.ils_freq(runway.name)
except KeyError: except KeyError:
logging.warning(f"No airfield data for {airport.name} ({airport.id}") logging.warning(f"No airfield data for {airport.name} ({airport.id}")
return cls( return cls(
airfield_name=airport.name, airfield_name=airport.name,
runway_heading=runway_heading, runway_heading=Heading(runway.heading),
runway_name=runway_name, runway_name=runway.name,
atc=atc, atc=atc,
tacan=tacan, tacan=tacan,
tacan_callsign=tacan_callsign, tacan_callsign=tacan_callsign,
@ -74,20 +72,16 @@ class RunwayData:
cls, theater: ConflictTheater, airport: Airport cls, theater: ConflictTheater, airport: Airport
) -> Iterator[RunwayData]: ) -> Iterator[RunwayData]:
for runway in airport.runways: for runway in airport.runways:
runway_number = runway.heading // 10 yield cls.for_pydcs_runway_runway(
runway_side = ["", "L", "R"][runway.leftright] theater,
runway_name = f"{runway_number:02}{runway_side}" airport,
yield cls.for_airfield( runway.main,
theater, airport, Heading.from_degrees(runway.heading), runway_name )
yield cls.for_pydcs_runway_runway(
theater,
airport,
runway.opposite,
) )
# pydcs only exposes one runway per physical runway, so to expose
# both sides of the runway we need to generate the other.
heading = Heading.from_degrees(runway.heading).opposite
runway_number = heading.degrees // 10
runway_side = ["", "R", "L"][runway.leftright]
runway_name = f"{runway_number:02}{runway_side}"
yield cls.for_airfield(theater, airport, heading, runway_name)
class RunwayAssigner: class RunwayAssigner:

View File

@ -32,7 +32,7 @@ pluggy==1.0.0
pre-commit==2.19.0 pre-commit==2.19.0
py==1.11.0 py==1.11.0
pydantic==1.9.1 pydantic==1.9.1
-e git+https://github.com/pydcs/dcs@0d06bcdf8b2e0a82a2891c612b0a7d4c8a4a4548#egg=pydcs -e git+https://github.com/pydcs/dcs@4c104828ecb95b0f4b095a0a9ea353bde75f48d0#egg=pydcs
pyinstaller==5.2 pyinstaller==5.2
pyinstaller-hooks-contrib==2022.8 pyinstaller-hooks-contrib==2022.8
pyparsing==3.0.9 pyparsing==3.0.9