From 5ca344e87b425d817788413bc3486b3cae957a7f Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Thu, 10 Aug 2023 20:45:28 -0700 Subject: [PATCH] Show the real front line bounds on the map. Fixes https://github.com/dcs-liberation/dcs_liberation/issues/1067. --- changelog.md | 1 + game/server/eventstream/models.py | 12 +++++++----- game/server/frontlines/models.py | 25 +++++++++++++------------ game/server/frontlines/routes.py | 4 +++- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/changelog.md b/changelog.md index a7bc582e..dd3dccbf 100644 --- a/changelog.md +++ b/changelog.md @@ -222,6 +222,7 @@ BAI/ANTISHIP/DEAD/STRIKE/BARCAP/CAS/OCA/AIR-ASSAULT (main) missions * **[UI]** An error will be displayed when invalid fast-forward options are selected rather than beginning a never ending simulation. * **[UI]** Added cheats for instantly repairing and destroying runways. * **[UI]** Improved usability of the flight properties UI. It now shows human-readable names and uses more appropriate UI elements. +* **[UI]** The map now shows the real front line bounds. ## Fixes diff --git a/game/server/eventstream/models.py b/game/server/eventstream/models.py index a2d7a69c..11d82c38 100644 --- a/game/server/eventstream/models.py +++ b/game/server/eventstream/models.py @@ -11,8 +11,7 @@ from game.server.flights.models import FlightJs from game.server.frontlines.models import FrontLineJs from game.server.iadsnetwork.models import IadsConnectionJs from game.server.leaflet import LeafletPoint -from game.server.mapzones.models import ThreatZonesJs -from game.server.mapzones.models import UnculledZoneJs +from game.server.mapzones.models import ThreatZonesJs, UnculledZoneJs from game.server.navmesh.models import NavMeshJs from game.server.supplyroutes.models import SupplyRouteJs from game.server.tgos.models import TgoJs @@ -59,6 +58,7 @@ class GameUpdateEventsJs(BaseModel): updated_unculled_zones = [] updated_iads = [] updated_supply_routes = [] + updated_front_lines = [] if game is not None: new_combats = [ FrozenCombatJs.for_combat(c, game.theater) for c in events.new_combats @@ -82,6 +82,10 @@ class GameUpdateEventsJs(BaseModel): updated_supply_routes = SupplyRouteJs.all_in_game(game) for route in updated_supply_routes: route.points = [] + updated_front_lines = [ + FrontLineJs.for_front_line(game.theater, f) + for f in events.updated_front_lines + ] return GameUpdateEventsJs( updated_flight_positions={ @@ -103,9 +107,7 @@ class GameUpdateEventsJs(BaseModel): deleted_flights=events.deleted_flights, selected_flight=events.selected_flight, deselected_flight=events.deselected_flight, - updated_front_lines=[ - FrontLineJs.for_front_line(f) for f in events.updated_front_lines - ], + updated_front_lines=updated_front_lines, deleted_front_lines=events.deleted_front_lines, updated_tgos=[TgoJs.for_tgo(tgo) for tgo in events.updated_tgos], updated_control_points=[ diff --git a/game/server/frontlines/models.py b/game/server/frontlines/models.py index fe4d471e..be966a96 100644 --- a/game/server/frontlines/models.py +++ b/game/server/frontlines/models.py @@ -5,12 +5,14 @@ from uuid import UUID from pydantic import BaseModel +from game.missiongenerator.frontlineconflictdescription import ( + FrontLineConflictDescription, +) from game.server.leaflet import LeafletPoint -from game.utils import nautical_miles if TYPE_CHECKING: from game import Game - from game.theater import FrontLine + from game.theater import FrontLine, ConflictTheater class FrontLineJs(BaseModel): @@ -21,17 +23,16 @@ class FrontLineJs(BaseModel): title = "FrontLine" @staticmethod - def for_front_line(front_line: FrontLine) -> FrontLineJs: - a = front_line.position.point_from_heading( - front_line.blue_forward_heading.right.degrees, - nautical_miles(2).meters, + def for_front_line(theater: ConflictTheater, front_line: FrontLine) -> FrontLineJs: + bounds = FrontLineConflictDescription.frontline_bounds(front_line, theater) + return FrontLineJs( + id=front_line.id, + extents=[bounds.left_position.latlng(), bounds.right_position.latlng()], ) - b = front_line.position.point_from_heading( - front_line.blue_forward_heading.left.degrees, - nautical_miles(2).meters, - ) - return FrontLineJs(id=front_line.id, extents=[a.latlng(), b.latlng()]) @staticmethod def all_in_game(game: Game) -> list[FrontLineJs]: - return [FrontLineJs.for_front_line(f) for f in game.theater.conflicts()] + return [ + FrontLineJs.for_front_line(game.theater, f) + for f in game.theater.conflicts() + ] diff --git a/game/server/frontlines/routes.py b/game/server/frontlines/routes.py index c62433d0..c51b5715 100644 --- a/game/server/frontlines/routes.py +++ b/game/server/frontlines/routes.py @@ -20,4 +20,6 @@ def list_front_lines(game: Game = Depends(GameContext.require)) -> list[FrontLin def get_front_line( front_line_id: UUID, game: Game = Depends(GameContext.require) ) -> FrontLineJs: - return FrontLineJs.for_front_line(game.db.front_lines.get(front_line_id)) + return FrontLineJs.for_front_line( + game.theater, game.db.front_lines.get(front_line_id) + )