Plan AEW&C in safer locations.

Fixes https://github.com/dcs-liberation/dcs_liberation/issues/1119
This commit is contained in:
Dan Albert 2021-05-31 14:57:25 -07:00
parent e94ebd6ed2
commit 2d0929cd69
2 changed files with 24 additions and 32 deletions

View File

@ -40,6 +40,10 @@ class ThreatZones:
) )
return DcsPoint(boundary.x, boundary.y) return DcsPoint(boundary.x, boundary.y)
def distance_to_threat(self, point: DcsPoint) -> Distance:
boundary = self.closest_boundary(point)
return meters(boundary.distance_to_point(point))
@singledispatchmethod @singledispatchmethod
def threatened(self, position) -> bool: def threatened(self, position) -> bool:
raise NotImplementedError raise NotImplementedError

View File

@ -506,31 +506,21 @@ class ObjectiveFinder:
c for c in self.game.theater.controlpoints if c.is_friendly(self.is_player) c for c in self.game.theater.controlpoints if c.is_friendly(self.is_player)
) )
def farthest_friendly_control_point(self) -> Optional[ControlPoint]: def farthest_friendly_control_point(self) -> ControlPoint:
""" """Finds the friendly control point that is farthest from any threats."""
Iterates over all friendly control points and find the one farthest away from the frontline threat_zones = self.game.threat_zone_for(not self.is_player)
BUT! prefer Cvs. Everybody likes CVs!
"""
from_frontline = 0
cp = None
first_friendly_cp = None
for c in self.game.theater.controlpoints: farthest = None
if c.is_friendly(self.is_player): max_distance = meters(0)
if first_friendly_cp is None: for cp in self.friendly_control_points():
first_friendly_cp = c distance = threat_zones.distance_to_threat(cp.position)
if c.is_carrier: if distance > max_distance:
return c farthest = cp
if c.has_active_frontline: max_distance = distance
if c.distance_to(self.front_lines().__next__()) > from_frontline:
from_frontline = c.distance_to(self.front_lines().__next__())
cp = c
# If no frontlines on the map, return the first friendly cp if farthest is None:
if cp is None: raise RuntimeError("Found no friendly control points. You probably lost.")
return first_friendly_cp return farthest
else:
return cp
def enemy_control_points(self) -> Iterator[ControlPoint]: def enemy_control_points(self) -> Iterator[ControlPoint]:
"""Iterates over all enemy control points.""" """Iterates over all enemy control points."""
@ -628,15 +618,13 @@ class CoalitionMissionPlanner:
eliminated this turn. eliminated this turn.
""" """
# Find farthest, friendly CP for AEWC # Find farthest, friendly CP for AEWC.
cp = self.objective_finder.farthest_friendly_control_point() yield ProposedMission(
if cp is not None: self.objective_finder.farthest_friendly_control_point(),
yield ProposedMission( [ProposedFlight(FlightType.AEWC, 1, self.MAX_AWEC_RANGE)],
cp, # Supports all the early CAP flights, so should be in the air ASAP.
[ProposedFlight(FlightType.AEWC, 1, self.MAX_AWEC_RANGE)], asap=True,
# Supports all the early CAP flights, so should be in the air ASAP. )
asap=True,
)
# Find friendly CPs within 100 nmi from an enemy airfield, plan CAP. # Find friendly CPs within 100 nmi from an enemy airfield, plan CAP.
for cp in self.objective_finder.vulnerable_control_points(): for cp in self.objective_finder.vulnerable_control_points():