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: