Limit task type combo box to valid mission types.

This commit is contained in:
Dan Albert 2020-09-25 00:25:25 -07:00
parent 0e1dfb8ccb
commit a3c06ce6e0
3 changed files with 106 additions and 16 deletions

View File

@ -1,22 +1,105 @@
"""Combo box for selecting a flight's task type.""" """Combo box for selecting a flight's task type."""
import logging
from typing import Iterator
from PySide2.QtWidgets import QComboBox from PySide2.QtWidgets import QComboBox
from gen.flights.flight import FlightType from gen.flights.flight import FlightType
from theater import (
ConflictTheater,
ControlPoint,
FrontLine,
MissionTarget,
TheaterGroundObject,
)
class QFlightTypeComboBox(QComboBox): class QFlightTypeComboBox(QComboBox):
"""Combo box for selecting a flight task type.""" """Combo box for selecting a flight task type."""
def __init__(self) -> None: COMMON_ENEMY_MISSIONS = [
FlightType.TARCAP,
FlightType.SEAD,
FlightType.DEAD,
# TODO: FlightType.ELINT,
# TODO: FlightType.ESCORT,
# TODO: FlightType.EWAR,
# TODO: FlightType.RECON,
]
FRIENDLY_AIRBASE_MISSIONS = [
FlightType.CAP,
# TODO: FlightType.INTERCEPTION
# TODO: FlightType.LOGISTICS
]
FRIENDLY_CARRIER_MISSIONS = [
FlightType.BARCAP,
# TODO: FlightType.INTERCEPTION
# TODO: Buddy tanking for the A-4?
# TODO: Rescue chopper?
# TODO: Inter-ship logistics?
]
ENEMY_CARRIER_MISSIONS = [
FlightType.TARCAP,
# TODO: FlightType.ANTISHIP
# TODO: FlightType.ESCORT,
]
ENEMY_AIRBASE_MISSIONS = [
# TODO: FlightType.STRIKE
] + COMMON_ENEMY_MISSIONS
FRIENDLY_GROUND_OBJECT_MISSIONS = [
FlightType.CAP,
# TODO: FlightType.LOGISTICS
# TODO: FlightType.TROOP_TRANSPORT
]
ENEMY_GROUND_OBJECT_MISSIONS = [
FlightType.STRIKE,
] + COMMON_ENEMY_MISSIONS
FRONT_LINE_MISSIONS = [
FlightType.CAS,
# TODO: FlightType.TROOP_TRANSPORT
# TODO: FlightType.EVAC
] + COMMON_ENEMY_MISSIONS
# TODO: Add BAI missions after we have useful BAI targets.
def __init__(self, theater: ConflictTheater, target: MissionTarget) -> None:
super().__init__() super().__init__()
self.addItem("CAP [Combat Air Patrol]", userData=FlightType.CAP) self.theater = theater
self.addItem("BARCAP [Barrier Combat Air Patrol]", userData=FlightType.BARCAP) self.target = target
self.addItem("TARCAP [Target Combat Air Patrol]", userData=FlightType.TARCAP) for mission_type in self.mission_types_for_target():
self.addItem("INTERCEPT [Interception]", userData=FlightType.INTERCEPTION) self.addItem(mission_type.name, userData=mission_type)
self.addItem("CAS [Close Air Support]", userData=FlightType.CAS)
self.addItem("BAI [Battlefield Interdiction]", userData=FlightType.BAI) def mission_types_for_target(self) -> Iterator[FlightType]:
self.addItem("SEAD [Suppression of Enemy Air Defenses]", userData=FlightType.SEAD) if isinstance(self.target, ControlPoint):
self.addItem("DEAD [Destruction of Enemy Air Defenses]", userData=FlightType.DEAD) friendly = self.target.captured
self.addItem("STRIKE [Strike]", userData=FlightType.STRIKE) fleet = self.target.is_fleet
self.addItem("ANTISHIP [Antiship Attack]", userData=FlightType.ANTISHIP) if friendly:
self.model().sort(0) if fleet:
yield from self.FRIENDLY_CARRIER_MISSIONS
else:
yield from self.FRIENDLY_AIRBASE_MISSIONS
else:
if fleet:
yield from self.ENEMY_CARRIER_MISSIONS
else:
yield from self.ENEMY_AIRBASE_MISSIONS
elif isinstance(self.target, TheaterGroundObject):
# TODO: Filter more based on the category.
friendly = self.target.parent_control_point(self.theater).captured
if friendly:
yield from self.FRIENDLY_GROUND_OBJECT_MISSIONS
else:
yield from self.ENEMY_GROUND_OBJECT_MISSIONS
elif isinstance(self.target, FrontLine):
yield from self.FRONT_LINE_MISSIONS
else:
logging.error(
f"Unhandled target type: {self.target.__class__.__name__}"
)

View File

@ -36,8 +36,9 @@ class QFlightCreator(QDialog):
layout = QVBoxLayout() layout = QVBoxLayout()
# TODO: Limit task selection to those valid for the target type. self.task_selector = QFlightTypeComboBox(
self.task_selector = QFlightTypeComboBox() self.game.theater, self.package.target
)
self.task_selector.setCurrentIndex(0) self.task_selector.setCurrentIndex(0)
layout.addLayout(QLabeledWidget("Task:", self.task_selector)) layout.addLayout(QLabeledWidget("Task:", self.task_selector))

View File

@ -1,11 +1,9 @@
from typing import List
import uuid import uuid
from dcs.mapping import Point from dcs.mapping import Point
from .missiontarget import MissionTarget from .missiontarget import MissionTarget
NAME_BY_CATEGORY = { NAME_BY_CATEGORY = {
"power": "Power plant", "power": "Power plant",
"ammo": "Ammo depot", "ammo": "Ammo depot",
@ -102,3 +100,11 @@ class TheaterGroundObject(MissionTarget):
@property @property
def name(self) -> str: def name(self) -> str:
return self.obj_name return self.obj_name
def parent_control_point(
self, theater: "ConflictTheater") -> "ControlPoint":
"""Searches the theater for the parent control point."""
for cp in theater.controlpoints:
if cp.id == self.cp_id:
return cp
raise RuntimeError("Could not find matching control point in theater")