commit 6152570fd8de84331c153e34f6ae4a13d28d4eeb Author: Vasiliy Horbachenko Date: Wed May 16 03:04:24 2018 +0300 initial diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..a295864e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pyc +__pycache__ diff --git a/__init__.py b/__init__.py new file mode 100755 index 00000000..2f3da4e8 --- /dev/null +++ b/__init__.py @@ -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}) diff --git a/game/__init__.py b/game/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/gen/__init__.py b/gen/__init__.py new file mode 100644 index 00000000..6d3d2097 --- /dev/null +++ b/gen/__init__.py @@ -0,0 +1,6 @@ +import dcs + +from .armor import * +from .aircraft import * +from .aaa import * + diff --git a/gen/aaa.py b/gen/aaa.py new file mode 100644 index 00000000..e69de29b diff --git a/gen/aircraft.py b/gen/aircraft.py new file mode 100644 index 00000000..bc670d4c --- /dev/null +++ b/gen/aircraft.py @@ -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() diff --git a/gen/armor.py b/gen/armor.py new file mode 100644 index 00000000..dc5f8140 --- /dev/null +++ b/gen/armor.py @@ -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) diff --git a/gen/conflictgen.py b/gen/conflictgen.py new file mode 100644 index 00000000..035f8c16 --- /dev/null +++ b/gen/conflictgen.py @@ -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) diff --git a/gen/naming.py b/gen/naming.py new file mode 100644 index 00000000..e8675c13 --- /dev/null +++ b/gen/naming.py @@ -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() + diff --git a/globals.py b/globals.py new file mode 100644 index 00000000..b3dc6753 --- /dev/null +++ b/globals.py @@ -0,0 +1,4 @@ +import dcs + +mission = dcs.mission.Mission() +country = mission.country("USA") diff --git a/map/__init__.py b/map/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/map/controlpoint.py b/map/controlpoint.py new file mode 100644 index 00000000..54c42958 --- /dev/null +++ b/map/controlpoint.py @@ -0,0 +1,5 @@ +import dcs + +class ControlPoint: + def __init__(self): + pass diff --git a/shop/__init__.py b/shop/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/userdata/__init__.py b/userdata/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/userdata/assets.py b/userdata/assets.py new file mode 100644 index 00000000..bb7b4b83 --- /dev/null +++ b/userdata/assets.py @@ -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)