From 801e9efe8c2ded7802af45da30ccfe72f038bf19 Mon Sep 17 00:00:00 2001 From: Raffson Date: Sun, 5 Feb 2023 18:10:07 +0100 Subject: [PATCH] Fix heli spawn/landing at FOB/FARP Fixes https://github.com/dcs-liberation/dcs_liberation/issues/2719. (cherry picked from commit 34de855b8f889b72406c101d0cea385988e24bf9) (cherry picked from commit b41ef0ab13fad0969eef321f71377ae6eb800d36) --- changelog.md | 1 + .../missiongenerator/aircraft/aircraftgenerator.py | 9 +++++++++ .../aircraft/flightgroupspawner.py | 14 ++++++++++---- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/changelog.md b/changelog.md index 6277b355..5f2cdc5e 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,7 @@ * **[Data]** Fixed unit ID for the KS-19 AAA. KS-19 would not previously generate correctly in missions. A new game is required for this fix to take effect. * **[Flight Planning]** Automatic flight planning will no longer accidentally plan a recovery tanker instead of a theater refueling package. This fixes a potential crash during mission generation when opfor plans a refueling task at a sunk carrier. You'll need to skip the current turn to force opfor to replan their flights to get the fix. * **[Mission Generation]** Using heliports (airports without any runways) will no longer cause mission generation to fail. +* **[Mission Generation]** Prevent helicopters from spawning into collisions at FARPs when more than one flight uses the same FARP. # 6.1.0 diff --git a/game/missiongenerator/aircraft/aircraftgenerator.py b/game/missiongenerator/aircraft/aircraftgenerator.py index 72a9aeb6..fcbc5121 100644 --- a/game/missiongenerator/aircraft/aircraftgenerator.py +++ b/game/missiongenerator/aircraft/aircraftgenerator.py @@ -26,6 +26,7 @@ from game.settings import Settings from game.theater.controlpoint import ( Airfield, ControlPoint, + Fob, ) from game.unitmap import UnitMap from .aircraftpainter import AircraftPainter @@ -180,4 +181,12 @@ class AircraftGenerator: self.unit_map, ).configure() ) + + wpt = group.waypoint("LANDING") + if flight.is_helo and isinstance(flight.arrival, Fob) and wpt: + hpad = self.helipads[flight.arrival].units.pop(0) + wpt.helipad_id = hpad.id + wpt.link_unit = hpad.id + self.helipads[flight.arrival].units.append(hpad) + return group diff --git a/game/missiongenerator/aircraft/flightgroupspawner.py b/game/missiongenerator/aircraft/flightgroupspawner.py index aa124066..33855bf0 100644 --- a/game/missiongenerator/aircraft/flightgroupspawner.py +++ b/game/missiongenerator/aircraft/flightgroupspawner.py @@ -230,16 +230,22 @@ class FlightGroupSpawner: def _generate_at_cp_helipad(self, name: str, cp: ControlPoint) -> FlyingGroup[Any]: try: helipad = self.helipads[cp] - except IndexError as ex: + except IndexError: raise NoParkingSlotError() group = self._generate_at_group(name, helipad) - if self.start_type is not StartType.COLD: + if self.start_type is StartType.WARM: group.points[0].type = "TakeOffParkingHot" + hpad = helipad.units[0] for i in range(self.flight.count): - group.units[i].position = helipad.units[i].position - group.units[i].heading = helipad.units[i].heading + group.units[i].position = hpad.position + group.units[i].heading = hpad.heading + # pydcs has just `parking_id = None`, so mypy thinks str is invalid. Ought + # to fix pydcs, but that's not the kind of change we want to pull into the + # 6.1 branch, and frankly we should probably just improve pydcs's handling + # of FARPs instead. + group.units[i].parking_id = str(i + 1) # type: ignore return group def dcs_start_type(self) -> DcsStartType: