From ad0d3412fb09f9b5fcf7eb5d430204115aeaee99 Mon Sep 17 00:00:00 2001 From: RndName Date: Thu, 24 Feb 2022 23:21:17 +0100 Subject: [PATCH] Cleanup helipad creation and heli spawn --- .../aircraft/aircraftgenerator.py | 2 +- .../aircraft/flightgroupspawner.py | 25 ++++------------ game/missiongenerator/tgogenerator.py | 30 +++++++++++-------- 3 files changed, 25 insertions(+), 32 deletions(-) diff --git a/game/missiongenerator/aircraft/aircraftgenerator.py b/game/missiongenerator/aircraft/aircraftgenerator.py index 81c67f4a..9daa68cd 100644 --- a/game/missiongenerator/aircraft/aircraftgenerator.py +++ b/game/missiongenerator/aircraft/aircraftgenerator.py @@ -50,7 +50,7 @@ class AircraftGenerator: laser_code_registry: LaserCodeRegistry, unit_map: UnitMap, air_support: AirSupport, - helipads: dict[ControlPoint, list[StaticGroup]], + helipads: dict[ControlPoint, StaticGroup], ) -> None: self.mission = mission self.settings = settings diff --git a/game/missiongenerator/aircraft/flightgroupspawner.py b/game/missiongenerator/aircraft/flightgroupspawner.py index 9a54d1d5..127299da 100644 --- a/game/missiongenerator/aircraft/flightgroupspawner.py +++ b/game/missiongenerator/aircraft/flightgroupspawner.py @@ -44,7 +44,7 @@ class FlightGroupSpawner: flight: Flight, country: Country, mission: Mission, - helipads: dict[ControlPoint, list[StaticGroup]], + helipads: dict[ControlPoint, StaticGroup], ) -> None: self.flight = flight self.country = country @@ -230,30 +230,17 @@ class FlightGroupSpawner: def _generate_at_cp_helipad(self, name: str, cp: ControlPoint) -> FlyingGroup[Any]: try: - # helipad = self.helipads[cp][0] - helipad = self.helipads[cp].pop() + helipad = self.helipads[cp] except IndexError as ex: - raise NoParkingSlotError(f"Not enough helipads available at {cp}") from ex + raise NoParkingSlotError() group = self._generate_at_group(name, helipad) - # Note : A bit dirty, need better support in pydcs - group.points[0].action = PointAction.FromParkingArea - group.points[0].type = "TakeOffParking" - group.units[0].heading = helipad.units[0].heading if self.start_type is not StartType.COLD: - group.points[0].action = PointAction.FromParkingArea group.points[0].type = "TakeOffParkingHot" - - for i in range(self.flight.count - 1): - try: - helipad = self.helipads[cp].pop() - except IndexError as ex: - raise NoParkingSlotError( - f"Not enough helipads available at {cp}" - ) from ex - group.units[1 + i].position = copy.copy(helipad.position) - group.units[1 + i].heading = helipad.units[0].heading + for i in range(self.flight.count): + group.units[i].position = helipad.units[i].position + group.units[i].heading = helipad.units[i].heading return group def dcs_start_type(self) -> DcsStartType: diff --git a/game/missiongenerator/tgogenerator.py b/game/missiongenerator/tgogenerator.py index 733ebbe9..956d4976 100644 --- a/game/missiongenerator/tgogenerator.py +++ b/game/missiongenerator/tgogenerator.py @@ -36,7 +36,7 @@ from dcs.task import ( ) from dcs.translation import String from dcs.triggers import Event, TriggerOnce, TriggerStart, TriggerZone -from dcs.unit import Unit +from dcs.unit import Unit, InvisibleFARP from dcs.unitgroup import MovingGroup, ShipGroup, StaticGroup, VehicleGroup from dcs.unittype import ShipType, VehicleType from dcs.vehicles import vehicle_map @@ -524,7 +524,12 @@ class HelipadGenerator: self.game = game self.radio_registry = radio_registry self.tacan_registry = tacan_registry - self.helipads: list[StaticGroup] = [] + self.helipads = self.m.farp( + self.m.country(self.game.neutral_country.name), + self.cp.name + "_helipad", + self.cp.position, + farp_type="InvisibleFARP", + ) def generate(self) -> None: # This gets called for every control point, so we don't want to add an empty group (causes DCS mission editor to crash) @@ -532,19 +537,20 @@ class HelipadGenerator: return # Note: Helipad are generated as neutral object in order not to interfer with # capture triggers - neutral_country = self.m.country(self.game.neutral_country.name) country = self.m.country(self.game.coalition_for(self.cp.captured).country_name) + for i, helipad in enumerate(self.cp.helipads): heading = helipad.heading.degrees name_i = self.cp.name + "_helipad" + "_" + str(i) - pad = self.m.farp( - neutral_country, - name_i, - helipad, - heading=heading, - farp_type="InvisibleFARP", - ) - self.helipads.append(pad) + if i == 0: + pad = self.helipads.units[0] + else: + # Create a new Helipad Unit + pad = InvisibleFARP(self.m.terrain, unit_id=self.m.next_unit_id()) + self.helipads.add_unit(pad) + pad.name = name_i + pad.position = helipad + pad.heading = heading # Generate a FARP Ammo and Fuel stack for each pad self.m.static_group( country=country, @@ -595,7 +601,7 @@ class TgoGenerator: self.unit_map = unit_map self.icls_alloc = iter(range(1, 21)) self.runways: Dict[str, RunwayData] = {} - self.helipads: dict[ControlPoint, list[StaticGroup]] = defaultdict(list) + self.helipads: dict[ControlPoint, StaticGroup] = {} def generate(self) -> None: for cp in self.game.theater.controlpoints: