mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Reconfigure escort task
This commit is contained in:
parent
ba66c18f28
commit
322a6a700a
@ -1,89 +1,57 @@
|
|||||||
import random
|
import random
|
||||||
from typing import List, Type, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
|
Optional
|
||||||
|
|
||||||
from dcs.point import MovingPoint
|
from dcs.point import MovingPoint
|
||||||
from dcs.task import (
|
from dcs.task import (
|
||||||
ControlledTask,
|
|
||||||
EngageTargets,
|
|
||||||
EscortTaskAction,
|
EscortTaskAction,
|
||||||
OptECMUsing,
|
OptECMUsing,
|
||||||
OptFormation,
|
OptFormation,
|
||||||
TargetType,
|
Targets,
|
||||||
Targets, GoToWaypoint, SwitchWaypoint,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from game.ato import FlightType
|
from game.ato import FlightType
|
||||||
from game.theater import NavalControlPoint
|
from game.theater import NavalControlPoint
|
||||||
from game.utils import nautical_miles
|
from game.utils import nautical_miles, feet
|
||||||
from .pydcswaypointbuilder import PydcsWaypointBuilder
|
from .pydcswaypointbuilder import PydcsWaypointBuilder
|
||||||
|
|
||||||
|
|
||||||
class JoinPointBuilder(PydcsWaypointBuilder):
|
class JoinPointBuilder(PydcsWaypointBuilder):
|
||||||
def add_tasks(self, waypoint: MovingPoint) -> None:
|
def add_tasks(self, waypoint: MovingPoint) -> None:
|
||||||
|
waypoint.tasks.append(OptFormation.finger_four_open())
|
||||||
|
|
||||||
if self.flight.flight_type == FlightType.ESCORT:
|
if self.flight.flight_type == FlightType.ESCORT:
|
||||||
# self.configure_escort_tasks(
|
self.configure_escort_tasks(
|
||||||
# waypoint,
|
waypoint,
|
||||||
# [
|
[
|
||||||
# Targets.All.Air.Planes.Fighters,
|
Targets.All.Air.Planes.Fighters.id,
|
||||||
# Targets.All.Air.Planes.MultiroleFighters,
|
Targets.All.Air.Planes.MultiroleFighters.id,
|
||||||
# ],
|
],
|
||||||
# )
|
|
||||||
|
|
||||||
waypoint.tasks.append(OptFormation.finger_four_open())
|
|
||||||
waypoint.tasks.append(SwitchWaypoint(3, 7))
|
|
||||||
|
|
||||||
rx = (random.random() + 0.1) * 500 * random.choice([-1, 1])
|
|
||||||
ry = (random.random() + 0.1) * 500 * random.choice([-1, 1])
|
|
||||||
rz = (random.random() + 0.1) * 500 * random.choice([-1, 1])
|
|
||||||
pos = {"x": rx, "y": ry, "z": rz}
|
|
||||||
targets = [
|
|
||||||
Targets.All.Air.Planes.Fighters.id,
|
|
||||||
Targets.All.Air.Planes.MultiroleFighters.id,
|
|
||||||
]
|
|
||||||
waypoint.tasks.append(
|
|
||||||
EscortTaskAction(
|
|
||||||
group_id=self.package.primary_flight.group_id,
|
|
||||||
engagement_max_dist=int(nautical_miles(40).meters),
|
|
||||||
lastwpt=6,
|
|
||||||
targets=targets,
|
|
||||||
position=pos)
|
|
||||||
)
|
)
|
||||||
elif self.flight.flight_type == FlightType.SEAD_ESCORT:
|
elif self.flight.flight_type == FlightType.SEAD_ESCORT:
|
||||||
# if isinstance(self.flight.package.target, NavalControlPoint):
|
if isinstance(self.flight.package.target, NavalControlPoint):
|
||||||
# self.configure_escort_tasks(
|
self.configure_escort_tasks(
|
||||||
# waypoint,
|
waypoint,
|
||||||
# [
|
[
|
||||||
# Targets.All.Naval,
|
Targets.All.Naval.id,
|
||||||
# Targets.All.GroundUnits.AirDefence.AAA.SAMRelated,
|
Targets.All.GroundUnits.AirDefence.AAA.SAMRelated.id,
|
||||||
# ],
|
],
|
||||||
# )
|
max_dist=40,
|
||||||
# else:
|
vertical_spacing=1000,
|
||||||
# self.configure_escort_tasks(
|
)
|
||||||
# waypoint, [Targets.All.GroundUnits.AirDefence.AAA.SAMRelated]
|
else:
|
||||||
# )
|
self.configure_escort_tasks(
|
||||||
|
waypoint,
|
||||||
|
[Targets.All.GroundUnits.AirDefence.AAA.SAMRelated.id],
|
||||||
|
max_dist=40,
|
||||||
|
vertical_spacing=1000,
|
||||||
|
)
|
||||||
|
|
||||||
# Let the AI use ECM to preemptively defend themselves.
|
# Let the AI use ECM to preemptively defend themselves.
|
||||||
ecm_option = OptECMUsing(value=OptECMUsing.Values.UseIfDetectedLockByRadar)
|
ecm_option = OptECMUsing(value=OptECMUsing.Values.UseIfDetectedLockByRadar)
|
||||||
waypoint.tasks.append(ecm_option)
|
waypoint.tasks.append(ecm_option)
|
||||||
|
|
||||||
waypoint.tasks.append(OptFormation.finger_four_open())
|
|
||||||
waypoint.tasks.append(SwitchWaypoint(3, 7))
|
|
||||||
|
|
||||||
rx = (random.random() + 0.1) * 500 * random.choice([-1, 1])
|
|
||||||
ry = (random.random() + 0.1) * 500 * random.choice([-1, 1])
|
|
||||||
rz = (random.random() + 0.1) * 500 * random.choice([-1, 1])
|
|
||||||
pos = {"x": rx, "y": ry, "z": rz}
|
|
||||||
targets = [Targets.All.GroundUnits.AirDefence.AAA.SAMRelated.id]
|
|
||||||
if isinstance(self.flight.package.target, NavalControlPoint):
|
|
||||||
targets.append(Targets.All.Naval.id)
|
|
||||||
waypoint.tasks.append(
|
|
||||||
EscortTaskAction(
|
|
||||||
group_id=self.package.primary_flight.group_id,
|
|
||||||
engagement_max_dist=int(nautical_miles(40).meters),
|
|
||||||
lastwpt=6,
|
|
||||||
targets=targets,
|
|
||||||
position=pos)
|
|
||||||
)
|
|
||||||
elif not self.flight.flight_type.is_air_to_air:
|
elif not self.flight.flight_type.is_air_to_air:
|
||||||
# Capture any non A/A type to avoid issues with SPJs that use the primary radar such as the F/A-18C.
|
# Capture any non A/A type to avoid issues with SPJs that use the primary radar such as the F/A-18C.
|
||||||
# You can bully them with STT to not be able to fire radar guided missiles at you,
|
# You can bully them with STT to not be able to fire radar guided missiles at you,
|
||||||
@ -93,50 +61,26 @@ class JoinPointBuilder(PydcsWaypointBuilder):
|
|||||||
ecm_option = OptECMUsing(value=OptECMUsing.Values.UseIfOnlyLockByRadar)
|
ecm_option = OptECMUsing(value=OptECMUsing.Values.UseIfOnlyLockByRadar)
|
||||||
waypoint.tasks.append(ecm_option)
|
waypoint.tasks.append(ecm_option)
|
||||||
|
|
||||||
waypoint.tasks.append(OptFormation.finger_four_open())
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def configure_escort_tasks(
|
def configure_escort_tasks(
|
||||||
|
self,
|
||||||
waypoint: MovingPoint,
|
waypoint: MovingPoint,
|
||||||
target_types: List[Type[TargetType]],
|
target_types: List[str],
|
||||||
max_dist: Optional[float] = 30.0
|
max_dist: Optional[float] = 30.0,
|
||||||
|
vertical_spacing: Optional[float] = 2000,
|
||||||
) -> None:
|
) -> None:
|
||||||
# Ideally we would use the escort mission type and escort task to have
|
|
||||||
# the AI automatically but the AI only escorts AI flights while they are
|
|
||||||
# traveling between waypoints. When an AI flight performs an attack
|
|
||||||
# (such as attacking the mission target), AI escorts wander aimlessly
|
|
||||||
# until the escorted group resumes its flight plan.
|
|
||||||
#
|
|
||||||
# As such, we instead use the Search Then Engage task, which is an
|
|
||||||
# enroute task that causes the AI to follow their flight plan and engage
|
|
||||||
# enemies of the set type within a certain distance. The downside to
|
|
||||||
# this approach is that AI escorts are no longer related to the group
|
|
||||||
# they are escorting, aside from the fact that they fly a similar flight
|
|
||||||
# plan at the same time. With Escort, the escorts will follow the
|
|
||||||
# escorted group out of the area. The strike element may or may not fly
|
|
||||||
# directly over the target, and they may or may not require multiple
|
|
||||||
# attack runs. For the escort flight we must just assume a flight plan
|
|
||||||
# for the escort to fly. If the strike flight doesn't need to overfly
|
|
||||||
# the target, the escorts are needlessly going in harms way. If the
|
|
||||||
# strike flight needs multiple passes, the escorts may leave before the
|
|
||||||
# escorted aircraft do.
|
|
||||||
#
|
|
||||||
# Another possible option would be to use Search Then Engage for join ->
|
|
||||||
# ingress and egress -> split, but use a Search Then Engage in Zone task
|
|
||||||
# for the target area that is set to end on a flag flip that occurs when
|
|
||||||
# the strike aircraft finish their attack task.
|
|
||||||
#
|
|
||||||
# https://forums.eagle.ru/topic/251798-options-for-alternate-ai-escort-behavior
|
|
||||||
waypoint.add_task(
|
|
||||||
ControlledTask(
|
|
||||||
EngageTargets(
|
|
||||||
# TODO: From doctrine.
|
|
||||||
max_distance=int(nautical_miles(max_dist).meters),
|
|
||||||
targets=target_types,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
# We could set this task to end at the split point. pydcs doesn't
|
rx = (random.random() + 0.1) * 1000
|
||||||
# currently support that task end condition though, and we don't really
|
ry = feet(vertical_spacing).meters
|
||||||
# need it.
|
rz = (random.random() + 0.1) * 50 * random.choice([-1, 1])
|
||||||
|
pos = {"x": rx, "y": ry, "z": rz}
|
||||||
|
|
||||||
|
lastwpt = 6 if self.package.primary_task == FlightType.STRIKE else 5
|
||||||
|
|
||||||
|
waypoint.tasks.append(
|
||||||
|
EscortTaskAction(
|
||||||
|
group_id=self.package.primary_flight.group_id,
|
||||||
|
engagement_max_dist=int(nautical_miles(max_dist).meters),
|
||||||
|
lastwpt=lastwpt,
|
||||||
|
targets=target_types,
|
||||||
|
position=pos)
|
||||||
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user