Fixed ai_flight_planner for maps lacking frontlines (such as battle of britain on The Channel map)

This commit is contained in:
Khopa 2021-04-23 23:45:14 +02:00
parent 45913b0add
commit 6aba07c33b

View File

@ -460,21 +460,31 @@ 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) -> ControlPoint: def farthest_friendly_control_point(self) -> Optional[ControlPoint]:
""" """
Iterates over all friendly control points and find the one farthest away from the frontline Iterates over all friendly control points and find the one farthest away from the frontline
BUT! prefer Cvs. Everybody likes CVs! BUT! prefer Cvs. Everybody likes CVs!
""" """
from_frontline = 0 from_frontline = 0
cp = None
first_friendly_cp = None
for c in self.game.theater.controlpoints: for c in self.game.theater.controlpoints:
if c.is_carrier and c.is_friendly(self.is_player): if c.is_friendly(self.is_player):
return c if first_friendly_cp is None:
if c.is_friendly(self.is_player) and c.has_frontline: first_friendly_cp = c
if c.distance_to(self.front_lines().__next__()) > from_frontline: if c.is_carrier:
from_frontline = c.distance_to(self.front_lines().__next__()) return c
cp = c if c.has_active_frontline:
return cp 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 cp is None:
return first_friendly_cp
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."""
@ -556,9 +566,10 @@ class CoalitionMissionPlanner:
# Find farthest, friendly CP for AEWC # Find farthest, friendly CP for AEWC
cp = self.objective_finder.farthest_friendly_control_point() cp = self.objective_finder.farthest_friendly_control_point()
yield ProposedMission( if cp is not None:
cp, [ProposedFlight(FlightType.AEWC, 1, self.MAX_AWEC_RANGE)] yield ProposedMission(
) cp, [ProposedFlight(FlightType.AEWC, 1, self.MAX_AWEC_RANGE)]
)
# 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():