From e80851b0a11f231c55fed4c7f29d58508168e9d4 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Mon, 24 Jan 2022 17:36:15 -0800 Subject: [PATCH] Impose minimum altitude for mid-mission spawns. We had this for the old style in-flight spawns, but not for mid-mission spawns. Aircraft that were spawning soon after takeoff could potentially be close to (or under) the ground, causing them to "crash" at game start. The altitude is different here than for the old style in-flight spawns to try to get closer to the intended spawn location. Fixes https://github.com/dcs-liberation/dcs_liberation/issues/1941 --- .../aircraft/flightgroupspawner.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/game/missiongenerator/aircraft/flightgroupspawner.py b/game/missiongenerator/aircraft/flightgroupspawner.py index 68ae8d27..075e9c77 100644 --- a/game/missiongenerator/aircraft/flightgroupspawner.py +++ b/game/missiongenerator/aircraft/flightgroupspawner.py @@ -15,13 +15,22 @@ from game.ato import Flight from game.ato.flightstate import InFlight from game.ato.starttype import StartType from game.theater import Airfield, ControlPoint, Fob, NavalControlPoint, OffMapSpawn -from game.utils import meters +from game.utils import feet, meters from gen.flights.traveltime import GroundSpeed from gen.naming import namegen WARM_START_HELI_ALT = meters(500) WARM_START_ALTITUDE = meters(3000) +# In-flight spawns are MSL for the first waypoint (this can maybe be changed to AGL, but +# AGL waypoints have different piloting behavior, so we need to check whether that's +# safe to do first), so spawn them high enough that they're unlikely to be near (or +# under) the ground, or any nearby obstacles. The highest airfield in DCS is Kerman in +# PG at 5700ft. This could still be too low if there are tall obstacles near the +# airfield, but the lowest we can push this the better to avoid spawning helicopters +# well above the altitude for WP1. +MINIMUM_MID_MISSION_SPAWN_ALTITUDE = feet(6000) + RTB_ALTITUDE = meters(800) RTB_DISTANCE = 5000 HELI_ALT = 500 @@ -131,6 +140,13 @@ class FlightGroupSpawner: pos = self.flight.state.estimate_position() pos += Point(random.randint(100, 1000), random.randint(100, 1000)) alt, alt_type = self.flight.state.estimate_altitude() + + # We don't know where the ground is, so just make sure that any aircraft + # spawning at an MSL altitude is spawned at some minimum altitude. + # https://github.com/dcs-liberation/dcs_liberation/issues/1941 + if alt_type == "BARO" and alt < MINIMUM_MID_MISSION_SPAWN_ALTITUDE: + alt = MINIMUM_MID_MISSION_SPAWN_ALTITUDE + group = self.mission.flight_group( country=self.country, name=name,