Dan Albert 4521053804 Move FlightPlan instantiation into the builder.
I'm working on moving the builder to be owned by the Flight, which will
simplify callers that need to create (or recreate) flight plans for a
flight.
2022-08-21 19:37:20 -07:00

42 lines
1.2 KiB
Python

from __future__ import annotations
import logging
from typing import Type
from game.theater.theatergroundobject import (
EwrGroundObject,
SamGroundObject,
)
from .formationattack import (
FormationAttackBuilder,
FormationAttackFlightPlan,
FormationAttackLayout,
)
from .invalidobjectivelocation import InvalidObjectiveLocation
from ..flightwaypointtype import FlightWaypointType
class DeadFlightPlan(FormationAttackFlightPlan):
@staticmethod
def builder_type() -> Type[Builder]:
return Builder
class Builder(FormationAttackBuilder[DeadFlightPlan, FormationAttackLayout]):
def layout(self) -> FormationAttackLayout:
location = self.package.target
is_ewr = isinstance(location, EwrGroundObject)
is_sam = isinstance(location, SamGroundObject)
if not is_ewr and not is_sam:
logging.exception(
f"Invalid Objective Location for DEAD flight {self.flight=} at "
f"{location=}"
)
raise InvalidObjectiveLocation(self.flight.flight_type, location)
return self._build(FlightWaypointType.INGRESS_DEAD)
def build(self) -> DeadFlightPlan:
return DeadFlightPlan(self.flight, self.layout())