Handle additional preset location types.

Missile sites were accidentally excluded, and coastal defenses aren't
being generated yet.
This commit is contained in:
Dan Albert 2020-11-24 15:45:41 -08:00
parent 8886850c60
commit efcdbebda5
3 changed files with 37 additions and 7 deletions

View File

@ -39,14 +39,15 @@ from dcs.unitgroup import (
StaticGroup, StaticGroup,
VehicleGroup, VehicleGroup,
) )
from dcs.vehicles import AirDefence, Armor from dcs.vehicles import AirDefence, Armor, MissilesSS
from gen.flights.flight import FlightType from gen.flights.flight import FlightType
from .controlpoint import ( from .controlpoint import (
Airfield, Airfield,
Carrier, Carrier,
ControlPoint, ControlPoint,
Lha, MissionTarget, Lha,
MissionTarget,
OffMapSpawn, OffMapSpawn,
) )
from .landmap import Landmap, load_landmap, poly_contains from .landmap import Landmap, load_landmap, poly_contains
@ -92,6 +93,8 @@ class MizCampaignLoader:
STRIKE_TARGET_UNIT_TYPE = Fortification.Workshop_A.id STRIKE_TARGET_UNIT_TYPE = Fortification.Workshop_A.id
OFFSHORE_STRIKE_TARGET_UNIT_TYPE = Fortification.Oil_platform.id OFFSHORE_STRIKE_TARGET_UNIT_TYPE = Fortification.Oil_platform.id
SHIP_UNIT_TYPE = USS_Arleigh_Burke_IIa.id SHIP_UNIT_TYPE = USS_Arleigh_Burke_IIa.id
MISSILE_SITE_UNIT_TYPE = MissilesSS.SRBM_SS_1C_Scud_B_9K72_LN_9P117M.id
COASTAL_DEFENSE_UNIT_TYPE = MissilesSS.SS_N_2_Silkworm.id
# Multiple options for the required SAMs so campaign designers can more # Multiple options for the required SAMs so campaign designers can more
# easily see the coverage of their IADS. Designers focused on campaigns that # easily see the coverage of their IADS. Designers focused on campaigns that
@ -212,6 +215,18 @@ class MizCampaignLoader:
if group.units[0].type == self.OFFSHORE_STRIKE_TARGET_UNIT_TYPE: if group.units[0].type == self.OFFSHORE_STRIKE_TARGET_UNIT_TYPE:
yield group yield group
@property
def missile_sites(self) -> Iterator[VehicleGroup]:
for group in self.blue.vehicle_group:
if group.units[0].type == self.MISSILE_SITE_UNIT_TYPE:
yield group
@property
def coastal_defenses(self) -> Iterator[VehicleGroup]:
for group in self.blue.vehicle_group:
if group.units[0].type == self.COASTAL_DEFENSE_UNIT_TYPE:
yield group
@property @property
def required_sams(self) -> Iterator[VehicleGroup]: def required_sams(self) -> Iterator[VehicleGroup]:
for group in self.red.vehicle_group: for group in self.red.vehicle_group:
@ -323,6 +338,14 @@ class MizCampaignLoader:
closest, distance = self.objective_info(group) closest, distance = self.objective_info(group)
closest.preset_locations.ships.append(group.position) closest.preset_locations.ships.append(group.position)
for group in self.missile_sites:
closest, distance = self.objective_info(group)
closest.preset_locations.missile_sites.append(group.position)
for group in self.coastal_defenses:
closest, distance = self.objective_info(group)
closest.preset_locations.coastal_defenses.append(group.position)
for group in self.required_sams: for group in self.required_sams:
closest, distance = self.objective_info(group) closest, distance = self.objective_info(group)
closest.preset_locations.required_sams.append(group.position) closest.preset_locations.required_sams.append(group.position)

View File

@ -95,6 +95,9 @@ class PresetLocations:
#: Locations used by offshore strike objectives. #: Locations used by offshore strike objectives.
offshore_strike_locations: List[Point] = field(default_factory=list) offshore_strike_locations: List[Point] = field(default_factory=list)
#: Locations used by missile sites like scuds and V-2s.
missile_sites: List[Point] = field(default_factory=list)
#: Locations of SAMs which should always be spawned. #: Locations of SAMs which should always be spawned.
required_sams: List[Point] = field(default_factory=list) required_sams: List[Point] = field(default_factory=list)
@ -113,20 +116,24 @@ class PresetLocations:
The location, if found, will be claimed by the caller and not available The location, if found, will be claimed by the caller and not available
to subsequent calls. to subsequent calls.
""" """
if location_type == LocationType.Garrison:
return self._random_from(self.base_garrisons)
if location_type == LocationType.Sam:
return self._random_from(self.sams)
if location_type == LocationType.BaseAirDefense: if location_type == LocationType.BaseAirDefense:
return self._random_from(self.base_air_defense) return self._random_from(self.base_air_defense)
if location_type == LocationType.Coastal:
return self._random_from(self.coastal_defenses)
if location_type == LocationType.Ewr: if location_type == LocationType.Ewr:
return self._random_from(self.ewrs) return self._random_from(self.ewrs)
if location_type == LocationType.Shorad: if location_type == LocationType.Garrison:
return self._random_from(self.base_garrisons) return self._random_from(self.base_garrisons)
if location_type == LocationType.MissileSite:
return self._random_from(self.missile_sites)
if location_type == LocationType.OffshoreStrikeTarget: if location_type == LocationType.OffshoreStrikeTarget:
return self._random_from(self.offshore_strike_locations) return self._random_from(self.offshore_strike_locations)
if location_type == LocationType.Sam:
return self._random_from(self.sams)
if location_type == LocationType.Ship: if location_type == LocationType.Ship:
return self._random_from(self.ships) return self._random_from(self.ships)
if location_type == LocationType.Shorad:
return self._random_from(self.base_garrisons)
if location_type == LocationType.StrikeTarget: if location_type == LocationType.StrikeTarget:
return self._random_from(self.strike_locations) return self._random_from(self.strike_locations)
logging.error(f"Unknown location type: {location_type}") logging.error(f"Unknown location type: {location_type}")