Add anti-ship missions.

The only practical difference between this and BAI is that the target is
floating, so this mostly shares its implementation with BAI.

Fixes https://github.com/Khopa/dcs_liberation/issues/350
This commit is contained in:
Dan Albert 2020-11-16 23:29:19 -08:00
parent 9f2409bb9e
commit 082e8c062c
4 changed files with 42 additions and 8 deletions

View File

@ -3,6 +3,7 @@
# Features/Improvements # Features/Improvements
* **[Flight Planner]** Added fighter sweep missions. * **[Flight Planner]** Added fighter sweep missions.
* **[Flight Planner]** Added BAI missions. * **[Flight Planner]** Added BAI missions.
* **[Flight Planner]** Added anti-ship missions.
* **[Flight Planner]** Differentiated BARCAP and TARCAP. TARCAP is now for hostile areas and will arrive before the package. * **[Flight Planner]** Differentiated BARCAP and TARCAP. TARCAP is now for hostile areas and will arrive before the package.
* **[Modding]** Possible to setup liveries overrides for factions * **[Modding]** Possible to setup liveries overrides for factions

View File

@ -629,7 +629,9 @@ class FlightPlanBuilder:
custom_targets: Optional[List[Unit]]) -> FlightPlan: custom_targets: Optional[List[Unit]]) -> FlightPlan:
# TODO: Flesh out mission types. # TODO: Flesh out mission types.
task = flight.flight_type task = flight.flight_type
if task == FlightType.BAI: if task == FlightType.ANTISHIP:
return self.generate_anti_ship(flight)
elif task == FlightType.BAI:
return self.generate_bai(flight) return self.generate_bai(flight)
elif task == FlightType.BARCAP: elif task == FlightType.BARCAP:
return self.generate_barcap(flight) return self.generate_barcap(flight)
@ -722,6 +724,31 @@ class FlightPlanBuilder:
return self.strike_flightplan(flight, location, targets) return self.strike_flightplan(flight, location, targets)
def generate_anti_ship(self, flight: Flight) -> StrikeFlightPlan:
"""Generates an anti-ship flight plan.
Args:
flight: The flight to generate the flight plan for.
"""
location = self.package.target
if isinstance(location, ControlPoint):
if location.is_fleet:
# The first group generated will be the carrier group itself.
location = location.ground_objects[0]
else:
raise InvalidObjectiveLocation(flight.flight_type, location)
if not isinstance(location, TheaterGroundObject):
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, targets)
def generate_barcap(self, flight: Flight) -> BarCapFlightPlan: def generate_barcap(self, flight: Flight) -> BarCapFlightPlan:
"""Generate a BARCAP flight at a given location. """Generate a BARCAP flight at a given location.
@ -985,7 +1012,7 @@ class FlightPlanBuilder:
@staticmethod @staticmethod
def target_waypoint(flight: Flight, builder: WaypointBuilder, def target_waypoint(flight: Flight, builder: WaypointBuilder,
target: StrikeTarget) -> FlightWaypoint: target: StrikeTarget) -> FlightWaypoint:
if flight.flight_type == FlightType.BAI: if flight.flight_type in {FlightType.ANTISHIP, FlightType.BAI}:
return builder.bai_group(target) return builder.bai_group(target)
elif flight.flight_type == FlightType.DEAD: elif flight.flight_type == FlightType.DEAD:
return builder.dead_point(target) return builder.dead_point(target)
@ -1097,7 +1124,7 @@ class FlightPlanBuilder:
elif flight.flight_type is FlightType.DEAD: elif flight.flight_type is FlightType.DEAD:
ingress = builder.ingress_dead(self.package.waypoints.ingress, ingress = builder.ingress_dead(self.package.waypoints.ingress,
location) location)
elif flight.flight_type is FlightType.BAI: elif flight.flight_type in {FlightType.ANTISHIP, FlightType.BAI}:
ingress = builder.ingress_bai(self.package.waypoints.ingress, ingress = builder.ingress_bai(self.package.waypoints.ingress,
location) location)
else: else:

View File

@ -255,9 +255,7 @@ class ControlPoint(MissionTarget):
] ]
else: else:
if self.is_fleet: if self.is_fleet:
yield from [ yield FlightType.ANTISHIP
# TODO: FlightType.ANTISHIP
]
else: else:
yield from [ yield from [
# TODO: FlightType.STRIKE # TODO: FlightType.STRIKE

View File

@ -156,7 +156,15 @@ class BuildingGroundObject(TheaterGroundObject):
return f"{self.category}|{self.group_id}|{self.object_id}" return f"{self.category}|{self.group_id}|{self.object_id}"
class GenericCarrierGroundObject(TheaterGroundObject): class NavalGroundObject(TheaterGroundObject):
def mission_types(self, for_player: bool) -> Iterator[FlightType]:
from gen.flights.flight import FlightType
if not self.is_friendly(for_player):
yield FlightType.ANTISHIP
yield from super().mission_types(for_player)
class GenericCarrierGroundObject(NavalGroundObject):
pass pass
@ -284,7 +292,7 @@ class EwrGroundObject(BaseDefenseGroundObject):
return f"{self.faction_color}|{super().group_name}" return f"{self.faction_color}|{super().group_name}"
class ShipGroundObject(TheaterGroundObject): class ShipGroundObject(NavalGroundObject):
def __init__(self, name: str, group_id: int, position: Point, def __init__(self, name: str, group_id: int, position: Point,
control_point: ControlPoint) -> None: control_point: ControlPoint) -> None:
super().__init__( super().__init__(