mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Estimate TOTs for packages.
We estimate the longest possible time from mission start to TOT for all flights in a package and use that to set the TOT (plus any delay used to stagger flights). This both cuts down on loiter time for shorter flights and ensures that long flights will make it to the target in time. This is also used to compute the start time for the AI, so the explicit delay option is no longer needed.
This commit is contained in:
@@ -1,26 +1,28 @@
|
||||
import datetime
|
||||
|
||||
from PySide2.QtGui import QStandardItem, QIcon
|
||||
|
||||
from game import db
|
||||
from gen.ato import Package
|
||||
from gen.flights.flight import Flight
|
||||
from gen.flights.traveltime import TotEstimator
|
||||
from qt_ui.uiconstants import AIRCRAFT_ICONS
|
||||
|
||||
|
||||
# TODO: Replace with QFlightList.
|
||||
class QFlightItem(QStandardItem):
|
||||
|
||||
def __init__(self, flight:Flight):
|
||||
def __init__(self, package: Package, flight: Flight):
|
||||
super(QFlightItem, self).__init__()
|
||||
self.package = package
|
||||
self.flight = flight
|
||||
|
||||
if db.unit_type_name(self.flight.unit_type).replace("/", " ") in AIRCRAFT_ICONS.keys():
|
||||
icon = QIcon((AIRCRAFT_ICONS[db.unit_type_name(self.flight.unit_type)]))
|
||||
self.setIcon(icon)
|
||||
self.setEditable(False)
|
||||
estimator = TotEstimator(self.package)
|
||||
delay = datetime.timedelta(seconds=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(self.flight.scheduled_in) + " minutes")
|
||||
|
||||
def update(self, flight):
|
||||
self.flight = 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(self.flight.scheduled_in) + " minutes")
|
||||
+ " in " + str(delay))
|
||||
|
||||
@@ -116,11 +116,14 @@ class QPackageDialog(QDialog):
|
||||
|
||||
self.finished.connect(self.on_close)
|
||||
|
||||
def on_close(self, _result) -> None:
|
||||
@staticmethod
|
||||
def on_close(_result) -> None:
|
||||
GameUpdateSignal.get_instance().redraw_flight_paths()
|
||||
|
||||
def save_tot(self) -> None:
|
||||
time = self.tot_spinner.time()
|
||||
seconds = time.hour() * 3600 + time.minute() * 60 + time.second()
|
||||
self.package_model.update_tot(seconds)
|
||||
GameUpdateSignal.get_instance().redraw_flight_paths()
|
||||
|
||||
def on_selection_changed(self, selected: QItemSelection,
|
||||
_deselected: QItemSelection) -> None:
|
||||
@@ -182,6 +185,7 @@ class QNewPackageDialog(QPackageDialog):
|
||||
Empty packages may be created. They can be modified later, and will have
|
||||
no effect if empty when the mission is generated.
|
||||
"""
|
||||
self.save_tot()
|
||||
self.ato_model.add_package(self.package_model.package)
|
||||
for flight in self.package_model.package.flights:
|
||||
self.game.aircraft_inventory.claim_for_flight(flight)
|
||||
@@ -227,6 +231,7 @@ class QEditPackageDialog(QPackageDialog):
|
||||
|
||||
def on_done(self) -> None:
|
||||
"""Closes the window."""
|
||||
self.save_tot()
|
||||
self.close()
|
||||
|
||||
def on_delete(self) -> None:
|
||||
|
||||
@@ -90,7 +90,11 @@ class QFlightCreator(QDialog):
|
||||
origin = self.airfield_selector.currentData()
|
||||
size = self.flight_size_spinner.value()
|
||||
|
||||
flight = Flight(aircraft, size, origin, task)
|
||||
if self.game.settings.perf_ai_parking_start:
|
||||
start_type = "Cold"
|
||||
else:
|
||||
start_type = "Warm"
|
||||
flight = Flight(aircraft, size, origin, task, start_type)
|
||||
flight.scheduled_in = self.package.delay
|
||||
|
||||
# noinspection PyUnresolvedReferences
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from PySide2.QtWidgets import QLabel, QHBoxLayout, QGroupBox, QSpinBox
|
||||
|
||||
|
||||
# TODO: Remove?
|
||||
class QFlightDepartureEditor(QGroupBox):
|
||||
|
||||
def __init__(self, flight):
|
||||
@@ -15,7 +16,7 @@ class QFlightDepartureEditor(QGroupBox):
|
||||
self.departure_delta = QSpinBox(self)
|
||||
self.departure_delta.setMinimum(0)
|
||||
self.departure_delta.setMaximum(120)
|
||||
self.departure_delta.setValue(self.flight.scheduled_in)
|
||||
self.departure_delta.setValue(self.flight.scheduled_in // 60)
|
||||
self.departure_delta.valueChanged.connect(self.change_scheduled)
|
||||
|
||||
layout.addWidget(self.depart_from)
|
||||
@@ -27,4 +28,4 @@ class QFlightDepartureEditor(QGroupBox):
|
||||
self.changed = self.departure_delta.valueChanged
|
||||
|
||||
def change_scheduled(self):
|
||||
self.flight.scheduled_in = int(self.departure_delta.value())
|
||||
self.flight.scheduled_in = int(self.departure_delta.value() * 60)
|
||||
|
||||
Reference in New Issue
Block a user