Cleanup helipad creation and heli spawn

This commit is contained in:
RndName 2022-02-24 23:21:17 +01:00
parent 6f8c30ec81
commit ad0d3412fb
No known key found for this signature in database
GPG Key ID: 5EF516FD9537F7C0
3 changed files with 25 additions and 32 deletions

View File

@ -50,7 +50,7 @@ class AircraftGenerator:
laser_code_registry: LaserCodeRegistry, laser_code_registry: LaserCodeRegistry,
unit_map: UnitMap, unit_map: UnitMap,
air_support: AirSupport, air_support: AirSupport,
helipads: dict[ControlPoint, list[StaticGroup]], helipads: dict[ControlPoint, StaticGroup],
) -> None: ) -> None:
self.mission = mission self.mission = mission
self.settings = settings self.settings = settings

View File

@ -44,7 +44,7 @@ class FlightGroupSpawner:
flight: Flight, flight: Flight,
country: Country, country: Country,
mission: Mission, mission: Mission,
helipads: dict[ControlPoint, list[StaticGroup]], helipads: dict[ControlPoint, StaticGroup],
) -> None: ) -> None:
self.flight = flight self.flight = flight
self.country = country self.country = country
@ -230,30 +230,17 @@ class FlightGroupSpawner:
def _generate_at_cp_helipad(self, name: str, cp: ControlPoint) -> FlyingGroup[Any]: def _generate_at_cp_helipad(self, name: str, cp: ControlPoint) -> FlyingGroup[Any]:
try: try:
# helipad = self.helipads[cp][0] helipad = self.helipads[cp]
helipad = self.helipads[cp].pop()
except IndexError as ex: except IndexError as ex:
raise NoParkingSlotError(f"Not enough helipads available at {cp}") from ex raise NoParkingSlotError()
group = self._generate_at_group(name, helipad) 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: if self.start_type is not StartType.COLD:
group.points[0].action = PointAction.FromParkingArea
group.points[0].type = "TakeOffParkingHot" group.points[0].type = "TakeOffParkingHot"
for i in range(self.flight.count):
for i in range(self.flight.count - 1): group.units[i].position = helipad.units[i].position
try: group.units[i].heading = helipad.units[i].heading
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
return group return group
def dcs_start_type(self) -> DcsStartType: def dcs_start_type(self) -> DcsStartType:

View File

@ -36,7 +36,7 @@ from dcs.task import (
) )
from dcs.translation import String from dcs.translation import String
from dcs.triggers import Event, TriggerOnce, TriggerStart, TriggerZone 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.unitgroup import MovingGroup, ShipGroup, StaticGroup, VehicleGroup
from dcs.unittype import ShipType, VehicleType from dcs.unittype import ShipType, VehicleType
from dcs.vehicles import vehicle_map from dcs.vehicles import vehicle_map
@ -524,7 +524,12 @@ class HelipadGenerator:
self.game = game self.game = game
self.radio_registry = radio_registry self.radio_registry = radio_registry
self.tacan_registry = tacan_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: 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) # 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 return
# Note: Helipad are generated as neutral object in order not to interfer with # Note: Helipad are generated as neutral object in order not to interfer with
# capture triggers # 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) country = self.m.country(self.game.coalition_for(self.cp.captured).country_name)
for i, helipad in enumerate(self.cp.helipads): for i, helipad in enumerate(self.cp.helipads):
heading = helipad.heading.degrees heading = helipad.heading.degrees
name_i = self.cp.name + "_helipad" + "_" + str(i) name_i = self.cp.name + "_helipad" + "_" + str(i)
pad = self.m.farp( if i == 0:
neutral_country, pad = self.helipads.units[0]
name_i, else:
helipad, # Create a new Helipad Unit
heading=heading, pad = InvisibleFARP(self.m.terrain, unit_id=self.m.next_unit_id())
farp_type="InvisibleFARP", self.helipads.add_unit(pad)
) pad.name = name_i
self.helipads.append(pad) pad.position = helipad
pad.heading = heading
# Generate a FARP Ammo and Fuel stack for each pad # Generate a FARP Ammo and Fuel stack for each pad
self.m.static_group( self.m.static_group(
country=country, country=country,
@ -595,7 +601,7 @@ class TgoGenerator:
self.unit_map = unit_map self.unit_map = unit_map
self.icls_alloc = iter(range(1, 21)) self.icls_alloc = iter(range(1, 21))
self.runways: Dict[str, RunwayData] = {} self.runways: Dict[str, RunwayData] = {}
self.helipads: dict[ControlPoint, list[StaticGroup]] = defaultdict(list) self.helipads: dict[ControlPoint, StaticGroup] = {}
def generate(self) -> None: def generate(self) -> None:
for cp in self.game.theater.controlpoints: for cp in self.game.theater.controlpoints: