This commit is contained in:
Vasiliy Horbachenko 2018-05-16 03:04:24 +03:00 committed by Vasyl Horbachenko
commit 6152570fd8
15 changed files with 276 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.pyc
__pycache__

25
__init__.py Executable file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env python3
import dcs
import os
import gen
m = dcs.Mission()
conflict = gen.Conflict(
heading=100,
attacker=m.country("USA"),
defender=m.country("Russia"),
point=m.terrain.krymsk().position,
size=10000)
armor_conflict = gen.ArmorConflictGenerator(m, conflict)
armor_conflict.generate(
attackers={dcs.vehicles.Armor.MBT_M1A2_Abrams: 8},
defenders={dcs.vehicles.Armor.MBT_T_80U: 6})
aircraft_conflict = gen.AircraftConflictGenerator(m, conflict)
aircraft_conflict.generate_cas({dcs.planes.A_10C: 2})
aircraft_conflict.generate_escort({dcs.planes.F_15C: 2})
aircraft_conflict.generate_interceptors({dcs.planes.Su_27: 2})

0
game/__init__.py Normal file
View File

6
gen/__init__.py Normal file
View File

@ -0,0 +1,6 @@
import dcs
from .armor import *
from .aircraft import *
from .aaa import *

0
gen/aaa.py Normal file
View File

104
gen/aircraft.py Normal file
View File

@ -0,0 +1,104 @@
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 *
SPREAD_DISTANCE_FACTOR = 0.1, 0.25
SPREAD_DISTANCE_SIZE_FACTOR = 0.5
ESCORT_MAX_DIST = 30000
WARM_START_ALTITUDE = 6000
WARM_START_AIRSPEED = 300
CAS_ALTITUDE = 3000
class AircraftConflictGenerator:
escort_targets = [] # type: typing.List[PlaneGroup]
def __init__(self, mission: Mission, conflict: Conflict):
self.m = mission
self.conflict = conflict
def _group_point(self, point) -> Point:
distance = randint(
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)
def _generate_group(
self,
name: str,
side: Country,
unit: UnitType,
count: int,
at: Point = None,
airport: Airport = None) -> PlaneGroup:
starttype = airport == None and StartType.Warm or StartType.Runway
return self.m.flight_group(
country=side,
name=name,
aircraft_type=unit,
airport=airport,
position=at,
altitude=WARM_START_ALTITUDE,
speed=WARM_START_AIRSPEED,
maintask=None,
start_type=starttype,
group_size=count)
def generate_cas(self, attackers: typing.Dict[PlaneType, int], airport: Airport = None):
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,
airport=airport)
self.escort_targets.append(group)
group.add_waypoint(self.conflict.point, CAS_ALTITUDE)
group.task = CAS.name
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)
group.task = Escort.name
for group in self.escort_targets:
group.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():
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,
airport=airport)
group.add_waypoint(self.conflict.point, CAS_ALTITUDE)
group.task = FighterSweep()

62
gen/armor.py Normal file
View File

@ -0,0 +1,62 @@
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 *
from dcs.country import *
SPREAD_DISTANCE_FACTOR = 0.01, 0.1
SPREAD_DISTANCE_SIZE_FACTOR = 0.5
class ArmorConflictGenerator:
def __init__(self, mission: Mission, conflict: Conflict):
self.m = mission
self.conflict = conflict
def _group_point(self, point) -> Point:
distance = randint(
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)
def _generate_group(self, side: Country, unit: UnitType, count: int, at: Point):
for c in range(count):
group = self.m.vehicle_group(
side,
namegen.next_armor_group_name(),
unit,
position=self._group_point(at),
group_size=1,
move_formation=PointAction.OnRoad)
wayp = group.add_waypoint(self.conflict.point)
wayp.tasks = []
def generate(self, attackers: typing.Dict[UnitType, int], defenders: typing.Dict[UnitType, int]):
for type, count in attackers.items():
self._generate_group(
side=self.conflict.attackers_side,
unit=type,
count=count,
at=self.conflict.ground_attackers_location)
for type, count in defenders.items():
self._generate_group(
side=self.conflict.defenders_side,
unit=type,
count=count,
at=self.conflict.ground_defenders_location)

31
gen/conflictgen.py Normal file
View File

@ -0,0 +1,31 @@
import typing
import pdb
import dcs
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 *
from dcs.country import *
def _opposite_heading(h):
return h+180
GROUND_DISTANCE_FACTOR = 1
AIR_DISTANCE_FACTOR = 4
class Conflict:
def __init__(self, heading: int, attacker: Country, defender: Country, 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.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)

22
gen/naming.py Normal file
View File

@ -0,0 +1,22 @@
class NameGenerator:
number = 0
def next_armor_group_name(self):
self.number += 1
return "Armor Unit {}".format(self.number)
def next_cas_group_name(self):
self.number += 1
return "CAS Unit {}".format(self.number)
def next_escort_group_name(self):
self.number += 1
return "Escort Unit {}".format(self.number)
def next_intercept_group_name(self):
self.number += 1
return "Intercept Unit {}".format(self.number)
namegen = NameGenerator()

4
globals.py Normal file
View File

@ -0,0 +1,4 @@
import dcs
mission = dcs.mission.Mission()
country = mission.country("USA")

0
map/__init__.py Normal file
View File

5
map/controlpoint.py Normal file
View File

@ -0,0 +1,5 @@
import dcs
class ControlPoint:
def __init__(self):
pass

0
shop/__init__.py Normal file
View File

0
userdata/__init__.py Normal file
View File

15
userdata/assets.py Normal file
View File

@ -0,0 +1,15 @@
import dcs
money = 2000
aircraft = []
armor = []
control_points = []
def add_aircraft(plane: dcs.planes.PlaneType):
aircraft.append(plane)
def add_armor(vehicle: dcs.vehicles.Armor):
armor.append(vehicle)
def add_control_point(cp):
control_points.append(cp)