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)