Possible to add additional helipad to any control point in campaign file. (WIP)

This commit is contained in:
Khopa 2021-04-14 00:00:25 +02:00
parent cce736bc16
commit 7ce05762f5
4 changed files with 64 additions and 4 deletions

View File

@ -94,6 +94,7 @@ class MizCampaignLoader:
FRONT_LINE_UNIT_TYPE = Armor.APC_M113.id FRONT_LINE_UNIT_TYPE = Armor.APC_M113.id
FOB_UNIT_TYPE = Unarmed.CP_SKP_11_ATC_Mobile_Command_Post.id FOB_UNIT_TYPE = Unarmed.CP_SKP_11_ATC_Mobile_Command_Post.id
FARP_HELIPAD = "SINGLE_HELIPAD"
EWR_UNIT_TYPE = AirDefence.EWR_55G6.id EWR_UNIT_TYPE = AirDefence.EWR_55G6.id
SAM_UNIT_TYPE = AirDefence.SAM_SA_10_S_300PS_SR_64H6E.id SAM_UNIT_TYPE = AirDefence.SAM_SA_10_S_300PS_SR_64H6E.id
@ -246,6 +247,12 @@ class MizCampaignLoader:
if group.units[0].type in self.REQUIRED_MEDIUM_RANGE_SAM_UNIT_TYPES: if group.units[0].type in self.REQUIRED_MEDIUM_RANGE_SAM_UNIT_TYPES:
yield group yield group
@property
def helipads(self) -> Iterator[StaticGroup]:
for group in self.blue.static_group:
if group.units[0].type == self.FARP_HELIPAD:
yield group
@cached_property @cached_property
def control_points(self) -> Dict[int, ControlPoint]: def control_points(self) -> Dict[int, ControlPoint]:
control_points = {} control_points = {}
@ -389,6 +396,12 @@ class MizCampaignLoader:
PointWithHeading.from_point(group.position, group.units[0].heading) PointWithHeading.from_point(group.position, group.units[0].heading)
) )
for group in self.helipads:
closest, distance = self.objective_info(group)
closest.helipads.append(
PointWithHeading.from_point(group.position, group.units[0].heading)
)
def populate_theater(self) -> None: def populate_theater(self) -> None:
for control_point in self.control_points.values(): for control_point in self.control_points.values():
self.theater.add_controlpoint(control_point) self.theater.add_controlpoint(control_point)

View File

@ -250,6 +250,7 @@ class ControlPoint(MissionTarget, ABC):
self.connected_objectives: List[TheaterGroundObject] = [] self.connected_objectives: List[TheaterGroundObject] = []
self.base_defenses: List[BaseDefenseGroundObject] = [] self.base_defenses: List[BaseDefenseGroundObject] = []
self.preset_locations = PresetLocations() self.preset_locations = PresetLocations()
self.helipads: List[PointWithHeading] = []
# TODO: Should be Airbase specific. # TODO: Should be Airbase specific.
self.size = size self.size = size

View File

@ -11,9 +11,10 @@ import logging
import random import random
from typing import Dict, Iterator, Optional, TYPE_CHECKING, Type, List from typing import Dict, Iterator, Optional, TYPE_CHECKING, Type, List
from dcs import Mission, Point from dcs import Mission, Point, unitgroup
from dcs.country import Country from dcs.country import Country
from dcs.statics import fortification_map, warehouse_map from dcs.point import StaticPoint
from dcs.statics import fortification_map, warehouse_map, Warehouse
from dcs.task import ( from dcs.task import (
ActivateBeaconCommand, ActivateBeaconCommand,
ActivateICLSCommand, ActivateICLSCommand,
@ -21,7 +22,7 @@ from dcs.task import (
OptAlarmState, OptAlarmState,
FireAtPoint, FireAtPoint,
) )
from dcs.unit import Ship, Unit, Vehicle from dcs.unit import Ship, Unit, Vehicle, SingleHeliPad, Static
from dcs.unitgroup import Group, ShipGroup, StaticGroup, VehicleGroup from dcs.unitgroup import Group, ShipGroup, StaticGroup, VehicleGroup
from dcs.unittype import StaticType, UnitType from dcs.unittype import StaticType, UnitType
from dcs.vehicles import vehicle_map from dcs.vehicles import vehicle_map
@ -47,7 +48,6 @@ from .tacan import TacanBand, TacanChannel, TacanRegistry
if TYPE_CHECKING: if TYPE_CHECKING:
from game import Game from game import Game
FARP_FRONTLINE_DISTANCE = 10000 FARP_FRONTLINE_DISTANCE = 10000
AA_CP_MIN_DISTANCE = 40000 AA_CP_MIN_DISTANCE = 40000
@ -477,6 +477,48 @@ class ShipObjectGenerator(GenericGroundObjectGenerator):
self._register_unit_group(group_def, group) self._register_unit_group(group_def, group)
class HelipadGenerator:
"""
Generates helipads for given control point
"""
def __init__(
self,
mission: Mission,
cp: ControlPoint,
game: Game,
radio_registry: RadioRegistry,
tacan_registry: TacanRegistry,
):
self.m = mission
self.cp = cp
self.game = game
self.radio_registry = radio_registry
self.tacan_registry = tacan_registry
def generate(self) -> None:
if self.cp.captured:
country_name = self.game.player_country
else:
country_name = self.game.enemy_country
country = self.m.country(country_name)
for i, helipad in enumerate(self.cp.helipads):
name = self.cp.name + "_helipad_" + str(i)
logging.info("Generating helipad : " + name)
pad = SingleHeliPad(name=self.m.string(name + "_unit"))
pad.position = Point(helipad.x, helipad.y)
pad.heading = helipad.heading
# pad.heliport_frequency = self.radio_registry.alloc_uhf() TODO : alloc radio & callsign
sg = unitgroup.StaticGroup(self.m.next_group_id(), self.m.string(name))
sg.add_unit(pad)
sp = StaticPoint()
sp.position = pad.position
sg.add_point(sp)
country.add_static_group(sg)
class GroundObjectsGenerator: class GroundObjectsGenerator:
"""Creates DCS groups and statics for the theater during mission generation. """Creates DCS groups and statics for the theater during mission generation.
@ -510,6 +552,10 @@ class GroundObjectsGenerator:
country_name = self.game.enemy_country country_name = self.game.enemy_country
country = self.m.country(country_name) country = self.m.country(country_name)
HelipadGenerator(
self.m, cp, self.game, self.radio_registry, self.tacan_registry
).generate()
for ground_object in cp.ground_objects: for ground_object in cp.ground_objects:
if isinstance(ground_object, BuildingGroundObject): if isinstance(ground_object, BuildingGroundObject):
generator = BuildingSiteGenerator( generator = BuildingSiteGenerator(