Dan Albert f5ef509af6
Fix drop zone display for air assault.
Troops must be dropped inside this zone or they won't attack the target.
The zone needs to be drawn in the map so players don't break the flight
plan by accidentally moving the drop waypoint outside the DZ.

I've move the API for doing this out of `PatrollingFlightPlan` in favor
of a mixin so this is no longer presented as `engagement_distance` by
the flight plan. I don't love that it's still the `commit-boundary`
endpoint, but it's fine for now.

I don't know why mypy wasn't able to catch this. pycharm is also
struggling to understand this class.
2022-11-26 15:18:41 +01:00

50 lines
1.6 KiB
Python

from uuid import UUID
from fastapi import APIRouter, Depends
from shapely.geometry import LineString, Point as ShapelyPoint
from game import Game
from game.ato.flightplans.uizonedisplay import UiZoneDisplay
from game.server import GameContext
from game.server.flights.models import FlightJs
from game.server.leaflet import LeafletPoly, ShapelyUtil
router: APIRouter = APIRouter(prefix="/flights")
@router.get("/", operation_id="list_flights", response_model=list[FlightJs])
def list_flights(
with_waypoints: bool = False, game: Game = Depends(GameContext.require)
) -> list[FlightJs]:
return FlightJs.all_in_game(game, with_waypoints)
@router.get("/{flight_id}", operation_id="get_flight_by_id", response_model=FlightJs)
def get_flight(
flight_id: UUID,
with_waypoints: bool = False,
game: Game = Depends(GameContext.require),
) -> FlightJs:
flight = game.db.flights.get(flight_id)
return FlightJs.for_flight(flight, with_waypoints)
@router.get(
"/{flight_id}/commit-boundary",
operation_id="get_commit_boundary_for_flight",
response_model=LeafletPoly,
)
def commit_boundary(
flight_id: UUID, game: Game = Depends(GameContext.require)
) -> LeafletPoly:
flight = game.db.flights.get(flight_id)
if not isinstance(flight.flight_plan, UiZoneDisplay):
return []
zone = flight.flight_plan.ui_zone()
if len(zone.points) == 1:
center = ShapelyPoint(zone.points[0].x, zone.points[0].y)
else:
center = LineString([ShapelyPoint(p.x, p.y) for p in zone.points])
bubble = center.buffer(zone.radius.meters)
return ShapelyUtil.poly_to_leaflet(bubble, game.theater)