mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Add distance and ground speed to the kneeboard.
This commit is contained in:
parent
1c4f255c7f
commit
eb69d01067
@ -1,9 +1,11 @@
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Dict, Iterable, Optional
|
from typing import Dict, Iterable, List, Optional
|
||||||
|
|
||||||
|
from dcs.mapping import Point
|
||||||
|
from dcs.point import MovingPoint, PointAction
|
||||||
|
from dcs.unittype import UnitType
|
||||||
|
|
||||||
from game import db
|
from game import db
|
||||||
from dcs.unittype import UnitType
|
|
||||||
from dcs.point import MovingPoint, PointAction
|
|
||||||
from theater.controlpoint import ControlPoint, MissionTarget
|
from theater.controlpoint import ControlPoint, MissionTarget
|
||||||
|
|
||||||
|
|
||||||
@ -98,11 +100,15 @@ class FlightWaypoint:
|
|||||||
self.tot: Optional[int] = None
|
self.tot: Optional[int] = None
|
||||||
self.departure_time: Optional[int] = None
|
self.departure_time: Optional[int] = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def position(self) -> Point:
|
||||||
|
return Point(self.x, self.y)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_pydcs(cls, point: MovingPoint,
|
def from_pydcs(cls, point: MovingPoint,
|
||||||
from_cp: ControlPoint) -> "FlightWaypoint":
|
from_cp: ControlPoint) -> "FlightWaypoint":
|
||||||
waypoint = FlightWaypoint(point.position.x, point.position.y,
|
waypoint = FlightWaypoint(FlightWaypointType.NAV, point.position.x,
|
||||||
point.alt)
|
point.position.y, point.alt)
|
||||||
waypoint.alt_type = point.alt_type
|
waypoint.alt_type = point.alt_type
|
||||||
# Other actions exist... but none of them *should* be the first
|
# Other actions exist... but none of them *should* be the first
|
||||||
# waypoint for a flight.
|
# waypoint for a flight.
|
||||||
@ -159,14 +165,3 @@ class Flight:
|
|||||||
if waypoint.waypoint_type in types:
|
if waypoint.waypoint_type in types:
|
||||||
return waypoint
|
return waypoint
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
# Test
|
|
||||||
if __name__ == '__main__':
|
|
||||||
from dcs.planes import A_10C
|
|
||||||
from theater import ControlPoint, Point, List
|
|
||||||
|
|
||||||
from_cp = ControlPoint(0, "AA", Point(0, 0), Point(0, 0), [], 0, 0)
|
|
||||||
f = Flight(A_10C(), 4, from_cp, FlightType.CAS, "Cold")
|
|
||||||
f.scheduled_in = 50
|
|
||||||
print(f)
|
|
||||||
|
|||||||
@ -29,16 +29,19 @@ from pathlib import Path
|
|||||||
from typing import Dict, List, Optional, Tuple
|
from typing import Dict, List, Optional, Tuple
|
||||||
|
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
|
from dcs.mapping import Point
|
||||||
from dcs.mission import Mission
|
from dcs.mission import Mission
|
||||||
from dcs.unittype import FlyingType
|
from dcs.unittype import FlyingType
|
||||||
from tabulate import tabulate
|
from tabulate import tabulate
|
||||||
|
|
||||||
|
from game.utils import meter_to_nm
|
||||||
from . import units
|
from . import units
|
||||||
from .aircraft import AIRCRAFT_DATA, FlightData
|
from .aircraft import AIRCRAFT_DATA, FlightData
|
||||||
from .airfields import RunwayData
|
from .airfields import RunwayData
|
||||||
from .airsupportgen import AwacsInfo, TankerInfo
|
from .airsupportgen import AwacsInfo, TankerInfo
|
||||||
from .briefinggen import CommInfo, JtacInfo, MissionInfoGenerator
|
from .briefinggen import CommInfo, JtacInfo, MissionInfoGenerator
|
||||||
from .flights.flight import FlightWaypoint, FlightWaypointType
|
from .flights.flight import FlightWaypoint, FlightWaypointType
|
||||||
|
from .flights.traveltime import TravelTime
|
||||||
from .radios import RadioFrequency
|
from .radios import RadioFrequency
|
||||||
|
|
||||||
|
|
||||||
@ -111,6 +114,7 @@ class FlightPlanBuilder:
|
|||||||
self.start_time = start_time
|
self.start_time = start_time
|
||||||
self.rows: List[List[str]] = []
|
self.rows: List[List[str]] = []
|
||||||
self.target_points: List[NumberedWaypoint] = []
|
self.target_points: List[NumberedWaypoint] = []
|
||||||
|
self.last_waypoint: Optional[FlightWaypoint] = None
|
||||||
|
|
||||||
def add_waypoint(self, waypoint_num: int, waypoint: FlightWaypoint) -> None:
|
def add_waypoint(self, waypoint_num: int, waypoint: FlightWaypoint) -> None:
|
||||||
if waypoint.waypoint_type == FlightWaypointType.TARGET_POINT:
|
if waypoint.waypoint_type == FlightWaypointType.TARGET_POINT:
|
||||||
@ -136,23 +140,59 @@ class FlightPlanBuilder:
|
|||||||
f"{first_waypoint_num}-{last_waypoint_num}",
|
f"{first_waypoint_num}-{last_waypoint_num}",
|
||||||
"Target points",
|
"Target points",
|
||||||
"0",
|
"0",
|
||||||
|
self._waypoint_distance(self.target_points[0].waypoint),
|
||||||
|
self._ground_speed(self.target_points[0].waypoint),
|
||||||
self._format_time(self.target_points[0].waypoint.tot),
|
self._format_time(self.target_points[0].waypoint.tot),
|
||||||
|
self._format_time(self.target_points[0].waypoint.departure_time),
|
||||||
])
|
])
|
||||||
|
self.last_waypoint = self.target_points[-1].waypoint
|
||||||
|
|
||||||
def add_waypoint_row(self, waypoint: NumberedWaypoint) -> None:
|
def add_waypoint_row(self, waypoint: NumberedWaypoint) -> None:
|
||||||
self.rows.append([
|
self.rows.append([
|
||||||
str(waypoint.number),
|
str(waypoint.number),
|
||||||
waypoint.waypoint.pretty_name,
|
waypoint.waypoint.pretty_name,
|
||||||
str(int(units.meters_to_feet(waypoint.waypoint.alt))),
|
str(int(units.meters_to_feet(waypoint.waypoint.alt))),
|
||||||
|
self._waypoint_distance(waypoint.waypoint),
|
||||||
|
self._ground_speed(waypoint.waypoint),
|
||||||
self._format_time(waypoint.waypoint.tot),
|
self._format_time(waypoint.waypoint.tot),
|
||||||
self._format_time(waypoint.waypoint.departure_time),
|
self._format_time(waypoint.waypoint.departure_time),
|
||||||
])
|
])
|
||||||
|
self.last_waypoint = waypoint.waypoint
|
||||||
|
|
||||||
def _format_time(self, time: Optional[int]) -> str:
|
def _format_time(self, time: Optional[int]) -> str:
|
||||||
if time is None:
|
if time is None:
|
||||||
return ""
|
return ""
|
||||||
local_time = self.start_time + datetime.timedelta(seconds=time)
|
local_time = self.start_time + datetime.timedelta(seconds=time)
|
||||||
return local_time.strftime(f"%H:%M:%S LOCAL")
|
return local_time.strftime(f"%H:%M:%S")
|
||||||
|
|
||||||
|
def _waypoint_distance(self, waypoint: FlightWaypoint) -> str:
|
||||||
|
if self.last_waypoint is None:
|
||||||
|
return "-"
|
||||||
|
|
||||||
|
distance = meter_to_nm(self.last_waypoint.position.distance_to_point(
|
||||||
|
waypoint.position
|
||||||
|
))
|
||||||
|
return f"{distance} NM"
|
||||||
|
|
||||||
|
def _ground_speed(self, waypoint: FlightWaypoint) -> str:
|
||||||
|
if self.last_waypoint is None:
|
||||||
|
return "-"
|
||||||
|
|
||||||
|
if waypoint.tot is None:
|
||||||
|
return "-"
|
||||||
|
|
||||||
|
if self.last_waypoint.departure_time is not None:
|
||||||
|
last_time = self.last_waypoint.departure_time
|
||||||
|
elif self.last_waypoint.tot is not None:
|
||||||
|
last_time = self.last_waypoint.tot
|
||||||
|
else:
|
||||||
|
return "-"
|
||||||
|
|
||||||
|
distance = meter_to_nm(self.last_waypoint.position.distance_to_point(
|
||||||
|
waypoint.position
|
||||||
|
))
|
||||||
|
duration = (waypoint.tot - last_time) / 3600
|
||||||
|
return f"{int(distance / duration)} kt"
|
||||||
|
|
||||||
def build(self) -> List[List[str]]:
|
def build(self) -> List[List[str]]:
|
||||||
return self.rows
|
return self.rows
|
||||||
@ -187,8 +227,9 @@ class BriefingPage(KneeboardPage):
|
|||||||
flight_plan_builder = FlightPlanBuilder(self.start_time)
|
flight_plan_builder = FlightPlanBuilder(self.start_time)
|
||||||
for num, waypoint in enumerate(self.flight.waypoints):
|
for num, waypoint in enumerate(self.flight.waypoints):
|
||||||
flight_plan_builder.add_waypoint(num, waypoint)
|
flight_plan_builder.add_waypoint(num, waypoint)
|
||||||
writer.table(flight_plan_builder.build(),
|
writer.table(flight_plan_builder.build(), headers=[
|
||||||
headers=["#", "Action", "Alt", "Time", "Departure"])
|
"#", "Action", "Alt", "Dist", "GSPD", "Time", "Departure"
|
||||||
|
])
|
||||||
|
|
||||||
writer.heading("Comm Ladder")
|
writer.heading("Comm Ladder")
|
||||||
comms = []
|
comms = []
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user