dcs_liberation/game/ato/flightwaypoint.py
Dan Albert 3e08e0e8b6 Un-pydantic FlightWaypoint.
Apparently it's a bad idea to try to make the core data pydantic models,
and those should really be treated more as a view-model. Doing otherwise
causes odd patterns (like the UI info I had leaked into the core type),
and makes it harder to interop with third-party types.
2022-02-21 23:10:28 -08:00

58 lines
1.6 KiB
Python

from __future__ import annotations
from collections.abc import Sequence
from dataclasses import dataclass, field
from datetime import timedelta
from typing import Literal, TYPE_CHECKING
from dcs import Point
from game.ato.flightwaypointtype import FlightWaypointType
from game.theater.theatergroup import TheaterUnit
from game.utils import Distance, meters
if TYPE_CHECKING:
from game.theater import ControlPoint, MissionTarget
AltitudeReference = Literal["BARO", "RADIO"]
@dataclass
class FlightWaypoint:
name: str
waypoint_type: FlightWaypointType
x: float
y: float
alt: Distance = meters(0)
alt_type: AltitudeReference = "BARO"
control_point: ControlPoint | None = None
# TODO: Merge with pretty_name.
# Only used in the waypoint list in the flight edit page. No sense
# having three names. A short and long form is enough.
description: str = ""
targets: Sequence[MissionTarget | TheaterUnit] = field(default_factory=list)
obj_name: str = ""
pretty_name: str = ""
only_for_player: bool = False
flyover: bool = False
# The minimum amount of fuel remaining at this waypoint in pounds.
min_fuel: float | None = None
# These are set very late by the air conflict generator (part of mission
# generation). We do it late so that we don't need to propagate changes
# to waypoint times whenever the player alters the package TOT or the
# flight's offset in the UI.
tot: timedelta | None = None
departure_time: timedelta | None = None
@property
def position(self) -> Point:
return Point(self.x, self.y)
def __hash__(self) -> int:
return hash(id(self))