diff --git a/game/dcs/aircrafttype.py b/game/dcs/aircrafttype.py index 7232f1a1..5d3ee09a 100644 --- a/game/dcs/aircrafttype.py +++ b/game/dcs/aircrafttype.py @@ -29,7 +29,7 @@ from game.radio.channels import ( ViggenRadioChannelAllocator, NoOpChannelAllocator, ) -from game.utils import Speed, kph +from game.utils import Distance, Speed, feet, kph, knots if TYPE_CHECKING: from gen.aircraft import FlightData @@ -90,12 +90,29 @@ class RadioConfig: }[config.get("namer", "default")] +@dataclass(frozen=True) +class PatrolConfig: + altitude: Optional[Distance] + speed: Optional[Speed] + + @classmethod + def from_data(cls, data: dict[str, Any]) -> PatrolConfig: + altitude = data.get("altitude", None) + speed = data.get("altitude", None) + return PatrolConfig( + feet(altitude) if altitude is not None else None, + knots(speed) if speed is not None else None, + ) + + @dataclass(frozen=True) class AircraftType(UnitType[FlyingType]): carrier_capable: bool lha_capable: bool always_keeps_gun: bool max_group_size: int + patrol_altitude: Optional[Distance] + patrol_speed: Optional[Speed] intra_flight_radio: Optional[Radio] channel_allocator: Optional[RadioChannelAllocator] channel_namer: Type[ChannelNamer] @@ -192,6 +209,7 @@ class AircraftType(UnitType[FlyingType]): raise KeyError(f"Missing required price field: {data_path}") from ex radio_config = RadioConfig.from_data(data.get("radios", {})) + patrol_config = PatrolConfig.from_data(data.get("patrol", {})) try: introduction = data["introduced"] @@ -214,6 +232,8 @@ class AircraftType(UnitType[FlyingType]): lha_capable=data.get("lha_capable", False), always_keeps_gun=data.get("always_keeps_gun", False), max_group_size=data.get("max_group_size", aircraft.group_size_max), + patrol_altitude=patrol_config.altitude, + patrol_speed=patrol_config.speed, intra_flight_radio=radio_config.intra_flight, channel_allocator=radio_config.channel_allocator, channel_namer=radio_config.channel_namer, diff --git a/gen/flights/flightplan.py b/gen/flights/flightplan.py index 66fd4022..af33411f 100644 --- a/gen/flights/flightplan.py +++ b/gen/flights/flightplan.py @@ -16,17 +16,6 @@ from functools import cached_property from typing import Iterator, List, Optional, Set, TYPE_CHECKING, Tuple from dcs.mapping import Point -from dcs.planes import ( - E_3A, - E_2C, - A_50, - IL_78M, - KC130, - KC135MPRS, - KC_135, - KJ_2000, - S_3B_Tanker, -) from dcs.unit import Unit from shapely.geometry import Point as ShapelyPoint @@ -1092,15 +1081,8 @@ class FlightPlanBuilder: orbit_location = self.aewc_orbit(location) - # As high as possible to maximize detection and on-station time. - if flight.unit_type.dcs_unit_type == E_2C: - patrol_alt = feet(30000) - elif flight.unit_type.dcs_unit_type == E_3A: - patrol_alt = feet(35000) - elif flight.unit_type.dcs_unit_type == A_50: - patrol_alt = feet(33000) - elif flight.unit_type.dcs_unit_type == KJ_2000: - patrol_alt = feet(40000) + if flight.unit_type.patrol_altitude is not None: + patrol_alt = flight.unit_type.patrol_altitude else: patrol_alt = feet(25000) @@ -1680,31 +1662,17 @@ class FlightPlanBuilder: builder = WaypointBuilder(flight, self.game, self.is_player) tanker_type = flight.unit_type - if tanker_type.dcs_unit_type is KC_135: - # ~300 knots IAS. - speed = knots(445) - altitude = feet(24000) - elif tanker_type.dcs_unit_type is KC135MPRS: - # ~300 knots IAS. - speed = knots(440) - altitude = feet(23000) - elif tanker_type.dcs_unit_type is KC130: - # ~210 knots IAS, roughly the max for the KC-130 at altitude. - speed = knots(370) - altitude = feet(22000) - elif tanker_type.dcs_unit_type is S_3B_Tanker: - # ~265 knots IAS. - speed = knots(320) - altitude = feet(12000) - elif tanker_type.dcs_unit_type is IL_78M: - # ~280 knots IAS. - speed = knots(400) - altitude = feet(21000) + if tanker_type.patrol_altitude is not None: + altitude = tanker_type.patrol_altitude else: - # ~280 knots IAS. - speed = knots(400) altitude = feet(21000) + if tanker_type.patrol_speed is not None: + speed = tanker_type.patrol_speed + else: + # ~280 knots IAS at 21000. + speed = knots(400) + racetrack = builder.race_track(racetrack_start, racetrack_end, altitude) return RefuelingFlightPlan( diff --git a/resources/units/aircraft/A-50.yaml b/resources/units/aircraft/A-50.yaml index 0f4af5d9..574f8cd9 100644 --- a/resources/units/aircraft/A-50.yaml +++ b/resources/units/aircraft/A-50.yaml @@ -1,5 +1,7 @@ description: The A-50 is an AWACS plane. max_group_size: 1 price: 50 +patrol: + altitude: 33000 variants: A-50: null diff --git a/resources/units/aircraft/E-2C.yaml b/resources/units/aircraft/E-2C.yaml index 8cd9a2f1..ca25d97e 100644 --- a/resources/units/aircraft/E-2C.yaml +++ b/resources/units/aircraft/E-2C.yaml @@ -8,5 +8,7 @@ manufacturer: Northrop Grumman origin: USA price: 50 role: AEW&C +patrol: + altitude: 30000 variants: E-2C Hawkeye: {} diff --git a/resources/units/aircraft/E-3A.yaml b/resources/units/aircraft/E-3A.yaml index af277724..ca781a23 100644 --- a/resources/units/aircraft/E-3A.yaml +++ b/resources/units/aircraft/E-3A.yaml @@ -1,5 +1,7 @@ description: The E-3A is a AWACS aicraft. price: 50 max_group_size: 1 +patrol: + altitude: 35000 variants: E-3A: null diff --git a/resources/units/aircraft/IL-78M.yaml b/resources/units/aircraft/IL-78M.yaml index 2cddc0f0..2acd1ea3 100644 --- a/resources/units/aircraft/IL-78M.yaml +++ b/resources/units/aircraft/IL-78M.yaml @@ -1,4 +1,8 @@ price: 20 max_group_size: 1 +patrol: + # ~280 knots IAS. + speed: 400 + altitude: 21000 variants: IL-78M: null diff --git a/resources/units/aircraft/KC-135.yaml b/resources/units/aircraft/KC-135.yaml index 91db8626..138ae873 100644 --- a/resources/units/aircraft/KC-135.yaml +++ b/resources/units/aircraft/KC-135.yaml @@ -8,5 +8,9 @@ manufacturer: Beoing origin: USA price: 25 role: Tanker +patrol: + # ~300 knots IAS. + speed: 445 + altitude: 24000 variants: KC-135 Stratotanker: {} diff --git a/resources/units/aircraft/KC130.yaml b/resources/units/aircraft/KC130.yaml index 04b429aa..802a16bb 100644 --- a/resources/units/aircraft/KC130.yaml +++ b/resources/units/aircraft/KC130.yaml @@ -5,5 +5,9 @@ manufacturer: Lockheed Martin origin: USA price: 25 role: Tanker +patrol: + # ~210 knots IAS, roughly the max for the KC-130 at altitude. + speed: 370 + altitude: 22000 variants: KC-130: {} diff --git a/resources/units/aircraft/KC135MPRS.yaml b/resources/units/aircraft/KC135MPRS.yaml index 63b379e8..4ba28ff5 100644 --- a/resources/units/aircraft/KC135MPRS.yaml +++ b/resources/units/aircraft/KC135MPRS.yaml @@ -7,5 +7,9 @@ manufacturer: Boeing origin: USA price: 25 role: Tanker +patrol: + # 300 knots IAS. + speed: 440 + altitude: 23000 variants: KC-135 Stratotanker MPRS: {} diff --git a/resources/units/aircraft/KJ-2000.yaml b/resources/units/aircraft/KJ-2000.yaml index 04f29793..cbb843c8 100644 --- a/resources/units/aircraft/KJ-2000.yaml +++ b/resources/units/aircraft/KJ-2000.yaml @@ -1,3 +1,5 @@ price: 50 +patrol: + altitude: 40000 variants: KJ-2000: null diff --git a/resources/units/aircraft/S-3B Tanker.yaml b/resources/units/aircraft/S-3B Tanker.yaml index 990c1a61..dabe7056 100644 --- a/resources/units/aircraft/S-3B Tanker.yaml +++ b/resources/units/aircraft/S-3B Tanker.yaml @@ -16,5 +16,9 @@ origin: USA price: 20 max_group_size: 1 role: Carrier-based Tanker +patrol: + # ~265 knots IAS. + speed: 320 + altitude: 12000 variants: S-3B Tanker: {}