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.SEAD,
FlightType.STRIKE]:
flightType = flight.flight_type.name
flightType = str(flight.flight_type)
flightTarget = flight.package.target
if flightTarget:
flightTargetName = None

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -121,14 +121,11 @@ class PackageModel(QAbstractListModel):
def text_for_flight(self, flight: Flight) -> str:
"""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)
delay = datetime.timedelta(
seconds=int(estimator.mission_start_time(flight).total_seconds()))
origin = flight.from_cp.name
return f"[{task}] {count} x {name} from {origin} in {delay}"
return f"{flight} from {origin} in {delay}"
@staticmethod
def icon_for_flight(flight: Flight) -> Optional[QIcon]:

View File

@ -171,7 +171,7 @@ class QTopPanel(QFrame):
def confirm_negative_start_time(self,
negative_starts: List[Package]) -> bool:
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(
QMessageBox.Question,

View File

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

View File

@ -13,4 +13,4 @@ class QFlightTypeComboBox(QComboBox):
self.theater = theater
self.target = target
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 game import db
@ -23,6 +21,4 @@ class QFlightItem(QStandardItem):
self.setEditable(False)
estimator = TotEstimator(self.package)
delay = estimator.mission_start_time(flight)
self.setText("["+str(self.flight.flight_type.name[:6])+"] "
+ str(self.flight.count) + " x " + db.unit_type_name(self.flight.unit_type)
+ " in " + str(delay))
self.setText(f"{flight} in {delay}")

View File

@ -17,7 +17,7 @@ class QFlightTypeTaskInfo(QGroupBox):
self.aircraft_icon.setPixmap(AIRCRAFT_ICONS[db.unit_type_name(self.flight.unit_type)])
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)
layout.addWidget(self.aircraft_icon, 0, 0)

View File

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

View File

@ -66,7 +66,7 @@ DCS Liberation 第 {{ game.turn }} 回合
====================
{% 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}}
{% endfor %}
--------------------------------------------------{% endfor %}
@ -78,7 +78,7 @@ DCS Liberation 第 {{ game.turn }} 回合
{{ 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 %}

View File

@ -66,7 +66,7 @@ Your flights:
====================
{% 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}}
{% endfor %}
--------------------------------------------------{% endfor %}
@ -78,7 +78,7 @@ Planned ally flights:
{{ 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 %}

View File

@ -66,7 +66,7 @@ Vols :
==========
{% 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}}
{% endfor %}
--------------------------------------------------{% endfor %}
@ -78,7 +78,7 @@ Vols alliés prévus :
{{ 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 %}