From 592b1a7833206cd0efa88464c52017722f3853c8 Mon Sep 17 00:00:00 2001 From: Raffson Date: Sat, 28 Dec 2024 01:02:40 +0100 Subject: [PATCH] Don't allow carrier's path over land in UI --- game/server/controlpoints/routes.py | 9 +++++++++ game/theater/landmap.py | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/game/server/controlpoints/routes.py b/game/server/controlpoints/routes.py index b1c8f9ed..4274f628 100644 --- a/game/server/controlpoints/routes.py +++ b/game/server/controlpoints/routes.py @@ -89,6 +89,15 @@ def set_destination( detail=f"Cannot move {cp} more than " f"{cp.max_move_distance.nautical_miles}nm.", ) + if ( + cp.is_fleet + and game.theater.landmap + and game.theater.landmap.land_inbetween(cp.position, point) + ): + raise HTTPException( + status.HTTP_400_BAD_REQUEST, + detail=f"Cannot move {cp} over land.", + ) cp.target_position = point from .. import EventStream diff --git a/game/theater/landmap.py b/game/theater/landmap.py index 66cad7a4..5ea5e020 100644 --- a/game/theater/landmap.py +++ b/game/theater/landmap.py @@ -10,7 +10,7 @@ from dcs.drawing.polygon import FreeFormPolygon from dcs.mapping import Point from dcs.mission import Mission from dcs.terrain.terrain import Terrain -from shapely import geometry +from shapely import geometry, LineString from shapely.geometry import MultiPolygon, Polygon @@ -32,6 +32,10 @@ class Landmap: def inclusion_zone_only(self) -> MultiPolygon: return self.inclusion_zones - self.exclusion_zones - self.sea_zones + def land_inbetween(self, a: Point, b: Point) -> bool: + line = LineString([[a.x, a.y], [b.x, b.y]]) + return self.inclusion_zones.intersects(line) + def load_landmap(filename: Path) -> Optional[Landmap]: try: