intercept mission

This commit is contained in:
Vasyl Horbachenko
2018-05-29 22:50:35 +03:00
committed by Vasyl Horbachenko
parent a61f487196
commit 781ddce09d
10 changed files with 256 additions and 96 deletions

View File

@@ -19,9 +19,12 @@ from dcs.task import *
SPREAD_DISTANCE_FACTOR = 1, 2
ESCORT_MAX_DIST = 30000
WORKAROUND_WAYP_DIST = 1000
WARM_START_ALTITUDE = 6000
WARM_START_AIRSPEED = 300
INTERCEPT_ALT = 15000
CAS_ALTITUDE = 3000
INTERCEPT_MAX_DISTANCE_FACTOR = 15
@@ -49,6 +52,7 @@ class AircraftConflictGenerator:
at: Point = None,
airport: Airport = None) -> PlaneGroup:
starttype = airport == None and StartType.Warm or StartType.Cold
print("generating {} ({}) at {} {}".format(unit, count, at, airport, side))
return self.m.flight_group(
country=side,
name=name,
@@ -61,52 +65,112 @@ class AircraftConflictGenerator:
start_type=starttype,
group_size=count)
def _generate_escort(self, units: typing.Dict[PlaneType, int], airport: Airport, side: Country, location: Point):
assert len(self.escort_targets) > 0
for type, count in units.items():
group = self._generate_group(
name=namegen.next_escort_group_name(),
side=side,
unit=type,
count=count,
at=location,
airport=airport)
group.task = Escort.name
group.load_task_default_loadout(dcs.task.Escort)
heading = group.position.heading_between_point(self.conflict.position)
position = group.position # type: Point
wayp = group.add_waypoint(position.point_from_heading(heading, WORKAROUND_WAYP_DIST), CAS_ALTITUDE)
for group in self.escort_targets:
wayp.tasks.append(EscortTaskAction(group.id, engagement_max_dist=ESCORT_MAX_DIST))
def generate_cas(self, attackers: typing.Dict[PlaneType, int], airport: Airport = None):
assert len(self.escort_targets) == 0
for type, count in attackers.items():
group = self._generate_group(
name=namegen.next_cas_group_name(),
side=self.conflict.attackers_side,
unit=type,
count=count,
at=airport == None and self._group_point(self.conflict.air_attackers_location) or None,
at=airport is None and self._group_point(self.conflict.air_attackers_location) or None,
airport=airport)
self.escort_targets.append(group)
group.add_waypoint(self.conflict.position, CAS_ALTITUDE)
group.task = CAS.name
group.load_task_default_loadout(CAS)
def generate_escort(self, attackers: typing.Dict[PlaneType, int], airport: Airport = None):
for type, count in attackers.items():
group = self._generate_group(
name=namegen.next_escort_group_name(),
side=self.conflict.attackers_side,
unit=type,
count=count,
at=airport == None and self._group_point(self.conflict.air_attackers_location) or None,
airport=airport)
def generate_cas_escort(self, attackers: typing.Dict[PlaneType, int], airport: Airport = None):
self._generate_escort(
units=attackers,
airport=airport,
side=self.conflict.attackers_side,
location=airport is None and self._group_point(self.conflict.air_attackers_location) or None
)
group.task = Escort.name
group.load_task_default_loadout(dcs.task.Escort.name)
def generate_transport_escort(self, escort: typing.Dict[PlaneType, int], airport: Airport = None):
self._generate_escort(
units=escort,
airport=airport,
side=self.conflict.defenders_side,
location=airport is None and self._group_point(self.conflict.air_defenders_location) or None
)
heading = group.position.heading_between_point(self.conflict.position)
position = group.position # type: Point
wayp = group.add_waypoint(position.point_from_heading(heading, 3000), CAS_ALTITUDE)
for group in self.escort_targets:
wayp.tasks.append(EscortTaskAction(group.id, engagement_max_dist=ESCORT_MAX_DIST))
def generate_interceptors(self, defenders: typing.Dict[PlaneType, int], airport: Airport = None):
def generate_defense(self, defenders: typing.Dict[PlaneType, int], airport: Airport = None):
for type, count in defenders.items():
group = self._generate_group(
name=namegen.next_intercept_group_name(),
side=self.conflict.defenders_side,
unit=type,
count=count,
at=airport == None and self._group_point(self.conflict.air_defenders_location) or None,
at=airport is None and self._group_point(self.conflict.air_defenders_location) or None,
airport=airport)
group.task = FighterSweep.name
group.load_task_default_loadout(dcs.task.FighterSweep())
group.load_task_default_loadout(FighterSweep)
wayp = group.add_waypoint(self.conflict.position, CAS_ALTITUDE)
wayp.tasks.append(dcs.task.EngageTargets(max_distance=self.conflict.size * INTERCEPT_MAX_DISTANCE_FACTOR))
wayp.tasks.append(dcs.task.OrbitAction())
def generate_transport(self, transport: typing.Dict[PlaneType, int], destination: Airport):
assert len(self.escort_targets) == 0
for type, count in transport.items():
group = self._generate_group(
name=namegen.next_transport_group_name(),
side=self.conflict.defenders_side,
unit=type,
count=count,
at=self._group_point(self.conflict.air_defenders_location),
airport=None
)
group.task = Transport.name
self.escort_targets.append(group)
group.land_at(destination)
def generate_interception(self, interceptors: typing.Dict[PlaneType, int], airport: Airport = None):
for type, count in interceptors.items():
group = self._generate_group(
name=namegen.next_intercept_group_name(),
side=self.conflict.attackers_side,
unit=type,
count=count,
at=airport is None and self._group_point(self.conflict.air_attackers_location) or None,
airport=airport
)
group.task = FighterSweep.name
group.load_task_default_loadout(FighterSweep)
heading = group.position.heading_between_point(self.conflict.position)
initial_wayp = group.add_waypoint(group.position.point_from_heading(heading, WORKAROUND_WAYP_DIST), INTERCEPT_ALT)
initial_wayp.tasks.append(EngageTargets())
wayp = group.add_waypoint(self.conflict.position, 0)
wayp.tasks.append(EngageTargets())

