From 582c43fb6cd0d4cbea53786f5eed65b1b924732c Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Tue, 29 Sep 2020 00:51:27 -0700 Subject: [PATCH] Generate CAP missions in useful locations. CAP missions should be between the protected location and the nearest threat. Find the closest enemy airfield and ensure that the CAP race track is between it and the protected location. --- gen/flights/flightplan.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/gen/flights/flightplan.py b/gen/flights/flightplan.py index a6e787a4..45bf2a13 100644 --- a/gen/flights/flightplan.py +++ b/gen/flights/flightplan.py @@ -16,6 +16,7 @@ from dcs.unit import Unit from game.data.doctrine import Doctrine, MODERN_DOCTRINE from game.utils import nm_to_meter from theater import ControlPoint, FrontLine, MissionTarget, TheaterGroundObject +from .closestairfields import ObjectiveDistanceCache from .flight import Flight, FlightType, FlightWaypoint, FlightWaypointType from .waypointbuilder import WaypointBuilder from ..conflictgen import Conflict @@ -37,6 +38,7 @@ class FlightPlanBuilder: def __init__(self, game: Game, is_player: bool) -> None: self.game = game + self.is_player = is_player if is_player: faction = self.game.player_faction else: @@ -174,18 +176,30 @@ class FlightPlanBuilder: self.doctrine.max_patrol_altitude ) + closest_cache = ObjectiveDistanceCache.get_closest_airfields(location) + for airfield in closest_cache.closest_airfields: + if airfield.captured != self.is_player: + closest_airfield = airfield + break + else: + logging.error("Could not find any enemy airfields") + return + + heading = location.position.heading_between_point( + closest_airfield.position + ) + loc = location.position.point_from_heading( - random.randint(0, 360), + heading, random.randint(self.doctrine.cap_min_distance_from_cp, self.doctrine.cap_max_distance_from_cp) ) - hdg = location.position.heading_between_point(loc) radius = random.randint( self.doctrine.cap_min_track_length, self.doctrine.cap_max_track_length ) - orbit0p = loc.point_from_heading(hdg - 90, radius) - orbit1p = loc.point_from_heading(hdg + 90, radius) + orbit0p = loc.point_from_heading(heading - 90, radius) + orbit1p = loc.point_from_heading(heading + 90, radius) builder = WaypointBuilder(self.doctrine) builder.ascent(flight.from_cp)