mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Fix mypy regressions.
Mostly in the plugin system, which needed a handful of asserts that shouldn't be necessary, but fixing them requires a refactor.
This commit is contained in:
@@ -205,6 +205,9 @@ class ChannelAssignment:
|
||||
class FlightData:
|
||||
"""Details of a planned flight."""
|
||||
|
||||
#: The package that the flight belongs to.
|
||||
package: Package
|
||||
|
||||
flight_type: FlightType
|
||||
|
||||
#: All units in the flight.
|
||||
@@ -237,14 +240,13 @@ class FlightData:
|
||||
#: Map of radio frequencies to their assigned radio and channel, if any.
|
||||
frequency_to_channel_map: Dict[RadioFrequency, ChannelAssignment]
|
||||
|
||||
#: Data concerning the target of a CAS/Strike/SEAD flight, or None else
|
||||
targetPoint = None
|
||||
|
||||
def __init__(self, flight_type: FlightType, units: List[FlyingUnit],
|
||||
size: int, friendly: bool, departure_delay: int,
|
||||
departure: RunwayData, arrival: RunwayData,
|
||||
divert: Optional[RunwayData], waypoints: List[FlightWaypoint],
|
||||
intra_flight_channel: RadioFrequency, targetPoint: Optional) -> None:
|
||||
def __init__(self, package: Package, flight_type: FlightType,
|
||||
units: List[FlyingUnit], size: int, friendly: bool,
|
||||
departure_delay: int, departure: RunwayData,
|
||||
arrival: RunwayData, divert: Optional[RunwayData],
|
||||
waypoints: List[FlightWaypoint],
|
||||
intra_flight_channel: RadioFrequency) -> None:
|
||||
self.package = package
|
||||
self.flight_type = flight_type
|
||||
self.units = units
|
||||
self.size = size
|
||||
@@ -257,7 +259,6 @@ class FlightData:
|
||||
self.intra_flight_channel = intra_flight_channel
|
||||
self.frequency_to_channel_map = {}
|
||||
self.callsign = create_group_callsign_from_unit(self.units[0])
|
||||
self.targetPoint = targetPoint
|
||||
|
||||
@property
|
||||
def client_units(self) -> List[FlyingUnit]:
|
||||
@@ -575,7 +576,8 @@ class AircraftConflictGenerator:
|
||||
return StartType.Warm
|
||||
|
||||
def _setup_group(self, group: FlyingGroup, for_task: Type[Task],
|
||||
flight: Flight, dynamic_runways: Dict[str, RunwayData]):
|
||||
package: Package, flight: Flight,
|
||||
dynamic_runways: Dict[str, RunwayData]) -> None:
|
||||
did_load_loadout = False
|
||||
unit_type = group.units[0].unit_type
|
||||
|
||||
@@ -635,6 +637,7 @@ class AircraftConflictGenerator:
|
||||
departure_runway = fallback_runway
|
||||
|
||||
self.flights.append(FlightData(
|
||||
package=package,
|
||||
flight_type=flight.flight_type,
|
||||
units=group.units,
|
||||
size=len(group.units),
|
||||
@@ -646,8 +649,7 @@ class AircraftConflictGenerator:
|
||||
divert=None,
|
||||
# Waypoints are added later, after they've had their TOTs set.
|
||||
waypoints=[],
|
||||
intra_flight_channel=channel,
|
||||
targetPoint=flight.targetPoint,
|
||||
intra_flight_channel=channel
|
||||
))
|
||||
|
||||
# Special case so Su 33 carrier take off
|
||||
@@ -789,7 +791,7 @@ class AircraftConflictGenerator:
|
||||
logging.info(f"Generating flight: {flight.unit_type}")
|
||||
group = self.generate_planned_flight(flight.from_cp, country,
|
||||
flight)
|
||||
self.setup_flight_group(group, flight, dynamic_runways)
|
||||
self.setup_flight_group(group, package, flight, dynamic_runways)
|
||||
self.create_waypoints(group, package, flight, timing)
|
||||
|
||||
def set_activation_time(self, flight: Flight, group: FlyingGroup,
|
||||
@@ -906,10 +908,11 @@ class AircraftConflictGenerator:
|
||||
if flight.unit_type.eplrs:
|
||||
group.points[0].tasks.append(EPLRS(group.id))
|
||||
|
||||
def configure_cap(self, group: FlyingGroup, flight: Flight,
|
||||
def configure_cap(self, group: FlyingGroup, package: Package,
|
||||
flight: Flight,
|
||||
dynamic_runways: Dict[str, RunwayData]) -> None:
|
||||
group.task = CAP.name
|
||||
self._setup_group(group, CAP, flight, dynamic_runways)
|
||||
self._setup_group(group, CAP, package, flight, dynamic_runways)
|
||||
|
||||
if flight.unit_type not in GUNFIGHTERS:
|
||||
ammo_type = OptRTBOnOutOfAmmo.Values.AAM
|
||||
@@ -921,10 +924,11 @@ class AircraftConflictGenerator:
|
||||
group.points[0].tasks.append(EngageTargets(max_distance=nm_to_meter(50),
|
||||
targets=[Targets.All.Air]))
|
||||
|
||||
def configure_cas(self, group: FlyingGroup, flight: Flight,
|
||||
def configure_cas(self, group: FlyingGroup, package: Package,
|
||||
flight: Flight,
|
||||
dynamic_runways: Dict[str, RunwayData]) -> None:
|
||||
group.task = CAS.name
|
||||
self._setup_group(group, CAS, flight, dynamic_runways)
|
||||
self._setup_group(group, CAS, package, flight, dynamic_runways)
|
||||
self.configure_behavior(
|
||||
group,
|
||||
react_on_threat=OptReactOnThreat.Values.EvadeFire,
|
||||
@@ -936,10 +940,11 @@ class AircraftConflictGenerator:
|
||||
targets=[Targets.All.GroundUnits.GroundVehicles])
|
||||
)
|
||||
|
||||
def configure_sead(self, group: FlyingGroup, flight: Flight,
|
||||
dynamic_runways: Dict[str, RunwayData]) -> None:
|
||||
def configure_sead(self, group: FlyingGroup, package: Package,
|
||||
flight: Flight,
|
||||
dynamic_runways: Dict[str, RunwayData]) -> None:
|
||||
group.task = SEAD.name
|
||||
self._setup_group(group, SEAD, flight, dynamic_runways)
|
||||
self._setup_group(group, SEAD, package, flight, dynamic_runways)
|
||||
self.configure_behavior(
|
||||
group,
|
||||
react_on_threat=OptReactOnThreat.Values.EvadeFire,
|
||||
@@ -947,33 +952,37 @@ class AircraftConflictGenerator:
|
||||
rtb_winchester=OptRTBOnOutOfAmmo.Values.ASM,
|
||||
restrict_jettison=True)
|
||||
|
||||
def configure_strike(self, group: FlyingGroup, flight: Flight,
|
||||
def configure_strike(self, group: FlyingGroup, package: Package,
|
||||
flight: Flight,
|
||||
dynamic_runways: Dict[str, RunwayData]) -> None:
|
||||
group.task = PinpointStrike.name
|
||||
self._setup_group(group, GroundAttack, flight, dynamic_runways)
|
||||
self._setup_group(group, GroundAttack, package, flight, dynamic_runways)
|
||||
self.configure_behavior(
|
||||
group,
|
||||
react_on_threat=OptReactOnThreat.Values.EvadeFire,
|
||||
roe=OptROE.Values.OpenFire,
|
||||
restrict_jettison=True)
|
||||
|
||||
def configure_anti_ship(self, group: FlyingGroup, flight: Flight,
|
||||
def configure_anti_ship(self, group: FlyingGroup, package: Package,
|
||||
flight: Flight,
|
||||
dynamic_runways: Dict[str, RunwayData]) -> None:
|
||||
group.task = AntishipStrike.name
|
||||
self._setup_group(group, AntishipStrike, flight, dynamic_runways)
|
||||
self._setup_group(group, AntishipStrike, package, flight,
|
||||
dynamic_runways)
|
||||
self.configure_behavior(
|
||||
group,
|
||||
react_on_threat=OptReactOnThreat.Values.EvadeFire,
|
||||
roe=OptROE.Values.OpenFire,
|
||||
restrict_jettison=True)
|
||||
|
||||
def configure_escort(self, group: FlyingGroup, flight: Flight,
|
||||
def configure_escort(self, group: FlyingGroup, package: Package,
|
||||
flight: Flight,
|
||||
dynamic_runways: Dict[str, RunwayData]) -> None:
|
||||
# Escort groups are actually given the CAP task so they can perform the
|
||||
# Search Then Engage task, which we have to use instead of the Escort
|
||||
# task for the reasons explained in JoinPointBuilder.
|
||||
group.task = CAP.name
|
||||
self._setup_group(group, CAP, flight, dynamic_runways)
|
||||
self._setup_group(group, CAP, package, flight, dynamic_runways)
|
||||
self.configure_behavior(group, roe=OptROE.Values.OpenFire,
|
||||
restrict_jettison=True)
|
||||
|
||||
@@ -982,22 +991,23 @@ class AircraftConflictGenerator:
|
||||
logging.error(f"Unhandled flight type: {flight.flight_type.name}")
|
||||
self.configure_behavior(group)
|
||||
|
||||
def setup_flight_group(self, group: FlyingGroup, flight: Flight,
|
||||
def setup_flight_group(self, group: FlyingGroup, package: Package,
|
||||
flight: Flight,
|
||||
dynamic_runways: Dict[str, RunwayData]) -> None:
|
||||
flight_type = flight.flight_type
|
||||
if flight_type in [FlightType.BARCAP, FlightType.TARCAP,
|
||||
FlightType.INTERCEPTION]:
|
||||
self.configure_cap(group, flight, dynamic_runways)
|
||||
self.configure_cap(group, package, flight, dynamic_runways)
|
||||
elif flight_type in [FlightType.CAS, FlightType.BAI]:
|
||||
self.configure_cas(group, flight, dynamic_runways)
|
||||
self.configure_cas(group, package, flight, dynamic_runways)
|
||||
elif flight_type in [FlightType.SEAD, FlightType.DEAD]:
|
||||
self.configure_sead(group, flight, dynamic_runways)
|
||||
self.configure_sead(group, package, flight, dynamic_runways)
|
||||
elif flight_type in [FlightType.STRIKE]:
|
||||
self.configure_strike(group, flight, dynamic_runways)
|
||||
self.configure_strike(group, package, flight, dynamic_runways)
|
||||
elif flight_type in [FlightType.ANTISHIP]:
|
||||
self.configure_anti_ship(group, flight, dynamic_runways)
|
||||
self.configure_anti_ship(group, package, flight, dynamic_runways)
|
||||
elif flight_type == FlightType.ESCORT:
|
||||
self.configure_escort(group, flight, dynamic_runways)
|
||||
self.configure_escort(group, package, flight, dynamic_runways)
|
||||
else:
|
||||
self.configure_unknown_task(group, flight)
|
||||
|
||||
|
||||
@@ -206,10 +206,9 @@ class PackageBuilder:
|
||||
if assignment is None:
|
||||
return False
|
||||
airfield, aircraft = assignment
|
||||
flight = Flight(aircraft, plan.num_aircraft, airfield, plan.task,
|
||||
self.start_type)
|
||||
flight = Flight(self.package, aircraft, plan.num_aircraft, airfield,
|
||||
plan.task, self.start_type)
|
||||
self.package.add_flight(flight)
|
||||
flight.targetPoint = self.package.target
|
||||
return True
|
||||
|
||||
def build(self) -> Package:
|
||||
@@ -222,7 +221,7 @@ class PackageBuilder:
|
||||
for flight in flights:
|
||||
self.global_inventory.return_from_flight(flight)
|
||||
self.package.remove_flight(flight)
|
||||
flight.targetPoint = None
|
||||
|
||||
|
||||
class ObjectiveFinder:
|
||||
"""Identifies potential objectives for the mission planner."""
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from enum import Enum
|
||||
from typing import Dict, Iterable, List, Optional
|
||||
from typing import Dict, Iterable, List, Optional, TYPE_CHECKING
|
||||
|
||||
from dcs.mapping import Point
|
||||
from dcs.point import MovingPoint, PointAction
|
||||
@@ -8,6 +10,9 @@ from dcs.unittype import UnitType
|
||||
from game import db
|
||||
from theater.controlpoint import ControlPoint, MissionTarget
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from gen.ato import Package
|
||||
|
||||
|
||||
class FlightType(Enum):
|
||||
CAP = 0 # Do not use. Use BARCAP or TARCAP.
|
||||
@@ -138,10 +143,11 @@ class Flight:
|
||||
use_custom_loadout = False
|
||||
preset_loadout_name = ""
|
||||
group = False # Contains DCS Mission group data after mission has been generated
|
||||
targetPoint = None # Contains either None or a Strike/SEAD target point location
|
||||
|
||||
def __init__(self, unit_type: UnitType, count: int, from_cp: ControlPoint,
|
||||
flight_type: FlightType, start_type: str) -> None:
|
||||
def __init__(self, package: Package, unit_type: UnitType, count: int,
|
||||
from_cp: ControlPoint, flight_type: FlightType,
|
||||
start_type: str) -> None:
|
||||
self.package = package
|
||||
self.unit_type = unit_type
|
||||
self.count = count
|
||||
self.from_cp = from_cp
|
||||
|
||||
@@ -186,6 +186,12 @@ class TotEstimator:
|
||||
time_to_target = self.estimate_waypoints_to_target(flight, {
|
||||
FlightWaypointType.PATROL_TRACK
|
||||
})
|
||||
if time_to_target is None:
|
||||
logging.warning(
|
||||
f"Found no race track. Cannot estimate TOT for {flight}")
|
||||
# Return 0 so this flight's travel time does not affect the rest
|
||||
# of the package.
|
||||
return 0
|
||||
else:
|
||||
time_to_ingress = self.estimate_waypoints_to_target(
|
||||
flight, INGRESS_TYPES
|
||||
|
||||
Reference in New Issue
Block a user