From 08365bcbdab5f5f698df0e997563af114bec49e0 Mon Sep 17 00:00:00 2001 From: Magnus Wolffelt Date: Fri, 13 Aug 2021 23:43:09 +0200 Subject: [PATCH 1/2] Simplify and enhance tarcap flight planning --- gen/flights/flightplan.py | 52 ++++++++++----------------------------- 1 file changed, 13 insertions(+), 39 deletions(-) diff --git a/gen/flights/flightplan.py b/gen/flights/flightplan.py index 408eb5fd..032c84e2 100644 --- a/gen/flights/flightplan.py +++ b/gen/flights/flightplan.py @@ -1115,7 +1115,7 @@ class FlightPlanBuilder: if isinstance(location, FrontLine): raise InvalidObjectiveLocation(flight.flight_type, location) - start_pos, end_pos = self.racetrack_for_objective(location, barcap=True) + start_pos, end_pos = self.cap_racetrack_for_objective(location, barcap=True) preferred_alt = flight.unit_type.preferred_patrol_altitude randomized_alt = preferred_alt + feet(random.randint(-2, 1) * 1000) @@ -1244,7 +1244,7 @@ class FlightPlanBuilder: bullseye=builder.bullseye(), ) - def racetrack_for_objective( + def cap_racetrack_for_objective( self, location: MissionTarget, barcap: bool ) -> Tuple[Point, Point]: closest_cache = ObjectiveDistanceCache.get_closest_airfields(location) @@ -1276,6 +1276,7 @@ class FlightPlanBuilder: - self.doctrine.cap_engagement_range - nautical_miles(5) ) + max_track_length = self.doctrine.cap_max_track_length else: # Other race tracks (TARCAPs, currently) just try to keep some # distance from the nearest enemy airbase, but since they are by @@ -1289,6 +1290,11 @@ class FlightPlanBuilder: ) distance_to_no_fly = distance_to_airfield - min_distance_from_enemy + # TARCAPs fly short racetracks because they need to react faster. + max_track_length = self.doctrine.cap_min_track_length + 0.3 * ( + self.doctrine.cap_max_track_length - self.doctrine.cap_min_track_length + ) + min_cap_distance = min( self.doctrine.cap_min_distance_from_cp, distance_to_no_fly ) @@ -1300,11 +1306,12 @@ class FlightPlanBuilder: heading.degrees, random.randint(int(min_cap_distance.meters), int(max_cap_distance.meters)), ) - diameter = random.randint( + + track_length = random.randint( int(self.doctrine.cap_min_track_length.meters), - int(self.doctrine.cap_max_track_length.meters), + int(max_track_length.meters), ) - start = end.point_from_heading(heading.opposite.degrees, diameter) + start = end.point_from_heading(heading.opposite.degrees, track_length) return start, end def aewc_orbit(self, location: MissionTarget) -> Point: @@ -1327,33 +1334,6 @@ class FlightPlanBuilder: orbit_heading.degrees, orbit_distance.meters ) - def racetrack_for_frontline( - self, origin: Point, front_line: FrontLine - ) -> Tuple[Point, Point]: - # Find targets waypoints - ingress, heading, distance = Conflict.frontline_vector(front_line, self.theater) - center = ingress.point_from_heading(heading.degrees, distance / 2) - orbit_center = center.point_from_heading( - heading.left.degrees, - random.randint( - int(nautical_miles(6).meters), int(nautical_miles(15).meters) - ), - ) - - combat_width = distance / 2 - if combat_width > 500000: - combat_width = 500000 - if combat_width < 35000: - combat_width = 35000 - - radius = combat_width * 1.25 - start = orbit_center.point_from_heading(heading.degrees, radius) - end = orbit_center.point_from_heading(heading.opposite.degrees, radius) - - if end.distance_to_point(origin) < start.distance_to_point(origin): - start, end = end, start - return start, end - def generate_tarcap(self, flight: Flight) -> TarCapFlightPlan: """Generate a CAP flight plan for the given front line. @@ -1375,13 +1355,7 @@ class FlightPlanBuilder: # Create points builder = WaypointBuilder(flight, self.coalition) - - if isinstance(location, FrontLine): - orbit0p, orbit1p = self.racetrack_for_frontline( - flight.departure.position, location - ) - else: - orbit0p, orbit1p = self.racetrack_for_objective(location, barcap=False) + orbit0p, orbit1p = self.cap_racetrack_for_objective(location, barcap=False) start, end = builder.race_track(orbit0p, orbit1p, patrol_alt) return TarCapFlightPlan( From 8f5b6f58d12ef0f0edd5f9ebcf44c71dc2a5ff47 Mon Sep 17 00:00:00 2001 From: Magnus Wolffelt Date: Mon, 16 Aug 2021 10:03:40 +0200 Subject: [PATCH 2/2] Add rmul to distance and speeds, so that reversed operands work --- game/utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/game/utils.py b/game/utils.py index 119a741a..fbb28d0e 100644 --- a/game/utils.py +++ b/game/utils.py @@ -62,6 +62,8 @@ class Distance: def __mul__(self, other: Union[float, int]) -> Distance: return meters(self.meters * other) + __rmul__ = __mul__ + def __truediv__(self, other: Union[float, int]) -> Distance: return meters(self.meters / other) @@ -147,6 +149,8 @@ class Speed: def __mul__(self, other: Union[float, int]) -> Speed: return kph(self.kph * other) + __rmul__ = __mul__ + def __truediv__(self, other: Union[float, int]) -> Speed: return kph(self.kph / other)