Avoid crash for custom/empty flight plans.

Fixes https://github.com/Khopa/dcs_liberation/issues/210
This commit is contained in:
Dan Albert 2020-10-17 14:10:36 -07:00
parent 002f55dc04
commit cace523aa8
2 changed files with 13 additions and 4 deletions

View File

@ -103,8 +103,8 @@ class FlightPlanBuilder:
logging.error(
"Troop transport flight plan generation not implemented"
)
except InvalidObjectiveLocation as ex:
logging.error(f"Could not create flight plan: {ex}")
except InvalidObjectiveLocation:
logging.exception(f"Could not create flight plan")
def regenerate_package_waypoints(self) -> None:
ingress_point = self._ingress_point()

View File

@ -42,8 +42,17 @@ class GroundSpeed:
for flight in package.flights:
waypoint = flight.waypoint_with_type(IP_TYPES)
if waypoint is None:
logging.error(f"Could not find ingress point for {flight}")
continue
logging.error(f"Could not find ingress point for {flight}.")
if flight.points:
logging.warning(
"Using first waypoint for mission altitude.")
waypoint = flight.points[0]
else:
logging.warning(
"Flight has no waypoints. Assuming mission altitude "
"of 25000 feet.")
waypoint = FlightWaypoint(FlightWaypointType.NAV, 0, 0,
25000)
speeds.add(GroundSpeed.for_flight(flight, waypoint.alt))
return min(speeds)