From ea726bbf06e4df4e12adbb3569a9c8129d5f4292 Mon Sep 17 00:00:00 2001 From: Raffson Date: Sat, 7 Oct 2023 21:37:49 +0200 Subject: [PATCH] Streamlining --- game/ato/flightplans/escort.py | 4 ++-- game/ato/flightplans/flightplan.py | 23 ++----------------- game/ato/flightplans/formation.py | 4 ++-- game/ato/flightplans/patrolling.py | 2 +- game/ato/flightplans/sweep.py | 5 ++-- game/migrator.py | 6 ++--- game/missiongenerator/flotgenerator.py | 2 +- game/missiongenerator/missiondata.py | 8 +++---- game/squadrons/squadron.py | 1 + .../newgame/WizardPages/QFactionSelection.py | 2 +- requirements.txt | 2 +- 11 files changed, 21 insertions(+), 38 deletions(-) diff --git a/game/ato/flightplans/escort.py b/game/ato/flightplans/escort.py index f7066d51..fe3e7797 100644 --- a/game/ato/flightplans/escort.py +++ b/game/ato/flightplans/escort.py @@ -1,6 +1,6 @@ from __future__ import annotations -from datetime import timedelta +from datetime import timedelta, datetime from typing import Type from .airassault import AirAssaultLayout @@ -17,7 +17,7 @@ from ...utils import feet class EscortFlightPlan(FormationAttackFlightPlan): @property - def push_time(self) -> timedelta: + def push_time(self) -> datetime: hold2join_time = ( self.travel_time_between_waypoints( self.layout.hold, diff --git a/game/ato/flightplans/flightplan.py b/game/ato/flightplans/flightplan.py index d3865be5..af03e78f 100644 --- a/game/ato/flightplans/flightplan.py +++ b/game/ato/flightplans/flightplan.py @@ -287,27 +287,6 @@ class FlightPlan(ABC, Generic[LayoutT]): + self.estimate_ground_ops() ) - # In case FP math has given us some barely below zero time, round to - # zero. - if math.isclose(start_time.total_seconds(), 0): - start_time = timedelta() - - # Trim microseconds. DCS doesn't handle sub-second resolution for tasks, - # and they're not interesting from a mission planning perspective so we - # don't want them in the UI. - # - # Round down so *barely* above zero start times are just zero. - start_time = timedelta(seconds=math.floor(start_time.total_seconds())) - - # Feature request #1309: Carrier planes should start at +1s - # This is a workaround to a DCS problem: some AI planes spawn on - # the 'sixpack' when start_time is zero and cause a deadlock. - # Workaround: force the start_time to 1 second for these planes. - if self.flight.departure.is_fleet and start_time.total_seconds() == 0: - start_time = timedelta(seconds=1) - - return start_time - def startup_time(self) -> datetime: return ( self.takeoff_time() - self.estimate_startup() - self.estimate_ground_ops() @@ -334,9 +313,11 @@ class FlightPlan(ABC, Generic[LayoutT]): def is_airassault(self) -> bool: return False + @property @abstractmethod def mission_begin_on_station_time(self) -> datetime | None: """The time that the mission is first on-station.""" + ... @property def is_custom(self) -> bool: diff --git a/game/ato/flightplans/formation.py b/game/ato/flightplans/formation.py index b1ca8c8c..cd90b493 100644 --- a/game/ato/flightplans/formation.py +++ b/game/ato/flightplans/formation.py @@ -93,8 +93,8 @@ class FormationFlightPlan(LoiterFlightPlan, ABC): @property def push_time(self) -> datetime: return self.join_time - self.travel_time_between_waypoints( - self.layout.hold.position, - self.layout.join.position, + self.layout.hold, + self.layout.join, ) @property diff --git a/game/ato/flightplans/patrolling.py b/game/ato/flightplans/patrolling.py index bebfa2df..f81a4005 100644 --- a/game/ato/flightplans/patrolling.py +++ b/game/ato/flightplans/patrolling.py @@ -88,7 +88,7 @@ class PatrollingFlightPlan(StandardFlightPlan[LayoutT], UiZoneDisplay, ABC): return self.layout.patrol_start @property - def mission_begin_on_station_time(self) -> datetime: + def mission_begin_on_station_time(self) -> datetime | None: return self.patrol_start_time @property diff --git a/game/ato/flightplans/sweep.py b/game/ato/flightplans/sweep.py index 10cbee98..428d3e6d 100644 --- a/game/ato/flightplans/sweep.py +++ b/game/ato/flightplans/sweep.py @@ -79,14 +79,15 @@ class SweepFlightPlan(LoiterFlightPlan): @property def push_time(self) -> datetime: return self.sweep_end_time - self.travel_time_between_waypoints( - self.layout.hold.position, - self.layout.sweep_end.position, + self.layout.hold, + self.layout.sweep_end, ) @property def mission_begin_on_station_time(self) -> datetime | None: return None + @property def mission_departure_time(self) -> datetime: return self.sweep_end_time diff --git a/game/migrator.py b/game/migrator.py index f8623eb1..18484369 100644 --- a/game/migrator.py +++ b/game/migrator.py @@ -1,7 +1,7 @@ from __future__ import annotations import typing -from datetime import datetime +from datetime import timedelta from typing import TYPE_CHECKING, Any from dcs.countries import countries_by_name @@ -68,9 +68,9 @@ class Migrator: for p in c.ato.packages: try_set_attr(p, "custom_name") try_set_attr(p, "frequency") - if self.is_liberation and isinstance(p.time_over_target, datetime): # type: ignore + if isinstance(p.time_over_target, timedelta): # type: ignore p.time_over_target = ( # type: ignore - p.time_over_target - self.game.conditions.start_time + p.time_over_target + self.game.conditions.start_time ) def _update_control_points(self) -> None: diff --git a/game/missiongenerator/flotgenerator.py b/game/missiongenerator/flotgenerator.py index 95b02734..4e48a9c4 100644 --- a/game/missiongenerator/flotgenerator.py +++ b/game/missiongenerator/flotgenerator.py @@ -286,7 +286,7 @@ class FlotGenerator: if len(tots) == 0 else min( [ - x.time_over_target + x.time_over_target - self.mission.start_time for x in self.game.ato_for(player).packages if x.primary_task == FlightType.CAS ] diff --git a/game/missiongenerator/missiondata.py b/game/missiongenerator/missiondata.py index e65fe013..8906feb4 100644 --- a/game/missiongenerator/missiondata.py +++ b/game/missiongenerator/missiondata.py @@ -33,8 +33,8 @@ class AwacsInfo(GroupInfo): """AWACS information for the kneeboard.""" depature_location: Optional[str] - start_time: datetime | None - end_time: datetime | None + start_time: datetime + end_time: datetime @dataclass @@ -43,8 +43,8 @@ class TankerInfo(GroupInfo): variant: str tacan: Optional[TacanChannel] - start_time: datetime | None - end_time: datetime | None + start_time: datetime + end_time: datetime @dataclass diff --git a/game/squadrons/squadron.py b/game/squadrons/squadron.py index c71b10e6..8f67c9a0 100644 --- a/game/squadrons/squadron.py +++ b/game/squadrons/squadron.py @@ -384,6 +384,7 @@ class Squadron: def plan_relocation(self, destination: ControlPoint, now: datetime) -> None: from game.theater import ParkingType + if destination == self.location: logging.warning( f"Attempted to plan relocation of {self} to current location " diff --git a/qt_ui/windows/newgame/WizardPages/QFactionSelection.py b/qt_ui/windows/newgame/WizardPages/QFactionSelection.py index 835d8862..4511a58f 100644 --- a/qt_ui/windows/newgame/WizardPages/QFactionSelection.py +++ b/qt_ui/windows/newgame/WizardPages/QFactionSelection.py @@ -94,7 +94,7 @@ class QFactionUnits(QScrollArea): def updateFactionUnits(self, units: Union[set, list]): deletes = [] for a in units: - if not self.checkboxes[a.name].isChecked(): + if not self.checkboxes[str(a)].isChecked(): deletes.append(a) for d in deletes: units.remove(d) diff --git a/requirements.txt b/requirements.txt index cb50a295..4a74bf9a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,7 +20,7 @@ iniconfig==2.0.0 Jinja2==3.1.2 lupa==2.0 MarkupSafe==2.1.3 -mypy==1.4.1 +mypy==1.5.1 mypy-extensions==1.0.0 nodeenv==1.8.0 packaging==23.1