Add mission targeting for cargo ships.

https://github.com/Khopa/dcs_liberation/issues/826
This commit is contained in:
Dan Albert 2021-04-25 14:31:13 -07:00
parent e80819fc06
commit 2d64acf299
4 changed files with 25 additions and 18 deletions

View File

@ -88,7 +88,7 @@ from game.theater.controlpoint import (
OffMapSpawn,
)
from game.theater.theatergroundobject import TheaterGroundObject
from game.transfers import Convoy
from game.transfers import MultiGroupTransport
from game.unitmap import UnitMap
from game.utils import Distance, meters, nautical_miles
from gen.ato import AirTaskingOrder, Package
@ -1719,7 +1719,7 @@ class BaiIngressBuilder(PydcsWaypointBuilder):
target_group = self.package.target
if isinstance(target_group, TheaterGroundObject):
group_name = target_group.group_name
elif isinstance(target_group, Convoy):
elif isinstance(target_group, MultiGroupTransport):
group_name = target_group.name
else:
logging.error(

View File

@ -1083,6 +1083,10 @@ class FlightPlanBuilder:
flight, location, FlightWaypointType.INGRESS_BAI, targets
)
@staticmethod
def anti_ship_targets_for_tgo(tgo: TheaterGroundObject) -> List[StrikeTarget]:
return [StrikeTarget(f"{g.name} at {tgo.name}", g) for g in tgo.groups]
def generate_anti_ship(self, flight: Flight) -> StrikeFlightPlan:
"""Generates an anti-ship flight plan.
@ -1091,20 +1095,20 @@ class FlightPlanBuilder:
"""
location = self.package.target
from game.transfers import CargoShip
if isinstance(location, ControlPoint):
if location.is_fleet:
# The first group generated will be the carrier group itself.
location = location.ground_objects[0]
else:
if not location.is_fleet:
raise InvalidObjectiveLocation(flight.flight_type, location)
if not isinstance(location, TheaterGroundObject):
# The first group generated will be the carrier group itself.
targets = self.anti_ship_targets_for_tgo(location.ground_objects[0])
elif isinstance(location, TheaterGroundObject):
targets = self.anti_ship_targets_for_tgo(location)
elif isinstance(location, CargoShip):
targets = [StrikeTarget(location.name, location)]
else:
raise InvalidObjectiveLocation(flight.flight_type, location)
targets: List[StrikeTarget] = []
for group in location.groups:
targets.append(StrikeTarget(f"{group.name} at {location.name}", group))
return self.strike_flightplan(
flight, location, FlightWaypointType.INGRESS_BAI, targets
)

View File

@ -18,7 +18,7 @@ from dcs.unitgroup import Group, VehicleGroup
if TYPE_CHECKING:
from game import Game
from game.transfers import Convoy
from game.transfers import MultiGroupTransport
from game.theater import (
ControlPoint,
@ -33,7 +33,7 @@ from .flight import Flight, FlightWaypoint, FlightWaypointType
@dataclass(frozen=True)
class StrikeTarget:
name: str
target: Union[VehicleGroup, TheaterGroundObject, Unit, Group, Convoy]
target: Union[VehicleGroup, TheaterGroundObject, Unit, Group, MultiGroupTransport]
class WaypointBuilder:

View File

@ -12,14 +12,14 @@ from PySide2.QtWidgets import (
from game import db
from game.theater import ControlPoint
from game.transfers import Convoy
from game.transfers import MultiGroupTransport
from qt_ui.dialogs import Dialog
from qt_ui.models import GameModel
from qt_ui.uiconstants import VEHICLES_ICONS
class DepartingConvoyInfo(QGroupBox):
def __init__(self, convoy: Convoy, game_model: GameModel) -> None:
def __init__(self, convoy: MultiGroupTransport, game_model: GameModel) -> None:
super().__init__(f"{convoy.name} to {convoy.destination}")
self.convoy = convoy
@ -78,11 +78,14 @@ class DepartingConvoysList(QFrame):
task_box_layout = QGridLayout()
scroll_content.setLayout(task_box_layout)
convoy_map = game_model.game.transfers.convoys
for convoy in convoy_map.departing_from(cp):
for convoy in game_model.game.transfers.convoys.departing_from(cp):
group_info = DepartingConvoyInfo(convoy, game_model)
task_box_layout.addWidget(group_info)
for cargo_ship in game_model.game.transfers.cargo_ships.departing_from(cp):
group_info = DepartingConvoyInfo(cargo_ship, game_model)
task_box_layout.addWidget(group_info)
scroll_content.setLayout(task_box_layout)
scroll = QScrollArea()
scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)