mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
refactor of previous commits
refactor to enum typing and many other fixes fix tests attempt to fix some typescript more typescript fixes more typescript test fixes revert all API changes update to pydcs mypy fixes Use properties to check if player is blue/red/neutral update requirements.txt black -_- bump pydcs and fix mypy add opponent property bump pydcs
This commit is contained in:
@@ -68,6 +68,7 @@ from .base import Base
|
||||
from .frontline import FrontLine
|
||||
from .interfaces.CTLD import CTLD
|
||||
from .missiontarget import MissionTarget
|
||||
from .player import Player
|
||||
from .theatergroundobject import (
|
||||
GenericCarrierGroundObject,
|
||||
TheaterGroundObject,
|
||||
@@ -377,7 +378,7 @@ class ControlPoint(MissionTarget, SidcDescribable, ABC):
|
||||
position: Point,
|
||||
at: StartingPosition,
|
||||
theater: ConflictTheater,
|
||||
starts_blue: bool,
|
||||
starting_coalition: Player,
|
||||
cptype: ControlPointType = ControlPointType.AIRBASE,
|
||||
is_invisible: bool = False,
|
||||
) -> None:
|
||||
@@ -386,8 +387,8 @@ class ControlPoint(MissionTarget, SidcDescribable, ABC):
|
||||
self.full_name = name
|
||||
self.at = at
|
||||
self.theater = theater
|
||||
self.starts_blue = starts_blue
|
||||
self.is_invisible = is_invisible
|
||||
self.starting_coalition = starting_coalition
|
||||
self.connected_objectives: List[TheaterGroundObject] = []
|
||||
self.preset_locations = PresetLocations()
|
||||
self.helipads: List[PointWithHeading] = []
|
||||
@@ -435,7 +436,7 @@ class ControlPoint(MissionTarget, SidcDescribable, ABC):
|
||||
|
||||
def finish_init(self, game: Game) -> None:
|
||||
assert self._coalition is None
|
||||
self._coalition = game.coalition_for(self.starts_blue)
|
||||
self._coalition = game.coalition_for(self.starting_coalition)
|
||||
assert self._front_line_db is None
|
||||
self._front_line_db = game.db.front_lines
|
||||
|
||||
@@ -444,7 +445,8 @@ class ControlPoint(MissionTarget, SidcDescribable, ABC):
|
||||
# the entire game state when it comes up.
|
||||
from game.sim import GameUpdateEvents
|
||||
|
||||
self._create_missing_front_lines(laser_code_registry, GameUpdateEvents())
|
||||
if self.captured != Player.NEUTRAL:
|
||||
self._create_missing_front_lines(laser_code_registry, GameUpdateEvents())
|
||||
|
||||
@property
|
||||
def front_line_db(self) -> Database[FrontLine]:
|
||||
@@ -455,9 +457,11 @@ class ControlPoint(MissionTarget, SidcDescribable, ABC):
|
||||
self, laser_code_registry: LaserCodeRegistry, events: GameUpdateEvents
|
||||
) -> None:
|
||||
for connection in self.convoy_routes.keys():
|
||||
if not connection.front_line_active_with(
|
||||
self
|
||||
) and not connection.is_friendly_to(self):
|
||||
if (
|
||||
not connection.front_line_active_with(self)
|
||||
and not connection.is_friendly_to(self)
|
||||
and connection.captured != Player.NEUTRAL
|
||||
):
|
||||
self._create_front_line_with(laser_code_registry, connection, events)
|
||||
|
||||
def _create_front_line_with(
|
||||
@@ -491,6 +495,8 @@ class ControlPoint(MissionTarget, SidcDescribable, ABC):
|
||||
|
||||
@property
|
||||
def has_frontline(self) -> bool:
|
||||
if self.captured.is_neutral:
|
||||
return False
|
||||
return bool(self.front_lines)
|
||||
|
||||
def front_line_active_with(self, other: ControlPoint) -> bool:
|
||||
@@ -500,14 +506,17 @@ class ControlPoint(MissionTarget, SidcDescribable, ABC):
|
||||
return self.front_lines[other]
|
||||
|
||||
@property
|
||||
def captured(self) -> bool:
|
||||
def captured(self) -> Player:
|
||||
return self.coalition.player
|
||||
|
||||
@property
|
||||
def standard_identity(self) -> StandardIdentity:
|
||||
return (
|
||||
StandardIdentity.FRIEND if self.captured else StandardIdentity.HOSTILE_FAKER
|
||||
)
|
||||
if self.captured.is_neutral:
|
||||
return StandardIdentity.UNKNOWN
|
||||
elif self.captured.is_blue:
|
||||
return StandardIdentity.FRIEND
|
||||
else:
|
||||
return StandardIdentity.HOSTILE_FAKER
|
||||
|
||||
@property
|
||||
def sidc_status(self) -> Status:
|
||||
@@ -819,7 +828,7 @@ class ControlPoint(MissionTarget, SidcDescribable, ABC):
|
||||
found.append(g)
|
||||
return found
|
||||
|
||||
def is_friendly(self, to_player: bool) -> bool:
|
||||
def is_friendly(self, to_player: Player) -> bool:
|
||||
return self.captured == to_player
|
||||
|
||||
def is_friendly_to(self, control_point: ControlPoint) -> bool:
|
||||
@@ -828,7 +837,9 @@ class ControlPoint(MissionTarget, SidcDescribable, ABC):
|
||||
def capture_equipment(self, game: Game) -> None:
|
||||
total = self.base.total_armor_value
|
||||
self.base.armor.clear()
|
||||
game.adjust_budget(total, player=not self.captured)
|
||||
game.adjust_budget(
|
||||
total, player=Player.BLUE if self.captured.is_red else Player.RED
|
||||
)
|
||||
game.message(
|
||||
f"{self.name} is not connected to any friendly points. Ground "
|
||||
f"vehicles have been captured and sold for ${total}M."
|
||||
@@ -857,7 +868,9 @@ class ControlPoint(MissionTarget, SidcDescribable, ABC):
|
||||
|
||||
def capture_aircraft(self, game: Game, airframe: AircraftType, count: int) -> None:
|
||||
value = airframe.price * count
|
||||
game.adjust_budget(value, player=not self.captured)
|
||||
game.adjust_budget(
|
||||
value, player=Player.BLUE if self.captured.is_red else Player.RED
|
||||
)
|
||||
game.message(
|
||||
f"No valid retreat destination in range of {self.name} for {airframe} "
|
||||
f"{count} aircraft have been captured and sold for ${value}M."
|
||||
@@ -960,7 +973,7 @@ class ControlPoint(MissionTarget, SidcDescribable, ABC):
|
||||
pass
|
||||
|
||||
# TODO: Should be Airbase specific.
|
||||
def capture(self, game: Game, events: GameUpdateEvents, for_player: bool) -> None:
|
||||
def capture(self, game: Game, events: GameUpdateEvents, for_player: Player) -> None:
|
||||
new_coalition = game.coalition_for(for_player)
|
||||
self.ground_unit_orders.refund_all(self.coalition)
|
||||
self.retreat_ground_units(game)
|
||||
@@ -1125,6 +1138,8 @@ class ControlPoint(MissionTarget, SidcDescribable, ABC):
|
||||
|
||||
@property
|
||||
def has_active_frontline(self) -> bool:
|
||||
if self.captured.is_neutral:
|
||||
return False
|
||||
return any(not c.is_friendly(self.captured) for c in self.connected_points)
|
||||
|
||||
def front_is_active(self, other: ControlPoint) -> bool:
|
||||
@@ -1211,7 +1226,7 @@ class Airfield(ControlPoint, CTLD):
|
||||
self,
|
||||
airport: Airport,
|
||||
theater: ConflictTheater,
|
||||
starts_blue: bool,
|
||||
starting_coalition: Player,
|
||||
ctld_zones: Optional[List[Tuple[Point, float]]] = None,
|
||||
influence_zone: Optional[List[Tuple[Point, float]]] = None,
|
||||
) -> None:
|
||||
@@ -1220,7 +1235,7 @@ class Airfield(ControlPoint, CTLD):
|
||||
airport.position,
|
||||
airport,
|
||||
theater,
|
||||
starts_blue,
|
||||
starting_coalition,
|
||||
cptype=ControlPointType.AIRBASE,
|
||||
)
|
||||
self.airport = airport
|
||||
@@ -1252,7 +1267,7 @@ class Airfield(ControlPoint, CTLD):
|
||||
return True
|
||||
return self.runway_is_operational()
|
||||
|
||||
def mission_types(self, for_player: bool) -> Iterator[FlightType]:
|
||||
def mission_types(self, for_player: Player) -> Iterator[FlightType]:
|
||||
from game.ato import FlightType
|
||||
|
||||
if not self.is_friendly(for_player):
|
||||
@@ -1373,7 +1388,7 @@ class NavalControlPoint(
|
||||
def is_fleet(self) -> bool:
|
||||
return True
|
||||
|
||||
def mission_types(self, for_player: bool) -> Iterator[FlightType]:
|
||||
def mission_types(self, for_player: Player) -> Iterator[FlightType]:
|
||||
from game.ato import FlightType
|
||||
|
||||
if self.is_friendly(for_player):
|
||||
@@ -1482,7 +1497,7 @@ class NavalControlPoint(
|
||||
|
||||
class Carrier(NavalControlPoint):
|
||||
def __init__(
|
||||
self, name: str, at: Point, theater: ConflictTheater, starts_blue: bool
|
||||
self, name: str, at: Point, theater: ConflictTheater, starts_blue: Player
|
||||
):
|
||||
super().__init__(
|
||||
name,
|
||||
@@ -1497,7 +1512,7 @@ class Carrier(NavalControlPoint):
|
||||
def symbol_set_and_entity(self) -> tuple[SymbolSet, Entity]:
|
||||
return SymbolSet.SEA_SURFACE, SeaSurfaceEntity.CARRIER
|
||||
|
||||
def capture(self, game: Game, events: GameUpdateEvents, for_player: bool) -> None:
|
||||
def capture(self, game: Game, events: GameUpdateEvents, for_player: Player) -> None:
|
||||
raise RuntimeError("Carriers cannot be captured")
|
||||
|
||||
@property
|
||||
@@ -1522,7 +1537,7 @@ class EssexCarrier(Carrier):
|
||||
|
||||
class Lha(NavalControlPoint):
|
||||
def __init__(
|
||||
self, name: str, at: Point, theater: ConflictTheater, starts_blue: bool
|
||||
self, name: str, at: Point, theater: ConflictTheater, starts_blue: Player
|
||||
):
|
||||
super().__init__(
|
||||
name, at, at, theater, starts_blue, cptype=ControlPointType.LHA_GROUP
|
||||
@@ -1532,7 +1547,7 @@ class Lha(NavalControlPoint):
|
||||
def symbol_set_and_entity(self) -> tuple[SymbolSet, Entity]:
|
||||
return SymbolSet.SEA_SURFACE, SeaSurfaceEntity.AMPHIBIOUS_ASSAULT_SHIP_GENERAL
|
||||
|
||||
def capture(self, game: Game, events: GameUpdateEvents, for_player: bool) -> None:
|
||||
def capture(self, game: Game, events: GameUpdateEvents, for_player: Player) -> None:
|
||||
raise RuntimeError("LHAs cannot be captured")
|
||||
|
||||
@property
|
||||
@@ -1555,7 +1570,7 @@ class OffMapSpawn(ControlPoint):
|
||||
return True
|
||||
|
||||
def __init__(
|
||||
self, name: str, position: Point, theater: ConflictTheater, starts_blue: bool
|
||||
self, name: str, position: Point, theater: ConflictTheater, starts_blue: Player
|
||||
):
|
||||
super().__init__(
|
||||
name,
|
||||
@@ -1570,10 +1585,10 @@ class OffMapSpawn(ControlPoint):
|
||||
def symbol_set_and_entity(self) -> tuple[SymbolSet, Entity]:
|
||||
return SymbolSet.LAND_INSTALLATIONS, LandInstallationEntity.AIPORT_AIR_BASE
|
||||
|
||||
def capture(self, game: Game, events: GameUpdateEvents, for_player: bool) -> None:
|
||||
def capture(self, game: Game, events: GameUpdateEvents, for_player: Player) -> None:
|
||||
raise RuntimeError("Off map control points cannot be captured")
|
||||
|
||||
def mission_types(self, for_player: bool) -> Iterator[FlightType]:
|
||||
def mission_types(self, for_player: Player) -> Iterator[FlightType]:
|
||||
yield from []
|
||||
|
||||
def total_aircraft_parking(self, parking_type: ParkingType) -> int:
|
||||
@@ -1630,7 +1645,7 @@ class Fob(ControlPoint, RadioFrequencyContainer, CTLD):
|
||||
name: str,
|
||||
at: Point,
|
||||
theater: ConflictTheater,
|
||||
starts_blue: bool,
|
||||
starts_blue: Player,
|
||||
ctld_zones: Optional[List[Tuple[Point, float]]] = None,
|
||||
is_invisible: bool = False,
|
||||
influence_zone: Optional[List[Tuple[Point, float]]] = None,
|
||||
@@ -1667,7 +1682,7 @@ class Fob(ControlPoint, RadioFrequencyContainer, CTLD):
|
||||
def runway_status(self) -> RunwayStatus:
|
||||
return RunwayStatus()
|
||||
|
||||
def mission_types(self, for_player: bool) -> Iterator[FlightType]:
|
||||
def mission_types(self, for_player: Player) -> Iterator[FlightType]:
|
||||
from game.ato import FlightType
|
||||
|
||||
if not self.is_friendly(for_player):
|
||||
|
||||
Reference in New Issue
Block a user