forked from dcs-liberation/dcs_liberation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ground objects are always generated and destroyable, even when it's n…
…ot the current mission objective. Fix : SAM site destruction status is saved correctly. Added most SAM site to generator.
- Loading branch information
Showing
40 changed files
with
812 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import math | ||
import random | ||
|
||
from dcs import unitgroup | ||
from dcs.point import PointAction | ||
from dcs.unit import Vehicle | ||
|
||
|
||
class AntiAirGroupGenerator(): | ||
|
||
def __init__(self, game, ground_object, group_object_group_id): | ||
self.game = game | ||
self.go = ground_object | ||
self.position = ground_object.position | ||
self.heading = random.randint(0, 359) | ||
self.vg = unitgroup.VehicleGroup(self.game.next_group_id(), self.go.group_identifier) | ||
|
||
wp = self.vg.add_waypoint(self.position, PointAction.OffRoad, 0) | ||
wp.ETA_locked = True | ||
|
||
def generate(self): | ||
raise NotImplementedError | ||
|
||
def get_generated_group(self): | ||
return self.vg | ||
|
||
def add_unit(self, unit_type, name, pos_x, pos_y, heading): | ||
|
||
nn = "cgroup|" + str(self.go.cp_id) + '|' + str(self.go.group_id) + '|' + str(self.go.group_identifier) + "|" + name | ||
|
||
unit = Vehicle(self.game.next_unit_id(), | ||
nn, unit_type.id) | ||
unit.position.x = pos_x | ||
unit.position.y = pos_y | ||
unit.heading = heading | ||
self.vg.add_unit(unit) | ||
return unit | ||
|
||
def get_circular_position(self, num_units, launcher_distance, coverage=90): | ||
""" | ||
Given a position on the map, array a group of units in a circle a uniform distance from the unit | ||
:param num_units: | ||
number of units to play on the circle | ||
:param launcher_distance: | ||
distance the units should be from the center unit | ||
:param coverage: | ||
0-360 | ||
:return: | ||
list of tuples representing each unit location | ||
[(pos_x, pos_y, heading), ...] | ||
""" | ||
if coverage == 360: | ||
# one of the positions is shared :'( | ||
outer_offset = coverage / num_units | ||
else: | ||
outer_offset = coverage / (num_units - 1) | ||
|
||
positions = [] | ||
|
||
if num_units % 2 == 0: | ||
current_offset = self.heading - ((coverage / (num_units - 1)) / 2) | ||
else: | ||
current_offset = self.heading | ||
current_offset -= outer_offset * (math.ceil(num_units / 2) - 1) | ||
for x in range(1, num_units + 1): | ||
positions.append(( | ||
self.position.x + launcher_distance * math.cos(math.radians(current_offset)), | ||
self.position.y + launcher_distance * math.sin(math.radians(current_offset)), | ||
current_offset, | ||
)) | ||
current_offset += outer_offset | ||
return positions | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import random | ||
|
||
from dcs.vehicles import AirDefence, Unarmed | ||
|
||
from gen.sam.group_generator import AntiAirGroupGenerator | ||
|
||
|
||
class AvengerGenerator(AntiAirGroupGenerator): | ||
""" | ||
This generate an Avenger group | ||
""" | ||
|
||
def generate(self): | ||
num_launchers = random.randint(2, 3) | ||
|
||
self.add_unit(Unarmed.Transport_M818, "TRUCK", self.position.x, self.position.y, self.heading) | ||
positions = self.get_circular_position(num_launchers, launcher_distance=110, coverage=180) | ||
for i, position in enumerate(positions): | ||
self.add_unit(AirDefence.SAM_Avenger_M1097, "SPAA#" + str(i), position[0], position[1], position[2]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import random | ||
|
||
from dcs.vehicles import AirDefence, Unarmed | ||
|
||
from gen.sam.group_generator import AntiAirGroupGenerator | ||
|
||
|
||
class ChaparralGenerator(AntiAirGroupGenerator): | ||
""" | ||
This generate a Chaparral group | ||
""" | ||
|
||
def generate(self): | ||
num_launchers = random.randint(2, 4) | ||
|
||
self.add_unit(Unarmed.Transport_M818, "TRUCK", self.position.x, self.position.y, self.heading) | ||
positions = self.get_circular_position(num_launchers, launcher_distance=110, coverage=180) | ||
for i, position in enumerate(positions): | ||
self.add_unit(AirDefence.SAM_Chaparral_M48, "SPAA#" + str(i), position[0], position[1], position[2]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import random | ||
|
||
from dcs.vehicles import AirDefence, Unarmed | ||
|
||
from gen.sam.group_generator import AntiAirGroupGenerator | ||
|
||
|
||
class GepardGenerator(AntiAirGroupGenerator): | ||
""" | ||
This generate a Gepard group | ||
""" | ||
|
||
def generate(self): | ||
self.add_unit(AirDefence.SPAAA_Gepard, "SPAAA", self.position.x, self.position.y, self.heading) | ||
if random.randint(0, 1) == 1: | ||
self.add_unit(AirDefence.SPAAA_Gepard, "SPAAA2", self.position.x, self.position.y, self.heading) | ||
self.add_unit(Unarmed.Transport_M818, "TRUCK", self.position.x + 80, self.position.y, self.heading) | ||
|
Oops, something went wrong.