diff --git a/game/missiongenerator/tgogenerator.py b/game/missiongenerator/tgogenerator.py index 56af0257..275a1c2c 100644 --- a/game/missiongenerator/tgogenerator.py +++ b/game/missiongenerator/tgogenerator.py @@ -17,15 +17,7 @@ from dcs.action import DoScript, SceneryDestructionZone from dcs.condition import MapObjectIsDead from dcs.country import Country from dcs.point import StaticPoint -from dcs.ships import ( - CVN_71, - CVN_72, - CVN_73, - CVN_75, - CV_1143_5, - KUZNECOW, - Stennis, -) + from dcs.statics import Fortification from dcs.task import ( ActivateBeaconCommand, @@ -361,9 +353,14 @@ class GenericCarrierGenerator(GroundObjectGenerator): # Set Carrier Specific Options if g_id == 0: - # Correct unit type for the carrier. - # This is only used for the super carrier setting - ship_group.units[0].type = self.get_carrier_type(group).id + # Get Correct unit type for the carrier. + # This will upgrade to super carrier if option is enabled + carrier_type = self.carrier_type + if carrier_type is None: + raise RuntimeError( + f"Error generating carrier group for {self.control_point.name}" + ) + ship_group.units[0].type = carrier_type.id tacan = self.tacan_registry.alloc_for_band( TacanBand.X, TacanUsage.TransmitReceive ) @@ -374,11 +371,9 @@ class GenericCarrierGenerator(GroundObjectGenerator): brc or Heading.from_degrees(0), atc, tacan, tacan_callsign, icls ) - def get_carrier_type(self, group: TheaterGroup) -> Type[ShipType]: - carrier_type = group.units[0].type - if issubclass(carrier_type, ShipType): - return carrier_type - raise RuntimeError(f"First unit of TGO {group.name} is no Ship") + @property + def carrier_type(self) -> Optional[Type[ShipType]]: + return self.control_point.get_carrier_group_type() def steam_into_wind(self, group: ShipGroup) -> Optional[Heading]: wind = self.game.conditions.weather.wind.at_0m @@ -445,32 +440,6 @@ class GenericCarrierGenerator(GroundObjectGenerator): class CarrierGenerator(GenericCarrierGenerator): """Generator for CV(N) groups.""" - def get_carrier_type(self, group: TheaterGroup) -> Type[ShipType]: - unit_type = super().get_carrier_type(group) - if self.game.settings.supercarrier: - unit_type = self.upgrade_to_supercarrier(unit_type, self.control_point.name) - return unit_type - - @staticmethod - def upgrade_to_supercarrier(unit: Type[ShipType], name: str) -> Type[ShipType]: - if unit == Stennis: - if name == "CVN-71 Theodore Roosevelt": - return CVN_71 - elif name == "CVN-72 Abraham Lincoln": - return CVN_72 - elif name == "CVN-73 George Washington": - return CVN_73 - elif name == "CVN-75 Harry S. Truman": - return CVN_75 - elif name == "Carrier Strike Group 8": - return CVN_75 - else: - return CVN_71 - elif unit == KUZNECOW: - return CV_1143_5 - else: - return unit - def tacan_callsign(self) -> str: # TODO: Assign these properly. return random.choice( diff --git a/game/theater/controlpoint.py b/game/theater/controlpoint.py index e180bd8a..d29cc873 100644 --- a/game/theater/controlpoint.py +++ b/game/theater/controlpoint.py @@ -21,13 +21,26 @@ from typing import ( Set, TYPE_CHECKING, Tuple, + Type, ) from uuid import UUID from dcs.mapping import Point -from dcs.ships import Forrestal, KUZNECOW, LHA_Tarawa, Stennis, Type_071 from dcs.terrain.terrain import Airport, ParkingSlot from dcs.unitgroup import ShipGroup, StaticGroup +from dcs.unittype import ShipType +from dcs.ships import ( + CVN_71, + CVN_72, + CVN_73, + CVN_75, + CV_1143_5, + KUZNECOW, + Stennis, + Forrestal, + LHA_Tarawa, + Type_071, +) from game.ato.closestairfields import ObjectiveDistanceCache from game.ground_forces.combat_stance import CombatStance @@ -612,6 +625,60 @@ class ControlPoint(MissionTarget, SidcDescribable, ABC): return group.group_name return None + def get_carrier_group_type( + self, always_supercarrier: bool = False + ) -> Optional[Type[ShipType]]: + """ + Get the carrier group type if the airbase is a carrier. Arguments: + always_supercarrier: True if should always return the supercarrier type, False if should only + return the supercarrier type when the supercarrier option is enabled in settings. + :return: Carrier group type + """ + if self.cptype in [ + ControlPointType.AIRCRAFT_CARRIER_GROUP, + ControlPointType.LHA_GROUP, + ]: + for g in self.ground_objects: + for group in g.groups: + u = group.units[0] + carrier_type = u.type + if ( + u.unit_type + and u.unit_type.unit_class + in [ + UnitClass.AIRCRAFT_CARRIER, + UnitClass.HELICOPTER_CARRIER, + ] + and issubclass(carrier_type, ShipType) + ): + if ( + self.coalition.game.settings.supercarrier + or always_supercarrier + ): + return self.upgrade_to_supercarrier(carrier_type, self.name) + return carrier_type + return None + + @staticmethod + def upgrade_to_supercarrier(unit: Type[ShipType], name: str) -> Type[ShipType]: + if unit == Stennis: + if name == "CVN-71 Theodore Roosevelt": + return CVN_71 + elif name == "CVN-72 Abraham Lincoln": + return CVN_72 + elif name == "CVN-73 George Washington": + return CVN_73 + elif name == "CVN-75 Harry S. Truman": + return CVN_75 + elif name == "Carrier Strike Group 8": + return CVN_75 + else: + return CVN_71 + elif unit == KUZNECOW: + return CV_1143_5 + else: + return unit + # TODO: Should be Airbase specific. def is_connected(self, to: ControlPoint) -> bool: return to in self.connected_points diff --git a/game/theater/theatergroundobject.py b/game/theater/theatergroundobject.py index ce1fe54d..b1be4d99 100644 --- a/game/theater/theatergroundobject.py +++ b/game/theater/theatergroundobject.py @@ -3,10 +3,13 @@ from __future__ import annotations import itertools import uuid from abc import ABC +from typing import Type from typing import Any, Iterator, List, Optional, TYPE_CHECKING from dcs.mapping import Point + from dcs.unittype import VehicleType +from dcs.unittype import ShipType from shapely.geometry import Point as ShapelyPoint from game.sidc import ( diff --git a/qt_ui/windows/basemenu/QBaseMenu2.py b/qt_ui/windows/basemenu/QBaseMenu2.py index 668c94ac..7eb1f5ae 100644 --- a/qt_ui/windows/basemenu/QBaseMenu2.py +++ b/qt_ui/windows/basemenu/QBaseMenu2.py @@ -9,6 +9,7 @@ from PySide2.QtWidgets import ( QVBoxLayout, QWidget, ) +from dcs.ships import Stennis, KUZNECOW from game import Game from game.ato.flighttype import FlightType @@ -240,10 +241,12 @@ class QBaseMenu2(QDialog): GameUpdateSignal.get_instance().updateGame(self.game_model.game) def get_base_image(self): - if self.cp.cptype == ControlPointType.AIRCRAFT_CARRIER_GROUP: - return "./resources/ui/carrier.png" - elif self.cp.cptype == ControlPointType.LHA_GROUP: - return "./resources/ui/lha.png" + if ( + self.cp.cptype == ControlPointType.AIRCRAFT_CARRIER_GROUP + or self.cp.cptype == ControlPointType.LHA_GROUP + ): + carrier_type = self.cp.get_carrier_group_type(always_supercarrier=True) + return f"./resources/ui/units/ships/{carrier_type.id}.png" elif self.cp.cptype == ControlPointType.FOB and self.cp.has_helipads: return "./resources/ui/heliport.png" elif self.cp.cptype == ControlPointType.FOB: diff --git a/resources/ui/carrier.png b/resources/ui/carrier.png deleted file mode 100644 index 4ae09dd6..00000000 Binary files a/resources/ui/carrier.png and /dev/null differ diff --git a/resources/ui/units/ships/CVN_71.png b/resources/ui/units/ships/CVN_71.png new file mode 100644 index 00000000..c4c60c01 Binary files /dev/null and b/resources/ui/units/ships/CVN_71.png differ diff --git a/resources/ui/units/ships/CVN_72.png b/resources/ui/units/ships/CVN_72.png new file mode 100644 index 00000000..f77e4d37 Binary files /dev/null and b/resources/ui/units/ships/CVN_72.png differ diff --git a/resources/ui/units/ships/CVN_73.png b/resources/ui/units/ships/CVN_73.png new file mode 100644 index 00000000..ee599527 Binary files /dev/null and b/resources/ui/units/ships/CVN_73.png differ diff --git a/resources/ui/units/ships/CVN_75.png b/resources/ui/units/ships/CVN_75.png new file mode 100644 index 00000000..66809f56 Binary files /dev/null and b/resources/ui/units/ships/CVN_75.png differ diff --git a/resources/ui/units/ships/CV_1143_5.png b/resources/ui/units/ships/CV_1143_5.png new file mode 100644 index 00000000..2d7783a6 Binary files /dev/null and b/resources/ui/units/ships/CV_1143_5.png differ diff --git a/resources/ui/units/ships/Forrestal.png b/resources/ui/units/ships/Forrestal.png new file mode 100644 index 00000000..6d37f3ef Binary files /dev/null and b/resources/ui/units/ships/Forrestal.png differ diff --git a/resources/ui/units/ships/KUZNECOW.png b/resources/ui/units/ships/KUZNECOW.png new file mode 100644 index 00000000..a22ad03d Binary files /dev/null and b/resources/ui/units/ships/KUZNECOW.png differ diff --git a/resources/ui/lha.png b/resources/ui/units/ships/LHA_Tarawa.png similarity index 100% rename from resources/ui/lha.png rename to resources/ui/units/ships/LHA_Tarawa.png diff --git a/resources/ui/units/ships/Stennis.png b/resources/ui/units/ships/Stennis.png new file mode 100644 index 00000000..f9aadd03 Binary files /dev/null and b/resources/ui/units/ships/Stennis.png differ diff --git a/resources/ui/units/ships/Type_071.png b/resources/ui/units/ships/Type_071.png new file mode 100644 index 00000000..d3370fa8 Binary files /dev/null and b/resources/ui/units/ships/Type_071.png differ diff --git a/resources/ui/units/ships/VINSON.png b/resources/ui/units/ships/VINSON.png new file mode 100644 index 00000000..45b963c0 Binary files /dev/null and b/resources/ui/units/ships/VINSON.png differ