Track theater in ControlPoint.

Simplifies finding the owning theater of a control point. Not used yet.
This commit is contained in:
Dan Albert 2022-08-21 15:18:52 -07:00
parent 6519f48149
commit 6bbe583e82
3 changed files with 54 additions and 22 deletions

View File

View File

@ -108,9 +108,8 @@ class MizCampaignLoader:
if self.mission.country(self.RED_COUNTRY.name) is None: if self.mission.country(self.RED_COUNTRY.name) is None:
self.mission.coalition["red"].add_country(self.RED_COUNTRY) self.mission.coalition["red"].add_country(self.RED_COUNTRY)
@staticmethod def control_point_from_airport(self, airport: Airport) -> ControlPoint:
def control_point_from_airport(airport: Airport) -> ControlPoint: cp = Airfield(airport, self.theater, starts_blue=airport.is_blue())
cp = Airfield(airport, starts_blue=airport.is_blue())
# Use the unlimited aircraft option to determine if an airfield should # Use the unlimited aircraft option to determine if an airfield should
# be owned by the player when the campaign is "inverted". # be owned by the player when the campaign is "inverted".
@ -257,20 +256,26 @@ class MizCampaignLoader:
for blue in (False, True): for blue in (False, True):
for group in self.off_map_spawns(blue): for group in self.off_map_spawns(blue):
control_point = OffMapSpawn( control_point = OffMapSpawn(
str(group.name), group.position, starts_blue=blue str(group.name), group.position, self.theater, starts_blue=blue
) )
control_point.captured_invert = group.late_activation control_point.captured_invert = group.late_activation
control_points[control_point.id] = control_point control_points[control_point.id] = control_point
for ship in self.carriers(blue): for ship in self.carriers(blue):
control_point = Carrier(ship.name, ship.position, starts_blue=blue) control_point = Carrier(
ship.name, ship.position, self.theater, starts_blue=blue
)
control_point.captured_invert = ship.late_activation control_point.captured_invert = ship.late_activation
control_points[control_point.id] = control_point control_points[control_point.id] = control_point
for ship in self.lhas(blue): for ship in self.lhas(blue):
control_point = Lha(ship.name, ship.position, starts_blue=blue) control_point = Lha(
ship.name, ship.position, self.theater, starts_blue=blue
)
control_point.captured_invert = ship.late_activation control_point.captured_invert = ship.late_activation
control_points[control_point.id] = control_point control_points[control_point.id] = control_point
for fob in self.fobs(blue): for fob in self.fobs(blue):
control_point = Fob(str(fob.name), fob.position, starts_blue=blue) control_point = Fob(
str(fob.name), fob.position, self.theater, starts_blue=blue
)
control_point.captured_invert = fob.late_activation control_point.captured_invert = fob.late_activation
control_points[control_point.id] = control_point control_points[control_point.id] = control_point

View File

