Fix waypoint altitudes for helicopters.

Fixes https://github.com/Khopa/dcs_liberation/issues/234
This commit is contained in:
Dan Albert 2020-10-23 14:52:14 -07:00
parent dd4c37cde3
commit c3fca6696d
2 changed files with 23 additions and 24 deletions

View File

@ -351,9 +351,6 @@ class FlightPlanBuilder:
if not isinstance(location, FrontLine):
raise InvalidObjectiveLocation(flight.flight_type, location)
is_helo = getattr(flight.unit_type, "helicopter", False)
cap_alt = 500 if is_helo else 1000
ingress, heading, distance = Conflict.frontline_vector(
location.control_points[0], location.control_points[1],
self.game.theater
@ -362,14 +359,14 @@ class FlightPlanBuilder:
egress = ingress.point_from_heading(heading, distance)
builder = WaypointBuilder(self.game.conditions, flight, self.doctrine)
builder.ascent(flight.from_cp, is_helo)
builder.ascent(flight.from_cp)
builder.hold(self._hold_point(flight))
builder.join(self.package.waypoints.join)
builder.ingress_cas(ingress, location)
builder.cas(center, cap_alt)
builder.cas(center)
builder.egress(egress, location)
builder.split(self.package.waypoints.split)
builder.rtb(flight.from_cp, is_helo)
builder.rtb(flight.from_cp)
flight.points = builder.build()

View File

@ -22,15 +22,18 @@ class WaypointBuilder:
self.waypoints: List[FlightWaypoint] = []
self.ingress_point: Optional[FlightWaypoint] = None
@property
def is_helo(self) -> bool:
return getattr(self.flight.unit_type, "helicopter", False)
def build(self) -> List[FlightWaypoint]:
return self.waypoints
def ascent(self, departure: ControlPoint, is_helo: bool = False) -> None:
def ascent(self, departure: ControlPoint) -> None:
"""Create ascent waypoint for the given departure airfield or carrier.
Args:
departure: Departure airfield or carrier.
is_helo: True if the flight is a helicopter.
"""
heading = RunwayAssigner(self.conditions).takeoff_heading(departure)
position = departure.position.point_from_heading(
@ -40,7 +43,7 @@ class WaypointBuilder:
FlightWaypointType.ASCEND_POINT,
position.x,
position.y,
500 if is_helo else self.doctrine.pattern_altitude
500 if self.is_helo else self.doctrine.pattern_altitude
)
waypoint.name = "ASCEND"
waypoint.alt_type = "RADIO"
@ -48,14 +51,14 @@ class WaypointBuilder:
waypoint.pretty_name = "Ascend"
self.waypoints.append(waypoint)
def descent(self, arrival: ControlPoint, is_helo: bool = False) -> None:
def descent(self, arrival: ControlPoint) -> None:
"""Create descent waypoint for the given arrival airfield or carrier.
Args:
arrival: Arrival airfield or carrier.
is_helo: True if the flight is a helicopter.
"""
landing_heading = RunwayAssigner(self.conditions).landing_heading(arrival)
landing_heading = RunwayAssigner(self.conditions).landing_heading(
arrival)
heading = (landing_heading + 180) % 360
position = arrival.position.point_from_heading(
heading, nm_to_meter(5)
@ -64,7 +67,7 @@ class WaypointBuilder:
FlightWaypointType.DESCENT_POINT,
position.x,
position.y,
300 if is_helo else self.doctrine.pattern_altitude
300 if self.is_helo else self.doctrine.pattern_altitude
)
waypoint.name = "DESCEND"
waypoint.alt_type = "RADIO"
@ -96,7 +99,7 @@ class WaypointBuilder:
FlightWaypointType.LOITER,
position.x,
position.y,
self.doctrine.rendezvous_altitude
500 if self.is_helo else self.doctrine.rendezvous_altitude
)
waypoint.pretty_name = "Hold"
waypoint.description = "Wait until push time"
@ -108,7 +111,7 @@ class WaypointBuilder:
FlightWaypointType.JOIN,
position.x,
position.y,
self.doctrine.ingress_altitude
500 if self.is_helo else self.doctrine.ingress_altitude
)
waypoint.pretty_name = "Join"
waypoint.description = "Rendezvous with package"
@ -120,7 +123,7 @@ class WaypointBuilder:
FlightWaypointType.SPLIT,
position.x,
position.y,
self.doctrine.ingress_altitude
500 if self.is_helo else self.doctrine.ingress_altitude
)
waypoint.pretty_name = "Split"
waypoint.description = "Depart from package"
@ -148,7 +151,7 @@ class WaypointBuilder:
ingress_type,
position.x,
position.y,
self.doctrine.ingress_altitude
500 if self.is_helo else self.doctrine.ingress_altitude
)
waypoint.pretty_name = "INGRESS on " + objective.name
waypoint.description = "INGRESS on " + objective.name
@ -161,7 +164,7 @@ class WaypointBuilder:
FlightWaypointType.EGRESS,
position.x,
position.y,
self.doctrine.ingress_altitude
500 if self.is_helo else self.doctrine.ingress_altitude
)
waypoint.pretty_name = "EGRESS from " + target.name
waypoint.description = "EGRESS from " + target.name
@ -248,12 +251,12 @@ class WaypointBuilder:
# TODO: This seems wrong, but it's what was there before.
self.ingress_point.targets.append(location)
def cas(self, position: Point, altitude: int) -> None:
def cas(self, position: Point) -> None:
waypoint = FlightWaypoint(
FlightWaypointType.CAS,
position.x,
position.y,
altitude
500 if self.is_helo else 1000
)
waypoint.alt_type = "RADIO"
waypoint.description = "Provide CAS"
@ -308,14 +311,13 @@ class WaypointBuilder:
self.race_track_start(start, altitude)
self.race_track_end(end, altitude)
def rtb(self, arrival: ControlPoint, is_helo: bool = False) -> None:
def rtb(self, arrival: ControlPoint) -> None:
"""Creates descent ant landing waypoints for the given control point.
Args:
arrival: Arrival airfield or carrier.
is_helo: True if the flight is a helicopter.
"""
self.descent(arrival, is_helo)
self.descent(arrival)
self.land(arrival)
def escort(self, ingress: Point, target: MissionTarget,
@ -339,7 +341,7 @@ class WaypointBuilder:
FlightWaypointType.TARGET_GROUP_LOC,
target.position.x,
target.position.y,
self.doctrine.ingress_altitude
500 if self.is_helo else self.doctrine.ingress_altitude
)
waypoint.name = "TARGET"
waypoint.description = "Escort the package"