Move has_radar into the TGO.

This commit is contained in:
Dan Albert 2020-12-22 12:47:40 -08:00
parent c53feb5ccb
commit e46262b021
2 changed files with 14 additions and 13 deletions

View File

@ -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,

View File

@ -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():