Move mission type compatibility to the target.

This was also needed in other parts of the UI and is easier to implement
in the target class anyway.

Note that DEAD is now properly restricted to air defense targets.

Also added error boxes to the UI for when planning fails on an invalid
target.
This commit is contained in:
Dan Albert
2020-11-16 19:57:26 -08:00
parent f3553ced78
commit 8bd00bf450
9 changed files with 119 additions and 138 deletions

View File

@@ -1,107 +1,16 @@
"""Combo box for selecting a flight's task type."""
import logging
from typing import Iterator
from PySide2.QtWidgets import QComboBox
from gen.flights.flight import FlightType
from theater import (
ConflictTheater,
ControlPoint,
FrontLine,
MissionTarget,
TheaterGroundObject,
)
from theater import ConflictTheater, MissionTarget
class QFlightTypeComboBox(QComboBox):
"""Combo box for selecting a flight task type."""
COMMON_ENEMY_MISSIONS = [
FlightType.TARCAP,
FlightType.ESCORT,
FlightType.SEAD,
FlightType.DEAD,
FlightType.SWEEP,
# TODO: FlightType.ELINT,
# TODO: FlightType.EWAR,
# TODO: FlightType.RECON,
]
COMMON_FRIENDLY_MISSIONS = [
FlightType.BARCAP,
]
FRIENDLY_AIRBASE_MISSIONS = [
# TODO: FlightType.INTERCEPTION
# TODO: FlightType.LOGISTICS
] + COMMON_FRIENDLY_MISSIONS
FRIENDLY_CARRIER_MISSIONS = [
# TODO: FlightType.INTERCEPTION
# TODO: Buddy tanking for the A-4?
# TODO: Rescue chopper?
# TODO: Inter-ship logistics?
] + COMMON_FRIENDLY_MISSIONS
ENEMY_CARRIER_MISSIONS = [
FlightType.ESCORT,
FlightType.BARCAP,
# TODO: FlightType.ANTISHIP
]
ENEMY_AIRBASE_MISSIONS = [
# TODO: FlightType.STRIKE
] + COMMON_ENEMY_MISSIONS
FRIENDLY_GROUND_OBJECT_MISSIONS = [
# TODO: FlightType.LOGISTICS
# TODO: FlightType.TROOP_TRANSPORT
] + COMMON_FRIENDLY_MISSIONS
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__()
self.theater = theater
self.target = target
for mission_type in self.mission_types_for_target():
for mission_type in self.target.mission_types(for_player=True):
self.addItem(mission_type.name, userData=mission_type)
def mission_types_for_target(self) -> Iterator[FlightType]:
if isinstance(self.target, ControlPoint):
friendly = self.target.captured
fleet = self.target.is_fleet
if friendly:
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.control_point.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__}"
)