mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
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:
parent
23ac510d26
commit
7b35a749e2
@ -25,7 +25,7 @@ class Uninitialized(FlightState):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def is_waiting_for_start(self) -> bool:
|
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:
|
def estimate_position(self) -> Point:
|
||||||
raise RuntimeError("Attempted to simulate flight that is not fully initialized")
|
raise RuntimeError("Attempted to simulate flight that is not fully initialized")
|
||||||
|
|||||||
@ -117,6 +117,17 @@ class Package:
|
|||||||
def set_tot_asap(self, now: datetime) -> None:
|
def set_tot_asap(self, now: datetime) -> None:
|
||||||
self.time_over_target = TotEstimator(self).earliest_tot(now)
|
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:
|
def add_flight(self, flight: Flight) -> None:
|
||||||
"""Adds a flight to the package."""
|
"""Adds a flight to the package."""
|
||||||
self.flights.append(flight)
|
self.flights.append(flight)
|
||||||
|
|||||||
@ -187,14 +187,7 @@ class PackageModel(QAbstractListModel):
|
|||||||
|
|
||||||
def set_tot(self, tot: datetime.datetime) -> datetime:
|
def set_tot(self, tot: datetime.datetime) -> datetime:
|
||||||
with self.game_model.sim_controller.paused_sim():
|
with self.game_model.sim_controller.paused_sim():
|
||||||
previous_tot = self.package.time_over_target
|
|
||||||
self.package.time_over_target = tot
|
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()
|
self.update_tot()
|
||||||
return self.package.time_over_target
|
return self.package.time_over_target
|
||||||
|
|
||||||
@ -209,6 +202,9 @@ class PackageModel(QAbstractListModel):
|
|||||||
self.package.set_tot_asap(
|
self.package.set_tot_asap(
|
||||||
self.game_model.sim_controller.current_time_in_sim
|
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()
|
self.tot_changed.emit()
|
||||||
# For some reason this is needed to make the UI update quickly.
|
# For some reason this is needed to make the UI update quickly.
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user