From 99eed33241a2b8cba1ef07ae08d11eea947e8e64 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Tue, 22 Aug 2023 20:24:29 -0700 Subject: [PATCH] Remove useless TravelTime class. This is only called for real in one spot. The other callers should have been deferring to the one real caller. --- game/ato/flightplans/flightplan.py | 9 +++++---- game/ato/flightplans/formation.py | 7 ++----- game/ato/flightplans/sweep.py | 7 ++----- game/ato/traveltime.py | 20 ++------------------ 4 files changed, 11 insertions(+), 32 deletions(-) diff --git a/game/ato/flightplans/flightplan.py b/game/ato/flightplans/flightplan.py index b0290cc6..8009404e 100644 --- a/game/ato/flightplans/flightplan.py +++ b/game/ato/flightplans/flightplan.py @@ -20,7 +20,7 @@ from game.utils import Distance, Speed, meters from .planningerror import PlanningError from ..flightwaypointtype import FlightWaypointType from ..starttype import StartType -from ..traveltime import GroundSpeed, TravelTime +from ..traveltime import GroundSpeed if TYPE_CHECKING: from game.dcs.aircrafttype import FuelConsumption @@ -228,9 +228,10 @@ class FlightPlan(ABC, Generic[LayoutT]): def travel_time_between_waypoints( self, a: FlightWaypoint, b: FlightWaypoint ) -> timedelta: - return TravelTime.between_points( - a.position, b.position, self.speed_between_waypoints(a, b) - ) + error_factor = 1.05 + speed = self.speed_between_waypoints(a, b) + distance = meters(a.position.distance_to_point(b.position)) + return timedelta(hours=distance.nautical_miles / speed.knots * error_factor) def tot_for_waypoint(self, waypoint: FlightWaypoint) -> datetime | None: raise NotImplementedError diff --git a/game/ato/flightplans/formation.py b/game/ato/flightplans/formation.py index b22854be..81bd7290 100644 --- a/game/ato/flightplans/formation.py +++ b/game/ato/flightplans/formation.py @@ -10,7 +10,6 @@ from game.typeguard import self_type_guard from game.utils import Speed from .flightplan import FlightPlan from .loiter import LoiterFlightPlan, LoiterLayout -from ..traveltime import GroundSpeed, TravelTime if TYPE_CHECKING: from ..flightwaypoint import FlightWaypoint @@ -93,10 +92,8 @@ class FormationFlightPlan(LoiterFlightPlan[LayoutT], ABC): @property def push_time(self) -> datetime: - return self.join_time - TravelTime.between_points( - self.layout.hold.position, - self.layout.join.position, - GroundSpeed.for_flight(self.flight, self.layout.hold.alt), + return self.join_time - self.travel_time_between_waypoints( + self.layout.hold, self.layout.join ) @property diff --git a/game/ato/flightplans/sweep.py b/game/ato/flightplans/sweep.py index 412a32b3..52507c9d 100644 --- a/game/ato/flightplans/sweep.py +++ b/game/ato/flightplans/sweep.py @@ -10,7 +10,6 @@ from game.utils import Heading from .ibuilder import IBuilder from .loiter import LoiterFlightPlan, LoiterLayout from .waypointbuilder import WaypointBuilder -from ..traveltime import GroundSpeed, TravelTime from ...flightplan import HoldZoneGeometry if TYPE_CHECKING: @@ -78,10 +77,8 @@ class SweepFlightPlan(LoiterFlightPlan[SweepLayout]): @property def push_time(self) -> datetime: - return self.sweep_end_time - TravelTime.between_points( - self.layout.hold.position, - self.layout.sweep_end.position, - GroundSpeed.for_flight(self.flight, self.layout.hold.alt), + return self.sweep_end_time - self.travel_time_between_waypoints( + self.layout.hold, self.layout.sweep_end ) @property diff --git a/game/ato/traveltime.py b/game/ato/traveltime.py index 7ccdb5ca..f71cd9dd 100644 --- a/game/ato/traveltime.py +++ b/game/ato/traveltime.py @@ -1,17 +1,9 @@ from __future__ import annotations -from datetime import datetime, timedelta +from datetime import datetime from typing import TYPE_CHECKING -from dcs.mapping import Point - -from game.utils import ( - Distance, - SPEED_OF_SOUND_AT_SEA_LEVEL, - Speed, - mach, - meters, -) +from game.utils import Distance, SPEED_OF_SOUND_AT_SEA_LEVEL, Speed, mach if TYPE_CHECKING: from .flight import Flight @@ -42,14 +34,6 @@ class GroundSpeed: return mach(cruise_mach, altitude) -class TravelTime: - @staticmethod - def between_points(a: Point, b: Point, speed: Speed) -> timedelta: - error_factor = 1.05 - distance = meters(a.distance_to_point(b)) - return timedelta(hours=distance.nautical_miles / speed.knots * error_factor) - - # TODO: Most if not all of this should move into FlightPlan. class TotEstimator: def __init__(self, package: Package) -> None: