Fix names of tasks to not use the enum name.

This commit is contained in:
Dan Albert 2020-11-23 17:15:42 -08:00
parent 9394ed663a
commit 6e0af7c144
16 changed files with 39 additions and 67 deletions

View File

@ -433,7 +433,7 @@ class Operation:
FlightType.DEAD, FlightType.DEAD,
FlightType.SEAD, FlightType.SEAD,
FlightType.STRIKE]: FlightType.STRIKE]:
flightType = flight.flight_type.name flightType = str(flight.flight_type)
flightTarget = flight.package.target flightTarget = flight.package.target
if flightTarget: if flightTarget:
flightTargetName = None flightTargetName = None

View File

@ -954,8 +954,8 @@ class AircraftConflictGenerator:
# Creating a flight even those this isn't a fragged mission lets us # Creating a flight even those this isn't a fragged mission lets us
# reuse the existing debriefing code. # reuse the existing debriefing code.
# TODO: Special flight type? # TODO: Special flight type?
flight = Flight(Package(control_point), aircraft, 1, FlightType.CAP, flight = Flight(Package(control_point), aircraft, 1,
"Cold", departure=control_point, FlightType.BARCAP, "Cold", departure=control_point,
arrival=control_point, divert=None) arrival=control_point, divert=None)
group = self._generate_at_airport( group = self._generate_at_airport(
name=namegen.next_unit_name(country, control_point.id, name=namegen.next_unit_name(country, control_point.id,
@ -1196,7 +1196,7 @@ class AircraftConflictGenerator:
def configure_unknown_task(self, group: FlyingGroup, def configure_unknown_task(self, group: FlyingGroup,
flight: Flight) -> None: flight: Flight) -> None:
logging.error(f"Unhandled flight type: {flight.flight_type.name}") logging.error(f"Unhandled flight type: {flight.flight_type}")
self.configure_behavior(group) self.configure_behavior(group)
def setup_flight_group(self, group: FlyingGroup, package: Package, def setup_flight_group(self, group: FlyingGroup, package: Package,

View File

@ -147,20 +147,13 @@ class Package:
FlightType.CAS, FlightType.CAS,
FlightType.STRIKE, FlightType.STRIKE,
FlightType.ANTISHIP, FlightType.ANTISHIP,
FlightType.RUNWAY_ATTACK,
FlightType.BAI, FlightType.BAI,
FlightType.EVAC,
FlightType.TROOP_TRANSPORT,
FlightType.RECON,
FlightType.ELINT,
FlightType.DEAD, FlightType.DEAD,
FlightType.SEAD, FlightType.SEAD,
FlightType.LOGISTICS,
FlightType.INTERCEPTION,
FlightType.TARCAP, FlightType.TARCAP,
FlightType.CAP,
FlightType.BARCAP, FlightType.BARCAP,
FlightType.SWEEP, FlightType.SWEEP,
FlightType.EWAR,
FlightType.ESCORT, FlightType.ESCORT,
] ]
for task in task_priorities: for task in task_priorities:
@ -179,7 +172,7 @@ class Package:
task = self.primary_task task = self.primary_task
if task is None: if task is None:
return "No mission" return "No mission"
return task.name return str(task)
def __hash__(self) -> int: def __hash__(self) -> int:
# TODO: Far from perfect. Number packages? # TODO: Far from perfect. Number packages?

View File

@ -86,7 +86,7 @@ class ProposedFlight:
max_distance: int max_distance: int
def __str__(self) -> str: def __str__(self) -> str:
return f"{self.task.name} {self.num_aircraft} ship" return f"{self.task} {self.num_aircraft} ship"
@dataclass(frozen=True) @dataclass(frozen=True)

View File

@ -17,29 +17,21 @@ if TYPE_CHECKING:
class FlightType(Enum): class FlightType(Enum):
CAP = 0 # Do not use. Use BARCAP or TARCAP. TARCAP = "TARCAP"
TARCAP = 1 BARCAP = "BARCAP"
BARCAP = 2 CAS = "CAS"
CAS = 3 INTERCEPTION = "Intercept"
INTERCEPTION = 4 STRIKE = "Strike"
STRIKE = 5 ANTISHIP = "Anti-ship"
ANTISHIP = 6 SEAD = "SEAD"
SEAD = 7 DEAD = "DEAD"
DEAD = 8 ESCORT = "Escort"
ESCORT = 9 BAI = "BAI"
BAI = 10 SWEEP = "Fighter sweep"
RUNWAY_ATTACK = "Runway attack"
# Helos def __str__(self) -> str:
TROOP_TRANSPORT = 11 return self.value
LOGISTICS = 12
EVAC = 13
ELINT = 14
RECON = 15
EWAR = 16
SWEEP = 17
RUNWAY_ATTACK = 18
class FlightWaypointType(Enum): class FlightWaypointType(Enum):
@ -172,5 +164,5 @@ class Flight:
return self.flight_plan.waypoints[1:] return self.flight_plan.waypoints[1:]
def __repr__(self): def __repr__(self):
return self.flight_type.name + " | " + str(self.count) + "x" + db.unit_type_name(self.unit_type) \ name = db.unit_type_name(self.unit_type)
+ " (" + str(len(self.points)) + " wpt)" return f"[{self.flight_type}] {self.count} x {name}"

View File

@ -56,9 +56,7 @@ class PlanningError(RuntimeError):
class InvalidObjectiveLocation(PlanningError): class InvalidObjectiveLocation(PlanningError):
"""Raised when the objective location is invalid for the mission type.""" """Raised when the objective location is invalid for the mission type."""
def __init__(self, task: FlightType, location: MissionTarget) -> None: def __init__(self, task: FlightType, location: MissionTarget) -> None:
super().__init__( super().__init__(f"{location.name} is not valid for {task} missions.")
f"{location.name} is not valid for {task.name} missions."
)
@dataclass(frozen=True) @dataclass(frozen=True)
@ -661,12 +659,8 @@ class FlightPlanBuilder:
return self.generate_sweep(flight) return self.generate_sweep(flight)
elif task == FlightType.TARCAP: elif task == FlightType.TARCAP:
return self.generate_tarcap(flight) return self.generate_tarcap(flight)
elif task == FlightType.TROOP_TRANSPORT:
logging.error(
"Troop transport flight plan generation not implemented"
)
raise PlanningError( raise PlanningError(
f"{task.name} flight plan generation not implemented") f"{task} flight plan generation not implemented")
def regenerate_package_waypoints(self) -> None: def regenerate_package_waypoints(self) -> None:
ingress_point = self._ingress_point() ingress_point = self._ingress_point()

View File

@ -121,14 +121,11 @@ class PackageModel(QAbstractListModel):
def text_for_flight(self, flight: Flight) -> str: def text_for_flight(self, flight: Flight) -> str:
"""Returns the text that should be displayed for the flight.""" """Returns the text that should be displayed for the flight."""
task = flight.flight_type.name
count = flight.count
name = db.unit_type_name(flight.unit_type)
estimator = TotEstimator(self.package) estimator = TotEstimator(self.package)
delay = datetime.timedelta( delay = datetime.timedelta(
seconds=int(estimator.mission_start_time(flight).total_seconds())) seconds=int(estimator.mission_start_time(flight).total_seconds()))
origin = flight.from_cp.name origin = flight.from_cp.name
return f"[{task}] {count} x {name} from {origin} in {delay}" return f"{flight} from {origin} in {delay}"
@staticmethod @staticmethod
def icon_for_flight(flight: Flight) -> Optional[QIcon]: def icon_for_flight(flight: Flight) -> Optional[QIcon]:

View File

@ -171,7 +171,7 @@ class QTopPanel(QFrame):
def confirm_negative_start_time(self, def confirm_negative_start_time(self,
negative_starts: List[Package]) -> bool: negative_starts: List[Package]) -> bool:
formatted = '<br />'.join( formatted = '<br />'.join(
[f"{p.primary_task.name} {p.target.name}" for p in negative_starts] [f"{p.primary_task} {p.target.name}" for p in negative_starts]
) )
mbox = QMessageBox( mbox = QMessageBox(
QMessageBox.Question, QMessageBox.Question,

View File

@ -60,7 +60,7 @@ class FlightDelegate(QStyledItemDelegate):
def first_row_text(self, index: QModelIndex) -> str: def first_row_text(self, index: QModelIndex) -> str:
flight = self.flight(index) flight = self.flight(index)
task = flight.flight_type.name task = flight.flight_type
count = flight.count count = flight.count
name = db.unit_type_name(flight.unit_type) name = db.unit_type_name(flight.unit_type)
estimator = TotEstimator(self.package) estimator = TotEstimator(self.package)

View File

@ -13,4 +13,4 @@ class QFlightTypeComboBox(QComboBox):
self.theater = theater self.theater = theater
self.target = target self.target = target
for mission_type in self.target.mission_types(for_player=True): for mission_type in self.target.mission_types(for_player=True):
self.addItem(mission_type.name, userData=mission_type) self.addItem(str(mission_type), userData=mission_type)

View File

@ -1,5 +1,3 @@
import datetime
from PySide2.QtGui import QStandardItem, QIcon from PySide2.QtGui import QStandardItem, QIcon
from game import db from game import db
@ -23,6 +21,4 @@ class QFlightItem(QStandardItem):
self.setEditable(False) self.setEditable(False)
estimator = TotEstimator(self.package) estimator = TotEstimator(self.package)
delay = estimator.mission_start_time(flight) delay = estimator.mission_start_time(flight)
self.setText("["+str(self.flight.flight_type.name[:6])+"] " self.setText(f"{flight} in {delay}")
+ str(self.flight.count) + " x " + db.unit_type_name(self.flight.unit_type)
+ " in " + str(delay))

View File

@ -16,8 +16,8 @@ class QFlightTypeTaskInfo(QGroupBox):
if db.unit_type_name(self.flight.unit_type) in AIRCRAFT_ICONS: if db.unit_type_name(self.flight.unit_type) in AIRCRAFT_ICONS:
self.aircraft_icon.setPixmap(AIRCRAFT_ICONS[db.unit_type_name(self.flight.unit_type)]) self.aircraft_icon.setPixmap(AIRCRAFT_ICONS[db.unit_type_name(self.flight.unit_type)])
self.task = QLabel("Task :") self.task = QLabel("Task:")
self.task_type = QLabel(flight.flight_type.name) self.task_type = QLabel(str(flight.flight_type))
self.task_type.setProperty("style", flight.flight_type.name) self.task_type.setProperty("style", flight.flight_type.name)
layout.addWidget(self.aircraft_icon, 0, 0) layout.addWidget(self.aircraft_icon, 0, 0)

View File

@ -64,7 +64,7 @@ class QFlightWaypointTab(QFrame):
def closure(): def closure():
return self.confirm_recreate(arg) return self.confirm_recreate(arg)
return closure return closure
button = QPushButton(f"Recreate as {task.name}") button = QPushButton(f"Recreate as {task}")
button.clicked.connect(make_closure(task)) button.clicked.connect(make_closure(task))
rlayout.addWidget(button) rlayout.addWidget(button)
self.recreate_buttons.append(button) self.recreate_buttons.append(button)

View File

@ -66,7 +66,7 @@ DCS Liberation 第 {{ game.turn }} 回合
==================== ====================
{% for flight in flights if flight.client_units %} {% for flight in flights if flight.client_units %}
-------------------------------------------------- --------------------------------------------------
{{ flight.flight_type.name }} {{ flight.units[0].type }} x {{ flight.size }}, {{ flight.package.target.name}} {{ flight.flight_type }} {{ flight.units[0].type }} x {{ flight.size }}, {{ flight.package.target.name}}
{% for waypoint in flight.waypoints %}{{ loop.index }} -- {{waypoint.name}} : {{ waypoint.description}} {% for waypoint in flight.waypoints %}{{ loop.index }} -- {{waypoint.name}} : {{ waypoint.description}}
{% endfor %} {% endfor %}
--------------------------------------------------{% endfor %} --------------------------------------------------{% endfor %}
@ -78,7 +78,7 @@ DCS Liberation 第 {{ game.turn }} 回合
{{ dep }} {{ dep }}
--------------------------------------------------- ---------------------------------------------------
{% for flight in allied_flights_by_departure[dep] %} {% for flight in allied_flights_by_departure[dep] %}
{{ flight.flight_type.name }} {{ flight.units[0].type }} x {{flight.size}}, departing in {{ flight.departure_delay }}, {{ flight.package.target.name}} {{ flight.flight_type }} {{ flight.units[0].type }} x {{flight.size}}, departing in {{ flight.departure_delay }}, {{ flight.package.target.name}}
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}

View File

@ -66,7 +66,7 @@ Your flights:
==================== ====================
{% for flight in flights if flight.client_units %} {% for flight in flights if flight.client_units %}
-------------------------------------------------- --------------------------------------------------
{{ flight.flight_type.name }} {{ flight.units[0].type }} x {{ flight.size }}, {{ flight.package.target.name}} {{ flight.flight_type }} {{ flight.units[0].type }} x {{ flight.size }}, {{ flight.package.target.name}}
{% for waypoint in flight.waypoints %}{{ loop.index }} -- {{waypoint.name}} : {{ waypoint.description}} {% for waypoint in flight.waypoints %}{{ loop.index }} -- {{waypoint.name}} : {{ waypoint.description}}
{% endfor %} {% endfor %}
--------------------------------------------------{% endfor %} --------------------------------------------------{% endfor %}
@ -78,7 +78,7 @@ Planned ally flights:
{{ dep }} {{ dep }}
--------------------------------------------------- ---------------------------------------------------
{% for flight in allied_flights_by_departure[dep] %} {% for flight in allied_flights_by_departure[dep] %}
{{ flight.flight_type.name }} {{ flight.units[0].type }} x {{flight.size}}, departing in {{ flight.departure_delay }}, {{ flight.package.target.name}} {{ flight.flight_type }} {{ flight.units[0].type }} x {{flight.size}}, departing in {{ flight.departure_delay }}, {{ flight.package.target.name}}
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}

View File

@ -66,7 +66,7 @@ Vols :
========== ==========
{% for flight in flights if flight.client_units %} {% for flight in flights if flight.client_units %}
-------------------------------------------------- --------------------------------------------------
{{ flight.flight_type.name }} {{ flight.units[0].type }} x {{ flight.size }}, {{ flight.package.target.name}} {{ flight.flight_type }} {{ flight.units[0].type }} x {{ flight.size }}, {{ flight.package.target.name}}
{% for waypoint in flight.waypoints %}{{ loop.index }} -- {{waypoint.name}} : {{ waypoint.description}} {% for waypoint in flight.waypoints %}{{ loop.index }} -- {{waypoint.name}} : {{ waypoint.description}}
{% endfor %} {% endfor %}
--------------------------------------------------{% endfor %} --------------------------------------------------{% endfor %}
@ -78,7 +78,7 @@ Vols alliés prévus :
{{ dep }} {{ dep }}
--------------------------------------------------- ---------------------------------------------------
{% for flight in allied_flights_by_departure[dep] %} {% for flight in allied_flights_by_departure[dep] %}
{{ flight.flight_type.name }} {{ flight.units[0].type }} x {{flight.size}}, départ dans {{ flight.departure_delay }}, {{ flight.package.target.name}} {{ flight.flight_type }} {{ flight.units[0].type }} x {{flight.size}}, départ dans {{ flight.departure_delay }}, {{ flight.package.target.name}}
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}