Remove aa_ranges in favor of using the TGO data.

This commit is contained in:
Dan Albert 2020-12-26 15:25:23 -08:00
parent d634fd3236
commit 17dd1b193e
3 changed files with 30 additions and 40 deletions

View File

@ -157,12 +157,11 @@ class TheaterGroundObject(MissionTarget):
return True
return False
@property
def threat_range(self) -> Distance:
def _max_range_of_type(self, range_type: str) -> Distance:
if not self.might_have_aa:
return meters(0)
threat_range = meters(0)
max_range = meters(0)
for group in self.groups:
for u in group.units:
unit = db.unit_type_from_name(u.type)
@ -170,12 +169,20 @@ class TheaterGroundObject(MissionTarget):
logging.error(f"Unknown unit type {u.type}")
continue
# Some units in pydcs have threat_range defined, but explicitly
# set to None.
unit_threat_range = getattr(unit, "threat_range", None)
if unit_threat_range is not None:
threat_range = max(threat_range, meters(unit_threat_range))
return threat_range
# Some units in pydcs have detection_range/threat_range defined,
# but explicitly set to None.
unit_range = getattr(unit, range_type, None)
if unit_range is not None:
max_range = max(max_range, meters(unit_range))
return max_range
@property
def detection_range(self) -> Distance:
return self._max_range_of_type("detection_range")
@property
def threat_range(self) -> Distance:
return self._max_range_of_type("threat_range")
class BuildingGroundObject(TheaterGroundObject):

View File

@ -72,6 +72,9 @@ class Distance:
def __floordiv__(self, other: Union[float, int]) -> Distance:
return meters(self.meters // other)
def __bool__(self) -> bool:
return not math.isclose(self.meters, 0.0)
def feet(value: float) -> Distance:
return Distance.from_feet(value)
@ -154,6 +157,9 @@ class Speed:
def __floordiv__(self, other: Union[float, int]) -> Speed:
return kph(self.kph // other)
def __bool__(self) -> bool:
return not math.isclose(self.kph, 0.0)
def knots(value: float) -> Speed:
return Speed.from_knots(value)

View File

@ -263,29 +263,6 @@ class QLiberationMap(QGraphicsView):
def update_reference_point(point: ReferencePoint, change: Point) -> None:
point.image_coordinates += change
@staticmethod
def aa_ranges(ground_object: TheaterGroundObject) -> Tuple[int, int]:
detection_range = 0
threat_range = 0
for g in ground_object.groups:
for u in g.units:
unit = db.unit_type_from_name(u.type)
if unit is None:
logging.error(f"Unknown unit type {u.type}")
continue
# Some units in pydcs have detection_range and threat_range
# defined, but explicitly set to None.
unit_detection_range = getattr(unit, "detection_range", None)
if unit_detection_range is not None:
detection_range = max(detection_range, unit_detection_range)
unit_threat_range = getattr(unit, "threat_range", None)
if unit_threat_range is not None:
threat_range = max(threat_range, unit_threat_range)
return detection_range, threat_range
def display_culling(self, scene: QGraphicsScene) -> None:
"""Draws the culling distance rings on the map"""
culling_points = self.game_model.game.get_culling_points()
@ -464,7 +441,6 @@ class QLiberationMap(QGraphicsView):
package.time_over_target = TotEstimator(package).earliest_tot()
self.draw_flight_plan(scene, flight, selected=True)
@staticmethod
def should_display_ground_objects_at(cp: ControlPoint) -> bool:
return ((DisplayOptions.sam_ranges and cp.captured) or
@ -472,12 +448,12 @@ class QLiberationMap(QGraphicsView):
def draw_threat_range(self, scene: QGraphicsScene, ground_object: TheaterGroundObject, cp: ControlPoint) -> None:
go_pos = self._transform_point(ground_object.position)
detection_range, threat_range = self.aa_ranges(
ground_object
)
detection_range = ground_object.detection_range
threat_range = ground_object.threat_range
if threat_range:
threat_pos = self._transform_point(Point(ground_object.position.x+threat_range,
ground_object.position.y+threat_range))
threat_pos = self._transform_point(
ground_object.position + Point(threat_range.meters,
threat_range.meters))
threat_radius = Point(*go_pos).distance_to_point(Point(*threat_pos))
# Add threat range circle
@ -486,8 +462,9 @@ class QLiberationMap(QGraphicsView):
if detection_range and DisplayOptions.detection_range:
# Add detection range circle
detection_pos = self._transform_point(Point(ground_object.position.x+detection_range,
ground_object.position.y+detection_range))
detection_pos = self._transform_point(
ground_object.position + Point(detection_range.meters,
detection_range.meters))
detection_radius = Point(*go_pos).distance_to_point(Point(*detection_pos))
scene.addEllipse(go_pos[0] - detection_radius/2 + 7, go_pos[1] - detection_radius/2 + 6,
detection_radius, detection_radius, self.detection_pen(cp.captured))