From 4cd3c24b4924fba966fb87a0528f45823dbbc352 Mon Sep 17 00:00:00 2001 From: Vasyl Horbachenko Date: Wed, 30 May 2018 01:57:46 +0300 Subject: [PATCH] aa spawn on available radials instead of random --- __init__.py | 26 +++++++++++++------------- game/mission.py | 7 +++++-- gen/aaa.py | 7 +++---- gen/conflictgen.py | 20 +++++++++++++++++--- theater/caucasus.py | 2 +- theater/controlpoint.py | 3 ++- 6 files changed, 41 insertions(+), 24 deletions(-) diff --git a/__init__.py b/__init__.py index 99b1c00d..b92cad68 100755 --- a/__init__.py +++ b/__init__.py @@ -35,19 +35,6 @@ theater.senaki.base.aa = { AirDefence.AAA_ZU_23_on_Ural_375: 2, } -op = game.mission.CaptureOperation( - mission=m, - attacker=m.country("USA"), - defender=m.country("Russia"), - from_cp=theater.senaki, - to_cp=theater.batumi, - cas={A_10C: 2}, - escort={F_15C: 2}, - attack={Armor.MBT_M1A2_Abrams: 4}, - intercept={Su_27: 4}, - defense={Armor.MBT_T_55: 4}, - aa={AirDefence.AAA_ZU_23_Insurgent_on_Ural_375: 3}) - op = game.mission.InterceptOperation( mission=m, attacker=m.country("USA"), @@ -67,6 +54,19 @@ op = game.mission.GroundInterceptOperation( target={Unarmed.Transport_ZIL_4331: 10}, strikegroup={A_10C: 2} ) + +op = game.mission.CaptureOperation( + mission=m, + attacker=m.country("USA"), + defender=m.country("Russia"), + from_cp=theater.senaki, + to_cp=theater.batumi, + cas={A_10C: 2}, + escort={F_15C: 2}, + attack={Armor.MBT_M1A2_Abrams: 4}, + intercept={Su_27: 4}, + defense={Armor.MBT_T_55: 4}, + aa={AirDefence.AAA_ZU_23_Insurgent_on_Ural_375: 3}) op.generate() if not os.path.exists("./build"): diff --git a/game/mission.py b/game/mission.py index 647f007a..531e4fd3 100644 --- a/game/mission.py +++ b/game/mission.py @@ -5,6 +5,7 @@ from dcs.mission import * from dcs.unitgroup import * from dcs.vehicles import * from theater.controlpoint import * +from theater.conflicttheater import * from theater.base import * from gen.armor import * @@ -71,7 +72,8 @@ class InterceptOperation(Operation): attacker=attacker, defender=defender, position=destination.position, - heading=randint(0, 360) + heading=randint(0, 360), + radials=ALL_RADIALS ) super(InterceptOperation, self).__init__(mission, conflict) @@ -98,7 +100,8 @@ class GroundInterceptOperation(Operation): attacker=attacker, defender=defender, position=position, - heading=randint(0, 360) + heading=randint(0, 360), + radials=ALL_RADIALS ) super(GroundInterceptOperation, self).__init__(mission, conflict) diff --git a/gen/aaa.py b/gen/aaa.py index c35c27d5..cfba29ef 100644 --- a/gen/aaa.py +++ b/gen/aaa.py @@ -26,10 +26,9 @@ class AAConflictGenerator: 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]) + for _, radial in zip(range(count), self.conflict.radials): + distance = randint(self.conflict.size * DISTANCE_FACTOR[0], self.conflict.size * DISTANCE_FACTOR[1]) + p = self.conflict.position.point_from_heading(radial, distance) self.m.vehicle_group( country=self.conflict.defenders_side, diff --git a/gen/conflictgen.py b/gen/conflictgen.py index 7b46af89..070a9cfb 100644 --- a/gen/conflictgen.py +++ b/gen/conflictgen.py @@ -26,13 +26,25 @@ INTERCEPT_ATTACKERS_DISTANCE = 60000 INTERCEPT_DEFENDERS_DISTANCE = 30000 class Conflict: + attackers_side = None # type: Country + defenders_side = None # type: Country + position = None # type: Point + size = None # type: int + radials = None # type: typing.List[int] + + ground_attackers_location = None # type: Point + ground_defenders_location = None # type: Point + air_attackers_location = None # type: Point + air_defenders_location = None # type: Point + @classmethod - def capture_conflict(self, attacker: Country, attack_heading: int, defender: Country, defense_heading: int, position: Point, size: int): + def capture_conflict(self, attacker: Country, attack_heading: int, defender: Country, defense_heading: int, position: Point, size: int, radials: typing.List[int]): instance = self() instance.attackers_side = attacker instance.defenders_side = defender instance.position = position instance.size = size + instance.radials = radials 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) @@ -43,7 +55,7 @@ class Conflict: return instance @classmethod - def intercept_conflict(self, attacker: Country, defender: Country, position: Point, heading: int): + def intercept_conflict(self, attacker: Country, defender: Country, position: Point, heading: int, radials: typing.List[int]): from theater.conflicttheater import SIZE_REGULAR instance = self() @@ -52,6 +64,7 @@ class Conflict: instance.position = position instance.size = SIZE_REGULAR + instance.radials = radials 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) @@ -59,7 +72,7 @@ class Conflict: return instance @classmethod - def ground_intercept_conflict(self, attacker: Country, defender: Country, position: Point, heading): + def ground_intercept_conflict(self, attacker: Country, defender: Country, position: Point, heading: int, radials: typing.List[int]): from theater.conflicttheater import SIZE_SMALL instance = self() @@ -68,6 +81,7 @@ class Conflict: instance.position = position instance.size = SIZE_SMALL + instance.radials = radials instance.air_attackers_location = instance.position.point_from_heading(random.randint(*INTERCEPT_ATTACKERS_HEADING) + heading, AIR_DISTANCE) instance.ground_defenders_location = instance.position diff --git a/theater/caucasus.py b/theater/caucasus.py index 3810fd79..cd19baab 100644 --- a/theater/caucasus.py +++ b/theater/caucasus.py @@ -7,7 +7,7 @@ class CaucasusTheater(ConflictTheater): kutaisi = ControlPoint(caucasus.Kutaisi.position, ALL_RADIALS, SIZE_SMALL, IMPORTANCE_LOW) senaki = ControlPoint(caucasus.Senaki.position, ALL_RADIALS, SIZE_REGULAR, IMPORTANCE_LOW) kobuleti = ControlPoint(caucasus.Kobuleti.position, COAST_VERTICAL, SIZE_SMALL, IMPORTANCE_LOW) - batumi = ControlPoint(caucasus.Batumi.position, COAST_VERTICAL, SIZE_REGULAR, IMPORTANCE_MEDIUM) + batumi = ControlPoint(caucasus.Batumi.position, COAST_VERTICAL, SIZE_SMALL, IMPORTANCE_MEDIUM) sukhumi = ControlPoint(caucasus.Sukhumi.position, COAST_VERTICAL, SIZE_REGULAR, IMPORTANCE_MEDIUM) gudauta = ControlPoint(caucasus.Gudauta.position, COAST_VERTICAL, SIZE_REGULAR, IMPORTANCE_MEDIUM) sochi = ControlPoint(caucasus.Sochi.position, COAST_VERTICAL, SIZE_BIG, IMPORTANCE_HIGH) diff --git a/theater/controlpoint.py b/theater/controlpoint.py index 03497e00..b4bd709e 100644 --- a/theater/controlpoint.py +++ b/theater/controlpoint.py @@ -49,6 +49,7 @@ class ControlPoint: defender=defender, defense_heading=defense_radial, position=self.position, - size=self.size) + size=self.size, + radials=self.radials)