De-spawn AI flights on RTB if start-type was set to In-Flight

Resolve #73
This commit is contained in:
Raffson 2024-01-21 18:40:33 +01:00
parent bc26eb3f5e
commit 0b060d3110
No known key found for this signature in database
GPG Key ID: B0402B2C9B764D99
5 changed files with 40 additions and 18 deletions

View File

@ -34,6 +34,7 @@
* **[Mission Generator]** F-15E Strike targets are automatically added as Mission Set 1 * **[Mission Generator]** F-15E Strike targets are automatically added as Mission Set 1
* **[Mission Generator]** Set F-14's IP waypoint according to the flight-plan's ingress point * **[Mission Generator]** Set F-14's IP waypoint according to the flight-plan's ingress point
* **[Mission Generator]** Automatically de-spawn aircraft when arrival/divert is an off-map spawn * **[Mission Generator]** Automatically de-spawn aircraft when arrival/divert is an off-map spawn
* **[Options]** Option to de-spawn AI flights in the air if their start-type was manually set to In-Flight
## Fixes ## Fixes
* **[Mission Generation]** Anti-ship strikes should use "group attack" in their attack-task * **[Mission Generation]** Anti-ship strikes should use "group attack" in their attack-task

View File

@ -7,12 +7,18 @@ from .pydcswaypointbuilder import PydcsWaypointBuilder
class LandingPointBuilder(PydcsWaypointBuilder): class LandingPointBuilder(PydcsWaypointBuilder):
def build(self) -> MovingPoint: def build(self) -> MovingPoint:
waypoint = super().build() waypoint = super().build()
waypoint.type = "Land" if self.ai_despawn(waypoint):
waypoint.action = PointAction.Landing waypoint.alt = round(
if (control_point := self.waypoint.control_point) is not None: self.flight.coalition.doctrine.max_patrol_altitude.meters
if isinstance(control_point, NavalControlPoint): )
waypoint.helipad_id = control_point.airdrome_id_for_landing waypoint.alt_type = "BARO"
waypoint.link_unit = control_point.airdrome_id_for_landing else:
else: waypoint.type = "Land"
waypoint.airdrome_id = control_point.airdrome_id_for_landing waypoint.action = PointAction.Landing
if (control_point := self.waypoint.control_point) is not None:
if isinstance(control_point, NavalControlPoint):
waypoint.helipad_id = control_point.airdrome_id_for_landing # type: ignore
waypoint.link_unit = control_point.airdrome_id_for_landing # type: ignore
else:
waypoint.airdrome_id = control_point.airdrome_id_for_landing
return waypoint return waypoint

View File

@ -11,6 +11,7 @@ from dcs.unitgroup import FlyingGroup
from game.ato import Flight, FlightWaypoint from game.ato import Flight, FlightWaypoint
from game.ato.flightwaypointtype import FlightWaypointType from game.ato.flightwaypointtype import FlightWaypointType
from game.ato.starttype import StartType
from game.ato.traveltime import GroundSpeed from game.ato.traveltime import GroundSpeed
from game.missiongenerator.missiondata import MissionData from game.missiongenerator.missiondata import MissionData
from game.theater import MissionTarget, TheaterUnit, OffMapSpawn from game.theater import MissionTarget, TheaterUnit, OffMapSpawn
@ -81,12 +82,20 @@ class PydcsWaypointBuilder:
self.add_tasks(waypoint) self.add_tasks(waypoint)
return waypoint return waypoint
def add_tasks(self, waypoint: MovingPoint) -> None: def ai_despawn(
self, waypoint: MovingPoint, ignore_landing_wpt: bool = False
) -> bool:
if self.flight.roster.members[0].is_player:
return False
arrival = self.flight.arrival arrival = self.flight.arrival
divert = self.flight.divert offmap = isinstance(arrival, OffMapSpawn)
offmap = isinstance(arrival, OffMapSpawn) or isinstance(divert, OffMapSpawn) ai_despawn = self.flight.coalition.game.settings.perf_ai_despawn_airstarted
pos = waypoint.position ai_despawn &= self.flight.start_type == StartType.IN_FLIGHT
if offmap and (arrival.position == pos or divert and divert.position == pos): is_landing_wpt = arrival.position == waypoint.position
return (offmap or ai_despawn) and (is_landing_wpt or ignore_landing_wpt)
def add_tasks(self, waypoint: MovingPoint) -> None:
if self.ai_despawn(waypoint):
waypoint.tasks.append( waypoint.tasks.append(
RunScript( RunScript(
f"local g = Group.getByName('{self.group.name}')\n" f"local g = Group.getByName('{self.group.name}')\n"

View File

@ -1,16 +1,12 @@
from dcs.point import MovingPoint from dcs.point import MovingPoint
from dcs.task import RefuelingTaskAction, ControlledTask from dcs.task import RefuelingTaskAction, ControlledTask
from game.theater import OffMapSpawn
from .pydcswaypointbuilder import PydcsWaypointBuilder from .pydcswaypointbuilder import PydcsWaypointBuilder
class RefuelPointBuilder(PydcsWaypointBuilder): class RefuelPointBuilder(PydcsWaypointBuilder):
def add_tasks(self, waypoint: MovingPoint) -> None: def add_tasks(self, waypoint: MovingPoint) -> None:
offmap = isinstance(self.flight.arrival, OffMapSpawn) if not self.ai_despawn(waypoint, True):
if self.flight.divert:
offmap |= isinstance(self.flight.divert, OffMapSpawn)
if not offmap:
refuel = ControlledTask(RefuelingTaskAction()) refuel = ControlledTask(RefuelingTaskAction())
refuel.start_probability(10) refuel.start_probability(10)
waypoint.add_task(refuel) waypoint.add_task(refuel)

View File

@ -961,6 +961,16 @@ class Settings:
default=True, default=True,
causes_expensive_game_update=True, causes_expensive_game_update=True,
) )
perf_ai_despawn_airstarted: bool = boolean_option(
"De-spawn AI in the air upon RTB",
page=MISSION_GENERATOR_PAGE,
section=PERFORMANCE_SECTION,
default=False,
detail=(
"If enabled, AI flights will de-spawn over their base "
"if the start-up type was manually changed to 'In-Flight'."
),
)
# Cheating. Not using auto settings because the same page also has buttons which do # Cheating. Not using auto settings because the same page also has buttons which do
# not alter settings. # not alter settings.