@ -26,21 +26,21 @@ from typing import (
from uuid import UUID from uuid import UUID
from dcs.mapping import Point from dcs.mapping import Point
from dcs.terrain.terrain import Airport, ParkingSlot
from dcs.unitgroup import ShipGroup, StaticGroup
from dcs.unittype import ShipType
from dcs.ships import ( from dcs.ships import (
CVN_71, CVN_71,
CVN_72, CVN_72,
CVN_73, CVN_73,
CVN_75, CVN_75,
CV_1143_5, CV_1143_5,
KUZNECOW,
Stennis,
Forrestal, Forrestal,
KUZNECOW,
LHA_Tarawa, LHA_Tarawa,
Stennis,
Type_071, Type_071,
) )
from dcs.terrain.terrain import Airport, ParkingSlot
from dcs.unitgroup import ShipGroup, StaticGroup
from dcs.unittype import ShipType
from game.ato.closestairfields import ObjectiveDistanceCache from game.ato.closestairfields import ObjectiveDistanceCache
from game.ground_forces.combat_stance import CombatStance from game.ground_forces.combat_stance import CombatStance
@ -56,8 +56,8 @@ from game.sidc import (
Status, Status,
SymbolSet, SymbolSet,
) )
from game.utils import Distance, Heading, meters
from game.theater.presetlocation import PresetLocation from game.theater.presetlocation import PresetLocation
from game.utils import Distance, Heading, meters
from .base import Base from .base import Base
from .frontline import FrontLine from .frontline import FrontLine
from .missiontarget import MissionTarget from .missiontarget import MissionTarget
@ -320,6 +320,7 @@ class ControlPoint(MissionTarget, SidcDescribable, ABC):
name: str, name: str,
position: Point, position: Point,
at: StartingPosition, at: StartingPosition,
theater: ConflictTheater,
starts_blue: bool, starts_blue: bool,
cptype: ControlPointType = ControlPointType.AIRBASE, cptype: ControlPointType = ControlPointType.AIRBASE,
) -> None: ) -> None:
@ -327,6 +328,7 @@ class ControlPoint(MissionTarget, SidcDescribable, ABC):
self.id = uuid.uuid4() self.id = uuid.uuid4()
self.full_name = name self.full_name = name
self.at = at self.at = at
self.theater = theater
self.starts_blue = starts_blue self.starts_blue = starts_blue
self.connected_objectives: List[TheaterGroundObject] = [] self.connected_objectives: List[TheaterGroundObject] = []
self.preset_locations = PresetLocations() self.preset_locations = PresetLocations()
@ -1040,11 +1042,14 @@ class ControlPoint(MissionTarget, SidcDescribable, ABC):
class Airfield(ControlPoint): class Airfield(ControlPoint):
def __init__(self, airport: Airport, starts_blue: bool) -> None: def __init__(
self, airport: Airport, theater: ConflictTheater, starts_blue: bool
) -> None:
super().__init__( super().__init__(
airport.name, airport.name,
airport.position, airport.position,
airport, airport,
theater,
starts_blue, starts_blue,
cptype=ControlPointType.AIRBASE, cptype=ControlPointType.AIRBASE,
) )
@ -1237,9 +1242,16 @@ class NavalControlPoint(ControlPoint, ABC):
class Carrier(NavalControlPoint): class Carrier(NavalControlPoint):
def __init__(self, name: str, at: Point, starts_blue: bool): def __init__(
self, name: str, at: Point, theater: ConflictTheater, starts_blue: bool
):
super().__init__( super().__init__(
name, at, at, starts_blue, cptype=ControlPointType.AIRCRAFT_CARRIER_GROUP name,
at,
at,
theater,
starts_blue,
cptype=ControlPointType.AIRCRAFT_CARRIER_GROUP,
) )
@property @property
@ -1276,8 +1288,12 @@ class Carrier(NavalControlPoint):
class Lha(NavalControlPoint): class Lha(NavalControlPoint):
def __init__(self, name: str, at: Point, starts_blue: bool): def __init__(
super().__init__(name, at, at, starts_blue, cptype=ControlPointType.LHA_GROUP) self, name: str, at: Point, theater: ConflictTheater, starts_blue: bool
):
super().__init__(
name, at, at, theater, starts_blue, cptype=ControlPointType.LHA_GROUP
)
@property @property
def symbol_set_and_entity(self) -> tuple[SymbolSet, Entity]: def symbol_set_and_entity(self) -> tuple[SymbolSet, Entity]:
@ -1306,9 +1322,16 @@ class OffMapSpawn(ControlPoint):
def runway_is_operational(self) -> bool: def runway_is_operational(self) -> bool:
return True return True
def __init__(self, name: str, position: Point, starts_blue: bool): def __init__(
self, name: str, position: Point, theater: ConflictTheater, starts_blue: bool
):
super().__init__( super().__init__(
name, position, position, starts_blue, cptype=ControlPointType.OFF_MAP name,
position,
position,
theater,
starts_blue,
cptype=ControlPointType.OFF_MAP,
) )
@property @property
@ -1365,8 +1388,12 @@ class OffMapSpawn(ControlPoint):
class Fob(ControlPoint): class Fob(ControlPoint):
def __init__(self, name: str, at: Point, starts_blue: bool): def __init__(
super().__init__(name, at, at, starts_blue, cptype=ControlPointType.FOB) self, name: str, at: Point, theater: ConflictTheater, starts_blue: bool
):
super().__init__(
name, at, at, theater, starts_blue, cptype=ControlPointType.FOB
)
self.name = name self.name = name
@property @property