View File

@@ -2,6 +2,7 @@ import typing
import pdb
import dcs
from random import randint
from dcs import Mission
from dcs.mission import *
@@ -17,18 +18,42 @@ def _opposite_heading(h):
return h+180
GROUND_DISTANCE_FACTOR = 2
AIR_DISTANCE_FACTOR = 5
AIR_DISTANCE = 8000
INTERCEPT_ATTACKERS_HEADING = -45, 45
INTERCEPT_DEFENDERS_HEADING = -10, 10
INTERCEPT_ATTACKERS_DISTANCE = 60000
INTERCEPT_DEFENDERS_DISTANCE = 30000
class Conflict:
def __init__(self, attacker: Country, attack_heading: int, defender: Country, defense_heading: int, position: Point, size: int):
self.attackers_side = attacker
self.defenders_side = defender
self.position = position
self.size = size
@classmethod
def capture_conflict(self, attacker: Country, attack_heading: int, defender: Country, defense_heading: int, position: Point, size: int):
instance = self()
instance.attackers_side = attacker
instance.defenders_side = defender
instance.position = position
instance.size = size
self.ground_attackers_location = self.position.point_from_heading(attack_heading, self.size * GROUND_DISTANCE_FACTOR)
self.ground_defenders_location = self.position.point_from_heading(defense_heading, self.size * GROUND_DISTANCE_FACTOR)
instance.ground_attackers_location = instance.position.point_from_heading(attack_heading, instance.size * GROUND_DISTANCE_FACTOR)
instance.ground_defenders_location = instance.position.point_from_heading(defense_heading, instance.size * GROUND_DISTANCE_FACTOR)
self.air_attackers_location = self.position.point_from_heading(attack_heading, self.size * AIR_DISTANCE_FACTOR)
self.air_defenders_location = self.position.point_from_heading(defense_heading, self.size * AIR_DISTANCE_FACTOR)
instance.air_attackers_location = instance.position.point_from_heading(attack_heading, AIR_DISTANCE)
instance.air_defenders_location = instance.position.point_from_heading(defense_heading, AIR_DISTANCE)
return instance
@classmethod
def intercept_conflict(self, attacker: Country, defender: Country, position: Point, heading: int):
from theater.conflicttheater import SIZE_REGULAR
instance = self()
instance.attackers_side = attacker
instance.defenders_side = defender
instance.position = position
instance.size = SIZE_REGULAR
instance.air_attackers_location = instance.position.point_from_heading(random.randint(*INTERCEPT_ATTACKERS_HEADING) + heading, INTERCEPT_ATTACKERS_DISTANCE)
instance.air_defenders_location = instance.position.point_from_heading(random.randint(*INTERCEPT_DEFENDERS_HEADING) + heading, INTERCEPT_DEFENDERS_DISTANCE)
return instance

View File

@@ -21,6 +21,10 @@ class NameGenerator:
self.number += 1
return "AA Unit {}".format(self.number)
def next_transport_group_name(self):
self.number += 1
return "Transport Unit {}".format(self.number)
namegen = NameGenerator()