From 91d9bbdc975ffbfb0cca953ad101d5347737e87c Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Wed, 23 Dec 2020 17:25:32 -0800 Subject: [PATCH] Add visual debugging for other fligth plans. --- game/theater/conflicttheater.py | 5 ++++ qt_ui/displayoptions.py | 4 +++ qt_ui/widgets/map/QLiberationMap.py | 40 +++++++++++++++++++++-------- 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/game/theater/conflicttheater.py b/game/theater/conflicttheater.py index 6b1b3a55..e0aa1154 100644 --- a/game/theater/conflicttheater.py +++ b/game/theater/conflicttheater.py @@ -537,6 +537,11 @@ class ConflictTheater: if distance < closest_distance: closest = tgo closest_distance = distance + for conflict in self.conflicts(): + distance = conflict.position.distance_to_point(point) + if distance < closest_distance: + closest = conflict + closest_distance = distance return closest def closest_opposing_control_points(self) -> Tuple[ControlPoint, ControlPoint]: diff --git a/qt_ui/displayoptions.py b/qt_ui/displayoptions.py index 100e7960..5d8e6373 100644 --- a/qt_ui/displayoptions.py +++ b/qt_ui/displayoptions.py @@ -82,6 +82,10 @@ class PathDebugOptions(DisplayGroup): super().__init__("Shortest paths", debug_only=True) self.hide = DisplayRule("DEBUG Hide paths", True) self.shortest_path = DisplayRule("DEBUG Show shortest path", False) + self.barcap = DisplayRule("DEBUG Show BARCAP plan", False) + self.cas = DisplayRule("DEBUG Show CAS plan", False) + self.sweep = DisplayRule("DEBUG Show fighter sweep plan", False) + self.strike = DisplayRule("DEBUG Show strike plan", False) self.tarcap = DisplayRule("DEBUG Show TARCAP plan", False) diff --git a/qt_ui/widgets/map/QLiberationMap.py b/qt_ui/widgets/map/QLiberationMap.py index b9255241..7946b7ad 100644 --- a/qt_ui/widgets/map/QLiberationMap.py +++ b/qt_ui/widgets/map/QLiberationMap.py @@ -52,7 +52,11 @@ from gen.flights.flight import ( FlightWaypoint, FlightWaypointType, ) -from gen.flights.flightplan import FlightPlan, FlightPlanBuilder +from gen.flights.flightplan import ( + FlightPlan, + FlightPlanBuilder, + InvalidObjectiveLocation, +) from qt_ui.displayoptions import DisplayOptions, ThreatZoneOptions from qt_ui.models import GameModel from qt_ui.widgets.map.QFrontLine import QFrontLine @@ -429,8 +433,8 @@ class QLiberationMap(QGraphicsView): prev_pos = new_pos - def draw_tarcap_plan(self, scene: QGraphicsScene, point_near_target: Point, - player: bool) -> None: + def draw_test_flight_plan(self, scene: QGraphicsScene, task: FlightType, + point_near_target: Point, player: bool) -> None: for line in self.shortest_path_segments: try: scene.removeItem(line) @@ -447,12 +451,14 @@ class QLiberationMap(QGraphicsView): origin = self.game.theater.enemy_points()[0] package = Package(target) - flight = Flight(package, F_16C_50, 2, FlightType.TARCAP, - start_type="Warm", departure=origin, arrival=origin, - divert=None) + flight = Flight(package, F_16C_50, 2, task, start_type="Warm", + departure=origin, arrival=origin, divert=None) package.add_flight(flight) planner = FlightPlanBuilder(self.game, package, is_player=player) - planner.populate_flight_plan(flight) + try: + planner.populate_flight_plan(flight) + except InvalidObjectiveLocation: + return self.draw_flight_plan(scene, flight, selected=True) @@ -1052,10 +1058,22 @@ class QLiberationMap(QGraphicsView): self.draw_shortest_path( self.scene(), self.game.navmesh_for(player=debug_blue), mouse_world_pos, player=False) - - if DisplayOptions.path_debug.tarcap: - self.draw_tarcap_plan(self.scene(), mouse_world_pos, - player=debug_blue) + elif not DisplayOptions.path_debug.hide: + if DisplayOptions.path_debug.barcap: + task = FlightType.BARCAP + elif DisplayOptions.path_debug.cas: + task = FlightType.CAS + elif DisplayOptions.path_debug.sweep: + task = FlightType.SWEEP + elif DisplayOptions.path_debug.strike: + task = FlightType.STRIKE + elif DisplayOptions.path_debug.tarcap: + task = FlightType.TARCAP + else: + raise ValueError( + "Unexpected value for DisplayOptions.path_debug") + self.draw_test_flight_plan(self.scene(), task, mouse_world_pos, + player=debug_blue) def sceneMousePressEvent(self, event: QGraphicsSceneMouseEvent): if self.state == QLiberationMapState.MOVING_UNIT: