Prevent past startup when adding new flights.

When a new flight is added to a package, if the TOT is early enough the
new flight might have a startup time in the past. Clamp the TOT when
adding new flights to the package to avoid this.

https://github.com/dcs-liberation/dcs_liberation/issues/1680
This commit is contained in:
Dan Albert 2023-02-06 00:34:30 -08:00
parent 23ac510d26
commit 7b35a749e2
3 changed files with 15 additions and 8 deletions

View File

@ -25,7 +25,7 @@ class Uninitialized(FlightState):
@property
def is_waiting_for_start(self) -> bool:
raise RuntimeError("Attempted to simulate flight that is not fully initialized")
return True
def estimate_position(self) -> Point:
raise RuntimeError("Attempted to simulate flight that is not fully initialized")

View File

@ -117,6 +117,17 @@ class Package:
def set_tot_asap(self, now: datetime) -> None:
self.time_over_target = TotEstimator(self).earliest_tot(now)
def clamp_tot_for_current_time(self, now: datetime) -> None:
if not self.all_flights_waiting_for_start():
return
if not self.flights:
return
earliest_startup_time = min(f.flight_plan.startup_time() for f in self.flights)
if earliest_startup_time < now:
self.time_over_target += now - earliest_startup_time
def add_flight(self, flight: Flight) -> None:
"""Adds a flight to the package."""
self.flights.append(flight)

View File

@ -187,14 +187,7 @@ class PackageModel(QAbstractListModel):
def set_tot(self, tot: datetime.datetime) -> datetime:
with self.game_model.sim_controller.paused_sim():
previous_tot = self.package.time_over_target
self.package.time_over_target = tot
for flight in self.package.flights:
if (
flight.flight_plan.startup_time()
< self.game_model.sim_controller.current_time_in_sim
):
self.package.time_over_target = previous_tot
self.update_tot()
return self.package.time_over_target
@ -209,6 +202,9 @@ class PackageModel(QAbstractListModel):
self.package.set_tot_asap(
self.game_model.sim_controller.current_time_in_sim
)
self.package.clamp_tot_for_current_time(
self.game_model.sim_controller.current_time_in_sim
)
self.tot_changed.emit()
# For some reason this is needed to make the UI update quickly.
self.layoutChanged.emit()