diff --git a/game/theater/theatergroundobject.py b/game/theater/theatergroundobject.py index 2908d5f3..df588ec8 100644 --- a/game/theater/theatergroundobject.py +++ b/game/theater/theatergroundobject.py @@ -7,6 +7,9 @@ from dcs.mapping import Point from dcs.unit import Unit from dcs.unitgroup import Group +from .. import db +from ..data.radar_db import UNITS_WITH_RADAR + if TYPE_CHECKING: from .controlpoint import ControlPoint from gen.flights.flight import FlightType @@ -144,6 +147,15 @@ class TheaterGroundObject(MissionTarget): def might_have_aa(self) -> bool: return False + @property + def has_radar(self) -> bool: + """Returns True if the ground object contains a unit with radar.""" + for group in self.groups: + for unit in group.units: + if db.unit_type_from_name(unit.type) in UNITS_WITH_RADAR: + return True + return False + class BuildingGroundObject(TheaterGroundObject): def __init__(self, name: str, category: str, group_id: int, object_id: int, diff --git a/gen/flights/ai_flight_planner.py b/gen/flights/ai_flight_planner.py index e2de9947..c6aad0f1 100644 --- a/gen/flights/ai_flight_planner.py +++ b/gen/flights/ai_flight_planner.py @@ -18,8 +18,6 @@ from typing import ( from dcs.unittype import FlyingType -from game import db -from game.data.radar_db import UNITS_WITH_RADAR from game.infos.information import Information from game.procurement import AircraftProcurementRequest from game.theater import ( @@ -36,7 +34,7 @@ from game.theater.theatergroundobject import ( EwrGroundObject, NavalGroundObject, VehicleGroupGroundObject, ) -from game.utils import Distance, nautical_miles, nautical_miles +from game.utils import Distance, nautical_miles from gen import Conflict from gen.ato import Package from gen.flights.ai_flight_planner_db import ( @@ -256,7 +254,7 @@ class ObjectiveFinder: if ground_object.name in found_targets: continue - if not self.object_has_radar(ground_object): + if not ground_object.has_radar: continue # TODO: Yield in order of most threatening. @@ -358,15 +356,6 @@ class ObjectiveFinder: for target, _range in targets: yield target - @staticmethod - def object_has_radar(ground_object: TheaterGroundObject) -> bool: - """Returns True if the ground object contains a unit with radar.""" - for group in ground_object.groups: - for unit in group.units: - if db.unit_type_from_name(unit.type) in UNITS_WITH_RADAR: - return True - return False - def front_lines(self) -> Iterator[FrontLine]: """Iterates over all active front lines in the theater.""" for cp in self.friendly_control_points():