mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Fix exception when campaign has only off map CPs.
This PR fixes an exception in custom campaigns that only contain off map spawns.
This commit is contained in:
parent
b014f2e543
commit
a213215c3f
@ -25,6 +25,7 @@ from game.utils import meters, nautical_miles
|
|||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from game import Game
|
from game import Game
|
||||||
from game.transfers import CargoShip, Convoy
|
from game.transfers import CargoShip, Convoy
|
||||||
|
from game.threatzones import ThreatZones
|
||||||
|
|
||||||
MissionTargetType = TypeVar("MissionTargetType", bound=MissionTarget)
|
MissionTargetType = TypeVar("MissionTargetType", bound=MissionTarget)
|
||||||
|
|
||||||
@ -193,17 +194,36 @@ class ObjectiveFinder:
|
|||||||
|
|
||||||
def farthest_friendly_control_point(self) -> ControlPoint:
|
def farthest_friendly_control_point(self) -> ControlPoint:
|
||||||
"""Finds the friendly control point that is farthest from any threats."""
|
"""Finds the friendly control point that is farthest from any threats."""
|
||||||
threat_zones = self.game.threat_zone_for(not self.is_player)
|
|
||||||
|
|
||||||
|
def find_farthest(
|
||||||
|
control_points: Iterator[ControlPoint],
|
||||||
|
threat_zones: ThreatZones,
|
||||||
|
consider_off_map_spawn: bool,
|
||||||
|
) -> ControlPoint | None:
|
||||||
farthest = None
|
farthest = None
|
||||||
max_distance = meters(0)
|
max_distance = meters(0)
|
||||||
for cp in self.friendly_control_points():
|
for cp in control_points:
|
||||||
if isinstance(cp, OffMapSpawn):
|
if isinstance(cp, OffMapSpawn) and not consider_off_map_spawn:
|
||||||
continue
|
continue
|
||||||
distance = threat_zones.distance_to_threat(cp.position)
|
distance = threat_zones.distance_to_threat(cp.position)
|
||||||
if distance > max_distance:
|
if distance > max_distance:
|
||||||
farthest = cp
|
farthest = cp
|
||||||
max_distance = distance
|
max_distance = distance
|
||||||
|
return farthest
|
||||||
|
|
||||||
|
threat_zones = self.game.threat_zone_for(not self.is_player)
|
||||||
|
|
||||||
|
farthest = find_farthest(
|
||||||
|
self.friendly_control_points(), threat_zones, consider_off_map_spawn=False
|
||||||
|
)
|
||||||
|
|
||||||
|
# If there are only off-map spawn control points, fall back to the farthest amongst off map spawn points
|
||||||
|
if farthest is None:
|
||||||
|
farthest = find_farthest(
|
||||||
|
self.friendly_control_points(),
|
||||||
|
threat_zones,
|
||||||
|
consider_off_map_spawn=True,
|
||||||
|
)
|
||||||
|
|
||||||
if farthest is None:
|
if farthest is None:
|
||||||
raise RuntimeError("Found no friendly control points. You probably lost.")
|
raise RuntimeError("Found no friendly control points. You probably lost.")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user