From 62a40db9ea0a59ea1748e51a13fcb8c7e1bd5d8a Mon Sep 17 00:00:00 2001 From: Raffson Date: Sat, 7 Oct 2023 18:53:16 +0200 Subject: [PATCH] Streamlining --- game/ato/flightplans/cas.py | 29 +++++++++---------- game/dcs/aircrafttype.py | 4 +-- game/missiongenerator/drawingsgenerator.py | 2 +- .../frontlineconflictdescription.py | 7 +++-- game/missiongenerator/missiongenerator.py | 2 +- game/missiongenerator/visualsgenerator.py | 2 +- 6 files changed, 21 insertions(+), 25 deletions(-) diff --git a/game/ato/flightplans/cas.py b/game/ato/flightplans/cas.py index 7ece04cf..1ca58e2e 100644 --- a/game/ato/flightplans/cas.py +++ b/game/ato/flightplans/cas.py @@ -3,7 +3,7 @@ from __future__ import annotations from collections.abc import Iterator from dataclasses import dataclass from datetime import timedelta -from typing import TYPE_CHECKING, Type, Optional +from typing import TYPE_CHECKING, Type from game.theater import FrontLine from game.utils import Distance, Speed, kph, dcs_to_shapely_point @@ -23,7 +23,7 @@ if TYPE_CHECKING: @dataclass class CasLayout(PatrollingLayout): - ingress: Optional[FlightWaypoint] + ingress: FlightWaypoint def iter_waypoints(self) -> Iterator[FlightWaypoint]: yield self.departure @@ -92,17 +92,14 @@ class Builder(IBuilder[CasFlightPlan, CasLayout]): FrontLineConflictDescription, ) - bounds = FrontLineConflictDescription.frontline_bounds( - location, self.theater, self.coalition.game.settings - ) - ingress = bounds.left_position - center = bounds.center - egress = bounds.right_position + bounds = FrontLineConflictDescription.frontline_bounds(location, self.theater) + patrol_start = bounds.left_position + patrol_end = bounds.right_position - start_distance = ingress.distance_to_point(self.flight.departure.position) - end_distance = egress.distance_to_point(self.flight.departure.position) + start_distance = patrol_start.distance_to_point(self.flight.departure.position) + end_distance = patrol_end.distance_to_point(self.flight.departure.position) if end_distance < start_distance: - patrol_start, patrol_end = ingress, egress + patrol_start, patrol_end = patrol_end, patrol_start builder = WaypointBuilder(self.flight) @@ -116,7 +113,7 @@ class Builder(IBuilder[CasFlightPlan, CasLayout]): ip_solver = IpSolver( dcs_to_shapely_point(self.flight.departure.position), - dcs_to_shapely_point(ingress), + dcs_to_shapely_point(patrol_start), self.doctrine, self.threat_zones.all, ) @@ -127,19 +124,19 @@ class Builder(IBuilder[CasFlightPlan, CasLayout]): if dump_debug_info: ip_solver.dump_debug_info() - ingress_point = ingress.new_in_same_map( + ingress_point = patrol_start.new_in_same_map( ingress_point_shapely.x, ingress_point_shapely.y ) patrol_start_waypoint = builder.nav( - ingress, ingress_egress_altitude, use_agl_patrol_altitude + patrol_start, ingress_egress_altitude, use_agl_patrol_altitude ) patrol_start_waypoint.name = "FLOT START" patrol_start_waypoint.pretty_name = "FLOT start" patrol_start_waypoint.description = "FLOT boundary" patrol_end_waypoint = builder.nav( - egress, ingress_egress_altitude, use_agl_patrol_altitude + patrol_end, ingress_egress_altitude, use_agl_patrol_altitude ) patrol_end_waypoint.name = "FLOT END" patrol_end_waypoint.pretty_name = "FLOT end" @@ -159,7 +156,7 @@ class Builder(IBuilder[CasFlightPlan, CasLayout]): use_agl_patrol_altitude, ), nav_from=builder.nav_path( - egress, + patrol_end, self.flight.arrival.position, ingress_egress_altitude, use_agl_patrol_altitude, diff --git a/game/dcs/aircrafttype.py b/game/dcs/aircrafttype.py index 4fca6f63..d9434cad 100644 --- a/game/dcs/aircrafttype.py +++ b/game/dcs/aircrafttype.py @@ -366,9 +366,7 @@ class AircraftType(UnitType[Type[FlyingType]]): @staticmethod def _migrator() -> Dict[str, str]: - return { - "F-15E Strike Eagle (AI)": "F-15E Strike Eagle" - } + return {"F-15E Strike Eagle (AI)": "F-15E Strike Eagle"} @classmethod def named(cls, name: str) -> AircraftType: diff --git a/game/missiongenerator/drawingsgenerator.py b/game/missiongenerator/drawingsgenerator.py index 1d8a9957..a7db3fd5 100644 --- a/game/missiongenerator/drawingsgenerator.py +++ b/game/missiongenerator/drawingsgenerator.py @@ -86,7 +86,7 @@ class DrawingsGenerator: """ for front_line in self.game.theater.conflicts(): bounds = FrontLineConflictDescription.frontline_bounds( - front_line, self.game.theater, self.game.settings + front_line, self.game.theater ) end_point = bounds.left_position.point_from_heading( diff --git a/game/missiongenerator/frontlineconflictdescription.py b/game/missiongenerator/frontlineconflictdescription.py index 2b92c36b..4a8b1e51 100644 --- a/game/missiongenerator/frontlineconflictdescription.py +++ b/game/missiongenerator/frontlineconflictdescription.py @@ -72,11 +72,12 @@ class FrontLineConflictDescription: @classmethod def frontline_bounds( - cls, front_line: FrontLine, theater: ConflictTheater, settings: Settings + cls, front_line: FrontLine, theater: ConflictTheater ) -> FrontLineBounds: """ Returns a vector for a valid frontline location avoiding exclusion zones. """ + settings = front_line.coalition.game.settings center_position, heading = cls.frontline_position(front_line, theater, settings) left_heading = heading.left right_heading = heading.right @@ -96,12 +97,12 @@ class FrontLineConflictDescription: @classmethod def frontline_cas_conflict( - cls, front_line: FrontLine, theater: ConflictTheater, settings: Settings + cls, front_line: FrontLine, theater: ConflictTheater ) -> FrontLineConflictDescription: # TODO: Break apart the front-line and air conflict descriptions. # We're wastefully not caching the front-line bounds here because air conflicts # can't compute bounds, only a position. - bounds = cls.frontline_bounds(front_line, theater, settings) + bounds = cls.frontline_bounds(front_line, theater) conflict = cls( theater=theater, front_line=front_line, diff --git a/game/missiongenerator/missiongenerator.py b/game/missiongenerator/missiongenerator.py index a66c9d45..2d579325 100644 --- a/game/missiongenerator/missiongenerator.py +++ b/game/missiongenerator/missiongenerator.py @@ -204,7 +204,7 @@ class MissionGenerator: player_cp = front_line.blue_cp enemy_cp = front_line.red_cp conflict = FrontLineConflictDescription.frontline_cas_conflict( - front_line, self.game.theater, self.game.settings + front_line, self.game.theater ) # Generate frontline ops player_gp = self.game.ground_planners[player_cp.id].units_per_cp[ diff --git a/game/missiongenerator/visualsgenerator.py b/game/missiongenerator/visualsgenerator.py index d75dbd09..741a692f 100644 --- a/game/missiongenerator/visualsgenerator.py +++ b/game/missiongenerator/visualsgenerator.py @@ -81,7 +81,7 @@ class VisualsGenerator: continue bounds = FrontLineConflictDescription.frontline_bounds( - front_line, self.game.theater, self.game.settings + front_line, self.game.theater ) for offset in range(