From 7a57bd3ee0a652358faeff2b59fed9a6e0b8d52f Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Thu, 25 May 2023 21:30:00 -0700 Subject: [PATCH] Save the TOT offset in the flight plan. Prep work for exposing this to the UI. --- game/ato/flightplans/flightplan.py | 11 +++++++++-- game/ato/flightplans/formationattack.py | 11 ----------- game/ato/flightplans/sead.py | 5 ++--- game/ato/flightplans/sweep.py | 9 ++------- game/ato/flightplans/tarcap.py | 9 ++------- 5 files changed, 15 insertions(+), 30 deletions(-) diff --git a/game/ato/flightplans/flightplan.py b/game/ato/flightplans/flightplan.py index 76e9c5c5..575d1e81 100644 --- a/game/ato/flightplans/flightplan.py +++ b/game/ato/flightplans/flightplan.py @@ -21,6 +21,7 @@ from .planningerror import PlanningError from ..flightwaypointtype import FlightWaypointType from ..starttype import StartType from ..traveltime import GroundSpeed, TravelTime +from ...savecompat import has_save_compat_for if TYPE_CHECKING: from game.dcs.aircrafttype import FuelConsumption @@ -65,6 +66,13 @@ class FlightPlan(ABC, Generic[LayoutT]): def __init__(self, flight: Flight, layout: LayoutT) -> None: self.flight = flight self.layout = layout + self.tot_offset = self.default_tot_offset() + + @has_save_compat_for(7) + def __setstate__(self, state: dict[str, Any]) -> None: + if "tot_offset" not in state: + state["tot_offset"] = self.default_tot_offset() + self.__dict__.update(state) @property def package(self) -> Package: @@ -207,8 +215,7 @@ class FlightPlan(ABC, Generic[LayoutT]): [meters(cp.position.distance_to_point(w.position)) for w in self.waypoints] ) - @property - def tot_offset(self) -> timedelta: + def default_tot_offset(self) -> timedelta: """This flight's offset from the package's TOT. Positive values represent later TOTs. An offset of -2 minutes is used diff --git a/game/ato/flightplans/formationattack.py b/game/ato/flightplans/formationattack.py index fc930088..c37fbd9a 100644 --- a/game/ato/flightplans/formationattack.py +++ b/game/ato/flightplans/formationattack.py @@ -25,10 +25,6 @@ if TYPE_CHECKING: class FormationAttackFlightPlan(FormationFlightPlan, ABC): - @property - def lead_time(self) -> timedelta: - return timedelta() - @property def package_speed_waypoints(self) -> set[FlightWaypoint]: return { @@ -50,13 +46,6 @@ class FormationAttackFlightPlan(FormationFlightPlan, ABC): def tot_waypoint(self) -> FlightWaypoint: return self.layout.targets[0] - @property - def tot_offset(self) -> timedelta: - try: - return -self.lead_time - except AttributeError: - return timedelta() - @property def target_area_waypoint(self) -> FlightWaypoint: return FlightWaypoint( diff --git a/game/ato/flightplans/sead.py b/game/ato/flightplans/sead.py index e58616aa..3c6e89ae 100644 --- a/game/ato/flightplans/sead.py +++ b/game/ato/flightplans/sead.py @@ -16,9 +16,8 @@ class SeadFlightPlan(FormationAttackFlightPlan): def builder_type() -> Type[Builder]: return Builder - @property - def lead_time(self) -> timedelta: - return timedelta(minutes=1) + def default_tot_offset(self) -> timedelta: + return -timedelta(minutes=1) class Builder(FormationAttackBuilder[SeadFlightPlan, FormationAttackLayout]): diff --git a/game/ato/flightplans/sweep.py b/game/ato/flightplans/sweep.py index 6e09b7da..60d8a5de 100644 --- a/game/ato/flightplans/sweep.py +++ b/game/ato/flightplans/sweep.py @@ -38,10 +38,6 @@ class SweepLayout(LoiterLayout): class SweepFlightPlan(LoiterFlightPlan): - @property - def lead_time(self) -> timedelta: - return timedelta(minutes=5) - @staticmethod def builder_type() -> Type[Builder]: return Builder @@ -54,9 +50,8 @@ class SweepFlightPlan(LoiterFlightPlan): def tot_waypoint(self) -> FlightWaypoint: return self.layout.sweep_end - @property - def tot_offset(self) -> timedelta: - return -self.lead_time + def default_tot_offset(self) -> timedelta: + return -timedelta(minutes=5) @property def sweep_start_time(self) -> timedelta: diff --git a/game/ato/flightplans/tarcap.py b/game/ato/flightplans/tarcap.py index 1a43ce81..cf8bfc9b 100644 --- a/game/ato/flightplans/tarcap.py +++ b/game/ato/flightplans/tarcap.py @@ -34,10 +34,6 @@ class TarCapLayout(PatrollingLayout): class TarCapFlightPlan(PatrollingFlightPlan[TarCapLayout]): - @property - def lead_time(self) -> timedelta: - return timedelta(minutes=2) - @property def patrol_duration(self) -> timedelta: # Note that this duration only has an effect if there are no @@ -64,9 +60,8 @@ class TarCapFlightPlan(PatrollingFlightPlan[TarCapLayout]): def combat_speed_waypoints(self) -> set[FlightWaypoint]: return {self.layout.patrol_start, self.layout.patrol_end} - @property - def tot_offset(self) -> timedelta: - return -self.lead_time + def default_tot_offset(self) -> timedelta: + return -timedelta(minutes=2) def depart_time_for_waypoint(self, waypoint: FlightWaypoint) -> timedelta | None: if waypoint == self.layout.patrol_end: