diff --git a/game/theater/controlpoint.py b/game/theater/controlpoint.py index b32ff97f..ec80a083 100644 --- a/game/theater/controlpoint.py +++ b/game/theater/controlpoint.py @@ -23,7 +23,10 @@ from .base import Base from .missiontarget import MissionTarget from .theatergroundobject import ( BaseDefenseGroundObject, + EwrGroundObject, + SamGroundObject, TheaterGroundObject, + VehicleGroupGroundObject, ) if TYPE_CHECKING: @@ -282,6 +285,24 @@ class ControlPoint(MissionTarget): def is_friendly(self, to_player: bool) -> bool: return self.captured == to_player + def clear_base_defenses(self) -> None: + for base_defense in self.base_defenses: + if isinstance(base_defense, EwrGroundObject): + self.preset_locations.ewrs.append(base_defense.position) + elif isinstance(base_defense, SamGroundObject): + self.preset_locations.base_air_defense.append( + base_defense.position) + elif isinstance(base_defense, VehicleGroupGroundObject): + self.preset_locations.base_garrisons.append( + base_defense.position) + else: + logging.error( + "Could not determine preset location type for " + f"{base_defense}. Assuming garrison type.") + self.preset_locations.base_garrisons.append( + base_defense.position) + self.base_defenses = [] + def capture(self, game: Game, for_player: bool) -> None: if for_player: self.captured = True @@ -293,9 +314,8 @@ class ControlPoint(MissionTarget): self.base.aircraft = {} self.base.armor = {} - # Handle cyclic dependency. + self.clear_base_defenses() from .start_generator import BaseDefenseGenerator - self.base_defenses = [] BaseDefenseGenerator(game, self).generate() def mission_types(self, for_player: bool) -> Iterator[FlightType]: diff --git a/game/theater/start_generator.py b/game/theater/start_generator.py index 35a829fb..81aac268 100644 --- a/game/theater/start_generator.py +++ b/game/theater/start_generator.py @@ -502,7 +502,8 @@ class BaseDefenseGenerator: self.control_point.base_defenses.append(g) def generate_shorad(self) -> None: - position = self.location_finder.location_for(LocationType.Garrison) + position = self.location_finder.location_for( + LocationType.BaseAirDefense) if position is None: return diff --git a/game/theater/theatergroundobject.py b/game/theater/theatergroundobject.py index c267a0eb..7f3f44a9 100644 --- a/game/theater/theatergroundobject.py +++ b/game/theater/theatergroundobject.py @@ -243,8 +243,8 @@ class BaseDefenseGroundObject(TheaterGroundObject): # TODO: Differentiate types. -# This type gets used both for AA sites (SAM, AAA, or SHORAD) but also for the -# armor garrisons at airbases. These should each be split into their own types. +# This type gets used both for AA sites (SAM, AAA, or SHORAD). These should each +# be split into their own types. class SamGroundObject(BaseDefenseGroundObject): def __init__(self, name: str, group_id: int, position: Point, control_point: ControlPoint, for_airbase: bool) -> None: diff --git a/resources/campaigns/inherent_resolve.miz b/resources/campaigns/inherent_resolve.miz index 881c28e4..c5d00d7f 100644 Binary files a/resources/campaigns/inherent_resolve.miz and b/resources/campaigns/inherent_resolve.miz differ