mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Previously we were trying to make every potential flight plan look just like a strike mission's flight plan. This led to a lot of special case behavior in several places that was causing us to misplan TOTs. I've reorganized this such that there's now an explicit `FlightPlan` class, and any specialized behavior is handled by the subclasses. I've also taken the opportunity to alter the behavior of CAS and front-line CAP missions. These no longer involve the usual formation waypoints. Instead the CAP will aim to be on station at the time that the CAS mission reaches its ingress point, and leave at its egress time. Both flights fly directly to the point with a start time configured for a rendezvous. It might be worth adding hold points back to every flight plan just to ensure that non-formation flights don't end up with a very low speed enroute to the target if they perform ground ops quicker than expected.
85 lines
3.2 KiB
Python
85 lines
3.2 KiB
Python
import itertools
|
|
|
|
from PySide2.QtCore import QItemSelectionModel, QPoint
|
|
from PySide2.QtGui import QStandardItem, QStandardItemModel
|
|
from PySide2.QtWidgets import QHeaderView, QTableView
|
|
|
|
from game.utils import meter_to_feet
|
|
from gen.ato import Package
|
|
from gen.flights.flight import Flight, FlightWaypoint
|
|
from qt_ui.windows.mission.flight.waypoints.QFlightWaypointItem import \
|
|
QWaypointItem
|
|
|
|
|
|
class QFlightWaypointList(QTableView):
|
|
|
|
def __init__(self, package: Package, flight: Flight):
|
|
super().__init__()
|
|
self.package = package
|
|
self.flight = flight
|
|
|
|
self.model = QStandardItemModel(self)
|
|
self.setModel(self.model)
|
|
self.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
|
self.model.setHorizontalHeaderLabels(["Name", "Alt", "TOT/DEPART"])
|
|
|
|
header = self.horizontalHeader()
|
|
header.setSectionResizeMode(0, QHeaderView.ResizeToContents)
|
|
|
|
if len(self.flight.points) > 0:
|
|
self.selectedPoint = self.flight.points[0]
|
|
self.update_list()
|
|
|
|
self.selectionModel().setCurrentIndex(self.indexAt(QPoint(1, 1)), QItemSelectionModel.Select)
|
|
self.selectionModel().selectionChanged.connect(self.on_waypoint_selected_changed)
|
|
|
|
def on_waypoint_selected_changed(self):
|
|
index = self.selectionModel().currentIndex().row()
|
|
|
|
def update_list(self):
|
|
self.model.clear()
|
|
|
|
self.model.setHorizontalHeaderLabels(["Name", "Alt", "TOT/DEPART"])
|
|
|
|
# The first waypoint is set up by pydcs at mission generation time, so
|
|
# we need to add that waypoint manually.
|
|
takeoff = FlightWaypoint(self.flight.from_cp.position.x,
|
|
self.flight.from_cp.position.y, 0)
|
|
takeoff.description = "Take Off"
|
|
takeoff.name = takeoff.pretty_name = "Take Off from " + self.flight.from_cp.name
|
|
takeoff.alt_type = "RADIO"
|
|
|
|
waypoints = itertools.chain([takeoff], self.flight.points)
|
|
for row, waypoint in enumerate(waypoints):
|
|
self.add_waypoint_row(row, self.flight, waypoint)
|
|
self.selectionModel().setCurrentIndex(self.indexAt(QPoint(1, 1)),
|
|
QItemSelectionModel.Select)
|
|
|
|
def add_waypoint_row(self, row: int, flight: Flight,
|
|
waypoint: FlightWaypoint) -> None:
|
|
self.model.insertRow(self.model.rowCount())
|
|
|
|
self.model.setItem(row, 0, QWaypointItem(waypoint, row))
|
|
|
|
altitude = meter_to_feet(waypoint.alt)
|
|
altitude_type = "AGL" if waypoint.alt_type == "RADIO" else "MSL"
|
|
altitude_item = QStandardItem(f"{altitude} ft {altitude_type}")
|
|
altitude_item.setEditable(False)
|
|
self.model.setItem(row, 1, altitude_item)
|
|
|
|
tot = self.tot_text(flight, waypoint)
|
|
tot_item = QStandardItem(tot)
|
|
tot_item.setEditable(False)
|
|
self.model.setItem(row, 2, tot_item)
|
|
|
|
@staticmethod
|
|
def tot_text(flight: Flight, waypoint: FlightWaypoint) -> str:
|
|
prefix = ""
|
|
time = flight.flight_plan.tot_for_waypoint(waypoint)
|
|
if time is None:
|
|
prefix = "Depart "
|
|
time = flight.flight_plan.depart_time_for_waypoint(waypoint)
|
|
if time is None:
|
|
return ""
|
|
return f"{prefix}T+{time}"
|