Fix heli spawn & farp helipad creation

cherry-pick from
ad0d3412fb09f9b5fcf7eb5d430204115aeaee99
6f8c30ec81cf70d4353f937b5c20819bb19f4f69
c88fa6d2afa745dbfbcbefd00f6b92a8fd4e4651
a53812c0fb45f111d77da274a8519c97ac0a3d7d
This commit is contained in:
RndName 2022-02-24 21:46:05 +01:00
parent a6e1dc14c3
commit 6f0119731b
No known key found for this signature in database
GPG Key ID: 5EF516FD9537F7C0
2 changed files with 34 additions and 42 deletions

View File

@ -231,7 +231,7 @@ class AircraftConflictGenerator:
laser_code_registry: LaserCodeRegistry,
unit_map: UnitMap,
air_support: AirSupport,
helipads: dict[ControlPoint, list[StaticGroup]],
helipads: dict[ControlPoint, StaticGroup],
) -> None:
self.m = mission
self.game = game
@ -576,9 +576,9 @@ class AircraftConflictGenerator:
)
try:
helipad = self.helipads[cp].pop()
except IndexError as ex:
raise RuntimeError(f"Not enough helipads available at {cp}") from ex
helipad = self.helipads[cp]
except IndexError:
raise NoParkingSlotError
group = self._generate_at_group(
name=name,
@ -589,21 +589,12 @@ class AircraftConflictGenerator:
at=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 start_type != "Cold":
group.points[0].action = PointAction.FromParkingArea
group.points[0].type = "TakeOffParkingHot"
for i in range(count - 1):
try:
helipad = self.helipads[cp].pop()
group.units[1 + i].position = Point(helipad.x, helipad.y)
group.units[1 + i].heading = helipad.units[0].heading
except IndexError as ex:
raise RuntimeError(f"Not enough helipads available at {cp}") from ex
group.units[i].position = helipad.units[i].position
group.units[i].heading = helipad.units[i].heading
return group
def _add_radio_waypoint(

View File

@ -605,49 +605,49 @@ class HelipadGenerator:
self.game = game
self.radio_registry = radio_registry
self.tacan_registry = tacan_registry
self.helipads: list[StaticGroup] = []
self.helipads: Optional[StaticGroup] = 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)
if len(self.cp.helipads) == 0:
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)
# Note: Helipad are generated as neutral object in order not to interfer with
# capture triggers
country = self.m.country(self.game.coalition_for(self.cp.captured).country_name)
name = self.cp.name + "_helipad"
sg = unitgroup.StaticGroup(self.m.next_group_id(), name)
sp = StaticPoint()
sp.position = self.cp.position
sg.add_point(sp)
for i, helipad in enumerate(self.cp.helipads):
# This is used as a trigger of the number of available pads when spawning flights
self.helipads.append(sg)
name_i = name + "_" + str(i)
logging.info("Generating helipad static : " + name_i)
pad = InvisibleFARP(unit_id=self.m.next_unit_id(), name=name_i)
pad.position = Point(helipad.x, helipad.y)
pad.heading = helipad.heading.degrees
sg.add_unit(pad)
heading = helipad.heading.degrees
name_i = self.cp.name + "_helipad" + "_" + str(i)
if self.helipads is None:
self.helipads = self.m.farp(
self.m.country(self.game.neutral_country.name),
name_i,
helipad,
farp_type="InvisibleFARP",
)
else:
# Create a new Helipad Unit
self.helipads.add_unit(InvisibleFARP(self.m.next_unit_id(), name_i))
pad = self.helipads.units[-1]
pad.position = helipad
pad.heading = heading
# Generate a FARP Ammo and Fuel stack for each pad
self.m.static_group(
country=country,
name=(name_i + "_fuel"),
_type=Fortification.FARP_Fuel_Depot,
position=pad.position.point_from_heading(helipad.heading.degrees, 35),
heading=pad.heading,
position=helipad.point_from_heading(heading, 35),
heading=heading,
)
self.m.static_group(
country=country,
name=(name_i + "_ammo"),
_type=Fortification.FARP_Ammo_Dump_Coating,
position=pad.position.point_from_heading(
helipad.heading.degrees, 35
).point_from_heading(helipad.heading.degrees + 90, 10),
heading=pad.heading,
position=helipad.point_from_heading(heading, 35).point_from_heading(
heading + 90, 10
),
heading=heading,
)
neutral_country.add_static_group(sg)
class GroundObjectsGenerator:
@ -674,7 +674,7 @@ class GroundObjectsGenerator:
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:
@ -685,7 +685,8 @@ class GroundObjectsGenerator:
self.m, cp, self.game, self.radio_registry, self.tacan_registry
)
helipad_gen.generate()
self.helipads[cp] = helipad_gen.helipads
if helipad_gen.helipads is not None:
self.helipads[cp] = helipad_gen.helipads
for ground_object in cp.ground_objects:
generator: GenericGroundObjectGenerator[Any]