base mission generation framework

This commit is contained in:
Vasiliy Horbachenko
2018-05-24 11:53:40 +03:00
parent 6152570fd8
commit f4a3aef2d5
15 changed files with 180 additions and 28 deletions

View File

@@ -0,0 +1,40 @@
import typing
import pdb
import dcs
from random import randint
import globals
from .conflictgen import *
from .naming import *
from dcs.mission import *
from dcs.vehicles import *
from dcs.unitgroup import *
from dcs.unittype import *
from dcs.mapping import *
from dcs.point import *
from dcs.task import *
DISTANCE_FACTOR = 4, 5
class AAConflictGenerator:
def __init__(self, mission: Mission, conflict: Conflict):
self.m = mission
self.conflict = conflict
def generate(self, units: typing.Dict[UnitType, int]):
for type, count in units.items():
for _ in range(count):
p = self.conflict.ground_defenders_location.random_point_within(
self.conflict.size * DISTANCE_FACTOR[1],
self.conflict.size * DISTANCE_FACTOR[0])
self.m.vehicle_group(
country=self.conflict.defenders_side,
name=namegen.next_ground_group_name(),
_type=type,
position=p,
group_size=1)

View File

@@ -17,14 +17,15 @@ from dcs.mapping import *
from dcs.point import *
from dcs.task import *
SPREAD_DISTANCE_FACTOR = 0.1, 0.25
SPREAD_DISTANCE_SIZE_FACTOR = 0.5
SPREAD_DISTANCE_FACTOR = 1, 2
ESCORT_MAX_DIST = 30000
WARM_START_ALTITUDE = 6000
WARM_START_AIRSPEED = 300
CAS_ALTITUDE = 3000
INTERCEPT_MAX_DISTANCE_FACTOR = 15
class AircraftConflictGenerator:
escort_targets = [] # type: typing.List[PlaneGroup]
@@ -37,8 +38,7 @@ class AircraftConflictGenerator:
int(self.conflict.size * SPREAD_DISTANCE_FACTOR[0]),
int(self.conflict.size * SPREAD_DISTANCE_FACTOR[1]),
)
return point.random_point_within(distance, self.conflict.size * SPREAD_DISTANCE_SIZE_FACTOR)
return point.random_point_within(distance, self.conflict.size * SPREAD_DISTANCE_FACTOR[0])
def _generate_group(
self,
@@ -48,7 +48,7 @@ class AircraftConflictGenerator:
count: int,
at: Point = None,
airport: Airport = None) -> PlaneGroup:
starttype = airport == None and StartType.Warm or StartType.Runway
starttype = airport == None and StartType.Warm or StartType.Cold
return self.m.flight_group(
country=side,
name=name,
@@ -86,9 +86,14 @@ class AircraftConflictGenerator:
airport=airport)
group.task = Escort.name
for group in self.escort_targets:
group.tasks.append(EscortTaskAction(group.id, engagement_max_dist=ESCORT_MAX_DIST))
group.load_task_default_loadout(dcs.task.Escort.name)
heading = group.position.heading_between_point(self.conflict.point)
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):
for type, count in defenders.items():
@@ -100,5 +105,8 @@ class AircraftConflictGenerator:
at=airport == None and self._group_point(self.conflict.air_defenders_location) or None,
airport=airport)
group.add_waypoint(self.conflict.point, CAS_ALTITUDE)
group.task = FighterSweep()
group.task = FighterSweep.name
group.load_task_default_loadout(dcs.task.FighterSweep())
wayp = group.add_waypoint(self.conflict.point, CAS_ALTITUDE)
wayp.tasks.append(dcs.task.EngageTargets(max_distance=self.conflict.size * INTERCEPT_MAX_DISTANCE_FACTOR))
wayp.tasks.append(dcs.task.OrbitAction())

View File

@@ -18,8 +18,8 @@ from dcs.point import *
from dcs.task import *
from dcs.country import *
SPREAD_DISTANCE_FACTOR = 0.01, 0.1
SPREAD_DISTANCE_SIZE_FACTOR = 0.5
SPREAD_DISTANCE_FACTOR = 0.1, 0.3
SPREAD_DISTANCE_SIZE_FACTOR = 0.1
class ArmorConflictGenerator:
def __init__(self, mission: Mission, conflict: Conflict):
@@ -42,7 +42,7 @@ class ArmorConflictGenerator:
unit,
position=self._group_point(at),
group_size=1,
move_formation=PointAction.OnRoad)
move_formation=PointAction.OffRoad)
wayp = group.add_waypoint(self.conflict.point)
wayp.tasks = []

View File

@@ -2,6 +2,8 @@ import typing
import pdb
import dcs
from dcs import Mission
from dcs.mission import *
from dcs.vehicles import *
from dcs.unitgroup import *
@@ -14,18 +16,22 @@ from dcs.country import *
def _opposite_heading(h):
return h+180
GROUND_DISTANCE_FACTOR = 1
AIR_DISTANCE_FACTOR = 4
GROUND_DISTANCE_FACTOR = 2
AIR_DISTANCE_FACTOR = 5
class Conflict:
def __init__(self, heading: int, attacker: Country, defender: Country, point: Point, size: int):
trigger_zone = None # type: TriggerZone
activation_trigger = None # type: Trigger
def __init__(self, attacker: Country, attack_heading: int, defender: Country, defense_heading: int, point: Point, size: int):
self.attackers_side = attacker
self.defenders_side = defender
self.point = point
self.size = size
self.ground_attackers_location = self.point.point_from_heading(heading, self.size * GROUND_DISTANCE_FACTOR)
self.ground_defenders_location = self.point.point_from_heading(_opposite_heading(heading), self.size * GROUND_DISTANCE_FACTOR)
self.ground_attackers_location = self.point.point_from_heading(attack_heading, self.size * GROUND_DISTANCE_FACTOR)
self.ground_defenders_location = self.point.point_from_heading(defense_heading, self.size * GROUND_DISTANCE_FACTOR)
self.air_attackers_location = self.point.point_from_heading(attack_heading, self.size * AIR_DISTANCE_FACTOR)
self.air_defenders_location = self.point.point_from_heading(defense_heading, self.size * AIR_DISTANCE_FACTOR)
self.air_attackers_location = self.point.point_from_heading(heading, self.size * AIR_DISTANCE_FACTOR)
self.air_defenders_location = self.point.point_from_heading(_opposite_heading(heading), self.size * AIR_DISTANCE_FACTOR)

View File

@@ -16,6 +16,10 @@ class NameGenerator:
def next_intercept_group_name(self):
self.number += 1
return "Intercept Unit {}".format(self.number)
def next_ground_group_name(self):
self.number += 1
return "AA Unit {}".format(self.number)
namegen = NameGenerator()